误删除不用怕,openGauss闪回恢复帮你搞定
下面主要从闪回查询、闪回表、闪回 DROP/TRUNCATE 方面进行演示。
闪回恢复功能是数据库恢复技术的一环,可以有选择性的撤销一个已提交事务的影响,将数据 从人为不正确的操作中进行恢复。
基于 MVCC 多版本的数据恢复(仅支持 Ustore):适用于误删除、误更新、误插入数据的查 询和恢复,用户通过配置旧版本保留时间,并执行相应的查询或恢复命令,查询或恢复到指定 的时间点或 CSN 点。
基于数据库回收站的恢复(仅支持 Ustore):适用于误 DROP、误 TRUNCATE 的表的恢复。 用户通过配置回收站开关,并执行相应的恢复命令,可以将误 DROP、误 TRUNCATE 的表找回。
说明:回收站暂不支持 Astore 引擎(闪回 DROP/TRUNCATE)。
1 闪回查询表
闪回查询可以查询过去某个时间点表的某个快照数据,这一特性可用于查看和逻辑重建意外删除或更改的受损数据。
闪回查询基于 MVCC 多版本机制,通过检索查询旧版本,获取指定老版本数据。
1.1 根据库配置文件 postgresql.conf 参数配置。
-
enable_default_ustore_table=on ###开启默认支持 Ustore 存储引擎
-
undo_zone_count=16384 ###内存中可分配的 undo zone 数量,0 代表禁用 undo 和 Ustore 表,建议取值为最大连接数 max_connections*4
-
undo_retention_time=2000 ###用于设置 undo 旧版本的保留时间,默认为 0,单位 s。
[omm@trex ~]$ gs_guc set -N all -I all -c "enable_default_ustore_table=on"
[omm@trex ~]$ gs_guc set -N all -I all -c "undo_zone_count=16384"
[omm@trex ~]$ gs_guc set -N all -I all -c "undo_retention_time=2000"
重新启动数据库。
[omm@trex ~]$ gs_om -t restart
1.2 查看修改后的参数值。
[omm@trex ~]$ gsql -d postgres -p 26000 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:09:38 commit 0 last mr )
NOTICE : The password has been expired, please change the password.
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
openGauss=# show enable_default_ustore_table;
enable_default_ustore_table
-----------------------------
on
(1 row)
openGauss=# show undo_zone_count;
undo_zone_count
-----------------
16384
(1 row)
openGauss=# show undo_retention_time;
undo_retention_time
---------------------
2000s
(1 row)
openGauss=