Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit70a7b47

Browse files
committed
Add backend type to csvlog and optionally log_line_prefix
The backend type, which corresponds to whatpg_stat_activity.backend_type shows, is added as a column to thecsvlog and can optionally be added to log_line_prefix using the new %bplaceholder.Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>Reviewed-by: Kuntal Ghosh <kuntalghosh.2007@gmail.com>Reviewed-by: Alvaro Herrera <alvherre@2ndquadrant.com>Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>Discussion:https://www.postgresql.org/message-id/flat/c65e5196-4f04-4ead-9353-6088c19615a3@2ndquadrant.com
1 parentd8cfa82 commit70a7b47

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6438,9 +6438,13 @@ local0.* /var/log/postgresql
64386438
right with spaces to give it a minimum width, whereas a positive
64396439
value will pad on the left. Padding can be useful to aid human
64406440
readability in log files.
6441+
</para>
6442+
6443+
<para>
64416444
This parameter can only be set in the <filename>postgresql.conf</filename>
64426445
file or on the server command line. The default is
64436446
<literal>'%m [%p] '</literal> which logs a time stamp and the process ID.
6447+
</para>
64446448

64456449
<informaltable>
64466450
<tgroup cols="3">
@@ -6477,6 +6481,11 @@ local0.* /var/log/postgresql
64776481
<entry>Remote host name or IP address</entry>
64786482
<entry>yes</entry>
64796483
</row>
6484+
<row>
6485+
<entry><literal>%b</literal></entry>
6486+
<entry>Backend type</entry>
6487+
<entry>no</entry>
6488+
</row>
64806489
<row>
64816490
<entry><literal>%p</literal></entry>
64826491
<entry>Process ID</entry>
@@ -6548,6 +6557,14 @@ local0.* /var/log/postgresql
65486557
</tgroup>
65496558
</informaltable>
65506559

6560+
<para>
6561+
The backend type corresponds to the column
6562+
<structfield>backend_type</structfield> in the view <xref
6563+
linkend="pg-stat-activity-view"/>, but additional types can appear
6564+
in the log that don't show in that view.
6565+
</para>
6566+
6567+
<para>
65516568
The <literal>%c</literal> escape prints a quasi-unique session identifier,
65526569
consisting of two 4-byte hexadecimal numbers (without leading zeros)
65536570
separated by a dot. The numbers are the process start time and the
@@ -6772,7 +6789,7 @@ log_line_prefix = '%m [%p] %q%u@%d/%a '
67726789
character count of the error position therein,
67736790
location of the error in the PostgreSQL source code
67746791
(if <varname>log_error_verbosity</varname> is set to <literal>verbose</literal>),
6775-
andapplication name.
6792+
application name, and backend type.
67766793
Here is a sample table definition for storing CSV-format log output:
67776794

67786795
<programlisting>
@@ -6801,6 +6818,7 @@ CREATE TABLE postgres_log
68016818
query_pos integer,
68026819
location text,
68036820
application_name text,
6821+
backend_type text,
68046822
PRIMARY KEY (session_id, session_line_num)
68056823
);
68066824
</programlisting>

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#include"libpq/pqformat.h"
7373
#include"mb/pg_wchar.h"
7474
#include"miscadmin.h"
75+
#include"postmaster/bgworker.h"
7576
#include"postmaster/postmaster.h"
7677
#include"postmaster/syslogger.h"
7778
#include"storage/ipc.h"
@@ -2492,6 +2493,23 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
24922493
padding>0 ?padding :-padding);
24932494

24942495
break;
2496+
case'b':
2497+
{
2498+
constchar*backend_type_str;
2499+
2500+
if (MyProcPid==PostmasterPid)
2501+
backend_type_str="postmaster";
2502+
elseif (MyBackendType==B_BG_WORKER)
2503+
backend_type_str=MyBgworkerEntry->bgw_type;
2504+
else
2505+
backend_type_str=GetBackendTypeDesc(MyBackendType);
2506+
2507+
if (padding!=0)
2508+
appendStringInfo(buf,"%*s",padding,backend_type_str);
2509+
else
2510+
appendStringInfoString(buf,backend_type_str);
2511+
break;
2512+
}
24952513
case'u':
24962514
if (MyProcPort)
24972515
{
@@ -2920,6 +2938,16 @@ write_csvlog(ErrorData *edata)
29202938
if (application_name)
29212939
appendCSVLiteral(&buf,application_name);
29222940

2941+
appendStringInfoChar(&buf,',');
2942+
2943+
/* backend type */
2944+
if (MyProcPid==PostmasterPid)
2945+
appendCSVLiteral(&buf,"postmaster");
2946+
elseif (MyBackendType==B_BG_WORKER)
2947+
appendCSVLiteral(&buf,MyBgworkerEntry->bgw_type);
2948+
else
2949+
appendCSVLiteral(&buf,GetBackendTypeDesc(MyBackendType));
2950+
29232951
appendStringInfoChar(&buf,'\n');
29242952

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@
528528
# %d = database name
529529
# %r = remote host and port
530530
# %h = remote host
531+
# %b = backend type
531532
# %p = process ID
532533
# %t = timestamp without milliseconds
533534
# %m = timestamp with milliseconds

‎src/test/regress/pg_regress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2334,7 +2334,7 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
23342334
fputs("\n# Configuration added by pg_regress\n\n",pg_conf);
23352335
fputs("log_autovacuum_min_duration = 0\n",pg_conf);
23362336
fputs("log_checkpoints = on\n",pg_conf);
2337-
fputs("log_line_prefix = '%m [%p] %q%a '\n",pg_conf);
2337+
fputs("log_line_prefix = '%m%b[%p] %q%a '\n",pg_conf);
23382338
fputs("log_lock_waits = on\n",pg_conf);
23392339
fputs("log_temp_files = 128kB\n",pg_conf);
23402340
fputs("max_prepared_transactions = 2\n",pg_conf);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp