How to Delete Archivelog in Oracle Dataguard Automatically

Hi,

Archivelogs in Oracle database are accumulated or kept when they are not deleted automatically.

 

You should define any deletion job for Standby database to delete older archivelogs automatically.

To delete archivelogs automatically, we need to create Crontab job in linux like following.

 

[oracle@MehmetSalih ~] crontab -e

Type following query in crontab to run RunDeleteArchive.sh bash script in 23:00

00 23 * * * sh /oracle/script/RunDeleteArchive.sh >/oracle/script/Delete.log
[oracle@MehmetSalih ~]

 

You can list crontab job like following if it is created or not.

[oracle@MehmetSalih ~] crontab -l
00 23 * * * sh /oracle/script/RunDeleteArchive.sh >/oracle/script/Delete.log
[oracle@MehmetSalih ~]

 

Open /oracle/script/RunDeleteArchive.sh bash script file with vi or vim editor and paste following scripts.

Firstly we set Oracle database environments after that we want to execute /oracle/script/DeleteArchive.rman script to connect rman and delete archivelogs.

 

 

[oracle@MehmetSalih ~] vi RunDeleteArchive.sh 
export ORACLE_BASE=/oracle/app
export ORACLE_HOME=/oracle/app/product/12.1.0.2/db
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P9
export ORACLE_SID=DEVECIDG
export PATH=$ORACLE_HOME/bin:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin:$PATH

rman target / @/oracle/script/DeleteArchive.rman
exit

 

you can see the content of /oracle/script/RunDeleteArchive.sh like following.

[oracle@MehmetSalih ~] cat RunDeleteArchive.sh 
export ORACLE_BASE=/oracle/app
export ORACLE_HOME=/oracle/app/product/12.1.0.2/db
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P9
export ORACLE_SID=DEVECIDG
export PATH=$ORACLE_HOME/bin:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin:$PATH

rman target / @/oracle/script/DeleteArchive.rman
exit

 

We need to insert following rman commands to the /oracle/script/DeleteArchive.rman file like following.

[oracle@MehmetSalih ~] vi DeleteArchive.rman 
run{
delete noprompt archivelog until time 'sysdate -1';
crosscheck archivelog all;
}
[oracle@MehmetSalih ~]

 

you can see the content of /oracle/script/DeleteArchive.rman like following.

[oracle@MehmetSalih ~] cat DeleteArchive.rman 
run{
delete noprompt archivelog until time 'sysdate -1';
crosscheck archivelog all;
}
[oracle@MehmetSalih ~]

 

Now Archivelogs older than 1 day in Standby database will be deleted automatically in Oracle dataguard.

 

 

Do you want to learn Oracle Database for Beginners, then read the following articles.

https://ittutorial.org/oracle-database-19c-tutorials-for-beginners/

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

Leave a Reply

Your email address will not be published. Required fields are marked *