Oracle的flashback-闪回

环境:oracle12c

1、闪回的类型及依赖

flashback query              利用undo 数据
flashback version query      利用undo数据
flashback table              利用undo数据
flashback transaction query  flashback transaction backout
flashback database           利用flashback log
flashback drop               利用recyclebin
flashback data archive       利用的undo数据

2、使用flashback查询数据

1)闪回查询 flashback query                  查询指定时间点的数据
2)闪回版本查询 flashback version query       查询两个时间点之间的数据
3)闪回事务查询 flashback transaction query   查看事务所的操作

show parameter undo_tablespace;            #查看undo表空间
NAME            TYPE   VALUE    
--------------- ------ -------- 
undo_tablespace string UNDOTBS1 
show parameter undo_retention;             #显示undo配置
NAME           TYPE    VALUE 
-------------- ------- ----- 
undo_retention integer 900  
SELECT * FROM dba_tablespaces
WHERE tablespace_name='UNDOTBS1';              #查看表空间是否保证保留15分钟
ALTER TABLESPACE undotbs1 RETENTION GUARANTEE; #改成必须保留undu15分钟

--flashback query Oracle                         9i推出特性 从还原段中读取特定时间点的数据  ------闪回查询--------
针对v$table动态性能视图无效 对dba、all、user开头数据字典是有效
查询语句的表名后面添加
a)as of timestamp
b)as of scn
show parameter nls_date_format                               #修改系统显示日期格式
ALTER SESSION SET nls_date_format='yyyy-mm-dd hh24:mi:ss';
#闪回查询方式一采用timestamp方式
SELECT sysdate FROM dual;                                    #查看表变更前时间
2020-08-01 11:38:27
SELECT * FROM hr.test01;                                     #查看表变更前数据
1    a
模拟用户DML操作 提交
UPDATE hr.test01
SET name='bbbbb'
WHERE id=1;
COMMIT;
SELECT sysdate FROM dual;                                    #查看表变更后时间
SELECT * FROM hr.test01;                                     #查看表变更后数据
SELECT * FROM hr.test01 AS OF TIMESTAMP sysdate-2/1440;      #闪回查询(查看两分钟前的test01的数据)
1    a
SELECT * FROM hr.test01 AS OF TIMESTAMP to_timestamp('2020-08-01 11:38:27','yyyy-mm-dd hh24:mi:ss')  
WHERE id=1;                                                  #使用timestamp方式
#闪回查询方式二 scn方式
查看SCN
SELECT current_scn FROM v$database;                          #查看变更前scn
3453275
SELECT dbms_flashback.get_system_change_number FROM dual;    #查看变更前scn方式二
3453282

UPDATE hr.test01                                             #对表进行操作
SET name='ccccc'
WHERE id=1;
COMMIT;

SELECT * FROM hr.test01 AS OF SCN 3453275                    #闪回查询(通过scn方式)
WHERE id=1;
1    bbbbb

# SCN和timestamp的关系
desc smon_scn_time                                                                               表记录SCN和timestamp对应关系  5分钟记录一次   scn和timestamp的转换
SELECT scn_to_timestamp(3453275) FROM dual;                                                      #将scn转换为timestamp
01-8月 -20 11.42.44.000000000 上午
SELECT timestamp_to_scn(to_timestamp('2020-08-01 11:38:27','yyyy-mm-dd hh24:mi:ss')) FROM dual;  #将timestamp转换为scn
3453157

