Commit e751b71b authored by Heikki Linnakangas's avatar Heikki Linnakangas

Use "replication" as the database name when constructing a connection

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.
parent c46f861c
<!-- $PostgreSQL: pgsql/doc/src/sgml/high-availability.sgml,v 1.72 2010/06/10 08:13:49 itagaki Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/high-availability.sgml,v 1.73 2010/06/11 10:13:08 heikki Exp $ -->
<chapter id="high-availability"> <chapter id="high-availability">
<title>High Availability, Load Balancing, and Replication</title> <title>High Availability, Load Balancing, and Replication</title>
...@@ -818,8 +818,10 @@ host replication foo 192.168.1.100/32 md5 ...@@ -818,8 +818,10 @@ host replication foo 192.168.1.100/32 md5
</para> </para>
<para> <para>
The host name and port number of the primary, connection user name, The host name and port number of the primary, connection user name,
and password are specified in the <filename>recovery.conf</> file or and password are specified in the <filename>recovery.conf</> file.
the corresponding environment variable on the standby. The password can also be set in the <filename>~/.pgpass</> file on the
standby (specify <literal>replication</> in the <replaceable>database</>
field).
For example, if the primary is running on host IP <literal>192.168.1.50</>, For example, if the primary is running on host IP <literal>192.168.1.50</>,
port <literal>5432</literal>, the superuser's name for replication is port <literal>5432</literal>, the superuser's name for replication is
<literal>foo</>, and the password is <literal>foopass</>, the administrator <literal>foo</>, and the password is <literal>foopass</>, the administrator
......
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.306 2010/05/26 23:49:18 tgl Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.307 2010/06/11 10:13:08 heikki Exp $ -->
<chapter id="libpq"> <chapter id="libpq">
<title><application>libpq</application> - C Library</title> <title><application>libpq</application> - C Library</title>
...@@ -6233,7 +6233,8 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough) ...@@ -6233,7 +6233,8 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
A host name of <literal>localhost</> matches both TCP (host name A host name of <literal>localhost</> matches both TCP (host name
<literal>localhost</>) and Unix domain socket (<literal>pghost</> empty <literal>localhost</>) and Unix domain socket (<literal>pghost</> empty
or the default socket directory) connections coming from the local or the default socket directory) connections coming from the local
machine. machine. In a standby server, a database name of <literal>replication</>
matches streaming replication connections made to the master server.
</para> </para>
<para> <para>
......
<!-- $PostgreSQL: pgsql/doc/src/sgml/recovery-config.sgml,v 2.7 2010/06/10 08:13:49 itagaki Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/recovery-config.sgml,v 2.8 2010/06/11 10:13:09 heikki Exp $ -->
<chapter Id="recovery-config"> <chapter Id="recovery-config">
<title>Recovery Configuration</title> <title>Recovery Configuration</title>
...@@ -268,9 +268,10 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows ...@@ -268,9 +268,10 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
primary (see primary (see
<xref linkend="streaming-replication-authentication">). <xref linkend="streaming-replication-authentication">).
A password needs to be provided too, if the primary demands password A password needs to be provided too, if the primary demands password
authentication. (The password can be provided either in authentication. It can be provided in the
the <varname>primary_conninfo</varname> string or in a separate <varname>primary_conninfo</varname> string, or in a separate
<filename>~/.pgpass</> file on the standby server.) <filename>~/.pgpass</> file on the standby server (use
<literal>replication</> as the database name).
Do not specify a database name in the Do not specify a database name in the
<varname>primary_conninfo</varname> string. <varname>primary_conninfo</varname> string.
</para> </para>
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -77,7 +77,7 @@ _PG_init(void)
static bool static bool
libpqrcv_connect(char *conninfo, XLogRecPtr startpoint) libpqrcv_connect(char *conninfo, XLogRecPtr startpoint)
{ {
char conninfo_repl[MAXCONNINFO + 18]; char conninfo_repl[MAXCONNINFO + 37];
char *primary_sysid; char *primary_sysid;
char standby_sysid[32]; char standby_sysid[32];
TimeLineID primary_tli; TimeLineID primary_tli;
...@@ -85,8 +85,14 @@ libpqrcv_connect(char *conninfo, XLogRecPtr startpoint) ...@@ -85,8 +85,14 @@ libpqrcv_connect(char *conninfo, XLogRecPtr startpoint)
PGresult *res; PGresult *res;
char cmd[64]; 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); streamConn = PQconnectdb(conninfo_repl);
if (PQstatus(streamConn) != CONNECTION_OK) if (PQstatus(streamConn) != CONNECTION_OK)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment