1.查看归档设置情况
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination ?/dbs/arch
Oldest online log sequence 10
Current log sequence 12
SQL>
2.打开归档
Oracle 10g
SQL> alter database archivelog;
Database altered.
如果没有使用flash revocery
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination ?/dbs/arch
Oldest online log sequence 13
Next log sequence to archive 15
Current log sequence 15
SQL>
如果使用了flash recovery
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 13
Next log sequence to archive 15
Current log sequence 15
SQL>
Oracle 9i
SQL> alter database archivelog;
Database altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Disabled
Archive destination ?/dbs/arch
Oldest online log sequence 13
Next log sequence to archive 15
Current log sequence 15
SQL>
这里就可以看出orcle9i 和 oracle 10g的区别了。修改数据库为归档模式以后,10g自动将自动归档打开,而9i不会。9i需要修改下面的参数:
SQL> show parameter log_archive_start
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_start boolean FALSE
SQL> alter system set log_archive_start = TRUE scope=spfile;
System altered.
SQL> startup force
ORACLE 例程已经启动。
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination ?/dbs/arch
Oldest online log sequence 13
Next log sequence to archive 15
Current log sequence 15
SQL>
3.查看及更改自动归档的存放位置
SQL>show parameter dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
standby_archive_dest string ?/dbs/arch
默认位置, 这里?代表$ORACLE_HOME
如果使用了flash recovery,默认位置为:
USE_DB_RECOVERY_FILE_DEST
修改归档位置及归档文件名的格式
SQL>alter system set log_archive_dest = '/oracle/u01/arch/'
System altered.
SQL>alter system set LOG_ARCHIVE_FORMAT='Evan__%S_%R.%T' scope=spfile;
System altered.
SQL>startup force
SQL>archive log list
atabase log mode No Archive Mode
Automatic archival Disabled
Archive destination /home/oracle/u01/app/oracle/arch/
Oldest online log sequence 15
Current log sequence 17
SQL> show parameter log
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------------------------
log_archive_format string Evan__%S_%R.%T
关于文件名格式的说明:10g中归档日志的默认文件格式为ARC%S_%R.%T,从10g开始,配置归档日志文件格式时,必须带有%s,%t和%r匹配符。
%s: 日志序列号:
%S: 日志序列号(带有前导0)
%t: 重做线程编号.
%T: 重做线程编号(带有前导0)
%a: 活动ID号
%d: 数据库ID号
%r RESETLOGS的ID值.
4.手动归档设定及解除
SQL> startup mount
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 75499764 bytes
Database Buffers 88080384 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> alter system archive log manual
System altered
这时,系统不再自动归档,你可以用
SQL>alter system archive log all;
来手动归档。
要解除手动归档,恢复到自动归档,将数据库启动到mount模式,关闭再打开归档就可以了。
SQL>alter database noarchivelog;
database altered
SQL>alter database archivelog;
database altered
5.测试自动归档是否成功
设置自动归档以后,redo log的切换会引发归档,我们可以通过手动的切换日志来测试归档。
SQL> select group#,sequence#,archived,status,first_time from v$log;
GROUP# SEQUENCE# ARCHIVED STATUS FIRST_TIME
---------- ---------- --------------- ---------------- --------------
1 19 YES INACTIVE 05-6月 -09
2 20 YES INACTIVE 05-6月 -09
3 21 NO CURRENT 05-6月 -09
当前log group 是 3 ,其余两个都归档过了,手动切换log file:
SQL> alter system switch logfile;
System altered.
SQL> select group#,sequence#,archived,status,first_time from v$log;
GROUP# SEQUENCE# ARCHIVED STATUS FIRST_TIME
---------- ---------- --------------- ---------------- --------------
1 22 NO CURRENT 05-6月 -09
2 20 YES INACTIVE 05-6月 -09
3 21 YES ACTIVE 05-6月 -09
已经切换到group1 了,我们看到group 3 的archive状态已经是yes了,表示归档已经完成。
进入归档目录,可以看到新的归档文件生成:
[oracle:~/u01/app/oracle/arch]$ls
Evan__0000000013_0688689467.0001Evan__0000000018_0688689467.0001
Evan__0000000014_0688689467.0001 Evan__0000000019_0688689467.0001
Evan__0000000017_0688689467.0001 Evan__0000000020_0688689467.0001
Evan__0000000021_0688689467.0001
注意归档文件名evan后面的序号21,即group 3 的序号。
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/u01/app/oracle/arch/
Oldest online log sequence 20
Next log sequence to archive 22
Current log sequence 22
下一个需要归档的log是22号,也就是group 1 。
6.开启归档后容易引发的问题
1)数据库挂起
归档启用了以后,数据库发生log切换的时候,会试图将上一个redo log的内容写入归档,如果写入不成功,这个redo log状态将被置成active,不能再次使用。当数据库运行一段时间,所有的redo log用完,会引发数据库挂起,检查alertSID.log,会有以下报错:
Fri Jun 5 00:41:00 2009
ORACLE Instance ora10glinux - Can not allocate log, archival required
Thread 1 cannot allocate new log, sequence 25
All online logs needed archiving
Current log# 3 seq# 24 mem# 0: /home/oracle/u01/app/oracle/oradata/ora10glinux/redo03.log
重启问题依旧不能解决。
原因一、没有开启自动归档
在oracle9i中,打开了归档以后,自动归档默认是没有开启,可以用
SQL> alter system archive log all
手动归档或者修改参数自动归档
SQL> alter system set log_archive_start = TRUE scope=spfile;
原因二、自动归档不成功。
如果自动归档开启了,就要检查归档目录有没有文件生成。引起自动归档不成功的常见原因是oracle用户对归档目录没有写权限,或者归档目录满了。需要在操作系统上检查归档目录。
2)修改参数错误,造成oracle无法启动
比如修改log_archive_dest参数指定归档目录的位置时,如果目录不存在,数据库会不能启动:
SQL> startup
ORA-16032: parameter LOG_ARCHIVE_DEST destination string cannot be translated
ORA-07286: sksagdi: cannot obtain device information.
Linux Error: 2: No such file or directory
SQL> startup nomount
ORA-16032: parameter LOG_ARCHIVE_DEST destination string cannot be translated
ORA-07286: sksagdi: cannot obtain device information.
Linux Error: 2: No such file or directory
连nomount模式都进入不了,可以用以下方法解决:
拷贝当前的spfile为pfile
SQL> create pfile from spfile;
File created.
然后修正pfile中参数log_archive_dest
$cd $ORACLE_HOME/dbs
$vi initora10glinux.ora
......
*.db_unique_name='ora10glinux'
*.job_queue_processes=10
*.log_archive_dest='/home/oracle/u01/app/oracle/arch/Evan_%S_%R.%T'
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=300
.......
然后用pfile启动数据库
SQL>startup pfile='xxxx/xx/xxx/initora10glinux.ora'
然后用pfile生成spfile就可以正常启动了
SQL> create spfile from pfile;
File created.
阅读(1014) | 评论(0) | 转发(0) |