参考文档:
http://wiki.postgresql.org/wiki/Warm_Standbyhttp://mrxiesdatabase.blogspot.com/2009/10/setting-up-postgresql-warm-standby.html
两台主机(dbmain/dbsub),都是Freebsd,Postgres 8.4.0 from ports
双方pgsql用户互信,部署ssh密钥,测试登录成功
安装rsync
在dbmain主机上设置postgresql.conf
- Archiving -
archive_mode = on # allows archiving to be done
# (change requires restart)
archive_command = 'rsync -a %p pgsql@dbsub:/data0/pool/wal/%f' # command to use to archive a logfile segment
archive_timeout = 1800 # force a logfile segment switch after this
# number of seconds; 0 disables
测试成功,在dbsub机上的 /data0/pool/wal 看到传输过来的 wal 文件。
将 dbsub 的数据库进程停止
rm -rf %DATA/*
将dbsub的postgresql.conf备份。
按
http://mrxiesdatabase.blogspot.com/2009/10/setting-up-postgresql-warm-standby.html 成生 recovery.conf 至备份区。
删除dbsub的数据区文件
同步数据区
psql -c "checkpoint;select pg_start_backup('dbbackup');"
rsync -a --progress ~/data/* pgsql@dbsub:/usr/local/pgsql/data
psql -c "select pg_stop_backup();
将备份的 postgresql.conf 和 recovery.conf 复制到 dbsub 的数据区
启动 dbsub 进程,失败,尝试过用 pg_ctl 或 /usr/local/etc/rc.d/postgres ,都不成功,提示
pg_ctl: another server might be running; trying to start server anyway
could not start server
查看系统日志,发现:
dbsub postgres[55938]: [1-1] FATAL: incorrect checksum in control file
求指点。
--
每一行代码都应该出自我手,工具可以帮我写,但不能替我写,更不能替我思考。
……
劉鑫
March.Liu