Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Cloud and hosting

How to size a VPS for a database: RAM, disk and CPU

Size a VPS for PostgreSQL, MySQL, MariaDB or MongoDB: measure hot data, disk latency and connections first, then choose RAM, NVMe and vCPUs.

CloudSat teamNovember 18, 20268 min read
Abstract illustration of database cylinders resting on a balance scale opposite stacked memory and storage blocks
On this pageMeasure the workload you already have

Most database servers get sized backwards: someone picks a plan, waits for the first slow page, then doubles everything. A database has three appetites, and all of them can be measured before you buy: memory for the data it reads often, storage that confirms writes quickly, and CPU for the queries running at the same moment. Measure those on the system you already have, size in that order, and choosing a plan becomes arithmetic. The queries below cover PostgreSQL, MySQL, MariaDB and MongoDB.

Measure the workload you already have

You need a few numbers: how big the data and indexes are, how much of that is read often, how many connections are open at peak, and how fast the write log grows. Run the queries during a busy hour, not on a quiet Sunday morning.

PostgreSQL

-- total size of the current database
SELECT pg_size_pretty(pg_database_size(current_database()));

-- the ten largest tables, indexes included
SELECT relname, pg_size_pretty(pg_total_relation_size(relid)) AS total
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC
LIMIT 10;

-- share of block reads served from shared_buffers
SELECT round(100.0 * sum(blks_hit) / nullif(sum(blks_hit) + sum(blks_read), 0), 2) AS hit_pct
FROM pg_stat_database;

-- connections now, and the configured ceiling
SELECT count(*) FROM pg_stat_activity;
SHOW max_connections;

-- WAL written since the last stats reset: run twice, an hour apart
SELECT pg_size_pretty(wal_bytes) FROM pg_stat_wal;

The hit percentage only counts PostgreSQL's own cache; a miss may still come from the OS page cache, so a low number is a reason to look closer, not proof of a busy disk.

MySQL and MariaDB

-- data plus index size per schema, in MB
SELECT table_schema,
       ROUND(SUM(data_length + index_length) / 1024 / 1024) AS size_mb
FROM information_schema.tables
GROUP BY table_schema
ORDER BY size_mb DESC;

-- logical reads versus reads that had to go to disk
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_read%';
SHOW GLOBAL STATUS LIKE 'Threads_connected';

Divide Innodb_buffer_pool_reads by Innodb_buffer_pool_read_requests. The smaller that fraction, the more of your hot data already fits in memory.

MongoDB

db.stats(1024 * 1024)   // dataSize, indexSize and storageSize in MB
db.serverStatus().wiredTiger.cache["bytes currently in the cache"]
db.serverStatus().wiredTiger.cache["maximum bytes configured"]
db.serverStatus().connections

Rerun them in three months to get a growth rate.

RAM: fit the hot data, not the whole database

The goal is not to hold the entire database in memory. It is to hold the working set: the rows and index pages that queries touch again and again. A large database whose users mostly read last month's orders can run well on modest memory, while a small one that reports scan end to end may not.

Indexes deserve first claim on memory. If the indexes behind your hottest queries fit with room to spare, most lookups never wait on storage. Then budget for connections. PostgreSQL's work_mem (4 MB by default) applies per sort or hash step, per connection, so a few hundred busy connections running complex queries can claim more than the main cache.

Each engine has one main memory setting, and its documentation gives a starting point:

Engine Main cache setting Documented starting point
PostgreSQL shared_buffers 25% of RAM on a dedicated server with 1 GB or more; going past 40% rarely helps, because PostgreSQL also relies on the OS page cache
MySQL and MariaDB (InnoDB) innodb_buffer_pool_size Up to 80% of RAM on a dedicated server, per the MySQL manual; MySQL's innodb_dedicated_server option picks 50% for 1 to 4 GB and 75% above 4 GB
MongoDB (WiredTiger) cacheSizeGB By default, the larger of 50% of (RAM minus 1 GB) or 256 MB; the filesystem cache uses free memory beyond that
Valkey and Redis maxmemory The whole dataset lives in RAM, and a write-heavy instance can use up to twice its normal memory while saving to disk

Those percentages assume the database is alone. If the app or a queue shares the machine, subtract their peak memory first.

Disk: latency first, capacity second

Every commit waits until the write-ahead log (PostgreSQL), the redo log (InnoDB) or the journal (MongoDB) is flushed to stable storage. So the time one small synced write takes matters more than headline throughput, which is why NVMe is the baseline for database work.

