PostgreSQL Source Code  git master
tcopprot.h File Reference
#include "nodes/params.h"
#include "nodes/plannodes.h"
#include "storage/procsignal.h"
#include "utils/guc.h"
#include "utils/queryenvironment.h"
Include dependency graph for tcopprot.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define STACK_DEPTH_SLOP   (512 * 1024L)
 
#define RESTRICT_RELKIND_VIEW   0x01
 
#define RESTRICT_RELKIND_FOREIGN_TABLE   0x02
 

Enumerations

enum  LogStmtLevel { LOGSTMT_NONE , LOGSTMT_DDL , LOGSTMT_MOD , LOGSTMT_ALL }
 

Functions

Listpg_parse_query (const char *query_string)
 
Listpg_rewrite_query (Query *query)
 
Listpg_analyze_and_rewrite_fixedparams (RawStmt *parsetree, const char *query_string, const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv)
 
Listpg_analyze_and_rewrite_varparams (RawStmt *parsetree, const char *query_string, Oid **paramTypes, int *numParams, QueryEnvironment *queryEnv)
 
Listpg_analyze_and_rewrite_withcb (RawStmt *parsetree, const char *query_string, ParserSetupHook parserSetup, void *parserSetupArg, QueryEnvironment *queryEnv)
 
PlannedStmtpg_plan_query (Query *querytree, const char *query_string, int cursorOptions, ParamListInfo boundParams)
 
Listpg_plan_queries (List *querytrees, const char *query_string, int cursorOptions, ParamListInfo boundParams)
 
void die (SIGNAL_ARGS)
 
void quickdie (SIGNAL_ARGS) pg_attribute_noreturn()
 
void StatementCancelHandler (SIGNAL_ARGS)
 
void FloatExceptionHandler (SIGNAL_ARGS) pg_attribute_noreturn()
 
void HandleRecoveryConflictInterrupt (ProcSignalReason reason)
 
void ProcessClientReadInterrupt (bool blocked)
 
void ProcessClientWriteInterrupt (bool blocked)
 
void process_postgres_switches (int argc, char *argv[], GucContext ctx, const char **dbname)
 
void PostgresSingleUserMain (int argc, char *argv[], const char *username) pg_attribute_noreturn()
 
void PostgresMain (const char *dbname, const char *username) pg_attribute_noreturn()
 
long get_stack_depth_rlimit (void)
 
void ResetUsage (void)
 
void ShowUsage (const char *title)
 
int check_log_duration (char *msec_str, bool was_logged)
 
void set_debug_options (int debug_flag, GucContext context, GucSource source)
 
bool set_plan_disabling_options (const char *arg, GucContext context, GucSource source)
 
const char * get_stats_option_name (const char *arg)
 

Variables

PGDLLIMPORT CommandDest whereToSendOutput
 
PGDLLIMPORT const char * debug_query_string
 
PGDLLIMPORT int max_stack_depth
 
PGDLLIMPORT int PostAuthDelay
 
PGDLLIMPORT int client_connection_check_interval
 
PGDLLIMPORT bool Log_disconnections
 
PGDLLIMPORT int log_statement
 
PGDLLIMPORT int restrict_nonsystem_relation_kind
 

Macro Definition Documentation

◆ RESTRICT_RELKIND_FOREIGN_TABLE

#define RESTRICT_RELKIND_FOREIGN_TABLE   0x02

Definition at line 48 of file tcopprot.h.

◆ RESTRICT_RELKIND_VIEW

#define RESTRICT_RELKIND_VIEW   0x01

Definition at line 47 of file tcopprot.h.

◆ STACK_DEPTH_SLOP

#define STACK_DEPTH_SLOP   (512 * 1024L)

Definition at line 25 of file tcopprot.h.

Enumeration Type Documentation

◆ LogStmtLevel

Enumerator
LOGSTMT_NONE 
LOGSTMT_DDL 
LOGSTMT_MOD 
LOGSTMT_ALL 

Definition at line 35 of file tcopprot.h.

36 {
37  LOGSTMT_NONE, /* log no statements */
38  LOGSTMT_DDL, /* log data definition statements */
39  LOGSTMT_MOD, /* log modification statements, plus DDL */
40  LOGSTMT_ALL, /* log all statements */
41 } LogStmtLevel;
LogStmtLevel
Definition: tcopprot.h:36
@ LOGSTMT_NONE
Definition: tcopprot.h:37
@ LOGSTMT_MOD
Definition: tcopprot.h:39
@ LOGSTMT_DDL
Definition: tcopprot.h:38
@ LOGSTMT_ALL
Definition: tcopprot.h:40

Function Documentation

◆ check_log_duration()

int check_log_duration ( char *  msec_str,
bool  was_logged 
)

Definition at line 2412 of file postgres.c.

2413 {
2414  if (log_duration || log_min_duration_sample >= 0 ||
2416  {
2417  long secs;
2418  int usecs;
2419  int msecs;
2420  bool exceeded_duration;
2421  bool exceeded_sample_duration;
2422  bool in_sample = false;
2423 
2426  &secs, &usecs);
2427  msecs = usecs / 1000;
2428 
2429  /*
2430  * This odd-looking test for log_min_duration_* being exceeded is
2431  * designed to avoid integer overflow with very long durations: don't
2432  * compute secs * 1000 until we've verified it will fit in int.
2433  */
2434  exceeded_duration = (log_min_duration_statement == 0 ||
2436  (secs > log_min_duration_statement / 1000 ||
2437  secs * 1000 + msecs >= log_min_duration_statement)));
2438 
2439  exceeded_sample_duration = (log_min_duration_sample == 0 ||
2440  (log_min_duration_sample > 0 &&
2441  (secs > log_min_duration_sample / 1000 ||
2442  secs * 1000 + msecs >= log_min_duration_sample)));
2443 
2444  /*
2445  * Do not log if log_statement_sample_rate = 0. Log a sample if
2446  * log_statement_sample_rate <= 1 and avoid unnecessary PRNG call if
2447  * log_statement_sample_rate = 1.
2448  */
2449  if (exceeded_sample_duration)
2450  in_sample = log_statement_sample_rate != 0 &&
2451  (log_statement_sample_rate == 1 ||
2453 
2454  if (exceeded_duration || in_sample || log_duration || xact_is_sampled)
2455  {
2456  snprintf(msec_str, 32, "%ld.%03d",
2457  secs * 1000 + msecs, usecs % 1000);
2458  if ((exceeded_duration || in_sample || xact_is_sampled) && !was_logged)
2459  return 2;
2460  else
2461  return 1;
2462  }
2463  }
2464 
2465  return 0;
2466 }
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
Definition: timestamp.c:1720
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1644
int log_min_duration_statement
Definition: guc_tables.c:525
int log_min_duration_sample
Definition: guc_tables.c:524
double log_statement_sample_rate
Definition: guc_tables.c:529
bool log_duration
Definition: guc_tables.c:490
double pg_prng_double(pg_prng_state *state)
Definition: pg_prng.c:268
pg_prng_state pg_global_prng_state
Definition: pg_prng.c:34
#define snprintf
Definition: port.h:238
TimestampTz GetCurrentStatementStartTimestamp(void)
Definition: xact.c:878
bool xact_is_sampled
Definition: xact.c:295

References GetCurrentStatementStartTimestamp(), GetCurrentTimestamp(), log_duration, log_min_duration_sample, log_min_duration_statement, log_statement_sample_rate, pg_global_prng_state, pg_prng_double(), snprintf, TimestampDifference(), and xact_is_sampled.

Referenced by exec_bind_message(), exec_execute_message(), exec_parse_message(), exec_simple_query(), and HandleFunctionRequest().

◆ die()

void die ( SIGNAL_ARGS  )

Definition at line 3015 of file postgres.c.

3016 {
3017  /* Don't joggle the elbow of proc_exit */
3018  if (!proc_exit_inprogress)
3019  {
3020  InterruptPending = true;
3021  ProcDiePending = true;
3022  }
3023 
3024  /* for the cumulative stats system */
3026 
3027  /* If we're still here, waken anything waiting on the process latch */
3028  SetLatch(MyLatch);
3029 
3030  /*
3031  * If we're in single user mode, we want to quit immediately - we can't
3032  * rely on latches as they wouldn't work when stdin/stdout is a file.
3033  * Rather ugly, but it's unlikely to be worthwhile to invest much more
3034  * effort just for the benefit of single user mode.
3035  */
3038 }
@ DestRemote
Definition: dest.h:89
volatile sig_atomic_t InterruptPending
Definition: globals.c:31
struct Latch * MyLatch
Definition: globals.c:62
volatile sig_atomic_t ProcDiePending
Definition: globals.c:33
bool proc_exit_inprogress
Definition: ipc.c:40
void SetLatch(Latch *latch)
Definition: latch.c:632
@ DISCONNECT_KILLED
Definition: pgstat.h:113
SessionEndType pgStatSessionEndCause
CommandDest whereToSendOutput
Definition: postgres.c:90
static bool DoingCommandRead
Definition: postgres.c:147
void ProcessInterrupts(void)
Definition: postgres.c:3287

References DestRemote, DISCONNECT_KILLED, DoingCommandRead, InterruptPending, MyLatch, pgStatSessionEndCause, proc_exit_inprogress, ProcDiePending, ProcessInterrupts(), SetLatch(), and whereToSendOutput.

Referenced by PostgresMain().

◆ FloatExceptionHandler()

void FloatExceptionHandler ( SIGNAL_ARGS  )

Definition at line 3062 of file postgres.c.

3063 {
3064  /* We're not returning, so no need to save errno */
3065  ereport(ERROR,
3066  (errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
3067  errmsg("floating-point exception"),
3068  errdetail("An invalid floating-point operation was signaled. "
3069  "This probably means an out-of-range result or an "
3070  "invalid operation, such as division by zero.")));
3071 }
int errdetail(const char *fmt,...)
Definition: elog.c:1203
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149

References ereport, errcode(), errdetail(), errmsg(), and ERROR.

Referenced by AutoVacWorkerMain(), BackgroundWorkerMain(), plperl_init_interp(), PostgresMain(), and ReplSlotSyncWorkerMain().

◆ get_stack_depth_rlimit()

long get_stack_depth_rlimit ( void  )

Definition at line 5097 of file postgres.c.

5098 {
5099 #if defined(HAVE_GETRLIMIT)
5100  static long val = 0;
5101 
5102  /* This won't change after process launch, so check just once */
5103  if (val == 0)
5104  {
5105  struct rlimit rlim;
5106 
5107  if (getrlimit(RLIMIT_STACK, &rlim) < 0)
5108  val = -1;
5109  else if (rlim.rlim_cur == RLIM_INFINITY)
5110  val = LONG_MAX;
5111  /* rlim_cur is probably of an unsigned type, so check for overflow */
5112  else if (rlim.rlim_cur >= LONG_MAX)
5113  val = LONG_MAX;
5114  else
5115  val = rlim.rlim_cur;
5116  }
5117  return val;
5118 #else
5119  /* On Windows we set the backend stack size in src/backend/Makefile */
5120  return WIN32_STACK_RLIMIT;
5121 #endif
5122 }
long val
Definition: informix.c:689

References val.

Referenced by check_max_stack_depth(), and InitializeGUCOptionsFromEnvironment().

◆ get_stats_option_name()

const char* get_stats_option_name ( const char *  arg)

Definition at line 3853 of file postgres.c.

3854 {
3855  switch (arg[0])
3856  {
3857  case 'p':
3858  if (optarg[1] == 'a') /* "parser" */
3859  return "log_parser_stats";
3860  else if (optarg[1] == 'l') /* "planner" */
3861  return "log_planner_stats";
3862  break;
3863 
3864  case 'e': /* "executor" */
3865  return "log_executor_stats";
3866  break;
3867  }
3868 
3869  return NULL;
3870 }
void * arg
PGDLLIMPORT char * optarg
Definition: getopt.c:53

References arg, and optarg.

Referenced by PostmasterMain(), and process_postgres_switches().

◆ HandleRecoveryConflictInterrupt()

void HandleRecoveryConflictInterrupt ( ProcSignalReason  reason)

Definition at line 3078 of file postgres.c.

3079 {
3080  RecoveryConflictPendingReasons[reason] = true;
3081  RecoveryConflictPending = true;
3082  InterruptPending = true;
3083  /* latch will be set by procsignal_sigusr1_handler */
3084 }
static volatile sig_atomic_t RecoveryConflictPendingReasons[NUM_PROCSIGNALS]
Definition: postgres.c:170
static volatile sig_atomic_t RecoveryConflictPending
Definition: postgres.c:169

