锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
涓嬮潰綆鍗曞仛涓涓獙璇侊細
c:>sqlplus / as sysdba
sys@EOS >create table test as select table_name,to_timestamp(last_analyzed) date_test from dba_tables;
琛ㄥ凡鍒涘緩銆?br />
sys@EOS> create index idx_test_date on test (date_test);
绱㈠紩宸插垱寤恒?br />
sys@EOS> desc test
鍚嶇О 鏄惁涓虹┖? 綾誨瀷
----------------------------------------------------- -------- ----------------
--------------------
TABLE_NAME NOT NULL VARCHAR2(30)
DATE_TEST TIMESTAMP(0)
sys@EOS> select date_test from test where date_test > TO_DATE('2007-11-5 00:00:00','yyyy-MM-dd HH24:mi:ss');
鎵ц璁″垝
----------------------------------------------------------
Plan hash value: 944171586
-------------------------------------------------------------------------------- --
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------- --
| 0 | SELECT STATEMENT | | 1 | 22 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IDX_TEST_DATE | 1 | 22 | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------- --
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("DATE_TEST">TIMESTAMP'2007-11-05 00:00:00')
Note
-----
- dynamic sampling used for this statement
緇熻淇℃伅
----------------------------------------------------------
7 recursive calls
0 db block gets
18 consistent gets
0 physical reads
0 redo size
280 bytes sent via SQL*Net to client
374 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
浠庝笂闈㈠彲浠ユ竻妤氱湅鍒幫紝timestamp>date鎯呭喌涓嬶紝璧扮儲寮?br />
綰犳鎴戜箣鍓嶇殑璁よ瘑銆?br />
鍙﹀鍐嶈ˉ鍏呬竴涓嬶紝date榪欎釜鏁版嵁綾誨瀷涓鑸儏鍐典笅寰堝皯鐢紝寤鴻浜у搧閲岄潰鎵鏈夌殑date鏁版嵁綾誨瀷鍏ㄩ儴鏀逛負timestamp
]]>
鍦ㄥ簲鐢ㄤ嬌鐢ㄨ繃紼嬩腑錛屾垜浠粡甯鎬細紕板埌搴旂敤鍝嶅簲鏃墮棿寰堟參錛岀敋鑷蟲病鏈夊搷搴旓紝浣嗘槸搴旂敤鏈嶅姟鍣ㄥ彲鑳藉茍涓嶆槸寰堢箒蹇欙紝cpu鍒╃敤鐜囦篃闈炲父浣庯紝寮曡搗榪欑鐘跺喌鐨勫師鍥犳湁寰堝縐嶏紝姣斿鐜闂錛屽簲鐢ㄨ祫婧愭硠婕忥紝鏁版嵁搴撳師鍥犵瓑絳夛紝鏈枃涓昏鏄粠涓嬈″簲鐢ㄦц兘璇婃柇榪囩▼鏉ヨ皥璋堝浣曢氳繃鏁版嵁搴撹瘖鏂簲鐢ㄦц兘闂銆?/p>
闂錛?/p>
嫻嬭瘯榪囩▼涓彂鐜板簲鐢ㄤ腑鏌愪釜璺寵漿欏甸潰鎵ц鏃墮棿姣旇緝闀匡紝緋葷粺鍘嬪姏涓嶅ぇ錛宑pu鍒╃敤寰堜綆錛岃欏甸潰闇瑕佷粠cache涓彇鏁版嵁錛岀涓嬈$殑鏃跺欏姞杞絚ache錛堜粠鏁版嵁搴撲腑鏌ヨ鍥炴暟鎹茍cache錛夈?/p>
璇婃柇錛?/p>
欏甸潰閫昏緫姣旇緝綆鍗曪紝鎴戜滑鍏堢敤loadrunner妯℃嫙騫跺彂嫻嬭瘯涓涓嬭繖涓〉闈紝鐒跺悗鍐嶆暟鎹簱绔崟鑾穝ql鎵ц鎯呭喌銆?/p>
1銆佹墦寮db2鐩戞帶寮鍏?/p>
#db2 connect to eos
#db2 update monitor switches using statement on
#db2 reset monitor all
2銆佸嚑鍒嗛挓涔嬪悗錛屾垜浠敹闆唖ql緇熻蹇収
#db2 get snapshot for dynamic sql on eos > dysqlstatus.out
鐜板湪緇熻淇℃伅宸茬粡瀛樻斁鍦╠ysqlstatus.out涓紝浣犲彲浠ヤ嬌鐢ㄤ換鎰忔柟渚跨殑鏂囨湰澶勭悊宸ュ叿鏌ョ湅錛屾垜涓鑸敤windows涓婄殑gvim鏉ュ鐞嗭紝鎵撳紑dysqlstatus.out
Number of executions = 1
Number of compilations = 1
Worst preparation time (ms) = 2
Best preparation time (ms) = 2
Internal rows deleted = 0
Internal rows inserted = 0
Rows read = 2
Internal rows updated = 0
Rows written = 0
Statement sorts = 0
Statement sort overflows = 0
Total sort time = 0
Buffer pool data logical reads = Not Collected
Buffer pool data physical reads = Not Collected
Buffer pool temporary data logical reads = Not Collected
Buffer pool temporary data physical reads = Not Collected
Buffer pool index logical reads = Not Collected
Buffer pool index physical reads = Not Collected
Buffer pool temporary index logical reads = Not Collected
Buffer pool temporary index physical reads = Not Collected
Total execution time (sec.ms) = 0.000377
Total user cpu time (sec.ms) = 0.010000
Total system cpu time (sec.ms) = 0.000000
Statement text = select ACTIVITYDEFID,ACTIVITYINSTID from wfworkitem wherePROCESSINSTID=104199 and CURRENTSTATE = 4
......
綆鍗曡涓涓媣i涓殑澶勭悊
:g!/Total execution time/d
鍙繚鐣欐枃鏈腑鐨剆ql鎵ц鏃墮棿錛屾垜浠鎸夌収鎵ц鏃墮棿鏉ユ帓搴?br>
閫氳繃vim鐨剉isual鍔熻兘閫夋嫨鎵ц鏃墮棿鍧楋紙絳夊彿鍚庨潰鐨勬暟瀛楋級錛岀劧鍚庢帓搴?br> Total execution time (sec.ms) = 0.050590
Total execution time (sec.ms) = 0.000170
Total execution time (sec.ms) = 0.000247
Total execution time (sec.ms) = 0.000292
Total execution time (sec.ms) = 0.000474
Total execution time (sec.ms) = 0.000330
Total execution time (sec.ms) = 0.000348
Total execution time (sec.ms) = 0.000279
Total execution time (sec.ms) = 0.000385
Total execution time (sec.ms) = 0.000296
Total execution time (sec.ms) = 0.000261
Total execution time (sec.ms) = 0.000195
Total execution time (sec.ms) = 0.000226
Total execution time (sec.ms) = 0.000227
Total execution time (sec.ms) = 0.000193
......
:'<,'>!sort
鎺掑簭鍚庣殑緇撴灉錛堥儴鍒嗭級
Total execution time (sec.ms) = 2.027776
Total execution time (sec.ms) = 2.203624
Total execution time (sec.ms) = 2.504677
Total execution time (sec.ms) = 2.951256
Total execution time (sec.ms) = 3.119875
Total execution time (sec.ms) = 3.303277
Total execution time (sec.ms) = 3.303517
Total execution time (sec.ms) = 4.017133
Total execution time (sec.ms) = 4.043329
Total execution time (sec.ms) = 4.252125
Total execution time (sec.ms) = 4.400952
Total execution time (sec.ms) = 4.606765
Total execution time (sec.ms) = 5.208087
Total execution time (sec.ms) = 5.778598
Total execution time (sec.ms) = 8.117470
Total execution time (sec.ms) = 9797.905136
鍙互鐪嬪埌鏈闀挎椂闂寸殑sql total鎵ц鏃墮棿鑰楄垂浜?797.905123s.
鐜板湪鎴戜滑鍒癲ysqlstatus.out涓幓鎵捐繖鏉¤鍙?/p>
Number of executions = 4602
Number of compilations = 4294967295
Worst preparation time (ms) = 2
Best preparation time (ms) = 2
Internal rows deleted = 0
Internal rows inserted = 0
Rows read = 2963688
Internal rows updated = 0
Rows written = 0
Statement sorts = 0
Statement sort overflows = 0
Total sort time = 0
Buffer pool data logical reads = Not Collected
Buffer pool data physical reads = Not Collected
Buffer pool temporary data logical reads = Not Collected
Buffer pool temporary data physical reads = Not Collected
Buffer pool index logical reads = Not Collected
Buffer pool index physical reads = Not Collected
Buffer pool temporary index logical reads = Not Collected
Buffer pool temporary index physical reads = Not Collected
Total execution time (sec.ms) = 9797.905136
Total user cpu time (sec.ms) = 9.290000
Total system cpu time (sec.ms) = 1.230000
Statement text = select * from XXXX_T_CNFACTIVITYDEF
榪欐潯璇彞鎬誨叡鎵ц浜?602嬈★紝騫沖潎姣忔鐨勬墽琛屾椂闂?S錛岃屼笖榪欎簺鏁版嵁搴旇鏄cache璧鋒潵鐨?nbsp; 錛涳級
鎬葷粨錛?/p>
涓婇潰鐨勬柟娉曠畝鍗曟葷粨浜嗕粠鏁版嵁搴撳眰闈㈠搴旂敤鐨勬ц兘闂璇婃柇錛屽笇鏈涘澶у鏈夋墍甯姪錛屽浜庢暟鎹簱蹇収璇婃柇闂鐨勬濊礬瀵逛簬浠繪剰鏁版嵁搴撻氱敤
琛ュ厖涓涓猽nix涓婅剼鏈鐞嗘柟寮忥細
sqlsort.sh
awk 'BEGIN{RS="";FS="\n";ORS="\n"};/Statement text/{print $1, $21, $24}' $1 | awk '$5 > 0 {print "AvgTime:", $11/$5, "\t", $0}'| sort -n | head -n $2|awk '{print $0, "\n"}'
鍦ㄥ簲鐢ㄤ腑錛屾垜浠粡甯鎬細紕板埌sql鎵ц寰堟參錛屼絾鏄暟鎹簱cpu鍜屽唴瀛樹嬌鐢ㄧ巼鍙堜笉楂樼殑鎯呭喌錛岀被浼肩殑闂鍩烘湰涓婄敱浜庨攣錛屾帓搴忕瓑鍘熷洜閫犳垚錛屾湰鏂囦富瑕佹弿榪板浣曞幓瀹氫綅閿佺瓑寰呴棶棰橈紝璋佸湪閿佺瓑寰咃紵絳夊緟璋佹寔鏈夌殑閿侊紵閿佸湪閭d釜琛紵
涓銆佹祴璇曞噯澶?/p>
1銆佸厛鍦╯ession1鎵ц濡備笅鎿嶄綔錛屽垱寤烘祴璇曡〃
#db2 connect to eos #export DB2OPTIONS=+C #db2 "create table tacy_test (a int not null primary key,b varchar(10))" #db2 "insert into tacy_test values(1,'a')" #db2 "insert into tacy_test values(2,'a')" #db2 "insert into tacy_test values(3,'a')" #db2 "insert into tacy_test values(4,'a')" #db2 commit
2銆佸湪session2鎵ц濡備笅鎿嶄綔
#db2 connect to eos #export DB2OPTIONS=+C
浜屻佷駭鐢熶竴涓猯ock wait
鍦╯ession1鍋氫竴涓〃鏇存柊錛?/p>
#db2 "update tacy_test set b='b' where a=4"
#db2 "update tacy_test set b='c' where a=4"
榪涚▼琚寕璧風瓑寰?/p>
涓夈佸畾浣嶉攣絳夊緟
1銆佸厛鏉ョ湅鐪嬪簲鐢ㄧ殑鎯呭喌錛?/p>
#db2pd -db eos -applications Database Partition 0 -- Database EOS -- Active -- Up 0 days 07:37:37 Applications: Address AppHandl [nod-index] NumAgents CoorPid Status C-AnchID C-StmtUID L-AnchID L-StmtUID Appid 0x10140040 8 [000-00008] 1 8425 Lock-wait 80 2 66 1 *LOCAL.db2inst1.071124043739 0x100CE540 7 [000-00007] 1 8358 UOW-Waiting 0 0 80 2 *LOCAL.db2inst1.071124043708
鍙互鐪嬪埌鏈変竴涓簲鐢ㄧ殑鐘舵佸浜嶭ock-wait
2銆佺幇鍦ㄦ垜浠潵鐪嬬湅搴旂敤鍦ㄧ瓑浠涔?/p>
#db2pd -db eos -locks showlock wait Database Partition 0 -- Database EOS -- Active -- Up 0 days 07:42:56 Locks: Address TranHdl Lockname Type Mode Sts Owner Dur HldCnt Att Rlse 0x2C8E0760 3 02001806078066020000000052 Row ..X W 2 1 0 0 0x0 TbspaceID 2 TableID 1560 RecordID 0x2668007
閿佺殑綾誨瀷涓篟ow錛堣閿侊級錛孹閿侊紙鎺掍粬閿侊級錛屼笅闈㈡槸鎴戜滑鏈鍏沖績鐨勯攣鐨勪綅緗?/p>
TbspaceID 2 TableID 1560 RecordID 0x2668007
鍏朵腑TbspaceID涓鴻〃絀洪棿ID錛孴ableID涓鴻〃鐨処D錛孯ecordID浠h〃鍏蜂綋浣嶇疆錛屽叏閮ㄥ簲璇ユ槸0x0266807,鍏朵腑鍓嶉潰涓変釜瀛楄妭涓簆age number錛屼負0x02668錛屽悗闈竴涓瓧鑺備唬琛╯olt identifier錛屼負0x073銆佹壘鍒扮浉搴旂殑琛?/p>
#db2 "select tbspace,tabschema,tabname,tableid,tbspaceid from syscat.tables where tbspaceid=2 and tableid=1560"
TBSPACE TABSCHEMA TABNAME TABLEID TBSPACEID
------------ ----------- ---------- ------- ---------
USERSPACE1 DB2INST1 TACY_TEST 1560 2
1 record(s) selected.
4銆佹牴鎹甊ecordID鎵懼埌閿佸湪鍝
db2鎻愪緵浜嗕竴涓己澶х殑鏁版嵁鍒嗘瀽宸ュ叿db2dart錛屽彲浠ump鍑虹浉搴旂殑page鏁版嵁
#db2dart eos /dd /tsi 2 /oi 1560 /ps 157312p /np 1 /v y Warning: The database state is not consistent. Warning: Reorg rows MAY be due to the inconsistent state of the database. DB2DART Processing completed with warning(s)! Complete DB2DART report found in: /home/db2inst1/sqllib/db2dump/DART0000/EOS.RPT
鍏朵腑tsi涓鴻〃絀洪棿id(2)錛宱i涓鴻〃id(1560)錛宲s涓簆age number(0x0266807)錛岄渶瑕佽漿鎹負鍗佽繘鍒訛紝鍦ㄧ粨灝懼繀欏誨姞p錛宯p浠h〃浣犺鑾峰彇鐨勯〉鏁幫紝v涓烘槸鍚﹁緇嗚緭鍑?/p>
鐜板湪鎴戜滑鏉ョ湅鐪婨OS.RPT
______________________________________________________________________________ _______ DART _______ D a t a b a s e A n a l y s i s a n d R e p o r t i n g T o o l IBM DB2 6000 ______________________________________________________________________________ DART (V8.1.0) Report: 2007-11-24-20.59.51.355893 Database Name: EOS Report name: EOS.RPT Old report back-up: EOS.BAK Database Subdirectory: /opt/db2/db2inst1/NODE0000/SQL00001 Operational Mode: Database Inspection Only (INSPECT) ______________________________________________________________________________ ------------------------------------------------------------------------------ Action option: DD Table-object-ID: 1560; Tablespace-ID: 2; First-page: 157312p; Number-pages: 1; Verbose: y Warning: The database state is not consistent. Warning: Reorg rows MAY be due to the inconsistent state of the database. Connecting to Buffer Pool Services... Table object report phase start. Dump format is verbose. ______________________________________ Page 0 of object 1560 from table space 2. BPS Page Header: Page Data Offset = 48 Page Data Length = 4048 Page LSN = 0000 AE97 AE41 Object Page Number = 0 Pool Page Number = 157312 Object ID = 1560 Object Type = Data Object Data Page Header: Slot Count = 8 Total Free Space = 2784 Total Reserve Space = 0 Youngest Reserve Space = n/a Youngest TID = n/a Free Space Offset = 2799 Maximum Record Size = 23 Data Records: Slot 0: Offset Location = 3996 (xF9C) Record Length = 32 (x20) Record Type = Data Object Header Control Record Page count = 1 Object Creation LSN = 0000 AE97 800C Object State = x0000 UDI Since Runstats = 0 DART Field = x00000000 Slot 1: Offset Location = 2992 (xBB0) Record Length = 1004 (x3EC) Record Type = Free Space Control Record Free space entries: 0: 2884 (x0B44), 4028 (x0FBC), 4028 (x0FBC), 4028 (x0FBC) 4: 4028 (x0FBC), 4028 (x0FBC), 4028 (x0FBC), 4028 (x0FBC) 8: 4028 (x0FBC), 4028 (x0FBC), 4028 (x0FBC), 4028 (x0FBC) 鐪佺暐銆傘傘? 492: 4028 (x0FBC), 4028 (x0FBC), 4028 (x0FBC), 4028 (x0FBC) 496: 4028 (x0FBC), 4028 (x0FBC), 4028 (x0FBC), 4028 (x0FBC) Slot 2: Offset Location = 2916 (xB64) Record Length = 76 (x4C) Record Type = Table Directory Record MetaIndex Root Page = 157377 Index Type = 2 Table Descriptor Pointer -- Page 157312 Slot 3 Max Insert Search = 0 Flags = x02000200 bit representation = 00000010 00000000 00000010 00000000 Check pending info: Constraint status = x00 Constraint RID = Page 0 Slot 0 last BID = x00000000 Slot 3: Offset Location = 2892 (xB4C) Record Length = 24 (x18) Record Type = Table Description Record Number of Columns = 2 Column 1: Type is Long Integer Length = 4 Prohibits NULLs Prohibits Default Fixed offset: 0 Column 2: Type is Fixed Length Character String Length = 10 Allows NULLs Prohibits Default Fixed offset: 4 Slot 4: Offset Location = 2869 (xB35) Record Length = 23 (x17) Record Type = Table Data Record (FIXEDVAR) Fixed part length value = 15 Column 1: Fixed offset: 0 Type is Long Integer Value = 1 Column 2: Fixed offset: 4 Type is Fixed Length Character String 61202020 20202020 2020 a Slot 5: Offset Location = 2846 (xB1E) Record Length = 23 (x17) Record Type = Table Data Record (FIXEDVAR) Fixed part length value = 15 Column 1: Fixed offset: 0 Type is Long Integer Value = 2 Column 2: Fixed offset: 4 Type is Fixed Length Character String 61202020 20202020 2020 a Slot 6: Offset Location = 2823 (xB07) Record Length = 23 (x17) Record Type = Table Data Record (FIXEDVAR) Fixed part length value = 15 Column 1: Fixed offset: 0 Type is Long Integer Value = 3 Column 2: Fixed offset: 4 Type is Fixed Length Character String 61202020 20202020 2020 a Slot 7: Offset Location = 2800 (xAF0) Record Length = 23 (x17) Record Type = Table Data Record (FIXEDVAR) Fixed part length value = 15 Column 1: Fixed offset: 0 Type is Long Integer Value = 4 Column 2: Fixed offset: 4 Type is Fixed Length Character String 61202020 20202020 2020 a Slots Summary: Total=8, In-use=8, Deleted=0. Table object report phase end. ______________________________________ DB2DART Processing completed with warning(s)! Warning(s) detected during processing. ______________________________________ Complete DB2DART report found in: /home/db2inst1/sqllib/db2dump/DART0000/EOS.RPT _______ D A R T P R O C E S S I N G C O M P L E T E _______
鎵懼埌Solt 7 (0x07)錛宱k錛屼綘鐜板湪鍙互娓呮鐨勭煡閬撳簲鐢ㄧ瓑寰呯殑Row涓?4,a)
鎬葷粨
閫氳繃涓婇潰鐨勬柟娉曪紝鎴戜滑綆鍗曟弿榪頒簡涓涓猟b2閿侀棶棰樼殑瀹氫綅鏂規硶錛屽笇鏈涜兘緇欏ぇ瀹跺湪鍒嗘瀽鍜屽畾浣嶅簲鐢ㄦц兘闂鐨勬椂鍊欒搗鍒頒竴瀹氱殑甯姪
db2 "create event monitor SQLCOST for statements write to file '/home/db2inst1'"
鍐嶈緗簨鍔$姸鎬佷負鎵撳紑
db2 "set event monitor SQLCOST state=1"
娉細1涓烘墦寮錛?涓哄叧闂紝鏀墮泦鏁版嵁涔嬪悗錛岃寰楀叧闂綘鐨勭洃鎺у櫒錛屽惁鍒欍傘傘?/font> 璺戜綘鐨勬祴璇曞悗錛屽湪浣犵殑/home/db2inst1鐩綍涓嬩細鐢熸垚涓浜沞vm鏂囦歡 鐢ㄤ笅闈㈡寚浠よ幏鍙栬瘖鏂俊鎭細 db2evmon -db eos51 -evm SQLCOST>sqlcost1.txt 瀹屾垚涔嬪悗鍒犻櫎浣犵殑鐩戞帶鍣? db2 "drop event monitor SQLCOST" 鐢熸垚鐨勯噰鏍蜂緥瀛愶紝浠庝笅闈㈢殑渚嬪瓙涓紝浣犲彲浠ユ竻闄ょ殑鐪嬪埌SQL鎵ц鐨勬椂闂達紝CPU娑堣楁儏鍐碉紝鎺掑簭鏄惁婧㈠嚭錛孊ufferPool鐨勪嬌鐢ㄦ儏鍐碉紝鏍規嵁榪欎簺淇℃伅錛孲QL鐨勬墽琛屾晥鐜囦竴鐩簡鐒訛細 26) Statement Event ... Appl Handle: 336 Appl Id: C0A80421.O905.0ABDA5065446 Appl Seq number: 0657 Record is the result of a flush: FALSE ------------------------------------------- Type : Dynamic Operation: Execute Section : 7 Creator : NULLID Package : SYSSN300 Consistency Token : SYSLVL01 Package Version ID : Cursor : SQL_CURSN300C7 Cursor was blocking: FALSE Text : update WFProcessInst set relateData=? where processInstID= ? ------------------------------------------- Start Time: 04/25/2007 14:57:19.402248 Stop Time: 04/25/2007 14:57:19.409622 Exec Time: 0.007374 seconds Number of Agents created: 1 User CPU: 0.000000 seconds System CPU: 0.000000 seconds [licl1] Fetch Count: 0 Total sort time: 0 Sort overflows: 0 [licl2] Rows read: 1 Rows written: 1 Internal rows deleted: 0 Internal rows updated: 0 Internal rows inserted: 0 Bufferpool data logical reads: 9 Bufferpool data physical reads: 0 Bufferpool temporary data logical reads: 0 Bufferpool temporary data physical reads: 0 Bufferpool index logical reads: 3 Bufferpool index physical reads: 0 Bufferpool temporary index logical reads: 0 Bufferpool temporary index physical reads: 0 [licl3] SQLCA: sqlcode: 0 sqlstate: 00000 [licl1]SQL鎵ц鏃墮棿鍜孋PU娑堣楁儏鍐? [licl2]SQL鐨勬帓搴忔儏鍐碉紝鍙互鐪嬪埌榪欎釜SQL娌℃湁鎺掑簭錛屽綋鐒朵篃娌℃湁鎺掑簭婧㈠嚭 [licl3]Bufferpool鐨勪嬌鐢ㄦ儏鍐碉紝閫昏緫璇誨拰鐗╃悊璇葷殑瀵規瘮
]]>