When managing a lot of databases, finding a good policy to manage the archive log files is very important to make the work easy. Usually archive log files are placed on dedicate volumns, purge by space will help to maximumly keep the archive logs. Following is my implementation of this feature with Perl, the first parameter is the maximum archive log sequence in current archive log dir, the second parameter is the gigabytes to keep.
#
# getLogSequenceBySize
#
sub getLogSequenceBySize
{
my ($logseq, $szlimit) = @_;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,
$size,$atime,$mtime,$ctime,$blksize,$blocks);
my $totalsz = 0;
my ($archive_log);
$szlimit = 20 if (!defined($szlimit) or $szlimit < 20);
while ($totalsz < $szlimit)
{
$archive_log = findLogBySequence($logseq);
if (-e $archive_log)
{
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,
$size,$atime,$mtime,$ctime,$blksize,
$blocks) = stat($archive_log);
$totalsz = $totalsz + ($size/1024/1024/1024);
$logseq --;
}
else
{
last;
}
}
scalar $logseq;
}
More databases more useful with this script. I will write a windows version if I have enough time. Now I have run this script on my AIX and Linux Oracle databases and their dataguards.
