How Much RAM Do You Need for a Small Postgres Server?
Some links on this page are affiliate links. If you sign up through them we may earn a commission at no extra cost to you. We only link to services we have actually used, and commission never decides what we recommend.
You already picked a VPS, installed Postgres, and now free -h shows swap creeping up while queries crawl. Or you are one click from buying a tier and guessing. Either way the question is the same: how much RAM does this thing actually need, and what breaks first if you get it wrong.
Quick verdict
For a small production Postgres — a few hundred MB of data, a handful of app servers, under a hundred concurrent connections — 2 GB is the floor and 4 GB is where you stop thinking about it. Buy 2 GB if the dataset is small and read-mostly; buy 4 GB if you have writes, background jobs, and a connection pooler you have not tuned yet. The tradeoff that matters: extra RAM buys you headroom for bad queries, and headroom for bad queries is how bad queries survive for two years. Size for your working set, then fix the queries.
What you are actually choosing between
| Option | Cost and ops shape | Ceiling and lock-in |
|---|---|---|
| 1 GB VPS | Cheapest tier; you own everything | Fine for a dev box or a read-only replica of a tiny dataset; one bad ORDER BY and the OOM killer decides your uptime |
| 2 GB VPS | Low monthly cost, still self-managed | The realistic minimum for a small app with a connection pooler; leaves roughly half the box for the OS page cache |
| 4–8 GB VPS | Mid tier; same ops burden as 2 GB | Comfortable for small production, room for pg_dump, vacuum, and a second app process on the same box |
| Managed Postgres | Premium; backups, patching, failover included | Higher ceiling on paper, but you lose control of postgresql.conf tuning and pay per GB of RAM forever |
| Dedicated or bare metal | Mid to premium; more ops work | Highest ceiling per euro, worst fit if you are a one-person shop without a spare machine |
The 1 GB row is where most people start and where most people get burned. Postgres itself will start happily on 1 GB. It will not stay happy once autovacuum, a pg_dump, and your app's connection burst overlap.
Step by step
1. Find out what is actually consuming memory now. Before you buy anything, look at the box you have.
free -m
ps aux --sort=-rss | head -20
sudo -u postgres psql -c "SELECT sum(blks_hit)*100.0/sum(blks_hit+blks_read) AS cache_hit_pct FROM pg_stat_database;"
If free -m shows swap in use and ps shows postgres processes at the top, you are memory-bound. If swap is zero and the cache hit ratio is above roughly 99%, you are not memory-bound and more RAM will not help. That distinction saves people money every week.
2. Set shared_buffers to about 25% of RAM. This is the documented starting point and it holds up. On a 2 GB box that is 512 MB; on 4 GB, 1 GB. Do not go past 40% — the OS page cache needs room, and Postgres relies on it for the second copy of your data.
3. Cap max_connections and put a pooler in front. This is the step people skip, and it is the one that causes the failure they hit next. Each backend is a process with its own memory footprint plus whatever work_mem it allocates per sort or hash node. Default max_connections is 100; if your app opens 80 of those and each runs a query with three sorts, your work_mem budget multiplies by 240.
# postgresql.conf — 4 GB box, small app
shared_buffers = 1GB
max_connections = 40
work_mem = 8MB
maintenance_work_mem = 256MB
effective_cache_size = 3GB
Put PgBouncer in transaction mode in front and let it hold the real connections. Your max_connections can then stay low while your app thinks it has hundreds.
4. Treat work_mem as a per-node budget, not a per-server one. The formula that keeps you out of trouble: work_mem × max_connections × average sorts per query should stay well under your free RAM. 8 MB with 40 connections is 320 MB worst case; 64 MB with the same connections is 2.5 GB and will get you OOM-killed on a 2 GB box. Start low, raise it only for the specific queries that spill to disk, using SET LOCAL work_mem in those sessions.
5. Set effective_cache_size honestly. It is a planner hint, not an allocation. Set it to roughly RAM minus shared_buffers, and the planner will correctly prefer index scans. Setting it too high makes the planner overestimate cache hits; too low and it avoids indexes it should use.
6. Leave the rest for the OS. On a 2 GB box, budget roughly 512 MB for shared_buffers, a few hundred MB for backends and the pooler, and let the remainder be page cache. Add your app process, your reverse proxy, and the monitoring agent to that budget before you decide the tier is big enough.
7. Pick the tier with that budget in hand, not before. This is where Hetzner is worth naming: their cloud instances give you a clean per-vCPU, per-GB ladder, and a 2 GB or 4 GB shared-vCPU instance is the honest default for a small self-managed Postgres. The catch is that shared vCPU means noisy neighbours on the host, and their block storage is network-attached, so watch iostat wait times as well as RAM. If you want to skip the tuning work entirely, a managed Postgres at a premium is the right call — you are buying the absence of postgresql.conf, not performance.
8. Verify after a week, not after an hour. Re-run the free -m and cache-hit check under real load. Look for swap growth during your nightly backup window specifically — that is when pg_dump competes with the page cache and where undersized boxes fall over first.
Where this falls short
Adding RAM is the most expensive way to fix a slow query. If your cache hit ratio is already high and queries are still slow, you have a missing index, a stale ANALYZE, or table bloat — none of which care how much memory you bought. Check pg_stat_statements before you check your credit card.
The 2 GB recommendation breaks down in three specific cases. First, if your working set genuinely exceeds RAM, you will page and no amount of tuning fixes it; you need a bigger box or a read replica. Second, if you run anything else on the same host — Redis, a queue worker, Docker with a few containers — subtract that from the budget first, and 2 GB becomes 1 GB fast. Third, if you cannot use a pooler because your app relies on session state, your connection count drives your memory floor and you should size up.
Hetzner specifically: you are the DBA. There is no managed backup, no automatic minor-version patching, no failover. Shared-vCPU instances have variable performance that shows up as unexplained latency spikes, and if you need consistent IOPS you are looking at their dedicated or volume-backed options instead. Their support is ticket-based and not a substitute for knowing how to restore from pg_dump. That is the trade for the price, and it is a fair trade only if you actually do the backups.
Finally, if this database is the thing your business cannot lose for an hour, stop reading VPS sizing guides and buy managed Postgres. The RAM question is the easy part; the recovery question is the one that costs you a weekend.
FAQ
Is 1 GB of RAM enough to run Postgres?
It runs, and for a development box or a tiny read-mostly dataset it is fine. In production it leaves no room for autovacuum, backups, and connection bursts to overlap, and the OOM killer does not send a polite warning. Treat 1 GB as a test tier.
Does Postgres use all the RAM I give it?
Not directly. shared_buffers is a fixed allocation, and the rest of your data lives in the OS page cache, which grows to fill free memory and looks alarming in free output. High "used" memory with zero swap is normal and healthy.
How much RAM does each Postgres connection need?
There is no fixed number. Each backend is a process with a small baseline, plus up to work_mem per sort or hash node in the query it is running. That is why connection count and work_mem have to be sized together, and why a pooler changes the arithmetic.
Will more RAM make my queries faster?
Only if they were waiting on disk. If your cache hit ratio is already near 100%, extra RAM does nothing and the bottleneck is CPU, locks, or a bad plan. Measure first, then buy.
Related reading: Cheap VPS Providers for Discord Bot Hosting: A Shortlist That Actually Stays Up, How to Host a Discord Bot on a VPS: systemd, Swap, and the Parts
Bottom line
For a small self-managed Postgres, 2 GB is the honest floor and 4 GB is the tier where you stop worrying. Set shared_buffers to a quarter of RAM, keep max_connections low behind a pooler, and treat work_mem as a per-query cost rather than a server-wide setting. If you want to skip all of that, pay for managed Postgres and get the backups with it.
Today: run free -m and the cache-hit query on your current box. If swap is zero and the hit ratio is high, you do not have a RAM problem — go look at pg_stat_statements instead. If swap is climbing, size the budget from step 6 and move up one tier.
Try Hetzner
Include as an honest non-affiliate option so the site is not a pure ad wall.