artur
10/24/2025, 8:11 PMMarvin
10/24/2025, 8:11 PMMarvin
10/24/2025, 8:14 PMBEGIN;
-- Order matters only if you do not use CASCADE; using CASCADE is simplest:
TRUNCATE TABLE events, event_resources, event_related_resources RESTART IDENTITY CASCADE;
COMMIT;
Notes:
- Table names can vary by version/migrations; inspect your schema first and include any relation tables that reference events or event_resources.
- This will erase all event history. Flow runs, task runs, and deployments are stored in separate tables and will continue to work.
- After truncation, you can keep events off if you don’t use them:
PREFECT_SERVER_SERVICES_EVENT_LOGGER_ENABLED=false
- Take a DB backup before doing this.
3) If vacuum is the blocker
- After pruning or truncating, use pg_repack to reclaim space online if VACUUM FULL is too disruptive.
- See Prefect DB maintenance for guidance and general tips.
Given you don’t use automations
- You can safely delete all events if you’re okay losing the timeline and event history; automations won’t be impacted because you aren’t using them. Do not truncate just event_resources—wipe the event tables together.
- If you’d prefer to keep a small rolling history, enable the persister and drop retention to a day or two until the tables shrink, then raise it back.
Happy to tailor exact SQL and environment settings if you can share:
- How you’re running Prefect Server (Docker Compose, Helm, etc.)
- Your Postgres version
- The current size/row counts of events/event_resources
- Whether you’d like to disable events permanently or keep a short retention window