References InterruptPending, RecoveryConflictPending, and RecoveryConflictPendingReasons.

Referenced by procsignal_sigusr1_handler().

◆ pg_analyze_and_rewrite_fixedparams()

List* pg_analyze_and_rewrite_fixedparams ( RawStmt parsetree,
const char *  query_string,
const Oid paramTypes,
int  numParams,
QueryEnvironment queryEnv 
)

Definition at line 676 of file postgres.c.

681 {
682  Query *query;
683  List *querytree_list;
684 
685  TRACE_POSTGRESQL_QUERY_REWRITE_START(query_string);
686 
687  /*
688  * (1) Perform parse analysis.
689  */
690  if (log_parser_stats)
691  ResetUsage();
692 
693  query = parse_analyze_fixedparams(parsetree, query_string, paramTypes, numParams,
694  queryEnv);
695 
696  if (log_parser_stats)
697  ShowUsage("PARSE ANALYSIS STATISTICS");
698 
699  /*
700  * (2) Rewrite the queries, as necessary
701  */
702  querytree_list = pg_rewrite_query(query);
703 
704  TRACE_POSTGRESQL_QUERY_REWRITE_DONE(query_string);
705 
706  return querytree_list;
707 }
bool log_parser_stats
Definition: guc_tables.c:502
Query * parse_analyze_fixedparams(RawStmt *parseTree, const char *sourceText, const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv)
Definition: analyze.c:105
void ShowUsage(const char *title)
Definition: postgres.c:5136
List * pg_rewrite_query(Query *query)
Definition: postgres.c:809
void ResetUsage(void)
Definition: postgres.c:5129
Definition: pg_list.h:54

References log_parser_stats, parse_analyze_fixedparams(), pg_rewrite_query(), ResetUsage(), and ShowUsage().

Referenced by _SPI_execute_plan(), _SPI_prepare_plan(), BeginCopyTo(), exec_simple_query(), execute_sql_string(), and RevalidateCachedQuery().

◆ pg_analyze_and_rewrite_varparams()

List* pg_analyze_and_rewrite_varparams ( RawStmt parsetree,
const char *  query_string,
Oid **  paramTypes,
int *  numParams,
QueryEnvironment queryEnv 
)

Definition at line 715 of file postgres.c.

720 {
721  Query *query;
722  List *querytree_list;
723 
724  TRACE_POSTGRESQL_QUERY_REWRITE_START(query_string);
725 
726  /*
727  * (1) Perform parse analysis.
728  */
729  if (log_parser_stats)
730  ResetUsage();
731 
732  query = parse_analyze_varparams(parsetree, query_string, paramTypes, numParams,
733  queryEnv);
734 
735  /*
736  * Check all parameter types got determined.
737  */
738  for (int i = 0; i < *numParams; i++)
739  {
740  Oid ptype = (*paramTypes)[i];
741 
742  if (ptype == InvalidOid || ptype == UNKNOWNOID)
743  ereport(ERROR,
744  (errcode(ERRCODE_INDETERMINATE_DATATYPE),
745  errmsg("could not determine data type of parameter $%d",
746  i + 1)));
747  }
748 
749  if (log_parser_stats)
750  ShowUsage("PARSE ANALYSIS STATISTICS");
751 
752  /*
753  * (2) Rewrite the queries, as necessary
754  */
755  querytree_list = pg_rewrite_query(query);
756 
757  TRACE_POSTGRESQL_QUERY_REWRITE_DONE(query_string);
758 
759  return querytree_list;
760 }
int i
Definition: isn.c:72
Query * parse_analyze_varparams(RawStmt *parseTree, const char *sourceText, Oid **paramTypes, int *numParams, QueryEnvironment *queryEnv)
Definition: analyze.c:145
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31

References ereport, errcode(), errmsg(), ERROR, i, InvalidOid, log_parser_stats, parse_analyze_varparams(), pg_rewrite_query(), ResetUsage(), and ShowUsage().

Referenced by exec_parse_message(), and PrepareQuery().

◆ pg_analyze_and_rewrite_withcb()

List* pg_analyze_and_rewrite_withcb ( RawStmt parsetree,
const char *  query_string,
ParserSetupHook  parserSetup,
void *  parserSetupArg,
QueryEnvironment queryEnv 
)

Definition at line 769 of file postgres.c.

774 {
775  Query *query;
776  List *querytree_list;
777 
778  TRACE_POSTGRESQL_QUERY_REWRITE_START(query_string);
779 
780  /*
781  * (1) Perform parse analysis.
782  */
783  if (log_parser_stats)
784  ResetUsage();
785 
786  query = parse_analyze_withcb(parsetree, query_string, parserSetup, parserSetupArg,
787  queryEnv);
788 
789  if (log_parser_stats)
790  ShowUsage("PARSE ANALYSIS STATISTICS");
791 
792  /*
793  * (2) Rewrite the queries, as necessary
794  */
795  querytree_list = pg_rewrite_query(query);
796 
797  TRACE_POSTGRESQL_QUERY_REWRITE_DONE(query_string);
798 
799  return querytree_list;
800 }
Query * parse_analyze_withcb(RawStmt *parseTree, const char *sourceText, ParserSetupHook parserSetup, void *parserSetupArg, QueryEnvironment *queryEnv)
Definition: analyze.c:186

References log_parser_stats, parse_analyze_withcb(), pg_rewrite_query(), ResetUsage(), and ShowUsage().

Referenced by _SPI_execute_plan(), _SPI_prepare_plan(), fmgr_sql_validator(), init_sql_fcache(), inline_set_returning_function(), and RevalidateCachedQuery().

◆ pg_parse_query()

List* pg_parse_query ( const char *  query_string)

Definition at line 614 of file postgres.c.

615 {
616  List *raw_parsetree_list;
617 
618  TRACE_POSTGRESQL_QUERY_PARSE_START(query_string);
619 
620  if (log_parser_stats)
621  ResetUsage();
622 
623  raw_parsetree_list = raw_parser(query_string, RAW_PARSE_DEFAULT);
624 
625  if (log_parser_stats)
626  ShowUsage("PARSER STATISTICS");
627 
628 #ifdef DEBUG_NODE_TESTS_ENABLED
629 
630  /* Optional debugging check: pass raw parsetrees through copyObject() */
631  if (Debug_copy_parse_plan_trees)
632  {
633  List *new_list = copyObject(raw_parsetree_list);
634 
635  /* This checks both copyObject() and the equal() routines... */
636  if (!equal(new_list, raw_parsetree_list))
637  elog(WARNING, "copyObject() failed to produce an equal raw parse tree");
638  else
639  raw_parsetree_list = new_list;
640  }
641 
642  /*
643  * Optional debugging check: pass raw parsetrees through
644  * outfuncs/readfuncs
645  */
646  if (Debug_write_read_parse_plan_trees)
647  {
648  char *str = nodeToStringWithLocations(raw_parsetree_list);
649  List *new_list = stringToNodeWithLocations(str);
650 
651  pfree(str);
652  /* This checks both outfuncs/readfuncs and the equal() routines... */
653  if (!equal(new_list, raw_parsetree_list))
654  elog(WARNING, "outfuncs/readfuncs failed to produce an equal raw parse tree");
655  else
656  raw_parsetree_list = new_list;
657  }
658 
659 #endif /* DEBUG_NODE_TESTS_ENABLED */
660 
661  TRACE_POSTGRESQL_QUERY_PARSE_DONE(query_string);
662 
663  return raw_parsetree_list;
664 }
List * raw_parser(const char *str, RawParseMode mode)
Definition: parser.c:42
#define WARNING
Definition: elog.h:36
#define elog(elevel,...)
Definition: elog.h:225
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223
const char * str
static List * new_list(NodeTag type, int min_size)
Definition: list.c:91
void pfree(void *pointer)
Definition: mcxt.c:1521
#define copyObject(obj)
Definition: nodes.h:224
char * nodeToStringWithLocations(const void *obj)
Definition: outfuncs.c:800
@ RAW_PARSE_DEFAULT
Definition: parser.h:39

References copyObject, elog, equal(), log_parser_stats, new_list(), nodeToStringWithLocations(), pfree(), RAW_PARSE_DEFAULT, raw_parser(), ResetUsage(), ShowUsage(), str, and WARNING.

Referenced by exec_parse_message(), exec_simple_query(), execute_sql_string(), fmgr_sql_validator(), ImportForeignSchema(), init_sql_fcache(), inline_function(), and inline_set_returning_function().

◆ pg_plan_queries()

List* pg_plan_queries ( List querytrees,
const char *  query_string,
int  cursorOptions,
ParamListInfo  boundParams 
)

Definition at line 981 of file postgres.c.

983 {
984  List *stmt_list = NIL;
985  ListCell *query_list;
986 
987  foreach(query_list, querytrees)
988  {
989  Query *query = lfirst_node(Query, query_list);
990  PlannedStmt *stmt;
991 
992  if (query->commandType == CMD_UTILITY)
993  {
994  /* Utility commands require no planning. */
996  stmt->commandType = CMD_UTILITY;
997  stmt->canSetTag = query->canSetTag;
998  stmt->utilityStmt = query->utilityStmt;
999  stmt->stmt_location = query->stmt_location;
1000  stmt->stmt_len = query->stmt_len;
1001  stmt->queryId = query->queryId;
1002  }
1003  else
1004  {
1005  stmt = pg_plan_query(query, query_string, cursorOptions,
1006  boundParams);
1007  }
1008 
1009  stmt_list = lappend(stmt_list, stmt);
1010  }
1011 
1012  return stmt_list;
1013 }
#define stmt
Definition: indent_codes.h:59
List * lappend(List *list, void *datum)
Definition: list.c:339
@ CMD_UTILITY
Definition: nodes.h:270
#define makeNode(_type_)
Definition: nodes.h:155
#define lfirst_node(type, lc)
Definition: pg_list.h:176
#define NIL
Definition: pg_list.h:68
PlannedStmt * pg_plan_query(Query *querytree, const char *query_string, int cursorOptions, ParamListInfo boundParams)
Definition: postgres.c:893
CmdType commandType
Definition: parsenodes.h:121
Node * utilityStmt
Definition: parsenodes.h:136
ParseLoc stmt_location
Definition: parsenodes.h:240

References CMD_UTILITY, Query::commandType, lappend(), lfirst_node, makeNode, NIL, pg_plan_query(), stmt, Query::stmt_location, and Query::utilityStmt.

Referenced by BuildCachedPlan(), exec_simple_query(), and execute_sql_string().

◆ pg_plan_query()

PlannedStmt* pg_plan_query ( Query querytree,
const char *  query_string,
int  cursorOptions,
ParamListInfo  boundParams 
)

Definition at line 893 of file postgres.c.

