首先进行一些基本的设置
1.SQL*PLUS中输入
SQL>conn assysdba;
SQL>altersystemsetjob_queue_processes=6;--自动执行数据收集时该参数需要大于0
SQL>altersystemsettimed_statistics=true;
--使用statspack收集统计信息时建议将该值设置为TRUE,否则收集的统计信息大约只能起到10%的作用
这句话不能少,否则下面的语句不会执行成功
在创建表空间createtablespaceperfstatdatafile‘d:/test_perfstat.dbf’size500M;
SQL>@C:\oracle\ora92\rdbms\admin\spcreate.sql;
输入perfstat_password的值:perfstat
输入default_tablespace的值:perfstat
输入temporary_tablespace的值:temp
NOTE:
SPCPKGcomplete.Pleasecheckspcpkg.lisforanyerrors.
--需要出现上述语句才算成功,否则请查看.lis文件并执行,进行重建
SQL>@C:\oracle\ora92\rdbms\admin\spdrop.sql
SQL>@C:\oracle\ora92\rdbms\admin\spcreate.sql;
2.查看文件夹会产生三个文件
C:\oracle\ora92\bin
spcpkg.lis
spctab.lis
spcusr.lis
3.手动执行STATSPACK收集统计信息
SQL>showuser
USER为"PERFSTAT"
SQL>executestatspack.snap;
4.生成STATSPACK调整报告
SQL>@C:\oracle\ora92\rdbms\admin\spreport.sql;
CurrentInstance
~~~~~~~~~~~~~~~~
DBIdDBNameInstNumInstance
-------------------------------------------
357371480COLM1colm
InstancesinthisStatspackschema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DBIdInstNumDBNameInstanceHost
-------------------------------------------------------
3573714801COLMcolmSTEVENHUANG3
Using357371480fordatabaseId
Using1forinstancenumber
CompletedSnapshots
SnapSnap
InstanceDBNameIdSnapStartedLevelComment
-------------------------------------------------------------------------
colmCOLM11110月200621:55
0
21110月200621:55
0
SpecifytheBeginandEndSnapshotIds
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
输入begin_snap的值:1
输入end_snap的值:2
EndSnapshotIdspecified:2
SpecifytheReportName
~~~~~~~~~~~~~~~~~~~~~~~
Thedefaultreportfilenameissp_1_2.Tousethisname,
press<return></return>tocontinue,otherwiseenteranalternative.
输入report_name的值:report1.txt
EndofReport
5.查看产生的report1文档
C:\oracle\ora92\bin\report1.txt
6.自动执行STATSPACK收集统计信息
SQL>@C:\oracle\ora92\rdbms\admin\spauto.sql;
Jobnumberforautomatedstatisticscollectionforthisinstance
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Notethatthisjobnumberisneededwhenmodifyingorremoving
thejob:
JOBNO
----------
1
Jobqueueprocess
~~~~~~~~~~~~~~~~~
Belowisthecurrentsettingofthejob_queue_processesinit.ora
parameter-thevalueforthisparametermustbegreater
than0touseautomaticstatisticsgathering:
NAME_COL_PLUS_SHOW_PARAM
------------------------------------------------------------------------------
TYPE
----------------------
VALUE_COL_PLUS_SHOW_PARAM
------------------------------------------------------------------------------
job_queue_processes
integer
6
Nextscheduledrun
~~~~~~~~~~~~~~~~~~
Thenextscheduledrunforthisjobis:
JOBNEXT_DATE
--------------------
NEXT_SEC
----------------------------------------------------------------
111-10月-06
23:00:00
spauto.sql中主要调用dbms_job.submit,默认每小时收集1次(1/24)
variablejobnonumber;
variableinstnonumber;
begin
selectinstance_numberinto:instnofromv$instance;
dbms_job.submit(:jobno,'statspack.snap;',trunc(sysdate+1/24,'HH'),'trunc(SYSDATE+1/24,''HH'')',TRUE,:instno);
commit;
end;
/
可以通过修改这个值设置采集时间
1/24HH每小时一次
1/48MI每半小时一次
1/144MI每十分钟一次
1/288MI每五分钟一次
7.移除自动执行STATSPACK收集
SQL>selectjob,log_user,priv_user,last_date,next_date,intervalfromuser_jobs;--先查看当前自动收集的jobs
SQL>executedbms_job.remove('1');--移除任务1
8.删除统计资料(statspack相关的所有系统表)
SQL>selectmax(snap_id)fromstats$snapshot;
SQL>@C:\oracle\ora92\rdbms\admin\sptrunc.sql;
Warning
~~~~~~~
Runningsptrunc.sqlremovesALLdatafromStatspacktables.Youmay
wishtoexportthedatabeforecontinuing.
AbouttoTruncateStatspackTables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ifyouwouldliketocontinue,press<return></return>
输入return的值:
Entered-startingtruncateoperation