{"id":7571,"date":"2020-12-10T12:05:08","date_gmt":"2020-12-10T12:05:08","guid":{"rendered":"https:\/\/blog.cloudthat.com\/?p=7571"},"modified":"2024-06-25T11:09:58","modified_gmt":"2024-06-25T11:09:58","slug":"how-to-migrate-heroku-postgresql-database-to-aws-rds-postgresql-using-cli","status":"publish","type":"blog","link":"https:\/\/www.cloudthat.com\/resources\/blog\/how-to-migrate-heroku-postgresql-database-to-aws-rds-postgresql-using-cli","title":{"rendered":"How To Migrate Heroku PostgreSQL Database To AWS RDS PostgreSQL using CLI"},"content":{"rendered":"<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7572\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture2.jpg\" alt=\"Postgre SQL\" width=\"624\" height=\"312\" \/><\/a><\/p>\n<h2>Postgresql<\/h2>\n<p>Postgresql is one of the most widely used Open-source Databases in the modern Era. Millions of developers\u00a0and companies\u00a0believe that\u00a0PostgreSQL as their transactional data store to\u00a0drive application health and decision-making. And developers with knowledge of Oracle or MySQL databases can use their SQL querying experience to quickly leverage PostgreSQL&#8217;s capabilities as\u00a0a quick, functional, and powerful data resource.<\/p>\n<p>Today I am going to explain about Migration of Heroku\u00a0PostgreSQL\u00a0Database to AWS RDS\u00a0PostgreSQL. I think most people are aware of the Heroku Cloud.\u00a0Please click<strong>\u00a0<a href=\"https:\/\/devcenter.heroku.com\/categories\/reference\" target=\"_blank\" rel=\"noopener\">here<\/a><\/strong>\u00a0to know more\u00a0about Heroku Cloud.<\/p>\n<p>We have several methods for performing this Migration. Today I am explaining Migration using the pg_dump\u00a0and\u00a0pg_restore\u00a0method. I am using centos 7 Instance as a middle Instance for migration. You can use Windows, Mac or any System depends upon your easiness.<\/p>\n<p>First, we need to install Heroku CLI on our Machine. Before that, we need to install git as a prerequisite:<\/p>\n<pre class=\"\">yum install git<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7573\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture3.png\" alt=\"\" width=\"624\" height=\"130\" \/><\/a><\/p>\n<p>Now we can Install Heroku cli using below command,<\/p>\n<pre class=\"\">curl\u00a0<a href=\"https:\/\/cli-assets.heroku.com\/install.sh\">https:\/\/cli-assets.heroku.com\/install.sh<\/a>\u00a0|\u00a0sh<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7574\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture4.png\" alt=\"\" width=\"624\" height=\"166\" \/><\/a><\/p>\n<p>Please verify the\u00a0Heroku cli version, once it installed<\/p>\n<pre class=\"\">heroku\u00a0--version<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7575\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture5.png\" alt=\"\" width=\"473\" height=\"87\" \/><\/a><\/p>\n<p>We have installed the Heroku cli successfully. Now we\u00a0can\u00a0install\u00a0PostgreSQL\u00a0client,<\/p>\n<pre class=\"\">yum install -y https:\/\/download.postgresql.org\/pub\/repos\/yum\/10\/redhat\/rhel-7-x86_64\/pgdg-redhat10-10-2.noarch.rpm\r\n\r\nyum install postgresql10<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture61.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7588 alignleft\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture61.png\" alt=\"6\" width=\"622\" height=\"181\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture71.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7589\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture71.png\" alt=\"7\" width=\"624\" height=\"127\" \/><\/a><\/p>\n<p>PostgreSQL\u00a0client is installed now,\u00a0we\u00a0can check the version,<\/p>\n<pre class=\"\">psql\u00a0--version<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture81.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7590\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture81.png\" alt=\"8\" width=\"624\" height=\"108\" \/><\/a><\/p>\n<p>Next, we need to login into our Heroku account using the below command<\/p>\n<pre class=\"\">heroku\u00a0login -i<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture91.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7591\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture91.png\" alt=\"9\" width=\"624\" height=\"141\" \/><\/a><\/p>\n<p>Then please log in to our Heroku Account using a browser and select our\u00a0PostgreSQL\u00a0database and click on settings from the menu and click on view credentials.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture101.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7592\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture101.png\" alt=\"10\" width=\"624\" height=\"270\" \/><\/a><\/p>\n<p>Login to our Heroku\u00a0PostgreSQL\u00a0using Heroku CLI (PostgreSQL\u00a0connection string)<\/p>\n<pre class=\"\">heroku\u00a0pg:psql\u00a0postgresql-asymmetrical-11483\u00a0--app\u00a0nameless-wave-47716<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture112.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7593\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture112.png\" alt=\"11\" width=\"624\" height=\"158\" \/><\/a><\/p>\n<p class=\"\">Now we connected to our database. We can list the tables using:<\/p>\n<pre class=\"\"> \\dt command,<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture121.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7594\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture121.png\" alt=\"12\" width=\"624\" height=\"150\" \/><\/a><\/p>\n<p>Now we can see some of the tables are residing in the given database. Please login to our AWS RDS and verify the table.<\/p>\n<pre class=\"\">psql\u00a0\u201chost=rdsendpoint port=5432\u00a0dbname=db_blog\u00a0user=blog_user\u201d\r\n\r\ndb_blog=&gt; \\dt<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture131.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7595\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture131.png\" alt=\"13\" width=\"624\" height=\"116\" \/><\/a><\/p>\n<p>Next, we are going to create and download a backup of our\u00a0Postgresql\u00a0database using the below commands,<\/p>\n<pre class=\"\">heroku\u00a0pg:backups:capture\u00a0\u00a0--app\u00a0nameless-wave-47716\r\n\r\nheroku\u00a0pg:backups:download\u00a0\u00a0--app\u00a0nameless-wave-47716<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture141.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7596\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture141.png\" alt=\"14\" width=\"624\" height=\"83\" \/><\/a><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture151.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7597\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture151.png\" alt=\"15\" width=\"624\" height=\"92\" \/><\/a><\/p>\n<p>We export our dump file to our system,\u00a0now\u00a0we need to restore it into our AWS RDS using the below command,<\/p>\n<pre class=\"\">pg_restore\u00a0--verbose\u00a0--clean\u00a0--no-acl\u00a0--no-owner -h\u00a0<strong>rds<\/strong>-<strong>endpoint<\/strong>\r\n\r\n-U\u00a0dev_user\u00a0-d\u00a0dev_db\u00a0latest.dump<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture161.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7598\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture161.png\" alt=\"16\" width=\"624\" height=\"126\" \/><\/a><\/p>\n<p>Login to the RDS and verify\u00a0the table, once the restoration completes,<\/p>\n<pre class=\"\">psql\u00a0\u201chost=rdsendpoint port=5432\u00a0dbname=db_blog\u00a0user=blog_user\u201d\r\n\r\ndb_blog=&gt; \\dt<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture171.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7599\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture171.png\" alt=\"17\" width=\"624\" height=\"129\" \/><\/a><\/p>\n<p>Today we have learned about the migration of the<strong> Heroku\u00a0PostgreSQL\u00a0database to AWS RDS\u00a0using cli.<\/strong><\/p>\n<p>Please share your valuable feedback in the comment section.<\/p>\n","protected":false},"author":236,"featured_media":8071,"parent":0,"comment_status":"open","ping_status":"open","template":"","blog_category":[3606,3607],"user_email":"deepaks@cloudthat.com","published_by":"324","primary-authors":"","secondary-authors":"","acf":[],"_links":{"self":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/7571"}],"collection":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/users\/236"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/comments?post=7571"}],"version-history":[{"count":2,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/7571\/revisions"}],"predecessor-version":[{"id":46215,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/7571\/revisions\/46215"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/media?parent=7571"}],"wp:term":[{"taxonomy":"blog_category","embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog_category?post=7571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}