Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

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 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)
 
pg_noreturn void quickdie (SIGNAL_ARGS)
 
void StatementCancelHandler (SIGNAL_ARGS)
 
pg_noreturn void FloatExceptionHandler (SIGNAL_ARGS)
 
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)
 
pg_noreturn void PostgresSingleUserMain (int argc, char *argv[], const char *username)
 
pg_noreturn void PostgresMain (const char *dbname, const char *username)
 
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 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 44 of file tcopprot.h.

◆ RESTRICT_RELKIND_VIEW

#define RESTRICT_RELKIND_VIEW   0x01

Definition at line 43 of file tcopprot.h.

Enumeration Type Documentation

◆ LogStmtLevel

Enumerator
LOGSTMT_NONE 
LOGSTMT_DDL 
LOGSTMT_MOD 
LOGSTMT_ALL 

Definition at line 31 of file tcopprot.h.

32{
33 LOGSTMT_NONE, /* log no statements */
34 LOGSTMT_DDL, /* log data definition statements */
35 LOGSTMT_MOD, /* log modification statements, plus DDL */
36 LOGSTMT_ALL, /* log all statements */
LogStmtLevel
Definition: tcopprot.h:32
@ LOGSTMT_NONE
Definition: tcopprot.h:33
@ LOGSTMT_MOD
Definition: tcopprot.h:35
@ LOGSTMT_DDL
Definition: tcopprot.h:34
@ LOGSTMT_ALL
Definition: tcopprot.h:36

Function Documentation

◆ check_log_duration()

int check_log_duration ( char *  msec_str,
bool  was_logged 
)

Definition at line 2428 of file postgres.c.

2429{
2432 {
2433 long secs;
2434 int usecs;
2435 int msecs;
2436 bool exceeded_duration;
2437 bool exceeded_sample_duration;
2438 bool in_sample = false;
2439
2442 &secs, &usecs);
2443 msecs = usecs / 1000;
2444
2445 /*
2446 * This odd-looking test for log_min_duration_* being exceeded is
2447 * designed to avoid integer overflow with very long durations: don't
2448 * compute secs * 1000 until we've verified it will fit in int.
2449 */
2450 exceeded_duration = (log_min_duration_statement == 0 ||
2452 (secs > log_min_duration_statement / 1000 ||
2453 secs * 1000 + msecs >= log_min_duration_statement)));
2454
2455 exceeded_sample_duration = (log_min_duration_sample == 0 ||
2457 (secs > log_min_duration_sample / 1000 ||
2458 secs * 1000 + msecs >= log_min_duration_sample)));
2459
2460 /*
2461 * Do not log if log_statement_sample_rate = 0. Log a sample if
2462 * log_statement_sample_rate <= 1 and avoid unnecessary PRNG call if
2463 * log_statement_sample_rate = 1.
2464 */
2465 if (exceeded_sample_duration)
2466 in_sample = log_statement_sample_rate != 0 &&
2469
2470 if (exceeded_duration || in_sample || log_duration || xact_is_sampled)
2471 {
2472 snprintf(msec_str, 32, "%ld.%03d",
2473 secs * 1000 + msecs, usecs % 1000);
2474 if ((exceeded_duration || in_sample || xact_is_sampled) && !was_logged)
2475 return 2;
2476 else
2477 return 1;
2478 }
2479 }
2480
2481 return 0;
2482}
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
Definition: timestamp.c:1721
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1645
int log_min_duration_statement
Definition: guc_tables.c:543
int log_min_duration_sample
Definition: guc_tables.c:542
double log_statement_sample_rate
Definition: guc_tables.c:547
bool log_duration
Definition: guc_tables.c:507
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:239
TimestampTz GetCurrentStatementStartTimestamp(void)
Definition: xact.c:879
bool xact_is_sampled
Definition: xact.c:296

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 3031 of file postgres.c.

3032{
3033 /* Don't joggle the elbow of proc_exit */
3035 {
3036 InterruptPending = true;
3037 ProcDiePending = true;
3038 }
3039
3040 /* for the cumulative stats system */
3042
3043 /* If we're still here, waken anything waiting on the process latch */
3045
3046 /*
3047 * If we're in single user mode, we want to quit immediately - we can't
3048 * rely on latches as they wouldn't work when stdin/stdout is a file.
3049 * Rather ugly, but it's unlikely to be worthwhile to invest much more
3050 * effort just for the benefit of single user mode.
3051 */
3054}
@ DestRemote
Definition: dest.h:89
volatile sig_atomic_t InterruptPending
Definition: globals.c:32
struct Latch * MyLatch
Definition: globals.c:63
volatile sig_atomic_t ProcDiePending
Definition: globals.c:34
bool proc_exit_inprogress
Definition: ipc.c:40
void SetLatch(Latch *latch)
Definition: latch.c:290
@ DISCONNECT_KILLED
Definition: pgstat.h:59
SessionEndType pgStatSessionEndCause
CommandDest whereToSendOutput
Definition: postgres.c:91
static bool DoingCommandRead
Definition: postgres.c:136
void ProcessInterrupts(void)
Definition: postgres.c:3303

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

Referenced by PostgresMain().

◆ FloatExceptionHandler()

pg_noreturn void FloatExceptionHandler ( SIGNAL_ARGS  )

Definition at line 3078 of file postgres.c.

3079{
3080 /* We're not returning, so no need to save errno */
3081 ereport(ERROR,
3082 (errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
3083 errmsg("floating-point exception"),
3084 errdetail("An invalid floating-point operation was signaled. "
3085 "This probably means an out-of-range result or an "
3086 "invalid operation, such as division by zero.")));
3087}
int errdetail(const char *fmt,...)
Definition: elog.c:1207
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:150

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

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

◆ get_stats_option_name()

const char * get_stats_option_name ( const char *  arg)

Definition at line 3758 of file postgres.c.

3759{
3760 switch (arg[0])
3761 {
3762 case 'p':
3763 if (optarg[1] == 'a') /* "parser" */
3764 return "log_parser_stats";
3765 else if (optarg[1] == 'l') /* "planner" */
3766 return "log_planner_stats";
3767 break;
3768
3769 case 'e': /* "executor" */
3770 return "log_executor_stats";
3771 break;
3772 }
3773
3774 return NULL;
3775}
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 3094 of file postgres.c.

3095{
3096 RecoveryConflictPendingReasons[reason] = true;
3098 InterruptPending = true;
3099 /* latch will be set by procsignal_sigusr1_handler */
3100}
static volatile sig_atomic_t RecoveryConflictPendingReasons[NUM_PROCSIGNALS]
Definition: postgres.c:159
static volatile sig_atomic_t RecoveryConflictPending
Definition: postgres.c:158

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 669 of file postgres.c.

674{
675 Query *query;
676 List *querytree_list;
677
678 TRACE_POSTGRESQL_QUERY_REWRITE_START(query_string);
679
680 /*
681 * (1) Perform parse analysis.
682 */
684 ResetUsage();
685
686 query = parse_analyze_fixedparams(parsetree, query_string, paramTypes, numParams,
687 queryEnv);
688
690 ShowUsage("PARSE ANALYSIS STATISTICS");
691
692 /*
693 * (2) Rewrite the queries, as necessary
694 */
695 querytree_list = pg_rewrite_query(query);
696
697 TRACE_POSTGRESQL_QUERY_REWRITE_DONE(query_string);
698
699 return querytree_list;
700}
bool log_parser_stats
Definition: guc_tables.c:520
Query * parse_analyze_fixedparams(RawStmt *parseTree, const char *sourceText, const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv)
Definition: analyze.c:116
List * pg_rewrite_query(Query *query)
Definition: postgres.c:802
void ShowUsage(const char *title)
Definition: postgres.c:5067
void ResetUsage(void)
Definition: postgres.c:5060
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 708 of file postgres.c.

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

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 762 of file postgres.c.

767{
768 Query *query;
769 List *querytree_list;
770
771 TRACE_POSTGRESQL_QUERY_REWRITE_START(query_string);
772
773 /*
774 * (1) Perform parse analysis.
775 */
777 ResetUsage();
778
779 query = parse_analyze_withcb(parsetree, query_string, parserSetup, parserSetupArg,
780 queryEnv);
781
783 ShowUsage("PARSE ANALYSIS STATISTICS");
784
785 /*
786 * (2) Rewrite the queries, as necessary
787 */
788 querytree_list = pg_rewrite_query(query);
789
790 TRACE_POSTGRESQL_QUERY_REWRITE_DONE(query_string);
791
792 return querytree_list;
793}
Query * parse_analyze_withcb(RawStmt *parseTree, const char *sourceText, ParserSetupHook parserSetup, void *parserSetupArg, QueryEnvironment *queryEnv)
Definition: analyze.c:197

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

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

◆ pg_parse_query()

