| 1 |
|
| 2 |
# Copyright (c) 2021-2025, PostgreSQL Global Development Group |
| 3 |
|
| 4 |
# Test replication between databases with different encodings |
| 5 |
use strict; |
| 6 |
use warnings FATAL => 'all'; |
| 7 |
use PostgreSQL::Test::Cluster; |
| 8 |
use PostgreSQL::Test::Utils; |
| 9 |
use Test::More; |
| 10 |
|
| 11 |
my $node_publisher = PostgreSQL::Test::Cluster->new('publisher'); |
| 12 |
$node_publisher->init( |
| 13 |
allows_streaming => 'logical', |
| 14 |
extra => [ '--locale=C', '--encoding=UTF8' ]); |
| 15 |
$node_publisher->start; |
| 16 |
|
| 17 |
my $node_subscriber = PostgreSQL::Test::Cluster->new('subscriber'); |
| 18 |
$node_subscriber->init(extra => [ '--locale=C', '--encoding=LATIN1' ]); |
| 19 |
$node_subscriber->start; |
| 20 |
|
| 21 |
my $ddl = "CREATE TABLE test1 (a int, b text);"; |
| 22 |
$node_publisher->safe_psql('postgres', $ddl); |
| 23 |
$node_subscriber->safe_psql('postgres', $ddl); |
| 24 |
|
| 25 |
my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; |
| 26 |
|
| 27 |
$node_publisher->safe_psql('postgres', |
| 28 |
"CREATE PUBLICATION mypub FOR ALL TABLES;"); |
| 29 |
$node_subscriber->safe_psql('postgres', |
| 30 |
"CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr' PUBLICATION mypub;" |
| 31 |
); |
| 32 |
|
| 33 |
# Wait for initial sync to finish |
| 34 |
$node_subscriber->wait_for_subscription_sync($node_publisher, 'mysub'); |
| 35 |
|
| 36 |
$node_publisher->safe_psql('postgres', |
| 37 |
q{INSERT INTO test1 VALUES (1, E'Mot\xc3\xb6rhead')}); # hand-rolled UTF-8 |
| 38 |
|
| 39 |
$node_publisher->wait_for_catchup('mysub'); |
| 40 |
|
| 41 |
is( $node_subscriber->safe_psql( |
| 42 |
'postgres', q{SELECT a FROM test1 WHERE b = E'Mot\xf6rhead'} |
| 43 |
), # LATIN1 |
| 44 |
qq(1), |
| 45 |
'data replicated to subscriber'); |
| 46 |
|
| 47 |
$node_subscriber->stop; |
| 48 |
$node_publisher->stop; |
| 49 |
|
| 50 |
done_testing(); |