<?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>天道酬勤 &#187; HA</title>
	<atom:link href="http://www.ochef.net/tag/ha/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ochef.net</link>
	<description>Oracle and My Life</description>
	<lastBuildDate>Mon, 09 Jan 2012 05:39:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Stop and remove oracle advanced replication</title>
		<link>http://www.ochef.net/2009/03/stop-and-remove-oracle-advanced-replication.html</link>
		<comments>http://www.ochef.net/2009/03/stop-and-remove-oracle-advanced-replication.html#comments</comments>
		<pubDate>Thu, 05 Mar 2009 08:26:30 +0000</pubDate>
		<dc:creator>ochef</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[HA]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://www.ochef.net/?p=121</guid>
		<description><![CDATA[说说08年的一个案例，Oracle的高级复制，尽管现在大家都不用了。公司扩大业务，在HB建了分公司，要将SZ这边的一部分数据（其实有一千多张表）同步到HB，在配置好高级复制之后测试，由于要复制的数据量增长比较快，以至于表空间飞快增长，当我们想要停止和删除复制环境的时候，就被挂起，google的很多文章都不见效，最后救助Oracle TS解决，以下是解决方案： SOLUTION / ACTION PLAN To implement the solution, please execute the following steps: For each of the 5 groups,just do the actions one by one. 1. if posible,please stop the application for a while. But do not stop the resouce oracle using (including network,listener,etc) 2. Stop all the replication push and purge job. [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F09%2Fdb2_vs_oracle.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fstop-and-remove-oracle-advanced-replication.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DB2对比Oracle学习系列之:instance &amp; database concepts</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F04%2Foracle-buys-sun.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fstop-and-remove-oracle-advanced-replication.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Oracle Buys Sun</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fhow-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fstop-and-remove-oracle-advanced-replication.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">如何在一个业务繁忙的大表中增加一个并带有默认值的字段</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Finstall-oracle-102-on-solaris10.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fstop-and-remove-oracle-advanced-replication.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Install oracle 10.2 on Solaris10</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>说说08年的一个案例，<span style="color: #0000ff;">Oracle的高级复制</span>，尽管现在大家都不用了。公司扩大业务，在HB建了分公司，要将SZ这边的一部分数据（其实有一千多张表）同步到HB，在配置好高级复制之后测试，由于要复制的数据量增长比较快，以至于表空间飞快增长，当我们想要停止和删除复制环境的时候，就被挂起，google的很多文章都不见效，最后救助Oracle TS解决，以下是解决方案：</p>
<p><span style="color: #ff0000;">SOLUTION / ACTION PLAN</span><br />
To implement the solution, please execute the following steps:</p>
<p>For each of the 5 groups,just do the actions one by one.<br />
1. if posible,please stop the application for a while. But do not stop the resouce oracle using<br />
   (including network,listener,etc)</p>
<p>2. Stop all the replication push and purge job. Stop current running push&amp;purge job first.note:<br />
1)in 2 sites,run the whole step 2<br />
2)no special comments, all user please use &#8216;repadmin&#8217;</p>
<p>2.1 Check if the push job is currently running</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;">sql<span style="color: #66cc66;">&gt;</span>select <span style="color: #808080; font-style: italic;">/*+ ORDERED */</span> j<span style="color: #66cc66;">.</span>job<span style="color: #66cc66;">,</span> j<span style="color: #66cc66;">.</span>sid<span style="color: #66cc66;">,</span> d<span style="color: #66cc66;">.</span>dblink<span style="color: #66cc66;">,</span>
SUBSTR<span style="color: #66cc66;">&#40;</span>TO_CHAR<span style="color: #66cc66;">&#40;</span>J<span style="color: #66cc66;">.</span>THIS_DATE<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'MM/DD/RRRR HH24:MI:SS'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span> START_DATE
<span style="color: #993333; font-weight: bold;">FROM</span> defschedule d<span style="color: #66cc66;">,</span> dba_jobs_running j
<span style="color: #993333; font-weight: bold;">WHERE</span> j<span style="color: #66cc66;">.</span>job <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> job <span style="color: #993333; font-weight: bold;">FROM</span> dba_jobs
<span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #993333; font-weight: bold;">UPPER</span><span style="color: #66cc66;">&#40;</span>what<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%DBMS_DEFER_SYS.PUSH%'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">AND</span> j<span style="color: #66cc66;">.</span>job <span style="color: #66cc66;">=</span> d<span style="color: #66cc66;">.</span>job;</pre></td></tr></table></div>


<div class="wp_syntax"><div class="code"><pre class="test" style="font-family:monospace;">       JOB SID DBLINK START_DATE
       ---------- ---------- ------------------------------
        44 9 DB2.WORLD 05/16/2002 12:14:47</pre></div></div>

<p><span id="more-121"></span><br />
- if exist,then note the sid<br />
- Kill the Job Queue Process from the Operating System. To do this usethe sid to identify the<br />
  process in v$session, v$process and v$bgprocess. The process will generally be named<br />
  SNPx   or Jxxx.<br />
- After killing the process, wait approximately 1 minute, to ensure the job is removed from<br />
  dba_jobs_running.</p>
<p>You can kill the corresponding session after finding its serial# from v$session:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">sql<span style="color: #66cc66;">&gt;</span>select serial# <span style="color: #993333; font-weight: bold;">FROM</span> v$session <span style="color: #993333; font-weight: bold;">WHERE</span> sid<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">9</span>;
       SERIAL#
      <span style="color: #808080; font-style: italic;">----------</span>
        <span style="color: #cc66cc;">24909</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">sql<span style="color: #66cc66;">&gt;</span>alter system <span style="color: #993333; font-weight: bold;">KILL</span> <span style="color: #993333; font-weight: bold;">SESSION</span> <span style="color: #ff0000;">'8,24909'</span>;</pre></div></div>

<p>2.2 stop all push&amp;purge job in 2 sites.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">sql<span style="color: #66cc66;">&gt;</span>select job<span style="color: #66cc66;">,</span> what<span style="color: #66cc66;">,</span>broken <span style="color: #993333; font-weight: bold;">FROM</span> dba_jobs <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #993333; font-weight: bold;">UPPER</span><span style="color: #66cc66;">&#40;</span>what<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%DBMS_DEFER_SYS%'</span>;
&nbsp;
      JOB   WHAT BROKEN
      <span style="color: #808080; font-style: italic;">----   --------------------------------------------------------------------------</span>
       <span style="color: #cc66cc;">43</span>     <span style="color: #993333; font-weight: bold;">DECLARE</span> rc binary_integer;
                <span style="color: #993333; font-weight: bold;">BEGIN</span> rc :<span style="color: #66cc66;">=</span> sys<span style="color: #66cc66;">.</span>dbms_defer_sys<span style="color: #66cc66;">.</span>purge<span style="color: #66cc66;">&#40;</span> N
                delay_seconds<span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #993333; font-weight: bold;">END</span>;
       <span style="color: #cc66cc;">44</span>     <span style="color: #993333; font-weight: bold;">DECLARE</span> rc binary_integer;
                <span style="color: #993333; font-weight: bold;">BEGIN</span> rc :<span style="color: #66cc66;">=</span> sys<span style="color: #66cc66;">.</span>dbms_defer_sys<span style="color: #66cc66;">.</span>push<span style="color: #66cc66;">&#40;</span>d N
                estination<span style="color: #66cc66;">=&gt;</span><span style="color: #ff0000;">'DB2.WORLD'</span><span style="color: #66cc66;">,</span> stop_on_error<span style="color: #66cc66;">=&gt;</span>FALSE<span style="color: #66cc66;">,</span> delay_seconds<span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span>
                parallelism<span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #993333; font-weight: bold;">END</span>;</pre></div></div>

<p>- Break the job with :<br />
execute dbms_job.broken(, true);&#8211;need be changed from the previous query result.commit;<br />
Query again to confirm the push &amp; purge job has all been stopped</p>
<p>3. remove the deferred queue</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;">sql<span style="color: #66cc66;">&gt;</span>select constraint_name<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span>
      <span style="color: #993333; font-weight: bold;">FROM</span> sys<span style="color: #66cc66;">.</span>dba_constraints <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'DEF$_CALLDEST'</span>;</pre></td></tr></table></div>


<div class="wp_syntax"><div class="code"><pre class="test" style="font-family:monospace;">       CONSTRAINT_NAME TABLE_NAME
       ------------------------------ ------------------
       DEF$_CALLDEST_PRIMARY DEF$_CALLDEST
       DEF$_CALL_DESTINATION DEF$_CALLDEST</pre></div></div>

<p>Note: As of Oracle8, system.DEF$_CALLDEST_CALL in not being used and system.DEF$_CALL has been changed to system.DEF$_AQCALL (this is due to the advanced queueing features in Oracle8)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;">sql<span style="color: #66cc66;">&gt;</span>truncate <span style="color: #993333; font-weight: bold;">TABLE</span> system<span style="color: #66cc66;">.</span>DEF$_AQCALL;
sql<span style="color: #66cc66;">&gt;</span>truncate <span style="color: #993333; font-weight: bold;">TABLE</span> system<span style="color: #66cc66;">.</span>DEF$_CALLDEST;
sql<span style="color: #66cc66;">&gt;</span>truncate <span style="color: #993333; font-weight: bold;">TABLE</span> system<span style="color: #66cc66;">.</span>DEF$_ERROR;
sql<span style="color: #66cc66;">&gt;</span>truncate <span style="color: #993333; font-weight: bold;">TABLE</span> system<span style="color: #66cc66;">.</span>DEF$_AQERROR;
sql<span style="color: #66cc66;">&gt;</span>truncate <span style="color: #993333; font-weight: bold;">TABLE</span> system<span style="color: #66cc66;">.</span>DEF$_LOB; <span style="color: #808080; font-style: italic;">-- if there are LOBs replicated.</span>
sql<span style="color: #66cc66;">&gt;</span>select <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> DEFCALL;
       no <span style="color: #993333; font-weight: bold;">ROWS</span>
sql<span style="color: #66cc66;">&gt;</span>select <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> DEFTRAN;
       no <span style="color: #993333; font-weight: bold;">ROWS</span>
sql<span style="color: #66cc66;">&gt;</span>select <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> DEFERROR;
       no <span style="color: #993333; font-weight: bold;">ROWS</span></pre></td></tr></table></div>

<p>4. When All the steps are implemented on 2 sites,we can try to suspend the master group from the master definition site.<br />
It wont take a lot of time. Then,you can remove the replcation object and the w<br />
hole replication enviroment.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;">sql<span style="color: #66cc66;">&gt;</span>select gname<span style="color: #66cc66;">,</span> request<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">STATUS</span><span style="color: #66cc66;">,</span> errnum
     <span style="color: #993333; font-weight: bold;">FROM</span> dba_repcatlog
     <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> id<span style="color: #66cc66;">,</span> gname;</pre></td></tr></table></div>

<p>Additional:<br />
If the below step be done,u must start again and u do above steps .</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="plsql" style="font-family:monospace;">DBMS_DEFER_SYS<span style="color: #00F;">.</span>SET_DISABLED <span style="color: #00F;">&#40;</span>
                         destination <span style="color: #00F;">IN</span> <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">,</span>
                         disabled <span style="color: #00F;">IN</span> <span style="color: #00F;">BOOLEAN</span> <span style="color: #00F;">:=</span> <span style="color: #00F;">TRUE</span><span style="color: #00F;">,</span>
                         catchup <span style="color: #00F;">IN</span> <span style="color: #00F;">RAW</span> <span style="color: #00F;">:=</span> <span style="color: #F00;">'00'</span><span style="color: #00F;">,</span>
                         override <span style="color: #00F;">IN</span> <span style="color: #00F;">BOOLEAN</span> <span style="color: #00F;">:=</span> <span style="color: #00F;">FALSE</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
DBMS_DEFER_SYS<span style="color: #00F;">.</span>SET_DISABLED <span style="color: #00F;">&#40;</span>
                         Destination <span style="color: #00F;">=</span>&amp;gt<span style="color: #00F;">;</span> ‘meslf’<span style="color: #00F;">,</span>
                         disabled <span style="color: #00F;">=</span> <span style="color: #00F;">TRUE</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span></pre></td></tr></table></div>

<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F09%2Fdb2_vs_oracle.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fstop-and-remove-oracle-advanced-replication.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DB2对比Oracle学习系列之:instance &amp; database concepts</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F04%2Foracle-buys-sun.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fstop-and-remove-oracle-advanced-replication.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Oracle Buys Sun</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fhow-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fstop-and-remove-oracle-advanced-replication.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">如何在一个业务繁忙的大表中增加一个并带有默认值的字段</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Finstall-oracle-102-on-solaris10.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fstop-and-remove-oracle-advanced-replication.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Install oracle 10.2 on Solaris10</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.ochef.net/2009/03/stop-and-remove-oracle-advanced-replication.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何在一个业务繁忙的大表中增加一个并带有默认值的字段</title>
		<link>http://www.ochef.net/2009/03/how-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html</link>
		<comments>http://www.ochef.net/2009/03/how-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html#comments</comments>
		<pubDate>Thu, 05 Mar 2009 02:41:08 +0000</pubDate>
		<dc:creator>ochef</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[HA]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://www.ochef.net/?p=107</guid>
		<description><![CDATA[方法来自Piner的新书《构建Oracle高可用环境》 1.先增加一个字段 sql&#62;Alter TABLE TABLE_NAME ADD field_name NUMBER; 2.把该字段修改为有默认值 sql&#62;Alter TABLE TABLE_NAME MODIFY field_name DEFAULT 0; 该语句并不修改以前的记录，只是标记以后的记录将会有默认值0,所以，这个语句的执行很快，不会引发阻塞。 3.修改以前的记录，让其有默认值（每修改1000条记录 commit一次） 1 2 3 4 5 6 7 8 9 10 11 12 DECLARE row_num NUMBER := 0; BEGIN FOR c_test IN &#40;SELECT ROWID rid FROM table_name t WHERE field_name IS NULL&#41; LOOP UPDATE table_name t SET [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fstop-and-remove-oracle-advanced-replication.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fhow-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Stop and remove oracle advanced replication</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F09%2Fdb2_vs_oracle.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fhow-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DB2对比Oracle学习系列之:instance &amp; database concepts</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F04%2Foracle-buys-sun.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fhow-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Oracle Buys Sun</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Finstall-oracle-102-on-solaris10.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fhow-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Install oracle 10.2 on Solaris10</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>方法来自<a href="http://www.ixdba.com/" target="_blank">Piner</a>的新书<a href="http://www.china-pub.com/38185" target="_blank">《构建Oracle高可用环境》</a><br />
1.先增加一个字段</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">sql<span style="color: #66cc66;">&gt;</span>Alter <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #993333; font-weight: bold;">ADD</span> field_name <span style="color: #993333; font-weight: bold;">NUMBER</span>;</pre></div></div>

<p>2.把该字段修改为有默认值</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">sql<span style="color: #66cc66;">&gt;</span>Alter <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #993333; font-weight: bold;">MODIFY</span> field_name <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #cc66cc;">0</span>;</pre></div></div>

<p>该语句并不修改以前的记录，只是标记以后的记录将会有默认值0,所以，这个语句的执行很快，不会引发阻塞。<br />
3.修改以前的记录，让其有默认值（每修改1000条记录 commit一次）</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">DECLARE</span>
       row_num <span style="color: #00F;">NUMBER</span> <span style="color: #00F;">:=</span> <span style="color: #800;">0</span><span style="color: #00F;">;</span>
<span style="color: #00F;">BEGIN</span>
       <span style="color: #00F;">FOR</span> c_test <span style="color: #00F;">IN</span> <span style="color: #00F;">&#40;</span><span style="color: #00F;">SELECT</span> <span style="color: #00F;">ROWID</span> rid <span style="color: #00F;">FROM</span> table_name t <span style="color: #00F;">WHERE</span> field_name <span style="color: #00F;">IS</span> <span style="color: #00F;">NULL</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">LOOP</span>
             <span style="color: #00F;">UPDATE</span> table_name t <span style="color: #00F;">SET</span> t<span style="color: #00F;">.</span>field_name <span style="color: #00F;">=</span> <span style="color: #800;">0</span> <span style="color: #00F;">WHERE</span> <span style="color: #00F;">ROWID</span> <span style="color: #00F;">=</span> c_test<span style="color: #00F;">.</span>rid<span style="color: #00F;">;</span>
             row_num <span style="color: #00F;">:=</span> row_num <span style="color: #00F;">+</span> <span style="color: #800;">1</span><span style="color: #00F;">;</span>
             <span style="color: #00F;">IF</span> <span style="color: #000;">MOD</span><span style="color: #00F;">&#40;</span>row_num<span style="color: #00F;">,</span><span style="color: #800;">1000</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span><span style="color: #800;">0</span> <span style="color: #00F;">THEN</span>
                  <span style="color: #00F;">COMMIT</span><span style="color: #00F;">;</span>
             <span style="color: #00F;">END</span> <span style="color: #00F;">IF</span><span style="color: #00F;">;</span>
        <span style="color: #00F;">END</span> <span style="color: #00F;">LOOP</span><span style="color: #00F;">;</span>
        <span style="color: #00F;">COMMIT</span><span style="color: #00F;">;</span>
<span style="color: #00F;">END</span><span style="color: #00F;">;</span></pre></td></tr></table></div>

<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fstop-and-remove-oracle-advanced-replication.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fhow-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Stop and remove oracle advanced replication</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F09%2Fdb2_vs_oracle.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fhow-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DB2对比Oracle学习系列之:instance &amp; database concepts</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F04%2Foracle-buys-sun.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fhow-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Oracle Buys Sun</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Finstall-oracle-102-on-solaris10.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fhow-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Install oracle 10.2 on Solaris10</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.ochef.net/2009/03/how-in-a-busy-adding-a-large-table-with-a-default-value-of-the-field.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

