diff options
author | Fujii Masao <fujii@postgresql.org> | 2014-09-13 02:55:45 +0900 |
---|---|---|
committer | Fujii Masao <fujii@postgresql.org> | 2014-09-13 02:55:45 +0900 |
commit | 4ad2a548050fdde07fed93e6c60a4d0a7eba0622 (patch) | |
tree | 6cb44928047a8209ddbb5e34b9f76edd2ea31353 /src/backend | |
parent | a2dabf0e1dda93c860b10bff7b73617e7b090108 (diff) | |
download | postgresql-4ad2a548050fdde07fed93e6c60a4d0a7eba0622.tar.gz postgresql-4ad2a548050fdde07fed93e6c60a4d0a7eba0622.zip |
Add GUC to enable logging of replication commands.
Previously replication commands like IDENTIFY_COMMAND were not logged
even when log_statements is set to all. Some users who want to audit
all types of statements were not satisfied with this situation. To
address the problem, this commit adds new GUC log_replication_commands.
If it's enabled, all replication commands are logged in the server log.
There are many ways to allow us to enable that logging. For example,
we can extend log_statement so that replication commands are logged
when it's set to all. But per discussion in the community, we reached
the consensus to add separate GUC for that.
Reviewed by Ian Barwick, Robert Haas and Heikki Linnakangas.
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/replication/walsender.c | 11 | ||||
-rw-r--r-- | src/backend/utils/misc/guc.c | 9 | ||||
-rw-r--r-- | src/backend/utils/misc/postgresql.conf.sample | 1 |
3 files changed, 19 insertions, 2 deletions
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 844a5dea1de..384c9b61ce1 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 @@ -1268,13 +1269,19 @@ exec_replication_command(const char *cmd_string) 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 af667f54ada..0192def17a5 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -925,6 +925,15 @@ static struct config_bool ConfigureNamesBool[] = 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."), NULL, diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index df98b02d788..1b5f39fa6c1 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 |