用于从回收站中恢复被删除的 TABLE。
回收站需要处于开启状态,可以通过
show variables like 'recyclebin';
来查看回收站是否开启。
OceanBase(admin@test)> show variables like 'recyclebin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| recyclebin | ON |
+---------------+-------+
1 row in set (0.00 sec)
如果回收站处于关闭状态,可以通过
set recyclebin = on;
来开启。回收站中的表没有被实际删除,仍然会占用资源,如果需要彻底删除,可以执行
purge recyclebin;
FLASHBACK TABLE object_name TO BEFORE DROP [RENAME to db_name.table_name];
参数 | 解释 |
---|---|
object_name | 指定要恢复的 object 名称或表名,只有在表所在的 database 中才能执行。恢复 TABLE 时,也会将和 TABLE 相关的 INDEX 也恢复出来。 |
RENAME to | 修改表名和表所属的库。 |
OceanBase(admin@test)> create table t(id int primary key, k int);
Query OK, 0 rows affected (0.04 sec)
OceanBase(admin@test)> insert into t values(1,1);
Query OK, 1 row affected (0.00 sec)
OceanBase(admin@test)> select * from t;
+----+------+
| id | k |
+----+------+
| 1 | 1 |
+----+------+
1 row in set (0.00 sec)
OceanBase(admin@test)> drop table t;
Query OK, 0 rows affected (0.01 sec)
OceanBase(admin@test)> select * from t;
ERROR 1146 (42S02): Table 'test.t' does not exist
OceanBase(admin@test)> show recyclebin;
+--------------------------------+---------------+-------+----------------------------+
| OBJECT_NAME | ORIGINAL_NAME | TYPE | CREATETIME |
+--------------------------------+---------------+-------+----------------------------+
| __recycle_$_1_1597028971700936 | t | TABLE | 2020-08-10 11:09:31.701033 |
+--------------------------------+---------------+-------+----------------------------+
1 row in set (0.00 sec)
OceanBase(admin@test)> flashback table t to before drop;
Query OK, 0 rows affected (0.01 sec)
OceanBase(admin@test)> select * from t;
+----+------+
| id | k |
+----+------+
| 1 | 1 |
+----+------+
1 row in set (0.00 sec)
备案信息: 粤ICP备15087711号-2
Copyright © 2008-2024 啊嘎哇在线工具箱 All Rights.
本站所有资料来源于网络,版权归原作者所有,仅作学习交流使用,如不慎侵犯了您的权利,请联系我们。