Rotate and Purge Oracle Log Files

Every running Oracle installation has several directories and files that need to be rotated and/or purged. Surprisingly, or not, Oracle has not included this basic maintenance in their software. I have come across the oraclean utility in the past, but the script does not do everything I need.

To achieve what I required, I recently hacked together a single script that does the following things:

  • Cleans audit_dump_dest.
  • Cleans background_dump_dest.
  • Cleans core_dump_dest.
  • Cleans user_dump_dest.
  • Cleans Oracle Clusterware log files.
  • Rotates and purges alert log files.
  • Rotates and purges listener log files.

The script has been tested on Solaris 9 and 10 with Oracle database versions 9i and 10g. It has also been tested with Oracle Clusterware and ASM 11g. The script can be scheduled on each server having one or more Oracle homes installed, and it will clean all of them up using the retention policy specified. The limitation is that log file retention is specified per server, not per instance. However, I find that placing a single crontab entry on each database server is easier than setting up separate log purge processes for each one.

The script finds all unique Oracle Homes listed in the oratab file and retrieves the list of running Oracle instances and listeners. Once the script knows that information, it rotates and cleans the trace, dump, and log files.

Download: cleanhouse.sh

Usage: [bash]cleanhouse.sh -d DAYS [-a DAYS] [-b DAYS] [-c DAYS] [-n DAYS] [-r DAYS] [-u DAYS] [-t] [-h]
-d = Mandatory default number of days to keep log files that are not explicitly passed as parameters.
-a = Optional number of days to keep audit logs.
-b = Optional number of days to keep background dumps.
-c = Optional number of days to keep core dumps.
-n = Optional number of days to keep network log files.
-r = Optional number of days to keep clusterware log files.
-u = Optional number of days to keep user dumps.
-h = Optional help mode.
-t = Optional test mode. Does not delete any files.[/bash]

How To Download Patches From Oracle E-Delivery

Have you ever wanted to automatically download all of the patches on an Oracle E-Delivery page? We have, and we thought this script might be useful to others.

Script: get_edelivery.sh

Prerequisites:

  • Firefox Browser on your desktop
  • Export Domain Cookies Firefox Plugin

Instructions:

  • Visit Oracle E-Delivery.
  • Select the software you would like to download and navigate to the patch download page.
  • Note the “egroup_aru_number” from the URL.
    • For example, the number is 11249872 for URL below: [text]http://edelivery.oracle.com/EPD/Download/get_form?egroup_aru_number=11249872.[/text]
  • Export your browser cookies using the “Export Domain Cookies” Firefox Plugin.
  • Copy your cookies file to the server.
  • Run the download script from the directory where you are going to download the patches.
    • [bash]get_edelivery.sh 11249872 cookies.txt[/bash]

The script will download all of the patches available via “Download” buttons on the E-Delivery page. At the very end, it will perform a checksum on each file. If a file fails, you can delete the corrupt file and run the script again.

How To Move Oracle Online Redo Log Files

Issue


You have online redo log files in the wrong place and want to move them.

Solution


  1. Run the following SQL to locate the current redo log groups and their members:
  2. [sql]select l.group# group_number<br />
    , l.status group_status<br />
    , f.member group_member<br />
    , f.status file_status<br />
    from v$log l<br />
    , v$logfile f<br />
    where l.group# = f.group#<br />
    order by l.group#, f.member;[/sql]

  3. Find a location that can contain the new log files.
  4. Create the new log files using the following SQL. Note that there must be at least two logfile groups after dropping unnecessary log files.
  5. [sql]sqlplus /nolog<br />
    connect / as sysdba<br />
    alter database add logfile (‘/path/to/new/redo_01_01.log’,’/path/to/new/redo_01_02.log’;) size 150M;<br />
    alter database add logfile (‘/path/to/new/redo_02_01.log’,’/path/to/new/redo_02_02.log’;) size 150M;[/sql]

  6. Run the SQL from Step 1 to determine which logfile is CURRENT.
  7. Run the following command to switch log files. After running the SWITCH command, run the SQL from Step 1 again. Repeat the process until one of the newly created logfile groups has a CURRENT status.
  8. [sql]alter system switch logfile;[/sql]

  9. After one of the newly created log files is CURRENT, run the following SQL. You should only drop logfile groups that have an INACTIVE status.
  10. [sql]alter database drop logfile group GROUP#;[/sql]

  11. Repeat Step 6 for each undesired logfile group.
  12. Delete the old redo log files from the file system.
  13. References


    Oracle® Database Administrator’s Guide – Managing the Redo Log