Avoid dropping physical slots too early (#3244)

Consider a situation: there is a permanent logical slot and primary and replica are temporary down.
When Patroni is started on the former primary it starts Postgres in a standby mode, what leads to removal of physical replication slot for the replica because it has xmin.

We should postpone removal of such physical slots:
- on replica until there will be a leader in the cluster
- on primary until Postgres is promoted
This commit is contained in:
Alexander Kukushkin
2025-01-30 13:08:30 +01:00
committed by GitHub
parent 7db7dfd3c5
commit 2bc25a32e4
2 changed files with 17 additions and 3 deletions
+7
View File
@@ -355,6 +355,13 @@ class TestSlotsHandler(BaseTestPostgresql):
patch.object(SlotsHandler, 'drop_replication_slot', Mock(return_value=(False, False))):
self.s.sync_replication_slots(cluster, self.tags)
with patch.object(SlotsHandler, '_query', Mock(side_effect=[[('test_1', 'physical', 1, 12345, None, None,
None, None, None)], Exception])), \
patch.object(Cluster, 'is_unlocked', Mock(return_value=True)), \
patch.object(SlotsHandler, 'drop_replication_slot') as mock_drop:
self.s.sync_replication_slots(cluster, self.tags)
mock_drop.assert_not_called()
@patch.object(Postgresql, 'is_primary', Mock(return_value=False))
@patch.object(Postgresql, 'role', PropertyMock(return_value='replica'))
@patch.object(TestTags, 'tags', PropertyMock(return_value={'nofailover': True}))