天天看點

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)

(四)提升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

(八)重做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)

使用方式

以上更新最好在資料庫主版本一緻的情況下進行

如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

如遇到此情況,需要先停止Master資料庫對外服務,然後更新Master為大版本,重新做Slave解決

如果slave(9.5.2)更新到(9.5.3)

 可以順利更新

本文轉自 pgmia 51CTO部落格,原文連結:http://blog.51cto.com/heyiyi/1928603