<@ULVA73B9P> what's the best way to delete old flo...
# ask-marvin
p
@Marvin what's the best way to delete old flow and task runs in the self-hosted Prefect database?
m
To delete old flow and task runs in a self-hosted Prefect database, you'll need to handle this manually, as there isn't a built-in feature for this in Prefect. Here are some steps you can follow: 1. Database Access: Access your Prefect database directly. If you're using PostgreSQL (recommended for high orchestration volume), you can use a database client like
psql
or any GUI-based client. 2. Identify Old Runs: Determine the criteria for "old" runs. This could be based on the age of the runs or their state (e.g., completed or failed runs older than a certain date). 3. Delete Runs: Execute SQL commands to delete these runs. You might need to delete entries from multiple tables, such as
flow_runs
and
task_runs
, ensuring that you maintain referential integrity. 4. Automate if Needed: Consider writing a script or using a database job scheduler to automate this cleanup process regularly. For more information on managing a self-hosted Prefect server, you can refer to Prefect's self-hosting documentation. If you have any specific questions about SQL commands or database schema, feel free to ask. Just remember, deleting data directly from the database should be done with caution to avoid unintended consequences.