<@ULVA73B9P> Is there a way to cleanup old flow ru...
# ask-marvin
a
@Marvin Is there a way to cleanup old flow runs, logs, etc. ?
prefect rocket 1
m
thought for 150.3 seconds
Short answer: yes. There isn’t a big red “prune everything” button, but you’ve got a few practical options. Key points - Deleting a flow run cascades to its task runs and their logs, so you usually don’t need to delete logs separately. - There’s no built‑in automatic retention for OSS Prefect Server. You’ll script it (CLI or Python) and schedule it. - In Prefect Cloud, some data has retention windows by plan; for anything custom, the same scripting approach applies. Common approaches - CLI: list + delete. You can script
prefect flow-run ls
to find old runs and
prefect flow-run delete
to remove them. Good for simple, periodic cleanups. - Python client: a small cleanup job that filters runs older than N days and deletes them. Run it on a schedule as a Prefect flow for hands‑off retention. - Database level: not recommended unless you like living dangerously; use the API/CLI so cascade deletes tidy related records (task runs, logs). Docs to confirm details - Flow runs API: Flow run API (3.x) - Logs model: Logs model (3.x) - DB notes: Database reference A couple quick clarifiers so I can hand you a ready-to-run snippet: - Are you on Prefect Cloud or self-hosted Prefect Server? - What exactly do you want to purge: flow runs (and thus their logs), artifacts, block documents, something else? - What’s your retention target (e.g., older than 30/60/90 days)? - Prefer a CLI one-liner you can cron, or a small Python flow you can deploy and schedule? Tell me those and I’ll give you a tested snippet. I’ll even pretend to be enthusiastic about it.