欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > 检查是否存在占用内存过大的SQL

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

2025/4/4 3:11:10 来源:https://blog.csdn.net/weixin_45699851/article/details/146921749  浏览:    关键词:检查是否存在占用内存过大的SQL

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;

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com