How to Optimize InnoDB Buffer Pool Size for a 2GB VPS

On a 2GB VPS, the single most effective MySQL setting you can change is the InnoDB buffer pool size. This one number decides how much of your database MySQL keeps in RAM instead of reading from disk on every query. Set it too small and every page load waits on slow disk reads. Set it too big and MySQL starts fighting PHP-FPM and the operating system for memory, which ends in swap, stalls, or a killed database process.

What the InnoDB Buffer Pool Size Actually Controls

The InnoDB buffer pool is a chunk of RAM where MySQL caches table data and indexes. When a query needs a row, MySQL checks the pool first. If the row is already there, the query answers from memory. If it is not, MySQL reads the page from disk, loads it into the pool, and only then answers, and that disk read is the slow path.

So the InnoDB buffer pool size sets the size of that cache. A bigger pool means more of your hot data stays in memory and fewer queries touch disk. It does not speed up bad queries or fix missing indexes. It removes disk waits from queries that are already reasonable, and owners who raise the pool expecting a broken query to heal end up disappointed.

How Much RAM Is Really Free on a 2GB VPS

A 2GB VPS does not give MySQL 2GB. The operating system takes a few hundred megabytes, Nginx takes a little, and PHP-FPM is the other big consumer: each worker holds tens of megabytes, and a busy WordPress site can run ten or more at once. If you want a reliable starting point, measure first instead of guessing.

Run free -m while the site is under normal traffic and look at the available column, not the free column. Available counts memory the system can hand out without swapping, which is the number that matters. In practice that leaves roughly 700MB to 1GB for MySQL, and that is the budget your buffer pool has to fit inside. PHP-FPM worker count matters here too, since the two settings compete for the same RAM. Our guide to tuning PHP-FPM on a 2GB VPS walks through sizing workers so the web server and the database stop fighting each other.

A Safe Starting Point for a 2GB VPS

For a typical 2GB VPS running a website stack, start with 512MB. If the server runs only MySQL and a light web stack, and your database is small, 768MB can work. Going to 1GB is possible when the database is the main workload and PHP-FPM is tightly limited, but it leaves little headroom, so treat it as a ceiling rather than a default. The well-known 70 to 80 percent rule applies to a dedicated database server, not to a box that also runs a web server, and applying it here is how small VPS setups end up swapping.

Server workload Starting pool size Why
WordPress + PHP-FPM + Nginx 512MB Leaves room for PHP workers and the OS
Light stack, small database 768MB More cache, still leaves headroom
MySQL is the main workload 1GB Maximum sensible size; limit PHP-FPM workers
Database larger than 1GB 1GB Cache the hot data, not the whole database

Notice the last row. A pool does not need to hold your entire database. It needs to hold the data your site actually reads: recent posts, active sessions, the tables behind your most-visited pages. A 3GB database on a 2GB VPS still runs fine when the hot working set fits in 512MB to 1GB. If you want the longer version of the reasoning behind these numbers, our practical rule of thumb for buffer pool sizing on small VPS covers the same trade-offs in more depth.

How to Change innodb_buffer_pool_size

Since MySQL 5.7, innodb_buffer_pool_size is a dynamic variable, so you can change it without restarting MySQL. But a change made only with SET GLOBAL disappears at the next restart, so always write it into the configuration file as well. That is the step people skip, and it is why a tuned server quietly reverts to the 128MB default after a reboot.

Check the current value first:

mysql -u root -p -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';"

The value comes back in bytes, so 134217728 means 128MB. Next, edit the MySQL configuration file, usually /etc/mysql/my.cnf or a file under /etc/mysql/mysql.conf.d/, and add the setting under the [mysqld] section:

[mysqld]
innodb_buffer_pool_size = 512M
innodb_buffer_pool_instances = 1

Keep innodb_buffer_pool_instances at 1 for a pool of 1GB or less. Splitting a small pool into several instances adds overhead without benefit. Then apply the change live:

mysql -u root -p -e "SET GLOBAL innodb_buffer_pool_size = 512*1024*1024;"
sudo systemctl restart mysql

The restart is not strictly needed for the resize itself, but it confirms the configuration file loads cleanly. If MySQL fails to start after your edit, the file has a typo or an invalid value, and you want to find that out now, not during the next unplanned reboot. After the restart, verify the value stuck:

mysql -u root -p -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';"

If you are tuning several MySQL settings at once rather than just the pool, the MySQL 8.4 tuning settings that help on a 2GB VPS lists the other values worth adjusting alongside it, with the same low-memory mindset.

How to Tell If the Size Is Right

Do not judge the pool by feel. MySQL keeps counters that show exactly how well it is working. Run this after the server has been up for at least a few hours under normal traffic, so the pool has had time to warm up:

mysql -u root -p -e "SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_read%';"

Two numbers matter. Innodb_buffer_pool_read_requests counts logical reads served from the pool. Innodb_buffer_pool_reads counts reads that had to go to disk. The MySQL buffer pool hit rate is (1 - reads / read_requests) * 100. Above 99 percent is healthy for most small sites. Between 95 and 99 percent is workable but worth watching. Below 95 percent means the pool is too small for the working set, and raising it is likely to help, provided the RAM is actually free.

Watch for swap as well. Check with free -m or vmstat 1: any sustained swap activity after a pool increase means you overshot and should step back down. A pool that looks fine in the hit rate but starves the rest of the system is not a good setting, it is a crash waiting for a traffic spike. That is the heart of mysql buffer pool tuning on a small server: the best size is the largest one that never makes the system swap.

Three Mistakes That Take a Small VPS Down

The first mistake is copying a setting from a bigger server. A guide written for a 16GB dedicated database box will tell you to use 12GB of pool. That number on a 2GB VPS guarantees the out-of-memory killer will visit. Always scale the advice to the RAM you actually have.

The second mistake is forgetting connection count. Each MySQL connection carries its own buffers, and a WordPress site under a traffic spike or a bot crawl can open dozens of connections at once. A 1GB pool plus fifty connections with large sort and join buffers can push total MySQL memory well past what the server has. If you see connection errors after tuning, the pool is only one suspect. Our guide to fixing the MySQL too many connections error explains how to check whether connections or the pool is the real problem.

The third mistake is setting the pool and never checking it again. Databases grow, and a pool that fit a 300MB database six months ago may be too small for the same site at 900MB. Re-check the hit rate every month or two, or after any big content import, and adjust in 128MB or 256MB steps. Small steps make it easy to tell which change helped and which one caused the swap.

When to Raise the Pool, and When to Leave It Alone

Raise the pool when the hit rate sits below 95 percent, free RAM is available, and the database keeps growing. Raise it in small steps and re-check the hit rate and swap usage after each one. Leave it alone when the hit rate is already above 99 percent, because extra cache for data nobody reads buys nothing. Leave it alone too when the real problem is a missing index or a slow query, which you can spot in the slow query log.

On a 2GB VPS the goal is not the biggest pool you can set. It is the biggest pool that leaves the rest of the server breathing room. Start at 512MB, measure the hit rate, watch for swap, and only then decide whether the next step up is worth it.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.