From e751b71b56f1ba6fa3bb277059f9d5a8ea7b84af Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Fri, 11 Jun 2010 10:13:09 +0000 Subject: 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. --- .../replication/libpqwalreceiver/libpqwalreceiver.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c index 1807fde9e4b..b62f48be825 100644 --- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c +++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c @@ -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) -- cgit v1.2.3