Skip to content

Commit f3d4019

Browse files
committed
Ensure consistent logical replication of datetime and float8 values.
In walreceiver, set the publisher's relevant GUCs (datestyle, intervalstyle, extra_float_digits) to the same values that pg_dump uses, and for the same reason: we need the output to be read the same way regardless of the receiver's settings. Without this, it's possible for subscribers to misinterpret transmitted values. Although this is clearly a bug fix, it's not without downsides: subscribers that are storing values into some other datatype, such as text, could get different results than before, and perhaps be unhappy about that. Given the lack of previous complaints, it seems best to change this only in HEAD, and to call it out as an incompatible change in v15. Japin Li, per report from Sadhuprasad Patro Discussion: https://postgr.es/m/CAFF0-CF=D7pc6st-3A9f1JnOt0qmc+BcBPVzD6fLYisKyAjkGA@mail.gmail.com
1 parent 01fc652 commit f3d4019

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

+14-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
128128
{
129129
WalReceiverConn *conn;
130130
PostgresPollingStatusType status;
131-
const char *keys[5];
132-
const char *vals[5];
131+
const char *keys[6];
132+
const char *vals[6];
133133
int i = 0;
134134

135135
/*
@@ -153,8 +153,20 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
153153
vals[i] = appname;
154154
if (logical)
155155
{
156+
/* Tell the publisher to translate to our encoding */
156157
keys[++i] = "client_encoding";
157158
vals[i] = GetDatabaseEncodingName();
159+
160+
/*
161+
* Force assorted GUC parameters to settings that ensure that the
162+
* publisher will output data values in a form that is unambiguous to
163+
* the subscriber. (We don't want to modify the subscriber's GUC
164+
* settings, since that might surprise user-defined code running in
165+
* the subscriber, such as triggers.) This should match what pg_dump
166+
* does.
167+
*/
168+
keys[++i] = "options";
169+
vals[i] = "-c datestyle=ISO -c intervalstyle=postgres -c extra_float_digits=3";
158170
}
159171
keys[++i] = NULL;
160172
vals[i] = NULL;

0 commit comments

Comments
 (0)