DEV Community

Jerry Ng
Jerry Ng

Posted on • Edited on • Originally published at jerrynsh.com

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. With the goal to keep my infrastructure cost as low as possible, I started off 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 on a weekly basis 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.


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 resources 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.
    You can only view and make SQL queries on the default database name  raw `railway` endraw

    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 something that 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 the decision of migrating 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](http://www.postgresql.org/docs/current/static/app-pgrestore.html) command

Setup Railway

  1. Setup a Railway account (referral link)
  2. Go to your Railway dashboard and create a new project and provision PostgreSQL Take note of your database credentials under the > 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>
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. Verify that your data is imported correctly. To do so, you can use the psql command as shown in the example in Step 4; or connect to your own database via a tool like pgAdmin.
  2. 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 really 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 own 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!


This article was originally published on jerrynsh.com

Top comments (0)