postgresql基於流複製 (streaming replication)的warm-standby

panpong發表於2017-02-09

postgresql基於流複製 (streaming replication)warm-standby

 
例項一枚:

Primary:

l  歸檔設定:

         Wal_level=archive

         Archive_mode=on

         archive_command = 'cp -i %p /data/pgsql/archived_wal/%f'

l  流複製相關設定:

         max_wal_senders = '10'       #啟動複製程式數量限制,必須大於0

max_replication_slots = '10'   #為使用replication slot,必須大於0replication slot作用是保證wal沒有同步到standby之前不能從pg_xlog移走;

wal_keep_segments = '50'               #指定pg_xlog中最少保留的wal數量

 

select pg_create_physical_replication_slot(‘gp1_a_slot’);  #建立replication slot

select * from pg_replication_slots;                            #查詢建立的replication slot

 

l  編輯pg_hba.conf

# Allow replication connections from localhost, by a user with the replication privilege.

#host    replication     postgres        127.0.0.1/32            trust

#host    replication     postgres        ::1/128                 trust

local   replication     postgres                                trust

host    replication     postgres        192.168.12.0/24            trust

l  聯機備份過程(基礎備份)

#touch /var/lib/pgsql/backup_in_progress

$psql –c "select pg_start_backup('hot_backup');"

$tar -cf /var/lib/pgsql/backup.tar /var/lib/pgsql/data/

$psql -c "select pg_stop_backup();"

#rm /var/lib/pgsql/backup_in_progress

tar -rf /var/lib/pgsql/backup.tar /var/lib/pgsql/archive/  #打包歸檔

例項:

psql -c "select pg_start_backup('pgbk10');"

tar -zcf pgbk10.tgz data/

psql -c "select pg_stop_backup();"

 

Standby

l  編輯recovery.conf

standby_mode = 'on'

primary_conninfo = 'host=192.168.12.38 port=5666 user=postgres'

primary_slot_name='gp1_a_slot'

#restore_command = 'cp /data/pgsql/archived_wal/%f %p'

#archive_cleanup_command = 'pg_archivecleanup /data/pgsql/archived_wal %r'

 

l  將primary上的基礎備份傳輸到standby

$scp primary: /var/lib/pgsql/backup.tar .

解壓備份到standby上的$PGDATA

l  啟動standby

$pg_ctl start –D $PGDATA

啟動standby後,postgres開始從primary上接收wal日誌進行恢復,並且一直保持恢復狀態,psql不能登入;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16976507/viewspace-2133328/,如需轉載,請註明出處,否則將追究法律責任。

相關文章