Return-Path: <root@fatcity.cts.com>
Received: from ensim.rackshack.net (root@localhost)
 by orafaq.net (8.11.6/8.11.6) with ESMTP id gBD0BuZ11787
 for <oracle-l@orafaq.net>; Thu, 12 Dec 2002 18:11:56 -0600
X-ClientAddr: 209.68.248.164
Received: from newsfeed.cts.com (newsfeed.cts.com [209.68.248.164])
 by ensim.rackshack.net (8.11.6/8.11.6) with ESMTP id gBD0Bt311782
 for <oracle-l@orafaq.net>; Thu, 12 Dec 2002 18:11:56 -0600
Received: from fatcity.UUCP (uucp@localhost)
 by newsfeed.cts.com (8.9.3/8.9.3) with UUCP id MAA54017;
 Thu, 12 Dec 2002 12:54:47 -0800 (PST)
Received: by fatcity.com (26-Feb-2001/v1.0g-b72/bab) via UUCP id 00518DDA; Thu, 12 Dec 2002 11:48:47 -0800
Message-ID: <F001.00518DDA.20021212114847@fatcity.com>
Date: Thu, 12 Dec 2002 11:48:47 -0800
To: Multiple recipients of list ORACLE-L <ORACLE-L@fatcity.com>
X-Comment: Oracle RDBMS Community Forum
X-Sender: "Orr, Steve" <sorr@rightnow.com>
Sender: root@fatcity.com
Reply-To: ORACLE-L@fatcity.com
Errors-To: ML-ERRORS@fatcity.com
From: "Orr, Steve" <sorr@rightnow.com>
Subject: RE: Purging Managed Standby Database Archive Logs
Organization: Fat City Network Services, San Diego, California
X-ListServer: v1.0g, build 72; ListGuru (c) 1996-2001 Bruce A. Bergman
Precedence: bulk
Mime-Version: 1.0
Content-Type: multipart/alternative;	boundary="----_=_NextPart_001_01C2A217.4A479D30"
------_=_NextPart_001_01C2A217.4A479D30
Content-Type: text/plain;
 charset="iso-8859-1"

Hi John,

Keeping things simple sometimes complicates things when they go haywire. I
thought about the simple shotgun approach but wanted something a little more
robust and I didn't want to risk deleting an archive log that hadn't been
applied and then having to go through the hassle of finding in on tape. (We
use RMAN on production server and "archivelog all delete input" every
night.) A lot of logs could be zapped if the standby got hosed just before a
3-4 day weekend. I want to avoid having to rebuild the standby but I don't
want to keep multiple days worth of logs around either. I just want to
remove the logs that are no longer needed and the archive info is in the
data dictionary views so why not use it? 

Well after waiting on the list a while nobody did my job for me so I got
busy and rolled my own...   :-)
----------------------------------------------------------------------
#!/usr/bin/ksh
# File: sb_log_maint.sh ... Steve Orr, 12/12/2002
# Purpose: Purge standby database archive logs which have been applied.
ORAUBIN="/u01/app/oracle/bin"
SEQ_FILE="$ORAUBIN/last_purged_seqno.txt"
LAST_PURGED_SEQ=`cat ${SEQ_FILE}`

getAppliedLogs()
{
sqlplus -s "/ as sysdba" @$ORAUBIN/login.sql <<EOSQL
set feed off pages 0 echo off wra off
select sequence#, trim(name) from v\$archived_log
where sequence# > $LAST_PURGED_SEQ
and archived='YES'
order by sequence# ;
exit
EOSQL
}

getAppliedLogs | while read SEQNO FNAME
do
   echo "Removing file $FNAME"
   echo $SEQNO > $SEQ_FILE
   if [ -f $FNAME ]; then
      rm $FNAME
   fi
done
----------------------------------------------------------------------

...it seems to work and I wasn't in a PERLescent mood.


Steve Orr
Bozeman, Montana



-----Original Message-----
Sent: Thursday, December 12, 2002 10:19 AM
To: Multiple recipients of list ORACLE-L


Keep it simple.  If you are on unix put this in your crontab.

30 * * * * find  /archive/oradata/YOURSID -type f -name "1_*.arc"
-mtime +0 -exec rm -f {} \;

