[转] Oracle数据库维护常用SQL语句集合
进程相关:
1、 求当前会话的SID,SERIAL#
SELECT Sid, Serial#
FROM V$session
WHERE Audsid = Sys_Context('USERENV', 'SESSIONID');
2、 查询session的OS进程ID
SELECT p.Spid "OS Thread", b.NAME "Name-User", s.Program, s.Sid, s.Serial#,
s.Osuser, s.Machine
FROM V$process p, V$session s, V$bgprocess b
WHERE p.Addr = s.Paddr
AND p.Addr = b.Paddr
And (s.sid=&1 or p.spid=&1)
UNION ALL
SELECT p.Spid "OS Thread", s.Username "Name-User", s.Program, s.Sid,
s.Serial#, s.Osuser, s.Machine
FROM V$process p, V$session s
WHERE p.Addr = s.Paddr
And (s.sid=&1 or p.spid=&1)
AND s.Username IS NOT NULL;
3、根据sid查看对应连接正在运行的sql
SELECT /*+ PUSH_SUBQ */
Command_Type, Sql_Text, Sharable_Mem, Persistent_Mem, Runtime_Mem, Sorts,
Version_Count, Loaded_Versions, Open_Versions, Users_Opening, Executions,
Users_Executing, Loads, First_Load_Time, Invalidations, Parse_Calls,
Disk_Reads, Buffer_Gets, Rows_Processed, SYSDATE Start_Time,
SYSDATE Finish_Time, '>' || Address Sql_Address, 'N' Status
FROM V$sqlarea
WHERE Address = (SELECT Sql_Address
FROM V$session
WHERE Sid = &sid );
4、查找object为哪些进程所用
SELECT p.Spid, s.Sid, s.Serial# Serial_Num, s.Username User_Name,
a.TYPE Object_Type, s.Osuser Os_User_Name, a.Owner,
a.OBJECT Object_Name,
Decode(Sign(48 - Command), 1, To_Char(Command), 'Action Code #' || To_Char(Command)) Action,
p.Program Oracle_Process, s.Terminal Terminal, s.Program Program,
s.Status Session_Status
FROM V$session s, V$access a, V$process p
WHERE s.Paddr = p.Addr
AND s.TYPE = 'USER'
AND a.Sid = s.Sid
AND a.OBJECT = '&obj'
ORDER BY s.Username, s.Osuser
5、查看有哪些用户连接
SELECT s.Osuser Os_User_Name,
Decode(Sign(48 - Command),1,To_Char(Command),
'Action Code #' || To_Char(Command)) Action,
p.Program Oracle_Process, Status Session_Status, s.Terminal Terminal,
s.Program Program, s.Username User_Name,
s.Fixed_Table_Sequence Activity_Meter, '' Query, 0 Memory,
0 Max_Memory, 0 Cpu_Usage, s.Sid, s.Serial# Serial_Num
FROM V$session s, V$process p
WHERE s.Paddr = p.Addr
AND s.TYPE = 'USER'
ORDER BY s.Username, s.Osuser
6、根据v.sid查看对应连接的资源占用等情况
SELECT n.NAME, v.VALUE, n.CLASS, n.Statistic#
FROM V$statname n, V$sesstat v
WHERE v.Sid = &sid
AND v.Statistic# = n.Statistic#
ORDER BY n.CLASS, n.Statistic#
7、查询耗资源的进程(top session)
SELECT s.Schemaname Schema_Name,
Decode(Sign(48 - Command),
1, To_Char(Command), 'Action Code #' || To_Char(Command)) Action,
Status Session_Status, s.Osuser Os_User_Name, s.Sid, p.Spid,
s.Serial# Serial_Num, Nvl(s.Username, '[Oracle process]') User_Name,
s.Terminal Terminal, s.Program Program, St.VALUE Criteria_Value
FROM V$sesstat St, V$session s, V$process p
WHERE St.Sid = s.Sid
AND St.Statistic# = To_Number('38')
AND ('ALL' = 'ALL' OR s.Status = 'ALL')
AND p.Addr = s.Paddr
ORDER BY St.VALUE DESC, p.Spid ASC, s.Username ASC, s.Osuser ASC
8、查看锁(lock)情况
SELECT /*+ RULE */
Ls.Osuser Os_User_Name, Ls.Username User_Name,
Decode(Ls.TYPE,
'RW', 'Row wait enqueue lock', 'TM', 'DML enqueue lock',
'TX', 'Transaction enqueue lock', 'UL', 'User supplied lock') Lock_Type,
o.Object_Name OBJECT,
Decode(Ls.Lmode,
1, NULL, 2, 'Row Share', 3, 'Row Exclusive',
4, 'Share', 5, 'Share Row Exclusive', 6, 'Exclusive',
NULL) Lock_Mode,
o.Owner, Ls.Sid, Ls.Serial# Serial_Num, Ls.Id1, Ls.Id2
FROM Sys.Dba_Objects o,
(SELECT s.Osuser, s.Username, l.TYPE, l.Lmode, s.Sid, s.Serial#, l.Id1,
l.Id2
FROM V$session s, V$lock l
WHERE s.Sid = l.Sid) Ls
WHERE o.Object_Id = Ls.Id1
AND o.Owner <> 'SYS'
ORDER BY o.Owner, o.Object_Name
9、查看等待(wait)情况
SELECT Ws.CLASS, Ws.COUNT COUNT, SUM(Ss.VALUE) Sum_Value
FROM V$waitstat Ws, V$sysstat Ss
WHERE Ss.NAME IN ('db block gets', 'consistent gets')
GROUP BY Ws.CLASS, Ws.COUNT
10、求process/session的状态
SELECT p.Pid, p.Spid, s.Program, s.Sid, s.Serial#
FROM V$process p, V$session s
WHERE s.Paddr = p.Addr;
11、求谁阻塞了某个session(10g)
SELECT Sid, Username, Event, Blocking_Session, Seconds_In_Wait, Wait_Time
FROM V$session
WHERE State IN ('WAITING')
AND Wait_Class != 'Idle';
12、查会话的阻塞
col user_name format a32
SELECT /*+ rule */
Lpad(' ', Decode(l.Xidusn, 0, 3, 0)) || l.Oracle_Username User_Name,
o.Owner, o.Object_Name, s.Sid, s.Serial#
FROM V$locked_Object l, Dba_Objects o, V$session s
WHERE l.Object_Id = o.Object_Id
AND l.Session_Id = s.Sid
ORDER BY o.Object_Id, Xidusn DESC;
col username format a15
col lock_level format a8
col owner format a18
col object_name format a32
SELECT /*+ rule */
s.Username,
Decode(l.TYPE, 'tm', 'table lock', 'tx', 'row lock', NULL) Lock_Level,
o.Owner, o.Object_Name, s.Sid, s.Serial#
FROM V$session s, V$lock l, Dba_Objects o
WHERE l.Sid = s.Sid
AND l.Id1 = o.Object_Id(+)
AND s.Username IS NOT NULL;
13、求等待的事件及会话信息/求会话的等待及会话信息
SELECT Se.Sid, s.Username, Se.Event, Se.Total_Waits, Se.Time_Waited,
Se.Average_Wait
FROM V$session s, V$session_Event Se
WHERE s.Username IS NOT NULL
AND Se.Sid = s.Sid
AND s.Status = 'ACTIVE'
AND Se.Event NOT LIKE '%SQL*Net%'
ORDER BY s.Username;
SELECT s.Sid, s.Username, Sw.Event, Sw.Wait_Time, Sw.State,
Sw.Seconds_In_Wait
FROM V$session s, V$session_Wait Sw
WHERE s.Username IS NOT NULL
AND Sw.Sid = s.Sid
AND Sw.Event NOT LIKE '%SQL*Net%'
ORDER BY s.Username;
14、求会话等待的file_id/block_id
col event format a24
col p1text format a12
col p2text format a12
col p3text format a12
SELECT Sid, Event, P1text, P1, P2text, P2, P3text, P3
FROM V$session_Wait
WHERE Event NOT LIKE '%SQL%'
AND Event NOT LIKE '%rdbms%'
AND Event NOT LIKE '%mon%'
ORDER BY Event;
SELECT NAME, Wait_Time
FROM V$latch l
WHERE EXISTS (SELECT 1
FROM (SELECT Sid, Event, P1text, P1, P2text, P2, P3text, P3
FROM V$session_Wait
WHERE Event NOT LIKE '%SQL%'
AND Event NOT LIKE '%rdbms%'
AND Event NOT LIKE '%mon%') x
WHERE x.P1 = l.Latch#);
15、求会话等待的对象
col owner format a18
col segment_name format a32
col segment_type format a32
SELECT Owner, Segment_Name, Segment_Type
FROM Dba_Extents
WHERE File_Id = &File_Id
AND &Block_Id BETWEEN Block_Id AND Block_Id + Blocks - 1;
16、求出某个进程,并对它进行跟踪
SELECT s.Sid, s.Serial#
FROM V$session s, V$process p
WHERE s.Paddr = p.Addr
AND p.Spid = &1;
Exec Dbms_System.Set_Sql_Trace_In_Session(&1, &2, TRUE);
Exec Dbms_System.Set_Sql_Trace_In_Session(&1, &2, FALSE);
17、求当前session的跟踪文件
SELECT P1.VALUE || '/' || P2.VALUE || '_ora_' || p.Spid || '.ora' Filename
FROM V$process p, V$session s, V$parameter P1, V$parameter P2
WHERE P1.NAME = 'user_dump_dest'
AND P2.NAME = 'instance_name'
AND p.Addr = s.Paddr
AND s.Audsid = Userenv('SESSIONID')
AND p.Background IS NULL
AND Instr(p.Program, 'CJQ') = 0;
18、求出锁定的对象
SELECT Do.Object_Name, Session_Id, Process, Locked_Mode
FROM V$locked_Object Lo, Dba_Objects Do
WHERE Lo.Object_Id = Do.Object_Id;
[转] Oracle数据库维护常用SQL语句集合的更多相关文章
- Oracle数据库常用Sql语句大全
一,数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, 字段名2, ……) VALUES ( 值1, 值2, ……); INSE ...
- 常用SQL语句集合
一.数据定义 1.创建新数据库:CREATE DATABASE database_name2.创建新表:CREATE TABLE table_name (column_name datatype,co ...
- oracle数据库常用SQL语句(11.29更新)
笔者日常工作中常用到的sql语句,现总结如下,留作日后查看. 1.按照两列中的最大值取 ,只取两列其中的一列 SELECT * FROM t_doc T ORDER BY GREATEST(T.Loa ...
- oracle数据库常用SQL语句
1)删除表的一列 ALTER TABLE 表名 DROP COLUMN 列名; 2)增加表的一列 且默认值为0 alter table 表名 add 字段名 类型 default '0'; 3)修改表 ...
- Oracle 数据库常用SQL语句(2)查询语句
一.SQL基础查询 1.select语句 格式:select 字段 from 表名; 2.where 用于限制查询的结果. 3.查询条件 > < >= <= = != 4.与 ...
- Oracle 数据库常用SQL语句(1)
一.数据定义语句 CREATE:创建表或其它对象 create database test; //创建test数据库 ),sex )); //创建表 ALTER:修改表或其它对象的结构 )); //为 ...
- 【DB2】db2常用SQL语句集合
持续更新中 1.修改日志模式为不记录 alter table table_name activate not logged initially; 2.清空表 alter table t1 activ ...
- oracle常用SQL语句(汇总版)
Oracle数据库常用sql语句 ORACLE 常用的SQL语法和数据对象一.数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, ...
- oracle 常用sql语句
oracle 常用sql语句 1.查看表空间的名称及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizefrom d ...
随机推荐
- (转)Spring+JDBC组合开发
http://blog.csdn.net/yerenyuan_pku/article/details/52882435 搭建和配置Spring与JDBC整合的环境 使用Spring+JDBC集成步骤如 ...
- centos7 搭建双网卡bond1(主备模式)实例
前景须知: 在redhat6 中网卡叫bond,在redhat7及centos7中改名team,此处只记录centos7中双网卡主备搭建过程. 应用情景:实现网络的高可用,防止一条网线或交换机故障影响 ...
- this.$Message.success('提示信息') 少写了一个c 导致报错
this.$Message.success('提示信息') 少写了一个c 导致报错 而且 $Message 输出还没显示,导致我以为是没有 $Message 对象了,其实全局对象直接调用即可
- android 近百个源码项目【转】
http://www.cnblogs.com/helloandroid/articles/2385358.html Android开发又将带来新一轮热潮,很多开发者都投入到这个浪潮中去了,创造了许许多 ...
- 32位和64位系统下 int、char、long、double所占的内存
32位和64位系统下 int.char.long.double所占内存
- poj2065 SETI
题目描述: 多组数据,每次给出一个模数$p$和一个表示答案的字符串, 相当于给出一个方程组:$$a_1*1^{1}+a_2*1^{2}+……+a_n*1^{n}=f_1$$ $$a_1*2^{1}+a ...
- 【集合遍历-Java】
遍历List集合的三种方法 1.增强for循环 for(String str : list) {//其内部实质上还是调用了迭代器遍历方式,这种循环方式还有其他限制,不建议使用. System.out. ...
- 【03】使用 Firebug 调试 JavaScript
[03] 使用 Firebug 调试 JavaScript 描述 Firebug是一个非常强大的工具,可以帮助您发现代码发现错误的错误并解决错误. 在此我们使用Firebug来处理Javascript ...
- maven中的groupId和artifactId到底指的是什么?
具体回答如下: groupid和artifactId被统称为“坐标”是为了保证项目唯一性而提出的,如果你要把你项目弄到maven本地仓库去,你想要找到你的项目就必须根据这两个id去查找. groupI ...
- 【课余作品】简约QQ申请器(永久免费更新)
UPDATEDATE:2013-08-28 下载地址:http://pan.baidu.com/share/link?shareid=3376000151&uk=3339155803