Procwatcher: Useful Script to Monitor Oracle Processes

也许总在某个时候,作为Oracle DBA的你心里会想,这进程到底在干什么呢?为什么占用这么高的CPU?为什么写这么多数据到磁盘上产生这么大的IO?

当然,我们有各种各样的诊断方法来确认这些进程在做什么,不过,也很有可能在初步的诊断之后,还是一无所获,这时候也许类似于oradebug short_stack这样的命令或者是操作系统级别的debug命令能够让我们在重重迷雾中找到一些指路的明灯。不能否认,在某些时候,只是灵光一闪,从某些特征上忽然醒悟了该从哪个方向入手,就能帮助我们最终解决问题。

这里介绍的Procwatcher是一个shell脚本,运行在UNIX/LINUX操作系统级别,帮助我们给指定的Oracle Clusterware后台进程(比如crsd.bin, evmd.bin等)以及Oracle RDBMS后台进程(比如dbwr, smon, pmon等)进行定期的debug跟踪,将收集的stack traces按照进程和日期存储在磁盘上。

不要期望能够完全看明白stack trace的内容,那些是给专业的Oracle Support人员看的,但是我们至少可以知道在一个进程非常缓慢或者非常忙碌的时候,它被hang在了什么地方,也许是一个类似于kslwait这样的函数,这些就是蛛丝马迹,可以通过这些关键字去Metalink中找寻更有价值的信息。或者把这些trace内容上传给Oracle Support人员,也对解决疑难问题有很大帮助。

此脚本的内部注释非常完整,基本上所有的帮助信息都可以从脚本注释中找到。

启动和关闭脚本的命令分别是:

./prw.sh start 
./prw.sh stop

注意点:
1. 获取stack trace通常会对被debug的进程有短暂的suspend操作,比如ocssd.bin如果被suspend过长(超过css misscount时间),则会导致节点被重启。可以修改脚本中的CRSPROCS参数,将不需要trace的进程去除。

2. 在AIX平台上慎用EXAMINE_CRS=true,也就是在AIX平台上最好不要用这个脚本去获取Oracle Clusterware后台进程的stack trace,可能造成程序被hang住。

3. 默认保留2天的trace记录,可以通过下面的语法修改为3天或者更多。

./prw.sh start 3

可以登录Metalink的朋友可以在Note:459694.1中下载该脚本。
没有Metalink帐号的朋友在这里下载脚本。

How to use query in EXPDP

在datapump export中Oracle提供了query参数,允许只导出满足query条件的记录。

在Oracle 10gR2的官方文档中,提到的语法是:

QUERY = [schema.][table_name:] query_clause

并且给出了例子:

QUERY=employees:'”WHERE department_id > 10 AND salary > 10000″‘

但是实际上这个例子是错误的,按照例子中的语法,则会碰到ORA-06502错误。

D:\Temp>type emp_query.par
QUERY=emp:'"WHERE rownum<4"'
NOLOGFILE=y
DIRECTORY=DATA_PUMP_DIR
DUMPFILE=exp1.dmp

D:\Temp>expdp scott/tiger parfile=emp_query.par

Export: Release 11.1.0.6.0 - Production on Thursday, 26 February, 2009 18:07:24

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Oracle Database Vault
and Real Application Testing options
Starting "SCOTT"."SYS_EXPORT_SCHEMA_01":  scott/******** parfile=emp_query.par
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 192 KB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/POST_SCHEMA/PROCACT_SCHEMA
. . exported "SCOTT"."DEPT"                              5.937 KB       4 rows
ORA-31693: Table data object "SCOTT"."EMP" failed to load/unload and is being skipped due to error:
ORA-06502: PL/SQL: numeric or value error
ORA-31605: the following was returned from LpxXSLSetTextVar in routine kuxslSetParam:
LPX-314: an internal failure occurred
. . exported "SCOTT"."SALGRADE"                          5.867 KB       5 rows
. . exported "SCOTT"."BONUS"                                 0 KB       0 rows
Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is:
  D:\ORACLE\ADMIN\ORCL11G\DPDUMP\EXP1.DMP
Job "SCOTT"."SYS_EXPORT_SCHEMA_01" completed with 1 error(s) at 18:08:04

这份文档错误在Oracle 11gR1的官方文档中已经修正了。正确的语法,是去除掉例子中query字串的前后单引号:QUERY=emp:”WHERE rownum<4"

D:\Temp>type emp_query.par
QUERY=emp:"WHERE rownum<4"
NOLOGFILE=y
DIRECTORY=DATA_PUMP_DIR
DUMPFILE=exp1.dmp

D:\Temp>expdp scott/tiger parfile=emp_query.par reuse_dumpfiles=y

Export: Release 11.1.0.6.0 - Production on Thursday, 26 February, 2009 18:16:59

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Oracle Database Vault
and Real Application Testing options
Starting "SCOTT"."SYS_EXPORT_SCHEMA_01":  scott/******** parfile=emp_query.par reuse_dumpfiles=y
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 192 KB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/POST_SCHEMA/PROCACT_SCHEMA
. . exported "SCOTT"."DEPT"                              5.937 KB       4 rows
. . exported "SCOTT"."EMP"                               8.125 KB       3 rows
. . exported "SCOTT"."SALGRADE"                          5.867 KB       5 rows
. . exported "SCOTT"."BONUS"                                 0 KB       0 rows
Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is:
  D:\ORACLE\ADMIN\ORCL11G\DPDUMP\EXP1.DMP
Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at 18:17:32

更详细的Query用法可以参看Metalink Note:277010.1。

Delete Expired VS. Delete Obsolete

今天有朋友问,到底RMAN里面的命令delete expired和delete obsolete有什么区别?

先来看一下官方文档中的解释。via Backup and Recovery User Guide

delete exipired

If you run CROSSCHECK, and if RMAN cannot locate the files, then it updates their records in the RMAN repository to EXPIRED status. You can then use the DELETE EXPIRED command to remove records of expired backups and copies from the RMAN repository.

delete obsolete

The RMAN DELETE command supports an OBSOLETE option, which deletes backups that are no longer needed to satisfy specified recoverability requirements. You can delete files obsolete according to the configured default retention policy, or another retention policy that you specify as an option to the DELETE OBSOLETE command. As with other forms of the DELETE command, the files deleted are removed from backup media, deleted from the recovery catalog, and marked as DELETED in the control file.

delete expired删除的是那些本来RMAN以为存在但是实际上在磁盘或者磁带上已经被删除了的信息,删除的只是RMAN资料库中的记录;delete obsolete则删除旧于备份保留策略定义的备份数据同时也更新RMAN资料库以及控制文件。

那么再形象一点儿解释的话,就是“在不在”和“要不要”的区别。expired是不在了,obsolete是不要了。

不在的并不一定是不需要的。
不需要的也不一定就不在了。

外一句:数据库管理的时候,痛苦的是不需要的还在,还占据着资源;比这更痛苦的是,需要的已经不在了,想恢复却找不到备份集。 😀