如何在heroku上获得纯文本postgres数据库转储? [英] How can I get a plain text postgres database dump on heroku?

查看:93
本文介绍了如何在heroku上获得纯文本postgres数据库转储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我的postgres数据库在heroku(9.1)和本地安装(8.4)上的版本不兼容,我需要一个纯文本的sql数据库转储文件,所以我可以在我的本地测试环境中放置一份生产数据。



在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