1、概述

Tbase 是在开源数据库postgresql的基础进行开发的高度兼容oracle语法的分布式数据库

具体查看:https://github/Tencent/TBase/wiki

 

2、架构图

 

Coordinator:协调节点(简称 CN),对外提供接口,负责数据的分发和查询规划,多 个节点位置对等,每个节点都提供相同的数据库视图;在功能上 CN 上只存储系统的全 局元数据,并不存储实际的业务数据。

Datanode:处理存储本节点相关的元数据,每个节点还存储业务数据的分片,简称 DN。 在功能上,DN 节点负责完成执行协调节点分发的执行请求。

GTM:全局事务管理器(Global Transaction Manager),负责管理集群事务信息,同时管 理集群的全局对象,比如序列等。

 

在这个架构下,TBase 集群具有下面几个能力:
多活/多主:每个 coordinator 提供相同的集群视图,可以从任何一个 CN 进行写入,业

务无需感知集群拓扑;

读/写扩展:数据被分片存储在了不同的 DN,集群的读/写能力,随着集群规模的扩大做 而得到提升;

集群写一致:业务在一个 CN 节点发生的写事务会一致性的呈现在其他的 CN 节点,就 像这些事务是本 CN 节点发生的一样;

集群结构透明:数据位于不同的数据库节点中,当查询数据时,不必关心数据位于具体 的节点;

TBase 的 share nothing 集群架构方便了业务接入,降低了业务接入的门槛。

 

3、测试环境

3.1 组件列表

目前安装的是分布式Tbase V5版本。

角色

ip

配置

备注

cn1_主

 8core 16g 500gdb读写连接ip
cn1_备 8core 16g 500gdb只读连接ip
cn2_主 8core 16g 500gdb读写连接ip
cn2_备 8core 16g 500gdb只读连接ip
gtm_主 8core 16g 500g全局事务
gtm_备 8core 16g 500g全局事务
dn1_主 16core 64g 3.7t数据分片存储节点
dn1_备 16core 64g 3.7t数据分片存储节点
dn2_主 16core 64g 3.7t数据分片存储节点
dn2_备 16core 64g 3.7t数据分片存储节点
dn3_主 16core 64g 3.7t数据分片存储节点
dn3_备 16core 64g 3.7t数据分片存储节点
oss 8core 16g 500g

http://10.94.140.14:8080/

tbase集群管理平台

dbbridge 8core 16g 500

http://10.94.140.9:31030/

数据迁移

 

3.2  测试数据说明

staging 环境o下的所有业务表和视图。默认分布键采用主键的第一关键字。

 

3.3 连接信息

ip:10.94.

port:11345

database: 

user:

3.4 连接工具

Tbase是基于postgresql开发的,目前postgresql的连接工具都是可以直接连接tbase的,虽然存在小量差异,但并影响不大,具体使用如下:

  1.  开发同事使用桌面连接方法:使用常用navicat \ pgadmin\dbeaver等工具。
  2.  dba同事需兼顾使用tbase自带但psql进行连接,该工具可以使用" \d+ schema.tablename"方法查看表类型、分布键、分布节点方式。
  3.  java应用连接建议是tbase 定制但jar包(postgresql-42.2.12-TBase.jar)进行连接,具体查看附件。postgresql-42.2.12-TBase.jar
  4. python连接,使用现有pg库就可以了。

参考:https://github/Tencent/TBase/wiki/4%E3%80%81TBase%E5%BA%94%E7%94%A8%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97

4、开启oracle 特性

grant all on schema pg_oracle to cbs;

相关参数设置:

name

value

 

enable_oracle_compatible

on 
orafce.nls_date_format  
orafce.timezonePRC 
orafce.varchar2_null_safe_concatoff 
support_oracle_compatibleon 

参数修改方法:建议使用oss的【运维管理】-->【配置管理】

修改参数语法

alter system set support_oracle_compatible=on;

 

5、创建数据库和schema

5.1 创建数据库

create database CBS ENCODING UTF8 lc_collate 'zh_CN.utf8';

字符集只能继承db 模版(template0/template1)的字符集。

查看命令

psql>/l  

5.2 创建schema

建立用户

create role toubao with login password 'toubao@123';

建立用户对应的模式

create schema toubao AUTHORIZATION toubao;

 

这样使用用户toubao连接数据库,就不需要指定模式的情况下直接访问toubao模式下的数据表。

特别提醒

在tbase和postgresql中模式与用户不存在必要的对应关系,而且一个用户可以拥有多个模式

5.3 访问用户和权限授予参考pg模式

CREATE USER name [ [ WITH ] option [ ... ] ]

where option can be:

      SUPERUSER | NOSUPERUSER
    | CREATEDB | NOCREATEDB
    | CREATEROLE | NOCREATEROLE
    | INHERIT | NOINHERIT
    | LOGIN | NOLOGIN
    | REPLICATION | NOREPLICATION
    | BYPASSRLS | NOBYPASSRLS
    | CONNECTION LIMIT connlimit
    | [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL
    | VALID UNTIL 'timestamp'
    | IN ROLE role_name [, ...]
    | IN GROUP role_name [, ...]
    | ROLE role_name [, ...]
    | ADMIN role_name [, ...]
    | USER role_name [, ...]
    | SYSID uid

授权

grant select on book to hqq;

 

grant all on all tables in schema cbs to cbs;

alter table s02.t02 owner to schema_owner_01;

 

grant all on schema pg_oracle to cbs

5.4 应用登陆后免schema前缀的设置

配置数据库的默认搜索路径

alter database postgres set search_path to "$user", public,user1,user2;

 

配置用户的默认搜索路径

alter role user1 set search_path to "$user";

配置session的搜索路径

set search_path to public;

参数优先级别

 

session > 用户 > 数据库 > 系统默认

 

6 Tbase的表类型

Tbase的表类型可以分为分布式和复制表两类型。具体说明如下:

6.1 分布表

shared key必须为主键的一部分,如果不指定则使用主键的第一个关键字作为分布键。

创建语法:

--普通分布表

create table public.t1

(

f1 int not null,

f2 varchar(20),

primary key(f1)

)

distribute by shard(f1)

to group default_group

;

 

--分布分区表

create table public.t1_pt

(

f1 int not null,

f2 timestamp not null,

f3 varchar(20),

primary key(f1)

)

partition by range (f2)

begin (timestamp without time zone '2019-01-01 0:0:0')

step (interval '1 month') partitions (3)

distribute by shard(f1)

to group default_group;

 

--冷热分区表

create table public.t1_cold_hot

(

f1 int not null,

f2 timestamp not null,

f3 varchar(20),

primary key(f1)

)

partition by range (f2)

begin (timestamp without time zone '2019-01-01 0:0:0')

step (interval '1 month') partitions (3)

distribute by shard(f1,f2)

to group default_group cold_group;

 

6.2 复制表

create table public.t1_rep

(

f1 int not null,

f2 varchar(20),

primary key(f1)

)

distribute by replication

to group default_group;

更多推荐

Tbase基础积累一