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

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

问题描述

由于我的 postgres 数据库在 heroku (9.1) 和我的本地安装 (8.4) 上的版本不兼容,我需要一个纯文本的 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.

似乎在 heroku 上我无法使用 pg_dump 进行转储,而只能这样做:

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

推荐答案

你可以直接从你的 Heroku 数据库制作你自己的 pg_dump.

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

首先,使用 heroku config:get DATABASE_URL 获取你的 postgres 字符串.

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

查找 Heroku Postgres 网址(例如:HEROKU_POSTGRESQL_RED_URL:postgres://user3123:passkja83kd8@ec2-117-21-174-214.compute-1.amazonaws.com:6212/db982398),格式为postgres://:@:/.

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

终端将询问您的密码,然后运行它并将其转储到 output.sql 中.

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

然后导入:

psql -d my_local_database -f output.sql

这篇关于如何在 heroku 上获得纯文本 postgres 数据库转储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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