Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3693171
  • 博文数量: 715
  • 博客积分: 1860
  • 博客等级: 上尉
  • 技术积分: 7745
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-07 08:51
个人简介

偶尔有空上来看看

文章分类

全部博文(715)

文章存档

2023年(75)

2022年(134)

2021年(238)

2020年(115)

2019年(11)

2018年(9)

2017年(9)

2016年(17)

2015年(7)

2014年(4)

2013年(1)

2012年(11)

2011年(27)

2010年(35)

2009年(11)

2008年(11)

分类: Oracle

2021-07-03 22:50:39

pdb的引入,大家共享一个实例,有时候需要弄清除到底谁的会话导致占用内存高呢?
以下几板斧,看个清楚。

  1. set linesize 150
  2. set pagesize 3000
  3. set NUMWIDTH 15

  4. col Parameter format a30
  5. col component format a28
  6. COLUMN DEFAULT_ATTR FORMAT A7
  7. COLUMN OWNER FORMAT A15
  8. COLUMN OBJECT_NAME FORMAT A15
  9. COLUMN ALL_CONTAINERS FORMAT A3
  10. COLUMN CONTAINER_NAME FORMAT A10
  11. COLUMN CON_ID FORMAT 999
  12. COLUMN pdb_name FORMAT A20
  13. COLUMN memory Format A25
  14. COLUMN spid HEADING 'OSpid' FORMAT a8
  15. COLUMN pid HEADING 'Orapid' FORMAT 999999
  16. COLUMN sid HEADING 'Sess id' FORMAT 99999
  17. COLUMN serial# HEADING 'Serial#' FORMAT 999999
  18. COLUMN status HEADING 'Status' FORMAT a8
  19. COLUMN pga_alloc_mem HEADING 'PGA alloc' FORMAT 999,999,999
  20. COLUMN pga_used_mem HEADING 'PGA used' FORMAT 999,999,999
  21. COLUMN pga_max_mem HEADING 'PGA Max' FORMAT 999,999,999
  22. COLUMN username HEADING 'oracleuser' FORMAT a12
  23. COLUMN osuser HEADING 'OS user' FORMAT a12
  24. COLUMN program HEADING 'Program' FORMAT a24
  25. COLUMN Mbytes Heading 'Mbytes' FORMAT 999,999,999
  26. COLUMN name FORMAT A22

  27. alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS';
  28. --确认当前是否是cdb
  29. select name, cdb, con_id from v$database;
  30. --查询每个pdb状态

  31. --查询大于20M内存的会话
  32. REM v$sesstat pga memory over 20MB size
  33. SELECT NAME, CON_ID, OPEN_MODE, RESTRICTED, DBID, CON_UID, GUID FROM V$CONTAINERS ORDER BY CON_ID;

  34. break on spid skip 1

  35. SELECT p.spid, s.sid, p.con_id, substr(n.name,1,25) memory, ROUND(s.value/1024/1024) as MBytes
  36. FROM v$sesstat s, v$statname n, v$process p, v$session vs
  37. WHERE s.statistic# = n.statistic#
  38. AND n.name LIKE '%pga memory%'
  39. AND s.sid=vs.sid
  40. AND vs.paddr=p.addr
  41. AND s.value > 20000000 /* --remove this line to view all process size */
  42. order by spid,memory;

  43. break on off

  1. -- 某些进程最大占用内存
  2. SELECT pid, spid, con_id, substr(username,1,13) username, program, ROUND(pga_used_mem/1024/1024) pga_used, ROUND(pga_alloc_mem/1024/1024) pga_alloc, ROUND(pga_freeable_mem/1024/1024) pga_freeable, ROUND(pga_max_mem/1024/1024) pga_max
  3. FROM v$process
  4. WHERE pga_alloc_mem = (SELECT max(pga_alloc_mem)
  5.                        FROM v$process
  6.                        WHERE program NOT LIKE '%LGWR%');

  1. --所有pga合计
  2. SELECT ROUND(SUM(pga_alloc_mem)/1024/1024) AS "Mbytes allocated", ROUND(SUM(PGA_USED_MEM)/1024/1024) AS "Mbytes used"
  3. FROM v$process;


  1. --各pdb占用内存
  2. compute sum of "Mbytes allocated" on report
  3. break on report
  4. SELECT con_id, ROUND(SUM(pga_alloc_mem)/1024/1024) AS "Mbytes allocated", ROUND(SUM(PGA_USED_MEM)/1024/1024) AS "Mbytes used"
  5. FROM v$process
  6. group by con_id
  7. order by con_id;

  8. break on off

  1. --合计当前内存
  2. SELECT ROUND(SUM(value)/1024/1024) AS Mbytes
  3. FROM v$sesstat s, v$statname n
  4. WHERE n.STATISTIC# = s.STATISTIC#
  5. AND n.name = 'session pga memory';

  1. --各pdb当前内存汇总
  2. compute sum of MBYTES on report
  3. break on report
  4. select con_id, ROUND(sum(bytes)/1024/1024) as MBYTES from (SELECT p.con_id, s.value as bytes
  5. FROM v$sesstat s, v$statname n, v$process p, v$session vs
  6. WHERE s.statistic# = n.statistic#
  7. AND n.name = 'session pga memory'
  8. AND s.sid=vs.sid
  9. AND vs.paddr=p.addr)
  10. group by con_id
  11. order by con_id;

  12. break on off


  1. --实例启动以来,最大pga分配
  2. col name for a50
  3. select name, ROUND(value/1024/1024) as Mbytes from v$pgastat
  4. where name in ('maximum PGA allocated','aggregate PGA target parameter','aggregate PGA auto target');

  1. -- pga分配历史最高前10

  2. select * from (select name,SNAP_ID, ROUND(VALUE/1024/1024) Mbytes from CDB_HIST_PGASTAT
  3. where name='maximum PGA allocated'
  4. order by Mbytes desc,snap_id desc)
  5. where rownum <11;


  1. --查看当前各今晨分配内存情况
  2. break on con_id skip 4
  3. compute sum of pga_alloc_mem on con_id
  4. SELECT p.con_id,
  5.        p.spid,
  6.        p.pid,
  7.        s.sid,
  8.        s.serial#,
  9.        s.status,
  10.        ROUND(p.pga_alloc_mem/1024/1024) as pga_alloc_mem,
  11.        ROUND(p.pga_used_mem/1024/1024) as pga_used_mem,
  12.        ROUND(p.PGA_MAX_MEM/1024/1024) as pga_max_mem,
  13.        s.username,
  14.        s.osuser,
  15.        s.program
  16. FROM v$process p, v$session s
  17. WHERE s.paddr( + ) = p.addr
  18. --AND p.background is null /* Remove prevent listing background processes */
  19. ORDER BY con_id,pga_alloc_mem;

  20. break on off

  1. -- sga pga设置

  2. select con_id, name as Parameter, value/1024/1024 as Mbytes from v$parameter
  3. where name in ('pga_aggregate_target','memory_target','memory_max_target','sga_max_size','sga_target','pga_aggregate_limit')
  4. order by name;

  1. --显示动态组件的当前值
  2. select con_id, component, ROUND(USER_SPECIFIED_SIZE/1024/1024) as Mbytes, OPER_COUNT, LAST_OPER_TIME as "Last op time", ROUND(current_size/1024/1024) as Mbytes from v$memory_dynamic_components
  3. order by component;


  1. --通过数据库视图显示 SGA 内存使用情况
  2. select name, ROUND(bytes/1024/1024) as Mbytes from v$sgainfo;


  1. -显示可用来扩展 sga_target 的可用空闲 sga 内存
  2. select ROUND(current_size/1024/1024) Mbytes from V$SGA_DYNAMIC_FREE_MEMORY;

  1. --只显示超过 10M 的内存分配
  2. break on con_id skip 4
  3. select con_id, pool, name, ROUND(bytes/1024/1024,1) as Mbytes from v$sgastat
  4. where bytes/1024/1024 > 10 --alter to see smaller/larger allocations
  5. order by con_id;
  6. break on off

参考:
在可插拔数据库上如何监控进程内存的使用 (Doc ID 1985042.1)
如何监控可插拔数据库(PDB)的 SGA 内存使用情况 (Doc ID 2248684.1)
阅读(1308) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~