Cleaning Up Events
This guide covers using the cloacinactl admin cleanup-events command to manage the execution event table, which grows with every task execution and can impact query performance over time.
Prerequisites
Section titled “Prerequisites”cloacinactlbinary installed- Access to the Cloacina database (PostgreSQL or SQLite)
- Database URL available via
--database-url,DATABASE_URLenv var, or~/.cloacina/config.toml
Why Cleanup Matters
Section titled “Why Cleanup Matters”The execution events table grows with every task execution and can reach millions of rows in busy systems. Regular cleanup keeps the database responsive without losing data about recent executions.
Running Cleanup
Section titled “Running Cleanup”Step 1: Preview with Dry Run
Section titled “Step 1: Preview with Dry Run”Always start with --dry-run to see how many events would be deleted:
cloacinactl admin cleanup-events \ --database-url postgresql://cloacina:cloacina@localhost:5432/cloacina \ --older-than 90d \ --dry-runOutput:
[DRY RUN] Would delete 284,391 execution event(s) older than 2026-01-02T14:30:00ZStep 2: Execute the Cleanup
Section titled “Step 2: Execute the Cleanup”Once satisfied with the preview, remove the --dry-run flag:
cloacinactl admin cleanup-events \ --database-url postgresql://cloacina:cloacina@localhost:5432/cloacina \ --older-than 90dOutput:
Deleted 284,391 execution event(s) older than 2026-01-02T14:30:00ZIf no events match the threshold:
No execution events found older than 2026-01-02T14:30:00ZDuration Format
Section titled “Duration Format”The --older-than flag accepts a human-readable duration string with the following units:
| Unit | Meaning | Example |
|---|---|---|
d |
Days | 90d = 90 days |
h |
Hours | 24h = 24 hours |
m |
Minutes | 30m = 30 minutes |
s |
Seconds | 60s = 60 seconds |
Units can be combined:
# 7 days and 12 hourscloacinactl admin cleanup-events --older-than 7d12h --dry-run
# 1 day, 2 hours, 30 minutescloacinactl admin cleanup-events --older-than 1d2h30m --dry-runThe duration is case-insensitive (90D works the same as 90d). The default is 90d if --older-than is not specified.
Using the Config File for Database URL
Section titled “Using the Config File for Database URL”To avoid passing --database-url every time, set it in the config file:
cloacinactl config set database_url "postgresql://cloacina:cloacina@localhost:5432/cloacina"Then run cleanup without the flag:
cloacinactl admin cleanup-events --older-than 30d --dry-runThe command resolves the database URL from (in order): --database-url flag, DATABASE_URL environment variable, ~/.cloacina/config.toml.
Automating Cleanup
Section titled “Automating Cleanup”System Cron (Weekly)
Section titled “System Cron (Weekly)”Add a cron entry to run cleanup every Sunday at 3:00 AM:
crontab -e0 3 * * 0 /usr/local/bin/cloacinactl admin cleanup-events --older-than 90d >> /var/log/cloacina-cleanup.log 2>&1System Cron (Daily, Shorter Retention)
Section titled “System Cron (Daily, Shorter Retention)”For high-volume systems where events are only needed for a week:
0 2 * * * /usr/local/bin/cloacinactl admin cleanup-events --older-than 7d >> /var/log/cloacina-cleanup.log 2>&1Using Environment Variables
Section titled “Using Environment Variables”If the database URL is stored in an environment file:
0 3 * * 0 . /etc/cloacina/env && /usr/local/bin/cloacinactl admin cleanup-events --older-than 90d >> /var/log/cloacina-cleanup.log 2>&1Where /etc/cloacina/env contains:
export DATABASE_URL="postgresql://cloacina:secret@db.example.com:5432/cloacina"Considerations
Section titled “Considerations”Retention Policies
Section titled “Retention Policies”Choose a retention period that balances operational needs with storage costs:
| Use Case | Suggested Retention | Rationale |
|---|---|---|
| Development | 7d |
Only recent runs matter for debugging |
| Staging | 30d |
Keep enough history for release validation |
| Production | 90d |
Quarterly retention for incident investigation |
| Compliance-heavy | 365d or longer |
Regulatory requirements may mandate longer retention |
Before Cleanup
Section titled “Before Cleanup”- Back up first: If you might need historical events for compliance or auditing, back up the database before running cleanup.
- Off-peak hours: Schedule cleanup during low-traffic periods to minimize lock contention on the events table.
- Dry run in production: Always use
--dry-runfirst in production to verify the scope of deletion.
What Gets Deleted
Section titled “What Gets Deleted”The cleanup command deletes rows from the execution events table where created_at is older than the specified threshold. It does not delete:
- Pipeline execution records (the parent execution metadata)
- Task execution records
- Workflow packages or schedules
- API keys or tenant data
Execution records remain intact so you can still see that a pipeline ran, but the detailed per-task event log for old executions will be gone.