Databases13 min read•Updated November 2026

How to Tune MySQL and PostgreSQL Performance on a VPS

Quick answer

Give the database enough memory to cache its working set: for a dedicated server, set MySQL/MariaDB innodb_buffer_pool_size to roughly 50–70% of RAM, or PostgreSQL shared_buffers to about 25% of RAM with effective_cache_size around 50–75%. Keep max_connections modest and use connection pooling. Then turn on the slow query log, run EXPLAIN on the slowest queries and add the indexes they need; this usually gives the biggest gains. Use NVMe storage and avoid swapping.

Default database settings are deliberately conservative so they run on any machine. On a VPS with several GB of RAM, a few changes let the database use the memory you are paying for. But configuration is only half the story: most real-world slowness comes from queries and missing indexes, which no setting can fix. This guide covers both, for MySQL/MariaDB and PostgreSQL.

Step 1: Measure Before Changing Anything

  • Note current response times for key pages and queries.
  • Check memory with free -h and swap activity with vmstat 5.
  • Check disk latency with iostat -x 5.
  • Record the current configuration so you can roll back.

Change one thing at a time and measure again. Tuning by copying settings from the internet without measuring often makes things worse.

Step 2: Plan the Memory Budget

The database shares RAM with the OS, the application and its workers. On a server that runs everything, leave room for them first; on a dedicated database server, the database can take most of the memory.

ServerMySQL/MariaDB buffer poolPostgreSQL shared_buffers
8 GB, app + database together2–3 GB1–2 GB
16 GB, app + database together5–7 GB3–4 GB
32 GB, dedicated databaseabout 20–22 GBabout 8 GB

These are starting points. The aim is no swapping and as much of the frequently used data in memory as possible.

Step 3: MySQL / MariaDB Settings

# /etc/mysql/mysql.conf.d/tuning.cnf  (MariaDB: /etc/mysql/mariadb.conf.d/)
[mysqld]
innodb_buffer_pool_size = 6G
innodb_log_file_size = 1G           # MySQL 8.0.30+: use innodb_redo_log_capacity instead
innodb_flush_method = O_DIRECT
innodb_file_per_table = 1
max_connections = 150
tmp_table_size = 64M
max_heap_table_size = 64M
slow_query_log = 1
long_query_time = 1

Restart and verify the values with SHOW VARIABLES LIKE 'innodb_buffer_pool_size';. The buffer pool hit rate tells you whether it is large enough: compare Innodb_buffer_pool_reads (disk reads) with Innodb_buffer_pool_read_requests in SHOW GLOBAL STATUS; disk reads should be a tiny fraction.

The query cache was removed in MySQL 8.0; on MariaDB it is usually best left disabled for write-heavy workloads.

Step 4: PostgreSQL Settings

# postgresql.conf (or a file in conf.d), example for a 16 GB shared server
shared_buffers = 4GB
effective_cache_size = 10GB      # planner hint: memory available for caching incl. OS cache
work_mem = 16MB                  # per sort/hash operation, per query node
maintenance_work_mem = 512MB
max_connections = 100
random_page_cost = 1.1           # SSD/NVMe storage
effective_io_concurrency = 200   # SSD/NVMe storage
log_min_duration_statement = 1000

Be careful with work_mem: one complex query can use it several times, across many connections, so large values can exhaust memory. Most settings apply after a reload (SELECT pg_reload_conf();); shared_buffers and max_connections need a restart.

Enable the pg_stat_statements extension to see which queries use the most total time; it is the most useful single tool for PostgreSQL tuning.

Step 5: Connections and Pooling

Each connection uses memory, and PostgreSQL in particular uses a process per connection. Hundreds of mostly idle connections waste resources. Keep max_connections moderate and pool connections in the application, or use PgBouncer for PostgreSQL and ProxySQL for MySQL when many processes connect. Match application worker counts to what the database can serve.

Step 6: Find and Fix Slow Queries

This is where most of the gains are.

# MySQL: summarise the slow log
sudo mysqldumpslow -s t /var/log/mysql/mysql-slow.log | head -40

-- PostgreSQL: top queries by total time
SELECT query, calls, total_exec_time, mean_exec_time
FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 10;

For each slow query, look at the plan:

EXPLAIN ANALYZE SELECT ... ;    -- PostgreSQL, and MySQL 8.0.18+
EXPLAIN SELECT ... ;             -- MySQL/MariaDB