This will run every hour on the half hour and purge everything over 24
hours old.

Modify as you like.  (-mtime +1 gives you 48 hours)  Yes, I know this
could delete files that haven't been applied but I figure if your
standby is 24 hours behind, it will need to be re-established anyway.

HTH,
John


>>> sorr@rightnow.com 12/12/02 08:04AM >>>
Any one have a ready-made routine to purge the unneeded archives which
have
been automagically applied to a managed standby database?

I figure it needs to: 

1. Query v$archived_log and v$log_history to get a list of the archive
logs
(v$archived_log.name) where sequence# > [the max number you purged the
last
time];

2. Cycle through the above list and remove the files;

3. Record the max(sequence#) from v$log_history for the next purge.


Any other ideas/suggestions?


AtDhVaAnNkCsE!!!
Steve Orr
Standing by in Bozeman, Montana
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: John Carlson
  INET: jcarlson@CJ.COM

------_=_NextPart_001_01C2A217.4A479D30
Content-Type: text/html;
 charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2653.12">
<TITLE>RE: Purging Managed Standby Database Archive Logs</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>Hi John,</FONT>
</P>

<P><FONT SIZE=3D2>Keeping things simple sometimes complicates things =
when they go haywire. I thought about the simple shotgun approach but =
wanted something a little more robust and I didn't want to risk =
deleting an archive log that hadn't been applied and then having to go =
through the hassle of finding in on tape. (We use RMAN on production =
server and &quot;archivelog all delete input&quot; every night.) A lot =
of logs could be zapped if the standby got hosed just before a 3-4 day =
weekend. I want to avoid having to rebuild the standby but I don't want =
to keep multiple days worth of logs around either. I just want to =
remove the logs that are no longer needed and the archive info is in =
the data dictionary views so why not use it? </FONT></P>

<P><FONT SIZE=3D2>Well after waiting on the list a while nobody did my =
job for me so I got busy and rolled my own...&nbsp;&nbsp; :-)</FONT>
<BR><FONT =
SIZE=3D2>---------------------------------------------------------------=
-------</FONT>
<BR><FONT SIZE=3D2>#!/usr/bin/ksh</FONT>
<BR><FONT SIZE=3D2># File: sb_log_maint.sh ... Steve Orr, =
12/12/2002</FONT>
<BR><FONT SIZE=3D2># Purpose: Purge standby database archive logs which =
have been applied.</FONT>
<BR><FONT SIZE=3D2>ORAUBIN=3D&quot;/u01/app/oracle/bin&quot;</FONT>
<BR><FONT =
SIZE=3D2>SEQ_FILE=3D&quot;$ORAUBIN/last_purged_seqno.txt&quot;</FONT>
<BR><FONT SIZE=3D2>LAST_PURGED_SEQ=3D`cat ${SEQ_FILE}`</FONT>
</P>

<P><FONT SIZE=3D2>getAppliedLogs()</FONT>
<BR><FONT SIZE=3D2>{</FONT>
<BR><FONT SIZE=3D2>sqlplus -s &quot;/ as sysdba&quot; =
@$ORAUBIN/login.sql &lt;&lt;EOSQL</FONT>
<BR><FONT SIZE=3D2>set feed off pages 0 echo off wra off</FONT>
<BR><FONT SIZE=3D2>select sequence#, trim(name) from =
v\$archived_log</FONT>
<BR><FONT SIZE=3D2>where sequence# &gt; $LAST_PURGED_SEQ</FONT>
<BR><FONT SIZE=3D2>and archived=3D'YES'</FONT>
<BR><FONT SIZE=3D2>order by sequence# ;</FONT>
<BR><FONT SIZE=3D2>exit</FONT>
<BR><FONT SIZE=3D2>EOSQL</FONT>
<BR><FONT SIZE=3D2>}</FONT>
</P>

<P><FONT SIZE=3D2>getAppliedLogs | while read SEQNO FNAME</FONT>
<BR><FONT SIZE=3D2>do</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; echo &quot;Removing file =
$FNAME&quot;</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; echo $SEQNO &gt; $SEQ_FILE</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; if [ -f $FNAME ]; then</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rm $FNAME</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; fi</FONT>
<BR><FONT SIZE=3D2>done</FONT>
<BR><FONT =
SIZE=3D2>---------------------------------------------------------------=
-------</FONT>
</P>

