How to Tune MariaDB 11.x for a Low-Memory VPS (1-2GB RAM)

MariaDB ships with defaults written for servers with plenty of RAM. On a 1 to 2 GB VPS those defaults can swallow half the memory before WordPress or PHP-FPM even starts, and the first symptom is usually a site that slows to a crawl or a database that gets killed by the out-of-memory killer. The fix is not to buy a bigger VPS first. When you tune MariaDB low-memory VPS settings the right way, you cut the buffer pool to a size the box can afford, cap connections, and switch off features a small site never uses. This guide gives safe values for MariaDB 11.x on 1 to 2 GB of RAM, explains why each value is what it is, and shows how to check that the changes took effect.

Why MariaDB Eats RAM on a Small VPS

MariaDB uses RAM in several places at once. The InnoDB buffer pool caches table data and indexes, each connection gets its own sort, join, and read buffers, and the Aria engine keeps its own page cache for system tables. The performance schema tracks internal metrics in memory too. On a 4 GB server nobody notices. On a 1 GB VPS, a default install can reserve more memory than the box has, and Linux starts swapping or killing processes to cope.

The defaults are the first problem. A stock MariaDB 11.x install sets the InnoDB buffer pool to 128 MB, which sounds small, but the connection buffers are the quiet part. With max_connections at 151, a burst of traffic can push memory use far past the buffer pool. A WordPress site with a few plugins opens several connections per page load. Everything else on the box shares the same memory too: if MariaDB takes 600 MB and PHP-FPM takes 300 MB, a 1 GB server has nothing left for the operating system cache.

Check How Much Memory MariaDB Uses Now

Before you change anything, measure. Run free -h and look at the available column, since Linux counts disk cache as used. Then check MariaDB with ps aux | grep mariadbd and read the RSS column, which shows the real memory the process holds. On a quiet 1 GB VPS you will often see 300 to 500 MB here.

Inside MariaDB, run SHOW VARIABLES LIKE 'innodb_buffer_pool_size'; and SHOW VARIABLES LIKE 'max_connections'; to see the current values, then SHOW STATUS LIKE 'Threads_connected'; to see open connections. A small WordPress site usually shows fewer than 10, which tells you the default limit of 151 is far more than you need. The guide to install WordPress on a VPS with a LEMP stack shows the same services competing for the same memory, so these numbers are the baseline you are tuning against.

How to Tune MariaDB Low-Memory VPS Settings

Put the settings below in the [mysqld] section of your MariaDB config, usually /etc/mysql/mariadb.conf.d/50-server.cnf on Debian and Ubuntu. Back up the file first, then restart MariaDB with systemctl restart mariadb after editing.

[mysqld]
innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
innodb_log_buffer_size = 8M
max_connections = 25
key_buffer_size = 16M
aria_pagecache_buffer_size = 32M
performance_schema = OFF
skip-name-resolve
innodb_flush_log_at_trx_commit = 2

The mariadb innodb_buffer_pool_size setting is the big one, and 128 MB is the safe pick for a 1 GB VPS. It leaves room for PHP-FPM, Nginx, and the system while still caching the hot data of a small WordPress database, usually well under 100 MB. On a 2 GB VPS you can raise it to 256 MB. Keep the pool under a quarter of total RAM on a shared box. The log file size follows the pool: 32 MB is the usual quarter ratio, and the 8 MB log buffer is enough for the short transactions a blog or small shop produces.

Max connections at 25 sounds low next to the default of 151, but count what you actually use. A WordPress site with PHP-FPM running 5 to 10 workers opens a similar number of connections. A limit of 25 still leaves headroom for a traffic spike while capping worst case memory. Each extra connection can allocate sort and join buffers, so a high limit is an open door to memory exhaustion. This is where mariadb max_connections tuning pays off most: it limits the damage a traffic burst can do. The key buffer only matters for MyISAM tables, which modern WordPress barely uses, so 16 MB is plenty. Skip-name-resolve stops a reverse DNS lookup on every connection, and the flush setting at 2 writes the log to disk once per second instead of on every commit, trading a little crash safety for far fewer disk writes. A shop handling payments should keep the default of 1.

Aria and Logging: Small Settings That Free Real RAM

Aria is the storage engine MariaDB uses for its internal system tables, and it keeps its own page cache separate from InnoDB. The default of 128 MB is generous for tables that hold a few kilobytes of data. Setting aria_pagecache_buffer_size to 32 MB frees close to 100 MB, because system tables are tiny and rarely read. This is the easiest win in a low ram mariadb config.

The performance schema is a bigger saving. It collects detailed metrics about queries, locks, and waits, and holds that data in memory. On a 1 GB VPS it can eat 100 MB or more, and a small site owner almost never opens those tables, so setting performance_schema to OFF reclaims that memory. If you later need query analysis, turn it back on for a day and switch it off again.

How to Verify the New Settings Took Effect

Restarting MariaDB is not proof the settings applied. A typo can make MariaDB ignore a line, so verify every value after the restart. Run SHOW VARIABLES LIKE 'innodb_buffer_pool_size'; and confirm it returns 134217728, which is 128 MB in bytes. Do the same for max_connections, aria_pagecache_buffer_size, and performance_schema, which should read OFF.

Then watch memory for a day, not five minutes. Run free -h right after the restart and again after a full day of traffic. Check SHOW STATUS LIKE 'Threads_connected'; at peak traffic to confirm you stay well under the limit of 25. If connections keep climbing toward the cap, find the plugin or script opening them instead of raising the limit. Also check SHOW ENGINE INNODB STATUSG for the buffer pool hit rate. Above 95 percent means the 128 MB pool is doing its job.

Common Mistakes on a 1-2GB VPS

The most common mistake is setting the buffer pool too large. A 512 MB or 1 GB pool on a 1 GB VPS looks generous, but the moment PHP-FPM needs memory for a traffic spike there is nothing left, and the out-of-memory killer picks a victim, often MariaDB itself. Size the pool for the box you have, not the database you wish you had.

The second mistake is raising max_connections to fix a connection error without asking why connections are piling up. A plugin that opens a connection per request or a bot hammering wp-login.php will fill any limit you set. Fix the source, keep the limit low, and use a firewall or rate limit for the bots. The third mistake is running MariaDB beside a heavy PHP-FPM pool on a 1 GB box: 10 children at 50 MB each is 500 MB before MariaDB starts. Trim the PHP-FPM children to 3 to 5 for a small site, and use the ondemand process manager so idle workers exit. The web server matters too, and the comparison of choosing the right web server for a low-RAM VPS shows why Nginx is the usual pick when every megabyte counts.

What to Do When Tuning Is Not Enough

Tuning has a ceiling. If the buffer pool hit rate stays low after raising the pool to 256 MB, or if available memory still drops near zero at peak traffic, the site has outgrown the box. Before upgrading, check the cheap fixes. Turn off plugins you do not use. Add a page cache so Nginx serves repeat visitors without touching PHP or MariaDB. If the server still swaps under load, read the guide on adding swap to a VPS and add a small swap file as a safety net. Swap is a cushion for spikes, not a substitute for RAM.

When none of that is enough, the honest answer is a bigger VPS or a separate database server. The guide on how much RAM a WordPress VPS really needs lays out what each size of site uses in practice. Move up when the tuned 2 GB box still struggles, not before, and you will spend money on growth instead of on defaults you never fixed.

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.