Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jtvcU-0003j9-6I for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Jul 2020 16:11:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jtvcS-0004VM-PM for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Jul 2020 16:11:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jtvcS-0004VF-4r for pgsql-hackers@lists.postgresql.org; Fri, 10 Jul 2020 16:11:24 +0000 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jtvcO-00014Y-Qf for pgsql-hackers@postgresql.org; Fri, 10 Jul 2020 16:11:22 +0000 Received: by mail-il1-x12e.google.com with SMTP id a11so5552685ilk.0 for ; Fri, 10 Jul 2020 09:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zCVUjIl2ftCV7DpTrYCqEqZJ+7vsWL9VCZKoh7HyPOM=; b=yc2NoHnFxGTdU8E2ABzKrOOg/4asaqj/5xHVoJ4YKRC6WP39M6eyMzZZh13ZknHp9K j9Gje1kTh7HuxEiqh284t+cCeduRt0KuVrj9iJ2ztcAt1zbXaShjZbR6ZvBKjgswbyuu C7+a3CSp3UBLM4L7Z++ognvVQtdPuUQpjbWT2oaThCMHezLZg57RNzbHxiOuuSvjavXW dd8xXjsW1Au97YY0pwjlSgM6pyOY4DNkSZukkSR8bSZrI5PBCR/Sg301xEf+ctuv2N/d UcXPDDrvi8jEOH7sWOxHVoHVVszL2k1gTsjIE0XfGHh974Reaej0dex0XFbtVS29iagG KwdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zCVUjIl2ftCV7DpTrYCqEqZJ+7vsWL9VCZKoh7HyPOM=; b=SdEjNNlBhisKkiBUqDedvUv/uZm70t40HHkzYB3Q0MXzxlZBY5sJHPFrYywk3s/smt hfLwH4ZrgEZ2VIB3hCp7mStljjab/e1l5Ekrhg8fPg0vxzKwkwX/xFB+NSoGpaxjYG69 k/0uVURxVGBGp4X9IJ95arlGnZdKlMkKrb9S9V5kf34BQxcYqwhxUk76HCg29HfzxNKQ 9MZ2ky+ciwaTpJJVuBwB7ZVphD4Zo0TcjqD9IyWmRIVcvqWcXQUs+zXOIklZ+TrxoAhX 9WXnc2mzQcq+ouz68CrTA5R50YMaxieXMTXsqu0jZ8rPqJzDcg+W29hAEDM5CGYmp2Wo n9OQ== X-Gm-Message-State: AOAM531w4FfyVWc5JWz2wEBCUYo7DDz1eqLdupx2Eh4Sq6rLN5lZykgp CFrgK2Iv8uQdpIhTkZ0tbkrrRQ== X-Google-Smtp-Source: ABdhPJy6H8cITTNKgmCqL3/06cAdm58GmQQpSI0x2afr/KxWWu97VS7y7eVyFWDuxQulVtxtcUvX2g== X-Received: by 2002:a92:4b08:: with SMTP id m8mr50132253ilg.150.1594397479476; Fri, 10 Jul 2020 09:11:19 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id d77sm3728336ill.67.2020.07.10.09.11.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Jul 2020 09:11:18 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id B0D17800CA8; Fri, 10 Jul 2020 11:11:15 -0500 (CDT) Date: Fri, 10 Jul 2020 11:11:15 -0500 From: Justin Pryzby To: Julien Rouhaud Cc: Michael Paquier , Daniel Gustafsson , pgsql-hackers@postgresql.org Subject: Re: expose parallel leader in CSV and log_line_prefix Message-ID: <20200710161115.GK26220@telsasoft.com> References: <20200315111831.GA21492@telsasoft.com> <20200315114933.udjdx5wcgwkjnw45@nol> <20200318212511.GN26184@telsasoft.com> <8EC64544-2EAA-48B1-8B69-85158CA3EAE9@yesql.se> <20200710020940.GJ11153@paquier.xyz> <20200710022023.GE26220@telsasoft.com> <20200710151326.fics6czbbvloplsk@nol> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="cWoXeonUoKmBZSoM" Content-Disposition: inline In-Reply-To: <20200710151326.fics6czbbvloplsk@nol> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --cWoXeonUoKmBZSoM Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Jul 10, 2020 at 05:13:26PM +0200, Julien Rouhaud wrote: > There's a thinko in the padding handling. It should be dones whether MyProc > and/or lockGroupLeader is NULL or not, and only if padding was asked, like it's > done for case 'd' for instance. > > Also, the '%k' escape sounds a bit random. Is there any reason why we don't > use any uppercase character for log_line_prefix? %P could be a better > alternative, otherwise maybe %g, as GroupLeader/Gather? Thanks for looking. %P is a good idea - it's consistent with ps and pkill and probably other %commands. I also amended the docs. -- Justin --cWoXeonUoKmBZSoM Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Include-the-leader-PID-in-logfile.patch" From 68a892d0023e915cc48aea1bb77eae5deabcecec Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Fri, 13 Mar 2020 22:03:06 -0500 Subject: [PATCH v2] Include the leader PID in logfile See also: b025f32e0b, which adds the leader PID to pg_stat_activity --- doc/src/sgml/config.sgml | 11 ++++++- src/backend/utils/error/elog.c | 30 +++++++++++++++++++ src/backend/utils/misc/postgresql.conf.sample | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index b353c61683..e60403d6a5 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -6611,6 +6611,14 @@ local0.* /var/log/postgresql Process ID no + + %P + Process ID of the parallel group leader if this process was + at some point involved in parallel query, otherwise null. For a + parallel group leader itself, this field is set to its own process + ID. + no + %t Time stamp without milliseconds @@ -6943,7 +6951,7 @@ 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 log_error_verbosity is set to verbose), - application name, and backend type. + application name, backend type, and leader PID. Here is a sample table definition for storing CSV-format log output: @@ -6973,6 +6981,7 @@ CREATE TABLE postgres_log location text, application_name text, backend_type text, + leader_pid integer, PRIMARY KEY (session_id, session_line_num) ); diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index e4b717c79a..dea098faf1 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -77,6 +77,7 @@ #include "postmaster/syslogger.h" #include "storage/ipc.h" #include "storage/proc.h" +#include "storage/procarray.h" #include "tcop/tcopprot.h" #include "utils/guc.h" #include "utils/memutils.h" @@ -2448,6 +2449,25 @@ log_line_prefix(StringInfo buf, ErrorData *edata) else appendStringInfo(buf, "%d", MyProcPid); break; + + case 'P': + if (MyProc) + { + PGPROC *leader = MyProc->lockGroupLeader; + if (leader == NULL) + /* padding only */ + appendStringInfoSpaces(buf, + padding > 0 ? padding : -padding); + else if (padding != 0) + appendStringInfo(buf, "%*d", padding, leader->pid); + else + appendStringInfo(buf, "%d", leader->pid); + } + else if (padding != 0) + appendStringInfoSpaces(buf, + padding > 0 ? padding : -padding); + break; + case 'l': if (padding != 0) appendStringInfo(buf, "%*ld", padding, log_line_number); @@ -2836,6 +2856,16 @@ write_csvlog(ErrorData *edata) else appendCSVLiteral(&buf, GetBackendTypeDesc(MyBackendType)); + appendStringInfoChar(&buf, ','); + + /* leader PID */ + if (MyProc) + { + PGPROC *leader = MyProc->lockGroupLeader; + if (leader) + appendStringInfo(&buf, "%d", leader->pid); + } + appendStringInfoChar(&buf, '\n'); /* If in the syslogger process, try to write messages direct to file */ diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index e430e33c7b..48a50fb394 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -533,6 +533,7 @@ # %h = remote host # %b = backend type # %p = process ID + # %P = leader PID # %t = timestamp without milliseconds # %m = timestamp with milliseconds # %n = timestamp with milliseconds (as a Unix epoch) -- 2.17.0 --cWoXeonUoKmBZSoM--