fix(postgres): use unnamed prepared statements so poolers work - #86
Merged
Conversation
Follow-up to statement_cache_capacity(0) (#85), which was NOT enough: that only disables statement *reuse* — sqlx still creates a *named* prepared statement (sqlx_s_N) per query by default (persistent: true). Named statements don't survive a transaction pooler, so queries still failed with 'prepared statement "sqlx_s_1" does not exist'. Set .persistent(false) on every query so sqlx uses the UNNAMED statement, which is per-execution and survives PgBouncer / Supabase pooler / RDS Proxy. Covered: - lib.rs: bind_params() (SQL editor + JS db.query both route here) plus the direct SELECT 1 / pg_backend_pid / pg_cancel_backend / SET calls - introspect.rs: all 8 schema queries (these run during connect, which is why Connect specifically failed) - object_ops.rs: both JS scripting needs no separate change — db.query goes through DbConnection::stream/execute → bind_params.
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.
Why #85 wasn't enough
#85 set
statement_cache_capacity(0), but the user still hitprepared statement "sqlx_s_1" does not existthrough their PgBouncer after building locally.Root cause (from sqlx 0.8 source,
executor.rs): the cache capacity only disables statement reuse. sqlx still creates a named statement (sqlx_s_N) per query, becauseQuery::persistentdefaults totrue. Named statements don't survive a transaction pooler — the next query lands on a different backend where the name isn't defined.The real fix
Set
.persistent(false)on every query → sqlx uses the unnamed prepared statement (per-execution), which works through PgBouncer / Supabase pooler / RDS Proxy.Coverage:
lib.rs:bind_params()(both the SQL editor and JSdb.queryroute throughstream/execute→ here) + the directSELECT 1/pg_backend_pid/pg_cancel_backend/SET statement_timeoutcalls.introspect.rs: all 8 schema queries — these run during connect, which is exactly why Connect failed.object_ops.rs: both.JS scripting needs no separate change (it goes through the same driver methods).
Verified
cargo check+fmt+clippyclean.sqlx::query*in the crate now uses an unnamed statement.