• Oracle官方提供清理侦听器日志的4种方式


    Oracle官方提供清理侦听器日志的4种方式

    侦听器日志,例如:

    [root@dev-testdb trace]# ll /u01/app/grid/diag/tnslsnr/dev-testdb/listener/trace/listener.log 
    -rw-r----- 1 grid oinstall 1129 Jan 20 10:35 /u01/app/grid/diag/tnslsnr/dev-testdb/listener/trace/listener.log

    根据实际执行和Why Are My Listener Logs & Traces Not Purged By The ADR (文档 ID 1438242.1)可知,不会被如下命令adrci的交互式命令清除:

    purge -age <min> -type alert

    该命令只会清理xml格式的文本。

    以11g为例子,总结了官方提供的4种清除方式。

    1. ARCHIVED How to Rotate or Purge Listener Log Data to Avoid Large listener.log File (文档 ID 1457196.1)
      停止监听后删除或重命名日志,下次启动侦听器会创建新的日志
    2. ARCHIVED How to Rotate or Purge Listener Log Data to Avoid Large listener.log File (文档 ID 1457196.1)
      LSNRCTL> set current_listener <listenername>
      LSNRCTL> set log_status off
      在另一个窗口中重命名日志文件。然后返回上一个窗口
      LSNRCTL> set log_status on
      这将创建一个新的空 listener.log 文件,该文件将继续记录。  
    3. Excessive Listener XML FILES CREATED IN $GRID_HOMElogdiagtnslsnr (文档 ID 1927067.1)
      Adrci Purge Does Not Clear the Text-formatted Alert.Log located in the Trace Folder (文档 ID 751082.1)
      How To Purge Listener Log.Xml File (文档 ID 816871.1)
      这3篇官方文档指出adrci不会清理文本格式的 alert.log 文件,只修改 XML 格式的警报文件,而不是 Text 格式的警报文件。
      需要手工编辑或者删除文本基础.log的文件,例如:对文件进行拆分,或者使用 Unix 上的“vi”之类的编辑器来清空文件等...
    4. echo "" >| /u01/app/grid/diag/tnslsnr/dev-testdb/listener/trace/listener.log
      咋一看简单且暴力,一点也不优雅。
      purgeLogs Cleanup traces, logs in one command (文档 ID 2081655.1)中提供了一个脚本purgeLogs,需要使用root用户执行并且需要有/etc/init.d/init.ohasd脚本,即单机环境无法使用。
      下边详细说说这第4点。

    echo方式清空日志实际上就是purgeLogs这个脚本的处理方式。
    脚本功能比较强大,可以清理osw,tfa,rdbms等等的信息文件,不仅仅限于日志。

    [root@dev-testdb trace]# /soft/purgeLogs  -h
    Usage:
         purgeLogs [ -days <days> [ -aud ] [ -lsnr ] ] |
                   [ -orcl <days> [ -aud ] [ -lsnr ] ] |
                   [ -tfa <days> ] | 
                   [ -osw <days> ] | 
                   [ -oda <days> ] | 
                   [ -extra '<folder>':<days> | [, '<folder>':<days>] ]
                   [ -automigrate ]
                   [ -dryrun ]
    
         purgeLogs OPTIONS
          -days  <days>             Purge orcl,tfa,osw,oda components logs & traces older then # days
          -orcl  <days>             Purge only GI/RDBMS logs & traces (Default 30 days)
          -tfa   <days>             Purge only TFA repository older then # days (Default 30 days)
          -osw   <days>             Purge only OSW archives older then # days (Default 30 days)
          -oda   <days>             Purge only ODA logs and trace older then # days (Default 30 days)
          -extra '<folder>':<days>  Purge only files in user specified folders (Default 30 days)
          -aud                      Purge Audit logs based on '-orcl <days>' option
          -lsnr                     It will force the cleanup of listeners log independently by the age
          -dryrun                   It will show the purge commands w/o execute them
          -automigrate              It will run the adrci schema migrate commands in case of DIA-49803
          -h                        Display this help and exit
    
         Example:
           purgeLogs
           purgeLogs -days 20
           purgeLogs -orcl 50
           purgeLogs -orcl 50 -aud -lsnr
           purgeLogs -tfa  50
           purgeLogs -osw  20 -oda 10
           purgeLogs -orcl 20 -osw 20 -oda 10
           purgeLogs -orcl 20 -osw 20 -oda 10 -extra /tmp:10,/var/log:20

    根据帮助手册,删除GI/RDBMS日志和trace文件,同时删除侦听日志的指令:

    /soft/purgeLogs -orcl  10 -lsnr -aud -dryrun

    输出案例:

    [root@dev-testdb ~]# /soft/purgeLogs -orcl  10 -lsnr -aud -dryrun
    
    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
     purgeLogs version: 1.65
     Copyright (c) 2015-2020 Oracle and/or its affiliates.
     -------------------------------------------------------
     Author: Ruggero Citton <ruggero.citton@oracle.com>
     RAC Pack, Cloud Innovation and Solution Engineering Team
    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
    
    2022-01-20 11:01:04: I DRYRUN - Cleaning up Listener logs, ORACLE_BASE is '/u01/app/grid'
            echo "" >| /u01/app/grid/diag/tnslsnr/dev-testdb/listener/trace/listener.log
    2022-01-20 11:01:04: I DRYRUN - Cleaning up SCAN1 Listener logs, ORACLE_BASE is '/u01/app/grid'
    2022-01-20 11:01:04: W Path /u01/app/grid/diag/tnslsnr/dev-testdb/listener_scan1/trace does not exist, SCAN1 Listener logs cleanup skipped...
    2022-01-20 11:01:04: I DRYRUN - Cleaning up SCAN2 Listener logs, ORACLE_BASE is '/u01/app/grid'
    2022-01-20 11:01:04: W Path /u01/app/grid/diag/tnslsnr/dev-testdb/listener_scan2/trace does not exist, SCAN2 Listener logs cleanup skipped...
    2022-01-20 11:01:04: I DRYRUN - Cleaning up SCAN3 Listener logs, ORACLE_BASE is '/u01/app/grid'
    2022-01-20 11:01:04: W Path /u01/app/grid/diag/tnslsnr/dev-testdb/listener_scan3/trace does not exist, SCAN3 Listener logs cleanup skipped...
    2022-01-20 11:01:04: I DRYRUN - Cleaning up Management Listener logs, ORACLE_BASE is '/u01/app/grid'
    2022-01-20 11:01:04: W Path /u01/app/grid/diag/tnslsnr/dev-testdb/mgmtlsnr/trace does not exist, Management Listener logs cleanup skipped...
    2022-01-20 11:01:04: I DRYRUN - Cleaning up ASM Listener logs, ORACLE_BASE is '/u01/app/grid'
    2022-01-20 11:01:04: W Path /u01/app/grid/diag/tnslsnr/dev-testdb/asmnet1lsnr_asm/trace does not exist, ASM Listener logs cleanup skipped...
    2022-01-20 11:01:04: I GI Audit logs purge started
    2022-01-20 11:01:04: I DRYRUN - Purging GI Audit logs under '/u01/app/11.2.0/grid/rdbms/audit' older then 10 days
            rm /u01/app/11.2.0/grid/rdbms/audit/null_ora_26047_20210517200222237009143795.aud
            rm /u01/app/11.2.0/grid/rdbms/audit/+ASM1_ora_26076_20210517200222587121143795.aud
            rm /u01/app/11.2.0/grid/rdbms/audit/+ASM1_ora_26076_20210517200222588926143795.aud
            rm /u01/app/11.2.0/grid/rdbms/audit/+ASM1_ora_26089_20210517200222906375143795.aud
            rm /u01/app/11.2.0/grid/rdbms/audit/+ASM1_ora_26089_20210517200259048887143795.aud
            rm /u01/app/11.2.0/grid/rdbms/audit/+ASM1_ora_26201_20210517200259071998143795.aud
            ...省略部分内容...
    2022-01-20 11:01:04: I DRYRUN - Purging GI Audit logs under '/u01/app/grid/admin/_mgmtdb/adump' older then 10 days
    2022-01-20 11:01:04: W Path /u01/app/grid/admin/_mgmtdb/adump does not exist, GI Audit archive logs cleanup skipped...
    ~~~~~~~~~~~~~~~~~~~~~~adrci GI purge started~~~~~~~~~~~~~~~~~~~~~~
    2022-01-20 11:01:04: I Checking if this is an Oracle Restart environment
    2022-01-20 11:01:04: I DRYRUN - adrci GI purging diagnostic destination diag/asm/+asm/+ASM1 older than 10 days
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/asm/+asm/+ASM1;purge -age 14400 -type ALERT "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/asm/+asm/+ASM1;purge -age 14400 -type INCIDENT "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/asm/+asm/+ASM1;purge -age 14400 -type TRACE "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/asm/+asm/+ASM1;purge -age 14400 -type CDUMP "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/asm/+asm/+ASM1;purge -age 14400 -type STAGE "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/asm/+asm/+ASM1;purge -age 14400 -type SWEEP "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/asm/+asm/+ASM1;purge -age 14400 -type HM "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/asm/+asm/+ASM1;purge -age 14400 -type UTSCDMP "'
    2022-01-20 11:01:04: I DRYRUN - adrci GI purging diagnostic destination diag/tnslsnr/dev-testdb/listener older than 10 days
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/tnslsnr/dev-testdb/listener;purge -age 14400 -type ALERT "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/tnslsnr/dev-testdb/listener;purge -age 14400 -type INCIDENT "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/tnslsnr/dev-testdb/listener;purge -age 14400 -type TRACE "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/tnslsnr/dev-testdb/listener;purge -age 14400 -type CDUMP "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/tnslsnr/dev-testdb/listener;purge -age 14400 -type STAGE "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/tnslsnr/dev-testdb/listener;purge -age 14400 -type SWEEP "'
            su grid -c 'export ORACLE_HOME=/u01/app/11.2.0/grid;/u01/app/11.2.0/grid/bin/adrci exec="set homepath diag/tnslsnr/dev-testdb/listener;purge -age 14400 -type HM "'
    ......

    可以看到脚本实际就是使用了echo来清理日志的。10[天]这个参数不生效。

  • 相关阅读:
    XML 使用例子(转)
    [转载]网游数据解释
    [转载]游戏引擎列表
    (转)XML 使用
    LuaPlus新手使用方法(转)
    [转载]很有参考意义的显卡性能排行榜
    (转)LuaPlus子表遍历
    (转)LuaPlus集成Lua脚本
    HTML5尝鲜(1):使用aduio标签打造音乐播放器
    oracle的rollup
  • 原文地址:https://www.cnblogs.com/PiscesCanon/p/15825693.html
Copyright © 2020-2023  润新知