Skip to content

Drop prepared-statement-cache in postgres upon invalid cached plan - #4412

Closed
nipunn1313 wants to merge 1 commit into
transact-rs:mainfrom
nipunn1313:nipunn/drop-prepared-statement-cache
Closed

nipunn1313 wants to merge 1 commit into
transact-rs:mainfrom
nipunn1313:nipunn/drop-prepared-statement-cache

Conversation

@nipunn1313

Copy link
Copy Markdown
Contributor

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 740

I 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.

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
nipunn1313 marked this pull request as draft September 16, 2026 22:48
@nipunn1313

Copy link
Copy Markdown
Contributor Author

(seems like 84c31e0 happened and handles the problem better than me)

@nipunn1313 nipunn1313 closed this Sep 16, 2026
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.

1 participant