一、重建控制文件
--跟踪当前会话
SQL> oradebug setmypid
Statement processed.
--生成控制文件脚本
SQL> alter database backup controlfile to trace;
Database altered.
--获取trace文件位置
SQL> oradebug tracefile_name;
/u01/app/oracle/diag/rdbms/orcl_st/ORCL/trace/ORCL_ora_5736.trc
--查看控制文件内容
SQL> !cat /u01/app/oracle/diag/rdbms/orcl_st/ORCL/trace/ORCL_ora_5736.trc
Trace file /u01/app/oracle/diag/rdbms/orcl_st/ORCL/trace/ORCL_ora_5736.trc
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1
System name: Linux
Node name: dg1
Release: 3.8.13-16.2.1.el6uek.x86_64
Version: #1 SMP Thu Nov 7 17:01:44 PST 2013
Machine: x86_64
Instance name: ORCL
Redo thread mounted by this instance: 1
Oracle process number: 19
Unix process pid: 5736, image: oracle@dg1 (TNS V1-V3)
*** 2016-07-21 14:48:22.503
*** SESSION ID:(1.5) 2016-07-21 14:48:22.503
*** CLIENT ID:() 2016-07-21 14:48:22.503
*** SERVICE NAME:(SYS$USERS) 2016-07-21 14:48:22.503
*** MODULE NAME:(sqlplus@dg1 (TNS V1-V3)) 2016-07-21 14:48:22.503
*** ACTION NAME:() 2016-07-21 14:48:22.503
KQRCMT: Write failed with error=604 po=0x918420c8 cid=0
diagnostics : cid=0 hash=6b2bf49b flag=26
*** 2016-07-21 15:00:08.438
Processing Oradebug command 'setmypid'
*** 2016-07-21 15:00:08.446
Oradebug command 'setmypid' console output: <none>
*** 2016-07-21 15:00:45.907
-- 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.arc
--
-- DB_UNIQUE_NAME="orcl_st"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE'
-- LOG_ARCHIVE_CONFIG='DG_CONFIG=("orcl_pd")'
-- LOG_ARCHIVE_MAX_PROCESSES=4
-- STANDBY_FILE_MANAGEMENT=auto
-- STANDBY_ARCHIVE_DEST=?/dbs/arch
-- FAL_CLIENT=''
-- FAL_SERVER=orcl_pd
--
-- LOG_ARCHIVE_DEST_2='SERVICE=orcl_st'
-- LOG_ARCHIVE_DEST_2='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_2='LGWR NOAFFIRM NOEXPEDITE NOVERIFY ASYNC=61440'
-- LOG_ARCHIVE_DEST_2='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_2='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED'
-- LOG_ARCHIVE_DEST_2='DB_UNIQUE_NAME=orcl_pd'
-- LOG_ARCHIVE_DEST_2='VALID_FOR=(STANDBY_LOGFILE,STANDBY_ROLE)'
-- LOG_ARCHIVE_DEST_STATE_2=ENABLE
--
-- LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/oradata/orcl/archivelog'
-- LOG_ARCHIVE_DEST_1='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_1='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED'
-- LOG_ARCHIVE_DEST_1='DB_UNIQUE_NAME=orcl_st'
-- LOG_ARCHIVE_DEST_1='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_1=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.
-- WARNING! The current control file needs to be checked against
-- the datafiles to insure it contains the correct files. The
-- commands printed here may be missing log and/or data files.
-- Another report should be made after the database has been
-- successfully opened.
-- 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 FORCE LOGGING ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_1_c94vggms_.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_2_c94vgk0c_.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_3_c94vglyx_.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
-- GROUP 4 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_4_c94vgn8t_.log' SIZE 50M BLOCKSIZE 512,
-- GROUP 5 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_5_c94vgpsq_.log' SIZE 50M BLOCKSIZE 512,
-- GROUP 6 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_6_c94vgrd0_.log' SIZE 50M BLOCKSIZE 512,
-- GROUP 7 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_7_c94vgssm_.log' SIZE 50M BLOCKSIZE 512
DATAFILE
'/u01/app/oracle/oradata/orcl/system01.dbf',
'/u01/app/oracle/oradata/orcl/sysaux01.dbf',
'/u01/app/oracle/oradata/orcl/undotbs01.dbf',
'/u01/app/oracle/oradata/orcl/users01.dbf',
'/u01/app/oracle/oradata/orcl/example01.dbf'
CHARACTER SET WE8MSWIN1252
;
-- 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/oradata/orcl/archivelog/1_1_824297850.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/oradata/orcl/archivelog/1_1_898987193.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/orcl/temp01.dbf'
SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-- End of tempfile additions.
--
--
--
----------------------------------------------------------
-- The following script can be used on the standby database
-- to re-populate entries for a standby controlfile created
-- on the primary and copied to the standby site.
----------------------------------------------------------
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_4_c94vgn8t_.log'
SIZE 50M BLOCKSIZE 512 REUSE;
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_5_c94vgpsq_.log'
SIZE 50M BLOCKSIZE 512 REUSE;
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_6_c94vgrd0_.log'
SIZE 50M BLOCKSIZE 512 REUSE;
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_7_c94vgssm_.log'
SIZE 50M BLOCKSIZE 512 REUSE;
-- Registering these archivelog entries will help rebuild
-- information displayed by the V$ARCHIVED_LOG fixed view
-- 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.
-- WARNING! The current control file needs to be checked against
-- the datafiles to insure it contains the correct files. The
-- commands printed here may be missing log and/or data files.
-- Another report should be made after the database has been
-- successfully opened.
-- 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 FORCE LOGGING ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_1_c94vggms_.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_2_c94vgk0c_.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_3_c94vglyx_.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/orcl/system01.dbf',
'/u01/app/oracle/oradata/orcl/sysaux01.dbf',
'/u01/app/oracle/oradata/orcl/undotbs01.dbf',
'/u01/app/oracle/oradata/orcl/users01.dbf',
'/u01/app/oracle/oradata/orcl/example01.dbf'
CHARACTER SET WE8MSWIN1252
;
-- 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/oradata/orcl/archivelog/1_1_824297850.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/oradata/orcl/archivelog/1_1_898987193.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
-- Create log files for threads other than thread one.
;
-- 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/orcl/temp01.dbf'
SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-- End of tempfile additions.
--
--
--
----------------------------------------------------------
-- The following script can be used on the standby database
-- to re-populate entries for a standby controlfile created
-- on the primary and copied to the standby site.
----------------------------------------------------------
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_4_c94vgn8t_.log'
SIZE 50M BLOCKSIZE 512 REUSE;
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_5_c94vgpsq_.log'
SIZE 50M BLOCKSIZE 512 REUSE;
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_6_c94vgrd0_.log'
SIZE 50M BLOCKSIZE 512 REUSE;
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_7_c94vgssm_.log'
SIZE 50M BLOCKSIZE 512 REUSE;
-- Registering these archivelog entries will help rebuild
-- information displayed by the V$ARCHIVED_LOG fixed view
*** 2016-07-21 15:23:14.185
Processing Oradebug command 'tracefile_name'
*** 2016-07-21 15:23:14.185
Oradebug command 'tracefile_name' console output:
/u01/app/oracle/diag/rdbms/orcl_st/ORCL/trace/ORCL_ora_5736.trc
--使用noresetlogs 模式重建数据文件
上面的控制文件内容介绍resetlogs和norestlogs 模式重建数据文件的说明
SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS FORCE LOGGING ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_1_c94vggms_.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_2_c94vgk0c_.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_3_c94vglyx_.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
-- GROUP 4 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_4_c94vgn8t_.log' SIZE 50M BLOCKSIZE 512,
-- GROUP 5 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_5_c94vgpsq_.log' SIZE 50M BLOCKSIZE 512,
-- GROUP 6 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_6_c94vgrd0_.log' SIZE 50M BLOCKSIZE 512,
-- GROUP 7 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_7_c94vgssm_.log' SIZE 50M BLOCKSIZE 512
DATAFILE
'/u01/app/oracle/oradata/orcl/system01.dbf',
'/u01/app/oracle/oradata/orcl/sysaux01.dbf',
'/u01/app/oracle/oradata/orcl/undotbs01.dbf',
'/u01/app/oracle/oradata/orcl/users01.dbf',
'/u01/app/oracle/oradata/orcl/example01.dbf'
CHARACTER SET WE8MSWIN1252
23 ;
CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS FORCE LOGGING ARCHIVELOG
*
ERROR at line 1:
ORA-01503: CREATE CONTROLFILE failed
ORA-01192: must have at least one enabled thread
出现上面的原因是因为我没有删除数据库的控制文件做的实验,如果删除数据库的控制文件,上面的操作可以成功如下:
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 541068368 bytes
Database Buffers 289406976 bytes
Redo Buffers 2371584 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS FORCE LOGGING ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_1_c94vggms_.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_2_c94vgk0c_.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_3_c94vglyx_.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
-- GROUP 4 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_4_c94vgn8t_.log' SIZE 50M BLOCKSIZE 512,
-- GROUP 5 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_5_c94vgpsq_.log' SIZE 50M BLOCKSIZE 512,
-- GROUP 6 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_6_c94vgrd0_.log' SIZE 50M BLOCKSIZE 512,
-- GROUP 7 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_7_c94vgssm_.log' SIZE 50M BLOCKSIZE 512
DATAFILE
'/u01/app/oracle/oradata/orcl/system01.dbf',
'/u01/app/oracle/oradata/orcl/sysaux01.dbf',
'/u01/app/oracle/oradata/orcl/undotbs01.dbf',
'/u01/app/oracle/oradata/orcl/users01.dbf',
'/u01/app/oracle/oradata/orcl/example01.dbf'
CHARACTER SET WE8MSWIN1252
23 ;
Control file created.
SQL> alter database open;
Database altered.
--我们重建数据文件之后要添加temp表空间,虽然我们从dba_tablespaces视图里可以查看到temp 表空间,但是该表空确实没有数据文件的,我们需要手动添加。
SQL> select * from v$tempfile;no rows selected
SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf' SIZE 100m REUSE AUTOEXTEND ON NEXT 10m MAXSIZE 1000M;
Tablespace altered.
SQL> select * from v$tempfile;
FILE# CREATION_CHANGE# CREATION_ TS# RFILE# STATUS ENABLED BYTES BLOCKS CREATE_BYTES BLOCK_SIZE
---------- ---------------- --------- ---------- ---------- ------- ---------- ---------- ---------- ------------ ----------
NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 1012045 21-JUL-16 3 1 ONLINE READ WRITE 104857600 12800 104857600 8192
/u01/app/oracle/oradata/orcl/temp01.dbf
--解决方法使用resetlogs模式创建控制文件
SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS FORCE LOGGING ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_1_c94vggms_.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_2_c94vgk0c_.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_3_c94vglyx_.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/orcl/system01.dbf',
'/u01/app/oracle/oradata/orcl/sysaux01.dbf',
'/u01/app/oracle/oradata/orcl/undotbs01.dbf',
'/u01/app/oracle/oradata/orcl/users01.dbf',
'/u01/app/oracle/oradata/orcl/example01.dbf'
CHARACTER SET WE8MSWIN1252
19 ;
Control file created.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open resetlogs;
Database altered.
SQL> select status from v$instance;
STATUS
------------
OPEN
--我们重建数据文件之后要添加temp表空间,虽然我们从dba_tablespaces视图里可以查看到temp 表空间,但是该表空确实没有数据文件的,我们需要手动添加。
SQL> select * from v$tempfile;
no rows selected
SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf' SIZE 100m REUSE AUTOEXTEND ON NEXT 10m MAXSIZE 1000M;
Tablespace altered.
SQL> select * from v$tempfile;
FILE# CREATION_CHANGE# CREATION_ TS# RFILE# STATUS ENABLED BYTES BLOCKS CREATE_BYTES BLOCK_SIZE
---------- ---------------- --------- ---------- ---------- ------- ---------- ---------- ---------- ------------ ----------
NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 1012045 21-JUL-16 3 1 ONLINE READ WRITE 104857600 12800 104857600 8192
/u01/app/oracle/oradata/orcl/temp01.dbf
至此我们重建数据文件全部完成。