检查是否存在占用内存过大的SQL

发布于:2025-04-03 ⋅ 阅读:(18) ⋅ 点赞:(0)

1:此语句检查是否存在占用内存过大的SQL

SELECT *
FROM ( SELECT
A.SESS_ID,
A.THRD_ID,
A.USER_NAME ||':' || A.CURR_SCH LOGIN_INFO,
A.SQL_TEXT,
C.STATUS TRX_STATUS,
DATEDIFF(SS, LAST_RECV_TIME, SYSDATE) SS,
CAST( M.TS * 1.0/1024/1024 AS NUMBER(38,2)) USED_MEMORY_M,
'SP_CLOSE_SESSION(' ||A.SESS_ID ||');' KILL_SESS,
SF_GET_SESSION_SQL(A.SESS_ID) FULL_SQL ,
A.APPNAME|| A.CLNT_IP CLNT_INFO,
A.TRX_ID,
B.IO_WAIT_TIME,
B.LOGIC_READ_CNT,
B.PHY_READ_CNT,
B.RECYCLE_LOGIC_READ_CNT,
B.RECYCLE_PHY_READ_CNT,
C.UPD_CNT,
C.DEL_CNT,
C.INS_CNT
FROM V$SESSIONS A,
V$SQL_STAT B,
V$TRX C,
(SELECT SUM(TOTAL_SIZE) TS,CREATOR FROM V$MEM_POOL GROUP BY CREATOR) M
WHERE A.STATE ='ACTIVE'
AND A.SESS_ID = B.SESSID
AND A.TRX_ID = C.ID
AND A.SESS_ID = C.SESS_ID
AND A.THRD_ID = M.CREATOR)
ORDER BY SS DESC;

2:数据库层面查看内存大概占有多少,请使用以下sql进行查询

select
(select sum(cast(n_pages as bigint)* page_size)/1024/1024 from v$bufferpool)||'MB' as BUFFER_SIZE,
( select sum(cast(total_size as bigint))/1024/1024 from v$mem_pool)||'MB' as mem_pool,
(select sum(cast(n_pages as bigint) * page_size)/1024/1024 from v$bufferpool)+(select sum(cast(total_size as bigint))/1024/1024 from v$mem_pool)||'MB' as TOTAL_SIZE
From dual;

3 单个会话内存使用总量

SELECT A.CREATOR ,
B.SQL_TEXT ,
SUM(A.TOTAL_SIZE)/1024.0/1024.0 TOTAL_M,
SUM(A.DATA_SIZE) /1024.0/1024.0 DATA_SIZE_M --实际使用量
FROM V$MEM_POOL A,
V$SESSIONS B
WHERE A.CREATOR = B.THRD_ID
GROUP BY A.CREATOR,
B.SQL_TEXT
ORDER BY TOTAL_M DESC;

缓冲区

SELECT
(
SELECT
SUM(CAST(PAGE_SIZE AS NUMBER) *CAST(N_PAGES AS NUMBER))/1024/1024
FROM
V$BUFFERPOOL
) ||'MB' AS 缓冲区总大小,
(
SELECT
SUM(TOTAL_SIZE)/1024/1024
FROM
V$MEM_POOL
)||'MB' AS 池总大小,
(
SELECT
SUM(CAST(PAGE_SIZE AS NUMBER) *CAST(N_PAGES AS NUMBER))/1024/1024
FROM
V$BUFFERPOOL
) +
(
SELECT
SUM(TOTAL_SIZE)/1024/1024
FROM
V$MEM_POOL
) ||'MB' AS 总内存大小
FROM DUAL;

网站公告

今日签到

点亮在社区的每一天
去签到