|
6 | 6 | use warnings;
|
7 | 7 | use PostgreSQL::Test::Cluster;
|
8 | 8 | use PostgreSQL::Test::Utils;
|
9 |
| -use Test::Moretests=>5; |
| 9 | +use Test::Moretests=>7; |
10 | 10 |
|
11 | 11 | # Bug #15114
|
12 | 12 |
|
|
224 | 224 | $node_pub->stop('fast');
|
225 | 225 | $node_pub_sub->stop('fast');
|
226 | 226 | $node_sub->stop('fast');
|
| 227 | + |
| 228 | +# https://postgr.es/m/OS0PR01MB61133CA11630DAE45BC6AD95FB939%40OS0PR01MB6113.jpnprd01.prod.outlook.com |
| 229 | + |
| 230 | +# The bug was that when changing the REPLICA IDENTITY INDEX to another one, the |
| 231 | +# target table's relcache was not being invalidated. This leads to skipping |
| 232 | +# UPDATE/DELETE operations during apply on the subscriber side as the columns |
| 233 | +# required to search corresponding rows won't get logged. |
| 234 | +$node_publisher = PostgreSQL::Test::Cluster->new('publisher3'); |
| 235 | +$node_publisher->init(allows_streaming=>'logical'); |
| 236 | +$node_publisher->start; |
| 237 | + |
| 238 | +$node_subscriber = PostgreSQL::Test::Cluster->new('subscriber3'); |
| 239 | +$node_subscriber->init(allows_streaming=>'logical'); |
| 240 | +$node_subscriber->start; |
| 241 | + |
| 242 | +$node_publisher->safe_psql('postgres', |
| 243 | +"CREATE TABLE tab_replidentity_index(a int not null, b int not null)"); |
| 244 | +$node_publisher->safe_psql('postgres', |
| 245 | +"CREATE UNIQUE INDEX idx_replidentity_index_a ON tab_replidentity_index(a)" |
| 246 | +); |
| 247 | +$node_publisher->safe_psql('postgres', |
| 248 | +"CREATE UNIQUE INDEX idx_replidentity_index_b ON tab_replidentity_index(b)" |
| 249 | +); |
| 250 | + |
| 251 | +# use index idx_replidentity_index_a as REPLICA IDENTITY on publisher. |
| 252 | +$node_publisher->safe_psql('postgres', |
| 253 | +"ALTER TABLE tab_replidentity_index REPLICA IDENTITY USING INDEX idx_replidentity_index_a" |
| 254 | +); |
| 255 | + |
| 256 | +$node_publisher->safe_psql('postgres', |
| 257 | +"INSERT INTO tab_replidentity_index VALUES(1, 1),(2, 2)"); |
| 258 | + |
| 259 | +$node_subscriber->safe_psql('postgres', |
| 260 | +"CREATE TABLE tab_replidentity_index(a int not null, b int not null)"); |
| 261 | +$node_subscriber->safe_psql('postgres', |
| 262 | +"CREATE UNIQUE INDEX idx_replidentity_index_a ON tab_replidentity_index(a)" |
| 263 | +); |
| 264 | +$node_subscriber->safe_psql('postgres', |
| 265 | +"CREATE UNIQUE INDEX idx_replidentity_index_b ON tab_replidentity_index(b)" |
| 266 | +); |
| 267 | +# use index idx_replidentity_index_b as REPLICA IDENTITY on subscriber because |
| 268 | +# it reflects the future scenario we are testing: changing REPLICA IDENTITY |
| 269 | +# INDEX. |
| 270 | +$node_subscriber->safe_psql('postgres', |
| 271 | +"ALTER TABLE tab_replidentity_index REPLICA IDENTITY USING INDEX idx_replidentity_index_b" |
| 272 | +); |
| 273 | + |
| 274 | +$publisher_connstr =$node_publisher->connstr .' dbname=postgres'; |
| 275 | +$node_publisher->safe_psql('postgres', |
| 276 | +"CREATE PUBLICATION tap_pub FOR TABLE tab_replidentity_index"); |
| 277 | +$node_subscriber->safe_psql('postgres', |
| 278 | +"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub" |
| 279 | +); |
| 280 | + |
| 281 | +$node_publisher->wait_for_catchup('tap_sub'); |
| 282 | + |
| 283 | +# Also wait for initial table sync to finish |
| 284 | +$node_subscriber->poll_query_until('postgres',$synced_query) |
| 285 | +ordie"Timed out while waiting for subscriber to synchronize data"; |
| 286 | + |
| 287 | +is($node_subscriber->safe_psql( |
| 288 | +'postgres',"SELECT * FROM tab_replidentity_index"), |
| 289 | +qq(1|1 |
| 290 | +2|2), |
| 291 | +"check initial data on subscriber"); |
| 292 | + |
| 293 | +# Set REPLICA IDENTITY to idx_replidentity_index_b on publisher, then run UPDATE and DELETE. |
| 294 | +$node_publisher->safe_psql( |
| 295 | +'postgres',qq[ |
| 296 | +ALTER TABLE tab_replidentity_index REPLICA IDENTITY USING INDEX idx_replidentity_index_b; |
| 297 | +UPDATE tab_replidentity_index SET a = -a WHERE a = 1; |
| 298 | +DELETE FROM tab_replidentity_index WHERE a = 2; |
| 299 | +]); |
| 300 | + |
| 301 | +$node_publisher->wait_for_catchup('tap_sub'); |
| 302 | +is($node_subscriber->safe_psql( |
| 303 | +'postgres',"SELECT * FROM tab_replidentity_index"), |
| 304 | +qq(-1|1), |
| 305 | +"update works with REPLICA IDENTITY"); |
| 306 | + |
| 307 | +$node_publisher->stop('fast'); |
| 308 | +$node_subscriber->stop('fast'); |