- 最后登录
- 2014-12-16
- 在线时间
- 21 小时
- 威望
- 13
- 金钱
- 123
- 注册时间
- 2012-8-15
- 阅读权限
- 10
- 帖子
- 18
- 精华
- 0
- 积分
- 13
- UID
- 678
|
5#
发表于 2013-12-9 15:26:34
最后是如下实现的,输出的结果还等待验证。- -- 1.查看数据库中的所有用户,确认检查范围
- select * from dba_users where default_tablespace <> 'SYSTEM' and ACCOUNT_STATUS='OPEN';
- -- 2.执行dbms_stats.gather_schema_stats函数,做“非采样”分析
- exec dbms_stats.gather_schema_stats(
- ownname => 'YW',
- options => 'GATHER AUTO',
- estimate_percent => null,
- method_opt => 'for all columns size repeat',
- degree =>15)
- --3. 立即刷新状态信息
- exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;
- --附属操作,检查JOB是否有正常执行结束
- SELECT * FROM dba_optstat_operations ORDER BY start_time DESC;
- OPERATION, TARGET, START_TIME, END_TIME
- gather_schema_stats,YWUSER2,2013/12/8 23:52:03.481843 +08:00,2013/12/8 23:55:18.434827 +08:00
- --4. 执行条件查询(先找出有变化的,再求其补集)
- SELECT c.OWNER,
- c.TABLE_NAME,
- c.NUM_ROWS,
- d.TIMESTAMP AS last_modification
- FROM all_tables c, sys.dba_tab_modifications d
- WHERE c.TABLE_NAME NOT IN (SELECT a.TABLE_NAME
- FROM all_tables a,
- sys.dba_tab_modifications b
- WHERE a.TABLE_NAME = b.TABLE_NAME
- AND TABLE_OWNER = 'YW'
- AND b.TIMESTAMP > SYSDATE - 50)
- AND OWNER = 'YW'
- AND c.TABLE_NAME = d.TABLE_NAME
- AND c.num_rows > 100;
- --5. 验证结果正确性
复制代码 |
|