PostgreSQL vs MySQL for a Self-Hosted App: Which Database Fits a Small VPS?

Picking a database for a self-hosted app on a 1 or 2 GB VPS feels harder than it should. PostgreSQL vs MySQL for a small VPS is not really a debate about which engine is better in general. It is a question about which one behaves well when RAM is scarce, disk is slow, and nobody is watching the server at 3 a.m. Both databases run fine on modest hardware, but they fail in different ways, and the right pick depends on what your app actually does.

PostgreSQL vs MySQL for a Small VPS: The Short Answer

If your app stores JSON, runs analytical queries, or needs strict data rules, pick PostgreSQL. If your app is a standard web app with simple reads and writes, a WordPress site, or a project where you want the lowest possible memory footprint, pick MySQL. That is the short version. The rest of this guide explains why, and what to tune either way, so the choice still holds up six months from now.

In a PostgreSQL vs MySQL self-hosted setup, the database shares the box with your app, your web server, and your backup jobs. There is no separate database server to absorb a bad query. That shared box is the whole story: the winner is the engine you can keep inside its memory budget without babysitting it.

What a Small VPS Actually Gives Your Database

A 1 GB VPS leaves roughly 600 to 700 MB for the database after the operating system and your app take their share. A 2 GB VPS roughly doubles that. Those numbers sound workable until a backup job, a traffic spike, or a runaway query arrives at the same time. On a small VPS, the database is not the only tenant, and every megabyte it grabs is a megabyte your app cannot use.

Disk matters too. Many cheap VPS plans still ship with shared SSDs or disk-backed storage with modest IOPS. A write-heavy app, like one behind a logging endpoint, will feel that limit long before it feels a CPU limit. Check your plan’s disk type before you blame the database for slow queries.

Memory: Where the Two Databases Differ Most

MySQL with InnoDB starts lighter. A tuned MySQL instance can run a small app in 300 to 400 MB of RAM. PostgreSQL starts heavier: each connection spawns its own process, and its default settings assume a server with far more memory than a small VPS offers. Out of the box, PostgreSQL on a 1 GB VPS can eat its memory budget before your app serves its first request.

That gap narrows with tuning. Lowering shared_buffers and work_mem brings PostgreSQL into line, and connection pooling closes most of the remaining gap. PostgreSQL on a small VPS needs a pooler like PgBouncer once you pass a handful of concurrent connections. Our guide to PostgreSQL connection pooling with PgBouncer on a small VPS walks through a setup that keeps connection counts flat while your app scales.

Our earlier test of MySQL vs PostgreSQL on a 2GB VPS found the same pattern: defaults decide the winner more than the engine does. Whichever you pick, budget an hour to tune it before you invite real users in.

Side by Side: PostgreSQL vs MySQL on a Small VPS

The table below compares the two engines on the points that matter most when the server is small. Treat it as a starting point, not a verdict: your workload can flip any single row.

Factor PostgreSQL MySQL
Memory footprint (tuned) Moderate; needs pooling past a few connections Lower; comfortable in 300–400 MB
JSON support JSONB with indexing, fast queries on document data JSON type exists, but indexing and querying are weaker
Complex queries Strong: CTEs, window functions, rich SQL Good for simple CRUD, weaker for analytics
Full-text search Built in, solid for small catalogs Built in, adequate for basic search
Backups pg_dump, logical or physical; easy to script mysqldump or Percona XtraBackup; easy to script
Replication Streaming replication, solid but hands-on Simple primary-replica setup, widely documented
Extensions PostGIS, pg_trgm, and many more Fewer extensions, plugin system instead
Best fit JSON-heavy apps, analytics, strict data rules WordPress, forums, read-heavy CRUD apps

Which App Fits Which Database

PostgreSQL suits apps that ask hard questions of their data. A self-hosted analytics dashboard, a small SaaS with reporting features, or an app that stores semi-structured JSON in the same tables as relational data will use features MySQL either lacks or does half-heartedly. JSONB columns with indexes, window functions for leaderboards, and PostGIS for location data are real reasons to pick PostgreSQL, not trivia.

MySQL suits apps that mostly read and write rows by key. WordPress, Ghost, forums, and simple storefronts fall here. MySQL on a small VPS rewards you with lower memory use and a huge pile of tutorials written for exactly your setup. If your app already ships with MySQL as its default, switching to PostgreSQL buys you nothing unless your queries actually need PostgreSQL features.

One more factor beats both lists: what your app already expects. If your framework, your ORM, or your existing code assumes one engine, switching costs more than the performance difference is worth. Mismatched drivers, subtly different SQL dialects, and migration bugs will eat more of your weekend than a slightly heavier database ever will.

Backups and Recovery on Limited Disk

Both engines back up with a single command. pg_dump writes a logical dump of a PostgreSQL database, and mysqldump does the same for MySQL. On a small VPS the risk is not the command, it is the disk: a dump of a 5 GB database needs 5 GB of free space, plus room for the compressed copy, plus room for the app to keep running. Schedule dumps for quiet hours and compress them on the fly instead of writing an uncompressed file first.

Test your restores. A backup you have never restored is a hope, not a backup. Once a month, restore the dump into a throwaway database on the same VPS and run a few queries against it. If the restore fails, you want to learn that on a quiet afternoon, not during an outage. Our comparison of Restic vs BorgBackup: which encrypted backup tool fits a small VPS covers getting those dumps off the server encrypted, which matters because a backup stored on the same disk as the database dies with it.

PostgreSQL has one edge here: point-in-time recovery through WAL archiving lets you roll back to a minute before a bad delete. MySQL can do the same with binary logs, but the setup takes more steps. For most small apps, a nightly logical dump plus an off-site copy is enough.

Tuning That Matters on 1–2 GB of RAM

Defaults are written for servers with 8 GB or more. Change these four settings first and you fix most small-VPS database pain.

For MySQL, the big one is innodb_buffer_pool_size. On a 2 GB VPS where the app and database share the box, 512 MB to 1 GB is a sane range. Set it higher and the operating system starts swapping, which is slower than any query plan fix. Also set innodb_log_file_size to 128 MB and turn on the slow query log for a week so you can see which queries actually hurt.

For PostgreSQL, set shared_buffers to 128 MB on a 1 GB VPS or 256 MB on a 2 GB VPS, and keep work_mem low, around 4 MB. High work_mem looks harmless until ten connections run sorts at once and the server runs out of memory. A minimal tuned snippet for a 2 GB box looks like this:

shared_buffers = 256MB
effective_cache_size = 1536MB
maintenance_work_mem = 64MB
work_mem = 4MB
max_connections = 40

Restart the database after changing these, then watch memory for a day under real traffic. If the server swaps, lower the numbers. If it never touches swap and queries feel slow, raise them a little at a time.

How to Decide in 10 Minutes

Answer three questions and the choice mostly makes itself. First, does your app need JSONB, window functions, or PostGIS? If yes, pick PostgreSQL. Second, is your app WordPress, a forum, or a simple CRUD app with a tight memory budget? If yes, pick MySQL. Third, does your app already assume one engine in its docs or its default config? Follow that, unless the first question points the other way.

If tuning and maintenance sound like more work than you want, the managed route is worth pricing before you commit to self-hosting either engine. Our managed MySQL vs self-hosted MySQL cost comparison and our Aiven vs self-hosted PostgreSQL pricing breakdown both put real numbers next to the DIY option, so check official pricing before deciding.

Install the one your app already expects, tune it with the numbers above, and set up an off-site backup before you invite real users in. The engine matters less than the setup around 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.