postgresql非同步流複製搭建

來源:互聯網
上載者:User

標籤:postgresql 非同步流複製 standby自動啟用

節點 IP 角色
citus-master 10.10.100.1 master
citus-standby 10.10.100.2 standby

    master上建立流複製所需要的使用者。

CREATE ROLE replication WITH REPLICATION PASSWORD ‘replication‘ LOGIN;

    修改master的pg_hba.conf檔案,設定replication使用者遠端存取許可權

## vim /data/pgsql/data/pg_hba.conf,追加下面一行host    replication     replication        10.10.0.0/16         md5

    master上設定與複製相關的參數

wal_level = hot_standbymax_wal_senders = 5wal_keep_segments = 32

    master上重啟pgsql

/etc/init.d/postgresql-9.5 restart

    standby上使用pg_basebackup對master做一次全備並將備份拉到standby上來

pg_basebackup -h 10.10.100.1 -D /var/lib/pgsql/9.5/data/ -P -U replication -R  --xlog-method=stream

    修改standby節點上的postgresql.conf檔案,設定備庫為standby的狀態

## vim /data/pgsql/data/postgresql.confhot_standby = on

    修改standby的recovery.done檔案,設定master節點的同步資訊及trigger檔案

standby_mode = ‘on‘primary_conninfo = ‘user=replication password=replication host=10.10.100.1 port=5432 sslmode=prefer sslcompression=1 krbsrvname=postgres‘trigger_file = ‘/data/pgsql/data/postgresql.trigger.1973‘

    standby上重啟pgsql

/etc/init.d/postgresql-9.5 restart

    可以在master上建立一張測試表並插入資料,來驗證standby上是否同步過來資料。當master掛掉之後,在standby上建立trigger_file參數聲明的檔案,就會觸發standby的啟用,會自動把standby提升為master。

    當master掛掉之後,standby上建立trigger file之後,recovery.conf將會重新命名為recovery.done。這時standby將會接管master進入可讀寫狀態。緊接著可以將原來的master設定為現在的standby,過程如下

## 建立recovery.conf,寫入下面內容recovery_target_timeline = ‘latest‘standby_mode = ‘on‘primary_conninfo = ‘user=replication password=replication host=10.10.100.2 port=5432 sslmode=prefer sslcompression=1 krbsrvname=postgres‘
## vim postgresql.conf檔案,開啟hot_standbyhot_standby = on

    最後重啟pgsql,並查看日誌

/etc/init.d/postgresql-9.5   restarttail -9f  pg_log/postgresql-Tue.log< 2016-11-01 16:51:53.590 CST >LOG:  shutting down< 2016-11-01 16:51:53.594 CST >LOG:  database system is shut down< 2016-11-01 16:51:54.679 CST >LOG:  database system was shut down in recovery at 2016-11-01 16:51:53 CST< 2016-11-01 16:51:54.679 CST >LOG:  entering standby mode< 2016-11-01 16:51:54.692 CST >LOG:  consistent recovery state reached at 0/F001430< 2016-11-01 16:51:54.692 CST >LOG:  redo starts at 0/F001430< 2016-11-01 16:51:54.692 CST >LOG:  database system is ready to accept read only connections< 2016-11-01 16:51:54.692 CST >LOG:  invalid record length at 0/F001510< 2016-11-01 16:51:54.697 CST >LOG:  started streaming WAL from primary at 0/F000000 on timeline 3




本文出自 “勇敢向前,堅決向左” 部落格,謝絕轉載!

postgresql非同步流複製搭建

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.