Caught off-guard by Heroku's discontinuing of the free Heroku Dynos and Free Heroku Postgres starting November 28th, 2022? No need to worry. This post will detail how to migrate the data from your Heroku Postgres addon to Railway which is a great alternative to Heroku. The following steps will help towards facilitating a seamless migration of your data between the two platforms.
I. Ensure that you have postgres installed on your machine
II. Add the postgres bin directory to your machine's environment variables to access postgress on your windows CLI
III. Open a new CMD and confirm that postgres is accessible to your CLI through the following command:
psql --version
IV. Log in to heroku and click on your app's postgres DB addon.
V. Click the settings tab on the addon and click on the database credentials link to reveal your details.
VI. Now on your CMD window, connect to your heroku postgres DB using the following command. (Input the host, port, User and Data as they appear in the Heroku Postgres adon Database Credentials):
psql -h <host> -p <port> -U <User> -d <Database>
VII. You will be prompted to input a password. Use the password provided Heroku Postgres adon Database Credentials.
VIII. Now you are succesfully connected to your Heroku postgres DB. You can carry out any query to confirm this. For instance, type \dt
on your CMD to see all the tables within the DB (In the event you receive an error prompt, use the following command to encode the output appropriatrely:
set client_encoding='utf-8'
).
IX. Next, we shall create a dump file to temporarily hold the data from our Heroku postgres DB as is currently. Open a new CMD tab and input the following command:
pg_dump -h <host> -d <Database> -U <User> -W -Ft > filename.dump
(The filename can be anything really. Just ensure that you have the .dump file extension to the name you choose).
X. Now, create an account on Railway.app and create a project. Type ctrl+k In your project environment to bring up the help tab and type postgresql. Click on the postgresql service to create a new postgres DB instance on Railway.
XI. On the variables tab of the Railway Postgres instance are the DB credentials.
XII. Use the following command to transfer the DB data in the dump file we created in step 9 to Railway (Use the variables in step XI):
pg_restore -U <PGUSER> -h <PGHOST> -p <PGPORT> -W -Ft -d <PGDATABASE> filename.dump
XIII. These steps shall help you successfully migrate your data from Heroku Postgress to your Railway Postgres instance.
Top comments (0)