Klustron(原KunlunBase) 快速上手指南
大约 2 分钟
Klustron(原KunlunBase) 快速上手指南
注意:如无特别说明,文中的版本号可以使用任何已发布版本的版本号代替。所有已发布版本详见:Release Notes
本文目标:
XPanel 创建数据库集群后,使用命令行工具连接数据库,创建数据库、用户并赋予相应的权限。
通过创建非分区表和分区表以及查看数据分布的示例,了解 Klustron 的分布式架构。
1 环境检查
在部署集群时,选择 kunlun1(192.168.40.151) 上部署计算节点。登录 kunlun1 之后,运行命令
ps -ef|grep postgres
可以看到大量 postgres 相关的进程在运行,并且该计算节点的侦听端口时 47001
2 环境变量设置
在用户 kunlun 下,修改环境变量文件:
vi /kunlun/env.sh
将 env.sh 文件里的 envtype="${envtype:-no}" 修改为 envtype="all" ;下面的行是修改后的内容,并保存
envtype="all"
运行 env.sh ,使得环境变量在session级别生效
source /kunlun/env.sh
3 登录数据库
psql -h 192.168.40.151 -p 47001 postgres
4 创建用户 kunlun_test
create user kunlun_test with password 'kunlun';
5 创建数据库
create database testdb owner kunlun_test;
6 授予用户权限
grant all privileges on database testdb to kunlun_test;
7 退出 psql 命令行,重新以 kunlun_test 连接 testdb 数据库
psql -h 192.168.40.151 -p 47001 -U kunlun_test testdb
8 在 testdb 中创建普通表 test_nopart 和分区表 test_part
create table test_nopart (id int primary key);
create table test_part (id int primary key, name char(8)) partition by hash(id);
create table test_part_p1 partition of test_part for values with (modulus 6, remainder 0);
create table test_part_p2 partition of test_part for values with (modulus 6, remainder 1);
create table test_part_p3 partition of test_part for values with (modulus 6, remainder 2);
create table test_part_p4 partition of test_part for values with (modulus 6, remainder 3);
create table test_part_p5 partition of test_part for values with (modulus 6, remainder 4);
create table test_part_p6 partition of test_part for values with (modulus 6, remainder 5);
9 分别插入测试数据到 test_nopart 和 test_part 中
insert into test_nopart select generate_series(1,100);
insert into test_part select i,'text'||i from generate_series(1,300) i;
10 查看数据的分布情况
analyze test_nopart;
analyze test_part;
select relname table_name ,reltuples num_rows, name shard_name from pg_class t1,pg_shard t2 where t1.relshardid = t2.id and t1.reltype<>0 and t1.relname like '%test%';
从上面可以看到非分区表 test_nopart 所有记录都存放在存储节点 shard_3 上,而分区表 test_part 的记录均匀分布在3个存储节点上。
END