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

收工!!

posted @ 2011-12-05 15:21  心碎行  阅读(933)  评论(0编辑  收藏  举报