我在Heroku上使用Postgres,需要从生产数据库中转储一个表,并将其转储到暂存数据库中.我安装了heroku工具带,但不确定如何转储单个数据库表以导入到我的暂存数据库中.
我在Heroku上使用Postgres,需要从生产数据库中转储一个表,并将其转储到暂存数据库中.我安装了heroku工具带,但不确定如何转储单个数据库表以导入到我的暂存数据库中.
您可以转储单个数据表,如下所示:
$ 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
和a new call to 102 for the staging app的Connection URL:
输出,并仅恢复该表.
$ psql "[pasted postgres:// from pg:credentials:url of staging app]" < table.dump
SET
SET
...
...
...
...
$