|
3 | 3 | use warnings;
|
4 | 4 | use PostgresNode;
|
5 | 5 | use TestLib;
|
6 |
| -use Test::Moretests=>5; |
| 6 | +use Test::Moretests=>7; |
7 | 7 |
|
8 | 8 | # Bug #15114
|
9 | 9 |
|
|
153 | 153 | $rows * 2,"2x$rows rows in t");
|
154 | 154 | is($node_twoways->safe_psql('d2',"SELECT count(f) FROM t2"),
|
155 | 155 | $rows * 2,"2x$rows rows in t2");
|
| 156 | + |
| 157 | +# https://postgr.es/m/OS0PR01MB61133CA11630DAE45BC6AD95FB939%40OS0PR01MB6113.jpnprd01.prod.outlook.com |
| 158 | + |
| 159 | +# The bug was that when changing the REPLICA IDENTITY INDEX to another one, the |
| 160 | +# target table's relcache was not being invalidated. This leads to skipping |
| 161 | +# UPDATE/DELETE operations during apply on the subscriber side as the columns |
| 162 | +# required to search corresponding rows won't get logged. |
| 163 | +$node_publisher = get_new_node('publisher3'); |
| 164 | +$node_publisher->init(allows_streaming=>'logical'); |
| 165 | +$node_publisher->start; |
| 166 | + |
| 167 | +$node_subscriber = get_new_node('subscriber3'); |
| 168 | +$node_subscriber->init(allows_streaming=>'logical'); |
| 169 | +$node_subscriber->start; |
| 170 | + |
| 171 | +$node_publisher->safe_psql('postgres', |
| 172 | +"CREATE TABLE tab_replidentity_index(a int not null, b int not null)"); |
| 173 | +$node_publisher->safe_psql('postgres', |
| 174 | +"CREATE UNIQUE INDEX idx_replidentity_index_a ON tab_replidentity_index(a)" |
| 175 | +); |
| 176 | +$node_publisher->safe_psql('postgres', |
| 177 | +"CREATE UNIQUE INDEX idx_replidentity_index_b ON tab_replidentity_index(b)" |
| 178 | +); |
| 179 | + |
| 180 | +# use index idx_replidentity_index_a as REPLICA IDENTITY on publisher. |
| 181 | +$node_publisher->safe_psql('postgres', |
| 182 | +"ALTER TABLE tab_replidentity_index REPLICA IDENTITY USING INDEX idx_replidentity_index_a" |
| 183 | +); |
| 184 | + |
| 185 | +$node_publisher->safe_psql('postgres', |
| 186 | +"INSERT INTO tab_replidentity_index VALUES(1, 1),(2, 2)"); |
| 187 | + |
| 188 | +$node_subscriber->safe_psql('postgres', |
| 189 | +"CREATE TABLE tab_replidentity_index(a int not null, b int not null)"); |
| 190 | +$node_subscriber->safe_psql('postgres', |
| 191 | +"CREATE UNIQUE INDEX idx_replidentity_index_a ON tab_replidentity_index(a)" |
| 192 | +); |
| 193 | +$node_subscriber->safe_psql('postgres', |
| 194 | +"CREATE UNIQUE INDEX idx_replidentity_index_b ON tab_replidentity_index(b)" |
| 195 | +); |
| 196 | +# use index idx_replidentity_index_b as REPLICA IDENTITY on subscriber because |
| 197 | +# it reflects the future scenario we are testing: changing REPLICA IDENTITY |
| 198 | +# INDEX. |
| 199 | +$node_subscriber->safe_psql('postgres', |
| 200 | +"ALTER TABLE tab_replidentity_index REPLICA IDENTITY USING INDEX idx_replidentity_index_b" |
| 201 | +); |
| 202 | + |
| 203 | +$publisher_connstr =$node_publisher->connstr .' dbname=postgres'; |
| 204 | +$node_publisher->safe_psql('postgres', |
| 205 | +"CREATE PUBLICATION tap_pub FOR TABLE tab_replidentity_index"); |
| 206 | +$node_subscriber->safe_psql('postgres', |
| 207 | +"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub" |
| 208 | +); |
| 209 | + |
| 210 | +$node_publisher->wait_for_catchup('tap_sub'); |
| 211 | + |
| 212 | +# Also wait for initial table sync to finish |
| 213 | +$node_subscriber->poll_query_until('postgres',$synced_query) |
| 214 | +ordie"Timed out while waiting for subscriber to synchronize data"; |
| 215 | + |
| 216 | +is($node_subscriber->safe_psql( |
| 217 | +'postgres',"SELECT * FROM tab_replidentity_index"), |
| 218 | +qq(1|1 |
| 219 | +2|2), |
| 220 | +"check initial data on subscriber"); |
| 221 | + |
| 222 | +# Set REPLICA IDENTITY to idx_replidentity_index_b on publisher, then run UPDATE and DELETE. |
| 223 | +$node_publisher->safe_psql( |
| 224 | +'postgres',qq[ |
| 225 | +ALTER TABLE tab_replidentity_index REPLICA IDENTITY USING INDEX idx_replidentity_index_b; |
| 226 | +UPDATE tab_replidentity_index SET a = -a WHERE a = 1; |
| 227 | +DELETE FROM tab_replidentity_index WHERE a = 2; |
| 228 | +]); |
| 229 | + |
| 230 | +$node_publisher->wait_for_catchup('tap_sub'); |
| 231 | +is($node_subscriber->safe_psql( |
| 232 | +'postgres',"SELECT * FROM tab_replidentity_index"), |
| 233 | +qq(-1|1), |
| 234 | +"update works with REPLICA IDENTITY"); |
| 235 | + |
| 236 | +$node_publisher->stop('fast'); |
| 237 | +$node_subscriber->stop('fast'); |