← Back to Blog

What No One Tells You Before Buying a VPS Server

By Aya AlatrashFounder of ParkGuard Security System

I recently purchased a VPS server and deployed my ParkGuard system. Everything was running smoothly—until users suddenly couldn't log in.

My first instinct was to check the system logs:

journalctl
Journalctl logs showing MySQL failure
Screenshot of journalctl logs

The logs indicated that MySQL was failing to start. To get more details, I checked its status:

sudo systemctl status mysql
MySQL systemctl status showing OOM killer
Screenshot of MySQL service status

The output revealed that the Linux kernel had terminated the MySQL process due to an Out of Memory (OOM) condition. In other words, the server had run out of RAM, and the kernel's OOM killer stepped in to free memory by killing running processes.

At that point, the real issue became clear: the VPS had no swap space configured.

What Is Swap?

Swap is disk space that the Linux kernel uses as an overflow area when physical RAM becomes full. Since disk storage is significantly slower than memory, the kernel keeps frequently accessed data in RAM and moves less frequently used memory pages to swap when necessary.

While swap is not a replacement for RAM, it provides a safety net that can prevent your system from crashing during temporary memory spikes.

Fortunately, enabling swap is quick and straightforward.


Step 1: Check Whether Swap Already Exists

First, verify whether your system already has an active swap area. Run:

sudo swapon --show

If the command produces no output, there is currently no active swap. You can also confirm using:

free -h

If the Swap row shows 0B for total, used, and free, your system has no active swap configured.


Step 2: Create a Swap File

Create a swap file of your desired size. For example, to create a 1 GB swap file:

sudo fallocate -l 1G /swapfile

You can replace 1G with any size that fits your server's requirements and choose a different filename if desired.


Step 3: Enable the Swap File

Since swap may temporarily contain sensitive information from memory, restrict its permissions so only the root user can access it:

sudo chmod 600 /swapfile

Format the file as swap:

sudo mkswap /swapfile

Enable it:

sudo swapon /swapfile

Verify that it's active:

free -h

or

sudo swapon --show

Step 4: Make the Swap Persistent

Without adding the swap file to /etc/fstab, it will not be enabled automatically after a reboot.

Back up your fstab file:

sudo cp /etc/fstab /etc/fstab.bak

Then edit it:

sudo nano /etc/fstab

Add the following line to the end of the file:

/swapfile none swap sw 0 0

Save the file (Ctrl + O, then Enter) and exit (Ctrl + X).


Final Thoughts

A missing swap file is an easy detail to overlook when setting up a new VPS, but it can have a significant impact on system stability.

Keep in mind that swap is not a substitute for sufficient RAM. If your applications are constantly using swap, it's a sign that your server likely needs more memory. However, configuring swap provides an important safety net that can prevent services like MySQL from being terminated during temporary memory spikes.

If you're deploying applications on a fresh Linux VPS, checking whether swap is configured should be one of the first items on your setup checklist. It might save you hours of troubleshooting later.