控制文件恢复系列(3)

[3.10] 所有控制文件损坏,所有的活动和当前在线日志文件损坏,控制文件只有TRACE文件,数据文件没有备份,数据库异常关闭
--------使用隐含参数强制打开数据库
1:创建控制文trace备份
sys@ORCL> alter database backup controlfile to trace as '/backup/ctl.sql' reuse;

查看当前的日志组,模拟损坏日志组
ys@ORCL> select * from v$log;

GROUP# THREAD# SEQUENCE#      BYTES  BLOCKSIZE MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME   NEXT_CHANGE# NEXT_TIME
------ ------- --------- ---------- ---------- ------- --- ---------------- ------------- ------------ ------------ ------------
     1       1         1   52428800        512       1 YES INACTIVE             402714056 14-DEC-14       402716125 14-DEC-14
      2       1         2   52428800        512       1 NO  CURRENT              402716125 14-DEC-14      2.8147E+14
     3       1         0   52428800        512       1 YES UNUSED                       0                         0
[root@Lee orcl]# mv redo02.log /home/

DOWN机数据库
sys@ORCL> shutdown abort;
ORACLE instance shut down.

尝试恢复数据库
sys@ORCL> startup nomount;
ORACLE instance started.
Total System Global Area  784998400 bytes
Fixed Size                  2257352 bytes
Variable Size             499125816 bytes
Database Buffers          281018368 bytes
Redo Buffers                2596864 bytes
CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS  ARCHIVELOG
  2      MAXLOGFILES 16
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 100
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 4674
  7  LOGFILE
  8    GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log'  SIZE 50M BLOCKSIZE 512,
  9    GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log'  SIZE 50M BLOCKSIZE 512,
10    GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log'  SIZE 50M BLOCKSIZE 512
11  -- STANDBY LOGFILE
12  DATAFILE
13    '/u01/app/oracle/oradata/orcl/system01.dbf',
14    '/u01/app/oracle/oradata/orcl/sysaux01.dbf',
15    '/u01/app/oracle/oradata/orcl/undotbs01.dbf',
16    '/u01/app/oracle/oradata/orcl/users01.dbf',
17    '/u01/app/oracle/oradata/orcl/example01.dbf',
18    '/u01/app/oracle/oradata/orcl/users02.dbf'
19  CHARACTER SET ZHS16GBK
20  ;
Control file created.

修改参数文件,添加强制启动的三个参数:
[oracle@Lee dbs]$ vi initorcl.ora
orcl.__db_cache_size=281018368
orcl.__java_pool_size=4194304
orcl.__large_pool_size=71303168
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=297795584
orcl.__sga_target=490733568
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=125829120
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl','/u01/app/oracle/oradata/orcl/control03.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.memory_target=786432000
*.O7_DICTIONARY_ACCESSIBILITY=FALSE
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_management='auto'
*.undo_tablespace='UNDOTBS1'
*._allow_resetlogs_corruption=true
*._corrupted_rollback_segments=true
*._offline_rollback_segments=true
重启数据库
sys@ORCL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
sys@ORCL> startup pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora';
ORACLE instance started.

Total System Global Area  784998400 bytes
Fixed Size                  2257352 bytes
Variable Size             499125816 bytes
Database Buffers          281018368 bytes
Redo Buffers                2596864 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
sys@ORCL> alter database open resetlogs;

Database altered.
注意此时数据库为不一致状态,重启后立即备份数据库,导出数据

下面的实验是发生在数据文件丢失,没有备份,控制文件丢失的情况下如何恢复

[3.11.1] 数据文件丢失,无备份,控制文件损坏,有TRACE,数据库恢复起点在文件创建前。
1:创建测试数据文件、控制文件trace备份
sys@ORCL> create tablespace tbs01 datafile 'D:\ORACLE\ORADATA\FANGKUAI\TBS01_1DBF' size 10M;
Tablespace created.
sys@ORCL> create table t01 (x number) tablespace tbs01;
Table created.
sys@ORCL> insert into t01 values (99);
1 row created.
sys@ORCL> commit;
Commit complete.
sys@ORCL> alter database backup controlfile to trace as '/backup/ctl.sql' reuse;
Database altered.

2:模拟数据文件和控制文件丢失
[root@Lee orcl]# mv control0* /home/
[root@Lee orcl]# mv tbs01.dbf /home/

3:开始恢复数据文件
sys@ORCL> startup nomount;
ORACLE instance started.
Total System Global Area  784998400 bytes
Fixed Size                  2257352 bytes
Variable Size             499125816 bytes
Database Buffers          281018368 bytes
Redo Buffers                2596864 bytes
sys@ORCL> CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS  ARCHIVELOG
  2      MAXLOGFILES 16
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 100
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 4674
  7  LOGFILE
  8    GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log'  SIZE 50M BLOCKSIZE 512,
  9    GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/oradata/orcl/system01.dbf',
  '/u01/app/oracle/oradata/orcl/sysaux01.dbf',
  '/u01/app/oracle/oradata/orcl/undotbs01.dbf',
  '/u01/app/oracle/oradata/orcl/users01.dbf',
  '/u01/app/oracle/oradata/orcl/example01.dbf',
  '/u01/app/oracle/oradata/orcl/users02.dbf'
