控制文件用于记录和维护数据库。当恢复数据库时,服务器进程和后台进程需要从控制文件中读取各种备份相关的信息。如果控制文件损
控制文件用于记录和维护数据库。当恢复数据库时,服务器进程和后台进程需要从控制文件中读取各种备份相关的信息。如果控制文件损坏,则会导致这些备份信息的丢失。尽管使用多元化控制文件可以防止控制文件损坏,但因为控制文件的重要性,应该定期备份控制文件。当数据库配置发生改变时,一定要备份控制文件。涉及到数据库配置改变的命令:
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
这时应该重建多个控制文件。
如何做?