<@ULVA73B9P> The logs table in my postgres databas...
# ask-marvin
n
@Marvin The logs table in my postgres database is getting quite big. How do I make sure logs are not stored for too long?
m
thought for 119.5 seconds
If you're self-hosting Prefect 3 with Postgres, the main way to prevent the
log
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:
Copy code
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:
Copy code
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
Copy code
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