45.生产中如何恢复丢失的数据

1.执行数据库恢复

操作系统环境:
Red Hat Enterprise Linux Server release 7.7 (Maipo)
数据库环境:
Version 19.3.0.0.0
查看控制文件位置:
[oracle@enmotech ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on 星期六 5月 30 18:20:17 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
连接到: 
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SYS@orcl> show parameter control_files;
NAME	            TYPE	                 VALUE
---------------- ----------- ------------------------------
control_files		string	                 /u02/oradata/ORCL/control01.ctl, /u01/app/oracle/fast_recovery_area/ORCL/control02.ctl

一、针对不同的恢复方法给出具体的恢复思路:

1.1、通过重新拷贝冗余的控制文件

注意
1.具有多路控制文件镜像
2.其他冗余控制文件没有损坏

模拟:控制文件control01.ctl损坏

恢复
1、在线或者关闭数据库后损坏了其中部分控制文件;
2、shutdown abort关闭数据库;
3、拷贝其中一个完好的控制文件;
4、startup启动数据库。

操作步骤如下

1.模拟损坏控制文件

[oracle@enmotech ~]$ cat /dev/null > /u02/oradata/ORCL/control01.ctl

2.恢复控制文件

[oracle@enmotech ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on 星期六 5月 30 18:29:26 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
已连接到空闲例程。
SYS@orcl> startup
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
ORA-00205: ?????????, ??????, ???????
SYS@orcl> 

3.查看告警日志

[oracle@enmotech ~]$ [oracle@enmotech trace]$ tail -f /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log
ORA-205 signalled during: ALTER DATABASE   MOUNT...
2020-05-30T18:29:46.046678+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_mz00_6233.trc:
ORA-00202: ????: ''/u02/oradata/ORCL/control01.ctl''
ORA-27048: skgfifi: ????????
Additional information: 2
Checker run found 1 new persistent data failures

4.恢复控制文件

[oracle@enmotech trace]$ cd /u02/oradata/ORCL/
[oracle@enmotech ORCL]$ mv control01.ctl control01.ctl20200530error
[oracle@enmotech ORCL]$ cp /u01/app/oracle/fast_recovery_area/ORCL/control02.ctl ./control01.ctl

5.打开数据库

SYS@orcl> startup
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
数据库已经打开。

1.2、 通过备份控制文件进行完全恢复

注意:
1.备份了控制文件
2.备份了控制文件之后有连续的归档文件和redo文件

1、在线或者关闭数据库后损坏了所有控制文件;
2、shutdown abort关闭数据库;
3、startup nomount启动数据库;
4、restore controlfile from ‘xxx’;从备份中还原控制文件;
5、alter database mount;
5、recover database using backup controlfile until cancel,在执行时选择auto自动应用所有的归档文件;
6、再次执行recover database using backup controlfile until cancel,选择应用未归档的redo文件;
7、alter database open resetlogs;

模拟:控制文件control01.ctl,control02.ctl损坏

1.备份控制文件

[oracle@enmotech ~]$ mkdir -p /home/oracle/rmanbak/ctlbak/
[oracle@enmotech ~]$ rman target /
RMAN> backup current controlfile tag='ctl_bak' format='/home/oracle/rmanbak/ctlbak/ctl_%d_%T_%s_%p.bkp';
从位于 30-5月 -20 的 backup 开始
使用通道 ORA_DISK_1
通道 ORA_DISK_1: 正在启动全部数据文件备份集
通道 ORA_DISK_1: 正在指定备份集内的数据文件
备份集内包括当前控制文件
通道 ORA_DISK_1: 正于 30-5月 -20 启动段 1
通道 ORA_DISK_1: 完成了于 30-5月 -20 启动段 1
片段句柄 = /home/oracle/rmanbak/ctlbak/ctl_ORCL_20200530_5_1.bkp 标记 = CTL_BAK 注释 = NONE
通道 ORA_DISK_1: 备份集完成, 用时: 00:00:01
在 30-5月 -20 完成了 backup
从位于 30-5月 -20 的 Control File and SPFILE Autobackup 开始
片段句柄 = /u01/app/oracle/fast_recovery_area/ORCL/autobackup/2020_05_30/o1_mf_s_1041792645_hf4gn5yv_.bkp 注释 = NONE
在 30-5月 -20 完成了 Control File and SPFILE Autobackup

2.破坏控制文件control01.ctl,control02.ctl

[oracle@enmotech ~]$ cat /dev/null > /u02/oradata/ORCL/control01.ctl
[oracle@enmotech ~]$ cat /dev/null > /u01/app/oracle/fast_recovery_area/ORCL/control02.ctl 

3.关闭数据库

SYS@orcl> shutdown abort;
ORA-24324: 未初始化服务句柄
ORA-01041: 内部错误, hostdef 扩展名不存在

4.启动数据库到nomount状态

[oracle@enmotech ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on 星期六 5月 30 18:57:26 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
已连接到空闲例程。
SYS@orcl> startup nomount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
SYS@orcl> 

5.从备份中还原控制文件

[oracle@enmotech ~]$ rman target /
恢复管理器: Release 19.0.0.0.0 - Production on 星期六 5月 30 18:59:46 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
已连接到目标数据库: ORCL (未装载)
RMAN> restore controlfile from '/home/oracle/rmanbak/ctlbak/ctl_ORCL_20200530_5_1.bkp';
从位于 30-5月 -20 的 restore 开始
使用目标数据库控制文件替代恢复目录
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: SID=256 设备类型=DISK
通道 ORA_DISK_1: 正在还原控制文件
通道 ORA_DISK_1: 还原完成, 用时: 00:00:01
输出文件名=/u02/oradata/ORCL/control01.ctl
输出文件名=/u01/app/oracle/fast_recovery_area/ORCL/control02.ctl
在 30-5月 -20 完成了 restore

6.启动到mount状态

6.1在执行时选择auto自动应用所有的归档文件(可以从日志的读取修改时间判断,哪个是当前日志)

SYS@orcl> recover database using backup controlfile until cancel;
ORA-00279: ?? 3329195 (? 05/30/2020 18:34:48 ??) ???? 1 ????
ORA-00289: ??: /u02/oradata/orcl_arch_log/1_21_1040302643.arc
ORA-00280: ?? 3329195 (???? 1) ??? #21 ?
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: ������������������������ '/u02/oradata/orcl_arch_log/1_21_1040302643.arc' ORA-27037: ������������������������
Linux-x86_64
Error: 2: No such file or directory
Additional information: 7
ORA-00308: ������������������������ '/u02/oradata/orcl_arch_log/1_21_1040302643.arc' ORA-27037: ������������������������
Linux-x86_64
Error: 2: No such file or directory
Additional information: 7
ORA-01547: ������: RECOVER ��������� OPEN RESETLOGS ��������������������� ORA-01194: ������ 1 ���������������������������������������
ORA-01110:
������������ 1: '/u02/oradata/ORCL/system01.dbf'
6.2选择应用未归档的redo文件;(可以从日志的读取修改时间判断,哪个是当前日志)
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
/u02/oradata/ORCL/redo03.log
已应用的日志。
完成介质恢复。
7.重储打开数据库
SYS@orcl> alter database open resetlogs;
数据库已更改。

1.3、通过备份控制文件进行不完全恢复

注意:
1.备份了控制文件
2.备份了控制文件之后的归档文件或者redo文件不连续

1、在线或者关闭数据库后损坏了所有控制文件;
2、shutdown abort关闭数据库;
3、startup nomount启动数据库;
4、restore controlfile from ‘xxx’;从备份中还原控制文件;
5、alter database mount;
6、recover database using backup controlfile until cancel,在执行时选择auto自动应用尽可能多的归档文件;
7、alter database open resetlogs;

模拟
1.利用1.2环境中已经备份的控制文件
2.切换当前的redo日志,产生归档。

SYS@orcl> select group#, sequence#,status from v$log;
    GROUP#  SEQUENCE# STATUS
---------- ---------- ----------------
	 1	    1 CURRENT
	 2	    0 UNUSED
	 3	    0 UNUSED
SYS@orcl> alter system switch logfile;
系统已更改。
SYS@orcl> /
系统已更改。
SYS@orcl> /
系统已更改。
SYS@orcl> /
系统已更改。
SYS@orcl> /
系统已更改。
SYS@orcl> select group#, sequence#,status from v$log;
    GROUP#  SEQUENCE# STATUS
---------- ---------- ----------------
	 1	    4 INACTIVE
	 2	    5 INACTIVE
	 3	    6 CURRENT
[oracle@enmotech orcl_arch_log]$ ll
总用量 5684
-rw-r----- 1 oracle oinstall 5785088 5月  30 19:23 1_1_1041793920.arc
-rw-r----- 1 oracle oinstall    1024 5月  30 19:23 1_2_1041793920.arc
-rw-r----- 1 oracle oinstall   18944 5月  30 19:23 1_3_1041793920.arc
-rw-r----- 1 oracle oinstall    1024 5月  30 19:23 1_4_1041793920.arc
-rw-r----- 1 oracle oinstall    1024 5月  30 19:23 1_5_1041793920.arc
3.删除1_3_1041793920.arc归档文件
[oracle@enmotech ~]$ rman target /
恢复管理器: Release 19.0.0.0.0 - Production on 星期六 5月 30 19:29:31 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
已连接到目标数据库: ORCL (DBID=1568083377)
RMAN> delete archivelog sequence 3 thread 1;
释放的通道: ORA_DISK_1
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: SID=44 设备类型=DISK
db_unique_name 为 ORCL 的数据库的归档日志副本列表
=====================================================================
关键字     线程序列     S 时间下限
------- ---- ------- - ----------
18      1    3       A 30-5月 -20
        名称: /u02/oradata/orcl_arch_log/1_3_1041793920.arc
是否确定要删除以上对象 (输入 YES 或 NO)? yes
已删除的归档日志
归档日志文件名 = /u02/oradata/orcl_arch_log/1_3_1041793920.arc RECID=18 STAMP=1041794632
1 对象已删除
[oracle@enmotech orcl_arch_log]$ ll
总用量 5664
-rw-r----- 1 oracle oinstall 5785088 5月  30 19:23 1_1_1041793920.arc
-rw-r----- 1 oracle oinstall    1024 5月  30 19:23 1_2_1041793920.arc
-rw-r----- 1 oracle oinstall    1024 5月  30 19:23 1_4_1041793920.arc
-rw-r----- 1 oracle oinstall    1024 5月  30 19:23 1_5_1041793920.arc

4.破坏控制文件control01.ctl,control02.ctl

[oracle@enmotech ~]$ cat /dev/null > /u02/oradata/ORCL/control01.ctl
[oracle@enmotech ~]$ cat /dev/null > /u01/app/oracle/fast_recovery_area/ORCL/control02.ctl 

5.关闭数据库

SYS@orcl> shutdown abort;
ORA-24324: 未初始化服务句柄
ORA-01041: 内部错误, hostdef 扩展名不存在
SYS@orcl> quit

6.启动数据库到nomount状态

[oracle@enmotech ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on 星期六 5月 30 19:39:55 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
已连接到空闲例程。
SYS@orcl> startup nomount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes

7.从备份中还原控制文件

[oracle@enmotech ~]$ rman target /
恢复管理器: Release 19.0.0.0.0 - Production on 星期六 5月 30 19:43:07 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
已连接到目标数据库: ORCL (未装载)
RMAN> restore controlfile from '/home/oracle/rmanbak/ctlbak/ctl_ORCL_20200530_5_1.bkp';
从位于 30-5月 -20 的 restore 开始
使用目标数据库控制文件替代恢复目录
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: SID=256 设备类型=DISK
通道 ORA_DISK_1: 正在还原控制文件
通道 ORA_DISK_1: 还原完成, 用时: 00:00:01
输出文件名=/u02/oradata/ORCL/control01.ctl
输出文件名=/u01/app/oracle/fast_recovery_area/ORCL/control02.ctl
在 30-5月 -20 完成了 restore

8,启动到mount状态,

SYS@orcl> alter database mount;
数据库已更改。
SYS@orcl> recover database using backup controlfile until cancel;
ORA-00283: 恢复会话因错误而取消 ORA-19909:
数据文件 1 属于孤立的原型 ORA-01110:
数据文件 1: '/u02/oradata/ORCL/system01.dbf'

9.查看控制文件和数据文件的scn号

SYS@orcl> select file#,name,checkpoint_change# from v$datafile_header;
     FILE# NAME 						      CHECKPOINT_CHANGE#
---------- ---------------------------------------------------------- ------------------
	 1 /u02/oradata/ORCL/system01.dbf					 3334516
	 3 /u02/oradata/ORCL/sysaux01.dbf					 3334516
	 4 /u02/oradata/ORCL/undotbs01.dbf					 3334516
	 5 /u02/oradata/ORCL/pdbseed/system01.dbf				 2149302
	 6 /u02/oradata/ORCL/pdbseed/sysaux01.dbf				 2149302
	 7 /u02/oradata/ORCL/users01.dbf					 3334516
	 8 /u02/oradata/ORCL/pdbseed/undotbs01.dbf				 2149302
	 9 /u02/oradata/ORCL/orclpdb/system01.dbf				 3334516
	10 /u02/oradata/ORCL/orclpdb/sysaux01.dbf				 3334516
	11 /u02/oradata/ORCL/orclpdb/undotbs01.dbf				 3334516
	12 /u02/oradata/ORCL/orclpdb/users01.dbf				 3334516
	13 /u02/oradata/ORCL/orclpdb/lob_data01.dbf				 3334516
已选择 12 行。
SYS@orcl> select file#,name,checkpoint_change#,last_change# from v$datafile
  2  ;
     FILE# NAME 						      CHECKPOINT_CHANGE# LAST_CHANGE#
---------- ---------------------------------------------------------- ------------------ ------------
	 1 /u02/oradata/ORCL/system01.dbf					 3329195
	 3 /u02/oradata/ORCL/sysaux01.dbf					 3329195
	 4 /u02/oradata/ORCL/undotbs01.dbf					 3329195
	 5 /u02/oradata/ORCL/pdbseed/system01.dbf				 2149302
	 6 /u02/oradata/ORCL/pdbseed/sysaux01.dbf				 2149302
	 7 /u02/oradata/ORCL/users01.dbf					 3329195
	 8 /u02/oradata/ORCL/pdbseed/undotbs01.dbf				 2149302
	 9 /u02/oradata/ORCL/orclpdb/system01.dbf				 3329195
	10 /u02/oradata/ORCL/orclpdb/sysaux01.dbf				 3329195
	11 /u02/oradata/ORCL/orclpdb/undotbs01.dbf				 3329195
	12 /u02/oradata/ORCL/orclpdb/users01.dbf				 3329195
	13 /u02/oradata/ORCL/orclpdb/lob_data01.dbf				 3329195
已选择 12 行。

10.发现scn号不一致。

11.加入隐含参数,打开数据库

SYS@orcl> alter system set "_allow_resetlogs_corruption"=true scope=spfile;
系统已更改。
SYS@orcl> shu immediate;
ORA-01109: 数据库未打开
已经卸载数据库。
ORACLE 例程已经关闭。

12.重新启动数据库到mount状态

SYS@orcl> startup mount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
SYS@orcl> select file#,name,checkpoint_change#,last_change# from v$datafile;
     FILE# NAME 						      CHECKPOINT_CHANGE# LAST_CHANGE#
---------- ---------------------------------------------------------- ------------------ ------------
	 1 /u02/oradata/ORCL/system01.dbf					 3329195
	 3 /u02/oradata/ORCL/sysaux01.dbf					 3329195
	 4 /u02/oradata/ORCL/undotbs01.dbf					 3329195
	 5 /u02/oradata/ORCL/pdbseed/system01.dbf				 2149302
	 6 /u02/oradata/ORCL/pdbseed/sysaux01.dbf				 2149302
	 7 /u02/oradata/ORCL/users01.dbf					 3329195
	 8 /u02/oradata/ORCL/pdbseed/undotbs01.dbf				 2149302
	 9 /u02/oradata/ORCL/orclpdb/system01.dbf			 3329195
	10 /u02/oradata/ORCL/orclpdb/sysaux01.dbf			 3329195
	11 /u02/oradata/ORCL/orclpdb/undotbs01.dbf			 3329195
	12 /u02/oradata/ORCL/orclpdb/users01.dbf			 3329195
	13 /u02/oradata/ORCL/orclpdb/lob_data01.dbf			 3329195
已选择 12 行。
SYS@orcl> select file#,name,checkpoint_change# from v$datafile_header;
     FILE# NAME 						      CHECKPOINT_CHANGE#
---------- ---------------------------------------------------------- ------------------
	 1 /u02/oradata/ORCL/system01.dbf					 3334516
	 3 /u02/oradata/ORCL/sysaux01.dbf					 3334516
	 4 /u02/oradata/ORCL/undotbs01.dbf					 3334516
	 5 /u02/oradata/ORCL/pdbseed/system01.dbf				 2149302
	 6 /u02/oradata/ORCL/pdbseed/sysaux01.dbf				 2149302
	 7 /u02/oradata/ORCL/users01.dbf					 3334516
	 8 /u02/oradata/ORCL/pdbseed/undotbs01.dbf				 2149302
	 9 /u02/oradata/ORCL/orclpdb/system01.dbf			 3334516
	10 /u02/oradata/ORCL/orclpdb/sysaux01.dbf			 3334516
	11 /u02/oradata/ORCL/orclpdb/undotbs01.dbf			 3334516
	12 /u02/oradata/ORCL/orclpdb/users01.dbf			 3334516
	13 /u02/oradata/ORCL/orclpdb/lob_data01.dbf			 3334516
已选择 12 行。
SYS@orcl> alter database open resetlogs;
alter database open resetlogs
*
第 1 行出现错误:
ORA-00603: ORACLE server session terminated by fatal error
ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-00600: internal error code, arguments: [kcbzib_kcrsds_1], [], [], [], [], [], [], [], [], [], [], []
进程 ID: 13925
会话 ID: 237 序列号: 40956
SYS@orcl> show parameter undo;
ERROR:
ORA-03114: 未连接到 ORACLE
SYS@orcl> quit
从 Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0 断开
[oracle@enmotech ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on 星期六 5月 30 20:21:03 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
已连接到空闲例程。

13.重建undo

SYS@orcl> startup mount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
SYS@orcl> show parameter undo;
NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
temp_undo_enabled		     boolean	 FALSE
undo_management 		     string	 AUTO
undo_retention			     integer	 900
undo_tablespace 		     string	 UNDOTBS1
SYS@orcl> alter system set undo_management=manual scope=spfile;
系统已更改。
SYS@orcl> alter system set undo_tablespace=system scope=spfile;
系统已更改。
SYS@orcl> shu immediate;
ORA-01109: 数据库未打开
已经卸载数据库。
ORACLE 例程已经关闭。
SYS@orcl> startup mount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
SYS@orcl> alter database open ;
数据库已更改。
SYS@orcl> r
  1* select file#,name,checkpoint_change# from v$datafile_header
     FILE# NAME 						      CHECKPOINT_CHANGE#
---------- ---------------------------------------------------------- ------------------
	 1 /u02/oradata/ORCL/system01.dbf					 3431933
	 3 /u02/oradata/ORCL/sysaux01.dbf					 3431933
	 4 /u02/oradata/ORCL/undotbs01.dbf					 3431933
	 5 /u02/oradata/ORCL/pdbseed/system01.dbf				 2149302
	 6 /u02/oradata/ORCL/pdbseed/sysaux01.dbf				 2149302
	 7 /u02/oradata/ORCL/users01.dbf					 3431933
	 8 /u02/oradata/ORCL/pdbseed/undotbs01.dbf				 2149302
	 9 /u02/oradata/ORCL/orclpdb/system01.dbf			 3431933
	10 /u02/oradata/ORCL/orclpdb/sysaux01.dbf			 3431933
	11 /u02/oradata/ORCL/orclpdb/undotbs01.dbf			 3431933
	12 /u02/oradata/ORCL/orclpdb/users01.dbf			 3431933
	13 /u02/oradata/ORCL/orclpdb/lob_data01.dbf			 3431933
已选择 12 行。
SYS@orcl> select file#,name,checkpoint_change#,last_change# from v$datafile;
     FILE# NAME 						      CHECKPOINT_CHANGE# LAST_CHANGE#
---------- ---------------------------------------------------------- ------------------ ------------
	 1 /u02/oradata/ORCL/system01.dbf					 3431933
	 3 /u02/oradata/ORCL/sysaux01.dbf					 3431933
	 4 /u02/oradata/ORCL/undotbs01.dbf					 3431933
	 5 /u02/oradata/ORCL/pdbseed/system01.dbf				 2149302      2149302
	 6 /u02/oradata/ORCL/pdbseed/sysaux01.dbf				 2149302      2149302
	 7 /u02/oradata/ORCL/users01.dbf					 3431933
	 8 /u02/oradata/ORCL/pdbseed/undotbs01.dbf				 2149302      2149302
	 9 /u02/oradata/ORCL/orclpdb/system01.dbf			 3431933
	10 /u02/oradata/ORCL/orclpdb/sysaux01.dbf			 3431933
	11 /u02/oradata/ORCL/orclpdb/undotbs01.dbf			 3431933
	12 /u02/oradata/ORCL/orclpdb/users01.dbf			 3431933
	13 /u02/oradata/ORCL/orclpdb/lob_data01.dbf			 3431933
已选择 12 行。
SYS@orcl> create undo tablespace undotbs2 datafile '/u02/oradata/ORCL/undotbs02.dbf' size 1024M autoextend on next 50m maxsize unlimited;
表空间已创建。
SYS@orcl> alter system set undo_tablespace=undotbs2 scope=spfile;
系统已更改。
SYS@orcl> alter system set undo_management=auto scope=spfile;
系统已更改。
SYS@orcl> drop tablespace undotbs1 including contents and datafiles cascade constraint;
表空间已删除。
SYS@orcl> shu immediate;
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SYS@orcl> startup 
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
数据库已经打开。
SYS@orcl> show parameter undo;
NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
temp_undo_enabled		     boolean	 FALSE
undo_management 		     string	 AUTO
undo_retention			     integer	 900
undo_tablespace 		     string	 UNDOTBS2

14.如果允许的话,导出数据库,重建实例。如果数据量过大的话,还原隐含参数

alter system set "_allow_resetlogs_corruption"=false scope=spfile;

1.4、通过备份控制文件进行重建的恢复(noresetlogs方式)

1.备份了控制文件

2.redo文件无丢失或者无损坏

1、在线或者关闭数据库后损坏了所有控制文件;
2、shutdown abort关闭数据库;
3、startup nomount启动数据库;
4、restore controlfile from ‘xxx’;从备份中还原控制文件;
5、alter database mount;
6、alter database backup controlfile to trace,生成创建控制文件的脚本;
7、shutdown immediate并启动到startup nomount状态;
8、使用noresetlogs方式创建控制文件;
9、recover database恢复数据库;
10、恢复完后通过alter database open打开数据库;

1.1利用1.2环境中已经备份的控制文件

1.2模拟损坏的控制文件

[oracle@enmotech ~]$  cat /dev/null > /u02/oradata/ORCL/control01.ctl
[oracle@enmotech ~]$  cat /dev/null > /u01/app/oracle/fast_recovery_area/ORCL/control02.ctl

2.关闭数据库

SYS@orcl> shutdown abort;

3.启动到nomount状态,

SYS@orcl> startup nomount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		 1023410176 bytes
Database Buffers	  503316480 bytes
Redo Buffers		    7639040 bytes

4重储控制文件

[oracle@enmotech ~]$ rman target /
恢复管理器: Release 19.0.0.0.0 - Production on 星期六 5月 30 22:26:50 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
已连接到目标数据库: ORCL (未装载)
RMAN> restore controlfile from '/home/oracle/rmanbak/ctlbak/ctl_ORCL_20200530_1_1.bkp';
从位于 30-5月 -20 的 restore 开始
使用目标数据库控制文件替代恢复目录
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: SID=257 设备类型=DISK
通道 ORA_DISK_1: 正在还原控制文件
通道 ORA_DISK_1: 还原完成, 用时: 00:00:01
输出文件名=/u02/oradata/ORCL/control01.ctl
输出文件名=/u01/app/oracle/fast_recovery_area/ORCL/control02.ctl
在 30-5月 -20 完成了 restore

5.启动到mount状态,

SYS@orcl> alter database mount;
数据库已更改。

6.生成控制文件脚本

数据库已更改。
SYS@orcl> alter database backup controlfile to trace as '/home/oracle/controlfile.txt';

7.关闭数据库,并启动到nomount状态

SYS@orcl> shu immediate;
ORA-01109: ??????
已经卸载数据库。
ORACLE 例程已经关闭。
SYS@orcl> startup nomount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		 1023410176 bytes
Database Buffers	  503316480 bytes
Redo Buffers		    7639040 bytes

8.重建控制文件

CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 1024
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u02/oradata/ORCL/redo01.log'  SIZE 200M BLOCKSIZE 512,
  GROUP 2 '/u02/oradata/ORCL/redo02.log'  SIZE 200M BLOCKSIZE 512,
  GROUP 3 '/u02/oradata/ORCL/redo03.log'  SIZE 200M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/u02/oradata/ORCL/system01.dbf',
  '/u02/oradata/ORCL/sysaux01.dbf',
  '/u02/oradata/ORCL/undotbs01.dbf',
  '/u02/oradata/ORCL/pdbseed/system01.dbf',
  '/u02/oradata/ORCL/pdbseed/sysaux01.dbf',
  '/u02/oradata/ORCL/users01.dbf',
  '/u02/oradata/ORCL/pdbseed/undotbs01.dbf',
  '/u02/oradata/ORCL/orclpdb/system01.dbf',
  '/u02/oradata/ORCL/orclpdb/sysaux01.dbf',
  '/u02/oradata/ORCL/orclpdb/undotbs01.dbf',
  '/u02/oradata/ORCL/orclpdb/users01.dbf'
CHARACTER SET AL32UTF8
;
控制文件已创建。

9.恢复数据库

SYS@orcl> RECOVER DATABASE;
完成介质恢复。
SYS@orcl> ALTER SYSTEM ARCHIVE LOG ALL;
系统已更改。

10.打开数据库

SYS@orcl> ALTER DATABASE OPEN;
数据库已更改。

11.打开插件数据库

SYS@orcl> ALTER PLUGGABLE DATABASE ALL OPEN;
插接式数据库已变更。

12.添加临时表空间

SYS@orcl> ALTER TABLESPACE TEMP ADD TEMPFILE '/u02/oradata/ORCL/temp01.dbf' REUSE;
表空间已更改。
SYS@orcl> ALTER SESSION SET CONTAINER = "PDB$SEED";
会话已更改。
SYS@orcl> ALTER TABLESPACE TEMP ADD TEMPFILE '/u02/oradata/ORCL/pdbseed/temp012020-05-13_13-16-23-969-PM.dbf' REUSE;
表空间已更改。
ALTER SESSION SET CONTAINER = "ORCLPDB";
ALTER TABLESPACE TEMP ADD TEMPFILE '/u02/oradata/ORCL/orclpdb/temp01.dbf' REUSE;
会话已更改。
SYS@orcl> 
表空间已更改。
SYS@orcl> ALTER SESSION SET CONTAINER = "CDB$ROOT";
会话已更改。

1.5、通过备份控制文件进行重建的恢复(resetlogs方式)

注意:

1.备份了控制文件

2.redo文件丢失或者损坏

1、在线或者关闭数据库后损坏了所有控制文件;
2、shutdown abort关闭数据库;
3、startup nomount启动数据库;
4、restore controlfile from ‘xxx’;从备份中还原控制文件;
5、alter database mount;
6、alter database backup controlfile to trace,生成创建控制文件的脚本;
7、shutdown immediate并启动到startup nomount状态
8、使用resetlogs方式创建控制文件;
9、如果未归档的redo文件可用时,则直接recover database,然后选用未归档的redo文件应用,
最后通过alter database open resetlogs方式打开数据库。
10、如果未归档的redo文件不可用时,则需要设置隐含参数_allow_resetlogs_corruption为true跳
过一致性检查,最后用alter database open resetlogs方式打开数据库。
注:打开数据库后很多情况下会出现需要推进scn的问题。

1.6、通过手工重建的控制文件进行恢复(noresetlogs方式)

注意
1.无可用的控制文件备份
2.redo文件无丢失和损坏

1、在线或者关闭数据库后损坏了所有控制文件;
2、shutdown abort关闭数据库;
3、startup nomount启动数据库;
4、构造控制文件;
下面的步骤参考1.4的第八步;

1.7、通过手工重建的控制文件进行恢复(resetlogs方式)

注意:
1.无可用的控制文件备份
2.redo文件丢失或者损坏

1、在线或者关闭数据库后损坏了所有控制文件;
2、shutdown abort关闭数据库;
3、startup nomount启动数据库;
4、构造控制文件;

2.执行数据库恢复案例

[oracle@enmotech ~]$ cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.7 (Maipo)
数据库版本
[oracle@enmotech ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on 星期日 5月 31 10:23:55 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
连接到: 
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

redo0日志的状态 列有四种状态:
current: 当前日志组对应的脏块还没有全部从 data buffer 写入到 data file,含有实例恢复需要的信息,不能被覆盖
active: 日志组对应的脏块还没有完全从 data buffer 写入到 data file,含有实例恢复需要的信息,不能被覆盖
inactive; 日志组对应的脏块已经从 data buffer 写入到 data file,可以覆盖
unused: 新添加的日志组,还没有使用


redo文件损坏涉及到多种多样场景,具体场景可以分四大部分:
1、按照redo的状态可以分为current、active和inactive;
2、按照数据库归档模式可以分为归档和非归档;
3、按照脏块有没写入数据文件可以分为需要和不需要;
4、按照损坏时数据库的状态可以分为在线和关闭;
现在主要通过三部分来介绍redo文件恢复相关的内容:


1、current redo文件恢复介绍:
1.1 
a、current redo文件损坏;
b、数据库归档模式;
c、不需要写入数据文件
d、实例正常关闭后损坏

场景模拟;
1.查看当前日志状态
SYS@orcl> col member for a30;
SYS@orcl> select l.group#, l.sequence#, lf.member, l.bytes/1024/1024 M, l.archived, l.status from v$log l, v$logfile lf where l.group#=lf.group#;
    GROUP#  SEQUENCE# MEMBER						M ARC STATUS
---------- ---------- ---------------------------------------- ---------- --- ----------------
	 3	   18 /u02/oradata/ORCL/redo03.log		      200 NO  CURRENT
	 2	   17 /u02/oradata/ORCL/redo02.log		      200 YES INACTIVE
	 1	   16 /u02/oradata/ORCL/redo01.log		      200 YES INACTIVE
2.关闭数据库,模拟current redolog损坏
[oracle@enmotech ORCL]$ echo 1 >> /u02/oradata/ORCL/redo03.log
3.打开数据库
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
ORA-03113: 通信通道的文件结尾 进程 ID:
3845
会话 ID: 237 序列号: 62252
4.观察alter_sid.log报错
2020-05-31T11:05:52.415611+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_lgwr_3804.trc:
ORA-00313: ??????? 3 (???? 1) ???
ORA-00312: ???? 3 ?? 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: ??????????????
Additional information: 1
2020-05-31T11:05:52.415707+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_lgwr_3804.trc:
ORA-00313: ??????? 3 (???? 1) ???
ORA-00312: ???? 3 ?? 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: ??????????????
Additional information: 1
2020-05-31T11:05:52.416332+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_3845.trc:
ORA-00313: 无法打开日志组 1 (用于线程 ) 的成员
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
USER (ospid: ): terminating the instance due to ORA error 
2020-05-31T11:05:52.533550+08:00
System state dump requested by (instance=1, osid=3845), summary=[abnormal instance termination].
System State dumped to trace file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_diag_3786.trc
2020-05-31T11:05:52.641053+08:00
Dumping diagnostic data in directory=[cdmp_20200531110552], requested by (instance=1, osid=3845), summary=[abnormal instance termination].
5.重新连接数据库,清除当前日志组数据
SYS@orcl> alter database clear unarchived logfile group 3;
数据库已更改。
6.打开数据库
SYS@orcl> alter database open;
数据库已更改。


1.2
a、current redo文件损坏;
b、数据库非归档模式;
c、不需要写入数据文件
d、实例正常关闭后损坏

场景模拟:
1.常看数据库归档状态和当前日志组
SYS@orcl> archive log list;
数据库日志模式             非存档模式
自动存档             禁用
存档终点            /u02/oradata/orcl_arch_log
最早的联机日志序列     17
当前日志序列           19
SYS@orcl> col member for a40;
SYS@orcl> select l.group#, l.sequence#, lf.member, l.bytes/1024/1024 M, l.archived, l.status from v$log l, v$logfile lf where l.group#=lf.group#;
    GROUP#  SEQUENCE# MEMBER						M ARC STATUS
---------- ---------- ---------------------------------------- ---------- --- ----------------
	 3	    0 /u02/oradata/ORCL/redo03.log		      200 YES UNUSED
	 2	   17 /u02/oradata/ORCL/redo02.log		      200 YES INACTIVE
	 1	   19 /u02/oradata/ORCL/redo01.log		      200 NO  CURRENT
2.关闭数据库,模拟current redolog损坏
SYS@orcl> shu immediate;
数据库已经关闭。
已经卸载数据库。
[oracle@enmotech ORCL]$ echo 1 >> /u02/oradata/ORCL/redo01.log
3.打开数据库
SYS@orcl> startup 
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
ORA-03113: 通信通道的文件结尾 进程 ID:
5619
会话 ID: 237 序列号: 61537
4.观察alter_sid.log报错
2020-05-31T11:23:05.637817+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_lgwr_5575.trc:
ORA-00313: ??????? 1 (???? 1) ???
ORA-00312: ???? 1 ?? 1: '/u02/oradata/ORCL/redo01.log'
ORA-27046: ??????????????
Additional information: 1
2020-05-31T11:23:05.638267+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_lgwr_5575.trc:
ORA-00313: ??????? 1 (???? 1) ???
ORA-00312: ???? 1 ?? 1: '/u02/oradata/ORCL/redo01.log'
ORA-27046: ??????????????
Additional information: 1
2020-05-31T11:23:05.639749+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_5619.trc:
ORA-00313: 无法打开日志组 1 (用于线程 ) 的成员
ORA-00312: 联机日志 1 线程 1: '/u02/oradata/ORCL/redo01.log'
USER (ospid: ): terminating the instance due to ORA error 
2020-05-31T11:23:05.762325+08:00
System state dump requested by (instance=1, osid=5619), summary=[abnormal instance termination].
System State dumped to trace file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_diag_5558.trc
2020-05-31T11:23:05.848947+08:00
Dumping diagnostic data in directory=[cdmp_20200531112305], requested by (instance=1, osid=5619), summary=[abnormal instance termination].
2020-05-31T11:23:06.877329+08:00
Instance terminated by USER, pid = 5619
5.重新连接数据库,清除当前日志组数据
SYS@orcl> alter database clear logfile group 1;
数据库已更改。
6.打开数据库
SYS@orcl> alter database open;
数据库已更改。

---------------------------------------------------------------------------------------------------------------------------------
连接scott用户,创建test表,插入数据
[oracle@enmotech admin]$ sqlplus scott/tiger@orclpdb
SQL*Plus: Release 19.0.0.0.0 - Production on 星期日 5月 31 11:38:59 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
上次成功登录时间: 星期一 5月  18 2020 20:26:08 +08:00
连接到: 
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SCOTT@orclpdb> create table test (id number);
表已创建。
SCOTT@orclpdb> insert into test(id) values (1);
已创建 1 行。
SCOTT@orclpdb> commit;
提交完成。
SCOTT@orclpdb> insert into test(id) values (2);
已创建 1 行。
(插入数据2,不进行提交)
----------------------------------------------------------------------------------------------------------------------------------

1.3
a、current redo文件损坏;
b、数据库归档模式;
c、需要写入数据文件
d、实例在线current redo损坏

场景模拟:
1.查看当前日志状态
SYS@orcl> col member for a40;
SYS@orcl> select l.group#, l.sequence#, lf.member, l.bytes/1024/1024 M, l.archived, l.status from v$log l, v$logfile lf where l.group#=lf.group#
    GROUP#  SEQUENCE# MEMBER						M ARC STATUS
---------- ---------- ---------------------------------------- ---------- --- ----------------
	 3	   20 /u02/oradata/ORCL/redo03.log		      200 NO  CURRENT
	 2	   17 /u02/oradata/ORCL/redo02.log		      200 YES INACTIVE
	 1	    0 /u02/oradata/ORCL/redo01.log		      200 YES UNUSED
2.模拟current redolog损坏
[oracle@enmotech ORCL]$ echo 1 >> /u02/oradata/ORCL/redo03.log
3.commit提交数据,观察alter_sid.log报错
2020-05-31T11:49:31.281843+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_7598.trc:
ORA-00313: 无法打开日志组 3 (用于线程 1) 的成员
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
2020-05-31T11:49:31.281928+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_7598.trc:
ORA-00313: 无法打开日志组 3 (用于线程 1) 的成员
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
2020-05-31T11:49:31.320587+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_mz00_7880.trc:
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
4.清除当前日志组数据(一定不要关闭数据库,避免数据丢失)
SYS@orcl> alter system switch logfile;
系统已更改。
SYS@orcl> alter database clear unarchived logfile group 3;
数据库已更改。
5.打开数据库
SYS@orcl> alter database open;
数据库已更改。


1.4 
a、current redo文件损坏;
b、数据库归档模式;
c、需要写入数据文件
d、实例不正常关闭后current redo损坏

场景模拟:
1.查看当前日志状态
SYS@orcl> select l.group#, l.sequence#, lf.member, l.bytes/1024/1024 M, l.archived, l.status from v$log l, v$logfile lf where l.group#=lf.group#;
    GROUP#  SEQUENCE# MEMBER						M ARC STATUS
---------- ---------- ---------------------------------------- ---------- --- ----------------
	 3	   22 /u02/oradata/ORCL/redo03.log		      200 NO  CURRENT
	 2	   17 /u02/oradata/ORCL/redo02.log		      200 YES INACTIVE
	 1	    0 /u02/oradata/ORCL/redo01.log		      200 YES UNUSED
2.强关数据库
SYS@orcl> shutdown abort;
ORACLE 例程已经关闭。
3.模拟current redolog损坏
[oracle@enmotech ~]$  echo 1 >> /u02/oradata/ORCL/redo03.log
4.打开数据库
SYS@orcl> startup
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
ORA-00313: 无法打开日志组 3 (用于线程 1) 的成员 ORA-00312:
联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数 Additional
information: 1
5.查看告警日志
2020-05-31T12:12:03.310379+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_9337.trc:
ORA-00313: 无法打开日志组 3 (用于线程 1) 的成员
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
2020-05-31T12:12:03.362444+08:00
Slave encountered ORA-10388 exception during crash recovery
2020-05-31T12:12:03.375439+08:00
Slave encountered ORA-10388 exception during crash recovery
2020-05-31T12:12:03.378174+08:00
Aborting crash recovery due to error 313
2020-05-31T12:12:03.378309+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_9337.trc:
ORA-00313: 无法打开日志组 3 (用于线程 1) 的成员
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
2020-05-31T12:12:03.378837+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_9337.trc:
ORA-00313: 无法打开日志组 3 (用于线程 1) 的成员
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
ORA-313 signalled during: ALTER DATABASE OPEN...
2020-05-31T12:12:03.390997+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_mz00_9343.trc:
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
2020-05-31T12:12:03.476462+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_mz00_9343.trc:
ORA-00313: 无法打开日志组 3 (用于线程 1) 的成员
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
2020-05-31T12:12:03.552455+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_mz00_9343.trc:
ORA-00313: 无法打开日志组 3 (用于线程 1) 的成员
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
恢复数据
SYS@orcl> recover database until cancel;
ORA-00279: 更改 2991918 (在 05/31/2020 12:02:08 生成) 对于线程 1 是必需的 ORA-00289:
建议: /u02/oradata/orcl_arch_log/1_22_1040302643.arc
ORA-00280: 更改 2991918 (用于线程 1) 在序列 #22 中
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: 无法打开归档日志 '/u02/oradata/orcl_arch_log/1_22_1040302643.arc'
ORA-27037: 无法获得文件状态
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7
ORA-00308: 无法打开归档日志 '/u02/oradata/orcl_arch_log/1_22_1040302643.arc'
ORA-27037: 无法获得文件状态
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7
ORA-01547: 警告: RECOVER 成功但 OPEN RESETLOGS 将出现如下错误 ORA-01194:
文件 1 需要更多的恢复来保持一致性 ORA-01110:
数据文件 1: '/u02/oradata/ORCL/system01.dbf'
SYS@orcl> alter database open resetlogs;
alter database open resetlogs
*
第 1 行出现错误:
ORA-00603: ORACLE server session terminated by fatal error
ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-00600: internal error code, arguments: [kcbzib_kcrsds_1], [], [], [], [], [], [], [], [], [], [], []
进程 ID: 9733
会话 ID: 237 序列号: 18481
SYS@orcl> recover database until cancel;
ERROR:
ORA-03114: 未连接到 ORACLE
SYS@orcl> quit
6.启动数据库到mount状态
SYS@orcl> startup mount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
7.修改undo表空间
SYS@orcl> show parameter undo;
NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
temp_undo_enabled		     boolean	 FALSE
undo_management 		     string	 AUTO
undo_retention			     integer	 900
undo_tablespace 		     string	 UNDOTBS1
SYS@orcl> alter system set undo_management=manual scope=spfile;
系统已更改。
SYS@orcl> alter system set undo_tablespace=system scope=spfile;
系统已更改。
SYS@orcl> shu immediate;
ORA-01109: 数据库未打开
已经卸载数据库。
ORACLE 例程已经关闭。
SYS@orcl> startup mount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
8.打开数据库
SYS@orcl> alter database open;
数据库已更改。


1.5 
a、current redo文件损坏;
b、数据库非归档模式;
c、需要写入数据文件
d、实例在线current redo损坏

场景模拟:
1.查看当前日志状态
SYS@orcl> select l.group#, l.sequence#, lf.member, l.bytes/1024/1024 M, l.archived, l.status from v$log l, v$logfile lf where l.group#=lf.group#;
    GROUP#  SEQUENCE# MEMBER						M ARC STATUS
---------- ---------- ---------------------------------------- ---------- --- ----------------
	 3	   18 /u02/oradata/ORCL/redo03.log		      200 NO  CURRENT
	 2	   17 /u02/oradata/ORCL/redo02.log		      200 YES INACTIVE
	 1	   16 /u02/oradata/ORCL/redo01.log		      200 YES INACTIVE
2.查看告警日志
2020-05-31T13:31:10.075933+08:00
Thread 1 advanced to log sequence 19 (LGWR switch)
  Current log# 1 seq# 19 mem# 0: /u02/oradata/ORCL/redo01.log
2020-05-31T13:31:22.970981+08:00
alter database clear logfile group 3
ORA-1624 signalled during: alter database clear logfile group 3...
2020-05-31T13:31:23.058733+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_mz00_4507.trc:
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
2020-05-31T13:31:23.257429+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_mz00_4507.trc:
ORA-00313: 无法打开日志组 3 (用于线程 1) 的成员
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
2020-05-31T13:31:23.334583+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_mz00_4507.trc:
ORA-00313: 无法打开日志组 3 (用于线程 1) 的成员
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
Checker run found 2 new persistent data failures
2020-05-31T13:32:52.559008+08:00
alter database clear logfile group 3
2020-05-31T13:32:52.559989+08:00
Clearing online log 3 of thread 1 sequence number 18
2020-05-31T13:32:52.562391+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_4056.trc:
ORA-00313: 无法打开日志组 3 (用于线程 1) 的成员
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
2020-05-31T13:32:52.562794+08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_4056.trc:
ORA-00313: 无法打开日志组 3 (用于线程 1) 的成员
ORA-00312: 联机日志 3 线程 1: '/u02/oradata/ORCL/redo03.log'
ORA-27046: 文件大小不是逻辑块大小的倍数
Additional information: 1
3.切换redo日志
SYS@orcl> alter system switch logfile;
系统已更改。
4.归档当前的redo日志
SYS@orcl> alter system checkpoint;
系统已更改。
5.清除归档日志
SYS@orcl> alter database clear logfile group 3;
数据库已更改。
6.查看当前日志状态
SYS@orcl> select l.group#, l.sequence#, lf.member, l.bytes/1024/1024 M, l.archived, l.status from v$log l, v$logfile lf where l.group#=lf.group#;
    GROUP#  SEQUENCE# MEMBER						M ARC STATUS
---------- ---------- ---------------------------------------- ---------- --- ----------------
	 3	    0 /u02/oradata/ORCL/redo03.log		      200 NO  UNUSED
	 2	   17 /u02/oradata/ORCL/redo02.log		      200 YES INACTIVE
	 1	   19 /u02/oradata/ORCL/redo01.log		      200 NO  CURRENT
	 
	 
1.6 
a、current redo文件损坏;
b、数据库非归档模式;
c、需要写入数据文件
d、实例不正常关闭后current redo损坏

场景模拟:
1.查看当前日志状态
SYS@orcl> select l.group#, l.sequence#, lf.member, l.bytes/1024/1024 M, l.archived, l.status from v$log l, v$logfile lf where l.group#=lf.group#;
    GROUP#  SEQUENCE# MEMBER						M ARC STATUS
---------- ---------- ---------------------------------------- ---------- --- ----------------
	 3	    0 /u02/oradata/ORCL/redo03.log		      200 NO  UNUSED
	 2	   17 /u02/oradata/ORCL/redo02.log		      200 YES INACTIVE
	 1	   19 /u02/oradata/ORCL/redo01.log		      200 NO  CURRENT
2.模拟current redolog损坏
echo 1 >> /u02/oradata/ORCL/redo01.log
3.强关数据库
SYS@orcl> shutdown abort;
ORACLE 例程已经关闭。
4.恢复数据库
SYS@orcl> startup nomount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
SYS@orcl> alter system set "_allow_resetlogs_corruption"=true scope=spfile;
系统已更改。
SYS@orcl> shu immediate;
ORA-01507: ??????
ORACLE 例程已经关闭。
SYS@orcl> startup mount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
SYS@orcl> recover database until cancel;
ORA-00279: 更改 2983632 (在 05/31/2020 13:32:44 生成) 对于线程 1 是必需的 ORA-00289:
建议: /u02/oradata/orcl_arch_log/1_19_1040302643.arc
ORA-00280: 更改 2983632 (用于线程 1) 在序列 #19 中
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
/u02/oradata/orcl_arch_log/1_19_1040302643.arc
ORA-00308: 无法打开归档日志 '/u02/oradata/orcl_arch_log/1_19_1040302643.arc'
ORA-27037: 无法获得文件状态
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
/u02/oradata/ORCL/redo01.log
ORA-00308: 无法打开归档日志 '/u02/oradata/ORCL/redo01.log'
ORA-27046: 文件大小不是逻辑块大小的倍数 Additional
information: 1
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
/u02/oradata/ORCL/redo02.log
ORA-00310: 归档日志包含序列 17; 要求序列 19 ORA-00334:
归档日志: '/u02/oradata/ORCL/redo02.log'
ORA-01547: 警告: RECOVER 成功但 OPEN RESETLOGS 将出现如下错误 ORA-01194:
文件 1 需要更多的恢复来保持一致性 ORA-01110:
数据文件 1: '/u02/oradata/ORCL/system01.dbf'
SYS@orcl> recover database using backup controlfile until cancel;
ORA-00279: 更改 2983632 (在 05/31/2020 13:32:44 生成) 对于线程 1 是必需的 ORA-00289:
建议: /u02/oradata/orcl_arch_log/1_19_1040302643.arc
ORA-00280: 更改 2983632 (用于线程 1) 在序列 #19 中
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: 无法打开归档日志 '/u02/oradata/orcl_arch_log/1_19_1040302643.arc'
ORA-27037: 无法获得文件状态
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7
ORA-00308: 无法打开归档日志 '/u02/oradata/orcl_arch_log/1_19_1040302643.arc'
ORA-27037: 无法获得文件状态
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7
SYS@orcl> alter database open resetlogs;
alter database open resetlogs
*
第 1 行出现错误:
ORA-00603: ORACLE server session terminated by fatal error
ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-00600: internal error code, arguments: [ktcpoptx:!cmt top lvl], [], [], [], [], [], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcbzib_kcrsds_1], [], [], [], [], [], [], [], [], [], [], []
进程 ID: 5296
会话 ID: 237 序列号: 10783
5.切换undo
[oracle@enmotech ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on 星期日 5月 31 13:44:00 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
已连接到空闲例程。
SYS@orcl> startup mount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
SYS@orcl> show parameter undo;
NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
temp_undo_enabled		     boolean	 FALSE
undo_management 		     string	 AUTO
undo_retention			     integer	 900
undo_tablespace 		     string	 UNDOTBS1
SYS@orcl> alter system set undo_management=manual scope=spfile;
系统已更改。
SYS@orcl> alter system set undo_tablespace=system scope=spfile;
系统已更改。
[oracle@enmotech ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on 星期日 5月 31 13:50:08 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
连接到: 
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SYS@orcl> shu immediate;
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SYS@orcl> startup mount;
ORACLE 例程已经启动。
Total System Global Area 1543500832 bytes
Fixed Size		    9135136 bytes
Variable Size		  989855744 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7639040 bytes
数据库装载完毕。
SYS@orcl> alter database open;
数据库已更改。
7.重建undo即可恢复数据库


2 active redo文件恢复介绍
---------------------------------------------------------------------------------------------------------------------------------
做检查点切换 alter system checkpoint; 如成功,按照 inactive 损坏处理。否则,按 current 损坏处理。
----------------------------------------------------------------------------------------------------------------------------------
2.1
a、active redo文件损坏;
b、数据库归档模式;
c、需要写入数据文件
d、实例在线时损坏
e、未归档
(不要关闭数据库,直接执行alter database clear unarchived logfile group n,不会丢数据)
2.2
a、active redo文件损坏;
b、数据库归档模式;
c、需要写入数据文件
d、实例不正常关闭时损坏
e、未归档
(会丢数据)
2.3
a、active redo文件损坏;
b、数据库归档模式;
c、需要写入数据文件
d、实例在线时损坏
e、已归档
(不要关闭数据库,直接执行alter database clear unarchived logfile group n,不会丢数据)
2.4 
a、active redo文件损坏;
b、数据库归档模式;
c、需要写入数据文件
d、实例不正常关闭时损坏
e、已归档
(不会丢数据)
2.5 
a、active redo文件损坏;
b、数据库非归档模式;
c、需要写入数据文件
d、实例在线时损坏
e、不归档
(不要关闭数据库,直接执行alter database clear logfile group n,不会丢数据)
2.6
a、active redo文件损坏;
b、数据库非归档模式;
c、需要写入数据文件
d、实例在线时损坏
e、不归档
(会丢数据)


3.inactive redo文件恢复介绍
3.1
a、inactive redo文件损坏
b、不需要写入数据文件信息
c、实例在线损坏和实例异常关机损坏
d、数据库归档模式;
e、未归档
SYS@orcl> select l.group#, l.sequence#, lf.member, l.bytes/1024/1024 M, l.archived, l.status from v$log l, v$logfile lf where l.group#=lf.group#;
SYS@orcl> alter database clear unarchived logfile group n;
(在线直接执行上述命令,实例异常关机,启动到mount执行,
不会丢失数据,n损坏的inactive日志组,可以在mount状态查看或者告警日志查看)
3.2
a、inactive redo文件损坏
b、不需要写入数据文件信息
c、实例在线损坏和实例异常关机损坏
d、数据库归档模式;
e、已归档
SYS@orcl> select l.group#, l.sequence#, lf.member, l.bytes/1024/1024 M, l.archived, l.status from v$log l, v$logfile lf where l.group#=lf.group#;
SYS@orcl> alter database clear logfile group n;
(在线直接执行上述命令,实例异常关机,启动到mount执行,
不会丢失数据,n损坏的inactive日志组,可以在mount状态查看或者告警日志查看)
3.3
a、inactive redo文件损坏
b、不需要写入数据文件信息
c、实例在线损坏和实例异常关机损坏
d、数据库非归档模式;
e、不归档
SYS@orcl> select l.group#, l.sequence#, lf.member, l.bytes/1024/1024 M, l.archived, l.status from v$log l, v$logfile lf where l.group#=lf.group#;
SYS@orcl> alter database clear logfile group n;
(在线直接执行上述命令,实例异常关机,启动到mount执行,不会丢失数据,n损坏的inactive日志组,可以在mount状态查看或者告警日志查看)
posted @ 2023-03-04 08:33  竹蜻蜓vYv  阅读(32)  评论(0编辑  收藏  举报