- Consulting
- Training
- Partners
- About Us
x
Postgresql is one of the most widely used Open-source Databases in the modern Era. Millions of developers and companies believe that PostgreSQL as their transactional data store to drive application health and decision-making. And developers with knowledge of Oracle or MySQL databases can use their SQL querying experience to quickly leverage PostgreSQL’s capabilities as a quick, functional, and powerful data resource.
Today I am going to explain about Migration of Heroku PostgreSQL Database to AWS RDS PostgreSQL. I think most people are aware of the Heroku Cloud. Please click here to know more about Heroku Cloud.
We have several methods for performing this Migration. Today I am explaining Migration using the pg_dump and pg_restore method. I am using centos 7 Instance as a middle Instance for migration. You can use Windows, Mac or any System depends upon your easiness.
First, we need to install Heroku CLI on our Machine. Before that, we need to install git as a prerequisite:
1 |
yum install git |
Now we can Install Heroku cli using below command,
1 |
curl <a href="https://cli-assets.heroku.com/install.sh">https://cli-assets.heroku.com/install.sh</a> | sh |
Please verify the Heroku cli version, once it installed
1 |
heroku --version |
We have installed the Heroku cli successfully. Now we can install PostgreSQL client,
1 2 3 |
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm yum install postgresql10 |
PostgreSQL client is installed now, we can check the version,
1 |
psql --version |
Next, we need to login into our Heroku account using the below command
1 |
heroku login -i |
Then please log in to our Heroku Account using a browser and select our PostgreSQL database and click on settings from the menu and click on view credentials.
Login to our Heroku PostgreSQL using Heroku CLI (PostgreSQL connection string)
1 |
heroku pg:psql postgresql-asymmetrical-11483 --app nameless-wave-47716 |
Now we connected to our database. We can list the tables using:
1 |
\dt command, |
Now we can see some of the tables are residing in the given database. Please login to our AWS RDS and verify the table.
1 2 3 |
psql “host=rdsendpoint port=5432 dbname=db_blog user=blog_user” db_blog=> \dt |
Next, we are going to create and download a backup of our Postgresql database using the below commands,
1 2 3 |
heroku pg:backups:capture --app nameless-wave-47716 heroku pg:backups:download --app nameless-wave-47716 |
We export our dump file to our system, now we need to restore it into our AWS RDS using the below command,
1 2 3 |
pg_restore --verbose --clean --no-acl --no-owner -h <strong>rds</strong>-<strong>endpoint</strong> -U dev_user -d dev_db latest.dump |
Login to the RDS and verify the table, once the restoration completes,
1 2 3 |
psql “host=rdsendpoint port=5432 dbname=db_blog user=blog_user” db_blog=> \dt |
Today we have learned about the migration of the Heroku PostgreSQL database to AWS RDS using cli.
Please share your valuable feedback in the comment section.
Voiced by Amazon Polly |
Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!
Ritesh Takrani
Dec 17, 2020
Thank you for the wonderful explanation.
Keep up the good work.
Sumit
Dec 17, 2020
Good and informative blog! Thanks for this.
Ketan
Dec 17, 2020
Informative! Keep it up
Click to Comment