895 {
896  PlannedStmt *plan;
897 
898  /* Utility commands have no plans. */
899  if (querytree->commandType == CMD_UTILITY)
900  return NULL;
901 
902  /* Planner must have a snapshot in case it calls user-defined functions. */
904 
905  TRACE_POSTGRESQL_QUERY_PLAN_START();
906 
907  if (log_planner_stats)
908  ResetUsage();
909 
910  /* call the optimizer */
911  plan = planner(querytree, query_string, cursorOptions, boundParams);
912 
913  if (log_planner_stats)
914  ShowUsage("PLANNER STATISTICS");
915 
916 #ifdef DEBUG_NODE_TESTS_ENABLED
917 
918  /* Optional debugging check: pass plan tree through copyObject() */
919  if (Debug_copy_parse_plan_trees)
920  {
921  PlannedStmt *new_plan = copyObject(plan);
922 
923  /*
924  * equal() currently does not have routines to compare Plan nodes, so
925  * don't try to test equality here. Perhaps fix someday?
926  */
927 #ifdef NOT_USED
928  /* This checks both copyObject() and the equal() routines... */
929  if (!equal(new_plan, plan))
930  elog(WARNING, "copyObject() failed to produce an equal plan tree");
931  else
932 #endif
933  plan = new_plan;
934  }
935 
936  /* Optional debugging check: pass plan tree through outfuncs/readfuncs */
937  if (Debug_write_read_parse_plan_trees)
938  {
939  char *str;
940  PlannedStmt *new_plan;
941 
943  new_plan = stringToNodeWithLocations(str);
944  pfree(str);
945 
946  /*
947  * equal() currently does not have routines to compare Plan nodes, so
948  * don't try to test equality here. Perhaps fix someday?
949  */
950 #ifdef NOT_USED
951  /* This checks both outfuncs/readfuncs and the equal() routines... */
952  if (!equal(new_plan, plan))
953  elog(WARNING, "outfuncs/readfuncs failed to produce an equal plan tree");
954  else
955 #endif
956  plan = new_plan;
957  }
958 
959 #endif /* DEBUG_NODE_TESTS_ENABLED */
960 
961  /*
962  * Print plan if debugging.
963  */
964  if (Debug_print_plan)
966 
967  TRACE_POSTGRESQL_QUERY_PLAN_DONE();
968 
969  return plan;
970 }
Datum querytree(PG_FUNCTION_ARGS)
Definition: _int_bool.c:665
void elog_node_display(int lev, const char *title, const void *obj, bool pretty)
Definition: print.c:72
#define Assert(condition)
Definition: c.h:837
#define LOG
Definition: elog.h:31
bool Debug_print_plan
Definition: guc_tables.c:491
bool Debug_pretty_print
Definition: guc_tables.c:494
bool log_planner_stats
Definition: guc_tables.c:503
#define plan(x)
Definition: pg_regress.c:161
PlannedStmt * planner(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
Definition: planner.c:286
bool ActiveSnapshotSet(void)
Definition: snapmgr.c:782

References ActiveSnapshotSet(), Assert, CMD_UTILITY, copyObject, Debug_pretty_print, Debug_print_plan, elog, elog_node_display(), equal(), LOG, log_planner_stats, nodeToStringWithLocations(), pfree(), plan, planner(), querytree(), ResetUsage(), ShowUsage(), str, and WARNING.

Referenced by BeginCopyTo(), ExecCreateTableAs(), init_execution_state(), PerformCursorOpen(), pg_plan_queries(), refresh_matview_datafill(), and standard_ExplainOneQuery().

◆ pg_rewrite_query()

List* pg_rewrite_query ( Query query)

Definition at line 809 of file postgres.c.

810 {
811  List *querytree_list;
812 
813  if (Debug_print_parse)
814  elog_node_display(LOG, "parse tree", query,
816 
817  if (log_parser_stats)
818  ResetUsage();
819 
820  if (query->commandType == CMD_UTILITY)
821  {
822  /* don't rewrite utilities, just dump 'em into result list */
823  querytree_list = list_make1(query);
824  }
825  else
826  {
827  /* rewrite regular queries */
828  querytree_list = QueryRewrite(query);
829  }
830 
831  if (log_parser_stats)
832  ShowUsage("REWRITER STATISTICS");
833 
834 #ifdef DEBUG_NODE_TESTS_ENABLED
835 
836  /* Optional debugging check: pass querytree through copyObject() */
837  if (Debug_copy_parse_plan_trees)
838  {
839  List *new_list;
840 
841  new_list = copyObject(querytree_list);
842  /* This checks both copyObject() and the equal() routines... */
843  if (!equal(new_list, querytree_list))
844  elog(WARNING, "copyObject() failed to produce an equal rewritten parse tree");
845  else
846  querytree_list = new_list;
847  }
848 
849  /* Optional debugging check: pass querytree through outfuncs/readfuncs */
850  if (Debug_write_read_parse_plan_trees)
851  {
852  List *new_list = NIL;
853  ListCell *lc;
854 
855  foreach(lc, querytree_list)
856  {
857  Query *curr_query = lfirst_node(Query, lc);
858  char *str = nodeToStringWithLocations(curr_query);
859  Query *new_query = stringToNodeWithLocations(str);
860 
861  /*
862  * queryId is not saved in stored rules, but we must preserve it
863  * here to avoid breaking pg_stat_statements.
864  */
865  new_query->queryId = curr_query->queryId;
866 
867  new_list = lappend(new_list, new_query);
868  pfree(str);
869  }
870 
871  /* This checks both outfuncs/readfuncs and the equal() routines... */
872  if (!equal(new_list, querytree_list))
873  elog(WARNING, "outfuncs/readfuncs failed to produce an equal rewritten parse tree");
874  else
875  querytree_list = new_list;
876  }
877 
878 #endif /* DEBUG_NODE_TESTS_ENABLED */
879 
881  elog_node_display(LOG, "rewritten parse tree", querytree_list,
883 
884  return querytree_list;
885 }
bool Debug_print_rewritten
Definition: guc_tables.c:493
bool Debug_print_parse
Definition: guc_tables.c:492
#define list_make1(x1)
Definition: pg_list.h:212
List * QueryRewrite(Query *parsetree)

References CMD_UTILITY, Query::commandType, copyObject, Debug_pretty_print, Debug_print_parse, Debug_print_rewritten, elog, elog_node_display(), equal(), lappend(), lfirst_node, list_make1, LOG, log_parser_stats, new_list(), NIL, nodeToStringWithLocations(), pfree(), QueryRewrite(), ResetUsage(), ShowUsage(), str, and WARNING.

Referenced by fmgr_sql_validator(), init_sql_fcache(), inline_set_returning_function(), pg_analyze_and_rewrite_fixedparams(), pg_analyze_and_rewrite_varparams(), and pg_analyze_and_rewrite_withcb().

◆ PostgresMain()

void PostgresMain ( const char *  dbname,
const char *  username 
)

Definition at line 4264 of file postgres.c.

4265 {
4266  sigjmp_buf local_sigjmp_buf;
4267 
4268  /* these must be volatile to ensure state is preserved across longjmp: */
4269  volatile bool send_ready_for_query = true;
4270  volatile bool idle_in_transaction_timeout_enabled = false;
4271  volatile bool idle_session_timeout_enabled = false;
4272 
4273  Assert(dbname != NULL);
4274  Assert(username != NULL);
4275 
4277 
4278  /*
4279  * Set up signal handlers. (InitPostmasterChild or InitStandaloneProcess
4280  * has already set up BlockSig and made that the active signal mask.)
4281  *
4282  * Note that postmaster blocked all signals before forking child process,
4283  * so there is no race condition whereby we might receive a signal before
4284  * we have set up the handler.
4285  *
4286  * Also note: it's best not to use any signals that are SIG_IGNored in the
4287  * postmaster. If such a signal arrives before we are able to change the
4288  * handler to non-SIG_IGN, it'll get dropped. Instead, make a dummy
4289  * handler in the postmaster to reserve the signal. (Of course, this isn't
4290  * an issue for signals that are locally generated, such as SIGALRM and
4291  * SIGPIPE.)
4292  */
4293  if (am_walsender)
4294  WalSndSignals();
4295  else
4296  {
4298  pqsignal(SIGINT, StatementCancelHandler); /* cancel current query */
4299  pqsignal(SIGTERM, die); /* cancel current query and exit */
4300 
4301  /*
4302  * In a postmaster child backend, replace SignalHandlerForCrashExit
4303  * with quickdie, so we can tell the client we're dying.
4304  *
4305  * In a standalone backend, SIGQUIT can be generated from the keyboard
4306  * easily, while SIGTERM cannot, so we make both signals do die()
4307  * rather than quickdie().
4308  */
4309  if (IsUnderPostmaster)
4310  pqsignal(SIGQUIT, quickdie); /* hard crash time */
4311  else
4312  pqsignal(SIGQUIT, die); /* cancel current query and exit */
4313  InitializeTimeouts(); /* establishes SIGALRM handler */
4314 
4315  /*
4316  * Ignore failure to write to frontend. Note: if frontend closes
4317  * connection, we will notice it and exit cleanly when control next
4318  * returns to outer loop. This seems safer than forcing exit in the
4319  * midst of output during who-knows-what operation...
4320  */
4325 
4326  /*
4327  * Reset some signals that are accepted by postmaster but not by
4328  * backend
4329  */
4330  pqsignal(SIGCHLD, SIG_DFL); /* system() requires this on some
4331  * platforms */
4332  }
4333 
4334  /* Early initialization */
4335  BaseInit();
4336 
4337  /* We need to allow SIGINT, etc during the initial transaction */
4338  sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
4339 
4340  /*
4341  * Generate a random cancel key, if this is a backend serving a
4342  * connection. InitPostgres() will advertise it in shared memory.
4343  */
4346  {
4347  if (!pg_strong_random(&MyCancelKey, sizeof(int32)))
4348  {
4349  ereport(ERROR,
4350  (errcode(ERRCODE_INTERNAL_ERROR),
4351  errmsg("could not generate random cancel key")));
4352  }
4353  MyCancelKeyValid = true;
4354  }
4355 
4356  /*
4357  * General initialization.
4358  *
4359  * NOTE: if you are tempted to add code in this vicinity, consider putting
4360  * it inside InitPostgres() instead. In particular, anything that
4361  * involves database access should be there, not here.
4362  *
4363  * Honor session_preload_libraries if not dealing with a WAL sender.
4364  */
4365  InitPostgres(dbname, InvalidOid, /* database to connect to */
4366  username, InvalidOid, /* role to connect as */
4368  NULL); /* no out_dbname */
4369 
4370  /*
4371  * If the PostmasterContext is still around, recycle the space; we don't
4372  * need it anymore after InitPostgres completes.
4373  */
4374  if (PostmasterContext)
4375  {
4377  PostmasterContext = NULL;
4378  }
4379 
4381 
4382  /*
4383  * Now all GUC states are fully set up. Report them to client if
4384  * appropriate.
4385  */
4387 
4388  /*
4389  * Also set up handler to log session end; we have to wait till now to be
4390  * sure Log_disconnections has its final value.
4391  */
4394 
4396 
4397  /* Perform initialization specific to a WAL sender process. */
4398  if (am_walsender)
4399  InitWalSender();
4400 
4401  /*
4402  * Send this backend's cancellation info to the frontend.
4403  */
4405  {
4407 
4412  pq_endmessage(&buf);
4413  /* Need not flush since ReadyForQuery will do it. */
4414  }
4415 
4416  /* Welcome banner for standalone case */
4418  printf("\nPostgreSQL stand-alone backend %s\n", PG_VERSION);
4419 
4420  /*
4421  * Create the memory context we will use in the main loop.
4422  *
4423  * MessageContext is reset once per iteration of the main loop, ie, upon
4424  * completion of processing of each command message from the client.
4425  */
4427  "MessageContext",
4429 
4430  /*
4431  * Create memory context and buffer used for RowDescription messages. As
4432  * SendRowDescriptionMessage(), via exec_describe_statement_message(), is
4433  * frequently executed for ever single statement, we don't want to
4434  * allocate a separate buffer every time.
4435  */
4437  "RowDescriptionContext",
4442 
4443  /* Fire any defined login event triggers, if appropriate */
4445 
4446  /*
4447  * POSTGRES main processing loop begins here
4448  *
4449  * If an exception is encountered, processing resumes here so we abort the
4450  * current transaction and start a new one.
4451  *
4452  * You might wonder why this isn't coded as an infinite loop around a
4453  * PG_TRY construct. The reason is that this is the bottom of the
4454  * exception stack, and so with PG_TRY there would be no exception handler
4455  * in force at all during the CATCH part. By leaving the outermost setjmp
4456  * always active, we have at least some chance of recovering from an error
4457  * during error recovery. (If we get into an infinite loop thereby, it
4458  * will soon be stopped by overflow of elog.c's internal state stack.)
4459  *
4460  * Note that we use sigsetjmp(..., 1), so that this function's signal mask
4461  * (to wit, UnBlockSig) will be restored when longjmp'ing to here. This
4462  * is essential in case we longjmp'd out of a signal handler on a platform
4463  * where that leaves the signal blocked. It's not redundant with the
4464  * unblock in AbortTransaction() because the latter is only called if we
4465  * were inside a transaction.
4466  */
4467 
4468  if (sigsetjmp(local_sigjmp_buf, 1) != 0)
4469  {
4470  /*
4471  * NOTE: if you are tempted to add more code in this if-block,
4472  * consider the high probability that it should be in
4473  * AbortTransaction() instead. The only stuff done directly here
4474  * should be stuff that is guaranteed to apply *only* for outer-level
4475  * error recovery, such as adjusting the FE/BE protocol status.
4476  */
4477 
4478  /* Since not using PG_TRY, must reset error stack by hand */
4479  error_context_stack = NULL;
4480 
4481  /* Prevent interrupts while cleaning up */
4482  HOLD_INTERRUPTS();
4483 
4484  /*
4485  * Forget any pending QueryCancel request, since we're returning to
4486  * the idle loop anyway, and cancel any active timeout requests. (In
4487  * future we might want to allow some timeout requests to survive, but
4488  * at minimum it'd be necessary to do reschedule_timeouts(), in case
4489  * we got here because of a query cancel interrupting the SIGALRM
4490  * interrupt handler.) Note in particular that we must clear the
4491  * statement and lock timeout indicators, to prevent any future plain
4492  * query cancels from being misreported as timeouts in case we're
4493  * forgetting a timeout cancel.
4494  */
4495  disable_all_timeouts(false); /* do first to avoid race condition */
4496  QueryCancelPending = false;
4497  idle_in_transaction_timeout_enabled = false;
4498  idle_session_timeout_enabled = false;
4499 
4500  /* Not reading from the client anymore. */
4501  DoingCommandRead = false;
4502 
4503  /* Make sure libpq is in a good state */
4504  pq_comm_reset();
4505 
4506  /* Report the error to the client and/or server log */
4507  EmitErrorReport();
4508 
4509  /*
4510  * If Valgrind noticed something during the erroneous query, print the
4511  * query string, assuming we have one.
4512  */
4514 
4515  /*
4516  * Make sure debug_query_string gets reset before we possibly clobber
4517  * the storage it points at.
4518  */
4519  debug_query_string = NULL;
4520 
4521  /*
4522  * Abort the current transaction in order to recover.
4523  */
4525 
4526  if (am_walsender)
4528 
4530 
4531  /*
4532  * We can't release replication slots inside AbortTransaction() as we
4533  * need to be able to start and abort transactions while having a slot
4534  * acquired. But we never need to hold them across top level errors,
4535  * so releasing here is fine. There also is a before_shmem_exit()
4536  * callback ensuring correct cleanup on FATAL errors.
4537  */
4538  if (MyReplicationSlot != NULL)
4540 
4541  /* We also want to cleanup temporary slots on error. */
4542  ReplicationSlotCleanup(false);
4543 
4545 
4546  /*
4547  * Now return to normal top-level context and clear ErrorContext for
4548  * next time.
4549  */
4551  FlushErrorState();
4552 
4553  /*
4554  * If we were handling an extended-query-protocol message, initiate
4555  * skip till next Sync. This also causes us not to issue
4556  * ReadyForQuery (until we get Sync).
4557  */
4559  ignore_till_sync = true;
4560 
4561  /* We don't have a transaction command open anymore */
4562  xact_started = false;
4563 
4564  /*
4565  * If an error occurred while we were reading a message from the
4566  * client, we have potentially lost track of where the previous
4567  * message ends and the next one begins. Even though we have
4568  * otherwise recovered from the error, we cannot safely read any more
4569  * messages from the client, so there isn't much we can do with the
4570  * connection anymore.
4571  */
4572  if (pq_is_reading_msg())
4573  ereport(FATAL,
4574  (errcode(ERRCODE_PROTOCOL_VIOLATION),
4575  errmsg("terminating connection because protocol synchronization was lost")));
4576 
4577  /* Now we can allow interrupts again */
4579  }
4580 
4581  /* We can now handle ereport(ERROR) */
4582  PG_exception_stack = &local_sigjmp_buf;
4583 
4584  if (!ignore_till_sync)
4585  send_ready_for_query = true; /* initially, or after error */
4586 
4587  /*
4588  * Non-error queries loop here.
4589  */
4590 
4591  for (;;)
4592  {
4593  int firstchar;
4594  StringInfoData input_message;
4595 
4596  /*
4597  * At top of loop, reset extended-query-message flag, so that any
4598  * errors encountered in "idle" state don't provoke skip.
4599  */
4601 
4602  /*
4603  * For valgrind reporting purposes, the "current query" begins here.
4604  */
4605 #ifdef USE_VALGRIND
4606  old_valgrind_error_count = VALGRIND_COUNT_ERRORS;
4607 #endif
4608 
4609  /*
4610  * Release storage left over from prior query cycle, and create a new
4611  * query input buffer in the cleared MessageContext.
4612  */
4615 
4616  initStringInfo(&input_message);
4617 
4618  /*
4619  * Also consider releasing our catalog snapshot if any, so that it's
4620  * not preventing advance of global xmin while we wait for the client.
4621  */
4623 
4624  /*
4625  * (1) If we've reached idle state, tell the frontend we're ready for
4626  * a new query.
4627  *
4628  * Note: this includes fflush()'ing the last of the prior output.
4629  *
4630  * This is also a good time to flush out collected statistics to the
4631  * cumulative stats system, and to update the PS stats display. We
4632  * avoid doing those every time through the message loop because it'd
4633  * slow down processing of batched messages, and because we don't want
4634  * to report uncommitted updates (that confuses autovacuum). The
4635  * notification processor wants a call too, if we are not in a
4636  * transaction block.
4637  *
4638  * Also, if an idle timeout is enabled, start the timer for that.
4639  */
4640  if (send_ready_for_query)
4641  {
4643  {
4644  set_ps_display("idle in transaction (aborted)");
4646 
4647  /* Start the idle-in-transaction timer */
4650  {
4651  idle_in_transaction_timeout_enabled = true;
4654  }
4655  }
4657  {
4658  set_ps_display("idle in transaction");
4660 
4661  /* Start the idle-in-transaction timer */
4664  {
4665  idle_in_transaction_timeout_enabled = true;
4668  }
4669  }
4670  else
4671  {
4672  long stats_timeout;
4673 
4674  /*
4675  * Process incoming notifies (including self-notifies), if
4676  * any, and send relevant messages to the client. Doing it
4677  * here helps ensure stable behavior in tests: if any notifies
4678  * were received during the just-finished transaction, they'll
4679  * be seen by the client before ReadyForQuery is.
4680  */
4682  ProcessNotifyInterrupt(false);
4683 
4684  /*
4685  * Check if we need to report stats. If pgstat_report_stat()
4686  * decides it's too soon to flush out pending stats / lock
4687  * contention prevented reporting, it'll tell us when we
4688  * should try to report stats again (so that stats updates
4689  * aren't unduly delayed if the connection goes idle for a
4690  * long time). We only enable the timeout if we don't already
4691  * have a timeout in progress, because we don't disable the
4692  * timeout below. enable_timeout_after() needs to determine
4693  * the current timestamp, which can have a negative
4694  * performance impact. That's OK because pgstat_report_stat()
4695  * won't have us wake up sooner than a prior call.
4696  */
4697  stats_timeout = pgstat_report_stat(false);
4698  if (stats_timeout > 0)
4699  {
4702  stats_timeout);
4703  }
4704  else
4705  {
4706  /* all stats flushed, no need for the timeout */
4709  }
4710 
4711  set_ps_display("idle");
4713 
4714  /* Start the idle-session timer */
4715  if (IdleSessionTimeout > 0)
4716  {
4717  idle_session_timeout_enabled = true;
4720  }
4721  }
4722 
4723  /* Report any recently-changed GUC options */
4725 
4727  send_ready_for_query = false;
4728  }
4729 
4730  /*
4731  * (2) Allow asynchronous signals to be executed immediately if they
4732  * come in while we are waiting for client input. (This must be
4733  * conditional since we don't want, say, reads on behalf of COPY FROM
4734  * STDIN doing the same thing.)
4735  */
4736  DoingCommandRead = true;
4737 
4738  /*
4739  * (3) read a command (loop blocks here)
4740  */
4741  firstchar = ReadCommand(&input_message);
4742 
4743  /*
4744  * (4) turn off the idle-in-transaction and idle-session timeouts if
4745  * active. We do this before step (5) so that any last-moment timeout
4746  * is certain to be detected in step (5).
4747  *
4748  * At most one of these timeouts will be active, so there's no need to
4749  * worry about combining the timeout.c calls into one.
4750  */
4751  if (idle_in_transaction_timeout_enabled)
4752  {
4754  idle_in_transaction_timeout_enabled = false;
4755  }
4756  if (idle_session_timeout_enabled)
4757  {
4759  idle_session_timeout_enabled = false;
4760  }
4761 
4762  /*
4763  * (5) disable async signal conditions again.
4764  *
4765  * Query cancel is supposed to be a no-op when there is no query in
4766  * progress, so if a query cancel arrived while we were idle, just
4767  * reset QueryCancelPending. ProcessInterrupts() has that effect when
4768  * it's called when DoingCommandRead is set, so check for interrupts
4769  * before resetting DoingCommandRead.
4770  */
4772  DoingCommandRead = false;
4773 
4774  /*
4775  * (6) check for any other interesting events that happened while we
4776  * slept.
4777  */
4778  if (ConfigReloadPending)
4779  {
4780  ConfigReloadPending = false;
4782  }
4783 
4784  /*
4785  * (7) process the command. But ignore it if we're skipping till
4786  * Sync.
4787  */
4788  if (ignore_till_sync && firstchar != EOF)
4789  continue;
4790 
4791  switch (firstchar)
4792  {
4793  case PqMsg_Query:
4794  {
4795  const char *query_string;
4796 
4797  /* Set statement_timestamp() */
4799 
4800  query_string = pq_getmsgstring(&input_message);
4801  pq_getmsgend(&input_message);
4802 
4803  if (am_walsender)
4804  {
4805  if (!exec_replication_command(query_string))
4806  exec_simple_query(query_string);
4807  }
4808  else
4809  exec_simple_query(query_string);
4810 
4811  valgrind_report_error_query(query_string);
4812 
4813  send_ready_for_query = true;
4814  }
4815  break;
4816 
4817  case PqMsg_Parse:
4818  {
4819  const char *stmt_name;
4820  const char *query_string;
4821  int numParams;
4822  Oid *paramTypes = NULL;
4823 
4824  forbidden_in_wal_sender(firstchar);
4825 
4826  /* Set statement_timestamp() */
4828 
4829  stmt_name = pq_getmsgstring(&input_message);
4830  query_string = pq_getmsgstring(&input_message);
4831  numParams = pq_getmsgint(&input_message, 2);
4832  if (numParams > 0)
4833  {
4834  paramTypes = palloc_array(Oid, numParams);
4835  for (int i = 0; i < numParams; i++)
4836  paramTypes[i] = pq_getmsgint(&input_message, 4);
4837  }
4838  pq_getmsgend(&input_message);
4839 
4840  exec_parse_message(query_string, stmt_name,
4841  paramTypes, numParams);
4842 
4843  valgrind_report_error_query(query_string);
4844  }
4845  break;
4846 
4847  case PqMsg_Bind:
4848  forbidden_in_wal_sender(firstchar);
4849 
4850  /* Set statement_timestamp() */
4852 
4853  /*
4854  * this message is complex enough that it seems best to put
4855  * the field extraction out-of-line
4856  */
4857  exec_bind_message(&input_message);
4858 
4859  /* exec_bind_message does valgrind_report_error_query */
4860  break;
4861 
4862  case PqMsg_Execute:
4863  {
4864  const char *portal_name;
4865  int max_rows;
4866 
4867  forbidden_in_wal_sender(firstchar);
4868 
4869  /* Set statement_timestamp() */
4871 
4872  portal_name = pq_getmsgstring(&input_message);
4873  max_rows = pq_getmsgint(&input_message, 4);
4874  pq_getmsgend(&input_message);
4875 
4876  exec_execute_message(portal_name, max_rows);
4877 
4878  /* exec_execute_message does valgrind_report_error_query */
4879  }
4880  break;
4881 
4882  case PqMsg_FunctionCall:
4883  forbidden_in_wal_sender(firstchar);
4884 
4885  /* Set statement_timestamp() */
4887 
4888  /* Report query to various monitoring facilities. */
4890  set_ps_display("<FASTPATH>");
4891 
4892  /* start an xact for this function invocation */
4894 
4895  /*
4896  * Note: we may at this point be inside an aborted
4897  * transaction. We can't throw error for that until we've
4898  * finished reading the function-call message, so
4899  * HandleFunctionRequest() must check for it after doing so.
4900  * Be careful not to do anything that assumes we're inside a
4901  * valid transaction here.
4902  */
4903 
4904  /* switch back to message context */
4906 
4907  HandleFunctionRequest(&input_message);
4908 
4909  /* commit the function-invocation transaction */
4911 
4912  valgrind_report_error_query("fastpath function call");
4913 
4914  send_ready_for_query = true;
4915  break;
4916 
4917  case PqMsg_Close:
4918  {
4919  int close_type;
4920  const char *close_target;
4921 
4922  forbidden_in_wal_sender(firstchar);
4923 
4924  close_type = pq_getmsgbyte(&input_message);
4925  close_target = pq_getmsgstring(&input_message);
4926  pq_getmsgend(&input_message);
4927 
4928  switch (close_type)
4929  {
4930  case 'S':
4931  if (close_target[0] != '\0')
4932  DropPreparedStatement(close_target, false);
4933  else
4934  {
4935  /* special-case the unnamed statement */
4937  }
4938  break;
4939  case 'P':
4940  {
4941  Portal portal;
4942 
4943  portal = GetPortalByName(close_target);
4944  if (PortalIsValid(portal))
4945  PortalDrop(portal, false);
4946  }
4947  break;
4948  default:
4949  ereport(ERROR,
4950  (errcode(ERRCODE_PROTOCOL_VIOLATION),
4951  errmsg("invalid CLOSE message subtype %d",
4952  close_type)));
4953  break;
4954  }
4955 
4958 
4959  valgrind_report_error_query("CLOSE message");
4960  }
4961  break;
4962 
4963  case PqMsg_Describe:
4964  {
4965  int describe_type;
4966  const char *describe_target;
4967 
4968  forbidden_in_wal_sender(firstchar);
4969 
4970  /* Set statement_timestamp() (needed for xact) */
4972 
4973  describe_type = pq_getmsgbyte(&input_message);
4974  describe_target = pq_getmsgstring(&input_message);
4975  pq_getmsgend(&input_message);
4976 
4977  switch (describe_type)
4978  {
4979  case 'S':
4980  exec_describe_statement_message(describe_target);
4981  break;
4982  case 'P':
4983  exec_describe_portal_message(describe_target);
4984  break;
4985  default:
4986  ereport(ERROR,
4987  (errcode(ERRCODE_PROTOCOL_VIOLATION),
4988  errmsg("invalid DESCRIBE message subtype %d",
4989  describe_type)));
4990  break;
4991  }
4992 
4993  valgrind_report_error_query("DESCRIBE message");
4994  }
4995  break;
4996 
4997  case PqMsg_Flush:
4998  pq_getmsgend(&input_message);
5000  pq_flush();
5001  break;
5002 
5003  case PqMsg_Sync:
5004  pq_getmsgend(&input_message);
5005 
5006  /*
5007  * If pipelining was used, we may be in an implicit
5008  * transaction block. Close it before calling
5009  * finish_xact_command.
5010  */
5013  valgrind_report_error_query("SYNC message");
5014  send_ready_for_query = true;
5015  break;
5016 
5017  /*
5018  * 'X' means that the frontend is closing down the socket. EOF
5019  * means unexpected loss of frontend connection. Either way,
5020  * perform normal shutdown.
5021  */
5022  case EOF:
5023 
5024  /* for the cumulative statistics system */
5026 
5027  /* FALLTHROUGH */
5028 
5029  case PqMsg_Terminate:
5030 
5031  /*
5032  * Reset whereToSendOutput to prevent ereport from attempting
5033  * to send any more messages to client.
5034  */
5037 
5038  /*
5039  * NOTE: if you are tempted to add more code here, DON'T!
5040  * Whatever you had in mind to do should be set up as an
5041  * on_proc_exit or on_shmem_exit callback, instead. Otherwise
5042  * it will fail to be called during other backend-shutdown
5043  * scenarios.
5044  */
5045  proc_exit(0);
5046 
5047  case PqMsg_CopyData:
5048  case PqMsg_CopyDone:
5049  case PqMsg_CopyFail:
5050 
5051  /*
5052  * Accept but ignore these messages, per protocol spec; we
5053  * probably got here because a COPY failed, and the frontend
5054  * is still sending data.
5055  */
5056  break;
5057 
5058  default:
5059  ereport(FATAL,
5060  (errcode(ERRCODE_PROTOCOL_VIOLATION),
5061  errmsg("invalid frontend message type %d",
5062  firstchar)));
5063  }
5064  } /* end of input-reading loop */
5065 }
void ProcessNotifyInterrupt(bool flush)
Definition: async.c:1834
volatile sig_atomic_t notifyInterruptPending
Definition: async.c:413
void DropPreparedStatement(const char *stmt_name, bool showError)
Definition: prepare.c:516
sigset_t UnBlockSig
Definition: pqsignal.c:22
void pgstat_report_activity(BackendState state, const char *cmd_str)
@ STATE_IDLEINTRANSACTION_ABORTED
@ STATE_IDLE
@ STATE_IDLEINTRANSACTION
@ STATE_FASTPATH
signed int int32
Definition: c.h:482
void ReadyForQuery(CommandDest dest)
Definition: dest.c:256
@ DestDebug
Definition: dest.h:88
@ DestNone
Definition: dest.h:87
void EmitErrorReport(void)
Definition: elog.c:1687
ErrorContextCallback * error_context_stack
Definition: elog.c:94
void FlushErrorState(void)
Definition: elog.c:1867
sigjmp_buf * PG_exception_stack
Definition: elog.c:96
#define FATAL
Definition: elog.h:41
void EventTriggerOnLogin(void)
void HandleFunctionRequest(StringInfo msgBuf)
Definition: fastpath.c:188
#define palloc_array(type, count)
Definition: fe_memutils.h:76
int32 MyCancelKey
Definition: globals.c:52
int MyProcPid
Definition: globals.c:46
bool IsUnderPostmaster
Definition: globals.c:119
volatile sig_atomic_t QueryCancelPending
Definition: globals.c:32
bool MyCancelKeyValid
Definition: globals.c:51
Oid MyDatabaseId
Definition: globals.c:93
void BeginReportingGUCOptions(void)
Definition: guc.c:2546
void ReportChangedGUCOptions(void)
Definition: guc.c:2596
@ PGC_SIGHUP
Definition: guc.h:71
void ProcessConfigFile(GucContext context)
static char * username
Definition: initdb.c:153
volatile sig_atomic_t ConfigReloadPending
Definition: interrupt.c:27
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition: interrupt.c:61
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:309
void proc_exit(int code)
Definition: ipc.c:104
void jit_reset_after_error(void)
Definition: jit.c:127
#define pq_flush()
Definition: libpq.h:46
#define pq_comm_reset()
Definition: libpq.h:45
MemoryContext MessageContext
Definition: mcxt.c:153
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:383
MemoryContext TopMemoryContext
Definition: mcxt.c:149
MemoryContext PostmasterContext
Definition: mcxt.c:151
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
#define RESUME_INTERRUPTS()
Definition: miscadmin.h:135
@ NormalProcessing
Definition: miscadmin.h:449
@ InitProcessing
Definition: miscadmin.h:448
#define GetProcessingMode()
Definition: miscadmin.h:458
#define INIT_PG_LOAD_SESSION_LIBS
Definition: miscadmin.h:476
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:133
#define SetProcessingMode(mode)
Definition: miscadmin.h:460
static char * buf
Definition: pg_test_fsync.c:72
long pgstat_report_stat(bool force)
Definition: pgstat.c:671
@ DISCONNECT_CLIENT_EOF
Definition: pgstat.h:111
void pgstat_report_connect(Oid dboid)
bool pg_strong_random(void *buf, size_t len)
pqsigfunc pqsignal(int signo, pqsigfunc func)
#define printf(...)
Definition: port.h:244
#define PortalIsValid(p)
Definition: portal.h:212
void PortalDrop(Portal portal, bool isTopCommit)
Definition: portalmem.c:468
Portal GetPortalByName(const char *name)
Definition: portalmem.c:130
void PortalErrorCleanup(void)
Definition: portalmem.c:917
static void exec_describe_statement_message(const char *stmt_name)
Definition: postgres.c:2630
void quickdie(SIGNAL_ARGS)
Definition: postgres.c:2918
static void log_disconnections(int code, Datum arg)
Definition: postgres.c:5245
static void forbidden_in_wal_sender(char firstchar)
Definition: postgres.c:5075
static void exec_execute_message(const char *portal_name, long max_rows)
Definition: postgres.c:2106
void FloatExceptionHandler(SIGNAL_ARGS)
Definition: postgres.c:3062
void StatementCancelHandler(SIGNAL_ARGS)
Definition: postgres.c:3045
static bool ignore_till_sync
Definition: postgres.c:154
static void finish_xact_command(void)
Definition: postgres.c:2814
const char * debug_query_string
Definition: postgres.c:87
static void exec_simple_query(const char *query_string)
Definition: postgres.c:1022
static void exec_parse_message(const char *query_string, const char *stmt_name, Oid *paramTypes, int numParams)
Definition: postgres.c:1400
static void exec_bind_message(StringInfo input_message)
Definition: postgres.c:1635
void die(SIGNAL_ARGS)
Definition: postgres.c:3015
static bool xact_started
Definition: postgres.c:140
static MemoryContext row_description_context
Definition: postgres.c:173
static StringInfoData row_description_buf
Definition: postgres.c:174
static bool doing_extended_query_message
Definition: postgres.c:153
static void start_xact_command(void)
Definition: postgres.c:2775
static void exec_describe_portal_message(const char *portal_name)
Definition: postgres.c:2723
bool Log_disconnections
Definition: postgres.c:93
static void drop_unnamed_stmt(void)
Definition: postgres.c:2893
#define valgrind_report_error_query(query)
Definition: postgres.c:227
static int ReadCommand(StringInfo inBuf)
Definition: postgres.c:491
void BaseInit(void)
Definition: postinit.c:604
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bits32 flags, char *out_dbname)
Definition: postinit.c:698
bool pq_is_reading_msg(void)
Definition: pqcomm.c:1181
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:415
const char * pq_getmsgstring(StringInfo msg)
Definition: pqformat.c:579
void pq_getmsgend(StringInfo msg)
Definition: pqformat.c:635
void pq_putemptymessage(char msgtype)
Definition: pqformat.c:388
void pq_endmessage(StringInfo buf)
Definition: pqformat.c:296
int pq_getmsgbyte(StringInfo msg)
Definition: pqformat.c:399
void pq_beginmessage(StringInfo buf, char msgtype)
Definition: pqformat.c:88
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:144
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:671
#define PqMsg_CloseComplete
Definition: protocol.h:40
#define PqMsg_CopyDone
Definition: protocol.h:64
#define PqMsg_CopyData
Definition: protocol.h:65
#define PqMsg_FunctionCall
Definition: protocol.h:23
#define PqMsg_Describe
Definition: protocol.h:21
#define PqMsg_Parse
Definition: protocol.h:25
#define PqMsg_Bind
Definition: protocol.h:19
#define PqMsg_Sync
Definition: protocol.h:27
#define PqMsg_CopyFail
Definition: protocol.h:29
#define PqMsg_Flush
Definition: protocol.h:24
#define PqMsg_BackendKeyData
Definition: protocol.h:48
#define PqMsg_Query
Definition: protocol.h:26
#define PqMsg_Terminate
Definition: protocol.h:28
#define PqMsg_Execute
Definition: protocol.h:22
#define PqMsg_Close
Definition: protocol.h:20
static void set_ps_display(const char *activity)
Definition: ps_status.h:40
MemoryContextSwitchTo(old_ctx)
ReplicationSlot * MyReplicationSlot
Definition: slot.c:138
void ReplicationSlotRelease(void)
Definition: slot.c:652
void ReplicationSlotCleanup(bool synced_only)
Definition: slot.c:745
void InvalidateCatalogSnapshotConditionally(void)
Definition: snapmgr.c:443
int IdleSessionTimeout
Definition: proc.c:62
int IdleInTransactionSessionTimeout
Definition: proc.c:60
int TransactionTimeout
Definition: proc.c:61
char * dbname
Definition: streamutil.c:50
void initStringInfo(StringInfo str)
Definition: stringinfo.c:56
void enable_timeout_after(TimeoutId id, int delay_ms)
Definition: timeout.c:560
bool get_timeout_active(TimeoutId id)
Definition: timeout.c:780
void disable_all_timeouts(bool keep_indicators)
Definition: timeout.c:751
void InitializeTimeouts(void)
Definition: timeout.c:470
void disable_timeout(TimeoutId id, bool keep_indicator)
Definition: timeout.c:685
@ IDLE_SESSION_TIMEOUT
Definition: timeout.h:35
@ IDLE_IN_TRANSACTION_SESSION_TIMEOUT
Definition: timeout.h:33
@ IDLE_STATS_UPDATE_TIMEOUT
Definition: timeout.h:36
void WalSndErrorCleanup(void)
Definition: walsender.c:325
bool am_walsender
Definition: walsender.c:115
bool exec_replication_command(const char *cmd_string)
Definition: walsender.c:1952
void WalSndSignals(void)
Definition: walsender.c:3562
void InitWalSender(void)
#define SIGCHLD
Definition: win32_port.h:178
#define SIGHUP
Definition: win32_port.h:168
#define SIG_DFL
Definition: win32_port.h:163
#define SIGPIPE
Definition: win32_port.h:173
#define SIGQUIT
Definition: win32_port.h:169
#define SIGUSR1
Definition: win32_port.h:180
#define SIGUSR2
Definition: win32_port.h:181
#define SIG_IGN
Definition: win32_port.h:165
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4981
bool IsAbortedTransactionBlockState(void)
Definition: xact.c:406
void EndImplicitTransactionBlock(void)
Definition: xact.c:4343
void SetCurrentStatementStartTimestamp(void)
Definition: xact.c:913
void AbortCurrentTransaction(void)
Definition: xact.c:3443

References AbortCurrentTransaction(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, am_walsender, Assert, BaseInit(), BeginReportingGUCOptions(), buf, CHECK_FOR_INTERRUPTS, ConfigReloadPending, dbname, debug_query_string, DestDebug, DestNone, DestRemote, die(), disable_all_timeouts(), disable_timeout(), DISCONNECT_CLIENT_EOF, doing_extended_query_message, DoingCommandRead, drop_unnamed_stmt(), DropPreparedStatement(), EmitErrorReport(), enable_timeout_after(), EndImplicitTransactionBlock(), ereport, errcode(), errmsg(), ERROR, error_context_stack, EventTriggerOnLogin(), exec_bind_message(), exec_describe_portal_message(), exec_describe_statement_message(), exec_execute_message(), exec_parse_message(), exec_replication_command(), exec_simple_query(), FATAL, finish_xact_command(), FloatExceptionHandler(), FlushErrorState(), forbidden_in_wal_sender(), get_timeout_active(), GetPortalByName(), GetProcessingMode, HandleFunctionRequest(), HOLD_INTERRUPTS, i, IDLE_IN_TRANSACTION_SESSION_TIMEOUT, IDLE_SESSION_TIMEOUT, IDLE_STATS_UPDATE_TIMEOUT, IdleInTransactionSessionTimeout, IdleSessionTimeout, ignore_till_sync, INIT_PG_LOAD_SESSION_LIBS, InitializeTimeouts(), InitPostgres(), InitProcessing, initStringInfo(), InitWalSender(), InvalidateCatalogSnapshotConditionally(), InvalidOid, IsAbortedTransactionBlockState(), IsTransactionOrTransactionBlock(), IsUnderPostmaster, jit_reset_after_error(), Log_disconnections, log_disconnections(), MemoryContextDelete(), MemoryContextReset(), MemoryContextSwitchTo(), MessageContext, MyCancelKey, MyCancelKeyValid, MyDatabaseId, MyProcPid, MyReplicationSlot, NormalProcessing, notifyInterruptPending, on_proc_exit(), palloc_array, PG_exception_stack, pg_strong_random(), PGC_SIGHUP, pgstat_report_activity(), pgstat_report_connect(), pgstat_report_stat(), pgStatSessionEndCause, PortalDrop(), PortalErrorCleanup(), PortalIsValid, PostmasterContext, pq_beginmessage(), pq_comm_reset, pq_endmessage(), pq_flush, pq_getmsgbyte(), pq_getmsgend(), pq_getmsgint(), pq_getmsgstring(), pq_is_reading_msg(), pq_putemptymessage(), pq_sendint32(), PqMsg_BackendKeyData, PqMsg_Bind, PqMsg_Close, PqMsg_CloseComplete, PqMsg_CopyData, PqMsg_CopyDone, PqMsg_CopyFail, PqMsg_Describe, PqMsg_Execute, PqMsg_Flush, PqMsg_FunctionCall, PqMsg_Parse, PqMsg_Query, PqMsg_Sync, PqMsg_Terminate, pqsignal(), printf, proc_exit(), ProcessConfigFile(), ProcessNotifyInterrupt(), procsignal_sigusr1_handler(), QueryCancelPending, quickdie(), ReadCommand(), ReadyForQuery(), ReplicationSlotCleanup(), ReplicationSlotRelease(), ReportChangedGUCOptions(), RESUME_INTERRUPTS, row_description_buf, row_description_context, set_ps_display(), SetCurrentStatementStartTimestamp(), SetProcessingMode, SIG_DFL, SIG_IGN, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SIGPIPE, SIGQUIT, SIGUSR1, SIGUSR2, start_xact_command(), STATE_FASTPATH, STATE_IDLE, STATE_IDLEINTRANSACTION, STATE_IDLEINTRANSACTION_ABORTED, StatementCancelHandler(), TopMemoryContext, TransactionTimeout, UnBlockSig, username, valgrind_report_error_query, WalSndErrorCleanup(), WalSndSignals(), whereToSendOutput, and xact_started.

Referenced by BackendMain(), and PostgresSingleUserMain().

◆ PostgresSingleUserMain()

void PostgresSingleUserMain ( int  argc,
char *  argv[],
const char *  username 
)

Definition at line 4145 of file postgres.c.

4147 {
4148  const char *dbname = NULL;
4149 
4151 
4152  /* Initialize startup process environment. */
4153  InitStandaloneProcess(argv[0]);
4154 
4155  /*
4156  * Set default values for command-line options.
4157  */
4159 
4160  /*
4161  * Parse command-line options.
4162  */
4164 
4165  /* Must have gotten a database name, or have a default (the username) */
4166  if (dbname == NULL)
4167  {
4168  dbname = username;
4169  if (dbname == NULL)
4170  ereport(FATAL,
4171  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4172  errmsg("%s: no database nor user name specified",
4173  progname)));
4174  }
4175 
4176  /* Acquire configuration parameters */
4178  proc_exit(1);
4179 
4180  /*
4181  * Validate we have been given a reasonable-looking DataDir and change
4182  * into it.
4183  */
4184  checkDataDir();
4185  ChangeToDataDir();
4186 
4187  /*
4188  * Create lockfile for data directory.
4189  */
4190  CreateDataDirLockFile(false);
4191 
4192  /* read control file (error checking and contains config ) */
4193  LocalProcessControlFile(false);
4194 
4195  /*
4196  * process any libraries that should be preloaded at postmaster start
4197  */
4199 
4200  /* Initialize MaxBackends */
4202 
4203  /*
4204  * We don't need postmaster child slots in single-user mode, but
4205  * initialize them anyway to avoid having special handling.
4206  */
4208 
4209  /* Initialize size of fast-path lock cache. */
4211 
4212  /*
4213  * Give preloaded libraries a chance to request additional shared memory.
4214  */
4216 
4217  /*
4218  * Now that loadable modules have had their chance to request additional
4219  * shared memory, determine the value of any runtime-computed GUCs that
4220  * depend on the amount of shared memory required.
4221  */
4223 
4224  /*
4225  * Now that modules have been loaded, we can process any custom resource
4226  * managers specified in the wal_consistency_checking GUC.
4227  */
4229 
4231 
4232  /*
4233  * Remember stand-alone backend startup time,roughly at the same point
4234  * during startup that postmaster does so.
4235  */
4237 
4238  /*
4239  * Create a per-backend PGPROC struct in shared memory. We must do this
4240  * before we can use LWLocks.
4241  */
4242  InitProcess();
4243 
4244  /*
4245  * Now that sufficient infrastructure has been initialized, PostgresMain()
4246  * can do the rest.
4247  */
4249 }
TimestampTz PgStartTime
Definition: timestamp.c:53
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:1784
void InitializeGUCOptions(void)
Definition: guc.c:1530
@ PGC_POSTMASTER
Definition: guc.h:70
void InitializeShmemGUCs(void)
Definition: ipci.c:352
void CreateSharedMemoryAndSemaphores(void)
Definition: ipci.c:198
const char * progname
Definition: main.c:43
void ChangeToDataDir(void)
Definition: miscinit.c:464
void process_shmem_requests(void)
Definition: miscinit.c:1932
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:182
void process_shared_preload_libraries(void)
Definition: miscinit.c:1904
void checkDataDir(void)
Definition: miscinit.c:351
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1516
void InitPostmasterChildSlots(void)
Definition: pmchild.c:86
void process_postgres_switches(int argc, char *argv[], GucContext ctx, const char **dbname)
Definition: postgres.c:3893
static const char * userDoption
Definition: postgres.c:164
void PostgresMain(const char *dbname, const char *username)
Definition: postgres.c:4264
void InitializeMaxBackends(void)
Definition: postinit.c:543
void InitializeFastPathLocks(void)
Definition: postinit.c:575
void InitProcess(void)
Definition: proc.c:339
void InitializeWalConsistencyChecking(void)
Definition: xlog.c:4784
void LocalProcessControlFile(bool reset)
Definition: xlog.c:4846

References Assert, ChangeToDataDir(), checkDataDir(), CreateDataDirLockFile(), CreateSharedMemoryAndSemaphores(), dbname, ereport, errcode(), errmsg(), FATAL, GetCurrentTimestamp(), InitializeFastPathLocks(), InitializeGUCOptions(), InitializeMaxBackends(), InitializeShmemGUCs(), InitializeWalConsistencyChecking(), InitPostmasterChildSlots(), InitProcess(), InitStandaloneProcess(), IsUnderPostmaster, LocalProcessControlFile(), PGC_POSTMASTER, PgStartTime, PostgresMain(), proc_exit(), process_postgres_switches(), process_shared_preload_libraries(), process_shmem_requests(), progname, SelectConfigFiles(), userDoption, and username.

Referenced by main().

◆ process_postgres_switches()

void process_postgres_switches ( int  argc,
char *  argv[],
GucContext  ctx,
const char **  dbname 
)

Definition at line 3893 of file postgres.c.

3895 {
3896  bool secure = (ctx == PGC_POSTMASTER);
3897  int errs = 0;
3898  GucSource gucsource;
3899  int flag;
3900 
3901  if (secure)
3902  {
3903  gucsource = PGC_S_ARGV; /* switches came from command line */
3904 
3905  /* Ignore the initial --single argument, if present */
3906  if (argc > 1 && strcmp(argv[1], "--single") == 0)
3907  {
3908  argv++;
3909  argc--;
3910  }
3911  }
3912  else
3913  {
3914  gucsource = PGC_S_CLIENT; /* switches came from client */
3915  }
3916 
3917 #ifdef HAVE_INT_OPTERR
3918 
3919  /*
3920  * Turn this off because it's either printed to stderr and not the log
3921  * where we'd want it, or argv[0] is now "--single", which would make for
3922  * a weird error message. We print our own error message below.
3923  */
3924  opterr = 0;
3925 #endif
3926 
3927  /*
3928  * Parse command-line options. CAUTION: keep this in sync with
3929  * postmaster/postmaster.c (the option sets should not conflict) and with
3930  * the common help() function in main/main.c.
3931  */
3932  while ((flag = getopt(argc, argv, "B:bC:c:D:d:EeFf:h:ijk:lN:nOPp:r:S:sTt:v:W:-:")) != -1)
3933  {
3934  switch (flag)
3935  {
3936  case 'B':
3937  SetConfigOption("shared_buffers", optarg, ctx, gucsource);
3938  break;
3939 
3940  case 'b':
3941  /* Undocumented flag used for binary upgrades */
3942  if (secure)
3943  IsBinaryUpgrade = true;
3944  break;
3945 
3946  case 'C':
3947  /* ignored for consistency with the postmaster */
3948  break;
3949 
3950  case 'c':
3951  case '-':
3952  {
3953  char *name,
3954  *value;
3955 
3957  if (!value)
3958  {
3959  if (flag == '-')
3960  ereport(ERROR,
3961  (errcode(ERRCODE_SYNTAX_ERROR),
3962  errmsg("--%s requires a value",
3963  optarg)));
3964  else
3965  ereport(ERROR,
3966  (errcode(ERRCODE_SYNTAX_ERROR),
3967  errmsg("-c %s requires a value",
3968  optarg)));
3969  }
3970  SetConfigOption(name, value, ctx, gucsource);
3971  pfree(name);
3972  pfree(value);
3973  break;
3974  }
3975 
3976  case 'D':
3977  if (secure)
3978  userDoption = strdup(optarg);
3979  break;
3980 
3981  case 'd':
3982  set_debug_options(atoi(optarg), ctx, gucsource);
3983  break;
3984 
3985  case 'E':
3986  if (secure)
3987  EchoQuery = true;
3988  break;
3989 
3990  case 'e':
3991  SetConfigOption("datestyle", "euro", ctx, gucsource);
3992  break;
3993 
3994  case 'F':
3995  SetConfigOption("fsync", "false", ctx, gucsource);
3996  break;
3997 
3998  case 'f':
3999  if (!set_plan_disabling_options(optarg, ctx, gucsource))
4000  errs++;
4001  break;
4002 
4003  case 'h':
4004  SetConfigOption("listen_addresses", optarg, ctx, gucsource);
4005  break;
4006 
4007  case 'i':
4008  SetConfigOption("listen_addresses", "*", ctx, gucsource);
4009  break;
4010 
4011  case 'j':
4012  if (secure)
4013  UseSemiNewlineNewline = true;
4014  break;
4015 
4016  case 'k':
4017  SetConfigOption("unix_socket_directories", optarg, ctx, gucsource);
4018  break;
4019 
4020  case 'l':
4021  SetConfigOption("ssl", "true", ctx, gucsource);
4022  break;
4023 
4024  case 'N':
4025  SetConfigOption("max_connections", optarg, ctx, gucsource);
4026  break;
4027 
4028  case 'n':
4029  /* ignored for consistency with postmaster */
4030  break;
4031 
4032  case 'O':
4033  SetConfigOption("allow_system_table_mods", "true", ctx, gucsource);
4034  break;
4035 
4036  case 'P':
4037  SetConfigOption("ignore_system_indexes", "true", ctx, gucsource);
4038  break;
4039 
4040  case 'p':
4041  SetConfigOption("port", optarg, ctx, gucsource);
4042  break;
4043 
4044  case 'r':
4045  /* send output (stdout and stderr) to the given file */
4046  if (secure)
4048  break;
4049 
4050  case 'S':
4051  SetConfigOption("work_mem", optarg, ctx, gucsource);
4052  break;
4053 
4054  case 's':
4055  SetConfigOption("log_statement_stats", "true", ctx, gucsource);
4056  break;
4057 
4058  case 'T':
4059  /* ignored for consistency with the postmaster */
4060  break;
4061 
4062  case 't':
4063  {
4064  const char *tmp = get_stats_option_name(optarg);
4065 
4066  if (tmp)
4067  SetConfigOption(tmp, "true", ctx, gucsource);
4068  else
4069  errs++;
4070  break;
4071  }
4072 
4073  case 'v':
4074 
4075  /*
4076  * -v is no longer used in normal operation, since
4077  * FrontendProtocol is already set before we get here. We keep
4078  * the switch only for possible use in standalone operation,
4079  * in case we ever support using normal FE/BE protocol with a
4080  * standalone backend.
4081  */
4082  if (secure)
4084  break;
4085 
4086  case 'W':
4087  SetConfigOption("post_auth_delay", optarg, ctx, gucsource);
4088  break;
4089 
4090  default:
4091  errs++;
4092  break;
4093  }
4094 
4095  if (errs)
4096  break;
4097  }
4098 
4099  /*
4100  * Optional database name should be there only if *dbname is NULL.
4101  */
4102  if (!errs && dbname && *dbname == NULL && argc - optind >= 1)
4103  *dbname = strdup(argv[optind++]);
4104 
4105  if (errs || argc != optind)
4106  {
4107  if (errs)
4108  optind--; /* complain about the previous argument */
4109 
4110  /* spell the error message a bit differently depending on context */
4111  if (IsUnderPostmaster)
4112  ereport(FATAL,
4113  errcode(ERRCODE_SYNTAX_ERROR),
4114  errmsg("invalid command-line argument for server process: %s", argv[optind]),
4115  errhint("Try \"%s --help\" for more information.", progname));
4116  else
4117  ereport(FATAL,
4118  errcode(ERRCODE_SYNTAX_ERROR),
4119  errmsg("%s: invalid command-line argument: %s",
4120  progname, argv[optind]),
4121  errhint("Try \"%s --help\" for more information.", progname));
4122  }
4123 
4124  /*
4125  * Reset getopt(3) library so that it will work correctly in subprocesses
4126  * or when this function is called a second time with another array.
4127  */
4128  optind = 1;
4129 #ifdef HAVE_INT_OPTRESET
4130  optreset = 1; /* some systems need this too */
4131 #endif
4132 }
int errhint(const char *fmt,...)
Definition: elog.c:1317
bool IsBinaryUpgrade
Definition: globals.c:120
ProtocolVersion FrontendProtocol
Definition: globals.c:29
char OutputFileName[MAXPGPATH]
Definition: globals.c:78
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:4332
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:6362
GucSource
Definition: guc.h:108
@ PGC_S_ARGV
Definition: guc.h:113
@ PGC_S_CLIENT
Definition: guc.h:118
static struct @160 value
#define MAXPGPATH
PGDLLIMPORT int optind
Definition: getopt.c:51
PGDLLIMPORT int opterr
Definition: getopt.c:50
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: getopt.c:72
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
void set_debug_options(int debug_flag, GucContext context, GucSource source)
Definition: postgres.c:3782
static bool UseSemiNewlineNewline
Definition: postgres.c:166
static bool EchoQuery
Definition: postgres.c:165
bool set_plan_disabling_options(const char *arg, GucContext context, GucSource source)
Definition: postgres.c:3811
const char * get_stats_option_name(const char *arg)
Definition: postgres.c:3853
uint32 ProtocolVersion
Definition: pqcomm.h:100
char * flag(int b)
Definition: test-ctype.c:33
const char * name

References dbname, EchoQuery, ereport, errcode(), errhint(), errmsg(), ERROR, FATAL, flag(), FrontendProtocol, get_stats_option_name(), getopt(), IsBinaryUpgrade, IsUnderPostmaster, MAXPGPATH, name, optarg, opterr, optind, OutputFileName, ParseLongOption(), pfree(), PGC_POSTMASTER, PGC_S_ARGV, PGC_S_CLIENT, progname, set_debug_options(), set_plan_disabling_options(), SetConfigOption(), strlcpy(), userDoption, UseSemiNewlineNewline, and value.

Referenced by PostgresSingleUserMain(), and process_startup_options().

◆ ProcessClientReadInterrupt()

void ProcessClientReadInterrupt ( bool  blocked)

Definition at line 512 of file postgres.c.

513 {
514  int save_errno = errno;
515 
516  if (DoingCommandRead)
517  {
518  /* Check for general interrupts that arrived before/while reading */
520 
521  /* Process sinval catchup interrupts, if any */
524 
525  /* Process notify interrupts, if any */
528  }
529  else if (ProcDiePending)
530  {
531  /*
532  * We're dying. If there is no data available to read, then it's safe
533  * (and sane) to handle that now. If we haven't tried to read yet,
534  * make sure the process latch is set, so that if there is no data
535  * then we'll come back here and die. If we're done reading, also
536  * make sure the process latch is set, as we might've undesirably
537  * cleared it while reading.
538  */
539  if (blocked)
541  else
542  SetLatch(MyLatch);
543  }
544 
545  errno = save_errno;
546 }
void ProcessCatchupInterrupt(void)
Definition: sinval.c:174
volatile sig_atomic_t catchupInterruptPending
Definition: sinval.c:39

References catchupInterruptPending, CHECK_FOR_INTERRUPTS, DoingCommandRead, MyLatch, notifyInterruptPending, ProcDiePending, ProcessCatchupInterrupt(), ProcessNotifyInterrupt(), and SetLatch().

Referenced by interactive_getc(), and secure_read().

◆ ProcessClientWriteInterrupt()

void ProcessClientWriteInterrupt ( bool  blocked)

Definition at line 558 of file postgres.c.

559 {
560  int save_errno = errno;
561 
562  if (ProcDiePending)
563  {
564  /*
565  * We're dying. If it's not possible to write, then we should handle
566  * that immediately, else a stuck client could indefinitely delay our
567  * response to the signal. If we haven't tried to write yet, make
568  * sure the process latch is set, so that if the write would block
569  * then we'll come back here and die. If we're done writing, also
570  * make sure the process latch is set, as we might've undesirably
571  * cleared it while writing.
572  */
573  if (blocked)
574  {
575  /*
576  * Don't mess with whereToSendOutput if ProcessInterrupts wouldn't
577  * service ProcDiePending.
578  */
579  if (InterruptHoldoffCount == 0 && CritSectionCount == 0)
580  {
581  /*
582  * We don't want to send the client the error message, as a)
583  * that would possibly block again, and b) it would likely
584  * lead to loss of protocol sync because we may have already
585  * sent a partial protocol message.
586  */
589 
591  }
592  }
593  else
594  SetLatch(MyLatch);
595  }
596 
597  errno = save_errno;
598 }
volatile uint32 InterruptHoldoffCount
Definition: globals.c:42
volatile uint32 CritSectionCount
Definition: globals.c:44

References CHECK_FOR_INTERRUPTS, CritSectionCount, DestNone, DestRemote, InterruptHoldoffCount, MyLatch, ProcDiePending, SetLatch(), and whereToSendOutput.

Referenced by secure_write().

◆ quickdie()

void quickdie ( SIGNAL_ARGS  )

Definition at line 2918 of file postgres.c.

2919 {
2920  sigaddset(&BlockSig, SIGQUIT); /* prevent nested calls */
2921  sigprocmask(SIG_SETMASK, &BlockSig, NULL);
2922 
2923  /*
2924  * Prevent interrupts while exiting; though we just blocked signals that
2925  * would queue new interrupts, one may have been pending. We don't want a
2926  * quickdie() downgraded to a mere query cancel.
2927  */
2928  HOLD_INTERRUPTS();
2929 
2930  /*
2931  * If we're aborting out of client auth, don't risk trying to send
2932  * anything to the client; we will likely violate the protocol, not to
2933  * mention that we may have interrupted the guts of OpenSSL or some
2934  * authentication library.
2935  */
2938 
2939  /*
2940  * Notify the client before exiting, to give a clue on what happened.
2941  *
2942  * It's dubious to call ereport() from a signal handler. It is certainly
2943  * not async-signal safe. But it seems better to try, than to disconnect
2944  * abruptly and leave the client wondering what happened. It's remotely
2945  * possible that we crash or hang while trying to send the message, but
2946  * receiving a SIGQUIT is a sign that something has already gone badly
2947  * wrong, so there's not much to lose. Assuming the postmaster is still
2948  * running, it will SIGKILL us soon if we get stuck for some reason.
2949  *
2950  * One thing we can do to make this a tad safer is to clear the error
2951  * context stack, so that context callbacks are not called. That's a lot
2952  * less code that could be reached here, and the context info is unlikely
2953  * to be very relevant to a SIGQUIT report anyway.
2954  */
2955  error_context_stack = NULL;
2956 
2957  /*
2958  * When responding to a postmaster-issued signal, we send the message only
2959  * to the client; sending to the server log just creates log spam, plus
2960  * it's more code that we need to hope will work in a signal handler.
2961  *
2962  * Ideally these should be ereport(FATAL), but then we'd not get control
2963  * back to force the correct type of process exit.
2964  */
2965  switch (GetQuitSignalReason())
2966  {
2967  case PMQUIT_NOT_SENT:
2968  /* Hmm, SIGQUIT arrived out of the blue */
2969  ereport(WARNING,
2970  (errcode(ERRCODE_ADMIN_SHUTDOWN),
2971  errmsg("terminating connection because of unexpected SIGQUIT signal")));
2972  break;
2973  case PMQUIT_FOR_CRASH:
2974  /* A crash-and-restart cycle is in progress */
2976  (errcode(ERRCODE_CRASH_SHUTDOWN),
2977  errmsg("terminating connection because of crash of another server process"),
2978  errdetail("The postmaster has commanded this server process to roll back"
2979  " the current transaction and exit, because another"
2980  " server process exited abnormally and possibly corrupted"
2981  " shared memory."),
2982  errhint("In a moment you should be able to reconnect to the"
2983  " database and repeat your command.")));
2984  break;
2985  case PMQUIT_FOR_STOP:
2986  /* Immediate-mode stop */
2988  (errcode(ERRCODE_ADMIN_SHUTDOWN),
2989  errmsg("terminating connection due to immediate shutdown command")));
2990  break;
2991  }
2992 
2993  /*
2994  * We DO NOT want to run proc_exit() or atexit() callbacks -- we're here
2995  * because shared memory may be corrupted, so we don't want to try to
2996  * clean up our transaction. Just nail the windows shut and get out of
2997  * town. The callbacks wouldn't be safe to run from a signal handler,
2998  * anyway.
2999  *
3000  * Note we do _exit(2) not _exit(0). This is to force the postmaster into
3001  * a system reset cycle if someone sends a manual SIGQUIT to a random
3002  * backend. This is necessary precisely because we don't clean up our
3003  * shared memory state. (The "dead man switch" mechanism in pmsignal.c
3004  * should ensure the postmaster sees this as a crash, too, but no harm in
3005  * being doubly sure.)
3006  */
3007  _exit(2);
3008 }
sigset_t BlockSig
Definition: pqsignal.c:23
#define WARNING_CLIENT_ONLY
Definition: elog.h:38
QuitSignalReason GetQuitSignalReason(void)
Definition: pmsignal.c:213
@ PMQUIT_FOR_STOP
Definition: pmsignal.h:54
@ PMQUIT_FOR_CRASH
Definition: pmsignal.h:53
@ PMQUIT_NOT_SENT
Definition: pmsignal.h:52
bool ClientAuthInProgress
Definition: postmaster.c:355

References BlockSig, ClientAuthInProgress, DestNone, DestRemote, ereport, errcode(), errdetail(), errhint(), errmsg(), error_context_stack, GetQuitSignalReason(), HOLD_INTERRUPTS, PMQUIT_FOR_CRASH, PMQUIT_FOR_STOP, PMQUIT_NOT_SENT, SIGQUIT, WARNING, WARNING_CLIENT_ONLY, and whereToSendOutput.

Referenced by PostgresMain().

◆ ResetUsage()

void ResetUsage ( void  )

◆ set_debug_options()

void set_debug_options ( int  debug_flag,
GucContext  context,
GucSource  source 
)

Definition at line 3782 of file postgres.c.

3783 {
3784  if (debug_flag > 0)
3785  {
3786  char debugstr[64];
3787 
3788  sprintf(debugstr, "debug%d", debug_flag);
3789  SetConfigOption("log_min_messages", debugstr, context, source);
3790  }
3791  else
3792  SetConfigOption("log_min_messages", "notice", context, source);
3793 
3794  if (debug_flag >= 1 && context == PGC_POSTMASTER)
3795  {
3796  SetConfigOption("log_connections", "true", context, source);
3797  SetConfigOption("log_disconnections", "true", context, source);
3798  }
3799  if (debug_flag >= 2)
3800  SetConfigOption("log_statement", "all", context, source);
3801  if (debug_flag >= 3)
3802  SetConfigOption("debug_print_parse", "true", context, source);
3803  if (debug_flag >= 4)
3804  SetConfigOption("debug_print_plan", "true", context, source);
3805  if (debug_flag >= 5)
3806  SetConfigOption("debug_print_rewritten", "true", context, source);
3807 }
static rewind_source * source
Definition: pg_rewind.c:89
#define sprintf
Definition: port.h:240
tree context
Definition: radixtree.h:1835

