閃回資料庫
閃回主要有閃回表、閃回查詢、閃回資料庫(資料來自閃回日誌)三種,這裡主要了解閃回資料庫
閃回資料庫的最佳適用場景:當發生Drop table tablename purge或Truncate table或UNDO不足導致無法閃回表,需要找回丟失的表,但是丟失表之後的資料也不能丟,做閃回資料庫到丟失表之前的時刻點,做完後開啟到open read only模式下去,去檢視是否達到要求,達到後再exp匯出丟失的表,再shutdown immediate,再startup mount,再SQL>recover database;,再alter database open,再imp這張丟失的表
很重要的一點:如果執行完flashback database後還沒有open resetlgos,但是後悔執行falshback database了,可以直接recover database再alter database open,這樣和重啟了一次一樣。
Use the FLASHBACK DATABASE statement to return the database to a past time or system change number (SCN). This statement provides a fast alternative to performing incomplete database recovery.
Following a FLASHBACK DATABASE operation, in order to have write access to the flashed back database, you must reopen it with an ALTER DATABASE OPEN RESETLOGS statement.
You must have the SYSDBA system privilege. A fast recovery area must have been prepared for the database. The database must have been put in FLASHBACK mode with an ALTER DATABASE FLASHBACK ON statement unless you are flashing the database back to a guaranteed restore point. The database must be mounted but not open. In addition:
The database must run in ARCHIVELOG mode.
The database must be mounted, but not open, with a current control file. The control file cannot be a backup or re-created. When the database control file is restored from backup or re-created, all existing flashback log information is discarded.
The database must contain no online tablespaces for which flashback functionality was disabled with the SQL statement ALTER TABLESPACE ... FLASHBACK OFF.
使用FLASHBACK DATABASE語句將資料庫返回到過去的時間或系統更改編號(SCN)。 此語句提供了執行不完整資料庫恢復的快速替代方法。
在進行FLASHBACK DATABASE操作之後,為了對閃回的資料庫進行寫入訪問,必須使用ALTER DATABASE OPEN RESETLOGS語句重新開啟它。
您必須具有SYSDBA系統許可權。 必須為資料庫準備快速恢復區域。 必須使用ALTER DATABASE FLASHBACK ON語句將資料庫置於FLASHBACK模式,除非將資料庫閃回到保證還原點。 做閃回操作時資料庫必須在MOUNT狀態下,不能在OPEN狀態下。此外有如下限制
資料庫必須以ARCHIVELOG模式執行。
必須使用當前的控制檔案把資料庫開啟至MOUNT狀態而非OPNE狀態。 控制檔案不能是備份或重新建立。 當資料庫控制檔案從備份或重新建立恢復時,所有現有的閃回日誌資訊都將被丟棄。
資料庫不包含禁用閃回功能的聯機表空間。
上面的MOUNT狀態指的是做閃回操作時,資料庫必須是MOUNT狀態,而不是指Alter database flashback on必須在MOUNT狀態下執行,Alter database flashback on可以在MOUNT/OPEN兩種狀態下執行
V$database.flashback_on值為YES就代表開啟了閃回資料庫
Select flashback_on from v$database;
Flashback on的前提條件:archivelog模式+db_recovery_file_dest不為空
Archive log list限定的Archive destination可以不是USE_DB_RECOVERY_FILE_DEST
SQL> alter database flashback on;
alter database flashback on
*
ERROR at line 1:
ORA-38706: Cannot turn on FLASHBACK DATABASE logging.
ORA-38707: Media recovery is not enabled.
開啟閃回資料庫除了產生歸檔日誌,也產生閃回日誌(不是產生一個歸檔日誌就會同時產生一個閃回日誌)
閃回日誌的兩個檢視V$FLASHBACK_DATABASE_LOG、V$FLASHBACK_DATABASE_LOGFILE
閃回日誌的相關引數db_flashback_retention_target,控制閃回日誌存放時間
閃回資料庫的一次案例
1、建立test1、test2
2、記錄當前時間date
3、drop test1、truncate test2、create test3
4、要求恢復test1、test2的資料,並且不能造成test3丟失。
1、
SQL> conn t1/123456
Connected.
SQL> create table test1 as select * from dba_users;
Table created.
SQL> create table test2 as select * from dba_data_files;
Table created.
2、
[oracle@localhost flashback]$ date
2017年 08月 17日 星期四 15:00:09 CST
3、
[oracle@localhost flashback]$ sqlplus t1/123456
SQL> drop table test1;
Table dropped.
SQL> truncate table test2;
Table truncated.
SQL> create table test3 as select * from dba_tablespaces;
Table created.
SQL> select count(*) from test1;
select count(*) from test1
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> select count(*) from test2;
COUNT(*)
----------
0
SQL> select count(*) from test3;
COUNT(*)
----------
6
4、
[oracle@localhost flashback]$ sqlplus / as sysdba
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 321548288 bytes
Fixed Size 2252824 bytes
Variable Size 264245224 bytes
Database Buffers 50331648 bytes
Redo Buffers 4718592 bytes
Database mounted.
SQL>flashback database to timestamp to_timestamp('2017-08-17 15:00:09','yyyy-mm-dd hh24:mi:ss');
--expdp會建立job,所以read only狀態下是無法expdp的,但是可以使用exp
--閃回後,15:00:09之前的test1、test2回來了,但是之後的test3沒有了
SQL> alter database open read only;
Database altered.
SQL> conn t1/123456
Connected.
SQL> select count(*) from test1;
COUNT(*)
----------
37
SQL> select count(*) from test2;
COUNT(*)
----------
5
SQL> select count(*) from test3;
select count(*) from test3
*
ERROR at line 1:
ORA-00942: table or view does not exist
--exp匯出test1、test2表資料
[oracle@localhost flashback]$exp t1/123456 file=/home/oracle/test1_2.dmp tables=test1,test2
--關閉資料庫啟動到mount再recover在open,相當於重啟了一次資料庫,flashback沒有起任何作用
[oracle@localhost ~]$ sqlplus / as sysdba
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 321548288 bytes
Fixed Size 2252824 bytes
Variable Size 264245224 bytes
Database Buffers 50331648 bytes
Redo Buffers 4718592 bytes
Database mounted.
SQL> recover database;
Media recovery complete.
SQL> alter database open;
Database altered.
SQL> conn t1/123456
Connected.
SQL> select count(*) from test1;
select count(*) from test1
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> select count(*) from test2;
COUNT(*)
----------
0
SQL> select count(*) from test3;
COUNT(*)
----------
6
--imp匯入test1、test2,這樣恢復了test1、test2的資料,test3也沒丟失
[oracle@localhost flashback]$imp t1/123456 file=/home/oracle/test1_2.dmp full=y ignore=y
SQL> conn t1/123456
SQL> select count(*) from test1;
COUNT(*)
----------
37
SQL> select count(*) from test2;
COUNT(*)
----------
5
SQL> select count(*) from test3;
COUNT(*)
----------
6
繼續上面的步驟,再次閃回到上面第二步即未drop test1之前的時刻點,不用resetlogs看可以嗎。答案是不可以這樣的。
[oracle@localhost ~]$ sqlplus / as sysdba
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 321548288 bytes
Fixed Size 2252824 bytes
Variable Size 264245224 bytes
Database Buffers 50331648 bytes
Redo Buffers 4718592 bytes
Database mounted.
SQL> flashback database to timestamp to_timestamp('2017-08-17 15:00:09','yyyy-mm-dd hh24:mi:ss');
Flashback complete.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open resetlogs;
Database altered.
SQL> conn t1/123456
Connected.
SQL> select count(*) from test1;
COUNT(*)
----------
37
SQL> select count(*) from test2;
COUNT(*)
----------
5
SQL> select count(*) from test3;
select count(*) from test3
*
ERROR at line 1:
ORA-00942: table or view does not exist
閃回資料庫的最佳適用場景:當發生Drop table tablename purge或Truncate table或UNDO不足導致無法閃回表,需要找回丟失的表,但是丟失表之後的資料也不能丟,做閃回資料庫到丟失表之前的時刻點,做完後開啟到open read only模式下去,去檢視是否達到要求,達到後再exp匯出丟失的表,再shutdown immediate,再startup mount,再SQL>recover database;,再alter database open,再imp這張丟失的表
很重要的一點:如果執行完flashback database後還沒有open resetlgos,但是後悔執行falshback database了,可以直接recover database再alter database open,這樣和重啟了一次一樣。
Use the FLASHBACK DATABASE statement to return the database to a past time or system change number (SCN). This statement provides a fast alternative to performing incomplete database recovery.
Following a FLASHBACK DATABASE operation, in order to have write access to the flashed back database, you must reopen it with an ALTER DATABASE OPEN RESETLOGS statement.
You must have the SYSDBA system privilege. A fast recovery area must have been prepared for the database. The database must have been put in FLASHBACK mode with an ALTER DATABASE FLASHBACK ON statement unless you are flashing the database back to a guaranteed restore point. The database must be mounted but not open. In addition:
The database must run in ARCHIVELOG mode.
The database must be mounted, but not open, with a current control file. The control file cannot be a backup or re-created. When the database control file is restored from backup or re-created, all existing flashback log information is discarded.
The database must contain no online tablespaces for which flashback functionality was disabled with the SQL statement ALTER TABLESPACE ... FLASHBACK OFF.
使用FLASHBACK DATABASE語句將資料庫返回到過去的時間或系統更改編號(SCN)。 此語句提供了執行不完整資料庫恢復的快速替代方法。
在進行FLASHBACK DATABASE操作之後,為了對閃回的資料庫進行寫入訪問,必須使用ALTER DATABASE OPEN RESETLOGS語句重新開啟它。
您必須具有SYSDBA系統許可權。 必須為資料庫準備快速恢復區域。 必須使用ALTER DATABASE FLASHBACK ON語句將資料庫置於FLASHBACK模式,除非將資料庫閃回到保證還原點。 做閃回操作時資料庫必須在MOUNT狀態下,不能在OPEN狀態下。此外有如下限制
資料庫必須以ARCHIVELOG模式執行。
必須使用當前的控制檔案把資料庫開啟至MOUNT狀態而非OPNE狀態。 控制檔案不能是備份或重新建立。 當資料庫控制檔案從備份或重新建立恢復時,所有現有的閃回日誌資訊都將被丟棄。
資料庫不包含禁用閃回功能的聯機表空間。
上面的MOUNT狀態指的是做閃回操作時,資料庫必須是MOUNT狀態,而不是指Alter database flashback on必須在MOUNT狀態下執行,Alter database flashback on可以在MOUNT/OPEN兩種狀態下執行
V$database.flashback_on值為YES就代表開啟了閃回資料庫
Select flashback_on from v$database;
Flashback on的前提條件:archivelog模式+db_recovery_file_dest不為空
Archive log list限定的Archive destination可以不是USE_DB_RECOVERY_FILE_DEST
SQL> alter database flashback on;
alter database flashback on
*
ERROR at line 1:
ORA-38706: Cannot turn on FLASHBACK DATABASE logging.
ORA-38707: Media recovery is not enabled.
開啟閃回資料庫除了產生歸檔日誌,也產生閃回日誌(不是產生一個歸檔日誌就會同時產生一個閃回日誌)
閃回日誌的兩個檢視V$FLASHBACK_DATABASE_LOG、V$FLASHBACK_DATABASE_LOGFILE
閃回日誌的相關引數db_flashback_retention_target,控制閃回日誌存放時間
閃回資料庫的一次案例
1、建立test1、test2
2、記錄當前時間date
3、drop test1、truncate test2、create test3
4、要求恢復test1、test2的資料,並且不能造成test3丟失。
1、
SQL> conn t1/123456
Connected.
SQL> create table test1 as select * from dba_users;
Table created.
SQL> create table test2 as select * from dba_data_files;
Table created.
2、
[oracle@localhost flashback]$ date
2017年 08月 17日 星期四 15:00:09 CST
3、
[oracle@localhost flashback]$ sqlplus t1/123456
SQL> drop table test1;
Table dropped.
SQL> truncate table test2;
Table truncated.
SQL> create table test3 as select * from dba_tablespaces;
Table created.
SQL> select count(*) from test1;
select count(*) from test1
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> select count(*) from test2;
COUNT(*)
----------
0
SQL> select count(*) from test3;
COUNT(*)
----------
6
4、
[oracle@localhost flashback]$ sqlplus / as sysdba
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 321548288 bytes
Fixed Size 2252824 bytes
Variable Size 264245224 bytes
Database Buffers 50331648 bytes
Redo Buffers 4718592 bytes
Database mounted.
SQL>flashback database to timestamp to_timestamp('2017-08-17 15:00:09','yyyy-mm-dd hh24:mi:ss');
--expdp會建立job,所以read only狀態下是無法expdp的,但是可以使用exp
--閃回後,15:00:09之前的test1、test2回來了,但是之後的test3沒有了
SQL> alter database open read only;
Database altered.
SQL> conn t1/123456
Connected.
SQL> select count(*) from test1;
COUNT(*)
----------
37
SQL> select count(*) from test2;
COUNT(*)
----------
5
SQL> select count(*) from test3;
select count(*) from test3
*
ERROR at line 1:
ORA-00942: table or view does not exist
--exp匯出test1、test2表資料
[oracle@localhost flashback]$exp t1/123456 file=/home/oracle/test1_2.dmp tables=test1,test2
--關閉資料庫啟動到mount再recover在open,相當於重啟了一次資料庫,flashback沒有起任何作用
[oracle@localhost ~]$ sqlplus / as sysdba
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 321548288 bytes
Fixed Size 2252824 bytes
Variable Size 264245224 bytes
Database Buffers 50331648 bytes
Redo Buffers 4718592 bytes
Database mounted.
SQL> recover database;
Media recovery complete.
SQL> alter database open;
Database altered.
SQL> conn t1/123456
Connected.
SQL> select count(*) from test1;
select count(*) from test1
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> select count(*) from test2;
COUNT(*)
----------
0
SQL> select count(*) from test3;
COUNT(*)
----------
6
--imp匯入test1、test2,這樣恢復了test1、test2的資料,test3也沒丟失
[oracle@localhost flashback]$imp t1/123456 file=/home/oracle/test1_2.dmp full=y ignore=y
SQL> conn t1/123456
SQL> select count(*) from test1;
COUNT(*)
----------
37
SQL> select count(*) from test2;
COUNT(*)
----------
5
SQL> select count(*) from test3;
COUNT(*)
----------
6
繼續上面的步驟,再次閃回到上面第二步即未drop test1之前的時刻點,不用resetlogs看可以嗎。答案是不可以這樣的。
[oracle@localhost ~]$ sqlplus / as sysdba
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 321548288 bytes
Fixed Size 2252824 bytes
Variable Size 264245224 bytes
Database Buffers 50331648 bytes
Redo Buffers 4718592 bytes
Database mounted.
SQL> flashback database to timestamp to_timestamp('2017-08-17 15:00:09','yyyy-mm-dd hh24:mi:ss');
Flashback complete.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open resetlogs;
Database altered.
SQL> conn t1/123456
Connected.
SQL> select count(*) from test1;
COUNT(*)
----------
37
SQL> select count(*) from test2;
COUNT(*)
----------
5
SQL> select count(*) from test3;
select count(*) from test3
*
ERROR at line 1:
ORA-00942: table or view does not exist
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30126024/viewspace-2143699/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 閃回(關於閃回資料庫)資料庫
- Oracle閃回技術之閃回資料庫Oracle資料庫
- Oracle資料庫閃回Oracle資料庫
- Oracle閃回資料庫Oracle資料庫
- 資料庫的閃回資料庫
- 【備份恢復】閃回資料庫(一)閃回資料庫的管理資料庫
- 【備份恢復】閃回資料庫(五)RMAN 命令列閃回資料庫資料庫命令列
- 【備份恢復】閃回資料庫(二) 基於 SCN 閃回資料庫資料庫
- 閃回資料庫的事情資料庫
- Flashback Database 閃回資料庫Database資料庫
- 監視閃回資料庫資料庫
- 實驗-閃回資料庫資料庫
- Oracle閃回技術 為Oracle閃回配置資料庫Oracle資料庫
- Oracle 閃回技術 概覽 資料庫閃回功能Oracle資料庫
- 【備份恢復】閃回資料庫(三)基於時間戳閃回資料庫資料庫時間戳
- 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資料庫
- dg_閃回資料庫實驗資料庫
- 還原點和閃回資料庫資料庫
- Oracle 11g 閃回資料庫Oracle資料庫
- 資料庫基於版本的閃回資料庫
- 開啟資料庫的閃回功能:資料庫
- Backup And Recovery User's Guide-使用閃回資料庫來回退資料庫-閃回資料庫的先決條件GUIIDE資料庫
- 在物理備庫上部署閃回資料庫資料庫
- Backup And Recovery User's Guide-使用閃回資料庫和還原點-閃回資料庫的限制GUIIDE資料庫
- Backup And Recovery User's Guide-使用閃回資料庫和還原點-閃回資料庫視窗GUIIDE資料庫
- Oracle資料庫閃回區空間不足Oracle資料庫
- 基於時間戳閃回資料庫時間戳資料庫
- 閃回資料庫(flashback database)知識分享資料庫Database
- ORACLE資料庫閃回步驟詳解Oracle資料庫