控制文件损坏或者丢失的Oracle 10g数据库恢复控制文件一例

 

如果控制文件丢失或者损坏了,如何解决这个问题?

查看参数文件中的设置:

SQL> show parameter CONTROL_FILES ;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      C:\ORACLE\PRODUCT\10.2.0\ORADA
                                                 TA\KEYMEN\CONTROL01.CTL, C:\OR
                                                 ACLE\PRODUCT\10.2.0\ORADATA\KE
                                                 YMEN\CONTROL02.CTL, C:\ORACLE\
                                                 PRODUCT\10.2.0\ORADATA\KEYMEN\
                                                 CONTROL03.CTL
SQL>


查看Oracle数据库的动态性能视图

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------
----------------------------------------
C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\CONTROL01.CTL
C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\CONTROL02.CTL
C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\CONTROL03.CTL


Backing Up Control Files
Use the ALTER DATABASE BACKUP CONTROLFILE statement to back up your control files. You have two options:

Back up the control file to a binary file (duplicate of existing control file) using the following statement:

ALTER DATABASE BACKUP CONTROLFILE TO 'E:\oraclebackup\control.bkp';

Produce SQL statements that can later be used to re-create your control file:

ALTER DATABASE BACKUP CONTROLFILE TO TRACE;

This command writes a SQL script to the database trace file where it can be captured and edited to reproduce the control file.

 

-----------------------------------------------------------------------------

******************************************************************************

实验一:删除控制文件,仅仅保留一个控制文件
******************************************************************************

编辑C:\oracle\product\10.2.0\admin\keymen\pfile\init.ora 文件,仅仅在
###########################################
# File Configuration
###########################################
control_files=("c:\oracle\product\10.2.0\oradata\keymen\control01.ctl")
db_recovery_file_dest=c:\oracle\product\10.2.0/flash_recovery_area
db_recovery_file_dest_size=2147483648

SQL> shutdown immediate;
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup open pfile='C:\oracle\product\10.2.0\admin\keymen\pfile\init.ora';
ORACLE instance started.

Total System Global Area  612368384 bytes
Fixed Size                  1250428 bytes
Variable Size             167775108 bytes
Database Buffers          436207616 bytes
Redo Buffers                7135232 bytes
数据库装载完毕。
数据库已经打开。
SQL>

SQL> show parameter CONTROL_FILES ;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      C:\ORACLE\PRODUCT\10.2.0\ORADA
                                                 TA\KEYMEN\CONTROL01.CTL
SQL>


Oracle数据库从Oracle9i开始(当然也包括Oracle10g),数据库在启动时,首先会自动寻找SPFILE,从而读取SPFILE
中的参数,用于startup数据库。当SPFILE文件丢失或者损坏时,Oracle会找PFILE文件启动数据库。

如果PFILE文件也丢失或者损坏了,那么数据库就彻底启动不了了。


如果需要指定数据库使用PFILE文件,而不是使用SPFILE文件,则需要
startup open pfile='C:\oracle\product\10.2.0\admin\keymen\pfile\init.ora';

*********************************************************************************

实验二:删除所有控制文件,
*********************************************************************************
SQL> shutdown immediate;
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL>

通过操作系统命令,删除所有控制文件

SQL> startup
ORACLE 例程已经启动。

Total System Global Area  612368384 bytes
Fixed Size                  1250428 bytes
Variable Size             226495364 bytes
Database Buffers          377487360 bytes
Redo Buffers                7135232 bytes
ORA-00205: ?????????, ??????, ???????

SQL> alter session set nls_language='AMERICAN';

Session altered.

SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-00205: error in identifying control file, check alert log for more info


在NOMOUNT状态下,利用控制文件的追踪文件中的SQL Statement重新创建控制文件。
目前数据库的状态仅仅是控制文件丢失,日志文件都也用。


SQL> CREATE CONTROLFILE REUSE DATABASE "KEYMEN" NORESETLOGS  ARCHIVELOG
  2      MAXLOGFILES 16
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 100
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 292
  7  LOGFILE
  8    GROUP 1 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\REDO01.LOG'  SIZE 50M,
  9    GROUP 2 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\REDO02.LOG'  SIZE 50M,
 10    GROUP 3 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\REDO03.LOG'  SIZE 50M
 11  -- STANDBY LOGFILE
 12  DATAFILE
 13    'C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\SYSTEM01.DBF',
 14    'C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\UNDOTBS01.DBF',
 15    'C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\SYSAUX01.DBF',
 16    'C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\USERS01.DBF',
 17    'C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\EXAMPLE01.DBF',
 18    'C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\TESTTBS1.DBF'
 19  CHARACTER SET ZHS16GBK
 20  ;

Control file created.

SQL> -- Commands to re-create incarnation table
SQL> -- Below log names MUST be changed to existing filenames on
SQL> -- disk. Any one log file from each branch can be used to
SQL> -- re-create incarnation records.
SQL> -- ALTER DATABASE REGISTER LOGFILE 'C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\KEYMEN\ARCHIV
0_06\O1_MF_1_1_%U_.ARC';
SQL> -- ALTER DATABASE REGISTER LOGFILE 'C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\KEYMEN\ARCHIV
0_06\O1_MF_1_1_%U_.ARC';
SQL> -- ALTER DATABASE REGISTER LOGFILE 'C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\KEYMEN\ARCHIV
0_06\O1_MF_1_1_%U_.ARC';
SQL> -- ALTER DATABASE REGISTER LOGFILE 'C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\KEYMEN\ARCHIV
0_06\O1_MF_1_1_%U_.ARC';
SQL> -- ALTER DATABASE REGISTER LOGFILE 'C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\KEYMEN\ARCHIV
0_06\O1_MF_1_1_%U_.ARC';
SQL> -- Recovery is required if any of the datafiles are restored backups,
SQL> -- or if the last shutdown was not normal or immediate.
SQL> RECOVER DATABASE
ORA-00283: recovery session canceled due to errors
ORA-00264: no recovery required


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

System altered.

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

Database altered.

SQL> -- Commands to add tempfiles to temporary tablespaces.
SQL> -- Online tempfiles have complete space information.
SQL> -- Other tempfiles may require adjustment.
SQL> ALTER TABLESPACE TEMP ADD TEMPFILE 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\KEYMEN\TEMP01.DBF'
  2       SIZE 20971520  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;

Tablespace altered.

SQL> select open_mode from v$database;

OPEN_MODE
----------
READ WRITE

重新创建了控制文件,而且数据库的状态完好。数据没有丢失,所有的日志文件都可用。
下一步立刻使用RMAN进行全库的备份。

你可能感兴趣的:(控制文件损坏或者丢失的Oracle 10g数据库恢复控制文件一例)