Why Tune?
To achieve optimal performance, Oracle recommends that you tune your database. Oracle provides several database parameters that can be tuned in order to keep your database running its best. How you set these parameters will affect performance from background database processing to result set retrieval. DBAs must be familiar with performance tuning concepts before attempting to tune, because changing a parameter to an incorrect value could substantially degrade performance. The good news is, there is a lot of documentation on what, how, why and when to tune your Oracle database. Going into the why and when is out of scope for this document. However, I would like to introduce you to the how with STATSPACK, especially what it can do for you!
STATSPACK Sizing
The default initial and next extent sizes for each table and index created during the STATSPACK installation is 1MB. The minimum default installation space requirement is approximately 35MB, however I recommend having at least 100MB of available space for the installation. Table growth will depend on how often the STATSPACK data collection package is executed and the types and levels of statistics being collected. Tables can grow rapidly and you will need to monitor these regularly. You can set parameters to gather either minimum statistical data, or more detailed performance- related information. How you set them will also affect table growth.
statistical data are collected. This data is then stored in tables owned by the PERFSTAT user. The data can be analyzed immediately after data collection or at a later time. Each snapshot that is taken is given a sequence generated snapshot ID. The snapshot ID is made up from the following columns: snapshot id - (snap_id) instance number - (instance_number) database identifier - (dbid)
These columns comprise the unique key for a snapshot. This combination supports storing statistical data in the same Oracle base tables while working in an Oracle Parallel Server (OPS) environment. NOTE: You must not log in as the same user and run BSTAT/ESTAT in conjunction with Statspack. There is a table name conflict with the stats$waitstat table.
Reporting
You must gather data for at least two snapshots to run a report. You will be prompted for twosnapshot IDs during the report execution process. These IDs relate to the start and end time periods
you are interested in reviewing. The first snapshot ID you specify should be used as the performance baseline. The end snapshot id should reflect the ending or latest time that you want to analyze. The report will provide statistics on the instance between the two snapshots ids time period. The report can compare any two snapshots IDs specified, however it is not valid to compare two snapshots if the instance was shutdown between the beginning and ending time frames. In this case, you will receive an error. If you collect hourly statistical data and want to compare a 10:00 a.m. snapshot to a 4:00 p.m. snapshot, you can do this. You do not have to use consecutive snapshot IDs when running a report, as long as the database was not shutdown in between the 10:00 a.m. and 4:00 p.m. time period. In other words, you do not have to run a report after each statistical data collection. You can select the time intervals you want to compare regardless of how often the system collects statistics. One of the benefits is you can automate the actual report generation to a specific time of the day. You can also choose to only generate actual reports when a performance issue is identified. Either way will work as the statistics have already been collected and stored. However, I recommend looking at some type of database health check report on a regular basis. As Ive mentioned before, one of the nicer features of STATSPACK is that the data is collected and then stored in tables. The UTLBSTAT and UTLESTAT utilities do not have this capability. The DBA has to manually create and populate tables with statistical data to save historical values. However, this is now automatically done for you with STATSPACK! To ensure optimal report performance Oracle recommends that you analyze the STATSPACK tables. Check to ensure that the optimizer statistics are current before running the report. If there were significant data changes since the last time a report was generated, you will want to re-analyze the base tables that store your statistical data. You can execute one of the following commands to analyze the tables owned by STATSPACK: execute dbms_utility.analyze_schema('PERFSTAT','COMPUTE'); execute dbms_stats.gather_schema_stats('PERFSTAT');
Executing Reports
To run a report login as the PERFSTAT user and execute the statsrep.sql script. This will run the STATSPACK report. The statsrep.sql is located in the ORACLE_HOME/rdbms/admin directory. Next you will be prompted for the starting snapshot ID, the ending snapshot ID, and the output file name the report is to be written to. After this information is supplied, the report will run and output is written to the specified file. Below is an example of how to execute a report: SQL> @c:\oracle\ora81\rdbms\admin\statsrep.sql
Level >=0
Collects statistical information on the following: Wait statistics System events System statistics Rollback segment data Row cache SGA Background events Session events Lock statistics Buffer pool statistics Parent latch statistics
Levels >= 5
This level includes data collected in lower levels (see level >= 0 above). Statistics are gathered when an SQL statements resource usage exceeds one of these thresholds. These are collected for high resource usage SQL statements. There are four predefined threshold parameters listed below.
The default values for threshold parameters are also listed in a table.
Threshold Number of SQL statement executions Number of disk reads performed by SQL statement Number of parse calls performed by SQL statement Number of buffer gets performed by SQL statement
Level >=10
Includes all previously collected statistics along with child latch information. This level is resource intensive and should only be used if Oracle Support tells you to (per STATSPACK documentation).
SQL Example:
See the Parameter Modification Table for the appropriate parameter names and values. execute statspack.modify_statspack_parameter (I_snap_level=>10, I_buffer_gets_th=>10000, I_disk_reads_th=>1000); execute statspack.snap(i_snap_level=>0);
Uninstalling STATSPACK
If you choose to uninstall the STATSPACK package, you need to connect as SYS or connect internal and run the statsrep.sql executable. The statsdrp.sql file executes the statsdtab.sql and the statsdusr.sql files. The statsdrp.sql drops the tables and public synonyms, while the statsdusr.sql drops the PERFSTAT user. Two output files are generated when you run statsdrp.sql, statsdtab.lis and statsdusr.lis. Review each of these outputs files to ensure that everything was properly removed.
Statsauto.sql
This SQL file automates the collection of STATPACK statistics and should be run by the PERFSTAT user. The job_queue_processes init.ora parameter must be set to a number greater than zero before automatic statistics gathering will run. You can collect hourly statistical snapshots.
Statscre.sql
Statscre.sql connects internal, then creates the STATSPACK user, tables, and package. The statscusr.sql file is called and creates the PERFSTAT user along with necessary privileges. Then, the statsctab.sql is executed. This SQL file builds tables and synonyms. The last file called is statspack.sql, which creates the statistics package.
Statsctab.sql
This SQL file creates the tables that hold the start and end snapshot information and should be run by PERFSTAT user.
Statscusr.sql
Creates the user, which will house the STATSPACK database objects. You must connect internal or run this as SYS. You will be prompted for the temporary and default tablespaces for the PERFSTAT user. Unlimited quota is granted on the default tablespace.
Statsdrp.sql
This SQL file drops the PERFSTAT user and PERFSTAT owned objects. You must connect internal in order to execute this SQL. Statsdtab.sql and statsdusr.sql are called during execution.
Statsdtab.sql
Drops the STATSPACK snapshot related tables and must be run by PERFSTAT user.
Statsdusr.sql
Drops the PERFSTAT user. Must be run by SYS or connect internal. The x_$K views are dropped first, then PERFSTAT user is dropped with the cascade option.
Statspack.sql
Creates the STATSPACK package and must be run by PERFSTAT user.
Statsrep.sql
Reports the differences between statistical values that have been recorded within two snapshots. Normally run by PERFSTAT user. This report will prompt for the current database and instance, parallel if applicable, release, host and snapshot information for later use. The beginning snapshot ID, ending snapshot ID and file name to be written to will also be required. Again, if the database was shutdown between snapshot IDs the report will produce an error. Below are bullet items of statistical events that are collected/reported:
Print snapshot information Call statspack to calculate certain statistics Cache Sizes Load Profile Instance Efficiency Percentages Top Wait Events System Events Background process wait events SQL Reporting SQL statements ordered by buffer gets SQL statements ordered by physical reads SQL statements ordered by rows Instance Activity Statistics Session Activity Statistics Tablespace IO summary statistics File IO statistics Buffer waits summary Enqueue activity Rollback segment Latches activity Latch Sleep breakdown Latch Miss sources Buffer pools Dictionary Cache Library Cache SGA Initialization Parameters
Conclusion
STATSPACK is a powerful performance tuning utility supplied (but not installed) during the Oracle Server installation. With STATSPACK, you can automate statistical data collection for your database(s). Thresholds and level parameters can be modified prior to running a report to meet your specific business needs. Data collected and stored in base tables can then be analyzed with the report provided by Oracle. A one page high-level fact sheet is provided as part of the report. DBAs can use the information provided by this utility for proactive performance tuning and monitoring on a scheduled basis for specific time frames. Read all the STATSPACK related documentation provided by your installation. For more information, see articles written by the expert at technet.oracle.com. Search by using statspack as a keyword.