1、YashanDB基本介绍
崖山数据库系统YashanDB是一种新型的数据库管理系统,由深圳计算科学研究院自主设计研发。它在经典数据库理论的基础上,融入了原创的有界计算理论、近似计算理论、并行可扩展理论和跨模融合计算理论。YashanDB在部署模式上支持单机/主备、共享集群、分布式等多种部署方式,覆盖OLTP/HTAP/OLAP交易和分析混合负载场景,支持大规模并发事务处理和混合事务-分析处理、在线实时分析、海量数据查询加速以及异构数据融合处理场景。
1.1 YashanDB数据库核心特性
YashanDB数据库是全面自研的国产数据库,满足实时性和高并发下的性能和稳定性要求,同时具备主流的信创改造生态,符合应用迁移的标准。主要有以下特性:
- 全面兼容主流的Oracle数据库和MySQL数据库的语法、语义,应用无需大量改造,可以完成低成本的平滑迁移;
- 兼容适配主流的信创软硬件生态,包括芯片、操作系统和中间件等,并且内核代码自主可控,实现自主知识产权的核心竞争力;
- 基于NUMA架构设计并行计算框架,实现高性能低成本的性能要求;
- 提供金融级的高可用容灾能力,实现多种部署模式和多中心多活的高可用部署架构;
- 多种存储引擎架构支持混合负载和实时分析等融合数据处理
图片
1.2 YashanDB数据库部署架构
YashanDB在部署架构上分为单实例的主备部署、分布式部署以及共享集群的部署模式,部署架构如下图所示:
- 单实例主备部署:1主多备的主备部署模式,主备实例部署在不同的主机上采用本地存储,主备节点之间通过日志同步的方式进行数据同步。主节点故障时自动切换到备节点,保证服务的高可用。
- 分布式部署:基于Shared-nothing架构,由多个实例节点组成(包括MN节点、CN节点和DN节点),这些节点部署在不同的机器上
- 共享集群部署:基于聚合内存的技术实现集群数据库各实例之间协同数据页的读写访问以及各种非数据类的并发控制。共享集群在部署上是多实例多活的架构,多个数据库实例并发的读写同一份共享数据。在管理组件上多了YCS和YFS,分别对集群数据的高可用和集群的文件系统进行管理。
图片
三种部署模式分别适用于不同的场景,各自特性如下:
- 单实例主备架构:集中式数据库处理类型,基于高性能的服务器和存储满足高并发的联机类业务处理,同时1主多备的架构保证了系统的高可用。不过受限于单台服务器的处理性能和存储限制,适用于非大并发大数据量存储的应用。
- 分布式架构:原生的分布式数据库架构,支持在线交易和实时数据分析混合交易,适用于海量数据分析以及数据仓库类应用
- 共享集群架构:对标Oracle RAC的部署架构,满足核心业务场景的高性能、高可靠以及扩展性要求。适用于核心业务场景的国产化替换。
图片
1.3 YashanDB数据库内核架构
图片
YashanDB数据库的内存架构如图,主要包括以下部分:
- 私有内存区域:包括SQL执行区以及SQL算子使用的虚拟内存,这部分内存区域在各个线程运行时分配使用,释放后才能被其它线程使用
- 共享内存区域:包括SQL缓存、日志缓存等内存共享池和全局缓存、全局锁和全局队列等全局共享资源池、数据缓存区域以及有界加速缓存
- 工作线程:处理客户端连接请求的线程,可以为会话专有模式或共享模式
- 后台线程:写日志、写数据和checkpoint等数据库后台的工作线程。
对于分布式架构,还有MDS元数据管理、CMS分布式集群管理和GTS分布式全局时间管理等线程;对于共享存储架构,还有共享集群间的同步消息处理、GRC全局资源访问控制、GLS全局锁服务和GCS全局缓存服务等专有线程。
2、YashanDB主备部署实践
2.1 环境准备
2.1.1 主备集群服务器信息
1)YashanDB数据库1主1备部署服务器信息如下:
IP | 操作系统 | CPU | 内存 | YashanDB版本 | 角色 |
192.168.112.121 | Centos_7.4_x86_64 | 1核 | 2G | 1.1.100 | 主节点 |
192.168.112.122 | Centos_7.4_x86_64 | 1核 | 2G | 1.1.100 | 备节点 |
2)安装默认端口
图片
3)关闭防火墙
##关闭防火墙
# systemctl stop firewalld
##关闭开机自启
# systemctl disable firewalld
##检查防火墙状态
# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
4)开启SSH服务
##检查ssh服务
# systemctl start sshd.service
##检查ssh服务
# systemctl status sshd.service
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2023-11-23 09:13:12 CST; 1h 38min ago
Docs: man:sshd(8)
man:sshd_config(5)
2.1.2 创建用户yashan并加入sudoer中
##1、创建用户
# useradd -d /home/yashan -m yashan
# passwd yashan
##2、配置sudoers
# chmod +w /etc/sudoers
#在/etc/sudoers添加内容
yashan ALL=(ALL) NOPASSWD:ALL
# chmod -w /etc/sudoers
##3、查看用户
# id yashan
uid=1002(yashan) gid=1002(yashan) groups=1002(yashan)
2.1.3 安装目录规划
所有安装YashanDB的实例节点上必须规划的两个目录:
- HOME目录:YashanDB的产品目录,包含YashanDB所提供的命令、数据库运行所需的库及各关键组件。该目录由yashan用户执行安装部署时输入的install-path参数根据一定规则生成并创建。
- DATA目录:YashanDB的数据目录,包含数据库的各类系统数据文件、日志文件和配置文件,用户数据也缺省存储在该目录下。但对于共享集群,所有的数据文件和redo文件均需保存在共享存储上,DATA目录将只用于存储实例运行相关的配置文件、日志文件等数据。该目录由yashan用户执行安装部署时输入的data-path参数根据一定规则生成并创建。
2.2 主备节点安装
2.2.1 安装包和配置文件
1)解压安装包
# tar -xzvf yashandb-personal-23.1.1.100-linux-x86_64.tar.gz -C /usr/local/yashandb/install
2)在主备节点创建安装目录
#mkdir /usr/local/yashandb
3)执行yasboot package命令生成配置文件
#cd /usr/local/yashandb/install
#./bin/yasboot package se gen --cluster yashandb -u yashan -p xxxx --ip 192.168.112.121,192.168.112.122 --port 22 --install-path /usr/local/yashandb/yasdb_home --data-path /usr/local/yashandb/yasdb_data --begin-port 1688 --node 2
192.168.112.121
ip:192.168.112.121 cpu cores is less than 2
ip:192.168.112.121 memroy is less than 4096MB
192.168.112.122
ip:192.168.112.122 cpu cores is less than 2
ip:192.168.112.122 memroy is less than 4096MB
hostid | group | node_type | node_name | listen_addr | replication_addr | data_path
-------------------------------------------------------------------------------------------------------------------------
host0001 | dbg1 | db | 1-1 | 192.168.112.121:1688 | 192.168.112.121:1689 | /usr/local/yashandb/yasdb_data
----------+-------+-----------+-----------+----------------------+----------------------+--------------------------------
host0002 | dbg1 | db | 1-2 | 192.168.112.122:1688 | 192.168.112.122:1689 | /usr/local/yashandb/yasdb_data
----------+-------+-----------+-----------+----------------------+----------------------+--------------------------------
Generate config success
- --cluster指定为要部署的数据库集群名称,该名称也将作为集群中所有节点上初始创建数据库的名称(database name)
- -u和-p,指定创建的用户yashan和密码
- --port指定SSH服务端口,一般为22
- --install-path指定数据库安装路径,指定为/usr/local/yashandb/yasdb_home
- --data-path指定数据存放目录,指定为/usr/local/yashandb/yasdb_data
- --begin-port指定数据库监听端口,默认1688
- --node指定主备节点总数量,1主1备设置为2
4)上一步骤执行完毕后,当前目录下将生成yashandb.toml和hosts.toml两个配置文件,yashandb.toml为数据库集群的配置文件,hosts.toml为主机的配置文件。根据需要调整配置项,比如RUN_LOG_FILE_PATH和SLOW_LOG_FILE_PATH。
cluster = "yashandb"
create_simple_schema = false
uuid = "655eb2496767a825e8dda1d6c4da4d4e"
yas_type = "SE"
[[group]]
group_type = "db"
name = "dbg1"
[group.config]
CHARACTER_SET = "utf8"
ISARCHIVELOG = true
REDO_FILE_NUM = 4
REDO_FILE_SIZE = "128M"
[group.create_sql]
[[group.node]]
data_path = "/usr/local/yashandb/yasdb_data"
hostid = "host0001"
role = 1
[group.node.config]
LISTEN_ADDR = "192.168.112.121:1688"
REPLICATION_ADDR = "192.168.112.121:1689"
RUN_LOG_FILE_PATH = "/usr/local/yashandb/yasdb_home/yashandb/log/yashandb/db-1-1/run"
RUN_LOG_LEVEL = "INFO"
SLOW_LOG_FILE_PATH = "/usr/local/yashandb/yasdb_home/yashandb/log/yashandb/db-1-1/slow"
[[group.node]]
data_path = "/usr/local/yashandb/yasdb_data"
hostid = "host0002"
role = 2
[group.node.config]
LISTEN_ADDR = "192.168.112.122:1688"
REPLICATION_ADDR = "192.168.112.122:1689"
RUN_LOG_FILE_PATH = "/usr/local/yashandb/yasdb_home/yashandb/log/yashandb/db-1-2/run"
RUN_LOG_LEVEL = "INFO"
SLOW_LOG_FILE_PATH = "/usr/local/yashandb/yasdb_home/yashandb/log/yashandb/db-1-2/slow"
2.2.2 执行安装
使用以下命令执行安装
#./bin/yasboot package install -t hosts.toml -i /usr/local/src/yashandb-personal-23.1.1.100-linux-x86_64.tar.gz -f
checking install package...
install version: yashandb 23.1.1.100
host0001 100% [====================================================================] 6s
host0002 100% [====================================================================] 6s
update host to yasom...
注:指定参数-f不强制校验环境是否满足部署条件,否则会提示:
192.168.112.121
ip:192.168.112.121 cpu cores is less than 2
ip:192.168.112.121 memroy is less than 4096MB
2.2.3 数据库部署
1)执行部署命令
$ ./bin/yasboot cluster deploy -t yashandb.toml
type | uuid | name | hostid | index | status | return_code | progress | cost
------------------------------------------------------------------------------------------------------------
task | 3190567c61c193bc | DeployYasdbCluster | - | yashandb | SUCCESS | 0 | 100 | 59
------+------------------+--------------------+--------+----------+---------+-------------+----------+------
task completed, status: SUCCESS
2)生效环境变量
#部署命令成功执行后将会在$YASDB_HOME目录下的conf文件夹中生成<<集群名称>>.bashrc环境变量文件
$ cd /usr/local/yashandb/yasdb_home/yashandb/23.1.1.100/conf
# 如~/.bashrc中已存在YashanDB相关的环境变量,将其清除
$ cat yashandb.bashrc >> ~/.bashrc
$ source ~/.bashrc
3)开机后启动命令
yashoot process yasom start -c yashandb
yasboot process yasagent start -c yashandb
yasboot cluster start -c yashandb
2.2.4 修改sys用户口令
通过yasboot工具设置集群内所有节点sys用户的密码
#./bin/yasboot cluster password set -n xxxx -c yashandb
type | uuid | name | hostid | index | status | return_code | progress | cost
----------------------------------------------------------------------------------------------------------
task | ce83dacc3c2e4246 | YasdbPasswordSet | - | yashandb | SUCCESS | 0 | 100 | 2
------+------------------+------------------+--------+----------+---------+-------------+----------+------
task completed, status: SUCCESS
2.2.5 验证安装
1)查看数据库状态
$ ./bin/yasboot cluster status -c yashandb -d
hostid | node_type | nodeid | pid | instance_status | database_status | database_role | listen_address | data_path
----------------------------------------------------------------------------------------------------------------------------------------------------------
host0001 | db | 1-1:1 | 16119 | open | normal | primary | 192.168.112.121:1688 | /usr/local/yashandb/yasdb_data/db-1-1
----------+-----------+--------+-------+-----------------+-----------------+---------------+----------------------+---------------------------------------
host0002 | db | 1-2:2 | 15363 | open | normal | standby | 192.168.112.122:1688 | /usr/local/yashandb/yasdb_data/db-1-2
----------+-----------+--------+-------+-----------------+-----------------+---------------+----------------------+---------------------------------------
2)连接实例查看状态
$ ./bin/yasboot sql -d sys@192.168.112.121:1688
YashanDB SQL Personal Edition Release 23.1.1.100 x86_64
please input password: xxxx
Connected to:
YashanDB Server Personal Edition Release 23.1.1.100 x86_64 - X86 64bit Linux
SQL> SELECT STATUS FROM V$INSTANCE;
SELECT STATUS FROM V$INSTANCE;
STATUS
-------------
OPEN
1 row fetched.
SQL> SELECT database_name FROM v$database;
SELECT database_name FROM v$database;
DATABASE_NAME
----------------------------------------------------------------
yashandb
1 row fetched.
2.2.6 创建用户及授权
1)创建用户并授权
SQL> create user yasuser01 identified by "YashanDB01";
create user yasuser01 identified by "YashanDB01";
Succeed.
SQL> grant DBA to yasuser01;
grant DBA to yasuser01;
2)切换用户登录
#./bin/yasboot sql -d yasuser01@192.168.112.121:1688
Connected to:
YashanDB Server Personal Edition Release 23.1.1.100 x86_64 - X86 64bit Linux
SQL> SELECT database_name FROM v$database;
SELECT database_name FROM v$database;
DATABASE_NAME
----------------------------------------------------------------
yashandb
2.3 数据库访问操作
2.3.1 数据库表操作
1)创建表空间
SQL> create tablespace ts01;
create tablespace ts01;
#删除表空间
SQL> drop tablespace ts01;
删除表空间默认会保留文件,如果再创建相同的表空间名称时,会提示文件已经存在,但是在备节点观察时该文件已经删除了。
YAS-02044 file '/usr/local/yashandb/yasdb_data/db-1-1/dbfiles/TS010' already exists
在删除表空间时指定删除文件datafiles
SQL> drop tablespace ts02 including contents and datafiles;
drop tablespace ts02 including contents and datafiles;
2)创建表和索引
##1、创建表tb01,表空间为TS01
create table if not exists tb01(
id int NOT NULL,
c1 int NOT NULL DEFAULT '0',
c2 char(120) NOT NULL DEFAULT '',
c3 char(60) NOT NULL DEFAULT '')
TABLESPACE TS01;
##查看创建的表
SQL> SELECT TABLE_NAME,TABLE_TYPE FROM USER_TABLES;
TABLE_NAME TABLE_TYPE
---------------------------------------------------------------- ----------
TB01 HEAP
##2、创建索引
SQL> create unique index uniq_ix01 on tb01(id);
SQL> create index ix_c1 on tb01(c1);
##查看索引
SQL> SELECT * FROM USER_INDEXES;
INDEX_NAME INDEX_TYPE TABLE_OWNER TABLE_NAME TABLE_TYPE UNIQUENESS COMPRESSION PREFIX_LENGTH TABLESPACE_NAME INI_TRANS MAX_TRANS PCT_FREE LOGGING BLEVEL LEAF_BLOCKS DISTINCT_KEYS AVG_LEAF_BLOCKS_PER_KEY AVG_DATA_BLOCKS_PER_KEY STATUS NUM_ROWS SAMPLE_SIZE LAST_ANALYZED PARTITIONED TEMPORARY GENERATED VISIBILITY DATABASE_MAINTAINED CONSTRAINT_INDEX
---------------------------------------------------------------- ----------------------------- ---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------------- ---------- ----------- ------------- ---------------------------------------------------------------- ------------ ------------ ------------ ------- ------------ --------------------- --------------------- ----------------------- ----------------------- --------- --------------------- --------------------- -------------------------------- ----------- --------- --------- ------------- ------------------- ----------------
IX_C1 NORMAL YASUSER01 TB01 TABLE N DISABLED 0 USERS 2 255 8 Y VALID N N N VISIBLE N N
UNIQ_IX01 NORMAL YASUSER01 TB01 TABLE Y DISABLED 0 USERS 2 255 8 Y VALID N N N VISIBLE N N
2 rows fetched.
2.3.2 数据导入导出
1)从mysql数据库中导出表数据为csv格式
mysql> SELECT * INTO OUTFILE '/tmp/sbtest.sbtest1.csv'
-> FIELDS TERMINATED BY ','
-> ENCLOSED BY '"'
-> LINES TERMINATED BY '\n'
-> FROM sbtest1 where id<10000;
Query OK, 9999 rows affected (0.09 sec)
2)使用yasldr工具将csv格式数据导入到表里
#./yasldr yasuser01/xxxx batch_size=4032 control_text="'LOAD DATA OPTIONS(DEGREE_OF_PARALLELISM=2) INFILE '/tmp/sbtest.sbtest1.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' APPEND INTO TABLE tb01(id,c1,c2,c3) '"
YashanDB Loader Personal Edition Release 23.1.1.100 x86_64 0e623bd
9999 rows successfully loaded.
Check /tmp/sbtest.sbtest1.log for more info.
[YASLDR] execute succeeded
导入的命令项有多个:
- BATCH_SIZE:每批次的CSV数据行数,默认4032,范围[1,65535]。
- MODE:导入方式,包括BASIC方式和BATCH方式,默认BATCH方式。
图片
登录到表中查看数据情况
SQL> select count(1) from tb01 ;
COUNT(1)
---------------------
9999
1 row fetched.
3)使用exp和imp导出和导入到新表
#1、使用exp命令将yasuser01用户下所有数据导出至export. yasuser01.data文件中
[yashan@tango-DB01 ~]$ exp yasuser01/YashanDB01 FILE=export.yasuser01.dat OWNER=yasuser01
YashanDB Export Personal Edition Release 23.1.1.100 x86_64 0e623bd
export terminated successfully
[yashan@tango-DB01 ~]$ ll
total 1892
-rw-r----- 1 yashan yashan 1936736 Nov 23 19:54 export.yasuser01.dat
#2、使用imp命令将导出数据导入到yasuser02中
[yashan@tango-DB01 ~]$ imp yasuser02/YashanDB02 FILE=export.yasuser01.dat FROMUSER=yasuser01 TOUSER=yasuser02
YashanDB Import Personal Edition Release 23.1.1.100 x86_64 0e623bd
import terminated successfully
##查看表数据情况
SQL> SELECT table_name FROM USER_TABLES;
TABLE_NAME
----------------------------------------------------------------
TB01
1 row fetched.
SQL> select count(1) from tb01;
COUNT(1)
---------------------
9999
1 row fetched.
- FROMUSER模式用于导入指定用户下的对象及数据,包括用户下所有元数据、表数据以及用户权限等
- TOUSER命令用于更换导入的用户,将导入对象的OWNER更换成TOUSER指定的用户
3、系统高可用验证
3.1主备切换验证
3.1.1 主节点故障
在1主1备的部署架构下,不同于1主多备的Raft协议自动选举,主节点故障通过yasom仲裁,默认是不开启的。
1)使用命令开启election
[yashan@tango-DB01 ~]$ yasboot
election enable on
-c yashandb
result: Succeed
查看仲裁选举的参数配置
[yashan@tango-DB01 ~]$ yasboot election config show -c yashandb
Protection Mode: MAXIMUM PROTECTION
Members:
[1-1:1] - Primary database
[1-2:2] - Physical standby database
Transport Lag: 0 seconds
Apply Lag: 0 seconds
Apply Rate: 11.85 MByte/s
Properties:
FailoverThreshold = 9
FailoverAutoReinstate = false
ZeroDataLossMode = true
Automatic Failover: Enabled in Zero Data Loss Mode
默认是最大保护模式,表示redo log同步到备节点后,事务才提交。
- FailoverThreshold:备机心跳超时时间,到达该时间后,yasom将执行failover切换流程
- FailoverAutoReinstate:是否启用自动脑裂修复,启用后如果备机发送脑裂处于Need REPAIR状态,yasom将尝试自动修复
- ZeroDataLossMode:是否启用零丢失模式,启用后主备设置为最大保护模式,当主库宕机后备机会自动failover;当备库异常时主库降级为最大可用模式,并禁止自动failover,直到备库恢复同步。
另外通过以下命令修改配置
$ yasboot election enable off -c yashandb
$ yasboot election config set -k FailoverThreshold -v 2 -c yashandb
$ yasboot election enable on -c yashandb
$ yasboot election config show -c yashandb
2)检查主备集群的状态
[yashan@tango-DB01 ~]$ yasboot cluster status -c yashandb -d
hostid | node_type | nodeid | pid | instance_status | database_status | database_role | listen_address | data_path
----------------------------------------------------------------------------------------------------------------------------------------------------------
host0001 | db | 1-1:1 | 16119 | open | normal | primary | 192.168.112.121:1688 | /usr/local/yashandb/yasdb_data/db-1-1
----------+-----------+--------+-------+-----------------+-----------------+---------------+----------------------+---------------------------------------
host0002 | db | 1-2:2 | 15363 | open | normal | standby | 192.168.112.122:1688 | /usr/local/yashandb/yasdb_data/db-1-2
----------+-----------+--------+-------+-----------------+-----------------+---------------+----------------------+---------------------------------------
3)模拟主节点故障,kill主节点进程
[yashan@tango-DB01 ~]$ ps -fu $USER
UID PID PPID C STIME TTY TIME CMD
yashan 1874 1 0 11:14 ? 00:00:10 /usr/local/yashandb/yasdb_home/yashandb/23.1.1.100/bin/yasom -c yashandb -l 192.168.112.121:1675 -d
yashan 1952 1 0 11:16 ? 00:01:17 /usr/local/yashandb/yasdb_home/yashandb/23.1.1.100/bin/yasagent -c yashandb -l 192.168.112.121:1676 -d
yashan 95091 1 7 16:23 ? 00:01:47 /usr/local/yashandb/yasdb_home/yashandb/23.1.1.100/bin/yasdb open -D /usr/local/yashandb/yasdb_data/db-1-1
[yashan@tango-DB01 ~]$ kill -9 95091
查看yasom.log日志,能看到failover切换信息
2023-11-25 16:47:38 DEBUG [yasom] replication.go:188 process replication event: failover
2023-11-25 16:47:38 INFO [yasom] task.go:24 call yasagent api success: NodeAPI.ExecSQL, get result: {"connection":"DISCONNECTED","status":"NORMAL","time_since_last_msg":
"2"}
2023-11-25 16:47:38 ERROR [yasom] task.go:21 call yasagent api failed: NodeAPI.ExecSQL, err: YAS-00402 failed to connect socket, errno 111, error message "Connection refu
sed"
2023-11-25 16:47:38 INFO [yasom] task.go:24 call yasagent api success: NodeAPI.ExecSQL, get result: {"database_role":"STANDBY","status":"NORMAL","switchover_status":"NOT
ALLOWED"}
2023-11-25 16:47:38 INFO [yasom] replication.go:231 execute failover sql command on node 1-2:2, next reset id is 1
2023-11-25 16:47:40 INFO [yasom] task.go:24 call yasagent api success: NodeAPI.ExecSQL, get result: {}
2023-11-25 16:47:40 INFO
[yasom] replication.go:246 failover succeeds
4)查看主备状态,备节点已经升级为主节点
[yashan@tango-DB02 ~]$ yasboot cluster status -c yashandb -d
hostid | node_type | nodeid | pid | instance_status | database_status | database_role | listen_address | data_path
---------------------------------------------------------------------------------------------------------------------------------------------------------
host0001 | db | 1-1:1 | off | - | - | - | 192.168.112.121:1688 | /usr/local/yashandb/yasdb_data/db-1-1
----------+-----------+--------+------+-----------------+-----------------+---------------+----------------------+---------------------------------------
host0002 | db | 1-2:2 | 4410 | open | normal | primary | 192.168.112.122:1688 | /usr/local/yashandb/yasdb_data/db-1-2
----------+-----------+--------+------+-----------------+-----------------+---------------+----------------------+---------------------------------------
重启原来的主节点后,主备关系正常
[yashan@tango-DB02 ~]$ yasboot cluster status -c yashandb -d
hostid | node_type | nodeid | pid | instance_status | database_status | database_role | listen_address | data_path
-----------------------------------------------------------------------------------------------------------------------------------------------------------
host0001 | db | 1-1:1 | 102613 | open | normal | standby | 192.168.112.121:1688 | /usr/local/yashandb/yasdb_data/db-1-1
----------+-----------+--------+--------+-----------------+-----------------+---------------+----------------------+---------------------------------------
host0002 | db | 1-2:2 | 4410 | open | normal | primary | 192.168.112.122:1688 | /usr/local/yashandb/yasdb_data/db-1-2
----------+-----------+--------+--------+-----------------+-----------------+---------------+----------------------+---------------------------------------
3.1.2 手动主备切换
1)登录备机,检查主备机同步状态,确认主备机同步无异常
SQL> SELECT database_id,database_name,log_mode,open_mode,database_role FROM V$DATABASE;
DATABASE_ID DATABASE_NAME LOG_MODE OPEN_MODE DATABASE_ROLE
--------------------- ---------------------------------------------------------------- ----------------- ----------------- -----------------
2888093870 yashandb ARCHIVELOG READ_ONLY STANDBY
2)确认备机同步状态正常
SQL> SELECT connection, status, peer_addr, transport_lag, apply_lag FROM V$REPLICATION_STATUS;
CONNECTION STATUS PEER_ADDR TRANSPORT_LAG APPLY_LAG
----------------- ----------------- ---------------------------------------------------------------- ------------- ------------
CONNECTED NORMAL 192.168.112.121:1689 0 0
3)在备机执行switchover切换操作,此时主机的所有事务中断,且switchover执行过程中,客户端无法连接主机。
SQL>
alter database switchover;
切换完成后,查看主备机的角色是否发生变化
[yashan@tango-DB01 ~]$ yasboot cluster status -c yashandb -d
hostid | node_type | nodeid | pid | instance_status | database_status | database_role | listen_address | data_path
----------------------------------------------------------------------------------------------------------------------------------------------------------
host0001 | db | 1-1:1 | 39926 | open | normal | standby | 192.168.112.121:1688 | /usr/local/yashandb/yasdb_data/db-1-1
----------+-----------+--------+-------+-----------------+-----------------+---------------+----------------------+---------------------------------------
host0002 | db | 1-2:2 | 38096 | open | normal | primary | 192.168.112.122:1688 | /usr/local/yashandb/yasdb_data/db-1-2
----------+-----------+--------+-------+-----------------+-----------------+---------------+----------------------+---------------------------------------
4)也可以使用yaboot命令执行主备切换
[yashan@tango-DB01 ~]$
yasboot node switchover -c yashandb -n 1-1
|key |value
|-----------------------------------------------+------
|clusterName |yashandb
|the group type of input node is |db
|the group name of input node is |dbg1
|the role of input node is |standby
|the primary node name of input node's group is |1-2
Switchover need primary node and selected node all are open and normal
Are you sure you want to switchover node 1-1 to primary: [yashandb][yes/no]: yes
type | uuid | name | hostid | index | status | return_code | progress | cost
-------------------------------------------------------------------------------------------------------------
task | 839275bfbfccf242 | SwitchoverYasdbCluster | - | dbg1 | SUCCESS | 0 | 100 | 2
------+------------------+------------------------+--------+-------+---------+-------------+----------+------
task completed, status: SUCCESS
其中参数-n为要升主的节点ID(例如1-1,可以通过cluster status命令查看,不需要冒号及后面的数字)。检查主备节点状态,确认已经发生了切换。
3.2 表的闪回操作
YashanDB提供的闪回功能,当用户误操作等原因导致表的数据被删除,使用闪回功能可以查看过去的数据状态,并在时间上倒回指定时间点的数据,无需从备份中恢复数据。注:该功能只对行存表(HEAP表)有效
3.2.1 delete操作闪回
#1、删除表tb01数据
SQL> delete from tb01 where id<100;
99 rows affected.
SQL> select count(1) from tb01 ;
COUNT(1)
---------------------
9900
1 row fetched.
#2、开启row movement
SQL> ALTER TABLE tb01 ENABLE ROW MOVEMENT;
Succeed.
#3、表数据闪回(通过时间戳闪回)
SQL> FLASHBACK TABLE tb01 TO TIMESTAMP TO_TIMESTAMP('2023/11/23 20:18:00','yyyy/mm/dd hh24:mi:ss');
FLASHBACK TABLE tb01 TO TIMESTAMP TO_TIMESTAMP('2023/11/23 20:18:00','yyyy/mm/dd hh24:mi:ss');
Succeed.
#4、查看数据返回正常
SQL> select count(1) from tb01 ;
COUNT(1)
---------------------
9999
1 row fetched.
3.2.2 drop表操作闪回
#1、开启了回收站ALTER SYSTEM SET RECYCLEBIN_ENABLED=ON;
#2、删除表
SQL> drop table tb01 ;
#3、查询回收站是否存在TB01表
SQL> SELECT object_name FROM DBA_RECYCLEBIN WHERE original_name = 'TB01';
OBJECT_NAME
----------------------------------------------------------------
BIN$2260
#4、表结构及表数据闪回
SQL> FLASHBACK TABLE "BIN$2260" TO BEFORE DROP;
#5、表和索引已恢复
SQL> SELECT table_name FROM USER_TABLES;
TABLE_NAME
----------------------------------------------------------------
TB01
SQL> SELECT INDEX_NAME FROM USER_INDEXES WHERE TABLE_NAME = 'TB01';
INDEX_NAME
----------------------------------------------------------------
UNIQ_IX01
IX_C1
3.2.3 truncate表闪回
#1、开启了回收站ALTER SYSTEM SET RECYCLEBIN_ENABLED=ON;
#2、TRUNCATE表操作
SQL> truncate table tb01;
#3、查询回收站是否存在TB01表
SQL> SELECT object_name FROM DBA_RECYCLEBIN WHERE original_name = 'TB01';
OBJECT_NAME
----------------------------------------------------------------
TB01
#4、表结构及表数据闪回
SQL> FLASHBACK TABLE "TB01" TO BEFORE TRUNCATE;
#5、表数据已恢复
SQL> select count(1) from tb01;
COUNT(1)
---------------------
9999
4、总结
本文简要介绍了YashanDB的特性以及部署架构,并测试部署了1主1备的环境进行功能性验证。总结下来有以下几点:
- 文档还是挺全的,根据文档一步步能够搭建好环境使用。受限于个人体验版,只能部署单实例的主备环境,没法体验分布式以及共享集群的架构
- 作为一个新数据库,对用户来说有个学习和适应的过程,一些命令和SQL语句和MySQL或Oracle等还是有些差异,可能和Oracle更接近。
- 生态的建设上还在慢慢完善,比如对Python或Go等语言的支持,主流的开发框架的支持等。还有和主流的信创操作系统的适配性和稳定性,需要进一步测试验证。尤其是在一众国产数据库产品中建立领先优势,还是有一定的挑战性的。
- 在架构上主备集群的可用性通过yasom检测的,如果这台服务器宕机后主备切换是没有自动实现的,在高可用切换这一块有优化的空间。像OpenGauss在后续版本增加CM实现切换功能,也可以参考GoldenDB管理节点对数据节点的高可用管理。
- 在运维功能实现上,数据库运维管理平台,对服务器的纳管和一键部署、监控指标和客户的现有流程对接、CMDB元数据模型和告警接入等,还是有很多客户化落地的细节。