<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Sky&apos; Digests</title>
    <link rel="alternate" type="text/html" href="http://www.heysky.net/digest/" />
    <link rel="self" type="application/atom+xml" href="http://www.heysky.net/digest/atom.xml" />
    <id>tag:www.heysky.net,2008-07-11:/digest//1</id>
    <updated>2008-08-03T15:14:52Z</updated>
    
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Open Source 4.2rc3-en</generator>

<entry>
    <title>Automatic SQL Tuning and SQL Profiles Internals in Oracle 10g</title>
    <link rel="alternate" type="text/html" href="http://www.heysky.net/digest/2008/08/automatic-sql-tuning-and-sql-profiles-internals-in-oracle-10g.html" />
    <id>tag:www.heysky.net,2008:/digest//1.329</id>

    <published>2008-08-03T14:00:39Z</published>
    <updated>2008-08-03T15:14:52Z</updated>

    <summary>From: http://www.oracle-base.com/articles/10g/AutomaticSQLTuning10g.phpAutomatic SQL Tuning in Oracle Database 10g This article the discusses the new features which automate the tuning of SQL statements in Oracle 10g: OverviewSQL Tuning AdvisorManaging SQL ProfilesSQL Tuning SetsUseful Views Overview In its normal mode the query...</summary>
    <author>
        <name>Sky</name>
        <uri>http://www.heysky.net</uri>
    </author>
    
        <category term="Oracle" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="10g" label="10g" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="advisor" label="Advisor" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="automaticsqltuning" label="Automatic SQL Tuning" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="cbo" label="CBO" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="executionplan" label="Execution Plan" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="hints" label="Hints" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="internal" label="Internal" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="oracle" label="Oracle" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="performance" label="Performance" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="sqlprofiles" label="SQL Profiles" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="tuning" label="tuning" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.heysky.net/digest/">
        <![CDATA[<i>From: http://www.oracle-base.com/articles/10g/AutomaticSQLTuning10g.php</i><br /><br /><h1>Automatic SQL Tuning in Oracle Database 10g</h1>

This article the discusses the new features which automate the tuning of SQL statements in Oracle 10g:<br />

<ul><li><a href="http://www.oracle-base.com/articles/10g/AutomaticSQLTuning10g.php#overview">Overview</a></li><li><a href="http://www.oracle-base.com/articles/10g/AutomaticSQLTuning10g.php#sql_tuning_advisor">SQL Tuning Advisor</a></li><li><a href="http://www.oracle-base.com/articles/10g/AutomaticSQLTuning10g.php#managing_sql_profiles">Managing SQL Profiles</a></li><li><a href="http://www.oracle-base.com/articles/10g/AutomaticSQLTuning10g.php#sql_tuning_sets">SQL Tuning Sets</a></li><li><a href="http://www.oracle-base.com/articles/10g/AutomaticSQLTuning10g.php#useful_views">Useful Views</a></li></ul>

<h2>Overview</h2>
In its normal mode the query optimizer needs to make decisions about
execution plans in a very short time. As a result it may not always be
able to
obtain enough information to make the best decision. Oracle 10g allows
the optimizer to run in tuning mode where it can gather additional
information
and make recommendations about how specific statements can be tuned
further. This process may take several minutes for a single statement
so it is
intended to be used on high-load resource-intensive statements.<br />

<br />]]>
        <![CDATA[In tuning mode the optimizer performs the following analysis:<br />


<ul><li>Statistics Analysis - The optimizer recommends the
gathering of statistics on objects with missing or stale statistics.
Additional statistics for these objects are stored in an SQL profile.<br /><br /></li><li>SQL
Profiling - The optimizer may be able to improve performance by
gathering additional statistics and altering session specific
parameters such as the <code>OPTIMIZER_MODE</code>. If such improvements are
possible the information is stored in an SQL profile. If accepted this
information can then used by the optimizer when running in normal mode.
Unlike a stored outline which fixes the execution plan, an SQL profile
may still be of benefit when the contents of the table alter
drastically. Even so, it's sensible to update profiles periodically.
The SQL profiling is not performed when the tuining optimizer is run in
limited mode.<br /><br /></li><li>Access Path Analysis -
The optimizer investigates the effect of new or modified indexes on the
access path. It's index recommendations relate to a specific statement
so where necessary it will also suggest the use of the SQL Access
Advisor to check the impact of these indexes on a representative SQL
workload.<br /><br /></li><li>SQL
Structure Analysis - The optimizer suggests alternatives for SQL
statements that contain structures that may impact on performance. The
implementation of these suggestions requires human intervention to
check their validity.</li></ul>

The automatic SQL tuning features are accessible from Enterprise
Manager on the "Advisor Central" page these or from PL/SQL using the <code>DBMS_SQLTUNE</code> package.
This article will focus on the PL/SQL API as the Enterprise Manager interface is reasonably intuative.<br />



<h2>SQL Tuning Advisor</h2>


In order to access the SQL tuning advisor API a user must be granted the <code>ADVISOR</code> privilege:<br />


<blockquote><pre>CONN sys/password AS SYSDBA<br />GRANT ADVISOR TO scott;<br />CONN scott/tiger</pre></blockquote>


The first step when using the SQL tuning advisor is to create a new tuning task using the <code>CREATE_TUNING_TASK</code>
function. The statements to be
analyzed can be retrieved from the Automatic Workload Repository (AWR),
the cursor cache, an SQL tuning set or specified manually:<br />


<blockquote><pre>SET SERVEROUTPUT ON<br /><br />-- Tuning task created for specific a statement from the AWR.<br />DECLARE<br />  l_sql_tune_task_id  VARCHAR2(100);<br />BEGIN<br />  l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (<br />                          begin_snap  =&gt; 764,<br />                          end_snap    =&gt; 938,<br />                          sql_id      =&gt; '19v5guvsgcd1v',<br />                          scope       =&gt; DBMS_SQLTUNE.scope_comprehensive,<br />                          time_limit  =&gt; 60,<br />                          task_name   =&gt; '19v5guvsgcd1v_AWR_tuning_task',<br />                          description =&gt; 'Tuning task for statement 19v5guvsgcd1v in AWR.');<br />  DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);<br />END;<br />/<br /><br />-- Tuning task created for specific a statement from the cursor cache.<br />DECLARE<br />  l_sql_tune_task_id  VARCHAR2(100);<br />BEGIN<br />  l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (<br />                          sql_id      =&gt; '19v5guvsgcd1v',<br />                          scope       =&gt; DBMS_SQLTUNE.scope_comprehensive,<br />                          time_limit  =&gt; 60,<br />                          task_name   =&gt; '19v5guvsgcd1v_tuning_task',<br />                          description =&gt; 'Tuning task for statement 19v5guvsgcd1v.');<br />  DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);<br />END;<br />/<br /><br />-- Tuning task created from an SQL tuning set.<br />DECLARE<br />  l_sql_tune_task_id  VARCHAR2(100);<br />BEGIN<br />  l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (<br />                          sqlset_name =&gt; 'test_sql_tuning_set',<br />                          scope       =&gt; DBMS_SQLTUNE.scope_comprehensive,<br />                          time_limit  =&gt; 60,<br />                          task_name   =&gt; 'sqlset_tuning_task',<br />                          description =&gt; 'Tuning task for an SQL tuning set.');<br />  DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);<br />END;<br />/<br /><br />-- Tuning task created for a manually specified statement.<br />DECLARE<br />  l_sql               VARCHAR2(500);<br />  l_sql_tune_task_id  VARCHAR2(100);<br />BEGIN<br />  l_sql := 'SELECT e.*, d.* ' ||<br />           'FROM   emp e JOIN dept d ON e.deptno = d.deptno ' ||<br />           'WHERE  NVL(empno, ''0'') = :empno';<br /><br />  l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (<br />                          sql_text    =&gt; l_sql,<br />                          bind_list   =&gt; sql_binds(anydata.ConvertNumber(100)),<br />                          user_name   =&gt; 'scott',<br />                          scope       =&gt; DBMS_SQLTUNE.scope_comprehensive,<br />                          time_limit  =&gt; 60,<br />                          task_name   =&gt; 'emp_dept_tuning_task',<br />                          description =&gt; 'Tuning task for an EMP to DEPT join query.');<br />  DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);<br />END;<br />/</pre></blockquote>


If the <code>TASK_NAME</code> parameter is specified it's value is returned as the SQL tune task identifier. If ommitted a system generated name
like "TASK_1478" is returned. If the <code>SCOPE</code> parameter is set to <code>scope_limited</code> the SQL profiling analysis is omitted. The
<code>TIME_LIMIT</code> parameter simply restricts the time the optimizer can spend compiling the recommendations.<br />


<br />


The following examples will reference the last tuning set as it has no external dependancies other than the SCOTT schema. The <code>NVL</code>
in the
SQL statement was put in to provoke a reaction from the optimizer. In
addition we can delete the statistics from one of the tables to provoke
it even more:<br />


<blockquote><pre>EXEC DBMS_STATS.delete_table_stats('SCOTT','EMP');</pre></blockquote>


With the tuning task defined the next step is to execute it using the <code>EXECUTE_TUNING_TASK</code> procedure:<br />


<blockquote><pre>EXEC DBMS_SQLTUNE.execute_tuning_task(task_name =&gt; 'emp_dept_tuning_task');</pre></blockquote>

During the execution phase you may wish to pause and restart the task,
cancel it or reset the task to allow it to be re-executed:<br />


<blockquote><pre>-- Interrupt and resume a tuning task.<br />EXEC DBMS_SQLTUNE.interrupt_tuning_task (task_name =&gt; 'emp_dept_tuning_task');<br />EXEC DBMS_SQLTUNE.resume_tuning_task (task_name =&gt; 'emp_dept_tuning_task');<br /><br />-- Cancel a tuning task.<br />EXEC DBMS_SQLTUNE.cancel_tuning_task (task_name =&gt; 'emp_dept_tuning_task');<br /><br />-- Reset a tuning task allowing it to be re-executed.<br />EXEC DBMS_SQLTUNE.reset_tuning_task (task_name =&gt; 'emp_dept_tuning_task');</pre></blockquote>


The status of the tuning task can be monitored using the <code>DBA_ADVISOR_LOG</code> view:<br />


<blockquote><pre>SELECT task_name, status FROM dba_advisor_log WHERE owner = 'SCOTT';<br /><br />TASK_NAME                      STATUS<br />------------------------------ -----------<br />emp_dept_tuning_task           COMPLETED<br /><br />1 row selected.</pre></blockquote>


Once the tuning task has executed successfully the recommendations can be displayed using the <code>REPORT_TUNING_TASK</code> function:<br />


<blockquote><pre>SET LONG 10000;<br />SET PAGESIZE 1000<br />SET LINESIZE 200<br />SELECT DBMS_SQLTUNE.report_tuning_task('emp_dept_tuning_task') AS recommendations FROM dual;<br />SET PAGESIZE 24</pre></blockquote>


In this case the output looks like this:<br />


<blockquote><pre>RECOMMENDATIONS<br />--------------------------------------------------------------------------------<br />GENERAL INFORMATION SECTION<br />-------------------------------------------------------------------------------<br />Tuning Task Name   : emp_dept_tuning_task<br />Scope              : COMPREHENSIVE<br />Time Limit(seconds): 60<br />Completion Status  : COMPLETED<br />Started at         : 05/06/2004 09:29:13<br />Completed at       : 05/06/2004 09:29:15<br /><br />-------------------------------------------------------------------------------<br />SQL ID  : 0wrmfv2yvswx1<br />SQL Text: SELECT e.*, d.* FROM   emp e JOIN dept d ON e.deptno = d.deptno<br />          WHERE  NVL(empno, '0') = :empno<br /><br />-------------------------------------------------------------------------------<br />FINDINGS SECTION (2 findings)<br />-------------------------------------------------------------------------------<br /><br />1- Statistics Finding<br />---------------------<br />  Table "SCOTT"."EMP" and its indices were not analyzed.<br /><br />  Recommendation<br />  --------------<br />    Consider collecting optimizer statistics for this table and its indices.<br />    execute dbms_stats.gather_table_stats(ownname =&gt; 'SCOTT', tabname =&gt;<br />            'EMP', estimate_percent =&gt; DBMS_STATS.AUTO_SAMPLE_SIZE,<br />            method_opt =&gt; 'FOR ALL COLUMNS SIZE AUTO', cascade =&gt; TRUE)<br /><br />  Rationale<br />  ---------<br />    The optimizer requires up-to-date statistics for the table and its indices<br />    in order to select a good execution plan.<br /><br />2- Restructure SQL finding (see plan 1 in explain plans section)<br />----------------------------------------------------------------<br />  The predicate NVL("E"."EMPNO",0)=:B1 used at line ID 2 of the execution plan<br />  contains an expression on indexed column "EMPNO". This expression prevents<br />  the optimizer from selecting indices on table "SCOTT"."EMP".<br /><br />  Recommendation<br />  --------------<br />    Rewrite the predicate into an equivalent form to take advantage of<br />    indices. Alternatively, create a function-based index on the expression.<br /><br />  Rationale<br />  ---------<br />    The optimizer is unable to use an index if the predicate is an inequality<br />    condition or if there is an expression or an implicit data type conversion<br />    on the indexed column.<br /><br />-------------------------------------------------------------------------------<br />EXPLAIN PLANS SECTION<br />-------------------------------------------------------------------------------<br /><br />1- Original<br />-----------<br />Plan hash value: 1863486531<br /><br />----------------------------------------------------------------------------------------<br />| Id  | Operation                    | Name    | Rows  | Bytes | Cost (%CPU)| Time     |<br />----------------------------------------------------------------------------------------<br />|   0 | SELECT STATEMENT             |         |     1 |   107 |     4   (0)| 00:00:01 |<br />|   1 |  NESTED LOOPS                |         |     1 |   107 |     4   (0)| 00:00:01 |<br />|   2 |   TABLE ACCESS FULL          | EMP     |     1 |    87 |     3   (0)| 00:00:01 |<br />|   3 |   TABLE ACCESS BY INDEX ROWID| DEPT    |     1 |    20 |     1   (0)| 00:00:01 |<br />|   4 |    INDEX UNIQUE SCAN         | PK_DEPT |     1 |       |     0   (0)| 00:00:01 |<br />----------------------------------------------------------------------------------------<br /><br />Note<br />-----<br />   - dynamic sampling used for this statement<br /><br />-------------------------------------------------------------------------------<br /><br /><br />1 row selected.</pre></blockquote>


Once the tuning session is over the tuning task can be dropped using the <code>DROP_TUNING_TASK</code> procedure:<br />


<blockquote><pre>BEGIN<br />  DBMS_SQLTUNE.drop_tuning_task (task_name =&gt; '19v5guvsgcd1v_AWR_tuning_task');<br />  DBMS_SQLTUNE.drop_tuning_task (task_name =&gt; '19v5guvsgcd1v_tuning_task');<br />  DBMS_SQLTUNE.drop_tuning_task (task_name =&gt; 'sqlset_tuning_task');<br />  DBMS_SQLTUNE.drop_tuning_task (task_name =&gt; 'emp_dept_tuning_task');<br />END;<br />/</pre></blockquote>



<h2>Managing SQL Profiles</h2>


To manage SQL profiles a user needs the following privileges:<br />


<blockquote><pre>CONN sys/password AS SYSDBA<br />GRANT CREATE ANY SQL PROFILE TO scott;<br />GRANT DROP ANY SQL PROFILE TO scott;<br />GRANT ALTER ANY SQL PROFILE TO scott;<br />CONN scott/tiger</pre></blockquote>


If the recommendations of the SQL tuning advisor include a suggested profile you can choose to accept it using the <code>ACCEPT_SQL_PROFILE</code> procedure:<br />


<blockquote><pre>SET SERVEROUTPUT ON<br />DECLARE<br />  l_sql_tune_task_id  VARCHAR2(20);<br />BEGIN<br />  l_sql_tune_task_id := DBMS_SQLTUNE.accept_sql_profile (<br />                          task_name =&gt; 'emp_dept_tuning_task',<br />                          name      =&gt; 'emp_dept_profile');<br />  DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);<br />END;<br />/</pre></blockquote>


The <code>NAME</code> parameter is used to specify a name for the profile. If it is not specified a system generated name will be used.<br />


<br />


The <code>STATUS</code>, <code>NAME</code>, <code>DESCRIPTION</code>, and <code>CATEGORY</code> attributes of an SQL profile can be altered using the
<code>ALTER_SQL_PROFILE</code> procedure:<br />


<blockquote><pre>BEGIN<br />  DBMS_SQLTUNE.alter_sql_profile (<br />    name            =&gt; 'emp_dept_profile',<br />    attribute_name  =&gt; 'STATUS',<br />    value           =&gt; 'DISABLED');<br />END;<br />/</pre></blockquote>


Existing SQL profiles can be dropped using the <code>DROP_SQL_PROFILE</code> procedure:<br />


<blockquote><pre>BEGIN<br />  DBMS_SQLTUNE.drop_sql_profile (<br />    name   =&gt; 'emp_dept_profile',<br />    ignore =&gt; TRUE);<br />END;<br />/</pre></blockquote>


The <code>IGNORE</code> parameter prevents errors being reported if the specified profile does not exist.<br />



<h2>SQL Tuning Sets</h2>

An SQL tuning set is a group of statements along with their execution
context. These can be created automatically via Enterprise Manager or
manually provided
you have the necessary privileges:<br />


<blockquote><pre>CONN sys/password AS SYSDBA<br />GRANT ADMINISTER ANY SQL TUNING SET TO scott;<br />CONN scott/tiger</pre></blockquote>


An SQL tuning set is created using the <code>CREATE_SQLSET</code> procedure:<br />


<blockquote><pre>BEGIN<br />  DBMS_SQLTUNE.create_sqlset (<br />    sqlset_name  =&gt; 'test_sql_tuning_set',<br />    description  =&gt; 'A test SQL tuning set.');<br />END;<br />/</pre></blockquote>


Statements are added to the set using the <code>LOAD_SQLSET</code> procedure which accepts a <code>REF CURSOR</code> of statements retrieved
using one of the following pipelined functions:<br />


<ul><li><code>SELECT_WORKLOAD_REPOSITORY</code> - Retrieves statements from the Automatic Workload Repository (AWR).</li><li><code>SELECT_CURSOR_CACHE</code> - Retrieves statements from the cursor cache.</li><li><code>SELECT_SQLSET</code> - Retrieves statements from another SQL tuning set.</li></ul>


The following are examples of their usage:<br />


<blockquote><pre>-- Load the SQL set from the Automatic Workload Repository (AWR).<br />DECLARE<br />  l_cursor  DBMS_SQLTUNE.sqlset_cursor;<br />BEGIN<br />  OPEN l_cursor FOR<br />    SELECT VALUE(p)<br />    FROM   TABLE (DBMS_SQLTUNE.select_workload_repository (<br />                    765,  -- begin_snap<br />                    766,  -- end_snap<br />                    NULL, -- basic_filter<br />                    NULL, -- object_filter<br />                    NULL, -- ranking_measure1<br />                    NULL, -- ranking_measure2<br />                    NULL, -- ranking_measure3<br />                    NULL, -- result_percentage<br />                    10)   -- result_limit<br />                  ) p;<br /><br />  DBMS_SQLTUNE.load_sqlset (<br />    sqlset_name     =&gt; 'test_sql_tuning_set',<br />    populate_cursor =&gt; l_cursor);<br />END;<br />/<br /><br />-- Load the SQL set from the cursor cache.<br />DECLARE<br />  l_cursor  DBMS_SQLTUNE.sqlset_cursor;<br />BEGIN<br />  OPEN l_cursor FOR<br />    SELECT VALUE(p)<br />    FROM   TABLE (DBMS_SQLTUNE.select_cursor_cache (<br />                    NULL, -- basic_filter<br />                    NULL, -- object_filter<br />                    NULL, -- ranking_measure1<br />                    NULL, -- ranking_measure2<br />                    NULL, -- ranking_measure3<br />                    NULL, -- result_percentage<br />                    1)    -- result_limit<br />                  ) p;<br /><br />  DBMS_SQLTUNE.load_sqlset (<br />    sqlset_name     =&gt; 'test_sql_tuning_set',<br />    populate_cursor =&gt; l_cursor);<br />END;<br />/<br /><br />-- Create a new set and load it from the existing one.<br />DECLARE<br />  l_cursor  DBMS_SQLTUNE.sqlset_cursor;<br />BEGIN<br />  DBMS_SQLTUNE.create_sqlset(<br />    sqlset_name  =&gt; 'test_sql_tuning_set_2',<br />    description  =&gt; 'Another test SQL tuning set.');<br /><br />  OPEN l_cursor FOR<br />    SELECT VALUE(p)<br />    FROM   TABLE (DBMS_SQLTUNE.select_sqlset (<br />                    'test_sql_tuning_set', -- sqlset_name<br />                    NULL,                  -- basic_filter<br />                    NULL,                  -- object_filter<br />                    NULL,                  -- ranking_measure1<br />                    NULL,                  -- ranking_measure2<br />                    NULL,                  -- ranking_measure3<br />                    NULL,                  -- result_percentage<br />                    NULL)                  -- result_limit<br />                  ) p;<br /><br />  DBMS_SQLTUNE.load_sqlset (<br />    sqlset_name     =&gt; 'test_sql_tuning_set_2',<br />    populate_cursor =&gt; l_cursor);<br />END;<br />/</pre></blockquote>


The contents of an SQL tuning set can be displayed using the <code>SELECT_SQLSET</code> function:<br />


<blockquote><pre>SELECT *<br />FROM   TABLE(DBMS_SQLTUNE.select_sqlset ('test_sql_tuning_set'));</pre></blockquote>


References can be added to a set to indicate its usage by a client using the <code>ADD_SQLSET_REFERENCE</code> function. The resulting reference ID
can be used to remove it using the <code>REMOVE_SQLSET_REFERENCE</code> procedure:<br />


<blockquote><pre>DECLARE<br />  l_ref_id  NUMBER;<br />BEGIN<br />  -- Add a reference to a set.<br />  l_ref_id := DBMS_SQLTUNE.add_sqlset_reference (<br />    sqlset_name =&gt; 'test_sql_tuning_set',<br />    reference   =&gt; 'Used for manual tuning by SQL*Plus.');<br /><br />  -- Delete the reference.<br />  DBMS_SQLTUNE.remove_sqlset_reference (<br />    sqlset_name  =&gt; 'test_sql_tuning_set',<br />    reference_id =&gt; l_ref_id);<br />END;<br />/</pre></blockquote>


The <code>UPDATE_SQLSET</code> procedure is used to update specific string (<code>MODULE</code> and <code>ACTION</code>) and number
(<code>PRIORITY</code> and <code>PARSING_SCHEMA_ID</code>) attributes of specific statements within a set:<br />


<blockquote><pre>BEGIN<br />  DBMS_SQLTUNE.update_sqlset (<br />    sqlset_name     =&gt; 'test_sql_tuning_set',<br />    sql_id          =&gt; '19v5guvsgcd1v',<br />    attribute_name  =&gt; 'ACTION',<br />    attribute_value =&gt; 'INSERT');<br />END;<br />/</pre></blockquote>


The contents of a set can be trimmed down or deleted completely using the <code>DELETE_SQLSET</code> procedure:<br />


<blockquote><pre>BEGIN<br />  -- Delete statements with less than 50 executions.<br />  DBMS_SQLTUNE.delete_sqlset (<br />    sqlset_name  =&gt; 'test_sql_tuning_set',<br />    basic_filter =&gt; 'executions &lt; 50');<br /><br />  -- Delete all statements.<br />  DBMS_SQLTUNE.delete_sqlset (<br />    sqlset_name  =&gt; 'test_sql_tuning_set');<br />END;<br />/</pre></blockquote>


Tuning sets can be dropped using the <code>DROP_SQLSET</code> procedure:<br />


<blockquote><pre>BEGIN<br />  DBMS_SQLTUNE.drop_sqlset (sqlset_name =&gt; 'test_sql_tuning_set');<br />  DBMS_SQLTUNE.drop_sqlset (sqlset_name =&gt; 'test_sql_tuning_set_2');<br />END;<br />/</pre></blockquote>



<h2>Useful Views</h2>


Useful views related to automatic SQL tuning include:<br />


<ul><li><code>DBA_ADVISOR_TASKS</code></li><li><code>DBA_ADVISOR_FINDINGS</code></li><li><code>DBA_ADVISOR_RECOMMENDATIONS</code></li><li><code>DBA_ADVISOR_RATIONALE</code></li><li><code>DBA_SQLTUNE_STATISTICS</code></li><li><code>DBA_SQLTUNE_BINDS</code></li><li><code>DBA_SQLTUNE_PLANS</code></li><li><code>DBA_SQLSET</code></li><li><code>DBA_SQLSET_BINDS</code></li><li><code>DBA_SQLSET_STATEMENTS</code></li><li><code>DBA_SQLSET_REFERENCES</code></li><li><code>DBA_SQL_PROFILES</code></li><li><code>V$SQL</code></li><li><code>V$SQLAREA</code></li><li><code>V$ACTIVE_SESSION_HISTORY</code></li></ul>


For further information see:<br />


<ul><li><a href="http://download-west.oracle.com/docs/cd/B13789_01/server.101/b10752/sql_tune.htm">Automatic SQL Tuning</a></li><li><a href="http://download-west.oracle.com/docs/cd/B13789_01/appdev.101/b10802/d_sqltun.htm">DBMS_SQLTUNE</a></li></ul>


Hope this helps. Regards Tim...<br /><br /><br /><i>From http://jonathanlewis.wordpress.com/2007/02/11/profiles/<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; http://jonathanlewis.wordpress.com/2007/02/12/sql-profiles-2/<br />By Jonathan Lewis</i><br /><br /><h3 class="storytitle"><a href="http://jonathanlewis.wordpress.com/2007/02/11/profiles/" rel="bookmark">SQL Profiles&nbsp;(10g)</a></h3><p>When the <em><strong>Tuning Advisor</strong></em> suggests that you accept a <strong><em>SQL Profile</em></strong>, what is it offering you.&nbsp;If you want to find out, the following SQL seems to be the appropriate query to run <strong><span style="text-decoration: underline;">before</span></strong> you accept the profile:<br />
<span id="more-192"></span></p>
<pre><code><br />select<br />	rat.attr1<br />from<br />	wri$_adv_tasks		tsk,<br />	wri$_adv_rationale	rat<br />where<br />	tsk.name = {sql tuning task name}<br />and	rat.task_id   = tsk.id<br />;<br /></code></pre>
<p>The <em>{sql tuning task name}</em> will be the task name generated
and printed at the top of the Enterprisie Manager screen where you can
see the recommendations. The output might list a few lines like the
following:</p>
<pre><code><br />OPT_ESTIMATE(@"SEL$1",INDEX_SCAN, "REQUESTS"@"SEL$1",REQ_UK,SCALE_ROWS=5.786002118 )<br />OPT_ESTIMATE(@"SEL$1", TABLE, "REQUESTS"@"SEL$1",SCALE_ROWS=0.0004355485551)<br /></code></pre>
<p>These are actually hints - they will be accepted if you include them
in the usual fashion in your SQL (although that wouldn't be a good idea
at present as they are undocumented, unsupported, and liable to change
in their implementation).</p>
<p>Like <strong><em>Stored Outlines</em></strong>, the <strong><em>SQL Profile</em></strong>
consists of a stored SQL statement, and a set of hints that will be
brought into play when that SQL has to be optimised. Unlike <strong><em>Stored Outlines</em></strong>, the hints for <strong><em>SQL Profiles</em></strong>
do not attempt to dictate execution mechanisms directly. Instead they
supply arithmetical correction factors to the optimizer as it does its
arithemetic as, even with a 100% sample size, it is still possible for
the optimizer to misinterpret your statistics and produce an unsuitable
execution path.</p>
<p>In principle, if the data <strong><em>distributions</em></strong> do
not change, then a stored profile will ensure that the optimizer
"understands" your data and does the right thing - even when the data <strong><em>volume</em></strong> changes.</p><br /><h3 class="storytitle"><a href="http://jonathanlewis.wordpress.com/2007/02/12/sql-profiles-2/" rel="bookmark">SQL Profiles -&nbsp;2</a></h3>
	

	
		<p>Following <a href="http://jonathanlewis.wordpress.com/2007/02/11/profiles/" target="_self">yesterday's note </a>on <strong><em>SQL Profiles</em></strong>, someone asked how I detect that an <strong><em>opt_estimate</em></strong> hint had been used - with specific reference to the <strong><em>"index_scan"</em></strong> option. The reason for this particular choice is that other <strong><em>opt_estimate</em></strong> hints have a highly visible impact in the 10053 trace files, but this one doesn't.</p>
