Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jDRI3-0008OS-DD for pgsql-hackers@arkaria.postgresql.org; Sun, 15 Mar 2020 11:18:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jDRI1-0001uQ-6l for pgsql-hackers@arkaria.postgresql.org; Sun, 15 Mar 2020 11:18:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jDRI0-0001uJ-P2 for pgsql-hackers@lists.postgresql.org; Sun, 15 Mar 2020 11:18:40 +0000 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jDRHw-0007Nc-Hl for pgsql-hackers@postgresql.org; Sun, 15 Mar 2020 11:18:40 +0000 Received: by mail-qk1-x733.google.com with SMTP id p62so21070334qkb.0 for ; Sun, 15 Mar 2020 04:18:36 -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:mime-version:content-disposition :user-agent; bh=WCXPL9bugTxtJIcQeQl6Ur1boHBoWx8e6qPlFC17mIQ=; b=K/NWWUKBnzjoRDIJlNC6fWQ1XiArfOV18PDzVcENkAF8Y7lsro6+hU+qFouAY1Euj4 VwzMWNZw3vekz++FdX+e9NdJ9R8QrzgazBeMWRKCE0TwXCSsLIrMq1gFX8XSddvdYkiV Zt5BF8Ywx8kGbalt9NQmP+wTD68fXMWO+jB5DPk58Gbu8kJrWi+C83uIIHRDHRcmcreI ui6oD7zl3ihRugO2TNYpSrmnAJzQmM/w3/RVnOpUysKh47XS1SG2wg8AiT0k/JtSwC7M 89i9kFZ3LJJFWNpsJZF4Ag1BDZGh+jXYZh2dbHxIRrdLsLylhY05w7Cs8J+Wuymy6oKe BkwQ== 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:mime-version :content-disposition:user-agent; bh=WCXPL9bugTxtJIcQeQl6Ur1boHBoWx8e6qPlFC17mIQ=; b=WmKo9lf0Udr6SKjri7vJzO4uZn9kh+5oMhobRmX0SrAi6gN8T+Z9gNBenKf9a1vi0f IxtrDGHNmrSOFnAH/Kv4fiGiRaGYsi4uu0P281GI9X5vNooLGKHYBVNoe1Hr0T93r51C MLyNvTEsNgtTg4nqmw7lx4S8wOXDc/aW8E+7rD7W85AmGPdSTWQZWc5jKnZ0MN60OQrq 58hSUpVSh89jNBCBfE496da/yUhkgfSpOGvvU+v03n+8zCoAv/Wf/T0oDx5xrpegcmP5 YQX8JW6tYxY1v+bhOmu6HCv8HfzO9Qi3/jav8M7YfAgQ+0o1R6MyEWoXqwP7dhr16muZ vhVA== X-Gm-Message-State: ANhLgQ0XAm+x1nI8ByD2dKiSCt94dbUhEqmr3zkYgA4dVHIYCdwlFK6D /+0HVzDe0bay4lRPW8rE6FE3Uw== X-Google-Smtp-Source: ADFU+vsVUGtrfvcpqtF9vgCiex7qy8/JSLMKE15TWYlokIXLl8TKWJRMeRxW9kCJlcswZUJU3SLP8A== X-Received: by 2002:a37:9104:: with SMTP id t4mr22586590qkd.449.1584271113890; Sun, 15 Mar 2020 04:18:33 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id n6sm13295680qkh.70.2020.03.15.04.18.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 04:18:32 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 45B54800CF1; Sun, 15 Mar 2020 06:18:31 -0500 (CDT) Date: Sun, 15 Mar 2020 06:18:31 -0500 From: Justin Pryzby To: pgsql-hackers@postgresql.org Cc: Julien Rouhaud Subject: expose parallel leader in CSV and log_line_prefix Message-ID: <20200315111831.GA21492@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ikeVEW9yuYc//A+q" Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --ikeVEW9yuYc//A+q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline See also: https://commitfest.postgresql.org/27/2390/ https://www.postgresql.org/message-id/flat/CAOBaU_Yy5bt0vTPZ2_LUM6cUcGeqmYNoJ8-Rgto+c2+w3defYA@mail.gmail.com b025f32e0b Add leader_pid to pg_stat_activity -- Justin --ikeVEW9yuYc//A+q Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Include-the-leader-PID-in-logfile.patch" From 5268e89fb32fbb639cb39796729dfe0dfcf14705 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 | 20 +++++++++++++++++++ src/backend/utils/misc/postgresql.conf.sample | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 3cac340f32..f6ded2bc45 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -6491,6 +6491,14 @@ local0.* /var/log/postgresql Process ID no + + %k + Process ID of the parallel group leader if this + process is or was involved in parallel query, null + otherwise. For a parallel group leader, this field is + set to its own process ID. + no + %t Time stamp without milliseconds @@ -6789,7 +6797,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: @@ -6819,6 +6827,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 62eef7b71f..0f5881355d 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" @@ -2560,6 +2561,18 @@ log_line_prefix(StringInfo buf, ErrorData *edata) else appendStringInfo(buf, "%d", MyProcPid); break; + + case 'k': + if (MyBackendType != B_BG_WORKER) + ; /* Do nothing */ + else if (!MyProc->lockGroupLeader) + ; /* Do nothing */ + else if (padding != 0) + appendStringInfo(buf, "%*d", padding, MyProc->lockGroupLeader->pid); + else + appendStringInfo(buf, "%d", MyProc->lockGroupLeader->pid); + break; + case 'l': if (padding != 0) appendStringInfo(buf, "%*ld", padding, log_line_number); @@ -2948,6 +2961,13 @@ write_csvlog(ErrorData *edata) else appendCSVLiteral(&buf, GetBackendTypeDesc(MyBackendType)); + appendStringInfoChar(&buf, ','); + + /* leader PID */ + if (MyBackendType == B_BG_WORKER && + MyProc->lockGroupLeader) + appendStringInfo(&buf, "%d", MyProc->lockGroupLeader->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 aa44f0c9bf..6874792a15 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -530,6 +530,7 @@ # %h = remote host # %b = backend type # %p = process ID + # %k = leader PID # %t = timestamp without milliseconds # %m = timestamp with milliseconds # %n = timestamp with milliseconds (as a Unix epoch) -- 2.17.0 --ikeVEW9yuYc//A+q--