Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b8fdee7

Browse filesBrowse files
committed
Add %P to log_line_prefix for parallel group leader
This is useful for monitoring purposes with log parsing. Similarly to pg_stat_activity, the leader's PID is shown only for active parallel workers, minimizing the log footprint for the leaders as the equivalent shared memory field is set as long as a backend is alive. Author: Justin Pryzby Reviewed-by: Álvaro Herrera, Michael Paquier, Julien Rouhaud, Tom Lane Discussion: https://postgr.es/m/20200315111831.GA21492@telsasoft.com
1 parent f44b9b6 commit b8fdee7
Copy full SHA for b8fdee7

File tree

Expand file treeCollapse file tree

3 files changed

+47
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+47
-1
lines changed

‎doc/src/sgml/config.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/config.sgml
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6694,6 +6694,12 @@ local0.* /var/log/postgresql
66946694
<entry>Process ID</entry>
66956695
<entry>no</entry>
66966696
</row>
6697+
<row>
6698+
<entry><literal>%P</literal></entry>
6699+
<entry>Process ID of the parallel group leader, if this process
6700+
is a parallel query worker</entry>
6701+
<entry>no</entry>
6702+
</row>
66976703
<row>
66986704
<entry><literal>%t</literal></entry>
66996705
<entry>Time stamp without milliseconds</entry>
@@ -7026,7 +7032,7 @@ log_line_prefix = '%m [%p] %q%u@%d/%a '
70267032
character count of the error position therein,
70277033
location of the error in the PostgreSQL source code
70287034
(if <varname>log_error_verbosity</varname> is set to <literal>verbose</literal>),
7029-
application name, and backend type.
7035+
application name, backend type, and process ID of parallel group leader.
70307036
Here is a sample table definition for storing CSV-format log output:
70317037

70327038
<programlisting>
@@ -7056,6 +7062,7 @@ CREATE TABLE postgres_log
70567062
location text,
70577063
application_name text,
70587064
backend_type text,
7065+
leader_pid integer,
70597066
PRIMARY KEY (session_id, session_line_num)
70607067
);
70617068
</programlisting>

‎src/backend/utils/error/elog.c

Copy file name to clipboardExpand all lines: src/backend/utils/error/elog.c
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,6 +2448,29 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
24482448
else
24492449
appendStringInfo(buf, "%d", MyProcPid);
24502450
break;
2451+
2452+
case 'P':
2453+
if (MyProc)
2454+
{
2455+
PGPROC *leader = MyProc->lockGroupLeader;
2456+
2457+
/*
2458+
* Show the leader only for active parallel workers. This
2459+
* leaves out the leader of a parallel group.
2460+
*/
2461+
if (leader == NULL || leader->pid == MyProcPid)
2462+
appendStringInfoSpaces(buf,
2463+
padding > 0 ? padding : -padding);
2464+
else if (padding != 0)
2465+
appendStringInfo(buf, "%*d", padding, leader->pid);
2466+
else
2467+
appendStringInfo(buf, "%d", leader->pid);
2468+
}
2469+
else if (padding != 0)
2470+
appendStringInfoSpaces(buf,
2471+
padding > 0 ? padding : -padding);
2472+
break;
2473+
24512474
case 'l':
24522475
if (padding != 0)
24532476
appendStringInfo(buf, "%*ld", padding, log_line_number);
@@ -2836,6 +2859,21 @@ write_csvlog(ErrorData *edata)
28362859
else
28372860
appendCSVLiteral(&buf, GetBackendTypeDesc(MyBackendType));
28382861

2862+
appendStringInfoChar(&buf, ',');
2863+
2864+
/* leader PID */
2865+
if (MyProc)
2866+
{
2867+
PGPROC *leader = MyProc->lockGroupLeader;
2868+
2869+
/*
2870+
* Show the leader only for active parallel workers. This leaves out
2871+
* the leader of a parallel group.
2872+
*/
2873+
if (leader && leader->pid != MyProcPid)
2874+
appendStringInfo(&buf, "%d", leader->pid);
2875+
}
2876+
28392877
appendStringInfoChar(&buf, '\n');
28402878

28412879
/* If in the syslogger process, try to write messages direct to file */

‎src/backend/utils/misc/postgresql.conf.sample

Copy file name to clipboardExpand all lines: src/backend/utils/misc/postgresql.conf.sample
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@
537537
# %h = remote host
538538
# %b = backend type
539539
# %p = process ID
540+
# %P = process ID of parallel group leader
540541
# %t = timestamp without milliseconds
541542
# %m = timestamp with milliseconds
542543
# %n = timestamp with milliseconds (as a Unix epoch)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.