Closed windtalkerbj closed 4 years ago
https://github.com/Tencent/TBase/wiki/TBase-Quick-Start
使用数据库前需要创建default group以及sharding表 TBase使用datanode group来增加节点的管理灵活度,要求有一个default group才能使用,因此需要预先创建;一般情况下,会将节点的所有datanode节点加入到default group里 另外一方面,TBase的数据分布为了增加灵活度,加了中间逻辑层来维护数据记录到物理节点的映射,我们叫sharding,所以需要预先创建sharding,命令如下:
postgres=# create default node group default_group with (dn001,dn002); CREATE NODE GROUP postgres=# create sharding group to group default_group; CREATE SHARDING GROUP 创建数据库,用户,创建表,增删查改等操作 至此,就可以跟使用单机数据库一样来访问数据库集群了
postgres=# create database test;
CREATE DATABASE
postgres=# create user test with password 'test';
CREATE ROLE
postgres=# alter database test owner to test;
ALTER DATABASE
postgres=# \c test test
You are now connected to database "test" as user "test".
test=> create table foo(id bigint, str text) distribute by shard(id);
CREATE TABLE
test=> insert into foo values(1, 'tencent'), (2, 'shenzhen');
COPY 2
test=> select * from foo;
id | str
----+----------
1 | tencent
2 | shenzhen
(2 rows)
好吧,主页上加上这个WIKI吧,我觉得这个很基础,看好这个PG方案
好像只支持 distribute by shard 和 replication啊? tbase2.4
如下: testdb=# CREATE TABLE t_student(student_id int primary key,name varchar(20) not null,gender varchar(10),age int,class_id int, comment varchar(2000)) DISTRIBUTE BY MODULO(student_id); ERROR: Cannot support distribute type: Hash testdb=# CREATE TABLE t_student_course(id serial8,student_id int,course_id int) DISTRIBUTE BY HASH(id); ERROR: Cannot support distribute type: Hash 我的节点拓扑如下: testdb=# SELECT * FROM pgxc_node; node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferre d | node_id | node_cluster_name -----------+-----------+-----------+-----------------+----------------+---------------- --+------------+------------------- gtm | G | 20001 | 192.168.155.109 | t | f
| 428125959 | tbase_cluster coord1 | C | 20004 | 192.168.155.109 | f | f
| 1885696643 | tbase_cluster dn1 | D | 20008 | 192.168.155.109 | t | t
| -560021589 | tbase_cluster dn2 | D | 20009 | 192.168.155.101 | f | f
| 352366662 | tbase_cluster
请大神们看看怎么回事?