Skip to content

Add PgBouncer support via NullPool configuration#21525

Draft
zzstoatzz wants to merge 4 commits intomainfrom
support-pgbouncer-nullpool
Draft

Add PgBouncer support via NullPool configuration#21525
zzstoatzz wants to merge 4 commits intomainfrom
support-pgbouncer-nullpool

Conversation

@zzstoatzz
Copy link
Copy Markdown
Collaborator

closes #18616

Summary

  • Allow PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_SIZE=null to use SQLAlchemy's NullPool, disabling internal connection pooling for external poolers like PgBouncer
  • When pool_size is None, pool-related kwargs (pool_pre_ping, pool_use_lifo, pool_timeout, max_overflow) are excluded since NullPool doesn't support them
  • Adds PgBouncer setup docs to the database maintenance guide
revives #18643

The original PR was closed by the stale bot. This is a fresh implementation rebased on current main with the same approach — community members have been asking for this (see comments on the original PR).

Test plan

  • TestNullPoolConfiguration verifies NullPool is used when pool_size=None and regular pool when pool_size is an integer
  • Settings test verifies PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_SIZE=null env var parses correctly
  • All existing database dependency and settings tests pass

🤖 Generated with Claude Code

@github-actions github-actions bot added enhancement An improvement of an existing feature performance Related to an optimization or performance improvement docs and removed enhancement An improvement of an existing feature performance Related to an optimization or performance improvement labels Apr 13, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 13, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing support-pgbouncer-nullpool (e0909a7) with main (79ee315)

Open in CodSpeed

zzstoatzz and others added 4 commits April 13, 2026 15:39
Setting `PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_SIZE=null` disables
SQLAlchemy's internal connection pool (using NullPool), allowing external
connection poolers like PgBouncer to manage connections instead.

closes #18616

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
asyncpg requires scram-sha-256 auth with PostgreSQL 14+, which is not
PgBouncer's default. Discovered during E2E testing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Restores the original model_dump() approach and removes the deferred
import. Cleaner diff and less likely to drift if new settings are added.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support PgBouncer

1 participant