简体   繁体   中英

SQL Oracle: find last timestamp a view/package/function was used

I want to clean up our database by dropping old views, packages, and so on. So we do not need to maintain them anymore. I know there are tons of supporting views from Oracle's side like all_views for example. Is there any such a thing with a last used date or such a thing?

Best regards, Peter

There is no such thing as LAST USED TIME, if by that you mean the last time an object ( table, view, procedure, function, package, type, synonym, etc... ) has been used by an user process.

To actually know that you would need to have AUDIT enabled, but audit is not intended to be enable for everything, only for specific reasons, and with a lot of care because it has performance considerations.

Imagine I have a lot of objects owned by TEST_USER. I want to know how many are being used:

AUDIT ALL BY TEST_USER BY ACCESS;

Beginning with 11g release of Oracle Database, both BY SESSION and BY ACCESS cause Oracle Database to write one audit record for each audited statement and operation. BY SESSION continues to populate different values to the audit trail compared with BY ACCESS. If you specify neither clause, then BY SESSION is the default.

Read here more information about audit

https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_4007.htm#SQLRF01107

The only fields you have in DBA_OBJECTS ( ALL_OBJECTS ) are:

  • CREATED: Timestamp for the creation of the object.
  • LAST_DDL_TIME Timestamp for the last modification of the object resulting from a DDL statement (including grants and revokes ).

You can also see in DBA_DEPENDENCIES the dependencies between each other ( not valid when objects are invoked by dynamic sql ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM