一、闪回恢复
sql> select * from t;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
60 dba zw
sql> delete from t;
4 rows deleted.
sql> commit;
commit complete.
sql> create table t_r as select * from t as of timestamp timestamp'2023-06-09 11:30:00';
table created.
sql> select * from t_r;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
60 dba zw
二、闪出数据库
1、准备
需要设置删除区和大小并开启闪回
sql> alter system set db_recovery_file_dest_size=4g;
system altered.
sql> alter system set db_recovery_file_dest='/u01/app/oracle/fast_recovery_area';
system altered.
sql> select flashback_on from v$database;
flashback_on
------------------------------------
no
sql> alter database flashback on;
database altered.
sql> show parameter db_reco
name type
------------------------------------ ----------------------
value
------------------------------
db_recovery_file_dest string
/u01/app/oracle/fast_recovery_area
db_recovery_file_dest_size big integer
4g
sql> select flashback_on from v$database;
flashback_on
------------------------------------
yes
2、删除
sql> select * from t;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
60 dba zw
sql> delete from t;
4 rows deleted.
sql> commit;
commit complete.
sql> select * from t;
no rows selected
3、闪回数据库
sql> shutdown immediate
database closed.
database dismounted.
oracle instance shut down.
sql> startup mount;
oracle instance started.
total system global area 2415917880 bytes
fixed size 26594104 bytes
variable size 620756992 bytes
database buffers 1761607680 bytes
redo buffers 6959104 bytes
database mounted.
sql> flashback database to timestamp timestamp'2023-06-09 11:40:00';
sql> alter database open resetlogs;
database altered.
sql> select * from t;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
60 dba zw
三、闪回表
1、环境
sql> select * from t;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
60 dba zw
sql> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
session altered.
sql> select sysdate from dual;
sysdate
-------------------
2023-06-09 11:47:29
sql> delete from t;
4 rows deleted.
sql> commit;
commit complete.
2、闪回表
sql> flashback table t to timestamp timestamp'2023-06-09 11:47:29
2 ';
flashback table t to timestamp timestamp'2023-06-09 11:47:29
*
error at line 1:
ora-01882: timezone region not found
sql> flashback table t to timestamp timestamp'2023-06-09 11:47:29';
flashback table t to timestamp timestamp'2023-06-09 11:47:29'
*
error at line 1:
ora-08189: cannot flashback the table because row movement is not enabled
sql> alter table t enable rowmovement;
alter table t enable rowmovement
*
error at line 1:
ora-00905: missing keyword
sql> alter table t enable row movement;
table altered.
sql> flashback table t to timestamp timestamp'2023-06-09 11:47:29';
flashback complete.
sql> select * from t;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
60 dba zw
四、闪回drop
1、准备
sql> show parameter recyclebin
name type
------------------------------------ ----------------------
value
------------------------------
recyclebin string
off
sql> alter system set recyclebin=on;
alter system set recyclebin=on
*
error at line 1:
ora-02096: specified initialization parameter is not modifiable with this
option
sql> alter system set recyclebin=on scope=spfile;
system altered.
sql> startup force
oracle instance started.
total system global area 2415917880 bytes
fixed size 26594104 bytes
variable size 620756992 bytes
database buffers 1761607680 bytes
redo buffers 6959104 bytes
database mounted.
database opened.
sql>
2、查询回收站
sql> select * from dba_recyclebin;
owner object_name original_name operation type ts_name createtime droptime dropscn partition_name can_un can_pu related base_object purge_object space
------------------------------ ---------------------------------------- ---------------------------------------- ------------------ -------------------------------------------------- ---------------------------------------- -------------------------------------- -------------------------------------- ---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------ ------ ---------- ----------- ------------ ----------
cy bin$/a2phmcjdstgu8ncekwo5w==$0 t drop table users 2023-06-09:14:43:33 2023-06-09:14:43:37 12452461 yes yes 78001 78001 78001 8
3、方法一
sql> create table t1 as select * from "bin$/a2phmcjdstgu8ncekwo5w==$0";
table created.
sql> select * from t1;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
60 dba zw
4、方法二
sql> flashback table "bin$/a2phmcjdstgu8ncekwo5w==$0" to before drop;
flashback complete.
sql> select * from t;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
60 dba zw
5、方法三
sql> flashback table t to before drop rename to t3;
flashback complete.
sql> select * from t3;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
60 dba zw
flashback table
[ schema. ] table
[, [ schema. ] table ]...
to { { { scn | timestamp } expr
| restore point restore_point
} [ { enable | disable } triggers ]
| before drop [ rename to table ]
} ;
五、闪回事务
1、准备
sql> delete from t3 where dname='dba';
1 row deleted.
sql> commit;
commit complete.
sql> select * from t3;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
2、闪回事务
sql> col versions_starttime for a35
sql> col versions_endtime for a35
sql> col versions_xid for a30
sql> set lines 200
sql>
sql> select versions_starttime,versions_endtime, versions_xid, versions_operation, t3.* from t3 versions between timestamp minvalue and maxvalue order by versions_starttime;
versions_starttime versions_endtime versions_xid ve deptno dname loc
----------------------------------- ----------------------------------- ------------------------------ -- ---------- ---------------------------- --------------------------
09-jun-23 02.52.08 pm 1c000900030b0000 d 60 dba zw
09-jun-23 02.52.08 pm 60 dba zw
30 sales wz
10 accounting new york
20 research dallas
sql> col undo_sql for a65
sql> select xid,undo_sql from flashback_transaction_query where xid=hextoraw('&xid');
enter value for xid: 1c000900030b0000
old 1: select xid,undo_sql from flashback_transaction_query where xid=hextoraw('&xid')
new 1: select xid,undo_sql from flashback_transaction_query where xid=hextoraw('1c000900030b0000')
xid undo_sql
---------------- -----------------------------------------------------------------
1c000900030b0000
1c000900030b0000
undo_sql为空,需要开启附加日志
sql> alter database add supplemental log data;
database altered.
sql> select * from t3;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
sql> delete from t3 where deptno=30;
1 row deleted.
sql> commit;
commit complete.
sql> select * from t3;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
sql> select versions_starttime,versions_endtime, versions_xid, versions_operation, t3.* from t3 versions between timestamp minvalue and maxvalue order by versions_starttime;
versions_starttime versions_endtime versions_xid ve deptno dname loc
----------------------------------- ----------------------------------- ------------------------------ -- ---------- ---------------------------- --------------------------
09-jun-23 02.52.08 pm 1c000900030b0000 d 60 dba zw
09-jun-23 03.01.54 pm 17000c00ef0a0000 d 30 sales wz
09-jun-23 03.01.54 pm 30 sales wz
20 research dallas
09-jun-23 02.52.08 pm 60 dba zw
10 accounting new york
sql> select xid,undo_sql from flashback_transaction_query where xid=hextoraw('&xid');
enter value for xid: 17000c00ef0a0000
old 1: select xid,undo_sql from flashback_transaction_query where xid=hextoraw('&xid')
new 1: select xid,undo_sql from flashback_transaction_query where xid=hextoraw('17000c00ef0a0000')
xid undo_sql
---------------- -----------------------------------------------------------------
17000c00ef0a0000 insert into "cy"."t3"("deptno","dname","loc") values ('30','sales
','wz');
3、恢复
sql> insert into "cy"."t3"("deptno","dname","loc") values ('30','sales','wz');
1 row created.
sql> commit;
commit complete.
sql> select * from t3;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
六、bbed恢复
1、环境
sql> select dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid),t.* from t;
dbms_rowid.rowid_relative_fno(rowid) dbms_rowid.rowid_block_number(rowid) deptno dname loc
------------------------------------ ------------------------------------ ---------- ---------------------------- --------------------------
7 5083 50 boss a
7 5083 10 accounting new york
7 5083 20 research dallas
7 5083 30 sales wz
7 5083 60 boss zw
sql> delete from t where dname='boss';
2 rows deleted.
sql> commit;
commit complete.
sql> select * from t;
deptno dname loc
---------- ---------------------------- --------------------------
10 accounting new york
20 research dallas
30 sales wz
2、检查
bbed> set dba 7,5083
dba 0x01c013db (29365211 7,5083)
bbed> map /v
file: /u01/app/oracle/oradata/orcl/users01.dbf (7)
block: 5083 dba:0x01c013db
------------------------------------------------------------
ktb data block (table/cluster)
struct kcbh, 20 bytes @0
ub1 type_kcbh @0
ub1 frmt_kcbh @1
ub2 wrp2_kcbh @2
ub4 rdba_kcbh @4
ub4 bas_kcbh @8
ub2 wrp_kcbh @12
ub1 seq_kcbh @14
ub1 flg_kcbh @15
ub2 chkval_kcbh @16
ub2 spare3_kcbh @18
struct ktbbh, 96 bytes @20
ub1 ktbbhtyp @20
union ktbbhsid, 4 bytes @24
struct ktbbhcsc, 8 bytes @28
sb2 ktbbhict @36
ub1 ktbbhflg @38
ub1 ktbbhfsl @39
ub4 ktbbhfnx @40
struct ktbbhitl[3], 72 bytes @44
struct kdbh, 14 bytes @124
ub1 kdbhflag @124
sb1 kdbhntab @125
sb2 kdbhnrow @126
sb2 kdbhfrre @128
sb2 kdbhfsbo @130
sb2 kdbhfseo @132
sb2 kdbhavsp @134
sb2 kdbhtosp @136
struct kdbt[1], 4 bytes @138
sb2 kdbtoffs @138
sb2 kdbtnrow @140
sb2 kdbr[5] @142
ub1 freespace[7946] @152
ub1 rowdata[90] @8098
ub4 tailchk @8188
bbed> p kdbr
sb2 kdbr[0] @142 8051
sb2 kdbr[1] @144 8025
sb2 kdbr[2] @146 8003
sb2 kdbr[3] @148 7988
sb2 kdbr[4] @150 7974
bbed> p *kdbr[0]
rowdata[77]
-----------
ub1 rowdata[77] @8175 0x3c
bbed> p *kdbr[1]
rowdata[51]
-----------
ub1 rowdata[51] @8149 0x2c
bbed> p * kdbr[2]
rowdata[29]
-----------
ub1 rowdata[29] @8127 0x2c
bbed> p *kdbr[3]
rowdata[14]
-----------
ub1 rowdata[14] @8112 0x2c
bbed> p * kdbr[4]
rowdata[0]
----------
ub1 rowdata[0] @8098 0x3c
3、恢复
bbed> modify /x 2c offset 8175
warning: contents of previous bifile will be lost. proceed? (y/n) y
file: /u01/app/oracle/oradata/orcl/users01.dbf (7)
block: 5083 offsets: 8175 to 8191 dba:0x01c013db
------------------------------------------------------------------------
2c020302 c1330442 4f535301 4102063b b7
<32 bytes per line>
bbed> modify /x 2c offset 8098
file: /u01/app/oracle/oradata/orcl/users01.dbf (7)
block: 5083 offsets: 8098 to 8191 dba:0x01c013db
------------------------------------------------------------------------
2c020302 c13d0442 4f535302 7a772c00 0302c11f 0553414c 45530257 5a2c0003
02c11508 52455345 41524348 0644414c 4c41532c 000302c1 0b0a4143 434f554e
54494e47 084e4557 20594f52 4b2c0203 02c13304 424f5353 01410206 3bb7
<32 bytes per line>
bbed> p *kdbr[0]
rowdata[77]
-----------
ub1 rowdata[77] @8175 0x2c
bbed> p *kdbr[4]
rowdata[0]
----------
ub1 rowdata[0] @8098 0x2c
bbed> sum apply
check value for file 7, block 5083:
current = 0x7dac, required = 0x7dac
sql> select * from t;
deptno dname loc
---------- ---------------------------- --------------------------
50 boss a
10 accounting new york
20 research dallas
30 sales wz
60 boss zw
最后修改时间:2023-06-12 09:35:35
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。