感覺上, Oracle 的 table space 和 MS-SQL 的 DB 是一樣的。都是用來指定實體檔案。
google 到的範例居然有小 bug, 記錄一個修正版如下:
CREATE TABLESPACE TABPE_SPACE_NAME
DATAFILE 'TABPE_SPACE_NAME.dbf'
SIZE 1m
AUTOEXTEND ON;
完成之後,可以列出所有 table space:
SELECT A.TABLESPACE_NAME, A.FILE_NAME,
ROUND(B.FREE_GB,2) AS FREE_GB ,
ROUND(A.TOTAL_GB - b.FREE_GB) AS USED_GB ,
ROUND(A.TOTAL_GB,2) AS TOTAL_GB ,
ROUND(((A.TOTAL_GB - B.FREE_GB)/ A.TOTAL_GB )*100,2) AS USED_PERCENT,
ROUND((B.FREE_GB/ A.TOTAL_GB )*100,2) AS FREE_PERCENT
FROM
(
SELECT TABLESPACE_NAME, FILE_NAME,
SUM(BYTES)/ (1024*1024*1024) AS TOTAL_GB
FROM DBA_DATA_FILES
-- WHERE TABLESPACE_NAME='My_TableSpace_Name'
GROUP BY TABLESPACE_NAME, FILE_NAME
)A,
(
SELECT TABLESPACE_NAME,
SUM(BYTES) / (1024*1024*1024) AS FREE_GB
FROM DBA_FREE_SPACE
-- WHERE TABLESPACE_NAME='My_TableSpace_Name'
GROUP BY TABLESPACE_NAME
) B
WHERE A.TABLESPACE_NAME= B.TABLESPACE_NAME ;