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

王朝学院·作者佚名  2009-04-22
窄屏简体版  字體: 小  |  中  |  大  |  超大  

定时分析用户下的所有表

你的数据库运行在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的定时分析表的任务就做完!!!

收工!!

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航