19  CHARACTER SET ZHS16GBK
20  ;
Control file created.

sys@ORCL> alter database create datafile '/u01/app/oracle/oradata/orcl/tbs01.dbf';
alter database create datafile '/u01/app/oracle/oradata/orcl/tbs01.dbf'
*
ERROR at line 1:
ORA-01516: nonexistent log file, data file, or temporary file "/u01/app/oracle/oradata/orcl/tbs01.dbf"
sys@ORCL> recover database;                                       
ORA-00283: 恢复会话因错误而取消                              
ORA-01244: 未命名的数据文件由介质恢复添加至控制文件          
ORA-01110: 数据文件 2: 'D:\ORACLE\ORADATA\FANGKUAI\TBS01_1DBF'

sys@ORCL> alter database create datafile 'UNNAMED00002' as 'D:\ORACLE\ORADATA\FANGKUAI\TBS01DBF';

sys@ORCL> recover database              

sys@ORCL> alter database open;
Database altered.
sys@ORCL> select * from t01;
               X
----------------
              99
[3.11.2] 数据文件丢失,无备份,控制文件损坏,有TRACE,数据库OPEN后能读到file$丢失文件的生日信息
1:创建测试数据文件
sys@ORCL> create tablespace tbs01 datafile '/u01/app/oracle/oradata/orcl/tbs01.dbf' size 10m;
Tablespace created.

sys@ORCL> select file#,status$,CRSCNBAS from  file$;

     FILE#    STATUS$   CRSCNBAS
---------- ---------- ----------
         1          2          7
         2          2       1834
         3          2     923328
         4          2      16143
         5          2     949944
         6          2    1024670
          7          2  402739672
7 rows selected.

STATUS$和CRSCNBAS
STATUS$是文件的状态:2是正常的状态,1是删除状态
CRSCNBAS:创建数据文件的SCN

每次删除数据文件并重建数据文件,会重复使用file$
sys@ORCL> drop tablespace tbs01 including contents and datafiles;

Tablespace dropped.

sys@ORCL> create tablespace tbs01 datafile '/u01/app/oracle/oradata/orcl/tbs01.dbf' size 10m;

Tablespace created.

sys@ORCL> select file#,status$,CRSCNBAS from file$;

     FILE#    STATUS$   CRSCNBAS
---------- ---------- ----------
         1          2          7
         2          2       1834
         3          2     923328
         4          2      16143
         5          2     949944
         6          2    1024670
          7          2  402740078
sys@ORCL> select substr(name,1,40) dname, recover, fuzzy, checkpoint_change#,CHECKPOINT_COUNT from v$datafile_header;

DNAME                                                                            REC FUZ CHECKPOINT_CHANGE# CHECKPOINT_COUNT
-------------------------------------------------------------------------------- --- --- ------------------ ----------------
/u01/app/oracle/oradata/orcl/system01.db                                         NO  YES          402738584              226
/u01/app/oracle/oradata/orcl/sysaux01.db                                         NO  YES          402738584              226
/u01/app/oracle/oradata/orcl/undotbs01.d                                         NO  YES          402738584              147
/u01/app/oracle/oradata/orcl/users01.dbf                                         NO  YES          402738584              225
/u01/app/oracle/oradata/orcl/example01.d                                         NO  YES          402738584              143
/u01/app/oracle/oradata/orcl/users02.dbf                                         NO  YES          402738584              120
/u01/app/oracle/oradata/orcl/tbs01.dbf                                NO  YES          402740079                2--此处表示我们使用了2次7号文件

7 rows selected.
402740078创建数据文件时的SCN做了第1次检查点,402740078第2次做检查点

sys@ORCL> alter system switch logfile;

System altered.

sys@ORCL> /

System altered.

sys@ORCL> SELECT GROUP#,ARCHIVED,FIRST_CHANGE#,SEQUENCE#,STATUS FROM V$LOG;

GROUP# ARC FIRST_CHANGE# SEQUENCE# STATUS
------ --- ------------- --------- ----------------
     1 YES     402738581         1 ACTIVE
     2 YES     402740620         2 ACTIVE
     3 NO      402740623         3 CURRENT

sys@ORCL> alter database backup controlfile to trace as '/backup/ctl.sql' reuse;
Database altered.
2:DOWN数据库,模拟损坏文件
sys@ORCL> shutdown abort;
ORACLE instance shut down.
[root@Lee orcl]# mv control0* /home/
[root@Lee orcl]# mv tbs01.dbf /home/

3:恢复数据文件
文件既然坏了,没有备份,那么需要将文件从TRACE中去除
sys@ORCL> startup nomount;
ORACLE instance started.

