0% found this document useful (0 votes)
40 views6 pages

Query Pinning

Uploaded by

ganesh.jegadish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views6 pages

Query Pinning

Uploaded by

ganesh.jegadish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Query Pinning Document

1.Get Sql id’s from Customer or if it’s a situation generate AWR


report and find the Top Query with High Elapsed Time.
Eg: Environment

Database: PKEYSTAR

SQL ID: 19rmtp3m22xj2

2.Generate AWRSQRPT report from last 7days time frame and find a
Good Execution Plan with less Elapsed Time from more Executions
and then get a confirmation from customer.
Eg:
Last Capture
# Plan Hash Value Total Elapsed Time(ms) Executions 1st Capture Snap ID
Snap ID
4 3693203796 21,159 136 22416 22426

3.Check Whether SQL id having different Plans for both node.


select ADDRESS, HASH_VALUE, OLD_HASH_VALUE, PLAN_HASH_VALUE from gV$SQLAREA where
SQL_ID=’ 9jayubcfmkxx6';

Eg:

[email protected]>select ADDRESS, HASH_VALUE, OLD_HASH_VALUE, PLAN_HASH_VALUE from GV$SQLAREA where


SQL_ID='19rmtp3m22xj2';

ADDRESS HASH_VALUE OLD_HASH_VALUE PLAN_HASH_VALUE

---------------- ---------- -------------- ---------------

00000001515093C8 3860952610 924532344 473008269

000000014F0A1B40 3860952610 924532344 816465917

4. Drop sqlset and if not created already then it will through


error like below.
Set lines 300
col NAME format a20

col DESCRIPTION format a40

col CREATED format a30

col OWNER format a10

select * from DBA_SQLSET where name='Load_ 2hyfmnj7b068x';

Eg:

ID CON_DBID NAME OWNER DESCRIPTION CREATED LAST_MODI STATEMENT_COUNT

---------- ---------- -------------------- ---------- ---------------------------------------- ------------------------------ --------- ---------------

97 1113654254 Load_19rmtp3m22xj2 SYS 14-OCT-18 14-OCT-18 1

BEGIN

DBMS_SQLTUNE.DROP_SQLSET(

sqlset_name => ' Load_ 2hyfmnj7b068x');

END;

Eg:

[email protected]>BEGIN

DBMS_SQLTUNE.DROP_SQLSET(

sqlset_name => 'Load_19rmtp3m22xj2');

END;

/ 2 3 4 5

BEGIN

ERROR at line 1:

ORA-13754: "SQL Tuning Set" "Load_19rmtp3m22xj2" does not exist for user

"SYS".

ORA-06512: at "SYS.DBMS_SQLTUNE_INTERNAL", line 14233

ORA-06512: at "SYS.DBMS_SQLTUNE", line 5633

ORA-06512: at line 2

5.Create New SQLSET


exec DBMS_SQLTUNE.CREATE_SQLSET('Load_2hyfmnj7b068x');
Eg:

[email protected]>exec DBMS_SQLTUNE.CREATE_SQLSET('Load_19rmtp3m22xj2');

PL/SQL procedure successfully completed.

6.Capture good plan from AWR and load to SQL SET.(Replace with
AWR begin snap,end snap ,sql id,plan_hash_value)
declare
baseline_ref_cur DBMS_SQLTUNE.SQLSET_CURSOR;
begin
open baseline_ref_cur for
select VALUE(p) from table(
DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY(&begin_snap_id,
&end_snap_id,'sql_id='||CHR(39)||'&sql_id'||
CHR(39)||'',NULL,NULL,NULL,NULL,NULL,NULL,'ALL')) p;
DBMS_SQLTUNE.LOAD_SQLSET('Load_ 2hyfmnj7b068x',
baseline_ref_cur);
end;
/
Eg:

[email protected]>declare

2 baseline_ref_cursor DBMS_SQLTUNE.SQLSET_CURSOR;

3 begin

4 open baseline_ref_cursor for

