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, ExplainState *es)
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 2598 of file postgres.c.

2599{

2602 char *quotedval;

2603

2604 if (data->paramno < 0)

2605 return;

2606

2607

2608 if (data->paramval)

2609 {

2613 quotedval = buf.data;

2614 }

2615 else

2616 quotedval = NULL;

2617

2618 if (data->portalName && data->portalName[0] != '\0')

2619 {

2620 if (quotedval)

2621 errcontext("portal \"%s\" parameter $%d = %s",

2622 data->portalName, data->paramno + 1, quotedval);

2623 else

2624 errcontext("portal \"%s\" parameter $%d",

2625 data->portalName, data->paramno + 1);

2626 }

2627 else

2628 {

2629 if (quotedval)

2630 errcontext("unnamed portal parameter $%d = %s",

2631 data->paramno + 1, quotedval);

2632 else

2633 errcontext("unnamed portal parameter $%d",

2634 data->paramno + 1);

2635 }

2636

2637 if (quotedval)

2638 pfree(quotedval);

2639}

int log_parameter_max_length_on_error

void pfree(void *pointer)

static char buf[DEFAULT_XLOG_SEG_SIZE]

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

2430{

2433 {

2434 long secs;

2435 int usecs;

2436 int msecs;

2437 bool exceeded_duration;

2438 bool exceeded_sample_duration;

2439 bool in_sample = false;

2440

2443 &secs, &usecs);

2444 msecs = usecs / 1000;

2445

2446

2447

2448

2449

2450

2455

2460

2461

2462

2463

2464

2465

2466 if (exceeded_sample_duration)

2470

2472 {

2473 snprintf(msec_str, 32, "%ld.%03d",

2474 secs * 1000 + msecs, usecs % 1000);

2475 if ((exceeded_duration || in_sample || xact_is_sampled) && !was_logged)

2476 return 2;

2477 else

2478 return 1;

2479 }

2480 }

2481

2482 return 0;

2483}

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

3620{

3621 char *rawstring;

3622 List *elemlist;

3624 int flags = 0;

3625

3626

3628

3630 {

3631

3633 pfree(rawstring);

3635 return false;

3636 }

3637

3638 foreach(l, elemlist)

3639 {

3640 char *tok = (char *) lfirst(l);

3641

3644 else if (pg_strcasecmp(tok, "foreign-table") == 0)

3646 else

3647 {

3649 pfree(rawstring);

3651 return false;

3652 }

3653 }

3654

3655 pfree(rawstring);

3657

3658

3660 if (!*extra)

3661 return false;

3662 *((int *) *extra) = flags;

3663

3664 return true;

3665}

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

3033{

3034

3036 {

3039 }

3040

3041

3043

3044

3046

3047

3048

3049

3050

3051

3052

3055}

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

2493{

2495

2496 foreach(parsetree_item, raw_parsetree_list)

2497 {

2499

2501 {

2504

2506 if (pstmt)

2507 {

2508 errdetail("prepare: %s", pstmt->plansource->query_string);

2509 return 0;

2510 }

2511 }

2512 }

2513

2514 return 0;

2515}

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

1631{

1632 const char *portal_name;

1633 const char *stmt_name;

1634 int numPFormats;

1635 int16 *pformats = NULL;

1636 int numParams;

1637 int numRFormats;

1638 int16 *rformats = NULL;

1642 char *query_string;

1643 char *saved_stmt_name;

1647 bool snapshot_set = false;

1648 char msec_str[32];

1652

1653

1656

1659 *portal_name ? portal_name : "",

1660 *stmt_name ? stmt_name : "")));

1661

1662

1663 if (stmt_name[0] != '\0')

1664 {

1666

1669 }

1670 else

1671 {

1672

1674 if (!psrc)

1676 (errcode(ERRCODE_UNDEFINED_PSTATEMENT),

1677 errmsg("unnamed prepared statement does not exist")));

1678 }

1679

1680

1681

1682

1684

1686

1688 {

1690

1691 if (query->queryId != INT64CONST(0))

1692 {

1694 break;

1695 }

1696 }

1697

1699

1700 if (save_log_statement_stats)

1702

1703

1704

1705

1706

1707

1708

1710

1711

1713

1714

1715 numPFormats = pq_getmsgint(input_message, 2);

1716 if (numPFormats > 0)

1717 {

1719 for (int i = 0; i < numPFormats; i++)

1721 }

1722

1723

1725

1726 if (numPFormats > 1 && numPFormats != numParams)

1728 (errcode(ERRCODE_PROTOCOL_VIOLATION),

1729 errmsg("bind message has %d parameter formats but %d parameters",

1730 numPFormats, numParams)));

1731

1734 (errcode(ERRCODE_PROTOCOL_VIOLATION),

1735 errmsg("bind message supplies %d parameters, but prepared statement \"%s\" requires %d",

1736 numParams, stmt_name, psrc->num_params)));

1737

1738

1739

1740

1741

1742

1743

1744

1745

1749 numParams != 0))

1751 (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),

1752 errmsg("current transaction is aborted, "

1753 "commands ignored until end of transaction block"),

1755

1756

1757

1758

1759

1760 if (portal_name[0] == '\0')

1761 portal = CreatePortal(portal_name, true, true);

1762 else

1763 portal = CreatePortal(portal_name, false, false);

1764

1765

1766

1767

1768

1769

1770

1772

1773

1775

1776

1777 if (stmt_name[0])

1778 saved_stmt_name = pstrdup(stmt_name);

1779 else

1780 saved_stmt_name = NULL;

1781

1782

1783

1784

1785

1786

1787

1788