Full table scans (Seq Scan on large tables in PostgreSQL, type: ALL in MySQL) on queries that filter or join usually mean a missing index:

CREATE INDEX idx_orders_customer_created ON orders (customer_id, created_at);
-- PostgreSQL on a busy table: CREATE INDEX CONCURRENTLY ...

Put equality columns first in composite indexes, then range or sort columns. Do not index everything: each index slows writes and uses memory. Also look for the application-side causes: N+1 query patterns, SELECT * on wide tables and missing pagination.

Step 7: Routine Maintenance

  • PostgreSQL: autovacuum keeps tables healthy; leave it on and check that it keeps up on large, busy tables.
  • MySQL: ANALYZE TABLE after large data changes refreshes statistics.
  • Remove unused indexes; both databases can report index usage.
  • Archive or delete old rows from log and event tables that grow forever.

Step 8: Operating System and Storage

  • Avoid swapping: a database that swaps becomes very slow. Lower vm.swappiness (for example to 10) and size memory settings correctly (see our swap guide).
  • Use NVMe SSD storage: random I/O latency matters far more to databases than raw capacity.
  • Keep free disk space: at least 20%, for temporary files, vacuum and backups.
  • Cache in front: Redis for repeated reads and sessions takes load off the database (see our Redis guide).

SkyRainCloud Plans for This Workload

Database performance depends most on RAM for caching and on fast storage. A dedicated database server on the 8 vCore / 32 GB tier keeps a large working set in memory; small applications sharing a server with their database start at 2 vCores / 8 GB.

AMD EPYC 7C13 VPS

Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — AMD28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthWebsites, small APIs, bots, staging and VPN serversOrder
VPS 2 — AMD416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,299/monthWooCommerce, Node.js/Python backends, Docker Compose stacks, CI runnersOrder
VPS 3 — AMD832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,499/monthProduction databases, high-traffic sites, multi-container appsOrder
VPS 4 — AMD1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,899/monthLarge production workloads, SaaS platforms, analytics, in-memory cachesOrder

Intel Xeon Platinum 8269CY VPS

KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — Intel28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthBusiness websites, small apps, scheduled jobs and botsOrder
VPS 2 — Intel416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,169/monthBusiness software, mid-size databases, several sites on one serverCheck stock
VPS 3 — Intel832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,249/monthERP/CRM stacks, heavier databases, multiple production appsCheck stock
VPS 4 — Intel1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,299/monthHigh-memory workloads and consolidated production serversCheck stock

Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.

Frequently Asked Questions

What is the most important MySQL setting?
innodb_buffer_pool_size. It controls how much data and index pages InnoDB keeps in memory; around 50–70% of RAM on a dedicated database server is a common starting point.
What should shared_buffers be in PostgreSQL?
About 25% of RAM on a dedicated server is a common starting point, with effective_cache_size around 50–75% of RAM, because PostgreSQL also relies on the OS file cache.
Why is my database slow even after tuning?
Most slowness comes from queries: missing indexes, N+1 patterns or scanning large tables. Use the slow query log or pg_stat_statements and EXPLAIN to find them.
How many connections should I allow?
As few as your workload needs. Use connection pooling in the application or PgBouncer/ProxySQL rather than raising max_connections into the hundreds.
Is work_mem safe to increase?
Moderately. It applies per sort or hash operation per connection, so a large value multiplied by many queries can exhaust memory.
Should the database run on the same VPS as the app?
For small and medium apps, yes, with a memory budget for both. Move it to its own server when they compete for RAM or CPU.
Does SSD vs NVMe matter for databases?
Yes. Databases do many small random reads and writes; NVMe has much lower latency, which shortens query times when data is not in memory.
Should I add indexes to every column?
No. Index the columns used in frequent filters, joins and sorts. Every index slows writes and uses memory.
Is there a tool to suggest settings?
Tools such as MySQLTuner and PGTune suggest starting values from your RAM and workload. Treat them as starting points and measure.
Which SkyRainCloud plan suits a database server?
A dedicated database fits well on the 8 vCore / 32 GB AMD EPYC or Intel VPS; smaller apps sharing a server start at 2 vCores / 8 GB, all on NVMe storage.
Instant UPI • ₹649/mo
Fast KVM Cloud Provisioning