mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Add backend type to csvlog and optionally log_line_prefix
The backend type, which corresponds to what pg_stat_activity.backend_type shows, is added as a column to the csvlog and can optionally be added to log_line_prefix using the new %b placeholder. 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
This commit is contained in:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user