On Wed, Aug 20, 2014 at 1:14 PM, Michael Paquier
<michael.paqu...@gmail.com> wrote:
>
>
>
> On Wed, Aug 20, 2014 at 2:06 AM, Robert Haas <robertmh...@gmail.com> wrote:
>>
>> On Sat, Aug 16, 2014 at 10:27 AM, Amit Kapila <amit.kapil...@gmail.com>
>> wrote:
>> > I think ideally it would have been better if we could have logged
>> > replication commands under separate log_level, but as still there
>> > is no consensus on extending log_statement and nobody is even
>> > willing to pursue, it seems okay to go ahead and log these under
>> > 'all' level.
>>
>> I think the consensus is clearly for a separate GUC.
>
> +1.

Okay. Attached is the updated version of the patch which I posted before.
This patch follows the consensus and adds separate parameter
"log_replication_command".

Regards,

-- 
Fujii Masao
*** a/doc/src/sgml/config.sgml
--- b/doc/src/sgml/config.sgml
***************
*** 4558,4563 **** FROM pg_stat_activity;
--- 4558,4579 ----
        </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>
*** a/src/backend/replication/walsender.c
--- b/src/backend/replication/walsender.c
***************
*** 108,113 **** bool		am_db_walsender = false;	/* Connected to a database? */
--- 108,114 ----
  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
***************
*** 1268,1280 **** exec_replication_command(const char *cmd_string)
  	MemoryContext old_context;
  
  	/*
  	 * 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,
--- 1269,1287 ----
  	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();
  
  	CHECK_FOR_INTERRUPTS();
  
  	cmd_context = AllocSetContextCreate(CurrentMemoryContext,
*** a/src/backend/utils/misc/guc.c
--- b/src/backend/utils/misc/guc.c
***************
*** 925,930 **** static struct config_bool ConfigureNamesBool[] =
--- 925,939 ----
  		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_INTERNAL, PRESET_OPTIONS,
  			gettext_noop("Shows whether the running server has assertion checks enabled."),
  			NULL,
*** a/src/backend/utils/misc/postgresql.conf.sample
--- b/src/backend/utils/misc/postgresql.conf.sample
***************
*** 431,436 ****
--- 431,437 ----
  					# 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
*** a/src/include/replication/walsender.h
--- b/src/include/replication/walsender.h
***************
*** 25,30 **** extern bool wake_wal_senders;
--- 25,31 ----
  /* 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);
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to