启动和停止双机
在双机数据库安装完毕后,需要通过正确的方式启动两边的数据库,然后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