Compute. Storage. Backup retention.
The snapshot export you forgot about. The egress charge from the staging atmosphere that ran a ‘pg_dump’ final Tuesday.
No one opens their managed-database bill anticipating it to be low-cost.
However, dang.
The hole between “Postgres for $25 a month” and what reveals up on the cardboard has gotten broad, and a 4 GB VPS on the value of a single Supabase add-on now runs your entire database with room to spare for the OS to cache scorching pages.
Self-hosting a manufacturing Postgres database isn’t the operational nightmare it as soon as was. The PostgreSQL International Growth Group (PGDG) repo is strong; fashionable PostgreSQL installations (v14+) default to SCRAM-SHA-256 password encryption, with legacy MD5 formally deprecated as of v18. The explanations folks keep on RDS, Supabase, or Neon in the present day are operational, not technical.
We’re speaking about precise invoices, precise operational overhead, and what fashionable Postgres internet hosting actually seems to be like.
How A lot Does It Truly Value to Self-Host PostgreSQL on a VPS?
Self-hosted PostgreSQL on a 4 GB VPS generally runs at a fraction of equal RDS, Supabase Professional, or Neon Scale pricing as soon as storage, backups, and egress are stacked into the managed invoice.
PostgreSQL is the database 55.6% of builders use, in line with Stack Overflow’s 2025 Developer Survey, the preferred for the previous two years operating. It’s additionally the database you’ll be able to comfortably run your self.
Comparability for a consultant small-team workload (4 GB RAM, ~100 GB information, low-to-moderate write load, single area), priced as of Might 2026:
| Choice | Compute | Storage | Egress previous the free tier | Finest for |
|---|---|---|---|---|
| Self-hosted on a 4 GB VPS | Flat plan value | Often included | Often unmetered or high-cap | Regular workloads, cost-sensitive groups snug with Linux |
| AWS RDS db.t4g.medium | $47.45/month compute-only | ~$0.115/GB-month gp3 | ~$0.09/GB web/out-region | Groups that need managed backups, failover, and AWS-native ops |
| Supabase Professional | $25/month base + utilization | $0.125/GB database disk past the 8 GB included | $0.09/GB previous 250 GB | Apps that want Postgres, auth, storage, and real-time in a single stack |
| Neon Scale | $0.222 per CU/hour | $0.35 per GB/month | Utilization-metered | Spiky, preview-heavy, branch-heavy improvement workflows |
The RDS db.t4g.medium on-demand value is roughly $0.065 an hour, or about $47.45 a month for compute alone.
Add 100 GB of gp3 storage at roughly $0.115/GB-month and automatic backups, and a Single-AZ field lands close to $60/month. Activate Multi-AZ failover and the compute line roughly doubles, pushing a production-grade configuration to $100/month and up.
That’s not a small hole.
Self-hosting is cheaper as a result of you do the work that the managed invoice was paying for. Ops self-discipline, on-call, at 2 a.m. when the disk fills. The managed-DB various you’re sizing towards could have a unique ground subsequent quarter, so run the maths towards your personal invoice earlier than committing.
When Does Self-Internet hosting PostgreSQL Make Sense?
Self-hosting PostgreSQL on a VPS is sensible when you have got fundamental Linux consolation on the workforce, a gradual workload, a predictable working-set measurement, and an actual cause to flee the managed invoice.
It doesn’t work when you don’t have any ops capability, regulated HA necessities you’ll be able to’t construct your self, or a bursty sample that advantages from immediate scale.
Three issues drive this choice. Value, privateness and information sovereignty, and management.
The place self-hosted wins cleanly:
- Regular visitors in a single area with a predictable working set.
- Small-to-medium SaaS apps with one Postgres database and a Linux-comfortable workforce.
- Privateness-sensitive workloads the place the database shouldn’t sit in another person’s tenancy.
- Value-conscious groups whose managed invoice has crept previous the operational trouble threshold.
The place managed wins cleanly:
- Bursty workloads that profit from immediate scale-up and scale-down.
- Multi-region setups the place world replication is the product.
- Regulated environments needing turnkey HA, compliance certs, and audit trails.
- Groups with no spare ops capability and no plan to construct it.
The 40% to 60% cost-savings quantity will get cited loads. Date it rigorously.
As of 2021, AWS creator Rupesh Desai documented PostgreSQL on EC2 operating 40% to 60% cheaper than RDS at equal specs, older than most present RDS occasion households.
The present model is byteiota’s cost-stack evaluation, printed in late 2025, which says RDS is 75% to 88% dearer than equal devoted {hardware}.
The trustworthy break-even is operational hours, not server value.
How Do You Decide the Proper VPS Measurement for PostgreSQL?
Most manufacturing utility databases run comfortably on 4 GB of RAM with NVMe storage. Bigger datasets, heavy concurrent connections, or analytics workloads push the requirement to eight GB or 16 GB and up.
RAM determines how a lot of your working set Postgres can maintain in reminiscence; as soon as scorching pages spill to disk, queries decelerate. NVMe issues as a result of Postgres is delicate to random-read latency for warm pages and to flush throughput for the write-ahead log.
Widespread PostgreSQL tuning steering begins with:
shared_buffersat roughly 25% of system RAM.effective_cache_sizeat roughly 50%-75% of system RAM.work_memsized conservatively — based mostly on concurrent question complexity, not whole RAM alone.
On a 4 GB VPS, that normally means allocating round 1 GB to shared_buffers whereas leaving sufficient reminiscence for the Linux web page cache to carry continuously accessed information. That stability is a part of why a modest 4 GB field can comfortably run many small-to-midsize manufacturing workloads.
The plan-to-workload map you want to know:
| RAM Tier | Typical Workload | Really useful Stack Plan |
|---|---|---|
| 2 GB | Dev environments, low-traffic facet tasks | Beneath baseline |
| 4 GB | Most manufacturing utility databases | Stack 4 |
| 8 GB | Bigger datasets, extra concurrent connections | Stack 8 |
| 16 GB+ | Postgres alongside different heavy companies, analytics | Stack 16 |
DreamHost’s VPS Internet hosting plans offer you root entry, NVMe storage, and unmetered bandwidth on a predictable month-to-month invoice.
These are the 4 issues a self-hosted Postgres workload will depend on.
How Do You Set up PostgreSQL on a VPS?
You put in PostgreSQL on a VPS in 5 compressed steps.

- Provision the VPS: Decide a plan with sufficient RAM in your working set (Stack 4/4 GB is the baseline). Ubuntu 24.04 LTS is the really useful OS. SSH in with key-based authentication, not a password.
- Set up from the official PGDG repo: The distro
‘apt set up postgresql’lags main variations. Add the PGDG apt repo, then‘sudo apt set up postgresql-18.’Verify with‘sudo systemctl standing postgresql’ - Set the postgres password and create your app function: Run
sudo -i -u postgres, thenpsql, thenpassword postgres. Create a devoted least-privilege function:‘CREATE ROLE myapp WITH LOGIN PASSWORD '...';’and‘CREATE DATABASE myapp_prod OWNER myapp;’ - Bind the listener appropriately: Open /and so on/postgresql/18/essential/postgresql.conf. Set listen_addresses = ‘localhost’ if the app and database share the field, or bind to a personal IP if the app runs on a separate VPS. Keep away from binding PostgreSQL to 0.0.0.0 on a publicly reachable interface. Uncovered PostgreSQL situations are aggressively scanned and brute-forced by automated bots.
- Lock down ‘pg_hba.conf’ and UFW: Edit pg_hba.conf to permit solely the applying IPs you really want, with ‘scram-sha-256’ because the auth methodology. Configure UFW to permit port 5432 solely from those self same IPs. SSH-tunnel for admin instruments (and please don’t open 5432 to the general public web).
Do this from one other machine: psql -h .
A timeout or refused connection from an unauthorized IP normally means your listener and firewall guidelines are doing their job. A password immediate from the general public web means one thing is misconfigured. As soon as Postgres is operating, the configuration is barely half the job.
How Do You Safe PostgreSQL on a VPS?
PostgreSQL on a VPS will get secured at three layers, plus function hygiene and patching cadence.
- Authentication: Use scram-sha-256 for brand new installs and take away legacy md5 guidelines from pg_hba.conf. PostgreSQL’s docs now warn that MD5-encrypted password help is deprecated and will probably be eliminated in a future launch.
- Community: Bind PostgreSQL to ‘localhost,’ a personal IP, or an interface reachable solely by your utility servers. Keep away from binding it to a publicly reachable interface. Layer UFW on prime and permit port 5432 solely from trusted utility IPs.
- Encryption in transit: Activate TLS for any connection crossing a community boundary. Set ssl = on in postgresql.conf, then use hostssl … scram-sha-256 guidelines in pg_hba.conf so purchasers can’t silently fall again to non-TLS connections. Self-signed certificates are acceptable for inner visitors if purchasers confirm them correctly.
- Roles: Utility connections ought to use a least-privilege function with solely the rights wanted for that app’s schemas. The superuser is for migrations and emergencies.
- Patching: Use the PGDG apt repo for present PostgreSQL packages. Allow unattended safety updates for the OS, however schedule PostgreSQL updates intentionally so a shock restart doesn’t turn out to be your incident of the week.
Your safety guidelines:
- Use scram-sha-256 solely; disable md5.
- Bind ‘listen_addresses’ to localhost or non-public IP.
- UFW guidelines enable 5432 solely from trusted IPs.
- SSL/TLS on for any network-crossing connection.
- App connects as a least-privileged function, by no means as ‘postgres.’
- Unattended safety updates enabled.
- No ‘host all all 0.0.0.0/0 md5’ traces wherever in ‘pg_hba.conf,’ ever.
That final bullet is the cautionary story.
Public-facing port 5432 with weak credentials is a identified cryptominer and brute-force goal. Uncovered PostgreSQL situations get scanned repeatedly by automated bots in search of default accounts, leaked passwords, or permissive pg_hba.conf guidelines.
Publicly reachable Postgres situations with weak authentication continuously get compromised shockingly quick. A database uncovered on to the web with out correct community controls, TLS, and function isolation is the sort of mistake that turns into an incident report. A correctly configured database remains to be one disk failure away from information loss.
How Do You Again Up and Replicate PostgreSQL on a VPS?
PostgreSQL backups on a VPS use one in every of three mechanisms, picked by the failure you’re defending towards. Logical backups by way of pg_dump for portability, bodily backups by way of pg_basebackup plus WAL archiving for point-in-time restoration, and streaming replication for prime availability.
Logical backups deal with migrations, partial restores, and dev refreshes. Run pg_dump –format=customized –file=mydb.dump mydb_prod from a day by day cron job. Customized format compresses properly and, together with the listing format, helps pg_restore’s parallel and selective restore choices. Push the dump to off-VPS object storage (DreamObjects, S3-compatible).
Bodily backups deal with full-system restores and point-in-time restoration. pg_basebackup plus steady Write-Forward Log (WAL) archiving enables you to recuperate to any second between the final base backup and the newest WAL phase, the production-grade possibility when information loss tolerance is seconds, not hours.
Streaming replication is the third possibility. A learn reproduction on a second VPS is a scorching standby for read-heavy workloads or a quick failover goal. The database replication setup prices a second VPS however bounds your worst-case outage to minutes.
| Mechanism | What It Provides You | What It Prices |
|---|---|---|
| pg_dump + cron + off-VPS storage | Every day logical backup, moveable | Restore latency, not point-in-time |
| pg_basebackup + WAL archiving | Bodily backup with point-in-time restoration | Storage and operational complexity |
| Streaming replication | Sizzling standby, near-zero Restoration Level Goal (RPO), learn scaling | Second VPS plus replication administration |
Restore-test month-to-month. Managed companies bake all this in, and it’s a part of what the self-hosting financial savings are shopping for again. When you’re already on a managed supplier, the trail out is easier than it seems to be.
How Do You Migrate From RDS, Supabase, or Neon to a VPS?
You migrate from a managed Postgres supplier to a VPS in 4 steps.
- Provision the goal VPS: Match the supply Postgres main model precisely. Set up PostgreSQL on the brand new VPS following the steps above, then pre-create the applying function and database.
- Dump from the supply: Run pg_dump –format=customized –no-owner –no-privileges –file=src.dump
. The –no-owner and –no-privileges flags strip provider-specific function grants that not often recreate cleanly on a brand new host. - Restore to the goal: Run pg_restore –dbname=myapp_prod –jobs=4 –no-owner –no-privileges src.dump. Look ahead to extension warnings. RDS, Supabase, and Neon usually allow extensions that won’t exist on vanilla Postgres. Set up appropriate extensions from PGDG packages or postgresql-contrib earlier than restoring.
- Connection-string swap and verification: Level a staging atmosphere on the new VPS first, run your take a look at suite, then validate consultant manufacturing queries and utility flows earlier than switching the manufacturing connection string. For low-write functions, a brief upkeep window throughout last cutover is usually easier than establishing replication. Preserve the supply database on-line and read-only for a number of days as a rollback goal.
What adjustments by supplier?
- From RDS: RDS-specific roles (‘rds_superuser,’ ‘rdsadmin’) don’t exist on vanilla Postgres; –no-owner and –no-privileges deal with most of it. Some RDS-managed extensions want a guide set up, and egress out of AWS through the dump is billable.
- From Supabase: The Postgres is actual Postgres, however Supabase’s auth, storage, and edge layers don’t migrate. Your utility schema does. Change these layers with self-hosted equivalents earlier than slicing over.
- From Neon: Branching is gone post-migration; plan for backups as an alternative. Dump-and-restore is simple, however operational habits like immediate branches want a alternative workflow.
The migration itself normally takes much less time than choosing the VPS plan. Sensible downtime is minutes for small databases, longer with WAL replay for giant ones. Most installs cease right here, however there may be one situation that pushes you additional…
When Ought to You Add PgBouncer or Stick With Vanilla Postgres?
Most apps on a 4 GB VPS don’t want a connection pooler in the beginning. Add PgBouncer when concurrent connections exceed roughly 100, or your utility stack opens a brand new connection per request.
PostgreSQL connections are heavy as a result of each is a full working system course of. With 4 GB of RAM, you don’t need tons of of idle connections consuming reminiscence. The pooler holds the costly Postgres connections on its facet and arms out low-cost, short-lived connections to your app on the opposite.
Two pooling modes matter:
- Session pooling: Every consumer will get one server connection for the session. Secure for any app, no semantics change, decrease throughput acquire.
- Transaction pooling: Every consumer will get a server connection for one transaction. Large throughput acquire. You lose options counting on session state (ready statements, advisory locks, ‘LISTEN’/’NOTIFY’) except the app is written to anticipate it.
Most small SaaS apps with a connection-pooled ORM are advantageous with out PgBouncer till they aren’t. The sign that you just’ve crossed the road is ‘FATAL: too many connections’ errors or reminiscence strain from idle connections.
Set up it with sudo apt set up pgbouncer, configure /and so on/pgbouncer/pgbouncer.ini together with your database record and pool mode, then level the app at PgBouncer on port 6432.
Sure, you’ll know once you want it.
Making the Ultimate Name
The fee hole is actual sufficient to justify operating the maths towards your personal invoice. However setup isn’t the exhausting half.
The exhausting half is the operational work that the managed invoice was paying for. Backups, restore drills, patching, and monitoring.
Both approach, take a deep breath earlier than you open that subsequent bill.

