Skip to main content

Create SQL Plan Baselines for High Resource Intensive SQL's from AWR - 12C


=> Identify SNAP ID's for the interval

Here I am collecting resource intensive SQL's ran on a week from Monday (12-SEP-22) to Friday (16-SEP-22)


SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 SITPDB                         READ WRITE NO

SQL> alter session set container=SITPDB;

Session altered.

SQL>
SQL>
SQL> select min(snap_id) from dba_hist_snapshot where trunc(begin_interval_time)='12-SEP-22';

MIN(SNAP_ID)
------------
        3324

SQL> select max(snap_id) from dba_hist_snapshot where trunc(begin_interval_time)='16-SEP-22';

MAX(SNAP_ID)
------------
        3439

SQL> select user from v$database;

USER
------------------------------
SYS
SQL>


=> Create an AWR Baseline


BEGIN
 DBMS_WORKLOAD_REPOSITORY.create_baseline (
 start_snap_id => 3324,
 end_snap_id => 3439,
 baseline_name => 'weekly_baseline_sep_12_16');
END;
/

PL/SQL procedure successfully completed.
SQL>


=> Create a SQL Tuning Set Object


BEGIN
 dbms_sqltune.create_sqlset(
 sqlset_name => 'weekly_awr_dev1'
 ,description => 'STS from AWR');
END;
/

PL/SQL procedure successfully completed.
SQL>


=> Populate the SQL Tuning Set with High-Resource Queries Found in AWR Baseline

Here I am populating top 20 SQL's based on elapsed_time


DECLARE
 base_cur dbms_sqltune.sqlset_cursor;
BEGIN
 OPEN base_cur FOR
 SELECT value(x)
 FROM table(dbms_sqltune.select_workload_repository(
 'weekly_baseline_sep_12_16', null, null,'elapsed_time',
 null, null, null, 20)) x;
 dbms_sqltune.load_sqlset(
 sqlset_name => 'weekly_awr_dev1',
 populate_cursor => base_cur);
END;
/

PL/SQL procedure successfully completed.
SQL>


To view the queries within the SQL tuning set, run below query 

select * from dba_sqlset_statements where sqlset_name = 'weekly_awr_dev1';














=> Use the Tuning Set As Input to DBMS_SPM to Create Plan Baselines for Each Query Contained in the SQL Tuning Set


DECLARE
 dev_plan1 PLS_INTEGER;
BEGIN
 dev_plan1 := dbms_spm.load_plans_from_sqlset(
 sqlset_name=>'weekly_awr_dev1');
END;
/

PL/SQL procedure successfully completed.
SQL>


Now each query in the SQL tuning set has an enabled plan baseline associated with it.

SQL> select sql_handle, plan_name, enabled, accepted from dba_sql_plan_baselines order by elapsed_time desc;











Comments

Popular posts from this blog

Data Safe - Introduction

Oracle Data Safe - Practical Guide Oracle Data Safe learner guide Oracle Data Safe Assess risk, discover sensitive data, audit activity, and mask safely It focuses on what Data Safe helps you do operationally: review security posture, find risky identities, centralize auditing, locate sensitive data, and produce safer non-production copies. Contents 01 Why Data Safe matters 02 Where it fits 03 Capability map 04 Assessments 05 Activity Auditing 06 Discovery and Masking 07 Operating model 08 First 30 days 09 Knowledge check Section 01 Why Data Safe matters Database security work is often fragmented. One process checks configuration drift, another stores audit logs, another team scans for PII, and another team writes masking logic for test refreshes. Data Safe is useful because it turns those separate jobs into one security workflow. Key idea The best way to think about Data Safe is as a control plane for database security posture: assess the target, identify risky accounts, d...

Testing Different Access Paths : Concatenated Index

Oracle Concatenated Indexes - Practical Deep Dive Oracle concatenated index deep dive Concatenated Indexes How composite indexes really work, why column order matters, and when skip scan changes the story Concatenated indexes, also called composite indexes, are easy to explain badly and surprisingly rich to explain well. The usual summary is “Oracle can use the index only when the leading column is present,” but that is only the starting point. To design them properly, you need to think about leading portions, equality versus range predicates, ordering requirements, skip scan eligibility, covering behavior, and whether one composite index can replace several single-column indexes in a given workload. Contents 01 What concatenated indexes are 02 Leading edge and leading portion 03 Why column order matters 04 Skip scan and when it helps 05 Access patterns and plan reading 06 Covering and sort elimination 07 Design rules that actually hold 08 Common mistakes 09 End-to-end demo 1...

Database Replay - Real Application Testing (RAT)

Oracle Database Replay and RAT - Practical Deep Dive Oracle Database Replay deep dive Database Replay and Real Application Testing How to validate upgrades, patches, migrations, and risky changes with real workload behavior Database Replay is one of the most practical risk-reduction tools in the Oracle DBA toolbox. Instead of trusting synthetic benchmarks, isolated SQL tests, or intuition, you capture a real production workload, restore a test system to the same logical starting point, replay that workload, and analyze whether performance, errors, timing, and transactional behavior still look safe. Contents 01 What RAT actually is 02 Why Database Replay matters 03 End-to-end workflow 04 Capture design and prerequisites 05 Preprocess, calibrate, replay 06 Reading the results well 07 Pitfalls and unreplayable work 08 Database Replay vs SPA 09 Practical playbooks 10 Knowledge check Section 01 What Real Application Testing actually is Real Application Testing, usually shortened...