天天看點

P6Spy & SQL Profiler & IronTrack SQL

<a href="http://yulimin.javaeye.com/blog/28880">http://yulimin.javaeye.com/blog/28880</a>

關鍵字: hibernate   spring p6spy sql profiler irontrack sql    

“nearly 80 to 85 percent of database performance problems arise from the application database's design or the application's own code. good transaction throughput requires an application designed from the database up, with performance and scalability in mind.”

----db2 magazine

p6spy &amp; sql profiler &amp; irontrack sql

p6spy是一個可以用來在應用程式中攔截和修改資料操作語句的開源架構。

通過p6spy我們可以對sql語句進行攔截,相當于一個sql語句的記錄器,這樣我們可以用它來作相關的分析,比如性能分析。

一、p6spy的安裝與使用

2、把p6spy的jar包p6spy.jar放到classpath中,如果是web應用程式則放在yourwebapp/web-inf/lib/目錄下;

3、把spy.properties放到classes目錄下,如果是webapp就放在yourwebapp/web-inf/classess/目錄下,記得不是lib/目錄

4、修改你程式的資料庫驅動名稱為p6spy的驅動程式名稱com.p6spy.engine.spy.p6spydriver其它的都不用更改;

5、打開spy.properties檔案,把realdriver的值改為你的程式的資料庫驅動名稱;

6、運作你的應用程式或web應用程式,可以在spy.log裡看到監測到的sql詳細記錄資訊了。

7、驅動程式加載先後的問題解決

  如果spy.log裡出現

  你的程式的資料庫驅動名稱 is a real driver in spy.properties, but it has been loaded before p6spy. p6spy will not wrap these connections. either prevent the driver from loading, or try setting 'deregisterdrivers' to true in spy.properties

  請把spy.properties檔案裡的deregisterdrivers=false改為deregisterdrivers=true,重新運作即可。

二、結合sql profiler進行圖形化監控與使用

2、把p6spy.jar及sqlprofiler.jar放到classpath中,如果是web應用程式則放在yourwebapp/web-inf/lib/目錄下;

6、注意要先運作 java -jar sqlprofiler.jar 來啟動sql profiler,并成功看到啟動後界面;

7、然後再啟動你的應用程式或伺服器,并開始進行正常的系統請求處理操作;

8、這樣可以在sql profiler圖形化的界面上看到結果并進行分析了。

并且可以通過儲存按鈕導出資料庫優化建議的索引腳本

三、結合irontrack sql進行圖形化監控與使用

2、把irontracksql.jar、p6spy.jar、log4j-1.2.8.jar放到classpath中,如果是web應用程式則放在yourwebapp/web-inf/lib/目錄下;

6、設定監聽端口号monitorport=2000

6、先運作 java -jar irontracksql.jar 來啟動irontrack sql;

7、再啟動你的應用程式或伺服器;

8、可以在 irontrack sql 圖形化的界面上看到結果并進行分析了。