Oracle SPM 12c. IOUG #C15LV
-
Upload
alfredokrieg -
Category
Presentations & Public Speaking
-
view
185 -
download
3
Transcript of 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
Stabilize Your Plans with SQL Plan Management Including 12c
SPM 12c
Last session!!
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
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
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
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
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
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
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
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?
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
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
SPM Framework
■ SQL Plan Management Views
▪ DBA_SQL_PLAN_BASELINES & V$SQL
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
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
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
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
Setup SPM – Plan Capture
■ Automatic Plan Capture
▪ OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES = TRUE
▪ More than one SQL execution
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
Setup SPM – Plan Capture
■ Manual Plan Capture
Setup SPM – Plan Capture
■ Manual Plan Capture
Setup SPM – Plan Capture
■ Manual Plan Capture
Setup SPM – Plan Selection
■ OPTIMIZER_USE_SQL_PLAN_BASELINES=TRUE (Default)
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
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.
Setup SPM – Plan Evolution
■ Manual Plan Evolution
▪ 11gR1
Setup SPM – Plan Evolution
■ Manual Plan Evolution
▪ Display execution plans for a baseline
▪ Parameters:
— sql_handle =>
— plan_name =>
— format => ‘BASIC’, ‘TYPICAL’ & ‘ALL’
Setup SPM – Plan Evolution
Setup SPM – Plan Evolution
■ Manual Plan Evolution
▪ 11gR2
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.
Setup SPM – Plan Evolution
■ Manual Plan Evolution
▪ 12c
▪ Create evolve task
▪ Execute evolve task
Setup SPM – Plan Evolution
■ Manual Plan Evolution
▪ Generate report
▪ Manual execution of SPM EVOLVE ADVISOR does NOT
accept any sql plan baseline!!
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)
Setup SPM – Plan Evolution
■ Reject Plans
▪ 11gR1
Setup SPM – Plan Evolution
■ Reject Plans
▪ 11gR2 & 12c
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.
Setup SPM
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
Easy SPM Use With OEM 12c
Easy SPM Use With OEM 12c
Easy SPM Use With OEM 12c
Easy SPM Use With OEM 12c
Easy SPM Use With OEM 12c
Easy SPM Use With OEM 12c
Easy SPM Use With OEM 12c
Easy SPM Use With OEM 12c
Easy SPM Use With OEM 12c
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
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
SPM Administration
■ SPM Trace Doc ID 789520.1
Open an SR with Oracle Support and provide the trace file
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
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
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
SPM Administration
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)
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
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