List * pg_parse_query ( const char *  query_string)

Definition at line 603 of file postgres.c.

604{
605 List *raw_parsetree_list;
606
607 TRACE_POSTGRESQL_QUERY_PARSE_START(query_string);
608
610 ResetUsage();
611
612 raw_parsetree_list = raw_parser(query_string, RAW_PARSE_DEFAULT);
613
615 ShowUsage("PARSER STATISTICS");
616
617#ifdef DEBUG_NODE_TESTS_ENABLED
618
619 /* Optional debugging check: pass raw parsetrees through copyObject() */
620 if (Debug_copy_parse_plan_trees)
621 {
622 List *new_list = copyObject(raw_parsetree_list);
623
624 /* This checks both copyObject() and the equal() routines... */
625 if (!equal(new_list, raw_parsetree_list))
626 elog(WARNING, "copyObject() failed to produce an equal raw parse tree");
627 else
628 raw_parsetree_list = new_list;
629 }
630
631 /*
632 * Optional debugging check: pass raw parsetrees through
633 * outfuncs/readfuncs
634 */
635 if (Debug_write_read_parse_plan_trees)
636 {
637 char *str = nodeToStringWithLocations(raw_parsetree_list);
638 List *new_list = stringToNodeWithLocations(str);
639
640 pfree(str);
641 /* This checks both outfuncs/readfuncs and the equal() routines... */
642 if (!equal(new_list, raw_parsetree_list))
643 elog(WARNING, "outfuncs/readfuncs failed to produce an equal raw parse tree");
644 else
645 raw_parsetree_list = new_list;
646 }
647
648#endif /* DEBUG_NODE_TESTS_ENABLED */
649
650 TRACE_POSTGRESQL_QUERY_PARSE_DONE(query_string);
651
653 elog_node_display(LOG, "raw parse tree", raw_parsetree_list,
655
656 return raw_parsetree_list;
657}
void elog_node_display(int lev, const char *title, const void *obj, bool pretty)
Definition: print.c:72
List * raw_parser(const char *str, RawParseMode mode)
Definition: parser.c:42
#define LOG
Definition: elog.h:31
#define WARNING
Definition: elog.h:36
#define elog(elevel,...)
Definition: elog.h:226
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223
bool Debug_print_raw_parse
Definition: guc_tables.c:510
bool Debug_pretty_print
Definition: guc_tables.c:512
const char * str
static List * new_list(NodeTag type, int min_size)
Definition: list.c:91
void pfree(void *pointer)
Definition: mcxt.c:1594
#define copyObject(obj)
Definition: nodes.h:232
char * nodeToStringWithLocations(const void *obj)
Definition: outfuncs.c:811
@ RAW_PARSE_DEFAULT
Definition: parser.h:39

References copyObject, Debug_pretty_print, Debug_print_raw_parse, elog, elog_node_display(), equal(), LOG, 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(), inline_function(), inline_set_returning_function(), and sql_compile_callback().

◆ pg_plan_queries()

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

Definition at line 974 of file postgres.c.

976{
977 List *stmt_list = NIL;
978 ListCell *query_list;
979
980 foreach(query_list, querytrees)
981 {
982 Query *query = lfirst_node(Query, query_list);
984
985 if (query->commandType == CMD_UTILITY)
986 {
987 /* Utility commands require no planning. */
989 stmt->commandType = CMD_UTILITY;
990 stmt->canSetTag = query->canSetTag;
991 stmt->utilityStmt = query->utilityStmt;
992 stmt->stmt_location = query->stmt_location;
993 stmt->stmt_len = query->stmt_len;
994 stmt->queryId = query->queryId;
995 stmt->planOrigin = PLAN_STMT_INTERNAL;
996 }
997 else
998 {
999 stmt = pg_plan_query(query, query_string, cursorOptions,
1000 boundParams);
1001 }
1002
1003 stmt_list = lappend(stmt_list, stmt);
1004 }
1005
1006 return stmt_list;
1007}
#define stmt
Definition: indent_codes.h:59
List * lappend(List *list, void *datum)
Definition: list.c:339
@ CMD_UTILITY
Definition: nodes.h:280
#define makeNode(_type_)
Definition: nodes.h:161
#define lfirst_node(type, lc)
Definition: pg_list.h:176
#define NIL
Definition: pg_list.h:68
@ PLAN_STMT_INTERNAL
Definition: plannodes.h:40
PlannedStmt * pg_plan_query(Query *querytree, const char *query_string, int cursorOptions, ParamListInfo boundParams)
Definition: postgres.c:886
CmdType commandType
Definition: parsenodes.h:121
Node * utilityStmt
Definition: parsenodes.h:141
ParseLoc stmt_location
Definition: parsenodes.h:255

References CMD_UTILITY, Query::commandType, lappend(), lfirst_node, makeNode, NIL, pg_plan_query(), PLAN_STMT_INTERNAL, 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 886 of file postgres.c.

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

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(), PerformCursorOpen(), pg_plan_queries(), refresh_matview_datafill(), and standard_ExplainOneQuery().

◆ pg_rewrite_query()

List * pg_rewrite_query ( Query query)

Definition at line 802 of file postgres.c.

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

◆ PostgresMain()

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

Definition at line 4192 of file postgres.c.

4193{
4194 sigjmp_buf local_sigjmp_buf;
4195
4196 /* these must be volatile to ensure state is preserved across longjmp: */
4197 volatile bool send_ready_for_query = true;
4198 volatile bool idle_in_transaction_timeout_enabled = false;
4199 volatile bool idle_session_timeout_enabled = false;
4200
4201 Assert(dbname != NULL);
4202 Assert(username != NULL);
4203
4205
4206 /*
4207 * Set up signal handlers. (InitPostmasterChild or InitStandaloneProcess
4208 * has already set up BlockSig and made that the active signal mask.)
4209 *
4210 * Note that postmaster blocked all signals before forking child process,
4211 * so there is no race condition whereby we might receive a signal before
4212 * we have set up the handler.
4213 *
4214 * Also note: it's best not to use any signals that are SIG_IGNored in the
4215 * postmaster. If such a signal arrives before we are able to change the
4216 * handler to non-SIG_IGN, it'll get dropped. Instead, make a dummy
4217 * handler in the postmaster to reserve the signal. (Of course, this isn't
4218 * an issue for signals that are locally generated, such as SIGALRM and
4219 * SIGPIPE.)
4220 */
4221 if (am_walsender)
4222 WalSndSignals();
4223 else
4224 {
4226 pqsignal(SIGINT, StatementCancelHandler); /* cancel current query */
4227 pqsignal(SIGTERM, die); /* cancel current query and exit */
4228
4229 /*
4230 * In a postmaster child backend, replace SignalHandlerForCrashExit
4231 * with quickdie, so we can tell the client we're dying.
4232 *
4233 * In a standalone backend, SIGQUIT can be generated from the keyboard
4234 * easily, while SIGTERM cannot, so we make both signals do die()
4235 * rather than quickdie().
4236 */
4238 pqsignal(SIGQUIT, quickdie); /* hard crash time */
4239 else
4240 pqsignal(SIGQUIT, die); /* cancel current query and exit */
4241 InitializeTimeouts(); /* establishes SIGALRM handler */
4242
4243 /*
4244 * Ignore failure to write to frontend. Note: if frontend closes
4245 * connection, we will notice it and exit cleanly when control next
4246 * returns to outer loop. This seems safer than forcing exit in the
4247 * midst of output during who-knows-what operation...
4248 */
4249 pqsignal(SIGPIPE, SIG_IGN);
4251 pqsignal(SIGUSR2, SIG_IGN);
4253
4254 /*
4255 * Reset some signals that are accepted by postmaster but not by
4256 * backend
4257 */
4258 pqsignal(SIGCHLD, SIG_DFL); /* system() requires this on some
4259 * platforms */
4260 }
4261
4262 /* Early initialization */
4263 BaseInit();
4264
4265 /* We need to allow SIGINT, etc during the initial transaction */
4266 sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
4267
4268 /*
4269 * Generate a random cancel key, if this is a backend serving a
4270 * connection. InitPostgres() will advertise it in shared memory.
4271 */
4274 {
4275 int len;
4276
4277 len = (MyProcPort == NULL || MyProcPort->proto >= PG_PROTOCOL(3, 2))
4280 {
4281 ereport(ERROR,
4282 (errcode(ERRCODE_INTERNAL_ERROR),
4283 errmsg("could not generate random cancel key")));
4284 }
4286 }
4287
4288 /*
4289 * General initialization.
4290 *
4291 * NOTE: if you are tempted to add code in this vicinity, consider putting
4292 * it inside InitPostgres() instead. In particular, anything that
4293 * involves database access should be there, not here.
4294 *
4295 * Honor session_preload_libraries if not dealing with a WAL sender.
4296 */
4297 InitPostgres(dbname, InvalidOid, /* database to connect to */
4298 username, InvalidOid, /* role to connect as */
4300 NULL); /* no out_dbname */
4301
4302 /*
4303 * If the PostmasterContext is still around, recycle the space; we don't
4304 * need it anymore after InitPostgres completes.
4305 */
4307 {
4309 PostmasterContext = NULL;
4310 }
4311
4313
4314 /*
4315 * Now all GUC states are fully set up. Report them to client if
4316 * appropriate.
4317 */
4319
4320 /*
4321 * Also set up handler to log session end; we have to wait till now to be
4322 * sure Log_disconnections has its final value.
4323 */
4326
4328
4329 /* Perform initialization specific to a WAL sender process. */
4330 if (am_walsender)
4331 InitWalSender();
4332
4333 /*
4334 * Send this backend's cancellation info to the frontend.
4335 */
4337 {
4339
4343
4346 /* Need not flush since ReadyForQuery will do it. */
4347 }
4348
4349 /* Welcome banner for standalone case */
4351 printf("\nPostgreSQL stand-alone backend %s\n", PG_VERSION);
4352
4353 /*
4354 * Create the memory context we will use in the main loop.
4355 *
4356 * MessageContext is reset once per iteration of the main loop, ie, upon
4357 * completion of processing of each command message from the client.
4358 */
4360 "MessageContext",
4362
4363 /*
4364 * Create memory context and buffer used for RowDescription messages. As
4365 * SendRowDescriptionMessage(), via exec_describe_statement_message(), is
4366 * frequently executed for ever single statement, we don't want to
4367 * allocate a separate buffer every time.
4368 */
4370 "RowDescriptionContext",
4375
4376 /* Fire any defined login event triggers, if appropriate */
4378
4379 /*
4380 * POSTGRES main processing loop begins here
4381 *
4382 * If an exception is encountered, processing resumes here so we abort the
4383 * current transaction and start a new one.
4384 *
4385 * You might wonder why this isn't coded as an infinite loop around a
4386 * PG_TRY construct. The reason is that this is the bottom of the
4387 * exception stack, and so with PG_TRY there would be no exception handler
4388 * in force at all during the CATCH part. By leaving the outermost setjmp
4389 * always active, we have at least some chance of recovering from an error
4390 * during error recovery. (If we get into an infinite loop thereby, it
4391 * will soon be stopped by overflow of elog.c's internal state stack.)
4392 *
4393 * Note that we use sigsetjmp(..., 1), so that this function's signal mask
4394 * (to wit, UnBlockSig) will be restored when longjmp'ing to here. This
4395 * is essential in case we longjmp'd out of a signal handler on a platform
4396 * where that leaves the signal blocked. It's not redundant with the
4397 * unblock in AbortTransaction() because the latter is only called if we
4398 * were inside a transaction.
4399 */
4400
4401 if (sigsetjmp(local_sigjmp_buf, 1) != 0)
4402 {
4403 /*
4404 * NOTE: if you are tempted to add more code in this if-block,
4405 * consider the high probability that it should be in
4406 * AbortTransaction() instead. The only stuff done directly here
4407 * should be stuff that is guaranteed to apply *only* for outer-level
4408 * error recovery, such as adjusting the FE/BE protocol status.
4409 */
4410
4411 /* Since not using PG_TRY, must reset error stack by hand */
4412 error_context_stack = NULL;
4413
4414 /* Prevent interrupts while cleaning up */
4416
4417 /*
4418 * Forget any pending QueryCancel request, since we're returning to
4419 * the idle loop anyway, and cancel any active timeout requests. (In
4420 * future we might want to allow some timeout requests to survive, but
4421 * at minimum it'd be necessary to do reschedule_timeouts(), in case
4422 * we got here because of a query cancel interrupting the SIGALRM
4423 * interrupt handler.) Note in particular that we must clear the
4424 * statement and lock timeout indicators, to prevent any future plain
4425 * query cancels from being misreported as timeouts in case we're
4426 * forgetting a timeout cancel.
4427 */
4428 disable_all_timeouts(false); /* do first to avoid race condition */
4429 QueryCancelPending = false;
4430 idle_in_transaction_timeout_enabled = false;
4431 idle_session_timeout_enabled = false;
4432
4433 /* Not reading from the client anymore. */
4434 DoingCommandRead = false;
4435
4436 /* Make sure libpq is in a good state */
4437 pq_comm_reset();
4438
4439 /* Report the error to the client and/or server log */
4441
4442 /*
4443 * If Valgrind noticed something during the erroneous query, print the
4444 * query string, assuming we have one.
4445 */
4447
4448 /*
4449 * Make sure debug_query_string gets reset before we possibly clobber
4450 * the storage it points at.
4451 */
4452 debug_query_string = NULL;
4453
4454 /*
4455 * Abort the current transaction in order to recover.
4456 */
4458
4459 if (am_walsender)
4461
4463
4464 /*
4465 * We can't release replication slots inside AbortTransaction() as we
4466 * need to be able to start and abort transactions while having a slot
4467 * acquired. But we never need to hold them across top level errors,
4468 * so releasing here is fine. There also is a before_shmem_exit()
4469 * callback ensuring correct cleanup on FATAL errors.
4470 */
4471 if (MyReplicationSlot != NULL)
4473
4474 /* We also want to cleanup temporary slots on error. */
4476
4478
4479 /*
4480 * Now return to normal top-level context and clear ErrorContext for
4481 * next time.
4482 */
4485
4486 /*
4487 * If we were handling an extended-query-protocol message, initiate
4488 * skip till next Sync. This also causes us not to issue
4489 * ReadyForQuery (until we get Sync).
4490 */
4492 ignore_till_sync = true;
4493
4494 /* We don't have a transaction command open anymore */
4495 xact_started = false;
4496
4497 /*
4498 * If an error occurred while we were reading a message from the
4499 * client, we have potentially lost track of where the previous
4500 * message ends and the next one begins. Even though we have
4501 * otherwise recovered from the error, we cannot safely read any more
4502 * messages from the client, so there isn't much we can do with the
4503 * connection anymore.
4504 */
4505 if (pq_is_reading_msg())
4506 ereport(FATAL,
4507 (errcode(ERRCODE_PROTOCOL_VIOLATION),
4508 errmsg("terminating connection because protocol synchronization was lost")));
4509
4510 /* Now we can allow interrupts again */
4512 }
4513
4514 /* We can now handle ereport(ERROR) */
4515 PG_exception_stack = &local_sigjmp_buf;
4516
4517 if (!ignore_till_sync)
4518 send_ready_for_query = true; /* initially, or after error */
4519
4520 /*
4521 * Non-error queries loop here.
4522 */
4523
4524 for (;;)
4525 {
4526 int firstchar;
4527 StringInfoData input_message;
4528
4529 /*
4530 * At top of loop, reset extended-query-message flag, so that any
4531 * errors encountered in "idle" state don't provoke skip.
4532 */
4534
4535 /*
4536 * For valgrind reporting purposes, the "current query" begins here.
4537 */
4538#ifdef USE_VALGRIND
4539 old_valgrind_error_count = VALGRIND_COUNT_ERRORS;
4540#endif
4541
4542 /*
4543 * Release storage left over from prior query cycle, and create a new
4544 * query input buffer in the cleared MessageContext.
4545 */
4548
4549 initStringInfo(&input_message);
4550
4551 /*
4552 * Also consider releasing our catalog snapshot if any, so that it's
4553 * not preventing advance of global xmin while we wait for the client.
4554 */
4556
4557 /*
4558 * (1) If we've reached idle state, tell the frontend we're ready for
4559 * a new query.
4560 *
4561 * Note: this includes fflush()'ing the last of the prior output.
4562 *
4563 * This is also a good time to flush out collected statistics to the
4564 * cumulative stats system, and to update the PS stats display. We
4565 * avoid doing those every time through the message loop because it'd
4566 * slow down processing of batched messages, and because we don't want
4567 * to report uncommitted updates (that confuses autovacuum). The
4568 * notification processor wants a call too, if we are not in a
4569 * transaction block.
4570 *
4571 * Also, if an idle timeout is enabled, start the timer for that.
4572 */
4573 if (send_ready_for_query)
4574 {
4576 {
4577 set_ps_display("idle in transaction (aborted)");
4579
4580 /* Start the idle-in-transaction timer */
4583 {
4584 idle_in_transaction_timeout_enabled = true;
4587 }
4588 }
4590 {
4591 set_ps_display("idle in transaction");
4593
4594 /* Start the idle-in-transaction timer */
4597 {
4598 idle_in_transaction_timeout_enabled = true;
4601 }
4602 }
4603 else
4604 {
4605 long stats_timeout;
4606
4607 /*
4608 * Process incoming notifies (including self-notifies), if
4609 * any, and send relevant messages to the client. Doing it
4610 * here helps ensure stable behavior in tests: if any notifies
4611 * were received during the just-finished transaction, they'll
4612 * be seen by the client before ReadyForQuery is.
4613 */
4616
4617 /*
4618 * Check if we need to report stats. If pgstat_report_stat()
4619 * decides it's too soon to flush out pending stats / lock
4620 * contention prevented reporting, it'll tell us when we
4621 * should try to report stats again (so that stats updates
4622 * aren't unduly delayed if the connection goes idle for a
4623 * long time). We only enable the timeout if we don't already
4624 * have a timeout in progress, because we don't disable the
4625 * timeout below. enable_timeout_after() needs to determine
4626 * the current timestamp, which can have a negative
4627 * performance impact. That's OK because pgstat_report_stat()
4628 * won't have us wake up sooner than a prior call.
4629 */
4630 stats_timeout = pgstat_report_stat(false);
4631 if (stats_timeout > 0)
4632 {
4635 stats_timeout);
4636 }
4637 else
4638 {
4639 /* all stats flushed, no need for the timeout */
4642 }
4643
4644 set_ps_display("idle");
4646
4647 /* Start the idle-session timer */
4648 if (IdleSessionTimeout > 0)
4649 {
4650 idle_session_timeout_enabled = true;
4653 }
4654 }
4655
4656 /* Report any recently-changed GUC options */
4658
4659 /*
4660 * The first time this backend is ready for query, log the
4661 * durations of the different components of connection
4662 * establishment and setup.
4663 */
4667 {
4668 uint64 total_duration,
4669 fork_duration,
4670 auth_duration;
4671
4673
4674 total_duration =
4677 fork_duration =
4680 auth_duration =
4683
4684 ereport(LOG,
4685 errmsg("connection ready: setup total=%.3f ms, fork=%.3f ms, authentication=%.3f ms",
4686 (double) total_duration / NS_PER_US,
4687 (double) fork_duration / NS_PER_US,
4688 (double) auth_duration / NS_PER_US));
4689 }
4690
4692 send_ready_for_query = false;
4693 }
4694
4695 /*
4696 * (2) Allow asynchronous signals to be executed immediately if they
4697 * come in while we are waiting for client input. (This must be
4698 * conditional since we don't want, say, reads on behalf of COPY FROM
4699 * STDIN doing the same thing.)
4700 */
4701 DoingCommandRead = true;
4702
4703 /*
4704 * (3) read a command (loop blocks here)
4705 */
4706 firstchar = ReadCommand(&input_message);
4707
4708 /*
4709 * (4) turn off the idle-in-transaction and idle-session timeouts if
4710 * active. We do this before step (5) so that any last-moment timeout
4711 * is certain to be detected in step (5).
4712 *
4713 * At most one of these timeouts will be active, so there's no need to
4714 * worry about combining the timeout.c calls into one.
4715 */
4716 if (idle_in_transaction_timeout_enabled)
4717 {
4719 idle_in_transaction_timeout_enabled = false;
4720 }
4721 if (idle_session_timeout_enabled)
4722 {
4724 idle_session_timeout_enabled = false;
4725 }
4726
4727 /*
4728 * (5) disable async signal conditions again.
4729 *
4730 * Query cancel is supposed to be a no-op when there is no query in
4731 * progress, so if a query cancel arrived while we were idle, just
4732 * reset QueryCancelPending. ProcessInterrupts() has that effect when
4733 * it's called when DoingCommandRead is set, so check for interrupts
4734 * before resetting DoingCommandRead.
4735 */
4737 DoingCommandRead = false;
4738
4739 /*
4740 * (6) check for any other interesting events that happened while we
4741 * slept.
4742 */
4744 {
4745 ConfigReloadPending = false;
4747 }
4748
4749 /*
4750 * (7) process the command. But ignore it if we're skipping till
4751 * Sync.
4752 */
4753 if (ignore_till_sync && firstchar != EOF)
4754 continue;
4755
4756 switch (firstchar)
4757 {
4758 case PqMsg_Query:
4759 {
4760 const char *query_string;
4761
4762 /* Set statement_timestamp() */
4764
4765 query_string = pq_getmsgstring(&input_message);
4766 pq_getmsgend(&input_message);
4767
4768 if (am_walsender)
4769 {
4770 if (!exec_replication_command(query_string))
4771 exec_simple_query(query_string);
4772 }
4773 else
4774 exec_simple_query(query_string);
4775
4776 valgrind_report_error_query(query_string);
4777
4778 send_ready_for_query = true;
4779 }
4780 break;
4781
4782 case PqMsg_Parse:
4783 {
4784 const char *stmt_name;
4785 const char *query_string;
4786 int numParams;
4787 Oid *paramTypes = NULL;
4788
4789 forbidden_in_wal_sender(firstchar);
4790
4791 /* Set statement_timestamp() */
4793
4794 stmt_name = pq_getmsgstring(&input_message);
4795 query_string = pq_getmsgstring(&input_message);
4796 numParams = pq_getmsgint(&input_message, 2);
4797 if (numParams > 0)
4798 {
4799 paramTypes = palloc_array(Oid, numParams);
4800 for (int i = 0; i < numParams; i++)
4801 paramTypes[i] = pq_getmsgint(&input_message, 4);
4802 }
4803 pq_getmsgend(&input_message);
4804
4805 exec_parse_message(query_string, stmt_name,
4806 paramTypes, numParams);
4807
4808 valgrind_report_error_query(query_string);
4809 }
4810 break;
4811
4812 case PqMsg_Bind:
4813 forbidden_in_wal_sender(firstchar);
4814
4815 /* Set statement_timestamp() */
4817
4818 /*
4819 * this message is complex enough that it seems best to put
4820 * the field extraction out-of-line
4821 */
4822 exec_bind_message(&input_message);
4823
4824 /* exec_bind_message does valgrind_report_error_query */
4825 break;
4826
4827 case PqMsg_Execute:
4828 {
4829 const char *portal_name;
4830 int max_rows;
4831
4832 forbidden_in_wal_sender(firstchar);
4833
4834 /* Set statement_timestamp() */
4836
4837 portal_name = pq_getmsgstring(&input_message);
4838 max_rows = pq_getmsgint(&input_message, 4);
4839 pq_getmsgend(&input_message);
4840
4841 exec_execute_message(portal_name, max_rows);
4842
4843 /* exec_execute_message does valgrind_report_error_query */
4844 }
4845 break;
4846
4847 case PqMsg_FunctionCall:
4848 forbidden_in_wal_sender(firstchar);
4849
4850 /* Set statement_timestamp() */
4852
4853 /* Report query to various monitoring facilities. */
4855 set_ps_display("<FASTPATH>");
4856
4857 /* start an xact for this function invocation */
4859
4860 /*
4861 * Note: we may at this point be inside an aborted
4862 * transaction. We can't throw error for that until we've
4863 * finished reading the function-call message, so
4864 * HandleFunctionRequest() must check for it after doing so.
4865 * Be careful not to do anything that assumes we're inside a
4866 * valid transaction here.
4867 */
4868
4869 /* switch back to message context */
4871
4872 HandleFunctionRequest(&input_message);
4873
4874 /* commit the function-invocation transaction */
4876
4877 valgrind_report_error_query("fastpath function call");
4878
4879 send_ready_for_query = true;
4880 break;
4881
4882 case PqMsg_Close:
4883 {
4884 int close_type;
4885 const char *close_target;
4886
4887 forbidden_in_wal_sender(firstchar);
4888
4889 close_type = pq_getmsgbyte(&input_message);
4890 close_target = pq_getmsgstring(&input_message);
4891 pq_getmsgend(&input_message);
4892
4893 switch (close_type)
4894 {
4895 case 'S':
4896 if (close_target[0] != '\0')
4897 DropPreparedStatement(close_target, false);
4898 else
4899 {
4900 /* special-case the unnamed statement */
4902 }
4903 break;
4904 case 'P':
4905 {
4906 Portal portal;
4907
4908 portal = GetPortalByName(close_target);
4909 if (PortalIsValid(portal))
4910 PortalDrop(portal, false);
4911 }
4912 break;
4913 default:
4914 ereport(ERROR,
4915 (errcode(ERRCODE_PROTOCOL_VIOLATION),
4916 errmsg("invalid CLOSE message subtype %d",
4917 close_type)));
4918 break;
4919 }
4920
4923
4924 valgrind_report_error_query("CLOSE message");
4925 }
4926 break;
4927
4928 case PqMsg_Describe:
4929 {
4930 int describe_type;
4931 const char *describe_target;
4932
4933 forbidden_in_wal_sender(firstchar);
4934
4935 /* Set statement_timestamp() (needed for xact) */
4937
4938 describe_type = pq_getmsgbyte(&input_message);
4939 describe_target = pq_getmsgstring(&input_message);
4940 pq_getmsgend(&input_message);
4941
4942 switch (describe_type)
4943 {
4944 case 'S':
4945 exec_describe_statement_message(describe_target);
4946 break;
4947 case 'P':
4948 exec_describe_portal_message(describe_target);
4949 break;
4950 default:
4951 ereport(ERROR,
4952 (errcode(ERRCODE_PROTOCOL_VIOLATION),
4953 errmsg("invalid DESCRIBE message subtype %d",
4954 describe_type)));
4955 break;
4956 }
4957
4958 valgrind_report_error_query("DESCRIBE message");
4959 }
4960 break;
4961
4962 case PqMsg_Flush:
4963 pq_getmsgend(&input_message);
4965 pq_flush();
4966 break;
4967
4968 case PqMsg_Sync:
4969 pq_getmsgend(&input_message);
4970
4971 /*
4972 * If pipelining was used, we may be in an implicit
4973 * transaction block. Close it before calling
4974 * finish_xact_command.
4975 */
4978 valgrind_report_error_query("SYNC message");
4979 send_ready_for_query = true;
4980 break;
4981
4982 /*
4983 * PqMsg_Terminate means that the frontend is closing down the
4984 * socket. EOF means unexpected loss of frontend connection.
4985 * Either way, perform normal shutdown.
4986 */
4987 case EOF:
4988
4989 /* for the cumulative statistics system */
4991
4992 /* FALLTHROUGH */
4993
4994 case PqMsg_Terminate:
4995
4996 /*
4997 * Reset whereToSendOutput to prevent ereport from attempting
4998 * to send any more messages to client.
4999 */
5002
5003 /*
5004 * NOTE: if you are tempted to add more code here, DON'T!
5005 * Whatever you had in mind to do should be set up as an
5006 * on_proc_exit or on_shmem_exit callback, instead. Otherwise
5007 * it will fail to be called during other backend-shutdown
5008 * scenarios.
5009 */
5010 proc_exit(0);
5011
5012 case PqMsg_CopyData:
5013 case PqMsg_CopyDone:
5014 case PqMsg_CopyFail:
5015
5016 /*
5017 * Accept but ignore these messages, per protocol spec; we
5018 * probably got here because a COPY failed, and the frontend
5019 * is still sending data.
5020 */
5021 break;
5022
5023 default:
5024 ereport(FATAL,
5025 (errcode(ERRCODE_PROTOCOL_VIOLATION),
5026 errmsg("invalid frontend message type %d",
5027 firstchar)));
5028 }
5029 } /* end of input-reading loop */
5030}
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:519
sigset_t UnBlockSig
Definition: pqsignal.c:22
uint32 log_connections
ConnectionTiming conn_timing
@ LOG_CONNECTION_SETUP_DURATIONS
void pgstat_report_activity(BackendState state, const char *cmd_str)
@ STATE_IDLEINTRANSACTION_ABORTED
@ STATE_IDLE
@ STATE_IDLEINTRANSACTION
@ STATE_FASTPATH
int32_t int32
Definition: c.h:535
uint64_t uint64
Definition: c.h:540
#define TIMESTAMP_MINUS_INFINITY
Definition: timestamp.h:150
void ReadyForQuery(CommandDest dest)
Definition: dest.c:256
@ DestDebug
Definition: dest.h:88
@ DestNone
Definition: dest.h:87
void EmitErrorReport(void)
Definition: elog.c:1695
ErrorContextCallback * error_context_stack
Definition: elog.c:95
void FlushErrorState(void)
Definition: elog.c:1875
sigjmp_buf * PG_exception_stack
Definition: elog.c:97
#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
int MyCancelKeyLength
Definition: globals.c:53
int MyProcPid
Definition: globals.c:47
bool IsUnderPostmaster
Definition: globals.c:120
volatile sig_atomic_t QueryCancelPending
Definition: globals.c:33
uint8 MyCancelKey[MAX_CANCEL_KEY_LENGTH]
Definition: globals.c:52
struct Port * MyProcPort
Definition: globals.c:51
Oid MyDatabaseId
Definition: globals.c:94
void ProcessConfigFile(GucContext context)
Definition: guc-file.l:120
void BeginReportingGUCOptions(void)
Definition: guc.c:2551
void ReportChangedGUCOptions(void)
Definition: guc.c:2601
@ PGC_SIGHUP
Definition: guc.h:75
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:170
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:400
MemoryContext TopMemoryContext
Definition: mcxt.c:166
MemoryContext PostmasterContext
Definition: mcxt.c:168
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:469
#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:471
@ InitProcessing
Definition: miscadmin.h:470
#define IsExternalConnectionBackend(backend_type)
Definition: miscadmin.h:404
#define GetProcessingMode()
Definition: miscadmin.h:480
#define INIT_PG_LOAD_SESSION_LIBS
Definition: miscadmin.h:498
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:133
#define SetProcessingMode(mode)
Definition: miscadmin.h:482
BackendType MyBackendType
Definition: miscinit.c:64
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
const void size_t len
static char * buf
Definition: pg_test_fsync.c:72
long pgstat_report_stat(bool force)
Definition: pgstat.c:692
@ DISCONNECT_CLIENT_EOF
Definition: pgstat.h:57
void pgstat_report_connect(Oid dboid)
#define pqsignal
Definition: port.h:531
bool pg_strong_random(void *buf, size_t len)
#define printf(...)
Definition: port.h:245
#define PortalIsValid(p)
Definition: portal.h:211
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:2646
void quickdie(SIGNAL_ARGS)
Definition: postgres.c:2934
static void log_disconnections(int code, Datum arg)
Definition: postgres.c:5176
static void forbidden_in_wal_sender(char firstchar)
Definition: postgres.c:5040
static void exec_execute_message(const char *portal_name, long max_rows)
Definition: postgres.c:2112
void FloatExceptionHandler(SIGNAL_ARGS)
Definition: postgres.c:3078
void StatementCancelHandler(SIGNAL_ARGS)
Definition: postgres.c:3061
static bool ignore_till_sync
Definition: postgres.c:143
static void finish_xact_command(void)
Definition: postgres.c:2830
const char * debug_query_string
Definition: postgres.c:88
static void exec_simple_query(const char *query_string)
Definition: postgres.c:1016
static void exec_parse_message(const char *query_string, const char *stmt_name, Oid *paramTypes, int numParams)
Definition: postgres.c:1394
static void exec_bind_message(StringInfo input_message)
Definition: postgres.c:1629
void die(SIGNAL_ARGS)
Definition: postgres.c:3031
static bool xact_started
Definition: postgres.c:129
static MemoryContext row_description_context
Definition: postgres.c:162
static StringInfoData row_description_buf
Definition: postgres.c:163
static bool doing_extended_query_message
Definition: postgres.c:142
static void start_xact_command(void)
Definition: postgres.c:2791
static void exec_describe_portal_message(const char *portal_name)
Definition: postgres.c:2739
bool Log_disconnections
Definition: postgres.c:94
static void drop_unnamed_stmt(void)
Definition: postgres.c:2909
#define valgrind_report_error_query(query)
Definition: postgres.c:216
static int ReadCommand(StringInfo inBuf)
Definition: postgres.c:480
void BaseInit(void)
Definition: postinit.c:611
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bits32 flags, char *out_dbname)
Definition: postinit.c:711
bool pq_is_reading_msg(void)
Definition: pqcomm.c:1181
#define PG_PROTOCOL(m, n)
Definition: pqcomm.h:90
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:415
void pq_sendbytes(StringInfo buf, const void *data, int datalen)
Definition: pqformat.c:126
void pq_getmsgend(StringInfo msg)
Definition: pqformat.c:635
const char * pq_getmsgstring(StringInfo msg)
Definition: pqformat.c:579
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:674
#define MAX_CANCEL_KEY_LENGTH
Definition: procsignal.h:67
#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
ReplicationSlot * MyReplicationSlot
Definition: slot.c:148
void ReplicationSlotRelease(void)
Definition: slot.c:731
void ReplicationSlotCleanup(bool synced_only)
Definition: slot.c:820
void InvalidateCatalogSnapshotConditionally(void)
Definition: snapmgr.c:475
int IdleSessionTimeout
Definition: proc.c:62
int IdleInTransactionSessionTimeout
Definition: proc.c:60
int TransactionTimeout
Definition: proc.c:61
char * dbname
Definition: streamutil.c:49
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
TimestampTz ready_for_use
TimestampTz auth_start
TimestampTz socket_create
TimestampTz fork_start
TimestampTz auth_end
TimestampTz fork_end
ProtocolVersion proto
Definition: libpq-be.h:132
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
static uint64 TimestampDifferenceMicroseconds(TimestampTz start_time, TimestampTz stop_time)
Definition: timestamp.h:90
#define NS_PER_US
Definition: uuid.c:33
void WalSndErrorCleanup(void)
Definition: walsender.c:334
bool am_walsender
Definition: walsender.c:123
bool exec_replication_command(const char *cmd_string)
Definition: walsender.c:1974
void InitWalSender(void)
Definition: walsender.c:287
void WalSndSignals(void)
Definition: walsender.c:3703
#define SIGCHLD
Definition: win32_port.h:168
#define SIGHUP
Definition: win32_port.h:158
#define SIGPIPE
Definition: win32_port.h:163
#define SIGQUIT
Definition: win32_port.h:159
#define SIGUSR1
Definition: win32_port.h:170
#define SIGUSR2
Definition: win32_port.h:171
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:5001
bool IsAbortedTransactionBlockState(void)
Definition: xact.c:407
void EndImplicitTransactionBlock(void)
Definition: xact.c:4363
void SetCurrentStatementStartTimestamp(void)
Definition: xact.c:914
void AbortCurrentTransaction(void)
Definition: xact.c:3463

References AbortCurrentTransaction(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, am_walsender, Assert(), ConnectionTiming::auth_end, ConnectionTiming::auth_start, BaseInit(), BeginReportingGUCOptions(), buf, CHECK_FOR_INTERRUPTS, ConfigReloadPending, conn_timing, 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(), ConnectionTiming::fork_end, ConnectionTiming::fork_start, get_timeout_active(), GetCurrentTimestamp(), 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(), IsExternalConnectionBackend, IsTransactionOrTransactionBlock(), IsUnderPostmaster, jit_reset_after_error(), len, LOG, LOG_CONNECTION_SETUP_DURATIONS, log_connections, Log_disconnections, log_disconnections(), MAX_CANCEL_KEY_LENGTH, MemoryContextDelete(), MemoryContextReset(), MemoryContextSwitchTo(), MessageContext, MyBackendType, MyCancelKey, MyCancelKeyLength, MyDatabaseId, MyProcPid, MyProcPort, MyReplicationSlot, NormalProcessing, notifyInterruptPending, NS_PER_US, on_proc_exit(), palloc_array, PG_exception_stack, PG_PROTOCOL, 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_sendbytes(), 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(), Port::proto, QueryCancelPending, quickdie(), ReadCommand(), ConnectionTiming::ready_for_use, ReadyForQuery(), ReplicationSlotCleanup(), ReplicationSlotRelease(), ReportChangedGUCOptions(), RESUME_INTERRUPTS, row_description_buf, row_description_context, set_ps_display(), SetCurrentStatementStartTimestamp(), SetProcessingMode, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SIGPIPE, SIGQUIT, SIGUSR1, SIGUSR2, ConnectionTiming::socket_create, start_xact_command(), STATE_FASTPATH, STATE_IDLE, STATE_IDLEINTRANSACTION, STATE_IDLEINTRANSACTION_ABORTED, StatementCancelHandler(), TIMESTAMP_MINUS_INFINITY, TimestampDifferenceMicroseconds(), TopMemoryContext, TransactionTimeout, UnBlockSig, username, valgrind_report_error_query, WalSndErrorCleanup(), WalSndSignals(), whereToSendOutput, and xact_started.

Referenced by BackendMain(), and PostgresSingleUserMain().

◆ PostgresSingleUserMain()

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

Definition at line 4063 of file postgres.c.

4065{
4066 const char *dbname = NULL;
4067
4069
4070 /* Initialize startup process environment. */
4071 InitStandaloneProcess(argv[0]);
4072
4073 /*
4074 * Set default values for command-line options.
4075 */
4077
4078 /*
4079 * Parse command-line options.
4080 */
4082
4083 /* Must have gotten a database name, or have a default (the username) */
4084 if (dbname == NULL)
4085 {
4086 dbname = username;
4087 if (dbname == NULL)
4088 ereport(FATAL,
4089 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4090 errmsg("%s: no database nor user name specified",
4091 progname)));
4092 }
4093
4094 /* Acquire configuration parameters */
4096 proc_exit(1);
4097
4098 /*
4099 * Validate we have been given a reasonable-looking DataDir and change
4100 * into it.
4101 */
4102 checkDataDir();
4104
4105 /*
4106 * Create lockfile for data directory.
4107 */
4108 CreateDataDirLockFile(false);
4109
4110 /* read control file (error checking and contains config ) */
4112
4113 /*
4114 * process any libraries that should be preloaded at postmaster start
4115 */
4117
4118 /* Initialize MaxBackends */
4120
4121 /*
4122 * We don't need postmaster child slots in single-user mode, but
4123 * initialize them anyway to avoid having special handling.
4124 */
4126
4127 /* Initialize size of fast-path lock cache. */
4129
4130 /*
4131 * Give preloaded libraries a chance to request additional shared memory.
4132 */
4134
4135 /*
4136 * Now that loadable modules have had their chance to request additional
4137 * shared memory, determine the value of any runtime-computed GUCs that
4138 * depend on the amount of shared memory required.
4139 */
4141
4142 /*
4143 * Now that modules have been loaded, we can process any custom resource
4144 * managers specified in the wal_consistency_checking GUC.
4145 */
4147
4148 /*
4149 * Create shared memory etc. (Nothing's really "shared" in single-user
4150 * mode, but we must have these data structures anyway.)
4151 */
4153
4154 /*
4155 * Estimate number of openable files. This must happen after setting up
4156 * semaphores, because on some platforms semaphores count as open files.
4157 */
4159
4160 /*
4161 * Remember stand-alone backend startup time,roughly at the same point
4162 * during startup that postmaster does so.
4163 */
4165
4166 /*
4167 * Create a per-backend PGPROC struct in shared memory. We must do this
4168 * before we can use LWLocks.
4169 */
4170 InitProcess();
4171
4172 /*
4173 * Now that sufficient infrastructure has been initialized, PostgresMain()
4174 * can do the rest.
4175 */
4177}
TimestampTz PgStartTime
Definition: timestamp.c:54
void set_max_safe_fds(void)
Definition: fd.c:1041
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:1785
void InitializeGUCOptions(void)
Definition: guc.c:1531
@ PGC_POSTMASTER
Definition: guc.h:74
void InitializeShmemGUCs(void)
Definition: ipci.c:355
void CreateSharedMemoryAndSemaphores(void)
Definition: ipci.c:200
const char * progname
Definition: main.c:44
void ChangeToDataDir(void)
Definition: miscinit.c:409
void process_shmem_requests(void)
Definition: miscinit.c:1879
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:175
void process_shared_preload_libraries(void)
Definition: miscinit.c:1851
void checkDataDir(void)
Definition: miscinit.c:296
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1463
void InitPostmasterChildSlots(void)
Definition: pmchild.c:97
void process_postgres_switches(int argc, char *argv[], GucContext ctx, const char **dbname)
Definition: postgres.c:3798
static const char * userDoption
Definition: postgres.c:153
void PostgresMain(const char *dbname, const char *username)
Definition: postgres.c:4192
void InitializeMaxBackends(void)
Definition: postinit.c:554
void InitializeFastPathLocks(void)
Definition: postinit.c:579
void InitProcess(void)
Definition: proc.c:390
void InitializeWalConsistencyChecking(void)
Definition: xlog.c:4823
void LocalProcessControlFile(bool reset)
Definition: xlog.c:4885

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(), set_max_safe_fds(), 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 3798 of file postgres.c.