<p><span id="more-193"></span>Here are a few extracts from the <strong><em>Single Table Access</em></strong> section of the trace:</p>
<p>a) Following: <strong><em>opt_estimate(@sel$1, table, t1@sel$1, scale_rows=10)</em></strong> (multiply row count by 10)</p>
<pre><code>   Table: T1  Alias: T1<br />    Card: Original: 4000    &gt;&gt; Single Tab Card adjusted from: 10.00  to: 100.00<br />  Rounded: 100  Computed: 100.00  Non Adjusted: 10.00      <br /><br /></code></pre>
<p>b) Following: <strong><em>opt_estimate(@sel$1, join, (t2@sel$1, t1@sel$1), scale_rows=225)</em></strong> (multiply join cardinality by 225)</p>
<pre><code>&gt;&gt; Join Card adjusted from 0.00  to: 1.00, prelen=2<br />Adjusted Join Cards: adjRatio=2666.67 cardHjSmj=1.00 cardHjSmjNPF=1.00<br /></code><code>cardNlj=1.00 cardNSQ=1.00 cardNSQ_na=0.00<br /></code></pre>
<p>As you can see, the impact of the <strong><em>opt_estimate()</em></strong> shows up very clearly in these two cases, but when we try: <em><strong>opt_estimate(@sel$1, index_scan, t1@sel$1, t1_i1, scale_rows=0.05)</strong></em> (divide index selectivity by 20), we have to check the before and after trace files:<br />
Before:</p>
<pre><code>   Access Path: index (AllEqRange)<br />    Index: T1_I1<br />    resc_io: 168.00  resc_cpu: 1278402<br />    ix_sel: 0.05  ix_sel_with_filters: 0.05<br />    Cost: 168.19  Resp: 168.19  Degree: 1<br />  Best:: AccessPath: IndexRange  Index: T1_I1<br />         Cost: 168.19  Degree: 1  Resp: 168.19  Card: 10.00  Bytes: 0     <br /><br /></code></pre>
<p>After:</p>
<pre><code>   Access Path: index (AllEqRange)<br />    Index: T1_I1<br />    resc_io: 12.00  resc_cpu: 89967<br />    ix_sel: 0.0025  ix_sel_with_filters: 0.0025<br />    Cost: 12.01  Resp: 12.01  Degree: 1<br />  Best:: AccessPath: IndexRange  Index: T1_I1<br />         Cost: 12.01  Degree: 1  Resp: 12.01  Card: 10.00  Bytes: 0     <br /><br /></code></pre>
<p>In this case, we don't get any indication of <em>"adjusted values"</em>
- we actually have to check the before and after to see what has
changed - and infer from the drop in cost that we have used a reduced
cardinality. This can be particularly awkward to interpret in cases
where the targetted index is not a suitable candidate for a <em>single table access path</em>, but becomes available as an access path later in the join evolution.</p>DBMS_SQLTUNE.ACCEPT_SQL_PROFILE (<br />task_name =&gt; '',<br />category =&gt; 'MY_CATEGORY');<br /><br />ALTER SESSION SET SQLTUNE_CATEGORY='MY_CATEGORY' ;<br /><br />Once satisfied with Plan, change category to default.<br /><br />Comment by JM -- May 29, 2008 @ 6:27 pm UTC May 29,2008 <br /><br />Yuri,<br /><br />The view dba_sql_profiles lists the profiles. The text of the query is stored as a CLOB column called sql_text in this view.<br /><br />If you have lots of profiles and it's hard to find the relevant profile by querying this table, you could use explain plan to generate an execution plan for the query. It should report (in the notes section) something like:<br /><br />SQL profile "SYS_SQLPROF_01456abbc16a4000″ used for this statement<br /><br />I think the value reported is stored as the name in the view.<br /><br />Comment by Jonathan Lewis -- January 28, 2008 @ 10:25 pm UTC Jan 28,2008<br /><br />Thank for your answer!<br />But I'm interest in some different thing.<br />I'm curious in which form does the SQL Profile been stored?<br />And upon which SQL Profile information bases the cardinality adjustment done<br />by CBO,<br />such as "Single Tab Card adjusted from:11.441291 to:28.000000″.<br />I know some about SQL Profile, for example<br /><br />SQL&gt; select p.other_xml<br />2 from dba_sqltune_plans p, dba_sql_profiles s<br />3 where p.task_id=s.task_id<br />4 and s.name='profile_lastdoc_1′<br />5 and p.attribute='Using SQL profile'<br />6 and p.id=1;<br /><br />But in this column I can`t find anything about cardinality adjustment factor.<br /><br />Comment by Yuri A.P. -- January 29, 2008 @ 8:39 pm UTC Jan 29,2008<br /><br />The content of the SQL profile is not stored in a "public" view, but it can be found in table sql$profattr - for example:<br /><br />select<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sp.sp_name, sa.attr#, sa.attr_val<br />from<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sqlprof$&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sp,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sqlprof$attr&nbsp; sa<br />where<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sp.signature = sa.signature<br />and&nbsp;&nbsp;&nbsp;&nbsp; sp.category&nbsp; = sp.category<br />order by<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sp.sp_name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sa.attr#<br />;<br /><br />SP_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ATTR#<br />------------------------------ ----------<br />ATTR_VAL<br />-------------------------------------------------------------------------<br />SYS_SQLPROF_0145f1e5167c4000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br />OPT_ESTIMATE(@"SEL$1", JOIN, ("T2"@"SEL$1", "T1"@"SEL$1"), SCALE_ROWS=15)<br /><br />SYS_SQLPROF_0145f1e5167c4000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<br />OPT_ESTIMATE(@"SEL$1", TABLE, "T2"@"SEL$1", SCALE_ROWS=200)<br /><br />SYS_SQLPROF_0145f1e5167c4000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3<br />OPTIMIZER_FEATURES_ENABLE(default)<br /><br />In this example, we have two adjustments - the single table cardinality of table t2 in query block sel$1 should be multiplied by 200; and the join cardinality of (t1,t2) when they are joined in query block sel$1 should be multiplied by 15.<br /><br />Comment by Jonathan Lewis -- January 29, 2008 @ 10:22 pm UTC Jan 29,2008<br /><br />Thank you very much!<br />By the way, I have discovered that on 11g database such information can be retrieved from non-documented view DBMSHSXP_SQL_PROFILE_ATTR.<br /><br />Comment by Yuri A.P. -- January 30, 2008 @ 8:34 pm UTC Jan 30,2008<br /><br /><br /><font face="helvetica"><table border="0" cellpadding="0" cellspacing="6" width="80%"><tbody><tr><td align="right" valign="top">Subject: </td>
<td colspan="4" align="left"><strong>Automatic SQL Tuning - SQL Profiles</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="right" valign="top"><a href="https://metalink.oracle.com/help/usaeng/Search/search.html#file">Doc ID</a>: </td>
<td align="left"><strong>Note:271196.1</strong></td>
<td align="right" valign="top">Type: </td>
<td align="left"><strong>BULLETIN</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="right" valign="top">Last Revision Date: </td>
<td align="left"><strong>29-JUL-2008</strong></td>
<td align="right" valign="top">Status: </td>
<td align="left"><strong>PUBLISHED</strong></td>
</tr>
</tbody></table>
</font>
<pre><font face="courier"><br />Checked for relevance on 12-May-2008.<br /><br />Clarification/Explanation<br />==========================<br /><br />The query optimizer can sometimes produce inaccurate estimates about <br />an attribute of a statement due to lack of information,leading to poor<br />execution plans.  Traditionally, users have corrected  this problem by<br />manually adding hints to the application code to guide the optimizer <br />into making correct decisions. For packaged applications, changing <br />application code is not an option and the only alternative available <br />is to log a bug with the application vendor and wait for a fix.<br /><br />Automatic SQL Tuning deals with this problem with its SQL Profiling <br />capability. The Automatic Tuning Optimizer creates a profile of the <br />SQL statement called a SQL Profile, consisting of auxiliary statistics <br />specific to that statement. The query optimizer under normal mode makes <br />estimates about cardinality, selectivity, and cost that can sometimes be <br />off by a significant amount resulting in poor execution plans. SQL Profile <br />addresses this problem by collecting additional information using<br />sampling and partial execution techniques to verify and, if necessary, <br />adjust these estimates.<br /><br />During SQL Profiling, the Automatic Tuning Optimizer also uses execution<br />history information of the SQL statement to appropriately set optimizer <br />parameter settings, such as changing the OPTIMIZER_MODE initialization <br />parameter setting from ALL_ROWS to FIRST_ROWS for that SQL statement.<br /><br />The output of this type of analysis is a recommendation to accept the <br />SQL Profile. A SQL Profile, once accepted, is stored persistently in <br />the data dictionary. Note that the SQL Profile is specific to a <br />particular query. If accepted, the optimizer under normal mode uses the <br />information in the SQL Profile in conjunction with regular<br />database statistics when generating an execution plan. <br />The availability of the additional information makes it possible<br />to produce well-tuned plans for corresponding SQL statement without<br />requiring any change to the application code.<br /><br />The scope of a SQL Profile can be controlled by the CATEGORY profile attribute. <br />This attribute determines which user sessions can apply the profile. <br />You can view the CATEGORY attribute for a SQL Profile in CATEGORY column <br />of the DBA_SQL_PROFILES view. By default, all profiles are created in the <br />DEFAULT category. This means that all user sessions where the SQLTUNE_CATEGORY <br />initialization parameter is set to DEFAULT can use the profile.<br /><br />By altering the category of a SQL profile, you can determine which sessions are <br />affected by the creation of a profile. For example, by setting the category <br />of a SQL Profile to DEV, only those users sessions where the SQLTUNE_CATEGORY <br />initialization parameter is set to DEV can use the profile. All other sessions <br />do not have access to the SQL Profile and execution plans for SQL statements <br />are not impacted by the SQL profile. This technique enables you to test <br />a SQL Profile in a restricted environment before making it available to other <br />user sessions.<br /><br />It is important to note that the SQL Profile does not freeze the execution plan<br />of a SQL statement, as done by stored outlines. As tables grow or indexes <br />are created or dropped, the execution plan can change with the same SQL Profile. <br />The information stored in it continues to be relevant even as the data <br />distribution or access path of the corresponding statement change. <br />However, over a long period of time, its content can become outdated and <br />would have to be regenerated. This can be done by running Automatic <br />SQL Tuning again on the same statement to regenerate the SQL Profile.<br /><br />SQL Profiles apply to the following statement types:<br /><br />     SELECT statements <br />     UPDATE statements <br />     INSERT statements (only with a SELECT clause) <br />     DELETE statements <br />     CREATE TABLE statements (only with the AS SELECT clause) <br />     MERGE statements (the update or insert operations)<br /><br />Managing SQL Profiles<br />=====================<br /><br />While SQL Profiles are usually handled by Oracle Enterprise Manager as part <br />of the Automatic SQL Tuning process, SQL Profiles can be managed through the<br />DBMS_SQLTUNE package. To use the SQL Profiles APIs, you need the <br />CREATE ANY SQL_PROFILE, DROP ANY SQL_PROFILE, and ALTER ANY SQL_PROFILE<br />system privileges.<br /><br />Accepting a SQL Profile<br />=======================<br /><br />You can use the DBMS_SQLTUNE.ACCEPT_SQL_PROFILE procedure to accept a <br />SQL Profile recommended by the SQL Tuning Advisor. This creates and stores a<br />SQL Profile in the database. For example:<br /><br />DECLARE<br /> my_sqlprofile_name VARCHAR2(30);<br />BEGIN<br /> my_sqlprofile_name := DBMS_SQLTUNE.ACCEPT_SQL_PROFILE ( <br />    task_name =&gt; 'my_sql_tuning_task',<br />    name      =&gt; 'my_sql_profile');<br />END;<br /><br /><br />Where my_sql_tuning_task is the name of the SQL tuning task.<br />You can view information about a SQL Profile in the DBA_SQL_PROFILES view.<br /><br />Altering a SQL Profile<br />======================<br /><br />You can alter the STATUS, NAME, DESCRIPTION, and CATEGORY attributes of <br />an existing  SQL Profile with the ALTER_SQL_PROFILE procedure. For example:<br /><br />BEGIN<br />  DBMS_SQLTUNE.ALTER_SQL_PROFILE(<br />     name            =&gt; 'my_sql_profile', <br />     attribute_name  =&gt; 'STATUS', <br />     value           =&gt; 'DISABLED');<br />END;<br />/<br /><br /><br />In this example, my_sql_profile is the name of the SQL Profile that you want to alter. <br />The status attribute is changed to disabled which means the SQL Profile is<br />not used during SQL compilation.<br /><br />Dropping a SQL Profile<br />======================<br />You can drop a SQL Profile with the DROP_SQL_PROFILE procedure. For example:<br /><br />BEGIN<br />  DBMS_SQLTUNE.DROP_SQL_PROFILE(name =&gt; 'my_sql_profile');<br />END;<br />/<br /><br /><br />In this example, my_sql_profile is the name of the SQL Profile you want to drop. <br />You can also specify whether to ignore errors raised if the name does not exist.<br />For this example, the default value of FALSE is accepted.<br /><br />Example<br />=======<br /><br />SESSION 1 -- SCOTT<br />=========<br /><br />SQL&gt; create table test (n number );<br /><br />Table created.<br /><br />declare<br />begin<br />for i in 1 .. 10000<br />loop<br />insert into test values(i);<br />commit;<br />end loop;<br />end;<br /><br />PL/SQL procedure successfully completed.<br /><br /><br />create index test_idx on test(n);<br /><br />Index created.<br /><br /><br />analyze table test estimate statistics (OR use dbms_stats)<br /><br />Table analyzed.<br /><br /><br />select /*+ no_index(test test_idx) */ * from test where n=1<br /><br />Execution Plan<br />----------------------------------------------------------<br />   0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=1 Bytes=13)<br />   1    0   TABLE ACCESS (FULL) OF 'TEST' (TABLE) (Cost=6 Card=1 Bytes<br />          =13)<br /><br /><br /><br />SESSION 2  -- SYS<br />=========<br /><br />  1  DECLARE<br />  2   my_task_name VARCHAR2(30);<br />  3   my_sqltext   CLOB;<br />  4  BEGIN<br />  5   my_sqltext := 'select /*+ no_index(test test_idx) */ * from test where n=<br />1';<br />  6   my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(<br />  7           sql_text    =&gt; my_sqltext,<br />  8           user_name   =&gt; 'SCOTT',<br />  9           scope       =&gt; 'COMPREHENSIVE',<br /> 10           time_limit  =&gt; 60,<br /> 11           task_name   =&gt; 'my_sql_tuning_task_2',<br /> 12           description =&gt; 'Task to tune a query on a specified table');<br /> 13* END;<br /> 14  /<br /><br />PL/SQL procedure successfully completed.<br /><br /><br />  1  BEGIN<br />  2    DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name =&gt; 'my_sql_tuning_task_2');<br />  3* end;<br />SQL&gt; /<br /><br />PL/SQL procedure successfully completed.<br /><br /><br />  1  SET LONG 1000<br />  2  SET LONGCHUNKSIZE 1000<br />  3  SET LINESIZE 100<br />  4* SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK( 'my_sql_tuning_task_2') from DUAL;<br /><br /><br /><br />DBMS_SQLTUNE.REPORT_TUNING_TASK('MY_SQL_TUNING_TASK_2')<br />--------------------------------------------------------------------------------<br />--------------------<br />GENERAL INFORMATION SECTION<br />-------------------------------------------------------------------------------<br />Tuning Task Name   : my_sql_tuning_task_2<br />Scope              : COMPREHENSIVE<br />Time Limit(seconds): 60<br />Completion Status  : COMPLETED<br />Started at         : 05/04/2004 17:36:05<br />Completed at       : 05/04/2004 17:36:05<br /><br />-------------------------------------------------------------------------------<br />SQL ID  : d4wgpc5g0s0vu<br /><br />DBMS_SQLTUNE.REPORT_TUNING_TASK('MY_SQL_TUNING_TASK_2')<br />--------------------------------------------------------------------------------<br />--------------------<br />SQL Text: select /*+ no_index(test test_idx) */ * from test where n=1<br /><br />-------------------------------------------------------------------------------<br />FINDINGS SECTION (1 finding)<br />-------------------------------------------------------------------------------<br /><br />1- SQL Profile Finding (see explain plans section below)<br />--------------------------------------------------------<br />  A potentially better execution plan was found for this statement.<br /><br />  Recommendation (estimated benefit: 83.84%)<br /><br />DBMS_SQLTUNE.REPORT_TUNING_TASK('MY_SQL_TUNING_TASK_2')<br />--------------------------------------------------------------------------------<br />--------------------<br />  ------------------------------------------<br />    Consider accepting the recommended<br /><br /><br />  1  DECLARE<br />  2   my_sqlprofile_name VARCHAR2(30);<br />  3  BEGIN<br />  4   my_sqlprofile_name := DBMS_SQLTUNE.ACCEPT_SQL_PROFILE (<br />  5      task_name =&gt; 'my_sql_tuning_task_2',<br />  6      name      =&gt; 'my_sql_profile');<br />  7* END;<br />  8  /<br /><br />PL/SQL procedure successfully completed.<br /><br /><br />SQL&gt; select to_char(sql_text) from           dba_sql_profiles;<br /><br />TO_CHAR(SQL_TEXT)<br />------------------------------------------------------------------------<br />select /*+ no_index(test test_idx) */ * from test where n=1<br /><br /><br />SESSION 1 --- SCOTT<br /><br /><br />SQL&gt; select /*+ no_index(test test_idx) */ * from test where n=1;<br /><br />Execution Plan<br />----------------------------------------------------------<br />   0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=1 Card=1 Bytes=13)<br />   1    0   INDEX (RANGE SCAN) OF 'TEST_IDX' (INDEX) (Cost=1 Card=1 By<br />          tes=13<br /><br /><br />From http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:61313086268493<br /><br /></font></pre>Rasin -- Thanks for the question regarding "SQL Profiles", version 10.2<br /><br />You Asked<br /><br />Tom, <br />can you explain what are SQL Profiles, what are they used for how the CBO uses them and <br />how can we utilize this feature.<br /><br />Thanks.<br />&nbsp;<br />and we said...<br /><br />Ok, this is my conceptual explanation.&nbsp; <br /><br />In the past, the DBA could analyze single 'things'<br /><br />the DBA could analyze A TABLE - finding the number of blocks, rows, things like that.&nbsp; <br />about A TABLE.<br /><br />the DBA could analyze A COLUMN - get histograms, high/low values, number of distinct <br />values, things like that - about A COLUMN<br /><br />the DBA could analyze AN INDEX - get keys/get, leaf blocks, height, clustering factor.<br /><br />the DBA could analyze A SYSTEM - find the single block IO time, the multi-block IO time, <br />cpu speed and so on.<br /><br /><br />But - most of our queries (many of them) involve more than A TABLE, A COLUMN, AN INDEX, <br />and so on... They are complex.<br /><br />For example (blatant theft of example from Jonathan Lewis here - his CBO book is awesome, <br />I remember him first using this example in 2003 at the NoCoug meeting...)<br /><br />o How many of you are Pisces?&nbsp; 1/12th of the room will raise hands.<br /><br />o How many of you are born in December?&nbsp; 1/12 of the room will raise hands.<br /><br /><br />Now, how many of you Pisces were born in December?&nbsp; (silence, none of them are - I know, <br />I am Pisces :)<br /><br />Now, ask the optimizer!<br /><br /><br />ops$tkyte@ORA10GR2&gt; create table t<br />&nbsp; 2&nbsp; as<br />&nbsp; 3&nbsp; select decode( mod(rownum,12), 0, 'Capricorn',<br />&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1, 'Gemini',<br />&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2, 'Libra',<br />&nbsp; 6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3, 'Aquarius',<br />&nbsp; 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4, 'Cancer',<br />&nbsp; 8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5, 'Scorpio',<br />&nbsp; 9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6, 'Pisces',<br />&nbsp;10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7, 'Ariea',<br />&nbsp;11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8, 'Leo',<br />&nbsp;12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9, 'Sagittarius',<br />&nbsp;13&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10, 'Taurus',<br />&nbsp;14&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 11, 'Virgo' ) zodiac,<br />&nbsp;15&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add_months( to_date( '01-jan-2006' ), mod(rownum,12) ) dob<br />&nbsp;16&nbsp;&nbsp;&nbsp; from all_objects<br />&nbsp;17&nbsp; /<br /><br />Table created.<br /><br />ops$tkyte@ORA10GR2&gt;<br />ops$tkyte@ORA10GR2&gt; exec dbms_stats.gather_table_stats( user, 'T', method_opt=&gt; 'for all <br />columns size 254' );<br /><br />PL/SQL procedure successfully completed.<br /><br />ops$tkyte@ORA10GR2&gt;<br />ops$tkyte@ORA10GR2&gt; set autotrace traceonly explain<br />ops$tkyte@ORA10GR2&gt; select * from t;<br /><br />Execution Plan<br />----------------------------------------------------------<br />Plan hash value: 1601196873<br /><br />--------------------------------------------------------------------------<br />| Id&nbsp; | Operation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Name | Rows&nbsp; | Bytes | Cost (%CPU)| Time&nbsp;&nbsp;&nbsp;&nbsp; |<br />--------------------------------------------------------------------------<br />|&nbsp;&nbsp; 0 | SELECT STATEMENT&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 51292 |&nbsp;&nbsp; 751K|&nbsp;&nbsp;&nbsp; 52&nbsp;&nbsp; (6)| 00:00:01 |<br />|&nbsp;&nbsp; 1 |&nbsp; TABLE ACCESS FULL| T&nbsp;&nbsp;&nbsp; | 51292 |&nbsp;&nbsp; 751K|&nbsp;&nbsp;&nbsp; 52&nbsp;&nbsp; (6)| 00:00:01 |<br />--------------------------------------------------------------------------<br /><br />ops$tkyte@ORA10GR2&gt; select * from t where zodiac = 'Pisces';<br /><br />Execution Plan<br />----------------------------------------------------------<br />Plan hash value: 1601196873<br /><br />--------------------------------------------------------------------------<br />| Id&nbsp; | Operation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Name | Rows&nbsp; | Bytes | Cost (%CPU)| Time&nbsp;&nbsp;&nbsp;&nbsp; |<br />--------------------------------------------------------------------------<br />|&nbsp;&nbsp; 0 | SELECT STATEMENT&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp; 4107 | 61605 |&nbsp;&nbsp;&nbsp; 53&nbsp;&nbsp; (8)| 00:00:01 |<br />|*&nbsp; 1 |&nbsp; TABLE ACCESS FULL| T&nbsp;&nbsp;&nbsp; |&nbsp; 4107 | 61605 |&nbsp;&nbsp;&nbsp; 53&nbsp;&nbsp; (8)| 00:00:01 |<br />--------------------------------------------------------------------------<br /><br />Predicate Information (identified by operation id):<br />---------------------------------------------------<br /><br />&nbsp;&nbsp; 1 - filter("ZODIAC"='Pisces')<br /><br />ops$tkyte@ORA10GR2&gt; select * from t where dob = to_date( '01-dec-2006' );<br /><br />Execution Plan<br />----------------------------------------------------------<br />Plan hash value: 1601196873<br /><br />--------------------------------------------------------------------------<br />| Id&nbsp; | Operation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Name | Rows&nbsp; | Bytes | Cost (%CPU)| Time&nbsp;&nbsp;&nbsp;&nbsp; |<br />--------------------------------------------------------------------------<br />|&nbsp;&nbsp; 0 | SELECT STATEMENT&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp; 4494 | 67410 |&nbsp;&nbsp;&nbsp; 53&nbsp;&nbsp; (8)| 00:00:01 |<br />|*&nbsp; 1 |&nbsp; TABLE ACCESS FULL| T&nbsp;&nbsp;&nbsp; |&nbsp; 4494 | 67410 |&nbsp;&nbsp;&nbsp; 53&nbsp;&nbsp; (8)| 00:00:01 |<br />--------------------------------------------------------------------------<br /><br />Predicate Information (identified by operation id):<br />---------------------------------------------------<br /><br />&nbsp;&nbsp; 1 - filter("DOB"=TO_DATE('2006-12-01 00:00:00', 'yyyy-mm-dd<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hh24:mi:ss'))<br /><br />ops$tkyte@ORA10GR2&gt; select * from t where zodiac = 'Pisces' and dob = to_date( <br />'01-dec-2006' );<br /><br />Execution Plan<br />----------------------------------------------------------<br />Plan hash value: 1601196873<br /><br />--------------------------------------------------------------------------<br />| Id&nbsp; | Operation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Name | Rows&nbsp; | Bytes | Cost (%CPU)| Time&nbsp;&nbsp;&nbsp;&nbsp; |<br />--------------------------------------------------------------------------<br />|&nbsp;&nbsp; 0 | SELECT STATEMENT&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp; 360 |&nbsp; 5400 |&nbsp;&nbsp;&nbsp; 53&nbsp;&nbsp; (8)| 00:00:01 |<br />|*&nbsp; 1 |&nbsp; TABLE ACCESS FULL| T&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp; 360 |&nbsp; 5400 |&nbsp;&nbsp;&nbsp; 53&nbsp;&nbsp; (8)| 00:00:01 |<br />--------------------------------------------------------------------------<br /><br />Predicate Information (identified by operation id):<br />---------------------------------------------------<br /><br />&nbsp;&nbsp; 1 - filter("ZODIAC"='Pisces' AND "DOB"=TO_DATE('2006-12-01<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:00', 'yyyy-mm-dd hh24:mi:ss'))<br /><br /><br />We can sort of see this with dynamic sampling - which is *similar* to a sql profile, <br />but not stored like a profile would be:<br /><br /><br />ops$tkyte@ORA10GR2&gt; select /*+ dynamic_sampling( t 4 ) */ * from t where zodiac = <br />'Pisces' and dob = to_date( '01-dec-2006' );<br /><br />Execution Plan<br />----------------------------------------------------------<br />Plan hash value: 1601196873<br /><br />--------------------------------------------------------------------------<br />| Id&nbsp; | Operation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Name | Rows&nbsp; | Bytes | Cost (%CPU)| Time&nbsp;&nbsp;&nbsp;&nbsp; |<br />--------------------------------------------------------------------------<br />|&nbsp;&nbsp; 0 | SELECT STATEMENT&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; 1 |&nbsp;&nbsp;&nbsp; 15 |&nbsp;&nbsp;&nbsp; 53&nbsp;&nbsp; (8)| 00:00:01 |<br />|*&nbsp; 1 |&nbsp; TABLE ACCESS FULL| T&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; 1 |&nbsp;&nbsp;&nbsp; 15 |&nbsp;&nbsp;&nbsp; 53&nbsp;&nbsp; (8)| 00:00:01 |<br />--------------------------------------------------------------------------<br /><br />Predicate Information (identified by operation id):<br />---------------------------------------------------<br /><br />&nbsp;&nbsp; 1 - filter("ZODIAC"='Pisces' AND "DOB"=TO_DATE('2006-12-01<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:00', 'yyyy-mm-dd hh24:mi:ss'))<br /><br />Note<br />-----<br />&nbsp;&nbsp; - dynamic sampling used for this statement<br /><br />ops$tkyte@ORA10GR2&gt; set autotrace off<br /><br />the optimizer ran this query for us to parse:<br /><br />SELECT /* OPT_DYN_SAMP */ /*+ ALL_ROWS opt_param('parallel_execution_enabled',<br />&nbsp;&nbsp; 'false') NO_PARALLEL(SAMPLESUB) NO_PARALLEL_INDEX(SAMPLESUB) NO_SQL_TUNE<br />&nbsp; */ NVL(SUM(C1),:"SYS_B_0"), NVL(SUM(C2),:"SYS_B_1")<br />FROM<br />&nbsp;(SELECT /*+ NO_PARALLEL("T") FULL("T") NO_PARALLEL_INDEX("T") */ :"SYS_B_2"<br />&nbsp; AS C1, :"SYS_B_3" AS C2&nbsp; FROM "T" "T" WHERE "T"."ZODIAC"=:"SYS_B_4" AND<br />&nbsp; "T"."DOB"=TO_DATE(:"SYS_B_5", :"SYS_B_6")) SAMPLESUB<br /><br /><br />and used the results of that as the estimated cardinality.&nbsp; SQL profiles would do the <br />same - but would look at the entire query - cross table, column, whatever and do partial <br />executes on it (try out the data in your database) and remember that in the dictionary as <br />extended statistics.<br /><br />It can use that next time to parse and optimize the query.<br /><br />It'll remember other things too - like "this query is used to retrieve just the first <br />rows, we should not optimize for all rows, but first rows - let us remember that in the <br />future..."<br /><br />So, a SQL profile is sort of like gathering statistics on A QUERY - which involves many <br />tables, columns and the like....<br /><br />In fact - it is just like gathering statistics for a query, it stores additional <br />information in the dictionary which the optimizer uses at optimization time to determine <br />the correct plan.&nbsp; The SQL Profile is not "locking a plan in place", but rather giving <br />the optimizer yet more bits of information it can use to get the right plan.<br /><br />SQL PROFILES&nbsp;&nbsp; <br />Reviewer: Mark <br /><br />Tom,<br /><br />Do SQL Profiles get stale?&nbsp; If so, is there some way to refresh stale profiles like we do for <br />stats?<br /><br />Thanks for your time..<br /><br />Followup&nbsp;&nbsp; April 2, 2008 - 1pm US/Eastern:<br />you re-profile the sql statement.<br /><br />Yes, they can get "stale" - basically, sql profiles are better estimated cardinality values - better in that they are based on sampling your where clause - not based on basic 'statistical projection'.<br /><br />and if the underlying data changes - well, then they (the better card=values) would become wrong.<br /><br />Eg: if someone changes the zodiac lookup table so that pisces are born in december, the sample we ran that says "zero are" would be wrong<br /><br />sql profile vs Sql plan management of 11g&nbsp; <br />Reviewer: Aman Sharma from India<br /><br />Hi&nbsp; sir,<br />Its an excellent explanation.Can you please explain the difference in the sql profiles and sql plan <br />management /sql baselines of 11g ?<br />regards<br />Aman....<br /><br />Followup&nbsp;&nbsp; April 3, 2008 - 8pm US/Eastern:<br />the sql baselines is more akin to storing query plans and ensuring those plans are used. they are the baseline plans..<br /><br />sql profiles are what they are - cardinality information, subject to influencing a plan, but not dictating it.<br /><br /><br /><i>From http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:729346500346644123</i><br /><br />Joe -- Thanks for the question regarding "10g SQL Profiles", version 10.2<br /><br />You Asked<br />Can you explain how SQL profiles work when it comes to recommendations from the SQL Tuning Advisor in 10g?<br /><br />Thanks in advance.<br /><br />and we said...<br /><br />simply put:<br /><br />sql profiles work by taking the query itself and doing partial executions of various predicates - and remembering the ACTUAL card= values (cardinality values) and hinting the query so that it *KNOWS* "this step will return about 5 records, not the 50,000 you guessed at, but only 5"<br /><br />and the next time the query is hard parsed, we use those card= values to come up with the best plan.<br /><br />the key is to get the CORRECT card=value numbers, when we get the right number - you get the right plan. When we get the wrong number - that is when you see suboptimal plans.<br /><br />So, sql profiles simply take the query - execute bits of it, figure out how many rows are actually returned (or look at the execution HISTORY to see how many rows are actually flowing from the row sources as well) and STORE that information as extended statistics - and use that information the next time the query is hard parsed<br /><br />Profiles<br />Reviewer: Dana from Phoenix, AZ USA<br /><br />Are SQL Profiles an extension of sql outlines? <br />Many of the features sound similar or same.<br /><br />Followup&nbsp;&nbsp; March 26, 2008 - 8am US/Eastern:<br /><br />similar, but not the same.<br /><br />stored outlines are a set of hints that say "use this index, do this table first, do that next, use this access path, perform this filter then that filter"....<br /><br />sql profiles are more like extended statistics - they are the result of "analyzing a query", the information provided to the optimizer is not HOW to perform the query - but rather better information about how many rows will flow out of a step in the plan, how selective something is.<br /><br />say you have a query, you generate a stored outline for it. You now add an index to the underlying table. This index would be GREAT for the query. A stored outline won't use it, the stored outline says "use this index - query that table - then do this". Since the GREAT index did not exist when the outline was generated - it won't be used.<br /><br />say you have a query, you generate a profile for it. You now add an index to the underlying table. This index would be GREAT for the query. A profile can use it - since the profile is just more information for the CBO - better cardinality estimates.<br /><br /><br /><span class="mt-enclosure mt-enclosure-file" style="display: inline;"><a href="http://www.heysky.net/digest/uploads/2008/SQLProfiles_20060622.pdf">SQLProfiles_20060622.pdf</a></span><br /> <pre><font face="courier"><br /></font></pre><div><br /></div>]]>
    </content>
</entry>

<entry>
    <title>Hashing in Oracle</title>
    <link rel="alternate" type="text/html" href="http://www.heysky.net/digest/2008/07/hashing-in-oracle.html" />
    <id>tag:www.heysky.net,2008:/digest//1.328</id>

    <published>2008-07-29T22:26:28Z</published>
    <updated>2008-07-29T22:30:43Z</updated>

    <summary><![CDATA[From http://www.dbasupport.com/oracle/ora10g/hash.shtml &nbsp; Hashing in Oracle Steve Callan, stevencallan@hotmail.com The internal workings of the Oracle RDBMS are a marvel to behold. Think about all of the things you do know with respect to what it takes to issue a select...]]></summary>
    <author>
        <name>Sky</name>
        <uri>http://www.heysky.net</uri>
    </author>
    
        <category term="Oracle" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="10g" label="10g" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="hash" label="hash" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="oracle" label="Oracle" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="_bloom_filter_enabled" label="_BLOOM_FILTER_ENABLED" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.heysky.net/digest/">
        <![CDATA[<p><em>From </em><a href="http://www.dbasupport.com/oracle/ora10g/hash.shtml"><em>http://www.dbasupport.com/oracle/ora10g/hash.shtml</em></a></p>
<p>&nbsp;</p>
<p>Hashing in Oracle <br />Steve Callan, <a href="mailto:stevencallan@hotmail.com">stevencallan@hotmail.com</a> </p>
<p>The internal workings of the Oracle RDBMS are a marvel to behold. Think about all of the things you do know with respect to what it takes to issue a select statement, perform an update, or create a table. Latches, locks, serialization, caching, pinning, flushing, checkpointing, sorting, space management, undo, redo, and the list goes on and on. Aside from visible functions, there are a slew of transparent operations. Many of these transparent operations, as the adjective implies, not only work behind the scenes, but also stay there. There are also operations whose work is largely hidden, but whose results are exposed to us. One such operation found in several key areas of how Oracle works is hashing.</p>]]>
        <![CDATA[<p>What is Hashing?<br />Hash isn't a formal term, but more of a description for what takes place: chop and mix. A hash function returns a value for an input, and the output is generally shorter or more compact than the input. For a relatively simple hash function, there is no guarantee that inputs map one to one for outputs, that is, two different inputs can have the same hashed output value. Add more sophistication to the hash function, or add yet another hashing, and the probability of two distinct inputs having the same hashed output can be greatly decreased.</p>
<p>Before getting more into where hashing takes place in Oracle, let's look at some examples of how hashing is used. A good general overview of hashing and various types of hashing can be found at a Mathematica site. The table of names takes the sum of the ASCII values of each letter, sums them, and then lists the mod 13 remainder. The table is reproduced below with an additional column to help illustrate what is taking place. I also provided some code to help reproduce the results.</p>
<p>create table hash_example<br />(lastname varchar2(12),<br />&nbsp; ascii_sum number,<br />&nbsp; hashed_value number);<br />insert into hash_example (lastname) values ('Brecker');<br />insert into hash_example (lastname) values ('Corea');<br />insert into hash_example (lastname) values ('Davis');<br />insert into hash_example (lastname) values ('Hancock');<br />insert into hash_example (lastname) values ('Harris');<br />insert into hash_example (lastname) values ('Marsalis');<br />insert into hash_example (lastname) values ('Parker');<br />commit;</p>
<p>declare<br />&nbsp; cursor c is<br />&nbsp; select lower(lastname) lastname <br />&nbsp; from hash_example <br />&nbsp; for update;<br />&nbsp; l_name hash_example.lastname%type;<br />&nbsp; l_sum hash_example.ascii_sum%type := 0;<br />&nbsp; l_tmp number := 0;<br />begin<br />&nbsp; for r in c loop<br />&nbsp;&nbsp;&nbsp; for i in 1..length(r.lastname) loop<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; l_tmp := ascii(substr(r.lastname,i,1));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; l_sum := l_sum + l_tmp;<br />&nbsp;&nbsp;&nbsp; end loop;<br />&nbsp;&nbsp;&nbsp; update hash_example<br />&nbsp;&nbsp;&nbsp; set ascii_sum = l_sum,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hashed_value = mod(l_sum,13)<br />&nbsp;&nbsp;&nbsp; where current of c;<br />&nbsp;&nbsp;&nbsp; l_tmp := 0;<br />&nbsp;&nbsp;&nbsp; l_sum := 0;<br />&nbsp; end loop;<br />end;<br />/</p>
<p>PL/SQL procedure successfully completed.</p>
<p>SQL&gt; select * from hash_example;</p>
<p>LASTNAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ASCII_SUM HASHED_VALUE<br />------------ ---------- ------------<br />Brecker&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 734&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6<br />Corea&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 522&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<br />Davis&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 535&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<br />Hancock&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 727&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 12<br />Harris&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 649&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 12<br />Marsalis&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 860&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<br />Parker&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 645&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8</p>
<p><br />Overall, this was a pretty simple example. Given that you can pass in a value and get an output based on the hashing algorithm, and that the output is like a fingerprint of the original data, how do you think this can applied to a real table? Suppose you have a table that contains employee identification numbers along with salaries. Aside from using an already built in hashing function (e.g., SHA-1), you could devise a function to hash the combined employee ID and salary values. This hashed value could be stored elsewhere, and then auditing of the table would compare the current values and the stored values. Any (unknown) change in the fingerprint would be cause for concern. This is just one safeguard, and no doubt, you'd want to have some auditing (before the fact, not after!) on a sensitive table like this.</p>
<p>Hashing in a Database<br />So far, we've seen two uses of hashing that can be applied to a database. In the first example, a hashed value of some key attribute can be used for indexing (the hashed value points back to several values), and in the second example, hashing can be used as a comparison tool. These two concepts lend themselves to extensive use within Oracle.</p>
<p>How does Oracle know if a SQL statement is new or already parsed? A parsed statement has a hash value that is by and large unique enough (collisions, or same output for different inputs can happen, but are rare). Shown below is an extract from a trace file, and the lines show each statement's identifying information.</p>
<p>1 PARSING IN CURSOR #1 len=46 dep=0 uid=5 hv=810835083 ad='1d9cd494'</p>
<p>&nbsp; select ename from scott.emp where empno = 7369<br />&nbsp;<br />2 PARSING IN CURSOR #2 len=46 dep=0 uid=5 hv=1290101743 ad='1d9cca00'</p>
<p>&nbsp; select ename from scott.emp where empno = 7499<br />&nbsp;<br />3 PARSING IN CURSOR #1 len=46 dep=0 uid=5 hv=1589217292 ad='1d9cc7c4'</p>
<p>&nbsp; SELECT ENAME FROM SCOTT.EMP WHERE 7499 = EMPNO<br />&nbsp;<br />4 PARSING IN CURSOR #2 len=46 dep=0 uid=5 hv=810835083 ad='1d9cd494'</p>
<p>&nbsp; select ename from scott.emp where empno = 7369<br />&nbsp;<br />Statements 1, 2 and 3 are different, so each has its own hashed value (the hv value). Statements 1 and 4 are the same, and note both have the same hv value. One of the more desirable characteristics of a hashing function is that it should be quite fast and inexpensive to perform. If your statement has already been parsed (has a hash ID value), then a comparison is all that is needed. As pointed out in numerous other sources, hard parsing is undesirable. Re-use of statements can be accomplished two ways. One is via the use of bind variables, and the other is to embed commonly used statements in functions or procedures.</p>
<p>Where else is hashing used? Hash partitioning is useful for data that doesn't cleanly fall into categories such as range or list. Composite partitioning such as range-hash can be used to further categorized and distribute data. In these examples, the indexing feature or benefit is being used. Since this is such a highly performant arrangement of data, the use of hash clusters would be a natural extension. "Overview of Hash Clusters" in the Concepts guide provides a good description of how useful clusters can be. Clustered data is easier to find, and for sorted data, the benefits are even better. </p>
<p>Maybe not as obvious for usage as in the past, given how much better the cost based optimizer is, but hash joins are a frequently used means of accessing data. Incorporating a hint in a statement can result in seeing the hashing step in an execution plan. Without looking at execution plans, and by letting the optimizer do its thing, Oracle isn't going to "tell" you that a hash join was used. </p>
<p>Hidden Hashing<br />Now it's time for a behind the scene use of hashing. In fact, this particular use of hashing is so under the radar that you would probably never even know it existed in Oracle unless you encountered one of several bugs. From note 4960265.9 we have, "In some cases when using a join filter in a RAC configuration (parallel hash-join) wrong results can be produced." The stated fix for this is to set the undocumented parameter _BLOOM_FILTER_ENABLED to false. What is a Bloom filter?</p>
<p>There are lots of hashing techniques, and "General Purpose Hash Function Algorithms," by Arash Partow, gives a decent summary without delving too deep into some esoteric computer science. The definition of a Bloom filter given in the paper states the following:</p>
<p>A Bloom filter allows for the state of existence of a very large set of possible type values to be repsented with a much smaller piece of memory. This is achieved through the use of multiple distinct hash functions and also by allowing the result of a query for the existence of a particular type to have a certain amount of error. This error can be controlled by varying the size of the table used for the Bloom filter and also by varying the number of hash functions.</p>
<p>So now, we know another technique Oracle uses to store data. In a sense, the data can be "over stored," that is, we want to make really, really sure it exists in one place or another. We may be wrong about the place (and then go find an accurate location), but the main point is that it exists. With this type of hashing, it will be difficult to say we don't have it anywhere, when in fact we do.</p>
<p>In Closing<br />Hashing is but one of many cleverly implemented functions embedded in Oracle. What would be interesting is being able to document all of the hash function implementation used in Oracle. For example, how does Oracle come up with 810835083 from "select ename from scott.emp where empno = 7369?" And why do hashed partitions work better (better = data spread more evenly) when the number of buckets is a power of two?</p>]]>
    </content>
</entry>

<entry>
    <title>Oracle 数据库 10g 版本 1 中的 PL/SQL 纯编译 (NCOMP)</title>
    <link rel="alternate" type="text/html" href="http://www.heysky.net/digest/2008/07/oracle-10g-plsql-ncomp.html" />
    <id>tag:www.heysky.net,2008:/digest//1.327</id>

    <published>2008-07-29T19:01:09Z</published>
    <updated>2008-07-29T19:07:20Z</updated>

    <summary><![CDATA[From http://www.oracle.com/technology/global/cn/tech/pl_sql/htdocs/ncomp_faq.html &nbsp; Oracle 数据库 10g 版本 1 中的 PL/SQL 纯编译 (NCOMP) 2004 年 9 月 4 日更新&nbsp; --------------------------------------------------------------------------------什么是纯编译？如何实现 PL/SQL 纯编译？Oracle 数据库 10g 有什么新特性？什么对象可以进行 PL/SQL 纯编译？共享库 (DLL) 的命名惯例是什么？共享的动态链接库是否可以移植？在部署端是否需要 C 编译环境？哪些 Oracle 参数与纯编译相关？plsql_native_library_dir 参数plsql_native_library_subdir_count 参数plsql_code_type 参数$ORACLE_HOME/plsql/spnc_commands 文件的格式纯编译生成的共享库存储在哪个字典表中？当删除一个"纯编译"单元时，文件系统上的共享库将发生什么？如何更改 plsql_native_library_dir？是否还有其他场合需要手动删除共享库？如果误删除了一个共享库该怎么办？甲骨文公司是否建议混合使用纯编译单元和解释单元？在操作系统升级时，是否需要重新生成纯编译的共享库？在应用程序部署期间是否能够使用纯编译模式来节省时间（通过提供预先生成的 NCOMP 共享库）？纯编译测试：简单测试将数据库中的所有 PL/SQL...]]></summary>
    <author>
        <name>Sky</name>
        <uri>http://www.heysky.net</uri>
    </author>
    
        <category term="Oracle" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="10g" label="10g" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="ncomp" label="NCOMP" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="oracle" label="Oracle" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="plsql" label="pl/sql" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.heysky.net/digest/">
        <![CDATA[<p><em>From </em><a href="http://www.oracle.com/technology/global/cn/tech/pl_sql/htdocs/ncomp_faq.html"><em>http://www.oracle.com/technology/global/cn/tech/pl_sql/htdocs/ncomp_faq.html</em></a></p>
<p>&nbsp;</p>
<p>Oracle 数据库 10g 版本 1 中的 PL/SQL 纯编译 (NCOMP)</p>
<p>2004 年 9 月 4 日更新&nbsp; </p>
<p>--------------------------------------------------------------------------------<br /><br />什么是纯编译？<br />如何实现 PL/SQL 纯编译？<br />Oracle 数据库 10g 有什么新特性？<br />什么对象可以进行 PL/SQL 纯编译？<br />共享库 (DLL) 的命名惯例是什么？<br />共享的动态链接库是否可以移植？<br />在部署端是否需要 C 编译环境？<br />哪些 Oracle 参数与纯编译相关？<br />plsql_native_library_dir 参数<br />plsql_native_library_subdir_count 参数<br />plsql_code_type 参数<br />$ORACLE_HOME/plsql/spnc_commands 文件的格式<br />纯编译生成的共享库存储在哪个字典表中？<br />当删除一个"纯编译"单元时，文件系统上的共享库将发生什么？<br />如何更改 plsql_native_library_dir？<br />是否还有其他场合需要手动删除共享库？<br />如果误删除了一个共享库该怎么办？<br />甲骨文公司是否建议混合使用纯编译单元和解释单元？<br />在操作系统升级时，是否需要重新生成纯编译的共享库？<br />在应用程序部署期间是否能够使用纯编译模式来节省时间（通过提供预先生成的 NCOMP 共享库）？<br />纯编译测试：简单测试<br />将数据库中的所有 PL/SQL 单元进行纯编译<br /></p>]]>
        <![CDATA[什么是纯编译？ 
<p>您可以通过将 PL/SQL 模块（程序包、触发器、过程、函数和类型）编译成驻留在共享库中的纯代码来加速它们的运行。过程被转换成 C 代码，然后用一个 C 编译器进行编译，并与 Oracle 进程动态链接。 </p>
<p>您可以将该技术用于随付的 Oracle 程序包以及您自己编写的过程。用这种方式编译的过程可以用于所有服务器环境，如共享服务器配置（以前称为多线程服务器）和 Oracle 真正应用集群。 </p>
<p>使用了大量有代表性测试程序的性能实验（发布在 OTN 上）表明，在 Oracle 数据库 10g 中，纯 PL/SQL 程序的应用程序在纯编译时的速度与解释编译时的速度相比（其他保持不变），预计可以获得大约 1.05 到 2.4 倍的性能提高。提高的程度取决于程序的种类。 </p>
<p>注意：许多 Oracle 提供的程序包（如 UTL_FILE、UTL_RAW、DBMS_LOB）已经用 C 实施，而仅使用 PL/SQL 来提供 API。这些程序包不大可能从纯编译中获得显著的性能提高。同样，仅调用 SQL 语句的 PL/SQL 程序单元也可能几乎得不到加速。不过，纯编译的 PL/SQL 往往至少和相应的解释代码一样快。编译的代码将与解释的代码执行相同的库调用，因此它们的行为是完全相同的。 </p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>如何实现 PL/SQL 纯编译？ </p>
<p>如果未使用纯编译，则将每个 PL/SQL 程序单元编译成一种中间形式的机器可读码 (MCode)。MCode 存储在数据库字典中，并在运行时进行解释。 </p>
<p>使用 PL/SQL 纯编译，将 PL/SQL 程序编译成无需运行时解释的纯机器码，从而加快运行速度。</p>
<p>PL/SQL 使用命令文件 $ORACLE_HOME/plsql/spnc_commands 和支持的操作系统 C 编译器和链接器，将生成的 C 代码编译并链接到共享库中。共享库存储在数据字典中，这样便可将它们自动备份并防止它们被删除。这些共享库文件被复制到文件系统中，并在调用 PL/SQL 子程序时被加载和运行。如果在关闭数据库时从文件系统中删除了这些文件，或者如果您更改了这些库所在的目录，则自动重新提取这些文件。</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>Oracle 数据库 10g 有什么新特性？ </p>
<p>这个特性现在需要更少的设置和维护。</p>
<p>不需要用相同的代码类型设置来编译程序包主体及其规范。例如，可以对程序包主体进行纯编译，而对程序包规范进行解释编译。 <br />经过纯编译的子程序存储在数据库中，并在需要的时候自动提取相应的共享库。对于备份共享库、清理原有共享库等事项，您无需操心。 <br />而且简化了纯编译的初始化参数和命令的设置。唯一需要的参数是 plsql_native_library_dir。不再使用与编译器、链接器和 make 实用程序相关的参数。$ORACLE_HOME/plsql/spnc_commands 命令文件用于进行纯编译。它包含了用于编译和链接的命令和选项，从而不再依赖于 make 实用程序。不再需要或支持 plsql_native_make_utility 和 plsql_native_make_file_name 参数，但仍须像在 9.0.1 版和 9.2.0 版中一样指定 plsql_native_library_dir。这将指定用于生成共享库（在共享库被复制到数据库中之前）的目录的完整路径。 <br />纯编译期间出现的所有错误都存储在 USER_ERRORS 字典视图中，可通过 SQL*Plus 命令 SHOW ERRORS 来查询。 <br />开启和关闭纯编译是由一个单独的参数 plsql_code_type 来控制的，而不是 plsql_compiler_flags 参数的几个选项之一，现在不建议使用后者。 <br />RAC 支持：现在在没有集群（共享）文件系统的 RAC 环境中也支持 PL/SQL 纯编译。 <br />共享库清理：当删除（或在解释模式下重新编译）纯编译的 PL/SQL 模块时，现在将删除（在 plsql_native_library_dir 指定的位置下的）共享库的文件系统副本。在 RAC 配置中，将从所有实例中删除共享库。 </p>
<p><br />--------------------------------------------------------------------------------</p>
<p>什么对象可以进行 PL/SQL 纯编译？ </p>
<p>任何存储的 PL/SQL 模块都可以进行纯编译。匿名的 PL/SQL 程序块不能进行纯编译。</p>
<p>注意：Oracle 支持以下类型的存储 PL/SQL 模块：</p>
<p>FUNCTION<br />PACKAGE<br />PACKAGE BODY<br />PROCEDURE<br />TRIGGER<br />TYPE<br />TYPE BODY</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>共享库 (DLL) 的命名惯例是什么？ </p>
<p>纯编译为每个单元创建一个共享库。例如，将为程序包规范和程序包主体分别创建一个共享库。以下是生成的一些名称：</p>
<p>PKG__SCOTT__S__54682.so<br />PKG__SCOTT__B__54683.so</p>
<p>生成的名称一般包含单元名称、模式名称、对象类型和对象编号。不过，这是一个可能会变更的内部惯例，用户不应依赖这种文件名格式规范。</p>
<p>文件名的扩展名在不同平台上可能不同。例如，在 Solaris 上共享库的后缀为 .so，而在 HP-UX 上共享库的后缀为 .sl。</p>
<p>返回页首 <br />共享的动态可链接库是否可以移植？ </p>
<p>不，绝对不行！共享库包含特定于平台的目标代码。 </p>
<p>注意：在解释方式下创建的 MCode 也是特定于平台的。 </p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>在部署端是否需要 C 编译环境？ </p>
<p>是的。没有商量的余地。PL/SQL 单元可能需要在部署端进行编译，PL/SQL 纯编译依靠一个 C 编译器来生成目标（机器）代码。</p>
<p>例如，各种操作（如向表中增加一列）可能导致与该表相关的 PL/SQL 单元的自动失效。对这种单元的后续访问将触发重新编译。在这种情况下，在纯编译模式下再次重新编译该单元需要 C 编译环境。</p>
<p>另一种情况是需要在部署数据库上应用补丁。可能需要在部署环境中重新加载和编译个别程序包。</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>哪些 Oracle 参数与纯编译相关？ </p>
<p>plsql_native_library_dir <br />plsql_native_library_subdir_count<br />plsql_code_type <br />返回页首 <br />plsql_native_library_dir 参数 </p>
<p>这个参数指定保存共享库 (DLL) 的 OS 副本的目录位置。</p>
<p>当对一个模块进行纯编译时，将在这个位置创建共享库，然后将其复制到数据库字典表 (ncomp_dll$) 中。虽然共享库的主副本驻留在数据库中，但还将共享对象在文件系统中进行了物化，以便能够动态地将它们加载到 Oracle 的地址空间中。</p>
<p>注释 1：用户 (DBA) 决不能在系统启动并运行时从 plsql_native_library_dir 中手动删除共享库，因为这些 DLL 可能被映射到了 Oracle 进程上。只有在系统关闭的时候才能安全地删除共享库的 OS 副本。</p>
<p>注释 2：在 RAC 配置中，必须在每个实例中设置这个参数。不要求各实例拥有共享文件系统。在每个实例上，必须将 plsql_native_library_dir 设置为指向一个实例本地目录。或者，如果 RAC 配置支持共享（集群）文件系统，您可以将（共享文件系统上的）一个公共的目录用于所有实例。</p>
<p>注释 3：您必须创建这个目录。Oracle 不会自动为您创建这个目录。</p>
<p>注释 4：甲骨文公司在单实例或 RAC 配置中都不为 plsql_native_library_dir 提供 NFS 挂载目录支持。这是因为 NFS 在写或删除文件时会导致一些不可预测的时序问题。</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>plsql_native_library_subdir_count 参数 </p>
<p>一些文件系统可能无法在单个目录中处理大量的文件；您可能需要在 plsql_native_library_dir 指定的目录下创建子目录来存储纯编译生成的共享库。</p>
<p>如果您使用的是生产品质的文件系统（例如 Veritas），那么您可能无需创建子目录。然而，如果您使用的是 vanilla 文件系统，那么它可能无法在单个目录中轻松地处理大量的文件。对于拥有大约 70,000 个 PL/SQL 对象的 Oracle 应用程序，在使用 vanilla 文件系统时，我们使用了大约 500 个子目录。</p>
<p>这个参数的默认值是 0。为了指示 Oracle 将共享库分配到不同的子目录中，而不是将所有共享库存储在 plsql_native_library_dir 指定的单个目录中，请将 plsql_native_library_subdir_count 参数设为您要创建的子目录数。</p>
<p>例如，要使用 500 个子目录，则将以下行添加到您的初始化参数文件中：</p>
<p>plsql_native_library_subdir_count=500</p>
<p>然后您必须创建 500 个子目录（在 plsql_native_library_dir 参数指定的目录下），目录名称即为 d0、d1、d2、..、d498、d499。</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>plsql_code_type 参数 </p>
<p>plsql_code_type 参数决定对 PL/SQL 代码是进行纯编译还是解释。默认设置是 INTERPRETED。要启用 PL/SQL 纯编译，请将 plsql_code_type 的值设为 NATIVE。如果您想以 NATIVE 方式编译整个数据库，那么甲骨文公司建议您在系统级或在初始化参数文件中设置 plsql_code_type。 </p>
<p>使用以下语法设置该参数：</p>
<p>对于纯编译模式： <br />alter session set plsql_code_type='NATIVE'<br />或者， <br />alter system set plsql_code_type='NATIVE'<br />对于解释模式： <br />alter session set plsql_code_type='INTERPRETED'<br />或者， <br />alter system set plsql_code_type='INTERPRETED'</p>
<p><br />--------------------------------------------------------------------------------</p>
<p>spnc_commands 文件的格式 </p>
<p>$ORACLE_HOME/plsql 目录中的 spnc_commands 文件包含了编译和链接各个程序的命令模板。一些特殊的名称（如 %(src)）被预先定义，并用相应的文件名进行了替换。变量 $(ORACLE_HOME) 也自动被 Oracle 主目录的位置替换。您可以包含命令行（以 # 字符开始）。该文件包含解释所有特殊符号的注释。 </p>
<p>spnc_commands 文件根据特定的操作系统为 C 编译器包含了一个预先定义的路径。（每种操作系统支持一种特定的编译器。）在大多数情况下，您不需要更改这个路径，但如果系统管理员将编译器安装在了另一个位置，您可能就需要更改它了。 </p>
<p>这种方法意味着（与 9.0.1 版和 9.2.0 版不同）这里与 make 实用程序不存在依赖关系。 </p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>纯编译生成的共享库存储在哪个字典表中？ </p>
<p>纯编译生成的共享库被作为 BLOB 存储在数据库中的 ncomp_dll$ 字典表中。</p>
<p>SQL&gt; connect / as sysdba;<br />Connected.<br />SQL&gt; describe ncomp_dll$;<br />Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Null?Type<br />&nbsp;------------&nbsp;&nbsp; --------------&nbsp;&nbsp;&nbsp; -------- <br />OBJ#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NOT NULL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NUMBER<br />VERSION&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NUMBER<br />DLL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLOB<br />DLLNAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RAW(1024)</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>当删除一个"纯编译"单元时，文件系统上的共享库将发生什么？ </p>
<p>直到 9.2.0，未发生任何事情。不会对共享库进行垃圾收集。</p>
<p>在 10.1.0 版中，当删除或在解释模式下重新编译一个纯编译的单元时，将从 ncomp_dll$ 字典表以及从 plsql_native_library_dir 参数指定的文件系统位置中删除该共享库。在 RAC 配置的情况下，将从每个实例的 plsql_native_library_dir 位置中删除该共享库。</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>如何更改 plsql_native_library_dir？ </p>
<p>如果您需要更改该参数的值，建议采取以下步骤：</p>
<p>关闭数据库实例 <br />将初始化参数文件中的 plsql_native_library_dir 设置更改为指向新的位置。 <br />重新启动数据库实例。Oracle 将根据需要自动将共享库提取到这个新的位置中。 <br />注释 1：虽然可以通过 alter system..命令来更改这个参数，但 Oracle 不建议这么做。</p>
<p>注释 2：一旦执行了上述步骤，就可以安全地删除与 plsql_native_library_dir 先前的设置对应的原有目录了。Oracle 不会 自动从原有位置删除共享库。</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>是否还有其他场合需要手动删除共享库？ </p>
<p>没有。 </p>
<p>唯一的例外是当您想修改 plsql_native_library_dir 的设置的时候。请按照先前所述步骤更改 plsql_native_library_dir。然后就可以从原有位置删除共享库了。</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>如果误删除了一个共享库该怎么办？ </p>
<p>这可能导致非预期的内部错误和问题。建议的补救办法是关闭然后重新启动实例。Oracle 将根据需要自动从 ncomp_dll$ 字典表中提取共享库。</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>甲骨文公司是否建议混合使用纯编译单元和解释单元？ </p>
<p>虽然支持混合使用，并且决不会导致错误的行为，但当纯编译单元调用解释单元时，需要付出一定代价。如果纯编译单元频繁调用解释单元，那么您可能牺牲一些潜在的性能改善。</p>
<p>如果将所有模块纯编译成共享库的时间是个问题，那么一种选择是考虑将程序包和类型规范在解释模式下进行编译，而将所有其他类型的 PL/SQL 单元（程序包主体、类型主体、过程、函数和触发器）在纯编译模式下进行编译。因为规范一般没有太多可执行代码，因此就运行时性能而言您不会有太大损失。 </p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>在操作系统升级时，是否需要重新生成纯编译的共享库？ </p>
<p>假设您已经确定甲骨文支持这种类型的 OS 升级，而无需重新生成普通的 Oracle 可执行文件，那么 PL/SQL 纯编译产生的共享库也将可用，而无需重新生成。</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>在应用程序部署期间是否能够使用纯编译模式来节省时间（通过提供预先生成的 NCOMP 共享库）？ </p>
<p>不能！即使共享库是在与最终部署环境相同的平台上生成的，您也无法这么做。您也无法在解释模式下利用 MCode 这么做。</p>
<p>其原因与编译模式无关。基于 PL/SQL 的应用程序在数据库中的安装需要在数据库中加载和编译 PL/SQL 模块，以便可以正确解析所有的外部引用。</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>纯编译测试：简单测试 </p>
<p>创建一个目录，用于存储纯编译生成的共享库，并在初始化参数文件中将 plsql_native_library_dir 参数设置为指向该目录路径。例如，您需要在初始化参数文件中添加如下内容： <br />plsql_native_library_dir=/home/kmuthukk/oracle10g/dbs/ncomp_libraries</p>
<p><br />还可以在初始化参数文件中设置 plsql_native_library_subdir_count 并创建子目录。 <br />确保 spnc_commands 文件中使用的 C 编译器 -- 以及链接器（如果适用） -- 的 OS 路径是正确的。 <br />系统参数完整性检查： 必须指定 plsql_native_library_dir。plsql_native_library_subdir_count 是可选的，可以保留为 0（如果您不打算使用基于子目录的模式）。最好在初始化参数文件中指定这些参数。 <br />SQL&gt; show parameters plsql_native<br />NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TYPE&nbsp; VALUE<br />------------------------------------ ----------- ------------------------------<br />plsql_native_library_dir&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string&nbsp; /home/kmuthukk/oracle10g/dbs/ncomp_libraries<br />plsql_native_library_subdir_count&nbsp;&nbsp;&nbsp; integer&nbsp; 0</p>
<p>对 PL/SQL 模块进行纯编译</p>
<p>要在纯编译模式下加载和编译新的模块，必须将 plsql_code_type 参数设为 NATIVE。 <br />例如，尝试在 SQL*Plus 中执行以下操作： </p>
<p>connect scott/tiger<br />alter session set plsql_code_type='NATIVE';</p>
<p>create or replace procedure my_test is<br />begin<br />dbms_output.put_line('hello world');<br />end;<br />/<br />show errors;</p>
<p>set serveroutput on;<br />execute my_test;</p>
<p>验证步骤： </p>
<p>看一下 plsql_native_library_dir 指定的位置。应找到一个与 MY_TEST 过程相对应的新的共享库。在 Solaris 上，DLL 可能有一个类似 MY_TEST__SCOTT__P__54765.so 的名称。 <br />[要阅读有关共享库命名惯例的更多信息，请点击此处。] </p>
<p><br />此外，通过执行以下查询，确保该模块的 plsql_code_type 设置的确为 NATIVE： <br />select name, type, plsql_code_type <br />from user_plsql_object_settings <br />where name = 'MY_TEST';</p>
<p>如果您想手动地对特定的已经加载的模块进行纯编译，那么您可以使用 alter ... compile .. 语句。 <br />假定您有一个程序包 MYPKG，其规范和主体是用解释方式编译的。现在，如果您只想对其主体进行纯编译，那么可以执行以下命令： </p>
<p>alter package MYPKG compile body plsql_code_type=native reuse settings<br />&nbsp;&nbsp; <br />上面的 reuse settings 子句指示编译器应当保留该单元所有以前的设置 -- 被显式覆盖的设置（如在上述示例中设定的 plsql_code_type 的设置）除外。 </p>
<p>如果从上面的语句中删除了 body 子句，如： </p>
<p>alter package MYPKG compile plsql_code_type=native reuse settings<br />... 那么规范和主体都将在纯编译模式下重新编译。不过请注意，重新编译规范将造成依赖于该规范的其他模块失效。 </p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>将数据库中的所有 PL/SQL 单元进行纯编译 </p>
<p>在试图将数据库中的所有 PL/SQL 单元进行纯编译之前，在一个简单的测试案例上试验一下（如上一部分所述）。这将帮助确保您的纯编译设置是正确的。</p>
<p>操作系统文件描述符限制 <br />$ORACLE_HOME/rdbms/admin 目录下的两个 SQL*Plus 脚本（dbmsupgnv.sql 和 utlrp.sql）用来在纯编译模式下重新编译所有的 PL/SQL 模块。它们使用并行作业（取决于可用的 CPU 的数量）。在这种情况下，许多作业同时生成 C 文件并试图编译它们。因此不将文件描述符的最大数的 OS 限制设得过低非常重要。 </p>
<p>例如，在我的 Solaris 计算机上：</p>
<p>% ulimit -a<br />time(seconds)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unlimited<br />file(blocks)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unlimited<br />data(kbytes)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2097148<br />stack(kbytes)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8192<br />coredump(blocks)&nbsp;&nbsp;&nbsp;&nbsp; 3<br />nofiles(descriptors) 64</p>
<p>vmemory(kbytes)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unlimited</p>
<p>注意描述符的最大数（值为 64）。这在生产环境中太少了，因为有许多作业要进行并行纯编译。您可能想查看您计算机上的限制，并将其提高。例如： </p>
<p>在 Solaris 上，需要编辑 /etc/system 文件，使之包含： </p>
<p>set rlim_fd_max=4096<br />set rlim_fd_cur=1024</p>
<p>在 HP-UX 上，相应的参数位于 /stand/system 文件中。 </p>
<p>maxfiles&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2048 <br />maxfiles_lim&nbsp;&nbsp;&nbsp; 2048 </p>
<p><br />系统表空间 <br />因为 DLLs 的主副本存储在字典表中，因此您可能需要比以前更多的 SYSTEM 表空间。如果您遇到了与 SYSTEM 表空间的空间限制相关的错误，那么您将需要执行如下操作： </p>
<p>alter tablespace system<br />add datafile '/home/kmuthukk/oracle10g/dbs/mydata10.dbf'<br />size 500 m;</p>
<p>.. 或在数据文件上设置 autoextend。 </p>
<p><br />以纯编译模式重新编译所有的模块（dbmsupgnv.sql 和 utlrp.sql）</p>
<p>关闭所有的应用程序服务（包括 Forms Processe、Web Server、Reports Server 和 Concurrent Manager Server）。在关闭所有的应用程序服务之后，确保中断了所有与数据库的连接。 </p>
<p>关闭数据库的 TNS 监听器，以确保不会创建新的连接。 </p>
<p>关闭数据库（以正常模式或即时模式）。 </p>
<p>确定您已在初始化参数文件中设置了 plsql_native_library_dir。如果没有，则请查看上一部分所述的步骤。 </p>
<p>在初始化参数文件中将 plsql_code_type 设为 NATIVE。 <br />plsql_code_type=NATIVE</p>
<p><br />在 UPGRADE 模式下启动数据库（使用 STARTUP UPGRADE 或 ALTER DATABASE OPEN UPGRADE）。 </p>
<p>运行以下查询，获取无效对象的数量。这个值将在稍后用于作比较，以确保重新编译没有由于纯编译故障而产生额外的无效对象。 <br />Select count(*)<br />From all_objects<br />Where status='INVALID';</p>
<p>以下查询将为您展示，纯编译模式和解释模式分别编译了多少对象。 <br />SELECT plsql_code_type, count(*) <br />FROM dba_plsql_object_settings <br />GROUP BY plsql_code_type;</p>
<p>您可能看到一些对象的 plsql_code_type 为 NULL。这些是特殊的内部对象，可以忽略。 </p>
<p><br />cd（更改目录）至 $ORACLE_HOME/rdbms/admin。 </p>
<p>运行 $ORACLE_HOME/rdbms/admin/dbmsupgnv.sql（作为 SYS 用户）。 <br />注释 1： dbmsupgnv.sql 使所有的 PL/SQL 模块失效并更新字典表，将它们的 plsql_code_type 设置修改为 NATIVE。这一阶段必须在数据库上没有其他活动进行时完成；因此，我们要求在运行 dbmsupgnv.sql 期间必须以 UPGRADE 模式启动数据库。 </p>
<p>注释 2：如果您要从数据库的一个低版本向数据库高版本升级（例如，升级到 Oracle 数据库 10g），那么您必须首先运行升级脚本，然后运行 dbmsupgnv.sql。例如，如果您正从 9.2.0.3 升级到 10.1.0，那么请首先运行升级脚本 (u0902000.sql)，然后关闭数据库并运行 dbmsupgnv.sql 脚本。 </p>
<p><br />在运行 dbmsupgnv.sql 之后提交更改 <br />SQL&gt; commit;</p>
<p><br />关闭数据库。 </p>
<p>以正常模式重新启动数据库。 </p>
<p>运行 $ORACLE_HOME/rdbms/admin/utlrp.sql 脚本（作为 SYS 用户）。这一步骤将重新编译所有的 PL/SQL 模块。[在这个过程期间，您可能想定期查看 plsql_native_library_dir 指定的目录，以确保编译过程的确创建了新的共享库。] <br />注意：这一步骤是可重新启动的。如果由于任何原因这个步骤异常终止，那么您只需重新启动这个步骤（即重新运行 utlrp.sql 脚本）。它将重新编译余下的任何无效的 PL/SQL 模块。 </p>
<p><br />在编译成功完成之后，您应当验证无效对象数少于或等于重新编译之前的无效对象数。您可以使用以下查询获取无效对象数。 <br />Select count(*)<br />From all_objects<br />Where status='INVALID';</p>
<p>再运行以下查询，以确保没有遗漏解释的模块： </p>
<p>SELECT plsql_code_type, count(*) <br />FROM dba_plsql_object_settings <br />GROUP BY plsql_code_type;</p>]]>
    </content>
</entry>

<entry>
    <title>Oracle 11g Linux单机STANDBY配置</title>
    <link rel="alternate" type="text/html" href="http://www.heysky.net/digest/2008/07/oracle-11g-standby-config-on-linux.html" />
    <id>tag:www.heysky.net,2008:/digest//1.326</id>

    <published>2008-07-28T18:28:45Z</published>
    <updated>2008-07-28T18:32:57Z</updated>

    <summary><![CDATA[From: http://www.itpub.net/835722.html&nbsp;By blue_prince &nbsp; Oracle 11g Linux单机STANDBY配置 环境：RHEL 4 U5+Oracle 11.1.0.6主库SID：ora11g 备用库SID:standby主库数据文件存放目录：/home/oracle/opt/oradata/ora11g/备用库数据文件存放目录：/home/oracle/opt/oradata/standby/1、&nbsp; &nbsp; &nbsp; &nbsp; 验证主库是否归档，如果是未归档模式的话必须更改为归档模式：Sys@ORA11G&gt; archive log listDatabase log mode&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Archive ModeAutomatic archival&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; EnabledArchive destination&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;/home/oracle/opt/oradata/ora11g/archiveOldest online log sequence&nbsp;...]]></summary>
    <author>
        <name>Sky</name>
        <uri>http://www.heysky.net</uri>
    </author>
    
        <category term="Oracle" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="10g" label="10g" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="11g" label="11g" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="dataguard" label="dataguard" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="linux" label="Linux" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="oracle" label="Oracle" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="standby" label="standby" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.heysky.net/digest/">
        <![CDATA[<p>From: <a href="http://www.itpub.net/835722.html">http://www.itpub.net/835722.html</a>&nbsp;By blue_prince</p>
<p>&nbsp;</p>
<p><strong>Oracle 11g Linux单机STANDBY配置<br /></strong></p>
<div class="t_msgfont" id="message8301314">环境：RHEL 4 U5+Oracle 11.1.0.6<br />主库SID：ora11g 备用库SID:standby<br />主库数据文件存放目录：/home/oracle/opt/oradata/ora11g/<br />备用库数据文件存放目录：/home/oracle/opt/oradata/standby/<br /><br />1、&nbsp; &nbsp; &nbsp; &nbsp; 验证主库是否归档，如果是未归档模式的话必须更改为归档模式：<br /><br />Sys@ORA11G&gt; archive log list<br />Database log mode&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Archive Mode<br />Automatic archival&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Enabled<br />Archive destination&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;/home/oracle/opt/oradata/ora11g/archive<br />Oldest online log sequence&nbsp; &nbsp;&nbsp;&nbsp;61<br />Next log sequence to archive&nbsp; &nbsp;63<br />Current log sequence&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;63<br /><br />2、&nbsp; &nbsp; &nbsp; &nbsp; 将主库置于FORCE LOGGING模式：<br /><br />Sys@ORA11G&gt; alter database force logging;<br /><br />3、&nbsp; &nbsp; &nbsp; &nbsp; 对主库做一个全库的RMAN备份，用于STANDBY配置：</normalfont> 
<blockquote><pre><smallfont>PHP code:</smallfont><hr><code><span style="COLOR: #000000"><br />
<span style="COLOR: #0000bb"><br /></span><span style="COLOR: #007700">[</span><span style="COLOR: #0000bb">oracle</span><span style="COLOR: #007700">@</span><span style="COLOR: #0000bb">test51&nbsp;bin</span><span style="COLOR: #007700">]$&nbsp;./</span><span style="COLOR: #0000bb">rman&nbsp;target&nbsp;</span><span style="COLOR: #007700">/<br />
<br /><br />
<br /></span><span style="COLOR: #0000bb">Recovery&nbsp;Manager</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">Release&nbsp;11.1.0.6.0&nbsp;</span><span style="COLOR: #007700">-&nbsp;</span><span style="COLOR: #0000bb">Production&nbsp;on&nbsp;Thu&nbsp;Aug&nbsp;16&nbsp;15</span><span style="COLOR: #007700">:</span><span style="COLOR: #0000bb">51</span><span style="COLOR: #007700">:</span><span style="COLOR: #0000bb">22&nbsp;2007<br />
<br /><br />
<br />Copyright&nbsp;</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">c</span><span style="COLOR: #007700">)&nbsp;</span><span style="COLOR: #0000bb">1982</span><span style="COLOR: #007700">,&nbsp;</span><span style="COLOR: #0000bb">2007</span><span style="COLOR: #007700">,&nbsp;</span><span style="COLOR: #0000bb">Oracle</span><span style="COLOR: #007700">.&nbsp;&nbsp;</span><span style="COLOR: #0000bb">All&nbsp;rights&nbsp;reserved</span><span style="COLOR: #007700">.<br />
<br /><br />
<br /></span><span style="COLOR: #0000bb">connected&nbsp;to&nbsp;target&nbsp;database</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">ORA11G&nbsp;</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">DBID</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">4026454982</span><span style="COLOR: #007700">)<br />
<br /><br />
<br /></span><span style="COLOR: #0000bb">RMAN</span><span style="COLOR: #007700">&gt;&nbsp;</span><span style="COLOR: #0000bb">backup&nbsp;database&nbsp;format&nbsp;</span><span style="COLOR: #dd0000">'/home/oracle/liuyun/%U.bak'</span><span style="COLOR: #007700">;<br />
<br /><br />
<br /></span><span style="COLOR: #0000bb">Starting&nbsp;backup&nbsp;at&nbsp;16</span><span style="COLOR: #007700">-</span><span style="COLOR: #0000bb">AUG</span><span style="COLOR: #007700">-</span><span style="COLOR: #0000bb">07<br />
<br />using&nbsp;target&nbsp;database&nbsp;control&nbsp;file&nbsp;instead&nbsp;of&nbsp;recovery&nbsp;catalog<br />
<br />allocated&nbsp;channel</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">ORA_DISK_1<br />
<br />channel&nbsp;ORA_DISK_1</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">SID</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">121&nbsp;device&nbsp;type</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">DISK<br />
<br />channel&nbsp;ORA_DISK_1</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">starting&nbsp;full&nbsp;datafile&nbsp;backup&nbsp;set<br />
<br />channel&nbsp;ORA_DISK_1</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">specifying&nbsp;datafile</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">s</span><span style="COLOR: #007700">)&nbsp;</span><span style="COLOR: #0000bb">in&nbsp;backup&nbsp;set<br />
<br />input&nbsp;datafile&nbsp;file&nbsp;number</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">00004&nbsp;name</span><span style="COLOR: #007700">=/</span><span style="COLOR: #0000bb">home</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">oracle</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">opt</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">oradata</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">ora11g</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">users01</span><span style="COLOR: #007700">.</span><span style="COLOR: #0000bb">dbf<br />
<br />input&nbsp;datafile&nbsp;file&nbsp;number</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">00002&nbsp;name</span><span style="COLOR: #007700">=/</span><span style="COLOR: #0000bb">home</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">oracle</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">opt</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">oradata</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">ora11g</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">sysaux01</span><span style="COLOR: #007700">.</span><span style="COLOR: #0000bb">dbf<br />
<br />input&nbsp;datafile&nbsp;file&nbsp;number</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">00001&nbsp;name</span><span style="COLOR: #007700">=/</span><span style="COLOR: #0000bb">home</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">oracle</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">opt</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">oradata</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">ora11g</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">system01</span><span style="COLOR: #007700">.</span><span style="COLOR: #0000bb">dbf<br />
<br />input&nbsp;datafile&nbsp;file&nbsp;number</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">00005&nbsp;name</span><span style="COLOR: #007700">=/</span><span style="COLOR: #0000bb">home</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">oracle</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">opt</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">oradata</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">ora11g</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">example01</span><span style="COLOR: #007700">.</span><span style="COLOR: #0000bb">dbf<br />
<br />input&nbsp;datafile&nbsp;file&nbsp;number</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">00003&nbsp;name</span><span style="COLOR: #007700">=/</span><span style="COLOR: #0000bb">home</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">oracle</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">opt</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">oradata</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">ora11g</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">undotbs01</span><span style="COLOR: #007700">.</span><span style="COLOR: #0000bb">dbf<br />
<br />channel&nbsp;ORA_DISK_1</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">starting&nbsp;piece&nbsp;1&nbsp;at&nbsp;16</span><span style="COLOR: #007700">-</span><span style="COLOR: #0000bb">AUG</span><span style="COLOR: #007700">-</span><span style="COLOR: #0000bb">07<br />
<br />channel&nbsp;ORA_DISK_1</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">finished&nbsp;piece&nbsp;1&nbsp;at&nbsp;16</span><span style="COLOR: #007700">-</span><span style="COLOR: #0000bb">AUG</span><span style="COLOR: #007700">-</span><span style="COLOR: #0000bb">07<br />
<br />piece&nbsp;handle</span><span style="COLOR: #007700">=/</span><span style="COLOR: #0000bb">home</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">oracle</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">liuyun</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">03iphp8l_1_1</span><span style="COLOR: #007700">.</span><span style="COLOR: #0000bb">bak&nbsp;tag</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">TAG20070816T155148&nbsp;comment</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">NONE<br />
<br />channel&nbsp;ORA_DISK_1</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">backup&nbsp;set&nbsp;complete</span><span style="COLOR: #007700">,&nbsp;</span><span style="COLOR: #0000bb">elapsed&nbsp;time</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">00</span><span style="COLOR: #007700">:</span><span style="COLOR: #0000bb">01</span><span style="COLOR: #007700">:</span><span style="COLOR: #0000bb">45<br />
<br />channel&nbsp;ORA_DISK_1</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">starting&nbsp;full&nbsp;datafile&nbsp;backup&nbsp;set<br />
<br />channel&nbsp;ORA_DISK_1</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">specifying&nbsp;datafile</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">s</span><span style="COLOR: #007700">)&nbsp;</span><span style="COLOR: #0000bb">in&nbsp;backup&nbsp;set<br />
<br />including&nbsp;current&nbsp;control&nbsp;file&nbsp;in&nbsp;backup&nbsp;set<br />
<br />including&nbsp;current&nbsp;SPFILE&nbsp;in&nbsp;backup&nbsp;set<br />
<br />channel&nbsp;ORA_DISK_1</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">starting&nbsp;piece&nbsp;1&nbsp;at&nbsp;16</span><span style="COLOR: #007700">-</span><span style="COLOR: #0000bb">AUG</span><span style="COLOR: #007700">-</span><span style="COLOR: #0000bb">07<br />
<br />channel&nbsp;ORA_DISK_1</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">finished&nbsp;piece&nbsp;1&nbsp;at&nbsp;16</span><span style="COLOR: #007700">-</span><span style="COLOR: #0000bb">AUG</span><span style="COLOR: #007700">-</span><span style="COLOR: #0000bb">07<br />
<br />piece&nbsp;handle</span><span style="COLOR: #007700">=/</span><span style="COLOR: #0000bb">home</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">oracle</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">liuyun</span><span style="COLOR: #007700">/</span><span style="COLOR: #0000bb">04iphpc9_1_1</span><span style="COLOR: #007700">.</span><span style="COLOR: #0000bb">bak&nbsp;tag</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">TAG20070816T155148&nbsp;comment</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">NONE<br />
<br />channel&nbsp;ORA_DISK_1</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">backup&nbsp;set&nbsp;complete</span><span style="COLOR: #007700">,&nbsp;</span><span style="COLOR: #0000bb">elapsed&nbsp;time</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">00</span><span style="COLOR: #007700">:</span><span style="COLOR: #0000bb">00</span><span style="COLOR: #007700">:</span><span style="COLOR: #0000bb">01<br />
<br />Finished&nbsp;backup&nbsp;at&nbsp;16</span><span style="COLOR: #007700">-</span><span style="COLOR: #0000bb">AUG</span><span style="COLOR: #007700">-</span><span style="COLOR: #0000bb">07<br />
<br /></span><span style="COLOR: #007700">..<br /></span><span s< font></code><hr></pre></blockquote><normalfont>4、&nbsp; &nbsp; &nbsp; &nbsp; 准备STANDBY数据文件路径和其他路径：<br /><br />[oracle@test51 oradata]$ pwd&nbsp;&nbsp;<br />/home/oracle/opt/oradata<br />[oracle@test51 oradata]$ mkdir standby<br />[oracle@test51 oradata]$ ls<br />ora11g&nbsp;&nbsp;orcl&nbsp;&nbsp;standby<br />[oracle@test51 oradata]$ cd $ORACLE_BASE/admin<br />[oracle@test51 admin]$ mkdir standby<br />[oracle@test51 admin]$ ls<br />ora11g&nbsp;&nbsp;orcl&nbsp;&nbsp;standby<br />[oracle@test51 standby]$mkdir adump<br />[oracle@test51 standby]$mkdir dpdump<br />[oracle@test51 standby]$mkdir pfile<br />[oracle@test51 standby]$ ls<br />adump&nbsp;&nbsp;dpdump&nbsp;&nbsp;pfile<br /><br />5、更改tnsnames配置，添加主库和备用库的连接字：<br /><br />primary =<br />&nbsp;&nbsp;(DESCRIPTION =<br />&nbsp; &nbsp; (ADDRESS = (PROTOCOL = TCP)(HOST = test51)(PORT = 1522))<br />&nbsp; &nbsp; (CONNECT_DATA =<br />&nbsp; &nbsp;&nbsp; &nbsp;(SERVER = DEDICATED)<br />&nbsp; &nbsp;&nbsp; &nbsp;(SERVICE_NAME = ora11g)<br />&nbsp; &nbsp; )<br />&nbsp;&nbsp;)<br /><br />standby =<br />&nbsp;&nbsp;(DESCRIPTION =<br />&nbsp; &nbsp; (ADDRESS = (PROTOCOL = TCP)(HOST = test51)(PORT = 1522))<br />&nbsp; &nbsp; (CONNECT_DATA =<br />&nbsp; &nbsp;&nbsp; &nbsp;(SERVER = DEDICATED)<br />&nbsp; &nbsp;&nbsp; &nbsp;(SERVICE_NAME = standby)<br />&nbsp; &nbsp; )<br />&nbsp;&nbsp;)<br /><br />6、生成STANDBY控制文件：<br /><br />Sys@ORA11G&gt; alter database create standby controlfile as '/home/oracle/opt/oradata/standby/control01.ctl';<br /><br />Database altered.<br /><br />[oracle@test51 standby]$ cp control01.ctl control02.ctl<br />[oracle@test51 standby]$ cp control01.ctl control03.ctl<br />[oracle@test51 standby]$ ls<br />archive&nbsp;&nbsp;control01.ctl&nbsp;&nbsp;control02.ctl&nbsp;&nbsp;control03.ctl<br /><br />6、生成standby 初始化参数文件：<br /><br />Sys@ORA11G&gt; create pfile='$ORACLE_BASE/admin/standby/pfile/init.ora' from spfile;<br /><br />File created.<br /><br />添加以下几个参数，需要注意的是从11G开始原来备用库归档参数standby_archive_dest这个参数已经废除了，STANDBY的归档路径改为常规的归档路径log_archive_dest_n。还有原来单机配置STANDBY需要的参数lock_name_space也废除了：<br /><br />*.log_archive_config='DG_CONFIG=(ora11g,standby)'<br />*.fal_client='standby'<br />*.fal_server='primary'<br />*.db_file_name_convert='ora11g','standby'<br />*.log_file_name_convert='ora11g','standby'<br />*.standby_file_management='auto'<br />*.log_archive_dest_1='location=/home/oracle/opt/oradata/standby/archive VALID_FOR=(STANDBY_LOGFILE,STANDBY_ROLE)'<br /><br />更改后的参数文件如下，注意db_unique_name要和主库区分，否则无法MOUNT STANDBY：<br /><br />standby.__db_cache_size=234881024<br />standby.__java_pool_size=12582912<br />standby.__large_pool_size=4194304<br />standby.__oracle_base='/home/oracle/opt'#ORACLE_BASE set from environment<br />standby.__pga_aggregate_target=209715200<br />standby.__sga_target=629145600<br />standby.__shared_io_pool_size=0<br />standby.__shared_pool_size=369098752<br />standby.__streams_pool_size=0<br />*.audit_file_dest='/home/oracle/opt/admin/standby/adump'<br />*.audit_trail='db'<br />*.compatible='11.1.0.0.0'<br />*.control_files='/home/oracle/opt/oradata/standby/control01.ctl','/home/oracle/opt/oradata/standby/control02.ctl','/home/oracle/opt/oradata/standby/control03.ctl'<br />*.db_block_size=8192<br />*.db_domain=''<br />*.db_name='ora11g'<br />*.db_recovery_file_dest='/home/oracle/opt/flash_recovery_area'<br />*.db_recovery_file_dest_size=2147483648<br />*.db_unique_name='standby'<br />*.ddl_lock_timeout=10<br />*.diagnostic_dest='/home/oracle/opt'<br />*.dispatchers=''<br />*.job_queue_processes=0<br />*.local_listener='LISTENER_ora11g'<br />*.memory_target=838860800<br />*.open_cursors=300<br />*.processes=150<br />*.remote_login_passwordfile='EXCLUSIVE'<br />*.undo_tablespace='UNDOTBS1'<br /><br />*.log_archive_config='DG_CONFIG=(ora11g,standby)'<br />*.fal_client='standby'<br />*.fal_server='primary'<br />*.db_file_name_convert='ora11g','standby'<br />*.log_file_name_convert='ora11g','standby'<br />*.standby_file_management='auto'<br />*.log_archive_dest_1='location=/home/oracle/opt/oradata/standby/archive VALID_FOR=(STANDBY_LOGFILE,STANDBY_ROLE)'<br /><br />7、启动STANDBY数据库，进行RESTORE：</normalfont> <blockquote><pre><smallfont>PHP code:</smallfont><hr><code><span style="COLOR: #000000"><br />
<span style="COLOR: #0000bb"><br /></span><span style="COLOR: #007700">[</span><span style="COLOR: #0000bb">oracle</span><span style="COLOR: #007700">@</span><span style="COLOR: #0000bb">test51&nbsp;standby</span><span style="COLOR: #007700">]$&nbsp;</span><span style="COLOR: #0000bb">export&nbsp;ORACLE_SID</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">standby<br />
<br /></span><span style="COLOR: #007700">[</span><span style="COLOR: #0000bb">oracle</span><span style="COLOR: #007700">@</span><span style="COLOR: #0000bb">test51&nbsp;standby</span><span style="COLOR: #007700">]$&nbsp;</span><span style="COLOR: #0000bb">sql<br />
<br /><br />
<br />SQL</span><span style="COLOR: #007700">*</span><span style="COLOR: #0000bb">Plus</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">Release&nbsp;10.2.0.1.0&nbsp;</span><span style="COLOR: #007700">-&nbsp;</span><span style="COLOR: #0000bb">Production&nbsp;on&nbsp;Thu&nbsp;Aug&nbsp;16&nbsp;16</span><span style="COLOR: #007700">:</span><span style="COLOR: #0000bb">27</span><span style="COLOR: #007700">:</span><span style="COLOR: #0000bb">08&nbsp;2007<br />
<br /><br />
<br />Copyright&nbsp;</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">c</span><span style="COLOR: #007700">)&nbsp;</span><span style="COLOR: #0000bb">1982</span><span style="COLOR: #007700">,&nbsp;</span><span style="COLOR: #0000bb">2005</span><span style="COLOR: #007700">,&nbsp;</span><span style="COLOR: #0000bb">Oracle</span><span style="COLOR: #007700">.&nbsp;&nbsp;</span><span style="COLOR: #0000bb">All&nbsp;rights&nbsp;reserved</span><span style="COLOR: #007700">.<br />
<br /><br />
<br /></span><span style="COLOR: #0000bb">Connected&nbsp;to&nbsp;an&nbsp;idle&nbsp;instance</span><span style="COLOR: #007700">.<br />
<br /><br />
<br /></span><span style="COLOR: #0000bb">idle</span><span style="COLOR: #007700">&gt;&nbsp;</span><span style="COLOR: #0000bb">startup&nbsp;nomount&nbsp;pfile</span><span style="COLOR: #007700">=</span><span style="COLOR: #dd0000">'$ORACLE_BASE/admin/standby/pfile/init.ora'<br />
<br /></span><span style="COLOR: #0000bb">ORACLE&nbsp;instance&nbsp;started</span><span style="COLOR: #007700">.<br />
<br /><br />
<br /></span><span style="COLOR: #0000bb">Total&nbsp;System&nbsp;</span><span style="COLOR: #007700">Global&nbsp;</span><span style="COLOR: #0000bb">Area&nbsp;&nbsp;836976640&nbsp;bytes<br />
<br />Fixed&nbsp;Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1303132&nbsp;bytes<br />
<br />Variable&nbsp;Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;595594660&nbsp;bytes<br />
<br />Database&nbsp;Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;234881024&nbsp;bytes<br />
<br />Redo&nbsp;Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5197824&nbsp;bytes<br />
<br />idle</span><span style="COLOR: #007700">&gt;&nbsp;</span><span style="COLOR: #0000bb">alter&nbsp;database&nbsp;mount&nbsp;standby&nbsp;database</span><span style="COLOR: #007700">;<br />
<br /><br />
<br /></span><span style="COLOR: #0000bb">Database&nbsp;altered</span><span style="COLOR: #007700">.<br />
<br /><br />
<br />[</span><span style="COLOR: #0000bb">oracle</span><span style="COLOR: #007700">@</span><span style="COLOR: #0000bb">test51&nbsp;bin</span><span style="COLOR: #007700">]$&nbsp;./</span><span style="COLOR: #0000bb">rman&nbsp;target&nbsp;</span><span style="COLOR: #007700">/<br />
<br /><br />
<br /></span><span style="COLOR: #0000bb">Recovery&nbsp;Manager</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">Release&nbsp;11.1.0.6.0&nbsp;</span><span style="COLOR: #007700">-&nbsp;</span><span style="COLOR: #0000bb">Production&nbsp;on&nbsp;Thu&nbsp;Aug&nbsp;16&nbsp;16</span><span style="COLOR: #007700">:</span><span style="COLOR: #0000bb">30</span><span style="COLOR: #007700">:</span><span style="COLOR: #0000bb">11&nbsp;2007<br />
<br /><br />
<br />Copyright&nbsp;</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">c</span><span style="COLOR: #007700">)&nbsp;</span><span style="COLOR: #0000bb">1982</span><span style="COLOR: #007700">,&nbsp;</span><span style="COLOR: #0000bb">2007</span><span style="COLOR: #007700">,&nbsp;</span><span style="COLOR: #0000bb">Oracle</span><span style="COLOR: #007700">.&nbsp;&nbsp;</span><span style="COLOR: #0000bb">All&nbsp;rights&nbsp;reserved</span><span style="COLOR: #007700">.<br />
<br /><br />
<br /></span><span style="COLOR: #0000bb">connected&nbsp;to&nbsp;target&nbsp;database</span><span style="COLOR: #007700">:&nbsp;</span><span style="COLOR: #0000bb">ORA11G&nbsp;</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">DBID</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">4026454982</span><span style="COLOR: #007700">,&nbsp;</span><span style="COLOR: #0000bb">not&nbsp;open</span><span style="COLOR: #007700">)<br />
<br /><br />
<br /></span><span style="COLOR: #0000bb">RMAN</span><span style="COLOR: #007700">&gt;&nbsp;</span><span style="COLOR: #0000bb">restore&nbsp;database</span><span style="COLOR: #007700">;<br />
<br /><br />
<br /></span><span style="COLOR: #0000bb">Starting&nbsp;restore&nbsp;at&nbsp;16</span><span style="COLOR: #007700">-</span><span style="COLOR: 