三.转储控制文件:由于控制文件是个二进制文件,无法直接打开查阅,但
是通过上一章介绍的如下命令可以将控制文件内容转储出来便于查看:
alter session set events 'immediate trace name controlf level 12';
以下是来自Oracle Database 11g的转储测试:
SQL> alter session set events 'immediate trace name controlf level 12';
Session altered.
#备份控制文件到trace文件中
SQL> alter database backup controlfile to trace;
Database altered.
SQL> select value from v$diag_info where name='Default Trace File';
VALUE
--------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_4929.trc
注意:从11g 开始,可以通过v$diag_info 获得当前会话转储文件的名称。
四.控制文件检查数据库的一致性: 1.控制文件中记录了数据库系统scn号、数据文件scn号与数据文件头列里的开始scn号,如果这三个scn号一致说明数据库可以启动。如果不一致就要恢复。
#系统scn号
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
469717
#文件scn号
SQL> select checkpoint_change# from v$datafile;
2.scn号与时间的转换:
#全局检查点
SQL> alter system checkpoint;
System altered.
#创建一个函数
SQL> create or replace
function scn_to_timestamp(query_scn in NUMBER)
return TIMESTAMP
IS EXTERNAL
NAME "ktfexscntot"
WITH CONTEXT
PARAMETERS (context ,query_scn OCINUMBER,RETURN)
LIBRARY DBMS_TRAN_LIB;
/ 2 3 4 5 6 7 8 9
Function created.
#系统scn
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
473363
#scn转成时间
SQL> select scn_to_timestamp(473363) from dual;
SCN_TO_TIMESTAMP(473363)
---------------------------------------------------------------------------
16-JUN-14 06.16.14.000000000 AM
#时间转成scn
SQL> select timestamp_to_scn('16-JUN-14 06.16.14.000000000 AM') from dual;
--减少控制文件
SQL> alter system set control_files='/opt/oracle/oradata/orcl/control01.ctl' scope=spfile;
System altered.
或者
--增加控制文件:
SQL> alter system set control_files='/opt/oracle/oradata/orcl/control01.ctl',
'/opt/oracle/oradata/orcl/control02.ctl',
'/opt/oracle/oradata/orcl/control03.ctl' scope=spfile;
Total System Global Area 418484224 bytes
Fixed Size 1336932 bytes
Variable Size 276826524 bytes
Database Buffers 134217728 bytes
Redo Buffers 6103040 bytes
ORA-00205: error in identifying control file, check alert log for more info
②.查看告警日志:报错
ALTER DATABASE MOUNT
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/oradata/prod/disk3/control01.ctl'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/oradata/prod/disk2/control01.ctl'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/oradata/prod/disk1/control01.ctl'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Mon Jun 16 15:16:04 2014
Checker run found 2 new persistent data failures
ORA-205 signalled during: ALTER DATABASE MOUNT...
③.找trace 文件中的一句话(在trace 文件的最后),进行重建控制文件。 注意:这里的PROD是db_name .
CREATE CONTROLFILE REUSE DATABASE "PROD" NORESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 2
MAXDATAFILES 30
MAXINSTANCES 1
MAXLOGHISTORY 292
LOGFILE
GROUP 1 (
'/u01/app/oracle/oradata/prod/disk1/redo01.log',
'/u01/app/oracle/oradata/prod/disk2/redo01.log'
) SIZE 100M BLOCKSIZE 512,
GROUP 2 (
'/u01/app/oracle/oradata/prod/disk1/redo02.log',
'/u01/app/oracle/oradata/prod/disk2/redo02.log'
) SIZE 100M BLOCKSIZE 512,
GROUP 3 (
'/u01/app/oracle/oradata/prod/disk1/redo03.log',
'/u01/app/oracle/oradata/prod/disk2/redo03.log'
) SIZE 100M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/prod/disk3/system01.dbf',
'/u01/app/oracle/oradata/prod/disk3/sysaux01.dbf',
'/u01/app/oracle/oradata/prod/disk3/undotbs01.dbf',
'/u01/app/oracle/oradata/prod/disk3/users01.dbf'
CHARACTER SET AL32UTF8
;
在nomount执行上面的重建控制文件语句。
③.启动数据库到open状态,
SQL> alter database open;
Database altered.
查看表空间的信息
SQL> select tablespace_name ,contents from dba_tablespaces;