#下面对dba的表闪回操作
CREATE OR REPLACE FUNCTION get_number return number #创建一个function AS BEGIN return floor(dbms_random.value(
1,10000)); END; / SELECT * FROM user_source #查看function定义语句 WHERE name='GET_NUMBER'; SELECT get_number FROM dual; #function功能获取1-10000的随机数 SELECT sysdate FROM dual; #查看当前时间 2020-08-01 11:54:52 DROP FUNCTION get_number; #删除function SELECT text FROM dba_source AS OF TIMESTAMP to_timestamp('2020-08-01 11:54:52','yyyy-mm-dd hh24:mi:ss') #通过闪回查询dba 类型表 找回function的定义语句 WHERE name='GET_NUMBER'; #flashback version query 闪回版本查询 10g推出的特性 特定时间段 ------闪回版本查询------------
VERSIONS BETWEEN SCN scn1 AND scn2 #scn方式语法 VERSIONS BETWEEN TIMESTAMP t1 AND t2 #timestamp语法 MINVALUE MAXVALUE flashback version query 闪回版本查询的伪列 versions_xid 创建版本的事务ID versions_startscn versions_starttime 版本开始的scn或时间戳 versions_endscn versions_endtime 版本结束scn和时间戳 versions_operation 执行的操作

SELECT sysdate FROM dual;              #开始时间
2020-08-01 14:05:38

UPDATE employees
SET salary=4000
WHERE employee_id=198;
COMMIT;                               #版本一

INSERT INTO employees VALUES(207,'Owen','Mike','owen@qq.com',null,sysdate,'MK_REP',3000,null,100,50);
INSERT INTO employees VALUES(208,'Lisa','Mike','lisa@qq.com',null,sysdate,'MK_REP',4000,null,100,50);
COMMIT;                               #版本二

DELETE FROM employees
WHERE employee_id=207;
COMMIT;                               #版本三
SELECT sysdate FROM dual;
2020-08-01 14:10:41

SELECT versions_xid,versions_starttime,versions_endtime,versions_operation,employee_id,salary
FROM employees
VERSIONS BETWEEN TIMESTAMP to_timestamp('2020-08-01 14:05:38','yyyy-mm-dd hh24:mi:ss') AND to_timestamp('2020-08-01 14:10:41','yyyy-mm-dd hh24:mi:ss')
WHERE employee_id IN(198,207,208)
ORDER BY versions_starttime          #查看三个版本
05001D00EC050000 01-8月 -20 02.06.18.000000000 下午 U 198 4000
010009000B050000 01-8月 -20 02.08.15.000000000 下午 01-8月 -20 02.10.36.000000000 下午 I 207 3000
010009000B050000 01-8月 -20 02.08.15.000000000 下午 I 208 4000
06001C00BD050000 01-8月 -20 02.10.36.000000000 下午 D 207 3000
                                                   01-8月 -20 02.06.18.000000000 下午 198 40000

SELECT sysdate FROM dual;
2020-08-01 14:16:52

UPDATE employees
SET salary=10000
WHERE employee_id=198;

UPDATE employees
SET salary=20000
WHERE employee_id=198;

UPDATE employees
SET salary=30000
WHERE employee_id=198;

UPDATE employees
SET salary=4000
WHERE employee_id=198;
COMMIT;                           #一个版本的情况

SELECT sysdate FROM dual;
2020-08-01 14:18:06

SELECT versions_xid,versions_starttime,versions_endtime,versions_operation,employee_id,salary
FROM employees
VERSIONS BETWEEN TIMESTAMP to_timestamp('2020-08-01 14:16:52','yyyy-mm-dd hh24:mi:ss') AND to_timestamp('2020-08-01 14:18:06','yyyy-mm-dd hh24:mi:ss')
WHERE employee_id =198;         #闪回version查询
不能使用flashback version query
1)外部表 临时表 固定表 视图
2)version子句不能跨越DDL命令
3)段收缩操作

 

--#闪回事务查询 flashback transaction query                    ---------闪回事务查询---------------------
FLASHBACK_TRANSACTION_QUERY displays information about all flashback transaction queries in the database.
The database must have at least minimal supplemental logging enabled to avoid unpredictable behavior.

desc v$database
SUPPLEMENTAL_LOG_DATA_FK VARCHAR2(3) 
SUPPLEMENTAL_LOG_DATA_ALL VARCHAR2(3)

