Postgresql
Postgresql is the most popular Open-source Database in the modern Era. Millions of developers and companies use PostgreSQL to store their transactional data and drive decision-making and application health. Developers who have knowledge of Oracle and MySQL databases can leverage their SQL querying skills to quickly access PostgreSQL as a powerful, functional, and fast data resource.
Today, I will be explaining Migration of Heroku PostgreSQL Database to AWS RDS PostgreSQL. Most people are familiar with the Heroku Cloud. Click here to learn more about Heroku Cloud.
There are many ways to perform this migration. Today, I will explain Migration using the pg_dump or pg_restore methods. As a middle Instance, I am using centos 7. You can use Windows, Mac, or any System depending on your ease.
First, we must install Heroku CLI onto our Machine. We must first install Heroku CLI on our Machine.
yum install Git1yum Install Git
We can now install Heroku cli by using the below command
curl https://cli-assets.heroku.com/install.sh | sh1curl https://cli-assets.heroku.com/install.sh | sh
Once installed, please verify the Heroku cli version.
heroku –version1heroku
We have successfully installed the Heroku cli. Now we can install PostgreSQL client.
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpmyum install postgresql10123yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpmyum install postgresql10
We can now check the version of PostgreSQL client, which is already installed.
psql-version1psql
Next, use the following command to log into your Heroku account
Login to heroku -i1heroku Login -i
Log in to your Heroku Account with a browser. Next, select our PostgreSQL Database and click on Settings. Click on View Credentials.
Login to Heroku PostgreSQL by using Heroku CLI (PostgreSQL Connection String)
heroku pg:psql postgresql-asymmetrical-11483 –app nameless-wave-477161heroku pg:psql postgresql-asymmetrical-11483 –app nameless-wave-47716
Now, we connected to our database. Now we can list the tables using:
\dt command,1 \dt command,
We can now see which tables are stored in the database. Log in to our AWS RDS to verify the table.
psql “host=rdsendpoint port=5432 dbname=db_blog user=blog_user”db_blog=> \dt123psql “host=rdsendpoint port=5432 dbname=db_blog user=blog_user”db_blog=> \dt
Next, we will create and download a backup to our Postgresql Database using the following commands
heroku pg:backups:capture –app nameless-wave-47716heroku pg:backups:download –app nameless-wave-47716123heroku pg:backups:capture –app nameless-wave-47716heroku pg:backups:download –app nameless-wave-47716
Now that we have exported our dump file to our system, we need to restore it to our AWS RDS with the following command.
pg_restore –verbose –clean –no-acl –no-owner -h rds–endpoint-U dev_user -d dev_db latest.dump123pg_restore –verbose –clean –no-acl –no-owner -h rds–endpoint-U dev_user -d dev_db latest.dump
Log in to the RDS to verify the table once the restoration is complete.
psql “host=rdsendpoint port=5432 dbname=db_blog user=blog_user”db_blog=> \dt123psql “host=rdsendpoint port=5432 dbname=db_blog user=blog_user”db_blog=> \dt
Today, we learned about the migration from the Heroku PostgreSQL to AWS RDS database using cli.
Please leave your valuable feedback in our comment section.