3800{
3801 bool secure = (ctx == PGC_POSTMASTER);
3802 int errs = 0;
3803 GucSource gucsource;
3804 int flag;
3805
3806 if (secure)
3807 {
3808 gucsource = PGC_S_ARGV; /* switches came from command line */
3809
3810 /* Ignore the initial --single argument, if present */
3811 if (argc > 1 && strcmp(argv[1], "--single") == 0)
3812 {
3813 argv++;
3814 argc--;
3815 }
3816 }
3817 else
3818 {
3819 gucsource = PGC_S_CLIENT; /* switches came from client */
3820 }
3821
3822#ifdef HAVE_INT_OPTERR
3823
3824 /*
3825 * Turn this off because it's either printed to stderr and not the log
3826 * where we'd want it, or argv[0] is now "--single", which would make for
3827 * a weird error message. We print our own error message below.
3828 */
3829 opterr = 0;
3830#endif
3831
3832 /*
3833 * Parse command-line options. CAUTION: keep this in sync with
3834 * postmaster/postmaster.c (the option sets should not conflict) and with
3835 * the common help() function in main/main.c.
3836 */
3837 while ((flag = getopt(argc, argv, "B:bC:c:D:d:EeFf:h:ijk:lN:nOPp:r:S:sTt:v:W:-:")) != -1)
3838 {
3839 switch (flag)
3840 {
3841 case 'B':
3842 SetConfigOption("shared_buffers", optarg, ctx, gucsource);
3843 break;
3844
3845 case 'b':
3846 /* Undocumented flag used for binary upgrades */
3847 if (secure)
3848 IsBinaryUpgrade = true;
3849 break;
3850
3851 case 'C':
3852 /* ignored for consistency with the postmaster */
3853 break;
3854
3855 case '-':
3856
3857 /*
3858 * Error if the user misplaced a special must-be-first option
3859 * for dispatching to a subprogram. parse_dispatch_option()
3860 * returns DISPATCH_POSTMASTER if it doesn't find a match, so
3861 * error for anything else.
3862 */
3864 ereport(ERROR,
3865 (errcode(ERRCODE_SYNTAX_ERROR),
3866 errmsg("--%s must be first argument", optarg)));
3867
3868 /* FALLTHROUGH */
3869 case 'c':
3870 {
3871 char *name,
3872 *value;
3873
3875 if (!value)
3876 {
3877 if (flag == '-')
3878 ereport(ERROR,
3879 (errcode(ERRCODE_SYNTAX_ERROR),
3880 errmsg("--%s requires a value",
3881 optarg)));
3882 else
3883 ereport(ERROR,
3884 (errcode(ERRCODE_SYNTAX_ERROR),
3885 errmsg("-c %s requires a value",
3886 optarg)));
3887 }
3888 SetConfigOption(name, value, ctx, gucsource);
3889 pfree(name);
3890 pfree(value);
3891 break;
3892 }
3893
3894 case 'D':
3895 if (secure)
3896 userDoption = strdup(optarg);
3897 break;
3898
3899 case 'd':
3900 set_debug_options(atoi(optarg), ctx, gucsource);
3901 break;
3902
3903 case 'E':
3904 if (secure)
3905 EchoQuery = true;
3906 break;
3907
3908 case 'e':
3909 SetConfigOption("datestyle", "euro", ctx, gucsource);
3910 break;
3911
3912 case 'F':
3913 SetConfigOption("fsync", "false", ctx, gucsource);
3914 break;
3915
3916 case 'f':
3917 if (!set_plan_disabling_options(optarg, ctx, gucsource))
3918 errs++;
3919 break;
3920
3921 case 'h':
3922 SetConfigOption("listen_addresses", optarg, ctx, gucsource);
3923 break;
3924
3925 case 'i':
3926 SetConfigOption("listen_addresses", "*", ctx, gucsource);
3927 break;
3928
3929 case 'j':
3930 if (secure)
3931 UseSemiNewlineNewline = true;
3932 break;
3933
3934 case 'k':
3935 SetConfigOption("unix_socket_directories", optarg, ctx, gucsource);
3936 break;
3937
3938 case 'l':
3939 SetConfigOption("ssl", "true", ctx, gucsource);
3940 break;
3941
3942 case 'N':
3943 SetConfigOption("max_connections", optarg, ctx, gucsource);
3944 break;
3945
3946 case 'n':
3947 /* ignored for consistency with postmaster */
3948 break;
3949
3950 case 'O':
3951 SetConfigOption("allow_system_table_mods", "true", ctx, gucsource);
3952 break;
3953
3954 case 'P':
3955 SetConfigOption("ignore_system_indexes", "true", ctx, gucsource);
3956 break;
3957
3958 case 'p':
3959 SetConfigOption("port", optarg, ctx, gucsource);
3960 break;
3961
3962 case 'r':
3963 /* send output (stdout and stderr) to the given file */
3964 if (secure)
3966 break;
3967
3968 case 'S':
3969 SetConfigOption("work_mem", optarg, ctx, gucsource);
3970 break;
3971
3972 case 's':
3973 SetConfigOption("log_statement_stats", "true", ctx, gucsource);
3974 break;
3975
3976 case 'T':
3977 /* ignored for consistency with the postmaster */
3978 break;
3979
3980 case 't':
3981 {
3982 const char *tmp = get_stats_option_name(optarg);
3983
3984 if (tmp)
3985 SetConfigOption(tmp, "true", ctx, gucsource);
3986 else
3987 errs++;
3988 break;
3989 }
3990
3991 case 'v':
3992
3993 /*
3994 * -v is no longer used in normal operation, since
3995 * FrontendProtocol is already set before we get here. We keep
3996 * the switch only for possible use in standalone operation,
3997 * in case we ever support using normal FE/BE protocol with a
3998 * standalone backend.
3999 */
4000 if (secure)
4002 break;
4003
4004 case 'W':
4005 SetConfigOption("post_auth_delay", optarg, ctx, gucsource);
4006 break;
4007
4008 default:
4009 errs++;
4010 break;
4011 }
4012
4013 if (errs)
4014 break;
4015 }
4016
4017 /*
4018 * Optional database name should be there only if *dbname is NULL.
4019 */
4020 if (!errs && dbname && *dbname == NULL && argc - optind >= 1)
4021 *dbname = strdup(argv[optind++]);
4022
4023 if (errs || argc != optind)
4024 {
4025 if (errs)
4026 optind--; /* complain about the previous argument */
4027
4028 /* spell the error message a bit differently depending on context */
4030 ereport(FATAL,
4031 errcode(ERRCODE_SYNTAX_ERROR),
4032 errmsg("invalid command-line argument for server process: %s", argv[optind]),
4033 errhint("Try \"%s --help\" for more information.", progname));
4034 else
4035 ereport(FATAL,
4036 errcode(ERRCODE_SYNTAX_ERROR),
4037 errmsg("%s: invalid command-line argument: %s",
4038 progname, argv[optind]),
4039 errhint("Try \"%s --help\" for more information.", progname));
4040 }
4041
4042 /*
4043 * Reset getopt(3) library so that it will work correctly in subprocesses
4044 * or when this function is called a second time with another array.
4045 */
4046 optind = 1;
4047#ifdef HAVE_INT_OPTRESET
4048 optreset = 1; /* some systems need this too */
4049#endif
4050}
int errhint(const char *fmt,...)
Definition: elog.c:1321
bool IsBinaryUpgrade
Definition: globals.c:121
ProtocolVersion FrontendProtocol
Definition: globals.c:30
char OutputFileName[MAXPGPATH]
Definition: globals.c:79
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:4337
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:6384
GucSource
Definition: guc.h:112
@ PGC_S_ARGV
Definition: guc.h:117
@ PGC_S_CLIENT
Definition: guc.h:122
static struct @166 value
DispatchOption parse_dispatch_option(const char *name)
Definition: main.c:244
#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:3684
static bool UseSemiNewlineNewline
Definition: postgres.c:155
static bool EchoQuery
Definition: postgres.c:154
bool set_plan_disabling_options(const char *arg, GucContext context, GucSource source)
Definition: postgres.c:3716
const char * get_stats_option_name(const char *arg)
Definition: postgres.c:3758
@ DISPATCH_POSTMASTER
Definition: postmaster.h:139
uint32 ProtocolVersion
Definition: pqcomm.h:99
char * flag(int b)
Definition: test-ctype.c:33
const char * name

