undo_analyze.sh

#####added by hurp for undo analyze ##############
10 * * * * sh /oracle/hurp/undo_analyze.sh >/oracle/hurp/undo_analyze.log 2>&1 &

[oracle@c4oyy1a] /oracle> more /oracle/hurp/undo_analyze.sh 
#!/usr/sbin
. /oracle/.profile
$ORACLE_HOME/bin/sqlplus / as sysdba <<EOF
exec shsnc.undo_analyze('SHSNC','UNDO_ANALYZE_TABLE','D_MT_01','UNDO1');
EXIT;   
EOF


create or replace procedure       undo_analyze(owner_name varchar2,tb_name varchar2,tbs_name varchar2,tbs_undo varchar2) is
sesundo_size number;
tbs_usedpercent_count number;
t_count number;
v_sql varchar2(4000);
begin
select count(1) into tbs_usedpercent_count from dba_tablespace_usage_metrics where tablespace_name=tbs_undo AND USED_PERCENT>90;


if tbs_usedpercent_count=1 then
select count(1) into t_count from USER_tables where table_name=tb_name;
if t_count=0 then
v_sql:='create table '||owner_name||'.'||tb_name||'(sid number,
        program varchar(48),
        machine VARCHAR2(64),
        tx_addr varchar(60),
        status varchar(16),
        start_time varchar(20),
        tablespace_name varchar2(30),
        undo_size_mb number,
        used_urec number) tablespace '||tbs_name;
execute immediate v_sql;
v_sql:='insert into  '||owner_name||'.'||tb_name||'   select s.sid,
       substr(s.program, 1, 15) program,
       s.machine,
       t.xidusn ||''.''||  t.xidslot ||''.'' || t.xidsqn tx_addr,
       t.status,
       t.start_time,
       tbs.tablespace_name,
       round(t.used_ublk * tbs.block_size / 1024 / 1024, 2) undo_size_mb,
       t.used_urec
  from v$transaction t, v$session s, v$parameter p, dba_tablespaces tbs
 where t.ses_addr = s.saddr
   and p.name = ''undo_tablespace''
   and p.value = tbs.tablespace_name
   and round(t.used_ublk * tbs.block_size / 1024 / 1024, 2) >100
 order by t.used_ublk desc ';
execute immediate v_sql;
 commit;
 else
 v_sql:=' insert into  '||owner_name||'.'||tb_name||'   select s.sid,
       substr(s.program, 1, 15) program,
       s.machine,
       t.xidusn || ''.'' || t.xidslot || ''.'' || t.xidsqn tx_addr,
       t.status,
       t.start_time,
       tbs.tablespace_name,
       round(t.used_ublk * tbs.block_size / 1024 / 1024, 2) undo_size_mb,
       t.used_urec
  from v$transaction t, v$session s, v$parameter p, dba_tablespaces tbs
 where t.ses_addr = s.saddr
   and p.name = ''undo_tablespace''
   and p.value = tbs.tablespace_name
   and round(t.used_ublk * tbs.block_size / 1024 / 1024, 2) >100
 order by t.used_ublk desc';
 execute immediate v_sql;
 commit;
 end if;
 end if;
 end;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29446986/viewspace-1762392/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29446986/viewspace-1762392/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值