Commit 9660834d authored by Bruce Momjian's avatar Bruce Momjian

adjust query id feature to use pg_stat_activity.query_id

Previously, it was pg_stat_activity.queryid to match the
pg_stat_statements queryid column.  This is an adjustment to patch
4f0b0966.  This also adjusts some of the internal function calls to
match.  Catversion bumped.

Reported-by: Álvaro Herrera, Julien Rouhaud

Discussion: https://postgr.es/m/20210408032704.GA7498@alvherre.pgsql
parent 76453767
...@@ -919,7 +919,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser ...@@ -919,7 +919,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
<row> <row>
<entry role="catalog_table_entry"><para role="column_definition"> <entry role="catalog_table_entry"><para role="column_definition">
<structfield>queryid</structfield> <type>bigint</type> <structfield>query_id</structfield> <type>bigint</type>
</para> </para>
<para> <para>
Identifier of this backend's most recent query. If Identifier of this backend's most recent query. If
......
...@@ -833,7 +833,7 @@ CREATE VIEW pg_stat_activity AS ...@@ -833,7 +833,7 @@ CREATE VIEW pg_stat_activity AS
S.state, S.state,
S.backend_xid, S.backend_xid,
s.backend_xmin, s.backend_xmin,
S.queryid, S.query_id,
S.query, S.query,
S.backend_type S.backend_type
FROM pg_stat_get_activity(NULL) AS S FROM pg_stat_get_activity(NULL) AS S
......
...@@ -131,11 +131,11 @@ ExecutorStart(QueryDesc *queryDesc, int eflags) ...@@ -131,11 +131,11 @@ ExecutorStart(QueryDesc *queryDesc, int eflags)
{ {
/* /*
* In some cases (e.g. an EXECUTE statement) a query execution will skip * In some cases (e.g. an EXECUTE statement) a query execution will skip
* parse analysis, which means that the queryid won't be reported. Note * parse analysis, which means that the query_id won't be reported. Note
* that it's harmless to report the queryid multiple time, as the call will * that it's harmless to report the query_id multiple time, as the call will
* be ignored if the top level queryid has already been reported. * be ignored if the top level query_id has already been reported.
*/ */
pgstat_report_queryid(queryDesc->plannedstmt->queryId, false); pgstat_report_query_id(queryDesc->plannedstmt->queryId, false);
if (ExecutorStart_hook) if (ExecutorStart_hook)
(*ExecutorStart_hook) (queryDesc, eflags); (*ExecutorStart_hook) (queryDesc, eflags);
......
...@@ -175,7 +175,7 @@ ExecSerializePlan(Plan *plan, EState *estate) ...@@ -175,7 +175,7 @@ ExecSerializePlan(Plan *plan, EState *estate)
*/ */
pstmt = makeNode(PlannedStmt); pstmt = makeNode(PlannedStmt);
pstmt->commandType = CMD_SELECT; pstmt->commandType = CMD_SELECT;
pstmt->queryId = pgstat_get_my_queryid(); pstmt->queryId = pgstat_get_my_query_id();
pstmt->hasReturning = false; pstmt->hasReturning = false;
pstmt->hasModifyingCTE = false; pstmt->hasModifyingCTE = false;
pstmt->canSetTag = true; pstmt->canSetTag = true;
......
...@@ -132,7 +132,7 @@ parse_analyze(RawStmt *parseTree, const char *sourceText, ...@@ -132,7 +132,7 @@ parse_analyze(RawStmt *parseTree, const char *sourceText,
free_parsestate(pstate); free_parsestate(pstate);
pgstat_report_queryid(query->queryId, false); pgstat_report_query_id(query->queryId, false);
return query; return query;
} }
...@@ -171,7 +171,7 @@ parse_analyze_varparams(RawStmt *parseTree, const char *sourceText, ...@@ -171,7 +171,7 @@ parse_analyze_varparams(RawStmt *parseTree, const char *sourceText,
free_parsestate(pstate); free_parsestate(pstate);
pgstat_report_queryid(query->queryId, false); pgstat_report_query_id(query->queryId, false);
return query; return query;
} }
......
...@@ -694,7 +694,7 @@ pg_analyze_and_rewrite_params(RawStmt *parsetree, ...@@ -694,7 +694,7 @@ pg_analyze_and_rewrite_params(RawStmt *parsetree,
free_parsestate(pstate); free_parsestate(pstate);
pgstat_report_queryid(query->queryId, false); pgstat_report_query_id(query->queryId, false);
if (log_parser_stats) if (log_parser_stats)
ShowUsage("PARSE ANALYSIS STATISTICS"); ShowUsage("PARSE ANALYSIS STATISTICS");
...@@ -1031,7 +1031,7 @@ exec_simple_query(const char *query_string) ...@@ -1031,7 +1031,7 @@ exec_simple_query(const char *query_string)
DestReceiver *receiver; DestReceiver *receiver;
int16 format; int16 format;
pgstat_report_queryid(0, true); pgstat_report_query_id(0, true);
/* /*
* Get the command name for use in status display (it also becomes the * Get the command name for use in status display (it also becomes the
......
...@@ -544,7 +544,7 @@ pgstat_report_activity(BackendState state, const char *cmd_str) ...@@ -544,7 +544,7 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
beentry->st_activity_start_timestamp = 0; beentry->st_activity_start_timestamp = 0;
/* st_xact_start_timestamp and wait_event_info are also disabled */ /* st_xact_start_timestamp and wait_event_info are also disabled */
beentry->st_xact_start_timestamp = 0; beentry->st_xact_start_timestamp = 0;
beentry->st_queryid = UINT64CONST(0); beentry->st_query_id = UINT64CONST(0);
proc->wait_event_info = 0; proc->wait_event_info = 0;
PGSTAT_END_WRITE_ACTIVITY(beentry); PGSTAT_END_WRITE_ACTIVITY(beentry);
} }
...@@ -605,7 +605,7 @@ pgstat_report_activity(BackendState state, const char *cmd_str) ...@@ -605,7 +605,7 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
* identifier. * identifier.
*/ */
if (state == STATE_RUNNING) if (state == STATE_RUNNING)
beentry->st_queryid = UINT64CONST(0); beentry->st_query_id = UINT64CONST(0);
if (cmd_str != NULL) if (cmd_str != NULL)
{ {
...@@ -618,32 +618,32 @@ pgstat_report_activity(BackendState state, const char *cmd_str) ...@@ -618,32 +618,32 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
} }
/* -------- /* --------
* pgstat_report_queryid() - * pgstat_report_query_id() -
* *
* Called to update top-level query identifier. * Called to update top-level query identifier.
* -------- * --------
*/ */
void void
pgstat_report_queryid(uint64 queryId, bool force) pgstat_report_query_id(uint64 query_id, bool force)
{ {
volatile PgBackendStatus *beentry = MyBEEntry; volatile PgBackendStatus *beentry = MyBEEntry;
/* /*
* if track_activities is disabled, st_queryid should already have been * if track_activities is disabled, st_query_id should already have been
* reset * reset
*/ */
if (!beentry || !pgstat_track_activities) if (!beentry || !pgstat_track_activities)
return; return;
/* /*
* We only report the top-level query identifiers. The stored queryid is * We only report the top-level query identifiers. The stored query_id is
* reset when a backend calls pgstat_report_activity(STATE_RUNNING), or * reset when a backend calls pgstat_report_activity(STATE_RUNNING), or
* with an explicit call to this function using the force flag. If the * with an explicit call to this function using the force flag. If the
* saved query identifier is not zero it means that it's not a top-level * saved query identifier is not zero it means that it's not a top-level
* command, so ignore the one provided unless it's an explicit call to * command, so ignore the one provided unless it's an explicit call to
* reset the identifier. * reset the identifier.
*/ */
if (beentry->st_queryid != 0 && !force) if (beentry->st_query_id != 0 && !force)
return; return;
/* /*
...@@ -652,7 +652,7 @@ pgstat_report_queryid(uint64 queryId, bool force) ...@@ -652,7 +652,7 @@ pgstat_report_queryid(uint64 queryId, bool force)
* ensure the compiler doesn't try to get cute. * ensure the compiler doesn't try to get cute.
*/ */
PGSTAT_BEGIN_WRITE_ACTIVITY(beentry); PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
beentry->st_queryid = queryId; beentry->st_query_id = query_id;
PGSTAT_END_WRITE_ACTIVITY(beentry); PGSTAT_END_WRITE_ACTIVITY(beentry);
} }
...@@ -1022,12 +1022,12 @@ pgstat_get_crashed_backend_activity(int pid, char *buffer, int buflen) ...@@ -1022,12 +1022,12 @@ pgstat_get_crashed_backend_activity(int pid, char *buffer, int buflen)
} }
/* ---------- /* ----------
* pgstat_get_my_queryid() - * pgstat_get_my_query_id() -
* *
* Return current backend's query identifier. * Return current backend's query identifier.
*/ */
uint64 uint64
pgstat_get_my_queryid(void) pgstat_get_my_query_id(void)
{ {
if (!MyBEEntry) if (!MyBEEntry)
return 0; return 0;
...@@ -1037,7 +1037,7 @@ pgstat_get_my_queryid(void) ...@@ -1037,7 +1037,7 @@ pgstat_get_my_queryid(void)
* pg_stat_get_activity which is already protected, or from the same * pg_stat_get_activity which is already protected, or from the same
* backend which means that there won't be concurrent writes. * backend which means that there won't be concurrent writes.
*/ */
return MyBEEntry->st_queryid; return MyBEEntry->st_query_id;
} }
......
...@@ -914,10 +914,10 @@ pg_stat_get_activity(PG_FUNCTION_ARGS) ...@@ -914,10 +914,10 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
values[27] = BoolGetDatum(false); /* GSS Encryption not in values[27] = BoolGetDatum(false); /* GSS Encryption not in
* use */ * use */
} }
if (beentry->st_queryid == 0) if (beentry->st_query_id == 0)
nulls[29] = true; nulls[29] = true;
else else
values[29] = UInt64GetDatum(beentry->st_queryid); values[29] = UInt64GetDatum(beentry->st_query_id);
} }
else else
{ {
......
...@@ -2717,10 +2717,10 @@ log_line_prefix(StringInfo buf, ErrorData *edata) ...@@ -2717,10 +2717,10 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
case 'Q': case 'Q':
if (padding != 0) if (padding != 0)
appendStringInfo(buf, "%*lld", padding, appendStringInfo(buf, "%*lld", padding,
(long long) pgstat_get_my_queryid()); (long long) pgstat_get_my_query_id());
else else
appendStringInfo(buf, "%lld", appendStringInfo(buf, "%lld",
(long long) pgstat_get_my_queryid()); (long long) pgstat_get_my_query_id());
break; break;
default: default:
/* format error - ignore it */ /* format error - ignore it */
...@@ -2967,7 +2967,7 @@ write_csvlog(ErrorData *edata) ...@@ -2967,7 +2967,7 @@ write_csvlog(ErrorData *edata)
appendStringInfoChar(&buf, ','); appendStringInfoChar(&buf, ',');
/* query id */ /* query id */
appendStringInfo(&buf, "%lld", (long long) pgstat_get_my_queryid()); appendStringInfo(&buf, "%lld", (long long) pgstat_get_my_query_id());
appendStringInfoChar(&buf, '\n'); appendStringInfoChar(&buf, '\n');
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#define JUMBLE_SIZE 1024 /* query serialization buffer size */ #define JUMBLE_SIZE 1024 /* query serialization buffer size */
static uint64 compute_utility_queryid(const char *str, int query_location, int query_len); static uint64 compute_utility_query_id(const char *str, int query_location, int query_len);
static void AppendJumble(JumbleState *jstate, static void AppendJumble(JumbleState *jstate,
const unsigned char *item, Size size); const unsigned char *item, Size size);
static void JumbleQueryInternal(JumbleState *jstate, Query *query); static void JumbleQueryInternal(JumbleState *jstate, Query *query);
...@@ -97,7 +97,7 @@ JumbleQuery(Query *query, const char *querytext) ...@@ -97,7 +97,7 @@ JumbleQuery(Query *query, const char *querytext)
JumbleState *jstate = NULL; JumbleState *jstate = NULL;
if (query->utilityStmt) if (query->utilityStmt)
{ {
query->queryId = compute_utility_queryid(querytext, query->queryId = compute_utility_query_id(querytext,
query->stmt_location, query->stmt_location,
query->stmt_len); query->stmt_len);
} }
...@@ -135,7 +135,7 @@ JumbleQuery(Query *query, const char *querytext) ...@@ -135,7 +135,7 @@ JumbleQuery(Query *query, const char *querytext)
* Compute a query identifier for the given utility query string. * Compute a query identifier for the given utility query string.
*/ */
static uint64 static uint64
compute_utility_queryid(const char *query_text, int query_location, int query_len) compute_utility_query_id(const char *query_text, int query_location, int query_len)
{ {
uint64 queryId; uint64 queryId;
const char *sql; const char *sql;
......
...@@ -53,6 +53,6 @@ ...@@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 202104162 #define CATALOG_VERSION_NO 202104201
#endif #endif
...@@ -5281,7 +5281,7 @@ ...@@ -5281,7 +5281,7 @@
prorettype => 'record', proargtypes => 'int4', prorettype => 'record', proargtypes => 'int4',
proallargtypes => '{int4,oid,int4,oid,text,text,text,text,text,timestamptz,timestamptz,timestamptz,timestamptz,inet,text,int4,xid,xid,text,bool,text,text,int4,text,numeric,text,bool,text,bool,int4,int8}', proallargtypes => '{int4,oid,int4,oid,text,text,text,text,text,timestamptz,timestamptz,timestamptz,timestamptz,inet,text,int4,xid,xid,text,bool,text,text,int4,text,numeric,text,bool,text,bool,int4,int8}',
proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}', proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
proargnames => '{pid,datid,pid,usesysid,application_name,state,query,wait_event_type,wait_event,xact_start,query_start,backend_start,state_change,client_addr,client_hostname,client_port,backend_xid,backend_xmin,backend_type,ssl,sslversion,sslcipher,sslbits,ssl_client_dn,ssl_client_serial,ssl_issuer_dn,gss_auth,gss_princ,gss_enc,leader_pid,queryid}', proargnames => '{pid,datid,pid,usesysid,application_name,state,query,wait_event_type,wait_event,xact_start,query_start,backend_start,state_change,client_addr,client_hostname,client_port,backend_xid,backend_xmin,backend_type,ssl,sslversion,sslcipher,sslbits,ssl_client_dn,ssl_client_serial,ssl_issuer_dn,gss_auth,gss_princ,gss_enc,leader_pid,query_id}',
prosrc => 'pg_stat_get_activity' }, prosrc => 'pg_stat_get_activity' },
{ oid => '3318', { oid => '3318',
descr => 'statistics: information about progress of backends running maintenance command', descr => 'statistics: information about progress of backends running maintenance command',
......
...@@ -167,7 +167,7 @@ typedef struct PgBackendStatus ...@@ -167,7 +167,7 @@ typedef struct PgBackendStatus
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]; int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM];
/* query identifier, optionally computed using post_parse_analyze_hook */ /* query identifier, optionally computed using post_parse_analyze_hook */
uint64 st_queryid; uint64 st_query_id;
} PgBackendStatus; } PgBackendStatus;
...@@ -297,14 +297,14 @@ extern void pgstat_clear_backend_activity_snapshot(void); ...@@ -297,14 +297,14 @@ extern void pgstat_clear_backend_activity_snapshot(void);
/* Activity reporting functions */ /* Activity reporting functions */
extern void pgstat_report_activity(BackendState state, const char *cmd_str); extern void pgstat_report_activity(BackendState state, const char *cmd_str);
extern void pgstat_report_queryid(uint64 queryId, bool force); extern void pgstat_report_query_id(uint64 query_id, bool force);
extern void pgstat_report_tempfile(size_t filesize); extern void pgstat_report_tempfile(size_t filesize);
extern void pgstat_report_appname(const char *appname); extern void pgstat_report_appname(const char *appname);
extern void pgstat_report_xact_timestamp(TimestampTz tstamp); extern void pgstat_report_xact_timestamp(TimestampTz tstamp);
extern const char *pgstat_get_backend_current_activity(int pid, bool checkUser); extern const char *pgstat_get_backend_current_activity(int pid, bool checkUser);
extern const char *pgstat_get_crashed_backend_activity(int pid, char *buffer, extern const char *pgstat_get_crashed_backend_activity(int pid, char *buffer,
int buflen); int buflen);
extern uint64 pgstat_get_my_queryid(void); extern uint64 pgstat_get_my_query_id(void);
/* ---------- /* ----------
......
...@@ -1762,10 +1762,10 @@ pg_stat_activity| SELECT s.datid, ...@@ -1762,10 +1762,10 @@ pg_stat_activity| SELECT s.datid,
s.state, s.state,
s.backend_xid, s.backend_xid,
s.backend_xmin, s.backend_xmin,
s.queryid, s.query_id,
s.query, s.query,
s.backend_type s.backend_type
FROM ((pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc, leader_pid, queryid) FROM ((pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc, leader_pid, query_id)
LEFT JOIN pg_database d ON ((s.datid = d.oid))) LEFT JOIN pg_database d ON ((s.datid = d.oid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid))); LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_all_indexes| SELECT c.oid AS relid, pg_stat_all_indexes| SELECT c.oid AS relid,
...@@ -1877,7 +1877,7 @@ pg_stat_gssapi| SELECT s.pid, ...@@ -1877,7 +1877,7 @@ pg_stat_gssapi| SELECT s.pid,
s.gss_auth AS gss_authenticated, s.gss_auth AS gss_authenticated,
s.gss_princ AS principal, s.gss_princ AS principal,
s.gss_enc AS encrypted s.gss_enc AS encrypted
FROM pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc, leader_pid, queryid) FROM pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc, leader_pid, query_id)
WHERE (s.client_port IS NOT NULL); WHERE (s.client_port IS NOT NULL);
pg_stat_prefetch_recovery| SELECT s.stats_reset, pg_stat_prefetch_recovery| SELECT s.stats_reset,
s.prefetch, s.prefetch,
...@@ -2058,7 +2058,7 @@ pg_stat_replication| SELECT s.pid, ...@@ -2058,7 +2058,7 @@ pg_stat_replication| SELECT s.pid,
w.sync_priority, w.sync_priority,
w.sync_state, w.sync_state,
w.reply_time w.reply_time
FROM ((pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc, leader_pid, queryid) FROM ((pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc, leader_pid, query_id)
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid))) JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid))); LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
pg_stat_replication_slots| SELECT s.slot_name, pg_stat_replication_slots| SELECT s.slot_name,
...@@ -2090,7 +2090,7 @@ pg_stat_ssl| SELECT s.pid, ...@@ -2090,7 +2090,7 @@ pg_stat_ssl| SELECT s.pid,
s.ssl_client_dn AS client_dn, s.ssl_client_dn AS client_dn,
s.ssl_client_serial AS client_serial, s.ssl_client_serial AS client_serial,
s.ssl_issuer_dn AS issuer_dn s.ssl_issuer_dn AS issuer_dn
FROM pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc, leader_pid, queryid) FROM pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc, leader_pid, query_id)
WHERE (s.client_port IS NOT NULL); WHERE (s.client_port IS NOT NULL);
pg_stat_subscription| SELECT su.oid AS subid, pg_stat_subscription| SELECT su.oid AS subid,
su.subname, su.subname,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment