Creation Zone

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Sunday, 18 May 2008

Oracle 10g: Exporting SQL Profile(s) from One System to Another

Posted on 02:44 by Unknown
Oracle 10g RDBMS has some useful features to automate SQL tuning up to some extent. The SQL Tuning Advisor of Oracle 10g helps us in optimizing poorly written/tuned SQL statements. SQL Tuning Advisor can be used from the command line SQL*Plus environment or from the web based Enterprise Manager. The optimizer runs in the 'tuning' mode under the SQL Tuning Advisor; collects the SQL profile data and tries to improve the performance of the SQL by creating new indexes, gathering {additional} statistics, etc., In case of significant improvements, the potential SQL profile can be accepted and saved in the database, so the optimizer can use the potential SQL profile while executing similar SQL statements in the 'normal' mode.

Sometimes it is desirable to use similar SQL profile(s) in environments running similar databases -- Testing and Production database environments, for example. As long as the SQL tuning advisor's recommendations are within the boundaries of the database system administrator, it is easy to manually replicate one system's behavior on another. However in some cases it is beyond the control of a DBA to replicate the database system behavior - for example, optimizer might suggest a completely different explain plan based on some internal heuristics. In such cases it is hard to replicate similar behavior by hand. Fortunately the Transportable SQL Profile feature of Oracle Database 10g makes it possible to export the SQL profiles from one system to another in just few steps.

Without further ado, let's have a look at the necessary steps with examples.

  1. On the source system, create the staging table. The staging table will be used to store the contents of the SQL Profile.

    eg.,
    % sqlplus / as sysdba

    SQL*Plus: Release 10.2.0.3.0 - Production on Fri Apr 11 01:47:39 2008
    Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

    SQL> execute DBMS_SQLTUNE.CREATE_STGTAB_SQLPROF(table_name => 'CS90_BATCH_PROFILE_STGTAB');

    PL/SQL procedure successfully completed.

    The name of the {staging} table is CS90_BATCH_PROFILE_STGTAB.

  2. Load the contents of the SQL Profile into the staging table. To perform this step, you need to know the SQL profile name. When the profile is accepted, you can either specify a name of your choice for the profile, or accept the system generated name.

    SQL> execute DBMS_SQLTUNE.PACK_STGTAB_SQLPROF (profile_name => 'SYS_SQLPROF_01464eb777e6c001',
    staging_table_name => 'CS90_BATCH_PROFILE_STGTAB');


    PL/SQL procedure successfully completed.

    In this example, the name of the SQL Profile being loaded is SYS_SQLPROF_01464eb777e6c001, a system generated name.

    Note #1:
    You can store as many SQL profiles as you wish in the staging table. The following example, loads another SQL profile called SYS_SQLPROF_01464eb83e5f8002, another system generated name.

    SQL> execute DBMS_SQLTUNE.PACK_STGTAB_SQLPROF (profile_name => 'SYS_SQLPROF_01464eb83e5f8002',
    staging_table_name => 'CS90_BATCH_PROFILE_STGTAB');


    PL/SQL procedure successfully completed.

  3. Export the staging table (CS90_BATCH_PROFILE_STGTAB in this example) to the destination system using Data Pump, exp utility or DB Links.
    % exp \'CS90/CS90 AS SYSDBA\' FILE=CS90BatchSQLprofiles.DMP TABLES=CS90_BATCH_PROFILE_STGTAB

    Export: Release 10.2.0.3.0 - Production on Fri Apr 11 02:02:12 2008
    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    Export done in UTF8 character set and UTF8 NCHAR character set
    server uses WE8ISO8859P15 character set (possible charset conversion)

    About to export specified tables via Conventional Path ...
    . . exporting table CS90_BATCH_PROFILE_STGTAB 2 rows exported
    Export terminated successfully without warnings.

    Note #2:
    Since the string "AS SYSDBA" contains a blank, most operating systems require that entire string '<username>/<password> AS SYSDBA' be placed in quotes or marked as a literal by some method. Be aware that some operating systems also require that quotes on the command line be escaped as well.

  4. On the destination system, import the staging table into the database.

    eg., Import the staging table, CS90_BATCH_PROFILE_STGTAB, into the destination database using Data Pump, imp utility or DB Links.

    % imp \'CS90/CS90 AS SYSDBA\' FILE=CS90BatchSQLprofiles.DMP TABLES=CS90_BATCH_PROFILE_STGTAB

    Import: Release 10.2.0.3.0 - Production on Fri Apr 11 02:06:57 2008
    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options

    Export file created by EXPORT:V10.02.01 via conventional path
    import done in UTF8 character set and UTF8 NCHAR character set
    import server uses WE8ISO8859P15 character set (possible charset conversion)
    . importing SYS's objects into SYS
    . importing SYS's objects into SYS
    IMP-00015: following statement failed because the object already exists:
    "CREATE TYPE "SQLPROF_ATTR" TIMESTAMP '2008-02-02:00:37:22' OID 'AE1A3645A6B"
    "D1155E0340800209420B8' "
    " AS V"
    "ARRAY(2000) of VARCHAR2(500)"
    . . importing table "CS90_BATCH_PROFILE_STGTAB" 2 rows imported
    Import terminated successfully with warnings.

  5. Download SQL Profile content from the staging table to create equivalent SQL profile(s) in the destination database.

    % sqlplus / as sysdba

    SQL*Plus: Release 10.2.0.3.0 - Production on Fri Apr 11 02:08:02 2008
    Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options

    SQL> desc CS90_BATCH_PROFILE_STGTAB
    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    PROFILE_NAME VARCHAR2(30)
    CATEGORY VARCHAR2(30)
    SIGNATURE NUMBER
    SQL_TEXT CLOB
    DESCRIPTION VARCHAR2(500)
    TYPE VARCHAR2(9)
    STATUS VARCHAR2(8)
    BOOLEAN_FLAGS NUMBER
    ATTRIBUTES SQLPROF_ATTR
    VERSION NUMBER
    SPARE1 CLOB
    SPARE2 BLOB

    SQL> execute DBMS_SQLTUNE.UNPACK_STGTAB_SQLPROF( replace => FALSE, staging_table_name => 'CS90_BATCH_PROFILE_STGTAB');

    PL/SQL procedure successfully completed.

    [New:09/05/09]
    Note #3:
    By default the staging will be created in SYS schema. If you want it to be created in a different schema, specify the schema owner.

    SQL> execute DBMS_SQLTUNE.UNPACK_STGTAB_SQLPROF( replace => FALSE, staging_table_name => 'CS90_BATCH_PROFILE_STGTAB', staging_schema_owner => 'CS90');

    PL/SQL procedure successfully completed.

  6. Finally query the DBA_SQL_PROFILES table to make sure that the SQL profile(s) are successfully imported into the database.

    eg.,
    SQL> select NAME from DBA_SQL_PROFILES;

    NAME
    --------------------------------------------------------------------------------
    SYS_SQLPROF_01464eb83e5f8002
    SYS_SQLPROF_01464eb777e6c001
    ...
    ...

[New:09/05/09]
How to drop an SQL profile?

By using the DROP_SQL_PROFILE procedure in DBMS_SQLTUNE package.

eg.,
SQL> execute DBMS_SQLTUNE.drop_sql_profile (name => 'SYS_SQLPROF_01464eb83e5f8002', ignore => TRUE);

PL/SQL procedure successfully completed.

That is all there is in it. For further/detailed information around SQL Tuning Advisor and SQL profiles, check the following:
  • Optimizing the Optimizer: Essential SQL Tuning Tips and Techniques. An Oracle White Paper
  • Automatic SQL Tuning in Oracle Database 10g. Author: Tim. http://www.oracle-base.com

_____________
Technorati Tags:
 Oracle |  Database |  SQL Tuning |  Oracle Enterprise Manager
Email ThisBlogThis!Share to XShare to Facebook
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • *nix: Workaround to cannot find zipfile directory in one of file.zip or file.zip.zip ..
    Symptom: You are trying to extract the archived files off of a huge (any file with size > 2 GB or 4GB, depending on the OS) ZIP file with...
  • JDS: Installing Sun Java Desktop System 2.0
    This document will guide you through the process of installing JDS 2.0 on a PC from integrated CDROM images Requirements I...
  • Linux: Installing Source RPM (SRPM) package
    RPM stands for RedHat Package Manager. RPM is a system for installing and managing software & most common software package manager used ...
  • Solaris: malloc Vs mtmalloc
    Performance of Single Vs Multi-threaded application Memory allocation performance in single and multithreaded environments is an important a...
  • C/C++: Printing Stack Trace with printstack() on Solaris
    libc on Solaris 9 and later, provides a useful function called printstack , to print a symbolic stack trace to the specified file descripto...
  • Installing MySQL 5.0.51b from the Source Code on Sun Solaris
    Building and installing the MySQL server from the source code is relatively very easy when compared to many other OSS applications. At least...
  • Oracle Apps on T2000: ORA-04020 during Autoinvoice
    The goal of this brief blog post is to provide a quick solution to all Sun-Oracle customers who may run into a deadlock when a handful of th...
  • Siebel Connection Broker Load Balancing Algorithm
    Siebel server architecture supports spawning multiple application object manager processes. The Siebel Connection Broker, SCBroker, tries to...
  • 64-bit dbx: internal error: signal SIGBUS (invalid address alignment)
    The other day I was chasing some lock contention issue with a 64-bit application running on Solaris 10 Update 1; and stumbled with an unexpe...
  • Oracle 10gR2/Solaris x64: Fixing ORA-20000: Oracle Text errors
    First, some facts: * Oracle Applications 11.5.10 (aka E-Business Suite 11 i ) database is now supported on Solaris 10 for x86-64 architectur...

