Demystifying SQL Tuning: Tips and Techniques for SQL Experts

Similar documents
<Insert Picture Here> DBA Best Practices: A Primer on Managing Oracle Databases

SQL Gone Wild: Taming Bad SQL the Easy Way (or the Hard Way) Sergey Koltakov Product Manager, Database Manageability

This presentation is for informational purposes only and may not be incorporated into a contract or agreement.

Session id: The Self-Managing Database: Guided Application and SQL Tuning

OpenWorld 2018 SQL Tuning Tips for Cloud Administrators

<Insert Picture Here> DBA s New Best Friend: Advanced SQL Tuning Features of Oracle Database 11g

Oracle Database 10g The Self-Managing Database

What is Real Application Testing?

Moving Databases to Oracle Cloud: Performance Best Practices

Copyright 2018, Oracle and/or its affiliates. All rights reserved.

Oracle 1Z0-054 Exam Questions and Answers (PDF) Oracle 1Z0-054 Exam Questions 1Z0-054 BrainDumps

KillTest *KIJGT 3WCNKV[ $GVVGT 5GTXKEG Q&A NZZV ]]] QORRZKYZ IUS =K ULLKX LXKK [VJGZK YKX\OIK LUX UTK _KGX

Oracle Database 11g: Real Application Testing & Manageability Overview

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

Oracle EXAM - 1Z Oracle Database 11g: Performance Tuning. Buy Full Product.

Database Performance Analysis Techniques Using Metric Extensions and SPA

EZY Intellect Pte. Ltd., #1 Changi North Street 1, Singapore

Learning Objectives : This chapter provides an introduction to performance tuning scenarios and its tools.

SQL Tuning for Expert DBAs

Oracle Database 11g: Manageability Overview. An Oracle White Paper August 2007

Oracle Database 12c Performance Management and Tuning

Oracle 1Z Oracle Database 11g Release 2- SQL Tuning. Download Full Version :

Oracle Database 11g: Performance Tuning DBA Release 2

Oracle Database 12c: Performance Management and Tuning

Oracle Database 11g: SQL Tuning Workshop

Oracle Database 11g: Performance Tuning DBA Release 2

Oralogic Education Systems

Oracle Database 11g : Performance Tuning DBA Release2

Configuration changes such as conversion from a single instance to RAC, ASM, etc.

End-to-end Management with Grid Control. John Abrahams Technology Sales Consultant Oracle Nederland B.V.

PERFORMANCE TUNING TRAINING IN BANGALORE

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

Oracle Database 11g: Self-Managing Database - The Next Generation

RAC Performance Monitoring and Diagnosis using Oracle Enterprise Manager. Kai Yu Senior System Engineer Dell Oracle Solutions Engineering

5 Application Tuning CERTIFICATION OBJECTIVES Q&A

Oracle Database 11g: Real Application Testing & Manageability Overview. An Oracle White Paper June 2007

Oracle Database 18c and Autonomous Database

Oracle 1Z0-417 Exam Questions and Answers (PDF) Oracle 1Z0-417 Exam Questions 1Z0-417 BrainDumps

Tuning slow queries after an upgrade

In the Oracle Database 12c: Performance Management and

Oracle 11g Optimizer Statistics Inderpal S. Johal. Inderpal S. Johal, Data Softech Inc.

Manage Change With Confidence: Upgrading to Oracle Database 11g with Oracle Real Application Testing

ORACLE WHITEPAPER ORACLE ENTERPRISE MANAGER 13C CLOUD CONTROL

Performance Problems

1z0-062.exam.215q 1z0-062 Oracle Database 12c: Installation and Administration

Oracle 1Z0-514 Exam Questions and Answers (PDF) Oracle 1Z0-514 Exam Questions 1Z0-514 BrainDumps

1Z Oracle Database Performance and Tuning Essentials 2015 Exam Summary Syllabus Questions

Manually Create Sql Profile Oracle 10g

ORACLE DIAGNOSTICS PACK

Exadata Implementation Strategy

Session 1079: Using Real Application Testing to Successfully Migrate to Exadata - Best Practices and Customer Case Studies

Exadata Implementation Strategy

Oracle Diagnostics Pack For Oracle Database

<Insert Picture Here> Inside the Oracle Database 11g Optimizer Removing the black magic

Oracle 1Z0-053 Exam Questions and Answers (PDF) Oracle 1Z0-053 Exam Questions 1Z0-053 BrainDumps

Katharina Römer Principal Sales Consultant STCC Stuttgart ORACLE Deutschland GmbH

<Insert Picture Here> Managing Oracle Exadata Database Machine with Oracle Enterprise Manager 11g

Oracle. Exam Questions 1Z Oracle Database 11g: Administration I. Version:Demo

Real Application Testing Never Get Caught By Change Again. Michael R. Messina, Management Consultant Rolta-TUSC, NYOUG 2011 (60 min)

Top 7 Plan Stability Pitfalls & How to Avoid Them. Neil Chandler Chandler Systems Ltd UK

Essential (free) Tools for DBA!

Managing Oracle Database 12c with Oracle Enterprise Manager 12c

Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12

Oracle Database 11g: Administration I

Trouble-free Upgrade to Oracle Database 12c with Real Application Testing

Oracle Database 10g: New Features for Administrators Release 2

Using Automatic Workload Repository for Database Tuning: Tips for Expert DBAs. Kurt Engeleiter Product Manager

Oracle 1Z Number: Passing Score: 800 Time Limit: 120 min File Version: 1.0

Oracle Database 11g for Experienced 9i Database Administrators

Oracle 1Z Oracle Database 11g: New Features for Administrators.

Successful Upgrade Secrets: Preventing Performance Problems with Database Replay

Oracle Performance Tuning. Overview of performance tuning strategies

Oracle PL/SQL - 12c & 11g [Basic PL/SQL & Advanced PL/SQL]

Oracle Database. Real Application Testing User s Guide 11g Release 2 (11.2) E

A. The EMPLOYEES table will be changed to read-only mode during the shrink operation

<Insert Picture Here> Oracle Database 11g: Neue Features im Oracle Optimizer

Oracle DBA Course Content

Taming Banner 7 on Oracle 10g

Real Application Testing Certified for SAP

SQL Server 2014 Performance Tuning and Optimization

Expert Oracle Database

Reinventing Upgrades, Platform Changes, RAC and More with Database Replay

Oracle 1Z0-052 Exam Questions and Answers (PDF) Oracle 1Z0-052 Exam Questions 1Z0-052 BrainDumps

Triangle SQL Server User Group Adaptive Query Processing with Azure SQL DB and SQL Server 2017

Oracle Exam 1z0-054 Oracle Database 11g: Performance Tuning Version: 5.0 [ Total Questions: 192 ]

55144 SQL Server 2014 Performance Tuning and Optimization Microsoft Official Curriculum (MOC 55144)

Oracle Database 11g: SQL Fundamentals I

Oracle. 1z Oracle Database 11g- New Features for Administrators.

Oracle. Exam Questions 1Z Oracle Database 11g Release 2: SQL Tuning Exam. Version:Demo

55144-SQL Server 2014 Performance Tuning and Optimization

1 Dulcian, Inc., 2001 All rights reserved. Oracle9i Data Warehouse Review. Agenda

Oracle Database. 2 Day + Performance Tuning Guide 11g Release 2 (11.2) E

Leng Leng Tan Vice President Server Manageability and Diagnosability Oracle Corporation. Arvind Gidwani Kothandapani Subramaniyam

Exam Name: Oracle Database 11g: Performance Tuning

MAXGAUGE for Oracle Web Version 5.3

Oracle SQL Tuning for Developers Workshop Student Guide - Volume I

(10393) Database Performance Tuning Hands-On Lab

Oracle Database 11g: New Features for Administrators Release 2

Key to A Successful Exadata POC

Oracle. Exam Questions 1Z Oracle Database 11g: New Features for 9i OCPs. Version:Demo

Transcription:

Demystifying SQL Tuning: Tips and Techniques for SQL Experts Mughees A. Minhas Director of Product Management, Database and Systems Management Sergey Koltakov Product Manager, Database Manageability

Outline Identifying Problem SQL Identifying Problem with the SQL Manual Automatic Preventing SQL Regressions

Outline Identifying Problem SQL Identifying Problem with the SQL Manual Automatic Preventing SQL Regressions

Top System SQL: ADDM Snapshots in Automatic Workload Repository Automatic Database Diagnostic Monitor (ADDM) Self-Diagnostic Automatic Diagnostic Engine inside Engine DB Provides database-wide performance diagnostic Self-diagnostic engine in the database High-load SQL IO / CPU issues RAC issues Identifies top SQL for the entire system in the last hour Shows SQL impact SQL Advisor System Resource Advice Network + DB config Advice Frequency of occurrence

Identify Top SQL using Top Activity Performance Page Identify Top SQL by Time CPU I/O Wait class Real-time analysis: ASH data Historical analysis: AWR data More granular analysis Top Activity Enables identification of transient problem SQL

Identify Problem SQL using AWR Compare Period Report Enables comparison of Top SQL from one period to another Makes analysis of SQL variations diagnosis easier AWR SQL capture configurable Important to establish baseline period for comparison AWR Baselines Out-of-box Moving Window Baseline

Outline Identifying Problem SQL Identifying Problem with the SQL Manual Automatic Preventing SQL Regressions

Outline Identifying Problem SQL Identifying Problem with the SQL Manual Automatic Preventing SQL Regressions

Causes of Poor SQL Performance Operational Issues Stale optimizer statistics CBO requires up-to-date statistics to optimize SQL execution Not easy to determine when stale statistics are impacting plan selection Poor plan selection due to incorrect optimizer estimates Manually hinting SQL a solution: Requires significant expertise Is time consuming and error-prone trial and error method Does not work for packaged applications

Causes of Poor SQL Performance Application Issues Missing access structures Designing correct partitioning strategy not easy Identifying useful indexes and MVs non-trivial Difficult to assess performance impact of new structures on DMLs Bad SQL design Sometimes the only real remedy is to restructure SQL Requires expertise, time, application knowledge

Identifying Problem with the SQL Manual Real-time SQL Monitoring ASH Report Automatic SQL Tuning Advisor SQL Access Advisor

Identifying Problem with the SQL Manual Real-time SQL Monitoring ASH Report Automatic SQL Tuning Advisor SQL Access Advisor

Real-time SQL Monitoring Shows what s happening inside SQL execution Automatically monitors long running SQL > 5 secs of CPU or I/O All parallel statements Enabled out-of-the-box with no performance impact Monitors each SQL execution Exposes monitoring statistics Global execution level Plan operation level Parallel Execution level Guides tuning efforts

Demo Real-time SQL Monitoring

Identifying SQL Problem: Example 1

Identifying SQL Problem: Example 1

Identifying SQL Problem: Example 1

Identifying SQL Problem Big Plans

Identifying SQL Problem Example 2

Identifying SQL Problem Partially Parallelized

Identifying SQL Problem Example 3

Identifying SQL Problem PQ Skews

ASH Report ASH enables targeted performance analysis Facilitates transient problem diagnosis Helps answers questions like has this SQL gotten slower over time? ASH Report can be filtered by time, SID, SQL ID, Wait Class, Service, Module, Action, Client ID Performance Range * Time

ASH Report: SQL Main Sections

ASH Report: Top Events

ASH Report: Activity Over Time

Identifying Problem with the SQL Manual Real-time SQL Monitoring ASH Report Automatic SQL Tuning Advisor SQL Access Advisor

Identifying Problem with the SQL Manual Real-time SQL Monitoring ASH Report Automatic SQL Tuning Advisor SQL Access Advisor

SQL Tuning Advisor Analysis SQL Tuning Advisor Comprehensive Analysis Recommendation SQL Statistics Analysis Gather Missing or Stale Statistics Access Structure Analysis (Single SQL) SQL Design Analysis Add Missing Indexes (B* Tree) Modify SQL Constructs Plan Tuning (SQL Profiling) Create a SQL Profile

SQL Profiles Contains auxiliary information for a SQL statement Customized optimizer settings: Based on past execution history (e.g., first_rows vs. all_rows) Compensates for missing or stale statistics Compensates for errors in optimizer estimates Doesn t require any change to the SQL text: Ideal for Packaged Apps SQL Profiling SQL Tuning Advisor submit Optimizer (Tuning Mode) create use SQL Profile After Database Users submit Optimizer (Normal Mode) output Well-Tuned Plan

Automatic SQL Tuning Nightly Packaged Apps Custom Apps SQL Tuning Advisor SQL Profiles Automatic implement Well-tuned SQL Auto Capture High-Load SQL SQL Analysis Report Manually implement Automatically captures highload SQL Automatically tunes SQL without changing application by creating SQL Profiles Automatically validates SQL Profiles by test executing them Automatically implements (optional) greatly improved SQL plans Automatically reports analysis Automatically runs during maintenance window

SQL Access Advisor Analysis SQL Access Advisor Comprehensive Analysis Recommendation SQL Add New Indexes (B* Tree, Bitmap) Access Structure Analysis (Workload) Add New MV s, Logs Add New Partitions (Hash, Range)

Resource Consumption SQL Tuning Advisor Limited mode: Resource consumption minimal Stats, index and SQL restructure analysis is cheap Average is less than 1 second per SQL statement Comprehensive mode: Resource consumption may be significant SQL Profiling can potentially consume non-trivial resources Roughly comparable to amount of resources/time consumed when executing SQL statement(s) SQL Access Advisor Resource consumption depends on size of SQL workload For small number of SQL, resource consumption not very high

Live vs. Remote Tuning Live system tuning Run SQL Tuning Advisor in Comprehensive mode Run SQL Tuning Advisor in Limited mode only if System does not have spare resources to tune SQL Run SQL Access Advisor for few SQL at a time Remote tuning Tuning remotely if Cumulative resources/time consumed by all SQL statements being tuned significant System cannot spare resources Use SQL Profile and SQL Tuning Set export/import capabilities

Remote SQL Tuning Performed to shield production system from performance impact of SQL advisors Production System Test System Move SQL Transportable STS Tune SQL Storage Move SQL Profile Transportable SQL Profile

Remote SQL Tuning Use Automatic SQL Capture feature of SQL Tuning Set (STS) to capture SQL Workload Always validate SQL Profiles before enabling them DBMS_SQLTUNE.ACCEPT_SQL_PROFILE (task_name => <tuning task name>, category => MY_CATEGORY ); ALTER SESSION SET SQLTUNE_CATEGORY= MY_CATEGORY ; For remote tuning, ensure test system is similar to production system Schema Data distribution Volume If test system smaller than production, set optimizer stats manually

Outline Identifying Problem SQL Identifying Problem with the SQL Manual Automatic Preventing SQL Regressions

Outline Identifying Problem SQL Identifying Problem with the SQL Manual Automatic Preventing SQL Regressions

Preventing SQL Regressions Gather statistics for all objects (dictionary and user objects) Volatile objects Gathers statistics when object at max size and then lock table Delete all statistics and lock table dynamic sampling will be used Restoring old optimizer statistics Used when new stats result in poor execution plan selection Scope: Table, schema and database History maintained for 30 days API: DBMS_STATS.RESTORE_TABLE_STATS Don't use the ANALYZE command Officially obsolete for optimizer statistics Cannot gather GLOBAL statistics for partitioned objects Cannot gather statistics for external tables, fixed tables, etc. Invalidates/recompiles all dependent cursors at once DBMS_STATS marks cursors as unusable and recompiles gradually

Preventing SQL Regressions Automatic statistics collection job Out-of-the box, runs in maintenance window Configuration can be changed (at table level) Gathers statistics on user and dictionary objects Parameters chosen automatically based on DML monitoring Column usage monitoring Iterative sampling Uses new collection algorithm with accuracy of compute and speed faster than sampling of 1% Incrementally maintains statistics for partitioned tables very efficient

Preventing SQL Regressions Extended Stats Extended Optimizer Statistics provides a mechanism to collect statistics on a group of related columns Full integration into existing statistics framework Automatically maintained with column statistics DBMS_STATS.CREATE_EXTENDED_STATS Pending Stats Allows validation of statistics before publishing Disabled by default To enable, set table/schema PUBLISH setting to FALSE DBMS_STATS.SET_TABLE_PREFS('SH','CUSTOMERS','PUBLISH','false') To use for validation ALTER SESSION SET optimizer_pending_statistics = TRUE; Monitor using view: USER_(TAB/COL/IND)_PENDING_STATS

Validating SQL Performance Validate all changes that impact SQL plans, e.g., statistics refresh Use SQL Performance Analyzer (SPA) to validate statistics refresh 1. Capture SQL workload in STS using automatic cursor cache capture capability 2. Execute SPA pre-change trial 3. Refresh statistics using PENDING option 4. Execute SPA post-change trial 5. Run SPA report comparing SQL execution statistics Before PUBLISHing stats Remediate individual SQL for plan few regressions Revert to old statistics if too many regressions observed SQL Performance Analyzer (SPA) 11.1 Storage Compare SQL Performance Analysis Report Send SQL to execute Send execution stats 10.2 Storage