Using PG Failover Slots
During failover, the slots aren't synchronized to the standby immediately because of consistency reasons. The standby can be too behind logical slots or too ahead of logical slots on primary when the pg_failover_slots extension is activated. The extension does verification and synchronizes slots only when it's actually safe.
However, this brings a need to verify that the slots are synchronized and that the standby is actually ready to be a failover target with consistent logical decoding for all slots. You need to do this only initially. Once the slots are synchronized the first time, they're always consistent as long as the extension is active in the cluster.
The check for whether slots are fully synchronized with the primary is relatively simple. The slots just need to be present in the pg_replication_slots
view on the standby and have active state false
. An active state true
means the slots is currently being initialized.
For example, consider the following psql session:
This example shows slots regression_slot1
and regression_slot2
are synchronized from the primary to the standby, and regression_slot3
is still being synchronized. If failover happens at this stage, the regression_slot3
is lost.
After waiting a little, you can query again:
Now all three slots are synchronized. You can use the standby for failover without losing logical decoding state for any of them.
Could this page be better? Report a problem or suggest an addition!