On Thu, Apr  8, 2021 at 05:56:25AM +0800, Julien Rouhaud wrote:
> On Wed, Apr 07, 2021 at 04:22:55PM -0400, Bruce Momjian wrote:
> > aOn Wed, Apr  7, 2021 at 04:15:50PM -0400, Tom Lane wrote:
> > > Bruce Momjian <br...@momjian.us> writes:
> > > > Patch applied.  I am ready to adjust this with any improvements people
> > > > might have.  Thank you for all the good feedback we got on this, and I
> > > > know many users have waited a long time for this feature.
> > > 
> > > For starters, you could try to make the buildfarm green again.
> > 
> > Wow, that's odd.  The cfbot was green, so I never even looked at the
> > buildfarm.  I will look at that now, and the CVS log issue.
> 
> Sorry about that.  The issue came from animals with jit_above_cost = 0
> outputting more lines than expected.  I fixed that by using the same query as
> before in explain.sql, as they don't generate any JIT output.

Yes, I just came to the same conclusion, that 'SELECT 1' didn't generate
the proper output lines to allow explain_filter() to strip out the JIT
lines.  I have applied your patch for this, which should fix the build
farm. (I see my first green report now.)

> I also added the queryid to the csvlog output and fixed the documentation that
> mention how to create a table to access the data.

Uh, I think your patch missed a few things.  First, you use "%zd"
(size_t) for the printf string, but calls to pgstat_get_my_queryid() in
src/backend/utils/error/elog.c used "%ld".  Which is correct?  I see
pgstat_get_my_queryid() as returning uint64, but I didn't think a uint64
fits in a BIGINT SQL column.

Also, you missed the SGML paragraph doc change, but you correctly
changed the SQL table definition.

I am attaching my version of the patch.

-- 
  Bruce Momjian  <br...@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  If only the physical world exists, free will is an illusion.

>From d6b0d010678bab519cc8a54893ff6c4affd34422 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <br...@momjian.us>
Date: Wed, 7 Apr 2021 18:37:25 -0400
Subject: [PATCH] csv squash commit

---
 doc/src/sgml/config.sgml       | 4 +++-
 doc/src/sgml/file-fdw.sgml     | 3 ++-
 src/backend/utils/error/elog.c | 4 ++++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 963824d050..ea5cf3a2dc 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -7310,7 +7310,8 @@ log_line_prefix = '%m [%p] %q%u@%d/%a '
         character count of the error position therein,
         location of the error in the PostgreSQL source code
         (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:
 
 <programlisting>
@@ -7341,6 +7342,7 @@ CREATE TABLE postgres_log
   application_name text,
   backend_type text,
   leader_pid integer,
+  query_id bigint,
   PRIMARY KEY (session_id, session_line_num)
 );
 </programlisting>
diff --git a/doc/src/sgml/file-fdw.sgml b/doc/src/sgml/file-fdw.sgml
index 2e21806f48..2b531277de 100644
--- a/doc/src/sgml/file-fdw.sgml
+++ b/doc/src/sgml/file-fdw.sgml
@@ -266,7 +266,8 @@ CREATE FOREIGN TABLE pglog (
   location text,
   application_name text,
   backend_type text,
-  leader_pid integer
+  leader_pid integer,
+  query_id bigint,
 ) SERVER pglog
 OPTIONS ( filename 'log/pglog.csv', format 'csv' );
 </programlisting>
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 1cf71a649b..c3c2045580 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -2967,6 +2967,10 @@ write_csvlog(ErrorData *edata)
 
 	appendStringInfoChar(&buf, '\n');
 
+	/* query id */
+	appendStringInfo(&buf, "%ld", pgstat_get_my_queryid());
+	appendStringInfoChar(&buf, ',');
+
 	/* If in the syslogger process, try to write messages direct to file */
 	if (MyBackendType == B_LOGGER)
 		write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_CSVLOG);
-- 
2.20.1

Reply via email to