sqlplus 使用之六 模拟多进程压测

os: centos 7.4
db: oracle 11.2.0.4

create table

SQL> create table tmp_t0(c0 varchar2(100),c1 varchar2(100),c2 varchar2(100),c3 date );

shell 并发启动 100个进程

$ vi insert_date.sh 

#!/bin/bash
for((i=1;i<=100;i++));
do
(
sqlplus -S /nolog <<EOF
conn scott2/oracle
begin 
  for c_f in (
     select level as id
       from dual
      connect by level <=10000
  )
  loop
     insert into tmp_t0
     values(sys_guid(),c_f.id,c_f.id,sysdate)
     ;
     commit;
  end loop;

end;
/
exit
EOF
)&
done
wait

v$session 查看阻塞情况

with/*+ materialized +*/ aa as (
      select *
        from gv$session s
       where 1=1
)
select 
      'alter system kill session ''' || t.SID || ',' || t.SERIAL# || ''' immediate;' as kill_SID,
      lpad('+', 2 * level - 1) ||t.inst_sid as leveL_inst_sid,
      level level_flag,
      sys_connect_by_path(t.inst_sid,'/') as inst_sid_path,
      connect_by_root t.inst_sid as root_inst_sid,
      connect_by_isleaf as node_isleaf,
      '##########' as FLAGFLAG0, 
       t.status, 
       t.event#, 
       t.event, 
       t.program,
       t.module,
       t.action,
       t.client_identifier,
       t.OSUSER os_USER,
       t.machine os_machine,
       t.logon_time logon_time,
       t.last_call_et last_call_et,
       'alter system kill session ''' || t.SID || ',' || t.SERIAL# || ''' immediate;' as kill_SID,
      '##########' as FLAGFLAG,
      t.*  
from (
        select gs.inst_id||'-'||gs.sid as inst_sid,
               gs.blocking_instance||'-'||gs.blocking_session par_inst_sid,
               gs.*
          from aa gs
         where 1=1
           and (gs.inst_id,gs.sid ) in (
                    --被阻塞者
                    select s.inst_id,s.sid
                      from aa s
                     where 1=1
                       and s.BLOCKING_SESSION is not null
                    union all         
                    --阻塞者
                    select sw.inst_id,sw.sid
                      from aa sw
                     where 1=1
                     --and lower(sw.MACHINE) not like '%ejb%'
                       and (sw.INST_ID,sw.SID) in (
                          select/*+ hash_sj*/ 
                                s.BLOCKING_INSTANCE,
                                s.BLOCKING_SESSION
                           from aa s
                          where 1=1
                            and s.BLOCKING_SESSION is not null
                       )    
        )   
     ) t
where 1=1
 connect by prior t.inst_sid =t.par_inst_sid 
order siblings by t.inst_sid  
;

在这里插入图片描述

发布了721 篇原创文章 · 获赞 70 · 访问量 50万+

猜你喜欢

转载自blog.csdn.net/ctypyb2002/article/details/104191845