Implications of Setting Oracle9iR2’s Statistical Collection Level James F. Koopmann Co-Founder & Chief Architect dbDoctor Inc. Colorado www.dbdoctor.net Jkoopmann@dbdoctor.net james_koopmann@yahoo.com James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 1 Content 1. Why statistics are important, Who Needs them ? 2. What is the new method of setting up statistical collections. 3. How you can see what your settings are currently 4. How you can change your settings. 5. A test scenario for determining system impact of collecting statistics. 6. SPFILE Usage 7. Various Examples 8. Information exchange James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 2 Why Do We Care About Statistics, Who Needs Them TRUE or FALSE Collecting Statistics will make my database run faster James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 3 Why Do We Care About Statistics, Who Needs Them TRUE or FALSE Collecting Statistics will in the future make my database run faster James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 4 Why Do We Care About Statistics, Who Needs Them It’s All About Problem Detection What Are Problems? 1. Problems are anything that causes us, or our database discomfort. 2. Problems are anything that occurs in relation to the database that is a deviation from the norm. A few questions to ask yourself 1. If a batch job runs one hour longer than normal, is it a problem if no one knows about it? 2. If you take down the listener and no one tries to connect to your database, is it a problem? 3. If the database is down and isn’t being used, is it a problem? James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 5 Why Do We Care About Statistics, Who Needs Them It’s All About Problem Detection Lazy man method of finding problems a. You can find problems by snooping around in the database b. You can find problems from user complaints c. You can find problems when the system crashes or is unavailable d. Use of rudimentary statistics (wall clock, system feel) Intelligent method of finding problems a. Realizes that aggregate statistics aren’t enough b. Has a method of detecting change, where have I been and where am I going. c. Hard and fast statistics (V$ tables, iostat, vmstat, …). James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 6 Why Do We Care About Statistics, Who Needs Them The Problem with Problems 1. We have to fix them 2. Mistakes are common and we can’t rid ourselves of them 3. a. Be compassionate b. Be humble Receive new ideas with an open but analytical mind a. Research for yourself b. Have reliable sources 4. Validate what you have heard or read a. don’t take for granted everything you read or hear b. “Your mileage may vary” 5. Accept only after validation a. This is the best part, you can count on what you have learned b. You can use new knowledge to validate other scenarios James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 7 New to Oracle9iR2 STATISTICS_LEVEL Controls Collection of Advisories and Statistics 1. 2. 3. 4. 5. 6. 7. 8. Shared Pool Advice Buffer Cache Advice PGA Advice MTTR Advice Segment Level Statistics Timed Statistics Timed OS Statistics Plan Execution Statistics James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 8 New to Oracle9iR2 STATISTICS_LEVEL is a Dynamic Parameter DYNAMIC Parameter can be modified using the ALTER SESSION or ALTER SYSTEM statement while an instance is running. Syntax we are all familiar with ALTER SESSION SET parameter_name = value 1. 2. Change the value of a parameter for the duration of the session. The value of this parameter does not change for other sessions in the instance. ALTER SYSTEM SET parameter_name = value 1. 2. Change the value of the parameter for all current and future sessions. Record the change in the alert.log ALTER SYSTEM SET parameter_name = value [DEFERRED] 1. 2. Change only applies to future sessions that will connect to the database. Record the change in the alert.log James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 9 New to Oracle9iR2 V$STATISTICS_LEVEL Column STATISTICS_NAME Values(?) DESCRIPTION Description Name of the statistics/advisory. Description of what the statistics/advisory does and what it can be used for. SESSION_STATUS ENABLED|DISABLED Status of the statistics/advisory for this session. SYSTEM_STATUS ENABLED|DISABLED Status of the statistics/advisory system-wide. ACTIVATION_LEVEL BASIC|TYPICAL|ALL Indicates the level of STATISTICS_LEVEL than enable this statistics/advisory STATISTICS_VIEW_NAME If there is a single view externalizing this statistics/advisory, the name of that view.If there is no such a view, this column is empty. If there are multiple views involved, the DESCRIPTION column should mention the view names. SESSION_SETTABLE Whether this statistics/advisory can be set at the session level. YES|NO. James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 10 New to Oracle9iR2 V$STATISTICS_LEVEL SQL> SELECT statistics_name, statistics_view_name, description FROM v$statistics_level STATISTICS_NAME STATISTICS_VIEW_NAME DESCRIPTION ------------------------- --------------------- ---------------------------------------Shared Pool Advice V$SHARED_POOL_ADVICE Predicts the impact of different values of shared_pool_size on elapsed parse time saved Buffer Cache Advice V$DB_CACHE_ADVICE Predicts the impact of different cache sizes on number of physical reads PGA Advice V$PGA_TARGET_ADVICE Predicts the impact of different values of pga_aggregate_target on the performance of memory intensive SQL operators MTTR Advice V$MTTR_TARGET_ADVICE Predicts the impact of different MTTR settings on number of physical I/Os Segment Level Statistics V$SEGSTAT Enables gathering of segment access statistics Timed Statistics Enables gathering of timed statistics Timed OS Statistics Enables gathering of timed operating system statistics Plan Execution Statistics V$SQL_PLAN_STATISTICS Enables collection of plan execution statistics James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 11 SPFILE Is the Init.ora File Going Away ? 1. Simplified Parameter Management 2. Change in STARTUP Sequence 3. Push to Migrate from Parameter File James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 12 SPFILE DO You Have One? SQL> show parameter spfile NAME TYPE VALUE --------------------------- --------- -------------spfile string James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 13 SPFILE How Do I Get One? Help, I Want My INIT.ORA James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 14 SPFILE Items to Consider • • • • • • Must be SYSOPER or SYSDBA to create one Occasionally save you SPFILE SPFILE is a binary file SHUTDOWN / STARTUP to recognize ORA-12547: TNS:lost contact ALTER SYSTEM RECOGNIZE command James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 15 SPFILE Setting a Parameter ALTER SYSTEM SET DEFERRED, changes the value for the parameter for sessions connecting after the statement is issued. SCOPE, specifies when the change will take effect. 1. MEMORY - the change takes effect immediately but is not available after next startup 2. SPFILE - the change is made in the server parameter file only and available after next startup 3. BOTH - MEMORY + SPFILE, this is the default James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 16 SPFILE Resetting a Parameter ALTER SYSTEM RESET Switch to default statistics_level alter system set statistics_level=typical scope=memory; alter system reset statistics_level scope=spfile sid=‘*’; Switch timed_statistics to be under statistics_level control alter system set timed_statistics=true scope=memory; alter system reset timed_statistics scope=spfile sid=‘*’; James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 17 SPFILE Setting a Parameter that is a List of Strings alter system set control_files= '/u01/app/oracle/oradata/saigon/control01.ctl', '/u01/app/oracle/oradata/saigon/control02.ctl', '/u01/app/oracle/oradata/saigon/control03.ctl' scope=spfile; James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 18 STATISTICS_LEVEL Dynamic Parameters Parameter ALTER SESSION ALTER SYSTEM ALTER SYSTEM …DEFERRED STATISTICS_LEVEL Db_cache_advice Timed_statistics Timed_os_statistics James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 19 STATISTICS_LEVEL Three Settings Statistic / Advisory BASIC TYPICAL ALL Override SESSION SPFILE Shared Pool Advice Buffer Cache Advice db_cache_advice PGA Advice MTTR Advice Segment Level Statistics timed_statistics Timed Statistics Timed OS Statistics timed_os_statistics Plan Execution Statistics James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 20 Take a Look at Your Settings Override Control (V$PARAMETER) SQL> SELECT name, value, isses_modifiable, issys_modifiable,isdefault,ismodified FROM v$parameter WHERE NAME IN ('statistics_level','db_cache_advice', 'timed_statistics', 'timed_os_statistics'); NAME ---------------------- statistics_level timed_statistics timed_os_statistics db_cache_advice VALUE ------- TYPICAL FALSE 0 OFF ISSES_MODIFIABLE ---------------- TRUE TRUE TRUE FALSE TRUE = Default Value (NO SPFILE entry) FALSE = SPFILE entry ISSYS_MODIFIABLE ---------------- IMMEDIATE IMMEDIATE IMMEDIATE IMMEDIATE ISDEFAULT --------- ISMODIFIED --------- TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE = Not Modified since startup MODIFIED = ALTER SESSION SYSTEM_MOD = ALTER SYSTEM James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 21 Take a Look at Your Settings Override Control (V$STATISTICS_LEVEL) SQL> SELECT statistics_name, session_status, system _status activation_level, session_settable FROM v$statistics_level Am I Collecting STATISTICS NAME ------------------------Buffer Cache Advice MTTR Advice PGA Advice Segment Level Statistics Shared Pool Advice Timed Statistics Plan Execution Statistics Timed OS Statistics SESSION STATUS -------ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED DISABLED DISABLED SYSTEM STATUS -------ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED DISABLED DISABLED What Level in STATISTICS_LEVEL to Activate ACTIVATION LEVEL ---------TYPICAL TYPICAL TYPICAL TYPICAL TYPICAL TYPICAL ALL ALL James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level SESSION SETTABLE -------NO NO NO NO NO YES YES YES 22 Take a Look at Your Settings Don’t Get Confused • If there is an entry in SPFILE then setting STATISTICS_LEVEL will not have an impact on that statistic or advisory. • Even if the setting in the SPFILE is the DEFAULT, it will still not be under the control of the STATISTICS_LEVEL parameter. • When looking at v$parameter and v$statistics_level after you have made changes, you may get confused. • ALTER SYSTEM command will override any ALTER SESSION command • RESET any parameters that you want to be controlled by the new STATISTICS_LEVEL parameter. James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 23 Take a Look at Your Settings Oracle Gets Confused The setting of timed_os_statistics to anything other than 0 (zero) or 5 will switch the SESSION_STATUS & SYSTEM_STATUS in V$STATISTICS_LEVEL to UNKNOWN NAME ---------------------- VALUE ------- timed_os_statistics STATISTICS NAME ------------------------- Timed OS Statistics 10 ISSES_MODIFIABLE ---------------- ISSYS_MODIFIABLE ---------------- TRUE SESSION STATUS -------- UNKNOWN ISDEFAULT --------- IMMEDIATE SYSTEM STATUS --------- ACTIVATION LEVEL ---------- UNKNOWN ISMODIFIED --------- FALSE FALSE SESSION SETTABLE -------- ALL James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level YES 24 Human Impact The Most Hated Statements 1. You must set TIMED_STATISTICS to TRUE in the parameter file. 2. I recommend using timed statistics. 3. Doing this will have a small negative effect on system performance. 4. You will incur minimal resource overhead 5. You cannot afford to be without the information that timed statistics provides. 6. Gathering OS statistics is very expensive. James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 25 Human Impact Typical Responses 1. Sorry, Oracle Support does not have any specific benchmark information. 2. Contact ___________, they may have benchmark information. 3. Can anyone else share their input and experiences. 4. My Technical Consultant has not seen any specific benchmarks on this. 5. Take a look at the guide and if necessary we will try to get some development resources James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 26 System Impact Test Scenarios Statistic / Advisory Shared Pool Advice Buffer Cache Advice PGA Advice BASIC TYPICAL Why ALL 1. Reduce stress associated with statistical collection 2. Who else will help MTTR Advice Segment Level Statistics 3. Validate for myself Timed Statistics Timed OS Statistics Plan Execution Statistics James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 27 System Impact Basic Terminology Throughput User / Job Request (workload) (v$sysstat) LGWR wait for redo copy, log file sync, Sorts, Reads, Writes, Enqueues, Redo activity, Buffer cache activity, Parsing,… db file sequential read,… Resource Usage (v$sysstat) Wait Times (v$system_event) Database Completes Request User User Decides Queues What to Next Do Next Transaction Coffee Break Think Time Database Response Time James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 28 System Impact Test Scenarios (workload types) execute count, Total number of calls (user and recursive) that executed SQL statements calls to get snapshot scn: kcmgss, Number of times a snapshot system change number (SCN) was allocated. The SCN is allocated at the start of a transaction. session logical reads, The sum of db_block_gets and consistent_gets. db block gets, Number of times a CURRENT block was requested consistent gets, Number of times a consistent read was requested for a block. db block changes, This statistic counts the total number of changes that were part of an update or delete operation that were made to all blocks in the SGA. This approximates total database work. It statistic indicates the rate at which buffers are being dirtied. user commits, Number of user commits. When a user commits a transaction, the redo generated that reflects the changes made to database blocks must be written to disk. Commits often represent the closest thing to a user transaction rate. James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 29 System Impact Test Scenarios (workload types) Statistic BASIC timed_statistics TYPICAL TYPICAL / BASIC ALL ALL / TYPICAL execute count 520370 505683 (2.82%) 498753 (1.37%) 4.15% calls to get snapshot scn: kcmgss 703731 682467 (3.02%) 674396 (1.18%) 4.17% 1087327 1052570 (3.20%) 1041518 (1.05%) 4.21% 446278 431281 (3.36%) 427297 (0.92%) 4.25% 39405 38323 (2.75%) 37766 (1.45%) 4.16% session logical reads db block changes user commits James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level ALL / BASIC 30 System Impact Test Scenarios (wait types) Statistic Total Waits Total Timeouts Total Time Waited BASIC timed_statistics TYPICAL TYPICAL / BASIC ALL ALL / TYPICAL ALL / BASIC 44451 42719 (3.90%) 42558 (.38%) (4.26%) 39272 (3.23%) 38859 (1.05%) (4.25%) 634 (7.04%) 655 (-3.31%) (3.96%) 40584 682 James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 31 System Impact Test Scenarios (resource types) Statistic BASIC timed_statistics TYPICAL redo blocks written 146059 141432 139607 3.17% 1.29% 4.42% redo entries 224570 216854 214942 3.44% 0.88% 4.29% 68865028 66699016 65852920 3.15% 1.27% 4.37% 40685 39394 38970 3.17% 1.08% 4.22% change write time 1238 1227 1221 0.89% 0.49% 1.37% enqueue requests 143264 137748 137173 3.85% 0.42% 4.25% 8 33 20 -312.50% 39.39% -150.00% consistent changes 7162 6460 6833 9.80% -5.77% 4.59% physical reads 3210 2778 3116 13.46% -12.17% 2.93% physical writes 3297 2946 3040 10.65% -3.19% 7.79% parse count (total) 4818 4545 4680 5.67% -2.97% 2.86% sorts (memory) 1937 1830 1885 5.52% -3.01% 2.68% sorts (rows) 4251 4244 4243 0.16% 0.02% 0.19% table fetch by rowid 11975 11041 11505 7.80% -4.20% 3.92% table scan blocks gotten 85358 82778 81920 3.02% 1.04% 4.03% 400388 386772 383741 3.40% 0.78% 4.16% 17 16 17 5.88% -6.25% 0.00% 122229 118631 117138 2.94% 1.26% 4.17% redo size redo writes enqueue waits table scan rows gotten table scans (long tables) table scans (short tables) ALL TYPICAL / BASIC ALL / TYPICAL ALL / BASIC James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 32 System Impact More Data Give Me a Call file:///C:/temp/Vsysstat.htm file:///C:/temp/Vsysstat_xls.htm file:///C:/oradoc/920doc/server.920/a96536/apc2.htm James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 33 Buffer Cache Advisory Defined Why: Disk is slow, memory is fast What: Use to size the buffer caches When: Performance is bad Where: Populates V$DB_CACHE_ADVICE for each buffer cache in use (2K, 4K, 8K, 16K, 32K, KEEP, RECYCLE) How: db_cache_advice / statistics_level James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 34 Buffer Cache Advisory A Tried and True Friend Calculate Buffer Cache Hit Ratio SQL> SELECT name, block_size, 100*(1 - (physical_reads / (db_block_gets+consistent_gets))) buffhit FROM v$buffer_pool_statistics; How we size the buffer cache 1. Just issue the SQL to see the hit ratio 2. Got smarter and diff’d between a start and end time 3. Run a valid workload through system 4. Come up with a ballpark estimate on size 5. Increase buffer cache if hit ratio is low 6. Done if hit ratio is high James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 35 Buffer Cache Advisory Diff’d Buffer Cache Hit Ratio SQL> SELECT b.name, b.block_size, 100*(1 - ((e.physical_reads-b.physical_reads) / ((e.db_block_gets-b.db_block_gets)+ (e.consistent_gets-b.consistent_gets)))) buffhit FROM beg_buffer_pool_statistics b, end_buffer_pool_statistics e WHERE b.name=e.name AND b.block_size=e.block_size; How to diff 1. Create table beg_buffer_pool_statistics as select * from v$buffer_pool_statistics 2. Run workload through system 3. Create table end_buffer_pool_statistics as select * from v$buffer_pool_statistics 4. Issue above SQL James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 36 Buffer Cache Advisory Use of V$DB_CACHE_ADVICE SQL> SELECT name, block_size, size_for_estimate, estd_physical_read_factor, estd_physical_reads FROM V$DB_CACHE_ADVICE WHERE advice_status = 'ON'; How to get the statistics 1. Set db_cache_advice to ‘READY’ 2. Set db_cache_advice to ‘ON’ 3. Run a valid workload through system 4. Issue above SQL James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 37 Buffer Cache Advisory Output of V$DB_CACHE_ADVICE BLOCK Cache Estd Phys NAME SIZE Size Read Factor -------- ----- ----- ----------DEFAULT 8192 48 2.1133 DEFAULT 8192 96 1.7266 DEFAULT 8192 144 1.4763 DEFAULT 8192 192 1.3573 DEFAULT 8192 240 1.2801 DEFAULT 8192 288 1.2165 DEFAULT 8192 336 1.1686 DEFAULT 8192 384 1.1202 DEFAULT 8192 432 1.0877 DEFAULT 8192 480 1.0602 DEFAULT 8192 528 1.0196 DEFAULT 8192 544 1.00 1 DEFAULT 8192 576 .9765 DEFAULT 8192 624 .9392 DEFAULT 8192 672 .9216 DEFAULT 8192 720 .9013 DEFAULT 8192 768 .885 DEFAULT 8192 816 .8726 DEFAULT 8192 864 .8607 DEFAULT 8192 912 .8492 DEFAULT 8192 960 .8277 Estd Phys Reads ---------343669940 280783364 240091867 220733606 208181172 197842182 190052917 182180544 176884743 172420984 165812231 162626093 158797352 152735392 149879874 146571255 143928671 141908868 139972381 138098490 134610328 Its all about reads 1. Don’t reduce the size of your cache if you are going to incur more physical reads CURRENT 2. Don’t increase the size of your cache if you are not going to reduce the number of reads James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 38 Comments Concerns Questions Answers Dos Don’ts James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 39 Implications of Setting Oracle9iR2’s Statistical Collection Level James F. Koopmann dbDoctor Inc. Colorado www.dbdoctor.net Jkoopmann@dbdoctor.net james_koopmann@yahoo.com James F. Koopmann Implications of Setting Oracle9iR2’s Statistics Collection Level 40