heroku Heroku Postgres How to copy heroku database to local database


Steps to copy heroku database to local database:

1. Run copy process in terminal:

heroku pg:pull DATABASE_URL change_to_your_data_base_name --app change_to_your_app_name

2. Change db owner using this query:

GRANT ALL PRIVILEGES ON DATABASE change_to_your_data_base_name to change_to_your_user; ALTER DATABASE change_to_your_data_base_name OWNER TO change_to_your_user;

3. Generate and run query for all tables in you database:

SELECT 'ALTER TABLE '|| schemaname || '.' || tablename ||' OWNER TO change_to_your_user;' FROM pg_tables WHERE NOT schemaname IN ('pg_catalog', 'information_schema') ORDER BY schemaname, tablename;