log_replication_connections.patch
text/x-patch
Filename: log_replication_connections.patch
Type: text/x-patch
Part: 0
Message:
Re: Replication logging
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| doc/src/sgml/config.sgml | 15 | 0 |
| src/backend/postmaster/postmaster.c | 1 | 0 |
| src/backend/tcop/postgres.c | 1 | 0 |
| src/backend/utils/init/postinit.c | 16 | 13 |
| src/backend/utils/misc/guc.c | 8 | 0 |
| src/backend/utils/misc/postgresql.conf.sample | 1 | 0 |
| src/include/postmaster/postmaster.h | 1 | 0 |
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 8e2a2c5..5f83adf 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -3380,6 +3380,21 @@ local0.* /var/log/postgresql
</listitem>
</varlistentry>
+ <varlistentry id="guc-log-replication-connections" xreflabel="log_replication_connections">
+ <term><varname>log_replication_connections</varname> (<type>boolean</type>)</term>
+ <indexterm>
+ <primary><varname>log_replication_connections</> configuration parameter</primary>
+ </indexterm>
+ <listitem>
+ <para>
+ Causes each successful replication connection to the server to be
+ logged. This parameter can only be set in the
+ <filename>postgresql.conf</> file or on the server command line.
+ The default is on.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="guc-log-disconnections" xreflabel="log_disconnections">
<term><varname>log_disconnections</varname> (<type>boolean</type>)</term>
<indexterm>
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 179048f..a128e21 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -199,6 +199,7 @@ int AuthenticationTimeout = 60;
bool log_hostname; /* for ps display and logging */
bool Log_connections = false;
+bool Log_replication_connections = false;
bool Db_user_namespace = false;
bool enable_bonjour = false;
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index b227e6c..3c941b1 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -3137,6 +3137,7 @@ set_debug_options(int debug_flag, GucContext context, GucSource source)
if (debug_flag >= 1 && context == PGC_POSTMASTER)
{
SetConfigOption("log_connections", "true", context, source);
+ SetConfigOption("log_replication_connections", "true", context, source);
SetConfigOption("log_disconnections", "true", context, source);
}
if (debug_flag >= 2)
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index 76890f2..d09633e 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -219,22 +219,25 @@ PerformAuthentication(Port *port)
elog(FATAL, "could not disable timer for authorization timeout");
/*
- * Log connection for streaming replication even if Log_connections
- * disabled.
+ * Log connection for streaming replication if Log_replication_connections
+ * is enabled.
*/
if (am_walsender)
{
- if (port->remote_port[0])
- ereport(LOG,
- (errmsg("replication connection authorized: user=%s host=%s port=%s",
- port->user_name,
- port->remote_host,
- port->remote_port)));
- else
- ereport(LOG,
- (errmsg("replication connection authorized: user=%s host=%s",
- port->user_name,
- port->remote_host)));
+ if (Log_replication_connections)
+ {
+ if (port->remote_port[0])
+ ereport(LOG,
+ (errmsg("replication connection authorized: user=%s host=%s port=%s",
+ port->user_name,
+ port->remote_host,
+ port->remote_port)));
+ else
+ ereport(LOG,
+ (errmsg("replication connection authorized: user=%s host=%s",
+ port->user_name,
+ port->remote_host)));
+ }
}
else if (Log_connections)
ereport(LOG,
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index e4dea31..94c58a4 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -803,6 +803,14 @@ static struct config_bool ConfigureNamesBool[] =
false, NULL, NULL
},
{
+ {"log_replication_connections", PGC_BACKEND, LOGGING_WHAT,
+ gettext_noop("Logs each successful replication connection."),
+ NULL
+ },
+ &Log_replication_connections,
+ true, NULL, NULL
+ },
+ {
{"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
gettext_noop("Logs end of a session, including duration."),
NULL
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index f436b83..d9c8b97 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -353,6 +353,7 @@
#debug_pretty_print = on
#log_checkpoints = off
#log_connections = off
+#log_replication_connections = on
#log_disconnections = off
#log_duration = off
#log_error_verbosity = default # terse, default, or verbose messages
diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h
index 25cc84a..e2f5ba3 100644
--- a/src/include/postmaster/postmaster.h
+++ b/src/include/postmaster/postmaster.h
@@ -26,6 +26,7 @@ extern bool ClientAuthInProgress;
extern int PreAuthDelay;
extern int AuthenticationTimeout;
extern bool Log_connections;
+extern bool Log_replication_connections;
extern bool log_hostname;
extern bool enable_bonjour;
extern char *bonjour_name;