Skip to Main Content
  • Questions
  • How to delete records from the unified_audit_trail from one year ago.

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Eduardo.

Asked: July 29, 2025 - 7:17 pm UTC

Last updated: August 05, 2025 - 2:48 am UTC

Version: 12.1.0.2.0

Viewed 1000+ times

You Asked

How to delete records from the unified_audit_trail from one year ago?

The database is version 12.1.0.2.0, and I'm having trouble with queries because they're slow.

and Chris said...

The dbms_audit_mgmt package offers various ways to clear the audit trail.

For example, to remove logs created more than 365 days ago, you can:

- Use set_last_archive_timestamp to set this date
- Run clean_audit_trail to remove these

Like so:
begin
  dbms_audit_mgmt.set_last_archive_timestamp (
    audit_trail_type     =>  dbms_audit_mgmt.audit_trail_unified,
    last_archive_time    =>  systimestamp - 365
  );

  dbms_audit_mgmt.clean_audit_trail (
    audit_trail_type        => dbms_audit_mgmt.audit_trail_unified,
    use_last_arch_timestamp => true
  );
end;
/


If you have a large number of audit records to remove, this can take a long time. So it may be best to submit this as a job.

For more details, see the docs https://docs.oracle.com/database/121/DBSEG/audit_admin.htm#DBSEG90934

Rating

  (3 ratings)

Comments

Eduardo Pacheco Ledezma, July 31, 2025 - 4:04 pm UTC

Tanks for yoy help,

error ORA

Eduardo Pacheco, August 01, 2025 - 2:00 am UTC

Hi
I try and I get an error


ORA-08180: no snapshot found based on specified time
ORA-06512: at "SYS.TIMESTAMP_TO_SCN", line 1

Help me please
Connor McDonald
August 01, 2025 - 3:54 am UTC

Known bug that was fixed a long time ago .... that's the price of staying such an old release :-(

Thank you very much for your attention

Eduardo Pacheco Ledezma, August 04, 2025 - 4:38 pm UTC

Thank you very much for your attention
Connor McDonald
August 05, 2025 - 2:48 am UTC

glad we could help

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library