feat(postgresql): add forceDrop option to DROP DATABASE#405
Open
nicolasburtey wants to merge 1 commit into
Open
feat(postgresql): add forceDrop option to DROP DATABASE#405nicolasburtey wants to merge 1 commit into
nicolasburtey wants to merge 1 commit into
Conversation
Add an opt-in `forceDrop` field to the PostgreSQL Database managed resource (both cluster-scoped `postgresql.sql.crossplane.io` and namespaced `postgresql.sql.m.crossplane.io`). When set to true, the controller issues `DROP DATABASE IF EXISTS <name> WITH (FORCE)` instead of a bare drop. `WITH (FORCE)` (PostgreSQL 13+) terminates every backend connected to the target database before dropping it. This lets a Database with `deletionPolicy: Delete` be removed even when an application holds a long-lived connection pool against it, which would otherwise make the drop fail with SQLSTATE 55006 (object_in_use) and leave the managed resource stuck Terminating. The option is gated on the server version (>= 130000), mirroring the existing create-time `strategy` version guard. It is a delete-only behaviour toggle, so it is excluded from the up-to-date comparison (like `template` and `strategy`) and does not cause reconciliation churn. Default behaviour (bare drop) is unchanged. Includes regenerated CRDs/deepcopy, unit tests covering the default, force, and unsupported-version cases, and example manifests. Signed-off-by: Nicolas Burtey <nb@galoy.io>
c6867fb to
d3b9022
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in
forceDropfield to the PostgreSQLDatabasemanagedresource that makes the controller issue
DROP DATABASE IF EXISTS <name> WITH (FORCE)instead of a bare drop. Applies to both the cluster-scoped(
postgresql.sql.crossplane.io) and namespaced(
postgresql.sql.m.crossplane.io) APIs.WITH (FORCE)(PostgreSQL 13+) terminates every backend connected tothe target database before dropping it. Without it, a
DatabasewithdeletionPolicy: Deletecannot be removed while any client holds anopen connection, because the bare drop fails with SQLSTATE
55006(
object_in_use). The managed resource then sticksTerminatingindefinitely — i.e. provider-sql cannot delete what it created whenever
an application maintains a persistent connection pool against the
database.
Today,
Database.Deleteis:This adds the
WITH (FORCE)escape hatch so a declarativedeletionPolicy: Deleteworks even with a live pool.Design
spec.forProvider.forceDrop(defaults toomitted/false → behaviour unchanged).
DeleteappendsWITH (FORCE).server_version_num >= 130000),returning a clear error otherwise. This mirrors the existing
create-time
strategyversion guard.forceDropis a delete-only behaviour toggle, not an observableproperty of the database, so it is added to the
upToDateignore listalongside
templateandstrategy(no reconciliation churn).Open questions for reviewers
forceDropisrequested on a server older than 13, matching
strategy. A gentleralternative would be to fall back to a
pg_terminate_backenddrainstep (works on all versions) when
WITH (FORCE)is unavailable. Happyto switch to that if preferred. Note PostgreSQL 13 reached EOL in Nov
2025, so most deployments are already on 14+.
forceDropto map directly to the SQL keywordand stay consistent with the existing camelCase field style. Open to
force/forceDeleteif there's a preferred convention.Validation
controller-gen.WITH (FORCE)drop, and theunsupported-version error path (cluster + namespaced).
gofmt,go vet,go build ./..., andgo test ./...all pass.Example
Draft until I get a 👍 on the error-vs-fallback and naming questions above.