PostgreSQL9.0でReplicationとHot Standbyを試してみる
On The Mater Server
postgresql.confとpostgresql.conf_orgについて設定変更のdiffを記載する
154d153
< wal_level = hot_standby # minimal, archive, or hot_standby
183d181
< archive_mode = on # allows archiving to be done
186d183
< archive_command = 'cp -i %p /usr/local/pgsql/data/archive/%f </dev/null' # command to use to archive a logfile segment
193d189
< max_wal_senders = 1 # max number of walsender processes
197d195
< wal_keep_segments = 32 # in logfile segments, 16MB each; 0 disables
※ここでarchiveフォルダを作成すること。
pg_hba.confとpg_hba.conf_orgについて設定変更のdiffを記載する
ここではslave serverの設定を行う
83d82
< host replication all ***.***.***.***/32 trust
dataフォルダ以下をbackupしてSlaveサーバーへコピーする
$ psql -c "SELECT pg_start_backup('label', true)"
$ rsync -a ${PGDATA}/ ***.***.***.***:/usr/local/pgsql/data/ --exclude postmaster.pid
$ psql -c "SELECT pg_stop_backup()"
On The Slave Server
dataフォルダー以下を展開してからpostgresql.confを変更する。
postgresql.confとpostgresql.conf_orgについて設定変更のdiffを記載する
198d197
< hot_standby = on # "on" allows queries during recovery
recovery.confとrecovery.conf_orgについて設定変更のdiffを記載する
47d46
< restore_command = 'cp /usr/local/pgsql/data/restore_archive/%f %p' # e.g. 'cp /mnt/server/archivedir/%f %p'
100d98
< standby_mode = 'on'
103d100
< primary_conninfo = 'host=***.***.***.*** port=5432 user=postgres' # e.g. 'host=localhost port=5432'
113d109
< trigger_file = '/usr/local/pgsql/data/trigger'
※ここでrestore_archive, triggerフォルダを作成すること。
※postmaster.pidが残って入れば削除すること。
pg_xlogが壊れた場合
pg_resetxlog data -f
参考資料:
Ayutaya.com PostgreSQL-9.0 ホットスタンバイ構築
Load barancer for django and Hot stand by mode
5 steps to implement a PostgreSQL replication system