如何在linux下建立oracle统计分析的系统任务
金蝶云社区-云社区用户6q556819
云社区用户6q556819
5人赞赏了该文章 727次浏览 未经作者许可,禁止转载编辑于2018年05月17日 16:53:09

以oracle用户登录系统
1:增加脚本文件如test.sh并修改文件的执行权限chmod 777 
test.sh#!/bin/sh
cd /home/oracle
source /home/oracle/.bash_profile
sqlplus kdsa918/kdsa918@orcl 1>test.log<<EOF
@gen.sql;
EOF

2:生成统计脚本语句,vim gen.sql
set pages 0
set heading off
set echo off
set feedback off
spool an.sql
select 'analyze table '||table_name||' compute statistics;' from user_tables where table_name not like 'TM%' and table_name like 'T%' and instr(table_name,'_')>0;
select 'exec dbms_stats.gather_table_stats('''||sys_context('USERENV','CURRENT_USER')||''','''||table_name
  ||''','||'method_opt=>''for columns '||column_name||' size 254 '');' from user_tab_cols where virtual_column='YES' and table_name not like 'TMP%' and data_type<>'XMLTYPE' and hidden_column='NO';
spool off
@an.sql
exit


3:增加调度任务,例如每30分钟执行一次(crontab使用如果不清楚,请网上搜索)
crontab -e 
30 * * * * //home/oracle/test.sh >error.log 2>&1
注:
第一列 分钟
第二列 小时
第三列 天
第四列 月
第五列 每周第几天

4:如果没按计划执行,请查看error.log文件信息
5:确保crond服务已经启动
     service crond status   --查看状态
     service crond reload  --重新加载
     service crond start     --启动
     service crond stop     --停止
     service crond restart  --重新启动

赞 5