SQL 6
BC Clean sysaux xepdb1 By allan on 20th May 2026 06:36:42 AM
  1. -- Cronjob
  2. -- # Clean SYSAUX
  3. -- 30 1 * * 0  . /home/oracle/.bash_profile; cd /home/oracle/sql; sqlplus -s "/ as sysdba" @/home/oracle/sql/cleanup_sysaux_xepdb1.sql >/dev/null 2>&1
  4.  
  5. SET timing ON
  6.  
  7. SELECT to_char(sysdate, 'yyyy.mm.dd hh24:mi:ss') dt FROM dual;
  8.  
  9. spool clean_sysaux.log
  10.  
  11. prompt Cleanup started
  12.  
  13. ALTER SESSION SET container=xepdb1;
  14.  
  15. prompt DELETE expired tasks
  16. EXEC prvt_advisor.delete_expired_tasks;
  17.  
  18. prompt Rebuild indices TO reclaim SPACE
  19. EXEC dbms_pdb.exec_as_oracle_script('alter table WRI$_ADV_OBJECTS move');
  20. ALTER INDEX WRI$_ADV_OBJECTS_PK rebuild;
  21. ALTER INDEX WRI$_ADV_OBJECTS_IDX_01 rebuild;
  22.  
  23. prompt Clean Job Scheduler
  24. prompt Purge the ROWS FROM BOTH the job log AND the window log
  25. DECLARE
  26.     v_oldest INTEGER := 900;    -- days
  27.     v_increment INTEGER := 1;
  28.     v_cur_age INTEGER;
  29.     v_min_age INTEGER := 3;     -- Retain 4 days
  30. BEGIN
  31.     v_cur_age := v_oldest;
  32.     WHILE v_cur_age >= v_min_age LOOP
  33.         dbms_scheduler.purge_log(v_cur_age, 'JOB_AND_WINDOW_LOG');
  34.         commit;
  35.         v_cur_age := v_cur_age - v_increment;
  36.     END LOOP;
  37.     dbms_scheduler.purge_log(v_min_age, 'JOB_AND_WINDOW_LOG');
  38.     commit;
  39. EXCEPTION
  40.     WHEN OTHERS THEN
  41.         dbms_output.put_line('Execution halted with error number ' || sqlerrm);
  42. END;
  43. /
  44.  
  45. prompt CREATE a salvage TABLE TO store the ROWS they want TO keep
  46. CREATE TABLE scheduler$_job_output_copy tablespace SYSAUX AS SELECT * FROM scheduler$_job_output;
  47.  
  48. prompt TRUNCATE TABLE scheduler$_job_output:
  49. TRUNCATE TABLE scheduler$_job_output;
  50.  
  51. prompt Repopulate TABLE scheduler$_job_output:
  52. INSERT INTO scheduler$_job_output SELECT * FROM scheduler$_job_output_copy;
  53. commit;
  54.  
  55. prompt DROP the salvage TABLE:
  56. DROP TABLE scheduler$_job_output_copy purge;
  57. prompt Cleanup done.
  58. spool off
  59. exit

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.