rebuild controlfile

本文介绍如何在Oracle数据库中备份和重建控制文件。通过SQL命令备份控制文件到跟踪文件,并从跟踪文件中获取重建控制文件所需的SQL脚本。文章详细展示了两种情况下的重建过程:当在线redo日志可用时使用NORESETLOGS选项打开数据库,以及在线redo日志丢失时使用RESETLOGS选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 以sysdba登陆,导出控制文件

Sql代码 复制代码
  1. alter database backup controlfile to trace;  
alter database backup controlfile to trace;

 

2. 在%oracle_base%/oradata/%oracle_sid%/udump下找到刚刚创建的trc文件,打开它。可以看到里面包含了两段sql脚本。

Sql代码 复制代码
  1. -- Below are two sets of SQL statements, each of which creates a new   
  2. -- control file and uses it to open the database. The first set opens   
  3. -- the database with the NORESETLOGS option and should be used only if   
  4. -- the current versions of all online logs are available. The second   
  5. -- set opens the database with the RESETLOGS option and should be used   
  6. -- if online logs are unavailable.   
  7. -- The appropriate set of statements can be copied from the trace into   
  8. -- a script file, edited as necessary, and executed when there is a   
  9. -- need to re-create the control file.   
  10. --   
  11. --     Set #1. NORESETLOGS case   
  12. --   
  13. -- The following commands will create a new control file and use it   
  14. -- to open the database.   
  15. -- Data used by Recovery Manager will be lost.   
  16. -- Additional logs may be required for media recovery of offline   
  17. -- Use this only if the current versions of all online logs are   
  18. -- available.   
  19. -- After mounting the created controlfile, the following SQL   
  20. -- statement will place the database in the appropriate   
  21. -- protection mode:   
  22. --  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE   
  23. STARTUP NOMOUNT   
  24. CREATE CONTROLFILE REUSE DATABASE "EPCIT" NORESETLOGS  ARCHIVELOG   
  25.     MAXLOGFILES 16   
  26.     MAXLOGMEMBERS 3   
  27.     MAXDATAFILES 100   
  28.     MAXINSTANCES 8   
  29.     MAXLOGHISTORY 454   
  30. LOGFILE   
  31.   GROUP 1 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITREDO01.LOG'  SIZE 10M,   
  32.   GROUP 2 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITREDO02.LOG'  SIZE 10M,   
  33.   GROUP 3 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITREDO03.LOG'  SIZE 10M   
  34. -- STANDBY LOGFILE   
  35. DATAFILE   
  36.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITSYSTEM01.DBF',   
  37.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITUNDOTBS01.DBF',   
  38.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITSYSAUX01.DBF',   
  39.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITBLOBS01.DBF',   
  40.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITINDEX01.DBF',   
  41.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITUSERS01.DBF',   
  42.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITWCAUDIT01.DBF'  
  43. CHARACTER SET UTF8   
  44. ;   
  45. -- Configure RMAN configuration record 1   
  46. VARIABLE RECNO NUMBER;   
  47. EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CHANNEL','DEVICE TYPE DISK MAXPIECESIZE 100 M');   
  48. -- Configure RMAN configuration record 3   
  49. VARIABLE RECNO NUMBER;   
  50. EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');   
  51. -- Configure RMAN configuration record 4   
  52. VARIABLE RECNO NUMBER;   
  53. EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('BACKUP OPTIMIZATION','ON');   
  54. -- Configure RMAN configuration record 5   
  55. VARIABLE RECNO NUMBER;   
  56. EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('DEVICE TYPE','DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 1');   
  57. -- Commands to re-create incarnation table   
  58. -- Below log names MUST be changed to existing filenames on   
  59. -- disk. Any one log file from each branch can be used to   
  60. -- re-create incarnation records.   
  61. -- ALTER DATABASE REGISTER LOGFILE 'D:/ORACLE/FLASH_RECOVERY_AREA/EPCIT/ARCHIVELOG/2009_02_22/O1_MF_1_1_%U_.ARC';   
  62. -- Recovery is required if any of the datafiles are restored backups,   
  63. -- or if the last shutdown was not normal or immediate.   
  64. RECOVER DATABASE  
  65. -- All logs need archiving and a log switch is needed.   
  66. ALTER SYSTEM ARCHIVE LOG ALL;   
  67. -- Database can now be opened normally.   
  68. ALTER DATABASE OPEN;   
  69. -- Commands to add tempfiles to temporary tablespaces.   
  70. -- Online tempfiles have complete space information.   
  71. -- Other tempfiles may require adjustment.   
  72. ALTER TABLESPACE TEMP ADD TEMPFILE 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITTEMP01.DBF'  
  73.      SIZE 209715200  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;   
  74. -- End of tempfile additions.   
  75. --   
  76. --     Set #2. RESETLOGS case   
  77. --   
  78. -- The following commands will create a new control file and use it   
  79. -- to open the database.   
  80. -- Data used by Recovery Manager will be lost.   
  81. -- The contents of online logs will be lost and all backups will   
  82. -- be invalidated. Use this only if online logs are damaged.   
  83. -- After mounting the created controlfile, the following SQL   
  84. -- statement will place the database in the appropriate   
  85. -- protection mode:   
  86. --  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE   
  87. STARTUP NOMOUNT   
  88. CREATE CONTROLFILE REUSE DATABASE "EPCIT" RESETLOGS  ARCHIVELOG   
  89.     MAXLOGFILES 16   
  90.     MAXLOGMEMBERS 3   
  91.     MAXDATAFILES 100   
  92.     MAXINSTANCES 8   
  93.     MAXLOGHISTORY 454   
  94. LOGFILE   
  95.   GROUP 1 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITREDO01.LOG'  SIZE 10M,   
  96.   GROUP 2 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITREDO02.LOG'  SIZE 10M,   
  97.   GROUP 3 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITREDO03.LOG'  SIZE 10M   
  98. -- STANDBY LOGFILE   
  99. DATAFILE   
  100.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITSYSTEM01.DBF',   
  101.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITUNDOTBS01.DBF',   
  102.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITSYSAUX01.DBF',   
  103.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITBLOBS01.DBF',   
  104.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITINDEX01.DBF',   
  105.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITUSERS01.DBF',   
  106.   'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITWCAUDIT01.DBF'  
  107. CHARACTER SET UTF8   
  108. ;   
  109. -- Configure RMAN configuration record 1   
  110. VARIABLE RECNO NUMBER;   
  111. EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CHANNEL','DEVICE TYPE DISK MAXPIECESIZE 100 M');   
  112. -- Configure RMAN configuration record 3   
  113. VARIABLE RECNO NUMBER;   
  114. EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');   
  115. -- Configure RMAN configuration record 4   
  116. VARIABLE RECNO NUMBER;   
  117. EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('BACKUP OPTIMIZATION','ON');   
  118. -- Configure RMAN configuration record 5   
  119. VARIABLE RECNO NUMBER;   
  120. EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('DEVICE TYPE','DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 1');   
  121. -- Commands to re-create incarnation table   
  122. -- Below log names MUST be changed to existing filenames on   
  123. -- disk. Any one log file from each branch can be used to   
  124. -- re-create incarnation records.   
  125. -- ALTER DATABASE REGISTER LOGFILE 'D:/ORACLE/FLASH_RECOVERY_AREA/EPCIT/ARCHIVELOG/2009_02_22/O1_MF_1_1_%U_.ARC';   
  126. -- Recovery is required if any of the datafiles are restored backups,   
  127. -- or if the last shutdown was not normal or immediate.   
  128. RECOVER DATABASE USING BACKUP CONTROLFILE   
  129. -- Database can now be opened zeroing the online logs.   
  130. ALTER DATABASE OPEN RESETLOGS;   
  131. -- Commands to add tempfiles to temporary tablespaces.   
  132. -- Online tempfiles have complete space information.   
  133. -- Other tempfiles may require adjustment.   
  134. ALTER TABLESPACE TEMP ADD TEMPFILE 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITTEMP01.DBF'  
  135.      SIZE 209715200  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;   
  136. -- End of tempfile additions.  
