|
123 | 123 | "cannot sync slots on a non-standby server"); |
124 | 124 |
|
125 | 125 | ################################################## |
126 | | -# Test logical failover slots on the standby |
| 126 | +# Test logical failover slots corresponding to different plugins can be |
| 127 | +# synced to the standby. |
| 128 | +# |
127 | 129 | # Configure standby1 to replicate and synchronize logical slots configured |
128 | 130 | # for failover on the primary |
129 | 131 | # |
130 | | -# failover slot lsub1_slot ->| ----> subscriber1 (connected via logical replication) |
131 | | -# failover slot lsub2_slot | inactive |
| 132 | +# failover slot lsub1_slot | output_plugin: pgoutput |
| 133 | +# failover slot lsub2_slot | output_plugin: test_decoding |
132 | 134 | # primary ---> | |
133 | 135 | # physical slot sb1_slot --->| ----> standby1 (connected via streaming replication) |
134 | 136 | # | lsub1_slot, lsub2_slot (synced_slot) |
|
159 | 161 | $primary->append_conf('postgresql.conf', "log_min_messages = 'debug2'"); |
160 | 162 | $primary->reload; |
161 | 163 |
|
| 164 | +# Drop the subscription to prevent further advancement of the restart_lsn for |
| 165 | +# the lsub1_slot. |
| 166 | +$subscriber1->safe_psql('postgres', "DROP SUBSCRIPTION regress_mysub1;"); |
| 167 | + |
| 168 | +# To ensure that restart_lsn has moved to a recent WAL position, we re-create |
| 169 | +# the lsub1_slot. |
| 170 | +$primary->psql('postgres', |
| 171 | + q{SELECT pg_create_logical_replication_slot('lsub1_slot', 'pgoutput', false, false, true);} |
| 172 | +); |
| 173 | + |
162 | 174 | $primary->psql('postgres', |
163 | 175 | q{SELECT pg_create_logical_replication_slot('lsub2_slot', 'test_decoding', false, false, true);} |
164 | 176 | ); |
|
169 | 181 | # Start the standby so that slot syncing can begin |
170 | 182 | $standby1->start; |
171 | 183 |
|
172 | | -$primary->wait_for_catchup('regress_mysub1'); |
173 | | - |
174 | | -# Do not allow any further advancement of the restart_lsn for the lsub1_slot. |
175 | | -$subscriber1->safe_psql('postgres', |
176 | | - "ALTER SUBSCRIPTION regress_mysub1 DISABLE"); |
177 | | - |
178 | | -# Wait for the replication slot to become inactive on the publisher |
179 | | -$primary->poll_query_until( |
180 | | - 'postgres', |
181 | | - "SELECT COUNT(*) FROM pg_catalog.pg_replication_slots WHERE slot_name = 'lsub1_slot' AND active = 'f'", |
182 | | - 1); |
183 | | - |
184 | 184 | # Capture the inactive_since of the slot from the primary. Note that the slot |
185 | | -# will be inactive since the corresponding subscription is disabled. |
| 185 | +# will be inactive since the corresponding subscription was dropped. |
186 | 186 | my $inactive_since_on_primary = |
187 | 187 | $primary->validate_slot_inactive_since('lsub1_slot', $slot_creation_time_on_primary); |
188 | 188 |
|
189 | 189 | # Wait for the standby to catch up so that the standby is not lagging behind |
190 | | -# the subscriber. |
| 190 | +# the failover slots. |
191 | 191 | $primary->wait_for_replay_catchup($standby1); |
192 | 192 |
|
193 | 193 | # Synchronize the primary server slots to the standby. |
|
262 | 262 | $standby1->reload; |
263 | 263 |
|
264 | 264 | # Capture the time before the logical failover slot is created on the primary. |
265 | | -# Note that the subscription creates the slot again on the primary. |
266 | 265 | $slot_creation_time_on_primary = $publisher->safe_psql( |
267 | 266 | 'postgres', qq[ |
268 | 267 | SELECT current_timestamp; |
269 | 268 | ]); |
270 | 269 |
|
271 | 270 | # To ensure that restart_lsn has moved to a recent WAL position, we re-create |
272 | | -# the subscription and the logical slot. |
273 | | -$subscriber1->safe_psql( |
| 271 | +# the lsub1_slot. |
| 272 | +$primary->safe_psql( |
274 | 273 | 'postgres', qq[ |
275 | | - DROP SUBSCRIPTION regress_mysub1; |
276 | | - CREATE SUBSCRIPTION regress_mysub1 CONNECTION '$publisher_connstr' PUBLICATION regress_mypub WITH (slot_name = lsub1_slot, copy_data = false, failover = true); |
| 274 | + SELECT pg_drop_replication_slot('lsub1_slot'); |
| 275 | + SELECT pg_create_logical_replication_slot('lsub1_slot', 'pgoutput', false, false, true); |
277 | 276 | ]); |
278 | 277 |
|
279 | | -$primary->wait_for_catchup('regress_mysub1'); |
280 | | - |
281 | | -# Do not allow any further advancement of the restart_lsn for the lsub1_slot. |
282 | | -$subscriber1->safe_psql('postgres', |
283 | | - "ALTER SUBSCRIPTION regress_mysub1 DISABLE"); |
284 | | - |
285 | | -# Wait for the replication slot to become inactive on the publisher |
286 | | -$primary->poll_query_until( |
287 | | - 'postgres', |
288 | | - "SELECT COUNT(*) FROM pg_catalog.pg_replication_slots WHERE slot_name = 'lsub1_slot' AND active = 'f'", |
289 | | - 1); |
290 | | - |
291 | 278 | # Capture the inactive_since of the slot from the primary. Note that the slot |
292 | | -# will be inactive since the corresponding subscription is disabled. |
| 279 | +# will be inactive since the corresponding subscription was dropped. |
293 | 280 | $inactive_since_on_primary = |
294 | 281 | $primary->validate_slot_inactive_since('lsub1_slot', $slot_creation_time_on_primary); |
295 | 282 |
|
296 | 283 | # Wait for the standby to catch up so that the standby is not lagging behind |
297 | | -# the subscriber. |
| 284 | +# the failover slots. |
298 | 285 | $primary->wait_for_replay_catchup($standby1); |
299 | 286 |
|
300 | 287 | my $log_offset = -s $standby1->logfile; |
|
571 | 558 | $subscriber1->safe_psql( |
572 | 559 | 'postgres', qq[ |
573 | 560 | CREATE TABLE tab_int (a int PRIMARY KEY); |
574 | | - ALTER SUBSCRIPTION regress_mysub1 ENABLE; |
575 | | - ALTER SUBSCRIPTION regress_mysub1 REFRESH PUBLICATION; |
| 561 | + CREATE SUBSCRIPTION regress_mysub1 CONNECTION '$publisher_connstr' PUBLICATION regress_mypub WITH (slot_name = lsub1_slot, failover = true, create_slot = false); |
576 | 562 | ]); |
577 | 563 |
|
578 | 564 | $subscriber1->wait_for_subscription_sync; |
|
0 commit comments