V$SESSION_LONGOPS
对大部分DBA来说,V$SESSION_LONGOPS视图都不会陌生,以前在面试的时候,也有一些企业会问到如何查询数据库中运行时间比较长的SQL,就可以通过这个视图来查看。
V$SESSION_LONGOPS视图不但可以监控运行式时间比较长的SQL,也会记录RMAN备份、EXP/EXPDP、收集统计信息、排序等操作,基本数据库所有运行时间超过6秒的SQL都会记录在这个视图中,也有的DBA会定期检查这个视图来寻找可优化的SQL。
下面是这个视图的结构:
01
SQL> desc v$session_longops
02
名称 是否为空? 类型 注释
03
----------------------------------------- -------- ------------------ ------------------
04
SID NUMBER 和V$SESSION中的SID一样
05
SERIAL# NUMBER 和V$SESSION中的SERIAL#一样
06
OPNAME VARCHAR2(64) 操作的名称,如全表扫描
07
TARGET VARCHAR2(64) 被操作的对象名,如表名
08
TARGET_DESC VARCHAR2(32) TARGET的描述
09
SOFAR NUMBER 以完成的数量,如扫描多少数据块
10
TOTALWORK NUMBER 一共需要完成的数量
11
UNITS VARCHAR2(32) 计量单位
12
START_TIME DATE 开始时间
13
LAST_UPDATE_TIME DATE 最后一次调用set_session_longops的时间
14
TIMESTAMP DATE 特定操作的时间戳
15
TIME_REMAINING NUMBER 预计剩余时间,单位秒
16
ELAPSED_SECONDS NUMBER 开始操作到最后更新的时间
17
CONTEXT NUMBER
18
MESSAGE VARCHAR2(512) 对操作的描述
19
USERNAME VARCHAR2(30) 操作用户的名字
20
SQL_ADDRESS RAW(4) 用于关联V$SQL等视图
21
SQL_HASH_VALUE NUMBER 用于关联V$SQL等视图
22
SQL_ID VARCHAR2(13) 用于关联V$SQL等视图
23
SQL_PLAN_HASH_VALUE NUMBER 用于关联V$SQL等视图
24
SQL_EXEC_START DATE SQL开始运行的时间
25
SQL_EXEC_ID NUMBER SQL执行的标识符
26
SQL_PLAN_LINE_ID NUMBER SQL执行计划相关
27
SQL_PLAN_OPERATION VARCHAR2(30) SQL执行计划相关
28
SQL_PLAN_OPTIONS VARCHAR2(30) SQL执行计划相关
29
QCSID NUMBER 并行查询
下面简单做几个超过6秒的操作,来查看下这个视图。
先测试下insert操作。
01
SQL> create table longops_test as select * from dba_objects;
02
表已创建。
03
SQL> insert into longops_test select * from longops_test;
04
已创建65525行。
05
SQL> /
06
已创建131050行。
07
SQL> /
08
已创建262100行。
09
SQL> /
10
已创建524200行。
11
SQL> /
12
已创建1048400行。
13
SQL> commit;
14
提交完成。
现在INSERT操作已经超过6秒,查询下V$SESSION_LONGOPS视图。
1
SID SERIAL# OPNAME TARGET SOFAR TOTALWORK UNITS MESSAGE SQL_PLAN_OPERATION SQL_PLAN_OPTIONS
2
--- ------- --------- ---------------- ----- -------- ----- --------------- ------------------- ---------------
3
194 12 Table Scan SYS.LONGOPS_TEST 14895 14895 Blocks Table Scan: TABLE ACCESS FULL
4
SYS.LONGOPS_TEST:
5
14895 out of
6
14895 Blocks done
这是已经运行结束的INSERT操作,可见SOFAR和TOTALWORK的值是一样的,在看下没运行完的SQL。
1
SQL> create table longops_ctas as select * from longops_test;
在SQL执行6秒后(还没运行完)时,看下V$SESSION_LONGOPS视图的状态。
01
SID SERIAL# OPNAME TARGET SOFAR TOTALWORK UNITS MESSAGE SQL_PLAN_OPERATION SQL_PLAN_OPTIONS
02
--- ------- --------- ---------------- ----- -------- ----- --------------- ------------------- ---------------
03
194 12 Table Scan SYS.LONGOPS_TEST 14895 14895 Blocks Table Scan: TABLE ACCESS FULL
04
SYS.LONGOPS_TEST:
05
14895 out of
06
14895 Blocks done
07
194 12 Table Scan SYS.LONGOPS_TEST 13275 29785 Blocks Table Scan: TABLE ACCESS FULL
08
SYS.LONGOPS_TEST:
09
13275 out of
10
29785 Blocks done
可见,当前扫描了13275个数据块,总共需要扫描29785个数据块。RMAN备份和收集统计信息也同样会被这个视图记录。
01
OPNAME SOFAR TOTALWORK MESSAGE
02
--------------------------------- ---------- ---------- -------------------------------------------
03
Gather Table Partition Statistics 1 1 Gather Table Partition Statistics: Table
04
WR H$_OSSTAT : 1 out of 1 Partitions done
05
RMAN: aggregate input 1181953 1181953 RMAN: aggregate input: backup 33: 1181953
06
out of 1181953 Blocks done
07
RMAN: aggregate input 1181953 1181953 RMAN: aggregate input: backup 33: 1181953
08
out of 1181953 Blocks done
09
RMAN: aggregate output 359461 359461 RMAN: aggregate output: backup 33: 359461
10
out of 359461 Blocks done
11
RMAN: full datafile backup 1181280 1181280 RMAN: full datafile backup: Set Count 18:
12
1181280 out of 1181280 Blocks done
下面是ORACLE官方文档对V$SESSION_LONGOPS视图的介绍:
view source
01
V$SESSION_LONGOPS displays the status of various operations that run for longer than 6 seconds (in absolute time). These operations currently include many backup and recovery functions, statistics gathering, and query execution, and more operations are added for every Oracle release.
02
03
To monitor query execution progress, you must be using the cost-based optimizer and you must:
04
05
?Set the TIMED_STATISTICS or SQL_TRACE parameters to true
06
07
?Gather statistics for your objects with the DBMS_STATS package
08
09
You can add information to this view about application-specific long-running operations by using the DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS procedure.
10
Column Datatype Description
11
------------------- ---------- ---------------------------------------------------------------------------------
12
SID NUMBER Identifier of the session processing the long-running operation. If multiple sessi
13
ons are cooperating in the long-running operation, then SID corresponds to the mai
14
n or master session.
15
SERIAL# NUMBER Serial number of the session processing the long-running operation. If multiple se
16
ssions are cooperating in the long-running operation, then SERIAL# corresponds to
17
the main or master session. SERIAL# is used to uniquely identify a session's objec
18
ts. Guarantees that session-level commands are applied to the correct session obje
19
cts if the session ends and another session begins with the same session ID.
20
OPNAME VARCHAR2(64) Brief description of the operation
21
TARGET VARCHAR2(64) Object on which the operation is carried out
22
TARGET_DESC VARCHAR2(32) Description of the target
23
SOFAR NUMBER Units of work done so far
24
TOTALWORK NUMBER Total units of work
25
UNITS VARCHAR2(32) Units of measurement
26
START_TIME DATE Starting time of the operation
27
LAST_UPDATE_TIME DATE Time when statistics were last updated for the operation
28
TIMESTAMP DATE Timestamp specific to the operation
29
TIME_REMAINING NUMBER Estimate (in seconds) of time remaining for the operation to complete
30
ELAPSED_SECONDS NUMBER Number of elapsed seconds from the start of the operations
31
CONTEXT NUMBER Context
32
MESSAGE VARCHAR2(512) Statistics summary message
33
USERNAME VARCHAR2(30) User ID of the user performing the operation
34
SQL_ADDRESS RAW(4 | 8) Used with the value of the SQL_HASH_VALUE column to identify the SQL statement as
35
sociated with the operation
36
SQL_HASH_VALUE NUMBER Used with the value of the SQL_ADDRESS column to identify the SQL statement assoc
37
iated with the operation
38
SQL_ID VARCHAR2(13) SQL identifier of the SQL statement associated with the long operation, if any
39
SQL_PLAN_HASH_VALUE NUMBER SQL plan hash value; NULL if SQL_ID is NULL
40
SQL_EXEC_START DATE Time when the execution of the SQL started; NULL if SQL_ID is NULL
41
SQL_EXEC_ID NUMBER SQL execution identifier (see V$SQL_MONITOR)
42
SQL_PLAN_LINE_ID NUMBER SQL plan line ID corresponding to the long operation; NULL if the long operation
43
is not associated with a line of the execution plan
44
SQL_PLAN_OPERATION VARCHAR2(30) Plan operation name; NULL if SQL_PLAN_LINE_ID is NULL
45
SQL_PLAN_OPTIONS VARCHAR2(30) Plan operation options; NULL if SQL_PLAN_LINE_ID is NULL
46
QCSID NUMBER Session identifier of the parallel coordinator
V$SESSION_LONGOPS的更多相关文章
- 设置Hyper V
1.打开服务器管理器 2.添加角色和功能 3.安装类型 -> 基于角色或基于功能的安装 4.服务器选择 -> 下一步 5.服务器角色 勾选"Hyper V"
- Oracle 动态视图5 V$SESSION_LONGOPS
一.视图V$SESSION_LONGOPS显示运行超过6秒的操作的状态.包括备份,恢复,统计信息收集,查询等等 Column Datatype Description SID NUMBER Sessi ...
- algorithm@ Shortest Path in Directed Acyclic Graph (O(|V|+|E|) time)
Given a Weighted Directed Acyclic Graph and a source vertex in the graph, find the shortest paths fr ...
- 转:oracle几组重要的常见视图-v$undostat,v$open_cursor,v$rowcache,v$session_longops,v$waitstat
v$undostat 本视图监控当前实例中undo空间以及事务如何运行.并统计undo空间开销,事务开销以及实例可用的查询长度. V$UNDOSTAT中的常用列 Endtime:以10分钟为间隔的结束 ...
- 动态性能视图v$session_longops
v$session_longops This view displays the status of various operations that run for longer than 6 sec ...
- 学习动态性能表(10)--v$session_longops
学习动态性能表 第十篇--V$SESSION_LONGOPS 2007.6.7 本视图显示运行超过6秒的操作的状态.包括备份,恢复,统计信息收集,查询等等. 要监控查询执行进展状况,你必须使用cos ...
- 转 v$session_longops视图
转http://www.dbdream.com.cn/2013/10/14/vsession_longops%E8%A7%86%E5%9B%BE/ 1.有的时候不准确 ,我看到 session wai ...
- Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
在学习CGlib动态代理时,遇到如下错误: Exception in thread "main" java.lang.NoSuchMethodError: org.objectwe ...
- [Erlang 0118] Erlang 杂记 V
我在知乎回答问题不多,这个问题: "对你职业生涯帮助最大的习惯是什么?它是如何帮助你的?",我还是主动回答了一下. 做笔记 一开始笔记软件做的不好的时候就发邮件给自己, ...
随机推荐
- Python:变量与字符串
变量 使用dos页面进行命令的输入如下变量,进行打印: 同时,相同两个变量书写在同一行,中间用英文的“;”隔开 python中区分大小写变量 字符串 简单的说,字符串就是双引号,单引号,或者三 ...
- SAE网站搭建(1)
用了半天时间,把Django的基本结构同步到SAE上了,里边比较麻烦的地方如下: 1. 数据库的同步; SAE用的是SQL数据库,默认使用下面的用户名.密码等变量(SAE为我们做了很多工作) 首先需要 ...
- php 图片压缩
/** * desription 判断是否gif动画 * @param sting $image_file图片路径 * @return boolean t 是 f 否 */ function chec ...
- [NOIP2003]栈
2003年普及组 题目背景 栈是计算机中经典的数据结构,简单的说,栈就是限制在一端进行插入删除操作的线性表. 栈有两种最重要的操作,即pop(从栈顶弹出一个元素)和push(将一个元素进栈). 栈的重 ...
- Java笔记(四)……常量与变量
常量 常量表示不会改变的数值. Java中常量的分类: 整数常量:所有整数 小数常量:所有小数 布尔型常量:较为特有,只有两个数值,true false 字符常量:将一个数字字母或者符号用单引号(' ...
- POJ-2296 Map Labeler 2sat
题目链接:http://poj.org/problem?id=2296 二分+2sat,每个点的上下两个方向为2sat的两个状态. //STATUS:C++_AC_16MS_536KB #includ ...
- ORA-01653:表空间扩展失败的问题(开启表空间自动扩展)
----查询表空间使用情况---使用DBA权限登陆SELECT UPPER(F.TABLESPACE_NAME) "表空间名",D.TOT_GROOTTE_MB "表空间 ...
- Linux必学的命令
Linux必学的命令Linux提供了大量的命令,利用它可以有效地完成大量的工作,如磁盘操作.文件存取.目录操作.进程管理.文件权限设定等.所以,在Linux系统上工作离不开使用系统提供的命令.要想真正 ...
- C#- FTP递归下载文件
c# ftp递归下载文件,找来找去这个最好.(打断点,一小处foreach要改成for) /// <summary> /// ftp文件上传.下载操作类 /// </summary& ...
- Oracle学习过程(随时更新)
1.入门 实用的一些查询语句: 查询用户所有表注释 select * from user_tab_comments 条件查询 根据两个值查询 select*from table where 字段 in ...