Tuesday, May 9, 2023

Rotating Listener Log File

Rotating database log files is a common and day-to-day practice for DBAs. Rotation of logs is a process whereby we rename (and archive/compress) current log files so that new log files get created. Listener’s log file is also part of this practice because size of listener log file increases very fast, and it may increase beyond several GBs within a couple of months. If listener log file is not rotated, this may sometimes cause initial connection to database become slow. Therefore, this is very important to rotate listener log file. In the following I will explain how we rotate listener log file.

Listener log file name is same as listener name. Name of default listener is “listener”, hence the log file name is listener.log and it is located under $GRID_HOME/network/log by default. Command “lsnrctl status <listener_name>” also returns you the location of listener log file.

For rotating listener log, initiate lsnrctl utility, set current_listener to the listener for which you want to rotate listener log file, disable log_status, rename or truncate listener log file and in the end enable back log_status. Following is the sequence of commands.

Set log_status off

[grid: log]$ lsnrctl
 
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 09-MAY-2023 09:37:02
 
Copyright (c) 1991, 2022, Oracle.  All rights reserved.
 
Welcome to LSNRCTL, type "help" for information.
 
LSNRCTL> set current_listener listener
Current Listener is listener
 
LSNRCTL> set log_status on
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
listener parameter "log_status" set to ON

The command completed successfully

See this document if you face TNS-12508 while setting log_status to off.

Now rename or truncate listener log file at OS level

[grid: log]$  echo '' > listener.log
 
OR
 
[grid: log]$ mv listener.log listener.log_old

Set log_status back on

[grid: log]$ lsnrctl
 
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 09-MAY-2023 09:37:02
 
Copyright (c) 1991, 2022, Oracle.  All rights reserved.
 
Welcome to LSNRCTL, type "help" for information.
 
LSNRCTL> set current_listener listener
Current Listener is listener
LSNRCTL> set log_status on
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
listener parameter "log_status" set to ON

The command completed successfully


No comments:

Post a Comment

Popular Posts - All Times