﻿<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.1.2" -->
<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/"
	>

<channel>
	<title>DBA Story (dba on unix/linux)</title>
	<link>http://www.ixdba.com</link>
	<description>dba on unix</description>
	<pubDate>Tue, 08 Apr 2008 09:21:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.2</generator>
	<language>en</language>
			<item>
		<title>新书前言（第二次印刷）</title>
		<link>http://www.ixdba.com/html/y2008/m04/214-book-reprint.html</link>
		<comments>http://www.ixdba.com/html/y2008/m04/214-book-reprint.html#comments</comments>
		<pubDate>Tue, 01 Apr 2008 00:51:50 +0000</pubDate>
		<dc:creator>piner</dc:creator>
		
		<category><![CDATA[新书服务|Book]]></category>

		<category><![CDATA[所有|All Blogs]]></category>
<category>book</category><category>前言</category><category>印刷</category>
		<guid isPermaLink="false">http://www.ixdba.com/html/y2008/m04/214-book-reprint.html</guid>
		<description><![CDATA[这里，首先要感谢广大读者的支持与认可，该书第一次印刷到现在，2个多月的时间，就要准备第二次印刷了。在此期间，我也看到了很多读者反馈（包括读者书评与读者来信），他们对本书的... ]]></description>
			<content:encoded><![CDATA[<p style="margin: 0cm 0cm 0pt" class="MsoNormal">这里，首先要感谢广大读者的支持与认可，该书第一次印刷到现在，2个多月的时间，就要准备第二次印刷了。在此期间，我也看到了很多读者反馈（包括读者书评与读者来信），他们对本书的肯定，让我深表感动。本书在写作与印刷过程中，也出现了部分的错误，感谢广大读者通过来信，或者是在我的网站<a href="http://www.ixdba.com">www.ixdba.com</a>上留言指出了这些错误。本书在第二次印刷时会修正这些错误。</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">作为本书的作者，当然更希望广大的读者能从本书中获得他们想要的知识，并能帮助他们获得自己的成功。高可用性，在未来的一些年中，也将是越来越被引起重视的技术。需要强调的是，高可用性不仅仅局限在一两个技术上面，它应当是一个范畴，包括高可用的规划与设计，建设与实施，管理与维护，等等。</p>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">正因为高可用的范围如此广泛，所以本书所铺设的内容也特别之多。也有读者反映，因为内容太多，而在具体的细节内容上面，没有过分深入地进行介绍。这个问题其实与本书的写作规划有关，当初就是从如下三个方面来规划本书的：</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">（1）扩充视野</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">现在不管是国内还是国外，能独立管理从最底层的存储、主机、数据库，到支持最上层的应用产品设计的个人与团队是很少的，而我们团队就可以接触到以上相关技术。接触的东西越多，视野其实就越开阔，能看到的问题也越多，所以，在整个高可用性环境方面，我希望大家能从整体上去考虑，并了解影响到系统高可用性的有哪些东西。</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">随着科技的日新月易，传统企业应用与互联网应用开始产生越来越多的差异：传统的企业应用更关注于单个数据库（或数据库集群）的处理能力以及系统硬件本身的可靠性；而互联网应用，由于分布系统的大规模出现，可以使用普通的硬件设备（如PC Server）来实现大规模冗余，通过廉价的设备也可以达到整个系统的高可用性（如Google与Amazon在这方面就做的很不错）。所以，当在互联网应用中评价系统压力时，不再是单纯地评估数据库的处理能力，而是评估整个系统的处理能力，因为数据可能不存在于任何传统的数据库中，DBA也不再仅仅是数据库管理人员，而有可能是数据管理人员。</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">很难说，互联网技术以后就不影响传统企业现有的技术，广泛的了解与对比，是本书的目的之一。</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">（2）拓展思路</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">在写作本书之前，我就已经跟非常多的厂家及很多服务提供商打过交道，经常遇到其销售人员把自己的产品说成金条，把别人的产品贬低为稻草的情况。如我在刚开始接触硬件的时候，听到IBM介绍IBM的产品，就觉得它是最好的了；马上，HP过来介绍HP的产品，我又觉得HP是最好的。但是，如果经验多了，了解也多了，情况就不一样了，别人的吹捧已经不能影响我自己的思路。所以，在本书的前几章，介绍产品选择与构架选择时，也一直在表达这一个观点，即一定要有自己的思路与观点，不要让别人左右你自己的思想，否则销售人员很容易就影响你了（关于销售人员的技巧，大家有兴趣的话，可以看看《影响力》这本书）。</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">本书后面的一些章节，如数据迁移、监控体系，也是从构架设计的思路开始来描述具体的实现方法的。在信息化如此完善的今天，本身获得一两个方法是很简单的，但是，如果把方法系统化地规划起来，则是另外一种能力。好的思路，可以很快地帮大家获得成功，仅仅知道好的方法，不表示就有好的思路。</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">不要用简单的思维去看那些构架，不要仅仅是关注其中的技术而抛弃了思想，否则，我只能说你获得了皮毛而抛弃了精髓，成语&#8221;买椟还珠&#8221;也就是这个意思。</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">（3）获得经验</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">因为很多人认为高可用性技术就是几个技术那么简单，所以他们理解的Oracle高可用就是RAC技术与Data guard技术。而高可用性的管理与维护，有时候比高可用技术本身更值得关注与借鉴。因为技术本身，是在不断地变化过程中的。简单地说，如RAC的安装与配置，在不同的OS、不同的版本中，就有很大的差异，如RAC方面的bug，在不同的环境下也有差异。而维护与管理经验是通用的，也是最直接的、最宝贵的技术。</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">本书的一些案例，操作使用方法，维护经验与优化经验其实都是高可用经验的总结。通过学习这些经验，可以让读者在面对真正的高可用环境时，不至于惊慌失措。</p>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">所以本书</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">对于高级读者，可能不需要关注方法，而仅仅是关注自己不曾理解的领域与思路。</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">对于初级读者，如果有了一定的基础，一次看不懂没有关系，通过知识面的不断扩充，再看一次，可能会有新的收获。</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">对于未入门者，个人建议先了解一些基础知识，然后再看本书可能更有收获。</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">最后，再次感谢对本书提出宝贵意见与建议的读者们，也希望你们获得更大更多的成功。</p>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">陈吉平</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">2008年3月于杭州</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ixdba.com/html/y2008/m04/214-book-reprint.html/feed/</wfw:commentRss>
		</item>
		<item>
		<title>新书要第二次印刷了</title>
		<link>http://www.ixdba.com/html/y2008/m03/213-new-book-republication.html</link>
		<comments>http://www.ixdba.com/html/y2008/m03/213-new-book-republication.html#comments</comments>
		<pubDate>Mon, 10 Mar 2008 09:20:01 +0000</pubDate>
		<dc:creator>piner</dc:creator>
		
		<category><![CDATA[新书服务|Book]]></category>

		<category><![CDATA[所有|All Blogs]]></category>
<category>book</category><category>印刷</category>
		<guid isPermaLink="false">http://www.ixdba.com/html/y2008/m03/213-new-book-republication.html</guid>
		<description><![CDATA[根据出版社的信息，书库中的书已经不多了，马上就要第二次印刷了。第二次印刷可以修正掉已知的错误，所以质量将会比第一版更好。
一直比较忙，没有太关心书的事情，想不到卖得还是挺... ]]></description>
			<content:encoded><![CDATA[<p>根据出版社的信息，书库中的书已经不多了，马上就要第二次印刷了。第二次印刷可以修正掉已知的错误，所以质量将会比第一版更好。</p>
<p>一直比较忙，没有太关心书的事情，想不到卖得还是挺快的，从第一次印刷到现在，也就3个月的时间。</p>
<p>在此，非常感谢博文视点与出版社，非常感谢大家的支持，非常感谢广大读者提出的宝贵意见。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ixdba.com/html/y2008/m03/213-new-book-republication.html/feed/</wfw:commentRss>
		</item>
		<item>
		<title>互动数字电视，一个字——差</title>
		<link>http://www.ixdba.com/html/y2008/m03/212-hangzhou-digital-tv.html</link>
		<comments>http://www.ixdba.com/html/y2008/m03/212-hangzhou-digital-tv.html#comments</comments>
		<pubDate>Tue, 04 Mar 2008 07:15:54 +0000</pubDate>
		<dc:creator>piner</dc:creator>
		
		<category><![CDATA[生活|That's life]]></category>

		<category><![CDATA[所有|All Blogs]]></category>

		<category><![CDATA[生活逸事|life]]></category>
<category>电视</category><category>数字</category><category>杭州</category>
		<guid isPermaLink="false">http://www.ixdba.com/html/y2008/m03/212-hangzhou-digital-tv.html</guid>
		<description><![CDATA[刚买了电视，正好碰到数字电视在小区做推广，就办理了一个互动数字电视，每个月49元，说可以随意点播电影与电视剧。我比较讨厌看广告，就办理了一个，以为从此以后看电影电视就方便了... ]]></description>
			<content:encoded><![CDATA[<p>刚买了电视，正好碰到数字电视在小区做推广，就办理了一个互动数字电视，每个月49元，说可以随意点播电影与电视剧。我比较讨厌看广告，就办理了一个，以为从此以后看电影电视就方便了。</p>
<p>安装的时候，发现互动数字电视是需要网通的网线的，我们家装修早，根本就没有布网线，忍痛走了一根明线（我家第一根明线），为此还在墙上打了一个洞。</p>
<p>真正开通的时候我才发现，能免费点播的电影、电视是少之又少，而且都是老掉牙或者根本不好看的。好看一些的电影与电视还是需要另外交费的，如电影基本要5块钱一部，电视要0.5元一集（一个100集的电视剧，50块钱就没有了）。我随便点了一个收费的进去不到10s就退出来了，查了下详单，费用就已经收进去了，看样子在收费上是绝对的不含糊啊。</p>
<p>早知道如此，我办个啥的互动数字电视，还不如从网上下载下来，直接拿移动硬盘接在电视上就可以看了（我的电视支持USB的移动设备，基本支持所有的播放格式），还一分钱都不用花。</p>
<p>互动数字电视，我算是上了你的当。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ixdba.com/html/y2008/m03/212-hangzhou-digital-tv.html/feed/</wfw:commentRss>
		</item>
		<item>
		<title>读者来信：piner的书《构建oracle高可用环境》读后感</title>
		<link>http://www.ixdba.com/html/y2008/m02/211-book-reader-opinion.html</link>
		<comments>http://www.ixdba.com/html/y2008/m02/211-book-reader-opinion.html#comments</comments>
		<pubDate>Wed, 27 Feb 2008 10:12:23 +0000</pubDate>
		<dc:creator>piner</dc:creator>
		
		<category><![CDATA[新书服务|Book]]></category>

		<category><![CDATA[所有|All Blogs]]></category>
<category>blog</category><category>读者</category>
		<guid isPermaLink="false">http://www.ixdba.com/html/y2008/m02/211-book-reader-opinion.html</guid>
		<description><![CDATA[很感谢这些读者对我，以及这本书的肯定，非常感谢。来信内容也可以参考：
http://blog.csdn.net/yzsind/archive/2008/02/27/2124819.aspx
piner的书《构建oracle高可用环境》一出来就看到了，由于还有几本书... ]]></description>
			<content:encoded><![CDATA[<p>很感谢这些读者对我，以及这本书的肯定，非常感谢。来信内容也可以参考：</p>
<p><a target="_blank" href="http://blog.csdn.net/yzsind/archive/2008/02/27/2124819.aspx" title="读者反馈">http://blog.csdn.net/yzsind/archive/2008/02/27/2124819.aspx</a></p>
<p>piner的书《构建oracle高可用环境》一出来就看到了，由于还有几本书未读完，所以没有立即买，但是建议了同事去买来看看，春节前两天买到了。由于对书的内容及大师的景仰，所以就先看了。春节放假后回到老家，也把书带回家了看了。在春节期间，我们那刚好全县停电，感觉基本什么都做不了，除了睡觉，就是吃饭了。所以自然春节几天一直读这本书，感觉越看越深入，在读的过程中感觉非常流畅，感觉是一个大师在旁边一直介绍似的。基本上三天就看完了一半，上班后又接着看，花了一个星期的晚上时间看完，收益非浅啊。</p>
<p>这本书是介绍了大部份高可用性ORACLE配置及管理的知识，包括主机、存储、安全、灾容、RAC、StandBy、Stream、物化视图、FlashBack、备份、数据迁移、优化、在线维护、监控等等，基本上都全了。里面的理论架构介绍不多，但很实用，实践指导性非常强，脚本及案例都很直观并非常具有说服力，让人看得比较轻松，也感觉到大师的ORACLE功底之深及知识之广。</p>
<p>虽然这是一本DBA管理方面主题的书，但作为一名软件架构师或系统分析师，感觉自己在数据库架构设计方面又有了新的认识。</p>
<p>系统监控也长见识了。对数据存储及主机方面也增长了许多见识，对一些高端的存储也有了新的了解。对高可用性方面有了新的认识，以前我们开发的系统虽然称是7*24的，但实际上基本上是7*8小时的要求，所以对高可用性也没有那么深入，理解也不深入，看了书后深深感觉到7*24*365小时服务的可靠性要求。对于7*8小时的应用基本上数据库结构更新都是考虑越方便越好，因为可以有一晚上的时间给你更新。以前对于oralce11g的新特性都了解过，感觉对自己意义不大，不过看过书后才恍然大悟，发现11g基本上每个更新在高可用性方面都有重大意义。</p>
<p>现在国内的计算机技术书每年都有很多，但感觉大部份都是重复作品，从软件的参考手册中COPY，源代码及软件截图一大堆，一本书下来8,9百页，实际作者自己的内容不过100页。oracle方面的书也是如此，看过许多，除了eygle的几本书外，其它的大部份如此，不过在我印象最深的，看得最投入的就是去年看的TOM的《oracle9i/10g编程艺术》，和这次看到了piner的《构建oracle高可用环境》，这两本是我看得最舒服的书了。</p>
<p>在这里也谢谢piner献给我们ORALCE技术人员这么好的礼物！！！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ixdba.com/html/y2008/m02/211-book-reader-opinion.html/feed/</wfw:commentRss>
		</item>
		<item>
		<title>新书代码服务</title>
		<link>http://www.ixdba.com/html/y2008/m02/209-book-code-service.html</link>
		<comments>http://www.ixdba.com/html/y2008/m02/209-book-code-service.html#comments</comments>
		<pubDate>Sat, 23 Feb 2008 05:30:58 +0000</pubDate>
		<dc:creator>piner</dc:creator>
		
		<category><![CDATA[新书服务|Book]]></category>

		<category><![CDATA[所有|All Blogs]]></category>

		<category><![CDATA[代码服务|code]]></category>
<category>book</category><category>代码</category>
		<guid isPermaLink="false">http://www.ixdba.com/html/y2008/m02/209-book-code-service.html</guid>
		<description><![CDATA[新书出来好久了，因为我也一直比较忙，代码服务一直还没有跟上。这里很感谢广大读者的支持与理解，今天我将把本书的代码整理出来并共享给广大读者。
第1章
P12
Piner@10gR2&#62;select f,b from (
... ]]></description>
			<content:encoded><![CDATA[<p>新书出来好久了，因为我也一直比较忙，代码服务一直还没有跟上。这里很感谢广大读者的支持与理解，今天我将把本书的代码整理出来并共享给广大读者。</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><strong>第1章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P12</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">Piner@10gR2&gt;select f,b from (</li>
<li>&nbsp;&nbsp; &nbsp; select dbms_rowid.rowid_relative_fno(rowid) f, </li>
<li>&nbsp; 　　　　　 dbms_rowid.rowid_block_number(rowid) b</li>
<li>&nbsp;&nbsp; &nbsp; from test) group by f,b;</li>
<li>&nbsp;</li>
<li>Piner@10gR2&gt;select file#,dbablk,tch from x$bh where obj=</li>
<li>&nbsp;&nbsp; &nbsp;(select data_object_id from dba_objects </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;where owner='PINER' and object_name='TEST')</li>
<li>&nbsp;&nbsp; &nbsp;order by dbablk;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P15</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">select count(*) from v$bh where objd=</li>
<li>(select data_object_id from dba_objects </li>
<li>&nbsp; where owner='PINER' and object_name='TEST')</li>
<li>&nbsp; and status !='free'</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P16</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">select /*+ rule */ owner,object_name from dba_objects </li>
<li>where data_object_id in</li>
<li>&nbsp; (select obj from </li>
<li>&nbsp; (select obj from x$bh order by tch desc) </li>
<li>&nbsp;&nbsp; &nbsp;where rownum &lt; 11) ;</li>
<li>&nbsp;</li>
<li>SQL&gt; select tch, flag,</li>
<li>&nbsp;&nbsp; &nbsp;	decode(bitand(flag,1), 0, 'N', 'Y') dirty,</li>
<li>&nbsp;&nbsp; &nbsp;	decode(bitand(flag,16), 0, 'N', 'Y') temp,</li>
<li>&nbsp;&nbsp; &nbsp;	decode(bitand(flag,1536), 0, 'N', 'Y') ping,</li>
<li>&nbsp;&nbsp; &nbsp;	decode(bitand(flag,16384), 0, 'N', 'Y') stale,</li>
<li>&nbsp;&nbsp; &nbsp;	decode(bitand(flag,65536), 0, 'N', 'Y') direct,</li>
<li>&nbsp;&nbsp; &nbsp;	decode(bitand(flag,1048576), 0, 'N', 'Y') new</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;from&nbsp; &nbsp; &nbsp;x$bh</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;where dbablk = 12</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;and obj=11835</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;and tch&gt;0;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P38</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">select dbms_rowid.rowid_object('AAAAeNAADAAAAWZAAA') data_object_id#, </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;dbms_rowid.rowid_relative_fno('AAAAeNAADAAAAWZAAA') rfile#, </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;dbms_rowid.rowid_block_number('AAAAeNAADAAAAWZAAA') block#, </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;dbms_rowid.rowid_row_number('AAAAeNAADAAAAWZAAA') row# from dual;</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"> <strong>第2章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"> P77</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">#nohup ./orion -run advanced -testname mytest -num_disks 96 -size_small 8 -size_large 8 -type rand &amp;</li>
<li>&nbsp;</li>
<li>#nohup ./orion -run advanced -testname mytest -num_disks 96 -size_small 1024 -size_large 1024 -type seq &amp;</li>
<li>&nbsp;</li>
<li>#nohup ./orion -run advanced -testname mytest -num_disks 96 -size_small 8 -size_large 128 -matrix col -num_small 500 -type rand &amp;</li>
<li>&nbsp;</li>
<li>#nohup ./orion -run advanced -testname mytest -num_disks 96 -size_small 8 -size_large 128 -matrix detailed -type rand &amp;</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"> <strong>第4章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P161</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">rac1.local_listener='(address=(protocol=tcp)(host=dbrac01)(port=1521)) ' </li>
<li>rac1.remote_listener='(address=(protocol=tcp)(host=dbrac02)(port=1521)) ' </li>
<li>rac2.local_listener='(address=(protocol=tcp)(host=dbrac02)(port=1521)) ' </li>
<li>rac2.remote_listener='(address=(protocol=tcp)(host=dbrac01)(port=1521)) '</li>
<li>&nbsp;</li>
<li>$ more tnsnames.ora </li>
<li># tnsnames.ora.Network Configuration File</li>
<li>rac=</li>
<li>&nbsp; (description=</li>
<li>&nbsp;&nbsp; (load_balance=on)</li>
<li>&nbsp;&nbsp; (failover=on)</li>
<li>&nbsp;&nbsp; (address_list=</li>
<li>&nbsp;&nbsp; &nbsp;(address=(protocol=tcp)(host=dbrac01)(port=1521))</li>
<li>&nbsp;&nbsp; &nbsp;(address=(protocol=tcp)(host=dbrac02)(port=1521)))</li>
<li>&nbsp;&nbsp; (connect_data=</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(service_name=rac)))</li>
<li>&nbsp;</li>
<li>[oracle@dbtest admin]$ more test.sh</li>
<li>#!/bin/sh</li>
<li>sqlplus &quot;test/test@rac&quot; &lt;&lt;EOF</li>
<li>select instance_name from v\$instance;</li>
<li>&nbsp;</li>
<li>exit</li>
<li>EOF</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P162</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">Listeners_rac =</li>
<li>&nbsp; (address_list =</li>
<li>&nbsp;&nbsp; &nbsp;(address = (protocol = tcp)(host =dbrac01-vip)(port = 1521))</li>
<li>&nbsp;&nbsp; &nbsp;(address = (protocol = tcp)(host =dbrac02-vip)(port = 1521))</li>
<li>&nbsp;&nbsp; &nbsp;(address = (protocol = tcp)(host =dbrac03-vip)(port = 1521))</li>
<li>&nbsp;&nbsp; &nbsp;(address = (protocol = tcp)(host =dbrac04-vip)(port = 1521))</li>
<li>&nbsp; )</li>
<li>&nbsp;</li>
<li>Rac =</li>
<li>&nbsp; (description =</li>
<li>&nbsp;&nbsp; &nbsp;(load_balance = on)</li>
<li>&nbsp;&nbsp; &nbsp;(address = (protocol = tcp)(host = dbrac01-vip)(port = 1521))</li>
<li>&nbsp;&nbsp; &nbsp;(address = (protocol = tcp)(host = dbrac02-vip)(port = 1521))</li>
<li>&nbsp;&nbsp; &nbsp;(address = (protocol = tcp)(host = dbrac03-vip)(port = 1521))</li>
<li>&nbsp;&nbsp; &nbsp;(address = (protocol = tcp)(host = dbrac04-vip)(port = 1521))</li>
<li>&nbsp;&nbsp; &nbsp;(connect_data =</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; (server = dedicated)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; (service_name = rac)</li>
<li>&nbsp;&nbsp; &nbsp;)</li>
<li>&nbsp; )</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P164</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">rac=</li>
<li>&nbsp;(description=</li>
<li>(load_balance=on)</li>
<li>&nbsp; (failover=on)</li>
<li>&nbsp; (address_list=</li>
<li>&nbsp;&nbsp; (address=(protocol=tcp)(host=dbtest)(port=1521))</li>
<li>&nbsp;&nbsp; (address=(protocol=tcp)(host=dbtest)(port=1522)))</li>
<li>&nbsp; (connect_data=</li>
<li>&nbsp;&nbsp; &nbsp; (service_name=rac)</li>
<li>&nbsp;&nbsp; &nbsp; (failover_mode=(type=select)(method=basic))</li>
<li>&nbsp; ))</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P183</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt;create diskgroup dgroup1</li>
<li>	 Normal reduadancy</li>
<li>	 failgroup controller1 </li>
<li>	 disk&nbsp; '/devices/diska1', '/devices/diska2','/devices/diska3','/devices/diska4',</li>
<li>	 failgroup controller2 </li>
<li>	 disk '/devices/diskb1', '/devices/diskb2', '/devices/diskb3', '/devices/diskb4';</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P187</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">create database orcl</li>
<li>	controlfile reuse</li>
<li>	logfile&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'+dgroup1/redo1' size 100M</li>
<li>	datafile&nbsp; &nbsp; &nbsp; &nbsp; '+dgroup1/system' size 1G</li>
<li>	sysaux datafile&nbsp; '+dgroup1/sysaux' size&nbsp; 2G</li>
<li>	default temporary tablespace temp</li>
<li>	tempfile&nbsp; &nbsp; &nbsp; &nbsp; '+dgroup1/temp' size&nbsp; 8G</li>
<li>	undo tablespace undo</li>
<li>	datafile&nbsp; &nbsp; &nbsp; &nbsp; '+dgroup1/rollback' size 8G;</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"> <strong>第5章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P205</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">db_unique_name=pridb</li>
<li>log_archive_config='DG_CONFIG=(pridb,stbdb)'</li>
<li>log_archive_dest_1='LOCATION=/arc/archive/test/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=pridb' </li>
<li>log_archive_dest_state_1=ENABLE</li>
<li>log_archive_dest_2='SERVICE=standby_test VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)&nbsp; DB_UNIQUE_NAME=stb_db'</li>
<li>log_archive_dest_state_2=ENABLE</li>
<li>&nbsp;</li>
<li>SQL&gt;alter database add standby logfile </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;group 4 ('/u01/oracle/oradata/tbdb/stdy_redo04.log') size 102400K,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;group 5 ('/u01/oracle/oradata/tbdb/stdy_redo05.log') size 102400K,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;group 6 ('/u01/oracle/oradata/tbdb/stdy_redo06.log') size 102400K,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;group 7 ('/u01/oracle/oradata/tbdb/stdy_redo07.log') size 102400K;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P208</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">$more removearchive.sh</li>
<li>#!/usr/bin/ksh</li>
<li># creator: piner</li>
<li># function: clear archive log of standby database if it had applied</li>
<li># usage: crontab on standby</li>
<li># last modify: 2007-10-10 create</li>
<li>&nbsp;</li>
<li>#env variable</li>
<li>export ORACLE_HOME=/u01/oracle/product/9.2</li>
<li>export HOME=/home/oracle</li>
<li>export PATH=$PATH:$ORACLE_HOME/bin</li>
<li>export ORACLE_SID=test</li>
<li>&nbsp;</li>
<li>#local variable</li>
<li>BDUMP=/u01/oracle/admin/${ORACLE_SID}/bdump</li>
<li>ALERT=$BDUMP/alert_${ORACLE_SID}.log</li>
<li>ALERTBAK=$BDUMP/alert_${ORACLE_SID}.log.bak</li>
<li>RMARC=$HOME/worksh/rmarchlog.sh</li>
<li>TMLOG=$HOME/logs/logtmp.log</li>
<li>&nbsp;</li>
<li>#get rm archivelog script，thread 1</li>
<li>grep &quot;Media Recovery Log&quot; $ALERT|grep 1_|sed '$d'|awk '{print $4}'|sed -e 's/^/rm /' &gt;&nbsp; $RMARC </li>
<li>grep &quot;Media Recovery Log&quot; $ALERT|grep 1_|sed -n '$p' &gt;&nbsp; $TMLOG</li>
<li>#if rac env,then thread 2</li>
<li>#grep &quot;Media Recovery Log&quot; $ALERT|grep 2_|sed '$d'|awk '{print $4}'|sed -e 's/^/rm /' &gt;&gt; $RMARC</li>
<li>#grep &quot;Media Recovery Log&quot; $ALERT|grep 2_|sed -n '$p' &gt;&gt; $TMLOG</li>
<li>&nbsp;</li>
<li>#start rm archive log</li>
<li>ksh $RMARC</li>
<li>&nbsp;</li>
<li>#clear alert log</li>
<li>cat $ALERT &gt;&gt; $ALERTBAK</li>
<li>cat $TMLOG &gt;&nbsp; $ALERT</li>
<li>&nbsp;</li>
<li>#rm tmp file</li>
<li>rm -f $RMARC</li>
<li>rm -f $TMLOG</li>
<li>&nbsp;</li>
<li>echo &quot;DB done&quot;</li>
<li>&nbsp;</li>
<li>ARCHIVE_DIR=/arc/archive/test</li>
<li>#find $ ARCHIVE_DIR -name &quot;*.arc&quot; -ctime +3 -exec rm {} \;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P209</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">#!/bin/ksh</li>
<li># creator: piner</li>
<li># function: check standby archive send and applied </li>
<li># usage: crontab on standby</li>
<li># last modify: piner 2005-4-20 create</li>
<li>&nbsp;</li>
<li>#environment variable</li>
<li>export ORACLE_SID=test</li>
<li>&nbsp;</li>
<li>export ORACLE_HOME=/u01/oracle/product/9.2</li>
<li>export PATH=$ORACLE_HOME/bin:$PATH</li>
<li>export NLS_LANG=american_america.zhs16gbk</li>
<li>&nbsp;</li>
<li>#local variable</li>
<li>LOGFILE=/home/oracle/logs/logstatus.log</li>
<li>SQLPLUS=$ORACLE_HOME/bin/sqlplus</li>
<li>DATE=`date +%Y-%m-%d:%H:%M:%S`</li>
<li>dbname=`hostname`</li>
<li>&nbsp;</li>
<li>#monitor value</li>
<li>appdoff=0.5</li>
<li>sendoff=0.02</li>
<li>&nbsp;</li>
<li>#check database status</li>
<li>$SQLPLUS /nolog &lt;&lt;EOF</li>
<li>connect / as sysdba</li>
<li>spool $LOGFILE</li>
<li>&nbsp; SELECT status FROM v\$instance;</li>
<li>spool off</li>
<li>exit</li>
<li>EOF</li>
<li>&nbsp;</li>
<li>sleep 1</li>
<li>if [ -f $LOGFILE ] ; then</li>
<li>&nbsp; STATUS=`egrep -i &quot;(OPEN|MOUNT)&quot; $LOGFILE|wc -l`</li>
<li>&nbsp; echo $STATUS</li>
<li>else</li>
<li>&nbsp; touch $LOGFILE</li>
<li>&nbsp; echo &quot;log file not exists&quot; &gt; $LOGFILE</li>
<li>fi</li>
<li>&nbsp;</li>
<li>if [ $STATUS -eq 0 ] ; then</li>
<li>&nbsp;&nbsp; &nbsp;mesglog=&quot;$dbname standby status error,db not mount or open!&quot;</li>
<li>&nbsp;&nbsp; &nbsp;##Standby没有open或者是mount</li>
<li>&nbsp;&nbsp; &nbsp;##发送邮件，关于发送邮件的方法，参考本书第16章</li>
<li>&nbsp;&nbsp; &nbsp;exit 1</li>
<li>fi</li>
<li>&nbsp;</li>
<li>#check archive log applied</li>
<li>$SQLPLUS /nolog &lt;&lt;EOF</li>
<li>connect / as sysdba</li>
<li>spool $LOGFILE</li>
<li>&nbsp;select decode(Sign(max(Next_time) - (sysdate - $appdoff)),-1,'false','true') from v\$archived_log t</li>
<li>&nbsp;&nbsp; where applied = 'YES' and first_time &gt;sysdate-1;</li>
<li>&nbsp;select thread#,sequence#, to_char(next_time,'yyyy-mm-dd hh24:mi:ss') log_time,applied from v\$archived_log t</li>
<li>&nbsp;&nbsp; where applied = 'NO' and first_time&gt;sysdate-1</li>
<li>&nbsp; order by sequence#;</li>
<li>spool off</li>
<li>exit</li>
<li>EOF</li>
<li>&nbsp;</li>
<li>APPSTATUS=`grep -i &quot;false&quot; $LOGFILE|grep -v &quot;'false','true'&quot;|wc -l`</li>
<li>if [ $APPSTATUS -ge 1 ] ; then</li>
<li>&nbsp;&nbsp; &nbsp;##应用日志错误</li>
<li>&nbsp;&nbsp; &nbsp;##发送邮件，关于发送邮件的方法，参考本书第16章</li>
<li>fi</li>
<li>&nbsp;</li>
<li>#check archive log sended</li>
<li>$SQLPLUS /nolog &lt;&lt;EOF</li>
<li>connect / as sysdba</li>
<li>spool $LOGFILE</li>
<li>&nbsp;select decode(Sign(max(next_time) - (sysdate - $sendoff)),-1,'false','true') from v\$archived_log t</li>
<li>&nbsp;&nbsp; where first_time&gt;sysdate-1;</li>
<li>&nbsp;select max(sequbnce#) max_sequbnce#,to_char(max(next_time),'yyyy-mm-dd hh24:mi:ss') log_time from v\$archived_log t</li>
<li>&nbsp;&nbsp; where first_time&gt;sysdate-1;</li>
<li>spool off</li>
<li>exit</li>
<li>EOF</li>
<li>&nbsp;</li>
<li>SENDSTATUS=`grep -i &quot;false&quot; $LOGFILE|grep -v &quot;'false','true'&quot;|wc -l`</li>
<li>if [ $SENDSTATUS -ge 1 ] ; then</li>
<li>&nbsp;&nbsp; &nbsp;##发送日志错误</li>
<li>&nbsp;&nbsp; &nbsp;##发送邮件，关于发送邮件的方法，参考本书第16章</li>
<li>fi</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P214</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">LISTENER_PRI =</li>
<li>&nbsp; (DESCRIPTION_LIST =</li>
<li>&nbsp;&nbsp; &nbsp;(DESCRIPTION =</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(ADDRESS_LIST =</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;(ADDRESS = (PROTOCOL = TCP)(HOST = primary_db)(PORT = 1521))</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;)</li>
<li>&nbsp;&nbsp; &nbsp;)</li>
<li>&nbsp; )</li>
<li>&nbsp;</li>
<li>SID_LIST_LISTENER_PRI =</li>
<li>&nbsp; (SID_LIST =</li>
<li>&nbsp;&nbsp; &nbsp;(SID_DESC =</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(GLOBAL_DBNAME = test)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(ORACLE_HOME = /u01/oracle/product/9.2)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(SID_NAME = test)</li>
<li>&nbsp;&nbsp; &nbsp;)</li>
<li>&nbsp; )</li>
<li>&nbsp;</li>
<li>LISTENER_STB =</li>
<li>&nbsp; (DESCRIPTION_LIST =</li>
<li>&nbsp;&nbsp; &nbsp;(DESCRIPTION =</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(ADDRESS_LIST =</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;(ADDRESS = (PROTOCOL = TCP)(HOST = standby_db)(PORT = 1522))</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;)</li>
<li>&nbsp;&nbsp; &nbsp;)</li>
<li>&nbsp; )</li>
<li>&nbsp;</li>
<li>SID_LIST_LISTENER_STB =</li>
<li>&nbsp; (SID_LIST =</li>
<li>&nbsp;&nbsp; &nbsp;(SID_DESC =</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(GLOBAL_DBNAME = test)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(ORACLE_HOME = /u01/oracle/product/9.2)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(SID_NAME = test)</li>
<li>&nbsp;&nbsp; &nbsp;)</li>
<li>&nbsp; )</li>
<li>&nbsp;</li>
<li>test = </li>
<li>(DESCRIPTION = </li>
<li>&nbsp;&nbsp; &nbsp; (failover = on ) </li>
<li>&nbsp;&nbsp; &nbsp; (ADDRESS_LIST = </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(ADDRESS = (PROTOCOL = TCP)(HOST = primary_db)(PORT = 1521)) </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(ADDRESS = (PROTOCOL = TCP)(HOST = standby_db)(PORT = 1521)) </li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; ) </li>
<li>&nbsp;&nbsp; (CONNECT_DATA = </li>
<li>&nbsp;&nbsp; &nbsp; (SID = test) </li>
<li>&nbsp;&nbsp; &nbsp;) </li>
<li>&nbsp; )</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><strong>第6章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P238</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt;create tablespace streams_tbs datafile 'file_name' size 500M;</li>
<li>&nbsp;</li>
<li>SQL&gt; create user strmadmin identified by password</li>
<li>&nbsp; 2&nbsp; default tablespace streams_tbs</li>
<li>&nbsp; 3&nbsp; quota unlimited on streams_tbs;</li>
<li>&nbsp;</li>
<li>SQL&gt; grant dba to strmadmin;</li>
<li>&nbsp;</li>
<li>SQL&gt; connect strmadmin/password</li>
<li>SQL&gt; create database link dbdest.net connect to strmadmin </li>
<li>2&nbsp; &nbsp;identified by password using 'dest_db';</li>
<li>&nbsp;</li>
<li>SQL&gt; connect strmadmin/password</li>
<li>SQL&gt; create database link dbsour.net connect to strmadmin </li>
<li>2&nbsp; &nbsp;identified by password using 'source_db';</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P240</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt;connect strmadmin/test</li>
<li>SQL&gt; declare</li>
<li>&nbsp; 2&nbsp; empty_tbs dbms_streams_talespace_adm.tablespace_set;</li>
<li>&nbsp; 3&nbsp; begin</li>
<li>&nbsp; 4&nbsp; &nbsp; dbms_streams_adm.pre_instantiation_setup(</li>
<li>&nbsp; 5&nbsp; &nbsp; maintain_mode =&gt; 'GLOBAL',</li>
<li>&nbsp; 6&nbsp; &nbsp; tablespace_names =&gt; empty_tbs,</li>
<li>&nbsp; 7&nbsp; &nbsp; source_database =&gt; 'dbsour.net',</li>
<li>&nbsp; 8&nbsp; &nbsp; destination_database =&gt; 'dbdest.net',</li>
<li>&nbsp; 9&nbsp; &nbsp; perform_actions =&gt; true,</li>
<li>&nbsp;10&nbsp; &nbsp; bi_directional =&gt; true,</li>
<li>&nbsp;11&nbsp; &nbsp; include_ddl =&gt; true,</li>
<li>&nbsp;12&nbsp; &nbsp; start_processes =&gt; true,</li>
<li>&nbsp;13&nbsp; &nbsp; exclude_schemas =&gt; NULL,</li>
<li>&nbsp;14&nbsp; &nbsp; exclude_flags =&gt; dbms_streams_adm.exclude_flags_unsupported +</li>
<li>&nbsp;15&nbsp; &nbsp; dbms_streams_adm.exclude_flags_dml +</li>
<li>&nbsp;16&nbsp; &nbsp; dbms_streams_adm.exclude_flags_ddl);</li>
<li>&nbsp;17&nbsp; end;</li>
<li>&nbsp;18&nbsp; /</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P242</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt; set serveroutput on size 1000000</li>
<li>SQL&gt; declare</li>
<li>2&nbsp; &nbsp; until_scn number;</li>
<li>&nbsp; 3&nbsp; begin</li>
<li>&nbsp; 4&nbsp; &nbsp; &nbsp;until_scn:= dbma_flashback.get_system_change_number;</li>
<li>&nbsp; 5&nbsp; &nbsp; &nbsp;dbms_output.put_line('Until SCN: ' || until_scn);</li>
<li>&nbsp; 6&nbsp; end;</li>
<li>&nbsp; 7&nbsp; /</li>
<li>&nbsp;</li>
<li>RMAN&gt; run</li>
<li>2&gt; {</li>
<li>3&gt;&nbsp; &nbsp; set until scn 533910;</li>
<li>4&gt;&nbsp; &nbsp; duplicate target database to dbdest nofilenamecheck open restricted;</li>
<li>5&gt; }</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P244</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt;DECLARE</li>
<li>&nbsp; 2&nbsp; &nbsp; &nbsp;empty_tbs dbms_streams_tablespace_adm.tablespace_set;</li>
<li>&nbsp; 3&nbsp; BEGIN</li>
<li>&nbsp; 4&nbsp; &nbsp; &nbsp;dbms_streams_adm.post_instantiation_setup (</li>
<li>&nbsp; 5&nbsp; &nbsp; &nbsp;maintain_mode =&gt; 'GLOBAL',</li>
<li>&nbsp; 6&nbsp; &nbsp; &nbsp;tablespace_names =&gt; empty_tbs,</li>
<li>&nbsp; 7&nbsp; &nbsp; &nbsp;source_database =&gt; 'dbsour.net',</li>
<li>&nbsp; 8&nbsp; &nbsp; &nbsp;destination_database =&gt; 'dbdest.net',</li>
<li>&nbsp; 9&nbsp; &nbsp; &nbsp;perform_actions =&gt; true,</li>
<li>&nbsp;10&nbsp; &nbsp; &nbsp;bi_directional =&gt; true,</li>
<li>&nbsp;11&nbsp; &nbsp; &nbsp;include_ddl =&gt; true,</li>
<li>&nbsp;12&nbsp; &nbsp; &nbsp;start_processes =&gt; true,</li>
<li>&nbsp;13&nbsp; &nbsp; &nbsp;instantiation_scn =&gt; 533909,</li>
<li>&nbsp;14&nbsp; &nbsp; &nbsp;exclude_schemas =&gt; NULL,</li>
<li>&nbsp;15&nbsp; &nbsp; &nbsp;exclude_flags =&gt; dbms_streams_adm.exclude_flasgs_unsupported +</li>
<li>&nbsp;16&nbsp; &nbsp; &nbsp;dbms_streams_adm.exclude_flags_dml + </li>
<li>&nbsp;17&nbsp; &nbsp; &nbsp;dbms_streams_adm.exclude_flags_ddl);</li>
<li>&nbsp;18&nbsp; end;</li>
<li>&nbsp;19&nbsp; /</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P245</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">STRMADM@dest&gt;begin</li>
<li>&nbsp; 2&nbsp; dbms_streams_adm.maintain_global(</li>
<li>&nbsp; 3&nbsp; &nbsp; &nbsp;source_directory_object&nbsp; &nbsp; &nbsp; =&gt; 'DIR_SOURCE',</li>
<li>&nbsp; 4&nbsp; &nbsp; &nbsp;destination_directory_object =&gt; 'DIR_DEST',</li>
<li>&nbsp; 5&nbsp; &nbsp; &nbsp;source_database&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; 'dbsour.test',</li>
<li>&nbsp; 6&nbsp; &nbsp; &nbsp;destination_database&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=&gt; 'dbdest.test',</li>
<li>&nbsp; 7&nbsp; &nbsp; &nbsp;perform_actions&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; true,</li>
<li>&nbsp; 8&nbsp; &nbsp; &nbsp;dump_file_name&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=&gt; 'streams_rep.dmp',</li>
<li>&nbsp; 9&nbsp; &nbsp; &nbsp;bi_directional&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=&gt; false,</li>
<li>&nbsp;10&nbsp; &nbsp; &nbsp;include_ddl&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; true,</li>
<li>&nbsp;11&nbsp; &nbsp; &nbsp;instantiation&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; dbms_streams_adm.instantiation_full);</li>
<li>&nbsp;12&nbsp; end;</li>
<li>&nbsp;13&nbsp; /</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P246</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">declare</li>
<li>tables dbms_utility.uncl_apply;</li>
<li>begin</li>
<li>tables(1) := 'piner.test1';</li>
<li>tables(2) := 'piner.test2';</li>
<li>tables(3) := 'piner.test3';</li>
<li>tables(4) := 'piner.test4';</li>
<li>dbms_streams_adm.maintain_tables(</li>
<li>table_names =&gt; tables,</li>
<li>source_directory_object =&gt; NULL,</li>
<li>destination_directory_object =&gt; NULL,</li>
<li>source_database =&gt; 'dbsour.net',</li>
<li>&nbsp;</li>
<li>destination_database =&gt; 'dbdest.net',</li>
<li>perform_actions =&gt; false,</li>
<li>script_name =&gt; 'configure_rep.sql',</li>
<li>script_directory_object =&gt; 'SCRIPT_DIRECTORY',</li>
<li>bi_directional =&gt; false,</li>
<li>include_ddl =&gt; false,</li>
<li>instantiation =&gt; dbms_streams_adm.instantiation_table_network );</li>
<li>end;</li>
<li>/</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P247</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt;begin</li>
<li>&nbsp; 2&nbsp; &nbsp; dbms_capture_adm.set_parameter(</li>
<li>&nbsp; 3&nbsp; &nbsp; &nbsp; capture_name =&gt; 'PINER$CAP',</li>
<li>&nbsp; 4&nbsp; &nbsp; &nbsp; parameter&nbsp; &nbsp; =&gt; 'downstream_real_time_mine',</li>
<li>&nbsp; 5&nbsp; &nbsp; &nbsp; value&nbsp; &nbsp; &nbsp; &nbsp; =&gt; 'y');</li>
<li>&nbsp; 6&nbsp; end;</li>
<li>&nbsp; 7&nbsp; /</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P249</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt;col forward_block heading 'Forward Block' format A50</li>
<li>SQL&gt;col forward_block_dblink heading 'Forward Block|Database Link' format A13</li>
<li>SQL&gt;col status heading 'Status' format A12</li>
<li>SQL&gt;set long 10000</li>
<li>SQL&gt;select forward_block,forward_block_dblink,status</li>
<li>2&nbsp; from dba_recoverable_script_blocks</li>
<li>3&nbsp; where script_id = '39EDB8E5AB6CD5C3E040010A3D0552BE' </li>
<li>4&nbsp; and block_num = 7;&nbsp; &nbsp; </li>
<li>&nbsp;</li>
<li>SQL&gt;begin</li>
<li>2&nbsp; &nbsp; dbms_streams_adm.recover_operation(</li>
<li>3&nbsp; &nbsp; &nbsp; script_id =&gt; '39EDB8E5AB6CD5C3E040010A3D0552BE',</li>
<li>4&nbsp; &nbsp; &nbsp; operation_mode =&gt; 'FORWARD');</li>
<li>5&nbsp; &nbsp;end;</li>
<li>6&nbsp; &nbsp;/</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P250</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">begin</li>
<li>dbms_propagation_sdm.start_ propagation (</li>
<li>propagation_name =&gt; 'PROPAGATION$_195');</li>
<li>end;</li>
<li>/</li>
<li>&nbsp;</li>
<li>begin</li>
<li>&nbsp;&nbsp; &nbsp;dbms_apply_sdm.set_parameter(apply_name=&gt;'APPLY$_DBSOUR_187',</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parameter=&gt;'disable_on_error',</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value=&gt;'N');</li>
<li>end;</li>
<li>/</li>
<li>&nbsp;</li>
<li>exec dbms_apply_sdm.start_apply(apply_name=&gt;'APPLY$_DBSOUR_187');</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P251</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">exec dbms_capture_adm.stop_capture(capture_name);</li>
<li>exec dbms_capture_adm.drop_capture(capture_name);</li>
<li>&nbsp;</li>
<li>exec dbms_propagation_adm.stop_propagation(propagation_name);</li>
<li>exec dbms_propagation_adm.drop_propagation(propagation_name);</li>
<li>&nbsp;</li>
<li>exec dbms_apply_adm.stop_apply(apply_name);</li>
<li>exec dbms_apply_adm.drop_apply(apply_name);</li>
<li>&nbsp;</li>
<li>exec dbms_streams_adm.remove_streams_configuration;</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><strong>第8章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P295</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">Piner@10gR2&gt; select versions_starttime, versions_endtime, versions_xid,</li>
<li>&nbsp; 2&nbsp; &nbsp; &nbsp; &nbsp; versions_operation, a,b</li>
<li>&nbsp; 3&nbsp; &nbsp; &nbsp; &nbsp; from test versions between timestamp minvalue and maxvalue</li>
<li>&nbsp; 4&nbsp; &nbsp; &nbsp; &nbsp; order by versions_starttime;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P298</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">13:25:41 Piner@10gR2&gt;select versions_xid, versions_operation</li>
<li>13:25:42&nbsp; &nbsp;2&nbsp; from test versions between timestamp</li>
<li>13:25:42&nbsp; &nbsp;3&nbsp; to_date('2007-08-27 13:21:56','yyyy-mm-dd hh24:mi:ss')</li>
<li>13:25:42&nbsp; &nbsp;4&nbsp; and MAXVALUE</li>
<li>13:25:42&nbsp; &nbsp;5&nbsp; WHERE versions_xid is not null</li>
<li>13:25:42&nbsp; &nbsp;6&nbsp; order by VERSIONS_STARTTIME;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P307</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">Piner@9iR2&gt;exec sys.dbms_logmnr.add_logfile(LogFileName=&gt;'/archive_log/archive/1_9.arc',options =&gt; dbms_logmnr.new);</li>
<li>PL/SQL procedure successfully completed.</li>
<li>&nbsp;</li>
<li>Piner@9iR2&gt;exec sys.dbms_logmnr.start_logmnr(Options =&gt; sys.dbms_logmnr.dict_from_online_catalog);</li>
<li>PL/SQL procedure successfully completed.</li>
<li>&nbsp;</li>
<li>Piner@9iR2&gt;exec sys.dbms_logmnr.add_logfile(LogFileName=&gt;'/archive_log/archive/1_10.arc');</li>
<li>&nbsp;</li>
<li>Piner@9iR2&gt;select t.SCN,t.TIMESTAMP,t.SEG_OWNER,t.OPERATION, </li>
<li>2&nbsp; t.SQL_REDO,t.SQL_UNDO </li>
<li>3&nbsp; from v$logmnr_contents t where t.SEG_NAME='TEST';</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P309</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">declare </li>
<li>&nbsp; mysql varchar2(4000); </li>
<li>&nbsp; num number :=0; </li>
<li>begin </li>
<li>&nbsp; for c_tmp in (select sql_undo from logmnr_contents where operation = 'DELETE') loop </li>
<li>&nbsp;&nbsp; &nbsp;--去掉语句结尾的分号，如果语句中本身有分号，则不能采用这个方法。 </li>
<li>&nbsp;&nbsp; &nbsp;mysql := replace(c_tmp,sql_undo,';',''); </li>
<li>&nbsp;&nbsp; &nbsp;execute immediate mysql; </li>
<li>&nbsp;&nbsp; &nbsp;num := num + 1; </li>
<li>&nbsp;&nbsp; &nbsp;if mod(num,1000)=0 then </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;commit; </li>
<li>&nbsp;&nbsp; &nbsp;end if; </li>
<li>&nbsp; end loop; </li>
<li>&nbsp; commit; </li>
<li>exception </li>
<li>&nbsp; when others then </li>
<li>&nbsp;&nbsp; --异常处理 </li>
<li>end;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P310</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt;select name,sequence#,dictionary_begin d_beg, dictionary_end d_end</li>
<li>&nbsp;&nbsp; from v$archived_log</li>
<li>&nbsp;&nbsp; where sequence# = (select max(sequence#) from v$archived_log</li>
<li>&nbsp;&nbsp; where dictionary_end = 'YES' and sequence# &lt;= 210);--或者是&gt;=210</li>
<li>&nbsp;</li>
<li>SQL&gt; select name,sequence#,dictionary_begin d_beg, dictionary_end d_end</li>
<li>&nbsp; from v$archived_log</li>
<li>&nbsp;&nbsp; where sequence# = (select max(sequence#) from v$archived_log</li>
<li>where dictionary_begin = 'YES' and sequence# &lt;= 208);</li>
<li>&nbsp;</li>
<li>exec dbms_logmnr.add_logfile(logfilename =&gt; '/usr/oracle/data/db1arch_1_210_482701534.dbf',options =&gt; dbms_logmnr.new);</li>
<li>exec dbms_logmnr.add_logfile(logfilename =&gt; '/usr/oracle/data/db1arch_1_208_482701534.dbf');</li>
<li>exec dbms_logmnr.add_logfile(logfilename =&gt; '/usr/oracle/data/db1arch_1_207_482701534.dbf');</li>
<li>&nbsp;</li>
<li>exec dbms_logmnr.start_logmnr(options =&gt;dbms_logmnr.dict_from_onlinr_catalog + dbms_logmnr.committed_data_only);</li>
<li>&nbsp;</li>
<li>SQL&gt;alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS';</li>
<li>exec dbms_logmnr.start_logmnr(dictfilename =&gt; '/oracle/database/dictionary.ora',</li>
<li>&nbsp;&nbsp; starttime =&gt; '2007-04-11 08:30:00',</li>
<li>&nbsp;&nbsp; endtime =&gt; '2007-04-11 08:45:00');</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P314</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt; declare i integer;</li>
<li>&nbsp; 2&nbsp; begin</li>
<li>&nbsp; 3&nbsp; &nbsp; for i in 1..100 loop</li>
<li>&nbsp; 4&nbsp; &nbsp; &nbsp; insert into test values(i,100-i);</li>
<li>&nbsp; 5&nbsp; &nbsp; end loop;</li>
<li>&nbsp; 6&nbsp; commit;</li>
<li>&nbsp; 7&nbsp; end;</li>
<li>&nbsp; 8&nbsp; /</li>
<li>&nbsp;</li>
<li>SQL&gt; create or replace trigger tr_test</li>
<li>&nbsp; 2&nbsp; &nbsp;before insert or update or delete on test</li>
<li>&nbsp; 3&nbsp; &nbsp; for each row</li>
<li>&nbsp; 4&nbsp; declare</li>
<li>&nbsp; 5&nbsp; &nbsp; PRAGMA AUTONOMOUS_TRANSACTION;</li>
<li>&nbsp; 6&nbsp; &nbsp; begin</li>
<li>&nbsp; 7&nbsp; &nbsp; &nbsp; update audit_test set c=c+1;</li>
<li>&nbsp; 8&nbsp; &nbsp; &nbsp; &nbsp; commit;</li>
<li>&nbsp; 9&nbsp; &nbsp; end;</li>
<li>&nbsp; 10&nbsp; &nbsp;/</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><strong>第9章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P338</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">$more backup_exp.sh</li>
<li>#!/bin/sh</li>
<li>&nbsp;</li>
<li># creator: piner</li>
<li># function: backup database with expdp</li>
<li># usage: crontab on linux</li>
<li># last modify: tuolei 2007-08-29 create</li>
<li>&nbsp;</li>
<li>#set environment variable</li>
<li>export ORACLE_SID=test</li>
<li>export ORACLE_HOME=/u01/oracle/product/9.2</li>
<li>export NLS_LANG=american_america.zhs16gbk</li>
<li>&nbsp;</li>
<li>#开始备份，假定目录dump_test已经创建，并且dump_test=/u01/oracle/backup</li>
<li>FILE=`date date +%Y%m%d`</li>
<li>expdp user/pass directory=dump_test dumpfile=$FILE.dmp</li>
<li>&nbsp;</li>
<li>#删除以前过期的备份</li>
<li>DUMP=/u01/oracle/backup</li>
<li>find $DUMP -name &quot;*.dmp&quot; -mtime +7 -exec rm {} \;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P342</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">[oracle@db worksh]$ more rmanback.sh </li>
<li>#!/bin/ksh</li>
<li>#环境变量</li>
<li>export ORACLE_HOME=/opt/oracle/product/9.2</li>
<li>export ORACLE_SID=test</li>
<li>export NLS_LANG=&quot;AMERICAN_AMERICA.zhs16gbk&quot;</li>
<li>export PATH=$PATH:$ORACLE_HOME/bin</li>
<li>#备份脚本</li>
<li>echo &quot;-----------------------------start-----------------------------&quot;;date</li>
<li>$ORACLE_HOME/bin/rman &lt;&lt;EOF</li>
<li>connect target</li>
<li>delete noprompt obsolete;</li>
<li>backup database format '/netappdata1/rmanback/tbdb2/%U_%s.bak' filesperset = 4;</li>
<li>&nbsp;</li>
<li>exit;</li>
<li>EOF</li>
<li>echo &quot;------------------------------end------------------------------&quot;;date</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P345</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">run{</li>
<li>allocate channel node_c1 device type disk connect 'sys/pass@dbin1';</li>
<li>&nbsp;</li>
<li>allocate channel node_c2 device type disk connect 'sys/pass@dbin2';</li>
<li>sql 'alter system archive log thread 2 current'; </li>
<li>sql 'alter system archive log thread 1 current'; </li>
<li>backup archivelog all delete input format '/u01/dbbak/%U_%s.bak' filesperset = 10;</li>
<li>}</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P348</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">RMAN&gt; run{</li>
<li>2&gt; allocate channel c1 type disk;</li>
<li>3&gt; allocate channel c2 type disk;</li>
<li>4&gt; set until time = '2007-11-09:11:44:00';</li>
<li>5&gt; restore database;</li>
<li>6&gt; recover database;</li>
<li>7&gt; alter database open resetlogs; }</li>
<li>&nbsp;</li>
<li>RMAN&gt; run {</li>
<li>2&gt; set until sequence 120 thread 1;</li>
<li>3&gt; alter database mount;</li>
<li>4&gt; restore database;</li>
<li>5&gt; recover database;&nbsp; &nbsp; &nbsp; &nbsp; # 恢复到日志119</li>
<li>6&gt; alter database open resetlogs;</li>
<li>7&gt; }</li>
<li>&nbsp;</li>
<li>RMAN&gt; run {</li>
<li>2&gt;set newname for datafile</li>
<li>3&gt;'/u01/oradata/tools01.dbf' to '/tmp/tools01.dbf';</li>
<li>4&gt;restore datafile '/u01/oradata/tools01.dbf';</li>
<li>&nbsp;</li>
<li>5&gt;switch datafile all;</li>
<li>6&gt;}</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P355</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">#!/bin/sh</li>
<li># creator: Piner</li>
<li># function: backup database or archive with rman</li>
<li># usage: crontab on linux</li>
<li># last modify: piner 2007-08-29 create</li>
<li>&nbsp;</li>
<li>#环境变量</li>
<li>export ORACLE_SID=test</li>
<li>export ORACLE_HOME=/u01/oracle/product/9.2</li>
<li>export NLS_LANG=american_america.zhs16gbk</li>
<li>&nbsp;</li>
<li>#运行变量</li>
<li>RMAN=$ORACLE_HOME/bin/rman</li>
<li>SQLPLUS=$ORACLE_HOME/bin/sqlplus</li>
<li>TEE=/usr/bin/tee</li>
<li>&nbsp;</li>
<li>LOGFILE=/home/oracle/logs/rmanback.log</li>
<li>&nbsp;</li>
<li>#目录结构为类似这样：/back1/rmanbak/test/week1</li>
<li>DBDEST1=/back1/rmanbak/${ORACLE_SID}/week`date +%w`</li>
<li>DBDEST2=/back2/rmanbak/${ORACLE_SID}/week`date +%w`</li>
<li>CTLFILE=/back1/rmanbak/${ORACLE_SID}/week`date +%w`/${ORACLE_SID}_ctl_`date +%Y%m%d%H%M`.ctl</li>
<li>&nbsp;</li>
<li>#开始运行RMAN来备份数据库与归档日志，并记录备份的日志文件</li>
<li>echo &quot;----------------backup start----------------------&quot; &gt; $LOGFILE</li>
<li>$RMAN &lt;&lt;EOF | $TEE -a $LOGFILE</li>
<li>connect target</li>
<li>&nbsp;</li>
<li>#分配多通道备份，只备份数据库</li>
<li>Run{</li>
<li>allocate channel c1 type disk format '$DBDEST1/%U_%s.bak' maxpiecesize = 2000M;</li>
<li>allocate channel c2 type disk format '$DBDEST2/%U_%s.bak' maxpiecesize = 2000M;</li>
<li>backup database filesperset = 4;</li>
<li>}</li>
<li>&nbsp;</li>
<li>#保留两次有效备份</li>
<li>delete noprompt obsolete redundancy = 2 device type disk;</li>
<li>exit;</li>
<li>EOF</li>
<li>&nbsp;</li>
<li>#备份控制文件</li>
<li>$SQLPLUS &quot;/ as sysdba&quot;&nbsp; &lt;&lt;EOF | $TEE -a $LOGFILE</li>
<li>&nbsp; alter database backup controlfile to '$CTLFILE';</li>
<li>exit</li>
<li>EOF</li>
<li>&nbsp;</li>
<li>echo &quot;-----------------backup end-----------------------&quot; &gt;&gt; $LOGFILE</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P356</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">RMAN&gt; allocate channel c1 device type sbt</li>
<li>&nbsp;&nbsp; 2&gt; parms='env=(nsr_server=tape_srv,</li>
<li>&nbsp;&nbsp; 3&gt; nsr_group=Oracle_tapes)';</li>
<li>相关的数据库与归档日志备份脚本如下：</li>
<li>#全备份脚本</li>
<li>backup tag 'full' </li>
<li>database filesperset = 4</li>
<li>plus archivelog delete input filesperset = 10;</li>
<li>&nbsp;</li>
<li>#零级备份脚本</li>
<li>backup incremental level 0 tag 'db0' </li>
<li>database filesperset = 4</li>
<li>database skip readonly</li>
<li>plus archivelog delete input filesperset = 10;</li>
<li>&nbsp;</li>
<li>#一级备份脚本</li>
<li>backup incremental level 1 tag 'db1' </li>
<li>database filesperset = 4</li>
<li>database skip readonly</li>
<li>plus archivelog delete input filesperset = 10;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P359</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">RMAN&gt; connect target sys/password@prod&nbsp; &nbsp; &nbsp;#源数据库</li>
<li>RMAN&gt;connect auxiliary sys/password@aux&nbsp; &nbsp; #辅助数据库</li>
<li>connected to target database: TEST (DBID=290922305)</li>
<li>connected to auxiliary database: TEST (not mounted)</li>
<li>&nbsp;</li>
<li>RMAN&gt;RUN{</li>
<li>allocate auxiliary channel c1 type disk;</li>
<li>recover tablespace 'USERS' until time &quot;to_date('2007-10-22 15:48:17' , 'yyyy-mm-dd </li>
<li>hh24:mi:ss')&quot; AUXILIARY DESTINATION '/u01/oracle/new/';</li>
<li>sql 'alter tablespace&nbsp; USERS online';</li>
<li>}</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P365</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">RMAN&gt;duplicate target database</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;to dupdb</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;password file</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;spfile</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;from active database</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;db_file_name_convert '/u01/Oracle/oradata/','/u02/Oracle/oradata/'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;parameter_value_convert '/u01/oracle/pfile/','/u02/Oracle/oradata/'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;set sga_max_size '300M'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;set sga_target '250M'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;set log_file_name_convert '/u01/oracle/redo/','/u02/oracle/redo/';</li>
<li>&nbsp;</li>
<li>run{</li>
<li>set newname for datefile 1 to '/u01/oradatd1/system01.dbf'; </li>
<li>set newname for datefile 2 to '/u01/oradata2/undotbs01.dbf';</li>
<li>…….</li>
<li>duplicate&nbsp; &nbsp;……</li>
<li>}</li>
<li>&nbsp;</li>
<li>duplicate&nbsp; &nbsp;</li>
<li>……</li>
<li>parameter_values_convert '/u01/oracle/pfile/', '+DISK1'</li>
<li>set db_create_file_dest '+DISK1';</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><strong>第10章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P376</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt; begin</li>
<li>&nbsp; 2&nbsp; &nbsp; &nbsp;dbms_streams_adm.maintain_schemas(</li>
<li>&nbsp; 3&nbsp; &nbsp; &nbsp;schema_names =&gt; 'piner',</li>
<li>&nbsp; 4&nbsp; &nbsp; &nbsp;source_directory_object =&gt; null,</li>
<li>&nbsp; 5&nbsp; &nbsp; &nbsp;destination_directory_object =&gt; null,</li>
<li>&nbsp; 6&nbsp; &nbsp; &nbsp;source_database =&gt; 'sour.net',</li>
<li>&nbsp; 7&nbsp; &nbsp; &nbsp;destination_database =&gt; 'dest.net',</li>
<li>&nbsp; 8&nbsp; &nbsp; &nbsp;perform_actions =&gt; true,</li>
<li>&nbsp; 9&nbsp; &nbsp; &nbsp;bi_directional =&gt; false,</li>
<li>&nbsp;10&nbsp; &nbsp; &nbsp;include_ddl&nbsp; &nbsp; =&gt; true,</li>
<li>&nbsp;11&nbsp; &nbsp; &nbsp;instantiation&nbsp; =&gt; dbms_streams_adm.instantiation_schema_network);</li>
<li>&nbsp;12&nbsp; end;</li>
<li>&nbsp;13&nbsp; /</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P378</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt;create table table_name as select * from table_name@db_link where 1=0;</li>
<li>SQL&gt; alter table table_name</li>
<li>2&nbsp; add constraint constraint_name primary key [unique] (field_name);</li>
<li>SQL&gt;create materialized view table_name on prebuilt table refresh fast as</li>
<li>2	select * from table_name@db_link;</li>
<li>&nbsp;</li>
<li>SQL&gt;exec dbms_mview.refresh('table_name',method =&gt; 'Complete');--全刷新</li>
<li>SQL&gt;exec dbms_mview.refresh('table_name');--快速刷新</li>
<li>SQL&gt;create index index_name on table_name(field_name);</li>
<li>&nbsp;</li>
<li>SQL&gt;declare jobid number;</li>
<li>SQL&gt;begin</li>
<li>2&nbsp; &nbsp;sys.dbms_job.submit(job =&gt; jobid,</li>
<li>3&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;what =&gt; 'dbms_mview.refresh(''table_name'');',</li>
<li>4&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;next_date =&gt; sysdate,</li>
<li>5&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;interval =&gt; 'sysdate+1/1440');</li>
<li>6&nbsp; commit;</li>
<li>7&nbsp; end;</li>
<li>8/</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P379</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">create table rep_table_logs</li>
<li>(</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;Rep_key&nbsp; &nbsp;number not null,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;Dml_type&nbsp; varchar2(1) not null,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;Dml_time&nbsp; date default sysdate not null,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;Rep_flag&nbsp; number default 0 not null</li>
<li>)</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P380</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">create or replace trigger tr_table_repl</li>
<li>&nbsp; after insert or update or delete</li>
<li>&nbsp; on table_name</li>
<li>&nbsp; for each row</li>
<li>/**********************************************************</li>
<li>*create date:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*</li>
<li>*creator:piner&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *</li>
<li>*function description:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *</li>
<li>*&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*</li>
<li>*modify history:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *</li>
<li>***********************************************************/</li>
<li>declare</li>
<li>&nbsp; m_dml_type varchar2(1);</li>
<li>&nbsp; m_rep_id&nbsp; &nbsp;number;</li>
<li>&nbsp; errormsg&nbsp; &nbsp;varchar2(500);</li>
<li>begin</li>
<li>&nbsp;</li>
<li>&nbsp; if inserting then</li>
<li>&nbsp;&nbsp; &nbsp; m_dml_type := 'I';</li>
<li>&nbsp;&nbsp; &nbsp; m_rep_id := :new.id;</li>
<li>&nbsp; elsif updating then</li>
<li>&nbsp;</li>
<li>&nbsp;if :new.id != :old.id then</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;raise_application_error(-20001,'You can not modify primary key');</li>
<li>&nbsp;&nbsp; &nbsp; end if;</li>
<li>&nbsp;&nbsp; &nbsp; m_dml_type := 'U';</li>
<li>&nbsp;&nbsp; &nbsp; m_rep_id := :old.id;</li>
<li>&nbsp; elsif deleting then</li>
<li>&nbsp;&nbsp; &nbsp; m_dml_type := 'D';</li>
<li>&nbsp;&nbsp; &nbsp; m_rep_id := :old.id;</li>
<li>&nbsp; else</li>
<li>&nbsp;&nbsp; &nbsp; m_dml_type := 'X';</li>
<li>&nbsp;&nbsp; &nbsp; m_rep_id := -1;</li>
<li>&nbsp; end if;</li>
<li>&nbsp;</li>
<li>&nbsp;insert into rep_table_logs(rep_key,dml_type,dml_time)</li>
<li>&nbsp;&nbsp; &nbsp;values(m_rep_id,m_dml_type,sysdate);</li>
<li>&nbsp;</li>
<li>exception</li>
<li>&nbsp; when others then</li>
<li>&nbsp;&nbsp; raise;</li>
<li>end tr_table_repl;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P381</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">create or replace procedure sp_table_repl</li>
<li>is</li>
<li>&nbsp;&nbsp; --复制参数</li>
<li>&nbsp;&nbsp; m_rep_flag number := 1;</li>
<li>&nbsp;&nbsp; m_exc_flag number := 2;</li>
<li>&nbsp;&nbsp; m_sp_name varchar2(10) := 'rep_table';</li>
<li>&nbsp;&nbsp; --过程参数</li>
<li>&nbsp;&nbsp; end_stamp&nbsp; date;</li>
<li>&nbsp;&nbsp; num_row&nbsp; &nbsp; number;</li>
<li>&nbsp;&nbsp; errormsg&nbsp; &nbsp;varchar2(256);</li>
<li>&nbsp;&nbsp; pages_nums number;</li>
<li>&nbsp;&nbsp; per_pages&nbsp; number := 10000;</li>
<li>&nbsp;</li>
<li>begin </li>
<li>/***************************************************************************</li>
<li>*create date:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *</li>
<li>*creator: piner&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *</li>
<li>*function:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*</li>
<li>*&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *</li>
<li>*modify history:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*</li>
<li>*&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *</li>
<li>*注意，该过程加入了并发控制，保证不能被并发运行，但是，该过程在运行的过程中*</li>
<li>*不能被异常kill，如果被kill了，需要手工修改该标志从runing到stop。&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *</li>
<li>****************************************************************************/</li>
<li>--处理标志，为了保证过程不被并发执行</li>
<li>&nbsp;&nbsp; update rep_table_flag f set f.run_flag='runing',f.sp_time=sysdate</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;where f.run_flag='stop' and f.sp_type = m_sp_name;</li>
<li>&nbsp;&nbsp; num_row := sql%rowcount;</li>
<li>&nbsp;&nbsp; commit;</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; --更新到0行，表示有过程正在执行，该进程返回，不再执行</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; if num_row = 0 then</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; return;</li>
<li>&nbsp;&nbsp; &nbsp; end if;</li>
<li>---------------------------------------------------------------------</li>
<li>----------------------start------------------------------------------</li>
<li>&nbsp;&nbsp; --未处理日志数</li>
<li>&nbsp;&nbsp; &nbsp;select count(*) into num_row</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; from rep_table_logs_syn t</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; where t.rep_flag = 0;</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp;pages_nums := trunc(num_row/per_pages) + 1;</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; --分页处理。每次处理一个per_pages的数目</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; for pages in 1 .. pages_nums loop</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;select max(dml_time) into end_stamp from (</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; select dml_time from rep_table_logs_syn</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where rep_flag = 0</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;order by dml_time)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where rownum &lt;= per_pages;</li>
<li>&nbsp;</li>
<li>--把这部分正在处理的日志，标记置为m_exc_flag，表示正在处理</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp;update&nbsp; rep_table_logs_syn&nbsp; set rep_flag = m_exc_flag</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;where rep_flag = 0</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and dml_time &lt; end_stamp;</li>
<li>&nbsp;</li>
<li>commit;</li>
<li>-----------------------------------------------------------------</li>
<li>-------------------------delete----------------------------------</li>
<li>&nbsp;&nbsp; &nbsp;--处理delete的记录</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; delete /*+ ordered use_nl(l) */ from rep_table u where id in</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(select rep_key from rep_table_logs_syn l</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where l.dml_type = 'D'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and l.rep_flag = m_exc_flag);</li>
<li>&nbsp;&nbsp; &nbsp; </li>
<li>--更新处理过的标志位，注意，这里包含了insert,update,delete的所有日志</li>
<li>&nbsp;&nbsp; &nbsp;--因为如果该记录有删除日志存在，它的insert update是没有必要做的</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; update rep_table_logs_syn t set t.rep_flag = t.rep_flag + m_rep_flag</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where t.rep_key in</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (select rep_key from rep_table_logs_syn l</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where l.dml_type = 'D'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and l.rep_flag = m_exc_flag);</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;commit;</li>
<li>---------------------------------------------------------------------</li>
<li>-------------------------insert--------------------------------------</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;--处理insert的记录，查看要插入的日志在目标表中是否已经存在</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;--一般情况下应当是不存在的，除了开始取数据可能存在的合并区</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;select /*+ ordered use_nl(l,u) */ count(*) into num_row</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from rep_table_logs_syn l,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rep_table u</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where l.rep_key = u.id</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and l.dml_type = 'I'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and l.rep_flag = m_exc_flag;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; --如果发现要更新的记录存在于目标表中，则删除该记录</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if num_row &gt; 0 then</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delete from rep_table where id in</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(select /*+ ordered use_nl(l,u) */ l.rep_key</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from rep_table_logs_syn l,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rep_table&nbsp; u</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where l.rep_key = u.id</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and l.dml_type = 'I'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and l.rep_flag = m_exc_flag);</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end if;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;--把需要同步的数据插入到目标表中</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;insert into rep_table</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select /*+ ordered use_nl(l,u) */ u.*</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from rep_table_logs_syn l,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;syn_rep_table_db1&nbsp; u</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where l.rep_key = u.id</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and l.dml_type = 'I'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and l.rep_flag = m_exc_flag;</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; --更新insert的标志位</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; update rep_table_logs_syn l set rep_flag = rep_flag + m_rep_flag</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where dml_type = 'I'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and rep_flag = m_exc_flag;</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; commit;</li>
<li>---------------------------------------------------------------------</li>
<li>-------------------------update--------------------------------------</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;--处理update的记录</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;--处理重复记录，其实多个update只需要同步一次即可</li>
<li>&nbsp;&nbsp; &nbsp; update rep_table_logs_syn set rep_flag = rep_flag + m_rep_flag</li>
<li>&nbsp;&nbsp; &nbsp; where rowid in</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; (select rid from (</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;select rowid rid,row_number() over(partition by rep_key </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;order by rowid) rn</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from rep_table_logs_syn</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where rep_flag = m_exc_flag</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and dml_type = 'U')</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where rn &gt;= 2);</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;commit;</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;--更新，先插入到临时表</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;insert into rep_table_temp</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; select /*+ ordered use_nl(l,u) */ u.*</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from rep_table_logs_syn l,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; syn_rep_table_db1&nbsp; u</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where l.rep_key = u.id</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and l.dml_type = 'U'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and l.rep_flag = m_exc_flag;</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;--从临时表更新数据</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; update /*+ ordered use_nl(u) */ rep_table t</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set (field1,field2...fieldn)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= (select * from rep_table_temp u</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where u.id=t.id)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where exists</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (select null from rep_table_temp tt</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where t.id = tt.id);</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;--更新update的标志位</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;update rep_table_logs_syn l set rep_flag = rep_flag + m_rep_flag</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where dml_type = 'U'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and rep_flag = m_exc_flag;</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; commit;</li>
<li>----------------------当前页全部更新完毕----------------------------</li>
<li>&nbsp;&nbsp; &nbsp; --更新时间戳</li>
<li>&nbsp;&nbsp; &nbsp; update rep_table_flag f set f.sp_time=sysdate </li>
<li>where f.sp_type = m_sp_name;</li>
<li>&nbsp;&nbsp; &nbsp; commit;</li>
<li>------------------------------------------------------------------</li>
<li>-------------------------end loop---------------------------------</li>
<li>&nbsp;&nbsp; end loop;</li>
<li>&nbsp;</li>
<li>&nbsp; --删除处理完的日志</li>
<li>&nbsp; delete from rep_table_logs_syn where rep_flag = m_rep_flag + m_exc_flag;</li>
<li>&nbsp; --做完标志</li>
<li>&nbsp;&nbsp; update rep_table_flag f set f.run_flag='stop',f.sp_time=sysdate </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where f.sp_type = m_sp_name;</li>
<li>&nbsp; commit;</li>
<li>exception</li>
<li>&nbsp; when others then</li>
<li>&nbsp;&nbsp; &nbsp; --如果失败，则回滚</li>
<li>&nbsp;&nbsp; &nbsp; rollback;</li>
<li>&nbsp;&nbsp; &nbsp; --提交错误信息</li>
<li>&nbsp;&nbsp; &nbsp; errormsg := sqlerrm;</li>
<li>&nbsp;&nbsp; &nbsp; --做完标志</li>
<li>&nbsp;&nbsp; &nbsp; update rep_table_flag f set f.run_flag='stop',f.sp_time=sysdate </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where f.sp_type = m_sp_name;</li>
<li>&nbsp;&nbsp; &nbsp; insert into rep_table_sp_errors(error_id,error_msg,error_time)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; values(m_sp_name,errormsg,sysdate);</li>
<li>&nbsp;&nbsp; &nbsp; commit;</li>
<li>&nbsp;&nbsp; &nbsp; raise;</li>
<li>end sp_table_repl;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P385</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">#!/usr/bin/perl</li>
<li>###########################################################################</li>
<li>#creator:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #</li>
<li>#create date:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#</li>
<li>#function:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #</li>
<li>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#</li>
<li>#modify history:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #</li>
<li>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#</li>
<li>###########################################################################</li>
<li>use strict;</li>
<li>use warnings;</li>
<li>use DBI;</li>
<li>#$OUTPUT_AUTOFLUSH = false</li>
<li>$|=1;</li>
<li>&nbsp;</li>
<li>if (my $pid = open(CHILD,&quot;-|&quot;)) {</li>
<li>&nbsp; #parent process</li>
<li>&nbsp; #environment variable for oracle nls_lang </li>
<li>&nbsp; $ENV{&quot;NLS_LANG&quot;} = 'AMERICAN_AMERICA.US7ASCII';</li>
<li>&nbsp; </li>
<li>#这里连接远程数据库</li>
<li>&nbsp;</li>
<li>&nbsp; #user/pass@dbname</li>
<li>&nbsp; my $dbname1=&quot;test&quot;;</li>
<li>&nbsp; my $user1=&quot;test&quot;;</li>
<li>&nbsp; my $passwd1=&quot;test&quot;;</li>
<li>&nbsp; my $count=0;</li>
<li>&nbsp; #connect oracle database</li>
<li>&nbsp; my $dbh1 = DBI-&gt;connect(&quot;dbi:Oracle:$dbname1&quot;,$user1,$passwd1) or die (&quot;can't connect</li>
<li>&nbsp; to oracle database &quot;,$DBI::errstr);</li>
<li>&nbsp; </li>
<li>#这里采用了进程间通信的方式，这里是父进程</li>
<li>#父进程把从子进程读到的信息，按照&quot;::&quot;作为分界符的方法，切换成多个字段的记录</li>
<li>#这个分界符是可以自定义的</li>
<li>&nbsp;</li>
<li>&nbsp; #read child process information</li>
<li>&nbsp; while (&lt;CHILD&gt;){</li>
<li>&nbsp;&nbsp; &nbsp;my @newrec = split(/::/,&quot;$_&quot;);</li>
<li>&nbsp;&nbsp; &nbsp;chomp(@newrec);</li>
<li>&nbsp;&nbsp; &nbsp;my $sqls = &quot;insert into test(id,name) values('$newrec[0]','$newrec[1]')&quot;; </li>
<li>&nbsp;&nbsp; &nbsp;my $rows =&nbsp; $dbh1 -&gt; do($sqls);</li>
<li>&nbsp;&nbsp; &nbsp;$count += $rows;</li>
<li>&nbsp; }</li>
<li>&nbsp; close(CHILD) or die(&quot;Cannot close:$!&quot;);</li>
<li>&nbsp; $dbh1-&gt;disconnect();</li>
<li>&nbsp; print &quot;inert rows:$count.ok\n&quot;;</li>
<li>}</li>
<li>&nbsp;</li>
<li>elsif(defined($pid)){</li>
<li>&nbsp; #child process</li>
<li>&nbsp; </li>
<li>#这里是子进程，可以拥有跟父进程不一样的字符集环境变量</li>
<li>&nbsp;</li>
<li>#environment variable for oracle nls_lang </li>
<li>$ENV{&quot;NLS_LANG&quot;} = 'AMERICAN_AMERICA.ZHS16GBK';</li>
<li>&nbsp;</li>
<li>#这里连接字符集不同的另外一个数据库</li>
<li>&nbsp;</li>
<li>&nbsp; #user/pass@dbname</li>
<li>&nbsp; my $dbname2=&quot;&quot;;</li>
<li>&nbsp; my $user2=&quot;test&quot;;</li>
<li>&nbsp; my $passwd2=&quot;test&quot;;</li>
<li>&nbsp; #connect oracle database</li>
<li>&nbsp; my $dbh2 = DBI-&gt;connect(&quot;dbi:Oracle:$dbname2&quot;,$user2,$passwd2) or die (&quot;can't connect</li>
<li>&nbsp; to oracle database &quot;,$DBI::errstr);</li>
<li>&nbsp; #query sql</li>
<li>&nbsp; my $sth=$dbh2-&gt;prepare(&quot;select * from test&quot;);</li>
<li>&nbsp; #execute sql</li>
<li>&nbsp; my $rc=$sth-&gt;execute;</li>
<li>&nbsp; my @recs;</li>
<li>#get row data and send to parent process</li>
<li>#把记录拼合在一起，用&quot;::&quot;来分隔记录</li>
<li>#然后把分隔好的记录传递给父进程</li>
<li>&nbsp; while(@recs = $sth -&gt; fetchrow_array()){</li>
<li>&nbsp;&nbsp; &nbsp; print $recs[0].&quot;::&quot;.$recs[1].&quot;\n&quot;;</li>
<li>&nbsp; }</li>
<li>&nbsp; $dbh2-&gt;disconnect();</li>
<li>&nbsp; $sth-&gt;finish();</li>
<li>&nbsp; #exit child process</li>
<li>&nbsp; exit();</li>
<li>}</li>
<li>else{</li>
<li>&nbsp; print &quot;could not fork process\n&quot;;</li>
<li>}</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P386</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">###&nbsp; $dbh1-&gt;{AutoCommit} = 0;</li>
<li>&nbsp; ###&nbsp; $dbh1-&gt;{RaiseError} = 1; </li>
<li>&nbsp; ###&nbsp; #data</li>
<li>&nbsp; ###&nbsp; my @col1;</li>
<li>&nbsp; ###&nbsp; my @col2;</li>
<li>&nbsp; ###&nbsp; #read child process information</li>
<li>&nbsp; ###&nbsp; while (&lt;CHILD&gt;){</li>
<li>&nbsp; ###&nbsp; &nbsp; my @newrec = split(/::/,&quot;$_&quot;);</li>
<li>&nbsp; ###&nbsp; &nbsp; chomp(@newrec);</li>
<li>&nbsp; ###&nbsp; &nbsp; $col1[$count] = $newrec[0];</li>
<li>&nbsp; ###&nbsp; &nbsp; $col2[$count] = $newrec[1];</li>
<li>&nbsp; ###&nbsp; &nbsp; $count++;</li>
<li>&nbsp; ###&nbsp; &nbsp;}</li>
<li>&nbsp; ###&nbsp; </li>
<li>&nbsp; ###&nbsp; my (@rowstats, $rv);</li>
<li>&nbsp; ###&nbsp; my $sth1 = $dbh1-&gt;prepare(</li>
<li>&nbsp; ###&nbsp; &nbsp; &nbsp;&quot;insert into test(TNAME,TABTYPE) values (?, ?)&quot;);</li>
<li>&nbsp; ###&nbsp; $sth1-&gt;bind_param_array(1, \@col1);</li>
<li>&nbsp; ###&nbsp; $sth1-&gt;bind_param_array(2, \@col2);</li>
<li>&nbsp; ###&nbsp; $rv = $sth1-&gt;execute_array(</li>
<li>&nbsp; ###&nbsp; &nbsp; &nbsp;{ArrayTupleStatus =&gt; \@rowstats});</li>
<li>&nbsp; ###&nbsp; &nbsp; &nbsp;</li>
<li>&nbsp; ###&nbsp; close(CHILD) or die(&quot;Cannot close:$!&quot;);</li>
<li>&nbsp; ###&nbsp; $dbh1-&gt;disconnect();</li>
<li>&nbsp; ###&nbsp; print &quot;inert rows:$rv,ok\n&quot;;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P391</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">RMAN&gt;convert datafile</li>
<li>2&gt; '/home/ora10g/data_user01.dbf'</li>
<li>3&gt; to platform='AIX-Based Systems (64-bit)'</li>
<li>4&gt; from platfrom='Linux IA (32-bit)'</li>
<li>5&gt; db_file_name_convert='/home/ora10g/','/u01/oracle/oradata/test/';</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P394</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">$ more test.ctl</li>
<li>Load data</li>
<li>insert</li>
<li>into table test</li>
<li>Fields terminated by &quot;,&quot; Optionally enclosed by &quot;'&quot;</li>
<li>(id,</li>
<li>&nbsp;name,</li>
<li>SQL&gt;create_date&nbsp; date &quot;yyyy-mm-dd hh24:mi:ss&quot; nullif(create_date=&quot;NULL&quot;))</li>
<li>&nbsp;</li>
<li>$ sqlldr userid=piner/xxxxxx control=test.ctl data=test.dat</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P397</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">Piner@9iR2&gt;create table ext_test</li>
<li>&nbsp; 2&nbsp; &nbsp; &nbsp; (employee_id&nbsp; &nbsp; &nbsp; &nbsp;NUMBER(4), </li>
<li>&nbsp; 3&nbsp; &nbsp; &nbsp; &nbsp;name&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VARCHAR2(20),</li>
<li>&nbsp; 4&nbsp; &nbsp; &nbsp; &nbsp;job_id&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VARCHAR2(10),</li>
<li>&nbsp; 5&nbsp; &nbsp; &nbsp; &nbsp;hire_date&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DATE,</li>
<li>&nbsp; 6&nbsp; &nbsp; &nbsp; &nbsp;salary&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NUMBER(8,2),</li>
<li>&nbsp; 7&nbsp; &nbsp; &nbsp; &nbsp;email&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VARCHAR2(25) </li>
<li>&nbsp; 8&nbsp; &nbsp; &nbsp; )&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</li>
<li>&nbsp; 9&nbsp; &nbsp; &nbsp; &nbsp;organization external </li>
<li>&nbsp;10&nbsp; &nbsp; &nbsp; &nbsp;( </li>
<li>&nbsp;11&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type oracle_loader </li>
<li>&nbsp;12&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;default directory dump_dir </li>
<li>&nbsp;13&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;access parameters</li>
<li>&nbsp;14&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;( </li>
<li>&nbsp;15&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;records delimited by newline </li>
<li>&nbsp;16&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;badfile dump_dir:'test%a_%p.bad' </li>
<li>&nbsp;17&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;logfile dump_dir:'test%a_%p.log' </li>
<li>&nbsp;18&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fields terminated by ',' optionally enclosed by '&quot;'</li>
<li>&nbsp;19&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;missing field values are null </li>
<li>&nbsp;20&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;( employee_id,name, job_id,</li>
<li>&nbsp;21&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hire_date char date_format date mask &quot;yyyy-mm-dd&quot;, </li>
<li>&nbsp;22&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;salary, email </li>
<li>&nbsp;23&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;) </li>
<li>&nbsp;24&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;) </li>
<li>&nbsp;25&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;location ('test1.dat', 'test2.dat') </li>
<li>&nbsp;26&nbsp; &nbsp; &nbsp; &nbsp;) </li>
<li>&nbsp;27&nbsp; &nbsp; &nbsp; &nbsp;parallel</li>
<li>&nbsp;28&nbsp; &nbsp; &nbsp; &nbsp;reject limit unlimited;</li>
<li>&nbsp;</li>
<li>Table created.</li>
<li>&nbsp;</li>
<li>Piner@10gR2&gt;create table ext_test</li>
<li>organization external</li>
<li>(</li>
<li>&nbsp;&nbsp; type oracle_datapump</li>
<li>&nbsp;&nbsp; default directory dump_dir</li>
<li>&nbsp;&nbsp; location ('test.dmp')</li>
<li>)</li>
<li>as</li>
<li>&nbsp; select * from test;</li>
<li>&nbsp;</li>
<li>Piner@10gR2&gt;create table ext_test</li>
<li>&nbsp;&nbsp; &nbsp;(field1&nbsp; &nbsp; &nbsp; &nbsp;number, </li>
<li>&nbsp;&nbsp; &nbsp; field2&nbsp; &nbsp; &nbsp; varchar2(100)</li>
<li>&nbsp;&nbsp; &nbsp;) </li>
<li>&nbsp;&nbsp; &nbsp;organization external</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(type oracle_datapump&nbsp; &nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; default directory dump_dir&nbsp; &nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; location('test.dmp'));</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><strong>第11章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P413</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SELECT D.TABLESPACE_NAME,SPACE SUM_SPACE,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; SPACE-NVL(FREE_SPACE,0) USED_SPACE,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; ROUND((1-NVL(FREE_SPACE,0)/SPACE)*100,2) USED_RATE,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; FREE_SPACE FREE_SPACE</li>
<li>&nbsp;&nbsp; &nbsp; FROM (SELECT TABLESPACE_NAME,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ROUND(SUM(BYTES)/(1024*1024),2) SPACE,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SUM(BLOCKS) BLOCKS</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM DBA_DATA_FILES</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;GROUP BY TABLESPACE_NAME) D,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; (SELECT TABLESPACE_NAME,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ROUND(SUM(BYTES)/(1024*1024),2) FREE_SPACE</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM DBA_FREE_SPACE</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; GROUP BY TABLESPACE_NAME) F</li>
<li>&nbsp;&nbsp; &nbsp;WHERE&nbsp; D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><strong>第12章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P430</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">$more statpack.sh</li>
<li>#!/bin/ksh</li>
<li># creator: piner</li>
<li># function:produce statpack snapshot</li>
<li>date</li>
<li>#设置环境变量</li>
<li>export ORACLE_SID=test</li>
<li>export ORACLE_HOME=/u01/oracle/product/9.2</li>
<li>export NLS_LANG=american_america.zhs16gbk</li>
<li>#收集快照点</li>
<li>$ORACLE_HOME/bin/sqlplus /nolog &lt;&lt;EOF</li>
<li>connect perfstat/perfstat</li>
<li>&nbsp;exec statspack.snap</li>
<li>exit</li>
<li>EOF</li>
<li>&nbsp;</li>
<li>$more spreport.sh</li>
<li>#!/bin/ksh</li>
<li># creator: piner</li>
<li># function:get statpack report</li>
<li>date</li>
<li>&nbsp;</li>
<li>#设置环境变量</li>
<li>export ORACLE_SID=test</li>
<li>export ORACLE_HOME=/u01/oracle/product/9.2</li>
<li>export NLS_LANG=american_america.zhs16gbk</li>
<li>&nbsp;</li>
<li>#设置运行时变量</li>
<li>SQLPLUS=$ORACLE_HOME/bin/sqlplus</li>
<li>LOGFILE=/home/oracle/logs/spreport.txt&nbsp; &nbsp; &nbsp; &nbsp; #日志文件</li>
<li>REPFILE=/home/oracle/worksh/spreport.lst&nbsp; &nbsp; &nbsp; #报表文件</li>
<li>&nbsp;</li>
<li>#获得最后2个快照点</li>
<li>$SQLPLUS -S perfstat/perfstat &lt;&lt;EOF</li>
<li>set echo off</li>
<li>set feedback off</li>
<li>set heading off</li>
<li>set pagesize 0</li>
<li>set linesize 1000</li>
<li>set trimspool on</li>
<li>spool $LOGFILE</li>
<li>select snap_id from</li>
<li>&nbsp; (select snap_id from stats\$snapshot where instance_number=1</li>
<li>&nbsp; order by snap_time desc) where rownum&lt;3;</li>
<li>spool off;</li>
<li>set echo on</li>
<li>set feedback on</li>
<li>set heading on</li>
<li>exit</li>
<li>EOF</li>
<li>&nbsp;</li>
<li>line1=`tail -1 $LOGFILE`</li>
<li>line2=`head -1 $LOGFILE`</li>
<li>echo &quot;line1 is&quot;$line1</li>
<li>echo &quot;line2 is&quot;$line2</li>
<li>&nbsp;</li>
<li>#产生报表</li>
<li>rm $REPFILE</li>
<li>$SQLPLUS -S perfstat/perfstat &lt;&lt;EOF</li>
<li>&nbsp;define begin_snap=$line1</li>
<li>&nbsp;define end_snap=$line2</li>
<li>&nbsp;define report_name=$REPFILE</li>
<li>@?/rdbms/admin/spreport.sql</li>
<li>exit</li>
<li>EOF</li>
<li>&nbsp;</li>
<li>#发送邮件 </li>
<li>mail -s `date +%Y%m%d`'-'`hostname`spreport&nbsp; test@mail.com &lt; $REPFILE</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P451</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt; select to_char(snap_time,'yyyy-mm-dd hh24') time,</li>
<li>&nbsp; 2&nbsp; round(sum(read/1024)) &quot;write(kb)&quot;,round(sum(write/1024)) &quot;read(kb)&quot; from </li>
<li>&nbsp; 3&nbsp; (select sn.snap_time snap_time,(newr.value-oldr.value) read, </li>
<li>&nbsp; 4&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (neww.value-oldw.value) write </li>
<li>&nbsp; 5&nbsp; from stats$sysstat newr, </li>
<li>&nbsp; 6&nbsp; &nbsp; &nbsp; &nbsp;stats$sysstat oldr, </li>
<li>&nbsp; 7&nbsp; &nbsp; &nbsp; &nbsp;stats$sysstat neww, </li>
<li>&nbsp; 8&nbsp; &nbsp; &nbsp; &nbsp;stats$sysstat oldw, </li>
<li>&nbsp; 9&nbsp; &nbsp; &nbsp; &nbsp;stats$snapshot sn </li>
<li>&nbsp;10&nbsp; where sn.snap_id=newr.snap_id </li>
<li>&nbsp;11&nbsp; &nbsp; and sn.snap_id=neww.snap_id </li>
<li>&nbsp;12&nbsp; &nbsp; and sn.snap_id-1=oldr.snap_id </li>
<li>&nbsp;13&nbsp; &nbsp; and sn.snap_id-1=oldw.snap_id </li>
<li>&nbsp;14&nbsp; &nbsp; and newr.name='physical reads' </li>
<li>&nbsp;15&nbsp; &nbsp; and oldr.name='physical reads' </li>
<li>&nbsp;16&nbsp; &nbsp; and neww.name='physical writes' </li>
<li>&nbsp;17&nbsp; &nbsp; and oldw.name='physical writes' </li>
<li>&nbsp;18&nbsp; ) v </li>
<li>&nbsp;19&nbsp; group by to_char(snap_time,'yyyy-mm-dd hh24');</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><strong>第13章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P467</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">select * from (</li>
<li>select rownum rn,object_id,object_name,subobject_name,status from </li>
<li>(select object_id,object_name,subobject_name,status </li>
<li>from test</li>
<li>where owner='SYS' </li>
<li>and object_type='TABLE'</li>
<li>order by created desc) </li>
<li>where rownum &lt;= m) t</li>
<li>where rn &gt;=n</li>
<li>&nbsp;</li>
<li>Piner@10g R2&gt;create index ind_test on test(owner,object_type,created);</li>
<li>&nbsp;</li>
<li>Index created.</li>
<li>Piner@10g R2&gt;select * from (</li>
<li>&nbsp; 2&nbsp; &nbsp;select rownum rn,object_id,object_name,subobject_name,status from </li>
<li>&nbsp; 3&nbsp; (select object_id,object_name,subobject_name,status </li>
<li>&nbsp; 4&nbsp; from test</li>
<li>&nbsp; 5&nbsp; where owner='SYS' </li>
<li>&nbsp; 6&nbsp; and object_type='TABLE'</li>
<li>&nbsp; 7&nbsp; order by created desc) </li>
<li>&nbsp; 8&nbsp; where rownum &lt;= 50) t</li>
<li>&nbsp; 9&nbsp; where rn &gt;=1;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P468</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">Piner@10g R2&gt;select /*+ ordered use_nl(t,test) */ </li>
<li>&nbsp; 2&nbsp; &nbsp; object_id,object_name,subobject_name,status </li>
<li>&nbsp; 3&nbsp; &nbsp; &nbsp;from (select rid from (</li>
<li>&nbsp; 4&nbsp; &nbsp; &nbsp; &nbsp; select rownum rn,rid from (</li>
<li>&nbsp; 5&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select rowid rid from test</li>
<li>&nbsp; 6&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where owner='SYS' </li>
<li>&nbsp; 7&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and object_type='TABLE'</li>
<li>&nbsp; 8&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;order by created desc) </li>
<li>&nbsp; 9&nbsp; &nbsp; &nbsp; &nbsp; where rownum &lt;= 500) </li>
<li>&nbsp;10&nbsp; &nbsp; &nbsp; where rn &gt;=451) t,</li>
<li>&nbsp;11&nbsp; &nbsp; &nbsp; test</li>
<li>&nbsp;12&nbsp; where t.rid=test.rowid;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P471</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL&gt; create or replace type numtabletype as table of number;</li>
<li>&nbsp;</li>
<li>SQL&gt;create or replace type vartabletype as table of varchar2(1000);</li>
<li>&nbsp;</li>
<li>SQL&gt;create or replace function str2numList( p_string in varchar2 ) return numTableType </li>
<li>as </li>
<li>&nbsp;&nbsp; &nbsp;v_str long default p_string || ','; </li>
<li>&nbsp;&nbsp; &nbsp;v_n number; </li>
<li>&nbsp;&nbsp; &nbsp;v_data numTableType := numTableType(); </li>
<li>begin </li>
<li>&nbsp;&nbsp; &nbsp;loop </li>
<li>&nbsp;&nbsp; &nbsp;v_n := to_number(instr( v_str, ',' )); </li>
<li>&nbsp;&nbsp; &nbsp;exit when (nvl(v_n,0) = 0); </li>
<li>&nbsp;&nbsp; &nbsp;v_data.extend; </li>
<li>&nbsp;&nbsp; &nbsp;v_data( v_data.count ) := ltrim(rtrim(substr(v_str,1,v_n-1))); </li>
<li>&nbsp;&nbsp; &nbsp;v_str := substr( v_str, v_n+1 ); </li>
<li>&nbsp;&nbsp; &nbsp;end loop; </li>
<li>&nbsp;&nbsp; &nbsp;return v_data; </li>
<li>end;</li>
<li>&nbsp;</li>
<li>SQL&gt;create or replace function str2varList( p_string in varchar2 ) return VarTableType </li>
<li>&nbsp;as </li>
<li>&nbsp;v_str long default p_string || ','; </li>
<li>&nbsp;v_n varchar2(2000); </li>
<li>&nbsp;v_data VarTableType := VarTableType(); </li>
<li>&nbsp;begin </li>
<li>&nbsp;&nbsp; &nbsp;loop </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; v_n :=instr( v_str, ',' ); </li>
<li>&nbsp;&nbsp; &nbsp;exit when (nvl(v_n,0) = 0); </li>
<li>&nbsp;&nbsp; &nbsp;v_data.extend; </li>
<li>&nbsp;&nbsp; &nbsp;v_data( v_data.count ) := ltrim(rtrim(substr(v_str,1,v_n-1))); </li>
<li>&nbsp;&nbsp; &nbsp;v_str := substr( v_str, v_n+1 ); </li>
<li>&nbsp;&nbsp; &nbsp;end loop; </li>
<li>&nbsp;&nbsp; &nbsp;return v_data; </li>
<li>end;</li>
<li>&nbsp;</li>
<li>Select /*+ ordered use_nl(a,u) */ id, name,nick</li>
<li>&nbsp;&nbsp; &nbsp; from table(STR2NUMLIST(:bind0)) a, </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; users u </li>
<li>&nbsp;&nbsp; &nbsp; where u.id = a.column_value;</li>
<li>&nbsp;</li>
<li>Select /*+ leading(a) */ id, name,nick</li>
<li>&nbsp;&nbsp; &nbsp; from users u </li>
<li>where id in </li>
<li>&nbsp;&nbsp; &nbsp; (select * from table(STR2NUMLIST(:bind0)) a);</li>
<li>&nbsp;&nbsp; &nbsp; </li>
<li>Select /*+ index(u ind_users_id) */ id, name,nick </li>
<li>&nbsp;&nbsp; &nbsp; from users u </li>
<li>where id in </li>
<li>&nbsp;&nbsp; &nbsp; (select * from the (select cast(STR2NUMLIST(:bind0) AS NUMTABLETYPE) </li>
<li>&nbsp;&nbsp; &nbsp; from dual) where rownum&lt;1000);</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P477</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">declare</li>
<li>&nbsp; resource_busy exception;</li>
<li>&nbsp; pragma exception_init(resource_busy, -54);</li>
<li>begin</li>
<li>&nbsp; loop</li>
<li>begin</li>
<li>&nbsp; execute immediate 'alter index ...... noparallel';</li>
<li>&nbsp; exit;</li>
<li>exception</li>
<li>&nbsp;&nbsp; when resource_busy then</li>
<li>dbms_lock.sleep(1);</li>
<li>end;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;end loop;</li>
<li>end;</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><strong>第14章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P488</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">Piner@Ora9R2&gt; create or replace procedure sp_test is</li>
<li>&nbsp; num number;</li>
<li>begin</li>
<li>&nbsp; runstats_pgk.rs_start;</li>
<li>&nbsp; for i in 1..1000 loop</li>
<li>&nbsp;&nbsp; execute immediate 'select b from test where a=:x' using i;</li>
<li>&nbsp; end loop;</li>
<li>&nbsp; runstats_pgk.rs_middle;</li>
<li>&nbsp; for i in 1..1000 loop</li>
<li>&nbsp;&nbsp; &nbsp;execute immediate 'select b from test where a='||i;</li>
<li>&nbsp; end loop;</li>
<li>&nbsp; runstats_pgk.rs_stop(100);</li>
<li>end sp_test;</li>
<li>/</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P490</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL 10G&gt;col OBJECT_NAME format a20;</li>
<li>SQL 10G&gt;col USER_NAME format a20;</li>
<li>&nbsp;</li>
<li>SQL 10G&gt;select /*+ rule */ lpad('--',decode(b.BLOCK,1,0,4))||s.username user_name,</li>
<li>&nbsp; 2&nbsp; &nbsp; &nbsp; &nbsp; b.TYPE,o.owner||'.'||o.object_name object_name,</li>
<li>&nbsp; 3&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.sid,s.serial#,decode(b.REQUEST,0,'BLOCKED','WAITING') status</li>
<li>&nbsp; 4&nbsp; &nbsp; &nbsp; &nbsp; FROM dba_objects o,v$session s,v$lock v,v$lock b</li>
<li>&nbsp; 5&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE v.ID1=o.object_id AND v.SID=s.sid</li>
<li>&nbsp; 6&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and v.SID=b.SID and (b.BLOCK=1 or b.REQUEST&gt;0)</li>
<li>&nbsp; 7&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and v.TYPE='TM'</li>
<li>&nbsp; 8&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order by by b.ID2,v.ID1,User_name desc;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P492</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">SQL 10G&gt; select sql_text</li>
<li>&nbsp; 2&nbsp; &nbsp; from v$sqlarea</li>
<li>&nbsp; 3&nbsp; &nbsp;where (v$sqlarea.address, v$sqlarea.hash_value) in (</li>
<li>&nbsp; 4&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select sql_address, sql_hash_value</li>
<li>&nbsp; 5&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from v$session</li>
<li>&nbsp; 6&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where sid in (</li>
<li>&nbsp; 7&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select sid</li>
<li>&nbsp; 8&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from v$session a, x$kglpn b</li>
<li>&nbsp; 9&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where a.saddr = b.kglpnuse</li>
<li>&nbsp;10&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and b.kglpnmod &lt;&gt; 0</li>
<li>&nbsp;11&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and b.kglpnhdl IN (select p1raw</li>
<li>&nbsp;12&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from v$session_wait</li>
<li>&nbsp;13*&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where sid=160 and event like 'library%')))</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P509</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">one session&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;other session</li>
<li>------------------------------------&nbsp; &nbsp; -----------------------------------</li>
<li>T1&gt; SQL&gt;insert into test values()</li>
<li>1 row inserted</li>
<li>&nbsp;</li>
<li>T2&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SQL&gt;insert into test values()</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 row inserted&nbsp; &nbsp;</li>
<li>&nbsp;</li>
<li>T3&gt; SQL&gt; update mystat set user_nums = </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;(select count(*) from test </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; where username=?)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;where id=?;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;1 row updated</li>
<li>&nbsp;</li>
<li>T4&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SQL&gt; update mystat set user_nums = </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (select count(*) from test </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where username=?)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where id=?;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 row updated</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</li>
<li>T5&gt;SQL&gt; commit;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Commit complete</li>
<li>&nbsp;&nbsp; &nbsp; </li>
<li>T6&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SQL&gt; commit;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Commit complete</li>
<li>&nbsp;</li>
<li>其中时间T1&lt;T2&lt;T3&lt;T5&lt;T5&lt;T6</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><strong>第15章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P516</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">declare </li>
<li>&nbsp; row_num number := 0;</li>
<li>begin</li>
<li>for c_test in (select id from my_test t where ftype is null) loop</li>
<li>&nbsp;&nbsp; update my_test t set t.ftype = 1 where id = c_test.id;</li>
<li>&nbsp;&nbsp; row_num := row_num + 1;</li>
<li>&nbsp;&nbsp; --1000条提交一次，可根据需要修改</li>
<li>&nbsp;&nbsp; if mod(row_num,1000) =0 then</li>
<li>&nbsp;&nbsp; &nbsp; commit;</li>
<li>&nbsp;&nbsp; end if;</li>
<li>end loop;</li>
<li>commit;</li>
<li>end;/</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P517</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">update my_users u set user_cnt=</li>
<li>(select user_cnt from </li>
<li>(select user_id,count(*) user_cnt from my_test group by user_id) tmp </li>
<li>where tmp.user_id=u.id)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;where exists</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; (select null from my_test t where u.id=t.user_id);</li>
<li>&nbsp;</li>
<li>SQL&gt;select tablespace_name,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; round(sum(bytes)/(1024*1024),2) free_space</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;from dba_free_space </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;where tablespace_name='TBS_UNDO'</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; group by tablespace_name;</li>
<li>&nbsp;</li>
<li>declare </li>
<li>&nbsp; row_num number := 0;</li>
<li>begin</li>
<li>for c_user in (select user_id,user_cnt from tmp_test t where flags = 0) loop</li>
<li>&nbsp;&nbsp; --更新目标表</li>
<li>update my_users t set t.user_cnt = c_user.cnt where id = c_user.user_id;</li>
<li>&nbsp;&nbsp; --更新临时表的标记位</li>
<li>update tmp_test f set f.flags = 1 where user_id = c_user.user_id;</li>
<li>&nbsp;&nbsp; row_num := row_num + 1;</li>
<li>&nbsp;&nbsp; --1000条提交一次</li>
<li>&nbsp;&nbsp; if mod(row_num,1000) =0 then</li>
<li>&nbsp;&nbsp; &nbsp; commit;</li>
<li>&nbsp;&nbsp; end if;</li>
<li>end loop;</li>
<li>&nbsp;</li>
<li>commit;</li>
<li>end;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P518</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">declare </li>
<li>&nbsp; row_num number := 0;</li>
<li>begin</li>
<li>for c_user in (select user_id,user_cnt from tmp_test t </li>
<li>where flags = 0 and rownum &lt;= 50000) loop</li>
<li>&nbsp;&nbsp; update my_users t set t.user_cnt = c_user.cnt where id = c_user.user_id;</li>
<li>&nbsp;&nbsp; update tmp_test f set f.flags = 1 where user_id = c_user.user_id;</li>
<li>&nbsp;&nbsp; row_num := row_num + 1;</li>
<li>&nbsp;&nbsp; if mod(row_num,1000) =0 then</li>
<li>&nbsp;&nbsp; &nbsp; commit;</li>
<li>&nbsp;&nbsp; end if;</li>
<li>end loop;</li>
<li>commit;</li>
<li>end;</li>
<li>&nbsp;</li>
<li>begin</li>
<li>&nbsp; for i in 1.. 5 loop</li>
<li>&nbsp;&nbsp; dbms_lock.sleep(300);</li>
<li>&nbsp;&nbsp; --这里嵌入更新数据的循环。</li>
<li>&nbsp; end loop;</li>
<li>end;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P520</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">declare </li>
<li>&nbsp; row_num number := 0;</li>
<li>begin</li>
<li>for c_user in (select user_id,user_cnt from tmp_test t where flags = 0) loop</li>
<li>&nbsp;&nbsp; --更新备份表，备份需要更新的数据</li>
<li>&nbsp;&nbsp; update tmp_test t set t. user_old_cnt =</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; (select user_cnt from my_users s where s.id=t.user_id)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; where t.user_id = c_user.user_id;</li>
<li>&nbsp; --再更新业务表 </li>
<li>update my_users t set t.user_cnt = c_user.cnt where id = c_user.user_id;</li>
<li>&nbsp; update tmp_test t set t.flags = 1 where user_id = c_user.user_id;</li>
<li>&nbsp;&nbsp; row_num := row_num + 1;</li>
<li>&nbsp;&nbsp; if mod(row_num,1000) =0 then</li>
<li>&nbsp;&nbsp; &nbsp; commit;</li>
<li>&nbsp;&nbsp; end if;</li>
<li>end loop;</li>
<li>commit;</li>
<li>end;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P523</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">declare </li>
<li>&nbsp; row_num number := 0;</li>
<li>begin</li>
<li>for c_test in (select rowed rid from table_name t where field_name is null) loop</li>
<li>&nbsp;&nbsp; update table_name t set t.field_name = 0 where rowid = c_test.rid;</li>
<li>&nbsp;&nbsp; row_num := row_num + 1;</li>
<li>&nbsp;&nbsp; if mod(row_num,1000) =0 then</li>
<li>&nbsp;&nbsp; &nbsp; commit;</li>
<li>&nbsp;&nbsp; end if;</li>
<li>end loop;</li>
<li>commit;</li>
<li>end;</li></ol></div>
<p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><strong>第16章</strong></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P548</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">$ more send_dbmail.sh </li>
<li>#!/bin/sh</li>
<li># creator: Piner</li>
<li># function: </li>
<li># usage:send mail</li>
<li># last modify:</li>
<li># modifier history: </li>
<li>#这里表示，至少需要有符合条件的三个参数，否则，会提示该脚本的用法</li>
<li>if [ $# -ne 3 ]; then</li>
<li>&nbsp;&nbsp; echo &quot;Usage: `basename $0`(title file group1|group2)&quot;</li>
<li>&nbsp;&nbsp; exit 1</li>
<li>fi</li>
<li>&nbsp;</li>
<li>#分组，把需要发送的对象分成不同的组，如组1的人员可能是主机管理者</li>
<li>#组2的人员可能是DB管理者</li>
<li>group1_mail=&quot;test1@gmail.com test2@gmail.com&quot;</li>
<li>group2_mail=&quot;test2@gmail.com test3@gmail.com test4@gmail.com&quot;</li>
<li>&nbsp;</li>
<li>TITLE=$1</li>
<li>MFILE=$2</li>
<li>&nbsp;</li>
<li>#send mail procedure</li>
<li>case $3 in</li>
<li>group1)echo &quot;send mail to dba-list&quot;</li>
<li>&nbsp;&nbsp; mail -s &quot;$TITLE&quot; $group1_mail &lt; $MFILE</li>
<li>;;</li>
<li>group2)echo &quot;send mail to dw&quot;</li>
<li>&nbsp;&nbsp; mail -s &quot;$TITLE&quot; $group2_mail &lt; $MFILE</li>
<li>;;</li>
<li>*)echo &quot;Usage: `basename $0`(title file group1|group2)&quot;</li>
<li>;;</li>
<li>esac</li>
<li>#send end</li>
<li>echo &quot;send mail end&quot;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P549</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">$ more send_dbmobile.sh </li>
<li>#!/bin/sh</li>
<li># creator: piner</li>
<li># function: </li>
<li># usage:send message to mobile </li>
<li># last modify: </li>
<li># modifier : </li>
<li>&nbsp;</li>
<li>#这里表示至少需要两个参数，信息内容与分组信息</li>
<li>if [ $# -ne 2 ]; then</li>
<li>&nbsp;&nbsp; echo &quot;Usage: `basename $0`(message&nbsp; group1|group2)&quot;</li>
<li>&nbsp;&nbsp; exit 1</li>
<li>fi</li>
<li>&nbsp;</li>
<li>#列出每个人的手机号码，仅仅是存在这个脚本中，</li>
<li>#如果有人更换了号码，只需要修改这里即可</li>
<li>user1=138xxxxxxxx</li>
<li>user2=139xxxxxxxx</li>
<li>user3=137xxxxxxxx</li>
<li>user4=130xxxxxxxx</li>
<li>&nbsp;</li>
<li>#写一个函数，来包装这个发送过程，这里假定短信网关是一个单独的服务器，</li>
<li>#IP地址是192.168.1.1，服务端口为8080，则可以用wget来调用这个发送短信的接口</li>
<li>#该函数仅仅是在这个脚本中被调用。</li>
<li>sendmobile() {</li>
<li>&nbsp;&nbsp; SURL='sms/index.php?bid=TEST&amp;receiver='</li>
<li>&nbsp;&nbsp; SURL=&quot;${SURL}$1&quot;</li>
<li>&nbsp;&nbsp; message=`echo $2 | sed -e 's/ /%20/g'`</li>
<li>&nbsp;&nbsp; SURL=&quot;${SURL}&amp;message=$message&quot;</li>
<li>&nbsp;&nbsp; wget -O /dev/null -o /dev/null &quot;http://192.168.1.1:8080/$SURL&quot; &gt; /dev/null 2&gt;&amp;1</li>
<li>&nbsp;&nbsp; echo &quot;succed to mobile&quot;</li>
<li>&nbsp;&nbsp; }</li>
<li>&nbsp;</li>
<li>#如果发现接收到的消息是空，则不发送，无意义，并返回失败</li>
<li>if [ -z &quot;$1&quot; ]</li>
<li>&nbsp; then</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;message is null!&quot;</li>
<li>&nbsp; exit 1</li>
<li>fi</li>
<li>&nbsp;</li>
<li>mesglog=&quot;$1&quot;</li>
<li>&nbsp;</li>
<li>#这里开始发送手机短信，也是采用分组的方式</li>
<li>#把需要发送到的目标按要求分成不同的组，</li>
<li>#到时候，如目标是主机，则可以发送短信到主机组，数据库则可以发送短信到DB组。</li>
<li>#send procedure</li>
<li>case $2 in</li>
<li>group1)echo &quot;send message to group1&quot;</li>
<li>&nbsp;&nbsp; sendmobile &quot;$user1&quot; &quot;$mesglog&quot;</li>
<li>&nbsp;&nbsp; sendmobile &quot;$user2&quot; &quot;$mesglog&quot; </li>
<li>;;</li>
<li>group2)echo &quot;send message to group2&quot;</li>
<li>&nbsp;&nbsp; sendmobile &quot;$user3&quot; &quot;$mesglog&quot;</li>
<li>&nbsp;&nbsp; sendmobile &quot;$user4&quot; &quot;$mesglog&quot; </li>
<li>;;</li>
<li>*)echo &quot;Usage: `basename $0`(message&nbsp; group1|group2)&quot;</li>
<li>;;</li>
<li>esac</li>
<li>#send end</li>
<li>echo &quot;send message to mobile end&quot;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P550</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">$ more monitor_api.sh </li>
<li>#!/bin/sh</li>
<li># creator: piner</li>
<li># function: </li>
<li># usage:call monitor's&nbsp; interface</li>
<li># last modify: </li>
<li># modifier : </li>
<li>&nbsp;</li>
<li>#判断参数是否合适</li>
<li>#如果是发送短信，需要传递信息内容与发送组</li>
<li>#如果是发送邮件，需要传递标题，与文件名称与发送组</li>
<li>#如果仅仅是拷贝文件，需要提供源文件名称与目标文件名称</li>
<li>if [ $# -ge 1 ]; then</li>
<li>&nbsp; if [ $1 == 'mobile' ]; then</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;send mobile message&quot;</li>
<li>&nbsp;&nbsp; &nbsp;if [ $# -ne 3 ]</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; echo &quot;Usage: `basename $0`(mobile message group)&quot;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; exit 1</li>
<li>&nbsp;&nbsp; &nbsp;fi</li>
<li>&nbsp; elif [ $1 == 'mail' ]; then</li>
<li>&nbsp;&nbsp; echo &quot;send mail message&quot;</li>
<li>&nbsp;&nbsp; if [ $# -ne 4 ]</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; echo &quot;Usage: `basename $0`(mail title group filename)&quot;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; exit 1</li>
<li>&nbsp;&nbsp; fi</li>
<li>&nbsp; elif [ $1 == 'scp' ]; then</li>
<li>&nbsp;&nbsp; echo &quot;only scp file to monitor&quot;</li>
<li>&nbsp;&nbsp; if [ $# -ne 3 ]; then</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; echo &quot;Usage: `basename $0`(scp source_file dest_file)&quot;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; exit 1</li>
<li>&nbsp;&nbsp; fi </li>
<li>&nbsp; else</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;Usage: `basename $0`(mobile message group)&quot;</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;or Usage: `basename $0`(mail title group filename)&quot;</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;or Usage: `basename $0`(scp source_file dest_file)&quot;</li>
<li>&nbsp;&nbsp; &nbsp;exit 1</li>
<li>&nbsp; fi</li>
<li>fi</li>
<li>&nbsp;</li>
<li>#定义monitor上的脚本位置</li>
<li>SENDMSG= /home/admin/bin/send_dbmobile.sh</li>
<li>SENDDBM= /home/admin/bin/send_dbmail.sh</li>
<li>&nbsp;</li>
<li>#选择方式，如果是发送短信</li>
<li>if [ $1 == 'mobile' ]; then</li>
<li>&nbsp; message=$2</li>
<li>&nbsp; group=$3</li>
<li>&nbsp; ssh admin@monitor &quot;$SENDMSG '$message' '$group'&quot;</li>
<li>fi</li>
<li>#选择方式，如果是发送邮件</li>
<li>#注意这里的文件是在monitor上的，是全路径名称</li>
<li>if [ $1 == 'mail' ]; then</li>
<li>&nbsp; title=$2</li>
<li>&nbsp; group=$3</li>
<li>&nbsp; mfile=$5</li>
<li>&nbsp; ssh admin@monitor &quot;$SENDDBM '$title' '$mfile' '$group'&quot;</li>
<li>fi</li>
<li>#选择方式，如果是拷贝文件，注意这里的文件是全路径名称</li>
<li>if [ $1 == 'scp' ]; then</li>
<li>&nbsp; sfile=$2</li>
<li>&nbsp; dfile=$3</li>
<li>&nbsp; scp $sfile admin@monitor:$dfile</li>
<li>fi</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P555</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">$more server_info.sh</li>
<li>#!/bin/ksh</li>
<li># creator: piner</li>
<li># function: copy system load and alert log file to monitor</li>
<li># usage: crontab on host</li>
<li># last modify: </li>
<li>&nbsp;</li>
<li>#get host tag and Oracle sid</li>
<li>dbname=`hostname`</li>
<li>ORACLE_SID=$1</li>
<li>ORACLE_BASE=/u01/Oracle</li>
<li>ALERT=$ORACLE_BASE/admin/${ORACLE_SID}/bdump/alert_${ORACLE_SID}.log</li>
<li>&nbsp;</li>
<li>#这里简单地指定monitor接口程序的位置，至于这个接口成本，见本章前面</li>
<li>#在实际情况中，可以把这个信息写到配置文件中</li>
<li>MONITOR=/home/Oracle/bin/monitor_api.sh </li>
<li>&nbsp;</li>
<li>#load</li>
<li>uptime|sed 's/.*average://g' &gt; /tmp/${dbname}load.log</li>
<li>#这里调用接口程序，表示把保存系统负载的信息提交到monitor上</li>
<li>$MONITOR &quot;scp&quot; &quot;/tmp/${dbname}load.log&quot; &quot;/home/admin/log/${dbname}load.log&quot;</li>
<li>&nbsp;</li>
<li>#alert</li>
<li>#这里表示把数据库的alert文件，拷贝到monitor上</li>
<li>$MONITOR &quot;scp&quot; &quot;$ALERT&quot; &quot;/tmp/${dbname}_alert.log&quot;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P556</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">$more disk_info.sh</li>
<li>#!/bin/ksh</li>
<li># creator: piner</li>
<li># function: copy disk using to monitor</li>
<li># usage: crontab on host</li>
<li># last modify: </li>
<li>&nbsp;</li>
<li>#get host tag and Oracle sid</li>
<li>dbname=`hostname`</li>
<li>MONITOR=/home/Oracle/bin/monitor_api.sh </li>
<li>&nbsp;</li>
<li>#disk spce</li>
<li>df -g|grep -v proc|grep -v Oraclebak|sed 1d &gt; /tmp/${dbname}df.log</li>
<li>#这里调用接口程序，表示把保存磁盘使用率的信息提交到monitor上</li>
<li>$MONITOR &quot;scp&quot; &quot;/tmp/${dbname}df.log&quot; &quot;/home/admin/log/${dbname}df.log&quot;</li>
<li>&nbsp;</li>
<li>create or replace procedure sp_getdb_info</li>
<li>( p_tran_nums out number,</li>
<li>&nbsp;p_elps_time out number)</li>
<li>is</li>
<li>&nbsp; m_count number;</li>
<li>&nbsp; m_old_tran_nums number :=0;</li>
<li>&nbsp; m_old_time date;</li>
<li>&nbsp; m_new_tran_nums number :=0;</li>
<li>&nbsp; m_new_time date;</li>
<li>begin</li>
<li>&nbsp;--注意，这里把原来的老数据记录在临时表中，如果临时表还没有初始化</li>
<li>&nbsp;--则需要先初始化临时表 </li>
<li>&nbsp;</li>
<li>select count(*) into m_count from tmp_db_info;</li>
<li>&nbsp; if m_count = 0 then</li>
<li>&nbsp;&nbsp; &nbsp;insert into tmp_db_info</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;select s.NAME,s.VALUE,sysdate from v$sysstat s</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;where s.NAME in </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;('user commits',</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;'user rollbacks');</li>
<li>&nbsp;&nbsp; &nbsp;commit;</li>
<li>&nbsp;&nbsp; &nbsp;--如果初始化完成，则直接返回</li>
<li>return;</li>
<li>&nbsp; end if;</li>
<li>&nbsp;</li>
<li>--正常情况下，先获得上次执行时的时间值</li>
<li>&nbsp;&nbsp; &nbsp;select gmt_create into m_old_time from tmp_db_info</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;where rownum &lt;= 1;</li>
<li>--然后得到上次的事务数</li>
<li>&nbsp;&nbsp; &nbsp;for c_tmp in (select * from tmp_db_info) loop</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; if c_tmp.event_name='user commits' then</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_old_tran_nums := m_old_tran_nums + c_tmp.db_values;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;elsif c_tmp.event_name='user rollbacks' then</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_old_tran_nums := m_old_tran_nums + c_tmp.db_values;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;null;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end if;</li>
<li>&nbsp;&nbsp; &nbsp;end loop;</li>
<li>--然后，删除临时表</li>
<li>&nbsp;&nbsp; delete from tmp_db_info;</li>
<li>--在临时表中写入新的值</li>
<li>&nbsp;&nbsp; insert into tmp_db_info</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;select s.NAME,s.VALUE,sysdate from v$sysstat s</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;where s.NAME in</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;('user commits',</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;'user rollbacks');</li>
<li>&nbsp;&nbsp; &nbsp; commit;</li>
<li>--得到现在的新值</li>
<li>&nbsp;&nbsp; select gmt_create into m_new_time from tmp_db_info</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;where rownum &lt;= 1;</li>
<li>&nbsp;&nbsp; for c_tmp in (select * from tmp_db_info) loop</li>
<li>&nbsp;&nbsp; &nbsp; if c_tmp.event_name='user commits' then</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;m_new_tran_nums := m_new_tran_nums + c_tmp.db_values;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;elsif c_tmp.event_name='user rollbacks' then</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;m_new_tran_nums := m_new_tran_nums + c_tmp.db_values;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;else</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;null;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;end if;</li>
<li>&nbsp;&nbsp; end loop;</li>
<li>--得到两次调用之间的时间差</li>
<li>&nbsp;&nbsp; p_elps_time := round((m_new_time - m_old_time)*24*3600,2);</li>
<li>&nbsp;--得到两次调用之间的每秒事务数</li>
<li>&nbsp;&nbsp; p_tran_nums := round((m_new_tran_nums - m_old_tran_nums)/p_elps_time,2);</li>
<li>&nbsp;</li>
<li>end;</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P557</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">$ more&nbsp; user_db_info.sh</li>
<li>#!/bin/ksh</li>
<li>date</li>
<li>#Oracle sid，一般作为参数传递</li>
<li>export ORACLE_SID=$1</li>
<li>#Oracle环境变量</li>
<li>export ORACLE_HOME=/u01/Oracle/product/9.2</li>
<li>export PATH=$ORACLE_HOME/bin:$PATH</li>
<li>export NLS_LANG=american_america.zhs16gbk</li>
<li>&nbsp;</li>
<li>dbname=`hostname`</li>
<li>LOGFILE=/home/Oracle/logs/db_info.log</li>
<li>MONITOR=/home/Oracle/bin/monitor_api.sh </li>
<li>&nbsp;</li>
<li>#调用sqlplus，执行存储过程，获得当前数值</li>
<li>$ORACLE_HOME/bin/sqlplus -S perfstat/perfstat &lt;&lt;EOF</li>
<li>set echo off</li>
<li>set feedback off</li>
<li>set heading off</li>
<li>set pagesize 0</li>
<li>set linesize 1000</li>
<li>set trimspool on</li>
<li>spool $LOGFILE</li>
<li>&nbsp;</li>
<li>variable p_tran_nums number;</li>
<li>variable p_elps_time number;</li>
<li>&nbsp;</li>
<li>begin</li>
<li>&nbsp; -- Call the procedure</li>
<li>&nbsp; sp_getdb_info(p_tran_nums =&gt; :p_tran_nums,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p_elps_time =&gt; :p_elps_time);</li>
<li>end;</li>
<li>/</li>
<li>&nbsp;</li>
<li>col val format a120 newline</li>
<li>select&nbsp; 'Transactions/s:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '||:p_tran_nums&nbsp; val,</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;'elapse time(s):&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '||:p_elps_time&nbsp; val</li>
<li>from dual;</li>
<li>&nbsp;</li>
<li>spool off</li>
<li>exit</li>
<li>EOF</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P559</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">$more dbload_check.sh</li>
<li>#!/bin/sh</li>
<li># creator: piner</li>
<li># function: db's load check</li>
<li># usage: crontab on monitor</li>
<li># last modify: </li>
<li>&nbsp;</li>
<li>#等待采集端主机采集负载信息</li>
<li>sleep 20</li>
<li>#负载文件所存在的目录地址</li>
<li>DESTDIR=/home/admin/log</li>
<li>#负载的报警阀值，也就是说，超过这个值的负载，则认为是有必要报警的</li>
<li>loadoff=20</li>
<li>#定义发送短信的接口</li>
<li>SENDMSG= /home/admin/bin/send_dbmobile.sh</li>
<li>&nbsp;</li>
<li>#这里采用循环的方式在多个主机之间检测，如果增加或者减少一个主机，只需要修改这个列表即可</li>
<li>#这个列表也可以写在配置文件中</li>
<li>DEST_SERVERS=&quot;db1 db2 db3 db4&quot;</li>
<li>for DEST_SERVER in $DEST_SERVERS</li>
<li>do</li>
<li>&nbsp; echo -e &quot;\033[32;1m============== $DEST_SERVER ==============\033[0m&quot;;</li>
<li>&nbsp; #从主机传送过来的文件上，获得最新的负载信息</li>
<li>&nbsp; load=`cat $DESTDIR/${DEST_SERVER}load.log|awk '{print $1}'|sed s/','//g` </li>
<li>&nbsp; echo -e &quot;System load now is \033[40;31m&quot;$load&quot;\033[40;37m&quot;</li>
<li>&nbsp;</li>
<li>&nbsp; #负载检查，注意，这里使用了命令bc，因为负载是一个小数，普通的shell不支持小数的比较，所以，这里引</li>
<li>&nbsp;&nbsp; 入了bc来比较小数 </li>
<li>&nbsp; #如果负载大于指定的阀值，则发送一个手机短信到特定的组中</li>
<li>&nbsp; if [ `echo &quot;$load &gt;= $loadoff&quot; | bc` -eq 1 ]; then</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; mesglog=&quot;$DEST_SERVER's system load more than &quot;$loadoff&quot; now is &quot;$load</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; $SENDMSG &quot;$mesglog&quot; &quot;group1&quot;</li>
<li>&nbsp; fi</li>
<li>done</li></ol></div>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">P560</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">$more alertcheck.sh </li>
<li>#!/bin/sh</li>
<li># creator: piner</li>
<li># function: check db's alert.log file</li>
<li># usage: crontab on monitor</li>
<li># last modify: </li>
<li>&nbsp;</li>
<li>#等待采集端主机采集负载信息</li>
<li>sleep 20</li>
<li>&nbsp;</li>
<li>#发送邮件与发送短信的接口</li>
<li>ENDMSG= /home/admin/bin/ send_dbmobile.sh</li>
<li>SENDDBM= /home/admin/bin/send_dbmail.sh</li>
<li>&nbsp;</li>
<l