How do I dump a database from online server (heroku) to my local environment?

461 views Asked by At

I have been trying to get the data that I have on my database from the online servers (heroku) and copy it into a local database. I am new to both psql, heroku and basically to the whole concept of building web apps, so forgive me if I sound ignorant.

After reading this post saying that on windows I had to pg_dump and pg_restore separetely I went ahead and found the URL for my database and ran the pg_dump command successfully.

C:\>pg_dump postgres://ddzhoyyleezptg:X7AapV7z9LIYMDYXcEAVoNpA_e@ec2-54-83-17-8.compute-1.amazonaws.com:5432/***
(INFO OMITTED)
--
-- PostgreSQL database dump complete
--

and now I do not know how to move on. To clarify, my goal is to have a copy of the database that I have online so that I am able to work with the data locally without affecting the data on the server.

Any help is appreciated, Thank you in advance.

2

There are 2 answers

0
Sagar.Patil On

You can use this commands

 $ heroku pg:backups capture
 $ curl -o latest.dump `heroku pg:backups public-url`

Ref Heroku backup pg database

1
Akshay Borade On

To export the data from your Heroku Postgres database, create a new backup and use any number of download tools, such as curl or wget, to store the backup locally.

 heroku pg:backups capture

 curl -o latest.dump `heroku pg:backups public-url`

Hope this will help you.