Postgres-XL集羣部署與管理指南

Postgres-XL是一個基於PostgreSQL數據庫的橫向擴展開源SQL數據庫集羣,具有足夠的靈活性來處理不同的數據庫工作負載,架構如下圖所示:

  • Web 2.0
  • 操作數據存儲
  • GIS的地理空間
  • 混合業務工作環境
  • OLTP 寫頻繁的業務
  • 多租戶服務提供商託管環境
  • 完全ACID,保持事務一致性
  • 包含JSON的Key-value 存儲
  • 需要MPP並行性商業智能/大數據分析
    Postgres-XL集羣部署與管理指南
    各個組件介紹如下:
  • Global Transaction Monitor (GTM)
    全局事務管理器,確保羣集範圍內的事務一致性。GTM負責發放事務ID和快照作爲其多版本併發控制的一部分。集羣也可以配置一個或多個備用GTM,以改進可用性。此外,可以在協調器間配置GTM代理, 可用於改善可擴展性,減少GTM的通信量。
  • GTM Standby
    GTM的備用節點,在pgxc,pgxl中,GTM控制所有的全局事務分配,如果出現問題,就會導致整個集羣不可用,爲了增加可用性,增加該備用節點。當GTM出現問題時,GTM Standby可以升級爲GTM,保證集羣正常工作。
  • GTM Proxy
    GTM需要與所有的Coordinators通信,爲了降低壓力,可以在每個Coordinator機器上部署一個GTM Proxy。
  • Coordinator
    協調員管理用戶會話,並與GTM和數據節點進行交互。協調員解析,並計劃查詢,並給語句中的每一個組件發送下一個序列化的全局性計劃。爲節省機器,通常此服務和數據節點部署在一起。
  • Data Node
    數據節點是數據實際存儲的地方。數據的分佈可以由DBA來配置。爲了提高可用性,可以配置數據節點的熱備以便進行故障轉移準備。
    總之,GTM是負責ACID的,保證分佈式數據庫全局事務一致性。得益於此,就算數據節點是分佈的,但是在主節點操作增刪改查事務時,就如同只操作一個數據庫一樣簡單。Coordinator是調度的,將操作指令發送到各個數據節點。datanodes是數據節點,分佈式存儲數據。

    1、安裝Postgres-XL

    1.1 集羣規劃

    四臺機器規劃如下圖所示:
    Postgres-XL集羣部署與管理指南

    1.2 操作系統配置

    禁用防火牆、selinux。各個節點通過yum安裝以下軟件包:

    [root@pg01 ~]# yum -y install bzip2 readline-devel flex make gcc rsync

    另外,各個節點創建postgres用戶:

    [root@pg01 ~]# groupadd postgres;useradd -g postgres postgres;echo redhat|passwd --stdin postgres

    用戶創建完成後,還需要在各個節點配置postgres用戶的免密碼登錄(略)。然後編輯postgres用戶的環境變量,加入如下內容:

    [root@pg01 ~]# mkdir /u01;chown postgres:postgres /u01
    [root@pg01 ~]# su - postgres
    [postgres@pg01 ~]$ vi .bashrc
    export PGUSER=postgres
    export PGHOME=/usr/local/pgsql
    export PGXC_CTL_HOME=/u01/pgxl/pgxc_ctl
    export LD_LIBRARY_PATH=$PGHOME/lib
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
    export PATH=$PGHOME/bin:$PATH:$HOME/.local/bin:$HOME/bin

    1.3 Postgres-XL安裝

    在各個節點以root用戶進行安裝,默認的安裝目錄是/usr/local/pgsql。

    [root@pg01 ~]# wget https://×××w.postgres-xl.org/downloads/postgres-xl-10r1.tar.gz;tar -xzf postgres-xl-10r1.tar.gz;cd postgres-xl-10r1;./configure&&make&&make install
    [root@pg01 postgres-xl-10r1]#  cd contrib;make && make install

    2、配置Postgres-XL集羣

    2.1 生成pgxc_ctl配置文件

    在一個節點操作即可。

    [postgres@pg01 ~]$ pgxc_ctl
    PGXC prepare
    PGXC exit

    編輯生成的配置文件,內容如下:

    pgxcInstallDir=/u01
    pgxcOwner=$USER
    pgxcUser=$pgxcOwner
    tmpDir=/tmp
    localTmpDir=$tmpDir
    #--------GTM Master--------
    gtmName=gtm_master
    gtmMasterServer=pg01
    gtmMasterPort=20001
    gtmMasterDir=$pgxcInstallDir/pgxl/nodes/gtm
    gtmExtraConfig=none
    gtmMasterSpecificExtraConfig=none
    #-------GTM Slave---------
    gtmSlave=y
    gtmSlaveName=gtm_slave
    gtmSlaveServer=pg02 
    gtmSlavePort=20001
    gtmSlaveDir=$pgxcInstallDir/pgxl/nodes/gtm_slave
    gtmSlaveSpecificExtraConfig=none
    #-------GTM Proxy--------
    gtmProxyDir=$pgxcInstallDir/pgxl/nodes/gtm_pxy
    gtmProxy=y 
    gtmProxyNames=(gtm_pxy1 gtm_pxy2)
    gtmProxyServers=(pg01 pg02)
    gtmProxyPorts=(20002 20002)
    gtmProxyDirs=($gtmProxyDir $gtmProxyDir)
    gtmPxyExtraConfig=none
    gtmPxySpecificExtraConfig=(none none)
    #-----Coordinators Master----------
    coordMasterDir=$pgxcInstallDir/pgxl/nodes/coord
    coordSlaveDir=$pgxcInstallDir/pgxl/nodes/coord_slave
    coordArchLogDir=$pgxcInstallDir/pgxl/nodes/coord_archlog
    coordNames=(coord1 coord2)
    coordPorts=(5433 5433)
    poolerPorts=(5434 5434)
    coordPgHbaEntries=(0.0.0.0/0)
    coordMasterServers=(pg01 pg02)
    coordMasterDirs=($coordMasterDir $coordMasterDir)
    coordMaxWALsernder=5
    coordMaxWALSenders=($coordMaxWALsernder $coordMaxWALsernder)
    #-----Coordinators Slave----------
    coordSlave=y
    coordSlaveSync=y
    coordSlaveServers=(pg03 pg04)
    coordSlavePorts=(5433 5433)
    coordSlavePoolerPorts=(5434 5434)
    coordSlaveDirs=($coordSlaveDir $coordSlaveDir)
    coordArchLogDirs=($coordArchLogDir $coordArchLogDir)
    coordExtraConfig=coordExtraConfig
    cat > $coordExtraConfig <<EOF
    log_destination = 'stderr'
    logging_collector = on
    log_directory = 'pg_log'
    listen_addresses = '*'
    max_connections = 1000
    EOF
    coordSpecificExtraConfig=(none none)
    coordExtraPgHba=none
    coordSpecificExtraPgHba=(none none)
    #------Datanodes Master----------
    datanodeMasterDir=$pgxcInstallDir/pgxl/nodes/dnmaster
    datanodeSlaveDir=$pgxcInstallDir/pgxl/nodes/dnslave
    datanodeArchLogDir=$pgxcInstallDir/pgxl/nodes/dn_archlog
    primaryDatanode=pg03
    datanodeNames=(datanode1 datanode2)
    datanodePorts=(5436 5436)
    datanodePoolerPorts=(5437 5437)
    datanodePgHbaEntries=(0.0.0.0/0)
    datanodeMasterServers=(pg03 pg04)
    datanodeMasterDirs=($datanodeMasterDir $datanodeMasterDir)
    datanodeMaxWalSender=0 
    datanodeMaxWALSenders=($datanodeMaxWalSender $datanodeMaxWalSender)
    datanodeSlave=n

    2.2 Posgres-XL集羣初始化

    初始化完成後,會自動啓動集羣。

[postgres@pg01 ~]$ pgxc_ctl -c /u01/pgxl/pgxc_ctl/pgxc_ctl.conf init all
/bin/bash
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Reading configuration using /u01/pgxl/pgxc_ctl_bash --home /u01/pgxl --configuration /u01/pgxl/pgxc_ctl/pgxc_ctl.conf
Finished reading configuration.
******** PGXC_CTL START ***************

Current directory: /u01/pgxl
Initialize GTM master
The files belonging to this GTM system will be owned by user "postgres".
This user must also own the server process.

fixing permissions on existing directory /u01/pgxl/nodes/gtm ... ok
creating configuration files ... ok
creating control file ... ok

Success.
Done.
Start GTM master
server starting
Initialize GTM slave
The files belonging to this GTM system will be owned by user "postgres".
This user must also own the server process.

fixing permissions on existing directory /u01/pgxl/nodes/gtm_slave ... ok
creating configuration files ... ok
creating control file ... ok

Success.
Done.
Start GTM slavepgxc_ctl(13032):1811220924_48 server starting
Done.
Initialize all the gtm proxies.
Initializing gtm proxy gtm_pxy1.
Initializing gtm proxy gtm_pxy2.
The files belonging to this GTM system will be owned by user "postgres".
This user must also own the server process.

fixing permissions on existing directory /u01/pgxl/nodes/gtm_pxy ... ok
creating configuration files ... ok

Success.
The files belonging to this GTM system will be owned by user "postgres".
This user must also own the server process.

fixing permissions on existing directory /u01/pgxl/nodes/gtm_pxy ... ok
creating configuration files ... ok

Success.
Done.
Starting all the gtm proxies.
Starting gtm proxy gtm_pxy1.
Starting gtm proxy gtm_pxy2.
server starting
server starting
Done.
Initialize all the coordinator masters.
Initialize coordinator master coord1.
Initialize coordinator master coord2.
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /u01/pgxl/nodes/coord ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... creating cluster information ... ok
syncing data to disk ... ok
freezing database template0 ... ok
freezing database template1 ... ok
freezing database postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success.
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /u01/pgxl/nodes/coord ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... creating cluster information ... ok
syncing data to disk ... ok
freezing database template0 ... ok
freezing database template1 ... ok
freezing database postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success.
Done.
Starting coordinator master.
Starting coordinator master coord1
Starting coordinator master coord2
2018-11-22 09:24:59.252 CST [13950] LOG:  listening on IPv4 address "0.0.0.0", port 5433
2018-11-22 09:24:59.252 CST [13950] LOG:  listening on IPv6 address "::", port 5433
2018-11-22 09:24:59.254 CST [13950] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5433"
2018-11-22 09:24:59.302 CST [13950] LOG:  redirecting log output to logging collector process
2018-11-22 09:24:59.302 CST [13950] HINT:  Future log output will appear in directory "pg_log".
2018-11-22 09:24:59.060 CST [13633] LOG:  listening on IPv4 address "0.0.0.0", port 5433
2018-11-22 09:24:59.061 CST [13633] LOG:  listening on IPv6 address "::", port 5433
2018-11-22 09:24:59.062 CST [13633] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5433"
2018-11-22 09:24:59.109 CST [13633] LOG:  redirecting log output to logging collector process
2018-11-22 09:24:59.109 CST [13633] HINT:  Future log output will appear in directory "pg_log".
Done.
Initialize all the coordinator slaves.
Initialize the coordinator slave coord1.
Initialize the coordinator slave coord2.
Done.
Starting all the coordinator slaves.
Starting coordinator slave coord1.
Starting coordinator slave coord2.
2018-11-22 09:25:05.987 CST [13330] LOG:  listening on IPv4 address "0.0.0.0", port 5433
2018-11-22 09:25:05.987 CST [13330] LOG:  listening on IPv6 address "::", port 5433
2018-11-22 09:25:05.989 CST [13330] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5433"
2018-11-22 09:25:06.039 CST [13330] LOG:  redirecting log output to logging collector process
2018-11-22 09:25:06.039 CST [13330] HINT:  Future log output will appear in directory "pg_log".
2018-11-22 09:25:05.517 CST [13266] LOG:  listening on IPv4 address "0.0.0.0", port 5433
2018-11-22 09:25:05.517 CST [13266] LOG:  listening on IPv6 address "::", port 5433
2018-11-22 09:25:05.518 CST [13266] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5433"
2018-11-22 09:25:05.567 CST [13266] LOG:  redirecting log output to logging collector process
2018-11-22 09:25:05.567 CST [13266] HINT:  Future log output will appear in directory "pg_log".
Done
Initialize all the datanode masters.
Initialize the datanode master datanode1.
Initialize the datanode master datanode2.
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /u01/pgxl/nodes/dnmaster ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... creating cluster information ... ok
syncing data to disk ... ok
freezing database template0 ... ok
freezing database template1 ... ok
freezing database postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success.
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /u01/pgxl/nodes/dnmaster ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... creating cluster information ... ok
syncing data to disk ... ok
freezing database template0 ... ok
freezing database template1 ... ok
freezing database postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success.
Done.
Starting all the datanode masters.
Starting datanode master datanode1.
Starting datanode master datanode2.
2018-11-22 09:25:15.129 CST [13604] LOG:  listening on IPv4 address "0.0.0.0", port 5436
2018-11-22 09:25:15.130 CST [13604] LOG:  listening on IPv6 address "::", port 5436
2018-11-22 09:25:15.131 CST [13604] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5436"
2018-11-22 09:25:15.148 CST [13604] LOG:  redirecting log output to logging collector process
2018-11-22 09:25:15.148 CST [13604] HINT:  Future log output will appear in directory "pg_log".
2018-11-22 09:25:14.657 CST [13539] LOG:  listening on IPv4 address "0.0.0.0", port 5436
2018-11-22 09:25:14.657 CST [13539] LOG:  listening on IPv6 address "::", port 5436
2018-11-22 09:25:14.659 CST [13539] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5436"
2018-11-22 09:25:14.676 CST [13539] LOG:  redirecting log output to logging collector process
2018-11-22 09:25:14.676 CST [13539] HINT:  Future log output will appear in directory "pg_log".
Done.
ALTER NODE coord1 WITH (HOST='pg01', PORT=5433);
ALTER NODE
CREATE NODE coord2 WITH (TYPE='coordinator', HOST='pg02', PORT=5433);
CREATE NODE
CREATE NODE datanode1 WITH (TYPE='datanode', HOST='pg03', PORT=5436);
CREATE NODE
CREATE NODE datanode2 WITH (TYPE='datanode', HOST='pg04', PORT=5436);
CREATE NODE
SELECT pgxc_pool_reload();
 pgxc_pool_reload 
------------------
 t
(1 row)

CREATE NODE coord1 WITH (TYPE='coordinator', HOST='pg01', PORT=5433);
CREATE NODE
ALTER NODE coord2 WITH (HOST='pg02', PORT=5433);
ALTER NODE
CREATE NODE datanode1 WITH (TYPE='datanode', HOST='pg03', PORT=5436);
CREATE NODE
CREATE NODE datanode2 WITH (TYPE='datanode', HOST='pg04', PORT=5436);
CREATE NODE
SELECT pgxc_pool_reload();
 pgxc_pool_reload 
------------------
 t
(1 row)

Done.
EXECUTE DIRECT ON (datanode1) 'CREATE NODE coord1 WITH (TYPE=''coordinator'', HOST=''pg01'', PORT=5433)';
EXECUTE DIRECT
EXECUTE DIRECT ON (datanode1) 'CREATE NODE coord2 WITH (TYPE=''coordinator'', HOST=''pg02'', PORT=5433)';
EXECUTE DIRECT
EXECUTE DIRECT ON (datanode1) 'ALTER NODE datanode1 WITH (TYPE=''datanode'', HOST=''pg03'', PORT=5436)';
EXECUTE DIRECT
EXECUTE DIRECT ON (datanode1) 'CREATE NODE datanode2 WITH (TYPE=''datanode'', HOST=''pg04'', PORT=5436)';
EXECUTE DIRECT
EXECUTE DIRECT ON (datanode1) 'SELECT pgxc_pool_reload()';
 pgxc_pool_reload 
------------------
 t
(1 row)

