Tuesday, November 10, 2009

Manage Listener Log Files in 11g

In Oracle 11g, the listener log files by default are located in /diag/tnslsnr/product_name/listener. The nice feature about listener log file in this version is, whenever the size of log file grow to 10MB, Oracle starts to writes to a new file. So the log file will not be too large to open for troubleshooting. Overtime, you will have a lot of 10MB log file in the directory.


Oracle DBA needs to manage the listener log files regularly so the log files will not take too much space on the server. Based on my own experiment, compressed log files could take as little as 1/36 of the space uncompressed log files take. If you compressed the old listener log files in the same directory, when you tried to read the listener log file with ADRCI, you will get something similar to this:
------------------------------
>adrci
ADRCI: Release 11.1.0.6.0 - Beta on Tue Nov 10 09:53:49 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
ADR base = "/u01/app/oracle"
adrci> show alert
ADR Home = /u01/app/oracle/diag/tnslsnr/rhetdan/listener:
*************************************************************************
DIA-48156: Alert log purge has occurred - retry operation
DIA-48121: error with opening the ADR stream file [/u01/app/oracle/diag/tnslsnr/rhetdan/listener/alert/log_1.xml][0]
DIA-48127: attempting to open a file that does not exist
Linux Error: 2: No such file or directory
Additional information: 5
------------------------------
Log_1.xml is one of the files I have compressed with gzip.

Solution: create a subdirectory in the same alert directory. Move the entire compressed file into that subdirectory. ADRCI will not throw out error messages as it cannot see those files in the sub directory. ADRCI will read all the uncompressed file, combine them and present it as one file.

If you need to go back to those compressed files in the future for troubleshooting, you can unzip the file of your interest and use following command to open the file:

adrci>show alert –file /directory-where-you-have-the-logfile/yourlogfile.xml

Another observation: when you run ADRCI to purges old content of log files in the diag/tnslsnr/product_name/listener directory, the purge is based on the timestamp of files, not the content of them.

For example, I have following files :

-rw-r----- 1 oracle oinstall 6036 Sep 15 14:47 log.xml
-rw-r----- 1 oracle oinstall 348750 Sep 15 14:05 log.xml.gz


when running

adrci> purge -age 5 -type alert

only log.xml.gz is deleted. The content of log.xml is intact, even through some of the content in the log.xml are much older than five minutes.

The side effect of this purge operation is, all the old log files that are in the alert directory and that meet “age” requirement are purged, regardless whether they are compressed or not. You may lose old compressed log file you intent to keep. That is why I recommend saving old compressed log files in a sub directory, not current directory.

For the listener log files in /diag/tnslsnr/product_id/listener/trace, Oracle keeps them for backward compatibility purpose. The size of log files will grow and take up spaces. You can also compress them as you wish. After the log file is compressed, Oracle process will create a new log file with the same name when a network activity such as a new database connection occurred.
References:
1. http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/diag001.htm#CHDIABAA
2. http://download.oracle.com/docs/cd/B28359_01/server.111/b28278/diaus.htm#sthref13996
3. Metalink note # 816871.1, How To Purge Listener Log.Xml File?
4. Metalink note # 453125.1, 11g Diagnosability: Frequently Asked Questions, SQL*Net Listener Log File