
闪回DROP:可以恢复意外删除的表,从回收站(recycle bin)中恢复被删除的表及其附属结构如索引、表约束等。闪回drop是基于回收站机制,通过还原回收站中记录的表的物理文件,实现已drop表的恢复。
闪回TRUNCATE:可以恢复误操作或意外被进行truncate的表,从回收站中恢复被truncate的表及索引的物理数据。闪回truncate基于回收站机制,通过还原回收站中记录的表的物理文件,实现已truncate表的恢复。
前提条件
开启enable_recyclebin参数,启用回收站。
recyclebin_retention_time参数用于设置回收站对象保留时间,超过该时间的回收站对象将被自动清理,默认900s(15分钟)
模拟测试
测试环境
环境信息如下
操作系统:CentOS7.6 x86_64
数据库版本:5.0
数据库环境:单机
参数配置
查看参数信息
MogDB=# select name,setting,context from pg_settings where name in ('enable_recyclebin','recyclebin_retention_time');
name | setting | context
---------------------------+---------+---------
enable_recyclebin | off | sighup
recyclebin_retention_time | 900 | sighup
(2 rows)
修改参数并生效
MogDB=# select name,setting,context from pg_settings where name in ('enable_recyclebin','recyclebin_retention_time');
name | setting | context
---------------------------+---------+---------
enable_recyclebin | off | sighup
recyclebin_retention_time | 900 | sighup
(2 rows)
创建测试数据
创建表并插入数据
MogDB=# create table t2 (id int);
CREATE TABLE
MogDB=# insert into t2 select generate_series(1,5);
INSERT 0 5
MogDB=# select * from t2;
id
----
1
2
3
4
5
(5 rows)
闪回TRUNCATE
TRUNCATE表
MogDB=# truncate table t2;
TRUNCATE TABLE
MogDB=# select * from t2;
id
----
(0 rows)
闪回TRUNCATE操作
MogDB=# timecapsule table t2 to before truncate;
TimeCapsule Table
MogDB=# select * from t2;
id
----
1
2
3
4
5
(5 rows)
闪回DROP
DROP表
MogDB=# drop table t2;
DROP TABLE
查看回收站信息
MogDB=# select * from gs_recyclebin where rcyoperation='d' and rcyoriginname='t2';
-[ RECORD 1 ]--+------------------------------
rcybaseid | 18008
rcydbid | 16133
rcyrelid | 18003
rcyname | BIN$3F054EB4653$39849300==$0
rcyoriginname | t2
rcyoperation | d
rcytype | 0
rcyrecyclecsn | 11817
rcyrecycletime | 2023-08-15 18:19:18.240296+08
rcycreatecsn | 11739
rcychangecsn | 11739
rcynamespace | 2200
rcyowner | 10
rcytablespace | 0
rcyrelfilenode | 18003
rcycanrestore | t
rcycanpurge | t
rcyfrozenxid | 32536
rcyfrozenxid64 | 32536
闪回DROP表并且rename
MogDB=# timecapsule table t2 to before drop rename to new_t2;
TimeCapsule Table
MogDB=# select * from new_t2;
id
----
1
2
3
4
5
(5 rows)
DROP表时不放入回收站
MogDB=# drop table new_t2 purge;
DROP TABLE
MogDB=# select rcyname,rcyoriginname,rcytablespace from gs_recyclebin where rcyoperation='d';
rcyname | rcyoriginname | rcytablespace
---------+---------------+---------------
(0 rows)
关于作者
END
MogDB 是云和恩墨基于 openGauss 开源内核进行增强提升,推出的一款安稳易用的企业级关系型数据库。其具备金融级高可用和全密态计算的极致安全、面向多核处理器的极致性能、AI自诊断调优的极致智能能力,能够满足从核心交易到复杂计算的企业级业务需求。
访问官网了解更多:www.mogdb.io
产品兼容适配申请:partner@enmotech.com
加微信进入交流群:Roger_database


文章转载自MogDB,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




