Anda di halaman 1dari 10

THE INS & OUTS OF TUNING WITH STATSPACK (PAPER # 10193)

Susan McClain, marchFIRST

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!

The STATSPACK Utility


Oracle now has a new performance tuning tool STATSPACK. Historically, DBAs used the tuning utility supplied by Oracle for the last several years, UTLBSTAT and UTLESTAT. STATSPACK is a tuning utility that was introduced in release Oracle 8.1.6. STATSPACK has many new tuning features that are not available when running UTLBSTAT/UTLESTAT. It collects more information, pre-calculates some of the performance ratios, and stores performance statistics in permanent tables so that you can reference historical data. The statistics stored in the permanent Oracle tables, owned by PERFSTAT, can be analyzed by running the STATSPACK report. This report includes a summary page of high-resource SQL statements, wait events and initialization parameters. A great feature is that you can also automate performance-related data collection, store it in one of the STATSPACK tables, and review it at a later time. This document will provide an overview of how to install statspack, the data collection process, analysis reporting along with report execution levels, and the various SQL files that make up the STATSPACK utility. During the presentation I will discuss the topics listed above along with analytical data generated during a snapshot report. This includes reporting highlights, generating statistics, performance measuring and making recommendations for corrective actions.

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.

How to Install STATSPACK


To actually install STATSPACK you need to connect internal, then call statscre.sql (statspack create) from the ORACLE_HOME/rdbms/admin directory. The statscre.sql will call the following three SQL files: statscusr.sql - creates the PERFSTAT user and grants the appropriate privileges. statsctab.sql - creates the permanent tables statspack.sql - creates the statspack package Output log files are created during the installation process. Review these files to ensure no errors were generated during the installation. Oracle recommends you change the PERFSTAT users password for security reasons. As stated above, the PERFSTAT user is automatically created by the installation script and owns all of the related objects including packages, tables, indexes and constraints. The installation script prompts for the PERFSTAT users default and temporary tablespaces along with the tablespaces that STATSPACK tables and indexes are to be created in. Oracle recommends that you do not use the SYSTEM tablespace to store the tables and indexes, and lists TOOLS as an alternative option. You can use the TOOLS tablespace, or create a separate tablespace specifically for the STATSPACK PERFSTAT user. Two additional packages are created during the STATSPACK installation. The DMBS_SHARED_POOL package, which allows you to pin a package in the shared pool and DMBS_JOB, which facilitates job scheduling are also created during the installation process.

What is a STATSPACK Snapshot?


An Oracle STATSPACK snapshot is each unique collection of statistical data and is based on the collection time period (every day, every hour, etc.). You can decide to collect database performance statistics on a regular basis for comparison purposes, or you can collect statistical data due to an immediate lack of performance. When you execute a snapshot, statistical data is collected for your database at that point in time. Wait events, cache sizes, system events, file statistics, activity statistics and several other types of

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.

Running Statspack Taking a Snapshot


To take a snapshot of your instance login as the PERFSTAT user and execute statspack.snap. execute statspack.snap This will collect statistical data about your instance in the STATSPACK tables, and give you a performance baseline to work from. If you set timed_statistics to true, timing information will also be populated in the STATSPACK tables. This timing data is sometimes required by Oracle support in order to further assess performance problems. You can change this parameter by altering the system or changing the init.ora file timed_statistics parameter to true. Setting this parameter will provide additional performance tuning information and enhance analysis.

Automating statistical data collection


The statsauto.sql file automates statistical data collection. Data collection can be automated by using Oracles DBMS_JOB package or the CRON utility in UNIX. The statsauto.sql uses the DBMS_JOB utility. Data can be collected and stored at different times during the day, once a day, once a week, or whatever time frame best suits your specific tuning needs. You can also manually run STATSPACK if you want to monitor immediate performance degradation issues. Again, every STATSPACK snapshot is stored in Oracle base tables. Data can be reviewed on a regular basis as a health check, for trending purposes, or to determine performance modification, to name a few. Data collections can also be automated using other tools such as CRON or AUTOSYS.

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

How Much Statistical Data is Collected?


You can collect different volumes of data. Monitor how much data is collected regularly. PERFSTAT user tables can grow very quickly and fill up disk space.

Setting Levels and Thresholds


The snapshot level and threshold you specify will determine the amount of statistical data that is being collected and stored in the STATPACK owned tables. Snapshot level and threshold information is stored in the stats$statspack_parameter table. Default threshold and level values can be changed when a snapshot is taken. Changing default values is addressed in the section titled Changing Default Threshold and Level Parameters. A feature added in release 8.1.7 includes an automated process for removing old snapshots.

Various Levels and Thresholds


Below is a listing of the various level and threshold parameters that are available.

Level >=0

General Performance Statistics

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

SQL Statements Along With Statistics from Lower Levels

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

Default Value 100 1,000 1,000 10,000

Level >=10

Child latch and all lower levels

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).

Changing Default Threshold and Level Parameters


There may be situations when you will want to alter the default threshold and level parameters, such as when a performance change or degradation occurs. You can modify default values with or without taking a snapshot. The following default values can be changed:

Parameter Modification Table


Parameter I_snap_level I_ucomment I_executions_th I_disk_reads_th I_parse_calls_th I_buffer_gets_th I_session_id I_modify_parameter Range of Values 0, 5,10 Text Integer >=0 Integer >=0 Interger >=0 Integer >=0 Valid SID from v$session True/false Default Value 5 Blank 100 1,000 1,000 10,000 0 (no session) False Description Snapshot level Comment that is stored with the snapshot SQL threshold number of times the statement was executed SQL threshold number of disk reads by statement SQL threshold number of parse calls the statement made SQL threshold number of buffer gets the statement made Session ID of the Oracle session If true, it saves the parameters specified for future snapshots

Modifying default values when taking a snapshot


You can update default values at the time a snapshot is taken by using the statspack.snap and i_modify_parameter. If you set the i_modify_parameter to true the new threshold values will be saved in the stats$statspack_parameter table. These values will become the new default value until otherwise changed. If the i_modify_parameter is set to false or not listed, the default value is not changed in the PERFSTAT user table, however it is changed for that specific snapshot run. SQL Example: This statement will change the i_snap_level value in the stats$statspace_parameter table to 0. execute statspack.snap - (i_snap_level=>0, i_modify_parameter=>true);

Modifying default values without running a snapshot


You can change the default values without taking a snapshot by running the statspack.modify_statspack_parameter procedure. This procedure will permanently set the specified values, but will not take a snapshot.

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);

Exporting the PERFSTAT User


There is a parameter in the Oracle_Home/rdbms/admin directory named statsuepx.par that can be used when exporting the PERFSTAT user. To export this schema, enter the following command: exp userid=perfstat/perfstat parfile=statsuexp.par A statsuexp.log and statsuexp.dmp file will be generated after issuing the above command. You can use the import command to import the export_file_name.dmp file into another database.

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.

STATSPACK SQL Files and Descriptions


The files listed below are located in the ORACLE_HOME/rdbms/admin directory.

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.

Anda mungkin juga menyukai