Total System Global Area  784998400 bytes
Fixed Size                  2257352 bytes
Variable Size             499125816 bytes
Database Buffers          281018368 bytes
Redo Buffers                2596864 bytes
CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 4674
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log'  SIZE 50M BLOCKSIZE 512,
  9    GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log'  SIZE 50M BLOCKSIZE 512,
10    GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log'  SIZE 50M BLOCKSIZE 512
11  -- STANDBY LOGFILE
12  DATAFILE
13     '/u01/app/oracle/oradata/orcl/system01.dbf',
14    '/u01/app/oracle/oradata/orcl/sysaux01.dbf',
15    '/u01/app/oracle/oradata/orcl/undotbs01.dbf',
16    '/u01/app/oracle/oradata/orcl/users01.dbf',
17    '/u01/app/oracle/oradata/orcl/example01.dbf',
18    '/u01/app/oracle/oradata/orcl/users02.dbf'

19  CHARACTER SET ZHS16GBK
20  ;

Control file created.

因为控制文件重建了,控制文件建立的时候,获取不到7号文件的开始SCN信息,所以,我们通过日志文件来写到控制文件的机会也落空了。此时无法创建数据文件,因为该数据文件信息还没在控制文件中,由于数据库是异常中断的,所以RECOVER=yes,至少要介质恢复。FUZZY=yes,因为异常关闭,数据文件不一致,要先恢复
sys@ORCL> recover database;
Media recovery complete.
sys@ORCL> alter database open;
Database altered.
现在可以打开数据库,恢复时读取在线日志,包括系统表空间需要前滚,前滚REDO到系统表空间FILE$记录了一个TBS01.DBF文件,FILE$中有7号文件,状态是2,此时控制文件却没有7号文件,打开的时候,会做数据字典检查,所以控制文件会添加一个missing00007
idle> select substr(name, 1, 55) dname, CHECKPOINT_CHANGE#,LAST_CHANGE# ,OFFLINE_CHANGE#,status from v$datafile;

DNAME                                                                                                          CHECKPOINT_CHANGE# LAST_CHANGE#
-------------------------------------------------------------------------------------------------------------- ------------------ ------------
OFFLINE_CHANGE# STATUS
--------------- -------
/u01/app/oracle/oradata/orcl/system01.dbf                                                                               402759685
              0 SYSTEM

/u01/app/oracle/oradata/orcl/sysaux01.dbf                                                                               402759685
              0 ONLINE

/u01/app/oracle/oradata/orcl/undotbs01.dbf                                                                              402759685
              0 ONLINE

/u01/app/oracle/oradata/orcl/users01.dbf                                                                                402759685
              0 ONLINE

/u01/app/oracle/oradata/orcl/example01.dbf                                                                              402759685
              0 ONLINE

/u01/app/oracle/oradata/orcl/users02.dbf                                                                                402759685
              0 ONLINE

/u01/app/oracle/product/11.2.0/db_1/dbs/ MISSING00007                                                                            0    402759740
              0 RECOVER

7 rows selected.

file$:
当你为数据库增加一个新的数据文件的时候,表FILE$中会相应的增加一条记录,而在数据库中删除一个数据文件的时候,表FILE$中并不会立即的删掉相关的记录,而是在字段STATUS$上标识为1(删除)。即使重启数据库后那些标识为1的记录也不会被删掉,但是在有新的数据文件增加后,该条记录有可能被重用,但是此时数据文件只存在file$文件中,控制文中没有该文件创建的初始信息,所以我们无法恢复
idle> alter database create datafile 'MISSING00007' as '/u01/app/oracle/oradata/orcl/TBS01.DBF';
alter database create datafile 'MISSING00007' as '/u01/app/oracle/oradata/orcl/TBS01.DBF'
*
ERROR at line 1:
ORA-01178: file 7 created before last CREATE CONTROLFILE, cannot recreate
ORA-01111: name for data file 7 is unknown - rename to correct file
ORA-01110: data file 7: '/u01/app/oracle/product/11.2.0/db_1/dbs/MISSING00007'

[3.11.3] file$文件
1:创建测试表空间
sys@ORCL> create tablespace test datafile '/u01/app/oracle/oradata/orcl/test01.dbf' size 10m;
Tablespace created.

sys@ORCL> select file#,status$,crscnbas from file$;

     FILE#    STATUS$   CRSCNBAS
---------- ---------- ----------
         1          2          7
         2          2       1834
         3          2     923328
         4          2      16143
         5          2     949944
         6          2    1024670
          7          2  402761417
sys@ORCL> create table b tablespace test as select * from dict;

Table created.
获取当前系统变更号:
sys@ORCL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER
------------------------
                402761794

sys@ORCL> drop tablespace test including contents and datafiles;

Tablespace dropped.

sys@ORCL> select file#,status$,crscnbas from file$;

     FILE#    STATUS$   CRSCNBAS
---------- ---------- ----------
         1          2          7
         2          2       1834
         3          2     923328
         4          2      16143
         5          2     949944
         6          2    1024670
          7          1  402761417












你可能感兴趣的:(Backup,&,Recovery)