Commit f57a2f5e authored by Bruce Momjian's avatar Bruce Momjian

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
parent 5100010e
...@@ -7310,7 +7310,8 @@ log_line_prefix = '%m [%p] %q%u@%d/%a ' ...@@ -7310,7 +7310,8 @@ log_line_prefix = '%m [%p] %q%u@%d/%a '
character count of the error position therein, character count of the error position therein,
location of the error in the PostgreSQL source code location of the error in the PostgreSQL source code
(if <varname>log_error_verbosity</varname> is set to <literal>verbose</literal>), (if <varname>log_error_verbosity</varname> is set to <literal>verbose</literal>),
application name, backend type, and process ID of parallel group leader. application name, backend type, process ID of parallel group leader,
and query id.
Here is a sample table definition for storing CSV-format log output: Here is a sample table definition for storing CSV-format log output:
<programlisting> <programlisting>
...@@ -7341,6 +7342,7 @@ CREATE TABLE postgres_log ...@@ -7341,6 +7342,7 @@ CREATE TABLE postgres_log
application_name text, application_name text,
backend_type text, backend_type text,
leader_pid integer, leader_pid integer,
query_id bigint,
PRIMARY KEY (session_id, session_line_num) PRIMARY KEY (session_id, session_line_num)
); );
</programlisting> </programlisting>
......
...@@ -266,7 +266,8 @@ CREATE FOREIGN TABLE pglog ( ...@@ -266,7 +266,8 @@ CREATE FOREIGN TABLE pglog (
location text, location text,
application_name text, application_name text,
backend_type text, backend_type text,
leader_pid integer leader_pid integer,
query_id bigint
) SERVER pglog ) SERVER pglog
OPTIONS ( filename 'log/pglog.csv', format 'csv' ); OPTIONS ( filename 'log/pglog.csv', format 'csv' );
</programlisting> </programlisting>
......
...@@ -2716,11 +2716,11 @@ log_line_prefix(StringInfo buf, ErrorData *edata) ...@@ -2716,11 +2716,11 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
break; break;
case 'Q': case 'Q':
if (padding != 0) if (padding != 0)
appendStringInfo(buf, "%*ld", padding, appendStringInfo(buf, "%*lld", padding,
pgstat_get_my_queryid()); (long long) pgstat_get_my_queryid());
else else
appendStringInfo(buf, "%ld", appendStringInfo(buf, "%lld",
pgstat_get_my_queryid()); (long long) pgstat_get_my_queryid());
break; break;
default: default:
/* format error - ignore it */ /* format error - ignore it */
...@@ -2964,6 +2964,10 @@ write_csvlog(ErrorData *edata) ...@@ -2964,6 +2964,10 @@ write_csvlog(ErrorData *edata)
if (leader && leader->pid != MyProcPid) if (leader && leader->pid != MyProcPid)
appendStringInfo(&buf, "%d", leader->pid); appendStringInfo(&buf, "%d", leader->pid);
} }
appendStringInfoChar(&buf, ',');
/* query id */
appendStringInfo(&buf, "%lld", (long long) pgstat_get_my_queryid());
appendStringInfoChar(&buf, '\n'); appendStringInfoChar(&buf, '\n');
......
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