]> granicus.if.org Git - postgresql/commitdiff
Fix logical replication with different encodings
authorPeter Eisentraut <peter_e@gmx.net>
Thu, 23 Feb 2017 16:27:59 +0000 (11:27 -0500)
committerPeter Eisentraut <peter_e@gmx.net>
Thu, 23 Feb 2017 16:29:12 +0000 (11:29 -0500)
reported by Shinoda, Noriyoshi <noriyoshi.shinoda@hpe.com>; partial
patch by Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
src/backend/replication/logical/proto.c

index 44a89c73fde9876fe38e650fbc74d92f90db8d94..44ded74f51980d30e44ca8eb8fbbdc356c67766a 100644 (file)
@@ -22,6 +22,7 @@
 #include "libpq-fe.h"
 #include "pqexpbuffer.h"
 #include "access/xlog.h"
+#include "mb/pg_wchar.h"
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "replication/logicalproto.h"
@@ -134,9 +135,16 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
        }
        keys[++i] = "fallback_application_name";
        vals[i] = appname;
+       if (logical)
+       {
+               keys[++i] = "client_encoding";
+               vals[i] = GetDatabaseEncodingName();
+       }
        keys[++i] = NULL;
        vals[i] = NULL;
 
+       Assert(i < sizeof(keys));
+
        conn = palloc0(sizeof(WalReceiverConn));
        conn->streamConn = PQconnectdbParams(keys, vals, /* expand_dbname = */ true);
        if (PQstatus(conn->streamConn) != CONNECTION_OK)
index 142cd993cd858519e657030cee72c4f643bb4ab0..bc6e9b5a98cb726cd3697825f0d76e6a4abba192 100644 (file)
@@ -444,7 +444,7 @@ logicalrep_write_tuple(StringInfo out, Relation rel, HeapTuple tuple)
                outputstr = OidOutputFunctionCall(typclass->typoutput, values[i]);
                len = strlen(outputstr) + 1;    /* null terminated */
                pq_sendint(out, len, 4);                /* length */
-               appendBinaryStringInfo(out, outputstr, len); /* data */
+               pq_sendstring(out, outputstr);  /* data */
 
                pfree(outputstr);