Kartik
10/06/2025, 9:58 AMMarvin
10/06/2025, 9:58 AMMarvin
10/06/2025, 10:00 AMpsql "host=<host> port=<port> dbname=<db> user=<user> sslmode=require" -c 'select 1'
- Or TCP check: nc -vz <host> <port>
(should say “succeeded”)
- Security groups/NACLs/routes:
- Inbound on the DB (e.g., RDS) allows 5432 from your EC2 instance’s SG.
- If the DB is on another host, Postgres is listening on 0.0.0.0 (not just localhost).
- Connection URL is correct and uses the async driver:
- It should look like: <postgresql+asyncpg://USER:PASS@HOST:5432/DBNAME>
- If your provider requires TLS, include it, e.g.: ...?sslmode=require
- The DB is up and healthy (logs show it accepting connections).
Optional: increase Prefect’s DB timeouts/pool limits
In Prefect 3.x you can tune these with environment variables (server-side):
- Increase connection establishment timeout (default ~5s):
- PREFECT_SERVER_DATABASE__CONNECTION_TIMEOUT=15
- Increase general DB operation timeout (default ~10s):
- PREFECT_SERVER_DATABASE__TIMEOUT=30
- Adjust pool if you’re under load (to avoid pool checkout timeouts):
- PREFECT_SERVER_DATABASE__SQLALCHEMY__POOL_SIZE=10
- PREFECT_SERVER_DATABASE__SQLALCHEMY__POOL_TIMEOUT=60
- PREFECT_SERVER_DATABASE__SQLALCHEMY__MAX_OVERFLOW=20
Example env setup
export PREFECT_SERVER_DATABASE__CONNECTION_URL='<postgresql+asyncpg://user:pass@your-host:5432/prefect?sslmode=require>'
export PREFECT_SERVER_DATABASE__CONNECTION_TIMEOUT=15
export PREFECT_SERVER_DATABASE__TIMEOUT=30
export PREFECT_SERVER_DATABASE__SQLALCHEMY__POOL_SIZE=10
export PREFECT_SERVER_DATABASE__SQLALCHEMY__POOL_TIMEOUT=60
export PREFECT_SERVER_DATABASE__SQLALCHEMY__MAX_OVERFLOW=20
References
- Prefect 3 database configuration (AsyncPostgresConfiguration)
- Prefect 3 settings reference
A couple of clarifying questions to zero in:
- Where exactly are you seeing this error: Prefect Server (API) logs on the EC2 host, or inside a flow/worker that connects to your own application database?
- What’s the DB host (RDS? another EC2?) and can you psql
to it from the same EC2 machine?
- Could you share your connection URL format (redact user/pass), and whether TLS is required by your DB?