NOTE: Take an XI backup/VM snapshot first, just in case:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
Yes, you have very large tables:
Code: Select all
| nagios_logentries | 13175.18 |
| nagios_notifications | 12378.66 |
I can't see your entire output but in order to reclaim the space you have two options:
1. If you are running
innodb_file_per_table=1 in your
/etc/my.cnf or in one of your
/etc/my.cnf.d files:
This means that each table uses it's own innodb file, so truncating the individual tables WILL reclaim the space, see the section "In certain instances, it may be necessary to truncate (empty) one or more tables" on page 5 of this PDF:
https://assets.nagios.com/downloads/nag ... tabase.pdf
2. If you are NOT running
innodb_file_per_table=1:
*** If you need to go this route, make sure to do it on a test system first as working with the DB is serious business
This means that your entire DB uses the same innodb file, which means that if you truncate a table, the space is NOT reclaimed. In order to reclaim space this way you would need to:
- Truncate the tables following the section from page 5 above
- Stop all of the nagios services
Code: Select all
service crond stop
service npcd stop
service nagios stop
service ndo2db stop
pkill -9 -u nagios
for i in $(ipcs -q | grep nagios |awk '{print $2}'); do ipcrm -q $i; done
rm -rf /usr/local/nagiosxi/var/dbmaint.lock
rm -rf /usr/local/nagiosxi/var/event_handler.lock
rm -rf /usr/local/nagiosxi/scripts/reconfigure_nagios.lock
service mysqld restart || service mariadb restart​
- mysqldump the nagiosxi DB:
Code: Select all
mysqldump -h 127.0.0.1 -uroot -pnagiosxi --add-drop-database -B nagiosxi > /tmp/nagiosxidump.sql
- Drop the DB, re-import the data, this will reclaim the space:
Code: Select all
mysql -h 127.0.0.1 -uroot -pnagiosxi nagiosxi < /tmp/nagiosxidump.sql
- Start the services back up:
Code: Select all
service ndo2db start
service nagios start
service npcd start
service crond start
service httpd restart
*** NOTE: If you have to do option 2, I would add some additional steps in there to convert your system to use
innodb_file_per_table=1.
If you'd like to do that (so that you can truncate in the future without exporting/re-importing to reclaim space, follow the steps for section 3 instead of section 2.
3.
- Truncate the tables following the section from page 5 above
- Stop all of the nagios services
Code: Select all
service crond stop
service npcd stop
service nagios stop
service ndo2db stop
pkill -9 -u nagios
for i in $(ipcs -q | grep nagios |awk '{print $2}'); do ipcrm -q $i; done
rm -rf /usr/local/nagiosxi/var/dbmaint.lock
rm -rf /usr/local/nagiosxi/var/event_handler.lock
rm -rf /usr/local/nagiosxi/scripts/reconfigure_nagios.lock
service mysqld restart || service mariadb restart​
- mysqldump all 3 DBs:
Code: Select all
mysqldump -h 127.0.0.1 -uroot -pnagiosxi --add-drop-database -B nagios > /tmp/nagiosdump.sql
mysqldump -h 127.0.0.1 -uroot -pnagiosxi --add-drop-database -B nagiosql > /tmp/nagiosqldump.sql
mysqldump -h 127.0.0.1 -uroot -pnagiosxi --add-drop-database -B nagiosxi > /tmp/nagiosxidump.sql
- Edit your
/etc/my.cnf and underneath the
[mysqld] section add:
Then stop mysqld/mariadb, remove the innodb files, start mysqld/mariadb:
Code: Select all
service mysqld stop|| service mariadb stop
rm -f /var/lib/mysql/ibdata1
rm -f /var/lib/mysql/ib_logfile0
rm -f /var/lib/mysql/ib_logfile1
service mysqld start || service mariadb start
- Re-import the data (this will drop the DBs and recreate them with innodb_file_per_table), this will reclaim the space:
Code: Select all
mysql -h 127.0.0.1 -uroot -pnagiosxi nagios < /tmp/nagiosdump.sql
mysql -h 127.0.0.1 -uroot -pnagiosxi nagiosql < /tmp/nagiosqldump.sql
mysql -h 127.0.0.1 -uroot -pnagiosxi nagiosxi < /tmp/nagiosxidump.sql
- Start the services back up:
Code: Select all
service ndo2db start
service nagios start
service npcd start
service crond start
service httpd restart