postgresql 在远程机器上恢复转储
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26378098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Restore dump on the remote machine
提问by Danila Zharenkov
I've got my own machine with postgres dmp file, which I want to restore on the remote virtual machine (e.g. ip is 192.168.0.190 and postgres port is 5432) in my network. Is it possible to restore this dump using pg_restore without copying dump to remote machine? Because the size of dump about 12GB and the disk space on the virtual machine is 20GB. Thanks
我有我自己的带有 postgres dmp 文件的机器,我想在我的网络中的远程虚拟机(例如 ip 是 192.168.0.190 和 postgres 端口是 5432)上恢复它。是否可以使用 pg_restore 恢复此转储而不将转储复制到远程机器?因为dump的大小约为12GB,虚拟机上的磁盘空间为20GB。谢谢
回答by nif
You can run a restore over the network without copying the dump to the remote host.
您可以通过网络运行还原,而无需将转储复制到远程主机。
Just invoke pg_restore
with -h <hostname>
and -p <port>
(and probably -U <username>
to authenticate as different user) on the host you got the dump file, for example:
只需在获得转储文件的主机上pg_restore
使用-h <hostname>
and调用-p <port>
(并且可能-U <username>
以不同的用户身份进行身份验证),例如:
pg_restore -h 192.168.0.190 -p 5432 -d databasename -U myuser mydump.dump
References:
参考:
回答by mopdobopot
Alternatively, you can use psql:
或者,您可以使用 psql:
psql -h 192.168.0.190 -p 5432 -d <dbname> -U <username> -W -f mydump.dump
psql -h 192.168.0.190 -p 5432 -d <dbname> -U <username> -W -f mydump.dump
回答by Dr Manhattan
An example for a remote RDS instance on AWS
AWS 上的远程 RDS 实例示例
psql -h mydb.dsdreetr34.eu-west-1.rds.amazonaws.com -p 5432 -d mydbname -U mydbuser -W -f mydatabase-dump.sql
-f, --file=FILENAME execute commands from file, then exit
-W, --password force password prompt (should happen automatically)
回答by Van
You can pass the password parameter in your script before "pg_restore" using PGPASSWORD="your_database_password"
您可以在“pg_restore”之前使用 PGPASSWORD="your_database_password" 在脚本中传递密码参数
回答by Franco S
I run this and works to me:
我运行这个并对我工作:
scp backup.dump user@remotemachine:~
ssh user@remotemachine "pg_restore -h localhost -p 5432 -U databaseuser -W -F c -d databasename -v backup.dump"
You can write a script to automate this.
您可以编写一个脚本来自动执行此操作。