How to get latest heroku postgresql database of your (rails) app on your local machine?

First download the latest database of your app on your local machine with below two commands:

heroku pg:backups:capture

heroku pg:backups:download

you will get the latest database downloaded in a filename latest.dump.<some number>

Now connect to postgresql on your local machine:

sudo -u postgres psql

create a new database fith command :

create database <database_name>;

now logout from postgresql prompt by pressing ctrl+D

Now just import the downloaded prod db into the new created local database :

pg_restore <hyphen><hyphen>no-owner -U karan -d <local_database_name> -1 <downloaded_dump_database_production>;

you are done!

to use the new database in your local rails app just edit the config/database.yml file on your local machine.

development:
<<: *default
database: cmsproddec

just change the database name above and your local rails app with start using the new database.

Enjoy.

Feel free to HMU.

Cheers.