6.重建控制文件打开数据库
重建控制文件方法如下:
A,确定控制文件,重做日志文件,数据文件位置(A某些情况下需要);
select * from v$controlfile;
select * from v$logfile;
select file#,name from v$datafile;
B,生成可以重建控制文件的脚本
alter database backup controlfile to trace;
C,获取trc文件位置的脚本
SELECT d.VALUE
|| '/'
|| LOWER (RTRIM (i.INSTANCE, CHR (0)))
|| '_ora_'
|| p.spid
|| '.trc' trace_file_name
FROM (SELECT p.spid
FROM v$mystat m, v$session s, v$process p
WHERE m.statistic# = 1 AND s.SID = m.SID AND p.addr = s.paddr) p,
(SELECT t.INSTANCE
FROM v$thread t, v$parameter v
WHERE v.NAME = 'thread'
AND (v.VALUE = 0 OR t.thread# = TO_NUMBER (v.VALUE))) i,
(SELECT VALUE
FROM v$parameter
WHERE NAME = 'user_dump_dest') d
/
D,查看trc文件内容
[Oracle@orcl admin]$ cat /home/oracle/admin/orcl/udump/orcl_ora_10202.trc
/home/oracle/admin/orcl/udump/orcl_ora_10202.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
ORACLE_HOME = /home/oracle/oracle
System name: Linux
Node name: orcl
Release: 2.6.18-164.el5
Version: #1 SMP Tue Aug 18 15:51:54 EDT 2009
Machine: i686
Instance name: orcl
Redo thread mounted by this instance: 1
Oracle process number: 15
Unix process pid: 10202, image: oracle@orcl (TNS V1-V3)
*** SERVICE NAME:(SYS$USERS) 2012-05-27 12:14:16.466
*** SESSION ID:(159.3) 2012-05-27 12:14:16.466
*** 2012-05-27 12:14:16.466
-- 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=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 "ORCL" NORESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/oradata/orcl/redo01.log' SIZE 50M,
GROUP 2 '/home/oracle/oradata/orcl/redo02.log' SIZE 50M,
GROUP 3 '/home/oracle/oradata/orcl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/home/oracle/oradata/orcl/system01.dbf',
'/home/oracle/oradata/orcl/undotbs01.dbf',
'/home/oracle/oradata/orcl/sysaux01.dbf',
'/home/oracle/oradata/orcl/users01.dbf',
'/home/oracle/oradata/orcl/example01.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 '/home/oracle/flash_recovery_area/ORCL/archivelog/2012_05_27/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/flash_recovery_area/ORCL/archivelog/2012_05_27/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
-- 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 '/home/oracle/oradata/orcl/temp01.dbf'
SIZE 22020096 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 "ORCL" RESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/oradata/orcl/redo01.log' SIZE 50M,
GROUP 2 '/home/oracle/oradata/orcl/redo02.log' SIZE 50M,
GROUP 3 '/home/oracle/oradata/orcl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/home/oracle/oradata/orcl/system01.dbf',
'/home/oracle/oradata/orcl/undotbs01.dbf',
'/home/oracle/oradata/orcl/sysaux01.dbf',
'/home/oracle/oradata/orcl/users01.dbf',
'/home/oracle/oradata/orcl/example01.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 '/home/oracle/flash_recovery_area/ORCL/archivelog/2012_05_27/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/flash_recovery_area/ORCL/archivelog/2012_05_27/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 '/home/oracle/oradata/orcl/temp01.dbf'
SIZE 22020096 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-- End of tempfile additions.
E,获取创建控制文件的脚本,根据数据库不同状况,可以选择是使用RESETLOGS(没有重做日志的情况)/NORESETLOGS(有重做日志的情况)来重建控制文件,下面为NORESETLOGS.
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/oradata/orcl/redo01.log' SIZE 50M,
GROUP 2 '/home/oracle/oradata/orcl/redo02.log' SIZE 50M,
GROUP 3 '/home/oracle/oradata/orcl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/home/oracle/oradata/orcl/system01.dbf',
'/home/oracle/oradata/orcl/undotbs01.dbf',
'/home/oracle/oradata/orcl/sysaux01.dbf',
'/home/oracle/oradata/orcl/users01.dbf',
'/home/oracle/oradata/orcl/example01.dbf'
CHARACTER SET WE8ISO8859P1;
RECOVER DATABASE
ALTER DATABASE OPEN;
ALTER TABLESPACE TEMP ADD TEMPFILE '/home/oracle/oradata/orcl/temp01.dbf'
SIZE 22020096 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
F,运行脚本重建控制文件
SQL> set echo on
SQL> STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/oradata/orcl/redo01.log' SIZE 50M,
GROUP 2 '/home/oracle/oradata/orcl/redo02.log' SIZE 50M,
GROUP 3 '/home/oracle/oradata/orcl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/home/oracle/oradata/orcl/system01.dbf',
'/home/oracle/oradata/orcl/undotbs01.dbf',
'/home/oracle/oradata/orcl/sysaux01.dbf',
'/home/oracle/oradata/orcl/users01.dbf',
'/home/oracle/oradata/orcl/example01.dbf'
CHARACTER SET WE8ISO8859P1;
RECOVER DATABASE
ALTER DATABASE OPEN;
ALTER TABLESPACE TEMP ADD TEMPFILE '/home/oracle/oradata/orcl/temp01.dbf'
SIZE 22020096 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 71305460 bytes
Database Buffers 92274688 bytes
Redo Buffers 2973696 bytes
SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Control file created.
SQL> Media recovery complete.
SQL>
Database altered.
SQL> 2
Tablespace altered.
更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
