v3-0001-Honor-GUC-settings-specified-in-CREATE-SUBSCRIPTI.patch

application/octet-stream

Filename: v3-0001-Honor-GUC-settings-specified-in-CREATE-SUBSCRIPTI.patch
Type: application/octet-stream
Part: 0
Message: Re: Allow GUC settings in CREATE SUBSCRIPTION CONNECTION to take effect

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v3-0001
Subject: Honor GUC settings specified in CREATE SUBSCRIPTION CONNECTION.
File+
src/backend/replication/libpqwalreceiver/libpqwalreceiver.c 32 11
From 4c5407fd093f1cf77234f4af604f2355d907a61e Mon Sep 17 00:00:00 2001
From: Fujii Masao <fujii@postgresql.org>
Date: Sat, 22 Nov 2025 22:35:22 +0900
Subject: [PATCH v3] Honor GUC settings specified in CREATE SUBSCRIPTION
 CONNECTION.

Previously, GUC settings supplied in the CONNECTION clause of
CREATE SUBSCRIPTION were not used by the publisher's walsender.
For example, in:

        CREATE SUBSCRIPTION mysub
            CONNECTION 'options=''-c wal_sender_timeout=1000'''
            PUBLICATION ...

the wal_sender_timeout setting had no effect.
This contrasted with physical replication, where GUCs in primary_conninfo
are applied to the walsender.

This limitation made it difficult to tune logical replication connections
individually, 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 removes the restriction by changing how logical replication
connections are established so that GUC settings in the CONNECTION string
are properly passed through to and uesd by the walsender. This enables
per-connection configuration for logical replication.

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
---
 .../libpqwalreceiver/libpqwalreceiver.c       | 43 ++++++++++++++-----
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
index 239641bfbb6..500632b462f 100644
--- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
+++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
@@ -180,17 +180,6 @@ libpqrcv_connect(const char *conninfo, bool replication, bool logical,
 			/* Tell the publisher to translate to our encoding */
 			keys[++i] = "client_encoding";
 			vals[i] = GetDatabaseEncodingName();
-
-			/*
-			 * Force assorted GUC parameters to settings that ensure that the
-			 * publisher will output data values in a form that is unambiguous
-			 * to the subscriber.  (We don't want to modify the subscriber's
-			 * GUC settings, since that might surprise user-defined code
-			 * running in the subscriber, such as triggers.)  This should
-			 * match what pg_dump does.
-			 */
-			keys[++i] = "options";
-			vals[i] = "-c datestyle=ISO -c intervalstyle=postgres -c extra_float_digits=3";
 		}
 		else
 		{
@@ -256,6 +245,38 @@ libpqrcv_connect(const char *conninfo, bool replication, bool logical,
 		PQclear(res);
 	}
 
+	/*
+	 * Force assorted GUC parameters to settings that ensure that the
+	 * publisher will output data values in a form that is unambiguous to the
+	 * subscriber.  (We don't want to modify the subscriber's GUC settings,
+	 * since that might surprise user-defined code running in the subscriber,
+	 * such as triggers.)  This should match what pg_dump does.
+	 */
+	if (replication && logical)
+	{
+		const char *params[] =
+		{"datestyle", "intervalstyle", "extra_float_digits"};
+		const char *values[] = {"ISO", "postgres", "3"};
+
+		for (int j = 0; j < lengthof(params); j++)
+		{
+			char		sql[100];
+			PGresult   *res;
+
+			sprintf(sql, "SET %s = %s", params[j], values[j]);
+			res = libpqsrv_exec(conn->streamConn, sql,
+								WAIT_EVENT_LIBPQWALRECEIVER_RECEIVE);
+			if (PQresultStatus(res) != PGRES_COMMAND_OK)
+			{
+				PQclear(res);
+				*err = psprintf(_("could not set %s: %s"),
+								params[j], pchomp(PQerrorMessage(conn->streamConn)));
+				goto bad_connection;
+			}
+			PQclear(res);
+		}
+	}
+
 	conn->logical = logical;
 
 	return conn;
-- 
2.51.2