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

<channel>
	<title>remidian.com &#187; scripts</title>
	<atom:link href="http://remidian.com/category/oracle/scripts/feed" rel="self" type="application/rss+xml" />
	<link>http://remidian.com</link>
	<description>Braindumps of Remi Visser, freelance Oracle DBA.</description>
	<lastBuildDate>Mon, 10 May 2010 12:33:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>dbverify in nohup</title>
		<link>http://remidian.com/oracle/dbverify-in-nohup.html</link>
		<comments>http://remidian.com/oracle/dbverify-in-nohup.html#comments</comments>
		<pubDate>Tue, 09 Oct 2007 13:57:05 +0000</pubDate>
		<dc:creator>remivisser</dc:creator>
				<category><![CDATA[oracle]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://remidian.com/oracle/dbverify-in-nohup.html</guid>
		<description><![CDATA[Suffering from corruption in your database, it is nearly just as challenging as in real life&#8230; The other day we suffered from a curruption in a 500+ Gigabyte database, as a sequentual dberify would take about 16+ hours I wrote this one below which starts the dbv&#8217;s in nohup in parallel. My dbv finished within [...]]]></description>
			<content:encoded><![CDATA[<p>
Suffering from corruption in your database, it is nearly just as challenging as in real life&#8230;<span id="more-62"></span>
</p>
<p>
The other day we suffered from a curruption in a 500+ Gigabyte database, as a sequentual dberify would take about 16+ hours I wrote this one below which starts the dbv&#8217;s in nohup in parallel. My dbv finished within the hour, system performance will drop though;)
</p>
<pre>
[SYSTEM@DB01.REMIDIAN.COM]
SQL&gt; l
&nbsp;&nbsp;1&nbsp;&nbsp;select
&nbsp;&nbsp;2&nbsp;&nbsp;&#039;nohup dbv&#039; ||
&nbsp;&nbsp;3&nbsp;&nbsp; &#039; file=&#039; || file_name ||
&nbsp;&nbsp;4&nbsp;&nbsp; &#039; blocksize=4096&#039; ||
&nbsp;&nbsp;5&nbsp;&nbsp; &#039; logfile=&#039; || file_id || &#039;_&#039; || substr( file_name, instr(file_name,&#039;/&#039;,-1) +1) || &#039;.log &amp;&#039;
&nbsp;&nbsp;6&nbsp;&nbsp;from
&nbsp;&nbsp;7* dba_data_files
</pre>
<pre>
[SYSTEM@DB01.REMIDIAN.COM]
SQL&gt; /
&nbsp;
&#039;NOHUPDBVFILE=&#039;||FILE_NAME||&#039;BLOCKSIZE=4096LOGFILE=&#039;||FILE_ID||&#039;_&#039;||SUBSTR(FILE_NAME,INSTR(FILE_NAME,&#039;/&#039;,-1)+1)||&#039;.LOG&amp;&#039;
&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-
nohup dbv file=C:\ORACLE\ORADATA\DB01\DB01\USERS01.DBF blocksize=4096 logfile=4_C:\ORACLE\ORADATA\DB01\DB01\USERS01.DBF.log &amp;
nohup dbv file=C:\ORACLE\ORADATA\DB01\DB01\SYSAUX01.DBF blocksize=4096 logfile=3_C:\ORACLE\ORADATA\DB01\DB01\SYSAUX01.DBF.log &amp;
nohup dbv file=C:\ORACLE\ORADATA\DB01\DB01\UNDOTBS01.DBF blocksize=4096 logfile=2_C:\ORACLE\ORADATA\DB01\DB01\UNDOTBS01.DBF.log &amp;
nohup dbv file=C:\ORACLE\ORADATA\DB01\DB01\SYSTEM01.DBF blocksize=4096 logfile=1_C:\ORACLE\ORADATA\DB01\DB01\SYSTEM01.DBF.log &amp;
nohup dbv file=C:\ORACLE\ORADATA\DB01\DB01\EXAMPLE01.DBF blocksize=4096 logfile=5_C:\ORACLE\ORADATA\DB01\DB01\EXAMPLE01.DBF.log &amp;
nohup dbv file=C:\ORACLE\ORADATA\DB01\DB01\P1PERG001.DBF blocksize=4096 logfile=7_C:\ORACLE\ORADATA\DB01\DB01\P1PERG001.DBF.log &amp;
nohup dbv file=C:\ORACLE\ORADATA\DB01\DB01\P1PERG002.DBF blocksize=4096 logfile=8_C:\ORACLE\ORADATA\DB01\DB01\P1PERG002.DBF.log &amp;
&nbsp;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://remidian.com/oracle/dbverify-in-nohup.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>delete large number of records with intermediate commits</title>
		<link>http://remidian.com/oracle/scripts/delete-large-number-of-records-with-intermediate-commits.html</link>
		<comments>http://remidian.com/oracle/scripts/delete-large-number-of-records-with-intermediate-commits.html#comments</comments>
		<pubDate>Tue, 14 Aug 2007 14:26:50 +0000</pubDate>
		<dc:creator>remivisser</dc:creator>
				<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://remidian.com/oracle/scripts/delete-large-number-of-records-with-intermediate-commits.html</guid>
		<description><![CDATA[Have to delete a large number of records and running out of undo tablespace &#8216;ORA-30036: unable to extend segment by 8 in undo tablespace &#8216;UNDO&#8217;? Script below does a delete with intermediate commits ever &#8216;x&#8217; records. declare &#160; &#160;&#160;&#45;- commit every &#039;i_commit&#039; rows &#160;&#160;i_commit&#160;&#160; pls_integer := 1000; &#160; &#160;&#160;&#45;- row counter, &#039;i_rowcount&#039; rows deleted &#160;&#160;i_rowcount [...]]]></description>
			<content:encoded><![CDATA[<p>
Have to delete a large number of records and running out of undo tablespace &#8216;ORA-30036: unable to extend segment by 8 in undo tablespace &#8216;UNDO&#8217;? Script below does a delete with intermediate commits ever &#8216;x&#8217; records. <span id="more-45"></span>
</p>
<pre>
declare
&nbsp;
&nbsp;&nbsp;&#45;- commit every &#039;i_commit&#039; rows
&nbsp;&nbsp;i_commit&nbsp;&nbsp; pls_integer := 1000;
&nbsp;
&nbsp;&nbsp;&#45;- row counter, &#039;i_rowcount&#039; rows deleted
&nbsp;&nbsp;i_rowcount pls_integer := 0;
&nbsp;
begin
&nbsp;
&nbsp;&nbsp;&#45;- define &#039;infinite&#039; loop
&nbsp;&nbsp;loop
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&#45;- delete &#039;i_commit&#039; rows
&nbsp;&nbsp;&nbsp;&nbsp;delete from obj
&nbsp;&nbsp;&nbsp;&nbsp;where rownum &lt;= i_commit;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;i_rowcount := i_rowcount + sql%rowcount;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&#45;- now it&#039;s time to exit the loop
&nbsp;&nbsp;&nbsp;&nbsp;if sql%rowcount = 0 then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; commit;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit;
&nbsp;&nbsp;&nbsp;&nbsp;end if;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;commit;
&nbsp;
&nbsp;&nbsp;end loop;
&nbsp;
&nbsp;&nbsp;&#45;- feedback
&nbsp;&nbsp;dbms_output.put_line( trim( to_char( i_rowcount, &#039;999999999999&#039;)) ||&nbsp;&nbsp;&#039; rows deleted&#039;) ;
&nbsp;
end;
/
&nbsp;
</pre>
<h3>
Example<br />
</h3>
<pre>
[REMI@DB01.REMIDIAN.COM]
SQL&gt; create table obj as select * from dba_objects;
&nbsp;
Table created.
&nbsp;
[REMI@DB01.REMIDIAN.COM]
SQL&gt; &#45;- get current commit count for this session
[REMI@DB01.REMIDIAN.COM]
SQL&gt; select&nbsp;&nbsp;s.*, n.name
&nbsp;&nbsp;2&nbsp;&nbsp;from&nbsp;&nbsp;v$mystat s left outer join v$statname n
&nbsp;&nbsp;3&nbsp;&nbsp;on&nbsp;&nbsp;s.statistic# = n.statistic#
&nbsp;&nbsp;4&nbsp;&nbsp;where&nbsp;&nbsp; n.name = &#039;user commits&#039;
&nbsp;&nbsp;5&nbsp;&nbsp;/
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;SID STATISTIC#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VALUE NAME
&#45;&#45;-&#45;&#45;&#45;- &#45;&#45;-&#45;&#45;-&#45;&#45;&#45;- &#45;&#45;-&#45;&#45;-&#45;&#45;&#45;- &#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;&#45;-
&nbsp;&nbsp;&nbsp;&nbsp;130&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2 user commits
&nbsp;
[REMI@DB01.REMIDIAN.COM]
SQL&gt; declare
&nbsp;&nbsp;2&nbsp;&nbsp;
&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&#45;- commit every &#039;i_commit&#039; rows
&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;i_commit&nbsp;&nbsp; pls_integer := 1000;
&nbsp;&nbsp;5&nbsp;&nbsp;
&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;&nbsp;&#45;- row counter, &#039;i_rowcount&#039; rows deleted
&nbsp;&nbsp;7&nbsp;&nbsp;&nbsp;&nbsp;i_rowcount pls_integer := 0;
&nbsp;&nbsp;8&nbsp;&nbsp;
&nbsp;&nbsp;9&nbsp;&nbsp;begin
 10&nbsp;&nbsp;
 11&nbsp;&nbsp;&nbsp;&nbsp;&#45;- define &#039;infinite&#039; loop
 12&nbsp;&nbsp;&nbsp;&nbsp;loop
 13&nbsp;&nbsp;
 14&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#45;- delete &#039;i_commit&#039; rows
 15&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delete from obj
 16&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;where rownum &lt;= i_commit;
 17&nbsp;&nbsp;
 18&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i_rowcount := i_rowcount + sql%rowcount;
 19&nbsp;&nbsp;
 20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#45;- now it&#039;s time to exit the loop
 21&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if sql%rowcount = 0 then
 22&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; commit;
 23&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit;
 24&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if;
 25&nbsp;&nbsp;
 26&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commit;
 27&nbsp;&nbsp;
 28&nbsp;&nbsp;&nbsp;&nbsp;end loop;
 29&nbsp;&nbsp;
 30&nbsp;&nbsp;&nbsp;&nbsp;&#45;- feedback
 31&nbsp;&nbsp;&nbsp;&nbsp;dbms_output.put_line( trim( to_char( i_rowcount, &#039;999999999999&#039;)) ||&nbsp;&nbsp;&#039; rows deleted&#039;) ;
 32&nbsp;&nbsp;end;
 33&nbsp;&nbsp;/
61963 rows deleted
&nbsp;
PL/SQL procedure successfully completed.
&nbsp;
[REMI@DB01.REMIDIAN.COM]
SQL&gt; &#45;- get current commit count for this session
[REMI@DB01.REMIDIAN.COM]
SQL&gt; select&nbsp;&nbsp;s.*, n.name
&nbsp;&nbsp;2&nbsp;&nbsp;from&nbsp;&nbsp;v$mystat s left outer join v$statname n
&nbsp;&nbsp;3&nbsp;&nbsp;on&nbsp;&nbsp;s.statistic# = n.statistic#
&nbsp;&nbsp;4&nbsp;&nbsp;where&nbsp;&nbsp; n.name = &#039;user commits&#039;
&nbsp;&nbsp;5&nbsp;&nbsp;/
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;SID STATISTIC#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VALUE NAME
&#45;&#45;-&#45;&#45;&#45;- &#45;&#45;-&#45;&#45;-&#45;&#45;&#45;- &#45;&#45;-&#45;&#45;-&#45;&#45;&#45;- &#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;&#45;-
&nbsp;&nbsp;&nbsp;&nbsp;130&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 64 user commits
&nbsp;
[REMI@DB01.REMIDIAN.COM]
SQL&gt; 
&nbsp;
</pre>
<p>
Of course the latter statement would be used on v$sesstat to monitor the progress of the &#8216;delete loop&#8217;.
</p>
<h6>Monitor user commits</h6>
<pre>
[REMI@DB01.REMIDIAN.COM]
SQL&gt; select&nbsp;&nbsp;s.*, n.name
&nbsp;&nbsp;2&nbsp;&nbsp;from&nbsp;&nbsp;v$sesstat s left outer join v$statname n
&nbsp;&nbsp;3&nbsp;&nbsp;on&nbsp;&nbsp;s.statistic# = n.statistic#
&nbsp;&nbsp;4&nbsp;&nbsp;where&nbsp;&nbsp; n.name = &#039;user commits&#039;
&nbsp;&nbsp;5&nbsp;&nbsp;and s.sid = &lt;sid&gt;
&nbsp;&nbsp;6&nbsp;&nbsp;/
 </pre>
]]></content:encoded>
			<wfw:commentRss>http://remidian.com/oracle/scripts/delete-large-number-of-records-with-intermediate-commits.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
