Skip to content

Allow drop slots when it gets deleted from the manifest #2089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 3, 2023

Conversation

idanovinda
Copy link
Member

@idanovinda idanovinda commented Oct 24, 2022

Problem

Users can specify replication slots in the Postgres manifest and they are added to the database via Patroni REST API. When the slot is removed from the manifest, it won't get deleted in the database. Here we follow the convention of the operator never dropping database objects because manifest edits could have been wrong accidentally.

However, with logical replication slots the situation is a little different. If they are not used, diskspace will grow until it's exhausted. Our users are mostly not aware of this and think the slot will be gone when it's not desired anymore in the manifest. Some users check the database and still find the slot. So they call pg_drop_replication_slot function to drop it only to be surprised seconds later that the slot is recreated.

Solution

The operator should drop replication slots when they are removed from the manifest by updating the Patroni config. So far, our code only adds new slots or slots that differ from existing slots to the configToSet. Patroni's config endpoint only merges the patches - it does not override the slots section.

To drop the replication slots that get deleted from the manifest, we can set the unused slots to null in the current Patroni's configuration and using PATCH /config.

@FxKu FxKu added this to the 1.9 milestone Nov 2, 2022
@@ -625,7 +625,7 @@ func (c *Cluster) checkAndSetGlobalPostgreSQLConfiguration(pod *v1.Pod, effectiv
}

// check if there exist only config updates that require a restart of the primary
if !util.SliceContains(restartPrimary, false) && len(configToSet) == 0 {
if len(restartPrimary) > 0 && !util.SliceContains(restartPrimary, false) && len(configToSet) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's nothing to set requiresMasterRestart would become true here which is wrong

SELECT slot_name
FROM pg_replication_slots
WHERE slot_name = '%s';
""" % (slot_to_remove)
Copy link
Member

@FxKu FxKu Dec 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the slot query not be defined once so we do formatting inside the assertions (self.eventuallyEqual)

@FxKu
Copy link
Member

FxKu commented Jan 3, 2023

👍

1 similar comment
@idanovinda
Copy link
Member Author

👍

@FxKu FxKu merged commit 486d5d6 into master Jan 3, 2023
@FxKu FxKu deleted the allow-delete-slots branch January 3, 2023 14:47
@FxKu FxKu mentioned this pull request Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants