<?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"
	>

<channel>
	<title>Oracle Expert</title>
	<atom:link href="http://www.oracleexpert.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.oracleexpert.co.uk</link>
	<description>Hilda Davies, an Oracle Data Architect, based in London, UK.</description>
	<pubDate>Thu, 29 Mar 2012 11:02:54 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>How to spot duplicate datafiles</title>
		<link>http://www.oracleexpert.co.uk/2012/03/how-to-spot-duplicate-datafiles/</link>
		<comments>http://www.oracleexpert.co.uk/2012/03/how-to-spot-duplicate-datafiles/#comments</comments>
		<pubDate>Thu, 29 Mar 2012 10:53:01 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[datafiles]]></category>

		<category><![CDATA[duplicate]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=496</guid>
		<description><![CDATA[This does not happen very often, but could be catastrophic.
For example DBA would like to move datafiles to a new file system, from smaller file systems, not realising that there are duplicated file names under the different file systems, and when moved to a file system, one overwrites the other&#8230; 
 select *  from ( select  tablespace_name, [...]]]></description>
			<content:encoded><![CDATA[<p>This does not happen very often, but could be catastrophic.</p>
<p>For example DBA would like to move datafiles to a new file system, from smaller file systems, not realising that there are duplicated file names under the different file systems, and when moved to a file system, one overwrites the other&#8230; </p>
<p><span style="font-size: xx-small;"> <span style="font-family: Courier; font-size: x-small;">select * </span> f</span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">rom</span></span></span><span style="font-size: xx-small;"> </span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">( select </span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">tablespace_name</span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">,</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">fullpath</span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">,</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">filename</span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">,</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">count(</span></span></span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">filename</span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">)</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">over</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">(partition</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">by</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">filename</span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">)</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;">  </span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">freq </span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">from </span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">(</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">select</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">tablespace_name</span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">,</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">file_name</span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">fullpath</span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">,</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">substr(</span></span></span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">file_name</span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">,</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">instr(</span></span></span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">file_name</span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">,</span></span></span><span style="font-family: Courier; color: #ff0000; font-size: x-small;"><span style="font-family: Courier; color: #ff0000; font-size: x-small;"><span style="font-family: Courier; color: #ff0000; font-size: x-small;">&#8216;/&#8217;</span></span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">,-</span></span></span><span style="font-family: Courier; color: #800000; font-size: x-small;"><span style="font-family: Courier; color: #800000; font-size: x-small;"><span style="font-family: Courier; color: #800000; font-size: x-small;">1</span></span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">)+</span></span></span><span style="font-family: Courier; color: #800000; font-size: x-small;"><span style="font-family: Courier; color: #800000; font-size: x-small;"><span style="font-family: Courier; color: #800000; font-size: x-small;">1</span></span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">)</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;">  </span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">filename </span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">from</span></span></span><span style="font-size: xx-small;"> </span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">dba_data_files </span></span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">) ) </span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">where</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; font-size: x-small;"><span style="font-family: Courier; font-size: x-small;">freq</span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;"><span style="font-family: Courier; color: #0000ff; font-size: x-small;">&gt;</span></span></span><span style="font-family: Times New Roman; font-size: xx-small;"> </span><span style="font-family: Courier; color: #800000; font-size: x-small;"><span style="font-family: Courier; color: #800000; font-size: x-small;"><span style="font-family: Courier; color: #800000; font-size: x-small;">1</span></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/03/how-to-spot-duplicate-datafiles/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Reordering a sparse sequence</title>
		<link>http://www.oracleexpert.co.uk/2012/03/reordering-a-sparse-sequence/</link>
		<comments>http://www.oracleexpert.co.uk/2012/03/reordering-a-sparse-sequence/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 10:59:37 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[linenumber]]></category>

		<category><![CDATA[ordering]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=494</guid>
		<description><![CDATA[Let&#8217;s say we have a table with data as follows:
select * from xx order by a;
1
2
4
6
7
11
12
13
14
120
We to change the linenumber so it is sequential (and not sparse), simply do
select a, row_number() over (order by a) newlinenumber
from xx;
And this will return
        
A NEWLINENUMBER
1 1
2 2
4 3
6 4
7 5
11 6
12 7
13 8
14 9
120 10
]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say we have a table with data as follows:</p>
<p>select * from xx order by a;</p>
<p>1<br />
2<br />
4<br />
6<br />
7<br />
11<br />
12<br />
13<br />
14<br />
120<br />
We to change the linenumber so it is sequential (and not sparse), simply do</p>
<p>select a, row_number() over (order by a) newlinenumber<br />
from xx;</p>
<p>And this will return<br />
        </p>
<p>A NEWLINENUMBER<br />
1 1<br />
2 2<br />
4 3<br />
6 4<br />
7 5<br />
11 6<br />
12 7<br />
13 8<br />
14 9<br />
120 10</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/03/reordering-a-sparse-sequence/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Insert blank line every 3rd row</title>
		<link>http://www.oracleexpert.co.uk/2012/03/insert-blank-line-every-3rd-row/</link>
		<comments>http://www.oracleexpert.co.uk/2012/03/insert-blank-line-every-3rd-row/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 10:55:41 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[linenumber]]></category>

		<category><![CDATA[ordering]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=492</guid>
		<description><![CDATA[Let&#8217;s say we have a table with data as follows:
select * from xx order by a;
1
2
4
6
7
11
12
13
14
120
We need to present the data as follows (insert blank line every 2 lines).
1
2
&#60;blank line&#62;
4
6
&#60;blank line&#62;
7
11
&#60;blank line&#62;
12
13
&#60;blank line&#62;
14
120
To illustrate this, I will use a staging table yy
create table yy (linenumber number, a number);
The technique is to simply use mod function [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say we have a table with data as follows:</p>
<p>select * from xx order by a;</p>
<p>1<br />
2<br />
4<br />
6<br />
7<br />
11<br />
12<br />
13<br />
14<br />
120<br />
We need to present the data as follows (insert blank line every 2 lines).<br />
1<br />
2<br />
&lt;blank line&gt;<br />
4<br />
6<br />
&lt;blank line&gt;<br />
7<br />
11<br />
&lt;blank line&gt;<br />
12<br />
13<br />
&lt;blank line&gt;<br />
14<br />
120<br />
To illustrate this, I will use a staging table yy<br />
create table yy (linenumber number, a number);</p>
<p>The technique is to simply use mod function as follows:<br />
declare<br />
cursor cur_i is select rownum linenumber, a from xx order by a;<br />
v_mod2 number;<br />
v_count number :=1;<br />
begin<br />
for i in cur_i<br />
loop<br />
 select mod(i.linenumber,2) into v_mod2 from dual;<br />
 if v_mod2 = 0 then<br />
   insert into yy values (v_count, a);<br />
   v_count := v_count+1;<br />
   insert into yy values (v_count,null);<br />
   v_count := v_count+1;<br />
 else<br />
   insert into yy values (v_count, a);<br />
   v_count := v_count+1;<br />
 end if;<br />
end loop;<br />
commit;<br />
end;<br />
/<br />
 <br />
 <br />
And the result will be :</p>
<p>select * from yy;</p>
<p>1 1<br />
2 2<br />
3 null<br />
4 4<br />
5 6<br />
6 null<br />
7 7<br />
8 11<br />
9 null<br />
10 12<br />
11 13<br />
12 null<br />
13 14<br />
14 120<br />
15 null</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/03/insert-blank-line-every-3rd-row/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Convert rows into CSV</title>
		<link>http://www.oracleexpert.co.uk/2012/03/convert-rows-into-csv/</link>
		<comments>http://www.oracleexpert.co.uk/2012/03/convert-rows-into-csv/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 11:47:52 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[convert csv]]></category>

		<category><![CDATA[csv]]></category>

		<category><![CDATA[partition]]></category>

		<category><![CDATA[partitioning]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=488</guid>
		<description><![CDATA[In this example,  I am using sys_connect_by_path in order to create the comma delimited string.
Here I am trying to automate the creation of commands to merge subpartitions within a table.
The command output would look like this
alter table xxx merge subpartitions a,b,c,d,e,f into sp_xx;
declare
cursor cur_part is select distinct partition_name from user_tab_subpartitions where table_name=&#8217;ACCOUNT_POSTING&#8217;;
v_sql varchar2(255);
begin
  for i [...]]]></description>
			<content:encoded><![CDATA[<p>In this example,  I am using sys_connect_by_path in order to create the comma delimited string.</p>
<p>Here I am trying to automate the creation of commands to merge subpartitions within a table.</p>
<p>The command output would look like this</p>
<p>alter table xxx merge subpartitions a,b,c,d,e,f into sp_xx;</p>
<p>declare<br />
cursor cur_part is select distinct partition_name from user_tab_subpartitions where table_name=&#8217;ACCOUNT_POSTING&#8217;;<br />
v_sql varchar2(255);<br />
begin<br />
  for i in cur_part<br />
  loop<br />
   <br />
    select &#8216;alter table account_posting merge subpartitions &#8216;||substr(max(sys_connect_by_path(subpartition_name,&#8217;,')),2)||&#8217; into sp_&#8217;||partition_name||&#8217;;&#8217; xx into v_sql<br />
    from (<br />
    select rownum id, subpartition_name,partition_name<br />
    from user_tab_subpartitions where table_name=&#8217;ACCOUNT_POSTING&#8217; and partition_name=i.partition_name)<br />
    start with id=1 connect by prior id=id-1<br />
    group by partition_name;<br />
   <br />
    dbms_output.put_line(v_sql);</p>
<p>  end loop;<br />
end;<br />
/</p>
<p>Note that I learned the hard way that you can merge only 2 subpartitions at a time.</p>
<p>But still I will leave this note here, to illustrate the rows to csv conversion&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/03/convert-rows-into-csv/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Load XML/CLOB/BLOB using SQLLDR</title>
		<link>http://www.oracleexpert.co.uk/2012/02/load-xmlclobblob-using-sqlldr/</link>
		<comments>http://www.oracleexpert.co.uk/2012/02/load-xmlclobblob-using-sqlldr/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 17:09:23 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[sqlldr]]></category>

		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=484</guid>
		<description><![CDATA[Say our target table is called XML_REPOSITORY
create table xml_repository
(file_name varchar2(30),
 xml clob);
Create a control file like this
load data
infile *
append into table xml_repository
(
file_name char(30),
xml lobfile (file_name) terminated by eof
)
begindata
file1.xml
file2.xml
file3.xml
Then prepare your xml files as listed above. This can be images or word document, etc (obviously with corresponding BLOB)
Then as usual
sqlldr userid/password@db control=loadxml.ctl
]]></description>
			<content:encoded><![CDATA[<p>Say our target table is called XML_REPOSITORY</p>
<p>create table xml_repository<br />
(file_name varchar2(30),<br />
 xml clob);</p>
<p>Create a control file like this</p>
<p>load data<br />
infile *<br />
append into table xml_repository<br />
(<br />
file_name char(30),<br />
xml lobfile (file_name) terminated by eof<br />
)<br />
begindata<br />
file1.xml<br />
file2.xml<br />
file3.xml</p>
<p>Then prepare your xml files as listed above. This can be images or word document, etc (obviously with corresponding BLOB)</p>
<p>Then as usual</p>
<p>sqlldr <a href="mailto:userid/password@db">userid/password@db</a> control=loadxml.ctl</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/02/load-xmlclobblob-using-sqlldr/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Oracle Space Management - Segment Advisor</title>
		<link>http://www.oracleexpert.co.uk/2012/01/oracle-space-management-segment-advisor/</link>
		<comments>http://www.oracleexpert.co.uk/2012/01/oracle-space-management-segment-advisor/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 15:43:24 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Sandbox]]></category>

		<category><![CDATA[fragmentation]]></category>

		<category><![CDATA[segment advisor]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=435</guid>
		<description><![CDATA[Here is a very useful query to highlight which tables/indexes would benefit from a reorg/rebuild or a shrink
SELECT segment_name, segment_type, round(allocated_space/1024/1024,3) alloc_mb ,round(used_space/1024/1024,3) used_mb ,
round(reclaimable_space/1024/1024,3) reclaimable_mb, round(reclaimable_space/allocated_space*100,3) pct_wastage
FROM TABLE(dbms_space.asa_recommendations())
where segment_owner=&#8217;HILDA&#8217;
order by 6 desc
]]></description>
			<content:encoded><![CDATA[<p>Here is a very useful query to highlight which tables/indexes would benefit from a reorg/rebuild or a shrink</p>
<p>SELECT segment_name, segment_type, round(allocated_space/1024/1024,3) alloc_mb ,round(used_space/1024/1024,3) used_mb ,<br />
round(reclaimable_space/1024/1024,3) reclaimable_mb, round(reclaimable_space/allocated_space*100,3) pct_wastage<br />
FROM TABLE(dbms_space.asa_recommendations())<br />
where segment_owner=&#8217;HILDA&#8217;<br />
order by 6 desc</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/01/oracle-space-management-segment-advisor/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ash</title>
		<link>http://www.oracleexpert.co.uk/2012/01/ash/</link>
		<comments>http://www.oracleexpert.co.uk/2012/01/ash/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 09:42:25 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[Sandbox]]></category>

		<category><![CDATA[ash]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=430</guid>
		<description><![CDATA[Reminder for me on how useful ASH is
&#8211; find snapid where a particular sql occurs
select distinct snap_id from dba_hist_sqlbind where sql_id=&#8217;80bd6bb7n33tk&#8217;  
&#8211; find bind variable values for the specified sql
select * from dba_hist_sqlbind
where snap_id = 20637  and trunc(last_captured) >= &#8216;17-NOV-2011&#8242; and sql_id=&#8217;80bd6bb7n33tk&#8217;
order by sql_id, position
select snap_id, sample_time, session_id, session_serial#, sql_id, session_state, blocking_session, blocking_session_serial#, [...]]]></description>
			<content:encoded><![CDATA[<p>Reminder for me on how useful ASH is</p>
<p>&#8211; find snapid where a particular sql occurs<br />
select distinct snap_id from dba_hist_sqlbind where sql_id=&#8217;80bd6bb7n33tk&#8217;  </p>
<p>&#8211; find bind variable values for the specified sql<br />
select * from dba_hist_sqlbind<br />
where snap_id = 20637  and trunc(last_captured) >= &#8216;17-NOV-2011&#8242; and sql_id=&#8217;80bd6bb7n33tk&#8217;<br />
order by sql_id, position</p>
<p>select snap_id, sample_time, session_id, session_serial#, sql_id, session_state, blocking_session, blocking_session_serial#, blocking_session_status, event from dba_hist_active_sess_history<br />
where (session_id,session_serial#) in (select session_id,session_serial# from dba_hist_active_sess_history where sql_id=&#8217;0trpbjywfsdp6&#8242; and snap_id between 20637 and 20639)<br />
and snap_id between 20637 and 20639 order by snap_id, sample_time</p>
<p>4a2fkw1d4u01u &#8212; deletion profile that was blocked </p>
<p>select snap_id, sample_time, session_id, session_serial#, sql_id, session_state, blocking_session, blocking_session_serial#, blocking_session_status, event from dba_hist_active_sess_history<br />
where (session_id,session_serial#) in (select session_id,session_serial# from dba_hist_active_sess_history where sql_id=&#8217;4a2fkw1d4u01u&#8217; and snap_id between 20637 and 20639)<br />
and snap_id between 20637 and 20639 order by snap_id, sample_time</p>
<p>select &#8216;USER&#8217;, sample_time, sql_id, session_state, blocking_session, blocking_session_serial#, blocking_session_status, event,<br />
(select sql_text from v$sql where sql_id=a.sql_id and rownum=1) xxx from dba_hist_active_sess_history  a<br />
where session_id=762 and session_serial#=45940<br />
and snap_id between 20637 and 20642 order by snap_id, sample_time</p>
<p>&#8211; blocked ETL Session<br />
select &#8216;ETL&#8217;, sample_time, sql_id, session_state, blocking_session, blocking_session_serial#, blocking_session_status, event,<br />
(select sql_text from DBA_HIST_SQLtext where sql_id=a.sql_id and rownum=1) xxx from dba_hist_active_sess_history  a<br />
where session_id=829 and session_serial#=31419<br />
and snap_id between 20637 and 20642 order by snap_id, sample_time</p>
<p>&#8211;USER1@host2( SID=915 )  is blocking ETL_USER@host1( SID=829 )<br />
&#8211; blocked by 915, which funnily enough only active 17 Nov from 17:44 till 22:15 - somehow this session did not release the lock at all until killed the following day<br />
select &#8216;USER&#8217;, sample_time, sql_id, session_state, blocking_session, blocking_session_serial#, blocking_session_status, event,<br />
(select sql_text from DBA_HIST_SQLtext where sql_id=a.sql_id and rownum=1) xxx from dba_hist_active_sess_history  a<br />
where session_id=915 and session_serial#=2165</p>
<p>select * from dba_hist_active_sess_history  a<br />
where session_id=915 and session_serial#=2165 </p>
<p>select *  from dba_tab_columns  where column_name=&#8217;HOST_NAME&#8217; and table_name like &#8216;DBA_HIST%&#8217;</p>
<p>select * from DBA_HIST_SQLbind where sql_id=&#8217;4a2fkw1d4u01u&#8217; and snap_id between 20637 and 20642</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/01/ash/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Index Rebuild</title>
		<link>http://www.oracleexpert.co.uk/2012/01/index-rebuild/</link>
		<comments>http://www.oracleexpert.co.uk/2012/01/index-rebuild/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 09:35:34 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Sandbox]]></category>

		<category><![CDATA[fragmented index]]></category>

		<category><![CDATA[index rebuild]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=428</guid>
		<description><![CDATA[The following script can be used to determine which indexes would benefit from a rebuild, how much they will shrink by (assuming 8k block size and 10% pctfree), results ordered by severity. 
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
select a.*, round(index_leaf_estimate_if_rebuilt/current_leaf_blocks*100) percent, case when index_leaf_estimate_if_rebuilt/current_leaf_blocks < 0.5 then 'candidate for rebuild' end status
from
(
select table_name, index_name, current_leaf_blocks, round (100 / 90 * [...]]]></description>
			<content:encoded><![CDATA[<p>The following script can be used to determine which indexes would benefit from a rebuild, how much they will shrink by (assuming 8k block size and 10% pctfree), results ordered by severity. </p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
select a.*, round(index_leaf_estimate_if_rebuilt/current_leaf_blocks*100) percent, case when index_leaf_estimate_if_rebuilt/current_leaf_blocks < 0.5 then 'candidate for rebuild' end status<br />
from<br />
(<br />
select table_name, index_name, current_leaf_blocks, round (100 / 90 *    (ind_num_rows * (rowid_length + uniq_ind + 4) + sum((avg_col_len) * (tab_num_rows) )   ) / (8192 - 192) ) as index_leaf_estimate_if_rebuilt<br />
from (<br />
select tab.table_name, tab.num_rows tab_num_rows , decode(tab.partitioned,'YES',10,6) rowid_length , ind.index_name, ind.index_type, ind.num_rows ind_num_rows, ind.leaf_blocks as current_leaf_blocks,<br />
 decode(uniqueness,'UNIQUE',0,1) uniq_ind,ic.column_name as ind_column_name, tc.column_name , tc.avg_col_len<br />
from dba_tables tab<br />
join dba_indexes ind on ind.owner=tab.owner and ind.table_name=tab.table_name<br />
join dba_ind_columns ic on ic.table_owner=tab.owner and ic.table_name=tab.table_name and ic.index_owner=tab.owner and ic.index_name=ind.index_name<br />
join dba_tab_columns tc on tc.owner=tab.owner and tc.table_name=tab.table_name and tc.column_name=ic.column_name<br />
where tab.owner='HILDA' and ind.leaf_blocks is not null and ind.leaf_blocks > 1000<br />
) group by table_name, index_name, current_leaf_blocks, ind_num_rows, uniq_ind, rowid_length<br />
) a where index_leaf_estimate_if_rebuilt/current_leaf_blocks < 0.5<br />
order by index_leaf_estimate_if_rebuilt/current_leaf_blocks<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/01/index-rebuild/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Check CPU usage by DB</title>
		<link>http://www.oracleexpert.co.uk/2012/01/check-cpu-usage-by-db/</link>
		<comments>http://www.oracleexpert.co.uk/2012/01/check-cpu-usage-by-db/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 10:25:20 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Sandbox]]></category>

		<category><![CDATA[performance tuning]]></category>

		<category><![CDATA[topinstance]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=425</guid>
		<description><![CDATA[Here is a script originally written by my friend Jim Baker, which I frequently use to check CPU utilisation on a shared DB server by instance
####################
# topinstance.sh
####################
#!/bin/ksh
DBS=`ps -eo args &#124; grep pmon &#124; grep -v grep &#124; cut -c 10-`
PROCS=/tmp/_$$_procs.txt
ps -eoargs,pcpu > $PROCS
for DB in `echo $DBS`
do
  echo `date` $DB `cat $PROCS &#124; grep [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a script originally written by my friend Jim Baker, which I frequently use to check CPU utilisation on a shared DB server by instance</p>
<p>####################<br />
# topinstance.sh<br />
####################<br />
#!/bin/ksh</p>
<p>DBS=`ps -eo args | grep pmon | grep -v grep | cut -c 10-`<br />
PROCS=/tmp/_$$_procs.txt<br />
ps -eoargs,pcpu > $PROCS</p>
<p>for DB in `echo $DBS`<br />
do<br />
  echo `date` $DB `cat $PROCS | grep $DB | grep -v grep | sed &#8217;s/.*  *//&#8217; | \<br />
        awk &#8216;BEGIN { totalcpu = 0.0 } { totalcpu += $0 } END { print totalcpu }&#8217;<br />
`<br />
done</p>
<p>rm -f $PROCS<br />
#####################</p>
<p>This can then be combined with</p>
<p>####################<br />
# pollstat.sh<br />
####################<br />
#!/bin/ksh<br />
touch /home/users/hilda/hostname_usage.log</p>
<p>while [ true ]<br />
do<br />
/home/users/hilda/topinstance.sh >> /home/users/hilda/hostname_usage.log<br />
sleep 30<br />
done</p>
<p>===============</p>
<p>to grab a snapshot every 30 seconds.</p>
<p>This has proven to be useful when combined with AWR reports, so we can quickly determine whether a performance issue is self inflicted within an application, or because some other database is hogging the resource.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/01/check-cpu-usage-by-db/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to fix unaligned sequence after UAT/DEV refresh</title>
		<link>http://www.oracleexpert.co.uk/2011/12/how-to-fix-unaligned-sequence-after-uatdev-refresh/</link>
		<comments>http://www.oracleexpert.co.uk/2011/12/how-to-fix-unaligned-sequence-after-uatdev-refresh/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 14:39:24 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[sequence]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=421</guid>
		<description><![CDATA[Sometimes after a database refresh, we discover that the sequence number has fallen behind compared to actual max value in the table. This then results in PK constraint error when we try to insert a new row using the sequence.
To realign the sequence, you can obviously drop/recreate/alter if you have the right privilege, however here [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes after a database refresh, we discover that the sequence number has fallen behind compared to actual max value in the table. This then results in PK constraint error when we try to insert a new row using the sequence.</p>
<p>To realign the sequence, you can obviously drop/recreate/alter if you have the right privilege, however here is a tip of how to do it if you do not have the schema owner privilege.</p>
<p>declare<br />
  v_table number;<br />
  v_seq   number;<br />
  v_diff  number;<br />
begin<br />
  select max(seq_id) into v_table from TABLE1;<br />
  select last_number into v_seq from all_sequences where sequence_owner=&#8217;OWNER01&#8242; and sequence_name=&#8217;TABLE1_SEQ&#8217; ;</p>
<p>  select v_seq - v_table into v_diff from dual;</p>
<p>  if v_diff < 0<br />
  then<br />
    select (v_diff * -1) + 2 into v_diff from dual;</p>
<p>    for i in 1 .. v_diff<br />
    loop<br />
      select TABLE1_SEQ.nextval into v_table from dual;<br />
    end loop;</p>
<p>  end if;</p>
<p>end;<br />
/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2011/12/how-to-fix-unaligned-sequence-after-uatdev-refresh/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

