发布时间:2025-12-09 20:50:51 浏览次数:4
Tbase 是在开源数据库postgresql的基础进行开发的高度兼容oracle语法的分布式数据库
具体查看:https://github.com/Tencent/TBase/wiki
Coordinator:协调节点(简称 CN),对外提供接口,负责数据的分发和查询规划,多 个节点位置对等,每个节点都提供相同的数据库视图;在功能上 CN 上只存储系统的全 局元数据,并不存储实际的业务数据。
Datanode:处理存储本节点相关的元数据,每个节点还存储业务数据的分片,简称 DN。 在功能上,DN 节点负责完成执行协调节点分发的执行请求。
GTM:全局事务管理器(Global Transaction Manager),负责管理集群事务信息,同时管 理集群的全局对象,比如序列等。
在这个架构下,TBase 集群具有下面几个能力:
多活/多主:每个 coordinator 提供相同的集群视图,可以从任何一个 CN 进行写入,业
务无需感知集群拓扑;
读/写扩展:数据被分片存储在了不同的 DN,集群的读/写能力,随着集群规模的扩大做 而得到提升;
集群写一致:业务在一个 CN 节点发生的写事务会一致性的呈现在其他的 CN 节点,就 像这些事务是本 CN 节点发生的一样;
集群结构透明:数据位于不同的数据库节点中,当查询数据时,不必关心数据位于具体 的节点;
TBase 的 share nothing 集群架构方便了业务接入,降低了业务接入的门槛。
目前安装的是分布式Tbase V5版本。
| cn1_主 | 8core 16g 500g | db读写连接ip | |
| cn1_备 | 8core 16g 500g | db只读连接ip | |
| cn2_主 | 8core 16g 500g | db读写连接ip | |
| cn2_备 | 8core 16g 500g | db只读连接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/ 数据迁移 |
staging 环境o下的所有业务表和视图。默认分布键采用主键的第一关键字。
ip:10.94.
port:11345
database:
user:
Tbase是基于postgresql开发的,目前postgresql的连接工具都是可以直接连接tbase的,虽然存在小量差异,但并影响不大,具体使用如下:
参考:https://github.com/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
grant all on schema pg_oracle to cbs;
相关参数设置:
| enable_oracle_compatible | on | |
| orafce.nls_date_format | ||
| orafce.timezone | PRC | |
| orafce.varchar2_null_safe_concat | off | |
| support_oracle_compatible | on |
参数修改方法:建议使用oss的【运维管理】-->【配置管理】
修改参数语法
alter system set support_oracle_compatible=on;
create database CBS ENCODING UTF8 lc_collate 'zh_CN.utf8';
字符集只能继承db 模版(template0/template1)的字符集。
查看命令
psql>/l
create role toubao with login password 'toubao@123';
create schema toubao AUTHORIZATION toubao;
这样使用用户toubao连接数据库,就不需要指定模式的情况下直接访问toubao模式下的数据表。
在tbase和postgresql中模式与用户不存在必要的对应关系,而且一个用户可以拥有多个模式
授权
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
alter database postgres set search_path to "$user", public,user1,user2;
alter role user1 set search_path to "$user";
set search_path to public;
session > 用户 > 数据库 > 系统默认
Tbase的表类型可以分为分布式和复制表两类型。具体说明如下:
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;
create table public.t1_rep
(
f1 int not null,
f2 varchar(20),
primary key(f1)
)
distribute by replication
to group default_group;