Recently I encountered one weird problem, my MariaDB database started to crash from time to time on one of my small RAM (512mb) virtual private servers. After some short googling I found out what what is potential problem with MariaDB on small RAM machines and how to fix it.
First of all, if you have this kind of problem, check MariaDB logs
tail -n 100 /var/log/mariadb/mariadb.logyou may find something like this:
160608 12:08:05 InnoDB: Completed initialization of buffer pool
160608 12:08:05 InnoDB: Fatal error: cannot allocate memory for the buffer pool
160608 12:08:05 [ERROR] Plugin 'InnoDB' init function returned error.
160608 12:08:05 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
160608 12:08:05 [ERROR] mysqld: Out of memory (Needed 128917504 bytes)After some research I figured out that mysql require a lot resources for performance schema, and disabling it will help on small memory machines. source
sudo vim /etc/my.cnfadd
performance_schema = offto section
[mysqld]To ensure that database server will restart on crash, on OS with Systemd like CentOS 7 you need to do following
Open following file for edit
sudo vim /etc/systemd/system/mariadb.serviceand add following lines
.include /lib/systemd/system/mariadb.service
[Service]
Restart=always
RestartSec=3Then you need to restart reload Systemd configuration
sudo systemctl daemon-reloadand restart MariaDB service
systemctl restart mariadbTo ensure that Systemd restarts service you can do following:
ps -ef|grep mariaYou will see something like this
mysql 26647 26368 0 Jun12 ? 00:06:22 /usr/libexec/mysqld ....Try to kill the process using
kill 26647Wait 3 seconds and check if MariaDB started again
ps -ef|grep maria
2 comments
Thanks! In upgrading to CentOS 7 I encountered this issue on a DigitalOcean budget VPS, and this post fixed it.
I have the same problem in DigitalOcean.