Skip to content

Commit 5453fcf

Browse files
MasaoFujiiCommitfest Bot
authored andcommitted
Honor GUC settings specified in CREATE SUBSCRIPTION CONNECTION.
Prior to v15, GUC settings supplied in the CONNECTION clause of CREATE SUBSCRIPTION were correctly passed through to the publisher's walsender. For example: CREATE SUBSCRIPTION mysub CONNECTION 'options=''-c wal_sender_timeout=1000''' PUBLICATION ... would cause wal_sender_timeout to take effect on the publisher's walsender. However, commit f3d4019 changed the way logical replication connections are established, forcing the publisher's relevant GUC settings (datestyle, intervalstyle, extra_float_digits) to override those provided in the CONNECTION string. As a result, from v15 through v18, GUC settings in the CONNECTION string were always ignored. This regression prevented per-connection tuning of logical replication. For example, using a shorter timeout for walsender connecting to a nearby subscriber and a longer one for walsender connecting to a remote subscriber. This commit restores the intended behavior by ensuring that GUC settings in the CONNECTION string are again passed through and applied by the walsender, allowing per-connection configuration. Backpatch to v15, where the regression was introduced. Author: Fujii Masao <masao.fujii@gmail.com> Reviewed-by: Chao Li <lic@highgo.com> Discussion: https://postgr.es/m/CAHGQGwGYV+-abbKwdrM2UHUe-JYOFWmsrs6=QicyJO-j+-Widw@mail.gmail.com Backpatch-through: 15
1 parent 795e94c commit 5453fcf

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,6 @@ libpqrcv_connect(const char *conninfo, bool replication, bool logical,
180180
/* Tell the publisher to translate to our encoding */
181181
keys[++i] = "client_encoding";
182182
vals[i] = GetDatabaseEncodingName();
183-
184-
/*
185-
* Force assorted GUC parameters to settings that ensure that the
186-
* publisher will output data values in a form that is unambiguous
187-
* to the subscriber. (We don't want to modify the subscriber's
188-
* GUC settings, since that might surprise user-defined code
189-
* running in the subscriber, such as triggers.) This should
190-
* match what pg_dump does.
191-
*/
192-
keys[++i] = "options";
193-
vals[i] = "-c datestyle=ISO -c intervalstyle=postgres -c extra_float_digits=3";
194183
}
195184
else
196185
{
@@ -256,6 +245,38 @@ libpqrcv_connect(const char *conninfo, bool replication, bool logical,
256245
PQclear(res);
257246
}
258247

248+
/*
249+
* Force assorted GUC parameters to settings that ensure that the
250+
* publisher will output data values in a form that is unambiguous to the
251+
* subscriber. (We don't want to modify the subscriber's GUC settings,
252+
* since that might surprise user-defined code running in the subscriber,
253+
* such as triggers.) This should match what pg_dump does.
254+
*/
255+
if (replication && logical)
256+
{
257+
const char *params[] =
258+
{"datestyle", "intervalstyle", "extra_float_digits"};
259+
const char *values[] = {"ISO", "postgres", "3"};
260+
261+
for (int j = 0; j < lengthof(params); j++)
262+
{
263+
char sql[100];
264+
PGresult *res;
265+
266+
sprintf(sql, "SET %s = %s", params[j], values[j]);
267+
res = libpqsrv_exec(conn->streamConn, sql,
268+
WAIT_EVENT_LIBPQWALRECEIVER_RECEIVE);
269+
if (PQresultStatus(res) != PGRES_COMMAND_OK)
270+
{
271+
PQclear(res);
272+
*err = psprintf(_("could not set %s: %s"),
273+
params[j], pchomp(PQerrorMessage(conn->streamConn)));
274+
goto bad_connection;
275+
}
276+
PQclear(res);
277+
}
278+
}
279+
259280
conn->logical = logical;
260281

261282
return conn;

0 commit comments

Comments
 (0)