SlideShare a Scribd company logo
Performance Management in Oracle
12c
Prepared by:
Alfredo Krieg
Sr. Oracle Enterprise Cloud Administrator
@alfredokrieg
Who am I?
• Alfredo Krieg (alfredokrieg@gmail.com)
• Senior Oracle Enterprise Cloud Administrator
• Oracle ACE Associate
• NEOOUG Secretary
• OEM Cloud Control 12c and Database Performance Tuning
• Oracle Technologies since 2004 & 11g Certified
• Blog bitkode.blogspot.com
Disclaimer
The opinions expressed in this presentation are
solely mine, and not that of my employer.
Motivation
• Performance problem (regression) on a critical SQL
statement
• Users claim that this SQL has been in 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
• You have the tools but you don’t know
• Sometimes(?) the problem is reported
at 1 am in the morning or Friday 5 pm
Agenda
• Cost Based Optimizer
• SQL Profiles
- SQL Tuning Advisor
- COE script (custom SQL Profiles)
• Oracle SQL Plan Management
- SPM Framework
- Enable SQL plan baseline capture
- Evolve plans to stabilize performance
- Pack, Load and Unpack baselines
• Oracle Real Time Monitoring
- Usage
- OEM 12c
Cost Based Optimizer
• 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
Cost Based Optimizer
• Cost Based Optimizer CBO
Cost Based Optimizer
• 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
Cost Based Optimizer
• Performance regression
Agenda
• Cost Based Optimizer
• SQL Profiles
- SQL Tuning Advisor
- COE script (custom SQL Profiles)
• Oracle SQL Plan Management
- SPM Framework
- Enable SQL plan baseline capture
- Evolve plans to stabilize performance
- Pack, Load and Unpack baselines
• Oracle Real Time Monitoring
- Usage
- OEM 12c
SQL Profiles
• Is a database object
• Contains auxiliary statistics specific to a SQL statement (not
to a plan)
• One time statistics
• If the SQL Profile changes, new plans are created
• Over time, profile content can be outdated
• It requires Diagnostics and Tuning license!
• Internally, a profile is implemented using hints
– OPT_ESTIMATE(@SEL$1, TABLE, TEST@SEL$1, SCALE_ROWS=30)
– TABLE_STATS(“SCOTT”, “TEST”, scale, blocks=3, rows=30)
– INDEX_STATS(“SCOTT”, “TEST”, “EMP_IDX”, scale, blocks=3,
rows=30)
SQL Profiles
• Can be created using:
– SQL Tuning Advisor
– Manually, to *lock a plan*
• The Oracle COE script
• Provided by SQLT. Support Note Id 215187.1
• coe_xfr_sql_profile.sql (Kerry’s site)
• SQL Profiles apply to the following statement types:
– SELECT statements
– UPDATE statements
– INSERT statements (only with a SELECT clause)
– DELETE statements
– CREATE TABLE statements (only with the AS SELECT clause)
– MERGE statements (the update or insert operations)
SQL Profiles
• SQL Tuning Advisor
SQL Profiles
• SQL Tuning Advisor
SQL Profiles
• SQL Tuning Advisor
SQL Profiles
• SQL Tuning Advisor
SQL Profiles
• SQL Tuning Advisor
• When the Automatic SQL Tuning task is configured to
implement SQL profiles automatically
• Behavior depends on the setting of the ACCEPT_SQL_PROFILE
SQL Profiles
SQL Profiles
• ACCEPT_SQL_PROFILE
– If set to TRUE, then the advisor implements SQL profiles automatically.
– If set to FALSE, then user intervention is required.
– If set to AUTO (default), then the setting is true when at least one SQL
statement exists with a SQL profile, and false when this condition is not
satisfied.
• Settings of Auto task from OEM 12c
SQL Profiles
• Settings of Auto task from command line
COL PARAMETER_NAME FORMAT a25
COL VALUE FORMAT a10
SELECT PARAMETER_NAME, PARAMETER_VALUE AS "VALUE"
FROM DBA_ADVISOR_PARAMETERS
WHERE ( (TASK_NAME = 'SYS_AUTO_SQL_TUNING_TASK') AND
( (PARAMETER_NAME LIKE '%PROFILE%') OR (PARAMETER_NAME =
'LOCAL_TIME_LIMIT') OR (PARAMETER_NAME = 'EXECUTION_DAYS_TO_EXPIRE')
) );
PARAMETER_NAME VALUE
------------------------- ----------
EXECUTION_DAYS_TO_EXPIRE 30
LOCAL_TIME_LIMIT 1000
ACCEPT_SQL_PROFILES FALSE
MAX_SQL_PROFILES_PER_EXEC 20
MAX_AUTO_SQL_PROFILES 10000
SQL Profiles
• Settings of Auto task from command line
BEGIN DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER
( task_name => 'SYS_AUTO_SQL_TUNING_TASK' ,
parameter => parameter_name ,
value => value ); END; /
BEGIN
DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER('SYS_AUTO_SQL_TUNING_TAS
K', 'LOCAL_TIME_LIMIT', 1200);
DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER('SYS_AUTO_SQL_TUNING_TAS
K', 'ACCEPT_SQL_PROFILES', 'true');
DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER('SYS_AUTO_SQL_TUNING_TAS
K', 'MAX_SQL_PROFILES_PER_EXEC', 50);
DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER('SYS_AUTO_SQL_TUNING_TAS
K', 'MAX_AUTO_SQL_PROFILES', 10002); END; /
SQL Profiles
• COE Script
– Identify a plan change in a SQL statement
SELECT SQL_ID, PLAN_HASH_VALUE, CHILD_NUMBER FROM V$SQL WHERE
SQL_ID=‘azcb6w2rc2fwk’;
SQL_ID PLAN_HASH_VALUE CHILD_NUMBER
------------- --------------- ------------
azcb6w2rc2fwk 1378164845 3
azcb6w2rc2fwk 648432385 4
azcb6w2rc2fwk 648432385 2
azcb6w2rc2fwk 1378164845 0
azcb6w2rc2fwk 1378164845 1
azcb6w2rc2fwk 1378164845 5
– Plan 648432385 is the “good” plan but is not longer executed!
SQL Profiles
• Download COE script
– Provided by SQLT. Support Note Id 215187.1
– coe_xfr_sql_profile.sql
$@coe_xfr_sql_profile
Parameter 1:
SQL_ID (required)
Enter value for 1: azcb6w2rc2fwk
PLAN_HASH_VALUE AVG_ET_SECS
--------------- -----------
648432385 .006
1378164845 2.03
Parameter 2:
PLAN_HASH_VALUE (required)
Enter value for 2: 648432385
Values passed:
~~~~~~~~~~~~~
SQL_ID : "azcb6w2rc2fwk"
PLAN_HASH_VALUE: "648432385"
Execute coe_xfr_sql_profile_azcb6w2rc2fwk_648432385.sql
on TARGET system in order to create a custom SQL Profile
with plan 648432385 linked to adjusted sql_text.
SQL Profiles
SQL>DECLARE
2 sql_txt CLOB;
3 h SYS.SQLPROF_ATTR;
4 BEGIN
5 sql_txt := q'[
6 UPDATE TABLE_NAME SET COLUMN_NUMBER = (S... FROM TABLE1..WHERE
7 ... )
8 ]';
9 h := SYS.SQLPROF_ATTR(
10 q'[BEGIN_OUTLINE_DATA]',
11 q'[IGNORE_OPTIM_EMBEDDED_HINTS]',
12 q'[OPTIMIZER_FEATURES_ENABLE('12.1.0.2')]',
13 q'[DB_VERSION('12.1.0.2')]',
14 q'[OPT_PARAM('_b_tree_bitmap_plans' 'false')]',
15 q'[OPT_PARAM('_fast_full_scan_enabled' 'false')]',
16 q'[OPT_PARAM('_optimizer_use_feedback' 'false')]',
17 q'[OPT_PARAM('_px_adaptive_dist_method' 'off')]',
18 q'[OPT_PARAM('_optimizer_dsdir_usage_control' 0)]',
19 q'[OPT_PARAM('_optimizer_adaptive_plans' 'false')]',
20 q'[OPT_PARAM('_optimizer_strans_adaptive_pruning' 'false')]',
21 q'[OPT_PARAM('_optimizer_gather_feedback' 'false')]',
22 q'[OPT_PARAM('_optimizer_nlj_hj_adaptive_join' 'false')]',
23 q'[ALL_ROWS]',
24 q'[FULL(@"SEL$A521A1A9" "TABLE1"@"SEL$2")]',
25 q'[END_OUTLINE_DATA]');
Agenda
• Cost Based Optimizer
• SQL Profiles
- SQL Tuning Advisor
- COE script (custom SQL Profiles)
• Oracle SQL Plan Management
- SPM Framework
- Enable SQL plan baseline capture
- Evolve plans to stabilize performance
- Pack, Load and Unpack baselines
• Oracle Real Time Monitoring
- Usage
- OEM 12c
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 (SMB)
– 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
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.ALTER_SQL_PLAN_BASELINE (11gR1)
• 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.
Performance Management in Oracle 12c
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
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
• 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)
Agenda
• Cost Based Optimizer
• SQL Profiles
- SQL Tuning Advisor
- COE script (custom SQL Profiles)
• Oracle SQL Plan Management
- SPM Framework
- Enable SQL plan baseline capture
- Evolve plans to stabilize performance
- Pack, Load and Unpack baselines
• Oracle Real Time Monitoring
- Usage
- OEM 12c
Oracle Real-Time SQL Monitoring
• Introduced in 11g
• By default, started automatically when a SQL runs in
parallel or has consumed at least 5 seconds of CPU and/or
I/O combined in a single execution
• Can be forced using the hint /*+ MONITOR */
• Requires STATISTICS_LEVEL set to ‘TYPICAL’ or ‘ALL’
• Diagnostic and Tuning license
• 2 System Views
– V$SQL_MONITOR
– V$SQL_PLAN_MONITOR
• 2 Packages
– DBMS_SQLTUNE.report_sql_monitor_list
– DBMS_SQLTUNE.report_sql_detail
Oracle Real-Time SQL Monitoring
• SQL Real-Time Monitor in OEM 12c
Oracle Real-Time SQL Monitoring
• SQL Real-Time Monitor in OEM 12c
Oracle Real-Time SQL Monitoring
• SQL Real-Time Monitor in OEM 12c
Oracle Real-Time SQL Monitoring
• SQL Real-Time Monitor in OEM 12c
Thank You!

More Related Content

PPT
Oracle Architecture
PDF
Backup and recovery in oracle
PDF
Oracle Multitenant meets Oracle RAC - IOUG 2014 Version
PDF
Rman Presentation
PDF
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
PDF
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
PDF
Deep review of LMS process
PPTX
Oracle 12c Architecture
Oracle Architecture
Backup and recovery in oracle
Oracle Multitenant meets Oracle RAC - IOUG 2014 Version
Rman Presentation
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
Deep review of LMS process
Oracle 12c Architecture

What's hot (20)

PDF
Awr + 12c performance tuning
PPTX
Explain the explain_plan
PDF
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
PPTX
PDF
Oracle db performance tuning
PPTX
Introduction to oracle database (basic concepts)
DOCX
Data guard architecture
PPT
Oracle backup and recovery
PDF
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
PPTX
Oracle architecture ppt
PDF
Tanel Poder - Performance stories from Exadata Migrations
PPTX
AWR and ASH Deep Dive
PPTX
Introduction to Oracle Database
PDF
Oracle Performance Tuning Fundamentals
PDF
Oracle 資料庫檔案介紹
PDF
Migration to Oracle Multitenant
PDF
Oracle RAC 12c Overview
PDF
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
PDF
Enterprise manager 13c
PDF
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Awr + 12c performance tuning
Explain the explain_plan
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle db performance tuning
Introduction to oracle database (basic concepts)
Data guard architecture
Oracle backup and recovery
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle architecture ppt
Tanel Poder - Performance stories from Exadata Migrations
AWR and ASH Deep Dive
Introduction to Oracle Database
Oracle Performance Tuning Fundamentals
Oracle 資料庫檔案介紹
Migration to Oracle Multitenant
Oracle RAC 12c Overview
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
Enterprise manager 13c
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Ad

Viewers also liked (13)

PPTX
Componenets of osb12c
PDF
oracle-osb
PDF
oracle service bus
PPT
Oracle PL/SQL - Creative Conditional Compilation
PPTX
Oracle Service Bus 12c (12.2.1) What You Always Wanted to Know
PDF
Oracle Service Bus (OSB) for the Busy IT Professonial
PDF
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
PPT
Less05 asm instance
PDF
Osb student guide
PDF
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
PPTX
Where and when to use the Oracle Service Bus (OSB)
PPTX
SQLcl overview - A new Command Line Interface for Oracle Database
PDF
Oracle OSB Tutorial 1
Componenets of osb12c
oracle-osb
oracle service bus
Oracle PL/SQL - Creative Conditional Compilation
Oracle Service Bus 12c (12.2.1) What You Always Wanted to Know
Oracle Service Bus (OSB) for the Busy IT Professonial
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Less05 asm instance
Osb student guide
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
Where and when to use the Oracle Service Bus (OSB)
SQLcl overview - A new Command Line Interface for Oracle Database
Oracle OSB Tutorial 1
Ad

Similar to Performance Management in Oracle 12c (20)

PDF
Oracle SQL Tuning
PDF
In Search of Plan Stability Part 2 with Karen Morton
PDF
My Experience Using Oracle SQL Plan Baselines 11g/12c
PPT
Oracle SQL Tuning
PPTX
Embarcadero In Search of Plan Stability Part 1 Webinar Slides
PDF
An Approach to Sql tuning - Part 1
PDF
11gR2 Upgrade.pdf
PDF
11gR2 Upgrade.pdf
PPTX
Adapting and adopting spm v04
PDF
Performance Stability, Tips and Tricks and Underscores
PDF
Using SQL Plan Management (SPM) to Balance Plan Flexibility and Plan Stability
PPTX
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
PPTX
Professional sql server dba online training
PPTX
Sql server 2008r2 dba course
PPTX
Sql server 2008r2 dba course
PPTX
Online sql dba training
PDF
Oracle DB 19c: SQL Tuning Using SPM
PPTX
Sql dba 2008 r2 online training
PPTX
Project oriented online realtime training on sql
PPTX
Sql server dba certification
Oracle SQL Tuning
In Search of Plan Stability Part 2 with Karen Morton
My Experience Using Oracle SQL Plan Baselines 11g/12c
Oracle SQL Tuning
Embarcadero In Search of Plan Stability Part 1 Webinar Slides
An Approach to Sql tuning - Part 1
11gR2 Upgrade.pdf
11gR2 Upgrade.pdf
Adapting and adopting spm v04
Performance Stability, Tips and Tricks and Underscores
Using SQL Plan Management (SPM) to Balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Professional sql server dba online training
Sql server 2008r2 dba course
Sql server 2008r2 dba course
Online sql dba training
Oracle DB 19c: SQL Tuning Using SPM
Sql dba 2008 r2 online training
Project oriented online realtime training on sql
Sql server dba certification

More from Alfredo Krieg (11)

PDF
Clone Oracle Databases In Minutes Without Risk Using Enterprise Manager 13c
PDF
Exadata SMART Monitoring - OEM 13c
PDF
Collaborate 2019 - How to Understand an AWR Report
PDF
Simplifying EBS 12.2 ADOP - Collaborate 2019
PPTX
Oracle database 12.2 new features
PPTX
Where did my day go?: Oracle Enterprise Manager 12c/13c Administration
PDF
Monitor Engineered Systems from a Single Pane of Glass: Oracle Enterprise Man...
PPTX
Where did my day go?: OEM 12c Administration #em12c #C15LV @IOUG
PPTX
Oracle SPM 12c. IOUG #C15LV
PDF
Oracle database performance are database users telling me the truth
PDF
553: Oracle Database Performance: Are Database Users Telling Me The Truth?
Clone Oracle Databases In Minutes Without Risk Using Enterprise Manager 13c
Exadata SMART Monitoring - OEM 13c
Collaborate 2019 - How to Understand an AWR Report
Simplifying EBS 12.2 ADOP - Collaborate 2019
Oracle database 12.2 new features
Where did my day go?: Oracle Enterprise Manager 12c/13c Administration
Monitor Engineered Systems from a Single Pane of Glass: Oracle Enterprise Man...
Where did my day go?: OEM 12c Administration #em12c #C15LV @IOUG
Oracle SPM 12c. IOUG #C15LV
Oracle database performance are database users telling me the truth
553: Oracle Database Performance: Are Database Users Telling Me The Truth?

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
KodekX | Application Modernization Development
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Electronic commerce courselecture one. Pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPT
Teaching material agriculture food technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Empathic Computing: Creating Shared Understanding
DOCX
The AUB Centre for AI in Media Proposal.docx
Approach and Philosophy of On baking technology
“AI and Expert System Decision Support & Business Intelligence Systems”
KodekX | Application Modernization Development
20250228 LYD VKU AI Blended-Learning.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Electronic commerce courselecture one. Pdf
MYSQL Presentation for SQL database connectivity
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation_ Review paper, used for researhc scholars
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Teaching material agriculture food technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Unlocking AI with Model Context Protocol (MCP)
Review of recent advances in non-invasive hemoglobin estimation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Network Security Unit 5.pdf for BCA BBA.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Empathic Computing: Creating Shared Understanding
The AUB Centre for AI in Media Proposal.docx

Performance Management in Oracle 12c

  • 1. Performance Management in Oracle 12c Prepared by: Alfredo Krieg Sr. Oracle Enterprise Cloud Administrator @alfredokrieg
  • 2. Who am I? • Alfredo Krieg (alfredokrieg@gmail.com) • Senior Oracle Enterprise Cloud Administrator • Oracle ACE Associate • NEOOUG Secretary • OEM Cloud Control 12c and Database Performance Tuning • Oracle Technologies since 2004 & 11g Certified • Blog bitkode.blogspot.com
  • 3. Disclaimer The opinions expressed in this presentation are solely mine, and not that of my employer.
  • 4. Motivation • Performance problem (regression) on a critical SQL statement • Users claim that this SQL has been in 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 • You have the tools but you don’t know • Sometimes(?) the problem is reported at 1 am in the morning or Friday 5 pm
  • 5. Agenda • Cost Based Optimizer • SQL Profiles - SQL Tuning Advisor - COE script (custom SQL Profiles) • Oracle SQL Plan Management - SPM Framework - Enable SQL plan baseline capture - Evolve plans to stabilize performance - Pack, Load and Unpack baselines • Oracle Real Time Monitoring - Usage - OEM 12c
  • 6. Cost Based Optimizer • 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
  • 7. Cost Based Optimizer • Cost Based Optimizer CBO
  • 8. Cost Based Optimizer • 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
  • 9. Cost Based Optimizer • Performance regression
  • 10. Agenda • Cost Based Optimizer • SQL Profiles - SQL Tuning Advisor - COE script (custom SQL Profiles) • Oracle SQL Plan Management - SPM Framework - Enable SQL plan baseline capture - Evolve plans to stabilize performance - Pack, Load and Unpack baselines • Oracle Real Time Monitoring - Usage - OEM 12c
  • 11. SQL Profiles • Is a database object • Contains auxiliary statistics specific to a SQL statement (not to a plan) • One time statistics • If the SQL Profile changes, new plans are created • Over time, profile content can be outdated • It requires Diagnostics and Tuning license! • Internally, a profile is implemented using hints – OPT_ESTIMATE(@SEL$1, TABLE, TEST@SEL$1, SCALE_ROWS=30) – TABLE_STATS(“SCOTT”, “TEST”, scale, blocks=3, rows=30) – INDEX_STATS(“SCOTT”, “TEST”, “EMP_IDX”, scale, blocks=3, rows=30)
  • 12. SQL Profiles • Can be created using: – SQL Tuning Advisor – Manually, to *lock a plan* • The Oracle COE script • Provided by SQLT. Support Note Id 215187.1 • coe_xfr_sql_profile.sql (Kerry’s site) • SQL Profiles apply to the following statement types: – SELECT statements – UPDATE statements – INSERT statements (only with a SELECT clause) – DELETE statements – CREATE TABLE statements (only with the AS SELECT clause) – MERGE statements (the update or insert operations)
  • 13. SQL Profiles • SQL Tuning Advisor
  • 14. SQL Profiles • SQL Tuning Advisor
  • 15. SQL Profiles • SQL Tuning Advisor
  • 16. SQL Profiles • SQL Tuning Advisor
  • 17. SQL Profiles • SQL Tuning Advisor • When the Automatic SQL Tuning task is configured to implement SQL profiles automatically • Behavior depends on the setting of the ACCEPT_SQL_PROFILE
  • 19. SQL Profiles • ACCEPT_SQL_PROFILE – If set to TRUE, then the advisor implements SQL profiles automatically. – If set to FALSE, then user intervention is required. – If set to AUTO (default), then the setting is true when at least one SQL statement exists with a SQL profile, and false when this condition is not satisfied. • Settings of Auto task from OEM 12c
  • 20. SQL Profiles • Settings of Auto task from command line COL PARAMETER_NAME FORMAT a25 COL VALUE FORMAT a10 SELECT PARAMETER_NAME, PARAMETER_VALUE AS "VALUE" FROM DBA_ADVISOR_PARAMETERS WHERE ( (TASK_NAME = 'SYS_AUTO_SQL_TUNING_TASK') AND ( (PARAMETER_NAME LIKE '%PROFILE%') OR (PARAMETER_NAME = 'LOCAL_TIME_LIMIT') OR (PARAMETER_NAME = 'EXECUTION_DAYS_TO_EXPIRE') ) ); PARAMETER_NAME VALUE ------------------------- ---------- EXECUTION_DAYS_TO_EXPIRE 30 LOCAL_TIME_LIMIT 1000 ACCEPT_SQL_PROFILES FALSE MAX_SQL_PROFILES_PER_EXEC 20 MAX_AUTO_SQL_PROFILES 10000
  • 21. SQL Profiles • Settings of Auto task from command line BEGIN DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER ( task_name => 'SYS_AUTO_SQL_TUNING_TASK' , parameter => parameter_name , value => value ); END; / BEGIN DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER('SYS_AUTO_SQL_TUNING_TAS K', 'LOCAL_TIME_LIMIT', 1200); DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER('SYS_AUTO_SQL_TUNING_TAS K', 'ACCEPT_SQL_PROFILES', 'true'); DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER('SYS_AUTO_SQL_TUNING_TAS K', 'MAX_SQL_PROFILES_PER_EXEC', 50); DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER('SYS_AUTO_SQL_TUNING_TAS K', 'MAX_AUTO_SQL_PROFILES', 10002); END; /
  • 22. SQL Profiles • COE Script – Identify a plan change in a SQL statement SELECT SQL_ID, PLAN_HASH_VALUE, CHILD_NUMBER FROM V$SQL WHERE SQL_ID=‘azcb6w2rc2fwk’; SQL_ID PLAN_HASH_VALUE CHILD_NUMBER ------------- --------------- ------------ azcb6w2rc2fwk 1378164845 3 azcb6w2rc2fwk 648432385 4 azcb6w2rc2fwk 648432385 2 azcb6w2rc2fwk 1378164845 0 azcb6w2rc2fwk 1378164845 1 azcb6w2rc2fwk 1378164845 5 – Plan 648432385 is the “good” plan but is not longer executed!
  • 23. SQL Profiles • Download COE script – Provided by SQLT. Support Note Id 215187.1 – coe_xfr_sql_profile.sql $@coe_xfr_sql_profile Parameter 1: SQL_ID (required) Enter value for 1: azcb6w2rc2fwk PLAN_HASH_VALUE AVG_ET_SECS --------------- ----------- 648432385 .006 1378164845 2.03 Parameter 2: PLAN_HASH_VALUE (required) Enter value for 2: 648432385 Values passed: ~~~~~~~~~~~~~ SQL_ID : "azcb6w2rc2fwk" PLAN_HASH_VALUE: "648432385" Execute coe_xfr_sql_profile_azcb6w2rc2fwk_648432385.sql on TARGET system in order to create a custom SQL Profile with plan 648432385 linked to adjusted sql_text.
  • 24. SQL Profiles SQL>DECLARE 2 sql_txt CLOB; 3 h SYS.SQLPROF_ATTR; 4 BEGIN 5 sql_txt := q'[ 6 UPDATE TABLE_NAME SET COLUMN_NUMBER = (S... FROM TABLE1..WHERE 7 ... ) 8 ]'; 9 h := SYS.SQLPROF_ATTR( 10 q'[BEGIN_OUTLINE_DATA]', 11 q'[IGNORE_OPTIM_EMBEDDED_HINTS]', 12 q'[OPTIMIZER_FEATURES_ENABLE('12.1.0.2')]', 13 q'[DB_VERSION('12.1.0.2')]', 14 q'[OPT_PARAM('_b_tree_bitmap_plans' 'false')]', 15 q'[OPT_PARAM('_fast_full_scan_enabled' 'false')]', 16 q'[OPT_PARAM('_optimizer_use_feedback' 'false')]', 17 q'[OPT_PARAM('_px_adaptive_dist_method' 'off')]', 18 q'[OPT_PARAM('_optimizer_dsdir_usage_control' 0)]', 19 q'[OPT_PARAM('_optimizer_adaptive_plans' 'false')]', 20 q'[OPT_PARAM('_optimizer_strans_adaptive_pruning' 'false')]', 21 q'[OPT_PARAM('_optimizer_gather_feedback' 'false')]', 22 q'[OPT_PARAM('_optimizer_nlj_hj_adaptive_join' 'false')]', 23 q'[ALL_ROWS]', 24 q'[FULL(@"SEL$A521A1A9" "TABLE1"@"SEL$2")]', 25 q'[END_OUTLINE_DATA]');
  • 25. Agenda • Cost Based Optimizer • SQL Profiles - SQL Tuning Advisor - COE script (custom SQL Profiles) • Oracle SQL Plan Management - SPM Framework - Enable SQL plan baseline capture - Evolve plans to stabilize performance - Pack, Load and Unpack baselines • Oracle Real Time Monitoring - Usage - OEM 12c
  • 26. 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
  • 27. 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 (SMB) – Set of database objects that store Plan History, SQL Plan Baseline and SQL Profiles
  • 28. SPM Framework • SQL Plan Management Views – DBA_SQL_PLAN_BASELINES & V$SQL
  • 29. 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
  • 30. 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
  • 31. 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
  • 32. Setup SPM – Plan Capture • Automatic Plan Capture – OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES = TRUE – More than one SQL execution
  • 33. 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
  • 34. Setup SPM – Plan Capture • Manual Plan Capture
  • 35. Setup SPM – Plan Capture • Manual Plan Capture
  • 36. Setup SPM – Plan Capture • Manual Plan Capture
  • 37. Setup SPM – Plan Selection • OPTIMIZER_USE_SQL_PLAN_BASELINES=TRUE (Default)
  • 38. 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.ALTER_SQL_PLAN_BASELINE (11gR1) • 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
  • 39. 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.
  • 40. Setup SPM – Plan Evolution • Manual Plan Evolution – 11gR1
  • 41. Setup SPM – Plan Evolution • Manual Plan Evolution – Display execution plans for a baseline – Parameters: • sql_handle => • plan_name => • format => ‘BASIC’, ‘TYPICAL’ & ‘ALL’
  • 42. Setup SPM – Plan Evolution
  • 43. Setup SPM – Plan Evolution • Manual Plan Evolution – 11gR2
  • 44. 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.
  • 46. Setup SPM – Plan Evolution • Manual Plan Evolution – 12c – Create evolve task – Execute evolve task
  • 47. Setup SPM – Plan Evolution • Manual Plan Evolution – Generate report – Manual execution of SPM EVOLVE ADVISOR does NOT accept any SQL plan baseline!!
  • 48. 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)
  • 49. Setup SPM – Plan Evolution • Reject Plans – 11gR1
  • 50. Setup SPM – Plan Evolution • Reject Plans – 11gR2 & 12c
  • 51. 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.
  • 53. 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
  • 54. 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
  • 55. 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
  • 56. 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)
  • 57. Agenda • Cost Based Optimizer • SQL Profiles - SQL Tuning Advisor - COE script (custom SQL Profiles) • Oracle SQL Plan Management - SPM Framework - Enable SQL plan baseline capture - Evolve plans to stabilize performance - Pack, Load and Unpack baselines • Oracle Real Time Monitoring - Usage - OEM 12c
  • 58. Oracle Real-Time SQL Monitoring • Introduced in 11g • By default, started automatically when a SQL runs in parallel or has consumed at least 5 seconds of CPU and/or I/O combined in a single execution • Can be forced using the hint /*+ MONITOR */ • Requires STATISTICS_LEVEL set to ‘TYPICAL’ or ‘ALL’ • Diagnostic and Tuning license • 2 System Views – V$SQL_MONITOR – V$SQL_PLAN_MONITOR • 2 Packages – DBMS_SQLTUNE.report_sql_monitor_list – DBMS_SQLTUNE.report_sql_detail
  • 59. Oracle Real-Time SQL Monitoring • SQL Real-Time Monitor in OEM 12c
  • 60. Oracle Real-Time SQL Monitoring • SQL Real-Time Monitor in OEM 12c
  • 61. Oracle Real-Time SQL Monitoring • SQL Real-Time Monitor in OEM 12c
  • 62. Oracle Real-Time SQL Monitoring • SQL Real-Time Monitor in OEM 12c