feat: Initial commit for 8.0 branch. history_json was added.

This commit is contained in:
Maksym Buz
2026-02-20 21:35:11 +00:00
parent 9d1b84225c
commit 9581dbdb62
31 changed files with 177 additions and 853991 deletions

View File

@@ -61,7 +61,7 @@ This procedure should be scheduled to run periodically (e.g., daily via `pg_cron
```sql
CALL partitions.run_maintenance();
```
### Automatic Maintenance (Cron)
### Automatic Maintenance
To ensure partitions are created in advance and old data is cleaned up, the maintenance procedure should be scheduled to run automatically.
@@ -69,16 +69,70 @@ It is recommended to run the maintenance **twice a day** (e.g., at 05:30 and 23:
* **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.
There are three ways to schedule this, depending on your environment:
#### Option 1: `pg_cron` (If you use RDS/Aurora)
If you are running on managed PostgreSQL (like AWS Aurora) or prefer to keep scheduling inside the database, `pg_cron` is the way to go.
1. Ensure `pg_cron` is installed and loaded in `postgresql.conf` (`shared_preload_libraries = 'pg_cron'`).
2. Run the following to schedule the maintenance:
```sql
CREATE EXTENSION IF NOT EXISTS pg_cron;
SELECT cron.schedule('zabbix_maintenance', '30 5,23 * * *', 'CALL partitions.run_maintenance();');
```
*Where:*
* `'zabbix_maintenance'` - The name of the job (must be unique).
* `'30 5,23 * * *'` - The standard cron schedule (runs at 05:30 and 23:30 daily).
* `'CALL partitions.run_maintenance();'` - The SQL command to execute.
#### Option 2: `systemd` Timers
For standard Linux VM deployments, `systemd` timers are modern, prevent overlapping runs, and provide excellent logging.
1. Create a service file (`/etc/systemd/system/zabbix-partitioning.service`):
```ini
[Unit]
Description=Zabbix PostgreSQL Partition Maintenance
[Service]
Type=oneshot
User=zabbix
# Ensure .pgpass is configured for the zabbix user so it doesn't prompt for a password
ExecStart=/usr/bin/psql -U zabbix -d zabbix -c "CALL partitions.run_maintenance();"
```
2. Create a timer file (`/etc/systemd/system/zabbix-partitioning.timer`):
```ini
[Unit]
Description=Zabbix Partitioning twice a day
[Timer]
OnCalendar=*-*-* 05,23:30:00
Persistent=true
[Install]
WantedBy=timers.target
```
3. Enable and start the timer:
```bash
systemctl daemon-reload
systemctl enable --now zabbix-partitioning.timer
```
#### Option 3: Standard Cron
This is the legacy, simple method for standard VMs and containerized environments.
**Example Crontab Entry (`crontab -e`):**
```bash
# Run Zabbix partition maintenance twice daily (5:30 AM and 5:30 PM)
# Run Zabbix partition maintenance twice daily (5:30 AM and 11: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:
If running in Docker, you can execute it via the container's host:
```bash
30 5,23 * * * docker exec zabbix-db-test psql -U zabbix -d zabbix -c "CALL partitions.run_maintenance();"
30 5,23 * * * docker exec zabbix-db psql -U zabbix -d zabbix -c "CALL partitions.run_maintenance();"
```
## Monitoring & Permissions