<@ULVA73B9P> I am using self hosted Prefect setup ...
# ask-marvin
b
@Marvin I am using self hosted Prefect setup with the Postgress DB in backend. my DB is getting full on daily basis as the flow count increases. I only want to retain the max last 30 days flows and its runs... how the space can be clered on its own or you give me teh table names which I put in a custom script to clean on regular basis
m
To manage the database size in your self-hosted Prefect setup with PostgreSQL, you can implement a custom cleanup script that retains only the last 30 days of flow runs. Here are some insights and steps you might consider: 1. Database Tables: Prefect uses several tables to store flow runs, task runs, logs, and other related data. Unfortunately, the specific table names aren't directly mentioned in the documentation, but you should focus on tables related to flow runs and task runs. 2. Retention Policy: Prefect does not have a built-in retention policy for PostgreSQL databases. However, you can create a custom script to delete old entries. Use a tool like
pg_cron
to schedule regular cleanup tasks safely. Be cautious with foreign key constraints to avoid breaking references. 3. Custom Script: A typical cleanup script might look like this:
Copy code
sql
   DELETE FROM flow_runs WHERE start_time < NOW() - INTERVAL '30 days';
   DELETE FROM task_runs WHERE start_time < NOW() - INTERVAL '30 days';
   -- Add similar queries for other tables if necessary
4. GitHub Discussions: There are ongoing discussions about database cleanup scripts and retention policies in the Prefect community. You can follow or contribute to these discussions for more insights. For instance, this GitHub issue discusses potential cleanup scripts. 5. Documentation & Resources: - Self-hosted Prefect Management - GitHub Issue on DB Cleanup By carefully implementing a cleanup strategy, you can manage your database size effectively while ensuring that necessary flow data is retained.