<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Oracle Force</title>
	<atom:link href="http://alexzeng.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://alexzeng.wordpress.com</link>
	<description>Alex Zeng's Oracle Weblog</description>
	<lastBuildDate>Mon, 29 Jun 2009 03:30:49 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='alexzeng.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/dd27d728a7b3af3e2be4c7ddd30f0d6b?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Oracle Force</title>
		<link>http://alexzeng.wordpress.com</link>
	</image>
			<item>
		<title>How to conver columns to rows and convert rows to columns?</title>
		<link>http://alexzeng.wordpress.com/2009/06/29/how-to-conver-columns-to-rows-and-convert-rows-to-columns/</link>
		<comments>http://alexzeng.wordpress.com/2009/06/29/how-to-conver-columns-to-rows-and-convert-rows-to-columns/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 03:30:49 +0000</pubDate>
		<dc:creator>alexzeng</dc:creator>
				<category><![CDATA[Data Management]]></category>

		<guid isPermaLink="false">http://alexzeng.wordpress.com/?p=124</guid>
		<description><![CDATA[Convert columns to rows:
create table tr1 (name varchar2(10), cust_value_1 number,cust_value_2 number,cust_value_3 number);
insert into tr1 values(&#8216;a&#8217;,1,1,1);
insert into tr1 values(&#8216;b&#8217;,1,0,1);
insert into tr1 values(&#8216;c&#8217;,0,0,1);
&#8211;transform sql
select * from (
select      name,
case when rowno=1 then cust_value_1
when rowno=2 then cust_value_2
when rowno=3 then cust_value_3
end cust_value
from tr1, (select rownum rowno  from dual connect by level &#60;= 3)
)
order by name;
NAME       CUST_VALUE
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-
a                   1
a                   1
a                   1
b                   [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=124&subd=alexzeng&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="color:#0000ff;">Convert columns to rows:</span><br />
create table tr1 (name varchar2(10), cust_value_1 number,cust_value_2 number,cust_value_3 number);<br />
insert into tr1 values(&#8216;a&#8217;,1,1,1);<br />
insert into tr1 values(&#8216;b&#8217;,1,0,1);<br />
insert into tr1 values(&#8216;c&#8217;,0,0,1);</p>
<p>&#8211;transform sql<br />
<span style="color:#0000ff;">select * from (<br />
select      name,<br />
case when rowno=1 then cust_value_1<br />
when rowno=2 then cust_value_2<br />
when rowno=3 then cust_value_3<br />
end cust_value<br />
from tr1, (select rownum rowno  from dual connect by level &lt;= 3)<br />
)<br />
order by name;</span></p>
<p>NAME       CUST_VALUE<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
a                   1<br />
a                   1<br />
a                   1<br />
b                   1<br />
b                   0<br />
b                   1<br />
c                   0<br />
c                   0<br />
c                   1</p>
<p>9 rows selected.</p>
<p><span style="color:#0000ff;"><br />
Convert rows to columns:</span><br />
<span style="color:#0000ff;">&#8211;1.number or varchar</span><br />
&#8211;create table and insert data<br />
create table tr2 (name varchar2(10), cust_value number);<br />
insert into tr2<br />
select * from (<br />
select      name,<br />
case when rowno=1 then cust_value_1<br />
when rowno=2 then cust_value_2<br />
when rowno=3 then cust_value_3<br />
end cust_value<br />
from tr1, (select rownum rowno  from dual connect by level &lt;= 3)<br />
)<br />
order by name;<br />
SQL&gt; select * from tr2;</p>
<p>NAME       CUST_VALUE<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
a                   1<br />
a                   1<br />
a                   1<br />
b                   1<br />
b                   0<br />
b                   1<br />
c                   0<br />
c                   0<br />
c                   1<br />
9 rows selected.</p>
<p>&#8211;transform sql<br />
<span style="color:#0000ff;">SELECT name,<br />
MAX(case when seq=1 then cust_value end) AS &#8220;cust_value_1&#8243;,<br />
MAX(case when seq=2 then cust_value end) AS &#8220;cust_value_2&#8243;,<br />
MAX(case when seq=3 then cust_value end) AS &#8220;cust_value_3&#8243;<br />
FROM (SELECT name, cust_value, ROW_NUMBER() over(partition by name ORDER BY name) AS seq FROM tr2)<br />
GROUP BY name;</span><br />
NAME       cust_value_1 cust_value_2 cust_value_3<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;<br />
a                     1            1            1<br />
b                     1            0            1<br />
c                     0            0            1</p>
<p>3 rows selected.</p>
<p><span style="color:#0000ff;">&#8211;2.connect varchar</span><br />
create table tr2v(gid number,name varchar2(10));<br />
insert into tr2v values (1,&#8217;Alex&#8217;);<br />
insert into tr2v values (1,&#8217;Alice&#8217;);<br />
insert into tr2v values (1,&#8217;Angle&#8217;);<br />
insert into tr2v values (2,&#8217;Bob&#8217;);<br />
insert into tr2v values (2,&#8217;Bill&#8217;);<br />
insert into tr2v values (3,&#8217;Charlie&#8217;);<br />
SQL&gt; select * from tr2v;</p>
<p>GID NAME<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
1 Alex<br />
1 Alice<br />
1 Angle<br />
2 Bob<br />
2 Bill<br />
3 Charlie</p>
<p>6 rows selected.</p>
<p>&#8211;transform sql<br />
<span style="color:#0000ff;">select gid,substr(SYS_CONNECT_BY_PATH(name,&#8217;,'),2) group_all<br />
from (select gid, name,<br />
count(*) over (partition by gid) cnt,<br />
row_number() over (partition by gid order by name) seq<br />
from tr2v<br />
) where cnt=seq<br />
start with seq=1 connect by prior seq+1=seq and prior gid=gid;</span></p>
<p>GID GROUP_ALL<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
1 Alex,Alice,Angle<br />
2 Bill,Bob<br />
3 Charlie</p>
<p>3 rows selected.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexzeng.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexzeng.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexzeng.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexzeng.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexzeng.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexzeng.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexzeng.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexzeng.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexzeng.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexzeng.wordpress.com/124/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=124&subd=alexzeng&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://alexzeng.wordpress.com/2009/06/29/how-to-conver-columns-to-rows-and-convert-rows-to-columns/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ec71fb52eb0cb170123476467bb48a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexzeng</media:title>
		</media:content>
	</item>
		<item>
		<title>How to setup Data Guard Broker and enable Fast Start Failover in 11g?</title>
		<link>http://alexzeng.wordpress.com/2009/06/24/how-to-setup-data-guard-broker-and-enable-fast-start-failover-in-11g/</link>
		<comments>http://alexzeng.wordpress.com/2009/06/24/how-to-setup-data-guard-broker-and-enable-fast-start-failover-in-11g/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 04:01:39 +0000</pubDate>
		<dc:creator>alexzeng</dc:creator>
				<category><![CDATA[Data Guard]]></category>
		<category><![CDATA[11g]]></category>
		<category><![CDATA[broker]]></category>

		<guid isPermaLink="false">http://alexzeng.wordpress.com/?p=121</guid>
		<description><![CDATA[Environment: 11g, initial primary db &#8216;upup&#8217;, standby db &#8216;upup1&#8242;
Here are the major steps:
1.Setup primary db and standby db
2.using spfile instead of pfile for both standby db and primary db.
3.set DG_BROKER_START = true
4.Set parameters of data guard broker configuration files
On the server you want to setup the broker, in my case, it is the primary db server
dg_broker_config_file1 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=121&subd=alexzeng&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Environment: 11g, initial primary db &#8216;upup&#8217;, standby db &#8216;upup1&#8242;</p>
<p>Here are the major steps:</p>
<p><span style="color:#0000ff;">1.Setup primary db and standby db</span><br />
<span style="color:#0000ff;">2.using spfile instead of pfile for both standby db and primary db.<br />
3.set DG_BROKER_START = true</span></p>
<p><span style="color:#0000ff;">4.Set parameters of data guard broker configuration files</span></p>
<p>On the server you want to setup the broker, in my case, it is the primary db server<br />
dg_broker_config_file1 = /u01/app/oracle/product/11.1.0/db_2/dbs/dr1upup1.dat<br />
dg_broker_config_file2 = /u01/app/oracle/product/11.1.0/db_2/dbs/dr2upup1.dat</p>
<p><span style="color:#0000ff;">5.static register services in listener</span></p>
<p>Configure service upup1_DGB in upup1 listener<br />
Configure service upup_DGB in upup listener</p>
<p><span style="color:#0000ff;">6.Setup the broker configuration</span><br />
<span style="color:#0000ff;">dgmgrl</span><br />
DGMGRL&gt; <span style="color:#0000ff;">connect /</span><br />
<span style="color:#0000ff;">create configuration my_dg as<br />
   primary database is upup1<br />
   connect identifier is upup1;</span></p>
<p><span style="color:#0000ff;">add database upup as<br />
   connect identifier is upup<br />
   maintained as physical;</span></p>
<p><span style="color:#0000ff;">enable configuration</span></p>
<p><span style="color:#0000ff;">show configuration<br />
</span>Configuration<br />
  Name:                my_dg<br />
  Enabled:             YES<br />
  Protection Mode:     MaxPerformance<br />
  Databases:<br />
    upup1 &#8211; Primary database<br />
    upup  &#8211; Physical standby database</p>
<p>Fast-Start Failover: DISABLED</p>
<p>Current status for &#8220;my_dg&#8221;:<br />
SUCCESS</p>
<p>DGMGRL&gt; <span style="color:#0000ff;">show database verbose upup1</span></p>
<p>Database<br />
  Name:            upup1<br />
  Role:            PRIMARY<br />
  Enabled:         YES<br />
  Intended State:  TRANSPORT-ON<br />
  Instance(s):<br />
    upup</p>
<p>  Properties:<br />
    DGConnectIdentifier             = &#8216;upup1&#8242;<br />
    ObserverConnectIdentifier       = &#8221;<br />
    LogXptMode                      = &#8216;ASYNC&#8217;<br />
    DelayMins                       = &#8216;0&#8242;<br />
    Binding                         = &#8216;OPTIONAL&#8217;<br />
    MaxFailure                      = &#8216;0&#8242;<br />
    MaxConnections                  = &#8216;1&#8242;<br />
    ReopenSecs                      = &#8216;300&#8242;<br />
    NetTimeout                      = &#8216;30&#8242;<br />
    RedoCompression                 = &#8216;DISABLE&#8217;<br />
    LogShipping                     = &#8216;ON&#8217;<br />
    PreferredApplyInstance          = &#8221;<br />
    ApplyInstanceTimeout            = &#8216;0&#8242;<br />
    ApplyParallel                   = &#8216;AUTO&#8217;<br />
    StandbyFileManagement           = &#8216;auto&#8217;<br />
    ArchiveLagTarget                = &#8216;0&#8242;<br />
    LogArchiveMaxProcesses          = &#8216;5&#8242;<br />
    LogArchiveMinSucceedDest        = &#8216;1&#8242;<br />
    DbFileNameConvert               = &#8221;<br />
    LogFileNameConvert              = &#8221;<br />
    FastStartFailoverTarget         = &#8221;<br />
    StatusReport                    = &#8216;(monitor)&#8217;<br />
    InconsistentProperties          = &#8216;(monitor)&#8217;<br />
    InconsistentLogXptProps         = &#8216;(monitor)&#8217;<br />
    SendQEntries                    = &#8216;(monitor)&#8217;<br />
    LogXptStatus                    = &#8216;(monitor)&#8217;<br />
    RecvQEntries                    = &#8216;(monitor)&#8217;<br />
    HostName                        = &#8216;rac1.baby.com&#8217;<br />
    SidName                         = &#8216;upup&#8217;<br />
    StandbyArchiveLocation          = &#8216;/u01/app/oracle/oradata/upup/arch/&#8217;<br />
    AlternateLocation               = &#8221;<br />
    LogArchiveTrace                 = &#8216;0&#8242;<br />
    LogArchiveFormat                = &#8216;upup_%t_%s_%r.arc&#8217;<br />
    LatestLog                       = &#8216;(monitor)&#8217;<br />
    TopWaitEvents                   = &#8216;(monitor)&#8217;</p>
<p>Current status for &#8220;upup1&#8243;:<br />
SUCCESS</p>
<p>DGMGRL&gt; <span style="color:#0000ff;">show database verbose upup</span></p>
<p>Database<br />
  Name:            upup<br />
  Role:            PHYSICAL STANDBY<br />
  Enabled:         YES<br />
  Intended State:  APPLY-ON<br />
  Instance(s):<br />
    upup</p>
<p>  Properties:<br />
    DGConnectIdentifier             = &#8216;upup&#8217;<br />
    ObserverConnectIdentifier       = &#8221;<br />
    LogXptMode                      = &#8216;ASYNC&#8217;<br />
    DelayMins                       = &#8216;0&#8242;<br />
    Binding                         = &#8216;OPTIONAL&#8217;<br />
    MaxFailure                      = &#8216;0&#8242;<br />
    MaxConnections                  = &#8216;1&#8242;<br />
    ReopenSecs                      = &#8216;300&#8242;<br />
    NetTimeout                      = &#8216;30&#8242;<br />
    RedoCompression                 = &#8216;DISABLE&#8217;<br />
    LogShipping                     = &#8216;ON&#8217;<br />
    PreferredApplyInstance          = &#8221;<br />
    ApplyInstanceTimeout            = &#8216;0&#8242;<br />
    ApplyParallel                   = &#8216;AUTO&#8217;<br />
    StandbyFileManagement           = &#8216;auto&#8217;<br />
    ArchiveLagTarget                = &#8216;0&#8242;<br />
    LogArchiveMaxProcesses          = &#8216;5&#8242;<br />
    LogArchiveMinSucceedDest        = &#8216;1&#8242;<br />
    DbFileNameConvert               = &#8221;<br />
    LogFileNameConvert              = &#8221;<br />
    FastStartFailoverTarget         = &#8221;<br />
    StatusReport                    = &#8216;(monitor)&#8217;<br />
    InconsistentProperties          = &#8216;(monitor)&#8217;<br />
    InconsistentLogXptProps         = &#8216;(monitor)&#8217;<br />
    SendQEntries                    = &#8216;(monitor)&#8217;<br />
    LogXptStatus                    = &#8216;(monitor)&#8217;<br />
    RecvQEntries                    = &#8216;(monitor)&#8217;<br />
    HostName                        = &#8216;rac2.baby.com&#8217;<br />
    SidName                         = &#8216;upup&#8217;<br />
    StandbyArchiveLocation          = &#8216;/u01/app/oracle/oradata/upup/arch/&#8217;<br />
    AlternateLocation               = &#8221;<br />
    LogArchiveTrace                 = &#8216;0&#8242;<br />
    LogArchiveFormat                = &#8216;upup_%t_%s_%r.arc&#8217;<br />
    LatestLog                       = &#8216;(monitor)&#8217;<br />
    TopWaitEvents                   = &#8216;(monitor)&#8217;</p>
<p>Current status for &#8220;upup&#8221;:<br />
SUCCESS</p>
<p><span style="color:#0000ff;">6.Switchover</span><br />
<span style="color:#0000ff;"><span style="color:#000000;">DGMGRL&gt;</span> switchover to upup<br />
</span>Performing switchover NOW, please wait&#8230;<br />
New primary database &#8220;upup&#8221; is opening&#8230;<br />
Operation requires shutdown of instance &#8220;upup&#8221; on database &#8220;upup1&#8243;<br />
Shutting down instance &#8220;upup&#8221;&#8230;<br />
ORA-01031: insufficient privileges</p>
<p>You are no longer connected to ORACLE<br />
Please connect again.<br />
Unable to shut down instance &#8220;upup&#8221;<br />
You must shut down instance &#8220;upup&#8221; manually<br />
Operation requires startup of instance &#8220;upup&#8221; on database &#8220;upup1&#8243;<br />
You must start instance &#8220;upup&#8221; manually<br />
Switchover succeeded, new primary is &#8220;upup&#8221;</p>
<p><span style="color:#0000ff;">Now upup is primary and in open status, I need to shutdown upup1 and startup mount</span><br />
conn <a href="mailto:sys/oracle@upup1">sys/oracle@upup1</a> as sysdba<br />
SQL&gt; shutdown immediate</p>
<p><span style="color:#0000ff;">7.Check DGMGRL status again</span><br />
DGMGRL&gt; show configuration</p>
<p>Configuration<br />
  Name:                my_dg<br />
  Enabled:             YES<br />
  Protection Mode:     MaxPerformance<br />
  Databases:<br />
    upup  &#8211; Primary database<br />
    upup1 &#8211; Physical standby database</p>
<p>Fast-Start Failover: DISABLED</p>
<p>Current status for &#8220;my_dg&#8221;:<br />
SUCCESS</p>
<p><span style="color:#0000ff;">8.Setup Fast failover</span><br />
<span style="color:#0000ff;">&#8211;Enable flashback on both db<br />
</span>SQL&gt; startup mount<br />
SQL&gt; alter system set db_recovery_file_dest_size=1G;<br />
SQL&gt; alter system set db_recovery_file_dest=&#8217;/u01/app/oracle/oradata&#8217;;</p>
<p><span style="color:#0000ff;">&#8211;set fast failover target</span><br />
DGMGRL&gt; EDIT DATABASE upup SET PROPERTY FastStartFailoverTarget = upup1;<br />
DGMGRL&gt; EDIT DATABASE upup1 SET PROPERTY FastStartFailoverTarget = upup;</p>
<p><span style="color:#0000ff;">&#8211;set log mode and protection mode</span><br />
DGMGRL&gt; EDIT DATABASE &#8216;upup&#8217; SET PROPERTY LogXptMode=SYNC;<br />
DGMGRL&gt; EDIT DATABASE &#8216;upup1&#8242; SET PROPERTY LogXptMode=SYNC;<br />
DGMGRL&gt; EDIT CONFIGURATION SET PROTECTION MODE AS MaxAvailability;<br />
DGMGRL&gt; EDIT CONFIGURATION SET PROPERTY FastStartFailoverThreshold = 10;</p>
<p><span style="color:#0000ff;">&#8211;enable fash failover<br />
</span>DGMGRL&gt; enable fast_start failover<br />
DGMGRL&gt; connect <a href="mailto:sys/oracle@upup1">sys/oracle@upup1</a><br />
Connected.<br />
DGMGRL&gt;<span style="color:#0000ff;"> start observer</span><br />
Observer started<br />
&#8230;&lt;to be continue&gt;&#8230;</p>
<p>&#8211;connect another session<br />
dgmgrl<br />
DGMGRL&gt; <span style="color:#0000ff;">show fast_start failover</span></p>
<p>Fast-Start Failover: ENABLED<br />
  Threshold:           10 seconds<br />
  Target:              upup1<br />
  Observer:            rac1.baby.com<br />
  Lag Limit:           30 seconds (not in use)<br />
  Shutdown Primary:    TRUE<br />
  Auto-reinstate:      TRUE</p>
<p>Configurable Failover Conditions<br />
  Health Conditions:<br />
    Corrupted Controlfile          YES<br />
    Corrupted Dictionary           YES<br />
    Inaccessible Logfile            NO<br />
    Stuck Archiver                  NO<br />
    Datafile Offline               YES</p>
<p>  Oracle Error Conditions:<br />
    (none)</p>
<p><span style="color:#0000ff;">Make sure standby db is ready to fast failover</span><br />
SQL&gt; <span style="color:#0000ff;"> select  FS_FAILOVER_STATUS,FS_FAILOVER_OBSERVER_PRESENT   from v$database;</span></p>
<p>FS_FAILOVER_STATUS     FS_FAIL<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;-<br />
<span style="color:#0000ff;">SYNCHRONIZED           YES</span></p>
<p><span style="color:#0000ff;">conn primary db, simulate primary failure</span><br />
SQL&gt; <span style="color:#0000ff;">shutdown abort<br />
</span>ORACLE instance shut down.</p>
<p>At the observer session:<br />
DGMGRL&gt; start observer<br />
Observer started<br />
21:50:30.64  Tuesday, June 23, 2009<br />
Initiating Fast-Start Failover to database &#8220;upup1&#8243;&#8230;<br />
Performing failover NOW, please wait&#8230;<br />
Failover succeeded, new primary is &#8220;upup1&#8243;<br />
21:50:51.64  Tuesday, June 23, 2009</p>
<p>21:56:10.28  Tuesday, June 23, 2009<br />
Initiating reinstatement for database &#8220;upup&#8221;&#8230;<br />
Reinstating database &#8220;upup&#8221;, please wait&#8230;<br />
Operation requires shutdown of instance &#8220;upup&#8221; on database &#8220;upup&#8221;<br />
Shutting down instance &#8220;upup&#8221;&#8230;<br />
ORA-01109: database not open</p>
<p>Database dismounted.<br />
ORACLE instance shut down.<br />
Operation requires startup of instance &#8220;upup&#8221; on database &#8220;upup&#8221;<br />
Starting instance &#8220;upup&#8221;&#8230;<br />
Unable to connect to database<br />
ORA-12541: TNS:no listener</p>
<p>Failed.<br />
You are no longer connected to ORACLE<br />
Please connect again.<br />
Unable to start instance &#8220;upup&#8221;<br />
You must start instance &#8220;upup&#8221; manually<br />
Reinstatement of database &#8220;upup&#8221; failed<br />
21:56:33.07  Tuesday, June 23, 2009</p>
<p>&#8211;as indicated, start upup<br />
SQL&gt; startup mount</p>
<p>DGMGRL&gt; <span style="color:#0000ff;">reinstate database upup;</span><br />
Reinstating database &#8220;upup&#8221;, please wait&#8230;<br />
Reinstatement of database &#8220;upup&#8221; succeeded</p>
<p>DGMGRL&gt; <span style="color:#0000ff;">show database verbose upup</span></p>
<p>Database<br />
  Name:            upup<br />
  Role:            PHYSICAL STANDBY<br />
  Enabled:         YES<br />
  Intended State:  APPLY-ON<br />
  Instance(s):<br />
    upup</p>
<p>  Properties:<br />
    DGConnectIdentifier             = &#8216;upup&#8217;<br />
    ObserverConnectIdentifier       = &#8221;<br />
    LogXptMode                      = &#8217;sync&#8217;<br />
    DelayMins                       = &#8216;0&#8242;<br />
    Binding                         = &#8216;OPTIONAL&#8217;<br />
    MaxFailure                      = &#8216;0&#8242;<br />
    MaxConnections                  = &#8216;1&#8242;<br />
    ReopenSecs                      = &#8216;300&#8242;<br />
    NetTimeout                      = &#8216;30&#8242;<br />
    RedoCompression                 = &#8216;DISABLE&#8217;<br />
    LogShipping                     = &#8216;ON&#8217;<br />
    PreferredApplyInstance          = &#8221;<br />
    ApplyInstanceTimeout            = &#8216;0&#8242;<br />
    ApplyParallel                   = &#8216;AUTO&#8217;<br />
    StandbyFileManagement           = &#8216;auto&#8217;<br />
    ArchiveLagTarget                = &#8216;0&#8242;<br />
    LogArchiveMaxProcesses          = &#8216;5&#8242;<br />
    LogArchiveMinSucceedDest        = &#8216;1&#8242;<br />
    DbFileNameConvert               = &#8221;<br />
    LogFileNameConvert              = &#8221;<br />
    FastStartFailoverTarget         = &#8216;upup1&#8242;<br />
    StatusReport                    = &#8216;(monitor)&#8217;<br />
    InconsistentProperties          = &#8216;(monitor)&#8217;<br />
    InconsistentLogXptProps         = &#8216;(monitor)&#8217;<br />
    SendQEntries                    = &#8216;(monitor)&#8217;<br />
    LogXptStatus                    = &#8216;(monitor)&#8217;<br />
    RecvQEntries                    = &#8216;(monitor)&#8217;<br />
    HostName                        = &#8216;rac2.baby.com&#8217;<br />
    SidName                         = &#8216;upup&#8217;<br />
    StandbyArchiveLocation          = &#8216;/u01/app/oracle/oradata/upup/arch/&#8217;<br />
    AlternateLocation               = &#8221;<br />
    LogArchiveTrace                 = &#8216;0&#8242;<br />
    LogArchiveFormat                = &#8216;upup_%t_%s_%r.arc&#8217;<br />
    LatestLog                       = &#8216;(monitor)&#8217;<br />
    TopWaitEvents                   = &#8216;(monitor)&#8217;</p>
<p>Current status for &#8220;upup&#8221;:<br />
SUCCESS</p>
<p><span style="color:#0000ff;">Note: monitor your alter logs all the time and correct error if any.</span></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexzeng.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexzeng.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexzeng.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexzeng.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexzeng.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexzeng.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexzeng.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexzeng.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexzeng.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexzeng.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=121&subd=alexzeng&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://alexzeng.wordpress.com/2009/06/24/how-to-setup-data-guard-broker-and-enable-fast-start-failover-in-11g/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ec71fb52eb0cb170123476467bb48a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexzeng</media:title>
		</media:content>
	</item>
		<item>
		<title>How to operate lob by using DBMS_LOB in 11g</title>
		<link>http://alexzeng.wordpress.com/2009/02/27/how-to-operate-lob-by-using-dbms_lob-in-11g/</link>
		<comments>http://alexzeng.wordpress.com/2009/02/27/how-to-operate-lob-by-using-dbms_lob-in-11g/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 07:03:02 +0000</pubDate>
		<dc:creator>alexzeng</dc:creator>
				<category><![CDATA[Program Development]]></category>
		<category><![CDATA[11g]]></category>
		<category><![CDATA[lob]]></category>

		<guid isPermaLink="false">http://alexzeng.wordpress.com/?p=116</guid>
		<description><![CDATA[–Test version: 11.1.0.6
&#8211;The DBMS_LOB package provides subprograms to operate on BLOBs, CLOBs, NCLOBs, BFILEs, and temporary LOBs.
&#8211;DBMS_LOB can read and modify BLOBs, CLOBs, and NCLOBs;it provides read-only operations for BFILEs
Temporary LOB
-Stored in temporary tablespaces, deleted at the end of the session by default
Internal LOB
-LOB columns are defined in a table
-Use DML to initialize or populate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=116&subd=alexzeng&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="color:#0000ff;">–Test version: 11.1.0.6</span></p>
<p>&#8211;The DBMS_LOB package provides subprograms to operate on BLOBs, CLOBs, NCLOBs, BFILEs, and temporary LOBs.<br />
&#8211;DBMS_LOB can read and modify BLOBs, CLOBs, and NCLOBs;it provides read-only operations for BFILEs<br />
<span style="color:#0000ff;">Temporary LOB</span><br />
-Stored in temporary tablespaces, deleted at the end of the session by default<br />
<span style="color:#0000ff;">Internal LOB</span><br />
-LOB columns are defined in a table<br />
-Use DML to initialize or populate the locators in the LOB columns<br />
<span style="color:#0000ff;">External LOB</span><br />
-BFILE is the only type, can only read data in oracle.<br />
-Using DIRECTORY and filename to create a LOB locator</p>
<p><span style="color:#0000ff;">&#8211;<br />
&#8211;Temporary LOB<br />
&#8211;</span><br />
&#8211;create test tables<br />
create table t1 (id number, chunk_value1 varchar2(4000),chunk_value2 varchar2(4000));<br />
create table t2 (id number, chunk clob);</p>
<p>create or replace function f_getclob(p_chunk1 in varchar2,p_chunk2 in varchar2)<br />
return clob<br />
as<br />
v_chunk clob;<br />
v_temp varchar2(8000);<br />
begin<br />
<span style="color:#0000ff;">dbms_lob.createtemporary(lob_loc=&gt; v_chunk, cache=&gt; true, dur=&gt; dbms_lob.session);</span><br />
v_temp := p_chunk1||p_chunk2;<br />
<span style="color:#0000ff;"> dbms_lob.write(v_chunk,length(v_temp),1,v_temp);</span><br />
&#8211;dbms_lob.freetemporary(v_chunk);<br />
&#8211;as we need to return it, we cannot free it now.let it free automatically<br />
return v_chunk;<br />
end;<br />
/</p>
<p>&#8211;insert data<br />
insert into t1 values(1,lpad(&#8216;*&#8217;,4000,&#8217;*'),&#8217;test&#8217;);<br />
insert into t2 select id,f_getclob(chunk_value1,chunk_value2) from t1;<br />
SQL&gt; select id,length(chunk) from t2;<br />
ID LENGTH(CHUNK)<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;-<br />
1          4004</p>
<p><span style="color:#0000ff;">SQL&gt; select * from V$TEMPORARY_LOBS;</span></p>
<p>SID CACHE_LOBS NOCACHE_LOBS ABSTRACT_LOBS<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;-<br />
231          0            0             0</p>
<p><span style="color:#0000ff;">&#8211;check tempsize used by temporary LOB</span><br />
select s.username, s.sid, u.tablespace, u.contents, u.segtype, round(u.blocks*8192/1024/1024,2) MB<br />
from v$session s, <span style="color:#0000ff;">v$sort_usage</span> u<br />
where s.saddr = u.session_addr and <span style="color:#0000ff;">u.contents = &#8216;TEMPORARY&#8217;</span> and <span style="color:#0000ff;">u.segtype=&#8217;LOB_DATA&#8217;</span><br />
order by MB DESC ;<br />
USERNAME                              SID TABLESPACE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
CONTENTS  SEGTYPE           MB<br />
&#8212;&#8212;&#8212; &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;-<br />
SCOTT                            231 TEMP<br />
TEMPORARY LOB_DATA           1</p>
<p><span style="color:#0000ff;">&#8211;<br />
&#8211;Internal LOB<br />
&#8211;</span><br />
create table ti1(id number unique, <span style="color:#0000ff;">chunk clob</span>);<br />
create or replace procedure p_insertlob(p_id in number,p_chunk1 in varchar2,p_chunk2 in varchar2) as<br />
v_clob clob;<br />
begin<br />
&#8211;insert<br />
insert into ti1 values (p_id,<span style="color:#0000ff;"> empty_clob()</span>) returning chunk into v_clob;<br />
<span style="color:#0000ff;"> dbms_lob.write(v_clob,length(p_chunk1),1,p_chunk1);</span><br />
commit;<br />
&#8211;update<br />
select chunk into v_clob from ti1 where id=p_id <span style="color:#0000ff;">for update;</span><br />
<span style="color:#0000ff;"> dbms_lob.writeappend(v_clob,length(p_chunk2),p_chunk2);</span><br />
commit;<br />
end;<br />
/</p>
<p>exec p_insertlob(1,lpad(&#8216;$&#8217;,32767,&#8217;$'),lpad(&#8216;*&#8217;,32767,&#8217;*'));</p>
<p>select id,dbms_lob.getlength(chunk) from ti1;</p>
<p>ID DBMS_LOB.GETLENGTH(CHUNK)<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1                     65534</p>
<p>Note:if you have functional and domain indexes on the LOB column, using dbms_lob.open() before write and dbms_lob.close() before commit are good for performance.<br />
as the close() operation will trigger update on indexes. If no open() and close(), the indexes are updated at the same time doing update.</p>
<p><span style="color:#0000ff;">&#8211;<br />
&#8211;External LOB<br />
&#8211;</span><br />
&#8211;function to read file from a giving diretory and file name<br />
create or replace function p_get_elob(p_directory varchar2, p_filename varchar2)<br />
return clob<br />
as<br />
v_file bfile;<br />
v_flag integer :=0;<br />
v_length number :=0;<br />
v_clob clob;<br />
v_src_offset integer :=1;<br />
v_des_offset integer :=1;<br />
v_lang_context integer :=0;<br />
v_waring integer;<br />
begin<br />
dbms_lob.createtemporary(v_clob, true, dbms_lob.session);<br />
<span style="color:#0000ff;">v_file := bfilename(p_directory,p_filename);</span><br />
v_flag := dbms_lob.fileexists(v_file);<br />
if v_flag =0  then<br />
dbms_output.put_line(&#8216;File does not exist!&#8217;);<br />
else<br />
v_flag := dbms_lob.fileisopen(v_file);<br />
if v_flag =0 then<br />
<span style="color:#0000ff;"> dbms_lob.fileopen(v_file,dbms_lob.file_readonly); </span><br />
end if;<br />
v_length := dbms_lob.getlength(v_file);<br />
<span style="color:#0000ff;">dbms_lob.loadclobfromfile(v_clob, v_file, v_length, v_src_offset, v_des_offset, 0, v_lang_context, v_waring);</span><br />
end if;<br />
dbms_output.put_line(&#8216;File length :&#8217;||dbms_lob.getlength(v_file));<br />
dbms_output.put_line(&#8216;Return length :&#8217;||dbms_lob.getlength(v_clob));<br />
dbms_lob.fileclose(v_file);<br />
return v_clob;<br />
end;<br />
/</p>
<p>&#8211;test<br />
select p_get_elob(&#8216;T&#8217;,'t.txt&#8217;)||&#8217;@&#8217; from dual;</p>
<p>P_GET_ELOB(&#8216;T&#8217;,'T.TXT&#8217;)||&#8217;@&#8217;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Data Pump default directory object created:<br />
directory object name: DATA_PUMP_DIR<br />
creation date: 11-FEB-2009 01:52<br />
END!<br />
@</p>
<p>File length :121<br />
Return length :121</p>
<p>References:<br />
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/d_lob.htm about operating lob<br />
http://www.mydatabasesupport.com/forums/oracle-server/244585-tuning-clob-usage.html about lob performance<br />
http://www.idevelopment.info/data/Oracle/DBA_tips/LOBs/LOBS_1.shtml about genernal lob idea<br />
metalink doc 61737.1</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexzeng.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexzeng.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexzeng.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexzeng.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexzeng.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexzeng.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexzeng.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexzeng.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexzeng.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexzeng.wordpress.com/116/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=116&subd=alexzeng&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://alexzeng.wordpress.com/2009/02/27/how-to-operate-lob-by-using-dbms_lob-in-11g/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ec71fb52eb0cb170123476467bb48a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexzeng</media:title>
		</media:content>
	</item>
		<item>
		<title>Result cache in oracle 11g</title>
		<link>http://alexzeng.wordpress.com/2008/12/18/result-cache-in-oracle-11g/</link>
		<comments>http://alexzeng.wordpress.com/2008/12/18/result-cache-in-oracle-11g/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 10:14:15 +0000</pubDate>
		<dc:creator>alexzeng</dc:creator>
				<category><![CDATA[Performance Management]]></category>
		<category><![CDATA[11g]]></category>

		<guid isPermaLink="false">http://alexzeng.wordpress.com/?p=113</guid>
		<description><![CDATA[DB version: 11.1.0.6
*Result cache:
The result cache stores the results of SQL queries and PL/SQL functions in an area called Result Cache Memory in the shared pool.
Server result cache is detetermined by below 3 parameters:
result_cache_max_result              integer     5
result_cache_max_size                big integer 384K
result_cache_mode string      MANUAL
if result_cache_mode is AUTO, no hint is requred to cache the sql result. It is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=113&subd=alexzeng&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>DB version: 11.1.0.6</p>
<p><span style="color:#0000ff;">*Result cache:<br />
The result cache stores the results of SQL queries and PL/SQL functions in an area called Result Cache Memory in the shared pool.</span></p>
<p><span style="color:#0000ff;">Server result cache</span> is detetermined by below 3 parameters:<br />
result_cache_max_result              integer     5<br />
result_cache_max_size                big integer 384K<br />
<span style="color:#0000ff;">result_cache_mode</span> string      MANUAL<br />
if result_cache_mode is AUTO, no hint is requred to cache the sql result. It is automatically done by oracle.</p>
<p><span style="color:#0000ff;">Client result cache </span>is detemined by below 2 parameters:<br />
client_result_cache_lag              big integer 3000<br />
<span style="color:#0000ff;">client_result_cache_size</span> big integer 0 (32K is minimum,less than it will disable the feature)<br />
When client result caching is enabled, the query result set can be cached on the client or on the server or both</p>
<p><span style="color:#0000ff;">Sql Example:<br />
SYS@ORA11G&gt;select/*+ result_cache */ count(*) from t.t2 where object_id&gt;10000;</span><br />
Both client side and server side require same hint result_cache when result_cache_mode is MANUAL.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexzeng.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexzeng.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexzeng.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexzeng.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexzeng.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexzeng.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexzeng.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexzeng.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexzeng.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexzeng.wordpress.com/113/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=113&subd=alexzeng&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://alexzeng.wordpress.com/2008/12/18/result-cache-in-oracle-11g/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ec71fb52eb0cb170123476467bb48a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexzeng</media:title>
		</media:content>
	</item>
		<item>
		<title>Step by step test Sql Performance Analyzer of Real Application Test</title>
		<link>http://alexzeng.wordpress.com/2008/12/12/step-by-step-test-sql-performance-analyzer-of-real-application-test/</link>
		<comments>http://alexzeng.wordpress.com/2008/12/12/step-by-step-test-sql-performance-analyzer-of-real-application-test/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 08:10:28 +0000</pubDate>
		<dc:creator>alexzeng</dc:creator>
				<category><![CDATA[Performance Management]]></category>
		<category><![CDATA[11g]]></category>
		<category><![CDATA[scratch]]></category>

		<guid isPermaLink="false">http://alexzeng.wordpress.com/?p=111</guid>
		<description><![CDATA[&#8211;Test version: 11.1.0.6
&#8211;
&#8211;create an analysis task
&#8211;
&#8211;Use the following procedures to create a sql tuning set
&#8211; populate the tuning set from the cursor cache
DECLARE
cur DBMS_SQLTUNE.SQLSET_CURSOR;
BEGIN
DBMS_SQLTUNE.CREATE_SQLSET(
sqlset_name =&#62; &#8216;my_sts&#8217;,
description  =&#62; &#8216;Sql tunning set for SPA&#8217;);
OPEN cur FOR
SELECT VALUE(P)
FROM table(
DBMS_SQLTUNE.SELECT_CURSOR_CACHE(
&#8216;parsing_schema_name &#60;&#62; &#8221;SYS&#8221; &#8216;,
NULL, NULL, NULL, NULL, 1, NULL,
&#8216;ALL&#8217;)) P;
DBMS_SQLTUNE.LOAD_SQLSET(sqlset_name =&#62; &#8216;my_sts&#8217;,
populate_cursor =&#62; cur);
END;
/
&#8211;show sql tune set contents
SELECT * FROM [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=111&subd=alexzeng&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="color:#0000ff;">&#8211;Test version: 11.1.0.6</span></p>
<p><span style="color:#0000ff;">&#8211;<br />
&#8211;create an analysis task<br />
&#8211;</span><br />
&#8211;Use the following procedures to create a sql tuning set<br />
&#8211; populate the tuning set from the cursor cache<br />
DECLARE<br />
cur DBMS_SQLTUNE.SQLSET_CURSOR;<br />
BEGIN<br />
DBMS_SQLTUNE.CREATE_SQLSET(<br />
sqlset_name =&gt; &#8216;my_sts&#8217;,<br />
description  =&gt; &#8216;Sql tunning set for SPA&#8217;);<br />
OPEN cur FOR<br />
SELECT VALUE(P)<br />
FROM table(<br />
DBMS_SQLTUNE.SELECT_CURSOR_CACHE(<br />
&#8216;parsing_schema_name &lt;&gt; &#8221;SYS&#8221; &#8216;,<br />
NULL, NULL, NULL, NULL, 1, NULL,<br />
&#8216;ALL&#8217;)) P;<br />
DBMS_SQLTUNE.LOAD_SQLSET(sqlset_name =&gt; &#8216;my_sts&#8217;,<br />
populate_cursor =&gt; cur);<br />
END;<br />
/<br />
&#8211;show sql tune set contents<br />
SELECT * FROM TABLE(DBMS_SQLTUNE.SELECT_SQLSET(&#8216;my_sts&#8217;));</p>
<p><span style="color:#0000ff;">&#8211;create analysis task<br />
VARIABLE t_name VARCHAR2(100);<br />
EXEC :t_name := DBMS_SQLPA.CREATE_ANALYSIS_TASK(sqlset_name =&gt; &#8216;my_sts&#8217;,task_name =&gt; &#8216;my_spa_task&#8217;);</span></p>
<p>&#8211;Also you can create a analysis task by giving sql_text<br />
EXEC :t_name := DBMS_SQLPA.CREATE_ANALYSIS_TASK(sql_text =&gt; &#8217;select * from t2 where object_id=990&#8242;,task_name =&gt; &#8217;single_spa_task&#8217;);</p>
<p><span style="color:#0000ff;">&#8211;create a pre-change sql trail<br />
EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(task_name =&gt; &#8216;my_spa_task&#8217;, execution_type =&gt; &#8216;TEST EXECUTE&#8217;, execution_name =&gt; &#8216;my_exec_BEFORE_change&#8217;);</span></p>
<p><span style="color:#0000ff;">&#8211;perform changes on the test system</span><br />
SYS@ORA11G&gt;alter system set memory_target=140m;<br />
T@ORA11G&gt;drop index t2_oid;<br />
&#8230;</p>
<p><span style="color:#0000ff;">&#8211;create a post-change sql trial<br />
EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(task_name =&gt; &#8216;my_spa_task&#8217;, execution_type =&gt; &#8216;TEST EXECUTE&#8217;, execution_name =&gt; &#8216;my_exec_AFTER_change&#8217;); </span></p>
<p><span style="color:#0000ff;">&#8211;compare sql trials<br />
&#8211;analysis<br />
EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(task_name =&gt; &#8216;my_spa_task&#8217;, execution_type =&gt; &#8216;COMPARE PERFORMANCE&#8217;, execution_name =&gt; &#8216;my_exec_compare&#8217;, execution_params =&gt; dbms_advisor.arglist(&#8216;execution_name1&#8242;,&#8217;my_exec_BEFORE_change&#8217;,'execution_name2&#8242;,&#8217;my_exec_AFTER_change&#8217;,'comparison_metric&#8217;, &#8216;buffer_gets&#8217;));</span></p>
<p><span style="color:#0000ff;">&#8211;report<br />
VAR rep   CLOB;<br />
EXEC :rep := DBMS_SQLPA.REPORT_ANALYSIS_TASK(&#8216;my_spa_task&#8217;,'text&#8217;, &#8216;typical&#8217;, &#8217;summary&#8217;);<br />
SET LONG 100000 LONGCHUNKSIZE 100000 LINESIZE 130<br />
PRINT :rep</span><br />
REP<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&#8212;&#8212;&#8212;-<br />
General Information<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Task Information:                              Workload Information:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Task Name    : my_spa_task                     SQL Tuning Set Name        : my_sts<br />
Task Owner   : SYS                             SQL Tuning Set Owner       : SYS<br />
Description  :                                 Total SQL Statement Count  : 17</p>
<p>Execution Information:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Execution Name  : my_exec_compare        Started             : 12/12/2008 15:52:51<br />
Execution Type  : COMPARE PERFORMANCE    Last Updated        : 12/12/2008 15:52:51<br />
Description     :                        Global Time Limit   : UNLIMITED<br />
Scope           : COMPREHENSIVE          Per-SQL Time Limit  : UNUSED<br />
Status          : COMPLETED              Number of Errors    : 8</p>
<p>Analysis Information:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Comparison Metric: BUFFER_GETS<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Workload Impact Threshold: 1%<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
SQL Impact Threshold: 1%<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Before Change Execution:                       After Change Execution:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Execution Name      : my_exec_BEFORE_change    Execution Name      : my_exec_AFTER_change<br />
Execution Type      : TEST EXECUTE             Execution Type      : TEST EXECUTE<br />
Description         :                          Description         :<br />
Scope               : COMPREHENSIVE            Scope               : COMPREHENSIVE<br />
Status              : COMPLETED                Status              : COMPLETED<br />
Started             : 12/12/2008 15:43:56      Started             : 12/12/2008 15:46:02<br />
Last Updated        : 12/12/2008 15:43:58      Last Updated        : 12/12/2008 15:46:03<br />
Global Time Limit   : UNLIMITED                Global Time Limit   : UNLIMITED<br />
Per-SQL Time Limit  : UNUSED                   Per-SQL Time Limit  : UNUSED<br />
Number of Errors    : 1                        Number of Errors    : 2</p>
<p>Report Summary<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Projected Workload Change Impact:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Overall Impact      :  -3.57%<br />
Improvement Impact  :  0%<br />
Regression Impact   :  -3.57%</p>
<p>SQL Statement Count<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
SQL Category  SQL Count  Plan Change Count<br />
Overall              17                  2<br />
Regressed             2                  2<br />
Unchanged             7                  0<br />
with Errors           8                  0</p>
<p>Projected Workload Performance Distribution<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
|          | Cumulative Perf. |        | Cumulative Perf. |        |<br />
| Bucket   | Before Change    | (%)    | After Change     | (%)    |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| &lt; = 1    |                0 |     0% |                0 |     0% |<br />
| &lt; = 4    |                9 |   .11% |                6 |   .07% |<br />
| &lt; = 32   |               31 |   .38% |                0 |     0% |<br />
| &lt; = 256  |              328 |  4.04% |              652 |  7.75% |<br />
| &lt; = 8192 |             7756 | 95.47% |             7756 | 92.18% |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Single SQL Statement Execution Count Distribution<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
|          | SQL Count     |        | SQL Count    |        |<br />
| Bucket   | Before Change | (%)    | After Change | (%)    |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| &lt; = 1    |             2 | 11.76% |            2 | 11.76% |<br />
| &lt; = 4    |             3 | 17.65% |            2 | 11.76% |<br />
| &lt; = 32   |             1 |  5.88% |            0 |     0% |<br />
| &lt; = 256  |             2 | 11.76% |            4 | 23.53% |<br />
| &lt; = 8192 |             1 |  5.88% |            1 |  5.88% |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>SQL Statements Sorted by their Absolute Value of Change Impact on the Workload<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
|           |               | Impact on | Metric | Metric | Impact   | % Workload | % Workload | Plan   |<br />
| object_id | sql_id        | Workload  | Before | After  | on SQL   | Before     | After      | Change |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
|        49 | <span style="color:#0000ff;">2ydjxgd87t9hk </span>|    -1.96% |      3 |    162 |   -5300% |       .04% |      1.93% | y   |<br />
|        47 | <span style="color:#0000ff;">94dwfa8yd87kw </span>|    -1.61% |     31 |    162 | -422.58% |       .38% |      1.93% | y   |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>SQL Statements with Errors Sorted by their object_id (8)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| object_id | sql_id        | Error Message                                    |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
|        36 | 572674pu6mra0 | Type of SQL statement not supported.             |<br />
|        37 | 8qhjcm5uv4j85 | Type of SQL statement not supported.             |<br />
|        38 | 2jpf0qbj9vxq3 | Type of SQL statement not supported.             |<br />
|        40 | g4y6nw3tts7cc | Type of SQL statement not supported.             |<br />
|        43 | 36s7502m471xz | Error in execution &#8216;my_exec_AFTER_change&#8217;:       |<br />
|           |               | ORA-01760: illegal argument for function         |<br />
|        46 | ccuwpvmn6rp9t | Error in execution &#8216;my_exec_AFTER_change&#8217;:       |<br />
|           |               | ORA-00907: missing right parenthesis             |<br />
|        51 | bsaf69ghqw2ja | Type of SQL statement not supported.             |<br />
|        52 | caj558xbnmytz | Type of SQL statement not supported.             |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>&#8211;find out the sql<br />
<span style="color:#0000ff;">SYS@ORA11G&gt;SELECT sql_text FROM TABLE(DBMS_SQLTUNE.SELECT_SQLSET(&#8216;my_sts&#8217;)) where sql_id=&#8217;2ydjxgd87t9hk&#8217;;<br />
</span><br />
SQL_TEXT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;-<br />
select count(*) from t2 where object_id&lt;1000</p>
<p>SYS@ORA11G&gt;SELECT sql_text FROM TABLE(DBMS_SQLTUNE.SELECT_SQLSET(&#8216;my_sts&#8217;)) where sql_id=&#8217;94dwfa8yd87kw&#8217;;</p>
<p>SQL_TEXT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&#8212;&#8212;&#8212;-<br />
select count(*) from t2</p>
<p>&#8211;tune regressed sql statement,reference SQL Tuning Advisor and SQL plan baselines procedures<br />
&#8211;For sql &#8216;94dwfa8yd87kw&#8217;, the sql plan before change is<br />
<span style="color:#0000ff;">T@ORA11G&gt;select * from table(dbms_xplan.display_cursor());</span></p>
<p>PLAN_TABLE_OUTPUT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;<br />
SQL_ID  94dwfa8yd87kw, child number 0<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
select count(*) from t2</p>
<p>Plan hash value: 3659760998</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| Id  | Operation             | Name   | Rows  | Cost (%CPU)| Time     |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
|   0 | SELECT STATEMENT      |        |       |     9 (100)|          |<br />
|   1 |  SORT AGGREGATE       |        |     1 |            |          |<br />
|   2 |   INDEX FAST FULL SCAN| T2_OID | 11892 |     9   (0)| 00:00:01 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p><span style="color:#0000ff;">&#8211;the sql plan after change, index is deleted, is<br />
T@ORA11G&gt;select * from table(dbms_xplan.display_cursor());</span></p>
<p>PLAN_TABLE_OUTPUT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&#8212;&#8212;&#8212;&#8212;<br />
SQL_ID  2hkvgb0cwhvvn, child number 0<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
select count(*) from t2</p>
<p>Plan hash value: 3321871023</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
|   0 | SELECT STATEMENT   |      |       |    48 (100)|          |<br />
|   1 |  SORT AGGREGATE    |      |     1 |            |          |<br />
|   2 |   TABLE ACCESS FULL| T2   | 11892 |    48   (0)| 00:00:01 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><span style="color:#0000ff;">&#8211;views related to SPA</span><br />
DBA_ADVISOR_TASKS<br />
DBA_ADVISOR_EXECUTIONS<br />
DBA_ADVISOR_FINDINGS<br />
DBA_ADVISOR_SQLPLANS<br />
DBA_ADVISOR_SQLSTATS<br />
V$ADVISOR_PROGRESS</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexzeng.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexzeng.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexzeng.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexzeng.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexzeng.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexzeng.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexzeng.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexzeng.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexzeng.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexzeng.wordpress.com/111/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=111&subd=alexzeng&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://alexzeng.wordpress.com/2008/12/12/step-by-step-test-sql-performance-analyzer-of-real-application-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ec71fb52eb0cb170123476467bb48a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexzeng</media:title>
		</media:content>
	</item>
		<item>
		<title>Step by step test Database Replay of Real Application Test</title>
		<link>http://alexzeng.wordpress.com/2008/12/10/step-by-step-test-database-replay-of-real-application-test/</link>
		<comments>http://alexzeng.wordpress.com/2008/12/10/step-by-step-test-database-replay-of-real-application-test/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 09:22:04 +0000</pubDate>
		<dc:creator>alexzeng</dc:creator>
				<category><![CDATA[Performance Management]]></category>
		<category><![CDATA[11g]]></category>
		<category><![CDATA[scratch]]></category>

		<guid isPermaLink="false">http://alexzeng.wordpress.com/?p=108</guid>
		<description><![CDATA[&#8211;Test version: 11.1.0.6

&#8211;
&#8211;1.Capture workload
&#8211;
Before capturing a database workload, carefully consider the following options:
*Restarting the Database
&#8211;to avoid capture partial transaction
*Defining the Workload Filters
&#8211;inclusion filters or exclusion filters, not both
*Setting Up the Capture Directory
&#8211;capturing a database workload using APIs, Adding and Removing Workload Filters
BEGIN
DBMS_WORKLOAD_CAPTURE.ADD_FILTER (
fname =&#62; &#8216;user_t&#8217;,
fattribute =&#62; &#8216;USER&#8217;,
fvalue =&#62; &#8216;T&#8217;);
END;
/
&#8211;this will filte out all sessions beloings [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=108&subd=alexzeng&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="color:#0000ff;">&#8211;Test version: 11.1.0.6<br />
</span><br />
<span style="color:#0000ff;">&#8211;<br />
&#8211;1.Capture workload<br />
&#8211;</span><br />
<span style="color:#0000ff;">Before capturing a database workload, carefully consider the following options:<br />
*Restarting the Database<br />
&#8211;to avoid capture partial transaction<br />
*Defining the Workload Filters<br />
&#8211;inclusion filters or exclusion filters, not both<br />
*Setting Up the Capture Directory</span></p>
<p>&#8211;capturing a database workload using APIs, Adding and Removing Workload Filters<br />
<span style="color:#0000ff;">BEGIN<br />
DBMS_WORKLOAD_CAPTURE.ADD_FILTER (<br />
fname =&gt; &#8216;user_t&#8217;,<br />
fattribute =&gt; &#8216;USER&#8217;,<br />
fvalue =&gt; &#8216;T&#8217;);<br />
END;<br />
/</span><br />
&#8211;this will filte out all sessions beloings to user T<br />
&#8211;fattribute should be PROGRAM, MODULE, ACTION, SERVICE, INSTANCE_NUMBER, and USER<br />
&#8211;wildcard can be used in fvalue, such as %</p>
<p>&#8211;to delete a filter<br />
BEGIN<br />
DBMS_WORKLOAD_CAPTURE.DELETE_FILTER (fname =&gt; &#8216;user_ichan&#8217;);<br />
END;<br />
/</p>
<p>&#8211;start_capture<br />
SYS@ORA11G&gt;create directory testdir as &#8216;D:\oracle\reorg&#8217;;<br />
<span style="color:#0000ff;">BEGIN<br />
DBMS_WORKLOAD_CAPTURE.START_CAPTURE (name =&gt; &#8216;mytest&#8217;,<br />
dir =&gt; &#8216;TESTDIR&#8217;,<br />
duration =&gt; 600);<br />
END;<br />
/</span><br />
&#8211;it will stop automatically after 600 seconds<br />
&#8211;if duration is not specified, call the following statement to stop it<br />
BEGIN<br />
DBMS_WORKLOAD_CAPTURE.FINISH_CAPTURE ();<br />
END;<br />
/</p>
<p>&#8211;export AWR data for workload capture<br />
Exporting AWR data enables detailed analysis of the workload.<br />
This data is also required if you plan to run the AWR Compare Period report<br />
on a pair of workload captures or replays.<br />
&#8211;get the capture id<br />
SYS@ORA11G&gt;select id from  DBA_WORKLOAD_CAPTURES;</p>
<p>ID<br />
&#8212;&#8212;&#8212;-<br />
1</p>
<p>&#8211;export awr of this id<br />
BEGIN<br />
DBMS_WORKLOAD_CAPTURE.EXPORT_AWR (capture_id =&gt; 1);<br />
END;<br />
/<br />
<span style="color:#0000ff;"><br />
&#8211;<br />
&#8211;2.Preprocessing workload<br />
&#8211;</span><br />
&#8211;This is very resource contention, should not run on production system<br />
&#8211;copy the dirctory files to the replay db, and run the procedure<br />
<span style="color:#0000ff;">BEGIN<br />
DBMS_WORKLOAD_REPLAY.PROCESS_CAPTURE (capture_dir =&gt; &#8216;TESTDIR&#8217;);<br />
END;<br />
/<br />
</span><br />
<span style="color:#0000ff;">&#8211;<br />
&#8211;3.Replaying a Database Workload<br />
&#8211;</span><br />
&#8211;step1. setup test system<br />
Using rman restore/duplicate to test system<br />
do the change you want, such as parameter change, hardware change<br />
resetting system time, set the system time to capture start time</p>
<p>&#8211;step2. replaying<br />
copy the preprocessed files to a db directory<br />
resolving references to external system: db links, external tables, directories,URL, Email<br />
remapping connections: the connection string used to connect the production system are captured<br />
options:<br />
synchronization<br />
connect_time_scale<br />
think_time_scale</p>
<p>&#8211;setting up replay clients<br />
replay program: $ORACLE_HOME/bin/wrc, a multithreaded program<br />
wrc [user/password[@server]] MODE=[value] [keyword=[value]]</p>
<p>&#8211;Calibrating Replay Clients<br />
C:\Documents and Settings\Zengw&gt;<span style="color:#0000ff;">wrc t/t mode=calibrate replaydir=D:\oracle\reorg</span></p>
<p>Workload Replay Client: Release 11.1.0.6.0 &#8211; Production on Wed Dec 10 16:15:37 2008</p>
<p>Copyright (c) 1982, 2007, Oracle.  All rights reserved.</p>
<p>Report for Workload in: D:\oracle\reorg<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Recommendation:<br />
Consider using at least 1 clients divided among 1 CPU(s).</p>
<p>Workload Characteristics:<br />
- max concurrency: 1 sessions<br />
- total number of sessions: 1</p>
<p>Assumptions:<br />
- 1 client process per 50 concurrent sessions<br />
- 4 client process per CPU<br />
- think time scale = 100<br />
- connect time scale = 100<br />
- synchronization = TRUE</p>
<p>&#8211;OEM is the primary tools to do replay<br />
-<span style="color:#0000ff;">-initializing replay data<br />
BEGIN<br />
DBMS_WORKLOAD_REPLAY.INITIALIZE_REPLAY (replay_name =&gt; &#8216;mytest_replay&#8217;,<br />
replay_dir =&gt; &#8216;TESTDIR&#8217;);<br />
END;<br />
/</span></p>
<p>&#8211;setting workload replay options<br />
BEGIN<br />
DBMS_WORKLOAD_REPLAY.PREPARE_REPLAY (synchronization =&gt; TRUE);<br />
END;<br />
/</p>
<p>&#8211;start replay clients<br />
C:\Documents and Settings\Zengw&gt;<span style="color:#0000ff;">wrc t/t mode=replay replaydir=D:\oracle\reorg</span></p>
<p>Workload Replay Client: Release 11.1.0.6.0 &#8211; Production on Wed Dec 10 16:23:07 2008</p>
<p>Copyright (c) 1982, 2007, Oracle.  All rights reserved.</p>
<p><span style="color:#0000ff;">Wait for the replay to start (16:23:07)</span><br />
&#8211;i get the below output after the below procedure is done<br />
<span style="color:#0000ff;">Replay started (16:23:48)<br />
Replay finished (16:25:39)</span></p>
<p>&#8211;starting a workload replay in another window<br />
<span style="color:#0000ff;">BEGIN<br />
DBMS_WORKLOAD_REPLAY.START_REPLAY ();<br />
END;<br />
/<br />
</span></p>
<p>&#8211;Exporting AWR Data for Workload Replay<br />
&#8211;get the replay id<br />
SYS@ORA11G&gt;select id from dba_workload_replays;</p>
<p>ID<br />
&#8212;&#8212;&#8212;-<br />
1</p>
<p>BEGIN<br />
DBMS_WORKLOAD_REPLAY.EXPORT_AWR (replay_id =&gt; 1);<br />
END;<br />
/</p>
<p>&#8211;workload replay views<br />
<span style="color:#0000ff;">DBA_WORKLOAD_CAPTURES<br />
DBA_WORKLOAD_FILTERS<br />
DBA_WORKLOAD_REPLAYS<br />
DBA_WORKLOAD_REPLAY_DIVERGENCE<br />
DBA_WORKLOAD_CONNECTION_MAP</span></p>
<p><span style="color:#0000ff;">&#8211;<br />
&#8211;4.Analyzing replay workload<br />
&#8211;</span></p>
<p><span style="color:#0000ff;">&#8211;generating a workload capture report, OEM/procedure</span><br />
<span style="color:#0000ff;">set serveroutput on<br />
DECLARE<br />
cap_id         NUMBER;<br />
cap_rpt        CLOB;<br />
rpt_len                 NUMBER;<br />
BEGIN<br />
cap_id  := DBMS_WORKLOAD_CAPTURE.GET_CAPTURE_INFO(dir =&gt; &#8216;TESTDIR&#8217;);<br />
cap_rpt := DBMS_WORKLOAD_CAPTURE.REPORT(capture_id =&gt; cap_id,format =&gt; DBMS_WORKLOAD_CAPTURE.TYPE_TEXT);<br />
rpt_len :=DBMS_LOB.GETLENGTH(cap_rpt);<br />
dbms_output.put_line(&#8216;length:&#8217;||rpt_len);<br />
dbms_output.put_line(DBMS_LOB.SUBSTR(cap_rpt,32767,1)); &#8211;if rpt_len &lt; 32767<br />
END;<br />
/</span><br />
length:11623</p>
<p>Database Capture Report For ORA11G</p>
<p>DB Name         DB Id    Release     RAC Capture Name               Status<br />
&#8212;&#8212;&#8212;&#8212;<br />
&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8211; &#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;-<br />
ORA11G        2333620726 11.1.0.6.0  NO  mytest                                            COMPLETED<br />
Start time: 10-Dec-08 15:43:05 (SCN = 237383)<br />
End time: 10-Dec-08 15:48:25<br />
(SCN = 238531)<br />
Duration: 5 minutes 20 seconds<br />
Capture size: 1.99 KB<br />
Directory object: TESTDIR<br />
Directory path: D:\oracle\reorg<br />
Directory shared in RAC: TRUE<br />
Filters used: 1 EXCLUSION filter</p>
<p>Captured Workload Statistics                          DB: ORA11G  Snaps: 13-14<br />
-&gt; &#8216;Value&#8217; represents the corresponding statistic aggregated across the entire captured database workload.<br />
-&gt; &#8216;% Total&#8217; is the percentage of &#8216;Value&#8217; over the corresponding system-wide aggregated total.<br />
Statistic Name                                   Value   %Total<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;<br />
DB time (secs)                                    0.06        0.22<br />
Average Active Sessions                           0.00<br />
User calls captured                                  4        8.00<br />
User calls captured with Errors                      0<br />
Session logins                                       0        0.00<br />
Transactions                                         0    0.00<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Top Events Captured                                   DB:ORA11G  Snaps: 13-14</p>
<p>No data exists for this section of the report.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Top Service/Module Captured                           DB:ORA11G  Snaps: 13-14<br />
No data exists for this section of the report.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Top SQL Captured                                      DB:ORA11G  Snaps: 13-14<br />
No data exists for this section of the report.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Top Sessions Captured                                 DB:ORA11G  Snaps: 13-14<br />
No data exists for this section of the report.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Top Events containing Unreplayable Calls              DB:ORA11G  Snaps: 13-14<br />
No data exists for this section of the report.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Top Service/Module containing Unreplayable Calls      DB:ORA11G  Snaps: 13-14<br />
No data exists for this section of the report.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Top SQL containing Unreplayable Calls                 DB:ORA11G  Snaps: 13-14<br />
No data exists for this section of the report.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Top Sessions containing Unreplayable Calls            DB:ORA11G  Snaps: 13-14<br />
No data exists for this section of the report.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Top Events Filtered Out                               DB:ORA11G  Snaps: 13-14<br />
Avg Active Event                        Event Class        % Event   Sessions<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
CPU + Wait for CPU<br />
CPU                  37.70       0.07<br />
db file scattered read              User I/O              1.64       0.00<br />
db file sequential<br />
read             User I/O              1.64       0.00<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Top Service/Module Filtered Out                       DB: ORA11G  Snaps: 13-14<br />
Service        Module                   % Activity<br />
Action               % Action<br />
&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;-<br />
SYS$USERS<br />
SQL*Plus                      39.34 UNNAMED                 39.34<br />
sqlplus.exe                    1.64 UNNAMED<br />
1.64<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Top SQL Filtered Out        DB: ORA11G  Snaps: 13-14<br />
SQL ID     % Activity Event                          % Event<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;-<br />
a6ta5bs4qwy6p          31.15 CPU + Wait for CPU<br />
31.15<br />
select count(*) from t,t2</p>
<p>2jpf0qbj9vxq3           3.28 CPU + Wait for CPU                3.28<br />
** SQL Text Not Available **</p>
<p>fcwj05qyp0f6w           3.28 db file scattered read            1.64<br />
** SQL Text Not Available **</p>
<p>db file sequential read           1.64</p>
<p>bs8bzd41vz3&#215;0           1.64 CPU + Wait for CPU                1.64<br />
BEGIN<br />
DBMS_WORKLOAD_CAPTURE.START_CAPTURE (name =&gt; &#8216;mytest&#8217;,<br />
dir =&gt; &#8216;TESTDIR&#8217;, duration =&gt; 600); END;</p>
<p>g9u5j7y6cfxxq<br />
1.64 CPU + Wait for CPU                1.64<br />
** SQL Text Not Available **</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Top Sessions Filtered Out                             DB:<br />
ORA11G  Snaps: 13-14<br />
-&gt; &#8216;# Samples Active&#8217; shows the number of ASH samples in which the session was found waiting for that particular event. The percentage shown in this column is calculated with respect to wall clock time and not total database activity.<br />
-&gt; &#8216;XIDs&#8217; shows the number of distinct transaction IDs sampled in ASH when the session was waiting for that particular event<br />
-&gt; For sessions running Parallel Queries, this section will NOT aggregate the PQ slave activity into the session issuing the PQ. Refer to the &#8216;Top Sessions running PQs&#8217; section for such statistics.<br />
Sid, Serial# % Activity<br />
Event                             % Event<br />
&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;-<br />
User<br />
Program                          # Samples Active     XIDs<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&#8212;&#8212;&#8211;<br />
88,    7      39.34 CPU + Wait for CPU                  36.07<br />
T                    sqlplus.exe<br />
22/320 [  7%]        2</p>
<p>db file scattered read               1.64</p>
<p>1/320 [  0%]        1</p>
<p>db file sequential read              1.64</p>
<p>1/320 [  0%]        1</p>
<p>61,   27       1.64 CPU + Wait for CPU                   1.64<br />
SYS                  sqlplus.exe<br />
1/320 [  0%]        0</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Top Events (Jobs and<br />
Background Activity)             DB: ORA11G  Snaps: 13-14<br />
Avg<br />
Active<br />
Event                               Event Class        % Event   Sessions<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
db file sequential read             User I/O             14.75       0.03<br />
CPU + Wait for CPU<br />
CPU                   9.84       0.02<br />
control file parallel write         System I/O            9.84       0.02<br />
null event<br />
Other                 6.56       0.01<br />
control file sequential read        System I/O            4.92       0.01<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Top Service/Module (Jobs and Background Activity)     DB:ORA11G  Snaps: 13-14<br />
Service        Module                   % Activity Action               % Action<br />
&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;-<br />
SYS$BACKGROUND UNNAMED                       37.70 UNNAMED<br />
37</p>
<p>PL/SQL procedure successfully completed.</p>
<p><span style="color:#0000ff;">&#8211;generating a workload replay report , OEM/procedure</p>
<p>set serveroutput on<br />
DECLARE<br />
cap_id         NUMBER;<br />
rep_id         NUMBER;<br />
rep_rpt        CLOB;<br />
rpt_len                 NUMBER;<br />
BEGIN<br />
cap_id := DBMS_WORKLOAD_REPLAY.GET_REPLAY_INFO(dir =&gt; &#8216;TESTDIR&#8217;);<br />
/* Get the latest replay for that capture */<br />
SELECT max(id)<br />
INTO   rep_id<br />
FROM   dba_workload_replays<br />
WHERE  capture_id = cap_id;</p>
<p>rep_rpt := DBMS_WORKLOAD_REPLAY.REPORT(replay_id =&gt; rep_id,<br />
format =&gt; DBMS_WORKLOAD_REPLAY.TYPE_TEXT);<br />
rpt_len :=DBMS_LOB.GETLENGTH(rep_rpt);<br />
dbms_output.put_line(&#8216;length:&#8217;||rpt_len);<br />
dbms_output.put_line(DBMS_LOB.SUBSTR(rep_rpt,32767,1)); &#8211;if rpt_len &lt; 32767<br />
END;<br />
/</span><br />
&#8211;format can be DBMS_WORKLOAD_REPLAY.TYPE_TEXT, DBMS_WORKLOAD_REPLAY.TYPE_HTML, and DBMS_WORKLOAD_REPLAY.TYPE_XML.<br />
length:6603<br />
DB Replay Report for mytest_replay<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| DB Name | DB Id      | Release    | RAC | Replay Name   | Replay Status<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| ORA11G  | 2333620726 | 11.1.0.6.0 | NO  |<br />
mytest_replay | COMPLETED     |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Replay Information<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
|   Information    | Replay             | Capture<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Name             | mytest_replay      | mytest<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Status           | COMPLETED          | COMPLETED<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Database Name    | ORA11G             | ORA11G<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Database Version | 11.1.0.6.0         | 11.1.0.6.0<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Start Time       | 10-DEC-08 16:23:38 | 10-DEC-08 15:43:05<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| End Time         | 10-DEC-08 16:24:02 | 10-DEC-08 15:48:25<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Duration         | 24 seconds         | 5 minutes 20 seconds<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Directory Object | TESTDIR            | TESTDIR<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Directory Path   | D:\oracle\reorg    | D:\oracle\reorg<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Replay Options<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
|       Option Name       | Value<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| Synchronization         | TRUE<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| Connect Time            | 100%<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| Think Time              | 100%<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| Think Time Auto Correct | TRUE<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| Number of WRC Clients   | 1 (1 Completed, 0 Running )<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Replay Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
|        Statistic        | Replay        | Capture<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| DB Time                 | 4.388 seconds | 0.061 seconds<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Average Active Sessions |           .18 |             0<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| User calls              |             4 |             4<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Network Time            | 0.000 seconds | .<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Think Time              | 0.000 seconds | .<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Replay Divergence Summary<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
|                Divergence Type                | Count<br />
| % Total |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Session Failures During Replay                |<br />
0 |    0.00 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Errors No Longer Seen During Replay           |<br />
0 |    0.00 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| New Errors Seen During Replay                 |<br />
0 |    0.00 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Errors Mutated During Replay                  |<br />
0 |    0.00 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| DMLs with Different Number of Rows Modified   |<br />
0 |    0.00 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| SELECTs with Different Number of Rows Fetched |<br />
0 |    0.00<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Workload Profile Top Events<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| No data<br />
exists for this section of the report. |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Top<br />
Service/Module/Action<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| No data exists for this section of the report.<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Top SQL with Top Events<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| No<br />
data exists for this section of the report. |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Top Sessions with Top<br />
Events<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| No data exists for this section of the report.<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Replay Divergence Session Failures By<br />
Application<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| No data exists for this section of the report.<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Error Divergence By<br />
Application<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| No data exists for this section of the report.<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
By SQL<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| No data exists for<br />
this section of the report. |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
By<br />
Session<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| No data exists for this section of the report.<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
DML Data Divergence By<br />
Application<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| No data exists for this section of the report.<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
By SQL<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| No data exists for<br />
this section of the report. |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
SELECT Data Divergence By<br />
Application<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| No data exists for this section of the report.<br />
|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>End of Report.</p>
<p>PL/SQL procedure successfully completed.</p>
<p><span style="color:#0000ff;">&#8211;cause I am doing the capture and replay on same db, there is no much divergence</span></p>
<p><span style="color:#0000ff;">&#8211;appendix: sql statements tested</span><br />
T@ORA11G&gt;create table t as select * from dba_objects;</p>
<p>Table created.</p>
<p>T@ORA11G&gt;select count(*) from dba_objects;</p>
<p>COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
12091</p>
<p>T@ORA11G&gt;create index t_oid on t(object_id);</p>
<p>Index created.</p>
<p>T@ORA11G&gt;create index t_oname on t(object_name);</p>
<p>Index created.</p>
<p>T@ORA11G&gt;update t set object_id=99999999-object_id;</p>
<p>12091 rows updated.</p>
<p>T@ORA11G&gt;commit;</p>
<p>Commit complete.</p>
<p>T@ORA11G&gt;select min(object_id) from t;</p>
<p>MIN(OBJECT_ID)<br />
&#8212;&#8212;&#8212;&#8212;&#8211;<br />
99987491</p>
<p>T@ORA11G&gt;create table t2 as select * from dba_objects;</p>
<p>Table created.</p>
<p>T@ORA11G&gt;select count(*) from t,t2 where t.object_id=t2.object_id;</p>
<p>COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
0</p>
<p>T@ORA11G&gt;select count(*) from t,t2 where t.object_name=t2.object_name;</p>
<p>COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
18629</p>
<p>T@ORA11G&gt;create index t2_oname on t2(object_name);</p>
<p>Index created.</p>
<p>T@ORA11G&gt;select count(*) from t,t2 where t.object_name=t2.object_name;</p>
<p>COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
18629</p>
<p>T@ORA11G&gt;update t set object_id=99999999-object_id;</p>
<p>12091 rows updated.</p>
<p>T@ORA11G&gt;select count(*) from t,t2 where t.object_id=t2.object_id;</p>
<p>COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
12091</p>
<p>T@ORA11G&gt;commit;</p>
<p>Commit complete.</p>
<p>T@ORA11G&gt;select count(*) from t,t2;</p>
<p>COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
146228554</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexzeng.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexzeng.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexzeng.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexzeng.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexzeng.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexzeng.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexzeng.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexzeng.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexzeng.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexzeng.wordpress.com/108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=108&subd=alexzeng&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://alexzeng.wordpress.com/2008/12/10/step-by-step-test-database-replay-of-real-application-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ec71fb52eb0cb170123476467bb48a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexzeng</media:title>
		</media:content>
	</item>
		<item>
		<title>Step by step test Sql Plan Management</title>
		<link>http://alexzeng.wordpress.com/2008/11/28/step-by-step-test-sql-plan-management/</link>
		<comments>http://alexzeng.wordpress.com/2008/11/28/step-by-step-test-sql-plan-management/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 08:48:23 +0000</pubDate>
		<dc:creator>alexzeng</dc:creator>
				<category><![CDATA[Performance Management]]></category>
		<category><![CDATA[11g]]></category>
		<category><![CDATA[scratch]]></category>

		<guid isPermaLink="false">http://alexzeng.wordpress.com/?p=103</guid>
		<description><![CDATA[&#8211;Test Version: 11.1.0.6
&#8211;Plan history is maintained only for repeatable SQL statements.A SQL statement is recognized as repeatable when it is parsed or executed again after it has been logged.
&#8211;How to turn on Automatic Plan Capture
Alter system set OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES = TRUE
&#8211;Manual Plan Loading
&#8211;Loading Plans from SQL Tuning Sets
DECLARE
my_plans pls_integer;
BEGIN
my_plans := DBMS_SPM.LOAD_PLANS_FROM_SQLSET(sqlset_name =&#62; &#8216;tset1&#8242;);
END;
/
&#8211;you can load plans [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=103&subd=alexzeng&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="color:#0000ff;">&#8211;Test Version: 11.1.0.6<br />
&#8211;Plan history is maintained only for repeatable SQL statements.A SQL statement is recognized as repeatable when it is parsed or executed again after it has been logged.</span></p>
<p><span style="color:#0000ff;">&#8211;How to turn on Automatic Plan Capture<br />
Alter system set OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES = TRUE</span></p>
<p><span style="color:#0000ff;">&#8211;Manual Plan Loading</span><br />
&#8211;Loading Plans from SQL Tuning Sets<br />
DECLARE<br />
my_plans pls_integer;<br />
BEGIN<br />
my_plans := DBMS_SPM.LOAD_PLANS_FROM_SQLSET(sqlset_name =&gt; &#8216;tset1&#8242;);<br />
END;<br />
/<br />
&#8211;you can load plans from AWR to Sql tuning Set, then load it to SPM</p>
<p><span style="color:#0000ff;">&#8211;Manual load from cursor cache</span><br />
&#8211;run a test sql<br />
T@ORCL11G&gt;select count(*) from t;</p>
<p>COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
1101840</p>
<p>SYS@orcl11g&gt;select sid,serial# from v$session where username=&#8217;T';</p>
<p>SID    SERIAL#<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
87          7</p>
<p>SYS@orcl11g&gt;select sql_id from v$session where sid=87;</p>
<p>SQL_ID<br />
&#8212;&#8212;&#8212;&#8212;-<br />
cyzznbykb509s</p>
<p><span style="color:#0000ff;">&#8211;manual load the sql to base line from cursor cache<br />
DECLARE<br />
my_plans pls_integer;<br />
BEGIN<br />
my_plans := DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE(sql_id =&gt; &#8216;cyzznbykb509s&#8217;);<br />
END;<br />
/</span></p>
<p><span style="color:#0000ff;">&#8211;get sql_handle<br />
SYS@orcl11g&gt;select sql_handle,sql_text from DBA_SQL_PLAN_BASELINES;</span></p>
<p>SQL_HANDLE                     SQL_TEXT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
SYS_SQL_793213869456f9be       select count(*) from t</p>
<p><span style="color:#0000ff;">&#8211;Evolving Plans<br />
SET SERVEROUTPUT ON<br />
SET LONG 10000<br />
DECLARE<br />
report clob;<br />
BEGIN<br />
report := DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE(<br />
sql_handle =&gt; &#8216;SYS_SQL_793213869456f9be&#8217;);<br />
DBMS_OUTPUT.PUT_LINE(report);<br />
END;<br />
/</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Evolve SQL Plan Baseline Report<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Inputs:<br />
&#8212;&#8212;-<br />
SQL_HANDLE =<br />
SYS_SQL_793213869456f9be<br />
PLAN_NAME  =<br />
TIME_LIMIT = DBMS_SPM.AUTO_LIMIT<br />
VERIFY     = YES<br />
COMMIT     =<br />
YES</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Report<br />
Summary<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
There were no SQL plan baselines that<br />
required processing.</p>
<p>PL/SQL procedure successfully completed.</p>
<p><span style="color:#0000ff;">&#8211;Displaying SQL Plan Baselines<br />
select * from table(<br />
dbms_xplan.display_sql_plan_baseline(<br />
sql_handle=&gt;&#8217;SYS_SQL_793213869456f9be&#8217;,<br />
format=&gt;&#8217;basic&#8217;));</span></p>
<p>PLAN_TABLE_OUTPUT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
SQL handle: SYS_SQL_793213869456f9be<br />
SQL text: select count(*) from t<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Plan name: SYS_SQL_PLAN_9456f9be3fdbb376<br />
Enabled: YES     Fixed: NO      Accepted: YES     Origin: MANUAL-LOAD<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Plan hash value: 2966233522<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id  | Operation          | Name |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
|   0 | SELECT STATEMENT   |      |<br />
|   1 |  SORT AGGREGATE    |      |<br />
|   2 |   TABLE ACCESS FULL| T    |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>20 rows selected.</p>
<p>&#8211;modify table and add index<br />
T@ORCL11G&gt;alter table t modify object_name not null;<br />
Table altered.</p>
<p>T@ORCL11G&gt;create index idx_obj_name on t(object_name);<br />
Index created.</p>
<p>T@ORCL11G&gt;select count(*) from t;<br />
COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
1101840</p>
<p>SYS@orcl11g&gt;select sql_id from v$session where sid=87;<br />
SQL_ID<br />
&#8212;&#8212;&#8212;&#8212;-<br />
cyzznbykb509s</p>
<p>&#8211;load the sql plan from cursor cache again<br />
SYS@orcl11g&gt;DECLARE<br />
my_plans pls_integer;<br />
BEGIN<br />
my_plans := DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE(sql_id =&gt; &#8216;cyzznbykb509s&#8217;);<br />
END;<br />
/<span style="color:#0000ff;"><br />
&#8211;When you manually load plans into a SQL plan baseline, these loaded plans are added as accepted plans.</span></p>
<p>&#8211;Evolving the sql plan again<br />
SYS@orcl11g&gt;DECLARE<br />
report clob;<br />
BEGIN<br />
report := DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE(<br />
sql_handle =&gt; &#8216;SYS_SQL_793213869456f9be&#8217;);<br />
DBMS_OUTPUT.PUT_LINE(report);<br />
END;<br />
/<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Evolve SQL Plan Baseline Report<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Inputs:<br />
&#8212;&#8212;-<br />
SQL_HANDLE =<br />
SYS_SQL_793213869456f9be<br />
PLAN_NAME  =<br />
TIME_LIMIT = DBMS_SPM.AUTO_LIMIT<br />
VERIFY     = YES<br />
COMMIT     = YES</p>
<p>Plan:<br />
SYS_SQL_PLAN_9456f9be3e1ca9ac<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Plan was verified: Time used 53.006 seconds.<br />
Passed<br />
performance criterion: Compound improvement ratio &gt;= 2.96.<br />
Plan was changed to an accepted plan.</p>
<p>Baseline Plan      Test Plan     Improv. Ratio<br />
&#8212;&#8212;&#8212;&#8212;-      &#8212;&#8212;&#8212;     &#8212;&#8212;&#8212;&#8212;-<br />
Execution Status:        COMPLETE       COMPLETE<br />
Rows Processed:                 1              1<br />
Elapsed Time(ms):           30428           5475                            5.56<br />
CPU Time(ms):                 290            130              2.23<br />
Buffer Gets:                16228           5477                            2.96<br />
Disk Reads:                 16217           5463              2.97<br />
Direct Writes:                  0              0</p>
<p>Fetches:                      238                101              2.36<br />
Executions:                     1                            1</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Report Summary<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Number of SQL plan baselines verified: 1.<br />
Number of SQL plan baselines evolved: 1.<br />
PL/SQL procedure successfully completed.</p>
<p>&#8211;The new plan was accepted<br />
&#8211;check SQL Plan Baselines again<br />
SYS@orcl11g&gt;select * from table(<br />
dbms_xplan.display_sql_plan_baseline(<br />
sql_handle=&gt;&#8217;SYS_SQL_793213869456f9be&#8217;,<br />
format=&gt;&#8217;basic&#8217;));<br />
PLAN_TABLE_OUTPUT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
SQL handle: SYS_SQL_793213869456f9be<br />
SQL text: select count(*) from t<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Plan name: SYS_SQL_PLAN_9456f9be3e1ca9ac<br />
Enabled: YES     Fixed: NO      Accepted: YES     <span style="color:#ff0000;">Origin: AUTO-CAPTURE  &#8211;Don&#8217;t understand why it is auto!?</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Plan hash value: 1628650996<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id  | Operation             | Name         |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
|   0 | SELECT STATEMENT      |              |<br />
|   1 |  SORT AGGREGATE       |              |<br />
|   2 |   INDEX FAST FULL SCAN| IDX_OBJ_NAME |<span style="color:#0000ff;"> &#8211;the new plan is added</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Plan name: SYS_SQL_PLAN_9456f9be3fdbb376<br />
Enabled: YES     Fixed: NO      Accepted: YES     Origin: MANUAL-LOAD<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Plan hash value: 2966233522<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id  | Operation          | Name |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
|   0 | SELECT STATEMENT   |      |<br />
|   1 |  SORT AGGREGATE    |      |<br />
|   2 |   TABLE ACCESS FULL| T    |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>35 rows selected.</p>
<p><span style="color:#0000ff;">&#8211;let&#8217;s fix the new plan SYS_SQL_PLAN_9456f9be3e1ca9ac<br />
DECLARE<br />
my_plans pls_integer;<br />
BEGIN<br />
my_plans := DBMS_SPM.ALTER_SQL_PLAN_BASELINE (<br />
sql_handle  =&gt; NULL,<br />
plan_name   =&gt; &#8216;SYS_SQL_PLAN_9456f9be3e1ca9ac&#8217;,<br />
attribute_name =&gt; &#8216;fixed&#8217;,<br />
attribute_value =&gt; &#8216;YES&#8217;);<br />
END;<br />
/</span></p>
<p>&#8211;let&#8217;s check the plan again<br />
SYS@orcl11g&gt;select * from table(<br />
dbms_xplan.display_sql_plan_baseline(<br />
sql_handle=&gt;&#8217;SYS_SQL_793213869456f9be&#8217;,<br />
format=&gt;&#8217;basic&#8217;));<br />
PLAN_TABLE_OUTPUT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
SQL handle: SYS_SQL_793213869456f9be<br />
SQL text: select count(*) from t<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan name: SYS_SQL_PLAN_9456f9be3e1ca9ac<br />
Enabled: YES    <span style="color:#0000ff;"> Fixed: YES </span> Accepted: YES     Origin: AUTO-CAPTURE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 1628650996  &#8211;It is now fixed &#8220;Fixed: YES&#8221;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id  | Operation             | Name         |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
|   0 | SELECT STATEMENT      |              |<br />
|   1 |  SORT AGGREGATE       |              |<br />
|   2 |   INDEX FAST FULL SCAN| IDX_OBJ_NAME |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan name: SYS_SQL_PLAN_9456f9be3fdbb376<br />
Enabled: YES     Fixed: NO      Accepted: YES     Origin: MANUAL-LOAD<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Plan hash value: 2966233522</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id  | Operation          | Name |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
|   0 | SELECT STATEMENT   |      |<br />
|   1 |  SORT AGGREGATE    |      |<br />
|   2 |   TABLE ACCESS FULL| T    |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>35 rows selected.</p>
<p><span style="color:#0000ff;">&#8211;A fixed plan takes precedence over a non-fixed plan.Oracle will use the fixed plan whenever possible<br />
&#8211;A SQL plan baseline is fixed if it contains at least one enabled plan whose FIXED attribute is set to YES.<br />
</span><br />
<span style="color:#0000ff;">&#8211;clean this sql baseline<br />
DECLARE<br />
my_plans pls_integer;<br />
BEGIN<br />
my_plans := DBMS_SPM.DROP_SQL_PLAN_BASELINE (sql_handle =&gt; &#8216;SYS_SQL_793213869456f9be&#8217;);<br />
END;<br />
/</span></p>
<p>T@ORCL11G&gt;select sql_handle,sql_text from DBA_SQL_PLAN_BASELINES;<br />
no rows selected</p>
<p><span style="color:#0000ff;">&#8211;Other related configurations<br />
&#8211;Disk Space Usage in SYSAUX<br />
&#8211;</span><br />
&#8211;To change the percentage limit, use the CONFIGURE procedure of the DBMS_SPM package:<br />
BEGIN<br />
DBMS_SPM.CONFIGURE(<br />
&#8217;space_budget_percent&#8217;,30);  &#8211;default 10% SYSAUX, range 1% to 50%<br />
END;<br />
/</p>
<p><span style="color:#0000ff;">&#8211;Purging Policy</span><br />
BEGIN<br />
DBMS_SPM.CONFIGURE(<br />
&#8216;plan_retention_weeks&#8217;,105);  &#8211;default 53 weeks, range 5 to 523<br />
END;<br />
/</p>
<p>&#8211;get the configuration from view dba_sql_management_config<br />
select parameter_name, parameter_value from dba_sql_management_config;<br />
PARAMETER_NAME                 PARAMETER_VALUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;<br />
SPACE_BUDGET_PERCENT                        30<br />
PLAN_RETENTION_WEEKS                       105</p>
<p><span style="color:#0000ff;">&#8211;<br />
&#8211;Importing and Exporting SQL Plan Baselines<br />
&#8211;</span><br />
1.On the original system, create a staging table using the CREATE_STGTAB_BASELINE procedure:<br />
BEGIN<br />
DBMS_SPM.CREATE_STGTAB_BASELINE(<br />
table_name =&gt; &#8217;stage1&#8242;);<br />
END;<br />
/</p>
<p>2.pack the needed baselines<br />
DECLARE<br />
my_plans number;<br />
BEGIN<br />
my_plans := DBMS_SPM.PACK_STGTAB_BASELINE(<br />
table_name =&gt; &#8217;stage1&#8242;,<br />
enabled =&gt; &#8216;yes&#8217;,<br />
creator =&gt; &#8216;dba1&#8242;);<br />
END;<br />
/</p>
<p>3.Export the staging table stage1 into a flat file using the export command or Oracle Data Pump.<br />
4.Transfer the flat file to the target system.<br />
5.Import the staging table stage1 from the flat file using the import command or Oracle Data Pump.<br />
6.Unpack the SQL plan baselines from the staging table into the SQL management base on the target system using the UNPACK_STGTAB_BASELINE function:<br />
DECLARE<br />
my_plans number;<br />
BEGIN<br />
my_plans := DBMS_SPM.UNPACK_STGTAB_BASELINE(<br />
table_name =&gt; &#8217;stage1&#8242;,<br />
fixed =&gt; &#8216;yes&#8217;);<br />
END;<br />
/</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexzeng.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexzeng.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexzeng.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexzeng.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexzeng.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexzeng.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexzeng.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexzeng.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexzeng.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexzeng.wordpress.com/103/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=103&subd=alexzeng&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://alexzeng.wordpress.com/2008/11/28/step-by-step-test-sql-plan-management/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ec71fb52eb0cb170123476467bb48a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexzeng</media:title>
		</media:content>
	</item>
		<item>
		<title>Step by step test 11g adaptive cursor</title>
		<link>http://alexzeng.wordpress.com/2008/11/27/step-by-step-test-11g-adaptive-cursor/</link>
		<comments>http://alexzeng.wordpress.com/2008/11/27/step-by-step-test-11g-adaptive-cursor/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 08:07:18 +0000</pubDate>
		<dc:creator>alexzeng</dc:creator>
				<category><![CDATA[Performance Management]]></category>
		<category><![CDATA[11g]]></category>
		<category><![CDATA[scratch]]></category>

		<guid isPermaLink="false">http://alexzeng.wordpress.com/?p=97</guid>
		<description><![CDATA[DB version: 11.1.0.6
&#8211;
&#8211;Adaptive Cursors in 11g
&#8211;
&#8211;create a test table
T@ORCL11G&#62;alter system flush shared_pool;
System altered.
T@ORCL11G&#62;create table t2
as
select case when rownum = 1 then 1 else 99 end id, a.*
from dba_objects a
/
Table created.
T@ORCL11G&#62;create index t2_id on t2(id);
Index created.
T@ORCL11G&#62; begin
dbms_stats.gather_table_stats
( user, &#8216;T2&#8242;,
estimate_percent =&#62; 100,
method_opt=&#62; &#8216;for all indexed columns&#8217;,cascade=&#62;TRUE);
end;
/
PL/SQL procedure successfully completed.
&#8211;gather 100% is necessary as the data is skew
&#8211;bind [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=97&subd=alexzeng&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="color:#0000ff;">DB version: 11.1.0.6<br />
&#8211;<br />
&#8211;Adaptive Cursors in 11g<br />
&#8211;</span><br />
<span style="color:#0000ff;">&#8211;create a test table</span><br />
T@ORCL11G&gt;alter system flush shared_pool;<br />
System altered.<br />
T@ORCL11G&gt;create table t2<br />
as<br />
select case when rownum = 1 then 1 else 99 end id, a.*<br />
from dba_objects a<br />
/</p>
<p>Table created.<br />
T@ORCL11G&gt;create index t2_id on t2(id);<br />
Index created.</p>
<p>T@ORCL11G&gt; begin<br />
dbms_stats.gather_table_stats<br />
( user, &#8216;T2&#8242;,<br />
estimate_percent =&gt; 100,<br />
method_opt=&gt; &#8216;for all indexed columns&#8217;,cascade=&gt;TRUE);<br />
end;<br />
/<br />
PL/SQL procedure successfully completed.<span style="color:#0000ff;"><br />
&#8211;gather 100% is necessary as the data is skew</span></p>
<p><span style="color:#0000ff;">&#8211;bind 99, which have many duplicated rows</span><br />
T@ORCL11G&gt;variable id number<br />
T@ORCL11G&gt;exec :id :=99<br />
PL/SQL procedure successfully completed.</p>
<p>T@ORCL11G&gt;select * from t2 where id=:id;<br />
&#8230;..<br />
68868 rows selected.</p>
<p><span style="color:#0000ff;">&#8211;check the LAST EXECUTED SQL plan<br />
T@ORCL11G&gt;select * from table(dbms_xplan.display_cursor(null,null,&#8217;typical +peeked_binds&#8217;));</span><br />
PLAN_TABLE_OUTPUT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
SQL_ID  g852rfbbqn2f9, child number 0<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
select * from t2 where id=:id</p>
<p>Plan hash value: 1513984157</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
|   0 | SELECT STATEMENT  |      |       |       |   293 (100)|          |<br />
|*  1 |  TABLE ACCESS FULL| T2   | 68868 |  6994K|   293   (1)| 00:00:04 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Peeked Binds (identified by position):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>1 &#8211; :ID (NUMBER): 99</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; filter(&#8220;ID&#8221;=:ID)</p>
<p>23 rows selected.</p>
<p>&#8211;it is &#8220;TABLE ACCESS FULL&#8221; now<br />
&#8211;let&#8217;s check the bina related statistics<br />
<span style="color:#0000ff;">T@ORCL11G&gt;select sql_id, is_bind_sensitive, is_bind_aware from v$sql where sql_text=&#8217;select * from t2 where id=:id&#8217;;</span></p>
<p>SQL_ID        I I<br />
&#8212;&#8212;&#8212;&#8212;- &#8211; -<br />
g852rfbbqn2f9 Y N<br />
<span style="color:#0000ff;">&#8211;is_bind_sensitive=Y, means oracle knows this sql is bind sensitive<br />
&#8211;is_bind_aware=N, means oracle is not aware yet of a performance issue with regards to the bind values<br />
</span><br />
<span style="color:#0000ff;">&#8211;let&#8217;s change the bind value and run again<br />
T@ORCL11G&gt;exec :id := 1;</span><br />
PL/SQL procedure successfully completed.</p>
<p>T@ORCL11G&gt;select * from t2 where id=:id;<br />
ID OWNER<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;<br />
OBJECT_NAME<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&#8212;&#8212;&#8211;<br />
SUBOBJECT_NAME                  OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE         CREATED            LAST_DDL_TIME<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;-<br />
TIMESTAMP           STATUS  T G S  NAMESPACE EDITION_NAME<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;- &#8211; - &#8211; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
1 SYS<br />
ICOL$<br />
20              2 TABLE               15-OCT-07          15-OCT-07<br />
2007-10-15:10:09:08 VALID   N N N          1</p>
<p>&#8211;let&#8217;s check the plan<br />
T@ORCL11G&gt;select * from table(dbms_xplan.display_cursor(null,null,&#8217;typical +peeked_binds&#8217;));<br />
PLAN_TABLE_OUTPUT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
SQL_ID  g852rfbbqn2f9, child number 0<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
select * from t2 where id=:id</p>
<p>Plan hash value: 1513984157</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
|   0 | SELECT STATEMENT  |      |       |       |   293 (100)|          |<br />
|*  1 |  TABLE ACCESS FULL| T2   | 68868 |  6994K|   293   (1)| 00:00:04 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Peeked Binds (identified by position):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>1 &#8211; :ID (NUMBER): 99</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; filter(&#8220;ID&#8221;=:ID)</p>
<p>23 rows selected.<br />
<span style="color:#0000ff;"><br />
&#8211;the same plan 1513984157 as previous, but oracle expected to get 68868 rows, but it actually got 1 row<br />
</span><span style="color:#0000ff;"><br />
&#8211;let&#8217;s run the same sql with same bind variable again</span><br />
T@ORCL11G&gt;select * from t2 where id=:id;</p>
<p>ID OWNER<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;<br />
OBJECT_NAME<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8211;<br />
SUBOBJECT_NAME                  OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE         CREATED            LAST_DDL_TIME<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8211;<br />
TIMESTAMP           STATUS  T G S  NAMESPACE EDITION_NAME<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;- &#8211; - &#8211; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
1 SYS<br />
ICOL$<br />
20              2 TABLE               15-OCT-07          15-OCT-07<br />
2007-10-15:10:09:08 VALID   N N N          1</p>
<p>&#8211;let&#8217;s check the plan<br />
T@ORCL11G&gt;select * from table(dbms_xplan.display_cursor(null,null,&#8217;typical +peeked_binds&#8217;));<br />
PLAN_TABLE_OUTPUT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
SQL_ID  g852rfbbqn2f9, child number 1<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
select * from t2 where id=:id</p>
<p>Plan hash value: 3119810522</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
|   0 | SELECT STATEMENT            |       |       |       |     2 (100)|          |<br />
<span style="color:#0000ff;">|   1 |  TABLE ACCESS BY INDEX ROWID| T2    |     1 |   104 |     2   (0)| 00:00:01 |<br />
|*  2 |   INDEX RANGE SCAN          | T2_ID |     1 |       |     1   (0)| 00:00:01 |</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Peeked Binds (identified by position):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>1 &#8211; :ID (NUMBER): 1</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>2 &#8211; access(&#8220;ID&#8221;=:ID)</p>
<p>24 rows selected.<br />
<span style="color:#0000ff;"><br />
&#8211;You see the execution plan is changed, cool!</span></p>
<p>&#8211;let&#8217;s check  bind aware or not<br />
T@ORCL11G&gt;select sql_id, child_number, is_bind_sensitive, is_bind_aware from v$sql where sql_text=&#8217;select * from t2 where id=:id&#8217;;<br />
SQL_ID        CHILD_NUMBER I I<br />
&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212; &#8211; -<br />
g852rfbbqn2f9            0 Y N<br />
<span style="color:#0000ff;">g852rfbbqn2f9            1 Y Y  &#8211;you can set is_bind_aware=Y in this new line. That means oracle know there is a problem</span></p>
<p><span style="color:#0000ff;">&#8211;let&#8217;s test another id which is not exist<br />
T@ORCL11G&gt;exec :id := 50;</span><br />
PL/SQL procedure successfully completed.</p>
<p>T@ORCL11G&gt;select * from t2 where id=:id;<br />
no rows selected</p>
<p>T@ORCL11G&gt;select * from table(dbms_xplan.display_cursor(null,null,&#8217;typical +peeked_binds&#8217;));<br />
PLAN_TABLE_OUTPUT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
<span style="color:#0000ff;">SQL_ID  g852rfbbqn2f9, child number 2</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
select * from t2 where id=:id</p>
<p>Plan hash value: 3119810522</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
|   0 | SELECT STATEMENT            |       |       |       |     2 (100)|          |<br />
|   1 |  TABLE ACCESS BY INDEX ROWID| T2    |     1 |   104 |     2   (0)| 00:00:01 |<br />
|*  2 |   INDEX RANGE SCAN          | T2_ID |     1 |       |     1   (0)| 00:00:01 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Peeked Binds (identified by position):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>1 &#8211; :ID (NUMBER): 50</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>2 &#8211; access(&#8220;ID&#8221;=:ID)</p>
<p>24 rows selected.<br />
<span style="color:#0000ff;"><br />
<span style="color:#0000ff;">&#8211;it is still using index, but it is a new plan with child number 2</span></span><span style="color:#0000ff;"><br />
&#8211;try another non exist id 2 times</span><br />
T@ORCL11G&gt;exec :id := 88<br />
PL/SQL procedure successfully completed.</p>
<p>T@ORCL11G&gt;select * from t2 where id=:id;<br />
no rows selected</p>
<p>T@ORCL11G&gt;select * from table(dbms_xplan.display_cursor(null,null,&#8217;typical +peeked_binds&#8217;));<br />
PLAN_TABLE_OUTPUT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
SQL_ID  g852rfbbqn2f9, child number 2<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
select * from t2 where id=:id</p>
<p>Plan hash value: 3119810522</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
|   0 | SELECT STATEMENT            |       |       |       |     2 (100)|          |<br />
|   1 |  TABLE ACCESS BY INDEX ROWID| T2    |     1 |   104 |     2   (0)| 00:00:01 |<br />
|*  2 |   INDEX RANGE SCAN          | T2_ID |     1 |       |     1   (0)| 00:00:01 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Peeked Binds (identified by position):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>1 &#8211; :ID (NUMBER): 50</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>2 &#8211; access(&#8220;ID&#8221;=:ID)</p>
<p>24 rows selected.</p>
<p>T@ORCL11G&gt;select * from t2 where id=:id;<br />
no rows selected</p>
<p>T@ORCL11G&gt;select * from table(dbms_xplan.display_cursor(null,null,&#8217;typical +peeked_binds&#8217;));<br />
PLAN_TABLE_OUTPUT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
SQL_ID  g852rfbbqn2f9, child number 2<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
select * from t2 where id=:id</p>
<p>Plan hash value: 3119810522</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
|   0 | SELECT STATEMENT            |       |       |       |     2 (100)|          |<br />
|   1 |  TABLE ACCESS BY INDEX ROWID| T2    |     1 |   104 |     2   (0)| 00:00:01 |<br />
|*  2 |   INDEX RANGE SCAN          | T2_ID |     1 |       |     1   (0)| 00:00:01 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Peeked Binds (identified by position):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>1 &#8211; :ID (NUMBER): 50</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>2 &#8211; access(&#8220;ID&#8221;=:ID)</p>
<p>24 rows selected.<br />
<span style="color:#0000ff;"><br />
&#8211;you can see, the 2 are using the same plan with child number 2</span></p>
<p><span style="color:#0000ff;">&#8211;let&#8217;s use sql_id to show all plans of this sql<br />
T@ORCL11G&gt;select * from table(dbms_xplan.display_cursor(&#8216;g852rfbbqn2f9&#8242;,null,&#8217;typical +peeked_binds));</span><br />
PLAN_TABLE_OUTPUT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
<span style="color:#0000ff;">SQL_ID  g852rfbbqn2f9, child number 0 </span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
select * from t2 where id=:id</p>
<p>Plan hash value: 1513984157</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
|   0 | SELECT STATEMENT  |      |       |       |   293 (100)|          |<br />
|*  1 |  TABLE ACCESS FULL| T2   | 68868 |  6994K|   293   (1)| 00:00:04 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Peeked Binds (identified by position):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>1 &#8211; :ID (NUMBER): 99</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; filter(&#8220;ID&#8221;=:ID)</p>
<p><span style="color:#0000ff;">SQL_ID  g852rfbbqn2f9, child number 1</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
select * from t2 where id=:id</p>
<p>Plan hash value: 3119810522</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
|   0 | SELECT STATEMENT            |       |       |       |     2 (100)|          |<br />
|   1 |  TABLE ACCESS BY INDEX ROWID| T2    |     1 |   104 |     2   (0)| 00:00:01 |<br />
|*  2 |   INDEX RANGE SCAN          | T2_ID |     1 |       |     1   (0)| 00:00:01 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Peeked Binds (identified by position):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>1 &#8211; :ID (NUMBER): 1</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>2 &#8211; access(&#8220;ID&#8221;=:ID)</p>
<p><span style="color:#0000ff;">SQL_ID  g852rfbbqn2f9, child number 2</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
select * from t2 where id=:id</p>
<p>Plan hash value: 3119810522</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
|   0 | SELECT STATEMENT            |       |       |       |     2 (100)|          |<br />
|   1 |  TABLE ACCESS BY INDEX ROWID| T2    |     1 |   104 |     2   (0)| 00:00:01 |<br />
|*  2 |   INDEX RANGE SCAN          | T2_ID |     1 |       |     1   (0)| 00:00:01 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Peeked Binds (identified by position):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>1 &#8211; :ID (NUMBER): 50</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>2 &#8211; access(&#8220;ID&#8221;=:ID)</p>
<p>71 rows selected.<br />
<span style="color:#0000ff;"><br />
&#8211;Oracle is not BLIND now even bind variable is used if there is accurate statistics.</span></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexzeng.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexzeng.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexzeng.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexzeng.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexzeng.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexzeng.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexzeng.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexzeng.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexzeng.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexzeng.wordpress.com/97/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=97&subd=alexzeng&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://alexzeng.wordpress.com/2008/11/27/step-by-step-test-11g-adaptive-cursor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ec71fb52eb0cb170123476467bb48a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexzeng</media:title>
		</media:content>
	</item>
		<item>
		<title>Step by step test flashback data archives, a.k.a. Total Recall</title>
		<link>http://alexzeng.wordpress.com/2008/11/24/step-by-step-test-flashback-data-archives-aka-total-recall/</link>
		<comments>http://alexzeng.wordpress.com/2008/11/24/step-by-step-test-flashback-data-archives-aka-total-recall/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 08:59:30 +0000</pubDate>
		<dc:creator>alexzeng</dc:creator>
				<category><![CDATA[Backup and Recovery]]></category>
		<category><![CDATA[Data Management]]></category>
		<category><![CDATA[11g]]></category>
		<category><![CDATA[scratch]]></category>

		<guid isPermaLink="false">http://alexzeng.wordpress.com/?p=95</guid>
		<description><![CDATA[&#8211;Flashback Data Archives, a.k.a. Total Recall
&#8211;  A Flashback Data Archive (Oracle Total Recall) provides the ability to track and store all transactional changes to a table over its lifetime.
&#8211;  Test version: 11.1.0.6
&#8211;create a system-wide default flashback archive on an existing tablespace.
conn / as sysdba
SYS@orcl11g&#62;create flashback archive default fb tablespace example retention 1 year;
Flashback archive created.
&#8211;create [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=95&subd=alexzeng&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="color:#0000ff;">&#8211;Flashback Data Archives, a.k.a. Total Recall<br />
&#8211;  A Flashback Data Archive (Oracle Total Recall) provides the ability to track and store all transactional changes to a table over its lifetime.<br />
&#8211;  Test version: 11.1.0.6</span></p>
<p><span style="color:#0000ff;">&#8211;create a system-wide default flashback archive on an existing tablespace.</span><br />
conn / as sysdba<br />
SYS@orcl11g&gt;create flashback archive default fb tablespace example retention 1 year;<br />
Flashback archive created.</p>
<p><span style="color:#0000ff;">&#8211;create test table t</span><br />
conn t/t@orcl11g<br />
create table t as select * from dba_objects;</p>
<p>T@orcl11g&gt;alter table t flashback archive;<br />
Table altered.</p>
<p>T@orcl11g&gt;select systimestamp from dual;<br />
SYSTIMESTAMP<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
<span style="color:#0000ff;">24-NOV-08 04.05.49.182000 PM +08:00</span></p>
<p>T@orcl11g&gt;select timestamp_to_scn(systimestamp) from dual;<br />
TIMESTAMP_TO_SCN(SYSTIMESTAMP)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
<span style="color:#0000ff;"> 1052630  &#8211;created point</span></p>
<p><span style="color:#0000ff;">&#8211;insert 1 time</span><br />
T@orcl11g&gt;insert into t select * from t;<br />
68865 rows created.<br />
T@orcl11g&gt;commit;<br />
Commit complete.<br />
T@orcl11g&gt;select current_scn from v$database;<br />
CURRENT_SCN<br />
&#8212;&#8212;&#8212;&#8211;<br />
<span style="color:#0000ff;"> 1052723  &#8211;test point A</span></p>
<p><span style="color:#0000ff;">&#8211;insert 2 times</span><br />
T@orcl11g&gt;insert into t select * from t;<br />
137730 rows created.<br />
T@orcl11g&gt;insert into t select * from t;<br />
275460 rows created.<br />
T@orcl11g&gt;commit;<br />
Commit complete.<br />
T@orcl11g&gt;select current_scn from v$database;<br />
CURRENT_SCN<br />
&#8212;&#8212;&#8212;&#8211;<br />
<span style="color:#0000ff;">1054928  &#8211;test point B</span><br />
<span style="color:#0000ff;"><br />
&#8211;insert another time </span><br />
T@orcl11g&gt;insert into t select * from t;<br />
550920 rows created.<br />
T@orcl11g&gt;commit;<br />
Commit complete.<br />
T@orcl11g&gt;select current_scn from v$database;<br />
CURRENT_SCN<br />
&#8212;&#8212;&#8212;&#8211;<br />
<span style="color:#0000ff;"> 1056385  &#8211;test point C</span></p>
<p><span style="color:#0000ff;">&#8211;check count(*) of T at created point, point A, B and C</span><br />
T@orcl11g&gt;select count(*) from t as of scn 1052630;<br />
COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
<span style="color:#0000ff;"> 68865  &#8211;start count</span></p>
<p>&#8211;you can also use timestamp to check<br />
T@orcl11g&gt;select count(*) from t as of timestamp to_timestamp_tz(&#8216;24-NOV-08 04.05.49.182000 PM +08:00&#8242;,&#8217;DD-Mon-RR HH:MI:SS.FF AM TZH:TZM&#8217;);<br />
COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
<span style="color:#0000ff;"> 68865  &#8211;start count</span></p>
<p>T@orcl11g&gt;select count(*) from t as of scn 1052723;<br />
COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
<span style="color:#0000ff;"> 137730    &#8211;point A, doubled</span></p>
<p>T@orcl11g&gt;select count(*) from t as of scn 1054928;<br />
COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
<span style="color:#0000ff;"> 550920  &#8211;point B, doubled 2 times comparing to A</span></p>
<p>T@orcl11g&gt;select count(*) from t as of scn 1056385;</p>
<p>COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
<span style="color:#0000ff;"> 1101840  &#8211;point C, doubled comparing to B</span></p>
<p><span style="color:#0000ff;">&#8211;it is exactly expected result! You may test it againt a long time period.</span></p>
<p>&#8211;Let&#8217;s check the under line view<br />
<span style="color:#0000ff;">&#8211;dba_flashback_archive includes all flashback archive defined in the db</span><br />
T@orcl11g&gt;select * from <span style="color:#0000ff;">dba_flashback_archive;</span><br />
FLASHBACK_ FLASHBACK_ARCHIVE# RETENTION_IN_DAYS CREATE_TIME<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
LAST_PURGE_TIME                                                             STATUS<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;-<br />
FB                          1               365 24-NOV-08 04.03.14.000000000 PM<br />
24-NOV-08 04.03.14.000000000 PM                                             DEFAULT</p>
<p><span style="color:#0000ff;">&#8211;dba_flashback_archive_ts includes tablespaces information related to falshback archive</span><br />
&#8211;you can have more than 1 tablespace in a flashback archive<br />
T@orcl11g&gt;select * from <span style="color:#0000ff;">dba_flashback_archive_ts</span>;</p>
<p>FLASHBACK_ FLASHBACK_ARCHIVE# TABLESPACE_NAME      QUOTA_IN_M<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;-<br />
FB                          1 EXAMPLE</p>
<p><span style="color:#0000ff;">&#8211;dba_flashback_archive_tables inculdes tables information</span><br />
T@orcl11g&gt;select * from <span style="color:#0000ff;">dba_flashback_archive_tables</span>;</p>
<p>TABLE_NAME OWNER_NAME FLASHBACK_ARCHIVE_NAME    ARCHIVE_TABLE_NAME<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
T          T          FB                        SYS_FBA_HIST_70992</p>
<p>&#8211;let&#8217;s clean up<br />
T@orcl11g&gt;<span style="color:#0000ff;">alter table t no flashback archive;</span><br />
Table altered.<br />
T@orcl11g&gt;select * from dba_flashback_archive_tables;<br />
no rows selected    &#8211;Table is removed</p>
<p>conn / as sysdba<br />
SYS@orcl11g&gt;<span style="color:#0000ff;">drop flashback archive fb;</span><br />
Flashback archive dropped.<br />
SYS@orcl11g&gt;select * from dba_flashback_archive;<br />
no rows selected  &#8211;fb is dropped<br />
SYS@orcl11g&gt;select * from dba_flashback_archive_ts;<br />
no rows selected  &#8211;related tablspace information is disappear, but the tablespace still exists</p>
<p><span style="color:#0000ff;">&#8211;Limitations:<br />
&#8211;These DDL Statements Not Allowed on Tables Enabled for Flashback Data Archive<br />
&#8211;<br />
**ALTER TABLE statement that does any of the following:<br />
Drops, renames, or modifies a column<br />
Performs partition or subpartition operations<br />
Converts a LONG column to a LOB column<br />
Includes an UPGRADE TABLE clause, with or without an INCLUDING DATA clause<br />
**DROP TABLE statement<br />
**RENAME TABLE statement<br />
**TRUNCATE TABLE statement</span></p>
<p>&#8211;<br />
<span style="color:#0000ff;">&#8211;Sql statement reference</span><br />
&#8211;<br />
-Create a default Flashback Data Archive named fla1 that uses up to 10 G of tablespace tbs1, whose data will be retained for one year:<br />
CREATE FLASHBACK ARCHIVE DEFAULT fla1 TABLESPACE tbs1 QUOTA 10G RETENTION 1 YEAR;</p>
<p>&#8211;Create a Flashback Data Archive named fla2 that uses tablespace tbs2, whose data will be retained for two years:<br />
CREATE FLASHBACK ARCHIVE fla2 TABLESPACE tbs2 RETENTION 2 YEAR;</p>
<p>&#8211;Make Flashback Data Archive fla1 the default Flashback Data Archive:<br />
ALTER FLASHBACK ARCHIVE fla1 SET DEFAULT;</p>
<p>&#8211;To Flashback Data Archive fla1, add up to 5 G of tablespace tbs3:<br />
ALTER FLASHBACK ARCHIVE fla1 ADD TABLESPACE tbs3 QUOTA 5G;</p>
<p>&#8211;To Flashback Data Archive fla1, add as much of tablespace tbs4 as needed:<br />
ALTER FLASHBACK ARCHIVE fla1 ADD TABLESPACE tbs4;</p>
<p>&#8211;Change the maximum space that Flashback Data Archive fla1 can use in tablespace tbs3 to 20 G:<br />
ALTER FLASHBACK ARCHIVE fla1 MODIFY TABLESPACE tbs3 QUOTA 20G;</p>
<p>&#8211;Allow Flashback Data Archive fla1 to use as much of tablespace tbs1 as needed:<br />
ALTER FLASHBACK ARCHIVE fla1 MODIFY TABLESPACE tbs1;</p>
<p>&#8211;Change the retention time for Flashback Data Archive fla1 to two years:<br />
ALTER FLASHBACK ARCHIVE fla1 MODIFY RETENTION 2 YEAR;</p>
<p>&#8211;Remove tablespace tbs2 from Flashback Data Archive fla1:<br />
ALTER FLASHBACK ARCHIVE fla1 REMOVE TABLESPACE tbs2;</p>
<p>&#8211;Purge all historical data from Flashback Data Archive fla1:<br />
ALTER FLASHBACK ARCHIVE fla1 PURGE ALL;</p>
<p>&#8211;Purge all historical data older than one day from Flashback Data Archive fla1:<br />
ALTER FLASHBACK ARCHIVE fla1<br />
PURGE BEFORE TIMESTAMP (SYSTIMESTAMP &#8211; INTERVAL &#8216;1&#8242; DAY);</p>
<p>&#8211;Purge all historical data older than SCN 728969 from Flashback Data Archive fla1:<br />
ALTER FLASHBACK ARCHIVE fla1 PURGE BEFORE SCN 728969;</p>
<p>&#8211;Remove Flashback Data Archive fla1 and all its historical data, but not its tablespaces:<br />
DROP FLASHBACK ARCHIVE fla1;</p>
<p>&#8211;Create table employee and store the historical data in the default Flashback Data Archive:<br />
CREATE TABLE employee (EMPNO NUMBER(4) NOT NULL, ENAME VARCHAR2(10)) FLASHBACK ARCHIVE;</p>
<p>&#8211;Create table employee and store the historical data in the Flashback Data Archive fla1:<br />
CREATE TABLE employee (EMPNO NUMBER(4) NOT NULL, ENAME VARCHAR2(10)) FLASHBACK ARCHIVE fla1;</p>
<p>&#8211;Enable flashback archiving for the table employee and store the historical data in the default Flashback Data Archive:<br />
ALTER TABLE employee FLASHBACK ARCHIVE;</p>
<p>&#8211;Enable flashback archiving for the table employee and store the historical data in the Flashback Data Archive fla1:<br />
ALTER TABLE employee FLASHBACK ARCHIVE fla1;</p>
<p>&#8211;Disable flashback archiving for the table employee:<br />
ALTER TABLE employee NO FLASHBACK ARCHIVE;</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexzeng.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexzeng.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexzeng.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexzeng.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexzeng.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexzeng.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexzeng.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexzeng.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexzeng.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexzeng.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=95&subd=alexzeng&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://alexzeng.wordpress.com/2008/11/24/step-by-step-test-flashback-data-archives-aka-total-recall/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ec71fb52eb0cb170123476467bb48a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexzeng</media:title>
		</media:content>
	</item>
		<item>
		<title>Step by step test 11g new partition methods</title>
		<link>http://alexzeng.wordpress.com/2008/11/12/step-by-step-tes-11g-new-partition-methods/</link>
		<comments>http://alexzeng.wordpress.com/2008/11/12/step-by-step-tes-11g-new-partition-methods/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 05:37:28 +0000</pubDate>
		<dc:creator>alexzeng</dc:creator>
				<category><![CDATA[Data Management]]></category>
		<category><![CDATA[11g]]></category>
		<category><![CDATA[scratch]]></category>

		<guid isPermaLink="false">http://alexzeng.wordpress.com/?p=92</guid>
		<description><![CDATA[DB version: 11.1.0.6
&#8211;new partition methods, ** are tested
**interval partition
**referencial partition
**virtual column partition
**system partition
*other new composite partitions
*Range-Range
*List-Range
*List-Hash
*List-List
*Interval-Range
*Interval-Hash
*Interval-List
*partition advisor, part of the SQL Access Advisor
*partition mode data pump, tables=[schema].[table_name].[partiton_name], PARTITION_OPTIONS = {NONE &#124; DEPARTITION &#124; MERGE}
&#8211;
&#8211;**interval partition, a kind of range partition
&#8211;
&#8211;use a sale table as example
create table sales
(prod_id        NUMBER,
cust_id        NUMBER,
time_id        DATE
)
PARTITION BY RANGE (time_id)
INTERVAL(NUMTOYMINTERVAL(1, &#8216;MONTH&#8217;)) STORE [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=92&subd=alexzeng&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="color:#0000ff;">DB version: 11.1.0.6</span></p>
<p><span style="color:#0000ff;">&#8211;new partition methods, ** are tested<br />
**interval partition<br />
**referencial partition<br />
**virtual column partition<br />
**system partition</span><br />
*other new composite partitions<br />
*Range-Range<br />
*List-Range<br />
*List-Hash<br />
*List-List<br />
*Interval-Range<br />
*Interval-Hash<br />
*Interval-List<br />
*partition advisor, part of the SQL Access Advisor<br />
*partition mode data pump, tables=[schema].[table_name].[partiton_name], PARTITION_OPTIONS = {NONE | DEPARTITION | MERGE}</p>
<p><span style="color:#0000ff;">&#8211;<br />
&#8211;**interval partition, a kind of range partition<br />
&#8211;</span></p>
<p>&#8211;use a sale table as example<br />
create table sales<br />
(prod_id        NUMBER,<br />
cust_id        NUMBER,<br />
time_id        DATE<br />
)<br />
PARTITION BY RANGE (time_id)<br />
INTERVAL(NUMTOYMINTERVAL(1, &#8216;MONTH&#8217;)) STORE IN (USERS,DATA)<br />
( PARTITION p1 VALUES LESS THAN (TO_DATE(&#8216;2007-1-1&#8242;, &#8216;YYYY-MM-DD&#8217;)),<br />
PARTITION p2 VALUES LESS THAN (TO_DATE(&#8216;2008-11-15&#8242;, &#8216;YYYY-MM-DD&#8217;))<br />
);<br />
&#8211;p1 and p2 are different wide partition<br />
&#8211;2008-11-15 is the transition point<br />
&#8211;abover it each partition will be created with the same width 1 month</p>
<p>&#8211;let&#8217;s add data<br />
INSERT INTO SALES VALUES (1,1,TO_DATE(&#8216;2006-09-02&#8242;,&#8217;YYYY-MM-DD&#8217;));<br />
INSERT INTO SALES VALUES (2,2,TO_DATE(&#8216;2008-10-14&#8242;,&#8217;YYYY-MM-DD&#8217;));<br />
INSERT INTO SALES VALUES (2,2,TO_DATE(&#8216;2008-11-08&#8242;,&#8217;YYYY-MM-DD&#8217;));<br />
INSERT INTO SALES VALUES (3,3,TO_DATE(&#8216;2008-12-16&#8242;,&#8217;YYYY-MM-DD&#8217;));<br />
INSERT INTO SALES VALUES (3,3,TO_DATE(&#8216;2008-12-26&#8242;,&#8217;YYYY-MM-DD&#8217;));<br />
commit;</p>
<p>&#8211;check partitions available<br />
T@ONASM&gt;SELECT PARTITION_NAME,TABLESPACE_NAME FROM DBA_SEGMENTS WHERE SEGMENT_NAME=&#8217;SALES&#8217;</p>
<p>PARTITION_NAME                 TABLESPACE_NAME<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
P1                             USERS<br />
P2                             USERS<br />
SYS_P41                        DATA</p>
<p>T@ONASM&gt;select * from SALES PARTITION (p1);</p>
<p>PROD_ID    CUST_ID TIME_ID<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
1          1 02-SEP-06  &#8211;each data before 2007-1-1 in this partition</p>
<p>T@ONASM&gt;select * from SALES PARTITION (p2);</p>
<p>PROD_ID    CUST_ID TIME_ID<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
2          2 14-OCT-08<br />
2          2 08-NOV-08  &#8211;each data before 2008-11-15 in this partition, it is predefined</p>
<p>T@ONASM&gt;select * from SALES PARTITION (SYS_P41);</p>
<p>PROD_ID    CUST_ID TIME_ID<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
3          3 16-DEC-08<br />
3          3 26-DEC-08  &#8211;they are in the same partition</p>
<p>&#8211;we can also use another approach &#8220;partition for&#8221; to access interval partion<br />
T@ONASM&gt;select * from sales partition for(TO_DATE(&#8216;2008-12-20&#8242;,&#8217;YYYY-MM-DD&#8217;));</p>
<p>PROD_ID    CUST_ID TIME_ID<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
3          3 16-DEC-08<br />
3          3 26-DEC-08</p>
<p>&#8211;check the partition value range<br />
T@ONASM&gt;select PARTITION_NAME,HIGH_VALUE from dba_tab_partitions where TABLE_NAME=&#8217;SALES&#8217;;<br />
PARTITION_NAME                 HIGH_VALUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
P1                             TO_DATE(&#8216; 2007-01-01 00:00:00&#8242;, &#8216;SYYYY-MM-DD HH24:MI:SS&#8217;, &#8216;NLS_CALENDAR=GREGORIA<br />
P2                             TO_DATE(&#8216; 2008-11-15 00:00:00&#8242;, &#8216;SYYYY-MM-DD HH24:MI:SS&#8217;, &#8216;NLS_CALENDAR=GREGORIA<br />
SYS_P41                        TO_DATE(&#8216; 2009-01-15 00:00:00&#8242;, &#8216;SYYYY-MM-DD HH24:MI:SS&#8217;, &#8216;NLS_CALENDAR=GREGORIA<br />
&#8211;The intermediate partition is not created</p>
<p>&#8211;let&#8217;s add a partition in the hole betweeen P2 and SYS_P41<br />
T@ONASM&gt;INSERT INTO SALES VALUES (3,3,TO_DATE(&#8216;2008-12-14&#8242;,&#8217;YYYY-MM-DD&#8217;));</p>
<p>&#8211;check value range again<br />
T@ONASM&gt;select PARTITION_NAME,HIGH_VALUE from dba_tab_partitions where TABLE_NAME=&#8217;SALES&#8217;;<br />
PARTITION_NAME                 HIGH_VALUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
P1                             TO_DATE(&#8216; 2007-01-01 00:00:00&#8242;, &#8216;SYYYY-MM-DD HH24:MI:SS&#8217;, &#8216;NLS_CALENDAR=GREGORIA<br />
P2                             TO_DATE(&#8216; 2008-11-15 00:00:00&#8242;, &#8216;SYYYY-MM-DD HH24:MI:SS&#8217;, &#8216;NLS_CALENDAR=GREGORIA<br />
SYS_P41                        TO_DATE(&#8216; 2009-01-15 00:00:00&#8242;, &#8216;SYYYY-MM-DD HH24:MI:SS&#8217;, &#8216;NLS_CALENDAR=GREGORIA<br />
SYS_P61                        TO_DATE(&#8216; 2008-12-15 00:00:00&#8242;, &#8216;SYYYY-MM-DD HH24:MI:SS&#8217;, &#8216;NLS_CALENDAR=GREGORIA</p>
<p>T@ONASM&gt;SELECT PARTITION_NAME,TABLESPACE_NAME FROM DBA_SEGMENTS WHERE SEGMENT_NAME=&#8217;SALES&#8217;;<br />
PARTITION_NAME                 TABLESPACE_NAME<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
P1                             USERS<br />
P2                             USERS  &#8211;the predefined partition are always using the first tablespace<br />
SYS_P41                        DATA   &#8211;you can see tablespace usage start with round-robin fashion<br />
SYS_P61                        USERS</p>
<p>&#8211;The system-generated partition name can be changed<br />
ALTER TABLE SALES RENAME PARTITION SYS_P41 to p_200901;</p>
<p>&#8211;an existing partitioned table can be altered to an interval-partitioned table<br />
ALTER TABLE customers SET INTERVAL (NUMTOYMINTERVAL (1, &#8216;MONTH&#8217;));</p>
<p><span style="color:#0000ff;">&#8211;interval partition limitations:<br />
&#8211;  can only use 1 partition key column, NUMBER or DATA type only<br />
&#8211;  at least one partition must be specified<br />
&#8211;  not support index-organized tables<br />
&#8211;  MAXVALUES is not allowed<br />
&#8211;  partition key cannot have null values<br />
&#8211;  cannot manually add partitions<br />
&#8211;  cannot used with reference partition</span></p>
<p><span style="color:#0000ff;">&#8211;<br />
&#8211;**reference partition<br />
&#8211;using orders and order_items as example</span><br />
CREATE TABLE orders<br />
( order_id           NUMBER(12),<br />
order_date         DATE,<br />
customer_id        NUMBER(6),<br />
CONSTRAINT orders_pk PRIMARY KEY(order_id)<br />
)<br />
PARTITION BY RANGE(order_date)<br />
( PARTITION Q1_2008 VALUES LESS THAN (TO_DATE(&#8216;2008-04-01&#8242;,&#8217;YYYY-MM-DD&#8217;)),<br />
PARTITION Q2_2008 VALUES LESS THAN (TO_DATE(&#8216;2008-07-01&#8242;,&#8217;YYYY-MM-DD&#8217;)),<br />
PARTITION Q3_2008 VALUES LESS THAN (TO_DATE(&#8216;2008-10-01&#8242;,&#8217;YYYY-MM-DD&#8217;)),<br />
PARTITION Q4_2008 VALUES LESS THAN (TO_DATE(&#8216;2009-01-01&#8242;,&#8217;YYYY-MM-DD&#8217;))<br />
);</p>
<p>CREATE TABLE order_items<br />
( order_id           NUMBER(12) NOT NULL,<br />
line_item_id       NUMBER(3)  NOT NULL,<br />
product_id         NUMBER(6)  NOT NULL,<br />
unit_price         NUMBER(8,2),<br />
quantity           NUMBER(8),<br />
CONSTRAINT order_items_fk<br />
FOREIGN KEY(order_id) REFERENCES orders(order_id)<br />
)<br />
PARTITION BY REFERENCE(order_items_fk);</p>
<p>&#8211;check the partitions<br />
T@ONASM&gt;SELECT SEGMENT_NAME,PARTITION_NAME FROM DBA_SEGMENTS WHERE SEGMENT_NAME IN (&#8216;ORDERS&#8217;,'ORDER_ITEMS&#8217;);</p>
<p>SEGMENT_NAME         PARTITION_NAME<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
ORDERS               Q1_2008<br />
ORDERS               Q2_2008<br />
ORDERS               Q3_2008<br />
ORDERS               Q4_2008<br />
ORDER_ITEMS          Q1_2008  &#8211;exactly what we expected<br />
ORDER_ITEMS          Q2_2008<br />
ORDER_ITEMS          Q3_2008<br />
ORDER_ITEMS          Q4_2008</p>
<p>8 rows selected.</p>
<p>&#8211;insert data to test<br />
insert into orders values (1,TO_DATE(&#8216;2008-03-03&#8242;,&#8217;YYYY-MM-DD&#8217;),1);<br />
insert into orders values (2,TO_DATE(&#8216;2008-06-03&#8242;,&#8217;YYYY-MM-DD&#8217;),2);<br />
insert into orders values (3,TO_DATE(&#8216;2008-09-03&#8242;,&#8217;YYYY-MM-DD&#8217;),3);<br />
insert into orders values (4,TO_DATE(&#8216;2008-12-03&#8242;,&#8217;YYYY-MM-DD&#8217;),4);<br />
insert into order_items values (1,1,1,1,1);<br />
insert into order_items values (2,2,2,2,2);<br />
insert into order_items values (3,3,3,3,3);<br />
insert into order_items values (4,4,4,4,4);<br />
commit;</p>
<p>&#8211;check data in partition<br />
T@ONASM&gt;select * from order_items partition (Q1_2008);<br />
ORDER_ID LINE_ITEM_ID PRODUCT_ID UNIT_PRICE   QUANTITY<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
1            1          1          1          1<br />
T@ONASM&gt;select * from order_items partition (Q2_2008);<br />
ORDER_ID LINE_ITEM_ID PRODUCT_ID UNIT_PRICE   QUANTITY<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
2            2          2          2          2<br />
T@ONASM&gt;select * from order_items partition (Q3_2008);<br />
ORDER_ID LINE_ITEM_ID PRODUCT_ID UNIT_PRICE   QUANTITY<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
3            3          3          3          3<br />
T@ONASM&gt;select * from order_items partition (Q4_2008);<br />
ORDER_ID LINE_ITEM_ID PRODUCT_ID UNIT_PRICE   QUANTITY<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
4            4          4          4          4<br />
&#8211;it is exactly as expected</p>
<p><span style="color:#0000ff;">&#8211;reference partition limitation: cannot used with interval partition<br />
&#8211;benefit: avoids having to duplicate the partition-key column, partition-wise join<br />
&#8211;         automatically maintain partitions at the same time</span></p>
<p><span style="color:#0000ff;">&#8211;<br />
&#8211;**virtual column partition, all partition methods are supported using virtual columns.<br />
&#8211;</span></p>
<p>&#8211;use a employee table as example<br />
create table employee (<br />
employee_id number,<br />
name  varchar2(20),<br />
title varchar2(40),<br />
emp_year as (trunc(employee_id,-4)/10000)<br />
)<br />
PARTITION BY RANGE (emp_year) INTERVAL (1)<br />
( PARTITION p1 VALUES LESS THAN (2006)<br />
);</p>
<p>-let&#8217;s add data, suppose the first 4 digit of employee_id is represent year.<br />
insert into employee(employee_id,name,title) values (20062023,&#8217;Alex&#8217;,'dba&#8217;);<br />
insert into employee(employee_id,name,title) values (20070001,&#8217;Daniel&#8217;,'ceo&#8217;);<br />
insert into employee(employee_id,name,title) values (20080201,&#8217;Susan&#8217;,&#8217;secretary&#8217;);<br />
insert into employee(employee_id,name,title) values (20080520,&#8217;Tom&#8217;,'accountant&#8217;);<br />
commit;</p>
<p>&#8211;let&#8217;s check the partition available<br />
T@ONASM&gt;select PARTITION_NAME,HIGH_VALUE from dba_tab_partitions where TABLE_NAME=&#8217;EMPLOYEE&#8217;;</p>
<p>PARTITION_NAME                 HIGH_VALUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
P1                             2006<br />
SYS_P81                        2007<br />
SYS_P82                        2008<br />
SYS_P83                        2009</p>
<p>&#8211;let&#8217;s check the data<br />
T@ONASM&gt;select * from employee partition (p1);</p>
<p>no rows selected</p>
<p>T@ONASM&gt;select * from employee partition (SYS_P81);</p>
<p>EMPLOYEE_ID NAME                 TITLE                                      EMP_YEAR<br />
&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
20062023 Alex                 dba                                            2006</p>
<p>T@ONASM&gt;select * from employee partition (SYS_P82);</p>
<p>EMPLOYEE_ID NAME                 TITLE                                      EMP_YEAR<br />
&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
20070001 Daniel               ceo                                            2007</p>
<p>T@ONASM&gt;select * from employee partition (SYS_P83);</p>
<p>EMPLOYEE_ID NAME                 TITLE                                      EMP_YEAR<br />
&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
20080201 Susan                secretary                                      2008<br />
20080520 Tom                  accountant                                     2008</p>
<p>&#8211;good, it is just as expected!<br />
<span style="color:#0000ff;">&#8211;vitual column partition comments:<br />
&#8211; vitual column stored as metadata only<br />
&#8211; can be used in queries, DML, DDL statements<br />
&#8211; can be indexed<br />
&#8211; can have statistics collected on them<br />
&#8211; limitation: cannot call PL/SQL function<br />
&#8211;     Cannot update, insert to a virtual column<br />
&#8211;     The virtual column cannot reference another virtual column<br />
&#8211;     All columns referenced in the expression for the virtual column<br />
&#8211;     must exist in the same table<br />
&#8211;     The output of the column expression must be a scalar value</span></p>
<p><span style="color:#0000ff;">&#8211;<br />
&#8211;**system partition, application-controlled partitioning, database do not control the data placement.<br />
&#8211; an insertion into a system partitioned table without the explicit specification of a partition will fail.</span><br />
CREATE TABLE credits (name varchar2(20), telephone number)<br />
PARTITION BY SYSTEM<br />
(<br />
PARTITION p_good,<br />
PARTITION p_fair,<br />
PARTITION p_bad<br />
);</p>
<p>INSERT INTO credits PARTITION (p_good) VALUES (&#8216;Alex&#8217;,50002563);<br />
INSERT INTO credits PARTITION (p_fair) VALUES (&#8216;Susan&#8217;,67002587);<br />
INSERT INTO credits PARTITION (p_bad) VALUES (&#8216;Daniel&#8217;,85892095);</p>
<p>&#8211;if you don&#8217;t specify the partition name<br />
T@ONASM&gt;INSERT INTO credits VALUES (&#8216;Bob&#8217;,12345678);<br />
INSERT INTO credits VALUES (&#8216;Bob&#8217;,12345678)<br />
*<br />
ERROR at line 1:<br />
ORA-14701: partition-extended name or bind variable must be used for DMLs on tables partitioned by the System method</p>
<p>&#8211;delete and update do not require partition syntax, but if specified, partition pruning is the benefit</p>
<p>&#8211;you can use bind variable to specify the partition name<br />
T@ONASM&gt;SELECT SUBOBJECT_NAME,OBJECT_ID FROM USER_OBJECTS WHERE object_name=&#8217;CREDITS&#8217; AND OBJECT_TYPE=&#8217;TABLE PARTITION&#8217;;</p>
<p>SUBOBJECT_NAME                  OBJECT_ID<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;-<br />
P_BAD                               12503<br />
P_FAIR                              12502<br />
P_GOOD                              12501</p>
<p>T@ONASM&gt;var partition_id number<br />
T@ONASM&gt;exec :partition_id :=12501</p>
<p>PL/SQL procedure successfully completed.</p>
<p>T@ONASM&gt;insert into credits partition(dataobj_to_partition(&#8220;CREDITS&#8221;, :partition_id)) values (&#8216;Tom&#8217;,98765432);</p>
<p>1 row created.</p>
<p>T@ONASM&gt;commit;</p>
<p>Commit complete.</p>
<p>T@ONASM&gt;select * from credits partition (p_good);</p>
<p>NAME                  TELEPHONE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;-<br />
Alex                   50002563<br />
Tom                    98765432  &#8211;it is here</p>
<p><span style="color:#0000ff;">&#8211;it is not SYSTEM. It is actually do it yourself, <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexzeng.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexzeng.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexzeng.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexzeng.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexzeng.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexzeng.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexzeng.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexzeng.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexzeng.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexzeng.wordpress.com/92/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexzeng.wordpress.com&blog=4375561&post=92&subd=alexzeng&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://alexzeng.wordpress.com/2008/11/12/step-by-step-tes-11g-new-partition-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ec71fb52eb0cb170123476467bb48a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexzeng</media:title>
		</media:content>
	</item>
	</channel>
</rss>