Question

Getting regular "Out of memory: Kill process". How to resolve this isse?

  • Posted July 30, 2013

Regularly I got the following message in syslog file: “Out of memory: Kill process 837 (mysqld) score 59 or sacrifice child”.

This is really annoying.

I already created a swapfile using this tutorial “https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04” but I still get error.

Could you please tell me how to fix this issue?

My droplet is a $5 one with 512Mb RAM. THe distro is Ubuntu 13.04 x64.

(the funny thing is that default mysql configuration worked perfectly on my previous server (VPS Gandi with only 256Mb RAM)

Subscribe
Share

Try disabling OOMKiller using this command:

echo 1 > /proc/sys/vm/overcommit_memory

You can make it permanent with /etc/sysctl.conf by adding vm.overcommit_memory = 1 and then running sysctl -p

Just be aware disabling OOMKiller will have negative effects if you actually run out of memory.

I found even with loosening the ratio to 60% it still killed off my processes with less than 60%.

Disabling it entirely by setting to 1 fixed my problem I think :)

I’m getting the same thing on $10 plan for apache2 (running wordpress and have basically zero traffic except for myself.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I used the suggestions at https://tech.labelleassiette.com/how-to-reduce-the-memory-usage-of-mysql-61ea7d1a9bd to resolve this issue.

A few notes to help clarify:

  1. Update your my.conf file to something similar to below (tweak as desired):
#
# Note the new values are after the included files below
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

[mysqld]

read_buffer_size             = 60K
sort_buffer_size             = 1M
innodb_buffer_pool_size      = 64M
tmp_table_size               = 8M
max_connections              = 25

  1. If you want to run the script that was shared at the bottom of the linked webpage, you need to save it as a file (e.g. sudo nano mysqlinfoscript), and you may want to add some mysql credentials to the first uncommented line (replacing the username and password) as below:
mysql -u username -p'password' -e "show variables; show status" | awk '
  1. To execute the script (assuming you named it mysqlinfoscript) run:
bash mysqlinfoscript
  1. It’s unsafe to leave the username/password in the script so you may want to remove that when finished.

5.) You’ll need to restart mysql after updating my.conf:

sudo service mysql restart

Hello,

Just encounter the issue.

I tweaked the default mysql.cnf installed and configured with the Wordpress Droplet config provided by DO.

If the issue disappeared definitively I will update here on the methodology.

I did not go with the swap file path as it was not recommended by DO.

Thanks

Restarting apache2 and mysql is only a temporary solution, not fixing the root cause.

Try to use a swap file. Getting this error with a nodejs process et resolved since using a swap

Try to use a swap file. Getting this error with a nodejs process et resolved since using a swap

Try to use a swap file. Getting this error with a nodejs process et resolved since using a swap

Hello, all

You will most definitely need to upgrade your droplet as you’re running out of memory and your application/website needs more resources in order to continue to operate.

What you can also do is to use the MySQLTuner script.

The MySQLTuner is a script written in Perl and allows you to quickly test your MySQL configuration and it gives you suggestions for adjustments to increase performance and stability.

According to the official GitHub page, it supports 300 indicators for MySQL/MariaDB/Percona Server in this last version.

To run the script you could do the following:

  • SSH to your Droplet
  • Download the script:
wget http://mysqltuner.pl/ -O mysqltuner.pl
  • Then execute it:
perl mysqltuner.pl

The script would run multiple checks against your MySQL instance, all checks done by MySQLTuner are documented here.

Also as stated in the official documentation, it is still extremely important for you to fully understand each change you make to a MySQL database server. If you don’t understand portions of the script’s output, or if you don’t understand the recommendations, you should consult a knowledgeable DBA or system administrator that you trust.

As a good practice make sure to always test your changes on staging environments before implementing them on your production database.

On the same note, if you want to have a worry-free MySQL hosting and focus on your application, I would recommend trying out the DigitalOcean Managed Databases:

https://www.digitalocean.com/products/managed-databases-mysql/

This was mini tutorial was posted from bobbyiliev in this question in our community: https://www.digitalocean.com/community/questions/how-to-tweak-mysql-mariadb-configuration-for-increased-performance-and-stability

You can also create a simple bash script to check if MySQL is running and if not to restart it.

#!/bin/bash

# Check if MySQL is running
sudo service mysql status > /dev/null 2>&1

# Restart the MySQL service if it's not running.
if [ $? != 0 ]; then
    sudo service mysql restart
fi

Run this script every 5 minutes using a cron job like this one:

 */5 * * * * /home/user/scripts/monitor.sh > /dev/null 2>&1

Hope that this helps! Regards, Alex

This is my Issue too. every time I log into One of my website it keeps happening. Error establishing database connection, and I get out of memory kill process mysqld in ssh console. sometimes it fixes itself in 15-20 seconds. But sometimes I have to turn off and turn on again droplet to solve it. Is that happening cause it needs to increase memory limit? I want to know how to diagnose exactly why this happening and then find the method how to fix it. thanks

The same problem, just want use wordpress with apache and mysql for a site web. Using droplet for $5

Good morning, I have the same problem the mysql stops for no reason I have the most basic plan, how the problem is solved.