怎样重建控制文件
发布网友
发布时间:2022-04-20 08:12
我来回答
共2个回答
懂视网
时间:2022-04-09 08:03
当这些信息更改或者变动时,oracle数据库会自动把最新信息更新到controlfile文件里面。
启动数据库时,Oracle从初始化参数文件(pfile/spfile)中获得控制文件的名字及位置,打开控制文件,然后从控制文件中读取数据文件和联机日志文件的信息,最后打开数据库。数据库运行时,Oracle会修改控制文件,所以,一旦控制文件损坏,数据库将不能正常运行。
创建控制文件有几个前提和几个区别:
前提:
1.如果是RAC下,则需要关闭群集:
alter system set cluster_database=FALSE scope=spfile sid=‘*‘;
否则恢复的时候会报错;
2.数据库在mount或者OPEN状态下,才能够重建。
区别:
重建控制文件有两种1.resetlogs恢复和noresetlogs恢复方式
下面还是着手恢复步骤:
重建控制文件,
备份方式
Sql>alter database backup controlfile to trace as ‘/u01/controlfile.trcd’;
创建controlfile备份文件到本地
alter database backup controlfile to ‘+UNDO/ORCL/control‘;
这个是备份控制文件到ASM管理存储里面
如果不知道当前控制文件在哪里
查看位置:select * from v$controlfile;
首先,库能够进入mount状态或者处于OPEN状态:
SQL>startup mount; 或者直接open状态
SQL> alter database backup controlfile to trace as ‘/u01/controlfile.trc‘;
进入/u01/下面
然后编辑这个控制文件
里面包含两部分恢复脚本
一个就是使用norestlogs和另外一个是使用resetlogs恢复的脚本:
内容就不详细全部列出来了:
标识Set #1.NORESETLOGS case的是使用noresetlogs恢复的
标识Set #1.RESETLOGS case的是使用resetlogs恢复的
内容如下:
第一个是noresetlogs恢复的脚本
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE"ORCL" NORESETLOGS ARCHIVELOG
MAXLOGFILES 192
MAXLOGMEMBERS 3
MAXDATAFILES 1024
MAXINSTANCES 32
MAXLOGHISTORY 292
LOGFILE
GROUP 1‘+UNDO/orcl/onlinelog/group_1.257.912261307‘ SIZE 50M BLOCKSIZE 512,
GROUP 2‘+UNDO/orcl/onlinelog/group_2.258.912261307‘ SIZE 50M BLOCKSIZE 512,
GROUP 3‘+UNDO/orcl/onlinelog/group_3.259.912261453‘ SIZE 50M BLOCKSIZE 512,
GROUP 4‘+UNDO/orcl/onlinelog/group_4.260.912261453‘ SIZE 50M BLOCKSIZE 512
DATAFILE
‘+DATA/orcl/datafile/system.256.912261237‘,
‘+DATA/orcl/datafile/sysaux.257.912261239‘,
‘+DATA/orcl/datafile/undotbs1.258.912261239‘,
‘+DATA/orcl/datafile/users.259.912261239‘,
‘+DATA/orcl/datafile/undotbs2.261.912261395‘
CHARACTER SET UTF8
VARIABLE RECNO NUMBER;
EXECUTE :RECNO :=SYS.DBMS_BACKUP_RESTORE.SETCONFIG(‘CONTROLFILE AUTOBACKUP‘,‘ON‘);
RECOVER DATABASE
ALTER SYSTEM ARCHIVE LOG ALL;
ALTER DATABASE OPEN;
ALTER TABLESPACE TEMP ADD TEMPFILE‘+DATA/orcl/tempfile/temp.260.912261313‘
SIZE 33554432 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
下面这就是一个resetlog恢复的脚本:
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE"ORCL" RESETLOGS ARCHIVELOG
MAXLOGFILES 192
MAXLOGMEMBERS 3
MAXDATAFILES 1024
MAXINSTANCES 32
MAXLOGHISTORY 292
LOGFILE
GROUP 1‘+UNDO/orcl/onlinelog/group_1.257.912261307‘ SIZE 50M BLOCKSIZE 512,
GROUP 2‘+UNDO/orcl/onlinelog/group_2.258.912261307‘ SIZE 50M BLOCKSIZE 512
DATAFILE
‘+DATA/orcl/datafile/system.256.912261237‘,
‘+DATA/orcl/datafile/sysaux.257.912261239‘,
‘+DATA/orcl/datafile/undotbs1.258.912261239‘,
‘+DATA/orcl/datafile/users.259.912261239‘,
‘+DATA/orcl/datafile/undotbs2.261.912261395‘
CHARACTER SET UTF8
;
VARIABLE RECNO NUMBER;
EXECUTE :RECNO :=SYS.DBMS_BACKUP_RESTORE.SETCONFIG(‘CONTROLFILE AUTOBACKUP‘,‘ON‘);
RECOVER DATABASE USING BACKUP CONTROLFILE
ALTER DATABASE ADD LOGFILE THREAD 2
GROUP 3‘+UNDO/orcl/onlinelog/group_3.259.912261453‘ SIZE 50M BLOCKSIZE 512 REUSE,
GROUP 4‘+UNDO/orcl/onlinelog/group_4.260.912261453‘ SIZE 50M BLOCKSIZE 512 REUSE;
ALTER DATABASE OPEN RESETLOGS;
ALTER TABLESPACE TEMP ADD TEMPFILE‘+DATA/orcl/tempfile/temp.260.912261313‘
SIZE 33554432 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
好了,下面开始停库恢复:
启动到nomount状态下:
Startup nomount
直接在nomount状态下复制粘贴下面这段脚本:
CREATE CONTROLFILE REUSE DATABASE"ORCL" NORESETLOGS ARCHIVELOG
MAXLOGFILES 192
MAXLOGMEMBERS 3
MAXDATAFILES 1024
MAXINSTANCES 32
MAXLOGHISTORY 292
LOGFILE
GROUP 1‘+UNDO/orcl/onlinelog/group_1.257.912261307‘ SIZE 50M BLOCKSIZE 512,
GROUP 2‘+UNDO/orcl/onlinelog/group_2.258.912261307‘ SIZE 50M BLOCKSIZE 512,
GROUP 3‘+UNDO/orcl/onlinelog/group_3.259.912261453‘ SIZE 50M BLOCKSIZE 512,
GROUP 4 ‘+UNDO/orcl/onlinelog/group_4.260.912261453‘ SIZE 50M BLOCKSIZE 512
DATAFILE
‘+DATA/orcl/datafile/system.256.912261237‘,
‘+DATA/orcl/datafile/sysaux.257.912261239‘,
‘+DATA/orcl/datafile/undotbs1.258.912261239‘,
‘+DATA/orcl/datafile/users.259.912261239‘,
‘+DATA/orcl/datafile/undotbs2.261.912261395‘
CHARACTER SET UTF8;
好了
现在控制文件创建好了;如果有报错,查看是不是RAC状态下没有关闭集群
查看当前状态:已经到了MOUNTED状态下了
执行后面的:
VARIABLE RECNO NUMBER;
EXECUTE :RECNO :=SYS.DBMS_BACKUP_RESTORE.SETCONFIG(‘CONTROLFILE AUTOBACKUP‘,‘YES‘);
在后面的
RECOVERY DATABASE就不用执行了,因为已经有数据文件了。
这里仅仅只是控制文件没有而已
直接ALTER DATABASE OPEN;
成功启动数据库
最后执行以下TEM表空间
ALTER TABLESPACE TEMP ADD TEMPFILE‘+DATA/orcl/tempfile/temp.260.912261313‘
SIZE33554432 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
resetlogs方式重建controlfile
数据文件在,但是日志文件没有是可以用这个方式回复
启动到nomount状态下:
Startup nomount
直接在nomount状态下复制粘贴下面这段脚本:
CREATE CONTROLFILE REUSE DATABASE"ORCL" RESETLOGS ARCHIVELOG
MAXLOGFILES 192
MAXLOGMEMBERS 3
MAXDATAFILES 1024
MAXINSTANCES 32
MAXLOGHISTORY 292
LOGFILE
GROUP 1‘+UNDO/orcl/onlinelog/group_1.257.912261307‘ SIZE 50M BLOCKSIZE 512,
GROUP 2‘+UNDO/orcl/onlinelog/group_2.258.912261307‘ SIZE 50M BLOCKSIZE 512
DATAFILE
‘+DATA/orcl/datafile/system.256.912261237‘,
‘+DATA/orcl/datafile/sysaux.257.912261239‘,
‘+DATA/orcl/datafile/undotbs1.258.912261239‘,
‘+DATA/orcl/datafile/users.259.912261239‘,
‘+DATA/orcl/datafile/undotbs2.261.912261395‘
CHARACTER SET UTF8;
好了
查看当前状态:已经到了MOUNTED状态下了
执行后面的:
VARIABLE RECNO NUMBER;
EXECUTE :RECNO :=SYS.DBMS_BACKUP_RESTORE.SETCONFIG(‘CONTROLFILE AUTOBACKUP‘,‘YES‘);
这里因为是用resetlogs恢复的所以启动数据库的时候也要resetlogs
ALTER DATABASE OPEN resetlogs;
成功启动数据库
最后执行以下TEM表空间
ALTER TABLESPACE TEMP ADD TEMPFILE‘+DATA/orcl/tempfile/temp.260.912261313‘
SIZE33554432 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
Ok这个也恢复成功了。
总结:
两种恢复方式基本一样,只有在启动数据库的时候有差别,可以根据数据库当时情况具体操作。
但是一般情况下不可能出现控制文件丢失。而且控制文件最少要备份两份以上放在不同的位置。
如有不足或缺漏请一起讨论,共同进步
本文出自 “且行且珍惜” 博客,请务必保留此出处http://zjwbk.blog.51cto.com/8740969/1788659
ORACLE之重建控制文件
标签:oracle 数据库 控制文件 controlfile
热心网友
时间:2022-04-09 05:11
环境:
OS:Red Hat Linux As 5
DB:10.2.0.4
在全部控制文件丢失或损坏,而且没有备份的情况下,可以使用重建控制文件的办法打开数据库.以下模拟所有的控制文件丢失的情况下重建控制文件.
1.备份控制文件(数据库mount或是open状态)
SQL> select status from v$instance;
STATUS
------------
OPEN
SQL>alter database backup controlfile to trace as '/u01/ftp/bak_controlfile';
2.删除控制文件
[oracle@hxl oracl]$ rm control01.ctl
rm: remove regular file `control01.ctl'? y
[oracle@hxl oracl]$ rm control02.ctl
rm: remove regular file `control02.ctl'? y
[oracle@hxl oracl]$ rm control03.ctl
rm: remove regular file `control03.ctl'? y
3.关闭数据库后尝试打开数据库
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 734003200 bytes
Fixed Size 1221564 bytes
Variable Size 218106948 bytes
Database Buffers 511705088 bytes
Redo Buffers 2969600 bytes
ORA-00205: error in identifying control file, check alert log for more info
这个时候数据无法打开,以为我们已经删除了控制文件.
4.查看备份控制文件的内容
[oracle@hxl ftp]$ more bak_controlfile
-- 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="oracl"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'
-- LOG_ARCHIVE_MAX_PROCESSES=2
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- STANDBY_ARCHIVE_DEST=?/dbs/arch
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_10='LOCATION=USE_DB_RECOVERY_FILE_DEST'
-- LOG_ARCHIVE_DEST_10='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_10='ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_10='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_10='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_10='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_10=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.
-- 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 "ORACL" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/oracl/redo01.log' SIZE 50M,
GROUP 2 '/u01/app/oracle/oradata/oracl/redo02.log' SIZE 50M,
GROUP 3 '/u01/app/oracle/oradata/oracl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/oracl/system01.dbf',
'/u01/app/oracle/oradata/oracl/undotbs01.dbf',
'/u01/app/oracle/oradata/oracl/sysaux01.dbf',
'/u01/app/oracle/oradata/oracl/users01.dbf'
CHARACTER SET WE8ISO8859P1
;
-- 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/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc';
-- 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 '/u01/app/oracle/oradata/oracl/temp01.dbf'
SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-- 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.
-- 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 "ORACL" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/oracl/redo01.log' SIZE 50M,
GROUP 2 '/u01/app/oracle/oradata/oracl/redo02.log' SIZE 50M,
GROUP 3 '/u01/app/oracle/oradata/oracl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/oracl/system01.dbf',
'/u01/app/oracle/oradata/oracl/undotbs01.dbf',
'/u01/app/oracle/oradata/oracl/sysaux01.dbf',
'/u01/app/oracle/oradata/oracl/users01.dbf'
CHARACTER SET WE8ISO8859P1
;
-- 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/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc';
-- 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
-- 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 '/u01/app/oracle/oradata/oracl/temp01.dbf'
SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-- End of tempfile additions.
--
5.从备份控制文件中提取我们需要的部分,这里我们选择RESETLOGS,将如下内容保存文件为
create_confile.sql
CREATE CONTROLFILE REUSE DATABASE "ORACL" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/oracl/redo01.log' SIZE 50M,
GROUP 2 '/u01/app/oracle/oradata/oracl/redo02.log' SIZE 50M,
GROUP 3 '/u01/app/oracle/oradata/oracl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/oracl/system01.dbf',
'/u01/app/oracle/oradata/oracl/undotbs01.dbf',
'/u01/app/oracle/oradata/oracl/sysaux01.dbf',
'/u01/app/oracle/oradata/oracl/users01.dbf'
CHARACTER SET WE8ISO8859P1
;
6.执行create_confile.sql
SQL>set sqlblanklines on -- 因为文件中有空行,需要将该选项打开,否则执行的时候报语法错误
SQL>@/u01/ftp/create_confile.sql
SQL> alter database open resetlogs;
Database altered.
说明:
重建控制文件后,若备份信息是存储在控制文件的,该信息会丢失.