Skip to main content

Klustron Quick Start Guide

KlustronAbout 2 min

Klustron Quick Start Guide

The objectives of this article are:

  • To connect to the database using command line tools after creating a database cluster in XPanel, and to create databases and users with appropriate permissions.

  • To understand the distributed architecture of Klustron through examples of creating non-partitioned and partitioned tables and viewing data distribution.

1 Environment Check

When deploying the cluster, choose kunlun1 (192.168.40.151) as the computing node. After logging in to kunlun1, run the command:

ps -ef|grep postgres

You can see that a large number of postgres-related processes are running, and the listening port of this computing node is 47001.

2 Environment Variable Settings

As the user kunlun, modify the environment variable file:

vi /kunlun/env.sh

Change envtype="${envtype:-no}" in the env.sh file to envtype="all"; the following line shows the modified content, and then save.

envtype="all"

Run env.sh to make the environment variables effective at the session level.

source /kunlun/env.sh

3 Log in to the Database

Note that this command has no user name or password, so it can only be executed on the server where the KlustronDB cluster's computing node is running, by the operating system user (by default it's Kunlun) specified for the KlustronDB cluster duing its bootstrap phase. Alternatively, one could use the user name and its password created during cluster installation

psql -h 192.168.40.151 -p 47001 postgres

4 Create User kunlun_test

create user kunlun_test with password 'kunlun';

5 Create Database

create database testdb owner kunlun_test;

6 Grant User Permissions

grant all privileges on database testdb to kunlun_test;

7 Exit the psql command line and reconnect to the testdb database as kunlun_test

psql -h 192.168.40.151 -p 47001 -U kunlun_test testdb

8 Create Ordinary Table test_nopart and Partitioned Table test_part in testdb

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 Insert Test Data into test_nopart and test_part respectively

insert into test_nopart select generate_series(1,100);
insert into test_part select i,'text'||i from generate_series(1,300) i;

10 View the Data Distribution

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%';

From the above, we can see that all the records of the non-partitioned table test_nopart are stored on the storage node shard_3, while the records of the partitioned table test_part are evenly distributed among the three storage nodes.

END