Saying Goodbye to Heroku Postgres for Now

A little less than a year ago, I built Burplist, a free search engine for craft beer in Singapore. Intending to keep my infrastructure cost as low as possible, I started with Heroku Postgres free tier.

With a row limit of 10,000 and a storage capacity of 1 GB, I thought that it would last me for at least a year — it didn’t.

Despite having a garbage collector service that runs every week to remove staled rows, Heroku Postgres’s free tier simply wasn’t enough. I started looking for alternatives.

TL;DR: I’ve migrated my side projects’ PostgreSQL to Railway because of its pricing and ease of migration.

💡
On 28 November 2022, Heroku phased out its free tier plan on this date. These are the 4 free tier alternatives that I migrated to.

Heroku Postgres Alternatives

After some Googling, I came across a couple of PaaS similar to Heroku, each with its own Postgres offerings:

One stood out

I chose Railway because it makes the most economical sense for my use case. Below are some of the things that I like about Railway:

  • Incredibly generous pricing, where you would only start paying for resource usage after $10. In my case, this is a lot cheaper than using Heroku.
  • They have a Discord community where you can easily get help from.
  • Rather slick and intuitive UI. On top of that, you can view and make SQL queries directly via the dashboard. Though, I would argue that using a database tool like TablePlus or pgAdmin would be much more convenient.
Railway PostgreSQL dashboard
You can only view and make SQL queries on the default database name railway
  • The dashboard also provides CPU, memory, and network metrics on your database usage; which is unavailable on Heroku’s free tier.
Railway PostgreSQL dashboard metrics
Railway PostgreSQL dashboard metrics

How to Migrate

The migration was a piece of cake. This is easily one of the push factors that made me decide to migrate to Railway Postgres.

Pre-requisite

  1. Installed postgresql locally on your machine. For E.g. if you’re on Mac — brew install postgresql
  2. Make sure you can run the pg_restore command

Setup Railway

  1. Setup a Railway account (referral link)
  2. Go to your Railway dashboard and create a new project and provision PostgreSQL
Railway PostgreSQL variables
Take note of your database credentials under the “Connect” or “Variables” tab. You’ll need them later

5 Migration Steps

  1. Export Heroku Postgres (reference).
heroku pg:backups:capture -a <heroku_app_name>
heroku pg:backups:download -a <heroku_app_name>

2. At your current working directory, you should see latest.dump file

$ heroku pg:backups:capture -a <heroku_app_name>

Starting backup of postgresql-encircled-90125... done
Use Ctrl-C at any time to stop monitoring progress; the backup will continue running.
Use heroku pg:backups:info to check progress.
Stop a running backup with heroku pg:backups:cancel.
Backing up DATABASE to b001... done

$ heroku pg:backups:download -a <heroku_app_name>
Getting backup from ⬢ <heroku_app_name>... done, #1
Downloading latest.dump... ████████████████████████▏  100% 00:00 309.99KB

$ ls
latest.dump

3. In the same working directory with latest.dump, run the following command to import your downloaded database dump to your Railway Postgres. Update accordingly with your own Postgres credentials:

# NOTE:
# Keep PGDATABASE as `railway` if you want to view your tables via the Railway dashboard.
# If you insist on another database name, you will have to create your own database via psql command.
#
# E.g.:
# PGPASSWORD=$PGPASSWORD psql -h $PGHOST -U $PGUSER -p $PGPORT -d $PGDATABASE
# CREATE DATABSE your_database_name;

PGPASSWORD=$PGPASSWORD pg_restore -h $PGHOST -U $PGUSER -p $PGPORT -d $PGDATABASE < latest.dump

4. Verify that your data is imported correctly. To do so, you can use the psql command as shown in the example in Step 4. Alternatively, connect to your database via a tool like pgAdmin.

5. Go to your existing apps, e.g. your Heroku app, and update the database connection URL/credentials accordingly.

That’s it!


I Miss Heroku Dataclip

One thing that I miss about Heroku Postgres is its ability to share query results with Dataclips. Heroku Dataclips is incredibly useful as you can easily:

  1. Make a SQL query via the UI
  2. Share the output in JSON or CSV format via a link

Once you have a sharable link to CSV, you easily import it to other SaaS such as Google Sheets. On top of that, most data processing SaaS supports CSV out of the box; this makes Dataclip incredibly useful.

Now, I’ll either have to generate my CSV on another server or pray that the SaaS that I’m using has PostgreSQL integration (hint: most don’t).

Having this said, I am still more than happy to make this tradeoff.

Other uses

Besides using Railway as my PostgreSQL database server for my projects, I am also using it to host my own umami analytics site in combination with Vercel.

I’d also recommend you to check out their other offerings such as Redis, MongoDB, and also their starter project templates.


Closing Thoughts

No, I’m not leaving Heroku entirely. Heroku has stood the test of time. I would expect a company owned by Salesforce to provide better reliability and stability.

On top of that Heroku’s add-ons often come in handy. Add-ons provide useful integration out of the box e.g. logging, search, and many more!

On the contrary, I can’t speak for the reliability and uptime of the Railway. Having that said, the projects that I am running allow me to take on this level of risk, and my experience so far has been great.

I’m rooting for Railway. I simply enjoy seeing competitions in the market.

Thanks for reading!

Written by human. Hosted on Digital Ocean.