diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 1e5c328d80..74110f0772 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -4672,6 +4672,22 @@ FROM pg_stat_activity;
+
+ log_replication_commands (boolean)
+
+ log_replication_commands> configuration parameter
+
+
+
+
+ Causes each replication command to be logged in the server log.
+ See for more information about
+ replication command. The default value is off>.
+ Only superusers can change this setting.
+
+
+
+
log_temp_files (integer)
diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml
index a8a09e4f0e..5f6ad6b5fb 100644
--- a/doc/src/sgml/protocol.sgml
+++ b/doc/src/sgml/protocol.sgml
@@ -1306,6 +1306,8 @@ To initiate streaming replication, the frontend sends the
of true> tells the backend to go into walsender mode, wherein a
small set of replication commands can be issued instead of SQL statements. Only
the simple query protocol can be used in walsender mode.
+Replication commands are logged in the server log when
+ is enabled.
Passing database> as the value instructs walsender to connect to
the database specified in the dbname> parameter, which will allow
the connection to be used for logical replication from that database.
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 844a5dea1d..384c9b61ce 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_commands = false;
/*
* State for WalSndWakeupRequest
@@ -1267,14 +1268,20 @@ exec_replication_command(const char *cmd_string)
MemoryContext cmd_context;
MemoryContext old_context;
+ /*
+ * Log replication command if log_replication_commands is enabled.
+ * Even when it's disabled, log the command with DEBUG1 level for
+ * backward compatibility.
+ */
+ ereport(log_replication_commands ? 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 af667f54ad..0192def17a 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -924,6 +924,15 @@ static struct config_bool ConfigureNamesBool[] =
false,
NULL, NULL, NULL
},
+ {
+ {"log_replication_commands", PGC_SUSET, LOGGING_WHAT,
+ gettext_noop("Logs each replication command."),
+ NULL
+ },
+ &log_replication_commands,
+ false,
+ NULL, NULL, NULL
+ },
{
{"debug_assertions", PGC_INTERNAL, PRESET_OPTIONS,
gettext_noop("Shows whether the running server has assertion checks enabled."),
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index df98b02d78..1b5f39fa6c 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_commands = 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 cff2be6d8f..d091e0f6d0 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_commands;
extern void InitWalSender(void);
extern void exec_replication_command(const char *query_string);