DB2 Under the Hood - Quest Software
DB2 Under the Hood - Quest Software
DB2 Under the Hood - Quest Software
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>DB2</strong> <strong>Under</strong> <strong>the</strong> <strong>Hood</strong>:<br />
An OS/390<br />
Performance Primer<br />
<strong>Quest</strong> <strong>Software</strong>
Agenda<br />
� Defining Performance<br />
� Identifying/Resolving Performance<br />
Issues<br />
� The Subsystem<br />
� Physical Design Considerations<br />
� Space management<br />
� Application Design<br />
� <strong>Quest</strong> Central for <strong>DB2</strong>
What is Performance?<br />
Performance: noun<br />
“The fulfillment of a claim, promise, or<br />
request”<br />
� How does your company define<br />
performance?<br />
– System availability<br />
– Transaction throughput<br />
– Minimum response times (SLA’s)
Subsystem Monitoring<br />
� All aspects of <strong>the</strong> subsystem need to be<br />
monitored.<br />
– Not just SQL<br />
– Where are your bottlenecks?
Subsystem Performance<br />
� Components to monitor<br />
–EDM Pool<br />
– RID Pool<br />
– Buffer pool<br />
– Sort pool
Monitoring Subsystem<br />
Performance<br />
� EDM Pool (Environmental Descriptor Management Pool)<br />
– DBD (Database Descriptor)<br />
– CT (Cursor Table)<br />
– PT (Package Table)<br />
– SKCT (Skeleton Cursor Table)<br />
– SKPT (Skeleton Package Table)<br />
– Plan/Package authorization Cache (CACHESIZE > 0)<br />
– Dynamic SQL skeletons (Dynamic SQL caching<br />
active)<br />
� “System Bufferpool”<br />
– Minimizes I/O against catalog and directory
Problem: An EDM pool that is<br />
too small causes<br />
� Increased I/O activity against DSNDB01<br />
•SCT02<br />
•SPT01<br />
•DBD01<br />
� Increased response times due to loading<br />
<strong>the</strong> SKCTs, SKPTs, and DBDs<br />
� Re-preparation of Dynamic SQL<br />
� Fewer threads used concurrently, due to a<br />
lack of storage<br />
� Resource unavailable “-904”
What to monitor<br />
� EDM Pool hit ratio should be at least 80%<br />
– PT/CT’s<br />
• 80-90%<br />
– DBD requests<br />
•100%<br />
– Pages used for Package/Cursor tables
Sizing EDM Pools<br />
� Determining size of EDM Pool<br />
– Average DBD size<br />
– Average Plan/Package size<br />
– Average cache size for Plans<br />
� Don’t be afraid to make EDM too big!
Managing EDM Pool Size<br />
� Reduce size of DBD’s<br />
� Run MODIFY utility regularly to remove old recovery info.<br />
� REORG tablespaces when tables dropped/recreated<br />
� Reduce storage used by Plans/Packages<br />
� Avoid large Plans<br />
• Use Packages (avoid DBRM’s)<br />
• Break applications into separate Plans<br />
� DEGREE(ANY) maintains 2 access paths<br />
• One each for Parallelism YES/NO<br />
� Bind w/AQUIRE(USE) vs. AQUIRE(ALLOCATE) when possible.<br />
� Use RELEASE(COMMIT) for infrequently used Plans/Pkg’s<br />
� Use RELEASE(DEALLOCATE) cautiously<br />
• Can cause EDM pool to grow enormously.<br />
• Only change a few programs at a time.<br />
– Monitor EDM pool and IRLM memory usage before/after changing<br />
from COMMIT to DEALLLOCATE
RID Pool<br />
� “Row Identifier” Pool<br />
– Used for Storing and Sorting RID’s for:<br />
• List Prefetch<br />
• Multiple index access<br />
• Hybrid Joins<br />
� Default size = 4MB<br />
– 1000MB max<br />
– 0 deactivates Prefetch and multi-IX scans
Problem<br />
� If RID pool is too small<br />
– Previously mentioned access paths can<br />
revert to TS scans<br />
� How Big?<br />
– #SQL statements requiring RID processing<br />
X Avg number of RID’s X 2 X 4 (5 for LOBs)
What to Monitor<br />
� Insufficient pool size<br />
– RID pool too small<br />
� RDS Limit<br />
– RID list > 25% #rows in<br />
table<br />
• Prefetch turned off and TS scan<br />
results<br />
– Determined at Bind time<br />
� DM Limit<br />
– RIDs req’d to satisfy query<br />
> 16 million<br />
– TS scan results<br />
<strong>Quest</strong> Central’s Spotlight Application Statistics Report
RID Pool Tuning<br />
� Insufficient pool size<br />
– Recalculate RID pool size<br />
– # of concurrent RIDS x Avg #RIDs x 2 x5 bytes/RID<br />
� RDS Limit<br />
– Have tables grown since BIND?<br />
– Make sure stats are accurate<br />
• RUNSTATS/REBIND<br />
� DM Limit<br />
– Is TS Scan best access?<br />
– Re-evaluate indexes<br />
– Add additional filtering
Bufferpools<br />
� Virtual storage for temporarily<br />
holding data and IX pages<br />
– Use DBM1 address space<br />
• Virtual bufferpools<br />
• Can define up to 80 BP’s<br />
– Limited to 1.6GB total<br />
–DBM1 + Hiperspace<br />
•Hiperpools<br />
• Additional 8GB of extended storage<br />
• “Holding tank” for infrequently updated<br />
data<br />
– MVS Dataspace<br />
• Support up to 8M buffers<br />
• Allows for direct I/O from extended storage<br />
Virtual BP<br />
Buffer<br />
Pages<br />
DASD<br />
Hiperpool<br />
Buffer<br />
Pages
Bufferpools<br />
� Hiperpools<br />
Advantages<br />
– Less space required for virtual pools<br />
• Reduce central storage requirements<br />
– Serve as cache for infrequently accessed data<br />
• Reduced response times vs. accessing DASD<br />
– Use hiperpools when paging rates are high on<br />
virtual pools<br />
� Disadvantage<br />
– No direct I/O from Hiperpool<br />
• Data is transferred back into virtual pool
Monitoring Bufferpools<br />
� -Display Bufferpool<br />
� 3 rd Party monitor
What to Monitor<br />
� Buffer Pool hit ratio<br />
(GETPAGES – pages read)/GETPAGES<br />
� Hiperpool Hit Ratio<br />
– #pages read from<br />
hiperpool/pages written<br />
� Page Externalization<br />
– Excessive writes to disk<br />
• Deferred write threshold<br />
(DWQT)<br />
• Vertical Deferred Write<br />
Threshold (VDQWT)<br />
Spotlight BP Detail
Effective Use of Bufferpools<br />
� <strong>DB2</strong> has 80 bufferpools available for a reason.<br />
� Separate bufferpools for:<br />
� Catalog and Directory (BP0)<br />
� DSNDB07<br />
� Tablespaces<br />
� Indexes<br />
• Large VPSIZE<br />
•More than one<br />
� Small, Read-only tables<br />
� Large tablespaces w/random processing<br />
� Small frequently updated tables and IX’s<br />
� Test environment for isolating test cases<br />
� The single biggest performance mistake is to stick<br />
everything in BP0!
Sort Pools<br />
� Sort pools should be made as<br />
large as possible<br />
– 240K – 64MB<br />
• Default to 1MB<br />
– Minimizes externalizing to physical<br />
sort files and BP’s<br />
•DSNDB07
Optimizing Sort<br />
� DSNDB07<br />
– Do not use BP0!<br />
– 4 –5 equally sized datasets<br />
– Keep in primary space<br />
– Separate volumes<br />
� Application Considerations<br />
– Avoid ORDER by, Group By, Distinct<br />
– Avoid sorting VARCHARs<br />
– Only select required columns
Physical Design<br />
� <strong>DB2</strong><br />
Catalog/Directory<br />
� Physical Objects<br />
– Tablespace<br />
–Index
Problem<br />
� A poorly designed/maintained catalog can<br />
result in:<br />
– Slow response time from catalog queries<br />
– Contention with o<strong>the</strong>r users
The <strong>DB2</strong> Catalog<br />
� Design Considerations<br />
– BP0 is isolated to <strong>the</strong> catalog only<br />
– Keep catalog and directory on separate<br />
volumes<br />
• Do not put o<strong>the</strong>r <strong>DB2</strong> objects on catalog<br />
volume<br />
– Keep EXTENTS to a minimum<br />
• Use REORG or RECOVER to re-allocate<br />
– Do not migrate catalog datasets (DFSMS)
<strong>DB2</strong> Catalog<br />
� Maintenance<br />
– Eliminate redundant grants in AUTH tables<br />
• Can be significant in older <strong>DB2</strong> environments<br />
• Can cause significant performance impact<br />
– Schedule regular maintenance<br />
• Treat Catalog like application<br />
–RUNSTATS<br />
–REORG<br />
• Reorg related directory tables at same time<br />
– SYSDBASE + DBD01<br />
– SYSPLAN + SCT02<br />
– SYSPACKAGE + SPT01
<strong>DB2</strong> Catalog<br />
To avoid contention:<br />
� Limit DDL and Binds to off hours<br />
� Create “canned” queries for catalog reports using<br />
VIEWS<br />
� Keep RUNSTATS current
Tablespace Design<br />
� What type of tablespace?<br />
� Simple<br />
� Segmented<br />
� Partitioned
Simple<br />
� In General avoid, use Segmented<br />
Advantage<br />
• If “READ ONLY” and data from 2 tables is being<br />
retrieved in a hierarchical order<br />
– Data from tables can be co-mingled onto same pages<br />
Disadvantages<br />
• Data from multiple tables on same page<br />
• Page/Table locks can lock data from multiple tables<br />
• Tablespace scans can be much slower if multiple tables<br />
in TS<br />
• Utilities lock entire TS<br />
• Dropped table space not immediately available
Segmented<br />
� Best choice for most applications<br />
Advantage<br />
• TS scans only scan segments assigned to table<br />
• Multiple tables data is not co-mingled<br />
– Data pages organized into segments (4-64)<br />
– Table locks do not affect o<strong>the</strong>r tables<br />
• Dropped table or mass delete space immediately<br />
available<br />
– Only space map updated<br />
– No REORG required<br />
• Less logging for mass delete<br />
Disadvantage<br />
• LOAD REPLACE, RECOVER, and COPY must be for<br />
entire tablespace
Segmented<br />
� Choosing SEGSIZE<br />
Pages<br />
28128<br />
Segsize<br />
4 – 28<br />
32<br />
64<br />
� For efficient sequential prefetch on small tables, choose a<br />
segsize = #pages in largest table
Partitioned<br />
� Best choice for very large tables or when<br />
Parallelism required<br />
– Advantages<br />
• Spread data across multiple devices and<br />
bufferpools<br />
• Partition independence<br />
– Utilities more manageable<br />
– Higher availability<br />
• I/O Parallelism<br />
– Prefetch data from multiple partitions concurrently<br />
• Query Parallelism<br />
– Partitions can be spread across SYSPLEX members
Partitioned<br />
–Disadvantage<br />
• Fixed # of partitions<br />
– Table must be dropped to add/remove<br />
partitions (changing in V8)<br />
• TS Scans less efficient than segmented<br />
• More open datasets
Index considerations<br />
� Separate bufferpools from tablespaces<br />
� Avoid updated columns<br />
– Especially for partitioning keys<br />
� Have thorough knowledge of SQL<br />
– Composite key IX’s can sometimes be more efficient<br />
than single column keys<br />
– Use Asc/Desc to avoid sorting
Space Management<br />
� Efficient DASD<br />
Utilization<br />
� Compression<br />
� Object<br />
Maintenance
Efficient DASD Utilization<br />
� Allocate <strong>DB2</strong> datasets to use only primary space<br />
– Excessive extents can cause inefficient I/O<br />
� Determine best page size for application<br />
– Data sharing<br />
• 8K or 16K page size can reduce overhead in coupling facility<br />
� Use HSM to manage datasets<br />
– Move infrequently accessed datasets to slower devices
Compression<br />
� Use COMPRESS when applicable<br />
– More rows/page minimizes I/O<br />
• Higher BP hit ratios<br />
• Fewer Getpage requests<br />
– Always use hardware compression<br />
• Significantly less overhead than<br />
EDITPROC/FIELPROC<br />
– Less DASD<br />
– Use DSN1COMP to check compression rate
Compression<br />
� Considerations<br />
– For heavily updated data<br />
• Increase PCTFREE to avoid increases in:<br />
– Synchronous reads<br />
–Lock requests<br />
– Getpage requests<br />
– Decoding is much cheaper than encoding<br />
– Overhead for TS scans can be higher<br />
– Cheaper for IX scans
Maintenance<br />
� Proper maintenance is critical for<br />
optimal performance<br />
–REORG<br />
– RUNSTATS<br />
–Real-Time Statistics
Reorg<br />
� What causes fragmentation?<br />
–Insert/Update<br />
• Check PCTFREE and FREEPAGE<br />
– VARCHAR fields being updated
Monitoring for REORGs<br />
� When to Reorg a tablespace:<br />
– CLUSTER RATIO < 95%<br />
•SYSINDEXES<br />
– CLUSTERATIO < 95%<br />
•SYSINDEXPART<br />
–FAROFFPOS> 10% of CARD<br />
– Excessive row relocation<br />
•SYSTABLEPART<br />
– NEARINDREF+FARINDREF > 10% of CARD<br />
– Excessive extents (>50)<br />
– Excessive drop space<br />
• Simple TS only<br />
– PERCDROP > 10%<br />
– LOB tablespaces<br />
•SYSLOBSTATS<br />
– ORGRATIO > 2
Monitoring for REORGs<br />
� When to REORG an Index<br />
– Excessive distance between LEAF pages<br />
• SYSINDEXPART<br />
– LEAFDIST > 200<br />
» Can cause Pre-fetch to be disabled<br />
» Should be monitored for growth<br />
– LEAFFAR > 10% of NLEAF (SYSINDEXES)<br />
– Excessive extents (>50)
RUNSTATS<br />
� Accurate statistics are a critical factor for<br />
performance monitoring and tuning<br />
• RUNSTATS provides statistical information for:<br />
1. Optimization of SQL<br />
2. Monitoring status of objects
RUNSTATS<br />
� When to run RUNSTATS:<br />
� After LOAD, REORG, and REBUILD IX<br />
� After creating new index<br />
� After heavy insert, update, delete activity<br />
� Performance Tip:<br />
� Only run RUNSTATS against partitions which have<br />
changed.<br />
� Consider using <strong>the</strong> SAMPLE option for column<br />
statistics to reduce processor costs<br />
• Be sure to check access paths when using<br />
SAMPLE option
Monitoring RUNSTATS<br />
� REBIND after RUNSTATS?<br />
� New index created<br />
� CLUSTERRATIOF changes 80%<br />
� Changes more than 20%<br />
• Cardinality<br />
•NPAGES<br />
• NACTIVEF<br />
•NLEAF<br />
• Range of HIGH2KEY to LOW2KEY
Real Time Stats<br />
� New for V7<br />
• Facility for automating <strong>the</strong> collection of <strong>DB2</strong><br />
statistics<br />
• Stored procedure DSNACCOR<br />
1. Recommends when to REORG, Copy, or run<br />
RUNSTATS<br />
2. Identifies TS and IX’s that have exceeded <strong>the</strong>ir<br />
dataset extents<br />
3. Identifies objects in restricted state<br />
4. Stores data in new stats database DSNRTSDB<br />
5. Application must be built around DSNACCOR to<br />
return information
Real Time Stats<br />
� Create stats database<br />
– DDL in SDSNSAMP(DSNTESS)<br />
� Set collection interval<br />
– Install panel DSNTIPO “Real TIME STATS”<br />
– DSNZPARM = STATSINT<br />
– Default interval = 30 Minutes<br />
– Data sharing environment has 1 interval per member<br />
� Start statistics database<br />
– START DATABASE(DSNRTSDB)
Application Design<br />
� Application prep<br />
� SQL Design considerations<br />
� Optimization Hints<br />
� Bind considerations<br />
� Efficient application design is <strong>the</strong> single<br />
most important aspect of an efficiently<br />
performing subsystem
Program Preparation �Check Object Validity<br />
Application<br />
Code<br />
Precompile<br />
Compile<br />
Link<br />
Edit<br />
Executable<br />
Load<br />
Module<br />
DBRM Bind<br />
Plan<br />
or<br />
Package<br />
<strong>DB2</strong><br />
Catalog<br />
Optimizer<br />
DSNDB01<br />
SKCT<br />
SKPT<br />
�Check authority<br />
�Compute filter factors<br />
�Choose access path<br />
�Prefetch Y/N
Optimization Tips<br />
� Make sure statistics<br />
are accurate<br />
� Use stage 1 vs. stage<br />
2 predicates<br />
� Only select required<br />
columns<br />
– Avoid SELECT *<br />
� Keep predicates as<br />
restrictive as possible<br />
– Minimize # rows<br />
returned<br />
– Minimize program<br />
filtering and let <strong>DB2</strong> do<br />
<strong>the</strong> work<br />
� Order predicates from<br />
most to least<br />
restrictive<br />
� Avoid sorts<br />
– ASC/DESC indexes can<br />
help avoid excessive<br />
sorting<br />
� Avoid UNION clause<br />
– CASE expression more<br />
efficient<br />
� AND MOST<br />
IMPORTANTLY…..
Use EXPLAIN!
Optimization Hints<br />
� Allows for user specified access path<br />
– Useful for maintaining access paths:<br />
• across releases<br />
•After Rebinds<br />
– Should be used cautiously
Using Hints<br />
� Save access path info for all critical queries before<br />
using HINTS<br />
� Plan_Table must be in correct 49 column format<br />
� DSNZPARM, Optimization Hints = Yes<br />
� Add QUERYNO clause to SQL<br />
� Update Plan_Table<br />
– Specify name in OPTHINT for desired access path<br />
– Static -REBIND PLAN(XYZ) EXPLAIN YES<br />
OPTHINT(‘MYACCESS’)<br />
– Dynamic – Set Current Optimization Hint = ‘MYACCESS’
Bind Considerations<br />
� ACQUIRE(ALLOCATE)/<br />
RELEASE(DEALLOCATE)<br />
– Best for long running applications<br />
– Good for batch processes<br />
– Advantage<br />
• Helps prevent deadlocking<br />
–Disadvantage<br />
• Reduces concurrency<br />
• Can lock all partitions of TS if LOCKPART<br />
YES<br />
• N/A for BIND PACKAGE<br />
• Can cause EDM pool overflow
Bind Considerations<br />
� ACQUIRE(USE)/RELEASE(deallocate)<br />
– Best choice for most applications<br />
–Advantage<br />
• Locks are taken only as needed<br />
• Least restrictive locks used<br />
• Locks released when plan terminates<br />
–Disadvantage<br />
• Can increase frequency of deadlocks
Bind Considerations<br />
� ACQUIRE(USE)/RELEASE(COMMIT)<br />
– Best for maximum concurrency<br />
– Advantages<br />
• Table/TS locks taken only when needed<br />
• Least restrictive lock selected<br />
• All locks released at COMMIT<br />
– Unless CURSOR WITH HOLD<br />
– Disadvantage<br />
• Excessive overhead for frequent COMMITS<br />
• Increased frequency of deadlocks
Summary<br />
� Build a strategy for how you will<br />
monitor/tune your <strong>DB2</strong> environment<br />
– Try to identify most critical applications and begin<br />
focusing on those<br />
– Set realistic performance expectations<br />
– Tune, monitor, tune, monitor…
<strong>Quest</strong> Central for <strong>DB2</strong><br />
� Everything <strong>the</strong> DBA needs to manage<br />
<strong>DB2</strong> in a single integrated console<br />
– Database Administration<br />
– SQL Tuning<br />
– Space Management<br />
– Performance/Diagnostics<br />
� Manage <strong>DB2</strong> running on OS/390,<br />
z/OS, Linux, Unix, and Windows form<br />
a single tool!
Database Administration<br />
� Complete Object<br />
Administration<br />
– Create<br />
– Extended Alter<br />
– Drop<br />
– Generate DDL<br />
– Migration<br />
– Compare/Sync
SQL Tuning<br />
� Complete SQL Tuning<br />
Lab<br />
– Easy to read Explain<br />
– All statistics in same<br />
window<br />
–Advice<br />
– Unique Compare Facility
Space Management<br />
� Space exceptions<br />
– User defined<br />
thresholds<br />
–Advice<br />
� Historical Growth<br />
� Space Calculator<br />
– “What-if” space<br />
estimation<br />
– Detailed space usage<br />
–Volume Analysis<br />
� Utility Generation
Performance Diagnostics<br />
� Complete view of<br />
Subsystem activity<br />
– User defined alert<br />
thresholds<br />
� Detailed Drilldowns<br />
– System Summary<br />
– Thread Details<br />
– “Top SQL” Details<br />
– BP Details<br />
� Historical Record/Playback<br />
– <strong>DB2</strong> Repository<br />
� Integrated with o<strong>the</strong>r<br />
components<br />
– SQL tuning<br />
– Space management<br />
– Database Administration
THANK YOU<br />
FOR LISTENING<br />
Download a free Trial of<br />
<strong>Quest</strong> Central for <strong>DB2</strong> Today!<br />
WWW.<strong>Quest</strong>.Com/<strong>DB2</strong><br />
Also, be sure to stop by our booth at:<br />
�IDUG Europe, Nice Oct 7-10<br />
�IBM Technical Conference, Las Vegas, Oct 27-31