客製自己想要的報表,好處之一是可以滿足自己的需求,好處之二就是你得要求自己去研究那些資訊要如何取得,從中也順便對DB有進一步的了解,也是自學的好方法之一!
因為小弟對MS SQL較熟悉,所以就想到用Reporting Services 2008 R2作為我報表呈現的工具,來去取得Oracle的資料,Reporting Services可以呈現精美的報表,也有訂閱的功能可以把報表送出,很方便喔
以下就先分享Tablespace Usage的報表
SELECT d.tablespace_name,
ROUND (a.total / 1024, 2) "Total",
ROUND (F.FREE / 1024, 2) "Free",
ROUND ( (F.FREE / a.TOTAL) * 100) "Free%",
d.STATUS,
d.CONTENTS
FROM dba_tablespaces d,
( SELECT tablespace_name, SUM (bytes / (1024 * 1024)) total
FROM dba_data_files
GROUP BY tablespace_name) a,
( SELECT TABLESPACE_NAME, ROUND (SUM (BYTES / (1024 * 1024))) FREE
FROM DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F
WHERE d.TABLESPACE_NAME = a.TABLESPACE_NAME
AND D.TABLESPACE_NAME = f.TABLESPACE_NAME(+)
ORDER BY "Free%";針對每個Tablespace可以再點進去看datafile的明細喔,如下
SELECT SUBSTR (df.tablespace_name, 1, 20) "Tablespace Name",
SUBSTR (df.file_name, 1, 80) "File Name",
V.Creation_Time,
V.Status,
V.Enabled,
ROUND (df.bytes / 1024 / 1024, 0) "Size_MB",
ROUND (df.increment_by * (df.bytes / df.blocks) / 1024 / 1024, 2)
"Increment By (M)",
ROUND (df.maxbytes / 1024 / 1024, 2) "Max Size (M)",
DECODE (e.used_bytes, NULL, 0, ROUND (e.used_bytes / 1024 / 1024, 0))
"Used (M)",
DECODE (f.free_bytes, NULL, 0, ROUND (f.free_bytes / 1024 / 1024, 0))
"Free (M)",
DECODE (e.used_bytes,
NULL, 0,
ROUND ( (e.used_bytes / df.bytes) * 100, 0))
"Used_Perc",
df.Autoextensible
FROM DBA_DATA_FILES DF,
( SELECT file_id, SUM (bytes) used_bytes
FROM dba_extents
GROUP BY file_id) E,
( SELECT MAX (bytes) free_bytes, file_id
FROM dba_free_space
GROUP BY file_id) f,
v$datafile v
WHERE e.file_id(+) = df.file_id
AND df.file_id = f.file_id(+)
AND df.File_Id = v.File#
AND df.Tablespace_Name = :Name;
最後RS的Sample也分享給各位吧!
4/5 更新
發現似乎漏掉了TEMPORARY的Tablespace了,補上修正的
SELECT
d.tablespace_name,
ROUND (a.total
/
1024, 2)
"Total",
ROUND (F.FREE
/
1024, 2)
"Free",
ROUND (
(F.FREE
/
a.TOTAL)
* 100) "Free%",
d.STATUS,
d.CONTENTS
FROM
dba_tablespaces d,
( SELECT
tablespace_name, SUM
(bytes
/
(1024 * 1024))
total
FROM
dba_data_files
GROUP BY
tablespace_name
union
SELECT
tablespace_name, SUM
(bytes
/
(1024 * 1024))
total
FROM
DBA_TEMP_FILES
GROUP
BY
tablespace_name) a,
( SELECT
TABLESPACE_NAME, ROUND
(SUM
(BYTES
/
(1024 * 1024)))
FREE
FROM
DBA_FREE_SPACE
GROUP BY
TABLESPACE_NAME
union
SELECT
TABLESPACE_NAME, ROUND
((FREE_SPACE
/
(1024 * 1024)))
FREE
FROM
DBA_TEMP_FREE_SPACE) F
WHERE d.TABLESPACE_NAME
=
a.TABLESPACE_NAME
AND
D.TABLESPACE_NAME =
f.TABLESPACE_NAME(+)
ORDER BY
"Free%";
0 意見:
張貼留言