客户提出了一个需求,他们改进了自己的程序,想证明程序现在open cursor变少了,也就是说程序运行过程中 open cursor的峰值变小了。 我写了一个脚本来进行这个监控。
oracle[aaa]@server:[/tmp/20140506]>more count.sql
select count(*) from v$open_cursor where sid=264;
oracle[aaa]@server:[/tmp/20140506]>more run.sh
while true
do
a=`sqlplus -s / as sysdba <<F
@count.sql
EXIT
F`
b=`(echo $a | cut -d' ' -f3)`
echo $b>>check.txt
echo ''>>check.txt
sleep 5
done
很直观的方法,每5秒运行一次sql select count(*) from v$open_cursor where sid= 。 这样把最后的结果进行排序找出峰值就可以了。