请咨询我 - 在我们的数据库(Oracle)中获取免费/已用表空间报告的最佳方法是什么 - (表空间名称,可用MB,已用MB)
可能是Oracle有一些实用程序提供我想要的报告吗? 如果没有,请咨询/建议其他方法。
关于!
答案 0 :(得分:1)
以sysdba
用户(或具有DBA
角色或SELECT ANY DICTIONARY
的用户)在SQL * Plus中运行以下代码。最好将其保存为SQL文件(例如fs.sql
)并使用@fs
它将报告每个表空间的有用内容,包括大小,免费Mb%免费等等
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。