Flashback整理,并演示了一些容易忽略的问题

本帖最后由 kevin.zhang 于 2010-11-4 16:23 编辑

This document guide you how to use flashback feature.  Some common problems you may come across are also shown in this document.

1.Flashback query.Flashback query use rollback segments, so you can perform an flashback query without really enabling flashback feature.
duck_11 > archive log list
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            /export01/backup/duck_11
Oldest online log sequence     12
Current log sequence           14

duck_11 > alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
Session altered.

duck_11 > create table testflash(i int,logtime date);
Table created.
duck_11 > insert into testflash values(1,sysdate);
1 row created.

duck_11 > commit;
Commit complete.

duck_11 > select sysdate from dual;
SYSDATE
-------------------
2010-10-28 21:34:48

duck_11 > insert into testflash values(2,sysdate);
1 row created.

duck_11 > commit;
Commit complete.

duck_11 > select * from testflash;
         I LOGTIME
---------- -------------------
         1 2010-10-28 21:34:35
         2 2010-10-28 21:35:09

duck_11 > select * from testflash as of timestamp to_timestamp('2010-10-28 21:34:48','YYYY-MM-DD HH24:MI:SS');
         I LOGTIME
---------- -------------------
         1 2010-10-28 21:34:35

2.Open flashback function.In this stage, you should know how to define flashback log destination and archive log destination into different directories.
duck_11 > ho mkdir -p /export01/flashback_area/duck_11

duck_11 > alter system set db_recovery_file_dest_size=4g ;
System altered.

duck_11 > alter system set db_recovery_file_dest='/export01/flashback_area/duck_11' scope=spfile;
System altered.

duck_11 > ho mkdir -p /export01/backup/duck_11

duck_11 > alter system set log_archive_dest_1='LOCATION=/export01/backup/duck_11';
System altered.

duck_11 > shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

duck_11 > startup mount;
ORACLE instance started.
Total System Global Area  418484224 bytes
Fixed Size                  1336932 bytes
Variable Size             314575260 bytes
Database Buffers           96468992 bytes
Redo Buffers                6103040 bytes
Database mounted.

duck_11 > alter database archivelog;
Database altered.

duck_11 > alter database flashback on;
Database altered.

duck_11 > alter database open;
Database altered.

3.Flashback table. In this step. You should notice that you can't flashback a table owned by SYS. AND if you want to flashback a table, you should enable row movement first.
duck_11 > select * from testflash;
         I LOGTIME
---------- -------------------
         1 2010-10-28 21:34:35
         2 2010-10-28 21:35:09

duck_11 > select sysdate from dual;
SYSDATE
-------------------
2010-10-28 21:44:18

duck_11 > insert into testflash values(3,sysdate);
1 row created.

duck_11 > commit;
Commit complete.

duck_11 > flashback table testflash to timestamp to_timestamp('2010-10-28 21:44:18','YYYY-MM-DD HH24:MI:SS');
flashback table testflash to timestamp to_timestamp('2010-10-28 21:44:18','YYYY-MM-DD HH24:MI:SS')
                *
ERROR at line 1:
ORA-08185: Flashback not supported for user SYS

duck_11 > create table scott.testflash as select * from testflash;
Table created.

duck_11 > select sysdate from dual;
SYSDATE
-------------------
2010-10-28 21:47:09

duck_11 > insert into scott.testflash values(4,sysdate);
1 row created.

duck_11 > commit;
Commit complete.

duck_11 > select count(*) from scott.testflash;
  COUNT(*)
----------
         4

duck_11 >  flashback table scott.testflash to timestamp to_timestamp('2010-10-28 21:47:09','YYYY-MM-DD HH24:MI:SS');
flashback table scott. testflash to timestamp to_timestamp('2010-10-28 21:44:18','YYYY-MM-DD HH24:MI:SS')
                        *
ERROR at line 1:
ORA-08189: cannot flashback the table because row movement is not enabled

duck_11 > alter table scott.testflash enable row movement;
Table altered.

duck_11 > flashback table scott. testflash to timestamp to_timestamp('2010-10-28 21:47:09','YYYY-MM-DD HH24:MI:SS');
Flashback complete.

duck_11 > select count(*) from scott.testflash;
  COUNT(*)
----------
         3

4.Flashback Dropped table. In this step, you should notice that a dropped table located on system tablespace can't be found in the recyclebin.  And if you want to check a recyclebin for a dropped table, your identify should be the table's owner,  not the one who performed the dropping operation.
duck_11 > show parameter recyclebin
NAME                                 TYPE                              VALUE
------------------------------------ --------------------------------- ----------------------
recyclebin                           string                            on

duck_11 > create table scott.testflash2 tablespace db_users as select * from scott.testflash;
Table created.

duck_11 > drop table scott.testflash;
Table dropped.

duck_11 > drop table scott.testflash2;
Table dropped.

duck_11 > show recyclebin

duck_11 > conn scott/tiger;
Connected.

duck_11 > show recyclebin
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
TESTFLASH2       BIN$k7jZlZ7AgxrgQAB/AQBEtA==$0 TABLE        2010-10-28:22:14:00

duck_11 > flashback table testflash2 to before drop;
Flashback complete.

duck_11 > drop table testflash2;
Table dropped.

duck_11 > show recyclebin;
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
TESTFLASH2       BIN$k7jcqIDJKn/gQAB/AQBFAg==$0 TABLE        2010-10-28:22:14:52

duck_11 > flashback table "BIN$k7jcqIDJKn/gQAB/AQBFAg==$0" to before drop rename to testflash;
Flashback complete.

5.Flashback database.  Once you flashback a database, you need to open the database with resetlogs option later. And oracle recommand you to perform a full database backup after a resetlog operation.
duck_11 > show user
USER is "SCOTT"

duck_11 > alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
Session altered.

duck_11 > select sysdate from dual;
SYSDATE
-------------------
2010-10-28 22:26:01

duck_11 > select count(*) from testflash;
  COUNT(*)
----------
         3

duck_11 > truncate table testflash;
Table truncated.

duck_11 > conn / as sysDBA
Connected.

duck_11 > shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

duck_11 > startup mount;
ORACLE instance started.
Total System Global Area  418484224 bytes
Fixed Size                  1336932 bytes
Variable Size             318769564 bytes
Database Buffers           92274688 bytes
Redo Buffers                6103040 bytes
Database mounted.

duck_11 > flashback database to timestamp to_timestamp('2010-10-28 22:26:01','YYYY-MM-DD HH24:MI:SS');
Flashback complete.

duck_11 > alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

duck_11 > alter database open resetlogs;
Database altered.

duck_11 > conn scott/tiger;
Connected.

duck_11 > select count(*) from testflash;
  COUNT(*)
----------
         3

标签: 暂无标签
kevin.zhang

写了 32 篇文章,拥有财富 308,被 10 人关注

转播转播 分享分享 分享淘帖
回复

使用道具

P6 | 发表于 2010-11-4 16:58:22
记住:
闪回查询、闪回表、闪回删除都是常用的,要熟悉原理和具体的应用。
对于闪回数据库,使用很少。
回复

使用道具

您需要登录后才可以回帖 登录 | 加入社区

本版积分规则

意见
反馈