Oracle Statspack
Oracle STATSPACK (Statistics Package) is a performance diagnostic tool provided by Oracle to collect, store, and analyze performance data of an Oracle database. It is especially useful for monitoring and diagnosing database performance over time.
Key Features of STATSPACK
Setting Up STATSPACK :-
Prerequisites : - Ensure you are using Standard Edition or not using Diagnostics Pack on your enterprise edition Database
Creating the STATSPACK User and Schema:
Run the spcreate.sql script located in the ORACLE_HOME/rdbms/admin directory to create the STATSPACK schema and user.
Taking Snapshots:
Manual snapshot: -
EXEC STATSPACK.SNAP;
Scheduled snapshots :-
VARIABLE jobno NUMBER; BEGIN DBMS_JOB.SUBMIT(:jobno, 'STATSPACK.SNAP;', SYSDATE, 'SYSDATE + 1/24'); COMMIT; END;
领英推荐
Generating STATSPACK Reports
To generate a STATSPACK report, you need two snapshots: a start snapshot and an end snapshot.
Analyzing STATSPACK Reports
A STATSPACK report contains several key sections that provide valuable insights into database performance:
Example Queries for STATSPACK Analysis
SELECT SNAP_ID, SNAP_TIME, SNAP_LEVEL FROM STATS$SNAPSHOT ORDER BY SNAP_ID;
2. Top 5 Wait Events:
SELECT * FROM (SELECT event, total_waits, time_waited FROM stats$system_eventWHERE snap_id = :snap_id ORDER BY time_waited DESC)
WHERE ROWNUM <= 5;
3. SQL Statistics:
SELECT sql_text, executions, buffer_gets, disk_reads, cpu_time, elapsed_time FROM stats$sql_summary WHERE snap_id = :snap_id ORDER BY buffer_gets DESC;