Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql Heroku上的Postgres并将单个表转储到转储文件_Postgresql_Heroku_Heroku Toolbelt - Fatal编程技术网

Postgresql Heroku上的Postgres并将单个表转储到转储文件

Postgresql Heroku上的Postgres并将单个表转储到转储文件,postgresql,heroku,heroku-toolbelt,Postgresql,Heroku,Heroku Toolbelt,我在Heroku上使用Postgres,我需要从生产数据库中转储一个表,并将其转储到暂存数据库中。我安装了heroku工具带,但不确定如何转储单个db表以导入到我的暂存db中 看看taps(db:pull),我相信您的用例包含在中。您可以像这样转储一个数据表: $ pg_dump --no-acl --no-owner -h [host ip].compute-1.amazonaws.com -U [user name] -t [table name] --data-only [database

我在Heroku上使用Postgres,我需要从生产数据库中转储一个表,并将其转储到暂存数据库中。我安装了heroku工具带,但不确定如何转储单个db表以导入到我的暂存db中

看看taps(
db:pull
),我相信您的用例包含在中。

您可以像这样转储一个数据表:

$ pg_dump --no-acl --no-owner -h [host ip].compute-1.amazonaws.com -U [user name] -t [table name] --data-only [database name] > table.dump
您可以通过以下方法获得所需的所有值:

$ heroku pg:credentials:url [DATABASE] -a [app_name]
Connection info string:
   "dbname=[database name] host=[host ip].compute-1.amazonaws.com port=5432 user=[user name] password=[password] sslmode=require"
Connection URL:
    postgres://[username]:[password]@[host ip].compute-1.amazonaws.com:5432/[database name]
这将提示您输入密码。输入它,然后您应该继续在本地驱动器上获取文件
table.dump

您可能希望在登台时截断表:

$ echo "truncate [table];" | heroku pg:psql [DATABASE] -a staging_app
使用该文件,您可以将
psql
连接URL:
输出一起使用,为登台应用程序
pg:credentials
进行新调用,并仅还原该表

$ psql "[pasted postgres:// from pg:credentials:url of staging app]" < table.dump
SET
SET
...
...
...
...
$ 
$psql“[pasted postgres://from pg:credentials:staging app的url]”
@catsbys答案

我还需要添加端口


pg_dump--no acl--no owner-h[host ip].compute-1.amazonaws.com-p[port]-U[user name]-t[table name]--data only[database name]>table.dump

当我运行命令
heroku db:pull--tables tbl_name--app dbname
时,我得到以下错误:无效的数据库URL这不再可能了。非常感谢您的帮助!如果需要多个表,请为每个表添加-t开关。所以,
pg_dump--no acl--no owner-h[host ip].compute-1.amazonaws.com-U[user name]-t[table name 1]-t[table name 2]-t[table name 3]--data only[database name]>table.dump
这很有效,谢谢。对于其他这样做的人:完成上述步骤后,不要忘记重置PG主键序列,以便它知道从哪个主键开始。非常感谢。你救了我;)很好的信息,但我有点被一个愚蠢的问题难住了:你能确认使用哪个用户/密码吗?我尝试了连接信息字符串中提供的用户,它看起来像一个散列值,以及
config/database.yml
中定义的数据库密码;还使用密码尝试了该文件中定义的用户(
railsapp
)。我已经尝试过我的heroku密码,以及各种用户名组合(提供的哈希、明文heroku用户名、dB用户名)。没有成功。获取
致命密码:在所有情况下,用户[user]
的密码身份验证都失败。