<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AnySQL.net &#187; Archive</title>
	<atom:link href="http://www.anysql.net/tag/archive/feed" rel="self" type="application/rss+xml" />
	<link>http://www.anysql.net</link>
	<description>SQLULDR2, DataCopy, DataSync, WebChart, OraMon, AUL/MyDUL, 性能优化及容量分析</description>
	<lastBuildDate>Wed, 14 Jul 2010 09:27:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>归档日志管理不容易</title>
		<link>http://www.anysql.net/dba/keep_enough_archive_log.html</link>
		<comments>http://www.anysql.net/dba/keep_enough_archive_log.html#comments</comments>
		<pubDate>Fri, 06 Feb 2009 17:10:21 +0000</pubDate>
		<dc:creator>anysql</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Archive]]></category>
		<category><![CDATA[Drop]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Recovery]]></category>

		<guid isPermaLink="false">http://www.anysql.net/wordpress/uncategorized/%e5%bd%92%e6%a1%a3%e6%97%a5%e5%bf%97%e7%ae%a1%e7%90%86%e4%b8%8d%e5%ae%b9%e6%98%93.html</guid>
		<description><![CDATA[&#160; &#160; 昨天晚上接到一网友电话, 咨询一件事情, 聊了一会后才明白了是什么事情. 一个数据库中有两个用户A和B, 理论上所有的表应当分别存在DATA_A和DATA_B中, 现在要清掉B用户及DATA_B表空间以释入空间, 没有事先做足够多的检查, 就将DATA_B表空间及数据文件删除了, 事后发现A用户有一两个重要的表存在DATA_B表空间上, 引起了系统停机问题. &#160; &#160; 由于数据库巨大, 最近的全备是一年多以前的了, 从里面还原出来进行恢复, 才发现丢了一年前的一两个归档日志, 因此束手无策, 来咨询我怎么办, 其实已经没有捷径可走了. 这个问题的背后从小处看却是归档日志管理的问题, 理论上大家都知道应当去定期检查, 但事实上能照着做的人很少. &#160; &#160; 最近我自已也有两个和归档日志有关的问题, 还好年前用智能化角本来管理归档日志了, 才避免了Standby的重建工作. 第一次在节前业务高峰, 远程Standby的存贮设备太差了, 恢复跟不上, 积累了上TB的归档日志, 如果用原来的归档清除脚本, 早就不行了, 用了智能的脚本强行顶着, 最后撑到了现在跟上了, 要不又要重建几个TB的Standby了. &#160; &#160; 第二次是过年中间远程备库的机器挂起了, 大家都回去过年了, 又是Standby就暂时不管了, 因为智能脚本中只会在Primary上删除已经在这个Standby上应用过的日志, 所以很多天的归档日志得以保留下来, 将机器重起一下后, 再传归档日志过去, 又一次避免了Standby的重建工作. &#160; &#160; 也和很多企业, 没有充分认识到数据的作用, 没有给管理员一个简单一些的操作环境, 有关. 当然更重要的是DBA要有责任心, [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp; &nbsp; 昨天晚上接到一网友电话, 咨询一件事情, 聊了一会后才明白了是什么事情. 一个数据库中有两个用户A和B, 理论上所有的表应当分别存在DATA_A和DATA_B中, 现在要清掉B用户及DATA_B表空间以释入空间, 没有事先做足够多的检查, 就将DATA_B表空间及数据文件删除了, 事后发现A用户有一两个重要的表存在DATA_B表空间上, 引起了系统停机问题. </p>
<p>&nbsp; &nbsp; 由于数据库巨大, 最近的全备是一年多以前的了, 从里面还原出来进行恢复, 才发现丢了一年前的一两个归档日志, 因此束手无策, 来咨询我怎么办, 其实已经没有捷径可走了.  这个问题的背后从小处看却是归档日志管理的问题, 理论上大家都知道应当去定期检查, 但事实上能照着做的人很少. </p>
<p>&nbsp; &nbsp; 最近我自已也有两个和归档日志有关的问题, 还好年前用<a href="http://www.anysql.net/dba/perl_purge_primary_archivelog.html">智能化角本</a>来管理归档日志了, 才避免了Standby的重建工作. 第一次在节前业务高峰, 远程Standby的存贮设备太差了, 恢复跟不上, 积累了上TB的归档日志, 如果用原来的归档清除脚本, 早就不行了, 用了智能的脚本强行顶着, 最后撑到了现在跟上了, 要不又要重建几个TB的Standby了. </p>
<p>&nbsp; &nbsp; 第二次是过年中间远程备库的机器挂起了, 大家都回去过年了, 又是Standby就暂时不管了, 因为智能脚本中只会在Primary上删除已经在这个Standby上应用过的日志, 所以很多天的归档日志得以保留下来, 将机器重起一下后, 再传归档日志过去, 又一次避免了Standby的重建工作. </p>
<p>&nbsp; &nbsp; 也和很多企业, 没有充分认识到数据的作用, 没有给管理员一个简单一些的操作环境, 有关. 当然更重要的是DBA要有责任心, 然后才能细心认真地工作. </p>
<h3  class="related_post_title">Relative Posts:</h3><ul class="related_post"><li>2008/07/06 -- <a href="http://www.anysql.net/aulmydul/tuning_update_sql_01.html" title="连错库误删100多张表">连错库误删100多张表</a> (9)</li><li>2007/06/02 -- <a href="http://www.anysql.net/research/use_mylog_for_recovery.html" title="MyLOG程序对于Drop类误操作恢复的作用">MyLOG程序对于Drop类误操作恢复的作用</a> (0)</li><li>2009/04/26 -- <a href="http://www.anysql.net/aulmydul/aul_customer_world_map.html" title="拯救数据, 拯救地球?">拯救数据, 拯救地球?</a> (9)</li><li>2008/12/27 -- <a href="http://www.anysql.net/aulmydul/aul_parallel_scan_extent.html" title="AUL并行扫描Extent">AUL并行扫描Extent</a> (1)</li><li>2008/11/25 -- <a href="http://www.anysql.net/developer/purge_archivelog_by_space.html" title="指定保留多少GB的归档">指定保留多少GB的归档</a> (1)</li><li>2008/08/14 -- <a href="http://www.anysql.net/life/forced_free_data_recovery.html" title="一次被迫免费的恢复">一次被迫免费的恢复</a> (14)</li><li>2008/08/13 -- <a href="http://www.anysql.net/dba/good_protect_your_data.html" title="小心看好你的数据">小心看好你的数据</a> (5)</li><li>2008/08/01 -- <a href="http://www.anysql.net/aulmydul/to_date_from_quarter.html" title="终极Oracle数据恢复工具 &#8212; AUL">终极Oracle数据恢复工具 &#8212; AUL</a> (8)</li><li>2008/05/12 -- <a href="http://www.anysql.net/aulmydul/undo_and_index_bugs.html" title="Oracle不行再用AUL">Oracle不行再用AUL</a> (7)</li><li>2008/04/17 -- <a href="http://www.anysql.net/aulmydul/aul_for_sybase_ase.html" title="Oracle DUL不行就用AUL">Oracle DUL不行就用AUL</a> (10)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.anysql.net/dba/keep_enough_archive_log.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>指定保留多少GB的归档</title>
		<link>http://www.anysql.net/developer/purge_archivelog_by_space.html</link>
		<comments>http://www.anysql.net/developer/purge_archivelog_by_space.html#comments</comments>
		<pubDate>Wed, 26 Nov 2008 05:57:34 +0000</pubDate>
		<dc:creator>anysql</dc:creator>
				<category><![CDATA[Developer]]></category>
		<category><![CDATA[Archive]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.anysql.net/wordpress/uncategorized/%e6%8c%87%e5%ae%9a%e4%bf%9d%e7%95%99%e5%a4%9a%e5%b0%91gb%e7%9a%84%e5%bd%92%e6%a1%a3.html</guid>
		<description><![CDATA[&#160; &#160; 管理很多个数据库的归档日志时, 比较好的功能是保留指定容量的归档, 一般来讲归档所在的卷是独立的, 以容易方式设置比设置归档产生时间和归档日志个数都有优势. 下面是用Perl实现了这个功能, 传入一个日志序号(通常传入最大的日志号)和一个容量(以GB为单位). # # getLogSequenceBySize # sub getLogSequenceBySize { &#160; my ($logseq, $szlimit) = @_; &#160; my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev, &#160; &#160; &#160; $size,$atime,$mtime,$ctime,$blksize,$blocks); &#160; my $totalsz = 0; &#160; my ($archive_log); &#160; $szlimit = 20 if (!defined($szlimit) or $szlimit &#60; 20); &#160; while ($totalsz &#60; $szlimit) &#160; { &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp; &nbsp; 管理很多个数据库的归档日志时, 比较好的功能是保留指定容量的归档, 一般来讲归档所在的卷是独立的, 以容易方式设置比设置归档产生时间和归档日志个数都有优势. 下面是用Perl实现了这个功能, 传入一个日志序号(通常传入最大的日志号)和一个容量(以GB为单位). </p>
<blockquote class="prefont"><p>
#<br />
# getLogSequenceBySize<br />
#<br />
sub getLogSequenceBySize<br />
{<br />
&nbsp;  my ($logseq, $szlimit) = @_;<br />
&nbsp;  my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,<br />
&nbsp; &nbsp; &nbsp;  $size,$atime,$mtime,$ctime,$blksize,$blocks);<br />
&nbsp;  my $totalsz = 0;<br />
&nbsp;  my ($archive_log);</p>
<p>&nbsp;  $szlimit = 20 if (!defined($szlimit) or $szlimit &lt; 20);</p>
<p>&nbsp;  while ($totalsz &lt; $szlimit)<br />
&nbsp;  {<br />
&nbsp; &nbsp; &nbsp; $archive_log = findLogBySequence($logseq);<br />
&nbsp; &nbsp; &nbsp; if (-e $archive_log)<br />
&nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp;  ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  $size,$atime,$mtime,$ctime,$blksize,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  $blocks) = stat($archive_log);<br />
&nbsp; &nbsp; &nbsp; &nbsp;  $totalsz = $totalsz + ($size/1024/1024/1024);<br />
&nbsp; &nbsp; &nbsp; &nbsp;  $logseq &#8211;;<br />
&nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; else<br />
&nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp;  last;<br />
&nbsp; &nbsp; &nbsp; }<br />
&nbsp;  }</p>
<p>&nbsp;  scalar $logseq;<br />
}
</p></blockquote>
<p>&nbsp; &nbsp; 数据库越多, 这样的智能脚本越有发挥余地. 有时间整一个Windows上的Perl脚本版本, Windows上的Oracle还是很多的. </p>
<h3  class="related_post_title">Relative Posts:</h3><ul class="related_post"><li>2008/11/25 -- <a href="http://www.anysql.net/developer/find_log_by_sequence.html" title="按Sequence查找归档日志">按Sequence查找归档日志</a> (0)</li><li>2008/11/20 -- <a href="http://www.anysql.net/dba/perl_purge_primary_archivelog.html" title="用Perl写Primary维护脚本">用Perl写Primary维护脚本</a> (1)</li><li>2008/11/15 -- <a href="http://www.anysql.net/dba/perl_purge_standby_archivelog.html" title="用Perl写Standby维护脚本">用Perl写Standby维护脚本</a> (1)</li><li>2009/07/08 -- <a href="http://www.anysql.net/developer/perl-script-crontab-schedule.html" title="在Crontab中调度Perl程序">在Crontab中调度Perl程序</a> (2)</li><li>2009/06/25 -- <a href="http://www.anysql.net/tools/oramon-system-event.html" title="oramon如何收集V$SYSTEM_EVENT数据?">oramon如何收集V$SYSTEM_EVENT数据?</a> (3)</li><li>2009/06/25 -- <a href="http://www.anysql.net/tools/oramon-session-history.html" title="oramon如何从V$SESSION收集性能数据?">oramon如何从V$SESSION收集性能数据?</a> (0)</li><li>2009/06/24 -- <a href="http://www.anysql.net/oracle/oramon-system-statistics.html" title="oramon如何从V$SYSSTAT收集性能数据?">oramon如何从V$SYSSTAT收集性能数据?</a> (1)</li><li>2009/05/26 -- <a href="http://www.anysql.net/dba/hard-choose-mysql-or-oracle.html" title="MySQL或Oracle, 是个问题?">MySQL或Oracle, 是个问题?</a> (7)</li><li>2009/05/21 -- <a href="http://www.anysql.net/dba/oramon-database-perf-alert.html" title="用oramon的数据进行报警">用oramon的数据进行报警</a> (3)</li><li>2009/04/05 -- <a href="http://www.anysql.net/dba/oramon_webchart_solution.html" title="轻量级Oracle性能监控">轻量级Oracle性能监控</a> (3)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.anysql.net/developer/purge_archivelog_by_space.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>按Sequence查找归档日志</title>
		<link>http://www.anysql.net/developer/find_log_by_sequence.html</link>
		<comments>http://www.anysql.net/developer/find_log_by_sequence.html#comments</comments>
		<pubDate>Wed, 26 Nov 2008 05:47:20 +0000</pubDate>
		<dc:creator>anysql</dc:creator>
				<category><![CDATA[Developer]]></category>
		<category><![CDATA[Archive]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[Startup]]></category>

		<guid isPermaLink="false">http://www.anysql.net/wordpress/uncategorized/%e6%8c%89sequence%e6%9f%a5%e6%89%be%e5%bd%92%e6%a1%a3%e6%97%a5%e5%bf%97.html</guid>
		<description><![CDATA[&#160; &#160; 在归档日志管理中很重要的一个功能, 就是根据一个Sequence号, 来查找归档日志的路径. 普通的做法是使用find命令来实现, 如下所示: # # Get the full archived log name by sequence # sub findLogBySequence { &#160; &#160; my ($logseq) = @_; &#160; &#160; my $logfile = &#8220;&#8221;; &#160; &#160; if (length($logfile) == 0) &#160; &#160; { &#160; &#160; &#160; &#160; # Foloowing logic is for Oracle 9i (sid_%t_%s.arc) &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp; &nbsp; 在归档日志管理中很重要的一个功能, 就是根据一个Sequence号, 来查找归档日志的路径. 普通的做法是使用find命令来实现, 如下所示: </p>
<blockquote class="prefont"><p>
#<br />
# Get the full archived log name by sequence<br />
#<br />
sub findLogBySequence<br />
{<br />
&nbsp; &nbsp; my ($logseq) = @_;<br />
&nbsp; &nbsp; my $logfile = &#8220;&#8221;;</p>
<p>&nbsp; &nbsp; if (length($logfile) == 0)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; # Foloowing logic is for Oracle 9i (sid_%t_%s.arc)<br />
&nbsp; &nbsp; &nbsp; &nbsp; $logfile = `find /data*/arch -follow -name *_${logseq}.* | head -1`;<br />
&nbsp; &nbsp; &nbsp; &nbsp; chomp($logfile);<br />
&nbsp; &nbsp; &nbsp; &nbsp; # Foloowing logic is for Oracle 10g (sid_%t_%s_%r.arc)<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (length($logfile) == 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  $logfile = `find /data*/arch -follow -name *_${logseq}_* | head -1`;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  chomp($logfile);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }</p>
<p>&nbsp; &nbsp; scalar $logfile;<br />
}
</p></blockquote>
<p>&nbsp; &nbsp; 如果要管理的归档日志很多, 可能要跑成百上千次find命令, 有些资源上的浪费, 可以好好优化一下, 一般来讲同类的归档肯定是放在一起的. 因此将上面的Perl程序优化如下: </p>
<p><span id="more-558"></span></p>
<blockquote class="prefont"><p>
my $logfmt = &#8220;???&#8221;;<br />
#<br />
# Get the full archived log name by sequence<br />
#<br />
sub findLogBySequence<br />
{<br />
&nbsp; &nbsp; my ($logseq) = @_;<br />
&nbsp; &nbsp; my $logfile = &#8220;&#8221;;</p>
<p>&nbsp; &nbsp; #<br />
&nbsp; &nbsp; # if archive log pattern is not null<br />
&nbsp; &nbsp; # get the archive log file from pattern<br />
&nbsp; &nbsp; #<br />
&nbsp; &nbsp; if ($logfmt ne &#8220;???&#8221;)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $logfile = $logfmt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; $logfile =~ s/XXXXXX/${logseq}/g;<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (! -e $logfile)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  $logfile = &#8220;&#8221;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  $logfmt = &#8220;???&#8221;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }</p>
<p>&nbsp; &nbsp; if (length($logfile) == 0)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; # Foloowing logic is for Oracle 9i (sid_%t_%s.arc)<br />
&nbsp; &nbsp; &nbsp; &nbsp; $logfile = `find /data*/arch -follow -name *_${logseq}.* | head -1`;<br />
&nbsp; &nbsp; &nbsp; &nbsp; chomp($logfile);<br />
&nbsp; &nbsp; &nbsp; &nbsp; # Foloowing logic is for Oracle 10g (sid_%t_%s_%r.arc)<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (length($logfile) == 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  $logfile = `find /data*/arch -follow -name *_${logseq}_* | head -1`;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  chomp($logfile);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }</p>
<p>&nbsp; &nbsp; # Store the archive log pattern<br />
&nbsp; &nbsp; if (length($logfile) and -e $logfile and $logfmt eq &#8220;???&#8221;)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $logfmt = $logfile;<br />
&nbsp; &nbsp; &nbsp; &nbsp; $logfmt =~ s/_${logseq}\./_XXXXXX\./;<br />
&nbsp; &nbsp; &nbsp; &nbsp; $logfmt =~ s/_${logseq}_/_XXXXXX_/;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; scalar $logfile;<br />
}
</p></blockquote>
<p>&nbsp; &nbsp; 有了高效的查找日志路径的算法, 就可以做更多智能的功能了, 如指定保留多少GB的归档. </p>
<h3  class="related_post_title">Relative Posts:</h3><ul class="related_post"><li>2008/11/25 -- <a href="http://www.anysql.net/developer/purge_archivelog_by_space.html" title="指定保留多少GB的归档">指定保留多少GB的归档</a> (1)</li><li>2008/11/20 -- <a href="http://www.anysql.net/dba/perl_purge_primary_archivelog.html" title="用Perl写Primary维护脚本">用Perl写Primary维护脚本</a> (1)</li><li>2008/11/15 -- <a href="http://www.anysql.net/dba/perl_purge_standby_archivelog.html" title="用Perl写Standby维护脚本">用Perl写Standby维护脚本</a> (1)</li><li>2009/07/08 -- <a href="http://www.anysql.net/developer/perl-script-crontab-schedule.html" title="在Crontab中调度Perl程序">在Crontab中调度Perl程序</a> (2)</li><li>2009/02/12 -- <a href="http://www.anysql.net/developer/get_aix_net_traffic.html" title="准确获取AIX的网络流量">准确获取AIX的网络流量</a> (0)</li><li>2008/12/04 -- <a href="http://www.anysql.net/developer/perl_get_disk_space.html" title="Perl取Linux/Unix磁盘空间">Perl取Linux/Unix磁盘空间</a> (4)</li><li>2008/11/28 -- <a href="http://www.anysql.net/developer/perl_is_tcp_port_alive.html" title="用Perl进行TCP端口确认">用Perl进行TCP端口确认</a> (0)</li><li>2008/08/28 -- <a href="http://www.anysql.net/developer/perl_aix_perfstat_script.html" title="Perl AIX-Perfstat-0.03编程">Perl AIX-Perfstat-0.03编程</a> (0)</li><li>2008/08/28 -- <a href="http://www.anysql.net/developer/install_perl_aix_perfstat.html" title="安装Perl AIX-Perfstat-0.03">安装Perl AIX-Perfstat-0.03</a> (1)</li><li>2007/08/22 -- <a href="http://www.anysql.net/dba/oracle_auto_startup.html" title="Oracle需要手工启动, 无法自动启动">Oracle需要手工启动, 无法自动启动</a> (4)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.anysql.net/developer/find_log_by_sequence.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用Perl写Primary维护脚本</title>
		<link>http://www.anysql.net/dba/perl_purge_primary_archivelog.html</link>
		<comments>http://www.anysql.net/dba/perl_purge_primary_archivelog.html#comments</comments>
		<pubDate>Thu, 20 Nov 2008 15:10:12 +0000</pubDate>
		<dc:creator>anysql</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Archive]]></category>
		<category><![CDATA[Data Guard]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Standby]]></category>

		<guid isPermaLink="false">http://www.anysql.net/wordpress/uncategorized/%e7%94%a8perl%e5%86%99primary%e7%bb%b4%e6%8a%a4%e8%84%9a%e6%9c%ac.html</guid>
		<description><![CDATA[&#160; &#160; 维护生产库上的归档日志都不是一件容易的事, 一方面要尽量保存可能多的归档日志, 另一方面又要确保归档日志空间足够, 给归档日志用的卷又不会是很大, 最关键的是你不能时时盯着卷的容量, 还要保证删除不出错. 这个工作其实是有如下几个需求: &#160; &#160; 1, 根据容量保存最新的日志, 如保存最新的200个归档. 2, 根据生成时间保存最新的日志, 如只删除一天以前产生的归档日志. 3, 只能删除已经在备库上应用过的归档日志, 以防止传输中出错, 最底要求是只能删除已经传送到一个或几个备库上的日志. 根据这三点要求来看, 你会发现目前没有好的现成的脚本来定期删除生产库上的归档日志, 所以我就自已写了一个, 可满足以上三个要求. &#160; &#160; 根据上一篇Standby的脚本, 很容易写一个脚本来获得备库上已经应用过的日志的Sequence号, 然后在删除主库归档日志文件的脚本中, 通过ssh来调用. sub getSSHStandbyLog { &#160; &#160; my ($host,$sid) = @_; &#160; &#160; my $logseq = &#8220;???&#8221;; &#160; &#160; eval { &#160; &#160; &#160; &#160; local [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp; &nbsp; 维护生产库上的归档日志都不是一件容易的事, 一方面要尽量保存可能多的归档日志, 另一方面又要确保归档日志空间足够, 给归档日志用的卷又不会是很大, 最关键的是你不能时时盯着卷的容量, 还要保证删除不出错. 这个工作其实是有如下几个需求: </p>
<p>&nbsp; &nbsp; 1, 根据容量保存最新的日志, 如保存最新的200个归档. 2, 根据生成时间保存最新的日志, 如只删除一天以前产生的归档日志. 3, 只能删除已经在备库上应用过的归档日志, 以防止传输中出错, 最底要求是只能删除已经传送到一个或几个备库上的日志. 根据这三点要求来看, 你会发现目前没有好的现成的脚本来定期删除生产库上的归档日志, 所以我就自已写了一个, 可满足以上三个要求. </p>
<p>&nbsp; &nbsp; 根据上一篇<a href="http://www.anysql.net/dba/perl_purge_standby_archivelog.html">Standby的脚本</a>, 很容易写一个脚本来获得备库上已经应用过的日志的Sequence号, 然后在删除主库归档日志文件的脚本中, 通过ssh来调用. </p>
<blockquote class="prefont"><p>
sub getSSHStandbyLog<br />
{<br />
&nbsp; &nbsp; my ($host,$sid) = @_;<br />
&nbsp; &nbsp; my $logseq = &#8220;???&#8221;;</p>
<p>&nbsp; &nbsp; eval {<br />
&nbsp; &nbsp; &nbsp; &nbsp; local $SIG{ALRM} = sub { die &#8220;???\n&#8221; }; # NB: \n required<br />
&nbsp; &nbsp; &nbsp; &nbsp; alarm 10;<br />
&nbsp; &nbsp; &nbsp; &nbsp; $logseq = `ssh -n -a -q -o NumberOfPasswordPrompts=0 $host /home/oracle/admin/bin/getstandbylog.pl $sid`;<br />
&nbsp; &nbsp; &nbsp; &nbsp; alarm 0;<br />
&nbsp; &nbsp; };<br />
&nbsp; &nbsp; $logseq = &#8220;???&#8221; if ($@ eq &#8220;???\n&#8221;);<br />
&nbsp; &nbsp; $logseq = &#8220;???&#8221; if (length($logseq) == 0);<br />
&nbsp; &nbsp; chomp($logseq);</p>
<p>&nbsp; &nbsp; scalar $logseq;<br />
}
</p></blockquote>
<p>&nbsp; &nbsp; 然后到着查找到最小的归档日志, 再顺着删除, 就比较完全了. 昨天已经在一个库上用上了新脚本, 正在观察中.</p>
<h3  class="related_post_title">Relative Posts:</h3><ul class="related_post"><li>2008/11/15 -- <a href="http://www.anysql.net/dba/perl_purge_standby_archivelog.html" title="用Perl写Standby维护脚本">用Perl写Standby维护脚本</a> (1)</li><li>2008/11/25 -- <a href="http://www.anysql.net/developer/purge_archivelog_by_space.html" title="指定保留多少GB的归档">指定保留多少GB的归档</a> (1)</li><li>2008/11/25 -- <a href="http://www.anysql.net/developer/find_log_by_sequence.html" title="按Sequence查找归档日志">按Sequence查找归档日志</a> (0)</li><li>2009/07/08 -- <a href="http://www.anysql.net/developer/perl-script-crontab-schedule.html" title="在Crontab中调度Perl程序">在Crontab中调度Perl程序</a> (2)</li><li>2009/02/12 -- <a href="http://www.anysql.net/developer/get_aix_net_traffic.html" title="准确获取AIX的网络流量">准确获取AIX的网络流量</a> (0)</li><li>2008/12/04 -- <a href="http://www.anysql.net/developer/perl_get_disk_space.html" title="Perl取Linux/Unix磁盘空间">Perl取Linux/Unix磁盘空间</a> (4)</li><li>2008/11/28 -- <a href="http://www.anysql.net/developer/perl_is_tcp_port_alive.html" title="用Perl进行TCP端口确认">用Perl进行TCP端口确认</a> (0)</li><li>2008/10/15 -- <a href="http://www.anysql.net/dba/huge_standby_with_rawsync.html" title="用rawsync来做Standby">用rawsync来做Standby</a> (0)</li><li>2008/10/14 -- <a href="http://www.anysql.net/dba/rawsync_ready_for_test.html" title="rawsync初步搞定">rawsync初步搞定</a> (1)</li><li>2008/09/27 -- <a href="http://www.anysql.net/dba/remote_raw_sync.html" title="Remote DD或Raw-rsync">Remote DD或Raw-rsync</a> (3)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.anysql.net/dba/perl_purge_primary_archivelog.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>用Perl写Standby维护脚本</title>
		<link>http://www.anysql.net/dba/perl_purge_standby_archivelog.html</link>
		<comments>http://www.anysql.net/dba/perl_purge_standby_archivelog.html#comments</comments>
		<pubDate>Sat, 15 Nov 2008 16:45:11 +0000</pubDate>
		<dc:creator>anysql</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Archive]]></category>
		<category><![CDATA[Data Guard]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Standby]]></category>

		<guid isPermaLink="false">http://www.anysql.net/wordpress/uncategorized/%e7%94%a8perl%e5%86%99standby%e7%bb%b4%e6%8a%a4%e8%84%9a%e6%9c%ac.html</guid>
		<description><![CDATA[&#160; &#160; Perl是一门非常适合用来写数据库管理脚本的语言, Shell当然也很强, 但在这个领域还是没有Perl好. 来讲一个最简单的需求, 需要取得Standby或Dataguard上最后一个应用的归档日志, 在普通恢复和Managed恢复方式都要支持, 这个需求并不容易准确地实现. 如果用Perl来分析Oracle的alert日志文件, 则比较容易. 如下所示: sub getLastRecoveredLog { &#160; &#160; my ($alert_log_file) = @_; &#160; &#160; my $logseq = &#8220;???&#8221;; &#160; &#160; my $lastline = `tail -1000 ${alert_log_file} &#124; grep &#8220;Media Recovery Log&#8221; &#124; tail -1`; &#160; &#160; if (defined($lastline)) &#160; &#160; { &#160; &#160; &#160; &#160; $lastline [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp; &nbsp; Perl是一门非常适合用来写数据库管理脚本的语言, Shell当然也很强, 但在这个领域还是没有Perl好. 来讲一个最简单的需求, 需要取得Standby或Dataguard上最后一个应用的归档日志, 在普通恢复和Managed恢复方式都要支持, 这个需求并不容易准确地实现. 如果用Perl来分析Oracle的alert日志文件, 则比较容易. 如下所示: </p>
<blockquote class="prefont"><p>
sub getLastRecoveredLog<br />
{<br />
&nbsp; &nbsp; my ($alert_log_file) = @_;<br />
&nbsp; &nbsp; my $logseq = &#8220;???&#8221;;<br />
&nbsp; &nbsp; my $lastline = `tail -1000 ${alert_log_file} | grep &#8220;Media Recovery Log&#8221; | tail -1`;<br />
&nbsp; &nbsp; if (defined($lastline))<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $lastline =~ s/.*\///g;<br />
&nbsp; &nbsp; &nbsp; &nbsp; my @cols = ($lastline =~ /\w+_\d?_(\d+)[\.|_]/);<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (defined($cols[0]))<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $logseq = $cols[0];<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $logseq = $logseq &#8211; 1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; scalar $logseq;<br />
}
</p></blockquote>
<p>&nbsp; &nbsp; 如要删除已经应用过的归档日志, 那么只需要再写一个根据Sequence查找归档日志位置的函数就行了. </p>
<blockquote class="prefont"><p>
sub findLogBySequence<br />
{<br />
&nbsp; &nbsp; my ($logseq) = @_;<br />
&nbsp; &nbsp; my $logfile = `find /data*/arch -follow -name *_${logseq}.* | head -1`;<br />
&nbsp; &nbsp; chomp($logfile);<br />
&nbsp; &nbsp; # Foloowing logic is for Oracle 10g<br />
&nbsp; &nbsp; if (length($logfile) == 0)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp;  $logfile = `find /data*/arch -follow -name *_${logseq}_* | head -1`;<br />
&nbsp; &nbsp; &nbsp;  chomp($logfile);<br />
&nbsp; &nbsp; }</p>
<p>&nbsp; &nbsp; scalar $logfile;<br />
}
</p></blockquote>
<p>&nbsp; &nbsp; 先找出所有要删除的归档日志, 存在变量中, 然后根据Sequence从小删到大就行了. </p>
<h3  class="related_post_title">Relative Posts:</h3><ul class="related_post"><li>2008/11/20 -- <a href="http://www.anysql.net/dba/perl_purge_primary_archivelog.html" title="用Perl写Primary维护脚本">用Perl写Primary维护脚本</a> (1)</li><li>2008/11/25 -- <a href="http://www.anysql.net/developer/purge_archivelog_by_space.html" title="指定保留多少GB的归档">指定保留多少GB的归档</a> (1)</li><li>2008/11/25 -- <a href="http://www.anysql.net/developer/find_log_by_sequence.html" title="按Sequence查找归档日志">按Sequence查找归档日志</a> (0)</li><li>2009/07/08 -- <a href="http://www.anysql.net/developer/perl-script-crontab-schedule.html" title="在Crontab中调度Perl程序">在Crontab中调度Perl程序</a> (2)</li><li>2009/02/12 -- <a href="http://www.anysql.net/developer/get_aix_net_traffic.html" title="准确获取AIX的网络流量">准确获取AIX的网络流量</a> (0)</li><li>2008/12/04 -- <a href="http://www.anysql.net/developer/perl_get_disk_space.html" title="Perl取Linux/Unix磁盘空间">Perl取Linux/Unix磁盘空间</a> (4)</li><li>2008/11/28 -- <a href="http://www.anysql.net/developer/perl_is_tcp_port_alive.html" title="用Perl进行TCP端口确认">用Perl进行TCP端口确认</a> (0)</li><li>2008/10/15 -- <a href="http://www.anysql.net/dba/huge_standby_with_rawsync.html" title="用rawsync来做Standby">用rawsync来做Standby</a> (0)</li><li>2008/10/14 -- <a href="http://www.anysql.net/dba/rawsync_ready_for_test.html" title="rawsync初步搞定">rawsync初步搞定</a> (1)</li><li>2008/09/27 -- <a href="http://www.anysql.net/dba/remote_raw_sync.html" title="Remote DD或Raw-rsync">Remote DD或Raw-rsync</a> (3)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.anysql.net/dba/perl_purge_standby_archivelog.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>LOG_ARCHIVE_FORMAT中%r值从哪儿来的?</title>
		<link>http://www.anysql.net/oracle/log_archive_format_10g.html</link>
		<comments>http://www.anysql.net/oracle/log_archive_format_10g.html#comments</comments>
		<pubDate>Fri, 03 Aug 2007 19:26:46 +0000</pubDate>
		<dc:creator>anysql</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Archive]]></category>
		<category><![CDATA[Format]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[Oracle10g]]></category>

		<guid isPermaLink="false">http://www.anysql.net/wordpress/uncategorized/log_archive_format%e4%b8%adr%e5%80%bc%e4%bb%8e%e5%93%aa%e5%84%bf%e6%9d%a5%e7%9a%84.html</guid>
		<description><![CDATA[&#160; &#160; 当数据库从9i或8i升级到10g时, 如果compatible参数也设成了10以上, 则LOG_ARCHIVE_FORMAT参数中必须包含%s, %t, %r参数. 其中%s是Log Seuqence; %t是Thread ID, RAC的节点中设有THREAD参数, 就是这个值了; %r指的是Resetlog ID了, 比较新, 得从Oracle 10g中增加的跨Resetlogs恢复功能说起. &#160; &#160; 为了支持这个功能, Oracle 10g在控制文件中新增了一部份内容, 就是历次Open Resetlogs的经过, 每经历一次Open Restlogs就生成了一个新的Incarnation(不知道如何翻译这个单词了), 反应到数据库中则是V$DATABASE_INCARNATION视图(基表x$kccic, 说明是存放在控制文件中的). 我这儿没有经过多次open resetlogs的数据库, 等一下验证一下. 查一个从来没有Open Resetlogs的库吧, 如下所示: ASQL&#62; SELECT * FROM v$DATABASE_INCARNATION/G; INCARNATION#&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;: 1 RESETLOGS_CHANGE#&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; : 1 RESETLOGS_TIME&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;: 2007-07-16 17:28:06.0 PRIOR_RESETLOGS_CHANGE#&#160;&#160;&#160;&#160;&#160;&#160; : 0 PRIOR_RESETLOGS_TIME&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;: null STATUS&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;: CURRENT [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp; &nbsp; 当数据库从9i或8i升级到10g时, 如果compatible参数也设成了10以上, 则LOG_ARCHIVE_FORMAT参数中必须包含%s, %t, %r参数. 其中%s是Log Seuqence; %t是Thread ID, RAC的节点中设有THREAD参数, 就是这个值了; %r指的是Resetlog ID了, 比较新, 得从Oracle 10g中增加的跨Resetlogs恢复功能说起. </p>
<p>&nbsp; &nbsp; 为了支持这个功能, Oracle 10g在控制文件中新增了一部份内容, 就是历次Open Resetlogs的经过, 每经历一次Open Restlogs就生成了一个新的Incarnation(不知道如何翻译这个单词了), 反应到数据库中则是V$DATABASE_INCARNATION视图(基表x$kccic, 说明是存放在控制文件中的). 我这儿没有经过多次open resetlogs的数据库, 等一下验证一下. 查一个从来没有Open Resetlogs的库吧, 如下所示:</p>
<blockquote class="prefont"><p>
ASQL&gt; SELECT * FROM v$DATABASE_INCARNATION/G;</p>
<p>INCARNATION#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 1<br />
RESETLOGS_CHANGE#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 1<br />
RESETLOGS_TIME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 2007-07-16 17:28:06.0<br />
PRIOR_RESETLOGS_CHANGE#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0<br />
PRIOR_RESETLOGS_TIME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: null<br />
STATUS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: CURRENT<br />
RESETLOGS_ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 628104486<br />
PRIOR_INCARNATION#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 0<br />
FLASHBACK_DATABASE_ALLOWED&nbsp;&nbsp;&nbsp;&nbsp;: NO</p>
<p>1 rows returned.
</p></blockquote>
<p>&nbsp; &nbsp; 从这儿可以推导出一个观点, 当你重建控制文件后, 将丢失跨Resetlogs恢复的能力. 还好控制文件的参数大部份都可以动态改了, 基本上没有重建它的需要了. 上面的值中, STATUS列的值为CURRENT表示是当前的Incarnation, 另外还可以从V$DATABASE中获得当前正在使用的Incarnation. 如下所示:</p>
<blockquote class="prefont"><p>
ASQL&gt; SELECT LAST_OPEN_INCARNATION# FROM V$DATABASE;</p>
<p>LAST_OPEN_INCARNATION#<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1</p>
<p>1 rows returned.
</p></blockquote>
<p>&nbsp; &nbsp; 有些部份还只是猜测, 如有错误, 请理解. </p>
<h3  class="related_post_title">Relative Posts:</h3><ul class="related_post"><li>2007/09/04 -- <a href="http://www.anysql.net/research/oracle_log_research_tasks.html" title="Oracle Log格式研究未完成的主要任务">Oracle Log格式研究未完成的主要任务</a> (0)</li><li>2007/09/04 -- <a href="http://www.anysql.net/research/oracle_11g_mylog_test.html" title="Oracle 11g系列测试 &#8212; MyLOG">Oracle 11g系列测试 &#8212; MyLOG</a> (2)</li><li>2007/08/24 -- <a href="http://www.anysql.net/research/log_change_capture.html" title="半年内Log研究可以达到的中间产品">半年内Log研究可以达到的中间产品</a> (7)</li><li>2007/05/30 -- <a href="http://www.anysql.net/research/my_oracle_logminer_10.html" title="解出Oracle日志文件中的Redo SQL语句之十">解出Oracle日志文件中的Redo SQL语句之十</a> (14)</li><li>2007/05/30 -- <a href="http://www.anysql.net/research/my_oracle_logminer_09.html" title="解出Oracle日志文件中的Redo SQL语句之九">解出Oracle日志文件中的Redo SQL语句之九</a> (1)</li><li>2007/05/29 -- <a href="http://www.anysql.net/research/my_oracle_logminer_08.html" title="解出Oracle日志文件中的Redo SQL语句之八">解出Oracle日志文件中的Redo SQL语句之八</a> (3)</li><li>2007/05/28 -- <a href="http://www.anysql.net/research/my_oracle_logminer_06.html" title="解出Oracle日志文件中的Redo SQL语句之六">解出Oracle日志文件中的Redo SQL语句之六</a> (0)</li><li>2007/05/25 -- <a href="http://www.anysql.net/research/my_oracle_logminer_05.html" title="解出Oracle日志文件中的Redo SQL语句之五">解出Oracle日志文件中的Redo SQL语句之五</a> (1)</li><li>2007/03/27 -- <a href="http://www.anysql.net/research/mylog_utility_update05.html" title="加强MyLOG软件, 以进行Log格式研究之五">加强MyLOG软件, 以进行Log格式研究之五</a> (0)</li><li>2007/03/26 -- <a href="http://www.anysql.net/research/mylog_utility_update04.html" title="加强MyLOG软件, 以进行Log格式研究之四">加强MyLOG软件, 以进行Log格式研究之四</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.anysql.net/oracle/log_archive_format_10g.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使refresh_mysql适用于数据归档的一点改进</title>
		<link>http://www.anysql.net/tools/refresh_mysql_delete_where.html</link>
		<comments>http://www.anysql.net/tools/refresh_mysql_delete_where.html#comments</comments>
		<pubDate>Fri, 30 Mar 2007 05:29:47 +0000</pubDate>
		<dc:creator>anysql</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Archive]]></category>
		<category><![CDATA[MVIEW]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Refresh]]></category>

		<guid isPermaLink="false">http://www.anysql.net/wordpress/uncategorized/%e4%bd%bfrefresh_mysql%e9%80%82%e7%94%a8%e4%ba%8e%e6%95%b0%e6%8d%ae%e5%bd%92%e6%a1%a3%e7%9a%84%e4%b8%80%e7%82%b9%e6%94%b9%e8%bf%9b.html</guid>
		<description><![CDATA[&#160; &#160; 受上一篇中案例的启发, 对refresh_mysql角本作了一点点改进, 可以为DELETE目标数据库的SQL加一个WHERE条件, 以防止删除不想删除的数据. 举个简单的例子来说, 有一个产品数据和历史库, 产品库中只有今年的记录, 而历史库中包括所有(当前的和07年以前)的数据, 我们还需要将产品库的修改比较实时地反应到历史库中, 那么我有可能要经常在产品库中删除三个月以前的记录, 为了不让这些删除操作被复制到历史库中, 就可以加一个Where条件了, 如&#8221;CREATE_DATE > SYSDATE &#8211; 30&#8243;, 这样的话, 就只能在历史库中更新最近三个月的记录了: &#160; &#160; 只需要refresh_mysql角本的配置文件后面再加一列, 如下所示: # SOURCE&#160;&#160;# PKEY&#160;&#160;&#160;&#160;&#160;&#160;# MVIEW Log&#160;&#160;&#160;&#160;&#160;&#160; # TARGET T_OBJECTS # OBJECT_ID # MLOG$_T_OBJECTS # T_OBJECGS # CREATE_DATE &#62; SYSDATE &#8211; 30 &#160; &#160; 这时在构造出来的删除目标表的SQL语句为: DELETE T_OBJECTS WHERE OBJECT_ID = ? AND [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp; &nbsp; 受<a href="http://www.anysql.net/dba/data_lost_by_mview_refresh.html">上一篇</a>中案例的启发, 对refresh_mysql角本作了一点点改进, 可以为DELETE目标数据库的SQL加一个WHERE条件, 以防止删除不想删除的数据. 举个简单的例子来说, 有一个产品数据和历史库, 产品库中只有今年的记录, 而历史库中包括所有(当前的和07年以前)的数据, 我们还需要将产品库的修改比较实时地反应到历史库中, 那么我有可能要经常在产品库中删除三个月以前的记录, 为了不让这些删除操作被复制到历史库中, 就可以加一个Where条件了, 如&#8221;CREATE_DATE > SYSDATE &#8211; 30&#8243;, 这样的话, 就只能在历史库中更新最近三个月的记录了: </p>
<p>&nbsp; &nbsp; 只需要refresh_mysql角本的<a href="http://www.anysql.net/tools/oracle_mysql_replication_demo.html">配置文件</a>后面再加一列, 如下所示: </p>
<blockquote class="prefont"><p>
# SOURCE&nbsp;&nbsp;# PKEY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# MVIEW Log&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # TARGET<br />
T_OBJECTS # OBJECT_ID # MLOG$_T_OBJECTS # T_OBJECGS # CREATE_DATE &gt; SYSDATE &#8211; 30
</p></blockquote>
<p>&nbsp; &nbsp; 这时在构造出来的删除目标表的SQL语句为: </p>
<blockquote class="prefont"><p>
DELETE T_OBJECTS WHERE OBJECT_ID = ? AND CREATE_DATE &gt; SYSDATE &#8211; 30
</p></blockquote>
<p>&nbsp; &nbsp; 其他的改进, 现在已经不是将UPDATE转化为先DELETE后INSERT了, 而是直接UPDATE, 以提高程序的效率, 减轻目标数据库的压力. 本角本可以免费使用, 但不提供免费的支持服务.</p>
<h3  class="related_post_title">Relative Posts:</h3><ul class="related_post"><li>2007/03/29 -- <a href="http://www.anysql.net/dba/data_lost_by_mview_refresh.html" title="由物化视图Complete刷新引起的数据丢失">由物化视图Complete刷新引起的数据丢失</a> (11)</li><li>2007/03/14 -- <a href="http://www.anysql.net/tools/oracle_mysql_replication_demo.html" title="refresh_mysql.pl角本的一个配置例子">refresh_mysql.pl角本的一个配置例子</a> (0)</li><li>2007/12/18 -- <a href="http://www.anysql.net/oracle/mview_ora_04031.html" title="MVIEW引起ORA-04031">MVIEW引起ORA-04031</a> (0)</li><li>2007/09/04 -- <a href="http://www.anysql.net/developer/tuning_with_array_dml.html" title="在Perl中用Array DML来进行性能调优">在Perl中用Array DML来进行性能调优</a> (0)</li><li>2007/03/24 -- <a href="http://www.anysql.net/developer/mysql_mview_log.html" title="在MySQL中建立实体化视图日志">在MySQL中建立实体化视图日志</a> (2)</li><li>2007/03/13 -- <a href="http://www.anysql.net/tools/perl_refresh_mysql.html" title="写了一个从Oracle复制到MySQL的Perl角本">写了一个从Oracle复制到MySQL的Perl角本</a> (2)</li><li>2007/03/12 -- <a href="http://www.anysql.net/oracle/oracle_mview_to_mysql.html" title="从Oracle向MySQL或其他库的数据复制方法">从Oracle向MySQL或其他库的数据复制方法</a> (7)</li><li>2007/03/09 -- <a href="http://www.anysql.net/oracle/mvlog_with_rowid_primarykey.html" title="Oracle的实体化视图(MVIEW)的深入研究之四">Oracle的实体化视图(MVIEW)的深入研究之四</a> (2)</li><li>2007/03/09 -- <a href="http://www.anysql.net/oracle/star_in_mview.html" title="Oracle的实体化视图(MVIEW)的深入研究之三">Oracle的实体化视图(MVIEW)的深入研究之三</a> (0)</li><li>2007/03/08 -- <a href="http://www.anysql.net/oracle/improve_mv_refresh.html" title="Oracle的实体化视图(MVIEW)的深入研究之一">Oracle的实体化视图(MVIEW)的深入研究之一</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.anysql.net/tools/refresh_mysql_delete_where.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
