有人可以帮助我的postgres最常见的稳定的复制机制 ,我可以在一天的特定时间运行(知道这听起来很奇怪)postgres,可以运行在SSH?
通过ssh是因为我的机器只有一个networking接口的linode – 公共,我不想公开端口
我使用从crontab启动的脚本:这个脚本创build一个到远程postgres主机的ssh隧道,使用本地的psql二进制启动到远程postgres数据库的会话,然后杀死隧道。
例如:
# $REMOTE is the hostname of the remote postgres server # this tunnel maps the local port 50432 to the remote port 5432 where the # remote postgres instance is listening /usr/bin/ssh -nNT postgres@${REMOTE} -L 50432:localhost:5432 & TUNNELPID=$! # wait a little for the tunnel to establish itself sleep 5 # execute the statements in load.sql against the remote database 'remotepgdb' /usr/local/pgsql/bin/psql -q -h localhost -p 50432 -U remotepguser remotepgdb < ${SCRIPT_PATH}/load.sql # kill the ssh tunnel /usr/bin/kill ${TUNNELPID}
在尝试这种技术之前,我build议确保本地psql客户端和远程postgres数据库的版本完全相同。
你也可以看看pgpool 。 我们使用它来持续复制postgres数据库,如果你保持ssh-tunnel(或stunnel),你可以在传输过程中encryption数据