Set fallback_application_name for a walreceiver to cluster_name
authorPeter Eisentraut
Fri, 8 Feb 2019 07:17:21 +0000 (08:17 +0100)
committerPeter Eisentraut
Wed, 27 Feb 2019 09:59:25 +0000 (10:59 +0100)
By default, the fallback_application_name for a physical walreceiver
is "walreceiver".  This means that multiple standbys cannot be
distinguished easily on a primary, for example in pg_stat_activity or
synchronous_standby_names.

If cluster_name is set, use that for fallback_application_name in the
walreceiver.  (If it's not set, it remains "walreceiver".)  If someone
set cluster_name to identify their instance, we might as well use that
by default to identify the node remotely as well.  It's still possible
to specify another application_name in primary_conninfo explicitly.

Reviewed-by: Euler Taveira
Discussion: https://www.postgresql.org/message-id/flat/1257eaee-4874-e791-e83a-46720c72cac7@2ndquadrant.com

doc/src/sgml/config.sgml
src/backend/replication/walreceiver.c

index 8bd57f376b25969ae1d4b3d8837bc8ef7aa284e4..1c3b7affa9f4c9f9170409f9bb53c43af24765b0 100644 (file)
@@ -3659,7 +3659,8 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"'  # Windows
         application_name setting of the standby, as set in the
         standby's connection information.  In case of a physical replication
         standby, this should be set in the primary_conninfo
-        setting; the default is walreceiver.
+        setting; the default is the setting of 
+        if set, else walreceiver.
         For logical replication, this can be set in the connection
         information of the subscription, and it defaults to the
         subscription name.  For other replication stream consumers,
@@ -6560,8 +6561,15 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
       
       
        
-        Sets the cluster name that appears in the process title for all
-        server processes in this cluster. The name can be any string of less
+        Sets a name that identifies this database cluster (instance) for
+        various purposes.  The cluster name appears in the process title for
+        all server processes in this cluster.  Moreover, it is the default
+        application name for a standby connection (see 
+        linkend="guc-synchronous-standby-names"/>.)
+       
+
+       
+        The name can be any string of less
         than NAMEDATALEN characters (64 characters in a standard
         build). Only printable ASCII characters may be used in the
         cluster_name value. Other characters will be
index 2e90944ad524fe77128b1f0b65807a0d6c0824ad..9eaaa8ff5057efbfdc2a2eaf85fa4febac2e4aff 100644 (file)
@@ -293,7 +293,7 @@ WalReceiverMain(void)
 
    /* Establish the connection to the primary for XLOG streaming */
    EnableWalRcvImmediateExit();
-   wrconn = walrcv_connect(conninfo, false, "walreceiver", &err);
+   wrconn = walrcv_connect(conninfo, false, cluster_name[0] ? cluster_name : "walreceiver", &err);
    if (!wrconn)
        ereport(ERROR,
                (errmsg("could not connect to the primary server: %s", err)));