控制文件用于记录和维护数据库,当恢复数据库时,服务器进程和后台进程需要从控制文件中读取各种与备份相关的信息。如果控制文件损坏,则会导致这些信息丢失。尽管多元化的控制文件可以防止控制文件损坏,但因控制文件的重要性,所以应当定期的备份控制文件。当数据库配置发生变化时,一定要备份控制文件。
涉及到改变数据库配置的命令一般以 alter database 、ceate tablespace,alter tablespace ,drop tablespace 等命令。
第一 建立控制文件的副本。
SQL> alter database backup controlfile
2 to 'F:\lib\control.ctl' reuse;
----resue 是当控制文件副本已经存在时,可以覆盖以前的副本。若不存在副本,则可以省去resue
数据库已更改。
执行该语句时,oracle会将当前的控制文件的信息全部存放到控制文件的副本中,通过控制文件副本,一 可以执行基于控制文件的不完全恢复,二是可以生成控制文件的文本跟踪文件。注意:在open状态时,控制文件只能用alter databae命令生成,而不能用os命令直接复制。
二 备份到跟踪文件。
SQL> alter database backup controlfile to trace;
数据库已更改。此命令将控制文件中记录的信息备份到跟踪文件,然后可以使用跟踪文件创建控制文件。
1) 确认跟踪文件的位置。
SQL> show parameter user_dump_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
user_dump_dest string f:\app\yang\diag\rdbms\oracl\o
racl\trace
2)确定跟踪文件的名称。跟着文件的名称_ora_.TRC。其中sid为例程名即 oracle_SID的名称,spid 是服务器进程所对应操作系统的进程号。
SQL> select a.spid from v$process a,v$session b
2 where a.addr=b.paddr and b.username='SYS';
SPID
------------------------
572
3)查看跟踪文件。oracl_ora_572 在这里我没有把注释去掉,以方便大家研究。
当将跟踪文件的注释内容和说明信息去掉,剩余部分就可以用来重新建立控制文件的全部内容。当控制文件出现介质损坏时,通过执行这部分语句就可以恢复损坏的控制文件了。
Trace file f:\app\yang\diag\rdbms\oracl\oracl\trace\oracl_ora_572.trc
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Windows XP Version V5.1 Service Pack 3
CPU : 2 - type 586, 2 Physical Cores
Process Affinity : 0x00000000
Memory (Avail/Total): Ph:902M/2046M, Ph+PgF:2348M/3938M, VA:1246M/2047M
Instance name: oracl
Redo thread mounted by this instance: 1
Oracle process number: 31
Windows thread id: 572, image: ORACLE.EXE (SHAD)
*** 2010-05-08 21:43:10.765
*** SESSION ID:(128.147) 2010-05-08 21:43:10.765
*** CLIENT ID:() 2010-05-08 21:43:10.765
*** SERVICE NAME:(SYS$USERS) 2010-05-08 21:43:10.765
*** MODULE NAME:(sqlplus.exe) 2010-05-08 21:43:10.765
*** ACTION NAME:() 2010-05-08 21:43:10.765
-- 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=%s_%t_%r.log
--
-- DB_UNIQUE_NAME="oracl"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'
-- LOG_ARCHIVE_MAX_PROCESSES=5
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- STANDBY_ARCHIVE_DEST=%ORACLE_HOME%\RDBMS
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_2='LOCATION=f:\app\yang\archive2'
-- LOG_ARCHIVE_DEST_2='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_2='ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_2='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_2='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_2='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_2=ENABLE
--
-- LOG_ARCHIVE_DEST_1='LOCATION=f:\app\yang\archive1'
-- 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 NODB_UNIQUE_NAME'
-- 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.
-- 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 "ORACL" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 'F:\APP\YANG\ORADATA\ORACL\REDO01.LOG' SIZE 50M,
GROUP 2 'F:\APP\YANG\ORADATA\ORACL\REDO02.LOG' SIZE 50M,
GROUP 3 'F:\APP\YANG\ORADATA\ORACL\REDO03.LOG' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'F:\APP\YANG\ORADATA\ORACL\SYSTEM01.DBF',
'F:\APP\YANG\ORADATA\ORACL\SYSAUX01.DBF',
'F:\APP\YANG\ORADATA\ORACL\UNDOTBS01.DBF',
'F:\APP\YANG\ORADATA\ORACL\USERS01.DBF',
'F:\APP\YANG\ORADATA\ORACL\EXAMPLE01.DBF'
CHARACTER SET ZHS16GBK
;
-- 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 'F:\APP\YANG\ARCHIVE2\1_1_636026939.LOG';
-- ALTER DATABASE REGISTER LOGFILE 'F:\APP\YANG\ARCHIVE2\1_1_715961434.LOG';
-- 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 'F:\APP\YANG\ORADATA\ORACL\TEMP01.DBF'
SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-- End of tempfile additions.
好了,如何备份控制文件到此结束。至于具体的基于控制文件的不完全恢复,我会在后续的文章中给出具体的步骤。。。。