控制檔案用於記錄和維護資料庫。當恢複資料庫時,伺服器處理序和後台進程需要從控制檔案中讀取各種備份相關的資訊。如果控制檔案損壞,則會導致這些備份資訊的丟失。儘管使用多元化控制檔案可以防止控制檔案損壞,但因為控制檔案的重要性,應該定期備份控制檔案。當資料庫配置發生改變時,一定要備份控制檔案。涉及到資料庫配置改變的命令:
alter database [add|drop] logfile
alter database [add|drop] logfile member
alter database [add|drop] logfile group
alter database [noarchivelog|archivelog]
alter database rename file
create tablespace
alter tablespace [add|rename] datafile
alter tablespace [read write|read only]
drop tablespace
控制檔案的備份,三種方式
1)使用OS命令進行拷貝
1)open狀態下,使用alter database命令產生控制檔案副本
2)open狀態下,使用alter database backup controlfile to trace命令將控制檔案備份到追蹤檔案
控制檔案的恢複,兩種方式
1)mount狀態下,使用RECOVER DATABASE USING BACKUP CONTROLFILE
2)mount狀態下,產生追蹤檔案並進行恢複
2--2樣本:
[Oracle@localhost ~]$ rlsqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 8月 1 21:40:03 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 528482304 bytes
Fixed Size 1220360 bytes
Variable Size 176161016 bytes
Database Buffers 343932928 bytes
Redo Buffers 7168000 bytes
Database mounted.
Database opened.
--open狀態下產生控制檔案副本
SQL> alter database backup controlfile to
2 '/oracle/10g/oracle/bakup/database/oralife.ctl';
alter database backup controlfile to
*
ERROR at line 1:
ORA-01580: error creating control backup file
/oracle/10g/oracle/bakup/database/oralife.ctl
ORA-27038: created file already exists
Additional information: 1
SQL> alter database backup controlfile to
2 '/oracle/10g/oracle/bakup/database/oralife.ctl' reuse;
--reuse用於覆蓋原有控制檔案副本
Database altered.
--手動刪除所有控制檔案類比檔案丟失
SQL> ho rm /oracle/10g/oracle/product/10.2.0/oradata/oralife/*.ctl;
--使用evan登入,並添加資料
SQL> conn evan/evan
Connected.
SQL> select * from t_evan;
TEXT
--------------------------------------------------------------------------------
oracle
java
spring
hibernate
hibernate
SQL> insert into t_evan values('added');
1 row created.
SQL> commit;
Commit complete.
SQL> conn / as sysdba
Connected.
SQL> shutdown immediate
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/oracle/10g/oracle/product/10.2.0/oradata/oralife/control01.ctl'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
SQL> shutdown abort
ORACLE instance shut down.
--alter_oralife.log出現這樣的資訊:
Mon Aug 1 23:13:51 2011
ORA-00202: control file: '/oracle/10g/oracle/product/10.2.0/oradata/oralife/control01.ctl'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
--拷貝控制檔案到目標路徑
SQL>ho cp /oracle/10g/oracle/bakup/database/oralife.ctl /oracle/10g/oracle/product/10.2.0/oradata/oralife/control01.ctl
SQL> alter system set control_files='/oracle/10g/oracle/product/10.2.0/oradata/oralife/control01.ctl' scope = spfile;
--修改control_files參數,指定可用的控制檔案
System altered.
SQL> startup force mount
ORACLE instance started.
Total System Global Area 528482304 bytes
Fixed Size 1220360 bytes
Variable Size 138412280 bytes
Database Buffers 381681664 bytes
Redo Buffers 7168000 bytes
Database mounted.
--產生trace檔案
SQL> alter database backup controlfile to trace noresetlogs;
Database altered.
SELECT c.VALUE || '/' || d.instance_name || '_ora_' || a.spid || '.trc' TRACE
FROM v$process a, v$session b, v$parameter c, v$instance d
WHERE a.addr = b.paddr
AND b.audsid = USERENV ('sessionid')
AND c.NAME = 'user_dump_dest';
TRACE
--------------------------------------------------------------------------------
/oracle/10g/oracle/product/10.2.0/db_1/admin/oralife/udump/oralife_ora_4558.trc
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
--開啟trace檔案,去掉注釋,在shutdown狀態下執行指令碼,建立控制檔案
--用evan登入驗證資料
SQL> conn evan/evan
Connected.
SQL> select * from t_evan;
TEXT
--------------------------------------------------------------------------------
oracle
java
spring
hibernate
hibernate
added
6 rows selected.
可見資料沒有丟失。
SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/oracle/10g/oracle/product/10.2.0/oradata/oralife/control01.ctl
這時
應該重建多個控制檔案。
如何做?