Posted on

Cleanup Database Logs with RMAN

Clean Archivelogs / ctrl file backups / flashback area 1.


The script below does the following things:

  • Removes (deletes) orphaned, expired and obsolete archivelogs and backups
  • Removes (deletes) past archivelogs
  • Removes (deletes) control file backups
  • Removes (deletes) flashback restore points on CDB and PDB(s)
  • Works with no parameters
  • Copy the script using this button →
RUN {
#Deletes obsolete and orphaned archivelogs and controlfile backups
change archivelog all crosscheck;
report obsolete orphan;
report obsolete;
crosscheck backup;
crosscheck copy;
crosscheck backup of controlfile;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt expired backup of controlfile;
delete force noprompt expired copy;
delete force noprompt obsolete orphan;
delete force noprompt obsolete;

#Deletes archivelogs
crosscheck archivelog all;
delete force noprompt archivelog all;

#Deletes flashback restore points
DECLARE
   l_drop_stmn VARCHAR2(300);
   CURSOR c1 IS
      SELECT 'DROP RESTORE POINT ' || rp.name ||
          CASE
            WHEN UPPER(rp.pdb_restore_point) = 'YES' THEN
              ' FOR PLUGGABLE DATABASE ' || pdb.name
          END as cmd
     FROM v$restore_point rp
        , v$pdbs pdb
    WHERE rp.con_id = pdb.con_id(+);
BEGIN
   DBMS_OUTPUT.ENABLE(1000);
   OPEN c1;
   LOOP
      FETCH c1 INTO l_drop_stmn;
      EXIT WHEN c1%NOTFOUND;
         EXECUTE IMMEDIATE l_drop_stmn;
   END LOOP;
EXCEPTION
   WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE(SQLERRM);
      NULL;
END;
/
}

  1. The script is proved to work with Oracle 12.2.;