当前位置 博文首页 > LuciferLiu_DBA:ORACLE19c新功能--TXT格式listener log自动Rota

    LuciferLiu_DBA:ORACLE19c新功能--TXT格式listener log自动Rota

    作者:[db:作者] 时间:2021-06-16 21:12

    19c之前的版本,ORACLE数据库的TXT格式listener log不能被自动循环管理(Mos 1744876.1),给使用者造成了很大负担。

    19c开始,导入了一下两个参数:

    https://docs.oracle.com/en/database/oracle/oracle-database/19/netrf/oracle-net-listener-parameters-in-listener-ora.html#GUID-FF94A234-A29C-46AA-8770-4CA1BFB5C27C

    7.5.3 LOG_FILE_NUM_listener_name
    The LOG_FILE_NUM_listener_name is a diagnostic parameter of the listener.ora file that specifies the number of log file segments.
    
    Purpose
    
    To specify the number of log file segments. At any point of time there can be only n log file segments where n is LOG_FILE_NUM_listener_name. If the log grows beyond this number, then the older segments are deleted.
    
    Default
    
    No default. If you don't specify a value, or set the value to zero, then the number of segments grows indefinitely.
    
    Values
    
    Any integer value.
    
    Example 7-9
    
    LOG_FILE_NUM_listener=3
    
    Parent topic: ADR Diagnostic Parameters for Oracle Net Listener
    
    7.5.4 LOG_FILE_SIZE_listener_name
    The LOG_FILE_SIZE_listener_name diagnostic parameter of the listener.ora file specifies the size of each log file segment.
    
    Purpose
    
    To specify the size of each log file segment. The size is in MB.
    
    Default
    
    300 MB
    
    Values
    
    Any integer value.
    
    Example 7-10 Example
    
    LOG_FILE_SIZE_listener=10

    通过上面的参数,TXT格式的listener log和XML格式的listener log一样可以自动循环管理了。

    例:

    LSNRCTL> stat
    Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
    STATUS of the LISTENER
    ------------------------
    Alias                     LISTENER
    Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
    Start Date                19-FEB-2021 14:43:38
    Uptime                    0 days 0 hr. 34 min. 55 sec
    Trace Level               off
    Security                  ON: Local OS Authentication
    SNMP                      OFF
    Listener Parameter File   /u01/app/oracle/product/19.0.0/db_1/network/admin/listener.ora
    Listener Log File         /u01/app/oracle/diag/tnslsnr/p19c/listener/alert/log.xml
    Listening Endpoints Summary...
      (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=p19c)(PORT=1521)))
    Services Summary...
    Service "bba8a80970b42669e0536438a8c0f7fd" has 1 instance(s).
      Instance "orcl", status READY, has 1 handler(s) for this service...
    Service "orcl" has 1 instance(s).
      Instance "orcl", status READY, has 1 handler(s) for this service...
    Service "orclXDB" has 1 instance(s).
      Instance "orcl", status READY, has 1 handler(s) for this service...
    The command completed successfully

    在/u01/app/oracle/product/19.0.0/db_1/network/admin/listener.ora文件中设置下面两个参数。

    oracle@p19c:/u01/app/oracle/product/19.0.0/db_1/network/admin$ cat listener.ora 
    
    LOG_FILE_NUM_LISTENER=8
    LOG_FILE_SIZE_LISTENER=1
    

    重启监听。

    LSNRCTL> stop
    Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
    The command completed successfully
    LSNRCTL> start
    Starting /u01/app/oracle/product/19.0.0/db_1/bin/tnslsnr: please wait...
    
    TNSLSNR for Linux: Version 19.0.0.0.0 - Production
    System parameter file is /u01/app/oracle/product/19.0.0/db_1/network/admin/listener.ora
    Log messages written to /u01/app/oracle/diag/tnslsnr/p19c/listener/alert/log.xml
    Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=p19c)(PORT=1521)))
    
    Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
    STATUS of the LISTENER
    ------------------------
    Alias                     LISTENER
    Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
    Start Date                19-FEB-2021 15:20:51
    Uptime                    0 days 0 hr. 0 min. 0 sec
    Trace Level               off
    Security                  ON: Local OS Authentication
    SNMP                      OFF
    Listener Parameter File   /u01/app/oracle/product/19.0.0/db_1/network/admin/listener.ora
    Listener Log File         /u01/app/oracle/diag/tnslsnr/p19c/listener/alert/log.xml
    Listening Endpoints Summary...
      (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=p19c)(PORT=1521)))
    The listener supports no services
    The command completed successfully
    

    测试一下。

    $> vi connect.sh
    #!/bin/bash
    while ( true ); do
    sqlplus -S -L?c##lucifer/lucifer@localhost:1521/cdb << EOF
    SELECT * FROM dual;
    EXIT;
    EOF
    done
    
    $> chmod +x connect.sh
    $> ./connect.sh > /dev/null
    $> ./connect.sh > /dev/null
    $> ./connect.sh > /dev/null
    $> ...
    

    ◆TXT格式listener log

    oracle@p19c:/u01/app/oracle/diag/tnslsnr/p19c/listener/trace$ du -sh *
    2.0M	listener_1.log
    488K	listener_2.log
    192K	listener.log
    

    ◆XML格式listener log

    oracle@p19c:/u01/app/oracle/diag/tnslsnr/p19c/listener/alert$ du -sh *
    3.8M	log_1.xml
    1.1M	log_2.xml
    448K	log.xml
    

    请注意上面的XML格式listener log的大小是1MB,TXT格式listener log却小于1MB。原因是两种格式的Log文件需要记录相同的接续记录,而每一条TXT格式的接续记录比XML格式使用的空间要小。

    另外,LOG_FILE_SIZE_listener的默认值是300MB,意味着即使不设置这个参数,XML的 listener log 到了300MB也会自动Rotation。