Kartik
10/06/2025, 8:46 AMMarvin
10/06/2025, 8:46 AMMarvin
10/06/2025, 8:48 AMpip install asyncpg
2) Set the database connection for Prefect Server
Option A — single URL (recommended)
export PREFECT_SERVER_DATABASE_CONNECTION_URL="postgresql+asyncpg://<USER>:<PASSWORD>@<RDS_HOST>:5432/<DB_NAME>"
prefect server start
Option B — individual fields (equivalent to the URL)
prefect config set \
PREFECT_SERVER_DATABASE_DRIVER=postgresql+asyncpg \
PREFECT_SERVER_DATABASE_HOST=<RDS_HOST> \
PREFECT_SERVER_DATABASE_PORT=5432 \
PREFECT_SERVER_DATABASE_USER=<USER> \
PREFECT_SERVER_DATABASE_PASSWORD=<PASSWORD> \
PREFECT_SERVER_DATABASE_NAME=<DB_NAME>
prefect server start
Notes
- Migrations: Prefect runs DB migrations on startup by default (migrate_on_start=True
), so you don’t need a separate migration command.
- Security/Network: Ensure your EC2 instance can reach your RDS (VPC/security groups). If your RDS enforces TLS, you may need to configure TLS settings; Prefect exposes SQLAlchemy/TLS settings if you need to supply a CA bundle.
- Data scope: This switches orchestration data (flows, deployments, runs, logs, events) to Postgres. Task/flow result payloads are controlled by the Results configuration separately.
Docs
- Self-hosting Prefect 3: Self-hosted guide
- Settings reference: Settings reference
Do you need to migrate your existing run history from SQLite to Postgres or is a fresh start okay? There isn’t an official automated migration from SQLite → Postgres; if you need to keep history, I can outline options and caveats for a manual migration.