I recently worked on a client's database, and their alert log had information going back four years. When trying to examine the log with vi, it would take several minutes to open the file due to it's enormity. To help them out, I used this simple little tool to keep the files in check.
As root, I simply created a new file in /etc/logrotate.d on each RAC node called ora_cleanup. The example below is from node 2. This will copy the alert log with a numerical extension and truncate the existing file. It performs this monthly and keeps 13 months worth of log information before deleting old files. The listener log grows much faster, so it is configured to rotate weekly and keep 53 weeks of files. The copytruncate parameter is important for the listener log because the listener process holds an open handle on the existing file.
# alert log /u01/app/oracle/diag/rdbms/orcl/orcl2/trace/alert_orcl2.log { monthly rotate 13 notifempty missingok copytruncate nocreate } # listener log /u01/app/asm/diag/tnslsnr/db102/listener_db102/trace/listener_db102.log { weekly rotate 53 notifempty missingok copytruncate nocreate }
After a few months, this is what the managed files look like in their directories.
$ cd /u01/app/oracle/diag/rdbms/orcl/orcl2/trace $ ls -arltp alert_orcl2* -rw-rw---- 1 oracle oinstall 50051579 Oct 10 15:17 alert_orcl2.log.5 -rw-rw---- 1 oracle oinstall 993219 Nov 1 04:02 alert_orcl2.log.4 -rw-rw---- 1 oracle oinstall 1124244 Dec 1 04:02 alert_orcl2.log.3 -rw-rw---- 1 oracle oinstall 1088332 Jan 1 04:02 alert_orcl2.log.2 -rw-rw---- 1 oracle oinstall 2163268 Feb 1 04:02 alert_orcl2.log.1 -rw-rw---- 1 oracle oinstall 279484 Feb 7 09:34 alert_orcl2.log $ cd /u01/app/asm/diag/tnslsnr/db102/listener_db102/trace $ ls -arltp listener_db102* -rw-rw---- 1 oracle oinstall 3857048716 Oct 10 15:28 listener_db102.log.18 -rw-rw---- 1 oracle oinstall 196362891 Oct 18 13:13 listener_db102.log.17 -rw-rw---- 1 oracle oinstall 40298571 Oct 20 04:02 listener_db102.log.16 -rw-rw---- 1 oracle oinstall 178408740 Oct 27 04:02 listener_db102.log.15 -rw-rw---- 1 oracle oinstall 188301497 Nov 3 04:02 listener_db102.log.14 -rw-rw---- 1 oracle oinstall 185073120 Nov 10 04:02 listener_db102.log.13 -rw-rw---- 1 oracle oinstall 178345071 Nov 17 04:02 listener_db102.log.12 -rw-rw---- 1 oracle oinstall 178945914 Nov 24 04:02 listener_db102.log.11 -rw-rw---- 1 oracle oinstall 165829858 Dec 1 04:02 listener_db102.log.10 -rw-rw---- 1 oracle oinstall 179395363 Dec 8 04:02 listener_db102.log.9 -rw-rw---- 1 oracle oinstall 175671704 Dec 15 04:02 listener_db102.log.8 -rw-rw---- 1 oracle oinstall 195136727 Dec 22 04:02 listener_db102.log.7 -rw-rw---- 1 oracle oinstall 195512012 Dec 29 04:02 listener_db102.log.6 -rw-rw---- 1 oracle oinstall 201759600 Jan 5 04:02 listener_db102.log.5 -rw-rw---- 1 oracle oinstall 204589312 Jan 12 04:02 listener_db102.log.4 -rw-rw---- 1 oracle oinstall 213276652 Jan 19 04:02 listener_db102.log.3 -rw-rw---- 1 oracle oinstall 212229296 Jan 26 04:02 listener_db102.log.2 -rw-rw---- 1 oracle oinstall 211244326 Feb 2 04:02 listener_db102.log.1 -rw-rw---- 1 oracle oinstall 159275570 Feb 7 09:35 listener_db102.log
Estupendo!
ReplyDeleteIt's the very first time I find how to use logrotate for Oracle's files and the example works perfectly. Thank's a lot.
Regards, Lorenzo
Wonderful... thanks a lot
ReplyDelete