References context, PGC_POSTMASTER, SetConfigOption(), source, and sprintf.

Referenced by PostmasterMain(), and process_postgres_switches().

◆ set_plan_disabling_options()

bool set_plan_disabling_options ( const char *  arg,
GucContext  context,
GucSource  source 
)

Definition at line 3811 of file postgres.c.

3812 {
3813  const char *tmp = NULL;
3814 
3815  switch (arg[0])
3816  {
3817  case 's': /* seqscan */
3818  tmp = "enable_seqscan";
3819  break;
3820  case 'i': /* indexscan */
3821  tmp = "enable_indexscan";
3822  break;
3823  case 'o': /* indexonlyscan */
3824  tmp = "enable_indexonlyscan";
3825  break;
3826  case 'b': /* bitmapscan */
3827  tmp = "enable_bitmapscan";
3828  break;
3829  case 't': /* tidscan */
3830  tmp = "enable_tidscan";
3831  break;
3832  case 'n': /* nestloop */
3833  tmp = "enable_nestloop";
3834  break;
3835  case 'm': /* mergejoin */
3836  tmp = "enable_mergejoin";
3837  break;
3838  case 'h': /* hashjoin */
3839  tmp = "enable_hashjoin";
3840  break;
3841  }
3842  if (tmp)
3843  {
3844  SetConfigOption(tmp, "false", context, source);
3845  return true;
3846  }
3847  else
3848  return false;
3849 }

