查询Oracle正在执行的sql语句及执行该语句的用户

查询Oracle正在执行的sql语句及执行该语句的用户
SELECT B.SID ORACLEID,
B.USERNAME 登录ORACLE用户名,
B.SERIAL#,
SPID 操作系统ID,
PADDR,
SQL_TEXT 正在执行的SQL,
B.MACHINE 计算机名
FROM V\$PROCESS A, V\$SESSION B, V\$SQLAREA C
WHERE A.ADDR = B.PADDR
AND B.SQL_HASH_VALUE = C.HASH_VALUE;

--查看正在执行sql的发起者的发放程序
SELECT OSUSER 电脑登录身份,
PROGRAM 发起请求的程序,
USERNAME 登录系统的用户名,
SCHEMANAME,
B.CPU_TIME 花费CPU的时间,
STATUS,
B.SQL_TEXT 执行的SQL
FROM V\$SESSION A
LEFT JOIN V\$SQL B
ON A.SQL_ADDRESS = B.ADDRESS
AND A.SQL_HASH_VALUE = B.HASH_VALUE
ORDER BY B.CPU_TIME DESC;

--锁表查询SQL
SELECT OBJECT_NAME, MACHINE, S.SID, S.SERIAL#
FROM GV\$LOCKED_OBJECT L, DBA_OBJECTS O, GV\$SESSION S
WHERE L.OBJECT_ID  = O.OBJECT_ID
AND L.SESSION_ID = S.SID;

--释放SESSION SQL:
--alter system kill session 'sid, serial#';
ALTER SYSTEM KILL SESSION '23, 1647';

--查某一用户下的表大小
SELECT SEGMENT_NAME, TABLESPACE_NAME, SUM(BYTES / 1024 / 1024) || 'M'
FROM USER_EXTENTS
WHERE SEGMENT_TYPE = 'TABLE'
GROUP BY SEGMENT_NAME, TABLESPACE_NAME
ORDER BY 3 DESC;

--查所有的表大小
SELECT SEGMENT_NAME, TABLESPACE_NAME, SUM(BYTES / 1024 / 1024) || 'M'
FROM DBA_EXTENTS
WHERE SEGMENT_TYPE = 'TABLE'
GROUP BY SEGMENT_NAME, TABLESPACE_NAME
ORDER BY 3 DESC;

--oracle查询历史执行语句
SELECT *
FROM V\$SQLAREA
WHERE /*PARSING_SCHEMA_NAME = 'ORDERS'
AND */SQL_TEXT LIKE '%delete%'
ORDER BY LAST_ACTIVE_TIME

posted @ 2019-12-25 00:39  ritchy  阅读(1973)  评论(0编辑  收藏  举报