Using DB2 Monitors to Analyze and Improve SQL & Query Performance
Total Page:16
File Type:pdf, Size:1020Kb
IBM System i™ Session: 440101 (47MA) Using DB2 Monitors To Analyze and Improve SQL & Query Performance Gene Cobb IBM Rochester, MN 8 Copyright IBM Corporation, 2006. All Rights Reserved. i want stress-free IT. This publication may refer to products that are not currently available in your country. IBM makes no commitment to make i want control. available any products referred to herein. i want an i. IBM System i Query Optimization and Execution Feedback V5R4 delivers! Many new and exciting tools for monitoring and analyzing DB2 UDB for iSeries SQL requests and SQL performance 2 i want an i. © 2006 IBM Corporation 1 IBM System i Query Optimization and Execution Feedback V5R4 V5R4 V5R4 Visual Explain Index SQE Plan SQE Cache Advised PlanCache Snapshots Detailed DB Monitor Data SQL request Summarized DB Monitor Query Data Optimization Debug Print SQL Job Log Information Messages Messages 3 i want an i. © 2006 IBM Corporation IBM System i What are the DB2 SQL Performance Monitors? • Integrated tool set used to gather database performance related statistics for SQL-based requests running on the iSeries – i5/OS – Applicable to both batch jobs and interactive work – Only collect information on the DB2 engine processing - does not include the time that it took for the requests to get to the DB2 engine (e.g., JDBC driver processing) • Monitor data dumped into table(s) where it can be queried to help identify and tune performance problem areas – Collected data can be analyzed to look at SQL performance at a global system level, job-level or, specific SQL statement level • Monitor data most useful given a basic understand of DB2 UDB engine and query optimization techniques • Monitor data does not tell you what to do – The science and art of query performance needs to be applied 4 i want an i. © 2006 IBM Corporation 2 IBM System i Database Monitor Information • Provides information such as: – System, job and user names – SQL statement text – Start and end timestamps – Estimated processing time – Total rows in table queried – Number of rows selected – Estimated number of rows selected – Estimated number of joined rows – Key columns for advised indexes – Total optimization time and run time – Open data path (ODP) implementation – QAQQINI settings – Many others 5 i want an i. © 2006 IBM Corporation IBM System i Database Monitor Information • Collected information can be analyzed later: – Which queries are the most time consuming? – How many queries rebuild access plans? – How many queries performed a full table scan? – How many temporary indexes have been created over a particular table? – Which user is running the longest running queries? – Has the implementation of a particular query changed with the application of a PTF or a new release? • Before and After comparison of the monitor data – Visually explain a given query plan • From detailed data captured by the query optimizer 6 i want an i. © 2006 IBM Corporation 3 IBM System i Measuring & Monitoring DB2 Performance END Output Results Disk I/O ƒJournaling RunTime ƒIndex Maintenance ƒConstraint Enforcement Communications ƒLocking ƒTrigger Processing Open ƒODP Creation Database Processing ƒDatabase Authentication Authentication ƒAccess Plan Creation Optimization ƒIndex Selection ƒIndex Estimates User Display I/O Process Request BEGIN 7 i want an i. © 2006 IBM Corporation IBM System i Measuring & Monitoring DB2 Performance • iSeries Navigator GUI interface – SQL Performance Monitors New! – SQE Plan Cache Snapshots – Start, Stop, Import, Capture, Manage, Analyze • Summarized Database Monitor • SQE Plan Cache Snapshot • Detailed Database Monitor • The collection and capture mechanism will depend on how wide a net you need to cast, and how fine the net should be woven 8 i want an i. © 2006 IBM Corporation 4 IBM System i Monitor Interfaces via iSeries Navigator 9 i want an i. © 2006 IBM Corporation IBM System i Summarized Database Monitor 10 i want an i. © 2006 IBM Corporation 5 IBM System i Summarized Database Monitor • Few enhancements in V5R4 • Summarized information collected by the SQL “monitoring” facility – Data is placed into multiple DB2 tables – Memory based – Low overhead • CQE and SQE support • API interface • GUI interface via iSeries Navigator – Access – Pre-filtering and Post-filtering – Analysis by time, user, job, statement, etc. – No Visual Explain • Data is not volatile – Information from the optimizer and engine is “captured” and summarized at a point in time 11 i want an i. © 2006 IBM Corporation IBM System i Summarized Database Monitor - New 12 i want an i. © 2006 IBM Corporation 6 IBM System i Summarized Database Monitor - New 13 i want an i. © 2006 IBM Corporation IBM System i Summarized Database Monitor - New 14 i want an i. © 2006 IBM Corporation 7 IBM System i Summarized Database Monitor - New 15 i want an i. © 2006 IBM Corporation IBM System i Summarized Database Monitor - Import 16 i want an i. © 2006 IBM Corporation 8 IBM System i Summarized Database Monitor - Import 17 i want an i. © 2006 IBM Corporation IBM System i Summarized Database Monitor - Properties 18 i want an i. © 2006 IBM Corporation 9 IBM System i Summarized Database Monitor - Properties 19 i want an i. © 2006 IBM Corporation IBM System i Summarized Database Monitor - Analyze 20 i want an i. © 2006 IBM Corporation 10 IBM System i Summarized Database Monitor - Analyze 21 i want an i. © 2006 IBM Corporation IBM System i SQE Plan Cache Snapshots 22 i want an i. © 2006 IBM Corporation 11 IBM System i SQE Plan Cache Snapshots • New V5R4 feature • System wide information materialized from the SQE Plan Cache – No overhead – data capture is part of normal query optimization and execution – Pre-filtering – Data is placed into a single DB2 table • SQE support only • SQL interface (CALL QSYS2/DUMP_PLAN_CACHE ‘schema’, ‘snapshot’) • GUI interface via iSeries Navigator – Access – Filtering – Analysis by time, user, job, statement, etc. – Visual Explain • Data is not volatile – Information from the SQE Plan Cache is “captured” at a point in time • SQE Plan Cache is always available – No need to “start and stop” a tool or utility • Additional analysis methods available like “before and after” comparisons 23 i want an i. © 2006 IBM Corporation IBM System i SQE Plan Cache Snapshots - New 24 i want an i. © 2006 IBM Corporation 12 IBM System i SQE Plan Cache Snapshots - New 25 i want an i. © 2006 IBM Corporation IBM System i SQE Plan Cache Snapshots - Import 26 i want an i. © 2006 IBM Corporation 13 IBM System i SQE Plan Cache Snapshots - Properties 27 i want an i. © 2006 IBM Corporation IBM System i SQE Plan Cache Snapshots - Properties 28 i want an i. © 2006 IBM Corporation 14 IBM System i SQE Plan Cache Snapshots - Analyze 29 i want an i. © 2006 IBM Corporation IBM System i SQE Plan Cache Snapshots - Analyze “Dashboard” provides a quick overview of information 30 i want an i. © 2006 IBM Corporation 15 IBM System i SQE Plan Cache Snapshots - Analyze Summary 31 i want an i. © 2006 IBM Corporation IBM System i SQE Plan Cache Snapshots - Analyze Statements 32 i want an i. © 2006 IBM Corporation 16 IBM System i SQE Plan Cache Snapshots - Show Statements 33 i want an i. © 2006 IBM Corporation IBM System i SQE Plan Cache Snapshots - Show Statements List is initially empty, the statements are filled after Retrieve or Refresh 34 i want an i. © 2006 IBM Corporation 17 IBM System i SQE Plan Cache Snapshots - Compare 35 i want an i. © 2006 IBM Corporation IBM System i SQE Plan Cache Snapshots - Compare 36 i want an i. © 2006 IBM Corporation 18 IBM System i SQE Plan Cache Snapshots – Compare VE 37 i want an i. © 2006 IBM Corporation IBM System i Detailed Database Monitor 38 i want an i. © 2006 IBM Corporation 19 IBM System i Detailed Database Monitor • Enhanced in V5R4 • Detailed information collected - SQL “trace” – Data is placed into a single DB2 table – Potentially high overhead • CQE and SQE support • Command interface – STRDBMON / ENDDBMON • Connection attributes interface • GUI interface via iSeries Navigator – Access – Pre-filtering and Post-filtering – Analysis by time, user, job, statement, etc. – Summary information via “dashboard” – Visual Explain • Data is not volatile – Information from the optimizer and engine is “captured” at a point in time • Additional analysis methods available like “before and after” comparisons 39 i want an i. © 2006 IBM Corporation IBM System i Detailed Database Monitor - STRDBMON command Type of records = *SUMMARY is NOT the memory based “summary” monitor 40 i want an i. © 2006 IBM Corporation 20 IBM System i Detailed Database Monitor - STRDBMON command New types of filtering to limit the scope and overhead of data collection 41 i want an i. © 2006 IBM Corporation IBM System i Detailed Database Monitor - STRDBMON command • New (late) filtering option based on the “query governor” thresholds – Query governors: query time limit and/or query storage limit • Set via System value, QAQQINI, CHGQRYA – Query storage limit exit point program called when a governor threshold reached • QIBM_QQQ_QUERY_GOVR – Filter capability added to V5R4 late – use the Comment parameter to specify the filter – Query governor filter is combined with other filters • FTRQRYGOVR parameter – Parameter values are *NONE, *ALL or *COND – Filtering parameter value *NONE - never react to the thresholds – Filtering parameter value *ALL - always react to the thresholds – Filter parameter value *COND - react based on the return code of the exit point 42 i want an i. © 2006 IBM Corporation 21 IBM System i Detailed Database Monitor - ENDDBMON command Ends a specifically named and numbered monitor – REMEMBER the name or ID 43 i want an i. © 2006 IBM Corporation IBM System i Detailed Database Monitor - New 44 i want an i. © 2006 IBM Corporation 22 IBM System i Detailed Database Monitor - New via Run SQL Scripts •A detailed database monitor can be started within Run SQL Scripts 45 i want an i.