如何在heroku上获得纯文本postgres数据库转储? [英] How can I get a plain text postgres database dump on heroku?
问题描述
在heroku上我似乎无法使用pg_dump进行转储,但只能执行此操作:
$ heroku pgbackups:capture
$ curl -o my_dump_file.dump`heroku pgbackups:url`
...这给了我自定义数据库转储格式而不是纯文本格式,所以我无法做到这一点:
$ psql -d my_local_database -f my_dump_file.sql
您可以直接从Heroku数据库中创建自己的pg_dump。
首先,使用 heroku config:get DATABASE_URL
来获取您的postgres字符串。
查找Heroku Postgres网址(例如: HEROKU_POSTGRESQL_RED_URL:postgres:// user3123:passkja83kd8 @ ec2-117-21-174-214。其中
postgres://< username>:< password> @< host_name>:<端口> /< dbname>
。
接下来,在您的命令行上运行:
pg_dump --host =< host_name> --port = LT;端口> --username =<用户名> --password --dbname =< dbname> > output.sql
终端会询问您的密码,然后运行它并将其转储到output.sql中。
然后导入它:
psql -d my_local_database -f输出.sql
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 production data on my local testing environment.
It seems on heroku I can't make a dump using pg_dump but can instead only do this:
$ heroku pgbackups:capture
$ curl -o my_dump_file.dump `heroku pgbackups:url`
...and this gives me the "custom database dump format" and not "plain text format" so I am not able to do this:
$ psql -d my_local_database -f my_dump_file.sql
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://<username>:<password>@<host_name>:<port>/<dbname>
.
Next, run this on your command line:
pg_dump --host=<host_name> --port=<port> --username=<username> --password --dbname=<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
这篇关于如何在heroku上获得纯文本postgres数据库转储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!