简体   繁体   English

SQL Oracle:查找使用视图/包/功能的最后时间戳

[英]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.我知道甲骨文方面有大量支持视图,例如 all_views。 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.没有最后使用时间之类的东西,如果你的意思是最后一次 object (表,视图,过程,function,package 类型已被用户使用,等等......

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.要真正知道您需要启用 AUDIT,但审计并非旨在为所有事情启用,仅出于特定原因,并且非常小心,因为它具有性能考虑。

Imagine I have a lot of objects owned by TEST_USER.想象一下,我有很多属于 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.从 Oracle 数据库的 11g 版本开始,BY SESSION 和 BY ACCESS 导致 Oracle 数据库为每个审计语句和操作写入一个审计记录。 BY SESSION continues to populate different values to the audit trail compared with BY ACCESS.与 BY ACCESS 相比,BY SESSION 继续向审计跟踪填充不同的值。 If you specify neither clause, then BY SESSION is the default.如果您没有指定任何子句,则默认为 BY SESSION。

Read here more information about audit在此处阅读有关审计的更多信息

https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_4007.htm#SQLRF01107 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:您在 DBA_OBJECTS ( ALL_OBJECTS ) 中拥有的唯一字段是:

  • CREATED: Timestamp for the creation of the object.已创建:创建 object 的时间戳。
  • LAST_DDL_TIME Timestamp for the last modification of the object resulting from a DDL statement (including grants and revokes ). LAST_DDL_TIME 上次修改 object 的时间戳,由 DDL 语句(包括 grants 和 revokes )产生。

You can also see in DBA_DEPENDENCIES the dependencies between each other ( not valid when objects are invoked by dynamic sql ).您还可以在 DBA_DEPENDENCIES 中看到彼此之间的依赖关系(当动态 sql 调用对象时无效)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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