-- 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 "EPCIT" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 454
LOGFILE
  GROUP 1 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITREDO01.LOG'  SIZE 10M,
  GROUP 2 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITREDO02.LOG'  SIZE 10M,
  GROUP 3 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITREDO03.LOG'  SIZE 10M
-- STANDBY LOGFILE
DATAFILE
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITSYSTEM01.DBF',
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITUNDOTBS01.DBF',
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITSYSAUX01.DBF',
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITBLOBS01.DBF',
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITINDEX01.DBF',
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITUSERS01.DBF',
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITWCAUDIT01.DBF'
CHARACTER SET UTF8
;
-- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CHANNEL','DEVICE TYPE DISK MAXPIECESIZE 100 M');
-- Configure RMAN configuration record 3
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');
-- Configure RMAN configuration record 4
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('BACKUP OPTIMIZATION','ON');
-- Configure RMAN configuration record 5
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('DEVICE TYPE','DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 1');
-- 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 'D:/ORACLE/FLASH_RECOVERY_AREA/EPCIT/ARCHIVELOG/2009_02_22/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 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITTEMP01.DBF'
     SIZE 209715200  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 "EPCIT" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 454
LOGFILE
  GROUP 1 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITREDO01.LOG'  SIZE 10M,
  GROUP 2 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITREDO02.LOG'  SIZE 10M,
  GROUP 3 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITREDO03.LOG'  SIZE 10M
