實驗-閃回資料庫
實驗-閃回資料庫
SELECT CURRENT_SCN
FROM V$DATABASE;
FROM V$DATABASE;
create restore point guarantee_rp guarantee flashback database;
list restore point all;
SELECT NAME, SCN, TIME, DATABASE_INCARNATION#,
GUARANTEE_FLASHBACK_DATABASE
FROM V$RESTORE_POINT
WHERE GUARANTEE_FLASHBACK_DATABASE='YES';
GUARANTEE_FLASHBACK_DATABASE
FROM V$RESTORE_POINT
WHERE GUARANTEE_FLASHBACK_DATABASE='YES';
drop table t;
create table a as select * from emp;
SELECT CURRENT_SCN
FROM V$DATABASE;
FROM V$DATABASE;
SELECT OLDEST_FLASHBACK_SCN, OLDEST_FLASHBACK_TIME
FROM V$FLASHBACK_DATABASE_LOG;
FROM V$FLASHBACK_DATABASE_LOG;
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
SHOW ALL;
FLASHBACK DATABASE TO SCN 46963;
ALTER DATABASE OPEN READ ONLY;
SHUTDOWN IMMEDIATE
STARTUP MOUNT
ALTER DATABASE OPEN RESETLOGS;
STARTUP MOUNT
ALTER DATABASE OPEN RESETLOGS;
Database altered.
1.連線到資料庫,建立確認恢復點,並檢視當前SCN
SQL> conn sys/sys@testdb as sysdba
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as SYS
SQL> conn sys/sys@testdb as sysdba
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as SYS
sys@TESTDB> alter database flashback on;
Database altered.
SQL> create restore point guarantee_rp guarantee flashback database;
Done
SQL> SELECT NAME, SCN, TIME, DATABASE_INCARNATION#,
2 GUARANTEE_FLASHBACK_DATABASE
3 FROM V$RESTORE_POINT
4 WHERE GUARANTEE_FLASHBACK_DATABASE='YES';
2 GUARANTEE_FLASHBACK_DATABASE
3 FROM V$RESTORE_POINT
4 WHERE GUARANTEE_FLASHBACK_DATABASE='YES';
NAME SCN TIME DATABASE_INCARNATION# GUARANTEE_FLASHBACK_DATABASE
-------------------------------------------------------------------------------- ---------- ------------------------------------------------- --------------------- ----------------------------
GUARANTEE_RP 4250399 10-5? -13 04.41.33.000000000 ?? 1 YES
-------------------------------------------------------------------------------- ---------- ------------------------------------------------- --------------------- ----------------------------
GUARANTEE_RP 4250399 10-5? -13 04.41.33.000000000 ?? 1 YES
2.進行DDL操作,並檢視SCN
SQL> create table T as select * from scott.emp;
Table created
SQL>
SQL> SELECT CURRENT_SCN
2 FROM V$DATABASE;
SQL> SELECT CURRENT_SCN
2 FROM V$DATABASE;
CURRENT_SCN
-----------
4250638
-----------
4250638
SQL> create table I as select * from scott.emp;
Table created
SQL>
SQL> SELECT CURRENT_SCN
2 FROM V$DATABASE;
SQL> SELECT CURRENT_SCN
2 FROM V$DATABASE;
CURRENT_SCN
-----------
4250665
-----------
4250665
SQL> create table N as select * from scott.emp;
Table created
SQL>
SQL> SELECT CURRENT_SCN
2 FROM V$DATABASE;
SQL> SELECT CURRENT_SCN
2 FROM V$DATABASE;
CURRENT_SCN
-----------
4250682
-----------
4250682
3.檢視當前資料SCN和可以恢復到的最早SCN號:
SQL> SELECT OLDEST_FLASHBACK_SCN, OLDEST_FLASHBACK_TIME
2 FROM V$FLASHBACK_DATABASE_LOG;
SQL> SELECT OLDEST_FLASHBACK_SCN, OLDEST_FLASHBACK_TIME
2 FROM V$FLASHBACK_DATABASE_LOG;
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TIME
-------------------- ---------------------
4249896 2013-5-10 16:05:08
-------------------- ---------------------
4249896 2013-5-10 16:05:08
4.重啟資料庫到mount狀態:
sys@TESTDB> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@TESTDB> startup mount;
ORACLE instance started.
sys@TESTDB> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@TESTDB> startup mount;
ORACLE instance started.
Total System Global Area 405929984 bytes
Fixed Size 1336848 bytes
Variable Size 314575344 bytes
Database Buffers 83886080 bytes
Redo Buffers 6131712 bytes
Database mounted.
sys@TESTDB>
Fixed Size 1336848 bytes
Variable Size 314575344 bytes
Database Buffers 83886080 bytes
Redo Buffers 6131712 bytes
Database mounted.
sys@TESTDB>
5.rman連線資料庫,顯示所有引數:
[oracle@localhost ~]$ rman target /
[oracle@localhost ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Fri May 10 16:12:36 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: TESTDB (DBID=2581100181, not open)
RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name TESTDB are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/ogg/rman_bk/$d%T%t';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/oracle/dbs/snapcf_testdb.f'; # default
RMAN configuration parameters for database with db_unique_name TESTDB are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/ogg/rman_bk/$d%T%t';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/oracle/dbs/snapcf_testdb.f'; # default
該步驟主要關注的是通道的配置,即上面內容中的:CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/ogg/rman_bk/$d%T%t';
6.將資料庫閃回到需要的SCN點上
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Fri May 10 16:49:57 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
idle> conn /as sysdba
Connected.
idle> flashback database to scn 4250638
2 ;
Connected.
idle> flashback database to scn 4250638
2 ;
Flashback complete.
idle> alter database open read only;
Database altered.
idle> select table_name from dba_tables where table_name in ('T','I','N') and wner='SYS';
TABLE_NAME
------------------------------
T
------------------------------
T
這時候,如果我覺得當前這個SCN太舊了,我希望看到刪除了I和N表後的結果。可以進行以下操作:
sys@TESTDB> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@TESTDB> startup mount
ORACLE instance started.
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@TESTDB> startup mount
ORACLE instance started.
Total System Global Area 405929984 bytes
Fixed Size 1336848 bytes
Variable Size 314575344 bytes
Database Buffers 83886080 bytes
Redo Buffers 6131712 bytes
Database mounted.
sys@TESTDB> select current_scn from v$database;
Fixed Size 1336848 bytes
Variable Size 314575344 bytes
Database Buffers 83886080 bytes
Redo Buffers 6131712 bytes
Database mounted.
sys@TESTDB> select current_scn from v$database;
CURRENT_SCN
-----------
0
-----------
0
sys@TESTDB> flashback database to scn 4250665
2 ;
2 ;
Flashback complete.
sys@TESTDB> alter database open read only;
Database altered.
sys@TESTDB> select table_name from dba_tables where table_name in ('T','I','N') and wner='SYS';
TABLE_NAME
------------------------------
T
I
------------------------------
T
I
這時,如果我希望再回到N表建立之後的SCN,按照可以執行以下命令:
sys@TESTDB> recover database until scn 4250682;
ORA-00277: illegal option to the UNTIL recovery flag SCN
ORA-00277: illegal option to the UNTIL recovery flag SCN
sys@TESTDB> recover database ;
ORA-00283: recovery session canceled due to errors
ORA-01124: cannot recover data file 1 - file is in use or recovery
ORA-01110: data file 1: '/u01/oradata/testdb/system01.dbf'
但報錯了。因此比較穩妥的方法還是先
shutdown immediate
startup mount
再flashback database to SCN xxxx;
shutdown immediate
startup mount
再flashback database to SCN xxxx;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26451536/viewspace-764057/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- dg_閃回資料庫實驗資料庫
- [Flashback]Flashback Database閃回資料庫實驗Database資料庫
- 閃回資料庫之後匯入資料實驗資料庫
- 【Flashback】Flashback Database閃回資料庫功能實驗Database資料庫
- 【Oracle 12c資料庫支援閃回庫功能】實驗Oracle資料庫
- 閃回(關於閃回資料庫)資料庫
- 閃回資料庫資料庫
- Oracle閃回技術之閃回資料庫Oracle資料庫
- Oracle資料庫閃回Oracle資料庫
- Oracle閃回資料庫Oracle資料庫
- 資料庫的閃回資料庫
- 【備份恢復】閃回資料庫(一)閃回資料庫的管理資料庫
- 【備份恢復】閃回資料庫(五)RMAN 命令列閃回資料庫資料庫命令列
- 【備份恢復】閃回資料庫(二) 基於 SCN 閃回資料庫資料庫
- 閃回資料庫的事情資料庫
- Flashback Database 閃回資料庫Database資料庫
- 監視閃回資料庫資料庫
- Oracle閃回技術 為Oracle閃回配置資料庫Oracle資料庫
- Oracle 閃回技術 概覽 資料庫閃回功能Oracle資料庫
- 【Flashback】Flashback Database閃回資料庫功能實踐Database資料庫
- 【備份恢復】閃回資料庫(三)基於時間戳閃回資料庫資料庫時間戳
- Backup And Recovery User's Guide-使用閃回資料庫-開啟閃回資料庫GUIIDE資料庫
- FlashBack總結之閃回資料庫與閃回刪除資料庫
- [Flashback]開啟資料庫閃回資料庫功能資料庫
- Oracle 閃回資料庫測試Oracle資料庫
- 詳解oracle資料庫閃回Oracle資料庫
- 基於SCN閃回資料庫資料庫
- Backup And Recovery User's Guide-使用閃回資料庫來回退資料庫-監控閃回資料庫GUIIDE資料庫
- 【備份恢復】閃回資料庫(四)基於可靠還原點閃回資料庫資料庫
- Backup And Recovery User's Guide-使用閃回資料庫來回退資料庫-執行閃回資料庫操作GUIIDE資料庫
- Backup And Recovery User's Guide-使用閃回資料庫和還原點-閃回資料庫GUIIDE資料庫
- 還原點和閃回資料庫資料庫
- Oracle 11g 閃回資料庫Oracle資料庫
- 資料庫基於版本的閃回資料庫
- 開啟資料庫的閃回功能:資料庫
- Backup And Recovery User's Guide-使用閃回資料庫來回退資料庫-閃回資料庫的先決條件GUIIDE資料庫
- 在物理備庫上部署閃回資料庫資料庫
- (f)--閃回恢復區---實踐2---閃回表(閃回DML部分資料會用到閃回查詢)