Automatic logical cleanup is performed using the Cron task scheduler. Subsequent physical cleaning and optimization of disk space is launched manually through the iBatyr Monitor compact script.
Note
The disk must contain at least 15% of the database volume; for more details, see the article Manual disk cleanup.
Logical Clear
Open the task scheduler in the iBatyr Monitor terminal and run Cron:
sudo crontab -e
Add lines to clean up the database. For example, to delete data from the database for a year every 1st day of the month at 23:00.
Note
Files and events are not restored, so carefully check the time range for deletion before you begin. If you have any questions, please contact to technical support.
00 23 1 * * && sudo ibatyr shard cleanup 12 >> /srv/cleanupdb.log 2>&1The command deletes shards in PostgreSQL, partitions in ClickHouse and files associated with them. Writes the operation log to the file /srv/cleanupdb.log.
See also
Deciphering cron parameters
0 — minute (00 minutes);
23 - hour;
— any day of the month;
— any month;
sudo ibatyr shard_cleanup 12— command to delete shards for the year;> /srv/cleanupdb.log- adds the command output to the log file.<p></p>
Optimizing the cleaned database
To physically free up disk space after clearing the database:
Open the compact script file:
sudo nano /usr/share/ibatyr/bin/compact
In the file, uncomment the lines echo “Vacuum database” and sudo -u postgres psql ibatyr -c “vacuum full”, like this:
#!/bin/bash # USE compact # HELP Cleanup unreffered dimensions and vaccum database ibatyr stop echo "Cleanup dimensions" cat sql/cleanup_dimensions.sql| bin/sql echo "Vacuum database" sudo -u postgres psql ibatyr -c "vacuum full" ibatyr start echo "Cleanup done" bin/infoNote
When the server is updated, all scripts are rewritten, so the changes made to them disappear. After the next server update, repeat the setup.
Save your changes.
After cleaning the database is complete, run the script:
ibatyr compact
Note
Database optimization can take a long time. Run it on non-working days or weekends.