会话的属性以及组建级别和客户端级别的SQL语句跟踪
来源:互联网 发布:华为交换机端口trunk 编辑:程序博客网 时间:2024/06/08 18:11
会话的四个属性就是四个变量,用于描述该会话的。用于区分与其他会话?不同会话的属性值可以完全一样的,因为属性值都是人为随意加的。 会话的属性表现在v$session视图里有module和action两个字段。
会话的四个属性就是四个变量,用于描述该会话的。用于区分与其他会话?不同会话的属性值可以完全一样的,因为属性值都是人为随意加的。
V$SESSION
MODULE
Foot 1 VARCHAR2(48)
Name of the currently executing module as set by calling theDBMS_APPLICATION_INFO.SET_MODULE
procedureACTION
Footref 1VARCHAR2(32)
Name of the currently executing action as set by calling theDBMS_APPLICATION_INFO.SET_ACTION
proceduremodule 即模块或说是组件,例如sqlplus.exe和sqldeveloperw.exe等客户端。
要建立一个会话,就需要借助一个客户端软件来连接到服务端,这样就形成了一条服务端的服务器进程和客户端的客户进程间的连线。(客户端要连接到服务端,就需要接受服务端的验证,故在客户端发出连接请求时(或前)要发出用户名和密码等信息来验证通过,通过才能连接成功)连接成功后,就会在服务端的内存上开辟一块区域,即就是会话区域,来记录一些该会话时操作的信息等,该会话可以通过服务器进程和客户端进程间的这条连线向客户端的操作用户(人)发送一些信息,如SQL语句执行的结果集等,客户端的操作用户也可以通过该条连线向会话(区域)发送如执行某个SQL语句的请求等信息。会话也可以是无存在连接的会话,例如并行操作时的并行服务器进程(不是协调者进程)对应有一个自己的会话,但是该并行服务器进程没有与客户端形成一条连接,所以称它的会话为无连接的会话。一个服务端的服务器进程可以有多个自己的会话,如在一个会话窗口中开启set autotrace on功能时,就会为该会话的服务器进程开启(开辟出)一块会话区域。
注释:
1、连接和会话的区别
连接(connection):连接是从客户到Oracle 实例的一条物理路径。连接可以在网络上建立,或者通过IPC 机制建立。通常会在客户进程与一个专用服务器或一个调度器之间建立连接。
会话(session):会话是实例中存在的一个逻辑实体。这就是你的会话状态(session state),也就是表示特定会话的一组内存中的数据结构.也就说,会话就是一块内存区域。提到"数据库连接"时,大多数人首先想到的就是“会话”。你要在服务器中的会话上执行SQL、提交事务和运行存储过程(斜体字部分说明了会话的作用)。
2、set autotrace 完成的动作
- 当启用set autotrace功能后,通常会创建一个新的会话用于监控当前的操作并返回统计信息,下面描述其过程
- a.在session1执行一个查询,则此时原来创建的会话(159,5)执行DML或DQL操作
- b.新创建的会话(139,25)会话则开始查询V$SESSTAT 视图来记住实际会话(即运行DML 的会话)的初始统计值
- c.原会话(139,25)中得DML或DQL操作执行
- d.新会话(139,25)将再次查询V$SESSTAT 视图,根据与上次的差值计算统计信息并生成执行时的执行计划以及统计信息予以返回
Connections and Sessions
3、
SQL> set autotrace trace exp
SQL> select * from t2;
Execution Plan
———————————————————-
Plan hash value: 1216610266
。。。。。。。
SQL> set autotrace off
SQL> select process from v$pq_tqstat;
no rows selected
可以看到 用set autotrace 后 查v$pq_tqstat norows ,这是2个原因造成的
1.set autotrace的原理
开启autotrace时候 一个process对应 2个 session
通常情况下是一个 session对应一个 server processs,但SErVER PORCESSS 可以对应多个session
2.v$pq_tqstat只提供当前session最后一次并行执行sql语句的信息
综合2点可以看出set autotrace 最后一个session 是 执行计划的,所以v$pq_tqstat为no rows
参考:
oracle 并行(并行度)
由上面例子说明:同一个服务器进程的多个会话可以共同使用可视化的界面窗口进行输入输出。上面例子中窗口里的执行计划的内容是来自set autotracetrace exp时新建的会话。
还有一个系统里的当前会话只有一个。上面例子中set autotrace off后,当前会话还是新建的那个会话,而v$pq_tqstat只提供当前session最后一次并行执行sql语句的信息,所以查v$pq_tqstat 的结果为no rows。不知道该例子用的oracle的什么版本做实验的。在oracle 11g R2上时,上述过程,查v$pq_tqstat 是有结果的。估计因为set autotrace off后,当前会话会切换到老的那个会话。
通过DBMS_APPLICATION_INFO.SET_MODULE和DBMS_APPLICATION_INFO.SET_ACTION就可以将执行该函数的会话任意取一个名。
通过DBMS_APPLICATION_INFO.SET_CLIENT_ID就可以将执行该函数的会话任意取一个名。
上述开启SQL_TRACE跟踪,跟踪SQL语句的解析、执行等过程。http://t.askmaclean.com/thread-1317-1-1.html
上述开启SQL_TRACE跟踪,跟踪SQL语句的解析、执行等过程。
V$SESSION
MODULE
Foot 1 VARCHAR2(48)
Name of the currently executing module as set by calling theDBMS_APPLICATION_INFO.SET_MODULE
procedureACTION
Footref 1VARCHAR2(32)
Name of the currently executing action as set by calling theDBMS_APPLICATION_INFO.SET_ACTION
procedure====================================================================================================================================
SET_MODULE Procedure
This procedure sets the name of the current application or module.
Syntax
DBMS_APPLICATION_INFO.SET_MODULE ( module_name IN VARCHAR2, action_name IN VARCHAR2);
Parameters
Table 20-6 SET_MODULE Procedure Parameters
module_name
Name of module that is currently running. When the current module terminates, call this procedure with the name of the new module if there is one, orNULL
if there is not. Names longer than 48 bytes are truncated.
action_name
Name of current action within the current module. If you do not want to specify an action, this value should beNULL
. Names longer than 32 bytes are truncated.
Usage Notes
Example
CREATE or replace PROCEDURE add_employee( name VARCHAR2, salary NUMBER, manager NUMBER, title VARCHAR2, commission NUMBER, department NUMBER) AS BEGIN DBMS_APPLICATION_INFO.SET_MODULE( module_name => 'add_employee', action_name => 'insert into emp'); INSERT INTO emp (ename, empno, sal, mgr, job, hiredate, comm, deptno) VALUES (name, emp_seq.nextval, salary, manager, title, SYSDATE, commission, department); DBMS_APPLICATION_INFO.SET_MODULE(null,null); END;
====================================================================================================================================
SET_ACTION Procedure
This procedure sets the name of the current action within the current module.
Syntax
DBMS_APPLICATION_INFO.SET_ACTION ( action_name IN VARCHAR2);
Parameters
Table 20-4 SET_ACTION Procedure Parameters
action_name
The name of the current action within the current module. When the current action terminates, call this procedure with the name of the next action if there is one, orNULL
if there is not. Names longer than 32 bytes are truncated.
Usage Notes
The action name should be descriptive text about the current action being performed. You should probably set the action name before the start of every transaction.
Set the transaction name to NULL
after the transaction completes, so that subsequent transactions are logged correctly. If you do not set the transaction name toNULL
, subsequent transactions may be logged with the previous transaction's name.
Example
The following is an example of a transaction that uses the registration procedure:
CREATE OR REPLACE PROCEDURE bal_tran (amt IN NUMBER(7,2)) AS BEGIN -- balance transfer transaction DBMS_APPLICATION_INFO.SET_ACTION( action_name => 'transfer from chk to sav'); UPDATE chk SET bal = bal + :amt WHERE acct# = :acct; UPDATE sav SET bal = bal - :amt WHERE acct# = :acct; COMMIT; DBMS_APPLICATION_INFO.SET_ACTION(null); END;
====================================================================================================================================
SET_CLIENT_INFO Procedure
This procedure supplies additional information about the client application.
Syntax
DBMS_APPLICATION_INFO.SET_CLIENT_INFO ( client_info IN VARCHAR2);
Parameters
Table 20-5 SET_CLIENT_INFO Procedure Parameters
client_info
Supplies any additional information about the client application. This information is stored in theV$SESSION
view. Information exceeding 64 bytes is truncated.
Note:
CLIENT_INFO
is readable and writable by any user. For storing secured application attributes, you can use the application context feature.- 会话的属性以及组建级别和客户端级别的SQL语句跟踪
- SQL语句级别的优化总结
- SQL语句级别的优化总结
- Sql Server 服务器级别角色 和 数据库级别的角色
- 事务的传播属性和隔离级别
- spring的传播属性和隔离级别
- 从客户端到SQL语句的跟踪
- oracle创建会话级别的临时表
- 如何持久化会话级别的Session
- printk的日志级别和控制台级别
- FORM级别和数据库级别的Trace
- 服务器级别和数据库级别的角色
- Hibernate属性级别的注解
- 关于级别表的两例常用sql语句
- sql事务的隔离级别以及一些MYSQL的命令
- SQL 和存储过程级别的事务及ADO.NET级别的事务
- spring里面事务的传播属性和事务隔离级别
- spring里面事务的传播属性和事务隔离级别
- 五个不为人知的ESC键妙用
- Centos 6.x Atheros AR8161网卡驱动安装
- 2013计算机视觉代码合集一
- myeclipse8.5集成SVN
- apk 植入代码
- 会话的属性以及组建级别和客户端级别的SQL语句跟踪
- 添加手势动作
- ubuntu 12.04安装fcitx, 添加云输入模块
- CodeForces 374 B. Inna and Nine
- Hadoop 新 MapReduce 框架 Yarn 详解[转]
- 我的梦想是什么
- TabHost布局需注意
- 网站获得/提高流量的顶级技巧
- jQuery中 hide和fadeOut的区别 show和fadeIn的区别