在Oracle中,有没有办法找到每个表空间的共享池使用情况?

时间:2014-04-02 18:18:43

标签: oracle shared-memory tablespace

我们目前维持N'每个Oracle实例的表空间。我们想看看我们是否可以扩展它。有没有办法找到每个表空间的共享池使用情况? Oracle是否也维护这些统计数据?

Oracle让我们可以访问许多视图,所以我想知道如何最好地处理这个问题。

3 个答案:

答案 0 :(得分:1)

您正在向应用程序添加其他自定义功能,因此使用表空间作为代理是不合适的。新功能对性能的影响将取决于新功能生成的工作负载,该工作负载与新代码引用所在的对象所在的表空间无关。对象所在的表空间不会影响性能

了解目前如何使用缓冲区缓存并不能让您深入了解如何使新块被缓存并迫使某些现有块更快老化的附加功能将会影响现有功能的表现。除非你有一个小玩具应用程序,缓冲区缓存将充满一些东西。但是,缓冲区缓存已满的事实并没有告诉您,为了支持新功能,在边缘处是否会老化的附加块是否会导致数百万个额外的物理读取或是否会对绩效没有影响。

但是,除了缓冲区缓存之外,新功能可能会通过消耗额外的CPU周期,对I / O子系统施加额外负载,或通过锁定会对现有功能性能产生负面影响的行来影响性能。从理论上讲,可以对其他功能部件如何影响现有系统进行一些估算。然而,对于胆小的人来说,这不是一项任务,这是一项相当复杂的工作。

幸运的是,由于您是构建新功能的人,因此您可以获得更轻松的解决方案。您可以在较低的环境中对现有应用程序进行基准测试,添加新功能,然后使用新功能对现有功能进行基准测试。这使您可以进行更多级别的比较 - 例如,您比较更改前后的事务时间,而不是测量CPU消耗等内容并尝试模拟这会影响事务处理时间。它通常更容易实现 - 您需要的只是某种负载测试,它以与生产中使用方式类似的方式运用现有功能。

答案 1 :(得分:0)

这能满足您的需求吗?

SELECT a.tablespace_name, a.file_name, a.bytes allocated_bytes, b.free_bytes 
FROM dba_data_files a, 
  (SELECT file_id, SUM(bytes) free_bytes FROM dba_free_space b GROUP BY file_id) b 
WHERE a.file_id=b.file_id ORDER BY a.tablespace_name;

答案 2 :(得分:0)

您可以运行此命令以获取共享内存池统计信息。不完全是你想要的,但可能会帮助你。

SET serveroutput on;

DECLARE
   object_mem       NUMBER;
   shared_sql       NUMBER;
   cursor_mem       NUMBER;
   mts_mem          NUMBER;
   used_pool_size   NUMBER;
   free_mem         NUMBER;
   pool_size        VARCHAR2 (512);                     -- Now from V$SGASTAT
BEGIN
   -- Stored objects (packages, views)
   SELECT SUM (sharable_mem)
     INTO object_mem
     FROM v$db_object_cache;

   -- Shared SQL -- need to have additional memory if dynamic SQL used
   SELECT SUM (sharable_mem)
     INTO shared_sql
     FROM v$sqlarea;

   -- User Cursor Usage -- run this during peak usage.
   --  assumes 250 bytes per open cursor, for each concurrent user.
   SELECT SUM (250 * users_opening)
     INTO cursor_mem
     FROM v$sqlarea;

   -- For a test system -- get usage for one user, multiply by # users
   -- select (250 * value) bytes_per_user
   -- from v$sesstat s, v$statname n
   -- where s.statistic# = n.statistic#
   -- and n.name = 'opened cursors current'
   -- and s.sid = 25;  -- where 25 is the sid of the process
   -- MTS memory needed to hold session information for shared server users
   -- This query computes a total for all currently logged on users (run
   --  multiply by # users.
   SELECT SUM (VALUE)
     INTO mts_mem
     FROM v$sesstat s, v$statname n
    WHERE s.statistic# = n.statistic# AND n.NAME = 'session uga memory max';

   -- Free (unused) memory in the SGA: gives an indication of how much memory
   -- is being wasted out of the total allocated.
   SELECT BYTES
     INTO free_mem
     FROM v$sgastat
    WHERE NAME = 'free memory' AND pool = 'shared pool';

   -- For non-MTS add up object, shared sql, cursors and 20% overhead.
   used_pool_size := ROUND (1.2 * (object_mem + shared_sql + cursor_mem));

   -- For MTS mts contribution needs to be included (comment out previous line)
   -- used_pool_size := round(1.2*(object_mem+shared_sql+cursor_mem+mts_mem));
   SELECT SUM (BYTES)
     INTO pool_size
     FROM v$sgastat
    WHERE pool = 'shared pool';

   -- Display results
   DBMS_OUTPUT.put_line ('Shared Pool Memory Utilization Report');
   DBMS_OUTPUT.put_line ('Obj mem:  ' || TO_CHAR (object_mem) || ' bytes');
   DBMS_OUTPUT.put_line ('Shared sql:  ' || TO_CHAR (shared_sql) || ' bytes');
   DBMS_OUTPUT.put_line ('Cursors:  ' || TO_CHAR (cursor_mem) || ' bytes');
   -- dbms_output.put_line ('MTS session: '||to_char (mts_mem) || ' bytes');
   DBMS_OUTPUT.put_line (   'Free memory: '
                         || TO_CHAR (free_mem)
                         || ' bytes '
                         || '('
                         || TO_CHAR (ROUND (free_mem / 1024 / 1024, 2))
                         || 'MB)'
                        );
   DBMS_OUTPUT.put_line (   'Shared pool utilization (total):  '
                         || TO_CHAR (used_pool_size)
                         || ' bytes '
                         || '('
                         || TO_CHAR (ROUND (used_pool_size / 1024 / 1024, 2))
                         || 'MB)'
                        );
   DBMS_OUTPUT.put_line (   'Shared pool allocation (actual):  '
                         || pool_size
                         || ' bytes '
                         || '('
                         || TO_CHAR (ROUND (pool_size / 1024 / 1024, 2))
                         || 'MB)'
                        );
   DBMS_OUTPUT.put_line (   'Percentage Utilized:  '
                         || TO_CHAR (ROUND (used_pool_size / pool_size * 100))
                        );
END;
/