References arg, context, SetConfigOption(), and source.

Referenced by PostmasterMain(), and process_postgres_switches().

◆ ShowUsage()

void ShowUsage ( const char *  title)

Definition at line 5136 of file postgres.c.

5137 {
5139  struct timeval user,
5140  sys;
5141  struct timeval elapse_t;
5142  struct rusage r;
5143 
5144  getrusage(RUSAGE_SELF, &r);
5145  gettimeofday(&elapse_t, NULL);
5146  memcpy((char *) &user, (char *) &r.ru_utime, sizeof(user));
5147  memcpy((char *) &sys, (char *) &r.ru_stime, sizeof(sys));
5148  if (elapse_t.tv_usec < Save_t.tv_usec)
5149  {
5150  elapse_t.tv_sec--;
5151  elapse_t.tv_usec += 1000000;
5152  }
5153  if (r.ru_utime.tv_usec < Save_r.ru_utime.tv_usec)
5154  {
5155  r.ru_utime.tv_sec--;
5156  r.ru_utime.tv_usec += 1000000;
5157  }
5158  if (r.ru_stime.tv_usec < Save_r.ru_stime.tv_usec)
5159  {
5160  r.ru_stime.tv_sec--;
5161  r.ru_stime.tv_usec += 1000000;
5162  }
5163 
5164  /*
5165  * The only stats we don't show here are ixrss, idrss, isrss. It takes
5166  * some work to interpret them, and most platforms don't fill them in.
5167  */
5168  initStringInfo(&str);
5169 
5170  appendStringInfoString(&str, "! system usage stats:\n");
5172  "!\t%ld.%06ld s user, %ld.%06ld s system, %ld.%06ld s elapsed\n",
5173  (long) (r.ru_utime.tv_sec - Save_r.ru_utime.tv_sec),
5174  (long) (r.ru_utime.tv_usec - Save_r.ru_utime.tv_usec),
5175  (long) (r.ru_stime.tv_sec - Save_r.ru_stime.tv_sec),
5176  (long) (r.ru_stime.tv_usec - Save_r.ru_stime.tv_usec),
5177  (long) (elapse_t.tv_sec - Save_t.tv_sec),
5178  (long) (elapse_t.tv_usec - Save_t.tv_usec));
5180  "!\t[%ld.%06ld s user, %ld.%06ld s system total]\n",
5181  (long) user.tv_sec,
5182  (long) user.tv_usec,
5183  (long) sys.tv_sec,
5184  (long) sys.tv_usec);
5185 #ifndef WIN32
5186 
5187  /*
5188  * The following rusage fields are not defined by POSIX, but they're
5189  * present on all current Unix-like systems so we use them without any
5190  * special checks. Some of these could be provided in our Windows
5191  * emulation in src/port/win32getrusage.c with more work.
5192  */
5194  "!\t%ld kB max resident size\n",
5195 #if defined(__darwin__)
5196  /* in bytes on macOS */
5197  r.ru_maxrss / 1024
5198 #else
5199  /* in kilobytes on most other platforms */
5200  r.ru_maxrss
5201 #endif
5202  );
5204  "!\t%ld/%ld [%ld/%ld] filesystem blocks in/out\n",
5205  r.ru_inblock - Save_r.ru_inblock,
5206  /* they only drink coffee at dec */
5207  r.ru_oublock - Save_r.ru_oublock,
5208  r.ru_inblock, r.ru_oublock);
5210  "!\t%ld/%ld [%ld/%ld] page faults/reclaims, %ld [%ld] swaps\n",
5211  r.ru_majflt - Save_r.ru_majflt,
5212  r.ru_minflt - Save_r.ru_minflt,
5213  r.ru_majflt, r.ru_minflt,
5214  r.ru_nswap - Save_r.ru_nswap,
5215  r.ru_nswap);
5217  "!\t%ld [%ld] signals rcvd, %ld/%ld [%ld/%ld] messages rcvd/sent\n",
5218  r.ru_nsignals - Save_r.ru_nsignals,
5219  r.ru_nsignals,
5220  r.ru_msgrcv - Save_r.ru_msgrcv,
5221  r.ru_msgsnd - Save_r.ru_msgsnd,
5222  r.ru_msgrcv, r.ru_msgsnd);
5224  "!\t%ld/%ld [%ld/%ld] voluntary/involuntary context switches\n",
5225  r.ru_nvcsw - Save_r.ru_nvcsw,
5226  r.ru_nivcsw - Save_r.ru_nivcsw,
5227  r.ru_nvcsw, r.ru_nivcsw);
5228 #endif /* !WIN32 */
5229 
5230  /* remove trailing newline */
5231  if (str.data[str.len - 1] == '\n')
5232  str.data[--str.len] = '\0';
5233 
5234  ereport(LOG,
5235  (errmsg_internal("%s", title),
5236  errdetail_internal("%s", str.data)));
5237 
5238  pfree(str.data);
5239 }
#define __darwin__
Definition: darwin.h:3
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1157
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1230
static char * user
Definition: pg_regress.c:119
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:94
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:179
struct timeval ru_utime
Definition: resource.h:14
struct timeval ru_stime
Definition: resource.h:15

