Chinaunix首页 | 论坛 | 博客
  • 博客访问: 70719
  • 博文数量: 22
  • 博客积分: 300
  • 博客等级: 二等列兵
  • 技术积分: 167
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-03 22:28
文章分类

全部博文(22)

文章存档

2011年(22)

我的朋友

分类: Oracle

2011-11-21 11:12:17

查询 SGA ,PGA 等内存信息(网络搜来的实不知出处 见谅)
  1. SELECT NAME,
  2.        TOTAL,
  3.        ROUND(TOTAL - FREE, 2) USED,
  4.        ROUND(FREE, 2) FREE,
  5.        ROUND((TOTAL - FREE) / TOTAL * 100, 2) PCTUSED
  6.   FROM (SELECT 'SGA' NAME,
  7.                (SELECT SUM(VALUE / 1024 / 1024) FROM V$SGA) TOTAL,
  8.                
  9.                (SELECT SUM(BYTES / 1024 / 1024)
  10.                   FROM V$SGASTAT
  11.                  WHERE NAME = 'free memory') FREE
  12.           FROM DUAL)

  13. UNION

  14. SELECT NAME,
  15.        TOTAL,
  16.        ROUND(USED, 2) USED,
  17.        ROUND(TOTAL - USED, 2) FREE,
  18.        ROUND(USED / TOTAL * 100, 2) PCTUSED
  19.   FROM (
  20.         
  21.         SELECT 'PGA' NAME,
  22.                 (SELECT VALUE / 1024 / 1024 TOTAL
  23.                    FROM V$PGASTAT
  24.                   WHERE NAME = 'aggregate PGA target parameter') TOTAL,
  25.                 
  26.                 (SELECT VALUE / 1024 / 1024 USED
  27.                    FROM V$PGASTAT
  28.                   WHERE NAME = 'total PGA allocated') USED
  29.           FROM DUAL)

  30. UNION

  31. SELECT NAME,
  32.        ROUND(TOTAL, 2) TOTAL,
  33.        ROUND((TOTAL - FREE), 2) USED,
  34.        ROUND(FREE, 2) FREE,
  35.        ROUND((TOTAL - FREE) / TOTAL * 100, 2) PCTUSED
  36.   FROM (
  37.         
  38.         SELECT 'Shared pool' NAME,
  39.                 (SELECT SUM(BYTES / 1024 / 1024)
  40.                    FROM V$SGASTAT
  41.                   WHERE POOL = 'shared pool') TOTAL,
  42.                 
  43.                 (SELECT BYTES / 1024 / 1024
  44.                    FROM V$SGASTAT
  45.                   WHERE NAME = 'free memory'
  46.                     AND POOL = 'shared pool') FREE
  47.           FROM DUAL)

  48. UNION

  49. SELECT NAME,
  50.        ROUND(TOTAL, 2) TOTAL,
  51.        ROUND(TOTAL - FREE, 2) USED,
  52.        ROUND(FREE, 2) FREE,
  53.        ROUND((TOTAL - FREE) / TOTAL, 2) PCTUSED
  54.   FROM (
  55.         
  56.         SELECT 'Default pool' NAME,
  57.                 (SELECT A.CNUM_REPL *
  58.                         (SELECT VALUE
  59.                            FROM V$PARAMETER
  60.                           WHERE NAME = 'db_block_size') / 1024 / 1024 TOTAL
  61.                    FROM X$KCBWDS A, V$BUFFER_POOL P
  62.                  
  63.                   WHERE A.SET_ID = P.LO_SETID
  64.                     AND P.NAME = 'DEFAULT'
  65.                     AND P.BLOCK_SIZE =
  66.                         (SELECT VALUE
  67.                            FROM V$PARAMETER
  68.                           WHERE NAME = 'db_block_size')) TOTAL,
  69.                 
  70.                 (SELECT A.ANUM_REPL *
  71.                         (SELECT VALUE
  72.                            FROM V$PARAMETER
  73.                           WHERE NAME = 'db_block_size') / 1024 / 1024 FREE
  74.                    FROM X$KCBWDS A, V$BUFFER_POOL P
  75.                  
  76.                   WHERE A.SET_ID = P.LO_SETID
  77.                     AND P.NAME = 'DEFAULT'
  78.                     AND P.BLOCK_SIZE =
  79.                         (SELECT VALUE
  80.                            FROM V$PARAMETER
  81.                           WHERE NAME = 'db_block_size')) FREE
  82.           FROM DUAL)

  83. UNION

  84. SELECT NAME,
  85.        NVL(ROUND(TOTAL, 2), 0) TOTAL,
  86.        NVL(ROUND(TOTAL - FREE, 2), 0) USED,
  87.        NVL(ROUND(FREE, 2), 0) FREE,
  88.        NVL(ROUND((TOTAL - FREE) / TOTAL, 2), 0) PCTUSED
  89.   FROM (
  90.         
  91.         SELECT 'KEEP pool' NAME,
  92.                 (SELECT A.CNUM_REPL *
  93.                         (SELECT VALUE
  94.                            FROM V$PARAMETER
  95.                           WHERE NAME = 'db_block_size') / 1024 / 1024 TOTAL
  96.                    FROM X$KCBWDS A, V$BUFFER_POOL P
  97.                  
  98.                   WHERE A.SET_ID = P.LO_SETID
  99.                     AND P.NAME = 'KEEP'
  100.                     AND P.BLOCK_SIZE =
  101.                         (SELECT VALUE
  102.                            FROM V$PARAMETER
  103.                           WHERE NAME = 'db_block_size')) TOTAL,
  104.                 
  105.                 (SELECT A.ANUM_REPL *
  106.                         (SELECT VALUE
  107.                            FROM V$PARAMETER
  108.                           WHERE NAME = 'db_block_size') / 1024 / 1024 FREE
  109.                    FROM X$KCBWDS A, V$BUFFER_POOL P
  110.                  
  111.                   WHERE A.SET_ID = P.LO_SETID
  112.                     AND P.NAME = 'KEEP'
  113.                     AND P.BLOCK_SIZE =
  114.                         (SELECT VALUE
  115.                            FROM V$PARAMETER
  116.                           WHERE NAME = 'db_block_size')) FREE
  117.           FROM DUAL)

  118. UNION

  119. SELECT NAME,
  120.        NVL(ROUND(TOTAL, 2), 0) TOTAL,
  121.        NVL(ROUND(TOTAL - FREE, 2), 0) USED,
  122.        NVL(ROUND(FREE, 2), 0) FREE,
  123.        NVL(ROUND((TOTAL - FREE) / TOTAL, 2), 0) PCTUSED
  124.   FROM (
  125.         
  126.         SELECT 'RECYCLE pool' NAME,
  127.                 (SELECT A.CNUM_REPL *
  128.                         (SELECT VALUE
  129.                            FROM V$PARAMETER
  130.                           WHERE NAME = 'db_block_size') / 1024 / 1024 TOTAL
  131.                    FROM X$KCBWDS A, V$BUFFER_POOL P
  132.                  
  133.                   WHERE A.SET_ID = P.LO_SETID
  134.                     AND P.NAME = 'RECYCLE'
  135.                     AND P.BLOCK_SIZE =
  136.                         (SELECT VALUE
  137.                            FROM V$PARAMETER
  138.                           WHERE NAME = 'db_block_size')) TOTAL,
  139.                 
  140.                 (SELECT A.ANUM_REPL *
  141.                         (SELECT VALUE
  142.                            FROM V$PARAMETER
  143.                           WHERE NAME = 'db_block_size') / 1024 / 1024 FREE
  144.                    FROM X$KCBWDS A, V$BUFFER_POOL P
  145.                  
  146.                   WHERE A.SET_ID = P.LO_SETID
  147.                     AND P.NAME = 'RECYCLE'
  148.                     AND P.BLOCK_SIZE =
  149.                         (SELECT VALUE
  150.                            FROM V$PARAMETER
  151.                           WHERE NAME = 'db_block_size')) FREE
  152.           FROM DUAL)

  153. UNION

  154. SELECT NAME,
  155.        NVL(ROUND(TOTAL, 2), 0) TOTAL,
  156.        NVL(ROUND(TOTAL - FREE, 2), 0) USED,
  157.        NVL(ROUND(FREE, 2), 0) FREE,
  158.        NVL(ROUND((TOTAL - FREE) / TOTAL, 2), 0) PCTUSED
  159.   FROM (
  160.         
  161.         SELECT 'DEFAULT 16K buffer cache' NAME,
  162.                 (SELECT A.CNUM_REPL * 16 / 1024 TOTAL
  163.                    FROM X$KCBWDS A, V$BUFFER_POOL P
  164.                  
  165.                   WHERE A.SET_ID = P.LO_SETID
  166.                     AND P.NAME = 'DEFAULT'
  167.                     AND P.BLOCK_SIZE = 16384) TOTAL,
  168.                 
  169.                 (SELECT A.ANUM_REPL * 16 / 1024 FREE
  170.                    FROM X$KCBWDS A, V$BUFFER_POOL P
  171.                  
  172.                   WHERE A.SET_ID = P.LO_SETID
  173.                     AND P.NAME = 'DEFAULT'
  174.                     AND P.BLOCK_SIZE = 16384) FREE
  175.           FROM DUAL)

  176. UNION

  177. SELECT NAME,
  178.        NVL(ROUND(TOTAL, 2), 0) TOTAL,
  179.        NVL(ROUND(TOTAL - FREE, 2), 0) USED,
  180.        NVL(ROUND(FREE, 2), 0) FREE,
  181.        NVL(ROUND((TOTAL - FREE) / TOTAL, 2), 0) PCTUSED
  182.   FROM (
  183.         
  184.         SELECT 'DEFAULT 32K buffer cache' NAME,
  185.                 (SELECT A.CNUM_REPL * 32 / 1024 TOTAL
  186.                    FROM X$KCBWDS A, V$BUFFER_POOL P
  187.                  
  188.                   WHERE A.SET_ID = P.LO_SETID
  189.                     AND P.NAME = 'DEFAULT'
  190.                     AND P.BLOCK_SIZE = 32768) TOTAL,
  191.                 
  192.                 (SELECT A.ANUM_REPL * 32 / 1024 FREE
  193.                    FROM X$KCBWDS A, V$BUFFER_POOL P
  194.                  
  195.                   WHERE A.SET_ID = P.LO_SETID
  196.                     AND P.NAME = 'DEFAULT'
  197.                     AND P.BLOCK_SIZE = 32768) FREE
  198.           FROM DUAL)

  199. UNION

  200. SELECT NAME,
  201.        TOTAL,
  202.        TOTAL - FREE USED,
  203.        FREE,
  204.        (TOTAL - FREE) / TOTAL * 100 PCTUSED
  205.   FROM (
  206.         
  207.         SELECT 'Java Pool' NAME,
  208.                 (SELECT SUM(BYTES / 1024 / 1024) TOTAL
  209.                    FROM V$SGASTAT
  210.                   WHERE POOL = 'java pool'
  211.                   GROUP BY POOL) TOTAL,
  212.                 
  213.                 (SELECT BYTES / 1024 / 1024 FREE
  214.                    FROM V$SGASTAT
  215.                   WHERE POOL = 'java pool'
  216.                     AND NAME = 'free memory') FREE
  217.           FROM DUAL)

  218. UNION

  219. SELECT NAME,
  220.        ROUND(TOTAL, 2),
  221.        ROUND(TOTAL - FREE, 2) USED,
  222.        ROUND(FREE, 2) FREE,
  223.        ROUND((TOTAL - FREE) / TOTAL * 100, 2) PCTUSED
  224.   FROM (
  225.         
  226.         SELECT 'Large Pool' NAME,
  227.                 (SELECT SUM(BYTES / 1024 / 1024) TOTAL
  228.                    FROM V$SGASTAT
  229.                   WHERE POOL = 'large pool'
  230.                   GROUP BY POOL) TOTAL,
  231.                 
  232.                 (SELECT BYTES / 1024 / 1024 FREE
  233.                    FROM V$SGASTAT
  234.                   WHERE POOL = 'large pool'
  235.                     AND NAME = 'free memory') FREE
  236.           FROM DUAL)

  237.  ORDER BY PCTUSED DESC;

阅读(2341) | 评论(0) | 转发(0) |
0

上一篇:Oracle sql 日常积累

下一篇:Shell 日常收集

给主人留下些什么吧!~~