oracle定时分析用户下的所有表

author:skate
time:  2009/04/16


定时分析用户下的所有表

 

你的数据库运行在CBO的模式下,就要对你的表经常做分析,尤其是变化
很大的表,这样oracle才会选择正确的执行计划,下面是我写的一个按时
分析表的一个的脚本


操作步骤:

1. 编写执行分析表的procedure
2. 编写调用procedure的os的shell脚本
3. 在os做crontab的定时任务


1. 编写执行分析表的procedure

 

create or replace procedure pro_analyze_user_objects (tablename varchar2  ---不分析的表名或表名的部分字符
)
is
  /*******************************************************
  author:skate
  time  :2009/04/16
  功能:分析大于1000行的表的统计信息
  说明:可以统计用户下的所有大于1000行的表,如果要统计其他用户
        ,只要把这个procedure放在相应的用户下或者用all_tables

  eg:exec pro_analyze_user_objects('_his')
 
  相关分析语句如下:
  analyze table D_COURSE compute statistics  for all indexes for all columns for table;
  analyze table D_COURSE compute statistics;
  ********************************************************/

 

cursor cur_tab is
select table_name
 from user_tables where num_rows>1000
 and table_name not like '%'||upper(tablename)||'%';
 
 record_cur_tab cur_tab%rowtype;


begin

open cur_tab;
loop
 fetch cur_tab into record_cur_tab;
 exit when cur_tab%notfound;
 execute immediate 'analyze table '|| record_cur_tab.table_name || ' compute statistics';
end loop;
end pro_analyze_user_objects;

 

2. 编写调用procedure的os的shell脚本


[oracle@svr-db-test sh]$ more ticket_analyze.sh
####################################
#author:skate
#time  :2009/04/16
#desc  : The timming analyze user of tables
####################################

cd /home/oracle/sh
date
sqlplus /nolog @ ticket_analyze.sql
date
exit
[oracle@svr-db-test sh]$

 


[oracle@svr-db-test sh]$ more ticket_analyze.sql
connect tickets/123456
set timing on
exec pro_analyze_user_objects('_his');
exit;

[oracle@svr-db-test sh]$

 

¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥


3. 在os做crontab的定时任务

 

 

#ayalyze tickets all tables

1 07 * * * sh /home/oracle/sh/ticket_analyze.sh >> /home/oracle/sh/ticket_analyze.log


这样一个每天7:01的定时分析表的任务就做完!!!

收工!!

 

 

---end---

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值