服务器主机配置:
CPU:单核2GHz
RAM:2GB
DISK:30GB HDD
Citus部署配置:
Coordinator X 1 (192.168.7.129)
Worker X 2 (192.168.7.130,192.168.7.131)
基于上一篇文章安装部署完Citus后。用psql命令登陆Coordinator节点:
psql -h 192.168.7.129 -p 5432 -U postgres
执行下列SQL语句
--创建表
create table test_table(id int, name varchar(16));
--表分片
SELECT master_create_distributed_table('test_table', 'id', 'hash');
--设定分片个数(2)及每个分片副本数(2)
SELECT master_create_worker_shards('test_table', 2, 2);
INSERT INTO test_table VALUES(1,'a');
INSERT INTO test_table VALUES(2,'b');
INSERT INTO test_table VALUES(3,'c');
INSERT INTO test_table VALUES(4,'d');
--集群管理
--查看work节点
SELECT * from master_get_active_worker_nodes();
--元数据查看
SELECT * from master_get_table_metadata('test_table');
--分区查看
SELECT * from pg_dist_partition;
--分片查看
SELECT * from pg_dist_shard;
--分片分布查看
SELECT * from pg_dist_shard_placement;
select * from test_table;
id | name
----+------
1 | a
3 | c
4 | d
2 | b
(4 行记录)
当停止一个worker_02(192.168.7.131)后,Coordinator仍然能够正常连接,数据也能正常取到,但是执行SQL查询时会出现警告,可以推断出其中的数据是从worker_01(192.168.7.131)上的副本中取得的。
select * from test_table;
WARNING: connection error: 192.168.7.131:5432
描述: could not connect to server: No route to host
Is the server running on host "192.168.7.131" and accepting
TCP/IP connections on port 5432?
id | name
----+------
1 | a
3 | c
4 | d
2 | b
(4 行记录)
当把两个worker都停止后,Coordinator仍然能够正常连接,但是SQL查询已经取不到数据了。
select * from test_table;
WARNING: connection error: 192.168.7.131:5432
描述: could not connect to server: No route to host
Is the server running on host "192.168.7.131" and accepting
TCP/IP connections on port 5432?
WARNING: could not establish asynchronous connection after 5000 ms
WARNING: connection error: 192.168.7.131:5432
描述: could not connect to server: No route to host
Is the server running on host "192.168.7.131" and accepting
TCP/IP connections on port 5432?
WARNING: could not establish asynchronous connection after 5000 ms
WARNING: connection error: 192.168.7.131:5432
描述: could not connect to server: No route to host
Is the server running on host "192.168.7.131" and accepting
TCP/IP connections on port 5432?
ERROR: failed to execute task 4