References __darwin__, appendStringInfo(), appendStringInfoString(), ereport, errdetail_internal(), errmsg_internal(), getrusage(), gettimeofday(), initStringInfo(), LOG, pfree(), rusage::ru_stime, rusage::ru_utime, RUSAGE_SELF, Save_r, Save_t, str, and user.

Referenced by _bt_leader_participate_as_worker(), _bt_leafbuild(), _bt_parallel_build_main(), _SPI_pquery(), btbuild(), exec_bind_message(), exec_execute_message(), exec_parse_message(), exec_simple_query(), pg_analyze_and_rewrite_fixedparams(), pg_analyze_and_rewrite_varparams(), pg_analyze_and_rewrite_withcb(), pg_parse_query(), pg_plan_query(), pg_rewrite_query(), PortalRun(), and PortalRunMulti().

◆ StatementCancelHandler()

void StatementCancelHandler ( SIGNAL_ARGS  )

Definition at line 3045 of file postgres.c.

3046 {
3047  /*
3048  * Don't joggle the elbow of proc_exit
3049  */
3050  if (!proc_exit_inprogress)
3051  {
3052  InterruptPending = true;
3053  QueryCancelPending = true;
3054  }
3055 
3056  /* If we're still here, waken anything waiting on the process latch */
3057  SetLatch(MyLatch);
3058 }

