Copy SQL Plan form one Database another Database (Using sqlt)




Step 1 – Download SQLT from Oracle Support
Step 2 – Identify the SQL ID, and Plan Hash Value (PHV) (Source DB)
Step 3 – Extract The SQL Profile Using  "coe_xfr_sql_profile.sql" - (Source DB) --( it iwll generate  a sql script "coe_xfr_sql_profile_<sqlid>_<planhash>.sql"
Step 4 – Create SQL Profile Anywhere You Need ( Target DB) 
Step 5 - Check Plan of SQL

Note: Schema Structure Should be same
In order to use this script, you DO NOT NEED to have SQLT installed. You can just add this script to your collection of scripts, and use it as needed.

Example Execution:
----------------------
Step 1 – Download SQLT from Oracle Support.
All About the SQLT Diagnostic Tool (Doc ID 215187.1).



Step 2 – Identify the SQL ID, and Plan Hash Value (PHV).
--------------------------------------------------------------
SQL> select distinct plan_hash_value from v$sql where sql_id='9dtxw5f7qdnvg';

PLAN_HASH_VALUE
---------------
3505580018



Step 3 – Extract The SQL Profile - "coe_xfr_sql_profile.sql"
----------------------------------------------------------------------
SQL> @coe_xfr_sql_profile.sql

Parameter 1:
SQL_ID (required)

Enter value for 1: 9dtxw5f7qdnvg


PLAN_HASH_VALUE AVG_ET_SECS
--------------- -----------
     3505580018      16.838
     1403905151
     3294507554

Parameter 2:
PLAN_HASH_VALUE (required)

Enter value for 2: 3505580018

Values passed to coe_xfr_sql_profile:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL_ID         : "9dtxw5f7qdnvg"
PLAN_HASH_VALUE: "3505580018"

SQL>BEGIN
  2    IF :sql_text IS NULL THEN
  3      RAISE_APPLICATION_ERROR(-20100, 'SQL_TEXT for SQL_ID &&sql_id. was not found in memory (gv$sqltext_with_newlines) or AWR (dba_hist_sqltext).');
  4    END IF;
  5  END;
  6  /
SQL>SET TERM OFF;
SQL>BEGIN
  2    IF :other_xml IS NULL THEN
  3      RAISE_APPLICATION_ERROR(-20101, 'PLAN for SQL_ID &&sql_id. and PHV &&plan_hash_value. was not found in memory (gv$sql_plan) or AWR (dba_hist_sql_plan).');
  4    END IF;
  5  END;
  6  /
SQL>SET TERM OFF;

Execute coe_xfr_sql_profile_9dtxw5f7qdnvg_3505580018.sql
on TARGET system in order to create a custom SQL Profile
with plan 3505580018 linked to adjusted sql_text.


COE_XFR_SQL_PROFILE completed.
SQL>



Step 4 – Create SQL Profile Anywhere You Need ( Target DB)
------------------------------------------------------------
sqlplus / as sysdba
SQL> @coe_xfr_sql_profile_9dtxw5f7qdnvg_3505580018.sql


Step 5 - Check Plan of SQL
--------------------------
select * from table(dbms_xplan.display_cursor(‘SQL_ID’));

No comments:

Post a Comment