Oracle之表空间扩容
--1.多个单表空间使用率
select b.tablespace_name,
b.file_name,
b.bytes/1024/1024 "Size(MB)",
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 "Used(MB)",
concat(substr((b.bytes-sum(nvl(a.bytes,0)))/(b.bytes)*100,1,5),'%') "usage rate"
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.bytes
order by b.tablespace_name;
-- 2.查询表空间使用情况
SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
D.TOT_GROOTTE_GB "总大小(GB)",
D.TOT_GROOTTE_GB - F.TOTAL_BYTES "已使用(GB)",
TO_CHAR(ROUND((D.TOT_GROOTTE_GB - F.TOTAL_BYTES) / D.TOT_GROOTTE_GB * 100
,2)
,'990.99') "使用比",
F.TOTAL_BYTES "空闲空间(GB)",
F.MAX_BYTES "最大块(GB)"
FROM (SELECT TABLESPACE_NAME,
SUM(BYTES) / (1024 * 1024 * 1024) TOTAL_BYTES,
MAX(BYTES) / (1024 * 1024 * 1024) MAX_BYTES
FROM SYS.DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F,
(SELECT DD.TABLESPACE_NAME,
SUM(DD.BYTES) / (1024 * 1024 * 1024) TOT_GROOTTE_GB
FROM SYS.DBA_DATA_FILES DD
GROUP BY DD.TABLESPACE_NAME) D
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
ORDER BY 4 DESC;
--3.表空间扩容Sql
ALTER TABLESPACE 表空间名字 ADD DATAFILE
'+DATA01/data/datafile/link_index20200909' SIZE 20G;