3

I need to assess the database schema of the Postgres instance running on Heroku. Without luck, I have tried the following methods:

heroku run -a my_app_name 'pg_dump -s DATABASE_URL' > output.sql

where DATABASE_URL would be the whole string out of

heroku config:get DATABASE_URL -a my_app_name

This is the closest I could get, as the command runs but the output is left empty. For this I added the flag -s for pg_dump to only get the schema and no data.

I have also tried following this answer but couldn't use it to get the schema.

Francesco
  • 31
  • 3
  • 1
    Your first `heroku run -a ...` one should work fine, worked for me just now. Are you sure you're using the right `DATABASE_URL`? – mu is too short Feb 19 '19 at 04:38
  • 1
    Thanks @muistooshort, you are right, I eventually got the output file, successful as it ends with *-- PostgreSQL database dump complete* . However, I am not sure how long it took, the command execution never ends and I have to close the terminal window once done because not responding. Anyway good. – Francesco Feb 21 '19 at 04:46
  • 1
    Your answer was the only thing that worked for me after hours of trying... In my case I copied `DATABASE_URL` from the heroku -> my app -> resources -> view database credentials then copied `URI` if that helps anybody else. – Joe Boyle Oct 14 '21 at 16:23

1 Answers1

0

If you need permission to access the app, you can run it.

heroku pg:pull DATABASE_URL local_db_name --exclude-table-data="*.*" --app heroku_app_name

It will pull all the tables' structures but no data.