<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Sunbel&#039;s Blog</title>
	<atom:link href="http://sbelagam.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sbelagam.wordpress.com</link>
	<description>Just another WordPress.com site</description>
	<lastBuildDate>Mon, 26 Sep 2011 01:35:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sbelagam.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Sunbel&#039;s Blog</title>
		<link>http://sbelagam.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sbelagam.wordpress.com/osd.xml" title="Sunbel&#039;s Blog" />
	<atom:link rel='hub' href='http://sbelagam.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Wait Events</title>
		<link>http://sbelagam.wordpress.com/2011/09/26/wait-events/</link>
		<comments>http://sbelagam.wordpress.com/2011/09/26/wait-events/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 01:35:19 +0000</pubDate>
		<dc:creator>Sunil Belagam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sbelagam.wordpress.com/?p=44</guid>
		<description><![CDATA[Control file parallel write/ Control file sequential read: Definition The three different wait events of &#8216;control file sequential read&#8217;, &#8216;control file single write&#8217;, and &#8216;control file parallel write&#8217; all contribute to the amount of time Oracle takes to keep the &#8230; <a href="http://sbelagam.wordpress.com/2011/09/26/wait-events/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sbelagam.wordpress.com&amp;blog=14325917&amp;post=44&amp;subd=sbelagam&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Control file parallel write/ Control file sequential read: </strong></p>
<p><strong><span style="text-decoration:underline;">Definition</span></strong><br />
The three different wait events of &#8216;control file sequential read&#8217;, &#8216;control file single write&#8217;, and &#8216;control file parallel write&#8217; all contribute to the amount of time Oracle takes to keep the control file current.</p>
<p>Oracle maintains a record of the consistency of the database&#8217;s physical structures and operational state through a set of control files. The Oracle control file is essential to the database operation and ability to recover from an outage. In fact, if you lose the control file(s) associated with an instance you may not be able to recover completely. It is the Oracle control file(s) that records information about the consistency of a database&#8217;s physical structures and operational statuses. The database state changes through activities such as adding data files, altering the size or location of datafiles, redo being generated, archive logs being created, backups being taken, SCN numbers changing, or checkpoints being taken.</p>
<p>Through normal operation the control file is continuously hammered with reads and writes as it is being updated.</p>
<p><strong><span style="text-decoration:underline;">Why Control File Waits Occur</span></strong><br />
The performance around reads and writes against control files is often an indication of misplaced control files that share the same I/O access path or are on devices that are heavily used. It is interesting to note that Oracle has always defaulted the creation of control files in a single directory.</p>
<p>Query to check the control file wait event:</p>
<pre>SELECT *
FROM v$system_event
WHERE event IN (SELECT name
FROM V$EVENT_NAME
WHERE name LIKE '%control%');</pre>
<p>&nbsp;</p>
<p>Likewise you could query the V$SESSION_WAIT view to see which sessions are experiencing control file waits in real time.<br />
SELECT event, wait_time, p1, p2, p3<br />
FROM v$session_wait<br />
WHERE event LIKE &#8216;%control%&#8217;;</p>
<p>&nbsp;</p>
<p><strong><span style="text-decoration:underline;">Making Improvements</span></strong><br />
So how can I reduce the time spent for control file reads and writes? There are two distinct answers to this problem.</p>
<p>First, you can ensure that you have placed your control files on disks that are not under excessive heavy loads. When trying to determine how many control files to have, it is best to keep in mind that the more control files you have, the more I/O and time will be needed to write to all those copies. If is often better to have the O/S mirror the control files and reduce Oracle overhead.</p>
<p>Second, since the number of reads and writes are dictated by the type of activity within the database, it is often a good idea to revisit application logic and processing steps to ensure that excessive activities are not causing excessive reads and writes to the control files. For instance, I have seen code that produces excessive commits and even log switches. Since DBA activity is typically concentrated on modifying structures in the database, we need to be careful when performing batch runs of administrative scripts that could conflict with normal application processing. So be on the lookout for high activity levels such as log switching, checkpointing, backups taking place, and structural changes.</p>
<p>&nbsp;</p>
<p><strong>DB file sequential read / Db file scattered read:</strong></p>
<p>Because all Oracle databases retrieve and store data, the relative cost of physical disk access is an important topic. In Oracle, we see two types of data block access:</p>
<ul>
<li><em>db file sequential read</em>—A single-block read (i.e., index fetch by ROWID)<br />
 </li>
<li><em>db file scattered read</em>—A multiblock read (a full-table scan, OPQ, sorting)</li>
</ul>
<p>Physical disk speed is an important factor in weighing these costs. Faster disk access speeds can reduce the costs of a full-table scan vs. single block reads to a negligible level.</p>
<p>For example, the new solid state disks provide up to 100,000 I/Os per second, six times faster than traditional disk devices. In a solid-state disk environment, disk I/O is much faster and multiblock reads become far cheaper than with traditional disks.</p>
<p>The standard STATSPACK report can be generated when the database is processing a peak load, and you can get a super-detailed report of all elapsed-time metrics. The most important of these metrics is the STATSPACK top-five timed events. This report is critical because it shows the database events that constitute the bottleneck for the system. We can also see the same phenomenon where a system is disk I/O bound. In the STATSPACK report in Listing A, we see that the system is clearly constrained by disk I/O.</p>
<p>Top 5 Timed Events<em></em></p>
<p>                                                           % Total<em></em></p>
<p>Event                        Waits         Time (s)       Ela Time<em></em></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8211;      &#8212;&#8212;&#8211;<em></em></p>
<p><strong>db file sequential read       2,598          7,146          48.54</strong><em></em></p>
<p><strong>db file scattered read       25,519          3,246          22.04</strong><em></em></p>
<p>library cache load lock         673          1,363           9.26<em></em></p>
<p>CPU time                                     1,154           7.83<em></em></p>
<p>log file parallel write      19,157            837           5.68<em></em><br />
Here we see that reads and a write constitute the majority of the total database time. In this case, we would want to increase the RAM size of the <em>db_cache_size</em> to reduce disk I/O, tune the SQL to reduce disk I/O, or invest in a faster disk I/O subsystem.</p>
<p>The ideal optimizer settings depend on your environment and are heavily influenced by your system&#8217;s costs for scattered disk reads vs. sequential disk reads.  Below is a great script you can use to measure these I/O costs on your database.</p>
<p>col c1 heading &#8216;Average Waits|forFull| Scan Read I/O&#8217;        format 9999.999<em></em></p>
<p>col c2 heading &#8216;Average Waits|for Index|Read I/O&#8217;            format 9999.999<em></em></p>
<p>col c3 heading &#8216;Percent of| I/O Waits|for Full Scans&#8217;        format 9.99<em></em></p>
<p>col c4 heading &#8216;Percent of| I/O Waits|for Index Scans&#8217;       format 9.99<em></em></p>
<p>col c5 heading &#8216;Starting|Value|for|optimizer|index|cost|adj&#8217; format 999<em></em></p>
<p> <em></em></p>
<p> <em></em></p>
<p>select<em></em></p>
<p>   a.average_wait                                  c1,<em></em></p>
<p>   b.average_wait                                  c2,<em></em></p>
<p>   a.total_waits /(a.total_waits + b.total_waits)  c3,<em></em></p>
<p>   b.total_waits /(a.total_waits + b.total_waits)  c4,<em></em></p>
<p>   (b.average_wait / a.average_wait)*100           c5<em></em></p>
<p>from<em></em></p>
<p>  v$system_event  a,<em></em></p>
<p>  v$system_event  b<em></em></p>
<p>where<em></em></p>
<p>   a.event = &#8216;db file scattered read&#8217;<em></em></p>
<p>and<em></em></p>
<p>   b.event = &#8216;db file sequential read&#8217;;<em></em><br />
<strong>Scattered reads and full-table scans<br />
</strong><br />
Contrary to some opinions, full-table scans are not necessarily a detriment to performance, and they are often the fastest way to access the table rows. The CBO (cost-based optimizer) choice of performing a full-table scan depends on the settings for Oracle Parallel Query, the <em>db_block_size</em>, the <em>clustering_factor</em>, the estimated percentage of rows returned by the query (according to the CBO statistics), and many other factors.</p>
<p>Once Oracle has chosen a full-table scan, the speed of performing a full-table scan (SOFTS) depends on internal and external factors:</p>
<ul>
<li>The number of CPUs on the system</li>
<li>The setting for Oracle Parallel Query (parallel hints, alter table)</li>
<li>Table partitioning</li>
<li>The speed of the disk I/O subsystem (e.g., hardware-cached I/O, solid-state disk RAM 3)</li>
</ul>
<p>With all of these factors, it may be impossible to determine the exact best setting for the weight in <em>optimizer_index_cost_adj.</em> In the real world, the decision to invoke a full-table scan is heavily influenced by run-time factors such as:</p>
<ul>
<li>The availability of free blocks in the data buffers</li>
<li>The amount of TEMP tablespace (if the FTS has an <em>order by</em> clause)</li>
<li>The current demands on the CPUs</li>
</ul>
<p>Hence, it follows that the <em>optimizer_index_cost_adj</em> should change frequently, as the load changes on the server.</p>
<p>However, is it safe to assume that all of the SOFTS factors are reflected in the relative I/O speed of FTS vs. index access? If we make this assumption, we&#8217;ve measured the relative speed in <em>v$system_event</em> and have a foundation for creating a self-tuning parameter. To do this, we must accept the following assumptions:</p>
<ul>
<li>No systems are alike, and good DBAs must adjust <em>optimizer_index_cost_adj</em> according to their configuration and data access patterns.<br />
 </li>
<li>The SOFTS is measurable and is reflected in the wait times in <em>v$system_event.</em><br />
 </li>
<li>The overall amount of time spent performing full-table scans is equal to the percentage of <em>db file sequential read</em> waits as a percentage of total I/O waits from <em>v$system_event</em>:</li>
</ul>
<p>  (avg-wait-for-db-file-sequential-read /</p>
<p>    avg-wait-for-db-file-scattered-read)       * 100</p>
<p><strong>Control disk I/O</p>
<p></strong>Disk I/O-intensive systems are common to Oracle databases, and the time spent performing disk I/O often consumes the majority of the wait time. The job of the Oracle professional is to examine all SQL statements to ensure that they&#8217;re performing the minimum amount of disk I/O and to know their relative costs of index access vs. full-table scan access.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Direct path read/ Direct path read temp</strong></p>
<p>Description – Direct Path Read Temp</p>
<p>When a session reads buffers from disk directly into the PGA, the wait is on direct path read temp.  This is closely related to the direct path read wait.  If the I/O subsystem doesn’t support asynchronous I/Os, then each wait corresponds to a physical read request.  If the I/O subsystem supports asynchronous I/O, then the process overlaps read requests with processing the blocks already in the PGA. When the process attempts to access a block in the PGA that has not yet been read from disk, it issues a wait call and updates the statistics for this event. So, the number of waits is not always the same as the number of read requests.</p>
<p>Similarly, the direct path write temp wait event and direct path write wait event can occur when a process is writing buffers directly from PGA.  The process will wait on this event for the write call to complete. Operations that could perform direct path writes include when a sort goes to disk, parallel DML operations, direct-path INSERTs, parallel create table as select, and some LOB operations.  Like direct path reads, the number of waits is not the same as number of write calls issued if the I/O subsystem supports asynchronous writes. The session will wait if it has processed the buffers in the PGA and can’t continue work until an I/O request completes.</p>
<p>Diagnosing the direct path read temp wait</p>
<p>When a session is waiting on this event, an entry will be seen in the v$session_wait system view giving more information on the blocks being waited for:</p>
<p>SELECT p1 “file#”, p2 “block#”, p3 “class#”<br />
FROM v$session_wait<br />
WHERE event = ‘direct path read temp’;</p>
<p>In this case p1 represents the file_ID for the read call; p2 represents the start block_ID for the read call; while p3 is the number of blocks in the read call.  Check the file_ID to see if it is for temp.</p>
<p>SELECT relative_fno, owner, segment_name, segment_type<br />
FROM dba_extents<br />
WHERE file_id = &amp;file<br />
AND &amp;block BETWEEN block_id AND block_id + &amp;blocks – 1;</p>
<p>Causes for the direct path read temp wait</p>
<p>To reduce the direct path read wait event and direct path read temp wait event:</p>
<ul>
<li>High disk sorts – If the sorts are too large to fit in memory and get sent to disk, this wait can occur.</li>
<li>Parallel slaves – Parallel slaves are used for scanning data or parallel DML may be used to create and populate objects.  These may lead to direct path read wait and direct path write wait respectively.</li>
<li>Direct path loads – The direct path API is used to pass data to the load engine in the server and can cause the related direct path write wait.</li>
<li>Server process ahead of I/O – The server process is processing buffers faster than the I/O system can return the buffers. This can indicate an overloaded I/O system</li>
<li>Data Warehouse – Sorts in a data warehouse environment may always go to disk leading to high waits on direct path read temp and/or direct path write temp.</li>
<li>Hash area size – For query plans that call for a hash join, excessive I/O could result from having HASH_AREA_SIZE too small.</li>
</ul>
<p>Tune away the direct path read temp</p>
<p>High disk sorts –  The disk sort distribution can be checked:</p>
<p>select a.instance_number,to_char(a.snap_time,’dd/mon/yyyy hh24:mi’) meas_date, b.value<br />
from stats$snapshot a, stats$sysstat b, v$statname c<br />
where c.name=’sorts (disk)’<br />
and a.snap_time&gt;sysdate-7<br />
and c.statistic#=b.statistic#<br />
and b.snap_id=a.snap_id<br />
order by a.instance_number,a.snap_time</p>
<p>It is recommended to use pga_aggregate_target.  This area is used both for sorts and the hash join area.  If possible the PGA can be sized larger to fit more in-memory sorts reducing the disk sorts.  It is important to remember that there are limitations of pga_aggregate_target:  The total work area cannot exceed 200 megabytes of RAM because of the default setting for the hidden parameter_pga_max_size.  No RAM sort may use more than 5% of pga_aggregate_target or _pga_max_size, whichever is smaller. This means that no task may use more than 200 megabytes for sorting or hash joins.   Oracle does not recommend changing the hidden parameters, but for certain environments, the result can be beneficial.</p>
<p>To view the PGA and its distribution.</p>
<p>Select  * from v$pgastat;<br />
NAME                                          VALUE<br />
—————————————- ———-<br />
aggregate PGA target parameter            419430400<br />
aggregate PGA auto target                 343517184<br />
global memory bound                        20971520<br />
total PGA inuse                            37789696<br />
total PGA allocated                        42677248<br />
maximum PGA allocated                      53294080<br />
total freeable PGA memory                         0<br />
PGA memory freed back to OS                       0<br />
total PGA used for auto workareas                 0<br />
maximum PGA used for auto workareas           16384<br />
total PGA used for manual workareas               0<br />
maximum PGA used for manual workareas             0<br />
over allocation count                             0<br />
bytes processed                            26643456<br />
extra bytes read/written                          0<br />
cache hit percentage                            100</p>
<p>Tune the sorts – Find the session experiencing the waits and look at the SQL statement currently being run to see the cause of the sorts. Query V$TEMPSEG_USAGE to find the SQL statement generating the sort.  Also query the statistics from V$SESSTAT for the session to determine the size of the sort. Determine whether it is possible to reduce the sorting by tuning the SQL statement.<br />
Full Table Scans – If tables are defined with a high degree of parallelism, the optimizer leans towards using full table scans with parallel slaves. For a direct path read, locate the object being loaded.  Consider using disk striping or Automatic Storage Management (ASM) which can stripe for you.<br />
Parallel DML – Check the I/O distribution across the disks and make sure your I/O is configured for the parallelism being used.  Verify that the parameter DISK_ASYNCH_IO is set to true.</p>
<p>&nbsp;</p>
<p><strong>Direct path Write/Direct path Write temp:</strong></p>
<h3>direct path write</h3>
<p>A direct path write I/O operation is just the opposite of the direct path read operation, and it writes buffers from a session&#8217;s PGA to the datafiles. The direct path write operation allows a session to issue multiple write requests and continue processing. At some point, the session will wait on the direct path write event, either to confirm that the OS has completed all outstanding I/Os, or wait for slots to become available so that more writes can be issued. The direct path write operation is normally applied when writing to the temporary tablespace (sort overflows) or when using the direct load method to create or populate objects (CTAS, insert with the APPEND hint). Oracle 8.1.7 has a separate direct write I/O wait event for LOB segments &#8211; direct path write (lob).</p>
<p>Like the direct path read event, the number of waits and time waited for the direct path write event can be misleading if asynchronous I/O is supported and used. <strong>V$SESSION_WAIT Parameters:</strong></p>
<ul>
<li>P1=The absolute file#</li>
<li>P2=The starting block#</li>
<li>P3=Number of blocks read</li>
</ul>
<p>If P1 is not in DBA_DATA_FILES or V$DATAFILE and it is greater than the DB_FILES INIT.ORA parameter, then it is a TEMPFILE. <strong>Common Causes and Actions</strong></p>
<p>The direct path write wait event is also popular with direct load operations such as CTAS and INSERT /*+ APPEND */ … SELECT. First, make sure the query is properly tuned to minimize the number of sorts, then tune the I/O subsystem to remove hot spots, if any.</p>
<p>Applications that write to LOB segments that are stored as NOCACHE tend to bottleneck on this event. Make sure there is no I/O bound on the disks where the LOB segments live.</p>
<p><strong>Diagnosis</strong></p>
<p>In Oracle 8.1.6 and up, the DBA can identify live sessions that wrote the most number of blocks in direct mode using the query below.</p>
<p><strong>select</strong> <strong>a.name, b.sid, b.value</strong></p>
<p><strong>from</strong>   <strong>v$statname a, v$sesstat b </strong></p>
<p><strong>where</strong>  <strong>a.statistic# =</strong> <strong>b.statistic# </strong></p>
<p><strong>and</strong>    <strong>b.value</strong>      <strong>&gt; 0 </strong></p>
<p><strong>and</strong>    <strong>a.name       =</strong> <strong>&#8216;physical writes direct&#8217;</strong></p>
<p><strong>order</strong> <strong>by</strong> <strong>b.value; </strong></p>
<p><strong>select</strong> <strong>a.name, b.sid, b.value, d.ktssoblks </strong></p>
<p><strong>from</strong>   <strong>v$statname a, v$sesstat b, v$session</strong> <strong>c, x$ktsso d </strong></p>
<p><strong>where</strong>  <strong>a.statistic# =</strong> <strong>b.statistic# </strong></p>
<p><strong>and</strong>    <strong>b.value</strong>      <strong>&gt; 0 </strong></p>
<p><strong>and</strong>    <strong>a.name       =</strong> <strong>&#8216;physical writes direct&#8217;</strong></p>
<p><strong>and</strong>    <strong>b.sid        =</strong> <strong>c.sid </strong></p>
<p><strong>and</strong>    <strong>c.saddr      =</strong> <strong>d.ktssoses </strong></p>
<p><strong>and</strong>    <strong>c.serial#    =</strong> <strong>d.ktssosno </strong></p>
<p><strong>order</strong> <strong>by</strong> <strong>b.sid;</strong></p>
<p>The cure for the direct path write waits is to locate and tune the SQL statement to reduce the number of sorts and eliminate hot disks. When the statement is executing, examine the P1 values. If they mostly point to the TEMP tablespace, this means the statement is performing disk sort operations, and if there are a lot of them, then the statement must be tuned to reduce the number of sorts. The DBA can query the X$KTSSO table to see what kind of sorts are taking place to further guide the DBA in tuning the statement. If there is enough memory, consider increasing the SORT_AREA_SIZE parameter, which can help reduce the number of disk sorts. If P1s mostly point to a tablespace other than TEMP, then the statement is probably inserting into a table with the APPEND hint or creating a table with the CTAS operation. In this case, use the appropriate operating system tools or utilities such as sar –d or iostat –dxn to ensure that there are no hot disks. During Direct Path operations, the data is asynchronously written to the database files. At some stage the session needs to make sure that all outstanding asynchronous I/O have been completed to disk. This can also happen if, during a direct write, no more slots are available to store outstanding load requests (a load request could consist of multiple I/Os). <strong>Wait Time:</strong></p>
<p>10 seconds. The session will be posted by the completing asynchronous I/O. It will never wait the entire 10 seconds. The session waits in a tight loop until all outstanding I/Os have completed.</p>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="center"><strong>Parameter </strong></p>
</td>
<td>
<p align="center"><strong>Description </strong></p>
</td>
</tr>
<tr>
<td>descriptor address</td>
<td>This is a pointer to the I/O context of outstanding direct I/Os on which the session is currently waiting.</td>
</tr>
<tr>
<td>first dba</td>
<td>The dba of the oldest I/O in the context referenced by the descriptor address.</td>
</tr>
<tr>
<td>block cnt</td>
<td>Number of valid buffers in the context referenced by the descriptor address.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Log file parallel write:</strong></p>
<p>The <strong>&#8216;log file parallel write&#8217;</strong> event is caused by the Log writer (LGWR) process. The LGWR writes the redo buffer to the online redo log files. It issues a series of write calls to the system IO. The LGWR waits for the writes to complete on log file parallel write. A slow LGWR process can introduce log file sync waits which makes the user to experience wait times during commit or rollback. The log file parallel write and log file sync wait events are interrelated and must be dealt simultaneously.</p>
<p>If the average_wait time is high (above 10 milliseconds) it indicates that the system IO throughput is slow. To improve the average_wait time follow the same techniques used in <a href="http://oracledba-vinod.blogspot.com/2009/08/db-file-parallel-readwrite.html">db file parallel write</a> wait event.</p>
<p>Tuning options:</p>
<p>1. Avoid running hot backups during peak hours.<br />
2. Check for high commit sessions and try to change the <a href="http://oracledba-vinod.blogspot.com/2009/09/log-file-parallel-write.html">application logic</a> to commit less frequently. Use the following queries to find high commit sessions,</p>
<p>SQL&gt; <strong>select sid, value from v$sesstat</strong><strong><br />
<strong>where statistic# = select statistic# from v$statname where name = &#8216;user commits&#8217;) order by 2 desc;</strong></strong></p>
<p>A high redo wastage also indicates high frequency commits</p>
<p>SQL&gt; <strong>select b.name, a.value, round(sysdate &#8211; c.startup_time) days_old</strong><strong><br />
<strong>from v$sysstat a, v$statname b, v$instance c</strong><br />
<strong>where a.statistic# = b.statistic#</strong><br />
<strong>and b.name in (&#8216;redo wastage&#8217;,'redo size&#8217;);</strong></strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Log file switch completion:</strong></p>
<p>Definition &#8211; The amount of time users and applications must wait for a log switch to complete.</p>
<p>As users make changes to data, Oracle keeps a running log of these changes within a set of structures that make up what Oracle calls &#8220;redo&#8221;. These Redo Logs within Oracle are the critical link in the recovery process as they record the changes to data and provide the input to produce sets of archived logs that are used for point in time recovery. As redo logs fill to capacity and are readied for archival a log switch occurs that relinquishes control from the current redo log to the next available. A single log switch entails stopping further acceptance of generated of redo, reading &amp; writing to control files for redo log status and SCN, (System Change Number), information, flushing memory, and the closing &amp; opening of individual redo log files. Since there are many other resources in use when log switching occurs it is imperative that we are not fooled by high resource usage on these erroneous resources.</p>
<p>There is no record in Oracle that pinpoints the amount of time it takes for a log file switch. It is only experienced by users or applications and is recorded as a wait event at a session or system level. Other than individual sessions generating more redo through improper SQL applications this wait event can only be reduced by attacking it from a full system perspective.</p>
<p>Often the performance impact of switching too many redo logs is the culprit. A good rule of thumb is to switch a redo log every 20 to 30 minutes. Listing 1 gives a SQL statement that will show how often log switching is occurring every hour. You need only increase your redo log sizes to hold more redo and this will reduce the amount of log switching.</p>
<h2>Listing 1. Log switching history</h2>
<div align="center">
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
<tr>
<td width="7"> </td>
<td>select to_char(first_time,&#8217;YYYY-MON-DD&#8217;) day,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;00&#8242;,1,0)),&#8217;99&#8242;) &#8220;00&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;01&#8242;,1,0)),&#8217;99&#8242;) &#8220;01&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;02&#8242;,1,0)),&#8217;99&#8242;) &#8220;02&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;03&#8242;,1,0)),&#8217;99&#8242;) &#8220;03&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;04&#8242;,1,0)),&#8217;99&#8242;) &#8220;04&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;05&#8242;,1,0)),&#8217;99&#8242;) &#8220;05&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;06&#8242;,1,0)),&#8217;99&#8242;) &#8220;06&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;07&#8242;,1,0)),&#8217;99&#8242;) &#8220;07&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;08&#8242;,1,0)),&#8217;99&#8242;) &#8220;08&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;09&#8242;,1,0)),&#8217;99&#8242;) &#8220;09&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;10&#8242;,1,0)),&#8217;99&#8242;) &#8220;10&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;11&#8242;,1,0)),&#8217;99&#8242;) &#8220;11&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;12&#8242;,1,0)),&#8217;99&#8242;) &#8220;12&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;13&#8242;,1,0)),&#8217;99&#8242;) &#8220;13&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;14&#8242;,1,0)),&#8217;99&#8242;) &#8220;14&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;15&#8242;,1,0)),&#8217;99&#8242;) &#8220;15&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;16&#8242;,1,0)),&#8217;99&#8242;) &#8220;16&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;17&#8242;,1,0)),&#8217;99&#8242;) &#8220;17&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;18&#8242;,1,0)),&#8217;99&#8242;) &#8220;18&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;19&#8242;,1,0)),&#8217;99&#8242;) &#8220;19&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;20&#8242;,1,0)),&#8217;99&#8242;) &#8220;20&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;21&#8242;,1,0)),&#8217;99&#8242;) &#8220;21&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;22&#8242;,1,0)),&#8217;99&#8242;) &#8220;22&#8243;,<br />
to_char(sum(decode(to_char(first_time,&#8217;HH24&#8242;),&#8217;23&#8242;,1,0)),&#8217;99&#8242;) &#8220;23&#8243;<br />
from v$log_history group by to_char(first_time,&#8217;YYYY-MON-DD&#8217;);</td>
<td width="7"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
</tbody>
</table>
</div>
<p>Often times the placement of redo log groups on disk is not optimal for the subsystem. Optimally each group member should be assigned to its own disk. This is the only way to eliminate the contention of writing redo and reading redo for archival purposes. Use the SQL in Listing 2 to determine where on disk the redo log groups are. After you have pinpointed them, use a disk monitoring utility such as iostat during high redo activity to determine if you have any contention for reads and writes. Alternatively you could use a disk cache to speed I/O operations.</p>
<h2>Listing 2 Redo Log placement</h2>
<div align="center">
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
<tr>
<td width="7"> </td>
<td>select group#, status, member<br />
from sys.v$logfile ORDER BY group#;</td>
<td width="7"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
</tbody>
</table>
</div>
<p>Before diving into disk monitors, you can gain benefit from the SQL in Listing 3. This SQL will display sizes and statuses of the current configuration and use of redo logs. Of importance is the FIRST_CHANGE#. This column shows the first SCN number that was used for a particular redo log group. Use it to verify two redo log groups are not on the same disk that are used next to each other in the redo log rotation.</p>
<h2>Listing 3 Redo Log usage order</h2>
<div align="center">
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
<tr>
<td width="7"> </td>
<td>select group#, bytes, archived, status, first_change#, first_time from v$log order BY first_change#;</td>
<td width="7"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
</tbody>
</table>
</div>
<p>During the log switch operation, the control file is used quite extensively. It has always been recommended that practitioners multiplex control files through Oracle.</p>
<p>Done this way the log switch operation must keep in sync all the control files defined and thus overhead is increased by a factor of the number of control files multiplexed. Mirroring control files at the operating system level will eliminate the reads and writes for each control file. Use the SQL in Listing 4 to determine the extra amount of I/O you are incurring for each log switch (and many other operations). If you choose this route, please schedule a backup of your control file to trace often enough for recoverability. Alternatively you could use a disk cache to speed I/O operations.</p>
<h2>Listing 4 Control File placement</h2>
<div align="center">
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
<tr>
<td width="7"> </td>
<td>Listing 4 Control File placement</td>
<td width="7"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
</tbody>
</table>
</div>
<h2>Listing 5 ARCHIVE_LAG_TARGET setting</h2>
<div align="center">
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
<tr>
<td width="7"> </td>
<td>select name, value<br />
from v$parameter<br />
where name = &#8216;archive_lag_target&#8217;;</td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
<p><strong>Log file sync:</strong></p>
<h1>Log File Sync</h1>
<p>The “log file sync” wait event is triggered when a user session issues a commit (or a rollback). The user session will signal or post the LGWR to write the log buffer to the redo log file. When the LGWR has finished writing, it will post the user session. The wait is entirely dependent on LGWR to write out the necessary redo blocks and send confirmation of its completion back to the user session. The wait time includes the writing of the log buffer and the post, and is sometimes called “commit latency”.</p>
<p>The P1 parameter in &lt;View:V$SESSION_WAIT&gt; is defined as follows for this wait event:</p>
<div align="center">
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
<tr>
<td width="7"> </td>
<td>P1 = buffer#</p>
<p>All changes up to this buffer number (in the log buffer) must be flushed to disk and the writes confirmed to ensure that the transaction is committed and will be kept on an instance crash. The wait is for LGWR to flush up to this <strong>buffer#</strong>.</td>
<td width="7"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
</tbody>
</table>
</div>
<h2>Reducing Waits / Wait times:</h2>
<p>If a SQL statement is encountering a significant amount of total time for this event, the average wait time should be examined. If the average wait time is low, but the number of waits is high, then the application might be committing after every row, rather than batching COMMITs. Applications can reduce this wait by committing after “n” rows so there are fewer distinct COMMIT operations. Each commit has to be confirmed to make sure the relevant REDO is on disk. Although commits can be &#8220;piggybacked&#8221; by Oracle, reducing the overall number of commits by batching transactions can be very beneficial.</p>
<p>If the SQL statement is a SELECT statement, review the Oracle Auditing settings. If Auditing is enabled for SELECT statements, Oracle could be spending time writing and commit data to the AUDIT$ table.</p>
<p>If the average time waited is high, then examine the other log related waits for the session, to see where the session is spending most of its time. If a session continues to wait on the same</p>
<p>If the average time waited is high, then examine the other log related waits for the session, to see where the session is spending most of its time. If a session continues to wait on the same buffer# then the SEQ# column of V$SESSION_WAIT should increment every second. If not then the local session has a problem with wait event timeouts. If the SEQ# column is incrementing then the blocking process is the LGWR process. Check to see what LGWR is waiting on as it may be stuck. If the waits are because of slow I/O, then try the following:</p>
<ul>
<li>Reduce other I/O activity on the disks containing the redo logs, or use dedicated disks.
<ul>
<li>Try to reduce resource contention. Check the number of transactions (commits + rollbacks) each second, from V$SYSSTAT.</li>
<li>Alternate redo logs on different disks to minimize the effect of the archiver on the log writer.</li>
<li>Move the redo logs to faster disks or a faster I/O subsystem (for example, switch from RAID 5 to RAID 1).</li>
<li>Consider using raw devices (or simulated raw devices provided by disk vendors) to speed up the writes.</li>
<li>See if any activity can safely be done with NOLOGGING / UNRECOVERABLE options in order to reduce the amount of redo being written.</li>
<li>See if any of the processing can use the COMMIT NOWAIT option (be sure to understand the semantics of this before using it).</li>
<li>Check the size of the log buffer as it may be so large that LGWR is writing too many blocks at one time.</li>
</ul>
</li>
</ul>
<h2>Other Considerations:</h2>
<p>There may be a problem with LGWR”s ability to flush redo out quickly enough if “log file sync” waits are significant for the entire system. The overall wait time for “log file sync” can be broken down into several components. If the system still shows high &#8220;log file sync” wait times after completing the general tuning tips above, break down the total wait time into the individual components. Then, tune those components that take up the largest amount of time.</p>
<p>The “log file sync” wait may be broken down into the following components:</p>
<p>1. Wakeup LGWR if idle<br />
2. LGWR gathers the redo to be written and issues the I/O<br />
3. Wait time for the log write I/O to complete<br />
4. LGWR I/O post processing<br />
5. LGWR posting the foreground/user session that the write has completed<br />
6. Foreground/user session wakeup</p>
<p>Tune the system based on the “log file sync” component with the most wait time. Steps 2 and 3 are accumulated in the &#8220;redo write time&#8221; statistic. (i.e. as found under STATISICS section of Statspack) Step 3 is the &#8220;log file parallel write&#8221; wait event. (See Metalink Note 34583.1:&#8221;log file parallel write&#8221;) Steps 5 and 6 may become very significant as the system load increases. This is because even after the foreground has been posted it may take some time for the OS to schedule it to run.</p>
<h2>Data Guard Note:</h2>
<p>If Data Guard with synchronous transport and commit WAIT defaults is used, the above tuning steps will still apply. However step 3 will also include the network write time and the redo write to the standby redo logs. This wait event and how it applies to Data Guard is explained in detail in the MAA OTN white paper &#8211; Note 387174.1:MAA &#8211; Data Guard Redo Transport and Network Best Practices.</p>
<h2>Conclusion</h2>
<p>When a user session waits on the &#8220;Log File Sync” event, it is actually waiting for the LGWR process to write the log buffer to the redo log file and return confirmation/control back to it. If the total wait time is significant, review the average wait time. If the average wait time is low but the number of waits is high, reduce the number of commits by batching (or committing after “n”) rows.</p>
<p>If slow I/O, investigate the following:</p>
<ul>
<li>Reduce contention on existing disks.</li>
<li>Put log files on faster disks.</li>
<li>Put alternate redo logs on different disks to minimize the effect archive processes (log files switches).</li>
<li>Review application design, use NOLOGGING operations where appropriate, and avoid changing more data than required.</li>
</ul>
<p>If wait times are still significant, review each component of the “log file sync” and tune separately.</p>
<p>&nbsp;</p>
<p><strong>Read by other session:</strong></p>
<p>&nbsp;</p>
<h1>Read By Other Session</h1>
<p>Definition: When information is requested from the database, Oracle will first read the data from disk into the database buffer cache. If two or more sessions request the same information, the first session will read the data into the buffer cache while other sessions wait. In previous versions this wait was classified under the &#8220;buffer busy waits&#8221; event. However, in Oracle 10.1 and higher this wait time is now broken out into the &#8220;read by other session&#8221; wait event. Excessive waits for this event are typically due to several processes repeatedly reading the same blocks, e.g. many sessions scanning the same index or performing full table scans on the same table. Tuning this issue is a matter of finding and eliminating this contention.</p>
<h2>Finding the contention</h2>
<p>When a session is waiting on this event, an entry will be seen in the v$session_wait system view giving more information on the blocks being waited for:</p>
<div align="center">
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
<tr>
<td width="7"> </td>
<td>SELECT p1 &#8220;file#&#8221;, p2 &#8220;block#&#8221;, p3 &#8220;class#&#8221;<br />
FROM v$session_wait<br />
WHERE event = &#8216;read by other session&#8217;;</td>
<td width="7"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
</tbody>
</table>
</div>
<p>If information collected from the above query repeatedly shows that the same block, (or range of blocks), is experiencing waits, this indicates a &#8220;hot&#8221; block or object. The following query will give the name and type of the object:</p>
<div align="center">
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
<tr>
<td width="7"> </td>
<td>SELECT relative_fno, owner, segment_name, segment_type<br />
FROM dba_extents<br />
WHERE file_id = &amp;file<br />
AND &amp;block BETWEEN block_id AND block_id + blocks &#8211; 1;</td>
<td width="7"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
</tbody>
</table>
</div>
<h2>Eliminating contention</h2>
<p>Depending on the database environment and specific performance situation the following variety of methods can be used to eliminate contention:</p>
<ol>
<li><strong>Tune inefficient queries -</strong> This is one of those events you need to &#8220;catch in the act&#8221; through the v$session_wait view as prescribed above. Then, since this is a disk operating system issue, take the associated system process identifier (c.spid) and see what information we can obtain from the operating system.</li>
<li><strong>Redistribute data from the hot blocks –</strong>deleting and reinserting the hot rows will often move them to a new data block. This will help decrease contention for the hot block and increase performance. More information about the data residing within the hot blocks can be retrieved with queries similar to the following:</li>
</ol>
<div align="center">
<table width="525" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
<tr>
<td width="7"> </td>
<td>SELECT data_object_id<br />
FROM dba_objects<br />
WHERE owner=&#8217;&amp;owner&#8217; AND object_name=&#8217;&amp;object&#8217;;</p>
<p>SELECT dbms_rowid.rowid_create(1,&lt;data_object_id&gt;,&lt;relative_fno&gt;,&lt;block&gt;,0) start_rowid<br />
FROM dual;<br />
&#8211;rowid for the first row in the block</p>
<p>SELECT dbms_rowid.rowid_create(1,&lt;data_object_id&gt;,&lt;relative_fno&gt;,&lt;block&gt;,500) end_rowid<br />
FROM dual; <br />
&#8211;rowid for the 500th row in the block</p>
<p>SELECT &lt;column_list&gt;<br />
FROM &lt;owner&gt;.&lt;segment_name&gt;<br />
WHERE rowid BETWEEN &lt;start_rowid&gt; AND &lt;end_rowid&gt;</td>
<td width="7"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td width="7"> </td>
</tr>
</tbody>
</table>
</div>
<ol>
<li><strong>Adjust PCTFREE and PCTUSED – </strong>adjusting the PCTFREE value downward for an object will reduce the number of rows physically stored in a block. Adjusting the PCTUSED value for an object keeps that object from getting prematurely put back on the freelist.</li>
</ol>
<p>Depending on the type of contention, adjusting these values could help distribute data among more blocks and reduce the hot block problem. Be careful to optimize these parameters so blocks do move in and out of the freelist too frequently.</p>
<ol>
<li><strong>Reduce the Block Size – </strong>this is very similar to adjusting the PCTFREE and PCTUSED parameters in that the goal is to reduce the amount of data stored within one block. In Oracle 9i and higher this can be achieved by storing the hot object in a tablespace with a smaller block size. In databases prior to Oracle 9i the entire database must be rebuilt with a smaller block size.</li>
<li><strong>Optimize indexes – </strong>a low cardinality index has a relatively small number of unique values, e.g. a column containing state data with only 50 values. Similar to inefficient queries, the use of a low cardinality index could cause excessive number of blocks to be read into the buffer cache and cause premature aging out of &#8220;good&#8221; blocks.</li>
</ol>
<h2>Conclusion</h2>
<p>When a session waits on the &#8220;read by other session&#8221; event, it indicates a wait for another session to read the data from disk into the Oracle buffer cache. If this happens too often the performance of the query or the entire database can suffer. Typically this is caused by contention for &#8220;hot&#8221; blocks or objects so it is imperative to find out which data is being contended for. Once that is known this document lists several alternative methods for solving the issue.</p>
<p>&nbsp;</p>
<p><strong>Log file switch (checkpoint incomplete):</strong></p>
<p><strong>Log file switch (checkpoint incomplete)</strong></p>
<p>The <strong>log file switch &#8211; checkpoint incomplete</strong> event tells you that Oracle wants to reuse a redo log file, but the current checkpoint position is still in that log file. This results in redo generation being stopped until the log switch is done. Obviously not good!</p>
<p><strong>Recommendation:</strong><br />
To resolve these <strong>incomplete checkpoints</strong> you need to give the checkpoint process more time to cycle through the logs by doing one or both of the following:</p>
<p>* increase the size of the redo logs</p>
<p>* add more redo log groups</p>
<p>Additionally, consider turning off logging for the temporary tables with transient data using the the NOLOGGING attribute on the tables.</p>
<p>Per Oracle documentation &#8220;The NOLOGGING clause specifies that subsequent DML statements (UPDATE, DELETE, and conventional path insert) are unaffected by the NOLOGGING attribute of the table and generate redo.&#8221; Therefore the SQL Hint /*+ APPEND */ should be used in your application code (only for non-critical, temporary tables).</p>
<p>&nbsp;</p>
<p>DB file parallel write:</p>
<p><strong>db file parallel write</strong></p>
<p>The db file parallel write wait event belongs to the Oracle Database Writer (DBWR) process since it is the only process that writes blocks from the SGA to datafiles. When it is time to write, the DBWR process compiles a set of dirty blocks, hands the batch over to the OS, and waits on the db file parallel write event for the I/O to complete.</p>
<p>Although user sessions never experience the db file parallel write wait event, this doesn&#8217;t mean that they are never impacted by it. If the write complete waits or free buffer waits event shows up in user sessions, then they may be suffering from the impact of the db file parallel write event.</p>
<p>If a user session needs to modify a block that happens to be in the DBWR write batch, it has to wait on the write complete waits event until that batch of blocks is completely written to disk. If the batch size is large, or the I/O subsystem is slow, the DBWR process will incur additional time waiting for the I/O to complete, and so will the user session that needs the block that is being written.</p>
<p>If user sessions are experiencing the free buffer waits wait event, and the number of waits increases steadily, this means there is a shortage of free blocks in the SGA. This can happen if the Buffer Cache is too small, or DBWR can&#8217;t keep up with the rate of blocks being dirtied. One of the reasons why the DBWR process can&#8217;t keep up with dirty blocks is that it spends too much time on the db file parallel write event. <strong>Parameters:</strong></p>
<ul>
<li>P1=The number of files Oracle is writing to.</li>
<li>P2=The number of blocks to be written.</li>
<li>P3=Total number of I/O request same as P2 because multi-block I/O is not used.</li>
</ul>
<p>Since P1 and P2 report the number of files and blocks instead of the absolute file and block number, a DBA cannot tell which objects are being written. However, the user session that waits on the write complete waits or free buffer waits event does indicate the absolute file and block number in its P1 and P2 values. <strong>Common Causes and Actions</strong></p>
<p>The db file parallel write latency is normally a symptom of a slow I/O subsystem or poor I/O configurations. This includes poor layout of database files, bad mount point to I/O controller ratio, wrong stripe size and/or RAID level, and not enough disks (i.e. there are a few high capacity disks versus many lower capacity disks). The DBA needs to look at the average I/O time. A well-laid database and I/O subsystem should provide an average I/O wait that does not exceed 2 centiseconds. If this is an issue, the DBA should review the I/O configuration by mapping out the I/O routes from mount points to controllers, and controllers to physical disk groups, and ensure proper placement of database files. The command for this function is platform specific and unfortunately, often requires administrator privilege. For storage systems configured with the Veritas volume manager on Sun platform, the DBA may be able to use the vxprint –ht command. The DBA should also watch for usage (i.e. I/O throughput and bottlenecks) from the OS level using sar –d, iostat –dxn, or an equivalent tool. If some disks are hit hard for an extended period of time (i.e. almost 100% busy), and the average queue length is greater than 3, then the DBA needs to rearrange some of the database files.</p>
<p>Beyond ensuring the I/O subsystem is properly configured and database files are well placed, the DBA should make non-blocking I/O (DISK_ASYNC_IO = TRUE) available to the DBWR process if the platform supports asynchronous I/O.</p>
<p>A larger write batch increases the DBWR I/O wait time, especially in an environment where datafiles are poorly placed. A sure sign that the write batch is too big is when user sessions start to wait on the write complete waits event. Prior to Oracle 8i, the _DB_BLOCK_WRITE_BATCH parameter determined the DBWR write batch size and the value can be seen in X$KVII. It is listed as DB writer IO clump. In 8i and higher, this parameter was replaced by the _DB_WRITER_CHUNK_WRITES and is listed as DBWR write chunk. A new parameter _DB_WRITER_MAX_WRITES was introduced to limit the number of outstanding DBWR I/Os. The DBA should ensure the batch size is not so large that it causes write complete waits and longer db file parallel write, and also not so small that it causes long dirty queue and free buffer waits. Also, bear in mind the improvements that Oracle made since 8i should put the write batch issue to rest, and DBAs shouldn&#8217;t have to mess with it. The write complete waits event is prevalent in versions prior to 8i.</p>
<p>Prior to Oracle 8i</p>
<p><a title="view source" href="http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write#viewSource">view source</a></p>
<p><a href=""></a></p>
<p><a title="print" href="http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write#printSource">print</a><a title="?" href="http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write#about">?</a></p>
<p><strong>1.select</strong> <strong>*</strong> <strong>from</strong> <strong>x$kvii where</strong> <strong>kviitag =</strong> <strong>&#8216;kcbswc&#8217;;</strong></p>
<p>Oracle 8i and higher</p>
<p><a title="view source" href="http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write#viewSource">view source</a></p>
<p><a href=""></a></p>
<p><a title="print" href="http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write#printSource">print</a><a title="?" href="http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write#about">?</a></p>
<p><strong>1.select</strong> <strong>*</strong> <strong>from</strong> <strong>x$kvii where</strong> <strong>kviitag in</strong> <strong>(&#8216;kcbswc&#8217;,'kcbscw&#8217;);</strong></p>
<p>When the DB_BLOCK_MAX_DIRTY_TARGET parameter is set too low, it can also cause excessive waits on the db file parallel write and write complete waits events. This parameter is used to influence the amount of time it takes to perform instance recovery. When the number of dirty buffers exceeds the parameter&#8217;s value, DBWR will write the dirty buffers to disk. This is known as incremental checkpoint. A smaller value provides shorter instance recovery time but it may cause the DBWR process to become hyperactive, especially in an active database where a large number of buffers are being modified. This in turn may cause excessive write complete waits and a longer db file parallel write time. This parameter is hidden in 9i and DBAs should not have to be concerned with it. <strong>Diagnosis</strong></p>
<p>For system-level diagnosis, query the V$SYSTEM_EVENT view to determine if the AVERAGE_WAIT is an issue.</p>
<p><a title="view source" href="http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write#viewSource">view source</a></p>
<p><a href=""></a></p>
<p><a title="print" href="http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write#printSource">print</a><a title="?" href="http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write#about">?</a></p>
<p><strong>1.select</strong> <strong>*</strong> <strong>from</strong> <strong>v$system_event where</strong> <strong>event =</strong> <strong>&#8216;db file parallel write&#8217;;</strong></p>
<p>While at the V$SYSTEM_EVENT, look also for the companion events.</p>
<p><a title="view source" href="http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write#viewSource">view source</a></p>
<p><a href=""></a></p>
<p><a title="print" href="http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write#printSource">print</a><a title="?" href="http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write#about">?</a></p>
<p><strong>1.select</strong> <strong>*</strong> <strong>from</strong> <strong>v$system_event </strong></p>
<p><strong>2.where</strong>  <strong>event in</strong> <strong>(&#8216;write complete waits&#8217;, &#8216;free buffer waits&#8217;);</strong></p>
<p>This event occurs in the DBWR. It indicates that the DBWR is performing a parallel write to files and blocks. When the last I/O has gone to disk, the wait ends. <strong>Wait Time:</strong></p>
<p>Wait until all of the I/Os are completed.</p>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="center"><strong>Parameter </strong></p>
</td>
<td>
<p align="center"><strong>Description </strong></p>
</td>
</tr>
<tr>
<td>requests</td>
<td>This indicates the total number of I/O requests, which will be the same as blocks.</td>
</tr>
<tr>
<td>interrupt</td>
<td> </td>
</tr>
<tr>
<td>timeout</td>
<td>This indicates the timeout value in centiseconds to wait for the IO completion.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><strong>Streams AQ: qmn coordinator waiting for slave to start:</strong></p>
<p>&nbsp;</p>
<p>When someone asks you to take a quick look into database performance and for whatever reason you can’t run your usual scripts or performance tools on there, ), then what query would you run first?<br />
Yeah sometimes I’ve been not allowed to run custom scripts nor even touch the keyboard due security policies in effect.</p>
<p>Whenever you’re in such situation you want to be the command both short and effective for showing the database state.</p>
<p>The simplest query for determining database state performance wise would be this:</p>
<p>SQL&gt; <strong>select event, state, count(*) from v$session_wait group by event, state order by 3 desc;</strong></p>
<p>&nbsp;</p>
<p>EVENT                                                            STATE                 COUNT(*)</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;&#8212;&#8212;-</p>
<p>rdbms ipc message                                                WAITING                      9</p>
<p>SQL*Net message from client                                      WAITING                      8</p>
<p>log file sync                                                    WAITING                      6</p>
<p>gcs remote message                                               WAITING                      2</p>
<p>PL/SQL lock timer                                                WAITING                      2</p>
<p>PL/SQL lock timer                                                WAITED KNOWN TIME            2</p>
<p>Streams AQ: qmn coordinator idle wait                            WAITING                      1</p>
<p>smon timer                                                       WAITING                      1</p>
<p>log file parallel write                                          WAITING                      1</p>
<p>ges remote message                                               WAITING                      1</p>
<p>SQL*Net message to client                                        WAITED SHORT TIME            1</p>
<p>DIAG idle wait                                                   WAITING                      1</p>
<p>pmon timer                                                       WAITING                      1</p>
<p>db file sequential read                                          WAITING                      1</p>
<p>Streams AQ: waiting for messages in the queue                    WAITING                      1</p>
<p>rdbms ipc message                                                WAITED KNOWN TIME            1</p>
<p>jobq slave wait                                                  WAITING                      1</p>
<p>Streams AQ: qmn slave idle wait                                  WAITING                      1</p>
<p>Streams AQ: waiting for time management or cleanup tasks         WAITING                      1</p>
<p>&nbsp;</p>
<p>19 rows selected.</p>
<p>&nbsp;</p>
<p>It uses the Oracle wait interface to report what all database sessions are currently doing wait/CPU usage wise. Whenever there’s a systemic issue (like extremely slow log file writes) this query will give good hint towards the cause of problem. Of course just running couple of queries against wait interface doesn’t give you the full picture (as these kinds of database wide “healthchecks” can be misleading as we should be really measuring end user response time breakdown at session level and asking questions like what throughput/response time do you normally get) but nevertheless, if you want to see an instance sessions state overview, this is the simplest query I know.</p>
<p>Interpreting this query output should be combined with reading some OS performance tool output (like vmstat or perfmon), in order to determine whether the problem is induced by CPU overload. For example, if someone is running a parallel backup compression job on the server which is eating all CPU time, some of these waits may be just a side-effect of CPU overload).</p>
<p>Below is a cosmetically enhanced version of this command, as one thing I decode the “WAITED FOR xyz TIME” wait states to “WORKING” and “On CPU / runqueue” as event name as otherwise it’s easy to miss by accident that some sessions are not actually waiting on previous event anymore:</p>
<p>SQL&gt; select</p>
<p>  2     count(*),</p>
<p>  3     CASE WHEN state != &#8216;WAITING&#8217; THEN &#8216;WORKING&#8217;</p>
<p>  4          ELSE &#8216;WAITING&#8217;</p>
<p>  5     END AS state,</p>
<p>  6     CASE WHEN state != &#8216;WAITING&#8217; THEN &#8216;On CPU / runqueue&#8217;</p>
<p>  7          ELSE event</p>
<p>  8     END AS sw_event</p>
<p>  9  FROM</p>
<p> 10     v$session_wait</p>
<p> 11  GROUP BY</p>
<p> 12     CASE WHEN state != &#8216;WAITING&#8217; THEN &#8216;WORKING&#8217;</p>
<p> 13          ELSE &#8216;WAITING&#8217;</p>
<p> 14     END,</p>
<p> 15     CASE WHEN state != &#8216;WAITING&#8217; THEN &#8216;On CPU / runqueue&#8217;</p>
<p> 16          ELSE event</p>
<p> 17     END</p>
<p> 18  ORDER BY</p>
<p> 19     1 DESC, 2 DESC</p>
<p> 20  /</p>
<p>&nbsp;</p>
<p>  COUNT(*) STATE   EVENT</p>
<p>&#8212;&#8212;&#8212;- &#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>        11 WAITING log file sync</p>
<p>         9 WAITING rdbms ipc message</p>
<p>         4 WAITING SQL*Net message from client</p>
<p>         3 WAITING PL/SQL lock timer</p>
<p>         2 WORKING On CPU / runqueue</p>
<p>         2 WAITING gcs remote message</p>
<p>         1 WAITING ges remote message</p>
<p>         1 WAITING pmon timer</p>
<p>         1 WAITING smon timer</p>
<p>         1 WAITING jobq slave wait</p>
<p>         1 WAITING Streams AQ: waiting for messages in the</p>
<p>         1 WAITING DIAG idle wait</p>
<p>         1 WAITING Streams AQ: qmn slave idle wait</p>
<p>         1 WAITING Streams AQ: waiting for time management</p>
<p>         1 WAITING db file sequential read</p>
<p>         1 WAITING log file parallel write</p>
<p>         1 WAITING Streams AQ: qmn coordinator idle wait</p>
<p>&nbsp;</p>
<p>17 rows selected.</p>
<p>&nbsp;</p>
<p>SQL&gt;</p>
<p>&nbsp;</p>
<p>Also, sometimes you might want to exclude the background processes and idle sessions from the picture:</p>
<p>SQL&gt; select</p>
<p>  2     count(*),</p>
<p>  3     CASE WHEN state != &#8216;WAITING&#8217; THEN &#8216;WORKING&#8217;</p>
<p>  4          ELSE &#8216;WAITING&#8217;</p>
<p>  5     END AS state,</p>
<p>  6     CASE WHEN state != &#8216;WAITING&#8217; THEN &#8216;On CPU / runqueue&#8217;</p>
<p>  7          ELSE event</p>
<p>  8     END AS sw_event</p>
<p>  9  FROM</p>
<p> 10     v$session</p>
<p> 11  WHERE</p>
<p><strong> 12      type = &#8216;USER&#8217;</strong></p>
<p><strong> 13  AND status = &#8216;ACTIVE&#8217;</strong></p>
<p> 14  GROUP BY</p>
<p> 15     CASE WHEN state != &#8216;WAITING&#8217; THEN &#8216;WORKING&#8217;</p>
<p> 16          ELSE &#8216;WAITING&#8217;</p>
<p> 17     END,</p>
<p> 18     CASE WHEN state != &#8216;WAITING&#8217; THEN &#8216;On CPU / runqueue&#8217;</p>
<p> 19          ELSE event</p>
<p> 20     END</p>
<p> 21  ORDER BY</p>
<p> 22     1 DESC, 2 DESC</p>
<p> 23  /</p>
<p>&nbsp;</p>
<p>  COUNT(*) STATE   EVENT</p>
<p>&#8212;&#8212;&#8212;- &#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>         6 WAITING PL/SQL lock timer</p>
<p>         4 WORKING On CPU / runqueue</p>
<p>         3 WAITING db file sequential read</p>
<p>         1 WAITING read by other session</p>
<p>         1 WAITING Streams AQ: waiting for messages in the</p>
<p>         1 WAITING jobq slave wait</p>
<p>&nbsp;</p>
<p>6 rows selected.</p>
<p>&nbsp;</p>
<p>By the way, the above scripts report quite similar data what ASH is actually using (especially the instance performance graph which shows you the instance wait summary). ASH nicely puts the CPU count of server into the graph as well (that you would be able to put the number of “On CPU” sessions into perspective), so another useful command to run after this script is “show parameter cpu_count” or better yet, check at OS level to be sure <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Note that you can use similar technique for easily viewing the instance activity from other perspectives/dimensions, like which SQL is being executed:</p>
<p>SQL&gt; select sql_hash_value, count(*) from v$session</p>
<p>  2  where status = &#8216;ACTIVE&#8217; group by sql_hash_value order by 2 desc;</p>
<p>&nbsp;</p>
<p>SQL_HASH_VALUE   COUNT(*)</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;-</p>
<p>             0         20</p>
<p><strong>     966758382          8</strong></p>
<p>    2346103937          2</p>
<p>    3393152264          1</p>
<p>    3349907142          1</p>
<p>    2863564559          1</p>
<p>    4030344732          1</p>
<p>    1631089791          1</p>
<p>&nbsp;</p>
<p>8 rows selected.</p>
<p>&nbsp;</p>
<p>SQL&gt; select sql_text,users_executing from v$sql where hash_value = 966758382;</p>
<p>&nbsp;</p>
<p>SQL_TEXT                                                     USERS_EXECUTING</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;</p>
<p>BEGIN :1 := orderentry.neworder(:2,:3,:4); END;                           10</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Resmgr:cpu quantum:</strong></p>
<p>The session is waiting to be allocated a quantum of cpu. This event occurs when the resource manager is enabled and is throttling CPU consumption. To reduce the occurrence of this wait event, increase the CPU allocation for the sessions&#8217;s current consumer group.</p>
<p>Wait Time: The time the session waited to acquire a CPU quantum</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td valign="bottom"><strong>Parameter</strong></td>
<td valign="bottom"><strong>Description</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top"><em>location</em></td>
<td valign="top">Location of the wait</td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sbelagam.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sbelagam.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sbelagam.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sbelagam.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sbelagam.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sbelagam.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sbelagam.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sbelagam.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sbelagam.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sbelagam.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sbelagam.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sbelagam.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sbelagam.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sbelagam.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sbelagam.wordpress.com&amp;blog=14325917&amp;post=44&amp;subd=sbelagam&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sbelagam.wordpress.com/2011/09/26/wait-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb19275a9c3de65e45e6737bcdf2bfd7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbelagam</media:title>
		</media:content>
	</item>
		<item>
		<title>Monitoring DB Performance and trend</title>
		<link>http://sbelagam.wordpress.com/2011/07/18/monitoring-db-performance-and-trend/</link>
		<comments>http://sbelagam.wordpress.com/2011/07/18/monitoring-db-performance-and-trend/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 14:42:42 +0000</pubDate>
		<dc:creator>Sunil Belagam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sbelagam.wordpress.com/?p=25</guid>
		<description><![CDATA[Monitoring the DB performance round the clock is always becoming a prim challenge for a DBA with the limited tools available. Only tool I can see which can make our job easy is oracle enterprise manager grid with very easy &#8230; <a href="http://sbelagam.wordpress.com/2011/07/18/monitoring-db-performance-and-trend/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sbelagam.wordpress.com&amp;blog=14325917&amp;post=25&amp;subd=sbelagam&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Monitoring the DB performance round the clock is always becoming a prim challenge for a DBA with the limited tools available. Only tool I can see which can make our job easy is oracle enterprise manager grid with very easy to read diagramed representation.</p>
<p><a href="http://sbelagam.files.wordpress.com/2011/07/1213213.png"><img class="alignnone size-medium wp-image-26" title="1213213" src="http://sbelagam.files.wordpress.com/2011/07/1213213.png?w=300&#038;h=108" alt="" width="300" height="108" /></a></p>
<p>With above diagram from enterprise manage we can check the high load period or problematic time and can check the Database in deep for the particular time and can work on identifying the problem.<br />
But all above comforts you will get when you have enterprise manager available and number of databases you have is very less so that you can go to each and every database and monitor the performance to address this issue here I come with.<br />
Oracle AWR report is mainly driven based on time statistics which is nothing but DB_time. DB_Time is based on all wait events in a DB. So if we can monitor the DB time for the period of time we can easily identify the peak and bottle neck time of the database.<br />
To archive the this below are the query which is helpful to get the DB_TIME for certain period(in the query have filtered for monitoring time for last 1 week but it all depends on your AWR retention period)<br />
set feedback off<br />
set pagesize 2000<br />
set linesize 200<br />
set verify off echo off trimspool on</p>
<p>col snap_id format A8<br />
col begin_interval_time_N format A30 trunc<br />
col end_interval_time_N format A30 trunc<br />
col HOST_NAME format A15 trunc<br />
col INSTANCE_NUMBER format 9 heading &#8220;I&#8221;<br />
col begin_interval_time_N noprint<br />
col end_interval_time_N noprint<br />
select<br />
A.SNAP_ID<br />
, A.INSTANCE_NUMBER<br />
, C.HOST_NAME<br />
, MIN(A.begin_interval_time) OVER (partition by A.dbid, A.snap_id) AS begin_interval_time_N<br />
, MIN(A.end_interval_time) OVER (partition by A.dbid, A.snap_id) AS end_interval_time_N<br />
, (B. VALUE &#8211; LAG(B.VALUE,1,0) OVER (ORDER BY A.SNAP_ID))/1000000/60 as DB_TIME<br />
from dba_hist_snapshot A , DBA_HIST_SYS_TIME_MODEL B,dba_hist_database_instance C<br />
where A.SNAP_ID=B.SNAP_ID<br />
and A.DBID=B.DBID<br />
And A.INSTANCE_NUMBER=B.INSTANCE_NUMBER<br />
and B.STAT_NAME Like &#8216;DB time&#8217;<br />
and A.DBID=C.DBID<br />
and A.INSTANCE_NUMBER=C.INSTANCE_NUMBER<br />
and A.startup_time = C.startup_time<br />
and A.begin_interval_time &gt;= trunc(sysdate) &#8211; 7 and A.begin_interval_time &lt;= trunc(sysdate) + 20/(26*60)</p>
<p>In Mentioned query we are using dba_hist_snapshot , DBA_HIST_SYS_TIME_MODEL, dba_hist_database_instance views to get the DB_TIME along with LAG function to calculate DB time for that sanp interval.<br />
Once we have this output with us we can use some linux based graph plotting tools to get the nice graph as below and this job can be automated by using cron job.<br />
<a href="http://sbelagam.files.wordpress.com/2011/07/db_time_1.png"><img class="alignnone size-medium wp-image-27" title="db_time_1" src="http://sbelagam.files.wordpress.com/2011/07/db_time_1.png?w=300&#038;h=187" alt="" width="300" height="187" /></a></p>
<p>I have used Ploticaus tool to plot graph in linux, you can use your own way to plot the graph to get the best of it.</p>
<p>http://ploticus.sourceforge.net/doc/welcome.html</p>
<p>Apart from this we can also use excel to get the similar output by using ODBC drivers.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sbelagam.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sbelagam.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sbelagam.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sbelagam.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sbelagam.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sbelagam.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sbelagam.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sbelagam.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sbelagam.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sbelagam.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sbelagam.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sbelagam.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sbelagam.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sbelagam.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sbelagam.wordpress.com&amp;blog=14325917&amp;post=25&amp;subd=sbelagam&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sbelagam.wordpress.com/2011/07/18/monitoring-db-performance-and-trend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb19275a9c3de65e45e6737bcdf2bfd7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbelagam</media:title>
		</media:content>

		<media:content url="http://sbelagam.files.wordpress.com/2011/07/1213213.png?w=300" medium="image">
			<media:title type="html">1213213</media:title>
		</media:content>

		<media:content url="http://sbelagam.files.wordpress.com/2011/07/db_time_1.png?w=300" medium="image">
			<media:title type="html">db_time_1</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Advisor in Oracle 10g</title>
		<link>http://sbelagam.wordpress.com/2010/07/26/sql-advisor-in-oracle-10g/</link>
		<comments>http://sbelagam.wordpress.com/2010/07/26/sql-advisor-in-oracle-10g/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 09:15:01 +0000</pubDate>
		<dc:creator>Sunil Belagam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sbelagam.wordpress.com/?p=15</guid>
		<description><![CDATA[  Another great feature of Oracle 10G that allow you to tune SQL. Now you don&#8217;t need to tune SQL statement manually. This new feature does it for you. SQL Tuning Advisor using DBMS_SQLTUNE package and very simple to use. &#8230; <a href="http://sbelagam.wordpress.com/2010/07/26/sql-advisor-in-oracle-10g/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sbelagam.wordpress.com&amp;blog=14325917&amp;post=15&amp;subd=sbelagam&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> </p>
<p>Another great feature of Oracle 10G that allow you to tune SQL. Now you don&#8217;t need to tune SQL statement manually. This new feature does it for you.</p>
<p>SQL Tuning Advisor using DBMS_SQLTUNE package and very simple to use.</p>
<p>The example below shows how to use SQL advisor.<br />
1. Grant following access to the user that is going to run this new tool. In the example below SCOTT is the owner of the schema.</p>
<p> GRANT ADVISOR TO SCOTT;<br />
GRANT SELECT_CATALOG_ROLE TO SCOTT;<br />
GRANT EXECUTE ON DBMS_SQLTUNE TO SCOTT;</p>
<p>2. Create the tuning task<br />
 </p>
<p>DECLARE<br />
task_name_var VARCHAR2(30);<br />
sqltext_var CLOB;<br />
BEGIN<br />
sqltext_var := &#8216;SELECT * from EMP where empno = 1200&#8242;;<br />
task_name_var := DBMS_SQLTUNE.CREATE_TUNING_TASK(<br />
sql_text =&gt; sqltext_var,<br />
user_name =&gt; &#8216;SCOTT&#8217;,<br />
scope =&gt; &#8216;COMPREHENSIVE&#8217;,<br />
time_limit =&gt; 60,<br />
task_name =&gt; &#8216;sql_tuning_task_test1&#8242;,<br />
description =&gt; &#8216;This is a test tuning task on EMP table&#8217;);<br />
END;<br />
/</p>
<p>Some time you may have queries that might take longer than the time that you have specified in the &#8220;time_limit&#8221; parameter. If this is the case then remove this parameter.</p>
<p>NOTE: You can not create more than one task with the same name. If this is the case then drop the existing task or use a different name.</p>
<p>2.1 To view the existing task for the user run the following statement.<br />
 </p>
<p>select task_name from dba_advisor_log where owner = &#8216;SCOTT&#8217;;</p>
<p>3. Execute the tuning task<br />
 </p>
<p>Execute dbms_sqltune.Execute_tuning_task (task_name =&gt; &#8216;sql_tuning_task_test1&#8242;);</p>
<p>3.1 You can check the status of the task using following query.</p>
<p>select status from dba_advisor_log where task_name=&#8217;sql_tuning_task_test1&#8242;;</p>
<p>4. Now view the Recommendation<br />
 </p>
<p>set linesize 100<br />
set long 1000<br />
set longchunksize 1000</p>
<p>SQL&gt; select dbms_sqltune.report_tuning_task(&#8216;sql_tuning_task_test1&#8242;) from dual;</p>
<p>DBMS_SQLTUNE.REPORT_TUNING_TASK(&#8216;SQL_TUNING_TASK_TEST1&#8242;)<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 />
GENERAL INFORMATION SECTION<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;-<br />
Tuning Task Name : sql_tuning_task_test1<br />
Scope : COMPREHENSIVE<br />
Time Limit(seconds): 60<br />
Completion Status : COMPLETED<br />
Started at : 06/22/2006 15:33:13<br />
Completed at : 06/22/2006 15:33:14</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;-<br />
SQL ID : ad1437c24nqpn<br />
SQL Text: SELECT * from EMP where empno = 1200</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;-<br />
FINDINGS SECTION (1 finding)<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;-</p>
<p>1- Statistics Finding<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Table &#8220;SCOTT&#8221;.&#8221;EMP&#8221; was not analyzed.</p>
<p>Recommendation<br />
&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Consider collecting optimizer statistics for this table.<br />
execute dbms_stats.gather_table_stats(ownname =&gt; &#8216;SCOTT&#8217;, tabname =&gt;<br />
&#8216;EMP&#8217;, estimate_percent =&gt; DBMS_STATS.AUTO_SAMPLE_SIZE,<br />
Based on this information, you can decide what actions are necessary to tune the SQL.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sbelagam.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sbelagam.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sbelagam.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sbelagam.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sbelagam.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sbelagam.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sbelagam.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sbelagam.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sbelagam.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sbelagam.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sbelagam.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sbelagam.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sbelagam.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sbelagam.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sbelagam.wordpress.com&amp;blog=14325917&amp;post=15&amp;subd=sbelagam&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sbelagam.wordpress.com/2010/07/26/sql-advisor-in-oracle-10g/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb19275a9c3de65e45e6737bcdf2bfd7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbelagam</media:title>
		</media:content>
	</item>
		<item>
		<title>AMS Metadata</title>
		<link>http://sbelagam.wordpress.com/2010/07/01/ams-metadata/</link>
		<comments>http://sbelagam.wordpress.com/2010/07/01/ams-metadata/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 15:32:30 +0000</pubDate>
		<dc:creator>Sunil Belagam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sbelagam.wordpress.com/?p=12</guid>
		<description><![CDATA[AMS Metadata
After lots of research on web to find the key definitions I found really difficult to find right place to get those. Finally one of my senior colleague (I can also say my guru) helped me to find these definitions. Just uploading those definitions for those who looking like me.
Metadata is stored in first 256 files in ASM disk group
Space is initially allocated when disk group is created
Can be subsequently extended
Metadata allocation units are divided into blocks
Each block is 4096 bytes
Block size specifed using _asm_blksize 
Metadata files include
File# 	Description 
0 	Metadata Header 
1 	File Directory 
2 	Disk Directory 
3 	Active Change Directory 
4 	Continuing Operations Directory 
5 	Template Directory 
6 	Alias Directory 
9 	Attribute directory (optional) 
12 	Staleness registry (optional) 
 

 	Allocation Table --  Each ASM has an Allocation Table to track free and allocated space within the disk. The allocation table begins immediately after the disk header. The table contains Allocation Table Entry (ATE) for every allocation unit in the disk.  ATE’s are grouped into allocation table blocks. (ATB)
 	Free Space Table( FST)-- The FST indicated which ATBs might contain free allocation units. ASM consults a disk’s FST when the disk is selected for allocation.
 	Partnership Status Table ( PST)  . The PST tracks disk group membership and the disk partnerships. ASM consults the PST to determine whether a sufficient disks is online to mount the diskgroup.
 	File Directory – It contains all of the metadata relevant to ASM files. This directory contains every ASM file and is indexed by file number.
 	Disk Directory -- It contains information about all the disks in the disk group. Disk Directory is more detailed than PST. Each disk in the diskgroup has an entry in the Disk Directory indexed by disk number. 
 	Active Change Directory -- The ACD is the log that allows ASM to make atomic changes to multiple data structures. It is similar to the redo logs used by the oracle rdbms.
 	Continuing Operations Directory (COD) -- The COD tracks long running operations such as file creation and rebalance. COD entries allow ASM to recover from failures during long running operations.
 	Template Directory -- It contains information about all  of the file templates for the disk group. 
 	Alias Directory  - The alias directory contains all alias metadata as well as entreid for each system alias, system directory, user directory and user alias.

 <a href="http://sbelagam.wordpress.com/2010/07/01/ams-metadata/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sbelagam.wordpress.com&amp;blog=14325917&amp;post=12&amp;subd=sbelagam&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong> </strong></p>
<p>After lots of research on web to find the key definitions I found really difficult to find right place to get those. Finally one of my my guru could able to find these difinitions some where. Just uploading those definitions for those who looking like me.</p>
<p>Metadata is stored in first 256 files in ASM disk group</p>
<p>Space is initially allocated when disk group is created</p>
<p>Can be subsequently extended</p>
<p>Metadata allocation units are divided into blocks</p>
<p>Each block is 4096 bytes</p>
<p>Block size specifed using _asm_blksize</p>
<p>Metadata files include</p>
<table border="0" cellspacing="0" cellpadding="0" width="585">
<tbody>
<tr>
<td width="95" valign="top"><strong>File#</strong><strong> </strong></td>
<td width="491" valign="top"><strong>Description</strong><strong> </strong></td>
</tr>
<tr>
<td width="95" valign="top"><strong>0</strong><strong> </strong></td>
<td width="491" valign="top"><strong>Metadata Header</strong><strong> </strong></td>
</tr>
<tr>
<td width="95" valign="top"><strong>1</strong><strong> </strong></td>
<td width="491" valign="top"><strong>File Directory</strong><strong> </strong></td>
</tr>
<tr>
<td width="95" valign="top"><strong>2</strong><strong> </strong></td>
<td width="491" valign="top"><strong>Disk Directory</strong><strong> </strong></td>
</tr>
<tr>
<td width="95" valign="top"><strong>3</strong><strong> </strong></td>
<td width="491" valign="top"><strong>Active Change Directory</strong><strong> </strong></td>
</tr>
<tr>
<td width="95" valign="top"><strong>4</strong><strong> </strong></td>
<td width="491" valign="top"><strong>Continuing Operations Directory</strong><strong> </strong></td>
</tr>
<tr>
<td width="95" valign="top"><strong>5</strong><strong> </strong></td>
<td width="491" valign="top"><strong>Template Directory</strong><strong> </strong></td>
</tr>
<tr>
<td width="95" valign="top"><strong>6</strong><strong> </strong></td>
<td width="491" valign="top"><strong>Alias Directory</strong><strong> </strong></td>
</tr>
<tr>
<td width="95" valign="top"><strong>9</strong><strong> </strong></td>
<td width="491" valign="top"><strong>Attribute directory (optional)</strong><strong> </strong></td>
</tr>
<tr>
<td width="95" valign="top"><strong>12</strong><strong> </strong></td>
<td width="491" valign="top"><strong>Staleness registry (optional)</strong><strong> </strong></td>
</tr>
</tbody>
</table>
<p> </p>
<p>      <strong>Allocation Table</strong> &#8211;  Each ASM has an Allocation Table to track free and allocated space within the disk. The allocation table begins immediately after the disk header. The table contains Allocation Table Entry (ATE) for every allocation unit in the disk.  ATE’s are grouped into allocation table blocks. (ATB)</p>
<p>      <strong>Free Space Table( FST)&#8211; </strong>The FST indicated which ATBs might contain free allocation units. ASM consults a disk’s FST when the disk is selected for allocation.</p>
<p>      <strong>Partnership Status Table ( PST)</strong>  . The PST tracks disk group membership and the disk partnerships. ASM consults the PST to determine whether a sufficient disks is online to mount the diskgroup.</p>
<p>      <strong>File Directory</strong> – It contains all of the metadata relevant to ASM files. This directory contains every ASM file and is indexed by file number.</p>
<p>      <strong>Disk Directory &#8212; </strong>It contains information about all the disks in the disk group. Disk Directory is more detailed than PST. Each disk in the diskgroup has an entry in the Disk Directory indexed by disk number.</p>
<p>      <strong>Active Change Directory &#8212; </strong><em>The ACD is the log that allows ASM to make atomic changes to multiple data structures. It is similar to the redo logs used by the oracle rdbms.</em></p>
<p>      <strong>Continuing Operations Directory (COD) &#8211;</strong> <em>The COD tracks long running operations such as file creation and rebalance. COD entries allow ASM to recover from failures during long running operations.</em></p>
<p>      <strong>Template Directory &#8212; </strong>It contains information about all  of the file templates for the disk group.</p>
<p>      <strong>Alias Directory  -</strong> The alias directory contains all alias metadata as well as entreid for each system alias, system directory, user directory and user alias.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sbelagam.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sbelagam.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sbelagam.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sbelagam.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sbelagam.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sbelagam.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sbelagam.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sbelagam.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sbelagam.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sbelagam.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sbelagam.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sbelagam.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sbelagam.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sbelagam.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sbelagam.wordpress.com&amp;blog=14325917&amp;post=12&amp;subd=sbelagam&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sbelagam.wordpress.com/2010/07/01/ams-metadata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb19275a9c3de65e45e6737bcdf2bfd7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbelagam</media:title>
		</media:content>
	</item>
		<item>
		<title>How to adjust the high watermark in ORACLE 10g – ALTER TABLE SHRINK</title>
		<link>http://sbelagam.wordpress.com/2010/06/22/how-to-adjust-the-high-watermark-in-oracle-10g-%e2%80%93-alter-table-shrink/</link>
		<comments>http://sbelagam.wordpress.com/2010/06/22/how-to-adjust-the-high-watermark-in-oracle-10g-%e2%80%93-alter-table-shrink/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 08:46:04 +0000</pubDate>
		<dc:creator>Sunil Belagam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sbelagam.wordpress.com/?p=4</guid>
		<description><![CDATA[Recently lots of research on full table scans and performance of oracle PL-Sql code which pushed me to write my first blog&#8230;&#8230; It’s just all about adjusting High Watermark and the Oracle 10gR1 New Feature SEGMENT SHRINKING. The High Watermark &#8230; <a href="http://sbelagam.wordpress.com/2010/06/22/how-to-adjust-the-high-watermark-in-oracle-10g-%e2%80%93-alter-table-shrink/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sbelagam.wordpress.com&amp;blog=14325917&amp;post=4&amp;subd=sbelagam&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently lots of research on full table scans and performance of oracle PL-Sql code which pushed me to write my first blog&#8230;&#8230; It’s just all about adjusting High Watermark and the Oracle 10gR1 New Feature SEGMENT SHRINKING.</p>
<p>The High Watermark is the maximum fill-grade a table has ever reached. Above the high watermark are only empty blocks. These blocks can be formatted or unformatted.</p>
<p>First let’s have a look at the question when space is allocated</p>
<p>- when you create a table at least one extent (contiguous blocks) is allocated to the table<br />
- if you have specified MINEXTENTS the number of MINEXTENTS extents will be allocated immediately to the table<br />
- if you have not specified MINEXTENTS then exactly one extent will be allocated (we will look at extent sizes later in another post).</p>
<p>Immediately after creation of the segment (table) the high watermark will be at the first block of the first extent as long as there are no inserts made.</p>
<p>When you insert rows into the table the high watermark will be bumped up step by step.<br />
This is done by the server process which makes the inserts.</p>
<p>Now let us take a look at when space is released again from a segment like a table or index:</p>
<p>Let’s assume that we have filled a table with 100’0000 rows. And let’s assume that we deleted 50’000 rows afterwards.  In this case the high watermark will have reached the level of 100’000 and will have stayed there. This means that we have empty blocks below the high watermark now.  Oracle has a good reason this: it might occur that you delete rows and immediately this you insert rows into the same table. In this case it is good that the space was not released with the deletes, because it had to be get reallocate again for the following inserts, which would mean permanent changes to the data dictionary (=&gt; dba_free_space, dba_extents, dba_segements …) .<br />
Furthermore the physical addresses of the deleted row get recycled by new rows.</p>
<p>These empty blocks below the high watermark can get annoying in a number of situations because they are not used by DIRECT LOADs and DIRECT PATH LOADs:</p>
<p>1. seriell direct load:<br />
<strong><em>INSERT /*+ APPEND */ </em></strong><br />
<strong><em>INTO hr.employees </em></strong><br />
<strong><em>NOLOGGING</em></strong><br />
<strong><em>SELECT * </em></strong><br />
<strong><em>FROM oe.emps;</em></strong></p>
<p>2. parallel direct load:<br />
<strong><em>ALTER SESSION ENABLE PARALLEL DML;</em></strong><br />
<strong><em>INSERT /*+PARALLLEL(hr.employees,2)<br />
INTO hr.employees </em></strong><br />
<strong><em>NOLOGGING</em></strong><br />
<strong><em>SELECT * </em></strong><br />
<strong><em>FROM oe.emps;</em></strong></p>
<p>3. direct path loads:<br />
sqlldr hr/hr control=lcaselutz.ctl … direct=y (default is direct=n)</p>
<p>All the above actions case that the SGA is not used for the inserts but the PGA:<br />
there wil be temporary segements filled and dumped into newly formatted blocks above the high watermark.</p>
<p>So we might want to get high watermark down before we load data into the table in order to use the free empty blocks for the loading.</p>
<p>So how can we release unused space from a table?</p>
<p>There are a number of possible options which are already available before Oracle 10g:<br />
- What we always could do is export and import the segment. After an import the table will have only one extent. The rows will have new physical addresses and the high watermark will be adjusted.</p>
<p>With Oracle 9i another possibility was implemented:<br />
<em>ALTER TABLE emp MOVE TABLESPACE users;</em><br />
This statement will also cause that<br />
- the rows will have new physical addresses and the high watermark will be adjusted.<br />
<strong>But for this:</strong><br />
- we need a full (exclusive) table lock &#8211; the indexes will be left with the status unusable (because they contain the old rowids) and must be rebuilt.</p>
<p>Starting with ORACLE 10gR1 we can use a new feature for adjusting the high watermark,<br />
it is called segment shrinking and is only possible for segments which use ASSM, in other words, which are located in tablespaces which use Automatic Segment Space Management.<br />
In such a tablespace a table does not really have a High watermark!<br />
It uses two watermarks instead:<br />
- the High High Watermark referred to as HHWM, above which alle blocks ar unformatted.<br />
- the Low High Watermark referred to as LHWM below which all blocks are formatted.<br />
We now can have unformatted blocks in the middle of a segment!</p>
<p>ASSM was introduced in Oracle 9iR2 and it was made the default for tablespaces in Oracle 10gR2.  With the table shrinking feature we can get Oracle to move rows which are located in the middle or at the end of a segment further more down to the beginning of the segment and by<br />
this make the segment more compact.<br />
For this we must first allow ORACLE to change the ROWIDs of these rows by issuing <em><br />
ALTER TABLE emp ENABLE ROW MOVEMENT; <strong>(Even through oracle says row movement is online activity but all depending objects on this table will go invalid. It may cause your applications to behave abnormal.)</strong></em></p>
<p>ROWIDs are normally assigned to a row for the life time of the row at insert time.</p>
<p>After we have given Oracle the permission to change the ROWIDs<br />
we can now issue a shrink statement.<em><br />
ALTER TABLE emp </em>SHRINK SPACE;</p>
<p>This statement will proceed in two steps:<br />
- The first step makes the segment compact by moving rows further down to free blocks at the beginning of the segment.<br />
- The second step adjusts the high watermark. For this Oracle needs an exclusive table lock,<br />
but for a very short moment only.</p>
<p><strong><span style="text-decoration:underline;">Advantages of Table shrinking</span></strong><em><br />
</em>- will adjust the high watermark<br />
- can be done online<br />
- will cause only rowlocks during the operation and just a very short full table lock at the end of the operation<br />
- indexes will be maintained and remain usable<br />
- can be made in one go<br />
- can be made in two steps</p>
<p><em></em></p>
<p><em>- ALTER TABLE emp </em>SHRINK SPACE; – only for the emp table<br />
<em>- ALTER TABLE emp </em>SHRINK SPACE CASCADE; – for all dependent objects as well</p>
<p>- <em>ALTER TABLE emp </em>SHRINK SPACE COMPACT; – only makes the first step (moves the rows)<br />
)</p>
<p>The following restrictions apply to table shrinking:</p>
<p>1.) It is only possible in tablespaces with ASSM.<br />
2.) You cannot shrink:<br />
         &#8211; UNDO segments<br />
         &#8211; temporary segments<br />
         &#8211; clustered tables<br />
         &#8211; tables with a column of data type LONG</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sbelagam.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sbelagam.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sbelagam.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sbelagam.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sbelagam.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sbelagam.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sbelagam.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sbelagam.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sbelagam.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sbelagam.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sbelagam.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sbelagam.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sbelagam.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sbelagam.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sbelagam.wordpress.com&amp;blog=14325917&amp;post=4&amp;subd=sbelagam&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sbelagam.wordpress.com/2010/06/22/how-to-adjust-the-high-watermark-in-oracle-10g-%e2%80%93-alter-table-shrink/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb19275a9c3de65e45e6737bcdf2bfd7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbelagam</media:title>
		</media:content>
	</item>
		<item>
		<title>Hello world!</title>
		<link>http://sbelagam.wordpress.com/2010/06/22/hello-world/</link>
		<comments>http://sbelagam.wordpress.com/2010/06/22/hello-world/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 06:53:44 +0000</pubDate>
		<dc:creator>Sunil Belagam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sbelagam.wordpress.com/?p=1</guid>
		<description><![CDATA[Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sbelagam.wordpress.com&amp;blog=14325917&amp;post=1&amp;subd=sbelagam&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Welcome to <a href="http://wordpress.com/">WordPress.com</a>. This is your first post. Edit or delete it and start blogging!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sbelagam.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sbelagam.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sbelagam.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sbelagam.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sbelagam.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sbelagam.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sbelagam.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sbelagam.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sbelagam.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sbelagam.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sbelagam.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sbelagam.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sbelagam.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sbelagam.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sbelagam.wordpress.com&amp;blog=14325917&amp;post=1&amp;subd=sbelagam&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sbelagam.wordpress.com/2010/06/22/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb19275a9c3de65e45e6737bcdf2bfd7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbelagam</media:title>
		</media:content>
	</item>
	</channel>
</rss>