1789 if (numParams > 0 ||

1792 {

1794 snapshot_set = true;

1795 }

1796

1797

1798

1799

1800 if (numParams > 0)

1801 {

1802 char **knownTextValues = NULL;

1804

1805

1806

1807

1808

1810 one_param_data.paramno = -1;

1811 one_param_data.paramval = NULL;

1814 params_errcxt.arg = &one_param_data;

1816

1818

1819 for (int paramno = 0; paramno < numParams; paramno++)

1820 {

1824 bool isNull;

1826 char csave;

1828

1829 one_param_data.paramno = paramno;

1830 one_param_data.paramval = NULL;

1831

1833 isNull = (plength == -1);

1834

1835 if (!isNull)

1836 {

1837 char *pvalue;

1838

1839

1840

1841

1842

1843

1844

1845

1847 csave = pvalue[plength];

1848 pvalue[plength] = '\0';

1850 }

1851 else

1852 {

1853 pbuf.data = NULL;

1854 csave = 0;

1855 }

1856

1857 if (numPFormats > 1)

1858 pformat = pformats[paramno];

1859 else if (numPFormats > 0)

1860 pformat = pformats[0];

1861 else

1862 pformat = 0;

1863

1864 if (pformat == 0)

1865 {

1866 Oid typinput;

1867 Oid typioparam;

1868 char *pstring;

1869

1871

1872

1873

1874

1875

1876 if (isNull)

1877 pstring = NULL;

1878 else

1880

1881

1882 one_param_data.paramval = pstring;

1883

1885

1886 one_param_data.paramval = NULL;

1887

1888

1889

1890

1891

1892

1893 if (pstring)

1894 {

1896 {

1898

1900

1901 if (knownTextValues == NULL)

1902 knownTextValues = palloc0_array(char *, numParams);

1903

1905 knownTextValues[paramno] = pstrdup(pstring);

1906 else

1907 {

1908

1909

1910

1911

1912

1913

1914

1915 knownTextValues[paramno] =

1919 }

1920

1922 }

1923 if (pstring != pbuf.data)

1925 }

1926 }

1927 else if (pformat == 1)

1928 {

1929 Oid typreceive;

1930 Oid typioparam;

1932

1933

1934

1935

1937

1938 if (isNull)

1939 bufptr = NULL;

1940 else

1941 bufptr = &pbuf;

1942

1944

1945

1946 if (!isNull && pbuf.cursor != pbuf.len)

1948 (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),

1949 errmsg("incorrect binary data format in bind parameter %d",

1950 paramno + 1)));

1951 }

1952 else

1953 {

1955 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

1956 errmsg("unsupported format code: %d",

1957 pformat)));

1958 pval = 0;

1959 }

1960

1961

1962 if (!isNull)

1963 pbuf.data[plength] = csave;

1964

1967

1968

1969

1970

1971

1974 }

1975

1976

1978

1979

1980

1981

1982

1983

1987 knownTextValues,

1989 }

1990 else

1991 params = NULL;

1992

1993

1995

1996

1997

1998

1999

2001 params_data.params = params;

2004 params_errcxt.arg = &params_data;

2006

2007

2008 numRFormats = pq_getmsgint(input_message, 2);

2009 if (numRFormats > 0)

2010 {

2012 for (int i = 0; i < numRFormats; i++)

2014 }

2015

2017

2018

2019

2020

2021

2022

2023 cplan = GetCachedPlan(psrc, params, NULL, NULL);

2024

2025

2026

2027

2028

2029

2030

2032 saved_stmt_name,

2033 query_string,

2036 cplan);

2037

2038

2039 foreach(lc, portal->stmts)

2040 {

2042

2044 {

2046 break;

2047 }

2048 }

2049

2050

2051 if (snapshot_set)

2053

2054

2055

2056

2058

2059

2060

2061

2063

2064

2065

2066

2067

2069

2070

2071

2072

2075

2076

2077

2078

2080 {

2081 case 1:

2083 (errmsg("duration: %s ms", msec_str),

2085 break;

2086 case 2:

2088 (errmsg("duration: %s ms bind %s%s%s: %s",

2089 msec_str,

2090 *stmt_name ? stmt_name : "",

2091 *portal_name ? "/" : "",

2092 *portal_name ? portal_name : "",

2096 break;

2097 }

2098

2099 if (save_log_statement_stats)

2100 ShowUsage("BIND MESSAGE STATISTICS");

2101

2103

2105}

void pgstat_report_query_id(int64 query_id, bool force)

void pgstat_report_activity(BackendState state, const char *cmd_str)

void pgstat_report_plan_id(int64 plan_id, bool force)

#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)

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

2741{

2743

2744

2745

2746

2747

2749

2750

2752

2756 (errcode(ERRCODE_UNDEFINED_CURSOR),

2757 errmsg("portal \"%s\" does not exist", portal_name)));

2758

2759

2760

2761

2762

2763

2764

2765

2766

2770 (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),

2771 errmsg("current transaction is aborted, "

2772 "commands ignored until end of transaction block"),

2774

2776 return;

2777

2783 else

2785}

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

2648{

2650

2651

2652

2653

2654

2656

2657

2659

2660

2661 if (stmt_name[0] != '\0')

2662 {

2664

2667 }

2668 else

2669 {

2670

2672 if (!psrc)

2674 (errcode(ERRCODE_UNDEFINED_PSTATEMENT),

2675 errmsg("unnamed prepared statement does not exist")));

2676 }

2677

2678

2680

2681

2682

2683

2684

2685

2686

2687

2688

2689

2693 (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),

2694 errmsg("current transaction is aborted, "

2695 "commands ignored until end of transaction block"),

2697

2699 return;

2700

2701

2702

2703

2706

2708 {

2710

2712 }

2714

2715

2716

2717

2719 {

2720 List *tlist;

2721

2722

2724

2727 tlist,

2728 NULL);

2729 }

2730 else

2732}

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

2114{

2118 bool completed;

2120 const char *sourceText;

2121 const char *prepStmtName;

2124 bool is_xact_command;

2125 bool execute_is_fetch;

2126 bool was_logged = false;

2127 char msec_str[32];

2130 const char *cmdtagname;

2131 size_t cmdtaglen;

2133

2134

2138

2142 (errcode(ERRCODE_UNDEFINED_CURSOR),

2143 errmsg("portal \"%s\" does not exist", portal_name)));

2144

2145

2146

2147

2148

2149 if (portal->commandTag == CMDTAG_UNKNOWN)

2150 {

2153 return;

2154 }

2155

2156

2158

2159

2160

2161

2162

2163

2164

2168 else

2169 prepStmtName = "";

2171

2172

2173

2174

2176

2178

2179 foreach(lc, portal->stmts)

2180 {

2182

2184 {

2186 break;

2187 }

2188 }

2189

2190 foreach(lc, portal->stmts)

2191 {

2193

2195 {

2197 break;

2198 }

2199 }

2200

2202

2204

2205 if (save_log_statement_stats)

2207

2209

2210

2211

2212

2213

2217

2218

2219

2220

2221

2223

2224

2225

2226

2227

2228

2229

2230 execute_is_fetch = !portal->atStart;

2231

2232

2234 {

2236 (errmsg("%s %s%s%s: %s",

2237 execute_is_fetch ?

2238 _("execute fetch from") :

2239 _("execute"),

2240 prepStmtName,

2241 *portal_name ? "/" : "",

2242 *portal_name ? portal_name : "",

2243 sourceText),

2246 was_logged = true;

2247 }

2248

2249

2250

2251

2252

2256 (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),

2257 errmsg("current transaction is aborted, "

2258 "commands ignored until end of transaction block"),

2260

2261

2263

2264

2265

2266

2267

2269 params_data.params = portalParams;

2272 params_errcxt.arg = &params_data;

2274

2275 if (max_rows <= 0)

2277

2279 max_rows,

2280 true,

2281 receiver,

2282 receiver,

2283 &qc);

2284

2285 receiver->rDestroy(receiver);

2286

2287

2289

