Oracle SPM 12c. IOUG #C15LV

59
REMINDER Check in on the COLLABORATE mobile app Stabilize Your Plans with SQL Plan Management Including 12c Prepared by: Alfredo Krieg Sr. Oracle Cloud Administrator The Sherwin-Williams Company Session ID#: 231 @alfredokrieg

Transcript of Oracle SPM 12c. IOUG #C15LV

Page 1: Oracle SPM 12c. IOUG #C15LV

REMINDER

Check in on the

COLLABORATE mobile app

Stabilize Your Plans with SQL Plan Management Including 12c

Prepared by:

Alfredo Krieg

Sr. Oracle Cloud Administrator

The Sherwin-Williams Company

Session ID#: 231

@alfredokrieg

Page 2: Oracle SPM 12c. IOUG #C15LV

Stabilize Your Plans with SQL Plan Management Including 12c

SPM 12c

Page 3: Oracle SPM 12c. IOUG #C15LV

Last session!!

Page 4: Oracle SPM 12c. IOUG #C15LV

Who am I?

■ Alfredo Krieg ([email protected])

■ Senior Oracle Enterprise Cloud Administrator at The Sherwin-Williams Company based in Cleveland, OH

■ Oracle ACE Associate

■ OEM Cloud Control 12c and Database Performance Tuning

■ Oracle Technologies since 2004 & 11g Certified

■ Blog bitkode.blogspot.com

Page 5: Oracle SPM 12c. IOUG #C15LV

The Sherwin-Williams Company

■ Largest Producer of Paint & Coatings in US, among Top 3 worldwide

■ Founded in 1866 in Cleveland, OH

■ 2016 is 150th Anniversary

■ 2013 - $10.19 billion in sales

■ Business in 120+ Countries

■ 34,000+ employees

■ 4,000+ Company Owned Stores

■ 90+ Manufacturing Facilities Globally

Page 6: Oracle SPM 12c. IOUG #C15LV

The Sherwin-Williams Company

The Sherwin-Williams Company was founded by

Henry Sherwin and Edward Williams in 1866.

Today, we are global leader in the manufacture,

development, distribution and sale of coatings and related

products to professional, industrial, commercial and retail

customers.

The Company manufactures products under well-known brands such as

Sherwin-Williams®, Dutch Boy®, Krylon®, Minwax®, Thompson’s®

Water Seal® and many more. With global headquarters in Cleveland,

Ohio, Sherwin-Williams® branded products are sold exclusively through

more than 4,000 company-operated stores and facilities, while the

Company’s other brands are sold through leading mass merchandisers,

home centers, hardware stores, automotive retailers and industrial

distributors.

www.sherwin-williams.com

Page 7: Oracle SPM 12c. IOUG #C15LV

Motivation

■ Performance problem on a critical SQL statement

■ Users claim that this SQL has been place for a long period of time

■ Developers claim they haven’t made any changes to the SQL

■ You are responsible of making that SQL run with acceptable

performance

■ Sometimes(?) the problem is reported at 1 am in the morning or

Friday 5 pm

Page 8: Oracle SPM 12c. IOUG #C15LV

Agenda

■ SPM Framework

- How the SPM framework works

- Plan flexibility VS Plan stability

■ Setup SPM

- Enable SQL plan baseline capture

- Evolve plans to stabilize performance

- Pack, Load and Unpack baselines

■ Easy SPM Use With OEM 12c

- Use OEM 12c Cloud Control to easy the use of SPM

■ SPM Advanced Administration

- SPM trace

Page 9: Oracle SPM 12c. IOUG #C15LV

SPM Framework

■ Cost Based Optimizer CBO (since Oracle 7)

▪ Determines the most efficient way to execute a SQL statement

after considering:

— Parameters

— Statistics

— Others (Hints, Outlines, Index Selectivity, etc.)

▪ Produces an optimal execution plan most of the times

▪ Setup CBO to where most SQL plans are optimal

▪ We want the CBO to be flexible enough to produce optimal

plans as needed

Page 10: Oracle SPM 12c. IOUG #C15LV

SPM Framework

■ Plan Flexibility Vs Plan Stability

▪ Flexibility

— Goal is to allow the CBO to produce plans

(optimal/suboptimal)

— CBO Statistics and Histograms, Parameters, Bind Peeking,

Cardinality Feedback CFB, Adaptive Cursor Sharing, SQL

profiles STA

— Expect execution plan changes

http://bitkode.blogspot.com/2013/05/why-execution-plan-changed-

case-study.html

▪ Stability

— Goal is to allow only optimal plans to be executed

— Outlines, Hints, SQL Plan Management, Custom SQL

profiles SQLT

Page 11: Oracle SPM 12c. IOUG #C15LV

SPM Framework

EMPLOYEE

CREATE INDEX STATE_ID_IDX ON EMPLOYEE (STATE_ID);

VARIABLE A NUMBER;

EXEC :A := 5;

SELECT NAME FROM EMPLOYEE WHERE STATE_ID = :A;

EXEC :A := 1;

SELECT NAME FROM EMPLOYEE WHERE STATE_ID = :A;

INDEX SCAN?

FULL TABLE SCAN?

Page 12: Oracle SPM 12c. IOUG #C15LV

SPM Framework

■ SQL Plan Management

▪ New feature in 11g+ for plan stability and control

▪ Only selected plans (Accepted and Enabled) are executed

▪ New plans are captured and stored but not executed (default)

■ SQL Plan Control Flags

▪ Enabled (YES/NO)

— Either alive or deleted

▪ Accepted (YES/NO)

— If Enabled and Accepted will be executed; if not Accepted

can be Evolved

▪ Fixed (YES/NO) “only if accepted and enabled”

— Plans have priority over Accepted plans and are not

expected to change

Page 13: Oracle SPM 12c. IOUG #C15LV

SPM Framework

■ SQL Plan Baseline

▪ Group/Set of Accepted plans

■ Plan History

▪ Group/Set of Accepted and not-Accepted plans

■ Plan Evolution

▪ Process of making Enabled plans Accepted

■ SQL Management Base

▪ Set of database objects that store Plan History, SQL Plan

Baseline and SQL Profiles

Page 14: Oracle SPM 12c. IOUG #C15LV

SPM Framework

■ SQL Plan Management Views

▪ DBA_SQL_PLAN_BASELINES & V$SQL

Page 15: Oracle SPM 12c. IOUG #C15LV

SPM Framework

■ Signature

▪ Unique SQL identifier (hash) from the normalized SQL text

(uncased and whitespaces removed)

— DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE

■ SQL Plan Status Flags

▪ Reproduced (YES/NO)

— CBO can or cannot reproduce the plan

▪ Autopurge (YES/NO)

— If YES the plan will be purged if not used, NO never purged

▪ Rejected (YES/NO)

— Plan was Unaccepted (Accepted = NO) & has

LAST_VERIFIED date or ENABLED=NO

Page 16: Oracle SPM 12c. IOUG #C15LV

SPM Framework

■ SQL Plan Management Initialization Parameters

▪ OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES

— FALSE by default. Controls the automatic creation of SQL

plan baselines

▪ OPTIMIZER_USE_SQL_PLAN_BASELINES

— TRUE by default. Controls the use of SQL plan baselines

Page 17: Oracle SPM 12c. IOUG #C15LV

SPM Framework

■ SQL Plan Management has three main components

▪ Plan Capture

— Automatic Plan Capture

— Manual Plan Capture

▪ Plan Selection

▪ Plan Evolution

— Automatic Plan Evolution

— Manual Plan Evolution

Page 18: Oracle SPM 12c. IOUG #C15LV

Agenda

■ SPM Framework

- How the SPM framework works

- Plan flexibility VS Plan stability

■ Setup SPM

- Enable SQL plan baseline capture

- Evolve plans to stabilize performance

- Pack, Load and Unpack baselines

■ Easy SPM Use With OEM 12c

- Use OEM 12c Cloud Control to easy the use of SPM

■ SPM Advanced Administration

- SPM trace

Page 19: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Capture

■ Automatic Plan Capture

▪ OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES = TRUE

▪ More than one SQL execution

Page 20: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Capture

■ Manual Plan Capture

▪ Most common method to capture plans

▪ PL/SQL package DBMS_SPM or Enterprise Manager 12c

▪ Four different sources

— Cursor Cache

— SQL Tuning Set

— Stored Outlines

— Another DB System

▪ Loaded plans are automatically Accepted

Page 21: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Capture

■ Manual Plan Capture

Page 22: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Capture

■ Manual Plan Capture

Page 23: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Capture

■ Manual Plan Capture

Page 24: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Selection

■ OPTIMIZER_USE_SQL_PLAN_BASELINES=TRUE (Default)

Page 25: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Evolution

■ Accept or reject plans

▪ Automatic Plan Evolution

— SQL Tuning Advisor task (11g)

— SPM Evolve Advisor (SYS_AUTO_SPM_EVOLVE_TASK)

