Drop prepared-statement-cache in postgres upon invalid cached plan - #4412
Closed
nipunn1313 wants to merge 1 commit into
Closed
nipunn1313 wants to merge 1 commit into
nipunn1313 wants to merge 1 commit into
Conversation
Postgres returns this when a schema change to the database has made the prepared statement no longer valid. W/o this change, the query will repeatedly fail forever as it will try to use the incorrect cached prepared statement.
nipunn1313
marked this pull request as draft
September 16, 2026 22:48
Contributor
Author
|
(seems like 84c31e0 happened and handles the problem better than me) |
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.
Postgres returns this when a schema change to the database has made the prepared statement no longer valid. It returns in the form of FEATURE_NOT_SUPPORTED with a specific "routine()" set.
W/o this change, the query will repeatedly fail forever as it will try to use the incorrect cached prepared statement.
This is the same logic that other postgres clients use.
In our service we have (several times) had this issue occur where we run a database migration and it bricks existing connections, taking down the service until existing connections are all trashed. Errors are of the form:
PgDatabaseError - cached plan must not change result type at line 740I made this PR with the assistance of an LLM - but the PR description is fully handwritten. I personally spent time looking at every line to make sure it felt reasonable.
Does your PR solve an issue?
no - though I can file one if it would be helpful
Is this a breaking change?
no not a breaking change.