session跟踪失效的问题和分析(57天)

最近碰到一个奇怪的问题,在生产和其他比较正式的环境中进行sql trace都没问题,但就是测试环境的数据库不知道怎么的, 设置sql_trace,开启诊断事件,dbms_system,dbms_monitor都试了,就是没有trace日志,我都怀疑是不是有些配置给禁用了。

查看基本的参数设置,没有发现什么问题。

SQL> show parameter statis
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
optimizer_use_pending_statistics     boolean     FALSE
statistics_level                     string      TYPICAL
timed_os_statistics                  integer     0
timed_statistics                     boolean     TRUE

下午不甘心,还是测试了一把,还是没有日志。不过最终发现了问题。 得到当前的session

SQL> select sid,serial# from v$session where sid=174;
       SID    SERIAL# 
---------- ---------- 
       174        571

然后在另外一个session中开启trace

SQL> exec dbms_system.SET_SQL_TRACE_IN_SESSION(174,571,true);
PL/SQL procedure successfully completed.

查看系统级对应的process id,是8790

SQL> select spid,username,pid from v$process where addr=(select paddr from v$session where sid=174 and serial#=571);
SPID                     USERNAME               PID
------------------------ --------------- ----------
8790                     oracle                  20

我也不指望它生成日志了,看看process > ps -ef|grep 8790 oracle 8790 1 0 06:07 ? 00:01:34 ora_d003_TESTABP4 oracle 25499 23099 0 13:53 pts/3 00:00:00 grep -i 8790 发现这个进程是一个共享服务进程。 再次查看session的情况,确实是。

SQL> select sid,serial#,server from v$session where sid=174;

SID SERIAL# SERVER ---------- ---------- --------------------------- 174 571 SHARED 看看当前的session server情况 SQL> select server,count(*)from v$session group by server;

SERVER COUNT(*) --------------------------- ---------- DEDICATED 25 NONE 493 SHARED 2 有些session的server状态时none,有些是shared,有些事dedicated.如果是none说明当前没有共享服务进程来服务了。如果是shared说明还有共享服务进程,正在使用共享连接。 关于共享进程对应的user可以看到更多的信息,sys对应的都是dedicated的session,其他的用户连进来都是使用共享服务进程。

SQL> select username,server from v$session group by username,server;
USERNAME                       SERVER
------------------------------ ---------
                               DEDICATED
N1                             NONE
SYS                            DEDICATED
TESTDB4                         NONE
TESTDB7                         NONE
TESTDB7                         SHARED
TESTDB8                         NONE
TESTDB15                        NONE
TESTDB21                        NONE
TESTDB23                        NONE
TESTDB24                        NONE
TESTDB26                        NONE
TESTDB37                        NONE
TESTDBO26                       NONE

查看共享服务的配置,可以看到设置了5个dispatcher

SQL> show parameter dispatchers
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
dispatchers                          string      (DESCRIPTION=(SDU=2048) (ADDRE
                                                 SS=(PARTIAL=TESTE)(PROTOCOL=TCP
                                                 )(HOST=indlin224))) (DISPATCHE
                                                 RS=5)
max_dispatchers                      integer     20
SQL> show parameter servers
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
max_shared_servers                   integer     100
parallel_max_servers                 integer     10
parallel_min_servers                 integer     2
parallel_servers_target              integer     192
shared_servers                       integer     20

查看监听器的情况,可以看到共享服务的分发器有5个,从D000到D004。

> lsnrctl service indlin224
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 28-APR-2014 14:22:01
Copyright (c) 1991, 2010, Oracle.  All rights reserved.
Connecting to (address=(protocol=tcp)(host=indlin224)(port=1521))
Services Summary...
Service "TESTABP4" has 1 instance(s).
  Instance "TESTABP4", status READY, has 6 handler(s) for this service...
    Handler(s):
      "D004" established:3003 refused:0 current:127 max:1022 state:ready
         DISPATCHER <machine: indlin224, pid: 8792>
         (ADDRESS=(PROTOCOL=tcp)(HOST=indlin224)(PORT=28961))
      "D003" established:3097 refused:0 current:114 max:1022 state:ready
         DISPATCHER <machine: indlin224, pid: 8790>
         (ADDRESS=(PROTOCOL=tcp)(HOST=indlin224)(PORT=57578))
      "D002" established:3566 refused:0 current:114 max:1022 state:ready
         DISPATCHER <machine: indlin224, pid: 8788>
         (ADDRESS=(PROTOCOL=tcp)(HOST=indlin224)(PORT=47939))
      "D001" established:3857 refused:0 current:114 max:1022 state:ready
         DISPATCHER <machine: indlin224, pid: 8786>
         (ADDRESS=(PROTOCOL=tcp)(HOST=indlin224)(PORT=37229))
      "D000" established:3118 refused:0 current:113 max:1022 state:ready
         DISPATCHER <machine: indlin224, pid: 8784>
         (ADDRESS=(PROTOCOL=tcp)(HOST=indlin224)(PORT=18463))
      "DEDICATED" established:0 refused:0 state:ready
      ......
         LOCAL SERVER
The command completed successfully

监听的配置就是简单的一句话

indlin224= (address_list= (address= (protocol=tcp) (host=indlin224) (port=1521))) 可以通过v$process来关联查询每个session对应的process program情况

SQL>   select sid,serial#,server from v$session where sid=(select sid from v$mystat where rownum<2);
       SID    SERIAL# SERVER
---------- ---------- ---------
       163        697 SHARED
 
SQL> select spid,pid,program from v$process where addr=(select paddr from v$session where sid=163 and serial#=697);       
SPID                            PID PROGRAM
------------------------ ---------- ------------------------------------------------
8798                             24 oracle@indlin224 (S002)

共享服务的部分点到为止,来看和做trace的关系。 如果稍微等一会,通过两外一个session来查询session 8796的process情况,就发现进程编程了D001. SPID USERNAME PROGRAM ------------------------ --------------- ------------------------------------------------ 8786 oracle oracle@indlin224 (D001) 查看对应的session server情况,就从shared变成了none

SQL> select sid,serial#,server from v$session where sid=2947 and serial#=2427
  2  /
       SID    SERIAL# SERVER
---------- ---------- ---------
      2947       2427 NONE

讨论了这么多共享服务器的东西,那么话说过来,能不能对这类session做trace呢。甚至pl/sql在共享服务模式下是否也能够做trace. oracle给出的解释如下。

How to Use PL/SQL Tracing with Multi-Threaded Server (MTS) (Doc ID 238935.1) PL/SQL tracing cannot be used with the multi-threaded server (MTS).

Oracle trace files are opened at the process level, not the session level.

If SQL_TRACE is turned on while running MTS, trace information for more than just your user session will be seen because MTS allows many user processes to share very few server processes.

By turning on SQL_TRACE in MTS mode, all user sessions that are currently sharing the same shared server process will be traced. The output from sessions using MTS, XA or Oracle8 OCI may be spread across several trace files making it very difficult to interpret.

So, if performance tuning is being done and SQL_TRACE needs to be turned on, a dedicated connection must be used. In other words, if possible run the session to be traced using a DEDICATED connection or do not use an MTS (Multi-threaded Server) connection.

原文发布于微信公众号 - 杨建荣的学习笔记(jianrong-notes)

原文发表时间:2014-04-29

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Bug生活2048

Spring Boot学习笔记(五)整合MyBatis实现数据库访问

这里主要依赖两个,一个是连接MySql的`mysql-connector-java`,还一个是SpringBoot整合MyBatis的核心依赖`mybatis-...

492
来自专栏乐沙弥的世界

配置非默认端口的动态服务注册

从Oracle客户端连接到服务器,除了使用静态注册方式之外,9i后续的版本支持动态注册服务,同时可以将服务注册到非默认的端口。将服务注册到非默认端口可以提高数...

601
来自专栏数据和云

【云端起舞】在Oracle公有云上创建克隆数据库

作者简介: Joel Perez Oracle ACE总监, Maximum Availability OCM,OTN 专家,全球第一批ACE称号获得者,...

29311
来自专栏Laoqi's Linux运维专列

k8s集群运维篇–kubectl常用命令

6054
来自专栏k8s

k8s使用nfs存储

源项目地址https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-cl...

2593
来自专栏逸鹏说道

SQLServer 数据库镜像+复制切换方案

目标: 主机做了Mirror和Replication,当主机出现问题时,Replication和Mirror实现自动的故障转移(Mirror 和Re...

27611
来自专栏杨建荣的学习笔记

11g dataguard使用总结(r5笔记第12天)

11g的dataguard相比于10g来说,最优越的特性应该算就是active dataguard了,这一点改进在很大意义上促使用户需要把数据库从10g升级到1...

2476
来自专栏杨建荣的学习笔记

一天内碰到的3个rac节点问题 (r6笔记第36天)

说到问题,真是层出不穷,自己也算搭建了也不少的rac环境的,但是在本地试验的时候总是会碰到一些问题,昨晚铲掉旧环境,搭建了两遍rac环境,终于在凌晨搭建好了环境...

3117
来自专栏鬼谷君

13-部署traefik-ingress插件

1465
来自专栏Laoqi's Linux运维专列

Kubernetes 1.8.6 集群部署–微服务持续集成→发布,拒绝停服(十五)

1624

扫描关注云+社区