Skip to content

Commit f57a2f5

Browse files
committed
Add csvlog output for the new query_id value
This also adjusts the printf format for query id used by log_line_prefix (%Q). Reported-by: Justin Pryzby Discussion: https://postgr.es/m/20210408005402.GG24239@momjian.us Author: Julien Rouhaud, Bruce Momjian
1 parent 5100010 commit f57a2f5

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

doc/src/sgml/config.sgml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7310,7 +7310,8 @@ log_line_prefix = '%m [%p] %q%u@%d/%a '
73107310
character count of the error position therein,
73117311
location of the error in the PostgreSQL source code
73127312
(if <varname>log_error_verbosity</varname> is set to <literal>verbose</literal>),
7313-
application name, backend type, and process ID of parallel group leader.
7313+
application name, backend type, process ID of parallel group leader,
7314+
and query id.
73147315
Here is a sample table definition for storing CSV-format log output:
73157316

73167317
<programlisting>
@@ -7341,6 +7342,7 @@ CREATE TABLE postgres_log
73417342
application_name text,
73427343
backend_type text,
73437344
leader_pid integer,
7345+
query_id bigint,
73447346
PRIMARY KEY (session_id, session_line_num)
73457347
);
73467348
</programlisting>

doc/src/sgml/file-fdw.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ CREATE FOREIGN TABLE pglog (
266266
location text,
267267
application_name text,
268268
backend_type text,
269-
leader_pid integer
269+
leader_pid integer,
270+
query_id bigint
270271
) SERVER pglog
271272
OPTIONS ( filename 'log/pglog.csv', format 'csv' );
272273
</programlisting>

src/backend/utils/error/elog.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,11 +2716,11 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
27162716
break;
27172717
case 'Q':
27182718
if (padding != 0)
2719-
appendStringInfo(buf, "%*ld", padding,
2720-
pgstat_get_my_queryid());
2719+
appendStringInfo(buf, "%*lld", padding,
2720+
(long long) pgstat_get_my_queryid());
27212721
else
2722-
appendStringInfo(buf, "%ld",
2723-
pgstat_get_my_queryid());
2722+
appendStringInfo(buf, "%lld",
2723+
(long long) pgstat_get_my_queryid());
27242724
break;
27252725
default:
27262726
/* format error - ignore it */
@@ -2964,6 +2964,10 @@ write_csvlog(ErrorData *edata)
29642964
if (leader && leader->pid != MyProcPid)
29652965
appendStringInfo(&buf, "%d", leader->pid);
29662966
}
2967+
appendStringInfoChar(&buf, ',');
2968+
2969+
/* query id */
2970+
appendStringInfo(&buf, "%lld", (long long) pgstat_get_my_queryid());
29672971

29682972
appendStringInfoChar(&buf, '\n');
29692973

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy