PostgreSQL-XC 港控/mmm° 2022-07-12 02:29 307阅读 0赞 c 基本原理,对 PostgreSQL-XC 体系结构和组件有了初步认识,今天计划在虚拟机上安装 PostgreSQL-XC, 以做进一步学习分析,下面是 PostgreSQL-XC 安装的整个过程。 **一 安装准备 \--1.1 requiremetns** 硬件需求:官方建议使用 64 位的系统,内存至少 4GB 系统需求:64bit CentOS 5.4 或者其它其它 LINUX 系统 软件需求:GNU make version: 3.80 or newer Flex: 2.5.31 or later Perl: 5.8 or later GCC: Recent versions of GCC are recommendable 软件需求,具体可参考 [ http://postgres-xc.sourceforge.net/docs/1\_0/install-requirements.html][http_postgres-xc.sourceforge.net_docs_1_0_install-requirements.html] **--1.2 实际安装环境** 两台笔记本虚拟机 RHEL 6.2 ,内存 512 M IP 192.168.1.35 ;192.168.1.36 **--1.3 安装规划** 一个GTM节点,两个协调(Coordinator)节点,二个数据节点;这是第一次安装,为了操作简便,没有安装 GTM-Standby,节点和 GTM-Proxy,这两个节点可以后期测试。 <table> <tbody> <tr> <td><strong><span style="color:#ff0000"> 192.168.1.35<br> </span></strong>GTM节点: gtm 6666<br> 协调节点一: coord1 1921<br> 协调节点二: coord1 1925 <p><span style="color:#ff0000"><strong>192.168.1.36<br> </strong></span>数据节点一: db_1 15431<br> 数据节点二: db_2 15432</p> </td> </tr> </tbody> </table> **--1.4 安装规划图** ** ** ![PostgreSQL-XC : Installation - francs - PostgreSQL DBA][PostgreSQL-XC _ Installation - francs - PostgreSQL DBA] **二 系统配置 ( 两台 ) \--2.1 创建 pgxc 系统用户并赋权** \[root@redhatB bin\]\# groupadd pgxc \[root@redhatB bin\]\# useradd pgxc -g pgxc \[root@redhatB bin\]\# passwd pgxc Changing password for user pgxc. New password: BAD PASSWORD: it is based on a dictionary word Retype new password: passwd: all authentication tokens updated successfully. \[root@redhatB pgxc\]\# chown -R pgxc:pgxc /pgdata\_xc **--2.2 系统层面其它配置** ** ** 根据需要配置其它系统层参数,由于是在虚拟机上运行,其它系统参数暂不修改。 **三 安装 postgresql-xc ( 两台都安装 ) \--3.1 pgxc\_v1.0beta2 下载** [https://sourceforge.net/projects/postgres-xc/files/][https_sourceforge.net_projects_postgres-xc_files] 下载 pgxc\_v1.0beta2.tar.gz **--3.2 将安装包解压 ( 两台 )** <table> <tbody> <tr> <td> cd /opt/soft_bak<br> tar zxvf pgxc_v1.0beta2.tar.gz</td> </tr> </tbody> </table> 备注:解压后,产生目录 pgxc **-3.3 -配置** <table> <tbody> <tr> <td> ./configure --prefix=/opt/pgsql_xc --with-segsize=8 --with-wal-segsize=64 --with-wal-blocksize=64 --with-perl --with-python --with-openssl --with-pam --with-ldap --with-libxml --with-libxslt --enable-thread-safety</td> </tr> </tbody> </table> 备注:conifugre 过程中如有提示缺少相关包,yum 安装即可。 **--3.4 编译 ** <table> <tbody> <tr> <td> gmake</td> </tr> </tbody> </table> 备 注:编译后,如果出现"All of PostgreSQL successfully made. Ready to install.",说明编译成功。 **--3.5 安装 PostgreSQL XC** <table> <tbody> <tr> <td> gmake install</td> </tr> </tbody> </table> 备注:安装后如果提示 "PostgreSQL installation complete." 说明安装成功。 **四 配置数据节点 ( 192.168.1.36 ) \--4.1 修改环境变量( .bash\_profile )** <table> <tbody> <tr> <td> export PGPORT=15431<br> export PGDATA=/pgdata_xc/db_1/pg_root<br> export LANG=en_US.utf8 <p>export PGHOME=/opt/pgsql_xc<br> export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib<br> export DATE=`date +"%Y%m%d%H%M"`<br> export PATH=$PGHOME/bin:$PATH:.<br> export MANPATH=$PGHOME/share/man:$MANPATH<br> alias rm='rm -i'<br> alias ll='ls -lh' </p> </td> </tr> </tbody> </table> **--4.2 创建数据目录** <table> <tbody> <tr> <td> pgxc@redhatB pgdata_xc]$ mkdir -p /pgdata_xc/db_1/pg_root<br> [pgxc@redhatB pgdata_xc]$ mkdir -p /pgdata_xc/db_2/pg_root</td> </tr> </tbody> </table> **--4.3 初始化数据节点1** <table> <tbody> <tr> <td> initdb -D /pgdata_xc/db_1/pg_root --nodename db_1 -E UTF8 --locale=C -U postgres -W</td> </tr> </tbody> </table> **--4.4 修改数据节点一配置文件 postgresql.conf 参数** <table> <tbody> <tr> <td> # - Connection Settings -<br> <strong><span style="color:#ff0000">port = </span><span style="color:#ff0000">15431 </span></strong> <p># - Where to Log -<br> log_destination = 'csvlog'<br> logging_collector = on <br> log_directory = 'pg_log' <br> log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'<br> log_truncate_on_rotation = on <br> log_rotation_age = 1d <br> log_rotation_size = 10MB <br> gtm_host = 'localhost'</p> <p># GTM CONNECTION<br> <strong><span style="color:#ff0000">gtm_host = '192.168.1.35'<br> gtm_port = 6666 <br> </span></strong>pgxc_node_name = 'db_1' </p> <p># DATA NODES AND CONNECTION POOLING<br> pooler_port = 6667 <br> max_pool_size = 100 </p> </td> </tr> </tbody> </table> **--4.5修改数据节点一 pg\_hba.conf ,增加以下** <table> <tbody> <tr> <td>host all all 192.168.1.35/32 trust<br> host all all 0.0.0.0/0 md5</td> </tr> </tbody> </table> **--4.6 初始化数据节点2** <table> <tbody> <tr> <td> initdb -D /pgdata_xc/db_2/pg_root --nodename db_2 -E UTF8 --locale=C -U postgres -W</td> </tr> </tbody> </table> **--4.7 修改数据节点二配置文件 postgresql.conf 参数** <table> <tbody> <tr> <td> # - Connection Settings -<br> port = <strong><span style="color:#ff0000">15432 </span></strong> <p># - Where to Log -<br> log_destination = 'csvlog'<br> logging_collector = on <br> log_directory = 'pg_log' <br> log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'<br> log_truncate_on_rotation = on <br> log_rotation_age = 1d <br> log_rotation_size = 10MB <br> gtm_host = 'localhost'</p> <p># GTM CONNECTION<br> <strong><span style="color:#ff0000">gtm_host = </span><span style="color:#ff0000">'192.168.1.35'<br> gtm_port = 6666 <br> </span></strong>pgxc_node_name = 'db_2' </p> <p># DATA NODES AND CONNECTION POOLING<br> pooler_port = 6667 <br> max_pool_size = 100 </p> </td> </tr> </tbody> </table> **--4.8 修改数据节点一 pg\_hba.conf ,增加以下** <table> <tbody> <tr> <td> host all all 192.168.1.35/32 trust<br> host all all 0.0.0.0/0 md5</td> </tr> </tbody> </table> **五 配置 gtm 节点 ( 192.168.1.35 ) \--5.1 修改 .bash\_profile** <table> <tbody> <tr> <td> export PGPORT=1921<br> export PGDATA=/database/1922/pgdata1/pgdata_xc/coord1<br> export LANG=en_US.utf8 <p>export PGHOME=/opt/pgsql_xc</p> <p>export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib<br> export DATE=`date +"%Y%m%d%H%M"`<br> export PATH=$PGHOME/bin:$PATH:.<br> export MANPATH=$PGHOME/share/man:$MANPATH<br> alias rm='rm -i'<br> alias ll='ls -lh'</p> </td> </tr> </tbody> </table> **--5.2 创建 gtm 数据目录** <table> <tbody> <tr> <td> [pgxc@redhat6 pgdata_xc]$ mkdir -p /database/1922/pgdata1/pgdata_xc/gtm</td> </tr> </tbody> </table> **--5.3 install gtm** <table> <tbody> <tr> <td> <p> [pgxc@redhat6 bin]$ initgtm -Z gtm -D /database/1922/pgdata1/pgdata_xc/gtm<br> The files belonging to this GTM system will be owned by user "pgxc".<br> This user must also own the server process.</p> <p>fixing permissions on existing directory /database/1922/pgdata1/pgdata_xc/gtm ... ok<br> creating configuration files ... ok</p> <p>Success. You can now start the GTM server using:</p> <p> gtm -D /database/1922/pgdata1/pgdata_xc/gtm<br> or<br> gtm_ctl -Z gtm -D /database/1922/pgdata1/pgdata_xc/gtm -l logfile start</p> </td> </tr> </tbody> </table> **六 配置 coordinator 节点 \--6.1 创建 coordinator 数据目录** <table> <tbody> <tr> <td> [pgxc@redhat6 pgdata_xc]$ mkdir -p /database/1922/pgdata1/pgdata_xc/coord1<br> [pgxc@redhat6 pgdata_xc]$ mkdir -p /database/1922/pgdata1/pgdata_xc/coord2</td> </tr> </tbody> </table> **--6.2 install coord1** <table> <tbody> <tr> <td> initdb -D /database/1922/pgdata1/pgdata_xc/coord1 --nodename coord1 -E UTF8 --locale=C -U postgres -W</td> </tr> </tbody> </table> **--6.3 修改 coord1 配置文件 postgresql.conf** <table> <tbody> <tr> <td> # - Connection Settings -<br> <strong><span style="color:#ff0000">listen_addresses = '*'<br> port = 1921</span></strong> <p># - Where to Log -<br> log_destination = 'csvlog'<br> logging_collector = on <br> log_directory = 'pg_log' <br> log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'<br> log_truncate_on_rotation = on <br> log_rotation_age = 1d <br> log_rotation_size = 10MB <br> gtm_host = 'localhost'</p> <p># GTM CONNECTION<br> <strong><span style="color:#ff0000">gtm_host = 'localhost'<br> gtm_port = 6666 <br> pgxc_node_name = 'coord1' </span></strong></p> <p># DATA NODES AND CONNECTION POOLING<br> pooler_port = 6667<br> max_pool_size = 100 </p> </td> </tr> </tbody> </table> **--6.4 配置 coord1 pg\_hba.conf** <table> <tbody> <tr> <td> host all all 192.168.1.36/32 trust<br> host all all 0.0.0.0/0 md5</td> </tr> </tbody> </table> **--6.5 install coord2** <table> <tbody> <tr> <td> initdb -D /database/1922/pgdata1/pgdata_xc/coord2 --nodename coord2 -E UTF8 --locale=C -U postgres -W</td> </tr> </tbody> </table> **--6.6 配置 coord2 配置文件 postgresql.conf** <table> <tbody> <tr> <td> <p># - Connection Settings -<br> <strong><span style="color:#ff0000">listen_addresses = '*'<br> port = 1925</span></strong></p> <p># - Where to Log -<br> log_destination = 'csvlog'<br> logging_collector = on <br> log_directory = 'pg_log' <br> log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'<br> log_truncate_on_rotation = on <br> log_rotation_age = 1d <br> log_rotation_size = 10MB <br> gtm_host = 'localhost'</p> <p># GTM CONNECTION<br> <strong><span style="color:#ff0000">gtm_host = 'localhost'<br> gtm_port = 6666 <br> pgxc_node_name = 'coord2' </span></strong></p> <p># DATA NODES AND CONNECTION POOLING<br> <strong><span style="color:#ff0000">pooler_port = 6668<br> </span></strong>max_pool_size = 100 </p> </td> </tr> </tbody> </table> **--6.7 配置 coord1 pg\_hba.conf** <table> <tbody> <tr> <td> host all all 192.168.1.36/32 trust<br> host all all 0.0.0.0/0 md5</td> </tr> </tbody> </table> **--6.8 修改防火墙,打开相应端口 ( 两台)** 为了测试简便,先暂时关闭防火墙和 seliniux。 **七 启动 PostgreSQL-XC \--7.1 start gtm** <table> <tbody> <tr> <td> [pgxc@redhat6 bin]$ gtm -D /database/1922/pgdata1/pgdata_xc/gtm & <br> [1] 6185</td> </tr> </tbody> </table> **--查看 gtm 是否启动** <table> <tbody> <tr> <td> [pgxc@redhat6 bin]$ gtm_ctl status -S gtm -D /database/1922/pgdata1/pgdata_xc/gtm<br> pid: 6185<br> data: /database/1922/pgdata1/pgdata_xc/gtm<br> active: 1 <p>[pgxc@redhat6 bin]$ ps -ef | grep gtm<br> pgxc 6185 6135 0 20:50 pts/4 00:00:00 gtm -D /database/1922/pgdata1/pgdata_xc/gtm</p> </td> </tr> </tbody> </table> 备注: gtm 进程已经正常启动。 **--7.2 启动数据节点( 192.168.1.36 )** <table> <tbody> <tr> <td> postgres -X -D /pgdata_xc/db_1/pg_root -p 15431 -i &<br> postgres -X -D /pgdata_xc/db_2/pg_root -p 15432 -i &</td> </tr> </tbody> </table> 备注:-X 表示 datanode 节点。 **-- 查看数据节点是否启动** <table style="width:765px; height:433px"> <tbody> <tr> <td> [pgxc@redhatB pg_log]$ ps -ef | grep pgxc<br> root 371 351 0 09:16 pts/0 00:00:00 su - pgxc<br> pgxc 372 371 0 09:16 pts/0 00:00:00 -bash<br> root 420 398 0 09:16 pts/1 00:00:00 su - pgxc<br> pgxc 421 420 0 09:16 pts/1 00:00:00 -bash<br> pgxc 588 421 0 09:28 pts/1 00:00:00 postgres -X -D /pgdata_xc/db_1/pg_root -p 15431 -i<br> pgxc 589 588 0 09:28 ? 00:00:00 postgres: logger process <br> pgxc 591 588 0 09:28 ? 00:00:00 postgres: writer process <br> pgxc 592 588 0 09:28 ? 00:00:00 postgres: wal writer process <br> pgxc 593 588 0 09:28 ? 00:00:00 postgres: autovacuum launcher process <br> pgxc 594 588 0 09:28 ? 00:00:00 postgres: stats collector process <br> pgxc 595 421 0 09:28 pts/1 00:00:00 postgres -X -D /pgdata_xc/db_2/pg_root -p 15432 -i<br> pgxc 596 595 0 09:28 ? 00:00:00 postgres: logger process <br> pgxc 598 595 0 09:28 ? 00:00:00 postgres: writer process <br> pgxc 599 595 0 09:28 ? 00:00:00 postgres: wal writer process <br> pgxc 600 595 0 09:28 ? 00:00:00 postgres: autovacuum launcher process <br> pgxc 601 595 0 09:28 ? 00:00:00 postgres: stats collector process </td> </tr> </tbody> </table> **--7.3 启动 coordinator 节点** <table> <tbody> <tr> <td> postgres -C -D /database/1922/pgdata1/pgdata_xc/coord1 -p 1921 -i &<br> postgres -C -D /database/1922/pgdata1/pgdata_xc/coord2 -p 1925 -i &</td> </tr> </tbody> </table> 备注:-C 表示 coordinator 节点。 **--查看 coordinator 节点是否启来** <table style="width:849px; height:583px"> <tbody> <tr> <td>pgxc 11633 8961 0 10:25 pts/3 00:00:00 postgres -C -D /database/1922/pgdata1/pgdata_xc/coord1 -p 1921 -i<br> pgxc 11634 11633 0 10:25 ? 00:00:00 postgres: logger process <br> pgxc 11637 11633 0 10:25 ? 00:00:00 postgres: <strong><span style="color:#ff0000">pooler process <br> </span></strong>pgxc 11638 11633 0 10:25 ? 00:00:00 postgres: writer process <br> pgxc 11639 11633 0 10:25 ? 00:00:00 postgres: wal writer process <br> pgxc 11640 11633 0 10:25 ? 00:00:00 postgres: autovacuum launcher process <br> pgxc 11641 11633 0 10:25 ? 00:00:00 postgres: stats collector process <br> pgxc 11643 8961 0 10:25 pts/3 00:00:00 postgres -C -D /database/1922/pgdata1/pgdata_xc/coord2 -p 1925 -i<br> pgxc 11644 11643 0 10:26 ? 00:00:00 postgres: logger process <br> pgxc 11647 11643 0 10:26 ? 00:00:00 postgres: <strong><span style="color:#ff0000">pooler process</span></strong> <br> pgxc 11648 11643 0 10:26 ? 00:00:00 postgres: writer process <br> pgxc 11649 11643 0 10:26 ? 00:00:00 postgres: wal writer process <br> pgxc 11650 11643 0 10:26 ? 00:00:00 postgres: autovacuum launcher process <br> pgxc 11651 11643 0 10:26 ? 00:00:00 postgres: stats collector process <br> pgxc 12203 11633 0 10:53 ? 00:00:00 postgres: postgres postgres ::1(13531) idle <br> pgxc 12372 11643 0 11:01 ? 00:00:00 postgres: postgres postgres ::1(14789) idle <br> pgxc 12661 11643 0 11:16 ? 00:00:00 postgres: francs francs ::1(14825) idle </td> </tr> </tbody> </table> 备注:coord1,coord2 节点分别多了个 **pooler process 进程,**pooler process 用来与数据节点进行通信的。 **--7.4 查看GTM,POOL连接** <table> <tbody> <tr> <td> [root@redhat6 ~]# netstat -anp | grep gtm<br> tcp 0 0 0.0.0.0:6666 0.0.0.0:* LISTEN 11620/gtm <br> tcp 0 0 :::6666 :::* LISTEN 11620/gtm <br> tcp 0 0 ::1:6666 ::1:52228 ESTABLISHED 11620/gtm <br> <br> [root@redhat6 ~]# ps -ef | grep pool<br> pgxc 11637 11633 0 10:25 ? 00:00:00 postgres: pooler process <br> pgxc 11647 11643 0 10:26 ? 00:00:00 postgres: pooler process <br> root 13375 11658 0 11:53 pts/2 00:00:00 grep pool</td> </tr> </tbody> </table> 备注:如果到了这步,没有看到 pooler process ,或者没有 gtm 相关连接,说明配置有问题。 **八:注册节点 \--8.4 在 coord1,cord2 上注册数据节点** <table> <tbody> <tr> <td> CREATE NODE db_1 WITH (TYPE='datanode',HOST = '192.168.1.36', PORT=15431);<br> CREATE NODE db_2 WITH (TYPE='datanode',HOST = '192.168.1.36', PORT=15432);<br> CREATE NODE coord2 WITH (TYPE='coordinator',HOST = 'localhost', PORT=1925);<br> CREATE NODE coord1 WITH (TYPE='coordinator',HOST = 'localhost', PORT=1921);</td> </tr> </tbody> </table> <table> <tbody> <tr> <td> <p>[pgxc@redhat6 gtm]$ psql -p 1921 -U postgres<br> psql (PGXC 1.0beta2, based on PG 9.1.3)<br> Type "help" for help.</p> <p>postgres=# select * from pgxc_node;<br> node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id <br> -----------+-----------+-----------+-----------+----------------+------------------+------------<br> coord1 | C | 5432 | localhost | f | f | 1885696643<br> (1 row)</p> <p>postgres=# CREATE NODE db_1 WITH (TYPE='datanode',HOST = '192.168.1.36', PORT=15431,PRIMARY, PREFERRED);<br> CREATE NODE<br> postgres=# CREATE NODE db_2 WITH (TYPE='datanode',HOST = '192.168.1.36', PORT=15432);<br> CREATE NODE<br> postgres=# CREATE NODE coord2 WITH (TYPE='coordinator',HOST = '192.168.1.35', PORT=1925);<br> CREATE NODE<br> postgres=# select * from pgxc_node;<br> node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id <br> -----------+-----------+-----------+--------------+----------------+------------------+-------------<br> coord1 | C | 5432 | localhost | f | f | 1885696643<br> db_1 | D | 15431 | 192.168.1.36 | f | f | 1356996994<br> db_2 | D | 15432 | 192.168.1.36 | f | f | -822936791<br> coord2 | C | 1925 | localhost | f | f | -1197102633</p> <p>postgres=# select pgxc_pool_reload();<br> pgxc_pool_reload <br> ------------------<br> t<br> (1 row)</p> </td> </tr> </tbody> </table> 备注:到了这里, PostgreSQL-XC 安装完成,接下来验证下。 **九 测试 \--9.1 coord1 创建测试库和表** <table> <tbody> <tr> <td> [pgxc@redhat6 coord2]$ psql -p 1921 -U postgres<br> psql (PGXC 1.0beta2, based on PG 9.1.3)<br> Type "help" for help. <p>postgres=# \l<br> List of databases<br> Name | Owner | Encoding | Collate | Ctype | Access privileges <br> -----------+----------+----------+---------+-------+------------------------<br> francs | postgres | UTF8 | C | C | =Tc/postgres +<br> | | | | | postgres=CTc/postgres +<br> | | | | | francs=C*T*c*/postgres<br> postgres | postgres | UTF8 | C | C | <br> template0 | postgres | UTF8 | C | C | =c/postgres +<br> | | | | | postgres=CTc/postgres<br> template1 | postgres | UTF8 | C | C | =c/postgres +<br> | | | | | postgres=CTc/postgres<br> (4 rows)</p> <p>postgres=# create database test_xc;<br> CREATE DATABASE</p> <p>postgres=# \l<br> List of databases<br> Name | Owner | Encoding | Collate | Ctype | Access privileges <br> -----------+----------+----------+---------+-------+------------------------<br> postgres | postgres | UTF8 | C | C | <br> template0 | postgres | UTF8 | C | C | =c/postgres +<br> | | | | | postgres=CTc/postgres<br> template1 | postgres | UTF8 | C | C | =c/postgres +<br> | | | | | postgres=CTc/postgres<br> <strong><span style="color:#ff0000">test_xc </span></strong> | postgres | UTF8 | C | C | <br> (5 rows)</p> <p>postgres=# \c test_xc<br> You are now connected to database "test_xc" as user "postgres".<br> test_xc=# create table test_1 (id integer,name varchar(32));<br> CREATE TABLE<br> test_xc=# insert into test_1 select generate_series(1,100),'test_xc';<br> INSERT 0 100</p> </td> </tr> </tbody> </table> 备注:在 coord1 节点上创建了测试库 test\_xc,并在里面创建了一张表,接下来看看 coord2, db\_1,db\_2 节点情况。 **--9.2 coord2 上验证** <table> <tbody> <tr> <td> [pgxc@redhat6 pg_log]$ psql -p 1925 -U postgres<br> psql (PGXC 1.0beta2, based on PG 9.1.3)<br> Type "help" for help. <p>postgres=# \l<br> List of databases<br> Name | Owner | Encoding | Collate | Ctype | Access privileges <br> -----------+----------+----------+---------+-------+------------------------<br> postgres | postgres | UTF8 | C | C | <br> template0 | postgres | UTF8 | C | C | =c/postgres +<br> | | | | | postgres=CTc/postgres<br> template1 | postgres | UTF8 | C | C | =c/postgres +<br> | | | | | postgres=CTc/postgres<br> test_xc | postgres | UTF8 | C | C | <br> (5 rows)</p> <p>postgres=# \c test_xc<br> You are now connected to database "test_xc" as user "postgres".<br> test_xc=# \d<br> List of relations<br> Schema | Name | Type | Owner <br> --------+--------+-------+----------<br> public | test_1 | table | postgres<br> (1 row)</p> <p>test_xc=# select count(*) from test_1;<br> count <br> -------<br> 100<br> (1 row)</p> </td> </tr> </tbody> </table> **--9.3 数据节点 db\_1 上验证** <table> <tbody> <tr> <td> [pgxc@redhatB pg_log]$ psql -p 15431 -U postgres -d test_xc<br> psql (PGXC 1.0beta2, based on PG 9.1.3)<br> Type "help" for help. <p>test_xc=# \d<br> WARNING: Do not have a GTM snapshot available<br> WARNING: Do not have a GTM snapshot available<br> List of relations<br> Schema | Name | Type | Owner <br> --------+--------+-------+----------<br> public | test_1 | table | postgres<br> (1 row)</p> <p>test_xc=# select count(*) from test_1;<br> WARNING: Do not have a GTM snapshot available<br> WARNING: Do not have a GTM snapshot available<br> count <br> -------<br> 42<br> (1 row)</p> </td> </tr> </tbody> </table> **--9.4 数据节点 db\_2 上验证** <table> <tbody> <tr> <td> [pgxc@redhatB pg_log]$ psql -p 15432 -U postgres -d test_xc<br> psql (PGXC 1.0beta2, based on PG 9.1.3)<br> Type "help" for help. <p>test_xc=# select count(*) from test_1;<br> WARNING: Do not have a GTM snapshot available<br> WARNING: Do not have a GTM snapshot available<br> count <br> -------<br> 58<br> (1 row)</p> </td> </tr> </tbody> </table> 备注:表共有100条记录,数据节点一分布了 42 条,数据节点二分布了 58 条,可见数据已经分片到数据节点上。 当然在创建表时,也可以设置 replication 模式,这样数据就会完全复制到每个节点。 **十 可能出现的ERROR** <table> <tbody> <tr> <td> [pgxc@redhat6 coord1]$ psql -p 1921 -U postgres<br> postgres=# create database test;<br> <strong><span style="color:#ff0000">ERROR: Failed to get pooled connections</span></strong></td> </tr> </tbody> </table> 备注:如果在 coord1 节点上操作时,报 "ERROR: Failed to get pooled connections",可能的原因很多, 可能是节点没有注册好,这时要查看 pgxc\_node 视图;也有可能是 pg\_hba.conf,防火墙,selinux 等问题,总之逐一排查。 **十一 总结** 1 本次测试只是简单将 PostgreSQL-XC 搭建起来了,其中 gmt\_standby ,GTM-Proxy 没有配置,这个以后可 以测试下; 2 由于在 PostgreSQL-XC 体系中,coordinator 并不存储数据,数据被分片在数据节点中,这种机制与GreenPlumn 有点类似;而 coordinator 节点新增了 pooler process 进程,个人觉得 coordinator 很像一个连接池。 3 PostgreSQL-XC 所谓的多主节点( muti-master) 同时对外服务,实际上对应用服务的是 coordinator 节点,而 不是数据 节点本身;原来俺的理解是数据节点同时读写(多份数据,mater 同时读写),而在 PostgreSQL-XC 中 并不是这样。 4 由于每个数据节点存储一部分数据,那么如果数据节点 down 掉,整个 PostgreSQL-XC 将不可用,不知是否有 更好的方案,例如给每个数据节点配置个 standby 节点? 5 由于在 PostgreSQL-XC 体系中数据分片在多个数据节点中,IO 性能会提升,同时对网络压力会提升;具体性能 目前还没有测试。 6 尽管疑问重多,但还是要感谢来自日本的 PostgreSQL-XC 开发团队,他们为 PostgreSQL 带来了 muti-master 的集群方案。 **十二 参考** [http://postgres-xc.sourceforge.net/][http_postgres-xc.sourceforge.net] [http://postgres-xc.sourceforge.net/docs/1\_0/index.html\\][http_postgres-xc.sourceforge.net_docs_1_0_index.html] [http://blog.163.com/digoal@126/blog/static/16387704020121952051174/][http_blog.163.com_digoal_126_blog_static_16387704020121952051174] [http://michael.otacoo.com/tag/postgres-xc/][http_michael.otacoo.com_tag_postgres-xc] [http_postgres-xc.sourceforge.net_docs_1_0_install-requirements.html]: http://postgres-xc.sourceforge.net/docs/1_0/install-requirements.html [PostgreSQL-XC _ Installation - francs - PostgreSQL DBA]: http://img4.ph.126.net/ZCRIsrK7qgnC1o_OEmvwPQ==/3075114120581507434.jpg [https_sourceforge.net_projects_postgres-xc_files]: https://sourceforge.net/projects/postgres-xc/files/ [http_postgres-xc.sourceforge.net]: http://postgres-xc.sourceforge.net/ [http_postgres-xc.sourceforge.net_docs_1_0_index.html]: http://postgres-xc.sourceforge.net/docs/1_0/index.html/ [http_blog.163.com_digoal_126_blog_static_16387704020121952051174]: http://blog.163.com/digoal@126/blog/static/16387704020121952051174/ [http_michael.otacoo.com_tag_postgres-xc]: http://michael.otacoo.com/tag/postgres-xc/
还没有评论,来说两句吧...