Test sync latency on a new server before you load data. PostgreSQL ships pg_test_fsync for exactly this (on Debian and Ubuntu it sits in the version's directory, so replace 18 with your major version), and iostat from the sysstat package works for any engine:

sudo -u postgres /usr/lib/postgresql/18/bin/pg_test_fsync -f /var/lib/postgresql/fsync-test.out
iostat -x 5 3

In iostat, r_await and w_await are the average wait per request and %util is how busy the device is. A large jump in w_await at peak means writes are queuing.

For capacity, add up more than the data itself:

  • data and indexes today, plus a year of growth at the rate you measured
  • WAL, binary logs or the oplog, which swell during bulk imports or when a replica falls behind
  • temporary files from big sorts and index builds
  • room for at least one local dump, if backups are written to the same disk before they leave it

Then keep a real margin. Databases do not degrade gracefully on a full disk: PostgreSQL shuts down when it cannot write WAL, and other engines start failing writes.

CPU: concurrency and query shape

A single query mostly runs on one core. PostgreSQL can spread large scans across parallel workers, but the typical web request (an index lookup, a join over a handful of rows) runs on one core from start to finish, and InnoDB behaves the same way. That gives a simple rule: many small concurrent queries need more cores, and a few heavy queries need faster cores. For the heavy-query profile, CloudSat's High Frequency VPS line runs on AMD Ryzen at 4.2 GHz or more, where single-core speed is the point.

Connections are the other half of CPU planning. Each PostgreSQL connection is its own operating system process, and max_connections defaults to 100. If the application opens hundreds of connections, put a pooler such as PgBouncer in front instead of raising the limit: a small pool of busy connections beats a crowd of idle ones competing for memory and CPU time.

Same server as the app, or its own?

One server is a reasonable start for a small application: no network hop, one machine to back up. Split them when the two start competing (the app's memory growth squeezes the database cache, or a deploy's CPU spike shows up as slow queries), or when you add a second application server behind a load balancer.

A separate database server listens on the network, so restrict who can reach it. Allow the port only from your application servers, and never leave 5432, 3306 or 27017 open to the internet:

sudo ufw default deny incoming
sudo ufw allow OpenSSH
sudo ufw allow from 198.51.100.20 to any port 5432 proto tcp
sudo ufw enable

When that traffic crosses a public network, require TLS as well: hostssl lines in PostgreSQL's pg_hba.conf, or require_secure_transport=ON in MySQL.

Starting points by workload

Workload What runs out first Where to start
Small app or CMS, data under a few GB Memory for the cache, and little else 2 to 4 GB of RAM, 1 or 2 vCPUs, database on the app server
Busy web app, data larger than RAM Memory for hot rows and indexes, then disk latency RAM sized to the hot set plus indexes, NVMe, its own server
Write-heavy events, logs or queues Sync latency and log volume The fastest storage you can get, generous room for WAL or binlogs
Reports over large tables CPU per query, memory for sorts More and faster cores, or a columnar engine such as ClickHouse or DuckDB
Valkey or Redis cache RAM Dataset size plus headroom for background saves

These are opening positions, not verdicts: your measurements tell you when to move down a row.

Watch the numbers, then resize

Size for today plus a margin, and let monitoring say when to move up. The signals that matter:

  • the cache hit ratio drifting down as data grows
  • w_await or r_await rising at peak, or iowait climbing in top
  • swap in use on a server that never needed it before
  • active connections close to max_connections
  • the data disk more than about four-fifths full

CloudSat servers can be resized to a bigger plan from the console, which makes starting one size smaller a reasonable bet.

FAQ

Should a database server have swap?

A small swap file is a safety net. During a spike it gives the kernel somewhere to put idle pages instead of letting the out-of-memory killer stop the biggest process, which is usually the database. Keep vm.swappiness low, for example 10, and treat regular swapping as a sign the server is undersized.

How much disk should I keep for backups?

If dumps are written locally before being shipped elsewhere, reserve room for at least one full dump. Compressed dumps skip index data and are usually far smaller than the live database, but measure yours. The real backup copy belongs on another machine or in object storage, because a backup on the database's own disk disappears with it.

Is a managed database better than a VPS?

A managed service takes over patching, backups, replicas and failover, and charges for that work. A database on a VPS costs less and gives full control over versions, extensions and settings, but those jobs become yours. If nobody will test restores or apply minor releases, managed is safer.

Should Valkey or Redis get its own server?

Not at first. A cache with a maxmemory limit and an eviction policy such as allkeys-lru sits fine next to the application. Move it out when its memory, or the spike during background saves, starts squeezing the main database.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.