2290 if (completed)

2291 {

2293 {

2294

2295

2296

2297

2298

2299

2300

2301

2303

2304

2305

2306

2307

2308

2309 portalParams = NULL;

2310 }

2311 else

2312 {

2313

2314

2315

2316

2318

2319

2320

2321

2322

2324

2325

2326

2327

2328

2330 }

2331

2332

2334 }

2335 else

2336 {

2337

2340

2341

2342

2343

2344

2346 }

2347

2348

2349

2350

2352 {

2353 case 1:

2355 (errmsg("duration: %s ms", msec_str),

2357 break;

2358 case 2:

2360 (errmsg("duration: %s ms %s %s%s%s: %s",

2361 msec_str,

2362 execute_is_fetch ?

2363 _("execute fetch from") :

2364 _("execute"),

2365 prepStmtName,

2366 *portal_name ? "/" : "",

2367 *portal_name ? portal_name : "",

2368 sourceText),

2371 break;

2372 }

2373

2374 if (save_log_statement_stats)

2375 ShowUsage("EXECUTE MESSAGE STATISTICS");

2376

2378

2380}

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

1399{

1402 List *parsetree_list;

1403 RawStmt *raw_parse_tree;

1404 List *querytree_list;

1406 bool is_named;

1408 char msec_str[32];

1409

1410

1411

1412

1414

1416

1418

1419 if (save_log_statement_stats)

1421

1424 *stmt_name ? stmt_name : "",

1425 query_string)));

1426

1427

1428

1429

1430

1431

1432

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448 is_named = (stmt_name[0] != '\0');

1449 if (is_named)

1450 {

1451

1453 }

1454 else

1455 {

1456

1458

1459 unnamed_stmt_context =

1461 "unnamed prepared statement",

1464 }

1465

1466

1467

1468

1469

1471

1472

1473

1474

1475

1476

1479 (errcode(ERRCODE_SYNTAX_ERROR),

1480 errmsg("cannot insert multiple commands into a prepared statement")));

1481

1482 if (parsetree_list != NIL)

1483 {

1484 bool snapshot_set = false;

1485

1487

1488

1489

1490

1491

1492

1493

1494

1495

1499 (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),

1500 errmsg("current transaction is aborted, "

1501 "commands ignored until end of transaction block"),

1503

1504

1505

1506

1507

1510

1511

1512

1513

1515 {

1517 snapshot_set = true;

1518 }

1519

1520

1521

1522

1523

1524

1526 query_string,

1527 &paramTypes,

1528 &numParams,

1529 NULL);

1530

1531

1532 if (snapshot_set)

1534 }

1535 else

1536 {

1537

1538 raw_parse_tree = NULL;

1540 CMDTAG_UNKNOWN);

1541 querytree_list = NIL;

1542 }

1543

1544

1545

1546

1547

1548

1549

1550 if (unnamed_stmt_context)

1552

1553

1555 querytree_list,

1556 unnamed_stmt_context,

1557 paramTypes,

1558 numParams,

1559 NULL,

1560 NULL,

1562 true);

1563

1564

1566

1567 if (is_named)

1568 {

1569

1570

1571

1573 }

1574 else

1575 {

1576

1577

1578

1581 }

1582

1584

1585

1586

1587

1588

1589

1591

1592

1593

1594

1597

1598

1599

1600

1602 {

1603 case 1:

1605 (errmsg("duration: %s ms", msec_str),

1607 break;

1608 case 2:

1610 (errmsg("duration: %s ms parse %s: %s",

1611 msec_str,

1612 *stmt_name ? stmt_name : "",

1613 query_string),

1615 break;

1616 }

1617

1618 if (save_log_statement_stats)

1619 ShowUsage("PARSE MESSAGE STATISTICS");

1620

1622}

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

1018{

1021 List *parsetree_list;

1024 bool was_logged = false;

1025 bool use_implicit_block;

1026 char msec_str[32];

1027

1028

1029

1030

1032

1034

1035 TRACE_POSTGRESQL_QUERY_START(query_string);

1036

1037

1038

1039

1040

1041 if (save_log_statement_stats)

1043

1044

1045

1046

1047

1048

1049

1050

1052

1053

1054

1055

1056

1057

1058

1060

1061

1062

1063

1065

1066

1067

1068

1069

1071

1072

1074 {

1076 (errmsg("statement: %s", query_string),

1079 was_logged = true;

1080 }

1081

1082

1083

1084

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095 use_implicit_block = (list_length(parsetree_list) > 1);

1096

1097

1098

1099

1100 foreach(parsetree_item, parsetree_list)

1101 {

1103 bool snapshot_set = false;

1107 List *querytree_list,

1108 *plantree_list;

1112 const char *cmdtagname;

1113 size_t cmdtaglen;

1114

1117

1118

1119

1120

1121

1122

1123

1126

1128

1130

1131

1132

1133

1134

1135

1136

1137

1138

1142 (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),

1143 errmsg("current transaction is aborted, "

1144 "commands ignored until end of transaction block"),

1146

1147

1149

1150

1151

1152

1153

1154

1155

1156

1157 if (use_implicit_block)

1159

1160

1162

1163

1164

1165

1167 {

1169 snapshot_set = true;

1170 }

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184 if (lnext(parsetree_list, parsetree_item) != NULL)

1185 {

1186 per_parsetree_context =

1188 "per-parsetree message context",

1191 }

1192 else

1194

1196 NULL, 0, NULL);

1197

1198 plantree_list = pg_plan_queries(querytree_list, query_string,

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211 if (snapshot_set)

1213

1214

1216

1217

1218

1219

1220

1222

1223 portal->visible = false;

1224

1225

1226

1227

1228

1229

1231 NULL,

1232 query_string,

1233 commandTag,

1234 plantree_list,

1235 NULL);

1236

1237

1238

1239

1241

1242

1243

1244

1245

1246

1247

1248 format = 0;

1250 {

1252

1254 {

1256

1259 format = 1;

1260 }

1261 }

1263

1264

1265

1266

1270

1271

1272

1273

1275

1276

1277

1278

1281 true,

1282 receiver,

1283 receiver,

1284 &qc);

1285

1286 receiver->rDestroy(receiver);

1287

1289

1290 if (lnext(parsetree_list, parsetree_item) == NULL)

1291 {

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301 if (use_implicit_block)

1304 }

1306 {

1307

1308

1309

1310

1312 }

1313 else

1314 {

1315

1316

1317

1318

1319

1321

1322

1323

1324

1325

1327

1328

1329

1330

1331

1332

1334 }

1335

1336

1337

1338

1339

1340

1341

1343

1344

1345 if (per_parsetree_context)

1347 }

1348

1349

1350

1351

1352

1353

1355

1356

1357

1358

1359 if (!parsetree_list)

1361

1362

1363

1364

1366 {

1367 case 1:

1369 (errmsg("duration: %s ms", msec_str),

1371 break;

1372 case 2:

1374 (errmsg("duration: %s ms statement: %s",

1375 msec_str, query_string),

1378 break;

1379 }

1380

1381 if (save_log_statement_stats)

1383

1384 TRACE_POSTGRESQL_QUERY_DONE(query_string);

1385

1387}

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

3080{

3081

3083 (errcode(ERRCODE_FLOATING_POINT_EXCEPTION),

3084 errmsg("floating-point exception"),

3085 errdetail("An invalid floating-point operation was signaled. "

3086 "This probably means an out-of-range result or an "

3087 "invalid operation, such as division by zero.")));

3088}

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

3760{

3761 switch (arg[0])

3762 {

3763 case 'p':

3764 if (optarg[1] == 'a')

3765 return "log_parser_stats";

3766 else if (optarg[1] == 'l')

3767 return "log_planner_stats";

3768 break;

3769

3770 case 'e':

3771 return "log_executor_stats";

3772 break;

3773 }

3774

3775 return NULL;

3776}

PGDLLIMPORT char * optarg

References arg, and 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 237 of file postgres.c.

238{

239 int c;

240

241

242

243

246

248

249

250

251

253 {

254 if (c == '\n')

255 {

257 {

258

259

260

261

262 if (inBuf->len > 1 &&

263 inBuf->data[inBuf->len - 1] == '\n' &&

264 inBuf->data[inBuf->len - 2] == ';')

265 {

266

267 break;

268 }

269 }

270 else

271 {

272

273

274

275

276 if (inBuf->len > 0 &&

277 inBuf->data[inBuf->len - 1] == '\\')

278 {

279

280 inBuf->data[--inBuf->len] = '\0';

281

282 continue;

283 }

284 else

285 {

286

288 break;

289 }

290 }

291 }

292

293

295 }

296

297

298 if (c == EOF && inBuf->len == 0)

299 return EOF;

300

301

302

303

304

305

307

308

309

310

312 printf("statement: %s\n", inBuf->data);

314

316}

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

5178{

5180 long secs;

5181 int usecs;

5182 int msecs;

5183 int hours,

5184 minutes,

5185 seconds;

5186

5189 &secs, &usecs);

5190 msecs = usecs / 1000;

5191

5196

5198 (errmsg("disconnection: session time: %d:%02d:%02d.%03d "

5199 "user=%s database=%s host=%s%s%s",

5200 hours, minutes, seconds, msecs,

5201 port->user_name, port->database_name, port->remote_host,

5202 port->remote_port[0] ? " port=" : "", port->remote_port)));

