How can I get a plain text postgres database dump on heroku?

前端 未结 5 1427
猫巷女王i
猫巷女王i 2020-12-07 14:14

Due to version incompatibilities of my postgres database on heroku (9.1) and my local installation (8.4) I need a plain text sql database dump file so I can put a copy of my

5条回答
  •  天命终不由人
    2020-12-07 14:27

    You could just make your own pg_dump directly from your Heroku database.

    First, get your postgres string using heroku config:get DATABASE_URL.

    Look for the Heroku Postgres url (example: HEROKU_POSTGRESQL_RED_URL: postgres://user3123:passkja83kd8@ec2-117-21-174-214.compute-1.amazonaws.com:6212/db982398), which format is postgres://:@:/.

    Next, run this on your command line:

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

    The terminal will ask for your password then run it and dump it into output.sql.

    Then import it:

    psql -d my_local_database -f output.sql
    

提交回复
热议问题