5 select VALUE(p) from table(DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY(22416,22426,'sql_id='||CHR(39)||'19rmtp3m22xj2'||


CHR(39)||'’ and plan_hash_value=3693203796,NULL,NULL,NULL,NULL,NULL,NULL,'ALL')) p;

DBMS_SQLTUNE.LOAD_SQLSET('Load_19rmtp3m22xj2', baseline_ref_cursor);

6 7 end;

8 /

PL/SQL procedure successfully completed.

7.Load SQLSET into SPM to fix and enable the plan.


set serveroutput on

declare
my_integer pls_integer;

begin

my_integer := dbms_spm.load_plans_from_sqlset(sqlset_name => ' Load_ 2hyfmnj7b068x',

sqlset_owner => 'SYS',

fixed => 'YES',

enabled => 'YES');

DBMS_OUTPUT.PUT_line(my_integer);

end;

Eg:

[email protected]>set serveroutput on

declare

my_integer pls_integer;

begin

my_integer := dbms_spm.load_plans_from_sqlset(sqlset_name => 'Load_19rmtp3m22xj2',

sqlset_owner => 'SYS',

[email protected]> 2 3 4 5 6 fixed => 'YES',

7 enabled => 'YES');

8 DBMS_OUTPUT.PUT_line(my_integer);

end;

9 10 /

PL/SQL procedure successfully completed.

8.Verify Base plan created by Manual-Load (ENABLED=YES,


ACCEPTED=YES,FIXED=YES)
set lines 300

set pages 900

col SQL_HANDLE format a30

col PLAN_NAME format a30

col CREATED format a40


select SQL_HANDLE, PLAN_NAME, CREATED, ORIGIN, ENABLED, ACCEPTED, FIXED, OPTIMIZER_COST from
dba_sql_plan_baselines order by created;

Eg:

SQL_HANDLE PLAN_NAME CREATED ORIGIN ENA ACC FIX

------------------------- ------------------------------ ---------------------------------------- -------------- --- --- ---

SQL_d53239a9439a60f4 SQL_PLAN_dacjtp51tns7n753dcf4e 14-OCT-18 10.42.12.000000 AM MANUAL-LOAD YES YES YES

SQL_edb6fef259fb323e SQL_PLAN_fvdryy9czqcjyb26e7dcf 14-OCT-18 11.03.55.000000 AM MANUAL-LOAD YES YES YES

9.Check Old Hash Value


select ADDRESS, HASH_VALUE, OLD_HASH_VALUE, PLAN_HASH_VALUE from V$SQLAREA where
SQL_ID='19rmtp3m22xj2';

Eg:

[email protected]>select ADDRESS, HASH_VALUE, OLD_HASH_VALUE, PLAN_HASH_VALUE from V$SQLAREA where


SQL_ID='19rmtp3m22xj2';

ADDRESS HASH_VALUE OLD_HASH_VALUE PLAN_HASH_VALUE

---------------- ---------- -------------- ---------------

000000014F0A1B40 3860952610 924532344 816465917

10.Purge Old Hash Value from old plan value.


exec DBMS_SHARED_POOL.PURGE (000000014F0A1B40, 3860952610 , 'C');

Eg:

[email protected]>exec DBMS_SHARED_POOL.PURGE (000000014F0A1B40, 3860952610 , 'C');

11. Verify whether SQL query running with Current Fixed Plan for
both node.
select ADDRESS, HASH_VALUE, OLD_HASH_VALUE, PLAN_HASH_VALUE from gV$SQLAREA where SQL_ID
like '19rmtp3m22xj2';

Eg:

[email protected]>select ADDRESS, HASH_VALUE, OLD_HASH_VALUE, PLAN_HASH_VALUE from GV$SQLAREA where SQL_ID like
'19rmtp3m22xj2';
ADDRESS HASH_VALUE OLD_HASH_VALUE PLAN_HASH_VALUE

---------------- ---------- -------------- ---------------

00000001515093C8 3860952610 924532344 3693203796

000000014F0A1B40 3860952610 924532344 3693203796

12.To Double check ,Run AWRSQRPT report from next effected snap
interval for both node and make sure there is no multiple plan
running for single SQL ID.

You might also like