References dbname, DISPATCH_POSTMASTER, EchoQuery, ereport, errcode(), errhint(), errmsg(), ERROR, FATAL, flag(), FrontendProtocol, get_stats_option_name(), getopt(), IsBinaryUpgrade, IsUnderPostmaster, MAXPGPATH, name, optarg, opterr, optind, OutputFileName, parse_dispatch_option(), 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 501 of file postgres.c.

502{
503 int save_errno = errno;
504
506 {
507 /* Check for general interrupts that arrived before/while reading */
509
510 /* Process sinval catchup interrupts, if any */
513
514 /* Process notify interrupts, if any */
517 }
518 else if (ProcDiePending)
519 {
520 /*
521 * We're dying. If there is no data available to read, then it's safe
522 * (and sane) to handle that now. If we haven't tried to read yet,
523 * make sure the process latch is set, so that if there is no data
524 * then we'll come back here and die. If we're done reading, also
525 * make sure the process latch is set, as we might've undesirably
526 * cleared it while reading.
527 */
528 if (blocked)
530 else
532 }
533
534 errno = save_errno;
535}
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 547 of file postgres.c.

548{
549 int save_errno = errno;
550
551 if (ProcDiePending)
552 {
553 /*
554 * We're dying. If it's not possible to write, then we should handle
555 * that immediately, else a stuck client could indefinitely delay our
556 * response to the signal. If we haven't tried to write yet, make
557 * sure the process latch is set, so that if the write would block
558 * then we'll come back here and die. If we're done writing, also
559 * make sure the process latch is set, as we might've undesirably
560 * cleared it while writing.
561 */
562 if (blocked)
563 {
564 /*
565 * Don't mess with whereToSendOutput if ProcessInterrupts wouldn't
566 * service ProcDiePending.
567 */
569 {
570 /*
571 * We don't want to send the client the error message, as a)
572 * that would possibly block again, and b) it would likely
573 * lead to loss of protocol sync because we may have already
574 * sent a partial protocol message.
575 */
578
580 }
581 }
582 else
584 }
585
586 errno = save_errno;
587}
volatile uint32 InterruptHoldoffCount
Definition: globals.c:43
volatile uint32 CritSectionCount
Definition: globals.c:45

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

Referenced by secure_write().

◆ quickdie()

pg_noreturn void quickdie ( SIGNAL_ARGS  )

Definition at line 2934 of file postgres.c.

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

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 3684 of file postgres.c.

3685{
3686 if (debug_flag > 0)
3687 {
3688 char debugstr[64];
3689
3690 sprintf(debugstr, "debug%d", debug_flag);
3691 SetConfigOption("log_min_messages", debugstr, context, source);
3692 }
3693 else
3694 SetConfigOption("log_min_messages", "notice", context, source);
3695
3696 if (debug_flag >= 1 && context == PGC_POSTMASTER)
3697 {
3698 SetConfigOption("log_connections", "all", context, source);
3699 SetConfigOption("log_disconnections", "true", context, source);
3700 }
3701 if (debug_flag >= 2)
3702 SetConfigOption("log_statement", "all", context, source);
3703 if (debug_flag >= 3)
3704 {
3705 SetConfigOption("debug_print_raw_parse", "true", context, source);
3706 SetConfigOption("debug_print_parse", "true", context, source);
3707 }
3708 if (debug_flag >= 4)
3709 SetConfigOption("debug_print_plan", "true", context, source);
3710 if (debug_flag >= 5)
3711 SetConfigOption("debug_print_rewritten", "true", context, source);
3712}
static rewind_source * source
Definition: pg_rewind.c:89
#define sprintf
Definition: port.h:241