-- STANDBY LOGFILE
DATAFILE
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITSYSTEM01.DBF',
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITUNDOTBS01.DBF',
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITSYSAUX01.DBF',
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITBLOBS01.DBF',
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITINDEX01.DBF',
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITUSERS01.DBF',
  'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITWCAUDIT01.DBF'
CHARACTER SET UTF8
;
-- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CHANNEL','DEVICE TYPE DISK MAXPIECESIZE 100 M');
-- Configure RMAN configuration record 3
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');
-- Configure RMAN configuration record 4
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('BACKUP OPTIMIZATION','ON');
-- Configure RMAN configuration record 5
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('DEVICE TYPE','DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 1');
-- 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 'D:/ORACLE/FLASH_RECOVERY_AREA/EPCIT/ARCHIVELOG/2009_02_22/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 'D:/PTC/OCU_8.0/ORADATA/EPCIT/EPCITTEMP01.DBF'
     SIZE 209715200  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
-- End of tempfile additions.

 

第一段sql是在所有online redolog没有丢失,以noresetlogs选项打开数据库的情况下使用的。第二段则是在丢失了online redolog需要resetlogs的情况下使用。

 

3. 把"Set #1. NORESETLOGS case"下的sql拷贝出来,存为reCreateCtl.sql

 

4. 以sysdba登陆,shutdown immediate。然后删除所有控制文件。再运行reCreateCtl.sql。

Sql代码 复制代码
  1. SQL> @reCreateCtl   
  2. ORACLE instance started.   
  3.   
  4. Total System Global Area  251658240 bytes   
  5. Fixed Size                  1248356 bytes   
  6. Variable Size              83887004 bytes   
  7. Database Buffers          159383552 bytes   
  8. Redo Buffers                7139328 bytes   
  9.   
  10. Control file created.   
  11. PL/SQL procedure successfully completed.   
  12. PL/SQL procedure successfully completed.   
  13. PL/SQL procedure successfully completed.   
  14. PL/SQL procedure successfully completed.   
  15.   
  16. ORA-00283: recovery session canceled due to errors   
  17. ORA-00264: no recovery required   
  18.   
  19. System altered.   
  20. Database altered.   
  21. Tablespace altered.  
SQL> @reCreateCtl
ORACLE instance started.

Total System Global Area  251658240 bytes
Fixed Size                  1248356 bytes
Variable Size              83887004 bytes
Database Buffers          159383552 bytes
Redo Buffers                7139328 bytes

Control file created.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.

ORA-00283: recovery session canceled due to errors
ORA-00264: no recovery required

System altered.
Database altered.
Tablespace altered.

 

5. 成功创建了控制文件,数据库也正常打开。再没有使用Recovery Catalog的情况下,RMAN的备份资料是存在控制文件中的,重建控制文件会导致丢失备份资料库。

 

 

 

 

from:http://logicgate.javaeye.com/blog/336705

 

http://www.itpub.net/thread-188958-1-1.html

 

http://www.eygle.com/faq/How.To.Backup.and.Recreate.Controlfile.htm

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值