<?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/"
		xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>happydba</title>
	<atom:link href="http://www.orablogger.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.orablogger.com</link>
	<description>Enjoy your work, and your life. (arie.sun # hotmail.com)</description>
	<lastBuildDate>Mon, 12 Mar 2012 02:33:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<copyright>2006-2007 </copyright>
	<managingEditor>ariebeyond@gmail.com (happydba)</managingEditor>
	<webMaster>ariebeyond@gmail.com (happydba)</webMaster>
	<image>
		<url>http://www.orablogger.com/wp-content/plugins/podpress/images/powered_by_podpress.jpg</url>
		<title>happydba</title>
		<link>http://www.orablogger.com</link>
		<width>144</width>
		<height>144</height>
	</image>
	<itunes:subtitle></itunes:subtitle>
	<itunes:summary>oracle dba&#039;s site</itunes:summary>
	<itunes:keywords></itunes:keywords>
	<itunes:category text="Society &#38; Culture" />
	<itunes:author>happydba</itunes:author>
	<itunes:owner>
		<itunes:name>happydba</itunes:name>
		<itunes:email>ariebeyond@gmail.com</itunes:email>
	</itunes:owner>
	<itunes:block>no</itunes:block>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.orablogger.com/wp-content/plugins/podpress/images/powered_by_podpress_large.jpg" />
		<item>
		<title>Oracle 11g 新特性：Oracle11g 后台进程概述</title>
		<link>http://www.orablogger.com/2012/03/oracle-11g-%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%9aoracle11g-%e5%90%8e%e5%8f%b0%e8%bf%9b%e7%a8%8b%e6%a6%82%e8%bf%b0/</link>
		<comments>http://www.orablogger.com/2012/03/oracle-11g-%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%9aoracle11g-%e5%90%8e%e5%8f%b0%e8%bf%9b%e7%a8%8b%e6%a6%82%e8%bf%b0/#comments</comments>
		<pubDate>Mon, 12 Mar 2012 02:33:13 +0000</pubDate>
		<dc:creator>happydba</dc:creator>
				<category><![CDATA[11g]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://www.orablogger.com/?p=533</guid>
		<description><![CDATA[一。Oracle11g 后台进程与10gR2的比较 我们知道，oracle数据库的后台进程一般以ora_开头来命名，下面就来看一下在Oracle11g中的后台进程都有哪些，以单节点的Oracle实例 为例： [root@ractest ~]# ps -ef&#124;grep ora_ &#124;sort +7 root 11768 5567 0 05:30 pts/4 00:00:00 grep ora_ oracle 28069 1 0 Jul20 ? 00:00:03 ora_cjq0_orcl oracle 28063 1 0 Jul20 ? 00:02:10 ora_ckpt_orcl oracle 28049 1 0 Jul20 ? 00:00:00 ora_dbrm_orcl oracle 28059 1 0 Jul20 ? 00:00:08 ora_dbw0_orcl oracle 28055 1 [...]]]></description>
			<content:encoded><![CDATA[<p>一。Oracle11g 后台进程与10gR2的比较<br />
    我们知道，oracle数据库的后台进程一般以ora_开头来命名，下面就来看一下在Oracle11g中的后台进程都有哪些，以单节点的Oracle实例</p>
<p>为例：<br />
[root@ractest ~]# ps -ef|grep ora_ |sort +7<br />
root     11768  5567  0 05:30 pts/4    00:00:00 grep ora_<br />
oracle   28069     1  0 Jul20 ?        00:00:03 ora_cjq0_orcl<br />
oracle   28063     1  0 Jul20 ?        00:02:10 ora_ckpt_orcl<br />
oracle   28049     1  0 Jul20 ?        00:00:00 ora_dbrm_orcl<br />
oracle   28059     1  0 Jul20 ?        00:00:08 ora_dbw0_orcl<br />
oracle   28055     1  0 Jul20 ?        00:00:06 ora_dia0_orcl<br />
oracle   28047     1  0 Jul20 ?        00:00:02 ora_diag_orcl<br />
oracle   28085     1  0 Jul20 ?        00:00:02 ora_fbar_orcl<br />
oracle   28061     1  0 Jul20 ?        00:00:05 ora_lgwr_orcl<br />
oracle   28057     1  0 Jul20 ?        00:00:00 ora_mman_orcl<br />
oracle   28073     1  0 Jul20 ?        00:00:09 ora_mmnl_orcl<br />
oracle   28071     1  0 Jul20 ?        00:00:06 ora_mmon_orcl<br />
oracle   28043     1  0 Jul20 ?        00:00:08 ora_pmon_orcl<br />
oracle   28051     1  0 Jul20 ?        00:00:00 ora_psp0_orcl<br />
oracle   28108     1  0 Jul20 ?        00:00:00 ora_q000_orcl<br />
oracle   28110     1  0 Jul20 ?        00:00:00 ora_q001_orcl<br />
oracle   28089     1  0 Jul20 ?        00:00:00 ora_qmnc_orcl<br />
oracle   28067     1  0 Jul20 ?        00:00:00 ora_reco_orcl<br />
oracle   28087     1  0 Jul20 ?        00:00:00 ora_smco_orcl<br />
oracle   28065     1  0 Jul20 ?        00:00:14 ora_smon_orcl<br />
oracle   28045     1  0 Jul20 ?        00:00:00 ora_vktm_orcl<br />
oracle   11559     1  0 04:52 ?        00:00:00 ora_w000_orcl</p>
<p>比较一下Oracle10gR2中的后台进程：</p>
<p>oracle@lxsfrac03 $ ps -ef |grep ora_ |grep -v grep |sort +7<br />
  oracle 26479     1   0 15:02:44 ?           0:00 ora_cjq0_racg1<br />
  oracle 26473     1   0 15:02:44 ?           0:00 ora_ckpt_racg1<br />
  oracle 26464     1   0 15:02:44 ?           0:00 ora_dbw0_racg1<br />
  oracle 26469     1   0 15:02:44 ?           0:00 ora_dbw1_racg1<br />
  oracle 26416     1   0 15:02:44 ?           0:00 ora_diag_racg1<br />
  oracle 26518     1   0 15:02:46 ?           0:00 ora_lck0_racg1<br />
  oracle 26471     1   0 15:02:44 ?           0:00 ora_lgwr_racg1<br />
  oracle 26422     1   0 15:02:44 ?           0:00 ora_lmd0_racg1<br />
  oracle 26420     1   0 15:02:44 ?           0:00 ora_lmon_racg1<br />
  oracle 26424     1   0 15:02:44 ?           0:00 ora_lms0_racg1<br />
  oracle 26428     1   0 15:02:44 ?           0:00 ora_lms1_racg1<br />
  oracle 26452     1   0 15:02:44 ?           0:00 ora_mman_racg1<br />
  oracle 26483     1   0 15:02:44 ?           0:00 ora_mmnl_racg1<br />
  oracle 26481     1   0 15:02:44 ?           0:00 ora_mmon_racg1<br />
  oracle 26414     1   0 15:02:44 ?           0:00 ora_pmon_racg1<br />
  oracle 26418     1   0 15:02:44 ?           0:00 ora_psp0_racg1<br />
  oracle 26477     1   0 15:02:44 ?           0:00 ora_reco_racg1<br />
  oracle 26475     1   0 15:02:44 ?           0:00 ora_smon_racg1</p>
<p>二。Oracle11g 新的后台进程的功能<br />
新多的后台进程有：ora_dbrm_orcl，ora_dia0_orcl，ora_psp0_orcl，ora_smco_orcl，ora_vktm_orcl，ora_w000_orcl，<br />
这些后台进程的功能分别如下：<br />
DBRM：数据库资源管理进程, (The database resource manager process)，负责设置资源计划和其他的资源管理的工作。<br />
DIAG：数据库诊断进程， (The diagnosibility process) ，负责维护管理各种用于诊断的转储文件，并执行oradebug命令。<br />
DIA0：另一个数据库诊断进程，负责检测Oracle数据库中的挂起(hang)和死锁的处理。<br />
PSP0：process spawner，用于产生oracle进程<br />
SMCO：space management coordinator，该进程负责空间管理协调管理工作，负责执行空间的分配和回收。<br />
Wnnn；命名为W000，W001，W002&#8230;..，由smcO动态产生执行上述相关任务。<br />
VKTM：virtual keeper of time，用于提供wall-clock time，（每秒钟更新一次）。提供每二十毫秒更新一次的reference-time counter，看起来有点类似计时器的功能。</p>
<p>三。Oracle11g 新引入的其他后台进程<br />
再来认识一下Oracle11g中新引入的一些其他进程，因为一些特性在我的测试库中没有用到，比如asm，所以在ps -ef的结果中没有。</p>
<p>GMON：用于维护asm磁盘组的磁盘之间的关系。<br />
KATE：当ASM的磁盘离线的时候，该进程负责asm的元文件的io读写。<br />
MARK：如果有向asm离线磁盘的missed 写请求，该进程将ASM分配的单元的状态标记为stale<br />
FBDA：涉及到flashback-data-archive新特性的一个进程，The flashback data archiver proces。用于将“轨表”(tracked tables)的历史数据进行归档。当“轨表”上的事务提交以后，fbda进程负责将数据的前镜像保存到flashback archive区域。该进程还负责flashback的数据归档的空间管理、分配、保留，跟踪tracked transactions。<br />
         什么是“轨表”(tracked tables): 是指启用了flashback archive特性的表。<br />
RMSn：The Oracle RAC management processes,负责执行Oracle RAC的管理任务，比如RAC相关资源的创建和集群中新实例的添加。<br />
DSKM：The slave diskmon process ， 负责oracle 实例、asm实例和磁盘的管理进程之间的io fencing 信息的交换。如果使用SAGE的存储，该进程还负责SAGE存储的一些信息的管理。</p>
<p>四。复习一下Oracle 10gR2的后台进程<br />
最后 再来复习一下Oracle 10gR2中的一些后台进程：<br />
Queue Monitor Processes (QMNn)  是供 Oracle Streams Advanced Queuing使用的可选的进程，用于监控消息队列。这两类进程出错不会导致整个实例出错。<br />
MMON ：manageability monitor，与oracle10g的新特性－－诊断功能相关，负责管理一些后台任务，比收集最近修改过的 SQL 对象的统计信息<br />
MMNL ：与oracle10g的新特性－－诊断功能相关，会根据调度从SGA将统计结果－－如会话的历史信息，刷新输出至数据库表。<br />
MMAN ：与oracle10g的新特性－－诊断功能相关，负责执行一些数据库内部任务，自动设置SGA大小特性会使用这个进程。<br />
RBAL ：Rebalance。进程负责协调磁盘组间的负载平衡工作，在使用了ASM的数据库实例中运行。当向ASM磁盘组增加或删除磁盘时，RBAL进行负责处理重新平衡的请求。它可以使多个实例同时访问一个 ASM 磁盘（global open）。最终由 ORBn 进程实际执行数据扩展的负载均衡。 实例中可以运行多个 ORBn 进程，分别为 ORB0，ORB1，以此类推。<br />
ASMB: 在使用asm磁盘组的时候负责与asm实例的通信，向ASM实例提供更新统计信息.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.orablogger.com/2012/03/oracle-11g-%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%9aoracle11g-%e5%90%8e%e5%8f%b0%e8%bf%9b%e7%a8%8b%e6%a6%82%e8%bf%b0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HP-UX: Asynchronous i/o [ID 139272.1]</title>
		<link>http://www.orablogger.com/2012/02/hp-ux-asynchronous-io-id-139272-1/</link>
		<comments>http://www.orablogger.com/2012/02/hp-ux-asynchronous-io-id-139272-1/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 07:06:38 +0000</pubDate>
		<dc:creator>happydba</dc:creator>
				<category><![CDATA[hp-ux]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://www.orablogger.com/?p=530</guid>
		<description><![CDATA[修改时间 29-NOV-2011 类型 BULLETIN 状态 PUBLISHED PURPOSE &#8212;&#8212;- The purpose of this document is to discuss the implementation of asynchronous i/o (aio) on HP-UX, specifically to enable aio for the Oracle RDBMS Server. SCOPE &#038; APPLICATION &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- This note is intended for DBAs and Support Personnel. 1.0 Introduction ================ On HP-UX, when the Oracle datafiles [...]]]></description>
			<content:encoded><![CDATA[<p> 	修改时间 29-NOV-2011     类型 BULLETIN     状态 PUBLISHED	 </p>
<p>PURPOSE<br />
&#8212;&#8212;-</p>
<p>The purpose of this document is to discuss the implementation of<br />
asynchronous i/o (aio) on HP-UX, specifically to enable aio for the Oracle<br />
RDBMS Server.</p>
<p>SCOPE &#038; APPLICATION<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>This note is intended for DBAs and Support Personnel.</p>
<p>1.0 Introduction<br />
================<br />
On HP-UX, when the Oracle datafiles reside on a filesystem, then the DBWR<br />
process(es) make synchronous writes to these datafiles. This means that each<br />
write must return with a &#8216;succesful completion&#8217; before the next write is<br />
issued. This serial operation can lead to a i/o bottleneck. There are two ways<br />
to counteract this:<br />
  a. configure multiple DBWR processes<br />
  b. use asynchronous i/o</p>
<p>Before deciding on one of these two options, it should be noted that on HP-UX,<br />
aio is *only* possible on a raw device. Put in another way, aio *cannot* be used<br />
on a filesystem.</p>
<p>Multiple DBWRs can be used on a filesystem.</p>
<p>It is not recommended to use both multiple DBWRs and aio.</p>
<p>2.0 Configuring asynchronous i/o<br />
================================<br />
aio requires configuration of both Oracle and HP-UX</p>
<p>2.1 HP-UX Configuration<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
a. create the /dev/async character device<br />
   % /sbin/mknod /dev/async c 101 0&#215;0<br />
   % chown oracle:dba /dev/async<br />
   % chmod 660 /dev/async</p>
<p>   If the device does not exist, then ENODEV (Err #19) is returned when the device<br />
   is accessed:<br />
   Async driver not configured  : errno=19</p>
<p>   If the permissions are incorrect, then EACCES (Err #13) is returned:<br />
   Async driver not configured  : errno=13</p>
<p>b. configure the async driver in the kernel<br />
   Using SAM<br />
     -> Kernel Configuration<br />
        -> Drivers<br />
           -> the driver is called &#8216;asyncdsk&#8217;<br />
   Generate new kernel<br />
   Reboot</p>
<p>c. set max_async_ports<br />
   Using SAM<br />
     -> Kernel Configuration<br />
        -> Configurable Parameters<br />
           -> max_async_ports</p>
<p>   max_async_ports limits the maximum number of processes that can concurrently<br />
   use /dev/async. Set this parameter to the sum of<br />
     &#8216;processes&#8217; from init.ora + number of background processes</p>
<p>   The background processes started at instance startup will open /dev/async<br />
   twice.</p>
<p>   If max_async_ports is reached, subsequent processes will use synchronous i/o.</p>
<p>d. set aio_max_ops<br />
   Using SAM<br />
     -> Kernel Configuration<br />
        -> Configurable Parameters<br />
           -> aio_max_ops</p>
<p>   aio_max_ops limits the maximum number of asynchronous i/o operations that<br />
   can be queued at any time. Set this parameter to the default value (2048),<br />
   and monitor over time (use glance).</p>
<p>e. if HP-UX patch PHKL_22126 (or one that supersedes it) is installed, then<br />
   see Section 3.0</p>
<p>2.2 Oracle Configuration<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
The following init.ora parameters are required.</p>
<p>a. pre 7.3.0<br />
   no init.ora parameters required<br />
b. 7.3.X<br />
   use_async_io = TRUE<br />
c. 8.X<br />
   disk_asynch_io = TRUE     </p>
<p>3.0 Implications of HP-UX Patch PHKL_22126<br />
==========================================</p>
<p>This patch is called:<br />
PHKL_22126: s700_800 11.00 VM,async,hyperfabric</p>
<p>The HP-UX patch description says:<br />
 The effective user ID of the process calling async driver,<br />
 typically called by a process for database applications such<br />
 as Oracle, must be a superuser or the user must<br />
 be a member of a group that has the MLOCK privilege.</p>
<p>In essence, aio will not work for Oracle, unless the dba group has the MLOCK<br />
privilege.</p>
<p>To check if a group has the MLOCK privilege, execute:<br />
 % /usr/bin/getprivgrp <group-name></p>
<p>If the dba group is not listed, then set it:<br />
 % /usr/sbin/setprivgrp <group-name> MLOCK</p>
<p>Note, the next reboot will clear this privilege. To automate this at startup,<br />
create /etc/privgroup with the entry<br />
 dba MLOCK</p>
<p>This can be tested with<br />
 % /usr/sbin/setprivgrp -f /etc/privgroup<br />
See &#8216;man 1m setprivgrp&#8217; for more information.</p>
<p>If the MLOCK privilege is not granted to the dba group, then instance startup<br />
will exhibit the following:</p>
<p>a. prior to 8.1.7, each background and shadow process will dump a trace file<br />
   with the following:</p>
<p>   Ioctl ASYNC_CONFIG error, errno = 1</p>
<p>   errno 1 is EPERM (Not super-user).</p>
<p>   Such trace files may be found in<br />
      $ORACLE_HOME/rdbms/log<br />
      background_dump_dest<br />
      user_dump_dest </p>
<p>   Additionally, a tusc of instance startup will show the following for<br />
   each background process:<br />
   [16044] open(&#8220;/dev/async&#8221;, O_RDWR, 01760) &#8230;&#8230;&#8230;&#8230;&#8230;. = 14<br />
   &#8230;<br />
   [16044] ioctl(14, 0&#215;80106101, 0x7f7f51b0) &#8230;&#8230;&#8230;&#8230;&#8230;. ERR#1 EPERM</p>
<p>   Similar output will be given for a tusc of a shadow process.</p>
<p>   The instance does start, but i/o is synchronous</p>
<p>b. in 8.1.7, the instance will not start, and will error with:<br />
   SVRMGR> startup<br />
   ORA-00445: background process &#8220;PMON&#8221; did not start after 120 seconds</p>
<p>   See Note:133007.1 for the alert on this.</p>
<p>c. in 9.0.1, the behaviour is similar to pre-8.1.7, in that trace files with<br />
   the following are dumped:</p>
<p>   Ioctl ASYNC_CONFIG error, errno = 1</p>
<p>   Additionally, the following is also seen:</p>
<p>   Ioctl ASYNC_ADDSEG error, errno = 1</p>
<p>   The instance does start, but i/o is synchronous.</p>
<p>4.0 Checking that Asynchronous i/o is being used<br />
================================================<br />
Async i/o is being used if both the following are true:<br />
  a. /dev/async is open by DBWR<br />
  b. the relevant init.ora partameter is set (see Section 2.2)<br />
  c. the datafiles are on raw devices</p>
<p>To check if /dev/async is open by DBWR, do one of:<br />
    i. % fuser /dev/async<br />
   ii. % lsof -p <dbwr pid><br />
         lsof can be downloaded from ftp://vic.cc.purdue.edu/pub/tools/unix/lsof<br />
  iii. use glance/gpm to check files opened by DBWR</p>
<p>NB &#8211; Oracle server processes (background and foreground) will attempt to open<br />
     /dev/async if the async driver is enabled in the HP-UX kernel, regardless<br />
     of init.ora settings.</p>
<p>If (a), (b)and (c) are true, and i/o is still perceived to be synchronous, attach<br />
to DBWR with tusc, and check that write calls to /dev/async are not returning an<br />
error. The file descriptor for /dev/async will be needed, which can be retrieved<br />
using lsof.</p>
<p>5.0 The fs_async kernel parameter<br />
=================================<br />
The kernel parameter fs_async can be set to allow asynchronous writes to file<br />
systems. However, write calls can return without the data being physically<br />
written to disk (the write sits in the UNIX buffer cache). The data in question<br />
is file-system metadata such as free space lists, blocks and inodes.<br />
A system crash would potentially lose this data, and leave the filesystem in an<br />
inconsistent state, causing database corruption.</p>
<p>Oracle still opens files with the O_DSYNC flag (see &#8216;tusc&#8217; snipet<br />
below), which insists that writes are physically written:<br />
open(&#8220;/oracle/datafiles/system01.dbf&#8221;, O_RDWR|O_LARGEFILE|O_DSYNC, 0) = 19</p>
<p>In summary, fs_async is ignored for datafiles(due to open() with O_DSYNC).<br />
However, filesystem metadata may be lost, potentially causing datafile<br />
corruption.</p>
<p>Oracle does not recommend setting fs_async to &#8217;1&#8242;.</p>
<p>Settings:<br />
  fs_async=0 Do not use async writes to file systems<br />
  fs_async=1 Do async writes to file systems</p>
<p>RELATED DOCUMENTS<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Note:174487.1 &#8211; ALERT:HP-UX: RDBMS May Not Start if Async Disk Driver is<br />
                  Configured<br />
Note:133007.1 &#8211; ALERT: HP/UX: 8.1.7 RDBMS will not start if the async disk<br />
                  driver is configured</p>
]]></content:encoded>
			<wfw:commentRss>http://www.orablogger.com/2012/02/hp-ux-asynchronous-io-id-139272-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Disable Asynch_io on HP to Avoid Ioctl Async_config Error Errno = 1 [ID 302801.1]</title>
		<link>http://www.orablogger.com/2012/02/how-to-disable-asynch_io-on-hp-to-avoid-ioctl-async_config-error-errno-1-id-302801-1/</link>
		<comments>http://www.orablogger.com/2012/02/how-to-disable-asynch_io-on-hp-to-avoid-ioctl-async_config-error-errno-1-id-302801-1/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 07:03:45 +0000</pubDate>
		<dc:creator>happydba</dc:creator>
				<category><![CDATA[oracle]]></category>
		<category><![CDATA[排错]]></category>

		<guid isPermaLink="false">http://www.orablogger.com/?p=528</guid>
		<description><![CDATA[修改时间 08-NOV-2011 类型 HOWTO 状态 PUBLISHED In this Document Goal Solution References Applies to: Oracle Server &#8211; Enterprise Edition &#8211; Version: 9.2.0.1 to 11.2.0.2 &#8211; Release: 9.2 to 11.2 HP-UX PA-RISC (64-bit) HP-UX Itanium Goal How to disable async_io on Oracle in HP-UX to avoid this message in trace file: Ioctl ASYNC_CONFIG error, errno = [...]]]></description>
			<content:encoded><![CDATA[<p> 	修改时间 08-NOV-2011     类型 HOWTO     状态 PUBLISHED<br />
In this Document<br />
  Goal<br />
  Solution<br />
  References</p>
<p>Applies to:</p>
<p>Oracle Server &#8211; Enterprise Edition &#8211; Version: 9.2.0.1 to 11.2.0.2 &#8211; Release: 9.2 to 11.2<br />
HP-UX PA-RISC (64-bit)<br />
HP-UX Itanium<br />
Goal</p>
<p>How to disable async_io on Oracle in HP-UX to avoid this message in trace file:<br />
Ioctl ASYNC_CONFIG error, errno = 1<br />
Solution</p>
<p>If /dev/async is present and correctly configured, Oracle (for HP only) will use it for memory locking which is needed for async i/o for SGA memory pages via ioctl.</p>
<p>Oracle (for HP only) opens /dev/async successfully only if the /dev/async HP-UX device driver is properly configured for read and write.</p>
<p>This is irrespective of whether the DISK_ASYNCH_IO parameter is set to TRUE.</p>
<p>Problem is Oracle (for HP only) still uses async I/O regardless of the value of init settings<br />
(disk_asynch_io=FALSE and filesystemio_options=none).<br />
The parameter filesystemio_options=none doesn&#8217;t work.</p>
<p>From the 9.2 until 10.1 version, to inactivate ASYNCH_IO with Oracle, the workaround is to:</p>
<p>chown bin:bin /dev/async<br />
chmod 660 /dev/async<br />
Note: This may impact other applications that wish to use asynch I/O.<br />
It is recommended to shutdown Oracle database before inactivating asynch I/O.</p>
<p>Grant dba group the MLOCK privilege to avoid the Ioctl ASYNC_CONFIG trace file errors:</p>
<p>(1) # /usr/sbin/setprivgrp dba MLOCK<br />
(2) # vi /etc/privgroup<br />
&#8211; This should contain dba MLOCK RTSCHED RTPRIO<br />
(3) # cat /etc/privgroup<br />
dba MLOCK RTSCHED RTPRIO<br />
Since the Oracle 10.2 version, the problem is resolved as these settings stop the tracing:<br />
disk_asynch_io=FALSE<br />
filesystemio_options=none </p>
]]></content:encoded>
			<wfw:commentRss>http://www.orablogger.com/2012/02/how-to-disable-asynch_io-on-hp-to-avoid-ioctl-async_config-error-errno-1-id-302801-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Additional Considerations for Direct-Path INSERT &amp; NOtes added on</title>
		<link>http://www.orablogger.com/2011/09/additional-considerations-for-direct-path-insert-notes-added-on/</link>
		<comments>http://www.orablogger.com/2011/09/additional-considerations-for-direct-path-insert-notes-added-on/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 03:05:31 +0000</pubDate>
		<dc:creator>happydba</dc:creator>
				<category><![CDATA[Internal]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[append]]></category>
		<category><![CDATA[Direct-Path]]></category>
		<category><![CDATA[INSERT]]></category>

		<guid isPermaLink="false">http://www.orablogger.com/?p=526</guid>
		<description><![CDATA[Advantages of Using Direct-Path INSERT The following are performance benefits of direct-path INSERT: During direct-path INSERT, you can disable the logging of redo and undo entries. Conventional insert operations, in contrast, must always log such entries, because those operations reuse free space and maintain referential integrity. To create a new table with data from an [...]]]></description>
			<content:encoded><![CDATA[<p>Advantages of Using Direct-Path INSERT</p>
<p>The following are performance benefits of direct-path INSERT:</p>
<p>During direct-path INSERT, you can disable the logging of redo and undo entries. Conventional insert operations, in contrast, must always log such entries, because those operations reuse free space and maintain referential integrity.</p>
<p>To create a new table with data from an existing table, you have the choice of creating the new table and then inserting into it, or executing a CREATE TABLE &#8230; AS SELECT statement. By creating the table and then using direct-path INSERT operations, you update any indexes defined on the target table during the insert operation. The table resulting from a CREATE TABLE &#8230; AS SELECT statement, in contrast, does not have any indexes defined on it; you must define them later.</p>
<p>Direct-path INSERT operations ensure atomicity of the transaction, even when run in parallel mode. Atomicity cannot be guaranteed during parallel direct-path loads (using SQL*Loader).</p>
<p>If errors occur during parallel direct-path loads, some indexes could be marked UNUSABLE at the end of the load. Parallel direct-path INSERT, in contrast, rolls back the statement if errors occur during index update.</p>
<p>Direct-path INSERT must be used if you want to store the data in compressed form using table compression.</p>
<p>Enabling Direct-Path INSERT</p>
<p>You can implement direct-path INSERT operations by using direct-path INSERT statements, inserting data in parallel mode, or by using the Oracle SQL*Loader utility in direct-path mode. Direct-path inserts can be done in either serial or parallel mode.</p>
<p>To activate direct-path INSERT in serial mode, you must specify the APPEND hint in each INSERT statement, either immediately after the INSERT keyword, or immediately after the SELECT keyword in the subquery of the INSERT statement.</p>
<p>When you are inserting in parallel DML mode, direct-path INSERT is the default. In order to run in parallel DML mode, the following requirements must be met:</p>
<p>You must have Oracle Enterprise Edition installed.</p>
<p>You must enable parallel DML in your session. To do this, run the following statement:</p>
<p>ALTER SESSION { ENABLE | FORCE } PARALLEL DML;</p>
<p>You must specify the parallel attribute for the target table, either at create time or subsequently, or you must specify the PARALLEL hint for each insert operation.</p>
<p>To disable direct-path INSERT, specify the NOAPPEND hint in each INSERT statement. Doing so overrides parallel DML mode.</p>
<p>How Direct-Path INSERT Works</p>
<p>You can use direct-path INSERT on both partitioned and non-partitioned tables.</p>
<p>Serial Direct-Path INSERT into Partitioned or Non-partitioned Tables<br />
The single process inserts data beyond the current high water mark of the table segment or of each partition segment. (The high-water mark is the level at which blocks have never been formatted to receive data.) When a COMMIT runs, the high-water mark is updated to the new value, making the data visible to users.</p>
<p>Parallel Direct-Path INSERT into Partitioned Tables<br />
This situation is analogous to serial direct-path INSERT. Each parallel execution server is assigned one or more partitions, with no more than one process working on a single partition. Each parallel execution server inserts data beyond the current high-water mark of its assigned partition segment(s). When a COMMIT runs, the high-water mark of each partition segment is updated to its new value, making the data visible to users.</p>
<p>Parallel Direct-Path INSERT into Non-partitioned Tables<br />
Each parallel execution server allocates a new temporary segment and inserts data into that temporary segment. When a COMMIT runs, the parallel execution coordinator merges the new temporary segments into the primary table segment, where it is visible to users.</p>
<p>Specifying the Logging Mode for Direct-Path INSERT</p>
<p>Direct-path INSERT lets you choose whether to log redo and undo information during the insert operation.</p>
<p>You can specify logging mode for a table, partition, index, or LOB storage at create time (in a CREATE statement) or subsequently (in an ALTER statement).</p>
<p>If you do not specify either LOGGING or NOLOGGING at these times:</p>
<p>The logging attribute of a partition defaults to the logging attribute of its table.</p>
<p>The logging attribute of a table or index defaults to the logging attribute of the tablespace in which it resides.</p>
<p>The logging attribute of LOB storage defaults to LOGGING if you specify CACHE for LOB storage. If you do not specify CACHE, then the logging attributes defaults to that of the tablespace in which the LOB values resides.</p>
<p>You set the logging attribute of a tablespace in a CREATE TABLESPACE or ALTER TABLESPACE statements.</p>
<p>Note:<br />
If the database or tablespace is in FORCE LOGGING mode, then direct path INSERT always logs, regardless of the logging setting.<br />
Direct-Path INSERT with Logging<br />
In this mode, Oracle Database performs full redo logging for instance and media recovery. If the database is in ARCHIVELOG mode, then you can archive redo logs to tape. If the database is in NOARCHIVELOG mode, then you can recover instance crashes but not disk failures.</p>
<p>Direct-Path INSERT without Logging<br />
In this mode, Oracle Database inserts data without redo or undo logging. (Some minimal logging is done to mark new extents invalid, and data dictionary changes are always logged.) This mode improves performance. However, if you subsequently must perform media recovery, the extent invalidation records mark a range of blocks as logically corrupt, because no redo data was logged for them. Therefore, it is important that you back up the data after such an insert operation.</p>
<p>Additional Considerations for Direct-Path INSERT</p>
<p>The following are some additional considerations when using direct-path INSERT.</p>
<p>Index Maintenance with Direct-Path INSERT<br />
Oracle Database performs index maintenance at the end of direct-path INSERT operations on tables (partitioned or non-partitioned) that have indexes. This index maintenance is performed by the parallel execution servers for parallel direct-path INSERT or by the single process for serial direct-path INSERT. You can avoid the performance impact of index maintenance by dropping the index before the INSERT operation and then rebuilding it afterward.</p>
<p>Space Considerations with Direct-Path INSERT<br />
Direct-path INSERT requires more space than conventional-path INSERT.</p>
<p>All serial direct-path INSERT operations, as well as parallel direct-path INSERT into partitioned tables, insert data above the high-water mark of the affected segment. This requires some additional space.</p>
<p>Parallel direct-path INSERT into non-partitioned tables requires even more space, because it creates a temporary segment for each degree of parallelism. If the non-partitioned table is not in a locally managed tablespace in automatic segment-space management mode, you can modify the values of the NEXT and PCTINCREASE storage parameter and MINIMUM EXTENT tablespace parameter to provide sufficient (but not excess) storage for the temporary segments. Choose values for these parameters so that:</p>
<p>The size of each extent is not too small (no less than 1 MB). This setting affects the total number of extents in the object.</p>
<p>The size of each extent is not so large that the parallel INSERT results in wasted space on segments that are larger than necessary.</p>
<p>After the direct-path INSERT operation is complete, you can reset these parameters to settings more appropriate for serial operations.</p>
<p>Locking Considerations with Direct-Path INSERT<br />
During direct-path INSERT, the database obtains exclusive locks on the table (or on all partitions of a partitioned table). As a result, users cannot perform any concurrent insert, update, or delete operations on the table, and concurrent index creation and build operations are not permitted. Concurrent queries, however, are supported, but the query will return only the information before the insert operation.</p>
<p>NOtes Added On<br />
(1) in 10.x and previous releases the APPEND hint gets ignored when it is present in an INSERT with VALUES clause and that is the expected behavior for previous versions, including 9i and 10g. On 11g Release 1, the APPEND hint it is not ignored and a direct-path load is executed for an INSERT with VALUES clause, therefore such statements will allocate one row/database block.</p>
<p>(2) On 11g Release 2, there is a new hint &#8220;APPEND_VALUES&#8221;, i.e. use direct path load only when the &#8220;APPEND_VALUES&#8221; hint is referenced. On 11g Release 2 the &#8220;APPEND&#8221; hint is ignored for INSERT statements with VALUES clause. This is the expected behavior on 11g and it is currently implemented only in 11g Release 2.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.orablogger.com/2011/09/additional-considerations-for-direct-path-insert-notes-added-on/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux Tar安装oracle 10g</title>
		<link>http://www.orablogger.com/2011/09/linux-tar%e5%ae%89%e8%a3%85oracle-10g/</link>
		<comments>http://www.orablogger.com/2011/09/linux-tar%e5%ae%89%e8%a3%85oracle-10g/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 15:08:49 +0000</pubDate>
		<dc:creator>happydba</dc:creator>
				<category><![CDATA[排错]]></category>

		<guid isPermaLink="false">http://www.orablogger.com/?p=523</guid>
		<description><![CDATA[链接：http://www.dbasky.net/archives/2009/04/linux-taroracle-10g.html 最近公司业务的不断扩大，对数据库的使用也不断的增加，导致了基本每天都要进行安装的安装和配置。其实oracle的安装是很简单，不知道是否有更加方便，快捷的安装方式呢？答案：有的，那就是用linux常用的命令tar来进行安装。今天我就来尝试了在linux as4上用tar方式安装oracle 10g，下面简单记录下这次的操作过程。 原数据库所在服务器信息： kfserver-> more /etc/issue Red Hat Enterprise Linux AS release 4 (Nahant Update 5) Kernel \r on an \m kfserver-> uname -a Linux kfserver 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux 新数据库所在服务器信息： root@testserver:[/root]more /etc/issue Red Hat Enterprise Linux AS release 4 (Nahant Update 5) Kernel [...]]]></description>
			<content:encoded><![CDATA[<p>链接：http://www.dbasky.net/archives/2009/04/linux-taroracle-10g.html </p>
<p>       最近公司业务的不断扩大，对数据库的使用也不断的增加，导致了基本每天都要进行安装的安装和配置。其实oracle的安装是很简单，不知道是否有更加方便，快捷的安装方式呢？答案：有的，那就是用linux常用的命令tar来进行安装。今天我就来尝试了在linux as4上用tar方式安装oracle 10g，下面简单记录下这次的操作过程。</p>
<p>原数据库所在服务器信息：</p>
<p>kfserver-> more /etc/issue<br />
Red Hat Enterprise Linux AS release 4 (Nahant Update 5)<br />
Kernel \r on an \m</p>
<p>kfserver-> uname -a<br />
Linux kfserver 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux<br />
新数据库所在服务器信息：</p>
<p> root@testserver:[/root]more /etc/issue<br />
Red Hat Enterprise Linux AS release 4 (Nahant Update 5)<br />
Kernel \r on an \m<br />
 root@testserver:[/root]uname -a<br />
Linux testserver 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux<br />
以上二个系统版本是一样的。</p>
<p>1、在新服务器上添加用户<br />
 groupadd oinstall<br />
 useradd -g oinstall oracle</p>
<p>2、在新服务器上添加相关目录<br />
 mkdir -p /opt/oracle/product</p>
<p>3、设置核心参数<br />
 vi /etc/sysctl.conf，添加</p>
<p> # Controls whether core dumps will append the PID to the core filename.<br />
# Useful for debugging multi-threaded applications.<br />
kernel.core_uses_pid = 1<br />
kernel.shmall   =       2097152<br />
kernel.shmmax   =       2147483648<br />
kernel.shmmni   =       4096<br />
kernel.sem      =       250 32000 100 128<br />
fs.file-max     =       65536<br />
net.ipv4.ip_local_port_range    =       1024 65000<br />
net.core.rmem_default   =       1048576<br />
net.core.rmem_max       =       1048576<br />
net.core.wmem_default   =       262144<br />
net.core.wmem_max       =       262144</p>
<p> 使设置生效：<br />
 sysctl -p</p>
<p>4、修改oracle用户的环境变量<br />
 su &#8211; oracle<br />
 vi  .bash_profile 添加：</p>
<p># User specific environment and startup programs<br />
PATH=$PATH:$HOME/bin</p>
<p>export PATH<br />
unset USERNAME<br />
export PS1=&#8221;` /bin/hostname -s ` -> &#8221;<br />
export EDITOR=vi<br />
export ORACLE_SID=nuage<br />
export ORACLE_BASE=/opt/oracle<br />
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1<br />
export ORACLE_CLIENT=$ORACLE_BASE/product/10.2.0/cleint<br />
export LD_LIBRARY=$ORACLE_HOME/lib<br />
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin<br />
export NLS_LANG=&#8221;SIMPLIFIED CHINESE_CHINA.ZHS16GBK&#8221;</p>
<p>5、在原服务器打包程序<br />
把$ORACLE_HOME下的东西打包压缩：<br />
 cd $ORACLE_BASE/product<br />
 tar cfz oracle10203.tar 10.2</p>
<p>6、传送到新服务器并解压<br />
 scp 上传</p>
<p> cd $ORACLE_BASE/product<br />
 tar -xzfv oracle10203<br />
7、修改解压后的文件属主</p>
<p>[root@testserver oracle]# chown -R oracle:oinstall /opt/<br />
chown: changing ownership of `/opt/oracle/product/10.2/rdbms/filemap&#8217;: No such file or directory</p>
<p>这里出现一个错误，提示文件不存在，经检查这是一个软链接：</p>
<p>[root@testserver oracle]# ls -l /opt/oracle/product/10.2/rdbms/filemap<br />
lrwxrwxrwx  1 root root 22 Jan 10 17:22 /opt/oracle/product/10.2/rdbms/filemap -> /opt/ORCLfmap/prot1_64<br />
经检查，当前的系统确实不存在/opt/ORCLfmap目录，实际上/opt/ORCLfmap是有root.sh生成的，先删除这个软链接：<br />
rm -f /opt/oracle/product/10.2/rdbms/filemap</p>
<p>重新执行root.sh：</p>
<p>[root@testserver opt]# /opt/oracle/product/10.2/root.sh<br />
 Running Oracle10 root.sh script&#8230;</p>
<p> The following environment variables are set as:<br />
     ORACLE_OWNER= oracle<br />
     ORACLE_HOME=  /opt/oracle/product/10.2</p>
<p> Enter the full pathname of the local bin directory: [/usr/local/bin]:<br />
    Copying dbhome to /usr/local/bin &#8230;<br />
    Copying oraenv to /usr/local/bin &#8230;<br />
    Copying coraenv to /usr/local/bin &#8230;</p>
<p> Creating /etc/oratab file&#8230;<br />
 Entries will be added to the /etc/oratab file as needed by<br />
 Database Configuration Assistant when a database is created<br />
 Finished running generic part of root.sh script.<br />
 Now product-specific root actions will be performed.<br />
此时软连接和目录都已经存在：</p>
<p> [root@testserver opt]# ls /opt/oracle/product/10.2/rdbms/filemap<br />
 bin  etc  log<br />
 [root@testserver opt]# ls -l /opt/oracle/product/10.2/rdbms/filemap<br />
 lrwxrwxrwx  1 root root 22 Jan 10 17:40 /opt/oracle/product/10.2/rdbms/filemap -> /opt/ORCLfmap/prot1_64<br />
8、创建数据库<br />
   运行dbca，一步一步设置好就可以。</p>
<p>9、清理原网络相关文件、原密码文件等。</p>
<p>一般会出现的问题：<br />
1、chown: changing ownership of `/opt/oracle/product/10.2/rdbms/filemap&#8217;: No such file or directory<br />
这个问题在上文已有描述，这里不再赘述。</p>
<p>2、Exception in thread &#8220;main&#8221; java.lang.UnsatisfiedLinkError: /opt/oracle/product/10.2/jdk/jre/lib/i386/libawt.so: libXp.so.6: cannot open shared object file: No such file or directory</p>
<p>执行dbca时报错：</p>
<p> testserver ->$ dbca<br />
 Exception in thread &#8220;main&#8221;<br />
testserver ->$<br />
这里报错信息非常少，无法判断是什么原因，再执行netca就可以看得更多的错误信息了：</p>
<p>[oracle@testserver bin]$ netca<br />
Exception in thread &#8220;main&#8221; java.lang.UnsatisfiedLinkError: /opt/oracle/product/10.2/jdk/jre/lib/i386/libawt.so: libXp.so.6: cannot open shared object file: No such file or directory<br />
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)<br />
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1586)<br />
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1503)<br />
        at java.lang.Runtime.loadLibrary0(Runtime.java:788)<br />
        at java.lang.System.loadLibrary(System.java:834)<br />
        at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)<br />
        at java.security.AccessController.doPrivileged(Native Method)<br />
        at sun.awt.NativeLibLoader.loadLibraries(NativeLibLoader.java:38)<br />
        at sun.awt.DebugHelper.<clinit>(DebugHelper.java:29)<br />
        at java.awt.Component.<clinit>(Component.java:506)  </p>
<p>这个问题主要是缺少一个包xorg-x11-deprecated-libs导致的，把包安装上就可以：<br />
[root@testserver soft]# rpm -ivh xorg-x11-deprecated-libs-6.8.2-1.EL.13.37.i386.rpm<br />
 warning: xorg-x11-deprecated-libs-6.8.2-1.EL.13.37.i386.rpm: V3 DSA signature: NOKEY, key ID b38a8516<br />
 Preparing&#8230;                ########################################### [100%]<br />
    1:xorg-x11-deprecated-lib########################################### [100%]</p>
<p>   注意：虽然系统是64位的，但是这里要安装32位的包。</p>
<p>3、ORA-12547: TNS: 丢失连接<br />
在创建数据库前，简单测试一下sqlplus是否正常，发现了这个问题：</p>
<p> testserver ->$ sqlplus &#8220;/as sysdba&#8221;</p>
<p> SQL*Plus: Release 10.2.0.3.0 &#8211; Production on 星期四 1月 10 17:51:35 2008</p>
<p> Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.</p>
<p> oraclenewdemo: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory<br />
 ERROR:<br />
 ORA-12547: TNS: 丢失连接</p>
<p>请输入用户名: </p>
<p>引起问题的原因是libaio系统包，把相关包安装即可：</p>
<p> [root@testserver soft]# ls<br />
 libaio-0.3.105-2.i386.rpm  libaio-0.3.105-2.x86_64.rpm  libaio-devel-0.3.105-2.x86_64.rpm<br />
 [root@testserver soft]# rpm -ivh *<br />
 warning: libaio-0.3.105-2.i386.rpm: V3 DSA signature: NOKEY, key ID b38a8516<br />
 Preparing&#8230;                ########################################### [100%]<br />
    1:libaio                 ########################################### [ 33%]<br />
    2:libaio                 ########################################### [ 67%]<br />
    3:libaio-devel           ########################################### [100%]</p>
<p> 同样，这里也需要安装两个32位的包。 </p>
<p>4、ORA-01031: insufficient privileges<br />
testserver ->$ sqlplus &#8220;/as sysdba&#8221;</p>
<p>SQL*Plus: Release 10.2.0.3.0 &#8211; Production on 星期五 1月 11 10:48:35 2008</p>
<p>Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.</p>
<p>ERROR:<br />
ORA-01031: insufficient privileges</p>
<p>请输入用户名: </p>
<p>这个问题是因为用户组不一致造成的。</p>
<p>原库：</p>
<p>[oracle@kfserver oraInventory]$ id -a<br />
uid=500(oracle) gid=500(oinstall) groups=500(oinstall),501(dba) context=user_u:system_r:unconfined_t<br />
新库：</p>
<p>[oracle@testserver oraInventory]$ id -a<br />
uid=500(oracle) gid=500(oinstall) groups=500(oinstall) context=user_u:system_r:unconfined_t<br />
在新库上为oracle用户添加组就可以了：</p>
<p>[root@testserver ~]# usermod -G dba oracle</p>
]]></content:encoded>
			<wfw:commentRss>http://www.orablogger.com/2011/09/linux-tar%e5%ae%89%e8%a3%85oracle-10g/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PRAGMA EXCEPTION_INIT的用法</title>
		<link>http://www.orablogger.com/2011/09/pragma-exception_init/</link>
		<comments>http://www.orablogger.com/2011/09/pragma-exception_init/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 03:23:41 +0000</pubDate>
		<dc:creator>happydba</dc:creator>
				<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[Exception]]></category>

		<guid isPermaLink="false">http://www.orablogger.com/?p=477</guid>
		<description><![CDATA[ 如果要处理未命名的内部异常，必须使用OTHERS异常处理器或PRAGMA EXCEPTION_INIT 。PRAGMA由编译器控制，或者是对于编译器的注释。PRAGMA在编译时处理，而不是在运行时处理。EXCEPTION_INIT告诉编译器将异常名与ORACLE错误码结合起来，这样可以通过名字引用任意的内部异常，并且可以通过名字为异常编写一适当的异常处理器。 　　 　　在子程序中使用EXCEPTION_INIT的语法如下： 　　PRAGMA EXCEPTION_INIT(exception_name, -Oracle_error_number); 　　在该语法中，异常名是声明的异常，下例是其用法： 　　DECLARE 　　deadlock_detected EXCEPTION; 　　PRAGMA EXCEPTION_INIT(deadlock_detected, -60); 　　BEGIN 　　&#8230; &#8212; Some operation that causes an ORA-00060 error 　　EXCEPTION 　　WHEN deadlock_detected THEN 　　&#8211; handle the error 　　END; 下面看一个例子 create or replace procedure SP_Del_Test (P_ItemAdmin in mfitem.itemadmin%type, &#8211;ItemAdmin P_ItemCd in mfitem.itemcd%type, &#8211;ItemCode P_Return out number &#8211;输出参数 ) is exp [...]]]></description>
			<content:encoded><![CDATA[<h5> 如果要处理未命名的内部异常，必须使用OTHERS异常处理器或PRAGMA EXCEPTION_INIT 。PRAGMA由编译器控制，或者是对于编译器的注释。PRAGMA在编译时处理，而不是在运行时处理。EXCEPTION_INIT告诉编译器将异常名与ORACLE错误码结合起来，这样可以通过名字引用任意的内部异常，并且可以通过名字为异常编写一适当的异常处理器。<br />
　　<br />
　　在子程序中使用EXCEPTION_INIT的语法如下：<br />
　　PRAGMA EXCEPTION_INIT(exception_name,<strong> -Oracle_error_number</strong>);<br />
<span id="more-477"></span><br />
　　在该语法中，异常名是声明的异常，下例是其用法：<br />
　　DECLARE<br />
　　deadlock_detected EXCEPTION;<br />
　　PRAGMA EXCEPTION_INIT(deadlock_detected, -60);<br />
　　BEGIN<br />
　　&#8230; &#8212; Some operation that causes an ORA-00060 error<br />
　　EXCEPTION<br />
　　WHEN deadlock_detected THEN<br />
　　&#8211; handle the error<br />
　　END;<br />
下面看一个例子</h5>
<h5>create or replace procedure SP_Del_Test<br />
(P_ItemAdmin in mfitem.itemadmin%type, &#8211;ItemAdmin<br />
P_ItemCd in mfitem.itemcd%type, &#8211;ItemCode<br />
P_Return out number &#8211;输出参数<br />
) is<br />
exp exception;<br />
PRAGMA Exception_Init(exp, -2292);<br />
begin<br />
delete from mfitem t<br />
where t.itemcd = P_ItemCd<br />
and t.itemadmin = P_ItemAdmin; &#8211;这一句会引发-2292异常，有级连删除异常<br />
EXCEPTION<br />
WHEN EXP THEN<br />
P_Return := 9;<br />
ROLLBACK;<br />
WHEN OTHERS THEN<br />
ROLLBACK;<br />
end SP_Del_Test;　　</h5>
<h5>使用自定义的异常，自定我们自己的错误消息：过程RAISE_APPLICATION_ERROR</h5>
<h5>调用RAISE_APPLICATION_ERROR的语法如下：</h5>
<h5>raise_application_error(error_number, message[, {TRUE | FALSE}]);</h5>
<h5>error_number是一个范围在-20000至-20999之间的负整数，message是最大长度为2048字节的字符串。如果第三个可选参数为TRUE的话，错误就会被放到前面错误的栈顶。如果为FALSE(默认值)，错误就会替代前面所有的错误。</h5>
<h5>CREATE PROCEDURE raise_salary (emp_id NUMBER, amount NUMBER) AS<br />
curr_sal NUMBER;<br />
BEGIN<br />
SELECT sal<br />
INTO curr_sal<br />
FROM emp<br />
WHERE empno = emp_id;<br />
IF curr_sal IS NULL THEN<br />
/* Issue user-defined error message. */<br />
raise_application_error (-20101, &#8216;Salary is missing&#8217;);<br />
ELSE<br />
UPDATE emp<br />
SET sal = curr_sal + amount<br />
WHERE empno = emp_id;<br />
END IF;<br />
END raise_salary;</h5>
<h5>如何抛出PL/SQL异常</h5>
<h5>DECLARE<br />
out_of_stock EXCEPTION;<br />
number_on_hand NUMBER (4);<br />
BEGIN<br />
&#8230;<br />
IF number_on_hand &lt; 1 THEN<br />
RAISE out_of_stock;<br />
END IF;<br />
EXCEPTION<br />
WHEN out_of_stock THEN<br />
&#8211; handle the error<br />
END;</h5>
<h5> </h5>
]]></content:encoded>
			<wfw:commentRss>http://www.orablogger.com/2011/09/pragma-exception_init/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ORACLE PL/SQL异常处理(Exception)学习笔记</title>
		<link>http://www.orablogger.com/2011/09/oracle-plsql-exception/</link>
		<comments>http://www.orablogger.com/2011/09/oracle-plsql-exception/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 03:08:50 +0000</pubDate>
		<dc:creator>happydba</dc:creator>
				<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[Exception]]></category>

		<guid isPermaLink="false">http://www.orablogger.com/?p=474</guid>
		<description><![CDATA[1、PL/SQL错误类型 错误类型 报告者 处理方法 编译时错误 PL/SQL编译器 交互式地处理：编译器报告错误，你必须更正这些错误 运行时错误 PL/SQL运行时引擎 程序化地处理：异常由异常处理子程序引发并进行捕获 2、异常的声明 有两种异常：用户自定义异常和预定义异常 用户自定义异常就是由程序员自己定义的一个错误。该错误还不是非常重要，所以并没有将整个错误包含在Oracle的错误中。例如，它可能是一个与数据有关的错误。而预定义异常则对应于一般的SQL和PL/SQL错误。 用户自定义异常是在PL/SQL块的声明部分声明的。像变量一样，异常也有一个类型（EXCEPTION）和有效范围。例如：  DECLARE Exception_name EXCEPTION; …    3、异常的引发 与异常相关联的错误发生的时候，就会引发相应的异常。用户自定义异常是通过RAISE语句显式引发的，而预定义异常则是在它们关联的ORACLE错误发生的时候隐式引发的。如果发生了一个还没有和异常进行关联的ORACLE错误的时候，也会引发一个异常。该异常可以使用OTHERS子程序进行捕获。预定义的异常也可以使用RAISE进行显式地引发，如果需要这样做的话。 … RAISE exception_name; …      4、异常的处理 发生异常的时候，程序的控制就会转移到代码块的异常处理部分。异常处理部分是由异常处理子程序组成的，这些异常处理子程序可以是针对某些异常的，也可以是针对所有异常的。与该异常相关联的错误发生，并引发了该异常的时候，就会执行异常处理部分的代码。 异常处理部分的语法如下：  EXCEPTION WHEN exception_name THEN Sequence_of_statements1; WHEN exception_name THEN Sequence_of_statements2; WHEN OTHERS THEN Sequence_of_statements3; END;  每一个异常处理部分都是由WHEN子句和引发异常以后要执行的语句组成的。WHEN标识这个处理子程序是针对哪个异常的。 OTHERS异常处理子程序 PL/SQL定义了一个异常处理子程序，即OTHERS。当前异常处理部分定义的所有WHEN语句都没有处理的任意一个已引发的异常，都会导致执行这个OTHERS异常处理子程序。该异常处理子程序应该总是作为代码块的最后一个异常处理子程序，这样就会首先扫描前面的异常处理子程序。WHEN OTHERS会捕获所有异常，不管这些异常是预定义的，还是用户自定义的。 检查错误堆栈—SQLCODE和SQLERRM PL/SQL使用两个内置函数SQLCODE和SQLERRM提供错误信息。SQLCODE返回的是当前的错误代号，而SQLERRM返回的是当前的错误信息文本。如果是用户自定义的异常，SQLCODE就会返回值1，SQLERRM就会返回“ User-defined Exception”。  下面是一个使用SQLCODE和SQLERRM的例子 DECLARE   &#8212; [...]]]></description>
			<content:encoded><![CDATA[<div>
<h5><strong>1、PL/SQL错误类型</strong></h5>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="108">
<h5>错误类型</h5>
</td>
<td valign="top" width="156">
<h5>报告者</h5>
</td>
<td valign="top" width="265">
<h5>处理方法</h5>
</td>
</tr>
<tr>
<td valign="top" width="108">
<h5>编译时错误</h5>
</td>
<td valign="top" width="156">
<h5>PL/SQL编译器</h5>
</td>
<td valign="top" width="265">
<h5>交互式地处理：编译器报告错误，你必须更正这些错误</h5>
</td>
</tr>
<tr>
<td valign="top" width="108">
<h5>运行时错误</h5>
</td>
<td valign="top" width="156">
<h5>PL/SQL运行时引擎</h5>
</td>
<td valign="top" width="265">
<h5>程序化地处理：异常由异常处理子程序引发并进行捕获</h5>
</td>
</tr>
</tbody>
</table>
<h5><span id="more-474"></span></h5>
<h5><strong>2、异常的声明</strong></h5>
<h5>有两种异常：用户自定义异常和预定义异常</h5>
<h5>用户自定义异常就是由程序员自己定义的一个错误。该错误还不是非常重要，所以并没有将整个错误包含在Oracle的错误中。例如，它可能是一个与数据有关的错误。而预定义异常则对应于一般的SQL和PL/SQL错误。</h5>
<h5>用户自定义异常是在PL/SQL块的声明部分声明的。像变量一样，异常也有一个类型（EXCEPTION）和有效范围。例如： </h5>
<h5>DECLARE Exception_name EXCEPTION; …</h5>
<h5> </h5>
<h5> <strong>3、异常的引发</strong></h5>
<h5>与异常相关联的错误发生的时候，就会引发相应的异常。用户自定义异常是通过RAISE语句显式引发的，而预定义异常则是在它们关联的ORACLE错误发生的时候隐式引发的。如果发生了一个还没有和异常进行关联的ORACLE错误的时候，也会引发一个异常。该异常可以使用OTHERS子程序进行捕获。预定义的异常也可以使用RAISE进行显式地引发，如果需要这样做的话。</h5>
<h5>…<br />
RAISE exception_name;<br />
…</h5>
<h5>   </h5>
<h5> <strong>4、异常的处理</strong></h5>
<h5>发生异常的时候，程序的控制就会转移到代码块的异常处理部分。异常处理部分是由异常处理子程序组成的，这些异常处理子程序可以是针对某些异常的，也可以是针对所有异常的。与该异常相关联的错误发生，并引发了该异常的时候，就会执行异常处理部分的代码。</h5>
<h5>异常处理部分的语法如下：</h5>
<h5> EXCEPTION<br />
WHEN exception_name THEN<br />
Sequence_of_statements1;<br />
WHEN exception_name THEN<br />
Sequence_of_statements2;<br />
WHEN OTHERS THEN<br />
Sequence_of_statements3;<br />
END;</h5>
<h5> 每一个异常处理部分都是由WHEN子句和引发异常以后要执行的语句组成的。WHEN标识这个处理子程序是针对哪个异常的。</h5>
<h5>OTHERS异常处理子程序</h5>
<h5>PL/SQL定义了一个异常处理子程序，即OTHERS。当前异常处理部分定义的所有WHEN语句都没有处理的任意一个已引发的异常，都会导致执行这个OTHERS异常处理子程序。该异常处理子程序应该总是作为代码块的最后一个异常处理子程序，这样就会首先扫描前面的异常处理子程序。WHEN OTHERS会捕获所有异常，不管这些异常是预定义的，还是用户自定义的。</h5>
<h5>检查错误堆栈—SQLCODE和SQLERRM</h5>
<h5>PL/SQL使用两个内置函数<strong>SQLCODE</strong>和<strong>SQLERRM</strong>提供错误信息。SQLCODE返回的是当前的错误代号，而SQLERRM返回的是当前的错误信息文本。如果是用户自定义的异常，SQLCODE就会返回值1，SQLERRM就会返回“ User-defined Exception”。</h5>
<h5> 下面是一个使用SQLCODE和SQLERRM的例子</h5>
<h5>DECLARE<br />
  &#8212; Exception to indicate an error condition  </h5>
<h5>  e_DuplicateAuthors EXCEPTION;</h5>
<h5>  &#8212; IDs for three authors  </h5>
<h5>  v_Author1 books.author1%TYPE;</h5>
<h5>  v_Author2 books.author2%TYPE;</h5>
<h5>  v_Author3 books.author3%TYPE;</h5>
<h5>  &#8212; Code and text of other runtime errors  </h5>
<h5>  v_ErrorCode log_table.code%TYPE;</h5>
<h5>  v_ErrorText log_table.message%TYPE;</h5>
<h5>BEGIN</h5>
<h5>  /* Find the IDs for the 3 authors of &#8216;Oracle9i DBA 101&#8242; */</h5>
<h5>  SELECT author1, author2, author3<br />
 <br />
    INTO v_Author1, v_Author2, v_Author3<br />
 <br />
    FROM books<br />
 <br />
   WHERE title = &#8216;Oracle9i DBA 101&#8242;;</h5>
<h5>  /* Ensure that there are no duplicates */</h5>
<h5>  IF (v_Author1 = v_Author2) OR (v_Author1 = v_Author3) OR<br />
   <br />
     (v_Author2 = v_Author3) THEN<br />
 <br />
    RAISE e_DuplicateAuthors;<br />
 <br />
  END IF;</h5>
<h5>EXCEPTION</h5>
<h5>  WHEN e_DuplicateAuthors THEN<br />
 <br />
    /* Handler which executes when there are duplicate authors for <br />
   <br />
    Oracle9i DBA 101.  We will insert a log message recording  <br />
   <br />
    what has happened. */<br />
 <br />
    INSERT INTO log_table<br />
      (info)<br />
   <br />
    VALUES<br />
      (&#8216;Oracle9i DBA 101 has duplicate authors&#8217;);<br />
 <br />
  WHEN OTHERS THEN<br />
 <br />
    /* Handler which executes for all other errors. */<br />
 <br />
    v_ErrorCode := SQLCODE;<br />
 <br />
    &#8212; Note the use of SUBSTR here.  <br />
 <br />
    v_ErrorText := SUBSTR(SQLERRM, 1, 200);<br />
 <br />
    INSERT INTO log_table<br />
      (code, message, info)<br />
    VALUES<br />
   <br />
      (v_ErrorCode, v_ErrorText, &#8216;Oracle error occurred&#8217;);<br />
 <br />
END;</h5>
<h5>/</h5>
<h5>由于该堆栈上每一条错误消息文本的最大长度均为512个字节，但是堆栈中可能会有多条消息文本。在上面的例子中，v_ErrorText只有200个字符。如果该错误消息文本长度大于200个字符，那么赋值语句</h5>
<h5> v_ErrorText := SQLERRM;</h5>
<h5> 就会引发预定义的异常VALUE_ERROR。为了防止发生这种异常，我们使用了内置函数SUBSTR。</h5>
<h5> </h5>
<h5>注意，SQLCODE和SQLERRM的返回值首先会被分配给局部变量，然后再在SQL语句中使用这些局部变量。因为这些函数都是过程化的函数，所以不能直接在SQL语句中使用它们。</h5>
<h5> </h5>
<h5>通过下面这个例子我们看看错误号和相应的错误消息文本之间的关系</h5>
<h5> <br />
set serveroutput on  <br />
 <br />
BEGIN  <br />
 <br />
  DBMS_OUTPUT.PUT_LINE(&#8216;SQLERRM(0): &#8216; || SQLERRM(0));  <br />
 <br />
  DBMS_OUTPUT.PUT_LINE(&#8216;SQLERRM(100): &#8216; || SQLERRM(100));  <br />
 <br />
  DBMS_OUTPUT.PUT_LINE(&#8216;SQLERRM(10): &#8216; || SQLERRM(10));  <br />
 <br />
  DBMS_OUTPUT.PUT_LINE(&#8216;SQLERRM: &#8216; || SQLERRM);  <br />
 <br />
  DBMS_OUTPUT.PUT_LINE(&#8216;SQLERRM(-1): &#8216; || SQLERRM(-1));  <br />
 <br />
  DBMS_OUTPUT.PUT_LINE(&#8216;SQLERRM(-54): &#8216; || SQLERRM(-54));  <br />
 <br />
END;  <br />
 <br />
/  <br />
 <br />
&#8211;运行结果如下  <br />
 <br />
SQL&gt; @SQLERRM.sql  <br />
 <br />
SQLERRM(0): ORA-0000: normal, successful completion  <br />
 <br />
SQLERRM(100): ORA-01403: no data found  <br />
 <br />
SQLERRM(10):  -10: non-ORACLE exception  <br />
 <br />
SQLERRM: ORA-0000: normal, successful completion  <br />
 <br />
SQLERRM(-1): ORA-00001: unique constraint (.) violated  <br />
 <br />
SQLERRM(-54): ORA-00054: resource busy and acquire with NOWAIT specified  <br />
 <br />
   <br />
 <br />
PL/SQL procedure successfully completed.  <br />
 </h5>
<h5>EXCEPTION_INIT pragma</h5>
<h5>你可以将一个经过命名的异常和一个特别的ORACLE错误相关联。这会<strong>使你专门能够捕获<em>此</em>错误，而不是通过</strong><strong>WHEN OTHERS</strong><strong>处理器来进行捕获</strong>。EXCEPTION_INIT pragma的语法如下：</h5>
<h5>PRAGMA       EXCEPTION_INIT(exception_name, <strong>-</strong><strong>Oracle_error_number</strong>);</h5>
<h5>这里，exception_name是在PRAGMA前面声明的异常的名字，而Oracle_error_number是与此命名异常相关的所需错误代码。这个PRAGMA必须在声明部分。</h5>
<h5>下面这个例子在运行时刻如果遇到“ORA-1400:mandatory NOT NULL column missing or NULL during insert”错误时将引发e_MissingNull&#8211;用户定义的异常。</h5>
<h5>DECLARE  <br />
 <br />
  e_MissingNull EXCEPTION;  <br />
 <br />
  PRAGMA EXCEPTION_INIT(e_MissingNull, -1400);  <br />
 <br />
BEGIN  <br />
 <br />
  INSERT INTO students (id) VALUES (NULL);  <br />
 <br />
EXCEPTION   s<br />
 <br />
  WHEN e_MissingNull then  <br />
 <br />
    INSERT INTO log_table (info) VALUES (&#8216;ORA-1400 occurred&#8217;);  <br />
 <br />
END;  <br />
 <br />
/ <br />
 <br />
 </h5>
<h5>每次发生PRAGMA EXCEPTION_INIT时，一个Oracle错误只能和一个用户自定义异常相关联。在异常处理内部，SQLCODE和SQLERRM将会返回发生Oracle错误的代码和错误消息，但是不会返回用户定义的消息。</h5>
<h5> </h5>
<h5>使用RAISE_APPLICATION_ERROR</h5>
<h5>你可以使用内置函数<strong>RAISE_APPLICATION_ERROR</strong>以创建自己的错误消息，这可能要比已命名的异常更具说明性。用户定义消息从块中传递到调用环境中的方式和ORACLE错误是一样的。语法如下：</h5>
<h5>RAISE_APPLICATION_ERROR(error_number,error_message,[keep_errors]);</h5>
<h5> </h5>
<h5>error_number是从-200000到-20999之间的参数，error_message是与此错误相关的正文，不能多于512个字节。而<strong>keep_errors</strong>是一个布尔值，是可选的，如果为TRUE，那么新的错误将被添加到已经引发的错误列表中（如果有的话）。如果为FALSE（这是缺省的设置），那么新的错误将替换错误的当前列表。</h5>
<h5> </h5>
<h5>例如下面的这个例子将在为一个新的学生注册以前检查是否在班级中有足够的地方容纳他。</h5>
<h5>CREATE OR REPLACE PROCEDURE Register(<br />
                                    <br />
                                     /* Registers the student identified by the p_StudentID parameter in the class <br />
                                     <br />
                                          identified by the p_Department and p_Course parameters. Before calling <br />
                                     <br />
                                          ClassPackage.AddStudent, which actually adds the student to the class, this <br />
                                     <br />
                                          procedure verifies that there is room in the class, and that the class <br />
                                     <br />
                                          exists. */<br />
                                    <br />
                                     p_StudentID IN students.id%TYPE,<br />
                                    <br />
                                     p_Department IN classes.department%TYPE,<br />
                                    <br />
                                     p_Course IN classes.course%TYPE) AS</h5>
<h5>  v_CurrentStudents NUMBER; &#8212; Current number of students in the class </h5>
<h5>  v_MaxStudents NUMBER; &#8212; Maximum number of students in the class </h5>
<h5>BEGIN</h5>
<h5>  /* Determine the current number of students registered, and the maximum <br />
 <br />
  number of students allowed to register. */</h5>
<h5>  SELECT current_students, max_students<br />
 <br />
    INTO v_CurrentStudents, v_MaxStudents<br />
 <br />
    FROM classes<br />
 <br />
   WHERE course = p_Course<br />
       <br />
     AND department = p_Department;</h5>
<h5>  /* Make sure there is enough room for this additional student. */</h5>
<h5>  IF v_CurrentStudents + 1 &gt; v_MaxStudents THEN<br />
 <br />
    RAISE_APPLICATION_ERROR(-20000,<br />
                            &#8216;Can&#8221;t add more students to &#8216; ||<br />
                           <br />
                            p_Department || &#8216; &#8216; || p_Course);<br />
 <br />
  END IF;</h5>
<h5>  /* Add the student to the class. */</h5>
<h5>  ClassPackage.AddStudent(p_StudentID, p_Department, p_Course);</h5>
<h5>EXCEPTION</h5>
<h5>  WHEN NO_DATA_FOUND THEN<br />
 <br />
    /* Class information passed to this procedure doesn&#8217;t exist. Raise an error <br />
   <br />
    to let the calling program know of this. */<br />
 <br />
    RAISE_APPLICATION_ERROR(-20001,<br />
                            p_Department || &#8216; &#8216; || p_Course ||<br />
                           <br />
                            &#8216; doesn&#8221;t exist!&#8217;);<br />
 <br />
END Register;</h5>
<h5>/</h5>
<h5> </h5>
<h5><strong>5、异常的传播</strong></h5>
<h5> </h5>
<h5>1）在执行部分引发的异常</h5>
<h5>当一个异常是在块的执行部分引发的，PL/SQL使用下面的方法决定要激活哪个异常处理器：</h5>
<h5>如果当前块对该异常设置了处理器，那么执行它并成功完成该块的执行，然后控制会转给包含块。</h5>
<h5>如果当前块没有对当前异常定义处理器，那么通过在包含块中引发它来传播异常。然后对包含块执行步骤一。</h5>
<h5> </h5>
<h5>2）在声明部分引发的异常</h5>
<h5>如果在声明部分的赋值操作引发了一个异常，那么该异常将立即传播给包含块。发生这种情况以后，在前面给出的法则将进一步被应用到异常的传播上。尽管在当前块中有一个处理器，它也不会被执行。</h5>
<h5> </h5>
<h5>3）在异常处理部分引发的异常</h5>
<h5>在异常处理器中也可能引发异常，这可以是通过RAISE语句显式引发的，也可以是由运行时刻错误隐含引发的。无论怎样，异常都立即被传播给包含块，这和声明部分引发的异常相类似。</h5>
<h5> </h5>
<h5> </h5>
<h5><strong>6、使用异常的准则</strong></h5>
<h5> </h5>
<h5>1）异常的范围</h5>
<h5>异常像变量一样，也是有一定范围的。如果用户自定义异常传播到它的范围之外，就不能再通过名称引用它。</h5>
<h5> </h5>
<h5>BEGIN<br />
  DECLARE<br />
 <br />
    e_UserDefinedException EXCEPTION;<br />
 <br />
  BEGIN<br />
 <br />
    RAISE e_UserDefinedException;<br />
 <br />
  END;</h5>
<h5>EXCEPTION</h5>
<h5>  /* e_UserDefinedException is out of scope here &#8211; can only be <br />
 <br />
  handled by an OTHERS handler */</h5>
<h5>  WHEN OTHERS THEN<br />
 <br />
    /* Just re-raise the exception, which will be propagated to the <br />
   <br />
    calling environment */<br />
 <br />
    RAISE;<br />
 <br />
END;</h5>
<h5>/</h5>
<h5> </h5>
<h5>一般而言，如果打算将用户自定义的错误传播到代码块之外，最好的方法就是在包中定义该异常，以使其在该代码块之外仍可见，或使用RAISE_APPLICATION_ERROR引发该异常。如果创建一个成为GLOBALS的包，并在其中定义了一个e_UserDefinedException异常，那么这个异常在外部块中仍然可见。</h5>
<h5> </h5>
<h5>如下例所示</h5>
<h5>  <br />
/* This package contains global declarations. Objects declared here will  <br />
 <br />
   be visible via qualified references for any other blocks or procedures. <br />
 <br />
   Note that this package does not have a package body. */ <br />
 <br />
   <br />
 <br />
  /* A user-defined exception. */ <br />
 <br />
  e_UserDefinedException EXCEPTION;  <br />
 <br />
END Globals;  <br />
 <br />
/  <br />
 <br />
   <br />
 <br />
&#8211;有了这个和GLOBALS包以后，就可以重写前面的代码：  <br />
 <br />
   <br />
 <br />
BEGIN  <br />
 <br />
  BEGIN  <br />
 <br />
    RAISE Globals.e_UserDefinedException;  <br />
 <br />
  END;  <br />
 <br />
EXCEPTION  <br />
 <br />
  /* Since e_UserDefinedException is still visible, we can handle it  <br />
 <br />
     explicitly */ <br />
 <br />
  WHEN Globals.e_UserDefinedException THEN           &#8211;引用包中定义异常  <br />
 <br />
    /* Just re-raise the exception, which will be propagated to the <br />
 <br />
       calling environment */ <br />
 <br />
    RAISE;  <br />
 <br />
END;  <br />
 <br />
/ <br />
 <br />
 </h5>
<h5>2）避免未处理的异常</h5>
<h5>优秀的编程经验是在整个程序中避免出现任何未经过处理的异常。这可以通过在程序的最顶层使用一个OTHERS子程序来实现。该处理子程序可以只登记错误并登记错误发生的位置，通过这种方法，就可以保证每个错误都会得到检查。</h5>
<h5> </h5>
<h5>如下例所示</h5>
<h5> </h5>
<h5>CREATE OR REPLACE PACKAGE Globals AS</h5>
<h5>  v_errortext varchar2(200);</h5>
<h5>Begin</h5>
<h5>  …<br />
 <br />
  EXCEPTION<br />
 <br />
  WHEN OTHERS THEN<br />
 <br />
  v_errornumber := SQLCODE;</h5>
<h5>  v_errortext := SUBSTR(SQLERRM, 1, 200);</h5>
<h5>  INSERT INTO log_table<br />
    (code, message, info)<br />
 <br />
  VALUES<br />
 <br />
    (v_errornumber,<br />
     v_errortext,<br />
     ’Oracle error occurred<br />
     at’ || TO_CHAR(SYSDATE, ’DD &#8211; MON &#8211; YY HH24 :MI :SS’));</h5>
<h5>END;</h5>
<h5>3）标识错误发生的位置</h5>
<h5>由于整个代码块都使用同一个异常处理部分检查并处理异常，所以很难确定引发这个错误的是哪一条SQL语句。考虑下面示例</h5>
<h5> <br />
BEGIN<br />
SELECT…  <br />
 <br />
SELECT..  <br />
 <br />
SELECT…  <br />
 <br />
EXCEPTION  <br />
 <br />
WHEN NO_DATA_FOUND THEN  <br />
 <br />
&#8211;which select statement raised the exception?  <br />
 <br />
END;  <br />
 <br />
   <br />
 <br />
&#8211;解决上述问题的方法有两种。第一种是添加一个标识该SQL语句的计数器：  <br />
 <br />
   <br />
 <br />
DECLARE  <br />
 <br />
V_selectcounter NUMBER:=1;  <br />
 <br />
BEGIN  <br />
 <br />
SELECT…  <br />
 <br />
V_selectcounter NUMBER:=2;  <br />
 <br />
SELECT…  <br />
 <br />
V_selectcounter NUMBER:=3;  <br />
 <br />
SELECT…  <br />
 <br />
EXCEPTION  <br />
 <br />
WHEN NO_DATA_FOUND THEN  <br />
 <br />
INSERT INTO log_table(info) VALUES(‘NO DATA FOUND IN SELECT’||v_selectcounter);  <br />
 <br />
END;  <br />
 <br />
   <br />
 <br />
&#8211;另一种方法是将每一条语句都放置在它自己的子块中：  <br />
 <br />
   <br />
 <br />
BEGIN  <br />
 <br />
BEGIN  <br />
 <br />
              SELECT…  <br />
 <br />
       EXCEPTION  <br />
 <br />
              WHEN NO_DATA_FOUND THEN  <br />
 <br />
                     INSERT INTO log_table(info) VALUES(‘NO DATA FOUND IN SELECT 1’);  <br />
 <br />
       END;  <br />
 <br />
BEGIN  <br />
 <br />
              SELECT…  <br />
 <br />
       EXCEPTION  <br />
 <br />
              WHEN NO_DATA_FOUND THEN  <br />
 <br />
                     INSERT INTO log_table(info) VALUES(‘NO DATA FOUND IN SELECT 2’);  <br />
 <br />
       END;  <br />
 <br />
BEGIN  <br />
 <br />
              SELECT…  <br />
 <br />
       EXCEPTION  <br />
 <br />
              WHEN NO_DATA_FOUND THEN  <br />
 <br />
                     INSERT INTO log_table(info) VALUES(‘NO DATA FOUND IN SELECT 3’);  <br />
 <br />
       END;  <br />
 <br />
END;  <br />
  <br />
  </h5>
<h5><strong>7、异常代码的编写风格</strong></h5>
<h5> </h5>
<h5>1）RAISE_APPLICATION_ERROR和RAISE的比较</h5>
<h5> </h5>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="237">
<h5>RAISE_APPLICATION_ERROR</h5>
</td>
<td valign="top">
<h5>RAISE</h5>
</td>
</tr>
<tr>
<td valign="top" width="237">
<h5>允许我们填写自己的错误消息文本，该文本可以包含应用程序专用的数据</h5>
</td>
<td valign="top">
<h5>不允许包含消息文本</h5>
</td>
</tr>
<tr>
<td valign="top" width="237">
<h5>不能使用已命名的异常处理子程序进行捕获，只能使用OTHERS处理子程序进行捕获</h5>
</td>
<td valign="top">
<h5>可以使用已命名的处理子程序捕获该异常，只要该异常在它自己的异常范围内即可</h5>
</td>
</tr>
</tbody>
</table>
<h5> </h5>
<h5>通常而言，推荐对设计给终端用户看的错误，使用RAISE_APPLICATION_ERROR。因为对于他们而言，具体的错误编号和描述性文本非常有用。而另一方面，对设计为由程序直接进行处理的异常，推荐使用RAISE。</h5>
<h5> </h5>
<h5>2）将异常作为控制语句</h5>
<h5>因为引发异常会将程序的控制逻辑转移到代码块的异常处理部分，所以可以将RAISE语句用作控制语句，就像GOTO语句一样。例如，如果我们有很深的嵌套循环，并需要立即从中退出的时候，这可能会非常有用。</h5>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.orablogger.com/2011/09/oracle-plsql-exception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle中的格式化函数</title>
		<link>http://www.orablogger.com/2011/08/oracle%e4%b8%ad%e7%9a%84%e6%a0%bc%e5%bc%8f%e5%8c%96%e5%87%bd%e6%95%b0/</link>
		<comments>http://www.orablogger.com/2011/08/oracle%e4%b8%ad%e7%9a%84%e6%a0%bc%e5%bc%8f%e5%8c%96%e5%87%bd%e6%95%b0/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 01:18:02 +0000</pubDate>
		<dc:creator>happydba</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.orablogger.com/?p=470</guid>
		<description><![CDATA[  格式化函数提供一套有效的工具用于把各种数据类型（日期/时间，int，float，numeric）转换成格式化的字符串以及反过来从格式化的字符串转换成原始的数据类型。 表 5-6. 格式化函数 函数 返回 描述 例子 to_char(datetime, text) text 把datetime 转换成 string to_char(&#8216;now&#8217;::datetime, &#8216;hh12:mi:ss&#8217;) to_char(timestamp, text) text 把 timestamp 转换成 string to_char( now(), &#8216;hh12:mi:ss&#8217;) to_char(int, text) text 把 int4/int8 转换成 string to_char(125, &#8217;999&#8242;) to_char(float, text) text 把 float4/float8 转换成 string to_char(125.8, &#8217;999d9&#8242;) to_char(numeric, text) text 把 numeric 转换成 string to_char(-125.8, &#8217;999d99s&#8217;) to_datetime(text, [...]]]></description>
			<content:encoded><![CDATA[<h5> </h5>
<p>格式化函数提供一套有效的工具用于把各种数据类型（日期/时间，int，float，numeric）转换成格式化的字符串以及反过来从格式化的字符串转换成原始的数据类型。</p>
<p><strong>表 5-6. 格式化函数</strong><br />
<span id="more-470"></span></p>
<table class="calstable" border="1">
<tbody>
<tr>
<th align="left" valign="top">函数</th>
<th align="left" valign="top">返回</th>
<th align="left" valign="top">描述</th>
<th align="left" valign="top">例子</th>
</tr>
<tr>
<td valign="top">to_char(datetime, text)</td>
<td valign="top">text</td>
<td valign="top">把datetime 转换成<br />
string</td>
<td valign="top">to_char(&#8216;now&#8217;::datetime,<br />
&#8216;hh12:mi:ss&#8217;)</td>
</tr>
<tr>
<td valign="top">to_char(timestamp, text)</td>
<td valign="top">text</td>
<td valign="top">把 timestamp 转换成<br />
string</td>
<td valign="top">to_char( now(),<br />
&#8216;hh12:mi:ss&#8217;)</td>
</tr>
<tr>
<td valign="top">to_char(int,<br />
text)</td>
<td valign="top">text</td>
<td valign="top">把 int4/int8 转换成<br />
string</td>
<td valign="top">to_char(125,<br />
&#8217;999&#8242;)</td>
</tr>
<tr>
<td valign="top">to_char(float,<br />
text)</td>
<td valign="top">text</td>
<td valign="top">把 float4/float8<br />
转换成 string</td>
<td valign="top">to_char(125.8,<br />
&#8217;999d9&#8242;)</td>
</tr>
<tr>
<td valign="top">to_char(numeric, text)</td>
<td valign="top">text</td>
<td valign="top">把 numeric 转换成<br />
string</td>
<td valign="top">to_char(-125.8,<br />
&#8217;999d99s&#8217;)</td>
</tr>
<tr>
<td valign="top">to_datetime(text, text)</td>
<td valign="top">datetime</td>
<td valign="top">把 string 转换成<br />
datetime</td>
<td valign="top">to_datetime(&#8217;05<br />
dec 2000 13&#8242;, &#8216;dd mon yyyy hh&#8217;)</td>
</tr>
<tr>
<td valign="top">to_date(text,<br />
text)</td>
<td valign="top">date</td>
<td valign="top">把 string 转换成<br />
date</td>
<td valign="top">to_date(&#8217;05 dec<br />
2000&#8242;, &#8216;dd mon yyyy&#8217;)</td>
</tr>
<tr>
<td valign="top">to_timestamp(text, text)</td>
<td valign="top">date</td>
<td valign="top">把 string 转换成<br />
timestamp</td>
<td valign="top">to_timestamp(&#8217;05 dec 2000&#8242;, &#8216;dd<br />
mon yyyy&#8217;)</td>
</tr>
<tr>
<td valign="top">to_number(text,<br />
text)</td>
<td valign="top">numeric</td>
<td valign="top">把 string 转换成<br />
numeric</td>
<td valign="top">to_number(&#8217;12,454.8-&#8217;,<br />
&#8217;99g999d9s&#8217;)</td>
</tr>
</tbody>
</table>
<p>所有格式化函数都是 format-picture （格式图）的第二个参数。</p>
<p><strong>表 5-7. 用于日期/时间 to_char() 版本的format-pictures。</strong></p>
<table class="calstable" border="1">
<tbody>
<tr>
<th align="left" valign="top">format-picture</th>
<th align="left" valign="top">描述</th>
</tr>
<tr>
<td valign="top">hh</td>
<td valign="top">一天中的小时 (01-12)</td>
</tr>
<tr>
<td valign="top">hh12</td>
<td valign="top">一天中的小时 (01-12)</td>
</tr>
<tr>
<td valign="top">mi</td>
<td valign="top">分钟 (00-59)</td>
</tr>
<tr>
<td valign="top">ss</td>
<td valign="top">秒 (00-59)</td>
</tr>
<tr>
<td valign="top">ssss</td>
<td valign="top">过了午夜的秒<br />
(0-86399)</td>
</tr>
<tr>
<td valign="top">y,yyy</td>
<td valign="top">带逗号的年 (4 或更多位)</td>
</tr>
<tr>
<td valign="top">yyyy</td>
<td valign="top">年 (4 或更多位)</td>
</tr>
<tr>
<td valign="top">yyy</td>
<td valign="top">年的最后三位</td>
</tr>
<tr>
<td valign="top">yy</td>
<td valign="top">年的最后两位</td>
</tr>
<tr>
<td valign="top">y</td>
<td valign="top">年的最后一位</td>
</tr>
<tr>
<td valign="top">month</td>
<td valign="top">完整的月份名（9字符）-所有字符大写</td>
</tr>
<tr>
<td valign="top">month</td>
<td valign="top">完整的月份名（9字符）-首字符大写</td>
</tr>
<tr>
<td valign="top">month</td>
<td valign="top">完整的月份名（9字符）-所有字符小写</td>
</tr>
<tr>
<td valign="top">mon</td>
<td valign="top">缩写的月份名（3字符）-所有字符大写</td>
</tr>
<tr>
<td valign="top">mon</td>
<td valign="top">缩写的月份名（3字符）-首字符大写</td>
</tr>
<tr>
<td valign="top">mon</td>
<td valign="top">缩写的月份名（3字符）-所有字符小写</td>
</tr>
<tr>
<td valign="top">mm</td>
<td valign="top">月份(01-12)</td>
</tr>
<tr>
<td valign="top">day</td>
<td valign="top">完整的日期名（9字符）-所有字符大写</td>
</tr>
<tr>
<td valign="top">day</td>
<td valign="top">完整的日期名（9字符）-首字符大写</td>
</tr>
<tr>
<td valign="top">day</td>
<td valign="top">完整的日期名（9字符）-所有字符小写</td>
</tr>
<tr>
<td valign="top">dy</td>
<td valign="top">缩写的日期名（3字符）-所有字符大写</td>
</tr>
<tr>
<td valign="top">dy</td>
<td valign="top">缩写的日期名（3字符）-首字符大写</td>
</tr>
<tr>
<td valign="top">dy</td>
<td valign="top">缩写的日期名（3字符）-所有字符小写</td>
</tr>
<tr>
<td valign="top">ddd</td>
<td valign="top">一年中的日子<br />
(001-366)</td>
</tr>
<tr>
<td valign="top">dd</td>
<td valign="top">一月中的日子 (01-31)</td>
</tr>
<tr>
<td valign="top">d</td>
<td valign="top">一周中的日子 (1-7;<br />
sun=1)</td>
</tr>
<tr>
<td valign="top">w</td>
<td valign="top">月中的周</td>
</tr>
<tr>
<td valign="top">ww</td>
<td valign="top">年中的周</td>
</tr>
<tr>
<td valign="top">cc</td>
<td valign="top">世纪（两位）</td>
</tr>
<tr>
<td valign="top">j</td>
<td valign="top">julian 日子（从4712<br />
bc 年一月一日以来的日子）</td>
</tr>
<tr>
<td valign="top">q</td>
<td valign="top">季度</td>
</tr>
<tr>
<td valign="top">rm</td>
<td valign="top">罗马数字的月份 (i-xii;<br />
i=jan)</td>
</tr>
</tbody>
</table>
<p>所有 format-pictures （格式图）允许使用后缀（后缀/前缀）。对于近似<br />
format-picture（格式图），后缀总是有效的。&#8217;fx&#8217;只是全局前缀。</p>
<p><strong>表 5-8. 用于日期/时间 to_char() 版本的 format-pictures （格式图）后缀。</strong></p>
<table class="calstable" border="1">
<tbody>
<tr>
<th align="left" valign="top">后缀</th>
<th align="left" valign="top">描述</th>
<th align="left" valign="top">例子</th>
</tr>
<tr>
<td valign="top">fm</td>
<td valign="top">填充模式-前缀</td>
<td valign="top">fmmonth</td>
</tr>
<tr>
<td valign="top">th</td>
<td valign="top">大写顺序数-前缀</td>
<td valign="top">ddth</td>
</tr>
<tr>
<td valign="top">th</td>
<td valign="top">小写顺序数-后缀</td>
<td valign="top">ddth</td>
</tr>
<tr>
<td valign="top">fx</td>
<td valign="top">fx &#8211; （固定模式）全局<br />
format-picture<br />
（格式图）开关。如果没有使用这个选项 to_datetime /<br />
to_date<br />
忽略空白。必须作为formt-picture（格式图）里的第一个项目使用。</td>
<td valign="top">fx month dd day</td>
</tr>
<tr>
<td valign="top">sp</td>
<td valign="top">拼写模式（目前未实现）</td>
<td valign="top">ddsp</td>
</tr>
</tbody>
</table>
<p>&#8216;/&#8217; &#8211; 必须用做双 //，例如 &#8216;//hh//mi//ss&#8217;</p>
<p>&#8216;&#8221;&#8216; &#8211; 双引号之间的字串被忽略并且不被分析。如果你想向输出写 &#8216;&#8221;&#8216; 你必须用 //&#8221;，例如 &#8216;//&#8221;yyyy<br />
month//&#8221;&#8216;。</p>
<p>text &#8211; postgresql 的 to_char() 支持不带 &#8216;&#8221;&#8216;<br />
的文本，但是带有双引号的字串会快些并且可以保证该文本不会被解释成关键字（format-picture，格式图），例如<br />
&#8216;&#8221;hello year: &#8220;yyyy&#8217;。</p>
<p><strong>表 5-9. 用于数字 (int/float/numeric) to_char()<br />
版本的format-pictures （格式图）。</strong></p>
<table class="calstable" border="1">
<tbody>
<tr>
<th align="left" valign="top">格式图</th>
<th align="left" valign="top">描述</th>
</tr>
<tr>
<td valign="top">9</td>
<td valign="top">返回指定位数的值，如果不够位数用空白代替</td>
</tr>
<tr>
<td valign="top">0</td>
<td valign="top">象 9<br />
一样，但是把空白替换成零</td>
</tr>
<tr>
<td valign="top">. (句点)</td>
<td valign="top">小数点</td>
</tr>
<tr>
<td valign="top">, (逗号)</td>
<td valign="top">分组（千进）分隔符</td>
</tr>
<tr>
<td valign="top">pr</td>
<td valign="top">在尖括号内返回负数</td>
</tr>
<tr>
<td valign="top">s</td>
<td valign="top">用负号返回负数（使用本地）</td>
</tr>
<tr>
<td valign="top">l</td>
<td valign="top">货币符号（使用本地）</td>
</tr>
<tr>
<td valign="top">d</td>
<td valign="top">小数点（使用本地）</td>
</tr>
<tr>
<td valign="top">g</td>
<td valign="top">分组符（使用本地）</td>
</tr>
<tr>
<td valign="top">mi</td>
<td valign="top">在指定位置返回负号（如果数字<br />
&lt; 0）</td>
</tr>
<tr>
<td valign="top">pl</td>
<td valign="top">在指定位置返回正号（如果数字<br />
&gt; 0） postgresql 扩展</td>
</tr>
<tr>
<td valign="top">sg</td>
<td valign="top">在指定位置返回正/负号（如果数字 &lt; 0） -<br />
postgresql 扩展</td>
</tr>
<tr>
<td valign="top">rn</td>
<td valign="top">返回数字的罗马数字（数字必须介于1 和 3999之间）</td>
</tr>
<tr>
<td valign="top">th 或th</td>
<td valign="top">把数字转换成自然数（如果是负数或小数不转换） -<br />
postgresql 扩展</td>
</tr>
<tr>
<td valign="top">v</td>
<td valign="top">arg1 * (10 ^<br />
n)；- 返回一个乘以 10^n （这里 &#8216;n&#8217;<br />
是&#8217;v'后面的数字 &#8217;9&#8242;）。to_char() 不支持同时使用<br />
&#8216;v&#8217; 和小数点，如 &#8220;99.9v99&#8243;。</td>
</tr>
<tr>
<td valign="top">eeee</td>
<td valign="top">科学记数，目前不支持。</td>
</tr>
</tbody>
</table>
<p>注意：通过a sign formatted via &#8216;sg&#8217;，&#8217;pl&#8217; 或 &#8216;mi&#8217;<br />
格式化的符号数不一定是数字；to_char(-12, &#8216;s9999&#8242;)生成：</p>
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' -12'</pre>
<p>，但是 to_char(-12, &#8216;mi9999&#8242;)生成：</p>
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'- 12'</pre>
<p>。oracle 不允许在 &#8217;9&#8242; 前面使用 &#8216;mi&#8217;，在 oracle 里，它总是在 &#8217;9&#8242; 后面。.</p>
<p><strong>表 5-10. to_char()的例子</strong></p>
<table class="calstable" border="1">
<tbody>
<tr>
<th align="left" valign="top">输入</th>
<th align="left" valign="top">输出</th>
</tr>
<tr>
<td valign="top">to_char(now(),<br />
&#8216;day, hh12:mi:ss&#8217;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'tuesday , 05:39:18'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char(now(),<br />
&#8216;fmday, hh12:mi:ss&#8217;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'tuesday, 05:39:18'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( -0.1,<br />
&#8217;99.99&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' -.10'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( -0.1,<br />
&#8216;fm9.99&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'-.1'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 0.1,<br />
&#8217;0.9&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 0.1'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 12,<br />
&#8217;9990999.9&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 0012.0'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 12,<br />
&#8216;fm9990999.9&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'0012'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 485,<br />
&#8217;999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 485'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( -485,<br />
&#8217;999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'-485'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 485,<br />
&#8217;9 9 9&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 4 8 5'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 1485,<br />
&#8217;9,999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 1,485'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 1485,<br />
&#8217;9g999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 1 485'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 148.5,<br />
&#8217;999.999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 148.500'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 148.5,<br />
&#8217;999d999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 148,500'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char(<br />
3148.5,&#8217;9g999d999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 3 148,500'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( -485,<br />
&#8217;999s&#8217;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'485-'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( -485,<br />
&#8217;999mi&#8217;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'485-'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 485,<br />
&#8217;999mi&#8217;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'485'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 485,<br />
&#8216;pl999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'+485'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 485,<br />
&#8216;sg999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'+485'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( -485,<br />
&#8216;sg999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'-485'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( -485,<br />
&#8217;9sg99&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'4-85'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( -485,<br />
&#8217;999pr&#8217;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'&lt;485&gt;'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 485,<br />
&#8216;l999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'dm 485'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 485,<br />
&#8216;rn&#8217;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' cdlxxxv'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 485,<br />
&#8216;fmrn&#8217;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'cdlxxxv'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 5.2,<br />
&#8216;fmrn&#8217;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'v'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 482,<br />
&#8217;999th&#8217;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 482nd'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 485,<br />
&#8216;&#8221;good number:&#8221;999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'good number: 485'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 485.8,<br />
&#8216;&#8221;pre-decimal:&#8221;999&#8243;<br />
post-decimal:&#8221; .999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">'pre-decimal: 485 post-decimal: .800'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 12,<br />
&#8217;99v999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 12000'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 12.4,<br />
&#8217;99v999&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 12400'</pre>
</td>
</tr>
<tr>
<td valign="top">to_char( 12.45,<br />
&#8217;99v9&#8242;)</td>
<td valign="top">
<pre class="programlisting" style="word-wrap: break-word; white-space: normal;">' 125'</pre>
</td>
</tr>
</tbody>
</table>
<h5> </h5>
<h5> </h5>
<h5> </h5>
]]></content:encoded>
			<wfw:commentRss>http://www.orablogger.com/2011/08/oracle%e4%b8%ad%e7%9a%84%e6%a0%bc%e5%bc%8f%e5%8c%96%e5%87%bd%e6%95%b0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle10GR2 中的RESTORE POINT</title>
		<link>http://www.orablogger.com/2010/07/oracle10gr2-%e4%b8%ad%e7%9a%84restore-point/</link>
		<comments>http://www.orablogger.com/2010/07/oracle10gr2-%e4%b8%ad%e7%9a%84restore-point/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 08:04:41 +0000</pubDate>
		<dc:creator>happydba</dc:creator>
				<category><![CDATA[备份与恢复]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[RESTORE POINT]]></category>

		<guid isPermaLink="false">http://www.orablogger.com/?p=463</guid>
		<description><![CDATA[RESTORE POINT 还原点是10GR2新增加的一个功能,它是建立在数据库层面上的, 跟savepoint不同. 必须在数据库处于ARCHIVELOG模式下才可以使用,主题思想是在数据库的某个时间点创建一个restore point,在随后的某个时间点可以将表或数据库falshback 到这个restore point.那么能否真正的完成flashback,依赖于创建的restore point类型和flashback要操作的对象.flashback database需要SYSDBA权限,flashback table需要 FLASHBACK ANY TABLE的权限. guarantee restore point for flashback database guarantee restore point必须在数据库处于flashback on 的状态下，才可以定义的一中restore point,它的主题思想是保证数据库能够准确完整的flashback 到定义的 restore point. 操作依赖于flashback log和archivelog, 如果定义了guarantee restore point,那么flashback logs将不受db_recovery_retention_target参数的限制,oracle不会删除flashback log,只要flashback arae有足够的磁盘空间,oracle就会保存足够的flashback logs,满足flashback database to restore point. 如果数据库没有处于flashback on,那么定义一个guarantee restore point必须在database mount状态下进行.其实这个也可以理解,oracle根据定义的restore point,可以个保证database open后的归档可以不被删除.但有一点必须明确的是,guarantee restore point是针对flashback database而言的,不对flashback table起作用，为什么呢, 因为flashback table依赖于undo,如果在guarantee时间范围内,undo过期了, [...]]]></description>
			<content:encoded><![CDATA[<p>RESTORE POINT</p>
<p>还原点是10GR2新增加的一个功能,它是建立在数据库层面上的, 跟savepoint不同. 必须在数据库处于ARCHIVELOG模式下才可以使用,主题思想是在数据库的某个时间点创建一个restore point,在随后的某个时间点可以将表或数据库falshback 到这个restore point.那么能否真正的完成flashback,依赖于创建的restore point类型和flashback要操作的对象.flashback database需要SYSDBA权限,flashback table需要 FLASHBACK ANY TABLE的权限.<br />
<span id="more-463"></span><br />
guarantee restore point for flashback database</p>
<p>guarantee restore point必须在数据库处于flashback on 的状态下，才可以定义的一中restore point,它的主题思想是保证数据库能够准确完整的flashback 到定义的 restore point. 操作依赖于flashback log和archivelog, 如果定义了guarantee restore point,那么flashback logs将不受db_recovery_retention_target参数的限制,oracle不会删除flashback log,只要flashback arae有足够的磁盘空间,oracle就会保存足够的flashback logs,满足flashback database to restore point.</p>
<p>如果数据库没有处于flashback on,那么定义一个guarantee restore point必须在database mount状态下进行.其实这个也可以理解,oracle根据定义的restore point,可以个保证database open后的归档可以不被删除.但有一点必须明确的是,guarantee restore point是针对flashback database而言的,不对flashback table起作用，为什么呢, 因为flashback table依赖于undo,如果在guarantee时间范围内,undo过期了, 那么flatable table 还是不能还原到定义的guarantee restore point.</p>
<p>Normal restore point</p>
<p>普通的restore point 非常简单, 如果要flashback database,那么数据库必须处于flashback on 状态,但这个时候不一定可以flashback database到定义的restore point,oracle会根据db_recovery_retention_target自动维护创建的restore ponit和flashback logs,如果超过db_recovery_retention_target 定义的restore point,oracle会自动删除 , 无论是flashback table或者flashback database都不能完成.</p>
<p>简单的流水帐记录,为了试自己更加明确restore point的原理.</p>
<p>创建一个guarantee restore point</p>
<p>SQL&gt; create restore point a guarantee flashback database;<br />
创建一个普通的restore point</p>
<p>SQL&gt; create restore point b;<br />
flashback dtaase to restore point:(必须在guarantee restore point for flashback database的情况)</p>
<p>SQL&gt; startup mount<br />
ORACLE instance started.</p>
<p>Total System Global Area 209715200 bytes</p>
<p>Fixed Size 1266632 bytes</p>
<p>Variable Size 134220856 bytes</p>
<p>Database Buffers 71303168 bytes</p>
<p>Redo Buffers 2924544 bytes</p>
<p>Database mounted.</p>
<p>SQL&gt; flashback database to restore point a;</p>
<p>Flashback complete.</p>
<p>SQL&gt; alter database open resetlogs;</p>
<p>Database altered.</p>
<p>falshback table</p>
<p>SQL&gt; alter table test_histogram enable row movement;</p>
<p>Table altered.</p>
<p>SQL&gt; flashback table test_histogram to restore point a;</p>
<p>Flashback complete.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.orablogger.com/2010/07/oracle10gr2-%e4%b8%ad%e7%9a%84restore-point/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>man vmstat on HP-UX</title>
		<link>http://www.orablogger.com/2010/06/man-vmstat-on-hp-ux/</link>
		<comments>http://www.orablogger.com/2010/06/man-vmstat-on-hp-ux/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 14:25:35 +0000</pubDate>
		<dc:creator>happydba</dc:creator>
				<category><![CDATA[hp-ux]]></category>
		<category><![CDATA[vmstat]]></category>

		<guid isPermaLink="false">http://www.orablogger.com/?p=461</guid>
		<description><![CDATA[        vmstat &#8211; report virtual memory statistics  SYNOPSIS       vmstat [-dnS] [interval [count]]       vmstat -f &#124; -s &#124; -z  DESCRIPTION       The vmstat command reports certain statistics kept about process,       virtual memory, trap, and CPU activity.  It also can clear the       accumulators in the kernel sum structure.]]></description>
			<content:encoded><![CDATA[<p> <br />
      vmstat &#8211; report virtual memory statistics</p>
<p><span id="more-461"></span><br />
 SYNOPSIS</p>
<p>      vmstat [-dnS] [interval [count]]</p>
<p>      vmstat -f | -s | -z</p>
<p> DESCRIPTION</p>
<p>      The vmstat command reports certain statistics kept about process,</p>
<p>      virtual memory, trap, and CPU activity.  It also can clear the</p>
<p>      accumulators in the kernel sum structure.<br />
<!--more><br />
    Options</p>
<p>      vmstat recognizes the following options:</p>
<p>           -d        Report disk transfer information as a separate section,</p>
<p>                     in the form of transfers per second. <strong>(</strong><strong>增加显示每个磁盘的每秒传输率)</strong></p>
<p>           -n        Provide an output format that is more easily viewed on</p>
<p>                     an 80-column display device.  This format separates the</p>
<p>                     default output into two groups: virtual memory</p>
<p>                     information and CPU data.  Each group is displayed as a</p>
<p>                     separate line of output.  On multiprocessor systems,</p>
<p>                     this display format also provides CPU utilization on a</p>
<p>                     per CPU basis for the active processors.</p>
<p>【<strong> -n </strong><strong>以80</strong><strong>列显示模式，分两部分显示：vm</strong><strong>信息和每个cpu</strong><strong>数据，如下：</strong></p>
<p>&gt;vmstat -n 3 2                                                                                                                                           </p>
<p><strong>VM</strong></p>
<p>       memory                     page                          faults</p>
<p>     avm    free   re   at    pi   po    fr   de    sr     in     sy    cs </p>
<p> 3178506  994304    0    0     3    0     0    0     0   6294  56247  2062</p>
<p><strong>CPU</strong></p>
<p>    cpu          procs</p>
<p> us sy id    r     b     w</p>
<p>  4  1 95    3     0     0</p>
<p>  4  1 95</p>
<p>  4  2 95</p>
<p>  4  2 95</p>
<p>】</p>
<p>           -S        Report the number of processes swapped in and out (si</p>
<p>                     and so) instead of page reclaims and address</p>
<p>                     translation faults (re and at).</p>
<p>【- <strong>S </strong><strong>报告si/so</strong><strong>信息，而不是re/at</strong><strong>信息</strong></p>
<p>&gt;vmstat -S</p>
<p>         procs           memory                   page                              faults       cpu</p>
<p>    r     b     w      avm    free   si   so    pi   po    fr   de    sr     in     sy    cs  us sy id</p>
<p>1     0     0  3159434  1005232    0    0     3    0     0    0     0   6294  56249  2063   2  1 97</p>
<p>】</p>
<p>           interval  Display successive lines which are summaries over the</p>
<p>                     last interval seconds.  The first line reported is for</p>
<p>                     the time since a reboot and each subsequent line is for</p>
<p>                     the last interval only.  If interval is zero, the</p>
<p>                     output is displayed once only.  If the -d option is</p>
<p>                     specified, the column headers are repeated.  If -d is</p>
<p>                     omitted, the column headers are not repeated.</p>
<p>                     The command vmstat 5 prints what the system is doing</p>
<p>                     every five seconds.  This is a good choice of printing</p>
<p>                     interval since this is how often some of the statistics</p>
<p>                     are sampled in the system; others vary every second.</p>
<p>           count     Repeat the summary statistics count times.  If count is</p>
<p>                     omitted or zero, the output is repeated until an</p>
<p>                     interrupt or quit signal is received.  From the</p>
<p>                     terminal, these are commonly ^C and ^\, respectively</p>
<p>                     (see stty(1)).</p>
<p>           -f        Report on the number of forks and the number of pages</p>
<p>                     of virtual memory involved since boot-up.</p>
<p>【&gt;vmstat -f</p>
<p>68092569 forks, 4170099806676 pages, average=  61241.63 】</p>
<p>           -s        Print the total number of several kinds of paging-</p>
<p>                     related events from the kernel sum structure that have</p>
<p>                     occurred since boot-up or since vmstat was last</p>
<p>                     executed with the -z option.</p>
<p>【&gt;vmstat <strong>–s </strong><strong>自系统启动以来的累积paging</strong><strong>信息，-z</strong><strong>是自上次vmstat</strong><strong>执行以来的累积信息</strong></p>
<p>0 swap ins</p>
<p>0 swap outs</p>
<p>0 pages swapped in</p>
<p>0 pages swapped out</p>
<p>6274277458 total address trans. faults taken</p>
<p>1829303083 page ins</p>
<p>334 page outs</p>
<p>29737060 pages paged in</p>
<p>231 pages paged out</p>
<p>4607410940 reclaims from free list</p>
<p>0 total page reclaims</p>
<p>98789 intransit blocking page faults</p>
<p>2838038078424 zero fill pages created</p>
<p>9126773909 zero fill page faults</p>
<p>82503219875 executable fill pages created</p>
<p>15320876 executable fill page faults</p>
<p>0 swap text pages found in free list</p>
<p>0 inode text pages found in free list</p>
<p>167 revolutions of the clock hand</p>
<p>4347065 pages scanned for page out</p>
<p>2708823 pages freed by the clock daemon</p>
<p>17034954764 cpu context switches</p>
<p>53631522710 device interrupts</p>
<p>8334721720 traps</p>
<p>464471608504 system calls</p>
<p>654638208 Page Select Size Successes for Page size 4K</p>
<p>722151587 Page Select Size Successes for Page size 8K</p>
<p>1500141225 Page Select Size Successes for Page size 16K</p>
<p>292213775 Page Select Size Successes for Page size 64K</p>
<p>8210386 Page Select Size Successes for Page size 256K</p>
<p>5504193 Page Select Size Successes for Page size 1M</p>
<p>1168360 Page Select Size Successes for Page size 4M</p>
<p>761 Page Select Size Successes for Page size 16M</p>
<p>135 Page Select Size Successes for Page size 64M</p>
<p>1056 Page Select Size Successes for Page size 128M</p>
<p>654638208 Page Select Size Failures for Page size 8K</p>
<p>1215788126 Page Select Size Failures for Page size 16K</p>
<p>119694774 Page Select Size Failures for Page size 64K</p>
<p>19010270 Page Select Size Failures for Page size 256K</p>
<p>6761292 Page Select Size Failures for Page size 1M</p>
<p>5947041 Page Select Size Failures for Page size 4M</p>
<p>2984011 Page Select Size Failures for Page size 16M</p>
<p>2966867 Page Select Size Failures for Page size 64M</p>
<p>5934286 Page Select Size Failures for Page size 128M</p>
<p>1666451549 Page Allocate Successes for Page size 4K</p>
<p>626532779 Page Allocate Successes for Page size 8K</p>
<p>1352517747 Page Allocate Successes for Page size 16K</p>
<p>867564268 Page Allocate Successes for Page size 64K</p>
<p>8130004 Page Allocate Successes for Page size 256K</p>
<p>6106471 Page Allocate Successes for Page size 1M</p>
<p>2027256 Page Allocate Successes for Page size 4M</p>
<p>594 Page Allocate Successes for Page size 16M</p>
<p>1484 Page Allocate Successes for Page size 64M</p>
<p>480 Page Allocate Successes for Page size 128M</p>
<p>2761002041 Page Allocate Failures for Page size 4K</p>
<p>2264697395 Page Allocate Failures for Page size 8K</p>
<p>6114689303 Page Allocate Failures for Page size 16K</p>
<p>2149876393 Page Allocate Failures for Page size 64K</p>
<p>64214019 Page Allocate Failures for Page size 256K</p>
<p>86494940 Page Allocate Failures for Page size 1M</p>
<p>34049285 Page Allocate Failures for Page size 4M</p>
<p>354294 Page Allocate Failures for Page size 16M</p>
<p>6991 Page Allocate Failures for Page size 64M</p>
<p>78130 Page Allocate Failures for Page size 128M</p>
<p>10885603 Page Demotions for Page size 8K</p>
<p>3901281 Page Demotions for Page size 16K</p>
<p>599439 Page Demotions for Page size 64K</p>
<p>3739984 Page Demotions for Page size 256K</p>
<p>324867 Page Demotions for Page size 1M</p>
<p>1465 Page Demotions for Page size 4M</p>
<p>6 Page Demotions for Page size 16M</p>
<p>1 Page Demotions for Page size 64M</p>
<p>】</p>
<p>           -z        Clear all accumulators in the kernel sum structure.</p>
<p>                     This option is restricted to the super user.</p>
<p>      If none of these options is given, vmstat displays a one-line summary</p>
<p>      of the virtual memory activity since boot-up or since the -z option</p>
<p>      was last executed.</p>
<p>【<strong>只显示一行汇总信息</strong>】</p>
<p>    Column Descriptions</p>
<p>      The column headings and the meaning of each column are:</p>
<p>           procs       Information about numbers of processes in various</p>
<p>                       states.</p>
<p>                            r      In run queue  （在运行队列中）</p>
<p>                            b      Blocked for resources (I/O, paging, etc.) （<strong>因资源阻塞中，如等待</strong><strong>io</strong><strong>或者paging</strong><strong>等）</strong></p>
<p>                            w      Runnable or short sleeper (&lt; 20 secs) but</p>
<p>                                   swapped <strong>（可运行的或者sleep</strong><strong>小于20</strong><strong>秒的，但是被swap</strong><strong>的）</strong></p>
<p>           memory      Information about the usage of virtual and real</p>
<p>                       memory.  Virtual pages are considered active if they</p>
<p>                       belong to processes that are running or have run in</p>
<p>                       the last 20 seconds.</p>
<p>（包括虚拟内存和真实内存的使用情况，虚拟page考虑运行中的进程或者在最后20秒内运行的进程使用情况）</p>
<p>                            avm     Active virtual pages <strong>（活动的虚拟内存页）</strong></p>
<p>                            free    Size of the free list <strong>（free list</strong><strong>的size</strong><strong>）</strong></p>
<p>           page        Information about page faults and paging activity.</p>
<p>                       These are averaged each five seconds, and given in</p>
<p>                       units per second. <strong>（五秒内的平均值，每秒给出）</strong></p>
<p>                            re      Page reclaims (without -S)</p>
<p>                            at      Address translation faults (without -S)</p>
<p>                            si      <strong>Processes</strong> swapped in (with -S)  <strong>（swap-in</strong><strong>的进程数）</strong></p>
<p>                            so      Processes swapped out (with -S) <strong>（swap-out</strong><strong>的进程数）</strong></p>
<p>                            pi      Pages paged in   <strong>（换入的页数）</strong></p>
<p>                            po      Pages paged out  <strong>（换出的页数）</strong></p>
<p>                            fr      Pages freed per second <strong>（每秒释放的页数）</strong></p>
<p>                            de      Anticipated short term memory shortfall  （预期的短期内存差额）</p>
<p>                            sr      Pages scanned by clock algorithm, per <strong>（每秒scan</strong><strong>的页数）</strong></p>
<p>                                    second</p>
<p>           faults      Trap/interrupt rate averages per second over last 5</p>
<p>                       seconds.</p>
<p>                            in      Device interrupts per second (nonclock)</p>
<p>                            sy      System calls per second</p>
<p>                            cs      CPU context switch rate (switches/sec)</p>
<p>           cpu         Breakdown of percentage usage of CPU time for the</p>
<p>                       active processors</p>
<p>                            us      User time for normal and low priority</p>
<p>                                    processes</p>
<p>                            sy      System time</p>
<p>                            id      CPU idle</p>
<p> EXAMPLES</p>
<p>      The following examples show the output for various command options.</p>
<p>      For formatting purposes, some leading blanks have been deleted.</p>
<p>      1.   Display the default output.</p>
<p>      vmstat</p>
<p>                procs           memory                   page</p>
<p>                       faults       cpu</p>
<p>           r     b     w      avm    free   re   at    pi   po    fr   de    sr</p>
<p>                in     sy    cs  us sy id</p>
<p>           0     0     0     1158     511    0    0     0    0     0    0     0</p>
<p>               111     18     7   0  0 100</p>
<p>      2.   Add the disk tranfer information to the default output.</p>
<p>      vmstat -d</p>
<p>                procs           memory                   page</p>
<p>                       faults       cpu</p>
<p>           r     b     w      avm    free   re   at    pi   po    fr   de    sr</p>
<p>                in     sy    cs  us sy id</p>
<p>           0     0     0     1158     511    0    0     0    0     0    0     0</p>
<p>               111     18     7   0  0 100</p>
<p>           Disk Transfers</p>
<p>             device    xfer/sec</p>
<p>             c0t6d0        0</p>
<p>             c0t1d0        0</p>
<p>             c0t3d0        0</p>
<p>             c0t5d0        0</p>
<p>      3.   Display the default output in 80-column format.</p>
<p>      vmstat -n</p>
<p>           VM</p>
<p>               memory                     page                          faults</p>
<p>             avm    free   re   at    pi   po    fr   de    sr     in     sy    cs</p>
<p>            1158     430    0    0     0    0     0    0     0    111     18     7</p>
<p>           CPU</p>
<p>               cpu          procs</p>
<p>            us sy id    r     b     w</p>
<p>             0  0 100    0     0     0</p>
<p>      4.   Replace the page reclaims and address translation faults with</p>
<p>           process swapping in the default output.</p>
<p>      vmstat -S</p>
<p>                procs           memory                   page</p>
<p>                       faults       cpu</p>
<p>           r     b     w      avm    free   si   so    pi   po    fr   de    sr</p>
<p>                in     sy    cs  us sy id</p>
<p>           0     0     0     1158     430    0    0     0    0     0    0     0</p>
<p>               111     18     7   0  0 100</p>
<p>      5.   Display the default output twice at five-second intervals.  Note</p>
<p>           that the headers are not repeated.</p>
<p>      vmstat 5 2</p>
<p>                procs           memory                   page</p>
<p>                       faults       cpu</p>
<p>           r     b     w      avm    free   re   at    pi   po    fr   de    sr</p>
<p>                in     sy    cs  us sy id</p>
<p>           0     0     0     1158     456    0    0     0    0     0    0     0</p>
<p>               111     18     7   0  0 100</p>
<p>           0     0     0     1221     436    5    0     5    0     0    0     0</p>
<p>               108     65    18   0  1 99</p>
<p>      6.   Display the default output twice in 80-column format at five-</p>
<p>           second intervals.  Note that the headers are not repeated.</p>
<p>      vmstat -n 5 2</p>
<p>           VM</p>
<p>              memory                     page                          faults</p>
<p>            avm    free   re   at    pi   po    fr   de    sr     in     sy    cs</p>
<p>           1221     436    0    0     0    0     0    0     0    111     18     7</p>
<p>           CPU</p>
<p>               cpu          procs</p>
<p>            us sy id    r     b     w</p>
<p>             0  0 100    0     0     0</p>
<p>           1221     435    2    0     2    0     0    0     0    109     35    17</p>
<p>             0  1 99    0     0     0</p>
<p>      7.   Display the default output and disk transfers twice in 80-column</p>
<p>           format at five-second intervals.  Note that the headers are</p>
<p>           repeated.</p>
<p>      vmstat -dn 5 2</p>
<p>           VM</p>
<p>              memory                     page                          faults</p>
<p>            avm    free   re   at    pi   po    fr   de    sr     in     sy    cs</p>
<p>           1221     435    0    0     0    0     0    0     0    111     18     7</p>
<p>           CPU</p>
<p>               cpu          procs</p>
<p>            us sy id    r     b     w</p>
<p>             0  0 100    0     0     0</p>
<p>           Disk Transfers</p>
<p>             device    xfer/sec</p>
<p>             c0t6d0        0</p>
<p>             c0t1d0        0</p>
<p>             c0t3d0        0</p>
<p>             c0t5d0        0</p>
<p>           VM</p>
<p>              memory                     page                          faults</p>
<p>            avm    free   re   at    pi   po    fr   de    sr     in     sy    cs</p>
<p>           1219     425    0    0     0    0     0    0     0    111     54    15</p>
<p>           CPU</p>
<p>               cpu          procs</p>
<p>            us sy id    r     b     w</p>
<p>             1  8 92    0     0     0</p>
<p>           Disk Transfers</p>
<p>             device    xfer/sec</p>
<p>             c0t6d0        0</p>
<p>             c0t1d0        0</p>
<p>             c0t3d0        0</p>
<p>             c0t5d0        0</p>
<p>      8.   Display the number of forks and pages of virtual memory since</p>
<p>           boot-up.</p>
<p>      vmstat -f</p>
<p>           24558 forks, 1471595 pages, average=  59.92</p>
<p>      9.   Display the counts of paging-related events.</p>
<p>      vmstat -s</p>
<p>           0 swap ins</p>
<p>           0 swap outs</p>
<p>           0 pages swapped in</p>
<p>           0 pages swapped out</p>
<p>           1344563 total address trans. faults taken</p>
<p>           542093 page ins</p>
<p>           2185 page outs</p>
<p>           602573 pages paged in</p>
<p>           4346 pages paged out</p>
<p>           482343 reclaims from free list</p>
<p>           504621 total page reclaims</p>
<p>           124 intransit blocking page faults</p>
<p>           1460755 zero fill pages created</p>
<p>           404137 zero fill page faults</p>
<p>           366022 executable fill pages created</p>
<p>           71578 executable fill page faults</p>
<p>           0 swap text pages found in free list</p>
<p>           162043 inode text pages found in free list</p>
<p>           196 revolutions of the clock hand</p>
<p>           45732 pages scanned for page out</p>
<p>           4859 pages freed by the clock daemon</p>
<p>           36680636 cpu context switches</p>
<p>           1497746186 device interrupts</p>
<p>           1835626 traps</p>
<p>           87434493 system calls</p>
<p> WARNINGS</p>
<p>      Users of vmstat must not rely on the exact field widths and spacing of</p>
<p>      its output, as these will vary depending on the system, the release of</p>
<p>      HP-UX, and the data to be displayed.</p>
<p> AUTHOR</p>
<p>      vmstat was developed by the University of California, Berkeley and HP.</p>
<p> SEE ALSO</p>
<p>      iostat(1).</p>
<p> Hewlett-Packard Company            &#8211; 6 -       HP-UX 11i Version 3 Feb 2007</p>
]]></content:encoded>
			<wfw:commentRss>http://www.orablogger.com/2010/06/man-vmstat-on-hp-ux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 4.954 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-05-21 08:30:12 -->