EXECUTE DIRECT ON (datanode2) 'CREATE NODE coord1 WITH (TYPE=''coordinator'', HOST=''pg01'', PORT=5433)';
EXECUTE DIRECT
EXECUTE DIRECT ON (datanode2) 'CREATE NODE coord2 WITH (TYPE=''coordinator'', HOST=''pg02'', PORT=5433)';
EXECUTE DIRECT
EXECUTE DIRECT ON (datanode2) 'CREATE NODE datanode1 WITH (TYPE=''datanode'', HOST=''pg03'', PORT=5436)';
EXECUTE DIRECT
EXECUTE DIRECT ON (datanode2) 'ALTER NODE datanode2 WITH (TYPE=''datanode'', HOST=''pg04'', PORT=5436)';
EXECUTE DIRECT
EXECUTE DIRECT ON (datanode2) 'SELECT pgxc_pool_reload()';
 pgxc_pool_reload 
------------------
 t
(1 row)

Done.

通過查詢pgxc_node表可以獲取集羣節點信息:
Postgres-XL集羣部署與管理指南

2.3 Posgres-XL集羣啓動與關閉

[postgres@pg01 ~]$ pgxc_ctl -c /u01/pgxl/pgxc_ctl/pgxc_ctl.conf stop all
[postgres@pg01 ~]$ pgxc_ctl -c /u01/pgxl/pgxc_ctl/pgxc_ctl.conf start all

2.4 Posgres-XL集羣服務監控

[postgres@pg01 ~]$ pgxc_ctl -c /u01/pgxl/pgxc_ctl/pgxc_ctl.conf monitor all
/bin/bash
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Reading configuration using /u01/pgxl/pgxc_ctl_bash --home /u01/pgxl --configuration /u01/pgxl/pgxc_ctl/pgxc_ctl.conf
Finished reading configuration.
   ******** PGXC_CTL START ***************

Current directory: /u01/pgxl
Running: gtm master
Running: gtm slave
Running: gtm proxy gtm_pxy1
Running: gtm proxy gtm_pxy2
Running: coordinator master coord1
Running: coordinator slave coord1
Running: coordinator master coord2
Running: coordinator slave coord2
Running: datanode master datanode1
Running: datanode slave datanode1
Running: datanode master datanode2
Running: datanode slave datanode2

3、測試Posgres-XL集羣

3.1 創建測試表並插入數據

創建一張log表,然後插入500條數據,如下:

[postgres@pg01 ~]$ psql -p5433
psql (PGXL 10r1, based on PG 10.5 (Postgres-XL 10r1))
Type "help" for help.
postgres=# CREATE TABLE log (id numeric NOT NULL,stamp timestamp with time zone,user_id numeric);
postgres=# copy log from '/u02/tmp/log.csv' with csv;
COPY 499

3.2 查看錶數據分佈信息

可以在協調器節點或者各個數據節點查看,這裏使用下面的語句直接統計每個數據節點的表數據分佈情況:

postgres=# SELECT xc_node_id, count(*) FROM log GROUP BY xc_node_id;

Postgres-XL集羣部署與管理指南

3.3 建表說明

  • distribute表
    默認情況下,系統會將插入的數據,按照拆分規則,分配到不同的datanode節點中存儲,也就是sharding技術。每個datanode節點只保存了部分數據,通過coordinate節點可以查詢完整的數據視圖。上面創建的log表就是distribute表。建表語法如下:
    postgres=# CREATE TABLE log (id numeric NOT NULL,stamp timestamp with time zone,user_id numeric) distribute by hash(id);

    distribute表數據分佈如下圖:
    Postgres-XL集羣部署與管理指南

  • replication表
    各個datanode節點中,表的數據完全相同。也就是說,在插入數據時,系統會分別在每個datanode節點插入相同數據。讀數據時,只需要讀任意一個datanode節點上的數據即可。建表語法如下:
    postgres=# CREATE TABLE log2 (id numeric NOT NULL,stamp timestamp with time zone,user_id numeric) distribute by replication;
    postgres=# copy log2 from '/u02/tmp/log.csv' with csv;

    replication表數據分佈如下圖:
    Postgres-XL集羣部署與管理指南
    不論在哪個數據節點查詢,顯示的結果都一樣的。

    4、Postgres-XL Slave節點管理

    爲了提高集羣可用性,以下配置數據節點的熱備以便進行故障轉移切換。

    4.1 新增Slave數據節點

    在gtm節點操作,新增兩個slave數據節點,如下:

