PostgreSQL Source Code: src/backend/tcop/postgres.c File Reference (original) (raw)
Go to the source code of this file.
Functions | |
---|---|
static int | InteractiveBackend (StringInfo inBuf) |
static int | interactive_getc (void) |
static int | SocketBackend (StringInfo inBuf) |
static int | ReadCommand (StringInfo inBuf) |
static void | forbidden_in_wal_sender (char firstchar) |
static bool | check_log_statement (List *stmt_list) |
static int | errdetail_execute (List *raw_parsetree_list) |
static int | errdetail_params (ParamListInfo params) |
static int | errdetail_abort (void) |
static void | bind_param_error_callback (void *arg) |
static void | start_xact_command (void) |
static void | finish_xact_command (void) |
static bool | IsTransactionExitStmt (Node *parsetree) |
static bool | IsTransactionExitStmtList (List *pstmts) |
static bool | IsTransactionStmtList (List *pstmts) |
static void | drop_unnamed_stmt (void) |
static void | log_disconnections (int code, Datum arg) |
static void | enable_statement_timeout (void) |
static void | disable_statement_timeout (void) |
void | ProcessClientReadInterrupt (bool blocked) |
void | ProcessClientWriteInterrupt (bool blocked) |
List * | pg_parse_query (const char *query_string) |
List * | pg_analyze_and_rewrite_fixedparams (RawStmt *parsetree, const char *query_string, const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv) |
List * | pg_analyze_and_rewrite_varparams (RawStmt *parsetree, const char *query_string, Oid **paramTypes, int *numParams, QueryEnvironment *queryEnv) |
List * | pg_analyze_and_rewrite_withcb (RawStmt *parsetree, const char *query_string, ParserSetupHook parserSetup, void *parserSetupArg, QueryEnvironment *queryEnv) |
List * | pg_rewrite_query (Query *query) |
PlannedStmt * | pg_plan_query (Query *querytree, const char *query_string, int cursorOptions, ParamListInfo boundParams) |
List * | pg_plan_queries (List *querytrees, const char *query_string, int cursorOptions, ParamListInfo boundParams) |
static void | exec_simple_query (const char *query_string) |
static void | exec_parse_message (const char *query_string, const char *stmt_name, Oid *paramTypes, int numParams) |
static void | exec_bind_message (StringInfo input_message) |
static void | exec_execute_message (const char *portal_name, long max_rows) |
int | check_log_duration (char *msec_str, bool was_logged) |
static int | errdetail_recovery_conflict (ProcSignalReason reason) |
static void | exec_describe_statement_message (const char *stmt_name) |
static void | exec_describe_portal_message (const char *portal_name) |
void | quickdie (SIGNAL_ARGS) |
void | die (SIGNAL_ARGS) |
void | StatementCancelHandler (SIGNAL_ARGS) |
void | FloatExceptionHandler (SIGNAL_ARGS) |
void | HandleRecoveryConflictInterrupt (ProcSignalReason reason) |
static void | ProcessRecoveryConflictInterrupt (ProcSignalReason reason) |
static void | ProcessRecoveryConflictInterrupts (void) |
void | ProcessInterrupts (void) |
bool | check_client_connection_check_interval (int *newval, void **extra, GucSource source) |
bool | check_stage_log_stats (bool *newval, void **extra, GucSource source) |
bool | check_log_stats (bool *newval, void **extra, GucSource source) |
void | assign_transaction_timeout (int newval, void *extra) |
bool | check_restrict_nonsystem_relation_kind (char **newval, void **extra, GucSource source) |
void | assign_restrict_nonsystem_relation_kind (const char *newval, void *extra) |
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) |
void | process_postgres_switches (int argc, char *argv[], GucContext ctx, const char **dbname) |
void | PostgresSingleUserMain (int argc, char *argv[], const char *username) |
void | PostgresMain (const char *dbname, const char *username) |
void | ResetUsage (void) |
void | ShowUsage (const char *title) |
Variables | |
---|---|
const char * | debug_query_string |
CommandDest | whereToSendOutput = DestDebug |
bool | Log_disconnections = false |
int | log_statement = LOGSTMT_NONE |
int | PostAuthDelay = 0 |
int | client_connection_check_interval = 0 |
int | restrict_nonsystem_relation_kind |
static bool | xact_started = false |
static bool | DoingCommandRead = false |
static bool | doing_extended_query_message = false |
static bool | ignore_till_sync = false |
static CachedPlanSource * | unnamed_stmt_psrc = NULL |
static const char * | userDoption = NULL |
static bool | EchoQuery = false |
static bool | UseSemiNewlineNewline = false |
static volatile sig_atomic_t | RecoveryConflictPending = false |
static volatile sig_atomic_t | RecoveryConflictPendingReasons [NUM_PROCSIGNALS] |
static MemoryContext | row_description_context = NULL |
static StringInfoData | row_description_buf |
static struct rusage | Save_r |
static struct timeval | Save_t |
◆ valgrind_report_error_query
| #define valgrind_report_error_query | ( | | query | ) | ((void) 0) | | -------------------------------------- | - | | ----- | - | ---------- |
◆ BindParamCbData
◆ assign_restrict_nonsystem_relation_kind()
void assign_restrict_nonsystem_relation_kind | ( | const char * | newval, |
---|---|---|---|
void * | extra | ||
) |
◆ assign_transaction_timeout()
void assign_transaction_timeout | ( | int | newval, |
---|---|---|---|
void * | extra | ||
) |
◆ bind_param_error_callback()
static void bind_param_error_callback ( void * arg) | static |
---|
Definition at line 2594 of file postgres.c.
2595{
2598 char *quotedval;
2599
2600 if (data->paramno < 0)
2601 return;
2602
2603
2604 if (data->paramval)
2605 {
2609 quotedval = buf.data;
2610 }
2611 else
2612 quotedval = NULL;
2613
2614 if (data->portalName && data->portalName[0] != '\0')
2615 {
2616 if (quotedval)
2617 errcontext("portal \"%s\" parameter $%d = %s",
2618 data->portalName, data->paramno + 1, quotedval);
2619 else
2620 errcontext("portal \"%s\" parameter $%d",
2621 data->portalName, data->paramno + 1);
2622 }
2623 else
2624 {
2625 if (quotedval)
2626 errcontext("unnamed portal parameter $%d = %s",
2627 data->paramno + 1, quotedval);
2628 else
2629 errcontext("unnamed portal parameter $%d",
2630 data->paramno + 1);
2631 }
2632
2633 if (quotedval)
2634 pfree(quotedval);
2635}
int log_parameter_max_length_on_error
void pfree(void *pointer)
void initStringInfo(StringInfo str)
void appendStringInfoStringQuoted(StringInfo str, const char *s, int maxlen)
References appendStringInfoStringQuoted(), arg, buf, data, errcontext, initStringInfo(), log_parameter_max_length_on_error, and pfree().
Referenced by exec_bind_message().
◆ check_client_connection_check_interval()
bool check_client_connection_check_interval | ( | int * | newval, |
---|---|---|---|
void ** | extra, | ||
GucSource | source | ||
) |
◆ check_log_duration()
int check_log_duration | ( | char * | msec_str, |
---|---|---|---|
bool | was_logged | ||
) |
Definition at line 2425 of file postgres.c.
2426{
2429 {
2430 long secs;
2431 int usecs;
2432 int msecs;
2433 bool exceeded_duration;
2434 bool exceeded_sample_duration;
2435 bool in_sample = false;
2436
2439 &secs, &usecs);
2440 msecs = usecs / 1000;
2441
2442
2443
2444
2445
2446
2451
2456
2457
2458
2459
2460
2461
2462 if (exceeded_sample_duration)
2466
2468 {
2469 snprintf(msec_str, 32, "%ld.%03d",
2470 secs * 1000 + msecs, usecs % 1000);
2471 if ((exceeded_duration || in_sample || xact_is_sampled) && !was_logged)
2472 return 2;
2473 else
2474 return 1;
2475 }
2476 }
2477
2478 return 0;
2479}
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
TimestampTz GetCurrentTimestamp(void)
int log_min_duration_statement
int log_min_duration_sample
double log_statement_sample_rate
double pg_prng_double(pg_prng_state *state)
pg_prng_state pg_global_prng_state
TimestampTz GetCurrentStatementStartTimestamp(void)
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().
◆ check_log_statement()
static bool check_log_statement ( List * stmt_list) | static |
---|
◆ check_log_stats()
bool check_log_stats | ( | bool * | newval, |
---|---|---|---|
void ** | extra, | ||
GucSource | source | ||
) |
◆ check_restrict_nonsystem_relation_kind()
bool check_restrict_nonsystem_relation_kind | ( | char ** | newval, |
---|---|---|---|
void ** | extra, | ||
GucSource | source | ||
) |
Definition at line 3618 of file postgres.c.
3619{
3620 char *rawstring;
3621 List *elemlist;
3623 int flags = 0;
3624
3625
3627
3629 {
3630
3632 pfree(rawstring);
3634 return false;
3635 }
3636
3637 foreach(l, elemlist)
3638 {
3639 char *tok = (char *) lfirst(l);
3640
3643 else if (pg_strcasecmp(tok, "foreign-table") == 0)
3645 else
3646 {
3648 pfree(rawstring);
3650 return false;
3651 }
3652 }
3653
3654 pfree(rawstring);
3656
3657
3659 if (!*extra)
3660 return false;
3661 *((int *) *extra) = flags;
3662
3663 return true;
3664}
void * guc_malloc(int elevel, size_t size)
void list_free(List *list)
char * pstrdup(const char *in)
int pg_strcasecmp(const char *s1, const char *s2)
#define RESTRICT_RELKIND_FOREIGN_TABLE
#define RESTRICT_RELKIND_VIEW
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
References GUC_check_errdetail, guc_malloc(), lfirst, list_free(), LOG, newval, pfree(), pg_strcasecmp(), pstrdup(), RESTRICT_RELKIND_FOREIGN_TABLE, RESTRICT_RELKIND_VIEW, and SplitIdentifierString().
◆ check_stage_log_stats()
bool check_stage_log_stats | ( | bool * | newval, |
---|---|---|---|
void ** | extra, | ||
GucSource | source | ||
) |
◆ die()
Definition at line 3028 of file postgres.c.
3029{
3030
3032 {
3035 }
3036
3037
3039
3040
3042
3043
3044
3045
3046
3047
3048
3051}
volatile sig_atomic_t InterruptPending
volatile sig_atomic_t ProcDiePending
bool proc_exit_inprogress
void SetLatch(Latch *latch)
SessionEndType pgStatSessionEndCause
CommandDest whereToSendOutput
static bool DoingCommandRead
void ProcessInterrupts(void)
References DestRemote, DISCONNECT_KILLED, DoingCommandRead, InterruptPending, MyLatch, pgStatSessionEndCause, proc_exit_inprogress, ProcDiePending, ProcessInterrupts(), SetLatch(), and whereToSendOutput.
Referenced by PostgresMain().
◆ disable_statement_timeout()
static void disable_statement_timeout ( void ) | static |
---|
◆ drop_unnamed_stmt()
static void drop_unnamed_stmt ( void ) | static |
---|
◆ enable_statement_timeout()
static void enable_statement_timeout ( void ) | static |
---|
◆ errdetail_abort()
static int errdetail_abort ( void ) | static |
---|
◆ errdetail_execute()
static int errdetail_execute ( List * raw_parsetree_list) | static |
---|
Definition at line 2488 of file postgres.c.
2489{
2491
2492 foreach(parsetree_item, raw_parsetree_list)
2493 {
2495
2497 {
2500
2502 if (pstmt)
2503 {
2504 errdetail("prepare: %s", pstmt->plansource->query_string);
2505 return 0;
2506 }
2507 }
2508 }
2509
2510 return 0;
2511}
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
#define IsA(nodeptr, _type_)
#define lfirst_node(type, lc)
References errdetail(), FetchPreparedStatement(), IsA, lfirst_node, RawStmt::stmt, and stmt.
Referenced by exec_simple_query().
◆ errdetail_params()
◆ errdetail_recovery_conflict()
◆ exec_bind_message()
static void exec_bind_message ( StringInfo input_message) | static |
---|
Definition at line 1625 of file postgres.c.
1626{
1627 const char *portal_name;
1628 const char *stmt_name;
1629 int numPFormats;
1630 int16 *pformats = NULL;
1631 int numParams;
1632 int numRFormats;
1633 int16 *rformats = NULL;
1637 char *query_string;
1638 char *saved_stmt_name;
1642 bool snapshot_set = false;
1643 char msec_str[32];
1647
1648
1651
1654 *portal_name ? portal_name : "",
1655 *stmt_name ? stmt_name : "")));
1656
1657
1658 if (stmt_name[0] != '\0')
1659 {
1661
1664 }
1665 else
1666 {
1667
1669 if (!psrc)
1671 (errcode(ERRCODE_UNDEFINED_PSTATEMENT),
1672 errmsg("unnamed prepared statement does not exist")));
1673 }
1674
1675
1676
1677
1679
1681
1683 {
1685
1687 {
1689 break;
1690 }
1691 }
1692
1694
1695 if (save_log_statement_stats)
1697
1698
1699
1700
1701
1702
1703
1705
1706
1708
1709
1710 numPFormats = pq_getmsgint(input_message, 2);
1711 if (numPFormats > 0)
1712 {
1714 for (int i = 0; i < numPFormats; i++)
1716 }
1717
1718
1720
1721 if (numPFormats > 1 && numPFormats != numParams)
1723 (errcode(ERRCODE_PROTOCOL_VIOLATION),
1724 errmsg("bind message has %d parameter formats but %d parameters",
1725 numPFormats, numParams)));
1726
1729 (errcode(ERRCODE_PROTOCOL_VIOLATION),
1730 errmsg("bind message supplies %d parameters, but prepared statement \"%s\" requires %d",
1731 numParams, stmt_name, psrc->num_params)));
1732
1733
1734
1735
1736
1737
1738
1739
1740
1744 numParams != 0))
1746 (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),
1747 errmsg("current transaction is aborted, "
1748 "commands ignored until end of transaction block"),
1750
1751
1752
1753
1754
1755 if (portal_name[0] == '\0')
1756 portal = CreatePortal(portal_name, true, true);
1757 else
1758 portal = CreatePortal(portal_name, false, false);
1759
1760
1761
1762
1763
1764
1765
1767
1768
1770
1771
1772 if (stmt_name[0])
1773 saved_stmt_name = pstrdup(stmt_name);
1774 else
1775 saved_stmt_name = NULL;
1776
1777
1778
1779
1780
1781
1782
1783
1784 if (numParams > 0 ||
1787 {
1789 snapshot_set = true;
1790 }
1791
1792
1793
1794
1795 if (numParams > 0)
1796 {
1797 char **knownTextValues = NULL;
1799
1800
1801
1802
1803
1805 one_param_data.paramno = -1;
1806 one_param_data.paramval = NULL;
1809 params_errcxt.arg = &one_param_data;
1811
1813
1814 for (int paramno = 0; paramno < numParams; paramno++)
1815 {
1819 bool isNull;
1821 char csave;
1823
1824 one_param_data.paramno = paramno;
1825 one_param_data.paramval = NULL;
1826
1828 isNull = (plength == -1);
1829
1830 if (!isNull)
1831 {
1832 char *pvalue;
1833
1834
1835
1836
1837
1838
1839
1840
1842 csave = pvalue[plength];
1843 pvalue[plength] = '\0';
1845 }
1846 else
1847 {
1848 pbuf.data = NULL;
1849 csave = 0;
1850 }
1851
1852 if (numPFormats > 1)
1853 pformat = pformats[paramno];
1854 else if (numPFormats > 0)
1855 pformat = pformats[0];
1856 else
1857 pformat = 0;
1858
1859 if (pformat == 0)
1860 {
1861 Oid typinput;
1862 Oid typioparam;
1863 char *pstring;
1864
1866
1867
1868
1869
1870
1871 if (isNull)
1872 pstring = NULL;
1873 else
1875
1876
1877 one_param_data.paramval = pstring;
1878
1880
1881 one_param_data.paramval = NULL;
1882
1883
1884
1885
1886
1887
1888 if (pstring)
1889 {
1891 {
1893
1895
1896 if (knownTextValues == NULL)
1897 knownTextValues = palloc0_array(char *, numParams);
1898
1900 knownTextValues[paramno] = pstrdup(pstring);
1901 else
1902 {
1903
1904
1905
1906
1907
1908
1909
1910 knownTextValues[paramno] =
1914 }
1915
1917 }
1918 if (pstring != pbuf.data)
1920 }
1921 }
1922 else if (pformat == 1)
1923 {
1924 Oid typreceive;
1925 Oid typioparam;
1927
1928
1929
1930
1932
1933 if (isNull)
1934 bufptr = NULL;
1935 else
1936 bufptr = &pbuf;
1937
1939
1940
1941 if (!isNull && pbuf.cursor != pbuf.len)
1943 (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1944 errmsg("incorrect binary data format in bind parameter %d",
1945 paramno + 1)));
1946 }
1947 else
1948 {
1950 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1951 errmsg("unsupported format code: %d",
1952 pformat)));
1953 pval = 0;
1954 }
1955
1956
1957 if (!isNull)
1958 pbuf.data[plength] = csave;
1959
1962
1963
1964
1965
1966
1969 }
1970
1971
1973
1974
1975
1976
1977
1978
1982 knownTextValues,
1984 }
1985 else
1986 params = NULL;
1987
1988
1990
1991
1992
1993
1994
1996 params_data.params = params;
1999 params_errcxt.arg = ¶ms_data;
2001
2002
2003 numRFormats = pq_getmsgint(input_message, 2);
2004 if (numRFormats > 0)
2005 {
2007 for (int i = 0; i < numRFormats; i++)
2009 }
2010
2012
2013
2014
2015
2016
2017
2018 cplan = GetCachedPlan(psrc, params, NULL, NULL);
2019
2020
2021
2022
2023
2024
2025
2027 saved_stmt_name,
2028 query_string,
2031 cplan,
2032 psrc);
2033
2034
2035 foreach(lc, portal->stmts)
2036 {
2038
2040 {
2042 break;
2043 }
2044 }
2045
2046
2047 if (snapshot_set)
2049
2050
2051
2052
2054
2055
2056
2057
2059
2060
2061
2062
2063
2065
2066
2067
2068
2071
2072
2073
2074
2076 {
2077 case 1:
2079 (errmsg("duration: %s ms", msec_str),
2081 break;
2082 case 2:
2084 (errmsg("duration: %s ms bind %s%s%s: %s",
2085 msec_str,
2086 *stmt_name ? stmt_name : "",
2087 *portal_name ? "/" : "",
2088 *portal_name ? portal_name : "",
2092 break;
2093 }
2094
2095 if (save_log_statement_stats)
2096 ShowUsage("BIND MESSAGE STATISTICS");
2097
2099
2101}
void pgstat_report_plan_id(uint64 plan_id, bool force)
void pgstat_report_query_id(uint64 query_id, bool force)
void pgstat_report_activity(BackendState state, const char *cmd_str)
#define unconstify(underlying_type, expr)
int errmsg_internal(const char *fmt,...)
int errhidestmt(bool hide_stmt)
ErrorContextCallback * error_context_stack
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define palloc_array(type, count)
#define palloc0_array(type, count)
Datum OidReceiveFunctionCall(Oid functionId, StringInfo buf, Oid typioparam, int32 typmod)
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
void getTypeBinaryInputInfo(Oid type, Oid *typReceive, Oid *typIOParam)
char * pg_client_to_server(const char *s, int len)
MemoryContext MessageContext
char * pnstrdup(const char *in, Size len)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
ParamListInfo makeParamList(int numParams)
void ParamsErrorCallback(void *arg)
bool analyze_requires_snapshot(RawStmt *parseTree)
#define MAX_MULTIBYTE_CHAR_LEN
CachedPlan * GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams, ResourceOwner owner, QueryEnvironment *queryEnv)
void PortalDefineQuery(Portal portal, const char *prepStmtName, const char *sourceText, CommandTag commandTag, List *stmts, CachedPlan *cplan, CachedPlanSource *plansource)
Portal CreatePortal(const char *name, bool allowDup, bool dupSilent)
static int errdetail_abort(void)
int check_log_duration(char *msec_str, bool was_logged)
const char * debug_query_string
void ShowUsage(const char *title)
static int errdetail_params(ParamListInfo params)
static void bind_param_error_callback(void *arg)
static bool IsTransactionExitStmt(Node *parsetree)
static void start_xact_command(void)
#define valgrind_report_error_query(query)
unsigned int pq_getmsgint(StringInfo msg, int b)
void pq_getmsgend(StringInfo msg)
const char * pq_getmsgstring(StringInfo msg)
void pq_putemptymessage(char msgtype)
const char * pq_getmsgbytes(StringInfo msg, int datalen)
void PortalSetResultFormat(Portal portal, int nFormats, int16 *formats)
void PortalStart(Portal portal, ParamListInfo params, int eflags, Snapshot snapshot)
#define PqMsg_BindComplete
static void set_ps_display(const char *activity)
Snapshot GetTransactionSnapshot(void)
void PushActiveSnapshot(Snapshot snapshot)
void PopActiveSnapshot(void)
static void initReadOnlyStringInfo(StringInfo str, char *data, int len)
const char * query_string
struct RawStmt * raw_parse_tree
struct ErrorContextCallback * previous
void(* callback)(void *arg)
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
MemoryContext portalContext
CachedPlanSource * plansource
bool IsAbortedTransactionBlockState(void)
References analyze_requires_snapshot(), ErrorContextCallback::arg, bind_param_error_callback(), BuildParamLogString(), ErrorContextCallback::callback, check_log_duration(), CachedPlanSource::commandTag, CreatePortal(), StringInfoData::cursor, StringInfoData::data, DEBUG2, debug_query_string, DestRemote, ereport, errcode(), errdetail_abort(), errdetail_params(), errhidestmt(), errmsg(), errmsg_internal(), ERROR, error_context_stack, FetchPreparedStatement(), GetCachedPlan(), GetTransactionSnapshot(), getTypeBinaryInputInfo(), getTypeInputInfo(), i, initReadOnlyStringInfo(), InvalidSnapshot, IsAbortedTransactionBlockState(), ParamExternData::isnull, IsTransactionExitStmt(), StringInfoData::len, lfirst_node, LOG, log_parameter_max_length_on_error, log_statement_stats, makeParamList(), MAX_MULTIBYTE_CHAR_LEN, MemoryContextSwitchTo(), MessageContext, PortalData::name, CachedPlanSource::num_params, OidInputFunctionCall(), OidReceiveFunctionCall(), palloc0_array, palloc_array, PARAM_FLAG_CONST, CachedPlanSource::param_types, BindParamCbData::paramno, ParamListInfoData::params, ParamsErrorCbData::params, ParamsErrorCallback(), BindParamCbData::paramval, ParamListInfoData::paramValuesStr, ParamExternData::pflags, pfree(), pg_client_to_server(), pgstat_report_activity(), pgstat_report_plan_id(), pgstat_report_query_id(), plan, PreparedStatement::plansource, pnstrdup(), PopActiveSnapshot(), PortalData::portalContext, PortalDefineQuery(), BindParamCbData::portalName, ParamsErrorCbData::portalName, PortalSetResultFormat(), PortalStart(), pq_getmsgbytes(), pq_getmsgend(), pq_getmsgint(), pq_getmsgstring(), pq_putemptymessage(), PqMsg_BindComplete, ErrorContextCallback::previous, pstrdup(), ParamExternData::ptype, PushActiveSnapshot(), CachedPlanSource::query_list, CachedPlanSource::query_string, CachedPlanSource::raw_parse_tree, ResetUsage(), set_ps_display(), ShowUsage(), start_xact_command(), STATE_RUNNING, RawStmt::stmt, CachedPlan::stmt_list, PortalData::stmts, UINT64CONST, unconstify, unnamed_stmt_psrc, valgrind_report_error_query, ParamExternData::value, and whereToSendOutput.
Referenced by PostgresMain().
◆ exec_describe_portal_message()
static void exec_describe_portal_message ( const char * portal_name) | static |
---|
Definition at line 2736 of file postgres.c.
2737{
2739
2740
2741
2742
2743
2745
2746
2748
2752 (errcode(ERRCODE_UNDEFINED_CURSOR),
2753 errmsg("portal \"%s\" does not exist", portal_name)));
2754
2755
2756
2757
2758
2759
2760
2761
2762
2766 (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),
2767 errmsg("current transaction is aborted, "
2768 "commands ignored until end of transaction block"),
2770
2772 return;
2773
2779 else
2781}
Portal GetPortalByName(const char *name)
static StringInfoData row_description_buf
List * FetchPortalTargetList(Portal portal)
void SendRowDescriptionMessage(StringInfo buf, TupleDesc typeinfo, List *targetlist, int16 *formats)
References DestRemote, ereport, errcode(), errdetail_abort(), errmsg(), ERROR, FetchPortalTargetList(), PortalData::formats, GetPortalByName(), IsAbortedTransactionBlockState(), MemoryContextSwitchTo(), MessageContext, PortalIsValid, pq_putemptymessage(), PqMsg_NoData, row_description_buf, SendRowDescriptionMessage(), start_xact_command(), PortalData::tupDesc, and whereToSendOutput.
Referenced by PostgresMain().
◆ exec_describe_statement_message()
static void exec_describe_statement_message ( const char * stmt_name) | static |
---|
Definition at line 2643 of file postgres.c.
2644{
2646
2647
2648
2649
2650
2652
2653
2655
2656
2657 if (stmt_name[0] != '\0')
2658 {
2660
2663 }
2664 else
2665 {
2666
2668 if (!psrc)
2670 (errcode(ERRCODE_UNDEFINED_PSTATEMENT),
2671 errmsg("unnamed prepared statement does not exist")));
2672 }
2673
2674
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2689 (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),
2690 errmsg("current transaction is aborted, "
2691 "commands ignored until end of transaction block"),
2693
2695 return;
2696
2697
2698
2699
2702
2704 {
2706
2708 }
2710
2711
2712
2713
2715 {
2716 List *tlist;
2717
2718
2720
2723 tlist,
2724 NULL);
2725 }
2726 else
2728}
List * CachedPlanGetTargetList(CachedPlanSource *plansource, QueryEnvironment *queryEnv)
void pq_beginmessage_reuse(StringInfo buf, char msgtype)
void pq_endmessage_reuse(StringInfo buf)
static void pq_sendint32(StringInfo buf, uint32 i)
static void pq_sendint16(StringInfo buf, uint16 i)
#define PqMsg_ParameterDescription
References Assert(), CachedPlanGetTargetList(), DestRemote, ereport, errcode(), errdetail_abort(), errmsg(), ERROR, FetchPreparedStatement(), CachedPlanSource::fixed_result, i, IsAbortedTransactionBlockState(), MemoryContextSwitchTo(), MessageContext, CachedPlanSource::num_params, CachedPlanSource::param_types, PreparedStatement::plansource, pq_beginmessage_reuse(), pq_endmessage_reuse(), pq_putemptymessage(), pq_sendint16(), pq_sendint32(), PqMsg_NoData, PqMsg_ParameterDescription, CachedPlanSource::resultDesc, row_description_buf, SendRowDescriptionMessage(), start_xact_command(), unnamed_stmt_psrc, and whereToSendOutput.
Referenced by PostgresMain().
◆ exec_execute_message()
static void exec_execute_message ( const char * portal_name, long max_rows ) | static |
---|
Definition at line 2109 of file postgres.c.
2110{
2114 bool completed;
2116 const char *sourceText;
2117 const char *prepStmtName;
2120 bool is_xact_command;
2121 bool execute_is_fetch;
2122 bool was_logged = false;
2123 char msec_str[32];
2126 const char *cmdtagname;
2127 size_t cmdtaglen;
2129
2130
2134
2138 (errcode(ERRCODE_UNDEFINED_CURSOR),
2139 errmsg("portal \"%s\" does not exist", portal_name)));
2140
2141
2142
2143
2144
2145 if (portal->commandTag == CMDTAG_UNKNOWN)
2146 {
2149 return;
2150 }
2151
2152
2154
2155
2156
2157
2158
2159
2160
2164 else
2165 prepStmtName = "";
2167
2168
2169
2170
2172
2174
2175 foreach(lc, portal->stmts)
2176 {
2178
2180 {
2182 break;
2183 }
2184 }
2185
2186 foreach(lc, portal->stmts)
2187 {
2189
2191 {
2193 break;
2194 }
2195 }
2196
2198
2200
2201 if (save_log_statement_stats)
2203
2205
2206
2207
2208
2209
2213
2214
2215
2216
2217
2219
2220
2221
2222
2223
2224
2225
2226 execute_is_fetch = !portal->atStart;
2227
2228
2230 {
2232 (errmsg("%s %s%s%s: %s",
2233 execute_is_fetch ?
2234 _("execute fetch from") :
2235 _("execute"),
2236 prepStmtName,
2237 *portal_name ? "/" : "",
2238 *portal_name ? portal_name : "",
2239 sourceText),
2242 was_logged = true;
2243 }
2244
2245
2246
2247
2248
2252 (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),
2253 errmsg("current transaction is aborted, "
2254 "commands ignored until end of transaction block"),
2256
2257
2259
2260
2261
2262
2263
2265 params_data.params = portalParams;
2268 params_errcxt.arg = ¶ms_data;
2270
2271 if (max_rows <= 0)
2273
2275 max_rows,
2276 true,
2277 receiver,
2278 receiver,
2279 &qc);
2280
2281 receiver->rDestroy(receiver);
2282
2283
2285
2286 if (completed)
2287 {
2289 {
2290
2291
2292
2293
2294
2295
2296
2297
2299
2300
2301
2302
2303
2304
2305 portalParams = NULL;
2306 }
2307 else
2308 {
2309
2310
2311
2312
2314
2315
2316
2317
2318
2320
2321
2322
2323
2324
2326 }
2327
2328
2330 }
2331 else
2332 {
2333
2336
2337
2338
2339
2340
2342 }
2343
2344
2345
2346
2348 {
2349 case 1:
2351 (errmsg("duration: %s ms", msec_str),
2353 break;
2354 case 2:
2356 (errmsg("duration: %s ms %s %s%s%s: %s",
2357 msec_str,
2358 execute_is_fetch ?
2359 _("execute fetch from") :
2360 _("execute"),
2361 prepStmtName,
2362 *portal_name ? "/" : "",
2363 *portal_name ? portal_name : "",
2364 sourceText),
2367 break;
2368 }
2369
2370 if (save_log_statement_stats)
2371 ShowUsage("EXECUTE MESSAGE STATISTICS");
2372
2374
2376}
const char * GetCommandTagNameAndLen(CommandTag commandTag, Size *len)
void EndCommand(const QueryCompletion *qc, CommandDest dest, bool force_undecorated_output)
DestReceiver * CreateDestReceiver(CommandDest dest)
void BeginCommand(CommandTag commandTag, CommandDest dest)
void NullCommand(CommandDest dest)
#define CHECK_FOR_INTERRUPTS()
static void disable_statement_timeout(void)
static bool IsTransactionStmtList(List *pstmts)
static bool check_log_statement(List *stmt_list)
static bool IsTransactionExitStmtList(List *pstmts)
static void finish_xact_command(void)
bool PortalRun(Portal portal, long count, bool isTopLevel, DestReceiver *dest, DestReceiver *altdest, QueryCompletion *qc)
void SetRemoteDestReceiverParams(DestReceiver *self, Portal portal)
#define PqMsg_PortalSuspended
void set_ps_display_with_len(const char *activity, size_t len)
ParamListInfo portalParams
const char * prepStmtName
void(* rDestroy)(DestReceiver *self)
void CommandCounterIncrement(void)
#define XACT_FLAGS_PIPELINING
#define XACT_FLAGS_NEEDIMMEDIATECOMMIT
References _, ErrorContextCallback::arg, Assert(), PortalData::atStart, BeginCommand(), ErrorContextCallback::callback, CHECK_FOR_INTERRUPTS, check_log_duration(), check_log_statement(), CommandCounterIncrement(), PortalData::commandTag, CreateDestReceiver(), debug_query_string, generate_unaccent_rules::dest, DestRemote, DestRemoteExecute, disable_statement_timeout(), EndCommand(), ereport, errcode(), errdetail_abort(), errdetail_params(), errhidestmt(), errmsg(), ERROR, error_context_stack, FETCH_ALL, finish_xact_command(), GetCommandTagNameAndLen(), GetPortalByName(), IsAbortedTransactionBlockState(), IsTransactionExitStmtList(), IsTransactionStmtList(), lfirst_node, LOG, log_statement_stats, MyXactFlags, PortalData::name, NIL, NullCommand(), ParamsErrorCbData::params, ParamsErrorCallback(), pgstat_report_activity(), pgstat_report_plan_id(), pgstat_report_query_id(), PortalIsValid, ParamsErrorCbData::portalName, PortalData::portalParams, PortalRun(), pq_putemptymessage(), PqMsg_PortalSuspended, PortalData::prepStmtName, ErrorContextCallback::previous, pstrdup(), _DestReceiver::rDestroy, ResetUsage(), set_ps_display_with_len(), SetRemoteDestReceiverParams(), ShowUsage(), PortalData::sourceText, start_xact_command(), STATE_RUNNING, stmt, PortalData::stmts, UINT64CONST, valgrind_report_error_query, whereToSendOutput, XACT_FLAGS_NEEDIMMEDIATECOMMIT, and XACT_FLAGS_PIPELINING.
Referenced by PostgresMain().
◆ exec_parse_message()
static void exec_parse_message ( const char * query_string, const char * stmt_name, Oid * paramTypes, int numParams ) | static |
---|
Definition at line 1390 of file postgres.c.
1394{
1397 List *parsetree_list;
1398 RawStmt *raw_parse_tree;
1399 List *querytree_list;
1401 bool is_named;
1403 char msec_str[32];
1404
1405
1406
1407
1409
1411
1413
1414 if (save_log_statement_stats)
1416
1419 *stmt_name ? stmt_name : "",
1420 query_string)));
1421
1422
1423
1424
1425
1426
1427
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443 is_named = (stmt_name[0] != '\0');
1444 if (is_named)
1445 {
1446
1448 }
1449 else
1450 {
1451
1453
1454 unnamed_stmt_context =
1456 "unnamed prepared statement",
1459 }
1460
1461
1462
1463
1464
1466
1467
1468
1469
1470
1471
1474 (errcode(ERRCODE_SYNTAX_ERROR),
1475 errmsg("cannot insert multiple commands into a prepared statement")));
1476
1477 if (parsetree_list != NIL)
1478 {
1479 bool snapshot_set = false;
1480
1482
1483
1484
1485
1486
1487
1488
1489
1490
1494 (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),
1495 errmsg("current transaction is aborted, "
1496 "commands ignored until end of transaction block"),
1498
1499
1500
1501
1502
1505
1506
1507
1508
1510 {
1512 snapshot_set = true;
1513 }
1514
1515
1516
1517
1518
1519
1521 query_string,
1522 ¶mTypes,
1523 &numParams,
1524 NULL);
1525
1526
1527 if (snapshot_set)
1529 }
1530 else
1531 {
1532
1533 raw_parse_tree = NULL;
1535 CMDTAG_UNKNOWN);
1536 querytree_list = NIL;
1537 }
1538
1539
1540
1541
1542
1543
1544
1545 if (unnamed_stmt_context)
1547
1548
1550 querytree_list,
1551 unnamed_stmt_context,
1552 paramTypes,
1553 numParams,
1554 NULL,
1555 NULL,
1557 true);
1558
1559
1561
1562 if (is_named)
1563 {
1564
1565
1566
1568 }
1569 else
1570 {
1571
1572
1573
1576 }
1577
1579
1580
1581
1582
1583
1584
1586
1587
1588
1589
1592
1593
1594
1595
1597 {
1598 case 1:
1600 (errmsg("duration: %s ms", msec_str),
1602 break;
1603 case 2:
1605 (errmsg("duration: %s ms parse %s: %s",
1606 msec_str,
1607 *stmt_name ? stmt_name : "",
1608 query_string),
1610 break;
1611 }
1612
1613 if (save_log_statement_stats)
1614 ShowUsage("PARSE MESSAGE STATISTICS");
1615
1617}
void StorePreparedStatement(const char *stmt_name, CachedPlanSource *plansource, bool from_sql)
void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define CURSOR_OPT_PARALLEL_OK
static int list_length(const List *l)
#define linitial_node(type, l)
void SaveCachedPlan(CachedPlanSource *plansource)
void CompleteCachedPlan(CachedPlanSource *plansource, List *querytree_list, MemoryContext querytree_context, Oid *param_types, int num_params, ParserSetupHook parserSetup, void *parserSetupArg, int cursor_options, bool fixed_result)
CachedPlanSource * CreateCachedPlan(RawStmt *raw_parse_tree, const char *query_string, CommandTag commandTag)
List * pg_parse_query(const char *query_string)
List * pg_analyze_and_rewrite_varparams(RawStmt *parsetree, const char *query_string, Oid **paramTypes, int *numParams, QueryEnvironment *queryEnv)
static void drop_unnamed_stmt(void)
#define PqMsg_ParseComplete
CommandTag CreateCommandTag(Node *parsetree)
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, analyze_requires_snapshot(), CHECK_FOR_INTERRUPTS, check_log_duration(), CommandCounterIncrement(), CompleteCachedPlan(), CachedPlanSource::context, CreateCachedPlan(), CreateCommandTag(), CURSOR_OPT_PARALLEL_OK, DEBUG2, debug_query_string, DestRemote, drop_unnamed_stmt(), ereport, errcode(), errdetail_abort(), errhidestmt(), errmsg(), errmsg_internal(), ERROR, GetTransactionSnapshot(), IsAbortedTransactionBlockState(), IsTransactionExitStmt(), linitial_node, list_length(), LOG, log_statement_stats, MemoryContextSetParent(), MemoryContextSwitchTo(), MessageContext, NIL, pg_analyze_and_rewrite_varparams(), pg_parse_query(), pgstat_report_activity(), PopActiveSnapshot(), pq_putemptymessage(), PqMsg_ParseComplete, PushActiveSnapshot(), ResetUsage(), SaveCachedPlan(), set_ps_display(), ShowUsage(), start_xact_command(), STATE_RUNNING, RawStmt::stmt, StorePreparedStatement(), unnamed_stmt_psrc, and whereToSendOutput.
Referenced by PostgresMain().
◆ exec_simple_query()
static void exec_simple_query ( const char * query_string) | static |
---|
Definition at line 1011 of file postgres.c.
1012{
1015 List *parsetree_list;
1018 bool was_logged = false;
1019 bool use_implicit_block;
1020 char msec_str[32];
1021
1022
1023
1024
1026
1028
1029 TRACE_POSTGRESQL_QUERY_START(query_string);
1030
1031
1032
1033
1034
1035 if (save_log_statement_stats)
1037
1038
1039
1040
1041
1042
1043
1044
1046
1047
1048
1049
1050
1051
1052
1054
1055
1056
1057
1059
1060
1061
1062
1063
1065
1066
1068 {
1070 (errmsg("statement: %s", query_string),
1073 was_logged = true;
1074 }
1075
1076
1077
1078
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089 use_implicit_block = (list_length(parsetree_list) > 1);
1090
1091
1092
1093
1094 foreach(parsetree_item, parsetree_list)
1095 {
1097 bool snapshot_set = false;
1101 List *querytree_list,
1102 *plantree_list;
1106 const char *cmdtagname;
1107 size_t cmdtaglen;
1108
1111
1112
1113
1114
1115
1116
1117
1120
1122
1124
1125
1126
1127
1128
1129
1130
1131
1132
1136 (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),
1137 errmsg("current transaction is aborted, "
1138 "commands ignored until end of transaction block"),
1140
1141
1143
1144
1145
1146
1147
1148
1149
1150
1151 if (use_implicit_block)
1153
1154
1156
1157
1158
1159
1161 {
1163 snapshot_set = true;
1164 }
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178 if (lnext(parsetree_list, parsetree_item) != NULL)
1179 {
1180 per_parsetree_context =
1182 "per-parsetree message context",
1185 }
1186 else
1188
1190 NULL, 0, NULL);
1191
1192 plantree_list = pg_plan_queries(querytree_list, query_string,
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205 if (snapshot_set)
1207
1208
1210
1211
1212
1213
1214
1216
1217 portal->visible = false;
1218
1219
1220
1221
1222
1223
1225 NULL,
1226 query_string,
1227 commandTag,
1228 plantree_list,
1229 NULL,
1230 NULL);
1231
1232
1233
1234
1236
1237
1238
1239
1240
1241
1242
1243 format = 0;
1245 {
1247
1249 {
1251
1254 format = 1;
1255 }
1256 }
1258
1259
1260
1261
1265
1266
1267
1268
1270
1271
1272
1273
1276 true,
1277 receiver,
1278 receiver,
1279 &qc);
1280
1281 receiver->rDestroy(receiver);
1282
1284
1285 if (lnext(parsetree_list, parsetree_item) == NULL)
1286 {
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296 if (use_implicit_block)
1299 }
1301 {
1302
1303
1304
1305
1307 }
1308 else
1309 {
1310
1311
1312
1313
1314
1316
1317
1318
1319
1320
1322
1323
1324
1325
1326
1327
1329 }
1330
1331
1332
1333
1334
1335
1336
1338
1339
1340 if (per_parsetree_context)
1342 }
1343
1344
1345
1346
1347
1348
1350
1351
1352
1353
1354 if (!parsetree_list)
1356
1357
1358
1359
1361 {
1362 case 1:
1364 (errmsg("duration: %s ms", msec_str),
1366 break;
1367 case 2:
1369 (errmsg("duration: %s ms statement: %s",
1370 msec_str, query_string),
1373 break;
1374 }
1375
1376 if (save_log_statement_stats)
1378
1379 TRACE_POSTGRESQL_QUERY_DONE(query_string);
1380
1382}
if(TABLE==NULL||TABLE_index==NULL)
void MemoryContextDelete(MemoryContext context)
#define CURSOR_OPT_BINARY
static ListCell * lnext(const List *l, const ListCell *c)
void PortalDrop(Portal portal, bool isTopCommit)
List * pg_plan_queries(List *querytrees, const char *query_string, int cursorOptions, ParamListInfo boundParams)
List * pg_analyze_and_rewrite_fixedparams(RawStmt *parsetree, const char *query_string, const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv)
static int errdetail_execute(List *raw_parsetree_list)
void BeginImplicitTransactionBlock(void)
void EndImplicitTransactionBlock(void)
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, analyze_requires_snapshot(), Assert(), BeginCommand(), BeginImplicitTransactionBlock(), CHECK_FOR_INTERRUPTS, check_log_duration(), check_log_statement(), CommandCounterIncrement(), CreateCommandTag(), CreateDestReceiver(), CreatePortal(), CURSOR_OPT_BINARY, CURSOR_OPT_PARALLEL_OK, PortalData::cursorOptions, debug_query_string, generate_unaccent_rules::dest, DestRemote, disable_statement_timeout(), drop_unnamed_stmt(), EndCommand(), EndImplicitTransactionBlock(), ereport, errcode(), errdetail_abort(), errdetail_execute(), errhidestmt(), errmsg(), ERROR, FETCH_ALL, finish_xact_command(), format, GetCommandTagNameAndLen(), GetPortalByName(), GetTransactionSnapshot(), if(), InvalidSnapshot, IsA, IsAbortedTransactionBlockState(), IsTransactionExitStmt(), lfirst_node, list_length(), lnext(), LOG, log_statement_stats, MemoryContextDelete(), MemoryContextSwitchTo(), MessageContext, MyXactFlags, NullCommand(), pg_analyze_and_rewrite_fixedparams(), pg_parse_query(), pg_plan_queries(), pgstat_report_activity(), pgstat_report_plan_id(), pgstat_report_query_id(), PopActiveSnapshot(), PortalDefineQuery(), PortalDrop(), PortalIsValid, PortalRun(), PortalSetResultFormat(), PortalStart(), PushActiveSnapshot(), _DestReceiver::rDestroy, ResetUsage(), set_ps_display_with_len(), SetRemoteDestReceiverParams(), ShowUsage(), start_xact_command(), STATE_RUNNING, RawStmt::stmt, stmt, PortalData::visible, whereToSendOutput, and XACT_FLAGS_NEEDIMMEDIATECOMMIT.
Referenced by PostgresMain().
◆ finish_xact_command()
static void finish_xact_command ( void ) | static |
---|
◆ FloatExceptionHandler()
Definition at line 3075 of file postgres.c.
3076{
3077
3079 (errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
3080 errmsg("floating-point exception"),
3081 errdetail("An invalid floating-point operation was signaled. "
3082 "This probably means an out-of-range result or an "
3083 "invalid operation, such as division by zero.")));
3084}
References ereport, errcode(), errdetail(), errmsg(), and ERROR.
Referenced by AutoVacLauncherMain(), AutoVacWorkerMain(), BackgroundWorkerMain(), plperl_init_interp(), PostgresMain(), and ReplSlotSyncWorkerMain().
◆ forbidden_in_wal_sender()
static void forbidden_in_wal_sender ( char firstchar) | static |
---|
◆ get_stats_option_name()
const char * get_stats_option_name | ( | const char * | arg | ) |
---|
Definition at line 3755 of file postgres.c.
3756{
3757 switch (arg[0])
3758 {
3759 case 'p':
3760 if (optarg[1] == 'a')
3761 return "log_parser_stats";
3762 else if (optarg[1] == 'l')
3763 return "log_planner_stats";
3764 break;
3765
3766 case 'e':
3767 return "log_executor_stats";
3768 break;
3769 }
3770
3771 return NULL;
3772}
PGDLLIMPORT char * optarg
Referenced by PostmasterMain(), and process_postgres_switches().
◆ HandleRecoveryConflictInterrupt()
◆ interactive_getc()
static int interactive_getc ( void ) | static |
---|
◆ InteractiveBackend()
static int InteractiveBackend ( StringInfo inBuf) | static |
---|
Definition at line 236 of file postgres.c.
237{
238 int c;
239
240
241
242
245
247
248
249
250
252 {
253 if (c == '\n')
254 {
256 {
257
258
259
260
261 if (inBuf->len > 1 &&
262 inBuf->data[inBuf->len - 1] == '\n' &&
263 inBuf->data[inBuf->len - 2] == ';')
264 {
265
266 break;
267 }
268 }
269 else
270 {
271
272
273
274
275 if (inBuf->len > 0 &&
276 inBuf->data[inBuf->len - 1] == '\\')
277 {
278
279 inBuf->data[--inBuf->len] = '\0';
280
281 continue;
282 }
283 else
284 {
285
287 break;
288 }
289 }
290 }
291
292
294 }
295
296
297 if (c == EOF && inBuf->len == 0)
298 return EOF;
299
300
301
302
303
304
306
307
308
309
311 printf("statement: %s\n", inBuf->data);
313
315}
static bool UseSemiNewlineNewline
static int interactive_getc(void)
void resetStringInfo(StringInfo str)
void appendStringInfoChar(StringInfo str, char ch)
References appendStringInfoChar(), StringInfoData::data, EchoQuery, interactive_getc(), StringInfoData::len, PqMsg_Query, printf, resetStringInfo(), generate_unaccent_rules::stdout, and UseSemiNewlineNewline.
Referenced by ReadCommand().
◆ IsTransactionExitStmt()
static bool IsTransactionExitStmt ( Node * parsetree) | static |
---|
◆ IsTransactionExitStmtList()
static bool IsTransactionExitStmtList ( List * pstmts) | static |
---|
◆ IsTransactionStmtList()
static bool IsTransactionStmtList ( List * pstmts) | static |
---|
◆ log_disconnections()
static void log_disconnections ( int code, Datum arg ) | static |
---|
Definition at line 5173 of file postgres.c.
5174{
5176 long secs;
5177 int usecs;
5178 int msecs;
5179 int hours,
5180 minutes,
5181 seconds;
5182
5185 &secs, &usecs);
5186 msecs = usecs / 1000;
5187
5192
5194 (errmsg("disconnection: session time: %d:%02d:%02d.%03d "
5195 "user=%s database=%s host=%s%s%s",
5196 hours, minutes, seconds, msecs,
5197 port->user_name, port->database_name, port->remote_host,
5198 port->remote_port[0] ? " port=" : "", port->remote_port)));
5199}
TimestampTz MyStartTimestamp
References ereport, errmsg(), GetCurrentTimestamp(), LOG, MyProcPort, MyStartTimestamp, port, SECS_PER_HOUR, SECS_PER_MINUTE, and TimestampDifference().
Referenced by PostgresMain().
◆ 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 665 of file postgres.c.
670{
672 List *querytree_list;
673
674 TRACE_POSTGRESQL_QUERY_REWRITE_START(query_string);
675
676
677
678
681
683 queryEnv);
684
686 ShowUsage("PARSE ANALYSIS STATISTICS");
687
688
689
690
692
693 TRACE_POSTGRESQL_QUERY_REWRITE_DONE(query_string);
694
695 return querytree_list;
696}
Query * parse_analyze_fixedparams(RawStmt *parseTree, const char *sourceText, const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv)
List * pg_rewrite_query(Query *query)
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 704 of file postgres.c.
709{
711 List *querytree_list;
712
713 TRACE_POSTGRESQL_QUERY_REWRITE_START(query_string);
714
715
716
717
720
722 queryEnv);
723
724
725
726
727 for (int i = 0; i < *numParams; i++)
728 {
729 Oid ptype = (*paramTypes)[i];
730
731 if (ptype == InvalidOid || ptype == UNKNOWNOID)
733 (errcode(ERRCODE_INDETERMINATE_DATATYPE),
734 errmsg("could not determine data type of parameter $%d",
735 i + 1)));
736 }
737
739 ShowUsage("PARSE ANALYSIS STATISTICS");
740
741
742
743
745
746 TRACE_POSTGRESQL_QUERY_REWRITE_DONE(query_string);
747
748 return querytree_list;
749}
Query * parse_analyze_varparams(RawStmt *parseTree, const char *sourceText, Oid **paramTypes, int *numParams, QueryEnvironment *queryEnv)
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()
Definition at line 758 of file postgres.c.
763{
765 List *querytree_list;
766
767 TRACE_POSTGRESQL_QUERY_REWRITE_START(query_string);
768
769
770
771
774
775 query = parse_analyze_withcb(parsetree, query_string, parserSetup, parserSetupArg,
776 queryEnv);
777
779 ShowUsage("PARSE ANALYSIS STATISTICS");
780
781
782
783
785
786 TRACE_POSTGRESQL_QUERY_REWRITE_DONE(query_string);
787
788 return querytree_list;
789}
Query * parse_analyze_withcb(RawStmt *parseTree, const char *sourceText, ParserSetupHook parserSetup, void *parserSetupArg, QueryEnvironment *queryEnv)
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
611
613
616
617#ifdef DEBUG_NODE_TESTS_ENABLED
618
619
620 if (Debug_copy_parse_plan_trees)
621 {
623
624
626 elog(WARNING, "copyObject() failed to produce an equal raw parse tree");
627 else
628 raw_parsetree_list = new_list;
629 }
630
631
632
633
634
635 if (Debug_write_read_parse_plan_trees)
636 {
639
641
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
649
650 TRACE_POSTGRESQL_QUERY_PARSE_DONE(query_string);
651
652 return raw_parsetree_list;
653}
List * raw_parser(const char *str, RawParseMode mode)
bool equal(const void *a, const void *b)
static List * new_list(NodeTag type, int min_size)
char * nodeToStringWithLocations(const void *obj)
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(), 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 970 of file postgres.c.
972{
975
976 foreach(query_list, querytrees)
977 {
980
982 {
983
986 stmt->canSetTag = query->canSetTag;
989 stmt->stmt_len = query->stmt_len;
990 stmt->queryId = query->queryId;
991 }
992 else
993 {
995 boundParams);
996 }
997
999 }
1000
1001 return stmt_list;
1002}
List * lappend(List *list, void *datum)
PlannedStmt * pg_plan_query(Query *querytree, const char *query_string, int cursorOptions, ParamListInfo boundParams)
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(), execute_sql_string(), and UpdateCachedPlan().
◆ pg_plan_query()
Definition at line 882 of file postgres.c.
884{
886
887
889 return NULL;
890
891
893
894 TRACE_POSTGRESQL_QUERY_PLAN_START();
895
898
899
901
904
905#ifdef DEBUG_NODE_TESTS_ENABLED
906
907
908 if (Debug_copy_parse_plan_trees)
909 {
911
912
913
914
915
916#ifdef NOT_USED
917
919 elog(WARNING, "copyObject() failed to produce an equal plan tree");
920 else
921#endif
922 plan = new_plan;
923 }
924
925
926 if (Debug_write_read_parse_plan_trees)
927 {
928 char *str;
930
932 new_plan = stringToNodeWithLocations(str);
934
935
936
937
938
939#ifdef NOT_USED
940
942 elog(WARNING, "outfuncs/readfuncs failed to produce an equal plan tree");
943 else
944#endif
945 plan = new_plan;
946 }
947
948#endif
949
950
951
952
955
956 TRACE_POSTGRESQL_QUERY_PLAN_DONE();
957
959}
Datum querytree(PG_FUNCTION_ARGS)
void elog_node_display(int lev, const char *title, const void *obj, bool pretty)
PlannedStmt * planner(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
bool ActiveSnapshotSet(void)
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()
Definition at line 798 of file postgres.c.
799{
800 List *querytree_list;
801
805
808
810 {
811
813 }
814 else
815 {
816
818 }
819
821 ShowUsage("REWRITER STATISTICS");
822
823#ifdef DEBUG_NODE_TESTS_ENABLED
824
825
826 if (Debug_copy_parse_plan_trees)
827 {
829
831
833 elog(WARNING, "copyObject() failed to produce an equal rewritten parse tree");
834 else
836 }
837
838
839 if (Debug_write_read_parse_plan_trees)
840 {
843
844 foreach(lc, querytree_list)
845 {
848 Query *new_query = stringToNodeWithLocations(str);
849
850
851
852
853
854 new_query->queryId = curr_query->queryId;
855
858 }
859
860
862 elog(WARNING, "outfuncs/readfuncs failed to produce an equal rewritten parse tree");
863 else
865 }
866
867#endif
868
872
873 return querytree_list;
874}
bool Debug_print_rewritten
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()
void PostgresMain | ( | const char * | dbname, |
---|---|---|---|
const char * | username | ||
) |
Definition at line 4189 of file postgres.c.
4190{
4191 sigjmp_buf local_sigjmp_buf;
4192
4193
4194 volatile bool send_ready_for_query = true;
4195 volatile bool idle_in_transaction_timeout_enabled = false;
4196 volatile bool idle_session_timeout_enabled = false;
4197
4200
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4220 else
4221 {
4225
4226
4227
4228
4229
4230
4231
4232
4233
4236 else
4239
4240
4241
4242
4243
4244
4245
4250
4251
4252
4253
4254
4255 pqsignal(SIGCHLD, SIG_DFL);
4256
4257 }
4258
4259
4261
4262
4263 sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
4264
4265
4266
4267
4268
4271 {
4272 int len;
4273
4277 {
4279 (errcode(ERRCODE_INTERNAL_ERROR),
4280 errmsg("could not generate random cancel key")));
4281 }
4283 }
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4297 NULL);
4298
4299
4300
4301
4302
4304 {
4307 }
4308
4310
4311
4312
4313
4314
4316
4317
4318
4319
4320
4323
4325
4326
4329
4330
4331
4332
4334 {
4336
4340
4343
4344 }
4345
4346
4348 printf("\nPostgreSQL stand-alone backend %s\n", PG_VERSION);
4349
4350
4351
4352
4353
4354
4355
4357 "MessageContext",
4359
4360
4361
4362
4363
4364
4365
4367 "RowDescriptionContext",
4372
4373
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398 if (sigsetjmp(local_sigjmp_buf, 1) != 0)
4399 {
4400
4401
4402
4403
4404
4405
4406
4407
4408
4410
4411
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4427 idle_in_transaction_timeout_enabled = false;
4428 idle_session_timeout_enabled = false;
4429
4430
4432
4433
4435
4436
4438
4439
4440
4441
4442
4444
4445
4446
4447
4448
4450
4451
4452
4453
4455
4458
4460
4461
4462
4463
4464
4465
4466
4467
4470
4471
4473
4475
4476
4477
4478
4479
4482
4483
4484
4485
4486
4487
4490
4491
4493
4494
4495
4496
4497
4498
4499
4500
4501
4504 (errcode(ERRCODE_PROTOCOL_VIOLATION),
4505 errmsg("terminating connection because protocol synchronization was lost")));
4506
4507
4509 }
4510
4511
4513
4515 send_ready_for_query = true;
4516
4517
4518
4519
4520
4521 for (;;)
4522 {
4523 int firstchar;
4525
4526
4527
4528
4529
4531
4532
4533
4534
4535#ifdef USE_VALGRIND
4536 old_valgrind_error_count = VALGRIND_COUNT_ERRORS;
4537#endif
4538
4539
4540
4541
4542
4545
4547
4548
4549
4550
4551
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570 if (send_ready_for_query)
4571 {
4573 {
4576
4577
4580 {
4581 idle_in_transaction_timeout_enabled = true;
4584 }
4585 }
4587 {
4590
4591
4594 {
4595 idle_in_transaction_timeout_enabled = true;
4598 }
4599 }
4600 else
4601 {
4602 long stats_timeout;
4603
4604
4605
4606
4607
4608
4609
4610
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4628 if (stats_timeout > 0)
4629 {
4632 stats_timeout);
4633 }
4634 else
4635 {
4636
4639 }
4640
4643
4644
4646 {
4647 idle_session_timeout_enabled = true;
4650 }
4651 }
4652
4653
4655
4656
4657
4658
4659
4660
4664 {
4665 uint64 total_duration,
4666 fork_duration,
4667 auth_duration;
4668
4670
4671 total_duration =
4674 fork_duration =
4677 auth_duration =
4680
4682 errmsg("connection ready: setup total=%.3f ms, fork=%.3f ms, authentication=%.3f ms",
4683 (double) total_duration / NS_PER_US,
4684 (double) fork_duration / NS_PER_US,
4685 (double) auth_duration / NS_PER_US));
4686 }
4687
4689 send_ready_for_query = false;
4690 }
4691
4692
4693
4694
4695
4696
4697
4699
4700
4701
4702
4703 firstchar = ReadCommand(&input_message);
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713 if (idle_in_transaction_timeout_enabled)
4714 {
4716 idle_in_transaction_timeout_enabled = false;
4717 }
4718 if (idle_session_timeout_enabled)
4719 {
4721 idle_session_timeout_enabled = false;
4722 }
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4735
4736
4737
4738
4739
4741 {
4744 }
4745
4746
4747
4748
4749
4751 continue;
4752
4753 switch (firstchar)
4754 {
4756 {
4757 const char *query_string;
4758
4759
4761
4764
4766 {
4769 }
4770 else
4772
4774
4775 send_ready_for_query = true;
4776 }
4777 break;
4778
4780 {
4781 const char *stmt_name;
4782 const char *query_string;
4783 int numParams;
4784 Oid *paramTypes = NULL;
4785
4787
4788
4790
4793 numParams = pq_getmsgint(&input_message, 2);
4794 if (numParams > 0)
4795 {
4797 for (int i = 0; i < numParams; i++)
4798 paramTypes[i] = pq_getmsgint(&input_message, 4);
4799 }
4801
4803 paramTypes, numParams);
4804
4806 }
4807 break;
4808
4811
4812
4814
4815
4816
4817
4818
4820
4821
4822 break;
4823
4825 {
4826 const char *portal_name;
4827 int max_rows;
4828
4830
4831
4833
4837
4839
4840
4841 }
4842 break;
4843
4846
4847
4849
4850
4853
4854
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4868
4870
4871
4873
4875
4876 send_ready_for_query = true;
4877 break;
4878
4880 {
4881 int close_type;
4882 const char *close_target;
4883
4885
4889
4890 switch (close_type)
4891 {
4892 case 'S':
4893 if (close_target[0] != '\0')
4895 else
4896 {
4897
4899 }
4900 break;
4901 case 'P':
4902 {
4904
4908 }
4909 break;
4910 default:
4912 (errcode(ERRCODE_PROTOCOL_VIOLATION),
4913 errmsg("invalid CLOSE message subtype %d",
4914 close_type)));
4915 break;
4916 }
4917
4920
4922 }
4923 break;
4924
4926 {
4927 int describe_type;
4928 const char *describe_target;
4929
4931
4932
4934
4938
4939 switch (describe_type)
4940 {
4941 case 'S':
4943 break;
4944 case 'P':
4946 break;
4947 default:
4949 (errcode(ERRCODE_PROTOCOL_VIOLATION),
4950 errmsg("invalid DESCRIBE message subtype %d",
4951 describe_type)));
4952 break;
4953 }
4954
4956 }
4957 break;
4958
4963 break;
4964
4967
4968
4969
4970
4971
4972
4976 send_ready_for_query = true;
4977 break;
4978
4979
4980
4981
4982
4983
4984 case EOF:
4985
4986
4988
4989
4990
4992
4993
4994
4995
4996
4999
5000
5001
5002
5003
5004
5005
5006
5008
5012
5013
5014
5015
5016
5017
5018 break;
5019
5020 default:
5022 (errcode(ERRCODE_PROTOCOL_VIOLATION),
5023 errmsg("invalid frontend message type %d",
5024 firstchar)));
5025 }
5026 }
5027}
void ProcessNotifyInterrupt(bool flush)
volatile sig_atomic_t notifyInterruptPending
void DropPreparedStatement(const char *stmt_name, bool showError)
ConnectionTiming conn_timing
@ LOG_CONNECTION_SETUP_DURATIONS
@ STATE_IDLEINTRANSACTION_ABORTED
@ STATE_IDLEINTRANSACTION
#define TIMESTAMP_MINUS_INFINITY
void ReadyForQuery(CommandDest dest)
void EmitErrorReport(void)
void FlushErrorState(void)
sigjmp_buf * PG_exception_stack
void EventTriggerOnLogin(void)
void HandleFunctionRequest(StringInfo msgBuf)
volatile sig_atomic_t QueryCancelPending
uint8 MyCancelKey[MAX_CANCEL_KEY_LENGTH]
void ProcessConfigFile(GucContext context)
void BeginReportingGUCOptions(void)
void ReportChangedGUCOptions(void)
volatile sig_atomic_t ConfigReloadPending
void SignalHandlerForConfigReload(SIGNAL_ARGS)
void on_proc_exit(pg_on_exit_callback function, Datum arg)
void jit_reset_after_error(void)
void MemoryContextReset(MemoryContext context)
MemoryContext PostmasterContext
#define RESUME_INTERRUPTS()
#define IsExternalConnectionBackend(backend_type)
#define GetProcessingMode()
#define INIT_PG_LOAD_SESSION_LIBS
#define HOLD_INTERRUPTS()
#define SetProcessingMode(mode)
BackendType MyBackendType
long pgstat_report_stat(bool force)
void pgstat_report_connect(Oid dboid)
bool pg_strong_random(void *buf, size_t len)
void PortalErrorCleanup(void)
static void exec_describe_statement_message(const char *stmt_name)
void quickdie(SIGNAL_ARGS)
static void log_disconnections(int code, Datum arg)
static void forbidden_in_wal_sender(char firstchar)
static void exec_execute_message(const char *portal_name, long max_rows)
void FloatExceptionHandler(SIGNAL_ARGS)
void StatementCancelHandler(SIGNAL_ARGS)
static bool ignore_till_sync
static void exec_simple_query(const char *query_string)
static void exec_parse_message(const char *query_string, const char *stmt_name, Oid *paramTypes, int numParams)
static void exec_bind_message(StringInfo input_message)
static MemoryContext row_description_context
static bool doing_extended_query_message
static void exec_describe_portal_message(const char *portal_name)
static int ReadCommand(StringInfo inBuf)
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bits32 flags, char *out_dbname)
bool pq_is_reading_msg(void)
#define PG_PROTOCOL(m, n)
void pq_sendbytes(StringInfo buf, const void *data, int datalen)
void pq_endmessage(StringInfo buf)
int pq_getmsgbyte(StringInfo msg)
void pq_beginmessage(StringInfo buf, char msgtype)
void procsignal_sigusr1_handler(SIGNAL_ARGS)
#define MAX_CANCEL_KEY_LENGTH
#define PqMsg_CloseComplete
#define PqMsg_BackendKeyData
ReplicationSlot * MyReplicationSlot
void ReplicationSlotRelease(void)
void ReplicationSlotCleanup(bool synced_only)
void InvalidateCatalogSnapshotConditionally(void)
int IdleInTransactionSessionTimeout
TimestampTz ready_for_use
TimestampTz socket_create
void disable_all_timeouts(bool keep_indicators)
void InitializeTimeouts(void)
@ IDLE_IN_TRANSACTION_SESSION_TIMEOUT
@ IDLE_STATS_UPDATE_TIMEOUT
static uint64 TimestampDifferenceMicroseconds(TimestampTz start_time, TimestampTz stop_time)
void WalSndErrorCleanup(void)
bool exec_replication_command(const char *cmd_string)
bool IsTransactionOrTransactionBlock(void)
void SetCurrentStatementStartTimestamp(void)
void AbortCurrentTransaction(void)
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()
void PostgresSingleUserMain | ( | int | argc, |
---|---|---|---|
char * | _argv_[], | ||
const char * | username | ||
) |
Definition at line 4060 of file postgres.c.
4062{
4063 const char *dbname = NULL;
4064
4066
4067
4069
4070
4071
4072
4074
4075
4076
4077
4079
4080
4082 {
4086 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4087 errmsg("%s: no database nor user name specified",
4089 }
4090
4091
4094
4095
4096
4097
4098
4101
4102
4103
4104
4106
4107
4109
4110
4111
4112
4114
4115
4117
4118
4119
4120
4121
4123
4124
4126
4127
4128
4129
4131
4132
4133
4134
4135
4136
4138
4139
4140
4141
4142
4144
4145
4146
4147
4148
4150
4151
4152
4153
4154
4156
4157
4158
4159
4160
4162
4163
4164
4165
4166
4168
4169
4170
4171
4172
4174}
void set_max_safe_fds(void)
bool SelectConfigFiles(const char *userDoption, const char *progname)
void InitializeGUCOptions(void)
void InitializeShmemGUCs(void)
void CreateSharedMemoryAndSemaphores(void)
void ChangeToDataDir(void)
void process_shmem_requests(void)
void InitStandaloneProcess(const char *argv0)
void process_shared_preload_libraries(void)
void CreateDataDirLockFile(bool amPostmaster)
void InitPostmasterChildSlots(void)
void process_postgres_switches(int argc, char *argv[], GucContext ctx, const char **dbname)
static const char * userDoption
void PostgresMain(const char *dbname, const char *username)
void InitializeMaxBackends(void)
void InitializeFastPathLocks(void)
void InitializeWalConsistencyChecking(void)
void LocalProcessControlFile(bool reset)
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 3795 of file postgres.c.
3797{
3799 int errs = 0;
3802
3803 if (secure)
3804 {
3805 gucsource = PGC_S_ARGV;
3806
3807
3808 if (argc > 1 && strcmp(argv[1], "--single") == 0)
3809 {
3810 argv++;
3811 argc--;
3812 }
3813 }
3814 else
3815 {
3816 gucsource = PGC_S_CLIENT;
3817 }
3818
3819#ifdef HAVE_INT_OPTERR
3820
3821
3822
3823
3824
3825
3827#endif
3828
3829
3830
3831
3832
3833
3834 while ((flag = getopt(argc, argv, "B:bC:c:D:d:EeFf:h:ijk:lN:nOPp:r:S:sTt:v:W:-:")) != -1)
3835 {
3836 switch (flag)
3837 {
3838 case 'B':
3840 break;
3841
3842 case 'b':
3843
3844 if (secure)
3846 break;
3847
3848 case 'C':
3849
3850 break;
3851
3852 case '-':
3853
3854
3855
3856
3857
3858
3859
3862 (errcode(ERRCODE_SYNTAX_ERROR),
3863 errmsg("--%s must be first argument", optarg)));
3864
3865
3866 case 'c':
3867 {
3870
3873 {
3874 if (flag == '-')
3876 (errcode(ERRCODE_SYNTAX_ERROR),
3877 errmsg("--%s requires a value",
3879 else
3881 (errcode(ERRCODE_SYNTAX_ERROR),
3882 errmsg("-c %s requires a value",
3884 }
3888 break;
3889 }
3890
3891 case 'D':
3892 if (secure)
3894 break;
3895
3896 case 'd':
3898 break;
3899
3900 case 'E':
3901 if (secure)
3903 break;
3904
3905 case 'e':
3907 break;
3908
3909 case 'F':
3911 break;
3912
3913 case 'f':
3915 errs++;
3916 break;
3917
3918 case 'h':
3920 break;
3921
3922 case 'i':
3923 SetConfigOption("listen_addresses", "*", ctx, gucsource);
3924 break;
3925
3926 case 'j':
3927 if (secure)
3929 break;
3930
3931 case 'k':
3933 break;
3934
3935 case 'l':
3937 break;
3938
3939 case 'N':
3941 break;
3942
3943 case 'n':
3944
3945 break;
3946
3947 case 'O':
3948 SetConfigOption("allow_system_table_mods", "true", ctx, gucsource);
3949 break;
3950
3951 case 'P':
3952 SetConfigOption("ignore_system_indexes", "true", ctx, gucsource);
3953 break;
3954
3955 case 'p':
3957 break;
3958
3959 case 'r':
3960
3961 if (secure)
3963 break;
3964
3965 case 'S':
3967 break;
3968
3969 case 's':
3970 SetConfigOption("log_statement_stats", "true", ctx, gucsource);
3971 break;
3972
3973 case 'T':
3974
3975 break;
3976
3977 case 't':
3978 {
3980
3981 if (tmp)
3983 else
3984 errs++;
3985 break;
3986 }
3987
3988 case 'v':
3989
3990
3991
3992
3993
3994
3995
3996
3997 if (secure)
3999 break;
4000
4001 case 'W':
4003 break;
4004
4005 default:
4006 errs++;
4007 break;
4008 }
4009
4010 if (errs)
4011 break;
4012 }
4013
4014
4015
4016
4019
4020 if (errs || argc != optind)
4021 {
4022 if (errs)
4023 optind--;
4024
4025
4028 errcode(ERRCODE_SYNTAX_ERROR),
4029 errmsg("invalid command-line argument for server process: %s", argv[optind]),
4030 errhint("Try \"%s --help\" for more information.", progname));
4031 else
4033 errcode(ERRCODE_SYNTAX_ERROR),
4034 errmsg("%s: invalid command-line argument: %s",
4036 errhint("Try \"%s --help\" for more information.", progname));
4037 }
4038
4039
4040
4041
4042
4044#ifdef HAVE_INT_OPTRESET
4045 optreset = 1;
4046#endif
4047}
int errhint(const char *fmt,...)
ProtocolVersion FrontendProtocol
char OutputFileName[MAXPGPATH]
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
void ParseLongOption(const char *string, char **name, char **value)
DispatchOption parse_dispatch_option(const char *name)
int getopt(int nargc, char *const *nargv, const char *ostr)
size_t strlcpy(char *dst, const char *src, size_t siz)
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)
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 | ) |
---|
◆ ProcessClientWriteInterrupt()
void ProcessClientWriteInterrupt | ( | bool | blocked | ) |
---|
◆ ProcessInterrupts()
void ProcessInterrupts | ( | void | ) |
---|
Definition at line 3300 of file postgres.c.
3301{
3302
3304 return;
3306
3308 {
3312
3317 (errcode(ERRCODE_QUERY_CANCELED),
3318 errmsg("canceling authentication due to timeout")));
3321 (errcode(ERRCODE_ADMIN_SHUTDOWN),
3322 errmsg("terminating autovacuum process due to administrator command")));
3325 (errcode(ERRCODE_ADMIN_SHUTDOWN),
3326 errmsg("terminating logical replication worker due to administrator command")));
3328 {
3330 (errmsg_internal("logical replication launcher shutting down")));
3331
3332
3333
3334
3335
3337 }
3340 (errcode(ERRCODE_ADMIN_SHUTDOWN),
3341 errmsg("terminating walreceiver process due to administrator command")));
3344 (errcode(ERRCODE_ADMIN_SHUTDOWN),
3345 errmsg("terminating background worker \"%s\" due to administrator command",
3348 {
3350 (errmsg_internal("io worker shutting down due to administrator command")));
3351
3353 }
3354 else
3356 (errcode(ERRCODE_ADMIN_SHUTDOWN),
3357 errmsg("terminating connection due to administrator command")));
3358 }
3359
3361 {
3363
3364
3365
3366
3367
3368
3369
3371 {
3374 else
3377 }
3378 }
3379
3381 {
3382 QueryCancelPending = false;
3384
3387 (errcode(ERRCODE_CONNECTION_FAILURE),
3388 errmsg("connection to client lost")));
3389 }
3390
3391
3392
3393
3394
3395
3396
3397
3398
3400 {
3401
3402
3403
3404
3405
3406
3407
3408
3410 }
3412 {
3413 bool lock_timeout_occurred;
3414 bool stmt_timeout_occurred;
3415
3417
3418
3419
3420
3421
3424
3425
3426
3427
3428
3429
3430
3431 if (lock_timeout_occurred && stmt_timeout_occurred &&
3433 lock_timeout_occurred = false;
3434
3435 if (lock_timeout_occurred)
3436 {
3439 (errcode(ERRCODE_LOCK_NOT_AVAILABLE),
3440 errmsg("canceling statement due to lock timeout")));
3441 }
3442 if (stmt_timeout_occurred)
3443 {
3446 (errcode(ERRCODE_QUERY_CANCELED),
3447 errmsg("canceling statement due to statement timeout")));
3448 }
3450 {
3453 (errcode(ERRCODE_QUERY_CANCELED),
3454 errmsg("canceling autovacuum task")));
3455 }
3456
3457
3458
3459
3460
3461
3463 {
3466 (errcode(ERRCODE_QUERY_CANCELED),
3467 errmsg("canceling statement due to user request")));
3468 }
3469 }
3470
3473
3475 {
3476
3477
3478
3479
3480
3481
3484 {
3485 INJECTION_POINT("idle-in-transaction-session-timeout", NULL);
3487 (errcode(ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT),
3488 errmsg("terminating connection due to idle-in-transaction timeout")));
3489 }
3490 }
3491
3493 {
3494
3497 {
3500 (errcode(ERRCODE_TRANSACTION_TIMEOUT),
3501 errmsg("terminating connection due to transaction timeout")));
3502 }
3503 }
3504
3506 {
3507
3510 {
3513 (errcode(ERRCODE_IDLE_SESSION_TIMEOUT),
3514 errmsg("terminating connection due to idle-session timeout")));
3515 }
3516 }
3517
3518
3519
3520
3521
3524 {
3527 }
3528
3531
3534
3537
3540
3543}
volatile sig_atomic_t ParallelApplyMessagePending
void ProcessParallelApplyMessages(void)
void ProcessParallelMessages(void)
volatile sig_atomic_t ParallelMessagePending
bool IsLogicalWorker(void)
volatile sig_atomic_t IdleStatsUpdateTimeoutPending
volatile sig_atomic_t LogMemoryContextPending
volatile sig_atomic_t ProcSignalBarrierPending
volatile sig_atomic_t IdleSessionTimeoutPending
volatile uint32 QueryCancelHoldoffCount
volatile sig_atomic_t IdleInTransactionSessionTimeoutPending
volatile sig_atomic_t TransactionTimeoutPending
volatile sig_atomic_t ClientConnectionLost
volatile sig_atomic_t PublishMemoryContextPending
volatile sig_atomic_t CheckClientConnectionPending
#define INJECTION_POINT(name, arg)
bool IsLogicalLauncher(void)
void ProcessGetMemoryContextInterrupt(void)
void ProcessLogMemoryContextInterrupt(void)
#define AmAutoVacuumWorkerProcess()
#define AmBackgroundWorkerProcess()
#define AmWalReceiverProcess()
#define AmIoWorkerProcess()
int client_connection_check_interval
static void ProcessRecoveryConflictInterrupts(void)
bool ClientAuthInProgress
BackgroundWorker * MyBgworkerEntry
bool pq_check_connection(void)
void ProcessProcSignalBarrier(void)
void LockErrorCleanup(void)
char bgw_type[BGW_MAXLEN]
TimestampTz get_timeout_finish_time(TimeoutId id)
bool get_timeout_indicator(TimeoutId id, bool reset_indicator)
@ CLIENT_CONNECTION_CHECK_TIMEOUT
References AmAutoVacuumWorkerProcess, AmBackgroundWorkerProcess, AmIoWorkerProcess, AmWalReceiverProcess, BackgroundWorker::bgw_type, CheckClientConnectionPending, client_connection_check_interval, CLIENT_CONNECTION_CHECK_TIMEOUT, ClientAuthInProgress, ClientConnectionLost, CritSectionCount, DEBUG1, DestNone, DestRemote, DoingCommandRead, enable_timeout_after(), ereport, errcode(), errmsg(), errmsg_internal(), ERROR, FATAL, get_timeout_finish_time(), get_timeout_indicator(), IdleInTransactionSessionTimeout, IdleInTransactionSessionTimeoutPending, IdleSessionTimeout, IdleSessionTimeoutPending, IdleStatsUpdateTimeoutPending, INJECTION_POINT, InterruptHoldoffCount, InterruptPending, IsLogicalLauncher(), IsLogicalWorker(), IsTransactionOrTransactionBlock(), LOCK_TIMEOUT, LockErrorCleanup(), LogMemoryContextPending, MyBgworkerEntry, ParallelApplyMessagePending, ParallelMessagePending, pgstat_report_stat(), pq_check_connection(), proc_exit(), ProcDiePending, ProcessGetMemoryContextInterrupt(), ProcessLogMemoryContextInterrupt(), ProcessParallelApplyMessages(), ProcessParallelMessages(), ProcessProcSignalBarrier(), ProcessRecoveryConflictInterrupts(), ProcSignalBarrierPending, PublishMemoryContextPending, QueryCancelHoldoffCount, QueryCancelPending, RecoveryConflictPending, STATEMENT_TIMEOUT, TransactionTimeout, TransactionTimeoutPending, and whereToSendOutput.
Referenced by die().
◆ ProcessRecoveryConflictInterrupt()
Definition at line 3103 of file postgres.c.
3104{
3105 switch (reason)
3106 {
3108
3109
3110
3111
3113 return;
3114
3115
3116
3117
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3131 {
3135 return;
3136 }
3137
3139
3140
3141
3142
3146
3147
3148
3149
3151 return;
3152
3153
3154
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3184 {
3185
3186
3187
3188
3189
3191 return;
3192
3193
3194
3195
3196
3197
3198
3199
3201 {
3202
3204 {
3205
3206
3207
3208
3212 return;
3213 }
3214
3215
3216
3217
3218
3219
3220
3225 errmsg("canceling statement due to conflict with recovery"),
3227 break;
3228 }
3229 }
3230
3231
3232
3233
3235
3236
3237
3238
3239
3240
3244 ERRCODE_DATABASE_DROPPED :
3246 errmsg("terminating connection due to conflict with recovery"),
3248 errhint("In a moment you should be able to reconnect to the"
3249 " database and repeat your command.")));
3250 break;
3251
3252 default:
3253 elog(FATAL, "unrecognized conflict mode: %d", (int) reason);
3254 }
3255}
bool HoldingBufferPinThatDelaysRecovery(void)
LOCALLOCK * GetAwaitedLock(void)
#define ERRCODE_T_R_SERIALIZATION_FAILURE
void pgstat_report_recovery_conflict(int reason)
static int errdetail_recovery_conflict(ProcSignalReason reason)
int GetStartupBufferPinWaitBufId(void)
void CheckDeadLockAlert(void)
bool IsSubTransaction(void)
References CheckDeadLockAlert(), DoingCommandRead, elog, ereport, errcode(), ERRCODE_T_R_SERIALIZATION_FAILURE, errdetail_recovery_conflict(), errhint(), errmsg(), ERROR, FATAL, GetAwaitedLock(), GetStartupBufferPinWaitBufId(), HoldingBufferPinThatDelaysRecovery(), InterruptPending, IsAbortedTransactionBlockState(), IsSubTransaction(), IsTransactionOrTransactionBlock(), LockErrorCleanup(), MyProc, pgstat_report_recovery_conflict(), PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, PROCSIG_RECOVERY_CONFLICT_DATABASE, PROCSIG_RECOVERY_CONFLICT_LOCK, PROCSIG_RECOVERY_CONFLICT_LOGICALSLOT, PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, PROCSIG_RECOVERY_CONFLICT_TABLESPACE, QueryCancelHoldoffCount, RecoveryConflictPending, PGPROC::recoveryConflictPending, and RecoveryConflictPendingReasons.
Referenced by ProcessRecoveryConflictInterrupts().
◆ ProcessRecoveryConflictInterrupts()
static void ProcessRecoveryConflictInterrupts ( void ) | static |
---|
◆ quickdie()
Definition at line 2931 of file postgres.c.
2932{
2933 sigaddset(&BlockSig, SIGQUIT);
2934 sigprocmask(SIG_SETMASK, &BlockSig, NULL);
2935
2936
2937
2938
2939
2940
2942
2943
2944
2945
2946
2947
2948
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2969
2970
2971
2972
2973
2974
2975
2976
2977
2979 {
2981
2983 (errcode(ERRCODE_ADMIN_SHUTDOWN),
2984 errmsg("terminating connection because of unexpected SIGQUIT signal")));
2985 break;
2987
2989 (errcode(ERRCODE_CRASH_SHUTDOWN),
2990 errmsg("terminating connection because of crash of another server process"),
2991 errdetail("The postmaster has commanded this server process to roll back"
2992 " the current transaction and exit, because another"
2993 " server process exited abnormally and possibly corrupted"
2994 " shared memory."),
2995 errhint("In a moment you should be able to reconnect to the"
2996 " database and repeat your command.")));
2997 break;
2999
3001 (errcode(ERRCODE_ADMIN_SHUTDOWN),
3002 errmsg("terminating connection due to immediate shutdown command")));
3003 break;
3004 }
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020 _exit(2);
3021}
#define WARNING_CLIENT_ONLY
QuitSignalReason GetQuitSignalReason(void)
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().
◆ ReadCommand()
◆ ResetUsage()
Definition at line 5057 of file postgres.c.
5058{
5061}
static struct timeval Save_t
static struct rusage Save_r
int getrusage(int who, struct rusage *rusage)
int gettimeofday(struct timeval *tp, void *tzp)
References getrusage(), gettimeofday(), RUSAGE_SELF, Save_r, and Save_t.
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().
◆ set_debug_options()
◆ set_plan_disabling_options()
Definition at line 3713 of file postgres.c.
3714{
3715 const char *tmp = NULL;
3716
3717 switch (arg[0])
3718 {
3719 case 's':
3720 tmp = "enable_seqscan";
3721 break;
3722 case 'i':
3723 tmp = "enable_indexscan";
3724 break;
3725 case 'o':
3726 tmp = "enable_indexonlyscan";
3727 break;
3728 case 'b':
3729 tmp = "enable_bitmapscan";
3730 break;
3731 case 't':
3732 tmp = "enable_tidscan";
3733 break;
3734 case 'n':
3735 tmp = "enable_nestloop";
3736 break;
3737 case 'm':
3738 tmp = "enable_mergejoin";
3739 break;
3740 case 'h':
3741 tmp = "enable_hashjoin";
3742 break;
3743 }
3744 if (tmp)
3745 {
3747 return true;
3748 }
3749 else
3750 return false;
3751}
References arg, SetConfigOption(), and source.
Referenced by PostmasterMain(), and process_postgres_switches().
◆ ShowUsage()
void ShowUsage | ( | const char * | title | ) |
---|
Definition at line 5064 of file postgres.c.
5065{
5067 struct timeval user,
5068 sys;
5069 struct timeval elapse_t;
5071
5074 memcpy(&user, &r.ru_utime, sizeof(user));
5075 memcpy(&sys, &r.ru_stime, sizeof(sys));
5076 if (elapse_t.tv_usec < Save_t.tv_usec)
5077 {
5078 elapse_t.tv_sec--;
5079 elapse_t.tv_usec += 1000000;
5080 }
5082 {
5083 r.ru_utime.tv_sec--;
5084 r.ru_utime.tv_usec += 1000000;
5085 }
5087 {
5088 r.ru_stime.tv_sec--;
5089 r.ru_stime.tv_usec += 1000000;
5090 }
5091
5092
5093
5094
5095
5097
5100 "!\t%ld.%06ld s user, %ld.%06ld s system, %ld.%06ld s elapsed\n",
5101 (long) (r.ru_utime.tv_sec - Save_r.ru_utime.tv_sec),
5102 (long) (r.ru_utime.tv_usec - Save_r.ru_utime.tv_usec),
5103 (long) (r.ru_stime.tv_sec - Save_r.ru_stime.tv_sec),
5104 (long) (r.ru_stime.tv_usec - Save_r.ru_stime.tv_usec),
5105 (long) (elapse_t.tv_sec - Save_t.tv_sec),
5106 (long) (elapse_t.tv_usec - Save_t.tv_usec));
5108 "!\t[%ld.%06ld s user, %ld.%06ld s system total]\n",
5109 (long) user.tv_sec,
5110 (long) user.tv_usec,
5111 (long) sys.tv_sec,
5112 (long) sys.tv_usec);
5113#ifndef WIN32
5114
5115
5116
5117
5118
5119
5120
5122 "!\t%ld kB max resident size\n",
5124
5125 r.ru_maxrss / 1024
5126#else
5127
5128 r.ru_maxrss
5129#endif
5130 );
5132 "!\t%ld/%ld [%ld/%ld] filesystem blocks in/out\n",
5133 r.ru_inblock - Save_r.ru_inblock,
5134
5135 r.ru_oublock - Save_r.ru_oublock,
5136 r.ru_inblock, r.ru_oublock);
5138 "!\t%ld/%ld [%ld/%ld] page faults/reclaims, %ld [%ld] swaps\n",
5139 r.ru_majflt - Save_r.ru_majflt,
5140 r.ru_minflt - Save_r.ru_minflt,
5141 r.ru_majflt, r.ru_minflt,
5142 r.ru_nswap - Save_r.ru_nswap,
5143 r.ru_nswap);
5145 "!\t%ld [%ld] signals rcvd, %ld/%ld [%ld/%ld] messages rcvd/sent\n",
5146 r.ru_nsignals - Save_r.ru_nsignals,
5147 r.ru_nsignals,
5148 r.ru_msgrcv - Save_r.ru_msgrcv,
5149 r.ru_msgsnd - Save_r.ru_msgsnd,
5150 r.ru_msgrcv, r.ru_msgsnd);
5152 "!\t%ld/%ld [%ld/%ld] voluntary/involuntary context switches\n",
5153 r.ru_nvcsw - Save_r.ru_nvcsw,
5154 r.ru_nivcsw - Save_r.ru_nivcsw,
5155 r.ru_nvcsw, r.ru_nivcsw);
5156#endif
5157
5158
5159 if (str.data[str.len - 1] == '\n')
5160 str.data[--str.len] = '\0';
5161
5165
5167}
int errdetail_internal(const char *fmt,...)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
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().
◆ SocketBackend()
static int SocketBackend ( StringInfo inBuf) | static |
---|
Definition at line 352 of file postgres.c.
353{
354 int qtype;
355 int maxmsglen;
356
357
358
359
363
364 if (qtype == EOF)
365 {
368 (errcode(ERRCODE_CONNECTION_FAILURE),
369 errmsg("unexpected EOF on client connection with an open transaction")));
370 else
371 {
372
373
374
375
376
379 (errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
380 errmsg_internal("unexpected EOF on client connection")));
381 }
382 return qtype;
383 }
384
385
386
387
388
389
390
391
392
393
394
395 switch (qtype)
396 {
400 break;
401
405 break;
406
411 break;
412
417 break;
418
425 break;
426
429
431
433 break;
434
438 break;
439
444 break;
445
446 default:
447
448
449
450
451
452
454 (errcode(ERRCODE_PROTOCOL_VIOLATION),
455 errmsg("invalid frontend message type %d", qtype)));
456 maxmsglen = 0;
457 break;
458 }
459
460
461
462
463
464
466 return EOF;
468
469 return qtype;
470}
#define PQ_SMALL_MESSAGE_LIMIT
#define PQ_LARGE_MESSAGE_LIMIT
#define HOLD_CANCEL_INTERRUPTS()
#define RESUME_CANCEL_INTERRUPTS()
int pq_getmessage(StringInfo s, int maxlen)
void pq_startmsgread(void)
References COMMERROR, DEBUG1, DestNone, doing_extended_query_message, ereport, errcode(), errmsg(), errmsg_internal(), FATAL, HOLD_CANCEL_INTERRUPTS, ignore_till_sync, IsTransactionState(), pq_getbyte(), pq_getmessage(), PQ_LARGE_MESSAGE_LIMIT, PQ_SMALL_MESSAGE_LIMIT, pq_startmsgread(), PqMsg_Bind, PqMsg_Close, PqMsg_CopyData, PqMsg_CopyDone, PqMsg_CopyFail, PqMsg_Describe, PqMsg_Execute, PqMsg_Flush, PqMsg_FunctionCall, PqMsg_Parse, PqMsg_Query, PqMsg_Sync, PqMsg_Terminate, RESUME_CANCEL_INTERRUPTS, and whereToSendOutput.
Referenced by ReadCommand().
◆ start_xact_command()
static void start_xact_command ( void ) | static |
---|
Definition at line 2788 of file postgres.c.
2789{
2791 {
2793
2795 }
2797 {
2798
2799
2800
2801
2802
2803
2804
2806 }
2807
2808
2809
2810
2811
2812
2813
2814
2816
2817
2824}
static void enable_statement_timeout(void)
void StartTransactionCommand(void)
References BeginImplicitTransactionBlock(), client_connection_check_interval, CLIENT_CONNECTION_CHECK_TIMEOUT, enable_statement_timeout(), enable_timeout_after(), get_timeout_active(), IsUnderPostmaster, MyProcPort, MyXactFlags, StartTransactionCommand(), XACT_FLAGS_PIPELINING, and xact_started.
Referenced by exec_bind_message(), exec_describe_portal_message(), exec_describe_statement_message(), exec_execute_message(), exec_parse_message(), exec_simple_query(), and PostgresMain().
◆ StatementCancelHandler()
◆ client_connection_check_interval
int client_connection_check_interval = 0
◆ debug_query_string
const char* debug_query_string
Definition at line 88 of file postgres.c.
Referenced by _brin_begin_parallel(), _brin_parallel_build_main(), _bt_begin_parallel(), _bt_parallel_build_main(), _gin_begin_parallel(), _gin_parallel_build_main(), check_log_of_query(), current_query(), errstart(), exec_bind_message(), exec_execute_message(), exec_parse_message(), exec_replication_command(), exec_simple_query(), initialize_worker_spi(), parallel_vacuum_init(), parallel_vacuum_main(), ParallelQueryMain(), PostgresMain(), proc_exit_prepare(), send_message_to_server_log(), worker_spi_main(), write_csvlog(), and write_jsonlog().
◆ doing_extended_query_message
bool doing_extended_query_message = false | static |
---|
◆ DoingCommandRead
bool DoingCommandRead = false | static |
---|
◆ EchoQuery
◆ ignore_till_sync
bool ignore_till_sync = false | static |
---|
◆ Log_disconnections
bool Log_disconnections = false
◆ log_statement
◆ PostAuthDelay
◆ RecoveryConflictPending
volatile sig_atomic_t RecoveryConflictPending = false | static |
---|
◆ RecoveryConflictPendingReasons
◆ restrict_nonsystem_relation_kind
int restrict_nonsystem_relation_kind
◆ row_description_buf
◆ row_description_context
◆ Save_r
◆ Save_t
◆ unnamed_stmt_psrc
◆ userDoption
const char* userDoption = NULL | static |
---|
◆ UseSemiNewlineNewline
bool UseSemiNewlineNewline = false | static |
---|
◆ whereToSendOutput
Definition at line 91 of file postgres.c.
Referenced by BackendInitialize(), BeginCopyFrom(), BeginCopyTo(), BeginReportingGUCOptions(), die(), DoCopyTo(), errfinish(), exec_bind_message(), exec_describe_portal_message(), exec_describe_statement_message(), exec_execute_message(), exec_parse_message(), exec_simple_query(), NotifyMyFrontEnd(), PostgresMain(), PostmasterMain(), pq_cleanup_redirect_to_shm_mq(), pq_redirect_to_shm_mq(), ProcessClientWriteInterrupt(), ProcessInterrupts(), quickdie(), ReadCommand(), send_message_to_server_log(), should_output_to_client(), SocketBackend(), SyncRepWaitForLSN(), SysLoggerMain(), and WalSndShutdown().
◆ xact_started
bool xact_started = false | static |
---|