5203}

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

675{

677 List *querytree_list;

678

679 TRACE_POSTGRESQL_QUERY_REWRITE_START(query_string);

680

681

682

683

686

688 queryEnv);

689

691 ShowUsage("PARSE ANALYSIS STATISTICS");

692

693

694

695

697

698 TRACE_POSTGRESQL_QUERY_REWRITE_DONE(query_string);

699

700 return querytree_list;

701}

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

714{

716 List *querytree_list;

717

718 TRACE_POSTGRESQL_QUERY_REWRITE_START(query_string);

719

720

721

722

725

727 queryEnv);

728

729

730

731

732 for (int i = 0; i < *numParams; i++)

733 {

734 Oid ptype = (*paramTypes)[i];

735

736 if (ptype == InvalidOid || ptype == UNKNOWNOID)

738 (errcode(ERRCODE_INDETERMINATE_DATATYPE),

739 errmsg("could not determine data type of parameter $%d",

740 i + 1)));

741 }

742

744 ShowUsage("PARSE ANALYSIS STATISTICS");

745

746

747

748

750

751 TRACE_POSTGRESQL_QUERY_REWRITE_DONE(query_string);

752

753 return querytree_list;

754}

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

768{

770 List *querytree_list;

771

772 TRACE_POSTGRESQL_QUERY_REWRITE_START(query_string);

773

774

775

776

779

780 query = parse_analyze_withcb(parsetree, query_string, parserSetup, parserSetupArg,

781 queryEnv);

782

784 ShowUsage("PARSE ANALYSIS STATISTICS");

785

786

787

788

790

791 TRACE_POSTGRESQL_QUERY_REWRITE_DONE(query_string);

792

793 return querytree_list;

794}

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_sql_function_in_from(), prepare_next_query(), RevalidateCachedQuery(), and test_inline_in_from_support_func().

pg_parse_query()

List * pg_parse_query ( const char * query_string )

Definition at line 604 of file postgres.c.

605{

606 List *raw_parsetree_list;

607

608 TRACE_POSTGRESQL_QUERY_PARSE_START(query_string);

609

612

614

617

618#ifdef DEBUG_NODE_TESTS_ENABLED

619

620

621 if (Debug_copy_parse_plan_trees)

622 {

624

625

627 elog(WARNING, "copyObject() failed to produce an equal raw parse tree");

628 else

629 raw_parsetree_list = new_list;

630 }

631

632

633

634

635

636 if (Debug_write_read_parse_plan_trees)

637 {

640

642

644 elog(WARNING, "outfuncs/readfuncs failed to produce an equal raw parse tree");

645 else

646 raw_parsetree_list = new_list;

647 }

648

649#endif

650

651 TRACE_POSTGRESQL_QUERY_PARSE_DONE(query_string);

652

656

657 return raw_parsetree_list;

658}

void elog_node_display(int lev, const char *title, const void *obj, bool pretty)

List * raw_parser(const char *str, RawParseMode mode)

bool equal(const void *a, const void *b)

bool Debug_print_raw_parse

static List * new_list(NodeTag type, int min_size)

char * nodeToStringWithLocations(const void *obj)

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_sql_function_in_from(), sql_compile_callback(), and test_inline_in_from_support_func().

pg_plan_queries()

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

Definition at line 975 of file postgres.c.

977{

980

981 foreach(query_list, querytrees)

982 {

985

987 {

988

991 stmt->canSetTag = query->canSetTag;

994 stmt->stmt_len = query->stmt_len;

995 stmt->queryId = query->queryId;

997 }

998 else

999 {

1001 boundParams, NULL);

1002 }

1003

1005 }

1006

1007 return stmt_list;

1008}

List * lappend(List *list, void *datum)

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

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()

Definition at line 887 of file postgres.c.

