Hi hackers,
I tried a committed Logical Replication environment. I found that replication between databases of different encodings
didnot convert encodings in character type columns. Is this behavior correct?
I expected that the character 0xe6bca2 (UTF-8) would be converted to the same character 0xb4c1 (EUC_JP). The example
belowreplicates from the encoding UTF-8 database to the encoding EUC_JP database. You can see that the character
0xe6bca2(UTF-8) is stored intact in the SUBSCRIPTION side database.
- PUBLICATION side (encode=UTF-8)
postgres=> \l postgres List of databases Name | Owner | Encoding | Collate | Ctype |
Accessprivileges
----------+----------+----------+---------+-------+-------------------postgres | postgres | UTF8 | C | C
|
(1 row)
postgres=> CREATE TABLE encode1(col1 NUMERIC PRIMARY KEY, col2 VARCHAR(10)) ;
CREATE TABLE
postgres=> CREATE PUBLICATION pub1 FOR TABLE encode1 ;
CREATE PUBLICATION
postgres=> INSERT INTO encode1 VALUES (1, '漢') ; -- UTF-8 Character 0xe6bca2
INSERT 0 1
- SUBSCRIPTION side (encode=EUC_JP)
postgres=> \l postgres List of databases Name | Owner | Encoding | Collate | Ctype |
Accessprivileges
----------+----------+----------+---------+-------+-------------------postgres | postgres | EUC_JP | C | C
|
(1 row)
postgres=> CREATE TABLE encode1(col1 NUMERIC PRIMARY KEY, col2 VARCHAR(10)) ;
CREATE TABLE
postgres=# CREATE SUBSCRIPTION sub1 CONNECTION 'dbname=postgres host=localhost port=5432' PUBLICATION pub1 ;
NOTICE: created replication slot "sub1" on publisher
CREATE SUBSCRIPTION
postgres=# SELECT * FROM encode1 ;
ERROR: invalid byte sequence for encoding "EUC_JP": 0xa2
postgres=# SELECT heap_page_items(get_raw_page('encode1', 0)) ; heap_page_items
-------------------------------------------------------------------(1,8152,1,33,565,0,0,"(0,1)",2,2306,24,,,"\\x0b0080010009e6bca2")
<- stored UTF-8 char 0xe6bca2
(1 row)
Snapshot: https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.gz 2017-01-31 00:29:07
Operating System: Red Hat Enterprise Linux 7 Update 2 (x86-64)
Regards.