背景
熟悉PMON的含义及工作内容。
结论
1,pmon可以用10246 event进行跟踪PMON工作过程
2,pmon工作内容如下:
后经查询官方手册发现,PMON的工作内容如下:
1,监控后台进程运行状况
2,如果某些进程异常中断,PMON去释放会话资源以及占用的锁LOCK
3,更新事务表的标志以及清除事务XID的标记
4,清除异常中断会话在BUFFER CACHE占用的缓存
5,PMON也负责定期把数据库实例注册到监听器中
3,10246 EVENT产生的TRACE FILE分析摘录
--PMON接到通知
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksl2.h LINE:2160 ID:kslges, process=6c, post_num=5
*** 2015-11-01 21:49:30.646
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksl2.h LINE:2160 ID:kslges, process=39, post_num=6
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12751 ID:ksupsc, process=b8, post_num=7
*** 2015-11-01 22:03:02.812
deleting session 0xdc97f1b0 sid=201 serial=188 --PMON发现上述测试会话被人为KILL
*** 2015-11-01 22:03:03.382
deletion of killed session 0xdc97f1b0 successful
--这里就是ORACLE内核代码负责清理被KILL会话占用的资源
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12737 ID:ksuabt, process=0, post_num=8
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=9
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=10
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=11
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=12
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=13
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=14
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=15
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=16
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=17
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=18
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=19
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=20
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=21
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=22
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=23
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=24
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=25
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=26
PMON ignoring post from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2
*** 2015-11-01 22:03:06.428
marked process 0xdd6589c0 pid=184 serial=2 ospid = 11635 dead --PMON清理完被KILL后,标记为DEAD
*** 2015-11-01 22:03:06.446
deleting process 0xdd6589c0 pid=184 serial=2 priority=0 --然后删除这个会话对应的操作系统进程资源
deletion of process dd6589c0 pid=184 seq=2 successful
测试
1,数据库版本
SQL> select * from v$version where rownum=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
2,跟踪pmon
SQL> alter session set tracefile_identifier='pmon_test1';
Session altered.
SQL> alter system set events='10246 trace name context forever,level 1';
System altered.
3,用户测试会话
SQL> select sid from v$mystat where rownum=1;
SID
----------
201
SQL> select sid,serial# from v$session where sid=201;
SID SERIAL#
---------- ----------
201 188
SQL> create table t_pmon(a int,b int);
Table created.
SQL> insert into t_pmon select level,level from dual connect by level<=1000000;
insert into t_pmon select level,level from dual connect by level<=1000000
*
ERROR at line 1:
ORA-00028: your session has been killed
ORA-00028: your session has been killed
--另启会话杀掉正在插入记录的上述测试会话
SQL> alter system kill session '201,188';
System altered.
3,关闭pmon跟踪
SQL> alter system set events='10246 trace name context off';
System altered.
4,查看pmon的TRACE FILE
--PMON接到通知
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksl2.h LINE:2160 ID:kslges, process=6c, post_num=5
*** 2015-11-01 21:49:30.646
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksl2.h LINE:2160 ID:kslges, process=39, post_num=6
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12751 ID:ksupsc, process=b8, post_num=7
*** 2015-11-01 22:03:02.812
deleting session 0xdc97f1b0 sid=201 serial=188 --PMON发现上述测试会话被人为KILL
*** 2015-11-01 22:03:03.382
deletion of killed session 0xdc97f1b0 successful
--这里就是ORACLE内核代码负责清理被KILL会话占用的资源
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12737 ID:ksuabt, process=0, post_num=8
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=9
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=10
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=11
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=12
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=13
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=14
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=15
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=16
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=17
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=18
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=19
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=20
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=21
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=22
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=23
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=24
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=25
PMON posted from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2, post_num=26
PMON ignoring post from location=FILE:/ade/b/1640894963/oracle/rdbms/src/hdir/ksu.h LINE:12763 ID:ksuxfd, process=2
*** 2015-11-01 22:03:06.428
marked process 0xdd6589c0 pid=184 serial=2 ospid = 11635 dead --PMON清理完被KILL后,标记为DEAD
*** 2015-11-01 22:03:06.446
deleting process 0xdd6589c0 pid=184 serial=2 priority=0 --然后删除这个会话对应的操作系统进程资源
deletion of process dd6589c0 pid=184 seq=2 successful
继续测试,如果我们让PMON阻塞,再手工KILL测试会话会如何呢
SQL> select pid,spid from v$process where pname='PMON';
PID SPID
---------- ------------------------------------------------
2 10556
SQL> oradebug setospid 10556
Oracle pid: 2, Unix process pid: 10556, image: oracle@seconary (PMON)
SQL> oradebug suspend
Statement processed.
没看到任何有价值的内容
换个思路,如果阻塞PMON,事务提交会不会正常进行呢
SQL> oradebug setospid 10556
Oracle pid: 2, Unix process pid: 10556, image: oracle@seconary (PMON)
SQL> oradebug suspend
Statement processed.
可见事务提交不受影响
SQL> update t_pmon set a=111 where a=1;
1 row updated.
SQL> commit;
Commit complete.
后经查询官方手册发现,PMON的工作内容如下:
1,监控后台进程运行状况
2,如果某些进程异常中断,PMON去释放会话资源以及占用的锁LOCK
3,更新事务表的标志以及清除事务XID的标记
4,清除异常中断会话在BUFFER CACHE占用的缓存
5,PMON也负责定期把数据库实例注册到监听器中