Skip to content

Commit b3fc672

Browse files
committed
Allow using connection URI in primary_conninfo.
The old method of appending options to the connection string didn't work if the primary_conninfo was a postgres:// style URI, instead of a traditional connection string. Use PQconnectdbParams instead. Alex Shulgin
1 parent add1b05 commit b3fc672

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,28 @@ _PG_init(void)
8989
static void
9090
libpqrcv_connect(char *conninfo)
9191
{
92-
char conninfo_repl[MAXCONNINFO + 75];
92+
const char *keys[5];
93+
const char *vals[5];
9394

9495
/*
95-
* Connect using deliberately undocumented parameter: replication. The
96-
* database name is ignored by the server in replication mode, but specify
97-
* "replication" for .pgpass lookup.
96+
* We use the expand_dbname parameter to process the connection string
97+
* (or URI), and pass some extra options. The deliberately undocumented
98+
* parameter "replication=true" makes it a replication connection.
99+
* The database name is ignored by the server in replication mode, but
100+
* specify "replication" for .pgpass lookup.
98101
*/
99-
snprintf(conninfo_repl, sizeof(conninfo_repl),
100-
"%s dbname=replication replication=true fallback_application_name=walreceiver",
101-
conninfo);
102-
103-
streamConn = PQconnectdb(conninfo_repl);
102+
keys[0] = "dbname";
103+
vals[0] = conninfo;
104+
keys[1] = "replication";
105+
vals[1] = "true";
106+
keys[2] = "dbname";
107+
vals[2] = "replication";
108+
keys[3] = "fallback_application_name";
109+
vals[3] = "walreceiver";
110+
keys[4] = NULL;
111+
vals[4] = NULL;
112+
113+
streamConn = PQconnectdbParams(keys, vals, /* expand_dbname = */ true);
104114
if (PQstatus(streamConn) != CONNECTION_OK)
105115
ereport(ERROR,
106116
(errmsg("could not connect to the primary server: %s",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy