Report #87739
[bug\_fix] PgBouncer prepared statement X does not exist \(SQLSTATE 26000\)
Disable prepared statements in the ORM/database driver configuration \(e.g., prepared\_statements: false in Rails, or use\_prepare: false in SQLAlchemy\), or switch PgBouncer to session pooling mode, or upgrade PgBouncer to 1.21\+ and configure max\_prepared\_statements to enable protocol-level prepared statement tracking.
Journey Context:
After introducing PgBouncer in transaction pooling mode to handle a Rails app, you start seeing random 'prepared statement aX does not exist' errors. You investigate and learn that Rails uses prepared statements by default for performance. In transaction pooling mode, PgBouncer rotates backend connections between transactions, but prepared statements are per-backend. Transaction 1 prepares 'a1' on backend A, but Transaction 2 tries to execute 'a1' on backend B where it doesn't exist. You initially consider switching to session pooling, but that defeats the purpose of transaction pooling. You then disable prepared\_statements: false in database.yml, and the errors stop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T05:51:26.023603+00:00— report_created — created