<@ULVA73B9P> can I configure postgresql connection...
# ask-marvin
j
@Marvin can I configure postgresql connection pooling on the server? I was looking for config params around this but couldn't find any.
m
thought for 162.7 seconds
Yes. In Prefect 3.x you can tune the API server’s PostgreSQL connection pool via the built-in SQLAlchemy settings. The available knobs are: - pool_size - max_overflow - pool_timeout - pool_recycle You can set them with environment variables or in prefect.toml. Environment variables
Copy code
# Required DB URL (example uses asyncpg)
PREFECT_SERVER_DATABASE_CONNECTION_URL="<postgresql+asyncpg://user:pass@host:5432/dbname>"

# Connection pool tuning
PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_SIZE=20
PREFECT_SERVER_DATABASE_SQLALCHEMY_MAX_OVERFLOW=40
PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_TIMEOUT=30
PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_RECYCLE=1800
prefect.toml
Copy code
[server.database]
connection_url = "<postgresql+asyncpg://user:pass@host:5432/dbname>"

[server.database.sqlalchemy]
pool_size = 20
max_overflow = 40
pool_timeout = 30
pool_recycle = 1800
To confirm your current values at runtime:
Copy code
prefect config view --show-defaults
Docs - Settings reference (including server/database nesting and env var names): Prefect 3 Settings reference - Server database/SQLAlchemy settings (pool_size, max_overflow, pool_timeout, pool_recycle): Server database configuration (API reference) Using PgBouncer - You can place PgBouncer in front of your Postgres instance; it’s a common way to scale beyond the DB’s native connection limits. Choose a pooling mode that matches your workload and driver; session pooling is the most compatible, while transaction pooling offers higher density but can affect session-level features. Prefect does not require session state, but your broader environment might. If you can share your target concurrency and database max_connections, I’m happy to suggest starting values for these settings.
j
@Marvin in which version was the
pool_size
and
max_overflow
added? I can only see
pool_recycle
and
pool_timeout
when I do
prefect config view --show-defaults
m
🔄 Researching your answer... this may take a while 🔧 Using tool:
explore_module_offerings
📊 Tools used: •
check_cli_command
(2x) •
explore_module_offerings
(3x) •
read_github_issues
(1x) •
research_prefect_topic
(4x) •
search_github_discussions
(1x)
j
@Marvin I found it, but it's different than what you said so and what's the documentation says:
Copy code
PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_RECYCLE='3600' (from defaults)
PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_TIMEOUT='30.0' (from defaults)
PREFECT_SQLALCHEMY_POOL_SIZE='5' (from defaults)
m
🔄 Researching your answer... this may take a while 🔧 Using tool:
explore_module_offerings
📊 Tools used: •
explore_module_offerings
(1x)