Nils
05/19/2026, 9:48 AMMarvin
05/19/2026, 9:48 AMMarvin
05/19/2026, 9:50 AMlog table from growing forever is to enable the database vacuum service for flow runs.
Important detail: Prefect does not have a separate "log TTL" setting. Logs are generally removed when the related flow runs are deleted.
Recommended setup
Set:
bash
export PREFECT_SERVER_SERVICES_DB_VACUUM_ENABLED="events,flow_runs"
export PREFECT_SERVER_SERVICES_DB_VACUUM_RETENTION_PERIOD="604800"
That example keeps data for 7 days (604800 seconds). You can also tune how often cleanup runs:
bash
export PREFECT_SERVER_SERVICES_DB_VACUUM_LOOP_SECONDS="3600"
That runs cleanup hourly.
What this does
- flow_runs vacuum deletes old terminal flow runs
- Prefect then cleans up related logs
- events vacuum is separate, but usually worth keeping enabled too
Docs
- Database maintenance guide
- Settings reference
A few cautions
- flow_runs vacuum is not enabled by default in self-hosted setups
- Directly deleting from the log table with SQL is not recommended unless you really know what you're doing, because Prefect handles related cleanup at the application level
- If you use direct SQL to delete runs/logs, you may create orphaned records
Quick check in Postgres
sql
SELECT
pg_size_pretty(pg_total_relation_size('public.log')) AS total_size,
count(*) AS row_count,
min(timestamp) AS oldest_log,
max(timestamp) AS newest_log
FROM log;
If you want, I can also help you:
- choose a good retention period
- configure this in Docker / Helm / ECS / Kubernetes
- verify whether your current Prefect server already has vacuum enabled