ALTER DATABASE ADD supplemental log data;                         #闪回事务需要开启这个参数
ALTER DATABASE ADD supplemental log data(primary key) columns;

SELECT versions_xid,versions_starttime,versions_endtime,versions_operation,employee_id,salary
FROM employees
VERSIONS BETWEEN TIMESTAMP to_timestamp('2020-08-01 14:16:52','yyyy-mm-dd hh24:mi:ss') AND to_timestamp('2020-08-01 14:18:06','yyyy-mm-dd hh24:mi:ss')
WHERE employee_id =198;

SELECT sysdate FROM dual;
2020-08-01 15:06:29

UPDATE employees
SET salary=10000
WHERE employee_id=198;

UPDATE employees
SET salary=20000
WHERE employee_id=198;

UPDATE employees
SET salary=30000
WHERE employee_id=198;

UPDATE employees
SET salary=4000
WHERE employee_id=198;
COMMIT;

SELECT sysdate FROM dual;
2020-08-01 15:06:44

SELECT versions_xid,versions_starttime,versions_endtime,versions_operation,employee_id,salary
FROM employees
VERSIONS BETWEEN TIMESTAMP to_timestamp('2020-08-01 15:06:29','yyyy-mm-dd hh24:mi:ss') AND to_timestamp('2020-08-01 15:06:44','yyyy-mm-dd hh24:mi:ss')
WHERE employee_id =198;                                               #查找版本id
08001700DA050000 01-8月 -20 03.06.37.000000000 下午 U 198 4000
01-8月 -20 03.06.37.000000000 下午 198 4000

08001700DA050000                                                      #版本id(通过版本id查找对应事务)

SELECT xid, operation, start_scn, commit_scn, logon_user, undo_sql
FROM flashback_transaction_query
WHERE xid = HEXTORAW('08001700DA050000');                             #闪回事务查询

 3、闪回表

闪回表 flashback table 将表恢复到特定的时间点
--前提条件
a、具有flashback any table 系统权限或flashback 对象的对象权限 b、启用闪回表的行移动 --语法
FLASHBACK TABLE table_name TO TIMESTAMP
|SCN xxx; --实验 CREATE TABLE test_emp #创建一个表 AS SELECT * FROM employees WHERE rownum<5; SELECT rowid,a.* FROM test_emp a; #查看闪回前的rowid (即block存储的位置) AAASemAAFAAAACTAAA 198 Donald OConnell DOCONNEL 650.507.9833 2007-06-21 00:00:00 SH_CLERK 4000 124 50 AAASemAAFAAAACTAAB 199 Douglas Grant DGRANT 650.507.9844 2008-01-13 00:00:00 SH_CLERK 2600 124 50 AAASemAAFAAAACTAAC 200 Jennifer Whalen JWHALEN 515.123.4444 2003-09-17 00:00:00 AD_ASST 4400 101 10 AAASemAAFAAAACTAAD 201 Michael Hartstein MHARTSTE 515.123.5555 2004-02-17 00:00:00 MK_MAN 13000 100 20 desc user_tables SELECT table_name,row_movement FROM user_tables WHERE table_name='TEST_EMP'; #查看表是否开启行移动 TEST_EMP DISABLED ALTER TABLE test_emp #添加一些表的对象 索引、试图 ADD CONSTRAINT test_emp_pk PRIMARY KEY(employee_id); CREATE OR REPLACE VIEW test_emp_vm01 #添加一个表试图 AS SELECT employee_id,first_name,salary FROM test_emp; SELECT sysdate FROM dual; #操作开始时间 2020-08-01 14:32:56 模拟各种的表的操作 DELETE FROM test_emp; COMMIT; 闪回表 不能多系统表 不能跨越DDL操作 会生成undo和redo ALTER TABLE test_emp ENABLE ROW MOVEMENT; #开启行移动 SELECT table_name,row_movement FROM user_tables #查看行移动是否开启 WHERE table_name='TEST_EMP'; TEST_EMP ENABLED FLASHBACK TABLE test_emp TO TIMESTAMP to_timestamp('2020-08-01 14:35:56','yyyy-mm-dd hh24:mi:ss'); #闪回表操作 SELECT rowid,a.* FROM test_emp a; #查看表rowid(变更前的上方的) AAASemAAFAAAACTAAA 198 Donald OConnell DOCONNEL 650.507.9833 2007-06-21 00:00:00 SH_CLERK 4000 124 50 AAASemAAFAAAACTAAB 199 Douglas Grant DGRANT 650.507.9844 2008-01-13 00:00:00 SH_CLERK 2600 124 50 AAASemAAFAAAACTAAC 200 Jennifer Whalen JWHALEN 515.123.4444 2003-09-17 00:00:00 AD_ASST 4400 101 10 AAASemAAFAAAACTAAD 201 Michael Hartstein MHARTSTE 515.123.5555 2004-02-17 00:00:00 MK_MAN 13000 100 20 SELECT rowid,a.* FROM test_emp a; #查看闪回后的rowid(可以看到rowid变了,即产生了行移动block位置变了) AAASemAAFAAAACTAAE 198 Donald OConnell DOCONNEL 650.507.9833 2007-06-21 00:00:00 SH_CLERK 4000 124 50 AAASemAAFAAAACTAAF 199 Douglas Grant DGRANT 650.507.9844 2008-01-13 00:00:00 SH_CLERK 2600 124 50 AAASemAAFAAAACTAAG 200 Jennifer Whalen JWHALEN 515.123.4444 2003-09-17 00:00:00 AD_ASST 4400 101 10 AAASemAAFAAAACTAAH 201 Michael Hartstein MHARTSTE 515.123.5555 2004-02-17 00:00:00 MK_MAN 13000 100 20 ALTER TABLE test_emp DISABLE ROW MOVEMENT; #关闭行移动 FLASHBACK TABLE命令支持同时闪回多张表 FLASHBACK TABLE taba,tabb,tabc TO SCN xxx [enable|disable triggers]; #闪回默认是关闭了触发器 ,可以闪回时指定开启触发器 ENABLE | DISABLE TRIGGERS 统计信息不闪回 需要手动或系统自动job收集的统计信息 dbms_stats package提供收集统计信息存储过程 之前版本使用analyze

4、闪回数据库  flashback database

闪回数据库  flashback database
数据库处于归档模式
启用FRA
[oracle@12c ~]$ ps -ef|grep rvwr|grep -v grep
启用闪回数据库,启动rvwr后台进程,将负责从flashback buffer写入的flashback database log
SELECT * FROM v$bgprocess
WHERE name='RVWR';
00    0    RVWR    Recovery Writer    0         0
flashback database log存放在fast recover area

SELECT flashback_on,log_mode  FROM v$database;    #查看数据库闪回是否打开

--配置闪回数据库
1.配置FRA  设置FRA的位置和空间大小
show parameter db_recovery_file_dest
db_recovery_file_dest      string      /u02/app/oracle/fast_recovery 
db_recovery_file_dest_size big integer 4G  
2.设置flasback database log retention
show parameter db_flashback_retention_target; 单位为分钟
NAME                          TYPE    VALUE 
----------------------------- ------- ----- 
db_flashback_retention_target integer 1440  
DB_FLASHBACK_RETENTION_TARGET specifies the upper limit (in minutes) on how far back in time the database may be flashed back.
3.启用闪回数据库
在数据库的mount模式下
ALTER DATABASE FLASHBACK ON;  启用flashback database
ALTER DATABASE FLASHBACK OFF; 禁用flashback database  自动清空当前闪回数据库的日志

SELECT flashback_on,log_mode  FROM v$database;
YES    ARCHIVELOG

--启动mount状态执行闪回数据库
FLASHBACK DATABASE TO SCN xxxx;                    #闪回到某个scn
FLASHBACK DATABASE TO TIMESTAMP xxx;               #闪回到某个时间点
FLASHBACK DATABASE TO RESTORE POINT xxx;           #闪回到某个保存点
RMAN>FLASHBACK DATABASE TO TIME=
RMAN>FLASHBACK DATABASE TO SCN=xxx;

ALTER DATABASE OPEN RESETLOGS;|ALTER DATABASE OPEN READ ONLY;

--不能使用闪回数据库的情况
1)控制文件重建或还原
2)表空间被删除
3)数据文件大小减小

--监控闪回数据库
SELECT * FROM v$flashback_database_log;
3490899    01-8月 -20    1440    209715200    0    0
SELECT * FROM v$flashback_database_stat;                                           #每一行一个小时的时间间隔

SELECT * FROM v$restore_point;                                                     #查看系统现有的保存点
V$RESTORE_POINT displays information about restore points.                         #保存点试图介绍
GUARANTEE_FLASHBACK_DATABASE  Indicates whether flashback log files will be kept to ensure a flashback to this point (YES) or not (NO)

CREATE RESTORE POINT database_202008011632;                                         #创建保存点
CREATE RESTORE POINT database_202008011633 GUARANTEE FLASHBACK DATABASE;            #创建保存点,保证不被覆盖
select * from v$restore_point; #查看创建的保存点
3494381 3 YES 104857600 01-8月 -20 04.33.14.000000000 下午 YES DATABASE_202008011633 NO NO 0 0 3494310 3 NO 0 01-8月 -20 04.32.40.000000000 下午 NO DATABASE_202008011632 NO NO 0 0 FLASHBACK DATABASE TO RESTORE POINT database_202008011633; #闪回到保存点 --实验闪回数据库操作 SELECT sysdate FROM dual; 2020-08-01 16:33:59 desc scott.test01; SELECT * FROM scott.test01; TRUNCATE TABLE test01; ALTER TABLE scott.test01 ADD ( val varchar2(20)); desc scott.test01; DROP USER scott CASCADE; SELECT sysdate FROM dual; 2020-08-01 16:36:28 SQL> shutdown immediate SQL> startup mount; SQL> flashback database to timestamp to_timestamp('2020-08-01 16:33:59','yyyy-mm-dd hh24:mi:ss'); #闪回数据库到某个时间点 SQL> ALTER DATABASE OPEN RESETLOGS;

5、Oracle闪回数据归档

Oracle闪回数据归档  Oracle Totoal Recall
Flashback Data Archive 闪回数据的历史数据存储的区域
--闪回归档需要满足的前提条件 只能在ASSM的tablespace创建。 undo表空间必须使用auto管理 SELECT
* FROM dba_tablespaces; segment_space_management 必须AUTO show parameter undo_management; NAME TYPE VALUE --------------- ------ ----- undo_management string AUTO --闪回归档的后台进程 Flashback Archive的后台进程 SELECT * FROM v$bgprocess WHERE name='FBDA'; 00 0 FBDA Flashback Data Archiver Process 0 0 --试图解析 SELECT * FROM dba_flashback_archive; #查看当前数据库中闪回归档 DBA_FLASHBACK_ARCHIVE describes all flashback archives available in the database. #试图解析及三个关键字段解析 FLASHBACK_ARCHIVE_NAME RETENTION_IN_DAYS Maximum duration (in days) for which data is retained in the flashback archive STATUS Indicates whether the flashback archive is a default flashback archive for the system (DEFAULT) or not (NULL) --创建闪回归档表空间 1)Create a Flashback Data Archive SELECT * FROM dba_tablespaces; test01表空间 FLASHBACK ARCHIVE ADMINISTER system privilege: #创建闪回归档需要的系统权限 CREATE FLASHBACK ARCHIVE fda01 #创建一般的闪回归档表空间 TABLESPACE test01 QUOTA 100M RETENTION 100 DAY; CREATE FLASHBACK ARCHIVE DEFAULT fda_default #创建默认的闪回归档表空间 TABLESPACE test01 QUOTA 200M RETENTION 1 MONTH; SELECT * FROM dba_flashback_archive; #查看闪回归档表空间 SYS FDA01 1 100 01-8月 -20 05.00.29.000000000 下午 01-8月 -20 05.00.29.000000000 下午 SYS FDA_DEFAULT 2 30 01-8月 -20 05.01.23.000000000 下午 01-8月 -20 05.01.23.000000000 下午 DEFAULT --普通用户创建flashback data archive GRANT FLASHBACK ARCHIVE ADMINISTER TO HR; #赋予权限 为fda01的flashback data archive 添加表空间 移除表空间 修改表空间配额 修改fda的retention --使用闪回归档表空间方法 创建表的指定fda01存储历史记录 CREATE TABLE test_fda01(id number,name varchar2(20)) FLASHBACK ARCHIVE fda01; 使用alter table命令 启用flashback data archive CREATE TABLE test_01(id number); ALTER TABLE test_01 FLASHBACK ARCHIVE fda01;

修改数据库的default flashback data archive
ALTER FLASHBACK ARCHIVE fda01 SET DEFAULT;
ALTER FLASHBACK ARCHIVE fda_default SET DEFAULT;


查看当前数据库flashback data archive的表空间以及表空间的配额信息
SELECT * FROM dba_flashback_archive_ts;


为fdba01 添加表空间tbs03 配额指定200M
ALTER FLASHBACK ARCHIVE fda01
ADD TABLESPACE tbs03 QUOTA 200M;


将表空间tbs03哦那个flashback archive中移除
ALTER FLASHBACK ARCHIVE fda01
REMOVE TABLESPACE tbs03;


SELECT * FROM dba_flashback_archive_ts
WHERE flashback_archive_name='FDA01';


修改fda01的tbs01表空间的配额
ALTER FLASHBACK ARCHIVE fda01
MODIFY TABLESPACE test01 QUOTA 400M;


SELECT * FROM dba_flashback_archive_ts
WHERE flashback_archive_name='FDA01';


SELECT * FROM dba_flashback_archive;


修改fda01的retention time
ALTER FLASHBACK ARCHIVE fda01
MODIFY RETENTION 1 YEAR;


SELECT * FROM dba_flashback_archive;


使用 CREATE TABLE、ALTER TABLE 指定表使用FDA
查看当前数据库所有之前开启的flashback archive的表信息
SELECT * FROM dba_flashback_archive_tables;
TEST_FDA01 SYS FDA01 SYS_FBA_HIST_75720 ENABLED
TEST_01 SYS FDA01 SYS_FBA_HIST_75721 ENABLED


禁用表的flashback archive
ALTER TABLE test_01 NO FLASHBACK ARCHIVE;


SELECT * FROM dba_flashback_archive_tables;


ALTER TABLE test_01 FLASHBACK ARCHIVE; --使用的默认的flashback archive
ALTER TABLE test_01 FLASHBACK ARCHIVE fda01; --启用flashback archive 使用fda01的flashback archive

ALTER FLASHBACK ARCHIVE fda01 PURGE ALL;
ALTER FLASHBACK ARCHIVE fda01 PURGE BEFORE SCN xxx;
ALTER FLASHBACK ARCHIVE fda01 PURGE BEFORE TIMESTAMP xxx;
DROP FLASHBACK ARCHIVE xxx;



desc test_fda01;
ID NUMBER
NAME VARCHAR2(20)
SELECT * FROM test_fda01;
ALTER TABLE test_fda01
ADD(col1 VARCHAR2(20));



ALTER TABLE test_fda01
MODIFY(col1 VARCHAR2(30));


ALTER TABLE test_fda01
RENAME COLUMN col1 to column1;


DROP TABLE test_fda01;


procedure disassociate_fba(owner_name VARCHAR2, table_name VARCHAR2);        #禁用闪回归档(把当前表和历史表关联取消)
procedure reassociate_fba(owner_name VARCHAR2, table_name VARCHAR2);         #再次启用闪回归档
启用flashback archive的表有些DDL的操作不支持,通过dbms_flashback_archive软件包提供将表从flashback data archive中分离出来,执行特定DDL操作之后,又重新关联。
--实验
CREATE TABLE test_fda02(
id number,
name varchar2(20)
)
PARTITION BY RANGE(id)(
PARTITION p1 VALUES LESS THAN(100) TABLESPACE tbs03,
PARTITION p2 VALUES LESS THAN(200) TABLESPACE test01,
PARTITION p3 VALUES LESS THAN (maxvalue) TABLESPACE tbs03
)FLASHBACK ARCHIVE fda01;



CREATE TABLE test01(
id number,
name varchar2(20)
);


INSERT INTO test01 VALUES(110,'abc');
INSERT INTO test01 VALUES(120,'BBB');
INSERT INTO test01 VALUES(130,'CCC');
commit;
SELECT * FROM test01;


SELECT * FROM test_fda02;


使用exchange parttion交换分区中p2和test01表
ALTER TABLE test_fda02 EXCHANGE PARTITION p2 WITH TABLE test01;
ERROR at line 1:
ORA-55610: Invalid DDL statement on history-tracked table


SELECT * FROM dba_flashback_archive_tables;
TEST_FDA02 SYS FDA01 SYS_FBA_HIST_75736 ENABLED


exec dbms_flashback_archive.disassociate_fba('SYS','TEST_FDA02');
SELECT * FROM dba_flashback_archive_tables
WHERE table_name='TEST_FDA02';
TEST_FDA02 SYS FDA01 SYS_FBA_HIST_75736 DISASSOCIATED


ALTER TABLE test_fda02 EXCHANGE PARTITION p2 WITH TABLE test01;
SELECT * FROM test01;
SELECT * FROM test_fda02;


exec dbms_flashback_archive.reassociate_fba('SYS','TEST_FDA02');


SELECT * FROM dba_flashback_archive_tables
WHERE table_name='TEST_FDA02';


Also, to drop a table enabled for Flashback Data Archive, you must first disable Flashback Data Archive on the table by using the ALTER TABLE ... NO FLASHBACK ARCHIVE clause.

 

 6、闪回drop

flashback drop    --前提是回收站要打开(是通过回收站闪回数据)
If the parameter is set to off, then dropped tables do not go into the recycle bin. If this parameter is set to on, then dropped tables go into the recycle bin and can be recovered.
show parameter recyclebin;
NAME       TYPE   VALUE 
---------- ------ ----- 
recyclebin string on     
1)on  表示drop table  删除表是放入回收站   
2)off 表示drop table  删除表直接删除不进入回收站  drop table =drop table  purge

FLASHBACK TABLE origin_table|recyclebin_name TO BEFORE DROP;    ---采用的FILO 

SQL> show recyclebin;
ORIGINAL NAME     RECYCLEBIN NAME        OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST01         BIN$q9xkuQ5w/3vgU5ZfqMCFgA==$0 TABLE         2020-08-02:10:00:59

FLASHBACK TABLE test01 TO BEFORE DROP;
FLASHBACK TABLE "BIN$q9xkuQ5w/3vgU5ZfqMCFgA==$0" TO BEFORE DROP;
FLASHBACK TABLE "BIN$q9xkuQ5w/3vgU5ZfqMCFgA==$0" TO BEFORE DROP RENAME TO xxxx;

分区

PURGE {TABLE <table_name>|INDEX <index_name>}
PURGE TABLESPACE <ts_name> [USER <user_name>]
PURGE [USER_|DBA_]RECYCLEBIN

desc user_recyclebin;

 

posted @ 2020-08-01 15:59  苍茫宇宙  阅读(521)  评论(0编辑  收藏  举报