• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Techgoeasy

Techgoeasy

Learn Oracle, PHP, HTML,CSS,Perl,UNIX shell scripts

  • Home
  • Oracle database
  • Oracle Ebusiness Suite
  • Oracle weblogic
  • Oracle Performance Tuning
  • Oracle Hyperion
  • Oracle Cloud Tutorials
  • SQL
  • interview questions
  • Linux
  • PHP and HTML
  • Downloads
Home » Oracle » Oracle Database » Move SQL Baseline from One Database to Another in Oracle

Move SQL Baseline from One Database to Another in Oracle

June 5, 2023 by techgoeasy Leave a Comment

In this post, we will check out how to move SQL baseline from One Database to Another 

How to move the sql baselines in Oracle

Suppose you have created a sql baseline in System A and Now you want to transfer that sql baseline to System B.

Step 1
On System A: Creating a staging table to store the SQL baseline

exec DBMS_SPM.CREATE_STGTAB_BASELINE(table_name=>'STAGE',schema_name=>'SCOTT');

Step 2
On System A: Pack the SQL baselines into the Staging Table

Pack all baselines in the database.

set serveroutput on
DECLARE
x number;
BEGIN
x := DBMS_SPM.PACK_STGTAB_BASELINE('STAGE', 'SCOTT');
dbms_output.put_line(to_char(x) || ' plan baselines packed');
END;
/


Pack ALL Baselines Plans of a query

set serveroutput on
DECLARE
x number;
BEGIN
x := DBMS_SPM.PACK_STGTAB_BASELINE('STAGE', 'SCOTT', sql_handle => '&sql_handle');
dbms_output.put_line(to_char(x) || ' plan baselines packed');
END;
/


Pack a specific Baseline Plan of a Query


set serveroutput on
DECLARE
x number;
BEGIN
x := DBMS_SPM.PACK_STGTAB_BASELINE('STAGE', 'SCOTT', sql_handle => '&sql_handle', plan_name => '&plan_value' );
dbms_output.put_line(to_char(x) || ' plan baselines packed');
END;
/


Pack only ACCEPTED Baseline Plans of a Query


set serveroutput on
DECLARE
x number;
BEGIN
x := DBMS_SPM.PACK_STGTAB_BASELINE('STAGE', 'SCOTT', sql_handle => '&SQL_HANDLE', accepted => 'YES' );
dbms_output.put_line(to_char(x) || ' plan baselines packed');
END;
/

Step 3
On System A: Export from Source Database

$ exp scott/tiger file=stage.dmp tables=stage

Step 4
On System B: Import the staging table

$ imp scott/tiger file=stage.dmp full=y

Step 5
On System B: Unpack Staging Table

If importing to the same schema, the schema owner does not need to be specified:

SQL> EXEC DBMS_SPM.UNPACK_STGTAB_BASELINE('STAGE','SCOTT');

Step 6

On System B: Check if the baseline is enabled

SELECT sql_handle, plan_name, origin, enabled, accepted
FROM dba_sql_plan_baselines;

I hope you will find this article on How to move the sql baselines useful and helpful. Please do provide the feedback

Related Articles

SQL Tuning Set in Oracle
how to create sql baseline in Oracle 19c
how to create sql baseline from Sql tuning set in Oracle
How to drop the sql baseline in Oracle
how to create sql baseline from AWR repository without STS

Filed Under: Oracle, Oracle Database

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar



Subscribe to our mailing list

Enter your email address to subscribe to this blog and receive notifications of new posts by email

Recent Posts

  • How to clone Oracle Home in 10g/11g/12c/19c/23c
  • How to find the FND_FILE output of the running concurrent request
  • srvctl commands in Oracle
  • Top SQL Patch Queries in Oracle Database
  • how to find if the sql is using the SQL Patch

Copyright © 2023 : TechGoEasy

  • Hire me
  • Privacy Policy
  • Contact Us
  • New? Start Here
  • About Us