[postgres@pg01 ~]$ pgxc_ctl -c /u01/pgxl/pgxc_ctl/pgxc_ctl.conf
/bin/bash
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Reading configuration using /u01/pgxl/pgxc_ctl_bash --home /u01/pgxl --configuration /u01/pgxl/pgxc_ctl/pgxc_ctl.conf
Finished reading configuration.
   ******** PGXC_CTL START ***************

Current directory: /u01/pgxl
PGXC add datanode slave datanode1 pg05 5436 5437 /u01/pgxl/nodes/dnslave /u01/pgxl/nodes/dn_slave_war /u01/pgxl/nodes/dn_archlog
PGXC add datanode slave datanode2 pg06 5436 5437 /u01/pgxl/nodes/dnslave /u01/pgxl/nodes/dn_slave_war /u01/pgxl/nodes/dn_archlog

4.2 主備節點切換

檢查所有服務運行正常:

[postgres@pg01 ~]$ pgxc_ctl -c /u01/pgxl/pgxc_ctl/pgxc_ctl.conf monitor all
/bin/bash
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Reading configuration using /u01/pgxl/pgxc_ctl_bash --home /u01/pgxl --configuration /u01/pgxl/pgxc_ctl/pgxc_ctl.conf
Finished reading configuration.
   ******** PGXC_CTL START ***************

Current directory: /u01/pgxl
Running: gtm master
Running: gtm slave
Running: gtm proxy gtm_pxy1
Running: gtm proxy gtm_pxy2
Running: coordinator master coord1
Running: coordinator slave coord1
Running: coordinator master coord2
Running: coordinator slave coord2
Running: datanode master datanode1
Running: datanode slave datanode1
Running: datanode master datanode2
Running: datanode slave datanode2

當前的主節點是pg03和pg04,如下圖:
Postgres-XL集羣部署與管理指南
切換主備節點:

[postgres@pg01 ~]$ pgxc_ctl -c /u01/pgxl/pgxc_ctl/pgxc_ctl.conf monitor all
/bin/bash
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Reading configuration using /u01/pgxl/pgxc_ctl_bash --home /u01/pgxl --configuration /u01/pgxl/pgxc_ctl/pgxc_ctl.conf
Finished reading configuration.
   ******** PGXC_CTL START ***************

Current directory: /u01/pgxl
Running: gtm master
Running: gtm slave
Running: gtm proxy gtm_pxy1
Running: gtm proxy gtm_pxy2
Running: coordinator master coord1
Running: coordinator slave coord1
Running: coordinator master coord2
Running: coordinator slave coord2
Running: datanode master datanode1
Running: datanode slave datanode1
Running: datanode master datanode2
Running: datanode slave datanode2
[postgres@pg01 ~]$ pgxc_ctl -c /u01/pgxl/pgxc_ctl/pgxc_ctl.conf failover datanode datanode1 datanode2
/bin/bash
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Reading configuration using /u01/pgxl/pgxc_ctl_bash --home /u01/pgxl --configuration /u01/pgxl/pgxc_ctl/pgxc_ctl.conf
Finished reading configuration.
   ******** PGXC_CTL START ***************

Current directory: /u01/pgxl
Failover specified datanodes.
Failover the datanode datanode1.
Failover datanode datanode1 using GTM itself
Actual Command: ssh postgres@pg05 "( pg_ctl promote -Z datanode -D /u01/pgxl/nodes/dnslave ) > /tmp/pg01_STDOUT_4264_0 2>&1" < /dev/null > /dev/null 2>&1
Bring remote stdout: scp postgres@pg05:/tmp/pg01_STDOUT_4264_0 /tmp/STDOUT_4264_1 > /dev/null 2>&1
Actual Command: ssh postgres@pg05 "( pg_ctl restart -w -Z datanode -D /u01/pgxl/nodes/dnslave -o -i; sleep 1 ) > /tmp/pg01_STDOUT_4264_2 2>&1" < /dev/null > /dev/null 2>&1
Bring remote stdout: scp postgres@pg05:/tmp/pg01_STDOUT_4264_2 /tmp/STDOUT_4264_3 > /dev/null 2>&1
2018-11-23 14:52:34.655 CST [26323] LOG:  listening on IPv4 address "0.0.0.0", port 5436
2018-11-23 14:52:34.655 CST [26323] LOG:  listening on IPv6 address "::", port 5436
2018-11-23 14:52:34.657 CST [26323] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5436"
2018-11-23 14:52:34.675 CST [26323] LOG:  redirecting log output to logging collector process
2018-11-23 14:52:34.675 CST [26323] HINT:  Future log output will appear in directory "pg_log".
ALTER NODE
 pgxc_pool_reload 
