Oracle主库、备库redo日志管理

文章目录

  • 官方参考:
  • 1、添加日志组以及日志成员
  • 3、删除日志组或成员
    • 3.1、日志的重定位及重命名
    • 3.2、清空日志文件组
    • 3.3、删除日志成员
    • 3.4、删除日志组
  • 5、删除单实例数据库多余节点的日志组
  • 5、归档管理
  • 6、疑难日志清理案例
  • 7、有adg备库环境下扩大redo大小
    • 7.0、环境说明
    • 7.1、检查主备库信息
    • 7.2、主库上扩展日志操作
    • 7.3、扩展备库的日志大小

官方参考:

How To Add/Increase The Size Of Redo Log Files In Rac Environment? (Doc ID 779306.1)

How To Maintain and/or Add Redo Logs (Doc ID 602066.1)

Example of How To Resize the Online Redo Logfiles (Doc ID 1035935.6)

How to Change The Location Of Redo Log Files (Doc ID 395062.1)

Online Redo Logs on Physical Standby (Doc ID 740675.1)

Handling ORL and SRL (Resize) on Primary and Physical Standby in Data Guard Environment (Doc ID 1532566.1)

1、添加日志组以及日志成员

日志文件组,如果没有使用OMF请指定日志路径,RAC环境下需要指定thread

ALTER DATABASE ADD LOGFILE [THREAD n] [GROUP n] (‘ O R A C L E B A S E / o r a d a t a / u 01 / l o g n 1. r d o ′ , ′ ORACLE_BASE/oradata/u01/logn1.rdo',' ORACLEBASE/oradata/u01/logn1.rdo,ORACLE_BASE/oradata/u01/logn2.rdo’) SIZE mM;

添加standby 日志组

alter database add standby logfile thread 1 group 11 ‘+FRA/acctdbw/onlinelog/redo11A.dbf’ size 1g;

添加日志成员

ALTER DATABASE ADD LOGFILE MEMBER ‘ O R A C L E B A S E / o r a d a t a / u 01 / l o g n 1. r d o ′ T O G R O U P 1 , ′ ORACLE_BASE/oradata/u01/logn1.rdo' TO GROUP 1, ' ORACLEBASE/oradata/u01/logn1.rdoTOGROUP1,ORACLE_BASE/oradata/u01/logn2.rdo’ TO GROUP 2;

3、删除日志组或成员

注意:current redo log不能被删除,路径位置不对的也不能被删除,库中少于两组日志也不能被删除。

所以,要先rename,然后clear生成日志文件,这时候才能删除非current的日志。如果是current的日志想在备库删除,必须在主库做如下操作:

alter system switch logfile;

alter system archive log current; --RAC

alter system checkpoint;

3.1、日志的重定位及重命名

删除日志的时候会经常发现日志路径不存在,主要是用了别的库的控制文件。rename即可

select ‘alter database rename file ‘’’||member||’’’ to ‘’+FRA/acctdbw/onlinelog’||substr(member,instr(member,’/’,-1,1))||’’’;’ from v$logfile;

重定位及重命名的两种方法:
添加一个新成员到日志组,然后删除一个旧的成员
使用ALTER DATABASE RENAME FILE 命令(不区分归档与非归档模式)

复制联机日志文件到新路径:ho cp
执行ALTER DATABASE RENAME FILE ‘’ TO ‘’

对于处于CURRENT状态的需要改名且不切换的情况下,办法是切换到MOUNT状态下再执行上述操作
重命名或重定位之后建议立即备份控制文件

3.2、清空日志文件组

ALTER DATABASE CLEAR LOGIFLE GROUP n;

ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP n

–使用unarchived 避免归档

select ‘alter database clear logfile group ‘||group#||’;’ from v$logfile;

特别是用duplicate方式复制的备库,日志中残留着主库的日志信息,删除的时候会报日志组中有没有应用的日志信息,需要应用,否则丢失数据。因为是备库,可以直接清空后再删除。

3.3、删除日志成员

ALTER DATABASE DROP LOGFILE MEMBER ‘$ORACLE_BASE/oradata/u01/logn1.rdo’;

不能删除组内的唯一一个成员

不能删除处于active 和current 状态组内的成员

删除处于active 和current 状态组内的成员,应使用日志切换使其处于INACTIVE状态后再删除

对于组内如果一个成员为NULL 值,一个为INVALID,且组处入INACTIVE,仅能删除INVALID状态成员

删除日志成员,物理文件并没有真正删除,需要手动删除

删除日志文件后,控制文件被更新

对于处于归档模式下的数据库,删除成员时确保日志已被归档,查看v$log视图获得归档信息

3.4、删除日志组

ALTER DATABASE DROP LOGFILE GROUP n;
select ‘alter database drop logfile group ‘||group#||’;’ from v$logfile;

一个实例至少需要两个联机日志文件组

活动或当前的日志组不能被删除;

组内成员状态有NULL 值或INVALID状态并存,组不可删除;

