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的定时分析表的任务就做完!!!

收工!!

转载于:https://www.cnblogs.com/aqqa/archive/2011/12/05/2276868.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值