From 581c59a0cae43cdd5194d63a38147dab5795431d Mon Sep 17 00:00:00 2001 From: Maksym Buz Date: Thu, 19 Feb 2026 18:27:07 +0000 Subject: [PATCH] docs: Add automatic maintenance (cron) scheduling instructions and examples --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index ea5901e..0e22e0d 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,25 @@ This procedure should be scheduled to run periodically (e.g., daily via `pg_cron ```sql CALL partitions.run_maintenance(); ``` +### Automatic Maintenance (Cron) +To ensure partitions are created in advance and old data is cleaned up, the maintenance procedure should be scheduled to run automatically. + +It is recommended to run the maintenance **twice a day** (e.g., at 05:30 and 23:30). +* **Primary Run**: Creates new future partitions and drops old ones. +* **Secondary Run**: Acts as a safety check. Since the procedure is idempotent (safe to run multiple times), a second run ensures everything is consistent if the first run failed or was interrupted. + +**Example Crontab Entry (`crontab -e`):** +```bash +# Run Zabbix partition maintenance twice daily (5:30 AM and 5:30 PM) +30 5,23 * * * psql -U zabbix -d zabbix -c "CALL partitions.run_maintenance();" >> /var/log/zabbix_maintenance.log 2>&1 +``` + +**Docker Environment:** +If running in Docker, you can execute it via the container: +```bash +30 5,23 * * * docker exec zabbix-db-test psql -U zabbix -d zabbix -c "CALL partitions.run_maintenance();" +``` ## Monitoring & Permissions System state can be monitored via the `partitions.monitoring` view. It includes a `future_partitions` column which counts how many partitions exist *after* the current period. This is useful for alerting (e.g., trigger if `future_partitions < 2`).