0

请向我咨询 - 获取我们数据库 (Oracle) 中可用/已用表空间报告的最佳方法是什么 - (表空间名称、可用 MB、已用 MB)

可能是 Oracle 有一些我想要的实用程序提供报告吗?或者如果没有,请咨询/建议其他方法。

带着敬意!

4

1 回答 1

1

sysdba以用户(或具有DBAor 角色的用户)身份在 SQL*Plus 中运行以下代码SELECT ANY DICTIONARY。最好将其保存为 SQL 文件(例如fs.sql)并使用@fs

它将报告每个表空间的有用信息,包括大小、可用 Mb %free 等

COLUMN ts_name   FORMAT A25       HEADING "Tablespace"
COLUMN ts_size   FORMAT 999,999.9 HEADING "Size mb"
COLUMN ts_free   FORMAT 999,999.9 HEADING "Free Mb"
COLUMN pct_free  FORMAT 999.99    HEADING "% free"
COLUMN max_size  FORMAT 999,999.9 HEADING "Max Mb"
COLUMN frags     FORMAT 99,999    HEADING "Frags"
COLUMN largest   FORMAT 9,999.99  HEADING "Largest"
COLUMN smallest  FORMAT 9,999.99  HEADING "Smallest"
COLUMN average   FORMAT 9,999.99  HEADING "Average"
COLUMN dfiles    FORMAT 999       HEADING "DFs"
COLUMN ts_type   FORMAT A4        HEADING "Type"
COLUMN ex        FORMAT A2        HEADING "Ex"
COLUMN status    FORMAT A7        HEADING "Status"
COLUMN big       FORMAT A3        HEADING "Big"

SET PAGESIZE 9999
SET NULL 0

SELECT  SUBSTR(t.tablespace_name, 1, 25) AS ts_name,
    ts.ts_size,
    CASE WHEN(t.contents = 'TEMPORARY') THEN
        ts.ts_size - NVL(te.free_space, 0)
    ELSE
        NVL(te.free_space, 0)
    END AS ts_free,
    CASE WHEN(t.contents = 'TEMPORARY') THEN
        100-(100*NVL(te.free_space, 0)/ts_size)
    ELSE
        100*NVL(te.free_space, 0)/ts_size
    END AS pct_free,
    ts.max_size,
    NVL(te.fragments, 0) AS frags,
    NVL(te.largest, 0) AS largest,
    NVL(te.smallest, 0) AS smallest,
    NVL(te.average, 0) AS average,
    ts.dfiles,
    SUBSTR(t.contents, 1, 4) AS ts_type,
    SUBSTR(t.extent_management,1 ,1) AS ex,
    t.status,
    DECODE(t.bigfile, 'NO', 'No', 'Yes') AS big
FROM
    dba_tablespaces t
LEFT
JOIN   (SELECT  tablespace_name,
        SUM(bytes)/1024/1024 AS ts_size,
        COUNT(bytes) AS dfiles,
        SUM(DECODE(maxbytes, 0, bytes, maxbytes))/1024/1024 AS max_size
    FROM
        dba_data_files
    GROUP
    BY  tablespace_name
    UNION
    SELECT  tablespace_name,
        SUM(bytes)/1024/1024 AS ts_size,
        COUNT(bytes) AS dfiles,
        SUM(DECODE(maxbytes, 0, bytes, maxbytes))/1024/1024 AS max_size
    FROM
        dba_temp_files
    GROUP
    BY  tablespace_name
       ) ts ON t.tablespace_name = ts.tablespace_name
LEFT
JOIN   (SELECT  tablespace_name,
        MAX(bytes)/1024/1024 AS largest,
        MIN(bytes)/1024/1024 AS smallest,
        COUNT(bytes) AS fragments,
        SUM(bytes)/1024/1024 AS free_space,
        ROUND(AVG(bytes))/1024/1024 AS average
    FROM
        dba_free_space
    GROUP
    BY  tablespace_name
    UNION
    SELECT  tu.tablespace,
        0 AS largest,
        0 AS smallest,
        0 AS fragments,
        SUM(tu.blocks * ts.block_size)/1048576 AS free_space,
        0 AS average
    FROM
        v$tempseg_usage tu
    LEFT
    JOIN    dba_tablespaces ts ON tu.tablespace = ts.tablespace_name
    GROUP
    BY  tu.tablespace   
       ) te ON t.tablespace_name = te.tablespace_name
ORDER
BY  t.tablespace_name
/

它适用于 10g 和 11g。

于 2012-09-18T07:38:12.237 回答