<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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: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>Comments on: Lock table followed by DDL?</title>
	<atom:link href="http://orainternals.wordpress.com/2009/01/08/lock-table-followed-by-ddl/feed/" rel="self" type="application/rss+xml" />
	<link>http://orainternals.wordpress.com/2009/01/08/lock-table-followed-by-ddl/</link>
	<description>Discussions about Oracle performance tuning, Oracle internal &#38; E-business suite.</description>
	<lastBuildDate>Fri, 06 Nov 2009 05:09:37 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: orainternals</title>
		<link>http://orainternals.wordpress.com/2009/01/08/lock-table-followed-by-ddl/#comment-350</link>
		<dc:creator>orainternals</dc:creator>
		<pubDate>Tue, 04 Aug 2009 14:08:07 +0000</pubDate>
		<guid isPermaLink="false">http://orainternals.wordpress.com/?p=270#comment-350</guid>
		<description>Hi Saravanan
   Thanks for reading my blog. I had a mistake in that part of the script, Sorry. I was testing something else and accidentally must have introduced &#039;wait 300&#039; in the ddl statement. I have corrected it and your sql need to be modified as below:
  (BTW, sample is a keyword and it is probably not a good idea to use for table name).
declare
begin
      -- lock table in exclusive mode
      execute immediate &#039;lock table t1 in exclusive mode &#039;;
      dbms_output.put_line (&#039;**** Table locked. Dropping column ****&#039; ) ;
      -- If we lock it, drop the column
      execute immediate &#039;alter table t1 drop column n5 &#039;;
exception
  when others then
     dbms_output.put_line(&#039; No luck &#039;);
     dbms_output.put_line(&#039; SQL code&#039;&#124;&#124;sqlcode&#124;&#124;&#039;,&#039;&#124;&#124; &#039;error &#039;&#124;&#124;sqlerrm );
end;


Cheers
Riyaj</description>
		<content:encoded><![CDATA[<p>Hi Saravanan<br />
   Thanks for reading my blog. I had a mistake in that part of the script, Sorry. I was testing something else and accidentally must have introduced &#8216;wait 300&#8242; in the ddl statement. I have corrected it and your sql need to be modified as below:<br />
  (BTW, sample is a keyword and it is probably not a good idea to use for table name).<br />
declare<br />
begin<br />
      &#8212; lock table in exclusive mode<br />
      execute immediate &#8216;lock table t1 in exclusive mode &#8216;;<br />
      dbms_output.put_line (&#8216;**** Table locked. Dropping column ****&#8217; ) ;<br />
      &#8212; If we lock it, drop the column<br />
      execute immediate &#8216;alter table t1 drop column n5 &#8216;;<br />
exception<br />
  when others then<br />
     dbms_output.put_line(&#8216; No luck &#8216;);<br />
     dbms_output.put_line(&#8216; SQL code&#8217;||sqlcode||&#8217;,'|| &#8216;error &#8216;||sqlerrm );<br />
end;</p>
<p>Cheers<br />
Riyaj</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Saravanan</title>
		<link>http://orainternals.wordpress.com/2009/01/08/lock-table-followed-by-ddl/#comment-349</link>
		<dc:creator>Saravanan</dc:creator>
		<pubDate>Tue, 04 Aug 2009 04:57:49 +0000</pubDate>
		<guid isPermaLink="false">http://orainternals.wordpress.com/?p=270#comment-349</guid>
		<description>hai friend,
 i tried the following PL/SQL when droping a column in lock mode.but it show the ERROR.
SQL&gt; ed
Wrote file afiedt.buf

  1  declare
  2  begin
  3        dbms_output.put_line (&#039;1&#039;) ;
  4        -- lock table in exclusive mode and wait for 5 minutes
  5        execute immediate &#039;lock table sample in exclusive mode wait 60&#039;;
  6        dbms_output.put_line (&#039;2&#039;) ;
  7        dbms_output.put_line (&#039;**** Table locked. Dropping column ****&#039; ) ;
  8        dbms_output.put_line (&#039;3&#039;) ;
  9        -- If we lock it, drop the column
 10        execute immediate &#039;alter table sample add address varchar2(20)&#039;;
 11  exception
 12    when others then
 13       dbms_output.put_line(&#039; No luck &#039;);
 14       dbms_output.put_line(&#039; SQL code&#039;&#124;&#124;sqlcode&#124;&#124;&#039;,&#039;&#124;&#124; &#039;error &#039;&#124;&#124;sqlerrm );
 15* end;
SQL&gt; /
1
No luck
SQL code-933,error ORA-00933: SQL command not properly ended

PL/SQL procedure successfully completed.</description>
		<content:encoded><![CDATA[<p>hai friend,<br />
 i tried the following PL/SQL when droping a column in lock mode.but it show the ERROR.<br />
SQL&gt; ed<br />
Wrote file afiedt.buf</p>
<p>  1  declare<br />
  2  begin<br />
  3        dbms_output.put_line (&#8216;1&#8242;) ;<br />
  4        &#8212; lock table in exclusive mode and wait for 5 minutes<br />
  5        execute immediate &#8216;lock table sample in exclusive mode wait 60&#8242;;<br />
  6        dbms_output.put_line (&#8216;2&#8242;) ;<br />
  7        dbms_output.put_line (&#8216;**** Table locked. Dropping column ****&#8217; ) ;<br />
  8        dbms_output.put_line (&#8216;3&#8242;) ;<br />
  9        &#8212; If we lock it, drop the column<br />
 10        execute immediate &#8216;alter table sample add address varchar2(20)&#8217;;<br />
 11  exception<br />
 12    when others then<br />
 13       dbms_output.put_line(&#8216; No luck &#8216;);<br />
 14       dbms_output.put_line(&#8216; SQL code&#8217;||sqlcode||&#8217;,'|| &#8216;error &#8216;||sqlerrm );<br />
 15* end;<br />
SQL&gt; /<br />
1<br />
No luck<br />
SQL code-933,error ORA-00933: SQL command not properly ended</p>
<p>PL/SQL procedure successfully completed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: orainternals</title>
		<link>http://orainternals.wordpress.com/2009/01/08/lock-table-followed-by-ddl/#comment-242</link>
		<dc:creator>orainternals</dc:creator>
		<pubDate>Sun, 15 Mar 2009 17:43:53 +0000</pubDate>
		<guid isPermaLink="false">http://orainternals.wordpress.com/?p=270#comment-242</guid>
		<description>Mark
   I have corrected original comments.</description>
		<content:encoded><![CDATA[<p>Mark<br />
   I have corrected original comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Bobak</title>
		<link>http://orainternals.wordpress.com/2009/01/08/lock-table-followed-by-ddl/#comment-237</link>
		<dc:creator>Mark Bobak</dc:creator>
		<pubDate>Fri, 13 Mar 2009 16:19:21 +0000</pubDate>
		<guid isPermaLink="false">http://orainternals.wordpress.com/?p=270#comment-237</guid>
		<description>Note:  In the comments above, where I said DDL, I meant DML.</description>
		<content:encoded><![CDATA[<p>Note:  In the comments above, where I said DDL, I meant DML.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: orainternals</title>
		<link>http://orainternals.wordpress.com/2009/01/08/lock-table-followed-by-ddl/#comment-236</link>
		<dc:creator>orainternals</dc:creator>
		<pubDate>Fri, 13 Mar 2009 15:14:58 +0000</pubDate>
		<guid isPermaLink="false">http://orainternals.wordpress.com/?p=270#comment-236</guid>
		<description>Hi Mark
  Thanks for visiting my blog and thanks for the idea.
Cheers
Riyaj</description>
		<content:encoded><![CDATA[<p>Hi Mark<br />
  Thanks for visiting my blog and thanks for the idea.<br />
Cheers<br />
Riyaj</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Bobak</title>
		<link>http://orainternals.wordpress.com/2009/01/08/lock-table-followed-by-ddl/#comment-233</link>
		<dc:creator>Mark Bobak</dc:creator>
		<pubDate>Fri, 13 Mar 2009 06:32:48 +0000</pubDate>
		<guid isPermaLink="false">http://orainternals.wordpress.com/?p=270#comment-233</guid>
		<description>Hi Riyaj,

Well, ok, better late than never.

I remember that talk we had some time ago, and the investigation.

Once other solution, if 11g is not yet an option, is available, but would require modification of application code.  If that&#039;s an option, you can code DBMS_LOCK to take a user defined enqueue in shared mode before doing DML on the table, and call it from normal application operation.  When you want to add column, drop column, whatever, you can call DBMS_LOCK on your user defined enqueue with exclusive mode.  This will queue behind the shared mode locks held by the application.  Eventually, the app will release those locks, your session will acquire exclusive lock, and then you can proceed w/ drop column, add column, whatever.  As long as all DML on the table is happening from the application where code always takes the user defined enqueue first, this should work.  When you&#039;re done w/ the add/drop column, release the enqueue, and the application will start running again.

Hope that helps,

-Mark</description>
		<content:encoded><![CDATA[<p>Hi Riyaj,</p>
<p>Well, ok, better late than never.</p>
<p>I remember that talk we had some time ago, and the investigation.</p>
<p>Once other solution, if 11g is not yet an option, is available, but would require modification of application code.  If that&#8217;s an option, you can code DBMS_LOCK to take a user defined enqueue in shared mode before doing DML on the table, and call it from normal application operation.  When you want to add column, drop column, whatever, you can call DBMS_LOCK on your user defined enqueue with exclusive mode.  This will queue behind the shared mode locks held by the application.  Eventually, the app will release those locks, your session will acquire exclusive lock, and then you can proceed w/ drop column, add column, whatever.  As long as all DML on the table is happening from the application where code always takes the user defined enqueue first, this should work.  When you&#8217;re done w/ the add/drop column, release the enqueue, and the application will start running again.</p>
<p>Hope that helps,</p>
<p>-Mark</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: orainternals</title>
		<link>http://orainternals.wordpress.com/2009/01/08/lock-table-followed-by-ddl/#comment-200</link>
		<dc:creator>orainternals</dc:creator>
		<pubDate>Fri, 13 Feb 2009 01:28:47 +0000</pubDate>
		<guid isPermaLink="false">http://orainternals.wordpress.com/?p=270#comment-200</guid>
		<description>Hi Hrishy
   Thank you for reading my blog. Of course, there are more than one way to do that operation and that entry was related DDL and implicit commit.
   Hope you got that job.

Cheers
Riyaj</description>
		<content:encoded><![CDATA[<p>Hi Hrishy<br />
   Thank you for reading my blog. Of course, there are more than one way to do that operation and that entry was related DDL and implicit commit.<br />
   Hope you got that job.</p>
<p>Cheers<br />
Riyaj</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hrishy</title>
		<link>http://orainternals.wordpress.com/2009/01/08/lock-table-followed-by-ddl/#comment-197</link>
		<dc:creator>hrishy</dc:creator>
		<pubDate>Mon, 09 Feb 2009 17:29:38 +0000</pubDate>
		<guid isPermaLink="false">http://orainternals.wordpress.com/?p=270#comment-197</guid>
		<description>Hi

Coincidence i was asked this question in a interview and the same exact sceanario where the database is very busy.I mentioned my choice as dbms_redefination wundering why you didnt opt for the dbms_redefination way</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>Coincidence i was asked this question in a interview and the same exact sceanario where the database is very busy.I mentioned my choice as dbms_redefination wundering why you didnt opt for the dbms_redefination way</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: orainternals</title>
		<link>http://orainternals.wordpress.com/2009/01/08/lock-table-followed-by-ddl/#comment-191</link>
		<dc:creator>orainternals</dc:creator>
		<pubDate>Tue, 20 Jan 2009 16:44:59 +0000</pubDate>
		<guid isPermaLink="false">http://orainternals.wordpress.com/?p=270#comment-191</guid>
		<description>Hello Robert
  Thanks for reading my blog.
  Original script was supposed to drop and add few columns. I used &#039;drop&#039; part of the script to make my point. Obviously didn&#039;t catch that comment discrepancy. I have updated that.
  About &#039;sleep&#039;, yeah, there are more than one way to accomplish that goal :-)

Cheers
Riyaj</description>
		<content:encoded><![CDATA[<p>Hello Robert<br />
  Thanks for reading my blog.<br />
  Original script was supposed to drop and add few columns. I used &#8216;drop&#8217; part of the script to make my point. Obviously didn&#8217;t catch that comment discrepancy. I have updated that.<br />
  About &#8217;sleep&#8217;, yeah, there are more than one way to accomplish that goal <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Cheers<br />
Riyaj</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Klemme</title>
		<link>http://orainternals.wordpress.com/2009/01/08/lock-table-followed-by-ddl/#comment-190</link>
		<dc:creator>Robert Klemme</dc:creator>
		<pubDate>Tue, 20 Jan 2009 08:55:51 +0000</pubDate>
		<guid isPermaLink="false">http://orainternals.wordpress.com/?p=270#comment-190</guid>
		<description>Another worrying observation that would make a good explanation for &quot;the code block did not do what we wanted&quot;:

      dbms_output.put_line (&#039;**** Table locked. Adding column ****&#039; ) ;
      -- If we lock it, drop the column
      execute immediate &#039;alter table t1 drop column n5 &#039;;

The output talks about adding but the DDL is actually a DROP COLUMN... Btw, this also seems to be a bit inconsistent in your article. :-)

Another thing that made me wonder: why did you do the 10 second sleep?  If the application is OLTP and the table is heavily used, I&#039;d rather loop without sleep because IMHO you do not increase your likeliness of obtaining the lock by sleeping (OLTP =&gt; high frequency, short transactions).

One could add a max counter to avoid endless looping.  But then again, you can as well use CTRL-C to interrupt or kill the session.

Cheers</description>
		<content:encoded><![CDATA[<p>Another worrying observation that would make a good explanation for &#8220;the code block did not do what we wanted&#8221;:</p>
<p>      dbms_output.put_line (&#8216;**** Table locked. Adding column ****&#8217; ) ;<br />
      &#8212; If we lock it, drop the column<br />
      execute immediate &#8216;alter table t1 drop column n5 &#8216;;</p>
<p>The output talks about adding but the DDL is actually a DROP COLUMN&#8230; Btw, this also seems to be a bit inconsistent in your article. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Another thing that made me wonder: why did you do the 10 second sleep?  If the application is OLTP and the table is heavily used, I&#8217;d rather loop without sleep because IMHO you do not increase your likeliness of obtaining the lock by sleeping (OLTP =&gt; high frequency, short transactions).</p>
<p>One could add a max counter to avoid endless looping.  But then again, you can as well use CTRL-C to interrupt or kill the session.</p>
<p>Cheers</p>
]]></content:encoded>
	</item>
</channel>
</rss>
