Greenplum 添加或删除standby master节点

Greenplum支持master节点的standby,如果你在初始化集群时没有创建standby节点,或者原来的standby节点坏了或者其他原因,要重搭standby。
本文将告诉你怎么做。
1. 如果要新建standby,但是原来已有standby,首先要删除它。
gpinitstandby -r 
如果原来的standby只是某种原因挂了,不需要删除,只需要重启,则使用以下命令来重启standby 
gpinitstandby -n

2. 如果搭建standby的机器不在原来的GP集群中,则需要将机器添加进来。
详细添加方法参考   http://yq.aliyun.com/articles/177  (本文不再重复,大致的内容如下)
   环境配置,例如OS kernel 参数;
   创建gp管理用户;
   ssh key的交换(使用gpssh-exkeys -e exist_hosts -x new_hosts);
   greenplum bin软件的拷贝;
   使用gpcheck检查 (gpcheck -f new_hosts );
   使用gpcheckperf检查性能 (gpcheckperf -f new_hosts_file -d /data1 -d /data2 -v)

3. 如果在GP已有集群中的机器中选择一台来搭建standby,则可以跳过第二步。
了解master节点用了哪些filespace.
postgres=# select a.dbid,a.content,a.role,a.port,a.hostname,b.fsname,c.fselocation from gp_segment_configuration a,pg_filespace b,pg_filespace_entry c where a.dbid=c.fsedbid and b.oid=c.fsefsoid order by content;
 dbid | content | role | port  |     hostname      |  fsname   |              fselocation              
------+---------+------+-------+-------------------+-----------+---------------------------------------
    1 |      -1 | p    |  1921 | digoal_host.sqa.zmf | pg_system | /disk1/digoal/gpdata/gpseg-1
    1 |      -1 | p    |  1921 | digoal_host.sqa.zmf | ssd1      | /disk1/digoal/new_p/gp-1
。。。。。。
了解master的即可,可以看到除了pg_system,还有一个filespace叫ssd1。

4. 进入初始化standby的步骤。
根据第三步查到的信息,规划standby master filespace数据目录;
$ mkdir /disk1/digoal/gpdata
$ mkdir /disk1/digoal/new_p

如果在不同的主机创建standby master,则建议使用同样的端口和目录结构。
如下:
$gpinitstandby -F pg_system:/data01/gpdata/master_pgdata/gpseg-1 -s digoal_host199092.zmf 
20151221:14:17:24:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Validating environment and parameters for standby initialization...
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Checking for filespace directory /data01/gpdata/master_pgdata/gpseg-1 on digoal_host199092.zmf
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:------------------------------------------------------
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Greenplum standby master initialization parameters
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:------------------------------------------------------
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Greenplum master hostname               = digoal_host193096.zmf
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Greenplum master data directory         = /data01/gpdata/master_pgdata/gpseg-1
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Greenplum master port                   = 1921
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Greenplum standby master hostname       = digoal_host199092.zmf
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Greenplum standby master port           = 1921
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Greenplum standby master data directory = /data01/gpdata/master_pgdata/gpseg-1
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Greenplum update system catalog         = On
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:------------------------------------------------------
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:- Filespace locations
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:------------------------------------------------------
20151221:14:17:25:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-pg_system -> /data01/gpdata/master_pgdata/gpseg-1
Do you want to continue with standby master initialization? Yy|Nn (default=N):
> y
20151221:14:26:46:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Syncing Greenplum Database extensions to standby
20151221:14:26:46:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-The packages on digoal_host199092.zmf are consistent.
20151221:14:26:46:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Adding standby master to catalog...
20151221:14:26:46:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Database catalog updated successfully.
20151221:14:26:47:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Updating pg_hba.conf file...
20151221:14:26:52:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-pg_hba.conf files updated successfully.
20151221:14:26:56:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Updating filespace flat files...
20151221:14:26:56:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Filespace flat file updated successfully.
20151221:14:26:56:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Starting standby master
20151221:14:26:56:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Checking if standby master is running on host: digoal_host199092.zmf  in directory: /data01/gpdata/master_pgdata/gpseg-1
20151221:14:27:00:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Cleaning up pg_hba.conf backup files...
20151221:14:27:06:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Backup files of pg_hba.conf cleaned up successfully.
20151221:14:27:06:012334 gpinitstandby:digoal_host193096:digoal-[INFO]:-Successfully created standby master on digoal_host199092.zmf

digoal=# select * from gp_segment_configuration where content='-1';
 dbid | content | role | preferred_role | mode | status | port |     hostname      |      address      | replication_port | san_mounts 
------+---------+------+----------------+------+--------+------+-------------------+-------------------+------------------+------------
    1 |      -1 | p    | p              | s    | u      | 1921 | digoal_host193096.zmf | digoal_host193096.zmf |                  | 
   26 |      -1 | m    | m              | s    | u      | 1921 | digoal_host199092.zmf | digoal_host199092.zmf |                  | 
(2 rows)

