Skip to content

Retry PostgreSQL queries without statement_timeout behind PgBouncer - #1323

Merged
helpcodeai merged 2 commits into
mainfrom
fix/pgbouncer-statement-timeout
Oct 29, 2026
Merged

helpcodeai merged 2 commits into
mainfrom
fix/pgbouncer-statement-timeout

Conversation

@helpcodeai

Copy link
Copy Markdown
Contributor

Summary

A PostgreSQL DATABASE connector behind PgBouncer fails on every query. executePostgres passes statement_timeout in the Pool config, node-postgres sends it as a startup parameter, and PgBouncer answers unsupported startup parameter: statement_timeout (SQLSTATE 08P01). The connection test passes, because it does not set the timeout. Reported in #1296 after the multi-connector fix made that connector reachable.

Changes

  • database.engine.ts: executePostgres still sets statement_timeout (60 s) on the server first. When the error says unsupported startup parameter, it retries once with node-postgres' client-side query_timeout (same 60 s) instead. Any other error is thrown as before.
  • The query itself moved into runPostgres, unchanged.
  • No SET statement_timeout after connecting: with PgBouncer in transaction mode the setting would stay on the server connection and reach other clients.
  • Same behaviour on Cloud and self-hosted. Without PgBouncer nothing changes.

Type

  • Bug fix
  • New feature
  • Documentation
  • Refactoring
  • Performance improvement
  • Other (describe below)

Testing

  • Added/updated unit tests
  • Tested manually (describe steps below)
  • No tests needed (explain why)

Three new tests in database.engine.spec.ts: server timeout by default, retry with query_timeout (and no statement_timeout) on the PgBouncer error, no retry on other errors.

In packages/backend, after npx prisma generate:

  • npm run lint: OK (no unrelated rewrites).
  • npx tsc --noEmit -p tsconfig.json: OK.
  • npm test: 800 suites passed, 4 skipped; 23,694 tests passed, 1,625 skipped.

Checklist

  • My code follows the existing code style
  • I have tested my changes locally
  • I have updated documentation (if applicable)
  • All existing tests pass (npm test)
  • This PR has a descriptive title

Related Issues

Relates to #1296.

@helpcodeai
helpcodeai enabled auto-merge (squash) October 29, 2026 08:16
@helpcodeai
helpcodeai merged commit 60eec8a into main Oct 29, 2026
14 checks passed
@helpcodeai
helpcodeai deleted the fix/pgbouncer-statement-timeout branch October 29, 2026 08:28
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant