Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c3368f9

Browse files
committed
Fix logical replication with different encodings
reported by Shinoda, Noriyoshi <[email protected]>; partial patch by Kyotaro HORIGUCHI <[email protected]>
1 parent e8d016d commit c3368f9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "libpq-fe.h"
2323
#include "pqexpbuffer.h"
2424
#include "access/xlog.h"
25+
#include "mb/pg_wchar.h"
2526
#include "miscadmin.h"
2627
#include "pgstat.h"
2728
#include "replication/logicalproto.h"
@@ -134,9 +135,16 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
134135
}
135136
keys[++i] = "fallback_application_name";
136137
vals[i] = appname;
138+
if (logical)
139+
{
140+
keys[++i] = "client_encoding";
141+
vals[i] = GetDatabaseEncodingName();
142+
}
137143
keys[++i] = NULL;
138144
vals[i] = NULL;
139145

146+
Assert(i < sizeof(keys));
147+
140148
conn = palloc0(sizeof(WalReceiverConn));
141149
conn->streamConn = PQconnectdbParams(keys, vals, /* expand_dbname = */ true);
142150
if (PQstatus(conn->streamConn) != CONNECTION_OK)

src/backend/replication/logical/proto.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ logicalrep_write_tuple(StringInfo out, Relation rel, HeapTuple tuple)
444444
outputstr = OidOutputFunctionCall(typclass->typoutput, values[i]);
445445
len = strlen(outputstr) + 1; /* null terminated */
446446
pq_sendint(out, len, 4); /* length */
447-
appendBinaryStringInfo(out, outputstr, len); /* data */
447+
pq_sendstring(out, outputstr); /* data */
448448

449449
pfree(outputstr);
450450

0 commit comments

Comments
 (0)