performance management in oracle 12c
TRANSCRIPT
Performance Management in Oracle 12c
Prepared by:Alfredo KriegSr. Oracle Enterprise Cloud Administrator
@alfredokrieg
Who am I?• Alfredo Krieg ([email protected])
• 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 changeshttp://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_TASK', 'LOCAL_TIME_LIMIT', 1200); DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER('SYS_AUTO_SQL_TUNING_TASK', 'ACCEPT_SQL_PROFILES', 'true'); DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER('SYS_AUTO_SQL_TUNING_TASK', 'MAX_SQL_PROFILES_PER_EXEC', 50); DBMS_SQLTUNE.SET_TUNING_TASK_PARAMETER('SYS_AUTO_SQL_TUNING_TASK', '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 WHERESQL_ID=‘azcb6w2rc2fwk’;SQL_ID PLAN_HASH_VALUE CHILD_NUMBER------------- --------------- ------------azcb6w2rc2fwk 1378164845 3azcb6w2rc2fwk 648432385 4azcb6w2rc2fwk 648432385 2azcb6w2rc2fwk 1378164845 0azcb6w2rc2fwk 1378164845 1azcb6w2rc2fwk 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_profileParameter 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 ProfilesSQL>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.
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!