数据库锁定Contention是我们在实际中经常遇到的问题。严重的Contention可能会引起整体数据库性能衰减,乃至连接失败。实际生产如果出现Contention,通常是比较紧急的情况,快速定位错误问题,解决问题是运维人员的挑战。
Contention出现的原因很多,但总的来说有两个大的类型,一个是数据库本身后台进程之间协调故障,另一个是应用程序或者用户操作导致的等待锁定。前者通常是由于Oracle Bug引起的,后者是由于不成熟的设计开发引起的。
Contention锁定通常是进程之间的关系,所以解决问题的通法常常是利用oradebug和操作系统本身携带的Trace监控工具。对初学者而言,在紧急情况下使用这些工具常常是比较困难的。所以,Oracle推出了Procwatcher工具脚本,来进行统一的锁定分析工作。
Procwatcher可以从MOS官方网站进行下载,对应的文档ID为:459694.1。本篇主要介绍Procwatcher工具安装和使用。
1、环境介绍
我们使用的操作系统环境是Red Hat Linux 6.5。
[root@SimpleLinux /]# uname -r
2.6.32-431.el6.i686
2、Procwatcher安装配置
从MOS上下载的脚本是一个zip包,笔者版本为:prw_12.1.13.11.1.zip。在Linux中,创建专门目录进行上传。
[root@SimpleLinux ~]# cd /
[root@SimpleLinux /]# mkdir prw
[root@SimpleLinux /]# chown oracle:oinstall prw
[root@SimpleLinux /]# ls -l | grep prw
drwxr-xr-x. 2 oracle oinstall 4096 Apr 30 09:12 prw
使用sftp客户端上传zip包。
[root@SimpleLinux prw]# ls -l
total 36
-rw-r--r--. 1 root root 36203 Apr 30 09:16 prw_12.1.13.11.1.zip
[root@SimpleLinux prw]# unzip prw_12.1.13.11.1.zip
Archive: prw_12.1.13.11.1.zip
inflating: prw.sh
[root@SimpleLinux prw]# ls -l
total 220
-rw-r--r--. 1 root root 36203 Apr 30 09:16 prw_12.1.13.11.1.zip
-rwxr-xr-x. 1 root root 187245 Nov 26 23:12 prw.sh
[root@SimpleLinux prw]# chown oracle:oinstall *
[root@SimpleLinux prw]# ls -l
total 220
-rw-r--r--. 1 oracle oinstall 36203 Apr 30 09:16 prw_12.1.13.11.1.zip
-rwxr-xr-x. 1 oracle oinstall 187245 Nov 26 23:12 prw.sh
prw.sh就是工具的唯一实体,可以执行脚本来进行操作。
使用Procwatcher是需要操作系统环境检查,首先要求执行用户PATH中包括/usr/bin和/bin目录。
[oracle@SimpleLinux ~]$ env | grep PATH
PATH=/usr/lib/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/bin:/u01/app/oracle/bin
MODULEPATH=/usr/share/Modules/modulefiles:/etc/modulefiles
环境变量中包括标准的$ORACLE_系列。
[oracle@SimpleLinux ~]$ env | grep ORA
ORACLE_SID=ora11g
ORACLE_BASE=/u01/app
ORACLE_HOME=/u01/app/oracle
执行用户要求是Oracle owner用户。如果是cluster(RAC)或者多个oracle user的情况,可以使用root来执行。
操作系统中必须包括系统调试工具。列表如下:
Linux - /usr/bin/gdb
HP-UX and HP Itanium - /opt/langtools/bin/gdb64 or /usr/ccs/bin/gdb64
Sun - /usr/bin/pstack
IBM AIX - /bin/procstack or /bin/dbx
HP Tru64 - /bin/ladebug
[oracle@SimpleLinux ~]$ rpm -qa | grep gdb
gdb-7.2-60.el6_4.1.i686
gdbm-1.8.0-36.el6.i686
eggdbus-0.6-3.el6.i686
gdbm-devel-1.8.0-36.el6.i686
执行脚本prw.sh,可以自动的进行进程级别的数据收集。可以调用参数help来进行帮助信息。
[oracle@SimpleLinux prw]$ ./prw.sh help
Usage: prw.sh
Verbs are:
start [all] - Start Procwatcher on local node, if 'all' is specified, start on all nodes
stop [all] - Stop Procwatcher on local node, if 'all' is specified, stop on all nodes
stat - Check the current status of Procwatcher
pack - Package up Procwatcher files (on all nodes) to upload to support
param - Check current Procwatcher parameters
log [number] - See the last [number] lines of the procwatcher log file
log [runtime] - See contiuous procwatcher log file info - use Cntrl-C to break
help - What you are looking at...
参数调用是比较简单的,通过帮助信息可以了解使用的方法。相对于oradebug和操作系统层面的调用,易用性要好得多。使用stat参数,可以来查看脚本当前运行情况。
[oracle@SimpleLinux prw]$ ./prw.sh stat
Wed Apr 30 09:25:46 CST 2014: PROCWATCHER VERSION: 12.1.13.11.1
Wed Apr 30 09:25:46 CST 2014: ### Parameters ###
Wed Apr 30 09:25:46 CST 2014: EXAMINE_CLUSTER=false
Wed Apr 30 09:25:46 CST 2014: EXAMINE_BG=true
Wed Apr 30 09:25:46 CST 2014: PRWPERM=777
Wed Apr 30 09:25:46 CST 2014: RETENTION=7
Wed Apr 30 09:25:46 CST 2014: WARNINGEMAIL=
Wed Apr 30 09:25:46 CST 2014: INTERVAL=60
Wed Apr 30 09:25:46 CST 2014: THROTTLE=5
Wed Apr 30 09:25:46 CST 2014: IDLECPU=3
Wed Apr 30 09:25:46 CST 2014: SIDLIST=
Wed Apr 30 09:25:46 CST 2014: ### Advanced Parameters (non-default) ###
Wed Apr 30 09:25:46 CST 2014: ### End Parameters ###
Wed Apr 30 09:25:46 CST 2014: Procwatcher is not running on local node SimpleLinux
Wed Apr 30 09:25:46 CST 2014: Procwatcher files are be written to: /prw
3、阻塞环境构建
我们在11gR2中,构建出一个阻塞的环境场景。从而使用Procwatcher的可用性。
SQL> select * from v$version;
BANNER
-----------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 – Production
构建实验数据表T。
SQL> create table t as select * from dba_objects where rownum<10;
Table created
当前命令行会话编号35,删除数据,但是不进行提交动作。
SQL> select sid from v$mystat where rownum<2;
SID
----------
35
SQL> delete t;
9 rows deleted
在另一个会话中,也删除相同数据。在Oracle环境下,第二个会话被阻塞。
SQL> select sid from v$mystat where rownum<2;
SID
----------
42
SQL> delete t;
(等待阻塞……)
此时,后台Server Process有三个。说明:笔者使用PL/SQL的Command Window进行测试,两个Command窗口,后台对应Server Process有三个。
[oracle@SimpleLinux PRW_SYS_SimpleLinux]$ ps -ef | grep LOCAL
oracle 1983 1 0 09:28 ? 00:00:00 oracleora11g (LOCAL=NO)
oracle 1988 1 0 09:29 ? 00:00:00 oracleora11g (LOCAL=NO)
oracle 2012 1 0 09:31 ? 00:00:00 oracleora11g (LOCAL=NO)
oracle 26625 1807 0 09:37 pts/0 00:00:00 grep LOCAL
下面我们实验用Procwatcher去诊断出进程的阻塞关系。
4、执行诊断过程
执行start参数,进行诊断。
[oracle@SimpleLinux prw]$ ./prw.sh start
Wed Apr 30 09:32:21 CST 2014: Starting Procwatcher
Wed Apr 30 09:32:21 CST 2014: Thank you for using Procwatcher. :-)
Wed Apr 30 09:32:21 CST 2014: Please add a comment to Oracle Support Note 459694.1
Wed Apr 30 09:32:21 CST 2014: if you have any comments, suggestions, or issues with this tool.
Procwatcher files will be written to: /prw
Wed Apr 30 09:32:21 CST 2014: Started Procwatcher
对应目录/prw中,就有诊断的结果显示。
[oracle@SimpleLinux prw]$ ls -l
total 232
-rw-r--r--. 1 oracle oinstall 36203 Apr 30 09:16 prw_12.1.13.11.1.zip
drwxrwxrwx. 2 oracle oinstall 4096 Apr 30 09:32 PRW_DB_ora11g –数据库诊断
-rwxr-xr-x. 1 oracle oinstall 187245 Nov 26 23:12 prw.sh
-rwxrwxrwx. 1 oracle oinstall 2917 Apr 30 09:32 prw_SimpleLinux.log –Procwatcher执行日志
drwxrwxrwx. 2 oracle oinstall 4096 Apr 30 09:32 PRW_SYS_SimpleLinux –中间过程操作系统层面结果
PRW_DB_ora11g中,显示了对ora11g的数据库实例诊断结果。
[oracle@SimpleLinux prw]$ cd PRW_DB_ora11g/
[oracle@SimpleLinux PRW_DB_ora11g]$ ls -l
total 72
-rwxrwxrwx. 1 oracle oinstall 2095 Apr 30 09:33 prw_ora_arc0_ora11g_1626_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 2095 Apr 30 09:33 prw_ora_arc1_ora11g_1629_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 2095 Apr 30 09:33 prw_ora_arc2_ora11g_1631_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 2095 Apr 30 09:33 prw_ora_arc3_ora11g_1633_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 2050 Apr 30 09:33 prw_ora_ckpt_ora11g_1604_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 2050 Apr 30 09:32 prw_ora_dbw0_ora11g_1600_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 3136 Apr 30 09:33 prw_ora_fg_ora11g_1988_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 6993 Apr 30 09:33 prw_ora_fg_ora11g_2012_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 2050 Apr 30 09:32 prw_ora_lgwr_ora11g_1602_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 2091 Apr 30 09:32 prw_ora_pmon_ora11g_1582_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 2050 Apr 30 09:33 prw_ora_rvwr_ora11g_1623_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 2065 Apr 30 09:33 prw_ora_smon_ora11g_1606_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 158 Apr 30 09:32 pw_latchholder_ora11g_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 583 Apr 30 09:32 pw_lock_ora11g_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 587 Apr 30 09:32 pw_sessionwait_ora11g_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 667 Apr 30 09:32 pw_sqltimings_ora11g_04-30-14.out
-rwxrwxrwx. 1 oracle oinstall 1616 Apr 30 09:32 pw_waitchains_ora11g_04-30-14.out
目录中所有的文件都是对特定实例后台进程的分析和dump结果。Procwather是一个综合性程序,如果存在ASM实例,或者诊断RAC环境,对每一个实例都会有专门的文件夹。
结果进程中包括三个类型结果:首先是核心后台进程解析,比如dbwr、pmon等关键进行的dump结果和跟踪结果。第二部分是特定后台Server Process分析。如果Procwather的确发现相互锁定的进程,会特意将这些进程信息导出。最后就是分析情况,会从latch、sessionwait、lock和SQL Timing等多个角度进行分析。从快速问题分析的角度看,最后一部分是比较重要的。
目录PRW_SYS_SIMPLELINUX中包括的就是分析过程中使用的脚本和中间结果文件。
[oracle@SimpleLinux prw]$ cd PRW_SYS_SimpleLinux/
[oracle@SimpleLinux PRW_SYS_SimpleLinux]$ ls -l
total 244
-rwxrwxrwx. 1 oracle oinstall 1 Apr 30 09:32 badsidlist
-rwxrwxrwx. 1 oracle oinstall 5 Apr 30 09:32 examinebg
-rwxrwxrwx. 1 oracle oinstall 3 Apr 30 09:33 idlecpu
-rwxrwxrwx. 1 oracle oinstall 6 Apr 30 09:32 israc_ora11g
-rwxrwxrwx. 1 oracle oinstall 10 Apr 30 09:33 lastvmstat
(篇幅原因,有省略……)
-rwxrwxrwx. 1 oracle oinstall 2 Apr 30 09:33 viewtype_ora11g
-rwxrwxrwx. 1 oracle oinstall 245 Apr 30 09:33 vmstat
下面我们对结果文件进行分析和解析。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17203031/viewspace-1152611/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/17203031/viewspace-1152611/