Personal Your Total Stack. Apps, AI, Databases, and Extra.
Preserve each credential and dialog on a server you management, with NVMe velocity and unmetered bandwidth inbuilt.
Ceaselessly Requested Questions About PostgreSQL on a VPS
How a lot RAM does PostgreSQL want on a VPS?
PostgreSQL runs on 1 to 2 GB for tiny workloads and comfortably on 4 GB for many manufacturing utility databases. Heavier datasets, extra concurrent connections, or analytics workloads push the requirement to eight GB or extra.
Can I run PostgreSQL on a 2 GB VPS?
Sure, you’ll be able to run PostgreSQL on a 2 GB VPS for small apps, dev environments, and low-traffic facet tasks. A 2 GB field leaves little headroom for caching, so question efficiency drops as your information outgrows reminiscence. For manufacturing workloads, 4 GB is the safer baseline.
Is self-hosting PostgreSQL on a VPS cheaper than RDS or Supabase?
Sure, self-hosting PostgreSQL on a VPS is cheaper than RDS or Supabase for many steady-state workloads. A 4 GB VPS generally runs at a fraction of the equal RDS, Supabase Professional, or Neon Scale spec as soon as storage, backups, and egress are stacked in. The trade-off is that you just function the database your self.
How do I expose PostgreSQL on a VPS securely?
Don’t expose port 5432 to the general public web. Bind PostgreSQL to localhost or a personal IP, require scram-sha-256 authentication, and SSH-tunnel admin instruments as an alternative of opening 5432 to your laptop computer. Public 5432 with weak auth is a identified cryptominer goal.
Do I would like to make use of Docker for PostgreSQL on a VPS?
No, Docker shouldn’t be required. The official PGDG apt repository installs PostgreSQL as a local system service, which is the best production-grade setup. Docker is affordable in case you’re already operating different containers.
How do I again up PostgreSQL on a VPS?
Run pg_dump –format=customized on a day by day cron schedule and retailer the output off-VPS in S3-compatible object storage. Use pg_basebackup plus WAL archiving for point-in-time restoration when seconds of information loss matter. Restore-test month-to-month.
What plan ought to I select for self-hosting PostgreSQL on DreamHost?
DreamHost’s VPS Stack 4 plan (4 GB RAM) is the really useful baseline for many manufacturing utility databases. Select Stack 8 (8 GB) for bigger datasets or excessive concurrency, and Stack 16 for Postgres alongside different resource-heavy companies.
Ought to I take advantage of PgBouncer with PostgreSQL on a small VPS?
Most apps on a 4 GB VPS don’t want PgBouncer in the beginning. Add a connection pooler when concurrent connections method 100, or when your app opens a brand new connection per request.
Did you take pleasure in this text?