(12c)

▪ Manual Plan Evolution

— DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE function

(11gR2)

— SPM Evolve Advisor API (12c)

• DBMS_SPM.CREATE_EVOLVE_TASK

• DBMS_SPM.EXECUTE_EVOLVE_TASK

• DBMS_SPM.REPORT_EVOLVE_TASK

• DBMS_SPM.ACCEPT_SQL_PLAN_BASELINE

Page 26: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Evolution

■ Adaptive SQL Plan Management – Automatic Plan Evolution (12c)

▪ Enabled by default

▪ When automatic SQL tuning is in COMPREHENSIVE mode, it

runs a verification or evolve process for all SQL statements that

have non-accepted plans during the nightly maintenance

window.

▪ If the non-accepted plan performs better (1.5x default) than the

existing accepted plan (or plans) in the SQL plan baseline, then

the plan is automatically accepted and becomes usable by the

optimizer.

▪ After the task is complete, a persistent report is generated

detailing how the non-accepted plan performs compared to the

accepted plan performance.

Page 27: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Evolution

■ Manual Plan Evolution

▪ 11gR1

Page 28: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Evolution

■ Manual Plan Evolution

▪ Display execution plans for a baseline

▪ Parameters:

— sql_handle =>

— plan_name =>

— format => ‘BASIC’, ‘TYPICAL’ & ‘ALL’

Page 29: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Evolution

Page 30: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Evolution

■ Manual Plan Evolution

▪ 11gR2

Page 31: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Evolution

■ Manual Plan Evolution

▪ 11gR2

▪ VERIFY (YES/NO) compare the performance before changing

non-accepted plans into accepted plans

— When set to 'YES', the non-accepted plan(s) will be accepted

if verified to give better performance

— When set to 'NO', the non-accepted plan(s) will be changed

to accepted plan(s). (11gR1 like)

▪ COMMIT (YES/NO)

— When set to 'YES', baseline will be updated to ACCEPTED

status and a report will be generated

— When set to 'NO', a report will be generated without actually

changing the status of the baseline(s) to ACCEPTED.

Page 32: Oracle SPM 12c. IOUG #C15LV
Page 33: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Evolution

■ Manual Plan Evolution

▪ 12c

▪ Create evolve task

▪ Execute evolve task

Page 34: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Evolution

■ Manual Plan Evolution

▪ Generate report

▪ Manual execution of SPM EVOLVE ADVISOR does NOT

accept any sql plan baseline!!

Page 35: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Evolution

■ Manual Plan Evolution

▪ Accept the plan baseline recommended by the advisor

▪ If you try to accept the plan baseline which is NOT

recommended by SPM EVOLVE ADVISOR, it will fail

with ORA-38149.

▪ You can accept the plan baseline which is NOT recommended

by SPM EVOLVE ADVISOR, by setting force to TRUE.

▪ How to Manually Evolve and Accept SQL PLAN BASELINES in

Oracle 12c (Doc ID 1939828.1)

Page 36: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Evolution

■ Reject Plans

▪ 11gR1

Page 37: Oracle SPM 12c. IOUG #C15LV

Setup SPM – Plan Evolution

■ Reject Plans

▪ 11gR2 & 12c

Page 38: Oracle SPM 12c. IOUG #C15LV

Setup SPM

■ Pack, Load and Unpack baselines

▪ 1. On the original system, create a staging table using the

DBMS_SPM.CREATE_STGTAB_BASELINE procedure

▪ 2. Pack the SQL plan baselines you want to export from the

SQL management base into the staging table using the

DBMS_SPM.PACK_STGTAB_BASELINE function.

▪ 3. Export the staging table into a flat file using the export

command or Oracle Data Pump.

▪ 4. Transfer this flat file to the target system.

▪ 5. Import the staging table from the flat file using the import

command or Oracle Data Pump.

▪ 6. Unpack the SQL plan baselines from the staging table into

the SQL management base on the target system using the

DBMS_SPM.UNPACK_STGTAB_BASELINE function.

Page 39: Oracle SPM 12c. IOUG #C15LV

Setup SPM

Page 40: Oracle SPM 12c. IOUG #C15LV

Agenda

■ SPM Framework

- How the SPM framework works

- Plan flexibility VS Plan stability

■ Setup SPM

- Enable SQL plan baseline capture

- Evolve plans to stabilize performance

- Pack, Load and Unpack baselines

■ Easy SPM Use With OEM 12c

- Use OEM 12c Cloud Control to easy the use of SPM

■ SPM Advanced Administration

- SPM trace

Page 41: Oracle SPM 12c. IOUG #C15LV

Easy SPM Use With OEM 12c

Page 42: Oracle SPM 12c. IOUG #C15LV

Easy SPM Use With OEM 12c

Page 43: Oracle SPM 12c. IOUG #C15LV

Easy SPM Use With OEM 12c

Page 44: Oracle SPM 12c. IOUG #C15LV

Easy SPM Use With OEM 12c

Page 45: Oracle SPM 12c. IOUG #C15LV

Easy SPM Use With OEM 12c

Page 46: Oracle SPM 12c. IOUG #C15LV

Easy SPM Use With OEM 12c

Page 47: Oracle SPM 12c. IOUG #C15LV

Easy SPM Use With OEM 12c

Page 48: Oracle SPM 12c. IOUG #C15LV

Easy SPM Use With OEM 12c

Page 49: Oracle SPM 12c. IOUG #C15LV

Easy SPM Use With OEM 12c

Page 50: Oracle SPM 12c. IOUG #C15LV

Agenda

■ SPM Framework

- How the SPM framework works

- Plan flexibility VS Plan stability

■ Setup SPM

- Enable SQL plan baseline capture

- Evolve plans to stabilize performance

- Pack, Load and Unpack baselines

■ Easy SPM Use With OEM 12c

- Use OEM 12c Cloud Control to easy the use of SPM

■ SPM Advanced Administration

- SPM trace

Page 51: Oracle SPM 12c. IOUG #C15LV

SPM Administration

■ SPM Trace Doc ID 789520.1

▪ Issues where the baseline is expected to reproduce a specific

plan, but does not work as expected

▪ Issues with the creation or manipulation of baselines

▪ SRDC - How to Collect Standard Information for an Issue

Where a SQL Plan Management (SPM) Baseline is Not Used

(Doc ID 1644732.1)

ENABLE

DISABLE

Page 52: Oracle SPM 12c. IOUG #C15LV

SPM Administration

■ SPM Trace Doc ID 789520.1

Open an SR with Oracle Support and provide the trace file

Page 53: Oracle SPM 12c. IOUG #C15LV

SPM Administration

■ SPM Plan Retention

▪ Weekly scheduled task that runs as an automated task in the

maintenance window

▪ Purges plans that have not been used for longer than the plan

retention period

▪ Default retention is 53 weeks and can be setup from 5 to 523

weeks

Page 54: Oracle SPM 12c. IOUG #C15LV

SPM Administration

■ Manage SBM space limit

▪ Weekly background process measures the total space

occupied by the SMB in the SYSAUX tablespace, default 10%

▪ Process writes a warning message to the alert log

▪ Fix by increase SBM space limit, increase SYSAUX size or

purge baselines

Page 55: Oracle SPM 12c. IOUG #C15LV

SPM Administration

■ Licensing

▪ SPM is available as part of Oracle Database Enterprise Edition

▪ Includes any of the DBMS_SPM procedures

■ But, below features require the Tuning Pack

▪ Automatic Plan Evolution for SQL Plan Management STA

▪ Load plans from SQL Tuning Sets into SPM, STS can only be

created if you have Tuning pack or RAT pack

■ Maria Colgan’s Blog

https://blogs.oracle.com/optimizer/entry/does_the_use_of_sql

Page 56: Oracle SPM 12c. IOUG #C15LV

SPM Administration

Page 57: Oracle SPM 12c. IOUG #C15LV

SPM Administration

■ Acceptance threshold in the evolve process

▪ Controlled by hidden parameter

▪ How to Evolve a SQL Plan Baseline and Adjust the

Acceptance Threshold (Doc ID 1617790.1)

Page 58: Oracle SPM 12c. IOUG #C15LV

More?

■ Where to Find Information About Performance Related Features

(Doc ID 1361401.1)

■ Database SQL Tuning Guide

https://docs.oracle.com/database/121/TGSQL/tgsql_spm.htm#TG

SQL94621

■ SQL Plan Management 11g

http://www.oracle.com/technetwork/database/bi-

datawarehousing/twp-sql-plan-management-11gr2-133099.pdf

■ SQL Plan Management 12c

http://www.oracle.com/technetwork/database/bi-

datawarehousing/twp-sql-plan-mgmt-12c-1963237.pdf

Page 59: Oracle SPM 12c. IOUG #C15LV

Please complete the session evaluationWe appreciate your feedback and insight

You may complete the session evaluation either

on paper or online via the mobile app