Member-only story
How to Provision a Cheap PostgreSQL Database in AWS EC2
When RDS is beyond your budget, run Postgres on EC2

The Motivation
The biggest reason to run your database out of EC2 would be cost savings. As of writing this article, the cheapest/smallest RDS deployment costs around $30.88 USD/month. In contrast, we can run a t2.micro EC2 instance with 8GB of storage for around $6 USD/month. This cost can be further reduced if you opt for reserved billing.
Caveats / When You Should Opt for RDS
As a rule of thumb, if budget allows, always opt for RDS. It provides replication via a standby instance in a different availability zone and handles automatic fail-over. This is desirable for two reasons:
- Amazon guarantees 99.99999% up-time for regions, not availability zones. So having a standby replica in a different zone will ensure that even if the primary zone where your master database is hosted experiences an outage, your application will be able to fall back to the standby replica in a different (and presumably unaffected) zone.
- Your application does not need to be able to detect database failure and handle fail-over. This is handled by Amazon automatically. They will point your database host URL to the standby database if/when your primary database fails. After the crisis has been resolved, they will automatically catch up the recovered master database and promote it.
Now that we have that out of the way, let's get started. In case you’d prefer to consume this guide in video format:
Set Up the Infrastructure
Jump to the AWS EC2 console and provision a Linux server to host our DB. I’ll be choosing an Ubuntu 20.04 server because that is what I’m most accustomed to.