Out Of Memory (Is It Possible)

November 11, 2015 2.4k views
MySQL Apache


I am running a wordpress installation on a $20 droplet (2gb | 2 core ), which i thought would be more than enough to run a wordpress site with 300 hits a day.

I keep getting the 'Error establishing database connection', and i have to keep restarting the server.

Is it possible to find out what is causing the memory errors, and how much memory i need?

I've ran a view commands and i can see that:

/var/log/mysql/error.log:151111 8:38:10 InnoDB: Fatal error: cannot allocate memory for the buffer pool 
/var/log/mysql/error.log:151111 8:38:11 InnoDB: Fatal error: cannot allocate memory for the buffer pool

Thanks in advance for your help.

1 comment
4 Answers

Hi, thank you.

What does free-m do?

@mosaic - The free -m command will output something such as:

                    total      used       free     shared    buffers     cached
Mem:                2000       1982         18          0         95       1666
-/+ buffers/cache:              220       1780
Swap:               0             0          0

What this means is that I have 2000MB of RAM, I've "used" 1982MB, of which 1666MB is cached and 95MB is buffer.

You can also use

free -mh

for an easier to read and pre-converted output which is converted to MB & GB instead of the default shown above, such as:

                    total       used       free     shared    buffers     cached
Mem:                 2.0G       1.9G        20M       632K        88M       1.6G
-/+ buffers/cache:              210M       1.7G
Swap:                  0B         0B         0B

What this does is simply tell you how much RAM you're currently utilizing as of command execution.


That said, the free -m or free -mh command isn't going to tell you where your problem is. You really need to look at RAM usage by process, specifically MySQL, Apache/NGINX, PHP etc.

To start, I'd advise downloading, installing and running MySQL Tuner (installation and usage details are on the main page of the site). This needs to be done as the root user from the command line interface (CLI). Once executed, it'll provide you with a plethora of information that can be used to diagnose RAM usage by MySQL as well as overall performance.

If you would, run MySQL Tuner, copy & paste the results in a PasteBin and post the link to the PasteBin here. I'll be more than happy to look over it for you.

It'll also be helpful to see what the top output is. You can do this by running:


And then pressing shift m followed by c on your keyboard. That'll sort the processes by RAM usage and expand the commands / processes. You can then select (copy) and paste that in to the PasteBin as well.


To expand on the "used" RAM above, simply because I've "used" 1.9GB out of the 2GB I've been allocated does not mean that I've used that much. The 1.6GB's from the cache column is included in that 1.9GB's, so my actual usage is only ~300MB. The other 1.3GB is cached and used by current processes until they are either stopped, killed or restarted.

This particular Droplet does not have a swap allocation, which is why swap reports all 0's.

  • @jtittle thank you.

    When / If it times out again, i'll get the report to you, thanks again... much appreciated.

    • @mosaic - No problem, though I wouldn't wait if this has been a recurring issue. As long as MySQL has been running for at least 24 hours, the output from MySQL Tuner will be valid. Ultimately, finding out what the issue is now would be better than waiting until you install another plugin, a heavier theme, or simply see increased traffic.

      Like PHP-FPM, when you restart MySQL, the cache is wiped, thus you start from square one all over. Queries will be cached as they are called (if query caching is enabled -- by default, on most configurations, it's not), though it's best to simply keep a running cache (where and when possible) with as few interrupts as possible.

      The process of testing various configurations will take a little time as well as, unless the new configuration immediately results in MySQL crashing, we'll need to wait 24 hours on each update.

      • I have noticed that the company's staff (50+ employees) emails had a piece of code in the footer that was referencing icons that were on their old server, which were not actually on the new server which resulted in 1000's of calls a minute.

        I copied these files to the server and the memory dropped considerably. They are also changing their email footer so that it doesn't not make a call to the website every time an email is opened.

I have the same problem and tried a number of suggestions, including upgrading to a 1GB droplet, adding a swap file etc.. same problem.

I ended up creating an account here , transferred a copy of my site and it cleared up the problem, improved the performance dramatically and provided us with 24/7 support. This is one of those things where you get what you pay for.

I had the same issue, identical droplet size. It was an XML-RPC attack (Wordpress related).

Check this article for help:
How To Protect WordPress from XML-RPC Attacks on Ubuntu 14.04

WordPress is a popular and powerful CMS (content management system) platform. Its popularity can bring unwanted attention in the form of malicious traffic specially targeted at a WordPress site. There are many instances where a server that has not been protected or optimized could experience issues or errors after receiving a small amount of malicious traffic. This guide will show you how to protect WordPress from XML-RPC attacks on an Ubuntu 14.04 system.
Have another answer? Share your knowledge.