diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 371d7838fb6..3cac340f323 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -6438,9 +6438,13 @@ local0.* /var/log/postgresql
right with spaces to give it a minimum width, whereas a positive
value will pad on the left. Padding can be useful to aid human
readability in log files.
+
+
+
This parameter can only be set in the postgresql.conf
file or on the server command line. The default is
'%m [%p] ' which logs a time stamp and the process ID.
+
@@ -6477,6 +6481,11 @@ local0.* /var/log/postgresql
Remote host name or IP address
yes
+
+ %b
+ Backend type
+ no
+
%p
Process ID
@@ -6548,6 +6557,14 @@ local0.* /var/log/postgresql
+
+ The backend type corresponds to the column
+ backend_type in the view , but additional types can appear
+ in the log that don't show in that view.
+
+
+
The %c escape prints a quasi-unique session identifier,
consisting of two 4-byte hexadecimal numbers (without leading zeros)
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 '
character count of the error position therein,
location of the error in the PostgreSQL source code
(if log_error_verbosity is set to verbose),
- and application name.
+ application name, and backend type.
Here is a sample table definition for storing CSV-format log output:
@@ -6801,6 +6818,7 @@ CREATE TABLE postgres_log
query_pos integer,
location text,
application_name text,
+ backend_type text,
PRIMARY KEY (session_id, session_line_num)
);
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index f8ae94729cc..62eef7b71f4 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -72,6 +72,7 @@
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
+#include "postmaster/bgworker.h"
#include "postmaster/postmaster.h"
#include "postmaster/syslogger.h"
#include "storage/ipc.h"
@@ -2492,6 +2493,23 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
padding > 0 ? padding : -padding);
break;
+ case 'b':
+ {
+ const char *backend_type_str;
+
+ if (MyProcPid == PostmasterPid)
+ backend_type_str = "postmaster";
+ else if (MyBackendType == B_BG_WORKER)
+ backend_type_str = MyBgworkerEntry->bgw_type;
+ else
+ backend_type_str = GetBackendTypeDesc(MyBackendType);
+
+ if (padding != 0)
+ appendStringInfo(buf, "%*s", padding, backend_type_str);
+ else
+ appendStringInfoString(buf, backend_type_str);
+ break;
+ }
case 'u':
if (MyProcPort)
{
@@ -2920,6 +2938,16 @@ write_csvlog(ErrorData *edata)
if (application_name)
appendCSVLiteral(&buf, application_name);
+ appendStringInfoChar(&buf, ',');
+
+ /* backend type */
+ if (MyProcPid == PostmasterPid)
+ appendCSVLiteral(&buf, "postmaster");
+ else if (MyBackendType == B_BG_WORKER)
+ appendCSVLiteral(&buf, MyBgworkerEntry->bgw_type);
+ else
+ appendCSVLiteral(&buf, GetBackendTypeDesc(MyBackendType));
+
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 e58e4788a8e..aa44f0c9bf2 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -528,6 +528,7 @@
# %d = database name
# %r = remote host and port
# %h = remote host
+ # %b = backend type
# %p = process ID
# %t = timestamp without milliseconds
# %m = timestamp with milliseconds
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index a53e4a6243b..f6a5e1b9c76 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -2334,7 +2334,7 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
fputs("\n# Configuration added by pg_regress\n\n", pg_conf);
fputs("log_autovacuum_min_duration = 0\n", pg_conf);
fputs("log_checkpoints = on\n", pg_conf);
- fputs("log_line_prefix = '%m [%p] %q%a '\n", pg_conf);
+ fputs("log_line_prefix = '%m %b[%p] %q%a '\n", pg_conf);
fputs("log_lock_waits = on\n", pg_conf);
fputs("log_temp_files = 128kB\n", pg_conf);
fputs("max_prepared_transactions = 2\n", pg_conf);