|
6 | 6 | use warnings;
|
7 | 7 | use PostgresNode;
|
8 | 8 | use TestLib;
|
9 |
| -use Test::More tests => 11; |
| 9 | +use Test::More tests => 14; |
10 | 10 |
|
11 | 11 | # setup
|
12 | 12 |
|
|
16 | 16 |
|
17 | 17 | my $node_subscriber = get_new_node('subscriber');
|
18 | 18 | $node_subscriber->init(allows_streaming => 'logical');
|
| 19 | +$node_subscriber->append_conf('postgresql.conf', |
| 20 | + qq(max_logical_replication_workers = 6)); |
19 | 21 | $node_subscriber->start;
|
20 | 22 |
|
21 | 23 | my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
|
|
187 | 189 | "SELECT count(*), min(a), max(a) FROM tab1");
|
188 | 190 | is($result, qq(0||),
|
189 | 191 | 'truncate replicated in synchronous logical replication');
|
| 192 | + |
| 193 | +$node_publisher->safe_psql('postgres', |
| 194 | + "ALTER SYSTEM RESET synchronous_standby_names"); |
| 195 | +$node_publisher->safe_psql('postgres', "SELECT pg_reload_conf()"); |
| 196 | + |
| 197 | +# test that truncate works for logical replication when there are multiple |
| 198 | +# subscriptions for a single table |
| 199 | + |
| 200 | +$node_publisher->safe_psql('postgres', |
| 201 | + "CREATE TABLE tab5 (a int)"); |
| 202 | + |
| 203 | +$node_subscriber->safe_psql('postgres', |
| 204 | + "CREATE TABLE tab5 (a int)"); |
| 205 | + |
| 206 | +$node_publisher->safe_psql('postgres', |
| 207 | + "CREATE PUBLICATION pub5 FOR TABLE tab5"); |
| 208 | +$node_subscriber->safe_psql('postgres', |
| 209 | + "CREATE SUBSCRIPTION sub5_1 CONNECTION '$publisher_connstr' PUBLICATION pub5" |
| 210 | +); |
| 211 | +$node_subscriber->safe_psql('postgres', |
| 212 | + "CREATE SUBSCRIPTION sub5_2 CONNECTION '$publisher_connstr' PUBLICATION pub5" |
| 213 | +); |
| 214 | + |
| 215 | +# wait for initial data sync |
| 216 | +$node_subscriber->poll_query_until('postgres', $synced_query) |
| 217 | + or die "Timed out while waiting for subscriber to synchronize data"; |
| 218 | + |
| 219 | +# insert data to truncate |
| 220 | + |
| 221 | +$node_publisher->safe_psql('postgres', |
| 222 | + "INSERT INTO tab5 VALUES (1), (2), (3)"); |
| 223 | + |
| 224 | +$node_publisher->wait_for_catchup('sub5_1'); |
| 225 | +$node_publisher->wait_for_catchup('sub5_2'); |
| 226 | + |
| 227 | +$result = $node_subscriber->safe_psql('postgres', |
| 228 | + "SELECT count(*), min(a), max(a) FROM tab5"); |
| 229 | +is($result, qq(6|1|3), 'insert replicated for multiple subscriptions'); |
| 230 | + |
| 231 | +$node_publisher->safe_psql('postgres', "TRUNCATE tab5"); |
| 232 | + |
| 233 | +$node_publisher->wait_for_catchup('sub5_1'); |
| 234 | +$node_publisher->wait_for_catchup('sub5_2'); |
| 235 | + |
| 236 | +$result = $node_subscriber->safe_psql('postgres', |
| 237 | + "SELECT count(*), min(a), max(a) FROM tab5"); |
| 238 | +is($result, qq(0||), |
| 239 | + 'truncate replicated for multiple subscriptions'); |
| 240 | + |
| 241 | +# check deadlocks |
| 242 | +$result = $node_subscriber->safe_psql('postgres', |
| 243 | + "SELECT deadlocks FROM pg_stat_database WHERE datname='postgres'"); |
| 244 | +is($result, qq(0), 'no deadlocks detected'); |
0 commit comments