<P><FONT SIZE=3D2>...it seems to work and I wasn't in a PERLescent =
mood.</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>Steve Orr</FONT>
<BR><FONT SIZE=3D2>Bozeman, Montana</FONT>
</P>
<BR>
<BR>

<P><FONT SIZE=3D2>-----Original Message-----</FONT>
<BR><FONT SIZE=3D2>From: John Carlson [<A =
HREF=3D"mailto:jcarlson@CJ.COM">mailto:jcarlson@CJ.COM</A>]</FONT>
<BR><FONT SIZE=3D2>Sent: Thursday, December 12, 2002 10:19 AM</FONT>
<BR><FONT SIZE=3D2>To: Multiple recipients of list ORACLE-L</FONT>
<BR><FONT SIZE=3D2>Subject: Re: Purging Managed Standby Database =
Archive Logs</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>Keep it simple.&nbsp; If you are on unix put this in =
your crontab.</FONT>
</P>

<P><FONT SIZE=3D2>30 * * * * find&nbsp; /archive/oradata/YOURSID -type =
f -name &quot;1_*.arc&quot;</FONT>
<BR><FONT SIZE=3D2>-mtime +0 -exec rm -f {} \;</FONT>
</P>

<P><FONT SIZE=3D2>This will run every hour on the half hour and purge =
everything over 24</FONT>
<BR><FONT SIZE=3D2>hours old.</FONT>
</P>

<P><FONT SIZE=3D2>Modify as you like.&nbsp; (-mtime +1 gives you 48 =
hours)&nbsp; Yes, I know this</FONT>
<BR><FONT SIZE=3D2>could delete files that haven't been applied but I =
figure if your</FONT>
<BR><FONT SIZE=3D2>standby is 24 hours behind, it will need to be =
re-established anyway.</FONT>
</P>

<P><FONT SIZE=3D2>HTH,</FONT>
<BR><FONT SIZE=3D2>John</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>&gt;&gt;&gt; sorr@rightnow.com 12/12/02 08:04AM =
&gt;&gt;&gt;</FONT>
<BR><FONT SIZE=3D2>Any one have a ready-made routine to purge the =
unneeded archives which</FONT>
<BR><FONT SIZE=3D2>have</FONT>
<BR><FONT SIZE=3D2>been automagically applied to a managed standby =
database?</FONT>
</P>

<P><FONT SIZE=3D2>I figure it needs to: </FONT>
</P>

<P><FONT SIZE=3D2>1. Query v$archived_log and v$log_history to get a =
list of the archive</FONT>
<BR><FONT SIZE=3D2>logs</FONT>
<BR><FONT SIZE=3D2>(v$archived_log.name) where sequence# &gt; [the max =
number you purged the</FONT>
<BR><FONT SIZE=3D2>last</FONT>
<BR><FONT SIZE=3D2>time];</FONT>
</P>

<P><FONT SIZE=3D2>2. Cycle through the above list and remove the =
files;</FONT>
</P>

<P><FONT SIZE=3D2>3. Record the max(sequence#) from v$log_history for =
the next purge.</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>Any other ideas/suggestions?</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>AtDhVaAnNkCsE!!!</FONT>
<BR><FONT SIZE=3D2>Steve Orr</FONT>
<BR><FONT SIZE=3D2>Standing by in Bozeman, Montana</FONT>
<BR><FONT SIZE=3D2>-- </FONT>
<BR><FONT SIZE=3D2>Please see the official ORACLE-L FAQ: <A =
HREF=3D"http://www.orafaq.com" =
TARGET=3D"_blank">http://www.orafaq.com</A></FONT>
<BR><FONT SIZE=3D2>-- </FONT>
<BR><FONT SIZE=3D2>Author: John Carlson</FONT>
<BR><FONT SIZE=3D2>&nbsp; INET: jcarlson@CJ.COM</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C2A217.4A479D30--
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Orr, Steve
  INET: sorr@rightnow.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru@fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

