From: Bruce Momjian <bruce@momjian.us>
To: Julien Rouhaud <rjuju123@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Nitin Jadhav <nitinjadhavpostgres@gmail.com>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Hannu Krosing <hannuk@google.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Pavel Stehule <pavel.stehule@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: torikoshia <torikoshia@oss.nttdata.com>
Cc: Atsushi Torikoshi <atorik@gmail.com>
Cc: Tatsuro Yamada <tatsuro.yamada.tf@nttcom.co.jp>
Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: Evgeny Efimkin <efimkin@yandex-team.ru>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Feature improvement: can we add queryId for pg_catalog.pg_stat_activity view?
Date: Wed, 7 Apr 2021 20:54:02 -0400
Message-ID: <20210408005402.GG24239@momjian.us> (raw)
In-Reply-To: <20210408004748.mhqds3v3nij35ihw@nol>
References: <CAMm1aWbTTc7AJrAZa7q1QgNNqdNkFP_-owKHDR=zEjQGqevnpg@mail.gmail.com>
<20210407125726.tkvjdbw76hxnpwfi@nol>
<20210407181211.GB24239@momjian.us>
<1646131.1617826550@sss.pgh.pa.us>
<20210407202255.GD24239@momjian.us>
<20210407215625.syzdpwew4j47hhgl@nol>
<20210407223840.GE24239@momjian.us>
<1730584.1617836485@sss.pgh.pa.us>
<20210407233835.GF24239@momjian.us>
<20210408004748.mhqds3v3nij35ihw@nol>
On Thu, Apr 8, 2021 at 08:47:48AM +0800, Julien Rouhaud wrote:
> On Wed, Apr 07, 2021 at 07:38:35PM -0400, Bruce Momjian wrote:
> > On Wed, Apr 7, 2021 at 07:01:25PM -0400, Tom Lane wrote:
> > > Bruce Momjian <bruce@momjian.us> writes:
> > > > 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.
> > >
> > > Neither is correct. Project standard these days for printing [u]int64
> > > is to write "%lld" or "%llu", with an explicit (long long) cast on
> > > the printf argument.
> >
> > Yep, got it. The attached patch fixes all the calls to use %lld, and
> > adds casts. In implementing cvslog, I noticed that internally we pass
> > the hash as uint64, but output as int64, which I think is a requirement
> > for how pg_stat_statements has output it, and the use of bigint. Is
> > that OK?
>
> Indeed, this is due to how we expose the value in SQL. The original discussion
> is at
> https://www.postgresql.org/message-id/CAH2-WzkueMfAmY3onoXLi+g67SJoKY65Cg9Z1QOhSyhCEU8w3g@mail.gmail....
> As far as I know this is OK, as we want to show consistent values everywhere.
OK, yes, I do remember the discussion. I was wondering if there should
be a C comment about this anywhere.
> > I am also confused about the inconsistency of calling the GUC
> > compute_query_id (with underscore), but pg_stat_activity.queryid. If we
> > make it pg_stat_activity.query_id, it doesn't match most of the other
> > *id columsns in the table, leader_pid, usesysid, backend_xid. Is that
> > OK?I know I suggested pg_stat_activity.query_id, but maybe I was wrong.
>
> Mmm, most of the columns in pg_stat_activity do have a "_", so using query_id
> would make more sense.
OK, let me work on a patch to change that part.
> @@ -2967,6 +2967,10 @@ write_csvlog(ErrorData *edata)
>
> appendStringInfoChar(&buf, '\n');
>
> + /* query id */
> + appendStringInfo(&buf, "%lld", (long long) 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);
>
> Unless I'm missing something this will output the query id in the next log
> line? The new code should be added before the newline is output, and the comma
> should also be output before the queryid.
Yes, correct, updated patch attached.
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com
If only the physical world exists, free will is an illusion.
Attachments:csv.diff (text/x-diff, 2.7K) download
From 2e4beaef3690f7b61b91264a95a270e5410dad53 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Wed, 7 Apr 2021 20:51:10 -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 | 12 ++++++++----
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgmlindex 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.sgmlindex 2e21806f48..5b98782064 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.cindex 1cf71a649b..a1ebe06d5b 100644--- a/src/backend/utils/error/elog.c+++ b/src/backend/utils/error/elog.c@@ -2716,11 +2716,11 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
break;
case 'Q':
if (padding != 0)
- appendStringInfo(buf, "%*ld", padding,- pgstat_get_my_queryid());+ appendStringInfo(buf, "%*lld", padding,+ (long long) pgstat_get_my_queryid());
else
- appendStringInfo(buf, "%ld",- pgstat_get_my_queryid());+ appendStringInfo(buf, "%lld",+ (long long) pgstat_get_my_queryid());
break;
default:
/* format error - ignore it */
@@ -2964,6 +2964,10 @@ write_csvlog(ErrorData *edata)
if (leader && leader->pid != MyProcPid)
appendStringInfo(&buf, "%d", leader->pid);
}
+ appendStringInfoChar(&buf, ',');++ /* query id */+ appendStringInfo(&buf, "%lld", (long long) pgstat_get_my_queryid());
appendStringInfoChar(&buf, '\n');
--
2.20.1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: bruce@momjian.us, rjuju123@gmail.com, tgl@sss.pgh.pa.us, nitinjadhavpostgres@gmail.com, alvherre@alvh.no-ip.org, hannuk@google.com, robertmhaas@gmail.com, pavel.stehule@gmail.com, michael@paquier.xyz, torikoshia@oss.nttdata.com, atorik@gmail.com, tatsuro.yamada.tf@nttcom.co.jp, tomas.vondra@2ndquadrant.com, efimkin@yandex-team.ru
Subject: Re: Feature improvement: can we add queryId for pg_catalog.pg_stat_activity view?
In-Reply-To: <20210408005402.GG24239@momjian.us>
References: <CAMm1aWbTTc7AJrAZa7q1QgNNqdNkFP_-owKHDR=zEjQGqevnpg@mail.gmail.com> <20210407125726.tkvjdbw76hxnpwfi@nol> <20210407181211.GB24239@momjian.us> <1646131.1617826550@sss.pgh.pa.us> <20210407202255.GD24239@momjian.us> <20210407215625.syzdpwew4j47hhgl@nol> <20210407223840.GE24239@momjian.us> <1730584.1617836485@sss.pgh.pa.us> <20210407233835.GF24239@momjian.us> <20210408004748.mhqds3v3nij35ihw@nol> <20210408005402.GG24239@momjian.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox