aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-11-02 14:28:50 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-11-02 14:28:50 -0400
commitf3d4019da5d026f2c3fe5bd258becf6fbb6b4673 (patch)
treedc35d216fdc3e6c89bfe65e2fabe95e44a3dea58
parent01fc6527034a6f70ed44a078af8f636b1ab64947 (diff)
downloadpostgresql-f3d4019da5d026f2c3fe5bd258becf6fbb6b4673.tar.gz
postgresql-f3d4019da5d026f2c3fe5bd258becf6fbb6b4673.zip
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
-rw-r--r--src/backend/replication/libpqwalreceiver/libpqwalreceiver.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
index 5c6e56a5b24..c08e599eef5 100644
--- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
+++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
@@ -128,8 +128,8 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
{
WalReceiverConn *conn;
PostgresPollingStatusType status;
- const char *keys[5];
- const char *vals[5];
+ const char *keys[6];
+ const char *vals[6];
int i = 0;
/*
@@ -153,8 +153,20 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
vals[i] = appname;
if (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";
}
keys[++i] = NULL;
vals[i] = NULL;