通过ssh隧道进行pgAdmin3备份

时间:2015-09-04 12:39:27

标签: postgresql backup pgadmin ssh-tunnel

我在amazone ec2上运行了postgresql服务器。我通过ssh隧道连接pgAdmin3,直接在我的mac的pgAdmin3中配置。 我可以查询并查看完整的架构,没问题。

如果我尝试备份数据库(来自pgAdmin3 GUI),那么我得到(即使连接实际上是打开并正常工作)以下异常:

/Applications/pgAdmin3.app/Contents/SharedSupport/pg_dump --host localhost --port 5432 --username "MY_USERNAME" --role "MY_ROLE" --no-password  --format custom --encoding UTF8 --verbose --file "/Users/XXX/filename" "DATABASENAME"
pg_dump: [archiver (db)] connection to database "DATABASENAME" failed: could not connect to server: Connection refused
	Is the server running on host "localhost" (::1) and accepting
	TCP/IP connections on port 5432?
could not connect to server: Connection refused
	Is the server running on host "localhost" (127.0.0.1) and accepting
	TCP/IP connections on port 5432?

Process ended with Exitcode 1.

知道为什么后台的pg_dump无法通过ssh隧道连接吗?

2 个答案:

答案 0 :(得分:1)

替代方案直到我发现解决方案是通过终端

来实现
ssh <HOST> "pg_dump -U <USERNAME> -W -h localhost -F c <DATABASENAME> | gzip -c" > ./backup.sql.gz

答案 1 :(得分:0)

这条线对我有用:

ssh -o "Compression=no" server_adress "pg_dump -Z9 -Fc -U postgres db_name" > backup_name.dump