我有一个包含1500张桌子的生产数据库。想要清理为测试目的而创建的一些表。是否有任何过程可以识别未使用的表。
注意:数据库中未启用审核
答案 0 :(得分:1)
您需要定期拍摄v$segment_statistics
的快照,然后随时间比较数据。
类似的东西:
create table usage_statistics
(
as_of timestamp,
table_name varchar(30),
table_owner varchar(30),
num_logical_reads number,
num_physical_reads number,
num_full_scans
);
然后创建例如cron
或dbms_scheduler
作业以运行以下
insert into usage_statistics (as_of, table_name, table_owner, num_logical_reads, num_physical_reads, num_full_scans)
select current_timestamp,
object_name,
owner,
sum(case when statistic_name = 'logical reads' then value end),
sum(case when statistic_name = 'physical reads' then value end),
sum(case when statistic_name = 'segment scans' then value end),
from v$segment_statistics
where owner in ('USER_NAME_1', 'USER_NAME_2')
and object_type = 'TABLE'
group by object_type, object_name
order by object_type, object_name;
当然,您需要调整要监视的所有者的名称。
以上语句仅检查三个统计信息。使用视图V$SEGSTAT_NAME查看v$segment_statistics
然后过一会儿,您可以比较每个表的读取变化。
答案 1 :(得分:0)
我从这里开始:
select table_name, last_analyzed
from user_tables
order by last_analyzed desc;
select table_name, last_analyzed
from all_tables
order by last_analyzed desc;
我问程序员,我删除了最早的表。