889{

891

892

894 return NULL;

895

896

898

899 TRACE_POSTGRESQL_QUERY_PLAN_START();

900

903

904

906

909

910#ifdef DEBUG_NODE_TESTS_ENABLED

911

912

913 if (Debug_copy_parse_plan_trees)

914 {

916

917

918

919

920

921#ifdef NOT_USED

922

924 elog(WARNING, "copyObject() failed to produce an equal plan tree");

925 else

926#endif

927 plan = new_plan;

928 }

929

930

931 if (Debug_write_read_parse_plan_trees)

932 {

933 char *str;

935

937 new_plan = stringToNodeWithLocations(str);

939

940

941

942

943

944#ifdef NOT_USED

945

947 elog(WARNING, "outfuncs/readfuncs failed to produce an equal plan tree");

948 else

949#endif

950 plan = new_plan;

951 }

952

953#endif

954

955

956

957

960

961 TRACE_POSTGRESQL_QUERY_PLAN_DONE();

962

964}

Datum querytree(PG_FUNCTION_ARGS)

PlannedStmt * planner(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams, ExplainState *es)

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

804{

805 List *querytree_list;

806

810

813

815 {

816

818 }

819 else

820 {

821

823 }

824

826 ShowUsage("REWRITER STATISTICS");

827

828#ifdef DEBUG_NODE_TESTS_ENABLED

829

830

831 if (Debug_copy_parse_plan_trees)

832 {

834

836

838 elog(WARNING, "copyObject() failed to produce an equal rewritten parse tree");

839 else

841 }

842

843

844 if (Debug_write_read_parse_plan_trees)

845 {

848

849 foreach(lc, querytree_list)

850 {

853 Query *new_query = stringToNodeWithLocations(str);

854

855

856

857

858

859 new_query->queryId = curr_query->queryId;

860

863 }

864

865

867 elog(WARNING, "outfuncs/readfuncs failed to produce an equal rewritten parse tree");

868 else

870 }

871

872#endif

873

877

878 return querytree_list;

879}

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

4194{

4195 sigjmp_buf local_sigjmp_buf;

4196

4197

4198 volatile bool send_ready_for_query = true;

4199 volatile bool idle_in_transaction_timeout_enabled = false;

4200 volatile bool idle_session_timeout_enabled = false;

4201

4204

4206

4207

4208

4209

4210

4211

4212

4213

4214

4215

4216

4217

4218

4219

4220

4221

4224 else

4225 {

4228 pqsignal(SIGTERM, die);

4229

4230

4231

4232

4233

4234

4235

4236

4237

4240 else

4243

4244

4245

4246

4247

4248

4249

4254

4255

4256

4257

4258

4259 pqsignal(SIGCHLD, SIG_DFL);

4260

4261 }

4262

4263

4265

4266

4267 sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);

4268

4269

4270

4271

4272

4275 {

4276 int len;

4277

4281 {

4283 (errcode(ERRCODE_INTERNAL_ERROR),

4284 errmsg("could not generate random cancel key")));

4285 }

4287 }

4288

4289

4290

4291

4292

4293

4294

4295

4296

4297

4301 NULL);

4302

4303

4304

4305

4306

4308 {

4311 }

4312

4314

4315

4316

4317

4318

4320

4321

4322

4323

4324

4327

4329

4330

4333

4334

4335

4336

4338 {

4340

4344

4347

4348 }

4349

4350

4352 printf("\nPostgreSQL stand-alone backend %s\n", PG_VERSION);

4353

4354

4355

4356

4357

4358

4359

4361 "MessageContext",

4363

4364

4365

4366

4367

4368

4369

4371 "RowDescriptionContext",

4376

4377

4379

4380

4381

4382

4383

4384

4385

4386

4387

4388

4389

4390

4391

4392

4393

4394

4395

4396

4397

4398

4399

4400

4401

4402 if (sigsetjmp(local_sigjmp_buf, 1) != 0)

4403 {

4404

4405

4406

4407

4408

4409

4410

4411

4412

4414

4415

4417

4418

4419

4420

4421

4422

4423

4424

4425

4426

4427

4428

4431 idle_in_transaction_timeout_enabled = false;

4432 idle_session_timeout_enabled = false;

4433

4434

4436

4437

4439

4440

4442

4443

4444

4445

4446

4448

4449

4450

4451

4452

4454

4455

4456

4457

4459

4462

4464

4465

4466

4467

4468

4469

4470

4471

4474

4475

4477

4479

4480

4481

4482

4483

4486

4487

4488

4489

4490

4491

4494

4495

4497

4498

4499

4500

4501

4502

4503

4504

4505

4508 (errcode(ERRCODE_PROTOCOL_VIOLATION),

4509 errmsg("terminating connection because protocol synchronization was lost")));

4510

4511

4513 }

4514

4515

4517

4519 send_ready_for_query = true;

4520

4521

4522

4523

4524

4525 for (;;)

4526 {

4527 int firstchar;

4529

4530

4531

4532

4533

4535

4536

4537

4538

4539#ifdef USE_VALGRIND

4540 old_valgrind_error_count = VALGRIND_COUNT_ERRORS;

4541#endif

4542

4543

4544

4545

4546

4549

4551

4552

4553

4554

4555

4557

4558

4559

4560

4561

4562

4563

4564

4565

4566

4567

4568

4569

4570

4571

4572

4573

4574 if (send_ready_for_query)

4575 {

4577 {

4580

4581

4584 {

4585 idle_in_transaction_timeout_enabled = true;

4588 }

4589 }

4591 {

4594

4595

4598 {

4599 idle_in_transaction_timeout_enabled = true;

4602 }

4603 }

4604 else

4605 {

4606 long stats_timeout;

4607

4608

4609

4610

4611

4612

4613

4614

4617

4618

4619

4620

4621

4622

4623

4624

4625

4626

4627

4628

4629

4630

4632 if (stats_timeout > 0)

4633 {

4636 stats_timeout);

4637 }

4638 else

4639 {

4640

4643 }

4644

4647

4648

4650 {

4651 idle_session_timeout_enabled = true;

4654 }

4655 }

4656

4657

4659

4660

4661

4662

4663

4664

4668 {

4669 uint64 total_duration,

4670 fork_duration,

4671 auth_duration;

4672

4674

4675 total_duration =

4678 fork_duration =

4681 auth_duration =

4684

4686 errmsg("connection ready: setup total=%.3f ms, fork=%.3f ms, authentication=%.3f ms",

4687 (double) total_duration / NS_PER_US,

4688 (double) fork_duration / NS_PER_US,

4689 (double) auth_duration / NS_PER_US));

4690 }

4691

4693 send_ready_for_query = false;

4694 }

4695

4696

4697

4698

4699

4700

4701

4703

4704

4705

4706

4707 firstchar = ReadCommand(&input_message);

4708

4709

4710

4711

4712

4713

4714

4715

4716

4717 if (idle_in_transaction_timeout_enabled)

4718 {

4720 idle_in_transaction_timeout_enabled = false;

4721 }

4722 if (idle_session_timeout_enabled)

4723 {

4725 idle_session_timeout_enabled = false;

4726 }

4727

4728

4729

4730

4731

4732

4733

4734

4735

4736

4739

4740

4741

4742

4743

4745 {

4748 }

4749

4750

4751

4752

4753

4755 continue;

4756

4757 switch (firstchar)

4758 {

4760 {

4761 const char *query_string;

4762

4763

4765

4768

4770 {

4773 }

4774 else

4776

4778

4779 send_ready_for_query = true;

4780 }

4781 break;

4782

4784 {

4785 const char *stmt_name;

4786 const char *query_string;

4787 int numParams;

4788 Oid *paramTypes = NULL;

4789

4791

4792

4794

4797 numParams = pq_getmsgint(&input_message, 2);

4798 if (numParams > 0)

4799 {

4801 for (int i = 0; i < numParams; i++)

4802 paramTypes[i] = pq_getmsgint(&input_message, 4);

4803 }

4805

4807 paramTypes, numParams);

4808

4810 }

4811 break;

4812

4815

4816

4818

4819

4820

4821

4822

4824

4825

4826 break;

4827

4829 {

4830 const char *portal_name;

4831 int max_rows;

4832

4834

4835

4837

4841

4843

4844

4845 }

4846 break;

4847

4850

4851

4853

4854

4857

4858

4860

4861

4862

4863

4864

4865

4866

4867

4868

4869

4870

4872

4874

4875

4877

4879

4880 send_ready_for_query = true;

4881 break;

4882

4884 {

4885 int close_type;

4886 const char *close_target;

4887

4889

4893

4894 switch (close_type)

4895 {

4896 case 'S':

4897 if (close_target[0] != '\0')

4899 else

4900 {

4901

4903 }

4904 break;

4905 case 'P':

4906 {

4908

4912 }

4913 break;

4914 default:

4916 (errcode(ERRCODE_PROTOCOL_VIOLATION),

4917 errmsg("invalid CLOSE message subtype %d",

4918 close_type)));

4919 break;

4920 }

4921

4924

4926 }

4927 break;

4928

4930 {

4931 int describe_type;

4932 const char *describe_target;

4933

4935

4936

4938

4942

4943 switch (describe_type)

4944 {

4945 case 'S':

4947 break;

4948 case 'P':

4950 break;

4951 default:

4953 (errcode(ERRCODE_PROTOCOL_VIOLATION),

4954 errmsg("invalid DESCRIBE message subtype %d",

4955 describe_type)));

4956 break;

4957 }

4958

4960 }

4961 break;

4962

4967 break;

4968

4971

4972

4973

4974

4975

4976

4980 send_ready_for_query = true;

4981 break;

4982

4983

4984

4985

4986

4987

4988 case EOF:

4989

4990

4992

4993

4994

4996

4997

4998

4999

5000

5003

5004

5005

5006

5007

5008

5009

5010

5012

5016

5017

5018

5019

5020

5021

5022 break;

5023

5024 default:

5026 (errcode(ERRCODE_PROTOCOL_VIOLATION),

5027 errmsg("invalid frontend message type %d",

5028 firstchar)));

5029 }

5030 }

5031}

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

4066{

4067 const char *dbname = NULL;

4068

4070

4071

4073

4074

4075

4076

4078

4079

4080

4081

4083

4084

4086 {

4090 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

4091 errmsg("%s: no database nor user name specified",

4093 }

4094

4095

4098

4099

4100

4101

4102

4105

4106

4107

4108

4110

4111

4113

4114

4115

4116

4118

4119

4121

4122

4123

4124

4125

4127

4128

4130

4131

4132

4133

4135

4136

4137

4138

4139

4140

4142

4143

4144

4145

4146

4148

4149

4150

4151

4152

4154

4155

4156

4157

4158

4160

4161

4162

4163

4164

4166

4167

4168

4169

4170

4172

4173

4174

4175

4176

4178}

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

3801{

3803 int errs = 0;

3806

3807 if (secure)

3808 {

3809 gucsource = PGC_S_ARGV;

3810

3811

3812 if (argc > 1 && strcmp(argv[1], "--single") == 0)

3813 {

3814 argv++;

3815 argc--;

3816 }

3817 }

3818 else

3819 {

3820 gucsource = PGC_S_CLIENT;

3821 }

3822

3823#ifdef HAVE_INT_OPTERR

3824

3825

3826

3827

3828

3829

3831#endif

3832

3833

3834

3835

3836

3837

3838 while ((flag = getopt(argc, argv, "B:bC:c:D:d:EeFf:h:ijk:lN:nOPp:r:S:sTt:v:W:-:")) != -1)

3839 {

3840 switch (flag)

3841 {

3842 case 'B':

3844 break;

3845

3846 case 'b':

3847

3848 if (secure)

3850 break;

3851

3852 case 'C':

3853

3854 break;

3855

3856 case '-':

3857

3858

3859

3860

3861

3862

3863

3866 (errcode(ERRCODE_SYNTAX_ERROR),

3867 errmsg("--%s must be first argument", optarg)));

3868

3869

3870 case 'c':

3871 {

3874

3877 {

3878 if (flag == '-')

3880 (errcode(ERRCODE_SYNTAX_ERROR),

3881 errmsg("--%s requires a value",

3883 else

3885 (errcode(ERRCODE_SYNTAX_ERROR),

3886 errmsg("-c %s requires a value",

3888 }

3892 break;

3893 }

3894

3895 case 'D':

3896 if (secure)

3898 break;

3899

3900 case 'd':

3902 break;

3903

3904 case 'E':

3905 if (secure)

3907 break;

3908

3909 case 'e':

3911 break;

3912

3913 case 'F':

3915 break;

3916

3917 case 'f':

3919 errs++;

3920 break;

3921

3922 case 'h':

3924 break;

3925

3926 case 'i':

3927 SetConfigOption("listen_addresses", "*", ctx, gucsource);

3928 break;

3929

3930 case 'j':

3931 if (secure)

3933 break;

3934

3935 case 'k':

3937 break;

3938

3939 case 'l':

3941 break;

3942

3943 case 'N':

3945 break;

3946

3947 case 'n':

3948

3949 break;

3950

3951 case 'O':

3952 SetConfigOption("allow_system_table_mods", "true", ctx, gucsource);

3953 break;

3954

3955 case 'P':

3956 SetConfigOption("ignore_system_indexes", "true", ctx, gucsource);

3957 break;

3958

3959 case 'p':

3961 break;

3962

3963 case 'r':

3964

3965 if (secure)

3967 break;

3968

3969 case 'S':

3971 break;

3972

3973 case 's':

3974 SetConfigOption("log_statement_stats", "true", ctx, gucsource);

3975 break;

3976

3977 case 'T':

3978

3979 break;

3980

3981 case 't':

3982 {

3984

3985 if (tmp)

3987 else

3988 errs++;

3989 break;

3990 }

3991

3992 case 'v':

3993

3994

3995

3996

3997

3998

3999

4000

4001 if (secure)

4003 break;

4004

4005 case 'W':

4007 break;

4008

4009 default:

4010 errs++;

4011 break;

4012 }

4013

4014 if (errs)

4015 break;

4016 }

4017

4018

4019

4020

4023

4024 if (errs || argc != optind)

4025 {

4026 if (errs)

4027 optind--;

4028

4029

4032 errcode(ERRCODE_SYNTAX_ERROR),

4033 errmsg("invalid command-line argument for server process: %s", argv[optind]),

4034 errhint("Try \"%s --help\" for more information.", progname));

4035 else

4037 errcode(ERRCODE_SYNTAX_ERROR),

4038 errmsg("%s: invalid command-line argument: %s",

4040 errhint("Try \"%s --help\" for more information.", progname));

4041 }

4042

4043

4044

4045

4046

4048#ifdef HAVE_INT_OPTRESET

4049 optreset = 1;

4050#endif

4051}

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

3305{

3306

3308 return;

3310

3312 {

3316

3321 (errcode(ERRCODE_QUERY_CANCELED),

3322 errmsg("canceling authentication due to timeout")));

3325 (errcode(ERRCODE_ADMIN_SHUTDOWN),

3326 errmsg("terminating autovacuum process due to administrator command")));

3329 (errcode(ERRCODE_ADMIN_SHUTDOWN),

3330 errmsg("terminating logical replication worker due to administrator command")));

3332 {

3334 (errmsg_internal("logical replication launcher shutting down")));

3335

3336

3337

3338

3339

3341 }

3344 (errcode(ERRCODE_ADMIN_SHUTDOWN),

3345 errmsg("terminating walreceiver process due to administrator command")));

