ITPub博客

首页 > 数据库 > Oracle > oracle 11g开启归档模式及修改归档目录

oracle 11g开启归档模式及修改归档目录

Oracle 作者:swq618 时间:2016-11-08 12:58:43 0 删除 编辑

oracle 11g开启归档模式及修改归档目录


Oracle 11g,开启archive log模式时,默认归档目录为db_recovery_file_dest指定。此参数在pfile/spfile中可以指定:

db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'

 

更改归档模式

需要在mount状态下,更改归档模式。

 

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount

ORACLE instance started.

--如果安装多个库,会报错,找不到句柄

exit  再用管理员进入 

 

Total System Global Area 1258291200 bytes

Fixed Size 1219160 bytes

Variable Size 318768552 bytes

Database Buffers 922746880 bytes

Redo Buffers 15556608 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 USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence 15

Next log sequence to archive 17

Current log sequence 17

 

更改log_archive_dest_1参数可更改归档日志目录(pfile/spfile中参数db_recovery_file_dest指定的目录将无效

 

 SQL> alter system set log_archive_dest_1='location=/data/oracle/log1/archive_log';     最后的目录名称需要为archive_log!

Linux:alter system set log_archive_dest_1='location=/u01/oracle/log/archive_log';

System altered.

 

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            /data/oracle/log1/archive_log

Oldest online log sequence     26

Next log sequence to archive   28

Current log sequence           28

 

实际上Oracle 10g开始,可以生成多份一样的日志,保存多个位置,以防不测,方法如下:

SQL>alter system set log_archive_dest_2='location=/data/oracle/log2/archive_log';

 

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination           /data/oracle/log2/archive_log                         只能看到最新设置的归档目录。

Oldest online log sequence     30

Next log sequence to archive   32

Current log sequence           32

 

SQL> alter system archive log current;

 更新一下

System altered.

 

SQL> select name from v$archived_log;

 

NAME

--------------------------------------------------------------------------------

/data/oracle/log1/archive_log1_6637_737857592.dbf
/data/oracle/log2/archive_log1_6637_737857592.dbf

 

2rows selected.

 

未试 设置为默认值

log_archive_log设置为默认值时,归档目录将会变为?/dbs/arch

SQL> alter system set log_archive_dest_1='';

 

System altered.

 

SQL> alter system set log_archive_dest_2=''

  2  ;                                                                    ;号最后敲入按回车

 

System altered.

 

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination           ?/dbs/arch

Oldest online log sequence     33

Next log sequence to archive   35

Current log sequence           35

SQL> shutdown immediate;

 

重启数据库后,归档目录变回为db_recovery_file_dest指定的目录。

startup mount;

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     33

Next log sequence to archive   35

Current log sequence           35

 

 

修改日志文件命名格式:

SQL> alter system set log_archive_max_processes = 5;

SQL> alter system set log_archive_format = "archive_%t_%s_%r.log" scope=spfile;

 *****************************************************************************************************************

 SQL>archive log list;
如果显示为ENABLE则表示已成功归档
 SQL>select log_mode from v$database;
如果为ARCHIVELOG则表示已成功归档

********************************************************************************

SQL> show parameter db_recovery  

  NAME                                      TYPE                          VALUE
------------------------------------         -----------                       ------------------------------
db_recovery_file_dest                   string                       /data/oracle/flash_recovery_area
db_recovery_file_dest_size         big integer                  4231m

  可以修改db_recovery_file_dest_size参数的大小

  SQL>alter system set db_recovery_file_dest_size=21474836480

Shutdown immediate;

Startup;

完成




以下未测试:


查看oracle数据库是否归档和修改归档模式

http://wenku.baidu.com/view/862b79d1b14e852458fb57fb.html



ORACLE 11G 
http://wenku.baidu.com/view/9b65e47402768e9951e7386a.html


数据库归档模式管理

http://wenku.baidu.com/view/d46089a1b0717fd5360cdc9a.html**

http://baike.baidu.com/view/3431413.htm


两种方法:

1、配置RMAN自动管理ARCHIVELOG。也可在RMAN中将数据备份到磁带上,然后将过期的ARCHIVELOG删除;

2、可以手工来处理,步骤如下

  1)将/oracle下的相关ARCHIVELOG日志文件移到别的文件系统下(保留一段时间的ARCHIVELOG日志即可,其他的可移走,用系统命令mv移走)。然后打包、压缩,备份到介质上,此时可将这些移出的文件删除。注意:别在原来的/oracle打包了,否则空间占满了就有些麻烦了。

  2)以oracle用户登录,执行rman target /。如有多个实例此时执行rman target 用户名/密码@实例名,进入rman

  3)在rman中执行

  RMAN>list archivelog all; /*列出所有的归档日志文件

  RMAN>crosscheck archivelog all; /*与物理归档日志文件保持同步,之前移走了一部分文件,因此执行此命令后会在/oracle目录下找不到的归档日志标记为expired

  RMAN>list expired archivelog all; /*列出所有expired(过期)的归档日志文件,此时你就可看到移走的归档日志文件均被标记为expired

  RMAN>delete expired archivelog all; /*在oracle中删除所有过期的expired文件

  RMAN>list archivelog all; /*再列出所有的归档日志文件,就可发现移走的日志文件被删掉了

  RMAN>exit /*退出

  

  

  

  

http://hi.baidu.com/xyqq163/item/b16e73c32d705f25a0b50a97

  oracle数据库归档模式维护管理

一 设置为归档方式

------------------------

01.1 sql> archive log list;   #查看是不是归档方式  

02.2 sql> alter system set log_archive_start=true scope=spfile; #启用主动归档  

03.   sql> alter system set log_archive_dest='location=/oracle/ora9/oradata/arch' scope=spfile;  

04.      #设置归档路径  

05.   sql> alter system set log_archive_dest_1='location=/oracle/ora9/oradata/arch1' scope=spfile;  

06.   sql> alter system set log_archive_dest_2='location=/oracle/ora9/oradata/arch2' scope=spfile;  

07.      #如果归档到两个位置,则可以通过上边方法实现  

08.  sql> alter system set log_archive_format='arch_%d_%t_%r_%s.log'  #设置归档日记款式  

09.3 sql> shutdown immediate;  

10.4 sql> startup mount;    #打开控制文件,不打开数据文件  

11.5 sql> alter database archivelog; #将数据库切换为归档模式  

12.6 sql> alter database open;   #将数据文件打开  

13.7 sql> archive log list;   #查看此时是否处于归档模式  

14.8 查询以确定数据库位于archivelog模式中且归档过程正在运行  

15.sql> select log_mode from v$database;  

16.sql> select archiver from v$instance;  

17.9 日志切换  

18.sql> alter system switch logfile;  

19.10 这次日志切换将归档写到两个目标地,  

20.  1,即第二步的/oracle/ora9/oradata/arch1和/oracle/ora9/oradata/arch1,要是要对目录确认  

21.  

22.在oracle情况中运行如下查询:  

23.sql> select name from v$archived_log;  

24.而后在操作系统中确认查询所列出的文件  

二 设置非归档方式

------------------------------------------

01.1 sql> archive log list;   #查看是否是归档方式  

02.2 sql> alter system set log_archive_start=false scope=spfile; #禁用自动归档  

03.3 sql> shutdown immediate;  

04.4 sql> startup mount;    #打开控制文件,不打开数据文件  

05.5 sql> alter database noarchivelog; #将数据库切换为非归档模式  

06.6 sql> alter database open;   #将数据文件打开  

07.7 sql> archive log list;   #查看此时便处于非归档模式  

 

 

日常维护常用语句:

 

1.查询每日归档备份大小情况: 

SELECT TRUNC(FIRST_TIME) "日期", TRUNC(SUM(BLOCKS*BLOCK_SIZE)/1024/1024/1024,2) "大小(GB/DAY)" FROM V$ARCHIVED_LOG  GROUP BY TRUNC(FIRST_TIME)  ORDER BY 1 DESC;

 

2.查看归档空间占用情况:

select NAME,SPACE_LIMIT/1024/1024/1024,SPACE_USED/1024/1024/1024,NUMBER_OF_FILES from V$RECOVERY_FILE_DEST;

#查看大小单位为Gb




http://zhidao.baidu.com/question/149648251.html
1.查询系统使用的是哪一组日志文件:
select * from v$log;

2.查询正在使用的组所对应的日志文件:
select * from v$logfile;

3.强制日志切换:
alter system switch logfile;

4.查询历史日志:
select * from v$log_history;

5.查询日志的归档模式:
select dbid,name,created,log_mode from v$database;

6.查询归档日志的信息:
select recid,stamp,thread#,sequence#,name from v$archived_log;

7.增加与删除日志文件组
alter database add logfile group 1 ('/home1/oracle/oradata/ora8i/log1a.log'),'/home2/oracle/oradata/ora8i/log1b.log') size 100M;

alter database drop logfile group 1;

8.增加与删除日志成员
alter database add logfile member '/home1/oracle/oradata/ora8i/log1a.log' to group 1,'/home1/oracle/oradata/ora8i/log2a.log' to group 2;

alter database drop logfile member '/home1/oracle/oradata/ora8i/log1a.log' ;

9.日志文件移动
alter database rename file '/home1/oracle/oradata/ora8i/log1a.log' to '/home2/oracle/oradata/ora8i/log1a.log';
执行该命令之前必须保证该日志文件物理上已经移动到新目录

10.清除日志文件
alter database clear logfile '/home1/oracle/oradata/ora8i/log1a.log';
该命令不能用删除组及组成员命令删除日志时使用


http://www.2cto.com/database/201109/104615.html
archive log 日志已满
ORA-00257: archiver error. Connect internal only, until freed 错误的处理方法
1. 用sys用户登录
  sqlplus sys/pass@tt as sysdba
2. 看看archiv log所在位置
SQL> show parameter log_archive_dest;
NAME                                     TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest                   string
log_archive_dest_1               string
log_archive_dest_10             string
3. 一般VALUE为空时,可以用archive log list;检查一下归档目录和log sequence
SQL> archive log list;
Database log mode                 Archive Mode
Automatic archival                   Enabled
Archive destination                  USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     360
Next log sequence to archive  360
Current log sequence              362
4. 检查flash recovery area的使用情况,可以看见archivelog已经很大了,达到96.62
SQL> select * from V$FLASH_RECOVERY_AREA_USAGE;
FILE_TYPE    PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES
------------ ------------------ ------------------------- ---------------
CONTROLFILE                 .13                        0               1
ONLINELOG                  2.93                        0               3
ARCHIVELOG                96.62                       0              141
BACKUPPIECE                   0                         0               0
IMAGECOPY                      0                         0               0
FLASHBACKLOG                0                         0               0
5. 计算flash recovery area已经占用的空间
SQL> select sum(percent_space_used)*3/100 from v$flash_recovery_area_usage;
SUM(PERCENT_SPACE_USED)*3/100
-----------------------------
                       2.9904
                     
6. 找到recovery目录, show parameter recover
SQL> show parameter recover;
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string           /u01/app/oracle/flash_recovery_area
db_recovery_file_dest_size        big integer   5G
recovery_parallelism                   integer         0
                     
7 上述结果告诉我们,归档位置用的是默认值,放在flash_recovery_area下(db_recovery_file_dest目录=/u01/app/oracle/flash_recovery_area)
[root@sha3 10.2.0]# echo $ORACLE_BASE
/u01/app/oracle
[root@sha3 10.2.0]# cd $ORACLE_BASE/flash_recovery_area/tt/archivelog
转移或清除对应的归档日志, 删除一些不用的日期目录的文件,注意保留最后几个文件(比如360以后的)
---------------------------------------------------------------------------------------
注意:
在删除归档日志后,必须用RMAN维护控制文件,否则空间显示仍然不释放。
---------------------------------------------------------------------------------------
8. rman target sys/pass
[root@sha3 oracle]# rman target sys/pass
Recovery Manager: Release 10.2.0.4.0 - Production on Tue Jan 20 01:41:26 2009
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database: tt (DBID=4147983671)
 
9. 检查一些无用的archivelog
RMAN> crosscheck archivelog all;
10. 删除过期的归档
RMAN> delete expired archivelog all;
delete archivelog until time 'sysdate-1' ; 删除截止到前一天的所有archivelog
11. 再次查询,发现使用率正常,已经降到23.03
SQL> select * from V$FLASH_RECOVERY_AREA_USAGE;
FILE_TYPE    PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES
------------ ------------------ ------------------------- ---------------
CONTROLFILE                 .13                         0               1
ONLINELOG                  2.93                         0               3
ARCHIVELOG                23.03                         0              36
BACKUPPIECE                   0                         0               0
IMAGECOPY                     0                         0               0
FLASHBACKLOG                  0                         0               0
其它有用的Command:
----------------------------------
如果archive log模式下不能正常startup,则先恢复成noarchive log,startup成功后,再shutdown;
shutdown immediate;
startup mount;
alter database noarchivelog;
alter database open;
shutdown immediate;
再次startup以archive log模式
shutdown immediate;
startup mount;
show parameter log_archive_dest;
alter database archivelog;
archive log list;               
alter database open;
如果还不行,则删除一些archlog log
SQL> select group#,sequence# from v$log;
    GROUP# SEQUENCE#
---------- ----------
         1         62
         3         64
         2         63
原来是日志组一的一个日志不能归档
SQL> alter database clear unarchived logfile group 1;
alter database open;
最后,也可以指定位置Arch Log, 请按照如下配置
select name from v$datafile;
alter system set log_archive_dest='/opt/app/oracle/oradata/usagedb/arch' scope=spfile
或者修改大小
SQL> alter system set db_recovery_file_dest_size=3G scope=both;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29674916/viewspace-2127979/,如需转载,请注明出处,否则将追究法律责任。

全部评论

注册时间:2014-05-24

  • 博文量
    104
  • 访问量
    242087