xc集群搭建
【参考】
https://github.com/postgres-x2/postgres-x2
https://blog.csdn.net/u014539401/article/details/69733928
【环境流程】
git clone https://github.com.cnpmjs.org/postgres-x2/postgres-x2.git
./configure --prefix=$HOME/app/pgsql00 --with-openssl --enable-debug --enable-cassert --enable-thread-safety CFLAGS='-O0' --enable-depend;make ;make install;
/home/postgres/postgres-x2/project/bin/initgtm -Z gtm -D /home/postgres/data/gtm
/home/postgres/postgres-x2/project/bin/initdb -D /home/postgres/data/coord1 --nodename co1
/home/postgres/postgres-x2/project/bin/initdb -D /home/postgres/data/datanode1 --nodename dn1
/home/postgres/postgres-x2/project/bin/initdb -D /home/postgres/data/datanode2 --nodename dn2
修改postgres.conf,port配置
datanode1为15432
datanode2为15433
启动
/home/postgres/postgres-x2/project/bin/gtm -D /home/postgres/data/gtm
/home/postgres/postgres-x2/project/bin/postgres -D /home/postgres/data/datanode1 --datanode
/home/postgres/postgres-x2/project/bin/postgres -D /home/postgres/data/datanode2 --datanode
/home/postgres/postgres-x2/project/bin/postgres -D /home/postgres/data/coord1 --coordinator
【测试】
1)创建node
./psql -d postgres -U postgres -p 9400
CREATE NODE dn1 WITH (TYPE='datanode', PORT=15432);
CREATE NODE dn2 WITH (TYPE='datanode', PORT=15433);
select * from pgxc_node;
select pgxc_pool_reload();
2)创建node group及插入数据
CREATE NODE GROUP ngrp2 WITH (dn1, dn2);
CREATE TABLE testgrp2 (id int primary key, note text) DISTRIBUTE BY HASH(id) TO GROUP ngrp2;
CREATE TABLE test2 (id int primary key, note text);
#分布键默认使用主键
insert into test2 values(1, 'text');
insert into test2 values(2, 'text');
insert into test2 values(3, 'text');
insert into test2 values(4, 'text');
insert into test2 values(5, 'text');
3)查看结果
3.1)在cn上执行
postgres=# execute direct on(dn1) 'select * from test2';
id | note
----+------
1 | text
2 | text
5 | text
(3 rows)
3.2)在dn上执行
psql -d postgres -U postgres -p 15432
postgres=# select * from test2;
id | note
----+------
1 | text
2 | text
5 | text
(3 rows)
【其他分布方法】
1)REPLICATION
create table test3 (id int primary key, note text) distribute by replication to node (dn00,dn01);
全部都有
2)modulo
create table test4 (id int primary key, note text) distribute by modulo(id) to node (dn00,dn01);
id按2取模
3)roundrobin (无主键)
轮流
create table test5 (id int, note text) distribute by ROUNDROBIN;