原文链接:www.gbase.cn/community/p…
更多精彩内容尽在南大通用GBase技术社区,南大通用致力于成为用户最信赖的数据库产品供应商。
GBase 8c闪回技术是保证全局数据一致性的重要手段之一。闪回能够有选择性的高效撤销一个已提交事务的影响,从人为错误中恢复。在采用闪回技术之前,只能通过备份恢复、PITR等手段找回已提交的数据库修改,恢复时长需要数分钟甚至数小时。采用闪回技术后,恢复已提交的数据库修改前的数据,只需要秒级,而且恢复时间和数据库大小无关。
闪回支持两种恢复模式:
- 基于MVCC多版本的数据恢复:适用于误删除、误更新、误插入数据的查询和恢复,用户通过配置旧版本保留时间,并执行相应的查询或恢复命令,查询或恢复到指定的时间点或CSN点。
- 基于类似windows系统回收站的恢复:适用于误DROP、误TRUNCATE的表的恢复。用户通过配置回收站开关,并执行相应的恢复命令,可以将误DROP、误TRUNCATE的表找回。
使用方法
配置如下参数:
gs_guc set -N all -I all -c "undo_zone_count=16384" ## 内存中可分配的undo zone数量,0代表禁用undo和Ustore表,建议取值为max_connections*4
gs_guc set -N all -I all -c "enable_default_ustore_table=on" ## 开启默认支持Ustore存储引擎
gs_guc set -N all -I all -c "version_retention_age=10000" ## 旧版本保留的事务数,超过该事务数的旧版本将被回收清理
## 或登录数据库修改参数:
alter system set undo_zone_count=16384;
alter system set enable_default_ustore_table=on;
alter system set version_retention_age=10000;
建议配置回收站参数:
gs_guc set -N all -I all -c "enable_recyclebin=on" ## 打开回收站
gs_guc set -N all -I all -c "recyclebin_retention_time=15min" ## 设置回收站对象保留时间,超过该时间的回收站对象将被自动清理
并重启数据库生效:
gs_om -t restart
示例
示例一:
创建示例表,并插入数据:
postgres=# drop table if exists t1;
postgres=# create table t1(a int,b int,c int,d int);
postgres=# insert into t1 values(1,2,3,4),(21,22,23,24),(31,32,33,34);
查询数据:
postgres=# select * from t1;
postgres=# select current_timestamp;
pg_systimestamp
------------------------------
2021-10-12 10:03:08.272344+08
postgres=# update t1 set a=99;
postgres=# select * from t1;
a | b | c | d
----+----+----+----
99 | 2 | 3 | 4
99 | 22 | 23 | 24
99 | 32 | 33 | 34
postgres=# select snptime,snpcsn from gs_txn_snapshot where snptime between '2022-04-21 13:39:36.007842+08' and '2022-04-21 13:39:39.007842+08';
postgres=# select * from t1 timecapsule timestamp to_timestamp('2022-04-21 13:39:38.540667+08','YYYY-MM-DD HH24:MI:SS.FF');
a | b | c | d
----+----+----+----
1 | 2 | 3 | 4
21 | 22 | 23 | 24
31 | 32 | 33 | 34
postgres=# select * from t1 timecapsule csn 417232;
a | b | c | d
----+----+----+----
1 | 2 | 3 | 4
21 | 22 | 23 | 24
31 | 32 | 33 | 34
postgres=# SELECT rcyname,rcyoriginname,rcytablespace FROM GS_RECYCLEBIN;
rcyname | rcyoriginname | rcytablespace
-----------------------------+---------------+---------------
BIN$3BFF4EB403B$4C71318==$0 | t2 | 0 -- 仅看见Astore存储的t2表,并没有看到Ustore存储的t1表,注意!!
(1 row)
postgres=# timecapsule table t1 to before drop rename to t1_bak;
# 返回显示“TimeCapsule Table”表示执行成功。
postgres=# select * from t2_bak;
id | name
----+----------
1 | t2_Tom
2 | t2_Jerry
示例二:
postgres=# create table t_astore(id int,col1 varchar(8)) with (storage_type=astore);
postgres=# create table t_ustore(id int,col1 varchar(8));
postgres=# insert into t_ustore values(1,'u1'),(2,'u2');
postgres=# select now();
postgres=# update t_ustore set col1='uu' where id=2;
postgres=# select now();
postgres=# delete from t_ustore;
postgres=# select now();
postgres=# select * from t_ustore ;
postgres=# select * from t_ustore timecapsule timestamp to_timestamp('2022-03-20 23:33:41','YYYY-MM-DD HH24:MI:SS.FF');
id | col1
----+------
1 | u1
2 | u2
(2 rows)
postgres=# select * from t_ustore timecapsule timestamp to_timestamp('2022-03-20 23:34:04','YYYY-MM-DD HH24:MI:SS.FF');
id | col1
----+------
1 | u1
2 | uu
(2 rows)
postgres=# select * into t from t_ustore timecapsule timestamp to_timestamp('2022-03-20 23:34:04','YYYY-MM-DD HH24:MI:SS.FF');
postgres=# select * from t;
id | col1
----+------
1 | u1
2 | uu
(2 rows)
原文链接:www.gbase.cn/community/p…
更多精彩内容尽在南大通用GBase技术社区,南大通用致力于成为用户最信赖的数据库产品供应商。