References 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 3716 of file postgres.c.

3717{
3718 const char *tmp = NULL;
3719
3720 switch (arg[0])
3721 {
3722 case 's': /* seqscan */
3723 tmp = "enable_seqscan";
3724 break;
3725 case 'i': /* indexscan */
3726 tmp = "enable_indexscan";
3727 break;
3728 case 'o': /* indexonlyscan */
3729 tmp = "enable_indexonlyscan";
3730 break;
3731 case 'b': /* bitmapscan */
3732 tmp = "enable_bitmapscan";
3733 break;
3734 case 't': /* tidscan */
3735 tmp = "enable_tidscan";
3736 break;
3737 case 'n': /* nestloop */
3738 tmp = "enable_nestloop";
3739 break;
3740 case 'm': /* mergejoin */
3741 tmp = "enable_mergejoin";
3742 break;
3743 case 'h': /* hashjoin */
3744 tmp = "enable_hashjoin";
3745 break;
3746 }
3747 if (tmp)
3748 {
3749 SetConfigOption(tmp, "false", context, source);
3750 return true;
3751 }
3752 else
3753 return false;
3754}

References arg, SetConfigOption(), and source.

Referenced by PostmasterMain(), and process_postgres_switches().

◆ ShowUsage()

void ShowUsage ( const char *  title)