3348 (errcode(ERRCODE_ADMIN_SHUTDOWN),

3349 errmsg("terminating background worker \"%s\" due to administrator command",

3352 {

3354 (errmsg_internal("io worker shutting down due to administrator command")));

3355

3357 }

3358 else

3360 (errcode(ERRCODE_ADMIN_SHUTDOWN),

3361 errmsg("terminating connection due to administrator command")));

3362 }

3363

3365 {

3367

3368

3369

3370

3371

3372

3373

3375 {

3378 else

3381 }

3382 }

3383

3385 {

3386 QueryCancelPending = false;

3388

3391 (errcode(ERRCODE_CONNECTION_FAILURE),

3392 errmsg("connection to client lost")));

3393 }

3394

3395

3396

3397

3398

3399

3400

3401

3402

3404 {

3405

3406

3407

3408

3409

3410

3411

3412

3414 }

3416 {

3417 bool lock_timeout_occurred;

3418 bool stmt_timeout_occurred;

3419

3421

3422

3423

3424

3425

3428

3429

3430

3431

3432

3433

3434

3435 if (lock_timeout_occurred && stmt_timeout_occurred &&

3437 lock_timeout_occurred = false;

3438

3439 if (lock_timeout_occurred)

3440 {

3443 (errcode(ERRCODE_LOCK_NOT_AVAILABLE),

3444 errmsg("canceling statement due to lock timeout")));

3445 }

3446 if (stmt_timeout_occurred)

3447 {

3450 (errcode(ERRCODE_QUERY_CANCELED),

3451 errmsg("canceling statement due to statement timeout")));

3452 }

3454 {

3457 (errcode(ERRCODE_QUERY_CANCELED),

3458 errmsg("canceling autovacuum task")));

3459 }

3460

3461

3462

3463

3464

3465

3467 {

3470 (errcode(ERRCODE_QUERY_CANCELED),

3471 errmsg("canceling statement due to user request")));

3472 }

3473 }

3474

3477

3479 {

3480

3481

3482

3483

3484

3485

3488 {

3489 INJECTION_POINT("idle-in-transaction-session-timeout", NULL);

3491 (errcode(ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT),

3492 errmsg("terminating connection due to idle-in-transaction timeout")));

3493 }

3494 }

3495

3497 {

3498

3501 {

3504 (errcode(ERRCODE_TRANSACTION_TIMEOUT),

3505 errmsg("terminating connection due to transaction timeout")));

3506 }

3507 }

3508

3510 {

3511

3514 {

3517 (errcode(ERRCODE_IDLE_SESSION_TIMEOUT),

3518 errmsg("terminating connection due to idle-session timeout")));

3519 }

3520 }

3521

3522

3523

3524

3525

3528 {

3531 }

3532

3535

3538

3541

3544}

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 CheckClientConnectionPending

#define INJECTION_POINT(name, arg)

bool IsLogicalLauncher(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, ProcessLogMemoryContextInterrupt(), ProcessParallelApplyMessages(), ProcessParallelMessages(), ProcessProcSignalBarrier(), ProcessRecoveryConflictInterrupts(), ProcSignalBarrierPending, QueryCancelHoldoffCount, QueryCancelPending, RecoveryConflictPending, STATEMENT_TIMEOUT, TransactionTimeout, TransactionTimeoutPending, and whereToSendOutput.

Referenced by die().

ProcessRecoveryConflictInterrupt()

Definition at line 3107 of file postgres.c.

3108{

3109 switch (reason)

3110 {

3112

3113

3114

3115

3117 return;

3118

3119

3120

3121

3123

3124

3125

3126

3127

3128

3129

3130

3131

3132

3133

3135 {

3139 return;

3140 }

3141

3143

3144

3145

3146

3150

3151

3152

3153

3155 return;

3156

3157

3158

3160

3161

3162

3163

3164

3165

3166

3167

3168

3169

3170

3171

3172

3173

3174

3175

3176

3177

3178

3179

3180

3181

3182

3183

3184

3185

3188 {

3189

3190

3191

3192

3193

3195 return;

3196

3197

3198

3199

3200

3201

3202

3203

3205 {

3206

3208 {

3209

3210

3211

3212

3216 return;

3217 }

3218

3219

3220

3221

3222

3223

3224

3229 errmsg("canceling statement due to conflict with recovery"),

3231 break;

3232 }

3233 }

3234

3235

3236

3237

3239

3240

3241

3242

3243

3244

3248 ERRCODE_DATABASE_DROPPED :

3250 errmsg("terminating connection due to conflict with recovery"),

3252 errhint("In a moment you should be able to reconnect to the"

3253 " database and repeat your command.")));

3254 break;

3255

3256 default:

3257 elog(FATAL, "unrecognized conflict mode: %d", (int) reason);

3258 }

3259}

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