Categories

  • 80s music playlist
  • bandwidth iperf network solaris
  • best
  • black friday
  • breakdown database groups locality oracle pmap sga solaris
  • buy
  • deal
  • ebiz ebs hrms oracle payroll
  • emca oracle rdbms database ORA-01034
  • friday
  • Garmin
  • generic+discussion software installer
  • GPS
  • how-to solaris mmap
  • impdp ora-01089 oracle rdbms solaris tips upgrade workarounds zombie
  • Magellan
  • music
  • Navigation
  • OATS Oracle
  • Oracle Business+Intelligence Analytics Solaris SPARC T4
  • oracle database flashback FDA
  • Oracle Database RDBMS Redo Flash+Storage
  • oracle database solaris
  • oracle database solaris resource manager virtualization consolidation
  • Oracle EBS E-Business+Suite SPARC SuperCluster Optimized+Solution
  • Oracle EBS E-Business+Suite Workaround Tip
  • oracle lob bfile blob securefile rdbms database tips performance clob
  • oracle obiee analytics presentation+services
  • Oracle OID LDAP ADS
  • Oracle OID LDAP SPARC T5 T5-2 Benchmark
  • oracle pls-00201 dbms_system
  • oracle siebel CRM SCBroker load+balancing
  • Oracle Siebel Sun SPARC T4 Benchmark
  • Oracle Siebel Sun SPARC T5 Benchmark T5-2
  • Oracle Solaris
  • Oracle Solaris Database RDBMS Redo Flash F40 AWR
  • oracle solaris rpc statd RPC troubleshooting
  • oracle solaris svm solaris+volume+manager
  • Oracle Solaris Tips
  • oracle+solaris
  • RDC
  • sale
  • Smartphone Samsung Galaxy S2 Phone+Shutter Tip Android ICS
  • solaris oracle database fmw weblogic java dfw
  • SuperCluster Oracle Database RDBMS RAC Solaris Zones
  • tee
  • thanksgiving sale
  • tips
  • TomTom
  • windows

Blog Archive

  • ►  2013 (16)
    • ►  December (3)
    • ►  November (2)
    • ►  October (1)
    • ►  September (1)
    • ►  August (1)
    • ►  July (1)
    • ►  June (1)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  February (2)
    • ►  January (1)
  • ►  2012 (14)
    • ►  December (1)
    • ►  November (1)
    • ►  October (1)
    • ►  September (1)
    • ►  August (1)
    • ►  July (1)
    • ►  June (2)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (2)
  • ►  2011 (15)
    • ►  December (2)
    • ►  November (1)
    • ►  October (2)
    • ►  September (1)
    • ►  August (2)
    • ►  July (1)
    • ►  May (2)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2010 (19)
    • ►  December (3)
    • ►  November (1)
    • ►  October (2)
    • ►  September (1)
    • ►  August (1)
    • ►  July (1)
    • ►  June (1)
    • ►  May (5)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2009 (25)
    • ►  December (1)
    • ►  November (2)
    • ►  October (1)
    • ►  September (1)
    • ►  August (2)
    • ►  July (2)
    • ►  June (1)
    • ►  May (2)
    • ►  April (3)
    • ►  March (1)
    • ►  February (5)
    • ►  January (4)
  • ▼  2008 (34)
    • ►  December (2)
    • ►  November (2)
    • ►  October (2)
    • ►  September (1)
    • ►  August (4)
    • ►  July (2)
    • ►  June (3)
    • ▼  May (3)
      • Deploying TWiki 4.2.0 on Sun Java Web Server 7.0
      • OpenSolaris 2008.05
      • Oracle 10g: Exporting SQL Profile(s) from One Syst...
    • ►  April (2)
    • ►  March (5)
    • ►  February (4)
    • ►  January (4)
  • ►  2007 (33)
    • ►  December (2)
    • ►  November (4)
    • ►  October (2)
    • ►  September (5)
    • ►  August (3)
    • ►  June (2)
    • ►  May (3)
    • ►  April (5)
    • ►  March (3)
    • ►  February (1)
    • ►  January (3)
  • ►  2006 (40)
    • ►  December (2)
    • ►  November (6)
    • ►  October (2)
    • ►  September (2)
    • ►  August (1)
    • ►  July (2)
    • ►  June (2)
    • ►  May (4)
    • ►  April (5)
    • ►  March (5)
    • ►  February (3)
    • ►  January (6)
  • ►  2005 (72)
    • ►  December (5)
    • ►  November (2)
    • ►  October (6)
    • ►  September (5)
    • ►  August (5)
    • ►  July (10)
    • ►  June (8)
    • ►  May (9)
    • ►  April (6)
    • ►  March (6)
    • ►  February (5)
    • ►  January (5)
  • ►  2004 (36)
    • ►  December (1)
    • ►  November (5)
    • ►  October (12)
    • ►  September (18)
Powered by Blogger.

About Me

Unknown
View my complete profile