Skip to main content

KlustronDB Quick Start Guide

KlustronDBAbout 2 min

KlustronDB Quick Start Guide

Note: Unless otherwise specified, the version numbers in the text can be replaced with the version numbers of any released version. For all released versions, see: Release Notes

Overview

This article introduces how to get started with a KlustronDB cluster, including:

  • After XPanel creates the database cluster, use the command-line tool to connect to the database, create databases and users, and grant the appropriate permissions.

  • Understand the distributed architecture of KlustronDB through examples of creating non-partitioned tables and partitioned tables and viewing data distribution.

1 Environmental Inspection

When deploying the cluster, choose to deploy Kluscomp instances on kunlun1 (192.168.40.151). After logging into kunlun1, run the command

ps -ef|grep postgres

You can see a large number of postgres-related processes running, and the listening port of this Kluscomp instance is 47001.

2 Environment Variable Settings

Under the user kunlun, modify the environment variable file:

vi /kunlun/env.sh

Modify envtype="${envtype:-no}" in the env.sh file to envtype="all"; the following lines are the modified content, and save it.

envtype="all"

Run env.sh so that the environment variables take effect at the session level

source /kunlun/env.sh

3 Log in to the database

Note that this connection command does not specify a username and password, so it can only be run on the server's local machine where the Kluscomp instance is running, using the operating system user specified when the KlustronDB cluster was initialized (default is Kunlun). Otherwise, you need to use the username and password of the Kluscomp instance 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 a regular table test_nopart and a 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 separately

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

10 Check the distribution of the data

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, it can be seen that all records of the non-partitioned table test_nopart are stored on the Klustore instance shard_3, while the records of the partitioned table test_part are evenly distributed across the three Klustore instances.

END