Link to home
Start Free TrialLog in
Avatar of hussainkhan22
hussainkhan22Flag for United States of America

asked on

adrci set log purging

How do I use adrci to set log purging. I really appreciate your help. Thanks in advance for your time and help.
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Avatar of hussainkhan22

ASKER

I need an automatic script for purging log files using adrci.
If there is not built-in function to get this added to the default maintenance window then, put the commands in a script file and schedule it?
its oracle11g database on linux server. Please provide me the automatic script for purging using adrci. Thanks in advance.
$ uname -a
SunOS rdsun02 5.10 Generic_144488-06 sun4u sparc SUNW,Ultra-80

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE    11.1.0.7.0      Production
TNS for Solaris: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production


$ cd /tmp

$ vi adrci.sql
 
#!/usr/bin/ksh
#
#
#
# Description
# Shell script to interact with the ADR through ADRCI and purge ADR contents
#
# Tunables
###
LOCKFILE=/tmp/mor_adrci_purge_.lck
###

######
# Start Of Functions
#
# tidyup . common fuction called if error has occured
tidyup () {
        rm -f ${LOCKFILE}
        echo "ERROR: Purge aborted at `date` with exit code ${ERR}"
        exit ${ERR}
}

######
# End Of Functions

### Main Program

# Check user is oracle
USERID=`/usr/bin/id -u -nr`
if [ $? -ne 0 ]
then
        echo "ERROR: unable to determine uid"
        exit 99
fi
if [ "${USERID}" != "oracle" ]
then
        echo "ERROR: This script must be run as oracle"
        exit 98
fi

echo "INFO: Purge started at `date`"

# Check if lockfile exists
if [ -f ${LOCKFILE} ]
then
        echo "ERROR: Lock file already exists"
        echo "       Purge already active or incorrectly terminated"
        echo "       If you are sure tidy isn.t active, please remove " 
        echo "       ${LOCKFILE}"
        exit 97
fi

# Create lock file
touch ${LOCKFILE} 2>/dev/null
if [ $? -ne 0 ]
then
        echo "ERROR: Unable to create lock file"
        exit 96
fi

# Purge ADR contents
echo "INFO: adrci purge started at `date`"
/appl/oracle/product/v111/bin/adrci exec="show homes"|grep -v : | while rea
d file_line
do
  echo "INFO: adrci purging diagnostic destination " $file_line
  echo "INFO: purging ALERT older than 90 days .."
  /appl/oracle/product/v111/bin/adrci exec="set homepath $file_line;purge -
age 129600 -type ALERT"
  echo "INFO: purging INCIDENT older than 30 days .."
  /appl/oracle/product/v111/bin/adrci exec="set homepath $file_line;purge -
age 43200 -type INCIDENT"
  echo "INFO: purging TRACE older than 30 days .."
  /appl/oracle/product/v111/bin/adrci exec="set homepath $file_line;purge -
age 43200 -type TRACE"
  echo "INFO: purging CDUMP older than 30 days .."
  /appl/oracle/product/v111/bin/adrci exec="set homepath $file_line;purge -
age 43200 -type CDUMP"
  echo "INFO: purging HM older than 30 days .."
  /appl/oracle/product/v111/bin/adrci exec="set homepath $file_line;purge -
age 43200 -type HM"
  echo "" 
  echo "" 
done

echo
echo "INFO: adrci purge finished at `date`"

# All completed
rm -f ${LOCKFILE}
echo "SUCC: Purge completed successfully at `date`"

exit 0
----------------------------------------------------------------------------------------------
Getting the below errors

SQL> @/tmp/adrci.sql
SP2-0734: unknown command beginning "!/usr/bin/..." - rest of line ignored.
SP2-0734: unknown command beginning "Descriptio..." - rest of line ignored.
SP2-0734: unknown command beginning "Shell scri..." - rest of line ignored.
SP2-0042: unknown command "Tunables" - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SP2-0042: unknown command "##" - rest of line ignored.
SP2-0734: unknown command beginning "LOCKFILE=/..." - rest of line ignored.
SP2-0042: unknown command "##" - rest of line ignored.
SP2-0042: unknown command "#####" - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SP2-0310: unable to open file "Of.sql"
SP2-0734: unknown command beginning "tidyup . c..." - rest of line ignored.
SP2-0734: unknown command beginning "tidyup () ..." - rest of line ignored.
SP2-0734: unknown command beginning "rm -f ${LO..." - rest of line ignored.
SP2-0734: unknown command beginning "echo "ERRO..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
Usage: { EXIT | QUIT }  [ SUCCESS | FAILURE | WARNING | n |
       <variable> | :<bindvariable> ]  [ COMMIT | ROLLBACK ]
Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production




What you posted is a UNIX shell script not a SQLplus script.

You need to execute it from a UNIX command line.
how do I execute from unix please let me know?
I have saved that file as adrci.sh
$./adrci.sh
/usr/bin/id : illegal option -- u
Usage : id [-ap] [user]
ERROR: unable to determine uid
Please help me its urgent, I need to test the script and submit by end of day today
$ uname -a
SunOS rdsun02 5.10 Generic_144488-06 sun4u sparc SUNW,Ultra-80

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE    11.1.0.7.0      Production
TNS for Solaris: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production