------------------
 t
(1 row)

EXECUTE DIRECT
 pgxc_pool_reload 
------------------
 t
(1 row)

EXECUTE DIRECT
 pgxc_pool_reload 
------------------
 t
(1 row)

ALTER NODE
 pgxc_pool_reload 
------------------
 t
(1 row)

Failover the datanode datanode2.
Failover datanode datanode2 using GTM itself
Actual Command: ssh postgres@pg06 "( pg_ctl promote -Z datanode -D /u01/pgxl/nodes/dnslave ) > /tmp/pg01_STDOUT_4264_4 2>&1" < /dev/null > /dev/null 2>&1
Bring remote stdout: scp postgres@pg06:/tmp/pg01_STDOUT_4264_4 /tmp/STDOUT_4264_5 > /dev/null 2>&1
Actual Command: ssh postgres@pg06 "( pg_ctl restart -w -Z datanode -D /u01/pgxl/nodes/dnslave -o -i; sleep 1 ) > /tmp/pg01_STDOUT_4264_6 2>&1" < /dev/null > /dev/null 2>&1
Bring remote stdout: scp postgres@pg06:/tmp/pg01_STDOUT_4264_6 /tmp/STDOUT_4264_7 > /dev/null 2>&1
2018-11-23 14:52:38.607 CST [26317] LOG:  listening on IPv4 address "0.0.0.0", port 5436
2018-11-23 14:52:38.607 CST [26317] LOG:  listening on IPv6 address "::", port 5436
2018-11-23 14:52:38.609 CST [26317] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5436"
2018-11-23 14:52:38.628 CST [26317] LOG:  redirecting log output to logging collector process
2018-11-23 14:52:38.628 CST [26317] HINT:  Future log output will appear in directory "pg_log".
ALTER NODE
 pgxc_pool_reload 
------------------
 t
(1 row)

EXECUTE DIRECT
 pgxc_pool_reload 
------------------
 t
(1 row)

EXECUTE DIRECT
 pgxc_pool_reload 
------------------
 t
(1 row)

ALTER NODE
 pgxc_pool_reload 
------------------
 t
(1 row)

Done.
[postgres@pg01 ~]$ pgxc_ctl -c /u01/pgxl/pgxc_ctl/pgxc_ctl.conf monitor all
/bin/bash
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Installing pgxc_ctl_bash script as /u01/pgxl/pgxc_ctl_bash.
Reading configuration using /u01/pgxl/pgxc_ctl_bash --home /u01/pgxl --configuration /u01/pgxl/pgxc_ctl/pgxc_ctl.conf
Finished reading configuration.
   ******** PGXC_CTL START ***************

Current directory: /u01/pgxl
Running: gtm master
Running: gtm slave
Running: gtm proxy gtm_pxy1
Running: gtm proxy gtm_pxy2
Running: coordinator master coord1
Running: coordinator slave coord1
Running: coordinator master coord2
Running: coordinator slave coord2
Running: datanode master datanode1
Running: datanode master datanode2

切換完成後,舊的master節點作廢,而新建的兩個slave節點就轉變爲master節點角色。
Postgres-XL集羣部署與管理指南

4.3 刪除Slave節點

[postgres@pg01 ~]$ pgxc_ctl -c /u01/pgxl/pgxc_ctl/pgxc_ctl.conf remove datanode slave datanode1 clean
[postgres@pg01 ~]$ pgxc_ctl -c /u01/pgxl/pgxc_ctl/pgxc_ctl.conf remove datanode slave datanode2 clean
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章