On Wed, Jun 11, 2014 at 11:55 PM, Tom Lane <t...@sss.pgh.pa.us> wrote: > Andres Freund <and...@2ndquadrant.com> writes: >> Your wish just seems like a separate feature to me. Including >> replication commands in 'all' seems correct independent of the desire >> for a more granular control. > > No, I think I've got to vote with the other side on that. > > The reason we can have log_statement as a scalar progression > "none < ddl < mod < all" is that there's little visible use-case > for logging DML but not DDL, nor for logging SELECTS but not > INSERT/UPDATE/DELETE. However, logging replication commands seems > like something people would reasonably want an orthogonal control for. > There's no nice way to squeeze such a behavior into log_statement. > > I guess you could say that log_statement treats replication commands > as if they were DDL, but is that really going to satisfy users? > > I think we should consider log_statement to control logging of > SQL only, and invent a separate GUC (or, in the future, likely > more than one GUC?) for logging of replication activity.
Seems reasonable. OK. The attached patch adds log_replication_command parameter which causes replication commands to be logged. I added this to next CF. Regards, -- Fujii Masao
From 9874e36a8f65667d1f4d3a9a8d1d87d2d20f5188 Mon Sep 17 00:00:00 2001 From: MasaoFujii <masao.fu...@gmail.com> Date: Thu, 12 Jun 2014 19:32:00 +0900 Subject: [PATCH] Add log_replication_command configuration parameter. This GUC causes replication commands like IDENTIFY_SYSTEM to be logged in the server log. --- doc/src/sgml/config.sgml | 16 ++++++++++++++++ src/backend/replication/walsender.c | 11 +++++++++-- src/backend/utils/misc/guc.c | 9 +++++++++ src/backend/utils/misc/postgresql.conf.sample | 1 + src/include/replication/walsender.h | 1 + 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 697cf99..8532f08 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -4534,6 +4534,22 @@ FROM pg_stat_activity; </listitem> </varlistentry> + <varlistentry id="guc-log-replication-command" xreflabel="log_replication_command"> + <term><varname>log_replication_command</varname> (<type>boolean</type>) + <indexterm> + <primary><varname>log_replication_command</> configuration parameter</primary> + </indexterm> + </term> + <listitem> + <para> + Causes each replication command to be logged in the server log. + See <xref linkend="protocol-replication"> for more information about + replication command. The default value is <literal>off</>. + Only superusers can change this setting. + </para> + </listitem> + </varlistentry> + <varlistentry id="guc-log-temp-files" xreflabel="log_temp_files"> <term><varname>log_temp_files</varname> (<type>integer</type>) <indexterm> diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 088ee2c..009ad92 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -108,6 +108,7 @@ bool am_db_walsender = false; /* Connected to a database? */ int max_wal_senders = 0; /* the maximum number of concurrent walsenders */ int wal_sender_timeout = 60 * 1000; /* maximum time to send one * WAL data message */ +bool log_replication_command = false; /* * State for WalSndWakeupRequest @@ -1261,13 +1262,19 @@ exec_replication_command(const char *cmd_string) MemoryContext old_context; /* + * Log replication command if log_replication_command is enabled. + * Even when it's disabled, log the command with DEBUG1 level for + * backward compatibility. + */ + ereport(log_replication_command ? LOG : DEBUG1, + (errmsg("received replication command: %s", cmd_string))); + + /* * CREATE_REPLICATION_SLOT ... LOGICAL exports a snapshot until the next * command arrives. Clean up the old stuff if there's anything. */ SnapBuildClearExportedSnapshot(); - elog(DEBUG1, "received replication command: %s", cmd_string); - CHECK_FOR_INTERRUPTS(); cmd_context = AllocSetContextCreate(CurrentMemoryContext, diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 1d094f0..427af79 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -931,6 +931,15 @@ static struct config_bool ConfigureNamesBool[] = NULL, NULL, NULL }, { + {"log_replication_command", PGC_SUSET, LOGGING_WHAT, + gettext_noop("Logs each replication command."), + NULL + }, + &log_replication_command, + false, + NULL, NULL, NULL + }, + { {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS, gettext_noop("Turns on various assertion checks."), gettext_noop("This is a debugging aid."), diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index d109394..70d86cf 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -431,6 +431,7 @@ # e.g. '<%u%%%d> ' #log_lock_waits = off # log lock waits >= deadlock_timeout #log_statement = 'none' # none, ddl, mod, all +#log_replication_command = off #log_temp_files = -1 # log temporary files equal or larger # than the specified size in kilobytes; # -1 disables, 0 logs all temp files diff --git a/src/include/replication/walsender.h b/src/include/replication/walsender.h index cff2be6..0095bde 100644 --- a/src/include/replication/walsender.h +++ b/src/include/replication/walsender.h @@ -25,6 +25,7 @@ extern bool wake_wal_senders; /* user-settable parameters */ extern int max_wal_senders; extern int wal_sender_timeout; +extern bool log_replication_command; extern void InitWalSender(void); extern void exec_replication_command(const char *query_string); -- 1.7.1
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers