Avi Meir
Avi Meir

Reputation: 1010

"Error establishing a database connection" after days of site running

I am running Wordpress on AWS (Ubuntu). and have a very weird issue, every few days the database crashes and I am getting the "Error establishing a database connection" message. When I restart it with

sudo service mysql restart

Everything works fine, until the next time it happens several days later.

Any idea what is going wrong?

Thanks

Upvotes: 1

Views: 300

Answers (1)

Milos Jakovljevic
Milos Jakovljevic

Reputation: 56

Are you using micro instance? If so, then you are probably running out of memory. The workaround is to create a swap as a file. This are the steps to do that:

sudo dd if=/dev/zero of=/swapfile1 bs=1024 count=524288
sudo mkswap /swapfile
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
sudo swapon /swapfile

Now edit /etc/fstab file, so that when you restart the system, swap can be mounted automaticaly.

sudo nano /etc/fstab

And add this in the file:

/swapfile swap swap defaults 0 0

To get better performance from swap file in AWS you need to do this too:

echo 0 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

Upvotes: 2

Related Questions