关于 AntDB
2023年12月的 墨天轮中国数据库流行度排行 火热出炉,目前,AntDB 排在第十位。[1]
AntDB 数据库始于2008年,隶属于亚信科技旗下通用型企业级数据库产品,在运营商的核心系统上,为全国24个省份的10亿多用户提供在线服务,具备高性能、弹性扩展、可靠性等产品特性,峰值每秒可处理百万笔通信核心交易,应用范围包含通信、金融、交通、能源、物联网等行业。[2]
关于 AntDB 社区版
3月1日,亚信科技AntDB数据库社区版正式开放免费下载。作为AntDB数据库的首个社区版产品,AntDB-CE(Community Edition)V7.2.0具有完整、易用、兼容度高的企业级分布式数据库产品特性。[3]
AntDB-CE社区版采用了Share-Nothing的无共享架构,包括计算节点(Coordinator)、数据节点(DB)、全局事务管理器(GTM)和管理节点四种组件。
- 计算节点(Coordinator)
提供SQL解析、优化、路由、结果汇聚、分布式事务控制等功能
- 数据节点(DB)
真正存储业务数据的组件,通过分库分表实现数据库能力的水平扩展,提供多种分片函数,支持定制开发;支持数据节点的分组管理
- 全局事务管理器(GTMCoordinator)
分布式事务管理的重要组件;提供事务ID和事务快照以及全局序列号、时间戳,参与2PC提供分布式MVCC 能力,同时提供Coordinator 的能力
- 管理节点(Manager)
管理整个集群节点的添加、配置、删除、启停、初始化、主备倒换等所有状态。
AntDB 社区版集中式部署安装
从官方网站[4] 下载安装包,由于我本地操作系统为 Rocky Linux 9.3,网站并没有提供对应版本的安装包,这里选择了 centos8 作为替代。
[shawnyan@rocky9 ~]$ cat /etc/system-release
Rocky Linux release 9.3 (Blue Onyx)
官方网站已经给出了安装步骤,可以参考:
仅需 4 步,完成 AntDB 社区版安装:
1. 下载在root用户下
#wget http://gz.antdb.net/zip/antdb-ce-7.2.0.centos8.x86_64.tar.gz
2. 解压
#tar-zxvf antdb-ce-7.2.0.centos8.x86_64.tar.gz
3. 安装
#cd antdb-ce-7.2.0.centos8.x86_64
#sh antdb_install.sh -s
4. 进入客户端
#su - antdb
$psql -d antdb -p 6655
//根据部署的结果修改端口号
操作系统:CentOS 8
适配 Rocky 9
在执行安装脚本时,遇到报错,提示不支持 Rocky 操作系统。
[shawnyan@rocky9 antdb-ce-7.2.0.centos8.x86_64]$ ./antdb_install.sh -s
[Info] AntDB install begins
The current operating system hardware resources are less than the recommended hardware requirements for antdb operation.
...
Continue the installation.
It is recommended to improve the hardware configuration to improve the user experience.
No package was found.
The current operating system needs a package like antdb-.*.rocky.x86_64.tar.gz.
Please check the installation package. Exit.
[shawnyan@rocky9 antdb-ce-7.2.0.centos8.x86_64]$
找到相关的判断逻辑,然后增加 Rocky 部分即可。
vi ./setup/common/setup-common
在第 252 行增加如下判断。
//:252
Rocky)
os_version=8
os_name="CentOS"
;;
再次安装,遇到报错,提示缺少共享库文件。
/home/shawnyan/app/antdb/bin/initdb: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory
需要安装 compat-openssl11
依赖。
再次安装,提示成功。
[shawnyan@rocky9 antdb-ce-7.2.0.centos8.x86_64]$ ./antdb_install.sh -s
[Info] AntDB install begins
...
/data/stonedb/antdb-ce-7.2.0.centos8.x86_64/setup/common/AntDB-license-agreement-Community.txt
chown: invalid group: ‘shawnyan:shawnyanwheel’
...
[Info] AntDB install succeeds!
[Info] AntDB init begins
[Info] AntDB info:
+----------+-----------+------+-------------------------------+-------+----------+
| database | ip | port | data | user | password |
+----------+-----------+------+-------------------------------+-------+----------+
| antdb | localhost | 6655 | /home/shawnyan/app/antdb/data | antdb | antdb |
+----------+-----------+------+-------------------------------+-------+----------+
[Info] AntDB logon:
adb -d "database" -U "user" -p "port"
[Info] AntDB init succeeds
此时,AntDB 已经初始化成功,并且启动,如上面信息所示,监听端口为 6655。
连接 AntDB
使用 adb
命令,连接 AntDB,并查看版本信息和数据库信息。
[shawnyan@rocky9 ~]$ adb
adb (13.3)
Type "help" for help.
antdb=# select version();
version
-----------------------------------------------------------------------------
PostgreSQL 13.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 9.5.0, 64-bit
(1 row)
antdb=# l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
antdb | shawnyan | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | shawnyan | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | shawnyan | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/shawnyan +
| | | | | shawnyan=CTc/shawnyan
template1 | shawnyan | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/shawnyan +
| | | | | shawnyan=CTc/shawnyan
(4 rows)
开启 Oracle 兼容参数
AntDB 与 Oracle 数据库高度兼容,使得企业现有的基于Oracle数据库开发的应用程序无需做任何修改或只做少量的修改便可以运行在AntDB平台之上,由此降低了程序迁移的风险,减少了重写应用的成本,从而实现高效快捷的应用迁移。AntDB与Oracle数据库的兼容性包括两个大的方面:多模态SQL解析引擎和语法的兼容性。[5]
AntDB 中的 Oracle 兼容参数,可以通过全局变量和会话变量进行修改。并支持打印相关调试信息,由参数 debug_print_grammar
进行控制。
alter system set debug_print_grammar=t;
修改会话变量,并测试 Oracle 语法:
set grammar to oracle;
show grammar;
/*ora*/ select * from dual;
输出:
antdb=# set grammar to oracle;
SET
antdb=# show grammar;
grammar
---------
oracle
(1 row)
antdb=# /*ora*/ select * from dual;
DUMMY
-------
X
(1 row)
查看命名空间信息:
antdb=# SELECT oid, nspname
antdb-# FROM pg_namespace;
OID | NSPNAME
-------+--------------------
99 | pg_toast
11 | pg_catalog
2200 | public
13391 | information_schema
9098 | oracle
13765 | dbms_output
13767 | dbms_lock
13781 | dbms_random
(8 rows)
简单 SQL 测试
创建序列、表
创建序列 t1_seq
,创建表 t1
,插入测试数据,并查询表数据。
CREATE SEQUENCE t1_seq;
CREATE TABLE t1 (id INTEGER NOT NULL DEFAULT nextval('t1_seq'), name VARCHAR2(10), c3 NUMBER);
INSERT INTO t1 (name, c3) VALUES('A', 1), ('B ', 2),(' c', 3);
select *, length(name) from t1;
输出:
[shawnyan@rocky9 ~]$ adb
adb (13.3)
Type "help" for help.
antdb=# set grammar to oracle;
SET
antdb=# CREATE SEQUENCE t1_seq;
CREATE SEQUENCE
antdb=# CREATE TABLE t1 (id INTEGER NOT NULL DEFAULT nextval('t1_seq'), name VARCHAR2(10), c3 NUMBER);
CREATE TABLE
antdb=# INSERT INTO t1 (name, c3) VALUES('A', 1), ('B ', 2),(' c', 3);
INSERT 0 3
antdb=# select *, length(name) from t1;
ID | NAME | C3 | LENGTH(NAME)
----+------+----+--------------
1 | A | 1 | 1
2 | B | 2 | 2
3 | c | 3 | 2
(3 rows)
创建、刷新物化视图
创建物化视图 mv_t1
,并测试刷新物化视图命令。创建物化视图的同时,导入6条数据,再插入6条数据,刷新物化视图后,物化视图中有12条数据。
CREATE MATERIALIZED VIEW mv_t1 AS
SELECT *
FROM t1;
REFRESH MATERIALIZED VIEW mv_t1;
输出:
antdb=# CREATE MATERIALIZED VIEW mv_t1 AS
antdb-# SELECT *
antdb-# FROM t1;
SELECT 6
antdb=# d+ mv_t1
Materialized view "public.mv_t1"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------------------+-----------+----------+---------+----------+--------------+-------------
id | integer | | | | plain | |
name | oracle.varchar2(10) | | | | extended | |
c3 | numeric | | | | main | |
View definition:
SELECT t1.id,
t1.name,
t1.c3
FROM t1;
Access method: heap
antdb=# insert into t1(name) select name from t1;
INSERT 0 6
antdb=# select * from mv_t1;
id | name | c3
----+------+----
1 | A | 1
2 | B | 2
3 | c | 3
4 | | 5
5 | | 6
6 | | 4
(6 rows)
antdb=# REFRESH MATERIALIZED VIEW mv_t1;
REFRESH MATERIALIZED VIEW
antdb=# select * from mv_t1;
id | name | c3
----+------+----
1 | A | 1
2 | B | 2
3 | c | 3
4 | | 5
5 | | 6
6 | | 4
7 | A |
8 | B |
9 | c |
10 | |
11 | |
12 | |
(12 rows)
数据类型隐式转换测试
- test case
create table t1 (
id int not null,
name varchar(255) default null,
primary key(id)
);
insert into t1 values (1,'123456789012345611');
insert into t1 values (2,'123456789012345612');
insert into t1 values (3,'123123');
create table t2 (
id int not null,
name bigint default null,
primary key(id)
);
insert into t2 values (1,'123456789012345611');
insert into t2 values (2,'123456789012345611');
insert into t2 values (3,'123123');
select t1.id id1, t1.name name1, t2.id id2, t2.name name2
from t1,t2
where t1.name = t2.name;
- output
antdb=# select t1.id id1, t1.name name1, t2.id id2, t2.name name2
antdb-# from t1,t2
antdb-# where t1.name = t2.name;
ERROR: operator does not exist: character varying = bigint
LINE 3: where t1.name = t2.name;
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
antdb=# select t1.id id1, t1.name name1, t2.id id2, t2.name name2^Jfrom t1,t2^Jwhere t1.name = t2.name::varchar;
id1 | name1 | id2 | name2
-----+--------------------+-----+--------------------
1 | 123456789012345611 | 1 | 123456789012345611
1 | 123456789012345611 | 2 | 123456789012345611
3 | 123123 | 3 | 123123
(3 rows)
antdb=# select t1.id id1, t1.name name1, t2.id id2, t2.name name2^Jfrom t1,t2^Jwhere t1.name::bigint = t2.name;
id1 | name1 | id2 | name2
-----+--------------------+-----+--------------------
1 | 123456789012345611 | 1 | 123456789012345611
1 | 123456789012345611 | 2 | 123456789012345611
3 | 123123 | 3 | 123123
(3 rows)
总结
到此,AntDB 社区版 v7.2.0 的安装、适配已介绍完毕,并演示了 Oracle 兼容功能,以及部分 SQL 基础测试。
BTW,墨天轮课程中心上架了《AntDB ACA初级认证课程》[6] ,有兴趣的同学可以学起来。
-
https://www.modb.pro/db/1731856399742345216 ↩︎
-
https://www.modb.pro/wiki/55 ↩︎
-
http://www.antdb.net/news/detail/84 ↩︎
-
http://www.antdb.net/download ↩︎
-
http://www.antdb.net/72_benefit ↩︎
-
https://www.modb.pro/course/196 ↩︎