如果在同一台主机创建standby master,则需要使用不同的端口和目录结构。
如下:
指定不同的filespace路径,不同的监听端口。
$gpinitstandby -F pg_system:/disk1/digoal/gpdata/gpseg-2,ssd1:/disk1/digoal/new_p/gp-2 -P 1922 -s digoal_host.sqa.zmf
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Validating environment and parameters for standby initialization...
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Checking for filespace directory /disk1/digoal/gpdata/gpseg-2 on digoal_host.sqa.zmf
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Checking for filespace directory /disk1/digoal/new_p/gp-2 on digoal_host.sqa.zmf
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:------------------------------------------------------
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Greenplum standby master initialization parameters
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:------------------------------------------------------
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Greenplum master hostname               = digoal_host.sqa.zmf
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Greenplum master data directory         = /disk1/digoal/gpdata/gpseg-1
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Greenplum master port                   = 1921
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Greenplum standby master hostname       = digoal_host.sqa.zmf
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Greenplum standby master port           = 1922
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Greenplum standby master data directory = /disk1/digoal/gpdata/gpseg-2
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Greenplum update system catalog         = On
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:------------------------------------------------------
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:- Filespace locations
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:------------------------------------------------------
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-pg_system -> /disk1/digoal/gpdata/gpseg-2
20151221:14:34:01:077652 gpinitstandby:digoal_host:digoal-[INFO]:-ssd1 -> /disk1/digoal/new_p/gp-2
Do you want to continue with standby master initialization? Yy|Nn (default=N):
> y
20151221:14:34:03:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Syncing Greenplum Database extensions to standby
20151221:14:34:03:077652 gpinitstandby:digoal_host:digoal-[INFO]:-The packages on digoal_host.sqa.zmf are consistent.
20151221:14:34:03:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Adding standby master to catalog...
20151221:14:34:04:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Database catalog updated successfully.
20151221:14:34:05:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Updating pg_hba.conf file...
20151221:14:34:13:077652 gpinitstandby:digoal_host:digoal-[INFO]:-pg_hba.conf files updated successfully.
20151221:14:34:31:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Updating filespace flat files...
20151221:14:34:31:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Writing standby information to /disk1/digoal/gpdata/gpseg-1/gp_transaction_files_filespace flat file
20151221:14:34:32:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Writing standby information to /disk1/digoal/gpdata/gpseg-1/gp_temporary_files_filespace flat file
20151221:14:34:32:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Filespace flat file updated successfully.
20151221:14:34:32:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Starting standby master
20151221:14:34:32:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Checking if standby master is running on host: digoal_host.sqa.zmf  in directory: /disk1/digoal/gpdata/gpseg-2
20151221:14:36:16:077652 gpinitstandby:digoal_host:digoal-[WARNING]:-Could not start standby master
20151221:14:36:16:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Cleaning up pg_hba.conf backup files...
20151221:14:36:21:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Backup files of pg_hba.conf cleaned up successfully.
20151221:14:36:21:077652 gpinitstandby:digoal_host:digoal-[INFO]:-Successfully created standby master on digoal_host.sqa.zmf

启动standby
$gpinitstandby -n
20151221:14:39:40:085625 gpinitstandby:digoal_host:digoal-[INFO]:-Starting standby master
20151221:14:39:40:085625 gpinitstandby:digoal_host:digoal-[INFO]:-Checking if standby master is running on host: digoal_host.sqa.zmf  in directory: /disk1/digoal/gpdata/gpseg-2

查看standby延迟,查看pg_stat_replication 视图即可。
digoal=# select pg_switch_xlog();
 pg_switch_xlog 
----------------
 0/C0000D8
(1 row)
digoal=# select * from pg_stat_replication ;
 procpid | usesysid | usename  | application_name |  client_addr  | client_port |         backend_start         |   state   | sent_location | write_location | flush_location | replay_location | sync_priority | sync_state 
---------+----------+----------+------------------+---------------+-------------+-------------------------------+-----------+---------------+----------------+----------------+-----------------+---------------+------------
   13444 |       10 | dege.zzz | walreceiver      | 100.69.199.92 |       47792 | 2015-12-21 14:27:00.164785+08 | streaming | 0/D080000     | 0/CC00000      | 0/C880000      | 0/C0000B8       |             1 | sync
(1 row)
...
digoal=# select * from pg_stat_replication ;
 procpid | usesysid | usename  | application_name |  client_addr  | client_port |         backend_start         |   state   | sent_location | write_location | flush_location | replay_location | sync_priority | sync_state 
---------+----------+----------+------------------+---------------+-------------+-------------------------------+-----------+---------------+----------------+----------------+-----------------+---------------+------------
   13444 |       10 | dege.zzz | walreceiver      | 100.69.199.92 |       47792 | 2015-12-21 14:27:00.164785+08 | streaming | 0/10000000    | 0/10000000     | 0/10000000     | 0/10000000      |             1 | sync
(1 row)
参考
gpinitstandby -?
上一篇:kvm虚拟化学习笔记(十九)之convirt集中管理平台搭建


下一篇:redis 集群指导