日志组被删除后,物理文件需要手动删除(对于非OMF);

5、删除单实例数据库多余节点的日志组

需要禁用其它节点,
禁用thread:

SQL>alter database disable thread 2;

强制设置检查点间隔

ALTER SYSTEM SET FAST_START_MTTR_TARGET = n

5、归档管理

请参考MOS How To Enable Archive Logging In RAC Environment [ID 1186764.1]
http://blog.csdn.net/dbcommando/article/details/7925861

修改归档路径和归档文件格式:
alter system set log_archive_dest_1='location=/u01/app/oracle/oradata/arch' scope=both;

rac环境开启归档步骤:

(1)将该实例的cluster_database设置为false

alter system set cluster_database=false scope=spfile sid='prod1';

(2)关闭所有访问该数据库的实例

srvctl stop database -d prod

(3)使用本地实例挂载数据库

SQL>startup mount
(4)启用存档

SQL>alter database archivelog;

(5)将实例prod1的参数cluster_database设置为true;

alter system set cluster_database=true scope=spfile sid='prod1';

(6)关闭本地实例

SQL>shutdown immediate;

(7)启动所有实例

srrvctl start database -d prod

6、疑难日志清理案例

现象如下,有两个日志组状态为CLEARING_CURRENT,日志文件名称只有磁盘组的名字,显然不正常

GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME 
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ --------- 
25 1 0 1073741824 512 2 NO CLEARING_CURRENT 1.3911E+13 23-APR-18 2.8147E+14 
6 1 0 1073741824 512 2 YES UNUSED 1.3911E+13 23-APR-18 1.3911E+13 23-APR-18 
1 1 0 1073741824 512 2 YES UNUSED 1.3911E+13 23-APR-18 1.3911E+13 23-APR-18 
2 1 0 1073741824 512 2 YES UNUSED 1.3911E+13 23-APR-18 1.3911E+13 23-APR-18 
5 1 0 1073741824 512 2 YES UNUSED 1.3911E+13 23-APR-18 1.3911E+13 23-APR-18 
32 2 0 1073741824 512 2 NO CLEARING_CURRENT 1.3911E+13 23-APR-18 2.8147E+14 
GROUP# STATUS TYPE MEMBER IS_ 
---------- ------- ------- ------------------------------------------------------------ --- 
1 ONLINE +DATA/gzspaydbw/onlinelog/group_1.2029.1006889263 NO 
6 ONLINE +FRA/gzspaydbw/onlinelog/group_6.429.1006889277 NO 
25 INVALID ONLINE +DATA NO 
25 INVALID ONLINE +FRA NO 
32 INVALID ONLINE +DATA NO 
32 INVALID ONLINE +FRA NO 

问题原因:出现这种问题原因一般是因为启用了日志的OMF,自动创建日志失败导致。可能由于权限或者空间不足导致。
然后在主库切换日志,把备库的日志状态切换为非current状态就可以正常处理日志组了。

7、有adg备库环境下扩大redo大小

本章节主要翻译自mos文档 Handling ORL and SRL (Resize) on Primary and Physical Standby in Data Guard Environment (Doc ID 1532566.1)

ORA-16401 and ORA-16055 reported in primary alert.log when redolog switch is over frequently (Doc ID 1243177.1)

主备库环境下扩大redo大小需要按照先主库后备库的顺序操作,如果先处理备库很有可能会遇到redo日志组删除不掉的尴尬。

7.0、环境说明

案例:最大性能模式下,把主备库的redo大小从50m扩大到100m。
主库: prm11203
ADG备库: std11203

目的:
redo日志切换频繁,alert日志中出现ORA-16401和ORA-16055告警,
为了减少日志切换的频率,改进主数据库性能,现在需要把主备库的日志大小调大。

7.1、检查主备库信息

检查主库:

$sqlplus sys/ as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Tue Feb 26 10:41:27 2013

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select status,instance_name,database_role from v$database,v$instance;

STATUS       INSTANCE_NAME    DATABASE_ROLE
------------ ---------------- ----------------
OPEN         prm11203         PRIMARY

SQL> select group#,sum(bytes/1024/1024)"Size in MB" from v$log group by group#;

    GROUP# Size in MB
---------- ----------
         1         50
         2         50
         3         50

SQL> select group#,sum(bytes/1024/1024)"Size in MB" from v$standby_log group by group#;

    GROUP# Size in MB
---------- ----------
         6         50
         4         50
         5         50
         7         50

检查备库:

$sqlplus sys/ as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Tue Feb 26 10:48:30 2013

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select status,instance_name,database_role from v$database,v$Instance;

STATUS       INSTANCE_NAME    DATABASE_ROLE
------------ ---------------- ----------------
OPEN         std11203         PHYSICAL STANDBY

SQL> select group#, sum(bytes/1024/1024)"Size in MB" from v$log group by group#;

    GROUP# Size in MB
---------- ----------
         1         50
         2         50
         3         50