References InterruptPending, MyLatch, proc_exit_inprogress, QueryCancelPending, and SetLatch().

Referenced by AutoVacWorkerMain(), BackgroundWorkerMain(), PostgresMain(), and WalSndSignals().

Variable Documentation

◆ client_connection_check_interval

PGDLLIMPORT int client_connection_check_interval
extern

Definition at line 104 of file postgres.c.

Referenced by ProcessInterrupts(), and start_xact_command().

◆ debug_query_string

◆ Log_disconnections

PGDLLIMPORT bool Log_disconnections
extern

Definition at line 93 of file postgres.c.

Referenced by PostgresMain().

◆ log_statement

PGDLLIMPORT int log_statement
extern

Definition at line 95 of file postgres.c.

Referenced by check_log_statement(), and HandleFunctionRequest().

◆ max_stack_depth

PGDLLIMPORT int max_stack_depth
extern

Definition at line 98 of file postgres.c.

Referenced by check_stack_depth().

◆ PostAuthDelay

PGDLLIMPORT int PostAuthDelay
extern

Definition at line 101 of file postgres.c.

Referenced by AutoVacWorkerMain(), BackgroundWorkerMain(), and InitPostgres().

◆ restrict_nonsystem_relation_kind

PGDLLIMPORT int restrict_nonsystem_relation_kind
extern

◆ whereToSendOutput