Definition at line 5067 of file postgres.c.

5068{
5070 struct timeval user,
5071 sys;
5072 struct timeval elapse_t;
5073 struct rusage r;
5074
5076 gettimeofday(&elapse_t, NULL);
5077 memcpy(&user, &r.ru_utime, sizeof(user));
5078 memcpy(&sys, &r.ru_stime, sizeof(sys));
5079 if (elapse_t.tv_usec < Save_t.tv_usec)
5080 {
5081 elapse_t.tv_sec--;
5082 elapse_t.tv_usec += 1000000;
5083 }
5084 if (r.ru_utime.tv_usec < Save_r.ru_utime.tv_usec)
5085 {
5086 r.ru_utime.tv_sec--;
5087 r.ru_utime.tv_usec += 1000000;
5088 }
5089 if (r.ru_stime.tv_usec < Save_r.ru_stime.tv_usec)
5090 {
5091 r.ru_stime.tv_sec--;
5092 r.ru_stime.tv_usec += 1000000;
5093 }
5094
5095 /*
5096 * The only stats we don't show here are ixrss, idrss, isrss. It takes
5097 * some work to interpret them, and most platforms don't fill them in.
5098 */
5100
5101 appendStringInfoString(&str, "! system usage stats:\n");
5103 "!\t%ld.%06ld s user, %ld.%06ld s system, %ld.%06ld s elapsed\n",
5104 (long) (r.ru_utime.tv_sec - Save_r.ru_utime.tv_sec),
5105 (long) (r.ru_utime.tv_usec - Save_r.ru_utime.tv_usec),
5106 (long) (r.ru_stime.tv_sec - Save_r.ru_stime.tv_sec),
5107 (long) (r.ru_stime.tv_usec - Save_r.ru_stime.tv_usec),
5108 (long) (elapse_t.tv_sec - Save_t.tv_sec),
5109 (long) (elapse_t.tv_usec - Save_t.tv_usec));
5111 "!\t[%ld.%06ld s user, %ld.%06ld s system total]\n",
5112 (long) user.tv_sec,
5113 (long) user.tv_usec,
5114 (long) sys.tv_sec,
5115 (long) sys.tv_usec);
5116#ifndef WIN32
5117
5118 /*
5119 * The following rusage fields are not defined by POSIX, but they're
5120 * present on all current Unix-like systems so we use them without any
5121 * special checks. Some of these could be provided in our Windows
5122 * emulation in src/port/win32getrusage.c with more work.
5123 */
5125 "!\t%ld kB max resident size\n",
5126#if defined(__darwin__)
5127 /* in bytes on macOS */
5128 r.ru_maxrss / 1024
5129#else
5130 /* in kilobytes on most other platforms */
5131 r.ru_maxrss
5132#endif
5133 );
5135 "!\t%ld/%ld [%ld/%ld] filesystem blocks in/out\n",
5136 r.ru_inblock - Save_r.ru_inblock,
5137 /* they only drink coffee at dec */
5138 r.ru_oublock - Save_r.ru_oublock,
5139 r.ru_inblock, r.ru_oublock);
5141 "!\t%ld/%ld [%ld/%ld] page faults/reclaims, %ld [%ld] swaps\n",
5142 r.ru_majflt - Save_r.ru_majflt,
5143 r.ru_minflt - Save_r.ru_minflt,
5144 r.ru_majflt, r.ru_minflt,
5145 r.ru_nswap - Save_r.ru_nswap,
5146 r.ru_nswap);
5148 "!\t%ld [%ld] signals rcvd, %ld/%ld [%ld/%ld] messages rcvd/sent\n",
5149 r.ru_nsignals - Save_r.ru_nsignals,
5150 r.ru_nsignals,
5151 r.ru_msgrcv - Save_r.ru_msgrcv,
5152 r.ru_msgsnd - Save_r.ru_msgsnd,
5153 r.ru_msgrcv, r.ru_msgsnd);
5155 "!\t%ld/%ld [%ld/%ld] voluntary/involuntary context switches\n",
5156 r.ru_nvcsw - Save_r.ru_nvcsw,
5157 r.ru_nivcsw - Save_r.ru_nivcsw,
5158 r.ru_nvcsw, r.ru_nivcsw);
5159#endif /* !WIN32 */
5160
5161 /* remove trailing newline */
5162 if (str.data[str.len - 1] == '\n')
5163 str.data[--str.len] = '\0';
5164
5165 ereport(LOG,
5166 (errmsg_internal("%s", title),
5167 errdetail_internal("%s", str.data)));
5168
5169 pfree(str.data);
5170}
#define __darwin__
Definition: darwin.h:3
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1161
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1234
static char * user
Definition: pg_regress.c:119
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230
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 3061 of file postgres.c.

3062{
3063 /*
3064 * Don't joggle the elbow of proc_exit
3065 */
3067 {
3068 InterruptPending = true;
3069 QueryCancelPending = true;
3070 }
3071
3072 /* If we're still here, waken anything waiting on the process latch */
3074}

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

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

Variable Documentation

◆ client_connection_check_interval

PGDLLIMPORT int client_connection_check_interval
extern

Definition at line 102 of file postgres.c.

Referenced by ProcessInterrupts(), and start_xact_command().

◆ debug_query_string

◆ Log_disconnections

PGDLLIMPORT bool Log_disconnections
extern

Definition at line 94 of file postgres.c.

Referenced by PostgresMain().

◆ log_statement

PGDLLIMPORT int log_statement
extern

Definition at line 96 of file postgres.c.

Referenced by check_log_statement(), and HandleFunctionRequest().

◆ PostAuthDelay

PGDLLIMPORT int PostAuthDelay
extern

◆ restrict_nonsystem_relation_kind

PGDLLIMPORT int restrict_nonsystem_relation_kind
extern

◆ whereToSendOutput