当前位置:操作系统 > Unix/Linux >>

归档模式设置步骤

归档模式设置步骤
 
一.设置为归档模式的步骤
1.正常关闭数据库
2.把数据库置于 mount状态
3.把数据库修改为archivelog模式
4.打开数据库
5.正常关闭数据库,做一次全备份
 
sQL> conn /  as sysdba
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
Total System Global Area  146472960 bytes
Fixed Size                  1335080 bytes
Variable Size              92274904 bytes
Database Buffers           50331648 bytes
Redo Buffers                2531328 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/admin/wilson/test
Oldest online log sequence     114
Next log sequence to archive   116
Current log sequence           116

 

接下来,干净的关掉数据库,做个全备份。
 
二.在10g中,当数据库处于归档模式下时,还要设置两参数:log_archive_star和log_archive_max_processes。
1.归档模式下,把online redo log复制到指定的位置有两种方式,手动和自动。选择哪种方式和参数log_archive_start有关,它为ture,则为自动;它为false,则为手动。推荐使用自动方式。
2.在自动归档模式中,有多少个ARC进程来参与,由参数log_archive_max_processes来确定。
 
 
三.实例运行状态下,自动归档方式和手动归档方式的相互转变。
1.可以用命令archive log  list 来查看归档的方式,
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/admin/wilson/test
Oldest online log sequence     116
Next log sequence to archive   118
Current log sequence           118

 

 
2.如果开始在参数log_archive_star=false(手动方式)的情况下运行了数据库,怎么修改为自动方式?
先建立个文件,来存放归档日志,在/u01/admin/wilson/目录下建立文件夹arcdest。
然后
SQL> alter system archive log start to '/u01/admin/wilson/archdest';
System altered.

 

现在就是自动方式归档了,
SQL> alter system set log_archive_start=true scope=spfile;
System altered.

 

修改了初始化参数 log_archive_start=true ,下次重新启动还是动方式归档。
 
3.把自动方式改为手动方式,
SQL> alter system archive log stop;
System altered.
SQL> alter system set log_archive_start=false scope=spfile;
System altered.

 

在这里要说明一下,在11g中,只要处于Archivelog模式中,那么它的归档方式就为自动方式,没有了自动方式归档和手动方式的转换。
在归档模式下,在一组online redo log 被覆盖之前,必须先将其归档到指定的地方,不然数据库会hang在那里!!!
 
 
四.归档文件的路径
1.在较早的版本中,位置由参数log_archive_dest和log_archive_duplex_dest来指定,只能是两个。在数据库的标准版中,则必须使用它们。
2.现在使用参数log_archive_dest_n来指定,最多可以指定10个(n=1...10),只能在企业版数据库中使用。
主要介绍log_archive_dest_n对于log_archive_dest_n,有
log_archive_dest_1=”location=/archive/  mandatory”
log_archive_dest_1=”location=/archive/  optional”
log_archive_dest_2=”service=standy_db1”

 

 
其中location是本地地址,service是网络远端地址,
 Mandatory表示在一个online redo log file 在被重写之前,它必须先归档到这个地址,
Optional表示即使一个online redo log file没有归档到这个地址,它也可以被重写。
 
3.对于参数log_archive_min_succeed_dest,如
log_archive_min_succeed_dest=2,则表示在一个online redo log file 在被重写之前,它必须先归档到2个地方。
   结合着参数log_archive_dest_n 和log_archive_min_succeed_dest来看,在一个online redo log file 在被重写之前,它必须完成:
(1)全部成功写入到带mandatory参数的归档地址。
(2)成功归档的地址要大于或者等于log_archive_min_succeed_dest所规定的数值。
  也就是说如果(1)归档的地址数目大于(2)中的数值,则(2)中所规定的数值忽略,以(1)为准。如果(2)中规定的数值大于(1)中的数值,首先(1)全部要归档成功,然后还要达到(2)中所归档的数值。
 
4.log_archive_dest_state_n可以动态的控制一个归档地址是否有效。
log_archive_dest_state_1=enable表示log_archive_dest_1的归档地址可以被使用。
log_archive_dest_state_2=defer表示log_archive_dest_2的归档地址不可以被使用
log_archive_dest_state_3=alternate 表示log_archive_dest_3的归档地址当前不可以被使用,但
是当有另一个地址失效时,它自动成为可以使用地址。
 
5.归档文件名的格式
log_archive_dest_n规定了归档文件的地址目录,但是真正的文件名格式由参数log_archive_format来设置。
例如 /u01/admin/wilson/test/ wilson_%t_%S_%r.arc
其中 /u01/admin/wilson/test由log_archive_dest_n规定,wilson_%t_%S_%r.arc由log_archive_format规定。
(1)%t:线程号,显示为V$instance视图thread#列,在RAC数据库有用,单实例中为1。
(2)%s或者%S:表示日志切换序列号,这个变量能够保证任何一个数据库中的归档日志都不会彼此重写。%S的意思是每个序列号一样长,10位,不够长度,前面补零。
(3)%r:场景号,如果进行了不完全恢复,这个变量就十分重要。
 
11g中文件名的格式规定必须要上述三个:%s或者%S,%t,%r。
 
举个例子:
先在/u01/admin/wilson中建立个test的文件,
SQL> alter system set log_archive_dest_1="location=/u01/admin/wilson/archtest";
System altered.
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/admin/wilson/archtest
Oldest online log sequence     116
Next log sequence to archive   118
Current log sequence           118
显示Archive destination修改了。

SQL> alter system  set log_archive_format="sun_%t_%S_%r.arc"  scope=spfile;
System altered.
关闭重启,

SQL> show parameter archive
log_archive_duplex_dest              string
log_archive_format                   string      sun_%t_%S_%r.arc
log_archive_local_first              boolean     TRUE
log_archive_max_processes            integer     4
log_archive_min_succeed_dest         integer     1
log_archive_start                    boolean     TRUE
log_archive_trace                    integer     0
standby_archive_dest                 string      ?/dbs/arch
可以看到log_archive_format 改变了。

SQL> alter system  switch logfile;
System altered.
SQL> !ls -l /u01/admin/wilson/archtest
total 7720
-rw-r----- 1 oracle oinstall 7624192 Aug 17 01:04 sun_1_0000000118_805499090.arc
-rw-r----- 1 oracle oinstall  241664 Aug 17 01:10 sun_1_0000000119_805499090.arc
-rw-r----- 1 oracle oinstall    5632 Aug 17 01:11 sun_1_0000000120_805499090.arc

 

可以看到归档文件的格式。
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,