代码改变世界

RMAN(4)--- DRA诊断工具

2021-01-21 23:47  EniNiemand  阅读(464)  评论(0编辑  收藏  举报

1. 什么是DRA(Data Recovery Advisor)?

  答:DRA是一个诊断和恢复数据库的工具,通过两个途径操作,一个是RMAN界面,另一个是EM,它依赖于ADR的自动诊断信息以及Health Monitor(Health Monitor是11g里新增加的新特性,用于数据库的各层和各个组建的诊断检查。例如可以检查:文件损坏、物理逻辑块损坏、redo和undo故障、数据字典损坏等,并把发现的这些信息记录到ADR自动诊断信息库中)。

2. DRA 三板斧

  1. RMAN> list failure ;

  2. RMAN> advise failure;

  3. RMAN> repair failure;

3. 实验:

  1. 备份全库

  2. 删除其中的数据文件

  3. 重启数据库

  4. 利用DRA恢复数据库

  1 备份全库
  2 RMAN> backup database format '/u01/app/oracle/backup/%s_%t_%U.full';
  3 
  4 Starting backup at 2021-01-21 23:24:08
  5 using channel ORA_DISK_1
  6 channel ORA_DISK_1: starting full datafile backup set
  7 channel ORA_DISK_1: specifying datafile(s) in backup set
  8 input datafile file number=00003 name=/u01/app/oracle/oradata/OCP12C/sysaux01.dbf
  9 input datafile file number=00001 name=/u01/app/oracle/oradata/OCP12C/system01.dbf
 10 input datafile file number=00004 name=/u01/app/oracle/oradata/OCP12C/undotbs01.dbf
 11 input datafile file number=00007 name=/u01/app/oracle/oradata/OCP12C/users01.dbf
 12 input datafile file number=00016 name=/u01/app/oracle/oradata/OCP12C/hehe01.dbf
 13 input datafile file number=00017 name=/u01/app/oracle/oradata/OCP12C/memeda01.dbf
 14 input datafile file number=00019 name=/u01/app/oracle/oradata/OCP12C/xxp01.dbf
 15 input datafile file number=00020 name=/u01/app/oracle/oradata/OCP12C/aaa01.dbf
 16 input datafile file number=00023 name=/u01/app/oracle/backup/lalala01.dbf
 17 channel ORA_DISK_1: starting piece 1 at 2021-01-21 23:24:09
 18 channel ORA_DISK_1: finished piece 1 at 2021-01-21 23:27:44
 19 piece handle=/u01/app/oracle/backup/64_1062458649_20vl7l8p_1_1.full tag=TAG20210121T232408 comment=NONE
 20 channel ORA_DISK_1: backup set complete, elapsed time: 00:03:35
 21 channel ORA_DISK_1: starting full datafile backup set
 22 channel ORA_DISK_1: specifying datafile(s) in backup set
 23 input datafile file number=00010 name=/u01/app/oracle/oradata/OCP12C/ERP/sysaux01.dbf
 24 input datafile file number=00009 name=/u01/app/oracle/oradata/OCP12C/ERP/system01.dbf
 25 input datafile file number=00011 name=/u01/app/oracle/oradata/OCP12C/ERP/undotbs01.dbf
 26 input datafile file number=00012 name=/u01/app/oracle/oradata/OCP12C/ERP/users01.dbf
 27 input datafile file number=00015 name=/u01/app/oracle/oradata/OCP12C/ERP/test01.dbf
 28 input datafile file number=00018 name=/u01/app/oracle/oradata/OCP12C/ERP/xxp01.dbf
 29 input datafile file number=00021 name=/u01/app/oracle/backup/aaa01.dbf
 30 input datafile file number=00022 name=/u01/app/oracle/oradata/OCP12C/ERP/lalala01.dbf
 31 channel ORA_DISK_1: starting piece 1 at 2021-01-21 23:27:44
 32 channel ORA_DISK_1: finished piece 1 at 2021-01-21 23:28:20
 33 piece handle=/u01/app/oracle/backup/65_1062458864_21vl7lfg_1_1.full tag=TAG20210121T232408 comment=NONE
 34 channel ORA_DISK_1: backup set complete, elapsed time: 00:00:36
 35 channel ORA_DISK_1: starting full datafile backup set
 36 channel ORA_DISK_1: specifying datafile(s) in backup set
 37 input datafile file number=00006 name=/u01/app/oracle/oradata/OCP12C/pdbseed/sysaux01.dbf
 38 input datafile file number=00005 name=/u01/app/oracle/oradata/OCP12C/pdbseed/system01.dbf
 39 input datafile file number=00008 name=/u01/app/oracle/oradata/OCP12C/pdbseed/undotbs01.dbf
 40 channel ORA_DISK_1: starting piece 1 at 2021-01-21 23:28:20
 41 channel ORA_DISK_1: finished piece 1 at 2021-01-21 23:28:45
 42 piece handle=/u01/app/oracle/backup/66_1062458900_22vl7lgk_1_1.full tag=TAG20210121T232408 comment=NONE
 43 channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
 44 Finished backup at 2021-01-21 23:28:45
 45 
 46 Starting Control File and SPFILE Autobackup at 2021-01-21 23:28:45
 47 piece handle=/u01/app/oracle/product/12.2.0.1/db_1/dbs/c-671397679-20210121-15 comment=NONE
 48 Finished Control File and SPFILE Autobackup at 2021-01-21 23:28:47
 49 
 50 删除ERP下的两个数据文件
 51 [oracle@oracle12c backup]$ cd /u01/app/oracle/oradata/OCP12C/ERP/
 52 [oracle@oracle12c ERP]$ ll
 53 total 942024
 54 -rw-r----- 1 oracle oinstall   5251072 Jan 21 23:27 lalala01.dbf
 55 -rw-r----- 1 oracle oinstall 545267712 Jan 21 23:27 sysaux01.dbf
 56 -rw-r----- 1 oracle oinstall 272637952 Jan 21 23:27 system01.dbf
 57 -rw-r----- 1 oracle oinstall  67117056 Jan 20 06:03 temp01.dbf
 58 -rw-r----- 1 oracle oinstall   5251072 Jan 21 23:27 test01.dbf
 59 -rw-r----- 1 oracle oinstall 120594432 Jan 21 23:27 undotbs01.dbf
 60 -rw-r----- 1 oracle oinstall   5251072 Jan 21 23:27 users01.dbf
 61 -rw-r----- 1 oracle oinstall   5251072 Jan 21 23:27 xxp01.dbf
 62 [oracle@oracle12c ERP]$ rm -rf test01.dbf
 63 [oracle@oracle12c ERP]$ rm -rf xxp01.dbf
 64 [oracle@oracle12c ERP]$ ll
 65 total 931768
 66 -rw-r----- 1 oracle oinstall   5251072 Jan 21 23:27 lalala01.dbf
 67 -rw-r----- 1 oracle oinstall 545267712 Jan 21 23:27 sysaux01.dbf
 68 -rw-r----- 1 oracle oinstall 272637952 Jan 21 23:27 system01.dbf
 69 -rw-r----- 1 oracle oinstall  67117056 Jan 20 06:03 temp01.dbf
 70 -rw-r----- 1 oracle oinstall 120594432 Jan 21 23:27 undotbs01.dbf
 71 -rw-r----- 1 oracle oinstall   5251072 Jan 21 23:27 users01.dbf
 72 [oracle@oracle12c ERP]$
 73 
 74 重启数据库
 75 SQL> alter database open;
 76 alter database open
 77 *
 78 ERROR at line 1:
 79 ORA-01157: cannot identify/lock data file 18 - see DBWR trace file
 80 ORA-01110: data file 18: '/u01/app/oracle/oradata/OCP12C/ERP/xxp01.dbf'
 81 
 82 DRA恢复
 83 [oracle@oracle12c ERP]$ rman target /
 84 
 85 Recovery Manager: Release 12.2.0.1.0 - Production on Thu Jan 21 23:40:19 2021
 86 
 87 Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.
 88 
 89 connected to target database: OCP12C (DBID=671397679)
 90 
 91 RMAN> list failure;
 92 
 93 using target database control file instead of recovery catalog
 94 Database Role: PRIMARY
 95 
 96 List of Database Failures
 97 =========================
 98 
 99 Failure ID Priority Status    Time Detected       Summary
100 ---------- -------- --------- ------------------- -------
101 1962       CRITICAL OPEN      2021-01-21 23:36:17 System datafile 9: '/u01/app/oracle/oradata/OCP12C/ERP/system01.dbf' needs media recovery
102 2061       HIGH     OPEN      2021-01-21 23:38:29 One or more non-system datafiles are offline
103 208        HIGH     OPEN      2021-01-21 23:36:18 One or more non-system datafiles need media recovery
104 562        HIGH     OPEN      2021-01-21 23:32:20 One or more non-system datafiles are missing
105 
106 RMAN> advise failure;
107 
108 Database Role: PRIMARY
109 
110 List of Database Failures
111 =========================
112 
113 Failure ID Priority Status    Time Detected       Summary
114 ---------- -------- --------- ------------------- -------
115 1962       CRITICAL OPEN      2021-01-21 23:36:17 System datafile 9: '/u01/app/oracle/oradata/OCP12C/ERP/system01.dbf' needs media recovery
116 2061       HIGH     OPEN      2021-01-21 23:38:29 One or more non-system datafiles are offline
117 208        HIGH     OPEN      2021-01-21 23:36:18 One or more non-system datafiles need media recovery
118 562        HIGH     OPEN      2021-01-21 23:32:20 One or more non-system datafiles are missing
119 
120 analyzing automatic repair options; this may take some time
121 allocated channel: ORA_DISK_1
122 channel ORA_DISK_1: SID=49 device type=DISK
123 analyzing automatic repair options complete
124 
125 Not all specified failures can currently be repaired.
126 The following failures must be repaired before advise for others can be given.
127 
128 Failure ID Priority Status    Time Detected       Summary
129 ---------- -------- --------- ------------------- -------
130 1962       CRITICAL OPEN      2021-01-21 23:36:17 System datafile 9: '/u01/app/oracle/oradata/OCP12C/ERP/system01.dbf' needs media recovery
131 208        HIGH     OPEN      2021-01-21 23:36:18 One or more non-system datafiles need media recovery
132 562        HIGH     OPEN      2021-01-21 23:32:20 One or more non-system datafiles are missing
133 
134 Mandatory Manual Actions
135 ========================
136 no manual actions available
137 
138 Optional Manual Actions
139 =======================
140 1. If you restored the wrong version of data file /u01/app/oracle/oradata/OCP12C/ERP/system01.dbf, then replace it with the correct one
141 2. Automatic repairs may be available if you shutdown the database and restart it in mount mode
142 3. If you restored the wrong version of data file /u01/app/oracle/oradata/OCP12C/ERP/sysaux01.dbf, then replace it with the correct one
143 4. If you restored the wrong version of data file /u01/app/oracle/oradata/OCP12C/ERP/undotbs01.dbf, then replace it with the correct one
144 5. If you restored the wrong version of data file /u01/app/oracle/oradata/OCP12C/ERP/users01.dbf, then replace it with the correct one
145 6. If you restored the wrong version of data file /u01/app/oracle/backup/aaa01.dbf, then replace it with the correct one
146 7. If you restored the wrong version of data file /u01/app/oracle/oradata/OCP12C/ERP/lalala01.dbf, then replace it with the correct one
147 8. If file /u01/app/oracle/oradata/OCP12C/ERP/test01.dbf was unintentionally renamed or moved, restore it
148 9. If file /u01/app/oracle/oradata/OCP12C/ERP/xxp01.dbf was unintentionally renamed or moved, restore it
149 
150 Automated Repair Options
151 ========================
152 Option Repair Description
153 ------ ------------------
154 1      Restore and recover datafile 15; Restore and recover datafile 18; Recover datafile 9; ...
155   Strategy: The repair includes complete media recovery with no data loss
156   Repair script: /u01/app/oracle/diag/rdbms/ocp12c/OCP12C/hm/reco_2252412823.hm
157 
158 RMAN> repair failure;
159 
160 Strategy: The repair includes complete media recovery with no data loss
161 Repair script: /u01/app/oracle/diag/rdbms/ocp12c/OCP12C/hm/reco_2252412823.hm
162 
163 contents of repair script:
164    # restore and recover datafile
165    sql 'ERP' 'alter database datafile 15, 18 offline';
166    restore ( datafile 15, 18 );
167    recover datafile 15, 18;
168    sql 'ERP' 'alter database datafile 15, 18 online';
169    # recover datafile
170    sql 'ERP' 'alter database datafile 9, 10, 11, 12, 21, 22 offline';
171    recover datafile 9, 10, 11, 12, 21, 22;
172    sql 'ERP' 'alter database datafile 9, 10, 11, 12, 21, 22 online';
173 
174 Do you really want to execute the above repair (enter YES or NO)? y
175 executing repair script
176 
177 sql statement: alter database datafile 15, 18 offline
178 
179 Starting restore at 2021-01-21 23:41:41
180 using channel ORA_DISK_1
181 
182 channel ORA_DISK_1: starting datafile backup set restore
183 channel ORA_DISK_1: specifying datafile(s) to restore from backup set
184 channel ORA_DISK_1: restoring datafile 00015 to /u01/app/oracle/oradata/OCP12C/ERP/test01.dbf
185 channel ORA_DISK_1: restoring datafile 00018 to /u01/app/oracle/oradata/OCP12C/ERP/xxp01.dbf
186 channel ORA_DISK_1: reading from backup piece /u01/app/oracle/backup/65_1062458864_21vl7lfg_1_1.full
187 channel ORA_DISK_1: piece handle=/u01/app/oracle/backup/65_1062458864_21vl7lfg_1_1.full tag=TAG20210121T232408
188 channel ORA_DISK_1: restored backup piece 1
189 channel ORA_DISK_1: restore complete, elapsed time: 00:00:08
190 Finished restore at 2021-01-21 23:41:49
191 
192 Starting recover at 2021-01-21 23:41:49
193 using channel ORA_DISK_1
194 
195 starting media recovery
196 media recovery complete, elapsed time: 00:00:00
197 
198 Finished recover at 2021-01-21 23:41:49
199 
200 sql statement: alter database datafile 15, 18 online
201 
202 sql statement: alter database datafile 9, 10, 11, 12, 21, 22 offline
203 
204 Starting recover at 2021-01-21 23:41:49
205 using channel ORA_DISK_1
206 
207 starting media recovery
208 media recovery complete, elapsed time: 00:00:00
209 
210 Finished recover at 2021-01-21 23:41:50
211 
212 sql statement: alter database datafile 9, 10, 11, 12, 21, 22 online
213 repair failure complete
214 
215 RMAN>
216 
217 ERP数据库可以正常打开
218 SQL> conn sys/oracle@erp as sysdba
219 Connected.
220 SQL> select status from v$instance;
221 
222 STATUS
223 ------------------------
224 OPEN
225 
226 SQL>
DRA实验

 4. 注意:

  1. DRA修复遵循的顺序:list failure – advise failure – repair failure。

       2. 所有启动模式下都可以使用DRA,nomount下修复控制文件,mount或open下修复数据文件。

       3. DRA目前只能在单实例下运行,RAC不可以使用它