[3.1]镜像恢复
背景:控制文件有镜像,数据库在运行时某个控制文件突然损坏
1:查询当前数据库控制文件:
2:移动控制文件
3:启动数据库报错
4:使用镜像副本cp
sys@ORCL> !cp /u01/app/oracle/oradata/orcl/control02.ctl /u01/app/oracle/oradata/orcl/control01.ctl
5:启动数据库
sys@ORCL> alter database mount;
sys@ORCL> alter database open;
[3.2]控制文件损坏,有二进制备份,异常关闭
1:创建一个二进制控制文件
sys@ORCL> alter database backup controlfile to '/backup/ctl.ctl' reuse;
Database altered.
2:创建一个实验表
sys@ORCL> create table t1 (x int);
Table created.
sys@ORCL> insert into t1 values(1);
1 row created.
sys@ORCL> commit;
Commit complete.
3:模拟数据文件损坏并异常关闭数据库
[root@Lee orcl]# mv control0* /home
sys@ORCL> shutdown abort;
ORACLE instance shut down.
4:启动数据库,报ORA-00205错误
5:使用二进制文件恢复控制文件
sys@ORCL> !cp /home/control01.ctl /u01/app/oracle/oradata/orcl/control01.ctl
sys@ORCL> !cp /home/control02.ctl /u01/app/oracle/oradata/orcl/control02.ctl
sys@ORCL> !cp /home/control03.ctl /u01/app/oracle/oradata/orcl/control03.ctl
sys@ORCL> startup force mount;
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.
6:查看数据文件检查点SCN
从上图可以看出控制文件最后SCN与开始SCN
不一致,数据库需要前滚到
402831521,前滚的开始SCN是:
402831071
所以我们使用
sys@ORCL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
6:恢复数据库
7:最终打开数据库:
sys@ORCL> alter database open resetlogs;
Database altered
[3.3]控制文件损坏,有二进制备份,正常关闭数据库
背景:控制文件全部丢失,有二进制备份,数据库是正常关闭的
1:备份控制文件的二进制文件:
sys@ORCL> alter database backup controlfile to '/backup/ctl.ctl' reuse;
Database altered.
2:创建测试表、正常关闭数据库:
sys@ORCL> drop table t1;
Table dropped.
sys@ORCL> create table t1(x int);
Table created.
sys@ORCL> insert into t1 values (1);
1 row created.
sys@ORCL> commit;
Commit complete.
sys@ORCL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
3:删除数据库的控制文件
[root@Lee orcl]# mv control0* /home/
4:启动数据库报错
sys@ORCL> startup;
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
ORA-00205: error in identifying control file, check alert log for more info
5:使用二进制文件恢复控制你文件
sys@ORCL> !cp /backup/ctl.ctl /u01/app/oracle/oradata/orcl/control01.ctl
sys@ORCL> !cp /backup/ctl.ctl /u01/app/oracle/oradata/orcl/control02.ctl
sys@ORCL> !cp /backup/ctl.ctl /u01/app/oracle/oradata/orcl/control03.ctl
6:尝试mount数据库
sys@ORCL> alter database moount;
alter database moount
*
ERROR at line 1:
ORA-02231: missing or invalid option to ALTER DATABASE
上面报错,主要原因如下:
开始SCN>检查点SCN,数据库需要前滚,前滚的起点为老的控制文件号:
8:执行前滚
9:打开数据库
sys@ORCL> alter database open resetlogs;
Database altered.
sys@ORCL> select * from t1;
X
----------
1
[3.4]有trace的备份,正常关机
背景:控制文件丢失,有TRACE备份
1:生成控制文件备份文件
sys@ORCL> alter database backup controlfile to trace as '/backup/ctl.sql' reuse;
Database altered.
2:创建测试表
sys@ORCL> truncate table t1;
Table truncated.
sys@ORCL> insert into t1 values(1);
1 row created.
sys@ORCL> commit;
Commit complete.
3:正常关闭数据库、移动控制文件
sys@ORCL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[root@Lee orcl]# mv control0* /home
4:启动数据库报错
sys@ORCL> startup;
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
ORA-00205: error in identifying control file, check alert log for more info
5:使用trace文件新建数据库
sys@ORCL> CREATE CONTROLFILE REUSE DATABASE "ORCL"
NORESETLOGS 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;
Control file created.
此处选择
NORESETLOGS创建的控制文件,则此时将控制文件、数据文件、日志文件作为当前状态,他会读取当前控制文件指定的物理结构的文件上读取文件头,来构建控制文件
开始SCN跟结束SCN和datafile checkpoint SCN 都相等,都是当前
6:直接打开数据库
sys@ORCL> alter database open;
Database altered.
sys@ORCL> select * from t1;
X
----------
1
[3.5]有trace noresetlogs的备份,异常关机
1:生成trace备份
sys@ORCL> alter database backup controlfile to trace as '/backup/ctl.sql' reuse noresetlogs;
Database altered.
2:创建测试表并切换归档
sys@ORCL> truncate table t1;
Table truncated.
sys@ORCL> insert into t1 values(1);
1 row created.
sys@ORCL> commit ;
Commit complete.
sys@ORCL> alter system switch logfile;
System altered.
sys@ORCL> /
System altered.
3:异常关闭数据库,并启动数据库报错
sys@ORCL> shutdown abort;
ORACLE instance shut down.
sys@ORCL> startup;
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
ORA-00205: error in identifying control file, check alert log for more info
4:使用trace备份生成控制文件
CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS 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,
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
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;
Control file created.
5:查看数据文件头
6:恢复数据库,并打开数据库
sys@ORCL> recover database;
Media recovery complete.
sys@ORCL> alter database open;
Database altered.
sys@ORCL> select * from t1;
X
----------
1
[3.6]trace 控制文件RESETLOGS方式创建,非活动在线日志损坏,并异常关闭
背景:控制文件全部丢失,但是有TRACE文件,非活动的在线日志损坏,异常关机
1:生成trace文件
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 redo01.log /home/
[root@Lee orcl]# mv redo03.log /home/
3:异常关闭数据库并启动数据库报错
sys@ORCL> shutdown abort;
ORACLE instance shut down.
sys@ORCL> startup;
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
ORA-00205: error in identifying control file, check alert log for more info
4:创建控制文件
sys@ORCL> CREATE CONTROLFILE REUSE DATABASE "ORCL"
NORESETLOGS 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;
ERROR:
ORA-06550: line 1, column 29:
PLS-00553: character set name is not recognized
ORA-06550: line 0, column 0:
PL/SQL: Compilation unit analysis terminated
此处我们使用
NORESETLOGS创建数据库报错,原因是NORESETLOGS来创建控制文件时会读取在线日志头,所以使用resetlogs来创建
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.
5:此时我们尝试打开数据库
sys@ORCL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/system01.dbf'
提示需要进行数据库恢复
打开数据库
sys@ORCL> alter database open resetlogs;
Database altered.
sys@ORCL> select * from t1;
X
----------
1