Oracle重建控制文件


前言

以下只是记录一次重建控制文件的过程

一、重建原因

在rman恢复数据库的过程中,碰到恢复结束时,做不完全恢复后,无法resetlogs打开数据库的情况,报错如下:

在这里插入图片描述
在这里插入图片描述
这种情况不能rename日志文件,也不能添加新的redo后再把旧的redo删除,所以只能选择重建控制文件了。

二、重建步骤

在mount状态下备份控制文件到/u01/control12.trc

alter database backup controlfile to trace as '/u01/control12.trc';

查看控制文件

[root@cyhiscsdb u01]# cat control12.trc 
-- The following are current System-scope REDO Log Archival related
-- parameters and can be included in the database initialization file.
--
-- LOG_ARCHIVE_DEST=''
-- LOG_ARCHIVE_DUPLEX_DEST=''
--
-- LOG_ARCHIVE_FORMAT=%t_%s_%r.dbf
--
-- DB_UNIQUE_NAME="orcl"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'
-- LOG_ARCHIVE_MAX_PROCESSES=4
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- STANDBY_ARCHIVE_DEST=?/dbs/arch
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_1='LOCATION=/u01/archivelog'
-- LOG_ARCHIVE_DEST_1='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_1='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_1='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_1=ENABLE

--
-- Below are two sets of SQL statements, each of which creates a new
-- control file and uses it to open the database. The first set opens
-- the database with the NORESETLOGS option and should be used only if
-- the current versions of all online logs are available. The second
-- set opens the database with the RESETLOGS option and should be used
-- if online logs are unavailable.
-- The appropriate set of statements can be copied from the trace into
-- a script file, edited as necessary, and executed when there is a
-- need to re-create the control file.
--
--     Set #1. NORESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- Additional logs may be required for media recovery of offline
-- Use this only if the current versions of all online logs are
-- available.
-- WARNING! The current control file needs to be checked against
-- the datafiles to insure it contains the correct files. The
-- commands printed here may be missing log and/or data files.
-- Another report should be made after the database has been
-- successfully opened.

-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 192
    MAXLOGMEMBERS 3
    MAXDATAFILES 1024
    MAXINSTANCES 32
    MAXLOGHISTORY 2336
LOGFILE
  GROUP 1 '+data'  SIZE 200M BLOCKSIZE 512,
  GROUP 2 '+data'  SIZE 200M BLOCKSIZE 512,
  GROUP 3 '+data'  SIZE 200M BLOCKSIZE 512,
  GROUP 4 '+data'  SIZE 200M BLOCKSIZE 512,
  GROUP 5 '/u01/oradata/orcl/redo05.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 6 '/u01/oradata/orcl/redo06.log '  SIZE 50M BLOCKSIZE 512,
  GROUP 7 '/u01/oradata/orcl/redo07.log '  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/u01/oradata/orcl/system.259.1080556689',
  '/u01/oradata/orcl/sysaux.260.1080556691',
  '/u01/oradata/orcl/undotbs1.261.1080556691',
  '/u01/oradata/orcl/undotbs2.263.1080556695',
  '/u01/oradata/orcl/users.264.1080556695',
  '/u01/oradata/orcl/bs-whis.dbf',
  '/u01/oradata/orcl/ts_jyk.dbf',
  '/u01/oradata/orcl/portal.dbf',
  '/u01/oradata/orcl/bs-whis01.dbf',
  '/u01/oradata/orcl/ts_jyk01.dbf',
  '/u01/oradata/orcl/bs-whis.289.1089555583'
CHARACTER SET ZHS16GBK
;

-- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('DEVICE TYPE','DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET');
-- Configure RMAN configuration record 2
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('RETENTION POLICY','TO REDUNDANCY 3');
-- Configure RMAN configuration record 3
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('BACKUP OPTIMIZATION','ON');
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/u01/archivelog/1_1_1080556683.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE

-- All logs need archiving and a log switch is needed.
ALTER SYSTEM ARCHIVE LOG ALL;

-- Database can now be opened normally.
ALTER DATABASE OPEN;

-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '+DATA/orcl/tempfile/temp.262.1080556691' REUSE;
-- End of tempfile additions.
--
--     Set #2. RESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.
-- WARNING! The current control file needs to be checked against
-- the datafiles to insure it contains the correct files. The
-- commands printed here may be missing log and/or data files.
-- Another report should be made after the database has been
-- successfully opened.

-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 192
    MAXLOGMEMBERS 3
    MAXDATAFILES 1024
    MAXINSTANCES 32
    MAXLOGHISTORY 2336
