docs: Add automatic maintenance (cron) scheduling instructions and examples
This commit is contained in:
18
README.md
18
README.md
@@ -55,7 +55,25 @@ This procedure should be scheduled to run periodically (e.g., daily via `pg_cron
|
|||||||
```sql
|
```sql
|
||||||
CALL partitions.run_maintenance();
|
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
|
## 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`).
|
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`).
|
||||||
|
|||||||
Reference in New Issue
Block a user