2936{

2937 sigaddset(&BlockSig, SIGQUIT);

2938 sigprocmask(SIG_SETMASK, &BlockSig, NULL);

2939

2940

2941

2942

2943

2944

2946

2947

2948

2949

2950

2951

2952

2955

2956

2957

2958

2959

2960

2961

2962

2963

2964

2965

2966

2967

2968

2969

2970

2971

2973

2974

2975

2976

2977

2978

2979

2980

2981

2983 {

2985

2987 (errcode(ERRCODE_ADMIN_SHUTDOWN),

2988 errmsg("terminating connection because of unexpected SIGQUIT signal")));

2989 break;

2991

2993 (errcode(ERRCODE_CRASH_SHUTDOWN),

2994 errmsg("terminating connection because of crash of another server process"),

2995 errdetail("The postmaster has commanded this server process to roll back"

2996 " the current transaction and exit, because another"

2997 " server process exited abnormally and possibly corrupted"

2998 " shared memory."),

2999 errhint("In a moment you should be able to reconnect to the"

3000 " database and repeat your command.")));

3001 break;

3003

3005 (errcode(ERRCODE_ADMIN_SHUTDOWN),

3006 errmsg("terminating connection due to immediate shutdown command")));

3007 break;

3008 }

3009

3010

3011

3012

3013

3014

3015

3016

3017

3018

3019

3020

3021

3022

3023

3024 _exit(2);

3025}

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

5062{

5065}

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

3718{

3719 const char *tmp = NULL;

3720

3721 switch (arg[0])

3722 {

3723 case 's':

3724 tmp = "enable_seqscan";

3725 break;

3726 case 'i':

3727 tmp = "enable_indexscan";

3728 break;

3729 case 'o':

3730 tmp = "enable_indexonlyscan";

3731 break;

3732 case 'b':

3733 tmp = "enable_bitmapscan";

3734 break;

3735 case 't':

3736 tmp = "enable_tidscan";

3737 break;

3738 case 'n':

3739 tmp = "enable_nestloop";

3740 break;

3741 case 'm':

3742 tmp = "enable_mergejoin";

3743 break;

3744 case 'h':

3745 tmp = "enable_hashjoin";

3746 break;

3747 }

3748 if (tmp)

3749 {

3751 return true;

3752 }

3753 else

3754 return false;

3755}

References arg, SetConfigOption(), and source.

Referenced by PostmasterMain(), and process_postgres_switches().

ShowUsage()

void ShowUsage ( const char * title )

Definition at line 5068 of file postgres.c.

5069{

5071 struct timeval user,

5072 sys;

5073 struct timeval elapse_t;

5075

5078 memcpy(&user, &r.ru_utime, sizeof(user));

5079 memcpy(&sys, &r.ru_stime, sizeof(sys));

5080 if (elapse_t.tv_usec < Save_t.tv_usec)

5081 {

5082 elapse_t.tv_sec--;

5083 elapse_t.tv_usec += 1000000;

5084 }

5086 {

5087 r.ru_utime.tv_sec--;

5088 r.ru_utime.tv_usec += 1000000;

5089 }

5091 {

5092 r.ru_stime.tv_sec--;

5093 r.ru_stime.tv_usec += 1000000;

5094 }

5095

5096

5097

5098

5099

5101

5104 "!\t%ld.%06ld s user, %ld.%06ld s system, %ld.%06ld s elapsed\n",

5105 (long) (r.ru_utime.tv_sec - Save_r.ru_utime.tv_sec),

5106 (long) (r.ru_utime.tv_usec - Save_r.ru_utime.tv_usec),

5107 (long) (r.ru_stime.tv_sec - Save_r.ru_stime.tv_sec),

5108 (long) (r.ru_stime.tv_usec - Save_r.ru_stime.tv_usec),

5109 (long) (elapse_t.tv_sec - Save_t.tv_sec),

5110 (long) (elapse_t.tv_usec - Save_t.tv_usec));

5112 "!\t[%ld.%06ld s user, %ld.%06ld s system total]\n",

5113 (long) user.tv_sec,

5114 (long) user.tv_usec,

5115 (long) sys.tv_sec,

5116 (long) sys.tv_usec);

5117#ifndef WIN32

5118

5119

5120

5121

5122

5123

5124

5126 "!\t%ld kB max resident size\n",

5128

5129 r.ru_maxrss / 1024

5130#else

5131

5132 r.ru_maxrss

5133#endif

5134 );

5136 "!\t%ld/%ld [%ld/%ld] filesystem blocks in/out\n",

5137 r.ru_inblock - Save_r.ru_inblock,

5138

5139 r.ru_oublock - Save_r.ru_oublock,

5140 r.ru_inblock, r.ru_oublock);

5142 "!\t%ld/%ld [%ld/%ld] page faults/reclaims, %ld [%ld] swaps\n",

5143 r.ru_majflt - Save_r.ru_majflt,

5144 r.ru_minflt - Save_r.ru_minflt,

5145 r.ru_majflt, r.ru_minflt,

5146 r.ru_nswap - Save_r.ru_nswap,

5147 r.ru_nswap);

5149 "!\t%ld [%ld] signals rcvd, %ld/%ld [%ld/%ld] messages rcvd/sent\n",

5150 r.ru_nsignals - Save_r.ru_nsignals,

5151 r.ru_nsignals,

5152 r.ru_msgrcv - Save_r.ru_msgrcv,

5153 r.ru_msgsnd - Save_r.ru_msgsnd,

5154 r.ru_msgrcv, r.ru_msgsnd);

5156 "!\t%ld/%ld [%ld/%ld] voluntary/involuntary context switches\n",

5157 r.ru_nvcsw - Save_r.ru_nvcsw,

5158 r.ru_nivcsw - Save_r.ru_nivcsw,

5159 r.ru_nvcsw, r.ru_nivcsw);

5160#endif

5161

5162

5163 if (str.data[str.len - 1] == '\n')

5164 str.data[--str.len] = '\0';

5165

5169

5171}

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

354{

355 int qtype;

356 int maxmsglen;

357

358

359

360

364

365 if (qtype == EOF)

366 {

369 (errcode(ERRCODE_CONNECTION_FAILURE),

370 errmsg("unexpected EOF on client connection with an open transaction")));

371 else

372 {

373

374

375

376

377

380 (errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),

381 errmsg_internal("unexpected EOF on client connection")));

382 }

383 return qtype;

384 }

385

386

387

388

389

390

391

392

393

394

395

396 switch (qtype)

397 {

401 break;

402

406 break;

407

412 break;

413

418 break;

419

426 break;

427

430

432

434 break;

435

439 break;

440

445 break;

446

447 default:

448

449

450

451

452

453

455 (errcode(ERRCODE_PROTOCOL_VIOLATION),

456 errmsg("invalid frontend message type %d", qtype)));

457 maxmsglen = 0;

458 break;

459 }

460

461

462

463

464

465

467 return EOF;

469

470 return qtype;

471}

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

2793{

2795 {

2797

2799 }

2801 {

2802

2803

2804

2805

2806

2807

2808

2810 }

2811

2812

2813

2814

2815

2816

2817

2818

2820

2821

2828}

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 89 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 92 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