Greenplum 主备节点(master和standby)手动切换 步骤详细

1.准备

本次针对GP6.x版本之前
主备节点:
master:node01
standbymaster:node02
 
查看集群备用节点状态:
gpstate -f
20190104:14:34:34:261113 gpstate:node01:gpadmin-[INFO]:-Starting gpstate with args: -f
20190104:14:34:34:261113 gpstate:node01:gpadmin-[INFO]:-local Greenplum Version: 'postgres (Greenplum Database) 5.14.0 build commit:13927a46a9b39527fc1af2cbb1571d4fd394ff88'
20190104:14:34:34:261113 gpstate:node01:gpadmin-[INFO]:-master Greenplum Version: 'PostgreSQL 8.3.23 (Greenplum Database 5.14.0 build commit:13927a46a9b39527fc1af2cbb1571d4fd394ff88) on x86_64-pc-linux-gnu, compiled by GCC gcc (GCC) 6.2.0, 64-bit compiled on Nov 28 2018 08:08:06'
20190104:14:34:34:261113 gpstate:node01:gpadmin-[INFO]:-Obtaining Segment details from master...
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-Standby master details
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-----------------------
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-   Standby address          = node02
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-   Standby data directory   = /data/master/gpseg-1
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-   Standby port             = 5432
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-   Standby PID              = 139960
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-   Standby status           = Standby host passive
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--------------------------------------------------------------
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--pg_stat_replication
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--------------------------------------------------------------
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--WAL Sender State: streaming
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--Sync state: sync
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--Sent Location: 0/199DF208
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--Flush Location: 0/199DF208
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--Replay Location: 0/199DF208
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--------------------------------------------------------------

2.模拟master宕机

在master节点下
# 切换用户
su - gpadmin
# 停止master
pg_ctl stop -s -m fast -D  $MASTER_DATA_DIRECTORY
或者
pg_ctl stop -s -m fast -D /data/master/gpseg-1
返回信息:server stopped
查看standby节点状态(master节点执行)
gpstate -f
20190104:14:56:12:262549 gpstate:node01:gpadmin-[INFO]:-Starting gpstate with args: -f
20190104:14:56:12:262549 gpstate:node01:gpadmin-[INFO]:-local Greenplum Version: 'postgres (Greenplum Database) 5.14.0 build commit:13927a46a9b39527fc1af2cbb1571d4fd394ff88'
20190104:14:56:12:262549 gpstate:node01:gpadmin-[CRITICAL]:-gpstate failed. (Reason='could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
') exiting...

集群进入异常状态,无法获取信息

3.激活standby

(1)修改两个文件
su - dbadmin
vi .bashrc
vi .bash_profile
source /usr/local/greenplum-db/greenplum_path.sh
export MASTER_DATA_DIRECTORY=/data/master/gpseg-1
cat >>/home/gpadmin/.bashrc<<-EOF
export PGPORT=5432
EOF
生效:
source ~/.bashrc
 
(2)激活standby节点
gpactivatestandby -d $MASTER_DATA_DIRECTORY
Do you want to continue with standby master activation? Yy|Nn (default=N):
Y 输入Y确认切换
 
再次查看standby节点状态
gpstate -f
20190104:15:05:17:199264 gpstate:node02:gpadmin-[INFO]:-Starting gpstate with args: -f
20190104:15:05:17:199264 gpstate:node02:gpadmin-[INFO]:-local Greenplum Version: 'postgres (Greenplum Database) 5.14.0 build commit:13927a46a9b39527fc1af2cbb1571d4fd394ff88'
20190104:15:05:17:199264 gpstate:node02:gpadmin-[INFO]:-master Greenplum Version: 'PostgreSQL 8.3.23 (Greenplum Database 5.14.0 build commit:13927a46a9b39527fc1af2cbb1571d4fd394ff88) on x86_64-pc-linux-gnu, compiled by GCC gcc (GCC) 6.2.0, 64-bit compiled on Nov 28 2018 08:08:06'
20190104:15:05:17:199264 gpstate:node02:gpadmin-[INFO]:-Obtaining Segment details from master...
20190104:15:05:18:199264 gpstate:node02:gpadmin-[INFO]:-Standby master instance not configured
20190104:15:05:18:199264 gpstate:node02:gpadmin-[INFO]:--------------------------------------------------------------
20190104:15:05:18:199264 gpstate:node02:gpadmin-[INFO]:--pg_stat_replication
20190104:15:05:18:199264 gpstate:node02:gpadmin-[INFO]:--------------------------------------------------------------
20190104:15:05:18:199264 gpstate:node02:gpadmin-[INFO]:-No entries found.
20190104:15:05:18:199264 gpstate:node02:gpadmin-[INFO]:--------------------------------------------------------------

集群可以查看状态,无法获取信息备用节点信息,此时集群可以访问;

将原有主节点添加为standby (master节点,gpadmin账户操作)
这里添加的时候,会check master的数据库目录,要把原master节点的的目录删除或者重命名
mv /data/master/gpseg-1  /data/master/gpseg-1.bak
 
将原有主节点先添加为standby节点(在standby节点)
gpinitstandby -s node01
到此为止主备切换完成
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值