最近几天被厂商的数据库弄得头大,他们应用一小时能跑2TB的读数据出来
百度了一把搜索到了sql monitor这个工具出来,学习了一下
改成了脚本,执行以后会在/home/oracle目录下面生成badsql.txt文件,用more命令就可以看了
vi badsql.sh
添加下如内容
#!/bin/bash
su - oracle<<EOF
sqlplus / as sysdba
spool badsql.txt
col status fro a15
col username for a10
col module for a20
col PROGRAM for a20
set linesize 1000
set pagesize 300
select status,username,module,program,sql_id,PHYSICAL_READ_BYTES/1024/1024 READ_IO_MB,sql_text from v\$sql_monitor order by PHYSICAL_READ_BYTES desc;
spool off;
exit;
EOF
保存退出
打开badsql.txt文件
取出里面的sql_id,代入到下面的命令,就能出现详细的报告了
su - oracle
more badsql.txt
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
DONE (ALL ROWS) EOMSGZ JDBC Thin Client JDBC Thin Client 3371xmyjfzmxw 3936.85938
select commonfaul0_.id as id322_, commonfaul0_.mainId as mainId322_, commonfaul0_.title as title322_, commonfaul0_.mainApplySheetId as mainAppl4_322_, commonfaul0_.mai
nAlarmLevel as mainAlar5_322_, commonfaul0_.mainIfUrgentFault as mainIfUr6_322_, commonfaul0_.mainFaultResponseLevel as mainFaul7_322_, commonfaul0_.mainAlarmNum as ma
inAlar8_322_, commonfaul0_.mainAlarmState as mainAlar9_322_, commonfaul0_.mainAlarmDesc as mainAla10_322_, commonfaul0_.mainAlarmSolveDate as mainAla11_322_, commonfau
l0_.mainEquipmentFactory as mainEqu12_322_, commonfaul0_.mainEquipmentName as mainEqu13_322_, commonfaul0_.mainEquipmentModel as mainEqu14_322_, commonfaul0_.mainFault
GenerantTime as mainFau15_322_, commonfaul0_.mainIfAffectOperation as mainIfA16_322_, commonfaul0_.mainFaultDiscoverableMode as mainFau17_322_, commonfaul0_.mainAlarmI
d as mainAla18_322_, commonfaul0_.mainAlarmSource as mainAla19_322_, commonfaul0_.mainAlarmLogicSort as mainAla20_322_, commonfaul0_.mainAlarmLogicSortSub as mainAla
21_322_, commonfaul0_.mainFaultSpecialty as mainFau22_322_, commonfaul0_.mainEquipmentType as mainEqu23_322_, commonfaul0_.mainNetName as mainNet24_322_, commonfaul0_.
mainFaultGenerantProvince as mainFau25_322_, commonfaul0_.mainFaultGenerantCity as mainFau26_322_, commonfaul0_.mainNetSortOne as mainNet27_322_, commonfaul0_.mainNetS
ortTwo as mainNet28_322_, commonfaul0_.mainNetSortThree as mainNet29_322_, commonfaul0_.replyFaultAvoidTime as replyFa30_322_, commonfaul0_.replyOperRenewTime as reply
Op31_322_, commonfaul0_.replyAffectTimeLength as replyAf32_322_, commonfaul0_.replyDealStep as replyDe33_322_, commonfaul0_.replyFaultDealResult as replyFa34_322_, com
monfaul0_.replyFaultReasonSort as replyFa35_322_, commonfaul0_.replyFaultReasonSubsection as replyFa36_322_, commonfaul0_.replyIfGreatFault as replyIf37_322_, commonfa
ul0_.replyIfExcuteNetChange as replyIf38_322_, commonfaul0_.replyIfFinallySolveProject as replyIf39_322_, commonfaul0_.mainSheetType as mainShe40_322_, commonfaul0_.
SQL> col comm format a200
SQL> set linesize 3000
SQL> set pages 0
SQL> select dbms_sqltune.report_sql_monitor(sql_id=>‘3371xmyjfzmxw‘,report_level=>‘ALL‘,type=>‘TEXT‘) comm from dual;
Global Information
------------------------------
Status : DONE (ALL ROWS)
Instance ID : 1
Session : EOMSGZ (1545:18373)
SQL ID : 3371xmyjfzmxw
SQL Execution ID : 16777216
Execution Started : 07/22/2016 15:42:36
First Refresh Time : 07/22/2016 15:42:40
Last Refresh Time : 07/22/2016 15:42:45
Duration : 9s
Module/Action : JDBC Thin Client/-
Service : gzeomsdb
Program : JDBC Thin Client
Fetch Calls : 1
Global Stats
====================================================================================================
| Elapsed | Cpu | IO | Application | Cluster | Other | Fetch | Buffer | Read | Read |
| Time(s) | Time(s) | Waits(s) | Waits(s) | Waits(s) | Waits(s) | Calls | Gets | Reqs | Bytes |
====================================================================================================
| 8.81 | 3.69 | 4.44 | 0.00 | 0.00 | 0.68 | 1 | 504K | 3974 | 4GB |
====================================================================================================
SQL Plan Monitoring Details (Plan Hash Value=3739816812)
=============================================================================================================================================================
| Id | Operation | Name | Rows | Cost | Time | Start | Execs | Rows | Read | Read | Activity | Activity Detail |
| | | | (Estim) | | Active(s) | Active | | (Actual) | Reqs | Bytes | (%) | (# samples) |
=============================================================================================================================================================
| 0 | SELECT STATEMENT | | | | | | 1 | | | | | |
| 1 | TABLE ACCESS FULL | COMMONFAULTPACK_MAIN | 64 | 137K | 9 | +2 | 1 | 0 | 2789 | 3GB | 100.00 | Cpu (3) |
| | | | | | | | | | | | | direct path read (6) |
=============================================================================================================================================================
本文出自 “不忘初心Oracle” 博客,转载请与作者联系!
原文地址:http://136018.blog.51cto.com/126018/1828840