|
3 | 3 | use warnings;
|
4 | 4 | use PostgresNode;
|
5 | 5 | use TestLib;
|
6 |
| -use Test::More tests => 9; |
| 6 | +use Test::More tests => 12; |
7 | 7 |
|
8 | 8 | # setup
|
9 | 9 |
|
|
13 | 13 |
|
14 | 14 | my $node_subscriber = get_new_node('subscriber');
|
15 | 15 | $node_subscriber->init(allows_streaming => 'logical');
|
| 16 | +$node_subscriber->append_conf('postgresql.conf', |
| 17 | + qq(max_logical_replication_workers = 6)); |
16 | 18 | $node_subscriber->start;
|
17 | 19 |
|
18 | 20 | my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
|
|
158 | 160 | $result = $node_subscriber->safe_psql('postgres',
|
159 | 161 | "SELECT count(*), min(a), max(a) FROM tab2");
|
160 | 162 | is($result, qq(3|1|3), 'truncate of multiple tables some not published');
|
| 163 | + |
| 164 | +# test that truncate works for logical replication when there are multiple |
| 165 | +# subscriptions for a single table |
| 166 | + |
| 167 | +$node_publisher->safe_psql('postgres', |
| 168 | + "CREATE TABLE tab5 (a int)"); |
| 169 | + |
| 170 | +$node_subscriber->safe_psql('postgres', |
| 171 | + "CREATE TABLE tab5 (a int)"); |
| 172 | + |
| 173 | +$node_publisher->safe_psql('postgres', |
| 174 | + "CREATE PUBLICATION pub5 FOR TABLE tab5"); |
| 175 | +$node_subscriber->safe_psql('postgres', |
| 176 | + "CREATE SUBSCRIPTION sub5_1 CONNECTION '$publisher_connstr' PUBLICATION pub5" |
| 177 | +); |
| 178 | +$node_subscriber->safe_psql('postgres', |
| 179 | + "CREATE SUBSCRIPTION sub5_2 CONNECTION '$publisher_connstr' PUBLICATION pub5" |
| 180 | +); |
| 181 | + |
| 182 | +# wait for initial data sync |
| 183 | +$node_subscriber->poll_query_until('postgres', $synced_query) |
| 184 | + or die "Timed out while waiting for subscriber to synchronize data"; |
| 185 | + |
| 186 | +# insert data to truncate |
| 187 | + |
| 188 | +$node_publisher->safe_psql('postgres', |
| 189 | + "INSERT INTO tab5 VALUES (1), (2), (3)"); |
| 190 | + |
| 191 | +$node_publisher->wait_for_catchup('sub5_1'); |
| 192 | +$node_publisher->wait_for_catchup('sub5_2'); |
| 193 | + |
| 194 | +$result = $node_subscriber->safe_psql('postgres', |
| 195 | + "SELECT count(*), min(a), max(a) FROM tab5"); |
| 196 | +is($result, qq(6|1|3), 'insert replicated for multiple subscriptions'); |
| 197 | + |
| 198 | +$node_publisher->safe_psql('postgres', "TRUNCATE tab5"); |
| 199 | + |
| 200 | +$node_publisher->wait_for_catchup('sub5_1'); |
| 201 | +$node_publisher->wait_for_catchup('sub5_2'); |
| 202 | + |
| 203 | +$result = $node_subscriber->safe_psql('postgres', |
| 204 | + "SELECT count(*), min(a), max(a) FROM tab5"); |
| 205 | +is($result, qq(0||), |
| 206 | + 'truncate replicated for multiple subscriptions'); |
| 207 | + |
| 208 | +# check deadlocks |
| 209 | +$result = $node_subscriber->safe_psql('postgres', |
| 210 | + "SELECT deadlocks FROM pg_stat_database WHERE datname='postgres'"); |
| 211 | +is($result, qq(0), 'no deadlocks detected'); |
0 commit comments