啟動和停止雙機
在雙機資料庫安裝完畢後,需要通過正确的方式啟動兩邊的資料庫,然後GaussDB雙機關系才能夠正常建立。(分别以gaussdba使用者身份登入GaussDB伺服器主機、備機、級聯備機和次級聯備機,并執行下面的操作。)
方式一:在啟動的時候便指定主備機。
雙機方案 | 啟動時指定主備 |
一主一備 | 執行如下指令啟動雙機服務: 主機:gs_ctl start -M primary 備機:gs_ctl start -M standby |
一主雙備 | 執行如下指令啟動雙機服務: 主機:gs_ctl start -M primary 備機1:gs_ctl start -M standby 備機2:gs_ctl start -M standby |
一主一備一級聯一次級聯 | 執行如下指令啟動雙機服務: 主機:gs_ctl start -M primary 備機:gs_ctl start -M standby 級聯備機:gs_ctl start -M cascadestandby 次級聯備機:gs_ctl start -M cascadestandby1 |
方式二:啟動以後指定主備機。
雙機方案 | 啟動後指定主備 |
一主一備 | 在主備機上分别執行如下指令: gs_ctl start -M pending 通知兩個節點的主備關系,執行如下指令: (1) 主機:gs_ctl notify -M primary (2) 備機:gs_ctl notify -M standby |
一主雙備 | 在一主雙備上分别執行如下指令: gs_ctl start -M pending 通知三個節點的主備關系,執行如下指令: (1) 主機:gs_ctl notify -M primary (2) 備機1:gs_ctl notify -M standby (3) 備機2:gs_ctl notify -M standby |
一主一備一級聯一次級聯 | 在一主一備一級聯一次級聯上分别執行如下指令: gs_ctl start -M pending 通知四個節點的主備關系,執行如下指令: (1) 主機:gs_ctl notify -M primary (2) 備機:gs_ctl notify -M standby (3) 級聯備機:gs_ctl notify -M cascadestandby (4) 次級聯備機:gs_ctl notify -M cascadestandby1 |
注意:如果磁盤 IO 繁忙,GaussDB資料庫啟動過程中會延時等待,這時檢視程序隻有主程序gaussmaster啟動成功,一段時間(取決于磁盤IO阻塞時間)後,其他程序才被拉起。如果發生這種情況,建議解除磁盤IO繁忙狀态。
- 如果值為NeedRepair,表示未建立雙機關系,需要重建雙機。
- 如果值為Normal,表示雙機狀态正常,此時雙機啟動成功。
注意:初次安裝GaussDB資料庫一般都不會建立雙機同步狀态,因為雙機的資料目錄不是同源的,即雙機的資料目錄不是同一個GaussDB資料庫初始化建立的,需要通過重建雙機使得雙機的資料目錄同源。
示例:以一主雙備GaussDB安裝後初次啟動為例
1.按照角色啟動三台資料庫伺服器。将其中一台作為主機,執行如下指令。
gs_ctl start -M primary
将另外兩台作為備機,分别執行如下指令。
gs_ctl start -M standby
2.分别在兩台備機上查詢雙機狀态,發現未與主機建立雙機關系,需要重建備機。
Ha state:
LOCAL_ROLE : Standby
STATIC_CONNECTIONS : 1
DB_STATE : NeedRepair
DETAIL_INFORMATION : repl1: SystemIDNotMatched
Senders info:
No information
Receiver info:
No information
注意:DB_STATE字段為NeedRepair,說明需要重建備機。
3.分别在兩台備機上執行gs_ctl build指令,進行重建。
waiting for server to shut down.... done
server stopped
xlog start point: 0/3000020
gs_ctl: starting background WAL receiver
22407/22407 kB (100%), 1/1 tablespace
xlog end point: 0/30000E0
gs_ctl: waiting for background process to finish streaming...
gs_ctl: build completed.
server starting...... done
server started
4.分别在兩個備機上查詢雙機狀态。
Ha state:
LOCAL_ROLE : Standby
STATIC_CONNECTIONS : 1
DB_STATE : Normal
DETAIL_INFORMATION : Normal
Senders info:
No information
Receiver info:
RECEIVER_PID : 10640
LOCAL_ROLE : Standby
PEER_ROLE : Primary
PEER_STATE : Normal
STATE : streaming
SENDER_SENT_LOCATION : 0/3000000
SENDER_WRITE_LOCATION : 0/3000000
SENDER_FLUSH_LOCATION : 0/3000000
SENDER_REPLAY_LOCATION : 0/3000000
RECEIVER_RECEIVED_LOCATION : 0/3000000
RECEIVER_WRITE_LOCATION : 0/3000000
RECEIVER_FLUSH_LOCATION : 0/3000000
RECEIVER_REPLAY_LOCATION : 0/3000000
SYNC_PERCENT : 100%
CHANNEL : 10.144.197.189:52228 <--10.144.197.188:52228
注意:字段DB_STATE的值為Normal ,說明雙機狀态正常,雙機啟動成功。
5.分别在主機和兩個備機上停止資料庫運作。
[email protected]:~/opt/data> gs_ctl stop
waiting for server to shut down.... done
server stopped