1

I have a Ruby on Rails application and I want to get the data from a Heroku server to a local machine.

I have tried the steps mentioned in https://devcenter.heroku.com/articles/heroku-postgres-import-export, but it just copies the Data Definitions not the actual data on the server.

Is there any way to get the data from Heroku to local databases?

the_
  • 1,183
  • 2
  • 30
  • 61
user3002982
  • 13
  • 1
  • 4

1 Answers1

1

Try using the steps detailed here.

Basically, grab the information from your Heroku database using heroku config:get. Look for your Heroku Postgres url. It will look something like this: HEROKU_POSTGRESQL_RED_URL: postgres://user3123:passkja83kd8@ec2-117-21-174-214.compute-1.amazonaws.com:6212/db982398. Note that the string is configured as database://username:password@host:port/databasename. Thus, in this example, the username is user3123, the database name is db982398. You'll need this for the next part.

Then, you'll use the information in the above postgres string to make a local copy of your Heroku database using pg_dump. Enter the following into your terminal:

pg_dump --host=<host_name> --port=<port> --username=<username> --password --dbname=<dbname> > output.sql

In each place where <....> is in the above code, enter your specific information. After typing this, the terminal will ask you for your password. Enter it.

Finally, you'll load that dumpfile into your local database using psql.

psql -d <local_database_name> -f output.sql

Be sure to put the name of your local database.

Community
  • 1
  • 1
Alex
  • 8,321
  • 1
  • 34
  • 30