[英]Restoring a postgres database I dumped from remote
I'm trying to dump and restore a Postgres database hosted on an AWS bastion, using psql.我正在尝试使用 psql 转储和恢复托管在 AWS 堡垒上的 Postgres 数据库。 To do that I need to open a SSH tunnel.
为此,我需要打开一个 SSH 隧道。
I open the tunnel this way: ssh -v -A admin@bastion.my.company.name -L 15432:databasename.amazonaws.com:5432 -N
我这样打开隧道:
ssh -v -A admin@bastion.my.company.name -L 15432:databasename.amazonaws.com:5432 -N
Then dump it with: pg_dump -v -h 0.0.0.0 -p 15432 -U postgres -d databasename --clean -T tablesINeed > ~/pgdumps/databasenamedump.sql
然后转储它:
pg_dump -v -h 0.0.0.0 -p 15432 -U postgres -d databasename --clean -T tablesINeed > ~/pgdumps/databasenamedump.sql
So far so good, I can dum through my tunnel.到目前为止一切顺利,我可以通过我的隧道。 Then I close the tunnel and try to restore:
psql -h 0.0.0.0 -p 5432 -U postgres -d databasename < ~/pgdumps/databasenamedump.sql
然后我关闭隧道并尝试恢复:
psql -h 0.0.0.0 -p 5432 -U postgres -d databasename < ~/pgdumps/databasenamedump.sql
But I get:但我得到:
psql: error: could not connect to server: could not connect to server: Connection refused Is the server running on host "0.0.0.0" and accepting TCP/IP connections on port 5432?
psql:错误:无法连接到服务器:无法连接到服务器:连接被拒绝 服务器是否在主机“0.0.0.0”上运行并接受端口 5432 上的 TCP/IP 连接?
How is that?那个怎么样? I probably don't understand dump/restore conceptually?
我可能在概念上不理解转储/恢复? Once I have my dumped db, I simply want to run a local instance of it.
一旦我有了我的转储数据库,我只想运行它的本地实例。 Am I supposed to use
15432
(the port I opened for the ssh tunnel) to restore?我应该使用
15432
(我为 ssh 隧道打开的端口)来恢复吗? I'm afraid of trying as this is a production database.我害怕尝试,因为这是一个生产数据库。 I tried looking on psql documentation but didn't find a similar scenario
我尝试查看 psql 文档,但没有找到类似的情况
Thank you for any clarification感谢您的任何澄清
Once I have my dumped db, I simply want to run a local instance of it.
一旦我有了我的转储数据库,我只想运行它的本地实例。 Am I supposed to use 15432 (the port I opened for the ssh tunnel) to restore?
我应该使用 15432(我为 ssh 隧道打开的端口)来恢复吗? I'm afraid of trying as this is a production database.
我害怕尝试,因为这是一个生产数据库。
You are correct to be afraid.你害怕是对的。 That would restore back to the same database you dumped from, which is not what you want to happen.
这将恢复到您从中转储的同一个数据库,这不是您想要发生的。 Changes on production since the dump could be lost, since you had specified
--clean
to pg_dump.由于您已将
--clean
指定为 pg_dump,因此可能会丢失自转储以来的生产更改。
pg_restore doesn't create the database instance, it just restores into an already running instance. pg_restore 不创建数据库实例,它只是恢复到一个已经运行的实例中。 So you have to start by doing an
initdb
(or equivalent) to create such an instance, and pg_ctl start
(or equivalent) to start it up.因此,您必须首先执行
initdb
(或等效项)来创建这样的实例,然后执行pg_ctl start
(或等效项)来启动它。 Unless of course you have already done those things, but the error message you get suggests that you have not, or didn't do it correctly.当然,除非您已经完成了这些操作,但是您收到的错误消息表明您没有或没有正确地执行这些操作。
I tried looking on psql documentation but didn't find a similar scenario
我尝试查看 psql 文档,但没有找到类似的情况
psql
is just a command line "client" tool for connecting to the database, it is not the database software itself, so its documentation wouldn't be very relevant to you. psql
只是一个用于连接数据库的命令行“客户端”工具,它不是数据库软件本身,因此它的文档与您无关。
You may need to take a step back and start at the beginning .您可能需要退后一步,从头开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.