用RESETLOGS方式打开数据库之前恢复只读表空间的备份
如何在RESETLOGS方式打开数据库之前恢复只读表空间的备份
信息:
*在一个表空间处于只读模式之后备份它。
(只有当它在RESETLOGS之前不是读写模式)
这是一个内训测试方案
这是步骤:
步骤
——
SQL> select name,status,checkpoint_change# from v$datafile;
NAME STATUS CHECKPOINT_CHANGE#
---------------------------------------- ------- ------------------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF SYSTEM 766796
D:\ORACLE\ORADATA\AMAR\RBS01.DBF ONLINE 766796
D:\ORACLE\ORADATA\AMAR\USERS01.DBF ONLINE 766796
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF ONLINE 766796
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF ONLINE 766796
D:\ORACLE\ORADATA\AMAR\INDX01.DBF ONLINE 766796
D:\ORACLE\ORADATA\AMAR\DR01.DBF ONLINE 766796
D:\ORACLE\ORADATA\AMAR\TEST01.DBF ONLINE 423736 --> THIS IS THE READ ONLY TABLESPACE
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF ONLINE 766864
9 rows selected.
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
RBS ONLINE
USERS ONLINE
TEMP ONLINE
TOOLS ONLINE
INDX ONLINE
DRSYS ONLINE
TEST READ ONLY
JAGU ONLINE
9 rows selected.
SQL> shutdown abort
ORACLE instance shut down.
——假设有一个数据库崩溃-
SQL> alter database datafile 8 offline drop;
Database altered.
SQL> select name,status from v$datafile_header;
NAME STATUS
---------------------------------------- -------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\RBS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\USERS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\INDX01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\DR01.DBF ONLINE
OFFLINE - in datafile header entry is there
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF ONLINE
9 rows selected.
SQL> select FILE# from v$recover_file;
FILE#
——————
8 FILE NEEDS ReCOVERY
+++ DONE a INCOMPLETE Recovery
SQL> recover database until cancel
cancel
SQL> alter database open resetlogs;
Database altered.
SQL> select name,to_char(RESETLOGS_TIME,'DD-MON-YYYY HH:MI::SS') from v$database
2 ;
NAME TO_CHAR(RESETLOGS_TIM
---------------------------------------- ---------------------
AMAR 01-MAR-2004 01:07::18
SQL> select name,to_char(RESETLOGS_TIME,'DD-MON-YYYY HH:MI::SS')
2 from v$datafile_header;
NAME TO_CHAR(RESETLOGS_TIM
---------------------------------------- ---------------------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\RBS01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\USERS01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\INDX01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\DR01.DBF 01-MAR-2004 01:07::18
MISSING FOR DATAFILE 8
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF 01-MAR-2004 01:07::18
9 rows selected.
SQL> select file# from v$recover_file;
FILE#
----------
8 — 仍旧显示需要在 RESETLOGS之后恢复
++ 如果该文件在崩溃中丢失我们将需要恢复一样的文件从备份中在它被改成 READ ONLY
之后
SQL> recover datafile 8;
ORA-00283: recovery session canceled due to errors
ORA-00264: no recovery required
看到错误的原因
——————
++ 因为这是一个只读表空间,它不需要被介质恢复
++ 我们可以让数据文件直接在线
SQL> alter database datafile 8 online;
alter database datafile 8 online
*
ERROR at line 1:
ORA-01190: controlfile or data file 8 is from before the last RESETLOGS
ORA-01110: data file 8: 'D:\ORACLE\ORADATA\AMAR\TEST01.DBF'
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
RBS ONLINE
USERS ONLINE
TEMP ONLINE
TOOLS ONLINE
INDX ONLINE
DRSYS ONLINE
TEST READ ONLY -READONLY After RESETLOGS
JAGU ONLINE
9 rows selected.
SQL> select name,status from v$datafile;
clsNAME STATUS
---------------------------------------- -------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF SYSTEM
D:\ORACLE\ORADATA\AMAR\RBS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\USERS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\INDX01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\DR01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TEST01.DBF OFFLINE -- as we have offline drop this file
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF ONLINE
9 rows selected.
SQL> select name,status from v$datafile_header;
clsNAME STATUS
---------------------------------------- -------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\RBS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\USERS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\INDX01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\DR01.DBF ONLINE
OFFLINE -- as we have offline drop this file
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF ONLINE
9 rows selected.
++ 试着使只读表空间在线
SQL> alter tablespace test online;
Tablespace altered.
SQL> select name,status from v$datafile;
NAME STATUS
---------------------------------------- -------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF SYSTEM
D:\ORACLE\ORADATA\AMAR\RBS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\USERS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\INDX01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\DR01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TEST01.DBF ONLINE -File is online
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF ONLINE
9 rows selected.
SQL> select name,status from v$datafile_header;
NAME STATUS
---------------------------------------- -------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\RBS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\USERS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\INDX01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\DR01.DBF ONLINE
D:\ORACLE\ORADATA\AMAR\TEST01.DBF ONLINE - FIle is online
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF ONLINE
9 rows selected.
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
RBS ONLINE
USERS ONLINE
TEMP ONLINE
TOOLS ONLINE
INDX ONLINE
DRSYS ONLINE
TEST READ ONLY -- Still in Read only after resetlogs and is accessible in the database.
JAGU ONLINE
9 rows selected.
SQL> select name,checkpoint_change# from v$datafile_header;
NAME CHECKPOINT_CHANGE#
---------------------------------------- ------------------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF 766872
D:\ORACLE\ORADATA\AMAR\RBS01.DBF 766872
D:\ORACLE\ORADATA\AMAR\USERS01.DBF 766872
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF 766872
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF 766872
D:\ORACLE\ORADATA\AMAR\INDX01.DBF 766872
D:\ORACLE\ORADATA\AMAR\DR01.DBF 766872
D:\ORACLE\ORADATA\AMAR\TEST01.DBF 423736 -- its the same SCN as we started with
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF 766872
9 rows selected.
SQL> select name,to_char(RESETLOGS_TIME,'DD-MON-YYYY HH:MI::SS')
2 from v$datafile_header;
NAME TO_CHAR(RESETLOGS_TIM
---------------------------------------- ---------------------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\RBS01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\USERS01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\INDX01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\DR01.DBF 01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\TEST01.DBF 10-NOV-2003 01:12::26 -- Showing the LAST RESETLOGS date
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF 01-MAR-2004 01:07::18
9 rows selected.
SQL> alter tablespace test read write;
Tablespace altered.
SQL> select name,checkpoint_change# from v$datafile_header;
NAME CHECKPOINT_CHANGE#
---------------------------------------- ------------------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF 766872
D:\ORACLE\ORADATA\AMAR\RBS01.DBF 766872
D:\ORACLE\ORADATA\AMAR\USERS01.DBF 766872
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF 766872
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF 766872
D:\ORACLE\ORADATA\AMAR\INDX01.DBF 766872
D:\ORACLE\ORADATA\AMAR\DR01.DBF 766872
D:\ORACLE\ORADATA\AMAR\TEST01.DBF 766928 -Sync with the other files
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF 766872
9 rows selected.