Pg 流複製方式HA 版本升級步驟

一、HA Description:

Master:192.168.1.10

Slave:192.168.1.20

VIP: eth0:pgvip(master and slave) 192.168.1.30

PGDATA: /pgdata95

pg_version: 9.5.2


二、upgrade steps:

(一)升級Slave數據庫軟件版本

1.postgres(192.168.1.20)

pg_ctl -D /pgdata95 stop -m fast


2.postgres(192.168.1.20)

update postgresql soft version,不使用pg_upgrade命令方式升級,僅小版本升級使用9.5.2 --》 9.5.3

安裝同主分支版本 例如,9.5.3

3.postgres(192.168.1.20)

修改數據庫PATH爲最新版本的bin路徑,例如,

# Installation prefix

prefix=/opt/pgsql/9.5.7(新版本軟件目錄)

# Data directory

PGDATA="/pgdata95"(原data目錄)

啓動salve

pg_ctl -D /path/to/database start



(二)停止VIP,禁止提供服務

4.root(192.168.1.10)

ifconfig eth0:pgvip down


(三)Master 執行檢查點

5.db super(192.168.1.10)

checkpoint;


6.postgres(192.168.1.10)

SELECT sent_location, replay_location

FROM pg_stat_replication WHERE usename = 'rep_user';


7.postgres(192.168.1.10)

重複以上查詢,直到sent_location 和 replay_location 相等


8.postgres(192.168.1.10)

pg_ctl -D /pgdata95 stop -m fast


(四)提升Slave爲Master

9.postgres(192.168.1.20)

pg_ctl -D /pgdata95 promote


(五)啓動VIP,對外提供服務

10.root(192.168.1.20)

ifconfig eth0:pgvip 192.168.1.30 up


(六)通知研發或者運維重啓應用程序的數據庫連接池

11.如果必要,通知研發與支持重啓應用程序的數據庫連接池。


(七)升級 Master 數據庫軟件版本

12.postgres(192.168.1.10)

update postgresql soft version

修改數據庫PATH爲最新版本的bin路徑,例如,

# Installation prefix

prefix=/opt/pgsql/9.5.7(新版本軟件目錄)

# Data directory

PGDATA="/pgdata95"(原data目錄)


(八)重做Slave

13.postgres(192.168.1.10)

清空數據庫數據目錄,rm -Rf /pgdata95


14.postgres(192.168.1.10)

pg_basebackup -U rep_user -h 192.168.1.20 -D /pgdata95 --checkpoint=fast --xlog-method=stream -R


(九)啓動新的Slave

15.postgres(192.168.1.10)

pg_ctl -D /path/to/database start


使用方式

以上升級最好在數據庫主版本一致的情況下進行

  1. 如slave(9.5.2)升級到(10.0.beta1),pg_upgrade升級方式

    slave日誌報錯:

    2017-05-23 00:09:19.319 CST [10078] FATAL:  database system identifier differs between the primary and standby

    2017-05-23 00:09:19.319 CST [10078] DETAIL:  The primary's identifier is 6417769161397888214, the standby's identifier is 6422989582

    707312045.

    2017-05-23 00:09:34.340 CST [10098] FATAL:  database system identifier differs between the primary and standby

    2017-05-23 00:09:34.340 CST [10098] DETAIL:  The primary's identifier is 6417769161397888214, the standby's identifier is 6422989582

    707312045.

    如遇到此情況,需要先停止Master數據庫對外服務,然後升級Master爲大版本,重新做Slave解決

  2. 如果slave(9.5.2)升級到(9.5.3)

 可以順利升級




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章