Purger Table History - Uint

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Conseils

https://www.zabbix.com/forum/zabbix-troubleshooting-and-problems/446940-mysql-
database-cleanup

Pourquoi la taille du fichier history_uint.ibd est largement > à ce qu'on voit en


base ?
# du -hs /var/lib/mysql/zabbix/history_uint.ibd --> 23G
# mysql -uroot -p (enter)
USE zabbix ;
SELECT table_schema, table_name, round(((data_length + index_length) / 1024 /
1024), 2) AS "Size (MB)" FROM information_schema.tables WHERE table_schema =
'zabbix' AND table_name = 'history_uint';
--> 14G
*Solution
4. You probably know this, but many people do not, so it's worth
discussing: most databases (including MySQL) do not shrink the size of their on-
disk files when you delete data from tables. You might delete 10 million rows from
your history_uint table, but the on-disk size of that table is going to stay the
same. Deleting data from a table just creates "free slots" that MySQL will re-use
when it needs to insert new values in the future. If you've deleted massive amounts
of data from an over-sized table and you want to shrink the on-disk footprint, you
need to take special action. One thing you can look into is MySQL's documentation
for "OPTIMIZE TABLE" ( https://dev.mysql.com/doc/refman/8.0...ize-table.html ).
That actually will shrink the table, but it does it by creating a new copy of the
table that's smaller and then switching it into place of the old table, so while
it's operating it requires even more disk space. Make sure you have enough free
space on disk before you attempt this.
Backing up a table, dropping it, and then reloading the table from
backup will also physically shrink it, since you've effectively created a new table
that now only occupies as much disk space as it currently needs. This would be
something you would do with Zabbix offline.
A third option is create a new, empty table from the existing table
(see the docs for "CREATE TABLE LIKE ..." ,
https://dev.mysql.com/doc/refman/8.0...able-like.html ), copy some of the data from
the old table to the new table using some kind of selection criteria (for history,
it's probably based upon date), and then DROP the old table and rename the new
table to take its place. Like the "OPTIMIZE TABLE" option, this requires additional
space to populate the new (hopefully smaller) table with data from the old,
oversized table.

You might also like