隨筆-314  評論-209  文章-0  trackbacks-0
          Statspack是Oracle自帶的強(qiáng)大的性能分析工具。他可以對當(dāng)前數(shù)據(jù)庫的運(yùn)行狀況作出全面的分析(包括實(shí)例信息、PGA顧問信息、命中率、top sql、top 5 wait event等等),是個好東西吧!下面切入正題:

           

          1.以sysdba身份登陸,查看數(shù)據(jù)文件路徑

             

          Sql代碼 復(fù)制代碼
          1. C:\Documents and Settings\Administrator>sqlplus / as sysdba   
          2.   
          3. SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 4月 14 10:51:41 2010   
          4.   
          5. Copyright (c) 1982, 2005, Oracle.  All rights reserved.   
          6.   
          7.   
          8. 連接到:   
          9. Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production   
          10. With the Partitioning, OLAP and Data Mining options   
          11.   
          12. sys@AAA>show user;   
          13. USER 為 "SYS"  
          14. sys@AAA>select file_name from dba_data_files;   
          15.   
          16. FILE_NAME   
          17. --------------------------------------------------   
          18. D:\ORACLE\PRODUCT\10.2.0\ORADATA\AAA\USERS01.DBF   
          19. D:\ORACLE\PRODUCT\10.2.0\ORADATA\AAA\SYSAUX01.DBF   
          20. D:\ORACLE\PRODUCT\10.2.0\ORADATA\AAA\UNDOTBS01.DBF   
          21. D:\ORACLE\PRODUCT\10.2.0\ORADATA\AAA\SYSTEM01.DBF   
          22. D:\ORACLE\PRODUCT\10.2.0\ORADATA\AAA\BBB.DBF   
          23. D:\ORACLE\PRODUCT\10.2.0\ORADATA\AAA\PERFSTAT.DBF   
          24.   
          25. 已選擇6行。  

           

          2.創(chuàng)建statspack存儲數(shù)據(jù)的表空間,(注:statspack往往會產(chǎn)生大量的分析數(shù)據(jù),所以表空間還是大點(diǎn)為好)。

            

          Sql代碼 復(fù)制代碼
          1. create tablespace perfstat datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\AAA\PERFSTAT.DBF' size 2G;  

           

          3.運(yùn)行statspack安裝腳本。默認(rèn)位置在$oracle_home\rdbms\admin\spcreate.sql

            

             

          Sql代碼 復(fù)制代碼
          1. sys@AAA> @D:\oracle\product\10.2.0\db_1\RDBMS\ADMIN\spcreate.sql   
          2.   
          3. ...................   
          4.   
          5. 輸入 perfstat_password 的值:  perfstat   
          6.   
          7. ...   
          8.   
          9. 輸入 default_tablespace 的值:  perfstat   
          10. ..........   
          11. ..........   
          12. 輸入 temporary_tablespace 的值: temp  
          13. ..........   
          14. ..........  

           

          安裝完之后 會自動切換用戶到perfstat下:

            

          Sql代碼 復(fù)制代碼
          1. PERFSTAT@AAA> show user;   
          2.   
          3. USER is "PERFSTAT"  

           

           安裝完畢!

           

          4.接下來采樣分析,設(shè)定一個job,每小時執(zhí)行一次采樣。

             首先查看當(dāng)前DB中有沒有正在運(yùn)行的JOB:

            

          Sql代碼 復(fù)制代碼
          1. perfstat@AAA>select job,schema_user,next_date,interval,what from user_jobs;   
          2.   
          3. 未選定行  

           

          創(chuàng)建statspack采樣的job,沒每個小時采樣一次。

            

          Sql代碼 復(fù)制代碼
          1. perfstat@AAA>variable job number;   
          2. perfstat@AAA>begin  
          3.   2  dbms_job.submit(:job,'statspack.snap;',trunc(sysdate+1/24,'hh24'),'trunc(sysdate+1/24,''hh24'')');   
          4.   3  commit;   
          5.   4  end;   
          6.   5  /   
          7.   
          8. PL/SQL 過程已成功完成。  

           

          查看當(dāng)前正在運(yùn)行的job有哪些?

            

          Sql代碼 復(fù)制代碼
          1. perfstat@AAA>select job as j,schema_user,next_date,interval,what from user_jobs;   
          2.         J SCHEMA_USER                    NEXT_DATE      INTERVAL   WHAT   
          3. ---------- ------------------------------ -------------- ---------- ----------   
          4.          1 PERFSTAT                       14-4月 -10     trunc(sysd statspack.   
          5.                                                          ate+1/24,' snap;   
          6.                                                          hh24')  

           

           

          5.由于statspack的采集和分析會做很多DB的分析,產(chǎn)生大量的分析數(shù)據(jù),所以頻繁的采樣肯定會消耗系統(tǒng)性能,特別是在生產(chǎn)庫中,所以當(dāng)你建立了上面每小時執(zhí)行一次的那個job,請務(wù)必在不需要的時候停止它。不然的話,這個失誤可能會是致命的( statspack job每小時都會跑,永不停的跑下去,呵呵。),尤其在生產(chǎn)庫中。

           

          明天凌晨,系統(tǒng)比較清閑,采樣已經(jīng)沒多大意義(采樣分析的最終目的是分析高峰時段的系統(tǒng)瓶頸),所以停止這個job.

             

          Sql代碼 復(fù)制代碼
          1. perfstat@AAA>variable job number;   
          2. perfstat@AAA>begin  
          3.   2  dbms_job.submit(:job,'dbms_job.broken(1,true);',trunc(sysdate+1),'null');   
          4.   3  commit;   
          5.   4  end;   
          6.   5  /   
          7.   
          8. PL/SQL 過程已成功完成。  

           

           

          6.幾個小時候后,看看生成的哪些快照。

          Sql代碼 復(fù)制代碼
          1. perfstat@AAA>select snap_id,snap_time,startup_time from stats$snapshot;   
          2.   
          3.    SNAP_ID SNAP_TIME      STARTUP_TIME   
          4. ---------- -------------- --------------   
          5.          1 14-4月 -10     14-4月 -10   
          6.          2 14-4月 -10     14-4月 -10  

           

          7.設(shè)定任意兩個快照,產(chǎn)生這段時間內(nèi)的性能分析報(bào)告(此時需要跑spreport腳本,路徑和剛才那個腳本一致)。

          Sql代碼 復(fù)制代碼
          1. perfstat@AAA>@D:\oracle\product\10.2.0\db_1\RDBMS\ADMIN\spreport.sql   
          2.   
          3. Current Instance   
          4. ~~~~~~~~~~~~~~~~   
          5.    DB Id    DB Name     Inst Num Instance   
          6. ----------- ------------ -------- ------------   
          7.  1858440386 AAA                 1 aaa   
          8.   
          9.   
          10.   
          11. Instances in this Statspack schema  
          12. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
          13.   
          14.    DB Id    Inst Num DB Name      Instance     Host   
          15. ----------- -------- ------------ ------------ ------------   
          16.  1858440386        1 AAA          aaa          6979580041BD   
          17.                                                490   
          18.   
          19. Using 1858440386 for database Id   
          20. Using          1 for instance number   
          21.   
          22.   
          23. Specify the number of days of snapshots to choose from  
          24. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
          25. Entering the number of days (n) will result in the most recent   
          26. (n) days of snapshots being listed.  Pressing <return> without   
          27. specifying a number lists all completed snapshots.   
          28.   
          29.   
          30.   
          31. Listing all Completed Snapshots   
          32.   
          33.                                                        Snap   
          34. Instance     DB Name        Snap Id   Snap Started    Level Comment   
          35. ------------ ------------ --------- ----------------- ----- -------------   
          36. aaa          AAA                  1 14 4月  2010 09:5     5   
          37.                                     2   
          38.                                   2 14 4月  2010 09:5     5   
          39.                                     3   
          40.                                   3 14 4月  2010 11:0     5   
          41.                                     0   
          42.   
          43.   
          44.   
          45. Specify the Begin and End Snapshot Ids   
          46. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
          47. 輸入 begin_snap 的值:  1   
          48. Begin Snapshot Id specified: 1   
          49.   
          50. 輸入 end_snap 的值:  2   
          51. End   Snapshot Id specified: 2   
          52.   
          53.   
          54.   
          55. Specify the Report Name  
          56. ~~~~~~~~~~~~~~~~~~~~~~~   
          57. The default report file name is sp_1_2.  To use this name,   
          58. press <returnto continue, otherwise enter an alternative.   
          59.   
          60. 輸入 report_name 的值:  d:\myreport.txt  
          Sql代碼 復(fù)制代碼
          1. ...回車  

           

           

          8.完成后,會產(chǎn)生一個分析報(bào)告(d:\myreport.txt)。

          附件:報(bào)告的截取片段:

          Sql代碼 復(fù)制代碼
          1. STATSPACK report for  
          2.   
          3. Database    DB Id    Instance     Inst Num Startup Time    Release     RAC   
          4. ~~~~~~~~ ----------- ------------ -------- --------------- ----------- ---   
          5.           1858440386 aaa                 1 14-4月 -10 09:2 10.2.0.1.0  NO  
          6.                                            2   
          7.   
          8. Host  Name:   6979580041BD490  Num CPUs:    2        Phys Memory (MB):    3,326   
          9. ~~~~   
          10.   
          11. Snapshot       Snap Id     Snap Time      Sessions Curs/Sess Comment   
          12. ~~~~~~~~    ---------- ------------------ -------- --------- -------------------   
          13. Begin Snap:          1 14-4月 -10 09:52:22      15       4.3   
          14.   End Snap:          2 14-4月 -10 09:53:20      15       5.8   
          15.    Elapsed:                0.97 (mins)   
          16.   
          17. Cache Sizes                       Begin        End  
          18. ~~~~~~~~~~~                  ---------- ----------   
          19.                Buffer Cache:       184M             Std Block Size:         8K   
          20.            Shared Pool Size:       380M                 Log Buffer:     6,860K   
          21.   
          22. Load Profile                            Per Second       Per Transaction  
          23. ~~~~~~~~~~~~                       ---------------       ---------------   
          24.                   Redo size:             10,075.66            584,388.00   
          25.               Logical reads:                 58.41              3,388.00   
          26.               Block changes:                 18.81              1,091.00   
          27.              Physical reads:                  0.22                 13.00   
          28.             Physical writes:                  0.00                  0.00   
          29.                  User calls:                  0.52                 30.00   
          30.                      Parses:                  2.83                164.00   
          31.                 Hard parses:                  0.72                 42.00   
          32.                       Sorts:                  1.76                102.00   
          33.                      Logons:                  0.02                  1.00   
          34.                    Executes:                 10.88                631.00   
          35.                Transactions:                  0.02   
          36.   
          37.   % Blocks changed per Read:   32.20    Recursive Call %:    99.69   
          38.  Rollback per transaction %:    0.00       Rows per Sort:    70.69   
          39.   
          40. Instance Efficiency Percentages   
          41. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
          42.             Buffer Nowait %:  100.00       Redo NoWait %:  100.00   
          43.             Buffer  Hit   %:   99.62    In-memory Sort %:  100.00   
          44.             Library Hit   %:   90.06        Soft Parse %:   74.39   
          45.          Execute to Parse %:   74.01         Latch Hit %:  100.00   
          46. Parse CPU to Parse Elapsd %:   14.29     % Non-Parse CPU:   98.41   
          47.   
          48.  Shared Pool Statistics        Begin   End  
          49.                                ------  ------   
          50.              Memory Usage %:   21.05   20.98   
          51.     % SQL with executions>1:   54.05   60.06   
          52.   % Memory for SQL w/exec>1:   80.51   83.00   
          53.   
          54. Top 5 Timed Events                                                    Avg %Total   
          55. ~~~~~~~~~~~~~~~~~~                                                   wait   Call   
          56. Event                                            Waits    Time (s)   (ms)   Time  
          57. ----------------------------------------- ------------ ----------- ------ ------   
          58. CPU time                                                         1          70.7   
          59. control file sequential read                       189           0      1   23.6   
          60. db file sequential read                              8           0      3    2.5   
          61. control file parallel write                         27           0      1    1.9   
          62. log file sync                                        1           0      5     .6   
          63.   
          64. .....................   
          65. .........................   
          66. ...........................  

           

           9.若想刪除某個快照,制定snapid直接delete

          Sql代碼 復(fù)制代碼
          1. delete stats$snapshot where snap_id=1;  

           

          若想刪除所有快照 ,只保留statspack結(jié)構(gòu),執(zhí)行@sptrunc。腳本路徑也在rdbms/admin下。若想連statspack一起干掉,也可以,請執(zhí)行下面的腳本:@spdrop

           

          從此你也可以利用statspack來了解當(dāng)前數(shù)據(jù)庫的運(yùn)行狀況了。 

          posted on 2010-08-07 11:18 xzc 閱讀(1350) 評論(0)  編輯  收藏 所屬分類: Oracle
          主站蜘蛛池模板: 前郭尔| 沐川县| 三河市| 冷水江市| 双鸭山市| 景泰县| 宝山区| 阜新市| 涪陵区| 鹤庆县| 镇康县| 噶尔县| 丰原市| 长岭县| 巴林右旗| 崇文区| 柏乡县| 巨鹿县| 彭州市| 进贤县| 台中市| 富源县| 黄石市| 松阳县| 阿拉尔市| 浏阳市| 靖江市| 专栏| 河源市| 满洲里市| 惠州市| 墨竹工卡县| 壶关县| 四会市| 云南省| 天水市| 麟游县| 安多县| 九寨沟县| 斗六市| 石柱|