SQL> select group#,sum(bytes/1024/1024)"Size in MB" from v$standby_log group by group#;

    GROUP# Size in MB
---------- ----------
         6         50
         4         50
         5         50
         7         50
         
检查参数standby_file_management,在备库上此参数需要设置为manual才能添加删除日志组。
SQL> show parameter standby_file_management

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
standby_file_management              string      AUTO

SQL> alter system set standby_file_management=manual;

System altered.

SQL> show parameter standby_file_management

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
standby_file_management              string      MANUAL

7.2、主库上扩展日志操作

检查日志状态,inactive状态的可以直接删除,current和active状态的需要切换日志,直到该日志组变成inactive才能操作。

SQL> select group#,status from v$log;

    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 INACTIVE
         3 CURRENT

每删除一个50M日志组,紧接着再添加1组100M的,启用OMF情况下,可以不用指定路径,如下:

SQL> alter database drop logfile group 1;
SQL> alter database add logfile group 1 size 100M;
SQL> alter database drop logfile group 2;
SQL> alter database add logfile group 2 size 100M;

对于current状态的第三组日志,需要切换为inactive状态才能操作:

SQL> alter system switch logfile;

System altered.

SQL> select group#,status from v$log;

    GROUP# STATUS
---------- ----------------
         1 CURRENT
         2 UNUSED
         3 ACTIVE

SQL> alter system switch logfile;

System altered.

SQL> select group#,status from v$log;

    GROUP# STATUS
---------- ----------------
         1 ACTIVE
         2 CURRENT
         3 ACTIVE

SQL> alter system checkpoint;

System altered.

SQL> select group#,status from v$log;

    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 CURRENT
         3 INACTIVE
SQL> alter database drop logfile group 3;

Database altered.

SQL> alter database add logfile group 3 size 100M;

Database altered.

下面开始处理主库上面的standby redo log:

SQL> select group#,sum(bytes/1024/1024)"size in MB" from v$standby_log group by group#;

GROUP# size in MB
---------- ----------
6 50
4 50
5 50
7 50

SQL> select group#,status from v$standby_log;

GROUP# STATUS
---------- ----------
4 UNASSIGNED
5 UNASSIGNED
6 UNASSIGNED
7 UNASSIGNED

SQL> alter database drop standby logfile group 4;
SQL> alter database drop standby logfile group 5;
SQL> alter database drop standby logfile group 6;
SQL> alter database drop standby logfile group 7;
SQL> alter database add standby logfile group 4 size 100M;
SQL> alter database add standby logfile group 5 size 100M;
SQL> alter database add standby logfile group 6 size 100M;
SQL> alter database add standby logfile group 7 size 100M;

7.3、扩展备库的日志大小

检查日志状态,并关闭MRP进程

SQL> select group#,status from v$log;

GROUP# STATUS
---------- ----------------
1 CURRENT
3 CLEARING
2 CLEARING

SQL> alter database recover managed standby database cancel;

处理clearing状态的日志组:

SQL> alter database clear logfile group 2;

Database altered.

SQL> alter database drop logfile group 2;

Database altered.

SQL> alter database add logfile group 2 size 100M;

Database altered.

SQL> select group#,status from v$log;

GROUP# STATUS
---------- ----------------
1 CURRENT
3 CLEARING
2 UNUSED

SQL> alter database clear logfile group 3;

Database altered.

SQL> alter database drop logfile group 3;

Database altered.

SQL> alter database add logfile group 3 size 100M;

Database altered.

处理处于current状态的日志组1:

回到主库,切换日志组:
alter system switch logfile;
备库上检查日志组1的状态,直到为clearing状态为止。
最后,按照上面方式删除:
SQL> alter database clear logfile group 1;

Database altered.

SQL> alter database drop logfile group 1;

Database altered.

SQL> alter database add logfile group 1 size 100M;

处理备库上面的standby redo log:

SQL> select group#,sum(bytes/1024/1024)"size in MB" from v$standby_log group by group#;

GROUP# size in MB
---------- ----------
4 50
5 50
6 50
7 50

SQL> select group#,status from v$standby_log;

GROUP# STATUS
---------- ----------
4 ACTIVE
5 UNASSIGNED
6 UNASSIGNED
7 UNASSIGNED
和主库上的处理方式一致:
SQL> alter database drop standby logfile group 4;
SQL> alter database drop standby logfile group 5;
SQL> alter database drop standby logfile group 6;
SQL> alter database drop standby logfile group 7;
SQL> alter database add standby logfile group 4 size 100M;
SQL> alter database add standby logfile group 5 size 100M;
SQL> alter database add standby logfile group 6 size 100M;
SQL> alter database add standby logfile group 7 size 100M;

最后,恢复备库日志应用:

SQL> alter system set standby_file_management=auto;

System altered.

SQL> alter database recover managed standby database disconnect from session using current logfile;

Database altered.

SQL> select process,status,sequence# from v$managed_standby;

你可能感兴趣的:(Oracle数据库)