db_ha叢集安裝後的自動切換及切換後的判斷步驟說明文件

瀚高PG實驗室發表於2023-10-25

瀚高資料庫

目錄

環境

檔案用途

詳細資訊

相關檔案


環境 系統平臺: Linux x86-64 Red Hat Enterprise Linux 7

版本: 4.5.7


檔案用途

本檔案用於指導db_ha叢集安裝後的自動切換及切換後的判斷步驟


詳細資訊

一、db_ha叢集,會在主庫斷網,主庫當機的情況下發生主備切換,具體模擬實驗請檢視附件。

二、db_ha叢集,原主庫伺服器在恢復正常狀態之後,會自動降級為備庫加入叢集。

三、判斷切換之後的叢集為狀態採用如下方法。

1、檢查叢集流複製


①主庫檢視send程式

ps -ef | grep -v grep | grep walsender
root     21466 19862  0 14:51 ?        00:00:00 postgres: walsender sysdba 192.168.80.230(36582) streaming 0/4053860
root     23017 19862  0 15:06 ?        00:00:00 postgres: walsender sysdba 192.168.80.228(47786) streaming 0/4053860


②備庫檢視receive程式


ps -ef | grep -v grep | grep walreceive
root     13489 13482  0 15:45 ?        00:00:06 postgres: walreceiver   streaming 0/6004460


③如果資料庫查不到send和receive程式,只有post程式,資料庫已經脫離流複製,成為單機。


ps -ef | grep post
root      4148     1  0 6月13 ?       00:04:36 /opt/HighGo4.5.7-see/bin/postgres -D /opt/HighGo4.5.7-see/data
root      4149  4148  0 6月13 ?       00:00:00 postgres: logger
root      4150  4148  1 6月13 ?       00:11:30 postgres: auditwriter
root      4152  4148  0 6月13 ?       00:00:00 postgres: checkpointer
root      4153  4148  0 6月13 ?       00:00:04 postgres: background writer
root      4154  4148  0 6月13 ?       00:00:54 postgres: stats collector
root      4156  4148  0 6月13 ?       00:00:00 postgres: audit archiver or cleanup
root      4314  4148  0 6月13 ?       00:00:04 postgres: walwriter
root      4315  4148  0 6月13 ?       00:00:01 postgres: autovacuum launcher
root      4316  4148  0 6月13 ?       00:00:00 postgres: archiver   last was 000000040000000000000008
root      4317  4148  0 6月13 ?       00:00:00 postgres: logical replication launche


④如果資料庫post程式也查詢不到,說明資料庫不在執行。


2、使用叢集命令檢視


①叢集狀態正常:叢集所有節點healthy=t,nodetype=STANDBY的節點streamingState=streaming表示正常。


/usr/local/db_ha/bin/db_ha select -f /usr/local/db_ha/conf/db_ha.conf
connect monitor success
cluster num = 3         secondary monitor is normal
nodeip=192.168.80.228,nodetype=PRIMARY,replicationName=ha228 streamingType=NONE streamingState=none healthy=t agentState=NORMAL
nodeip=192.168.80.229,nodetype=STANDBY,replicationName=ha229 streamingType=ASYNC streamingState=streaming healthy=t agentState=NORMAL
nodeip=192.168.80.230,nodetype=STANDBY,replicationName=ha230 streamingType=ASYNC streamingState=streaming healthy=t agentState=NORMAL


②叢集檢查,228節點異常,streamingState=none healthy=f。


/usr/local/db_ha/bin/db_ha select -f /usr/local/db_ha/conf/db_ha.confconnect monitor success
cluster num = 3         secondary monitor is normal
nodeip=192.168.80.229,nodetype=PRIMARY,replicationName=ha229 streamingType=NONE streamingState=none healthy=t agentState=NORMAL
nodeip=192.168.80.228,nodetype=PRIMARY,replicationName=ha228 streamingType=NONE streamingState=none healthy=f agentState=UNUSUAL
nodeip=192.168.80.230,nodetype=STANDBY,replicationName=ha230 streamingType=ASYNC streamingState=streaming healthy=t agentState=NORMAL


3、pg_controldata檢視資料庫時間線和狀態

注意:資料庫各個節點時間線不一致,叢集出現問題。


①如下表示主庫正常執行

export LANG="en_US.UTF-8"
pg_controldata |grep -E "TimeLineID|state"
Database cluster state:               in production
Latest checkpoint's TimeLineID:       4
Latest checkpoint's PrevTimeLineID:   4


②如下表示備庫正常執行


export LANG="en_US.UTF-8"
pg_controldata |grep -E "TimeLineID|state"
Database cluster state:               in archive recovery
Latest checkpoint's TimeLineID:       4
Latest checkpoint's PrevTimeLineID:   4


4、檢視備庫標誌standby.signal


ll /opt/HighGo4.5.7-see/data/standby.signal
-rw------- 1 root root 18 6月  13 15:45 /opt/HighGo4.5.7-see/data/standby.signal



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

相關文章