- 表空间查询
select tablespace_name "表空间名称",
bytes "空间大小(G)",
free "未使用(G)",
bytes - free "已使用(G)",
used / bytes *100 "已用比例"
from (select a.tablespace_name,
floor(a.bytes/1024/1024/1024 ) bytes,
floor(b.free/1024/1024/1024 ) free,
floor(( a.bytes - b.free )/1024/1024/1024) used
from (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a --获取空间总量情况
inner join
(select tablespace_name,sum(bytes) free from dba_free_space group by tablespace_name) b --获取空余空间
on a.tablespace_name = b.tablespace_name) tb
;
2.数据文件路径及使用情况查询
select
b.tablespace_name "表空间名称",
b.file_name "文件名",
floor(b.bytes/1024/1024 ) "文件大小(M)",
(b.bytes/1024/1024-sum(nvl(a.bytes/1024/1024,0))) "文件已使用空间(M)",
sum(nvl(a.bytes/1024/1024,0)) "文件剩余空间(M)",
sum(nvl(a.bytes/1024/1024,0))/(b.bytes/1024/1024)*100 "文件未使用比例"
from dba_free_space a
inner join dba_data_files b
on a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.bytes
order by b.tablespace_name
;
3.数据库扩容,增加数据文件,SYSTEM 为用户名,根据自己的实际情况变更
alter tablespace SYSTEM add datafile '\data\oracle\oradata\db\datafile\db_check1.dbf' size 10g autoextend on ; --开启自动扩容,文件最大容量为32g