Upload
patrick-lane
View
214
Download
1
Embed Size (px)
Citation preview
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 1
Implications
of Setting
Oracle9iR2’s
Statistical Collection LevelJames F. Koopmann
Co-Founder & Chief Architect
dbDoctor Inc.
Colorado
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 2
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 3
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 4
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 5
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 yourself1. 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 6
Why Do We Care About Statistics, Who Needs Them
It’s All About Problem Detection
Lazy man method of finding problemsa. 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 problemsa. 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 7
Why Do We Care About Statistics, Who Needs Them
The Problem with Problems1. We have to fix them
2. Mistakes are common and we can’t rid ourselves of thema. Be compassionate
b. Be humble
3. Receive new ideas with an open but analytical minda. Research for yourself
b. Have reliable sources
4. Validate what you have heard or reada. don’t take for granted everything you read or hear
b. “Your mileage may vary”
5. Accept only after validationa. 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 8
New to Oracle9iR2
STATISTICS_LEVEL
Controls Collection of Advisories and Statistics
1. Shared Pool Advice2. Buffer Cache Advice3. PGA Advice4. MTTR Advice5. Segment Level Statistics6. Timed Statistics7. Timed OS Statistics8. Plan Execution Statistics
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 9
DYNAMICParameter 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. Change the value of a parameter for the duration of the session.
2. The value of this parameter does not change for other sessions in the instance.
ALTER SYSTEM SET parameter_name = value 1. Change the value of the parameter for all current and future sessions.
2. Record the change in the alert.log
ALTER SYSTEM SET parameter_name = value [DEFERRED] 1. Change only applies to future sessions that will connect to the database.
2. Record the change in the alert.log
STATISTICS_LEVEL is a Dynamic Parameter
New to Oracle9iR2
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 10
New to Oracle9iR2
V$STATISTICS_LEVELColumn Values(?) Description
STATISTICS_NAME Name of the statistics/advisory.
DESCRIPTION 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 YES|NO. Whether this statistics/advisory can be set at the
session level.
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 11
New to Oracle9iR2
V$STATISTICS_LEVELSQL> 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
PGA Advice V$PGA_TARGET_ADVICE Predicts the impact of different values of
pga_aggregate_target on the performance of
memory intensive SQL operators
Segment Level Statistics V$SEGSTAT Enables gathering of segment access statistics
Timed OS Statistics Enables gathering of timed operating system
statistics
MTTR Advice V$MTTR_TARGET_ADVICE Predicts the impact of different MTTR settings
on number of physical I/Os
Buffer Cache Advice V$DB_CACHE_ADVICE Predicts the impact of different cache sizes on
number of physical reads
Timed Statistics Enables gathering of timed 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 12
1. Simplified Parameter Management
2. Change in STARTUP Sequence
3. Push to Migrate from Parameter File
SPFILE
Is the Init.ora File Going Away ?
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 13
SQL> show parameter spfile
NAME TYPE VALUE
--------------------------- --------- --------------
spfile string
SPFILE
DO You Have One?
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 14
SPFILE
How Do I Get One?
Help, I Want My INIT.ORA
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 15
• 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
SPFILE
Items to Consider
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 16
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 startup2. SPFILE - the change is made in the server parameter file only and
available after next startup3. BOTH - MEMORY + SPFILE, this is the default
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 17
SPFILE
ALTER SYSTEM RESET
Resetting a Parameter
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 controlalter 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 18
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 19
STATISTICS_LEVEL
Parameter ALTER SESSION
ALTER SYSTEM
ALTER SYSTEM …DEFERRED
STATISTICS_LEVEL
Db_cache_advice
Timed_statistics
Timed_os_statistics
Dynamic Parameters
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 20
STATISTICS_LEVEL
Statistic / Advisory BASIC TYPICAL ALL 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
Three Settings Override
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 21
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 VALUE ISSES_MODIFIABLE ISSYS_MODIFIABLE ISDEFAULT ISMODIFIED
---------------------- ------- ---------------- ---------------- --------- ---------
timed_statistics FALSE TRUE IMMEDIATE TRUE FALSE
timed_os_statistics 0 TRUE IMMEDIATE TRUE FALSE
db_cache_advice OFF FALSE IMMEDIATE TRUE FALSE
Take a Look at Your Settings
Override Control (V$PARAMETER)
statistics_level TYPICAL TRUE IMMEDIATE TRUE FALSE
TRUE = Default Value
(NO SPFILE entry)
FALSE = SPFILE entry
FALSE = Not Modified since startup
MODIFIED = ALTER SESSION
SYSTEM_MOD = ALTER SYSTEM
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 22
SQL> SELECT statistics_name, session_status, system _status
activation_level, session_settable
FROM v$statistics_level
Take a Look at Your Settings
Override Control (V$STATISTICS_LEVEL)
STATISTICS SESSION SYSTEM ACTIVATION SESSION
NAME STATUS STATUS LEVEL SETTABLE
------------------------- -------- -------- ---------- --------
Buffer Cache Advice ENABLED ENABLED TYPICAL NO
MTTR Advice ENABLED ENABLED TYPICAL NO
PGA Advice ENABLED ENABLED TYPICAL NO
Segment Level Statistics ENABLED ENABLED TYPICAL NO
Shared Pool Advice ENABLED ENABLED TYPICAL NO
Timed Statistics ENABLED ENABLED TYPICAL YES
Plan Execution Statistics DISABLED DISABLED ALL YES
Timed OS Statistics DISABLED DISABLED ALL YES
What Level in STATISTICS_LEVEL
to ActivateAm I CollectingAm I Collecting
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 23
• 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.
Take a Look at Your Settings
Don’t Get Confused
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 24
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
Take a Look at Your Settings
Oracle Gets Confused
NAME VALUE ISSES_MODIFIABLE ISSYS_MODIFIABLE ISDEFAULT ISMODIFIED
---------------------- ------- ---------------- ---------------- --------- ---------
timed_os_statistics 10 TRUE IMMEDIATE FALSE FALSE
STATISTICS SESSION SYSTEM ACTIVATION SESSION
NAME STATUS STATUS LEVEL SETTABLE
------------------------- -------- --------- ---------- --------
Timed OS Statistics UNKNOWN UNKNOWN ALL YES
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 25
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 26
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 27
System Impact
Statistic / Advisory BASIC TYPICAL ALL
Shared Pool Advice
Buffer Cache Advice
PGA Advice
MTTR Advice
Segment Level Statistics
Timed Statistics
Timed OS Statistics
Plan Execution Statistics
Test Scenarios 1. Reduce stress
associated with statistical collection
2. Who else will help
3. Validate for myself
Why
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 28
System Impact
Basic Terminology
User / Job
Request
(workload)
(v$sysstat)
User
Decides
What to
Do Next
Database
Completes
Request
Database Response Time
Coffee Break
Throughput
Resource Usage
(v$sysstat)
Sorts, Reads, Writes, Enqueues, Redo activity, Buffer cache activity, Parsing,
…
User
Queues
Next
Transaction
Think
Time
LGWR wait for redo copy,
log file sync,
db file sequential read,…
Wait Times
(v$system_event)
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 29
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 30
System Impact
Test Scenarios (workload types) Statistic BASIC
timed_statisticsTYPICAL
TYPICAL / BASIC
ALL
ALL / TYPICAL ALL / BASIC
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%
session logical reads 1087327 1052570
(3.20%)
1041518
(1.05%)
4.21%
db block changes 446278 431281
(3.36%)
427297
(0.92%)
4.25%
user commits 39405 38323
(2.75%)
37766
(1.45%)
4.16%
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 31
System Impact
Test Scenarios (wait types)Statistic BASIC
timed_statisticsTYPICAL
TYPICAL / BASIC
ALL
ALL / TYPICAL ALL / BASIC
Total Waits 44451 42719
(3.90%)
42558
(.38%)
(4.26%)
Total Timeouts 40584 39272
(3.23%)
38859
(1.05%)
(4.25%)
Total Time Waited 682 634
(7.04%)
655
(-3.31%)
(3.96%)
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 32
System Impact
Test Scenarios (resource types)Statistic BASIC
timed_statistics
TYPICAL ALL TYPICAL / BASIC ALL / TYPICAL
ALL / BASIC
redo blocks written 146059 141432 139607 3.17% 1.29% 4.42%
redo entries 224570 216854 214942 3.44% 0.88% 4.29%
redo size 68865028 66699016 65852920 3.15% 1.27% 4.37%
redo writes 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%
enqueue waits 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%
table scan rows gotten 400388 386772 383741 3.40% 0.78% 4.16%
table scans (long tables) 17 16 17 5.88% -6.25% 0.00%
table scans (short tables) 122229 118631 117138 2.94% 1.26% 4.17%
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 33
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 34
Buffer Cache Advisory
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
Defined
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 35
Buffer Cache Advisory
A Tried and True FriendCalculate 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 36
Buffer Cache Advisory
Diff’d Buffer Cache Hit RatioSQL> 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 37
Buffer Cache Advisory
Use of V$DB_CACHE_ADVICESQL> 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 38
Buffer Cache Advisory
Output of V$DB_CACHE_ADVICE BLOCK Cache Estd Phys Estd PhysNAME SIZE Size Read Factor Reads-------- ----- ----- ----------- ----------DEFAULT 8192 48 2.1133 343669940DEFAULT 8192 96 1.7266 280783364DEFAULT 8192 144 1.4763 240091867DEFAULT 8192 192 1.3573 220733606DEFAULT 8192 240 1.2801 208181172DEFAULT 8192 288 1.2165 197842182DEFAULT 8192 336 1.1686 190052917DEFAULT 8192 384 1.1202 182180544DEFAULT 8192 432 1.0877 176884743DEFAULT 8192 480 1.0602 172420984DEFAULT 8192 528 1.0196 165812231DEFAULT 8192 544 1 162626093DEFAULT 8192 576 .9765 158797352DEFAULT 8192 624 .9392 152735392DEFAULT 8192 672 .9216 149879874DEFAULT 8192 720 .9013 146571255DEFAULT 8192 768 .885 143928671DEFAULT 8192 816 .8726 141908868DEFAULT 8192 864 .8607 139972381DEFAULT 8192 912 .8492 138098490DEFAULT 8192 960 .8277 134610328
DEFAULT 8192 544 1.00 162626093 CURRENT
Its all about reads1. Don’t reduce the size of
your cache if you are going to incur more physical reads
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 39
&CommentsConcernsQuestionsAnswers
DosDon’ts
James F. Koopmann
Implications of Setting Oracle9iR2’s Statistics Collection Level 40
Implications
of Setting
Oracle9iR2’s
Statistical Collection LevelJames F. Koopmann
dbDoctor Inc.
Colorado