<@ULVA73B9P> i have my prefect server running on a...
# marvin-ai
k
@Marvin i have my prefect server running on an ec2 instance, this is occupying the storage of the machine itself, i have my postgres rds for the storage, how can i use it instead of the default sqllite which stores everything on the machine, i want to store the data of the runs on the postgres rds
m
thought for 149.8 seconds
Great question. In Prefect 3.x, the server uses SQLite by default, but you can point it to your Postgres RDS by setting the server database settings. Here’s the quickest path: Summary of steps - Install the Postgres driver - Point Prefect Server at your RDS URL - Restart the server (it will run migrations automatically) 1) Install the async Postgres driver in the same environment running your server
Copy code
pip install asyncpg
2) Set the database connection for Prefect Server Option A — single URL (recommended)
Copy code
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)
Copy code
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.