Use "replication" as the database name when constructing a connection
authorHeikki Linnakangas
Fri, 11 Jun 2010 10:13:09 +0000 (10:13 +0000)
committerHeikki Linnakangas
Fri, 11 Jun 2010 10:13:09 +0000 (10:13 +0000)
string for a streaming replication connection. It's ignored by the
server, but allows libpq to pick up the password from .pgpass where
"replication" is specified as the database name.

Patch by Fujii Masao per Tom's suggestion, with some wording changes by me.

doc/src/sgml/high-availability.sgml
doc/src/sgml/libpq.sgml
doc/src/sgml/recovery-config.sgml
src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

index cc11ce69bd2703b9cb7b7582c44f55aba668744e..2ac79245d028c778aad82248d1c2ad3c3afcb2ec 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
 
  High Availability, Load Balancing, and Replication
@@ -818,8 +818,10 @@ host    replication     foo             192.168.1.100/32        md5
     
     
      The host name and port number of the primary, connection user name,
-     and password are specified in the recovery.conf file or
-     the corresponding environment variable on the standby.
+     and password are specified in the recovery.conf file.
+     The password can also be set in the ~/.pgpass file on the
+     standby (specify replication in the database
+     field).
      For example, if the primary is running on host IP 192.168.1.50,
      port 5432, the superuser's name for replication is
      foo, and the password is foopass, the administrator
index 57357b18bb2741ab3a9fb20564faf5753fe32397..646cb16cdd1609b09cd71bdc77d3c56b50185978 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
 
  <application>libpq</application> - C Library
@@ -6233,7 +6233,8 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
    A host name of localhost matches both TCP (host name
    localhost) and Unix domain socket (pghost empty
    or the default socket directory) connections coming from the local
-   machine.
+   machine. In a standby server, a database name of replication
+   matches streaming replication connections made to the master server.
   
 
   
index 5bea0f37d6ae7548eaf78a4ed5ae38ecd75eb54f..d555960b805ee024bd772e037cbae1375eff3b67 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
 
   Recovery Configuration
@@ -268,9 +268,10 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"'  # Windows
           primary (see
           ).
           A password needs to be provided too, if the primary demands password
-          authentication.  (The password can be provided either in
-          the primary_conninfo string or in a separate
-          ~/.pgpass file on the standby server.)
+          authentication.  It can be provided in the
+          primary_conninfo string, or in a separate
+          ~/.pgpass file on the standby server (use
+          replication as the database name).
           Do not specify a database name in the
           primary_conninfo string.
          
index 1807fde9e4b1de7698749b70b41d6bd938aa834b..b62f48be8254ec775ecb199e15e88bd94a5865a6 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c,v 1.10 2010/04/21 03:32:53 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c,v 1.11 2010/06/11 10:13:09 heikki Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -77,7 +77,7 @@ _PG_init(void)
 static bool
 libpqrcv_connect(char *conninfo, XLogRecPtr startpoint)
 {
-   char        conninfo_repl[MAXCONNINFO + 18];
+   char        conninfo_repl[MAXCONNINFO + 37];
    char       *primary_sysid;
    char        standby_sysid[32];
    TimeLineID  primary_tli;
@@ -85,8 +85,14 @@ libpqrcv_connect(char *conninfo, XLogRecPtr startpoint)
    PGresult   *res;
    char        cmd[64];
 
-   /* Connect using deliberately undocumented parameter: replication */
-   snprintf(conninfo_repl, sizeof(conninfo_repl), "%s replication=true", conninfo);
+   /*
+    * Connect using deliberately undocumented parameter: replication.
+    * The database name is ignored by the server in replication mode, but
+    * specify "replication" for .pgpass lookup.
+    */
+   snprintf(conninfo_repl, sizeof(conninfo_repl),
+            "%s dbname=replication replication=true",
+            conninfo);
 
    streamConn = PQconnectdb(conninfo_repl);
    if (PQstatus(streamConn) != CONNECTION_OK)