Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cca97ce

Browse filesBrowse files
Allow dbname in pg_basebackup/pg_receivewal connstring
As physical replication work at the cluster level and not database level, any dbname in the connection string is ignored. Proxies and middleware used in connecting to the cluster might however need to know the dbname in order to make the correct routing decision for the connection. With this the startup packet will include the dbname parameter. Author: Jelte Fennema-Nio <me@jeltef.nl> Reviewed-by: Tristen Raab <tristen.raab@highgo.ca> Reviewed-by: Jim Jones <jim.jones@uni-muenster.de> Discussion: https://postgr.es/m/CAGECzQTw-dZkVT_RELRzfWRzY714-VaTjoBATYfZq93R8C-auA@mail.gmail.com
1 parent c621467 commit cca97ce
Copy full SHA for cca97ce

File tree

Expand file treeCollapse file tree

3 files changed

+27
-14
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+27
-14
lines changed

‎doc/src/sgml/ref/pg_basebackup.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/ref/pg_basebackup.sgml
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,10 @@ PostgreSQL documentation
778778
The option is called <literal>--dbname</literal> for consistency with other
779779
client applications, but because <application>pg_basebackup</application>
780780
doesn't connect to any particular database in the cluster, any database
781-
name in the connection string will be ignored.
781+
name in the connection string will be ignored
782+
by <productname>PostgreSQL</productname>. Middleware, or proxies, used in
783+
connecting to <productname>PostgreSQL</productname> might however
784+
utilize the value.
782785
</para>
783786
</listitem>
784787
</varlistentry>

‎doc/src/sgml/ref/pg_receivewal.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/ref/pg_receivewal.sgml
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,11 @@ PostgreSQL documentation
316316
<para>
317317
The option is called <literal>--dbname</literal> for consistency with other
318318
client applications, but because <application>pg_receivewal</application>
319-
doesn't connect to any particular database in the cluster, database
320-
name in the connection string will be ignored.
319+
doesn't connect to any particular database in the cluster, any database
320+
name in the connection string will be ignored by
321+
<productname>PostgreSQL</productname>. Middleware, or proxies, used in
322+
connecting to <productname>PostgreSQL</productname> might however
323+
utilize the value.
321324
</para>
322325
</listitem>
323326
</varlistentry>

‎src/bin/pg_basebackup/streamutil.c

Copy file name to clipboardExpand all lines: src/bin/pg_basebackup/streamutil.c
+18-11Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ GetConnection(void)
7979
/*
8080
* Merge the connection info inputs given in form of connection string,
8181
* options and default values (dbname=replication, replication=true, etc.)
82-
* Explicitly discard any dbname value in the connection string;
83-
* otherwise, PQconnectdbParams() would interpret that value as being
84-
* itself a connection string.
8582
*/
8683
i = 0;
8784
if (connection_string)
@@ -92,18 +89,24 @@ GetConnection(void)
9289

9390
for (conn_opt = conn_opts; conn_opt->keyword != NULL; conn_opt++)
9491
{
95-
if (conn_opt->val != NULL && conn_opt->val[0] != '\0' &&
96-
strcmp(conn_opt->keyword, "dbname") != 0)
92+
if (conn_opt->val != NULL && conn_opt->val[0] != '\0')
9793
argcount++;
9894
}
9995

10096
keywords = pg_malloc0((argcount + 1) * sizeof(*keywords));
10197
values = pg_malloc0((argcount + 1) * sizeof(*values));
10298

99+
/*
100+
* Set dbname here already, so it can be overridden by a dbname in the
101+
* connection string.
102+
*/
103+
keywords[i] = "dbname";
104+
values[i] = "replication";
105+
i++;
106+
103107
for (conn_opt = conn_opts; conn_opt->keyword != NULL; conn_opt++)
104108
{
105-
if (conn_opt->val != NULL && conn_opt->val[0] != '\0' &&
106-
strcmp(conn_opt->keyword, "dbname") != 0)
109+
if (conn_opt->val != NULL && conn_opt->val[0] != '\0')
107110
{
108111
keywords[i] = conn_opt->keyword;
109112
values[i] = conn_opt->val;
@@ -115,11 +118,11 @@ GetConnection(void)
115118
{
116119
keywords = pg_malloc0((argcount + 1) * sizeof(*keywords));
117120
values = pg_malloc0((argcount + 1) * sizeof(*values));
121+
keywords[i] = "dbname";
122+
values[i] = dbname;
123+
i++;
118124
}
119125

120-
keywords[i] = "dbname";
121-
values[i] = dbname == NULL ? "replication" : dbname;
122-
i++;
123126
keywords[i] = "replication";
124127
values[i] = dbname == NULL ? "true" : "database";
125128
i++;
@@ -171,7 +174,11 @@ GetConnection(void)
171174
values[i] = NULL;
172175
}
173176

174-
tmpconn = PQconnectdbParams(keywords, values, true);
177+
/*
178+
* Only expand dbname when we did not already parse the argument as a
179+
* connection string ourselves.
180+
*/
181+
tmpconn = PQconnectdbParams(keywords, values, !connection_string);
175182

176183
/*
177184
* If there is too little memory even to allocate the PGconn object

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.