LOGFILE
  GROUP 1 '+data'  SIZE 200M BLOCKSIZE 512,
  GROUP 2 '+data'  SIZE 200M BLOCKSIZE 512,
  GROUP 5 '/u01/oradata/orcl/redo05.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 6 '/u01/oradata/orcl/redo06.log '  SIZE 50M BLOCKSIZE 512,
  GROUP 7 '/u01/oradata/orcl/redo07.log '  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/u01/oradata/orcl/system.259.1080556689',
  '/u01/oradata/orcl/sysaux.260.1080556691',
  '/u01/oradata/orcl/undotbs1.261.1080556691',
  '/u01/oradata/orcl/undotbs2.263.1080556695',
  '/u01/oradata/orcl/users.264.1080556695',
  '/u01/oradata/orcl/bs-whis.dbf',
  '/u01/oradata/orcl/ts_jyk.dbf',
  '/u01/oradata/orcl/portal.dbf',
  '/u01/oradata/orcl/bs-whis01.dbf',
  '/u01/oradata/orcl/ts_jyk01.dbf',
  '/u01/oradata/orcl/bs-whis.289.1089555583'
CHARACTER SET ZHS16GBK
;

-- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('DEVICE TYPE','DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET');
-- Configure RMAN configuration record 2
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('RETENTION POLICY','TO REDUNDANCY 3');
-- Configure RMAN configuration record 3
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('BACKUP OPTIMIZATION','ON');
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/u01/archivelog/1_1_1080556683.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE USING BACKUP CONTROLFILE

-- Create log files for threads other than thread one.
ALTER DATABASE ADD LOGFILE THREAD 2
  GROUP 3 '+data' SIZE 200M BLOCKSIZE 512 REUSE,
  GROUP 4 '+data' SIZE 200M BLOCKSIZE 512 REUSE;

-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;

-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '+DATA/orcl/tempfile/temp.262.1080556691' REUSE;
-- End of tempfile additions.
--

看起来控制文件很长啊,其实里面内容可以分成两部分来看,第一部分是NORESETLOGS–针对redo可用的情况,第二部分RESETLOGS–针对redo不可用的情况。

我们选择重建控制文件的原因,是因为redo路径不对,还是源库路径,redo已经不可用了,所以我们选择RESETLOGS这段。
截取RESETLOGS这段并稍作修改:
把源库的logfile从控制文件中去除,只留下我们新增的logfile文件

CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 192
    MAXLOGMEMBERS 3
    MAXDATAFILES 1024
    MAXINSTANCES 32
    MAXLOGHISTORY 2336
LOGFILE
  GROUP 5 '/u01/oradata/orcl/redo05.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 6 '/u01/oradata/orcl/redo06.log '  SIZE 50M BLOCKSIZE 512,
  GROUP 7 '/u01/oradata/orcl/redo07.log '  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/u01/oradata/orcl/system.259.1080556689',
  '/u01/oradata/orcl/sysaux.260.1080556691',
  '/u01/oradata/orcl/undotbs1.261.1080556691',
  '/u01/oradata/orcl/undotbs2.263.1080556695',
  '/u01/oradata/orcl/users.264.1080556695',
  '/u01/oradata/orcl/bs-whis.dbf',
  '/u01/oradata/orcl/ts_jyk.dbf',
  '/u01/oradata/orcl/portal.dbf',
  '/u01/oradata/orcl/bs-whis01.dbf',
  '/u01/oradata/orcl/ts_jyk01.dbf',
  '/u01/oradata/orcl/bs-whis.289.1089555583'
CHARACTER SET ZHS16GBK
;

修改完将创建控制文件脚本保存到/u01/control.sql

SQL> @/u01/control.sql

Control file created.

执行恢复

SQL> recover database using backup controlfile until cancel;
ORA-00279: change 3691999058 generated at 12/10/2021 02:14:01 needed for thread
2
ORA-00289: suggestion : /u01/archivelog/2_9397_1080556683.dbf
ORA-00280: change 3691999058 for thread 2 is in sequence #9397


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: cannot open archived log '/u01/archivelog/2_9397_1080556683.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3


ORA-00308: cannot open archived log '/u01/archivelog/2_9397_1080556683.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3


SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-38856: cannot mark instance UNNAMED_INSTANCE_2 (redo thread 2) as enabled

此处报错ORA-38856是因为源库是RAC,控制文件中没有线程2的logfile。

SQL> select group#,members,bytes/1024/1024,status from v$log; 

    GROUP#    MEMBERS BYTES/1024/1024 STATUS
---------- ---------- --------------- ----------------
	 5	    1		   50 UNUSED
	 7	    1		   50 CURRENT
	 6	    1		   50 UNUSED

需要添加线程2的logfile:

alter database add logfile thread 2 group 8('/u01/oradata/orcl/redo08.log ') size 50m;
 
alter database add logfile thread 2 group 9('/u01/oradata/orcl/redo09.log ') size 50m;

alter database add logfile thread 2 group 10('/u01/oradata/orcl/redo10.log') size 50m;

重新resetlogs打开数据库

SQL> alter database open resetlogs;

Database altered.

其他报错

ORA-01503: CREATE CONTROLFILE failed
ORA-01192: must have at least one enabled thread

用了NORESETLOGS参数改成RESETLOGS参数就好了。

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值