Help Running your server Care and troubleshooting
Add a swap file
Give the server a cushion of disk-backed memory, so a short spike slows it down instead of stopping a program.
Swap is disk space the server uses when memory is full. It's far slower than memory, so it's a cushion, not more memory: a short spike slows the server instead of the kernel stopping your database.
Check what you have#
swapon --showfree -hIf swapon prints nothing, and the Swap: line in free says 0B, there's no swap.
Make a swap file#
1 or 2 GB is plenty for most servers. Check there's room with df -h /, then make a 2 GB file:
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048 status=progressOnly root may read it, as it can hold anything that was in memory:
sudo chmod 600 /swapfileFormat it as swap, and turn it on:
sudo mkswap /swapfile && sudo swapon /swapfileTurn it on at every boot too:
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabCheck it worked:
swapon --showUse it only when needed#
Swappiness is how keen the server is to use swap. The default, 60, starts early; 10 keeps programs in memory until it really runs short:
echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-swappiness.confsudo sysctl --systemIs swap being used a lot?#
A little swap used is normal. Watch it for a few seconds:
vmstat 2 5si and so are memory moving in from and out to swap. Above zero all the time means the server is short of memory, which swap can't fix: find what's using it or upgrade your plan.
Remove it#
sudo swapoff /swapfile && sudo rm /swapfileThen delete the /swapfile line from /etc/fstab (sudo nano /etc/fstab).
Still stuck? Open a ticket and say which guide you followed.