$ cd /tmp

$ vi adrci.sh
 
#!/usr/bin/ksh
#
#
#
# Description
# Shell script to interact with the ADR through ADRCI and purge ADR contents
#
# Tunables
###
LOCKFILE=/tmp/mor_adrci_purge_.lck
###

######
# Start Of Functions
#
# tidyup . common fuction called if error has occured
tidyup () {
        rm -f ${LOCKFILE}
        echo "ERROR: Purge aborted at `date` with exit code ${ERR}"
        exit ${ERR}
}

######
# End Of Functions

### Main Program

# Check user is oracle
USERID=`/usr/bin/id -u -nr`
if [ $? -ne 0 ]
then
        echo "ERROR: unable to determine uid"
        exit 99
fi
if [ "${USERID}" != "oracle" ]
then
        echo "ERROR: This script must be run as oracle"
        exit 98
fi

echo "INFO: Purge started at `date`"

# Check if lockfile exists
if [ -f ${LOCKFILE} ]
then
        echo "ERROR: Lock file already exists"
        echo "       Purge already active or incorrectly terminated"
        echo "       If you are sure tidy isn.t active, please remove " 
        echo "       ${LOCKFILE}"
        exit 97
fi

# Create lock file
touch ${LOCKFILE} 2>/dev/null
if [ $? -ne 0 ]
then
        echo "ERROR: Unable to create lock file"
        exit 96
fi

# Purge ADR contents
echo "INFO: adrci purge started at `date`"
/appl/oracle/product/v111/bin/adrci exec="show homes"|grep -v : | while rea
d file_line
do
  echo "INFO: adrci purging diagnostic destination " $file_line
  echo "INFO: purging ALERT older than 90 days .."
  /appl/oracle/product/v111/bin/adrci exec="set homepath $file_line;purge -
age 129600 -type ALERT"
  echo "INFO: purging INCIDENT older than 30 days .."
  /appl/oracle/product/v111/bin/adrci exec="set homepath $file_line;purge -
age 43200 -type INCIDENT"
  echo "INFO: purging TRACE older than 30 days .."
  /appl/oracle/product/v111/bin/adrci exec="set homepath $file_line;purge -
age 43200 -type TRACE"
  echo "INFO: purging CDUMP older than 30 days .."
  /appl/oracle/product/v111/bin/adrci exec="set homepath $file_line;purge -
age 43200 -type CDUMP"
  echo "INFO: purging HM older than 30 days .."
  /appl/oracle/product/v111/bin/adrci exec="set homepath $file_line;purge -
age 43200 -type HM"
  echo "" 
  echo "" 
done

echo
echo "INFO: adrci purge finished at `date`"

# All completed
rm -f ${LOCKFILE}
echo "SUCC: Purge completed successfully at `date`"

exit 0
---------------------------------------------------------------------------------

$./adrci.sh

/usr/bin/id : illegal option -- u
Usage : id [-ap] [user]
ERROR: unable to determine uid
Sorry I can't do much debuging. I'm not on unix.  

From the error it looks like I doesn't like the command:
USERID=`/usr/bin/id -u -nr`

its working fine now but how do I set this script for multiple servers and multiple databases to run automatically
How can we just do set_control and just set it automatically without calling this script above. Please help me.
I'm not familiar with the term set_control.  It may be a unix specific term.  I can try to help if you provide the context for that term.
My team lead requesting me to use set_control parameter with adrci to purge log file automatically in the back ground without calling the above script. I really appreciate if anyone could help me in it. Thanks in advance
Oh, no underscore:  set control.

Did you not read the links I posted in the first post?

I suggest you check the second one.  It is anchored to the set control syntax.
I have set control parameter its executed fine but still its not purging files.


When I am executing
$ adrci exec='set homepath diag/rdbms/<SID>/<SID>;set control \(SHORTP_POLICY=144, LONGP_POLICY=144\)"

its not purging files.

I have checked
Adrci> show control

Its showing last_autoprg_time as 4/2/2011 instead of todays time 4/6/2011.

do we need to set anything else for auto purge files, we planning to set this parameter so that it will auto purge automatically instead of running manually or as a script.
I really appreciate your help. thanks for your time and help in advance
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I need a script or command for adrci to automatically purge files in background, no need of running adrci or purge command everytime, I just want to run once and it must automatically purge files now and in future automatically
>>I just want to run once and it must automatically purge files now and in future automatically

and?  If I read the online docs right, you now have 'automatic' purging every 6 days.
Yes even after setting automatic setting after 6 days still it's not purging automatically. I need to issue purge from adrci than it's purging files older than 6 days. Can you please let me know how to purge automatically
What makes you think it isn't purging?  From the links above, the last 'purge' was on the 2nd.  The next 'purge' should be on the 8th.
I am sorry for very late response it didnt purge on april 8 also I have to manually use purge command to purge files which were set using set control shotp_policy and longp_policy
At this point I would suggest you contact Oracle Support and ask why it is not automatically purging.