ORACLE表空间信息查询
--查看表空间的使用率
准确的查询表空间使用率:
select a.tablespace_name,a.maxbytes/1024/1024 "总大小(M)",a.bytes/1024/1024 "已分配大小(M)",
(a.bytes-b.bytes)/1024/1024 "已使用大小(M)",b.bytes/1024/1024 "已分配未使用大小(M)",
round (((a.bytes-b.bytes)/a.maxbytes)*100,2) "已使用比例(%)" from
(select tablespace_name,sum(bytes) bytes,sum(maxbytes) maxbytes from dba_data_files where maxbytes > 0 group by tablespace_name) a,
(select tablespace_name,sum(bytes) bytes,max (bytes) largest from dba_free_space group by tablespace_name)b
where a.tablespace_name=b.tablespace_name
order by ((a.bytes-b.bytes)/a.bytes) desc
-------查询每个表空间文件的上限大小---------------------------------
SELECT T.TABLESPACE_NAME,D.FILE_NAME,
D.AUTOEXTENSIBLE,D.BYTES/1024/1024 "USED_SPACE",D.MAXBYTES/1024/1024 "MAX_SPACE(M)",D.STATUS
FROM DBA_TABLESPACES T,DBA_DATA_FILES D
WHERE T.TABLESPACE_NAME =D.TABLESPACE_NAME AND D.TABLESPACE_NAME='USERS'
ORDER BY TABLESPACE_NAME,FILE_NAME;
--查看表空间数量
select t1.name,t2.name from vdatafile t2 where t1.ts# = t2.ts#;
--增加表空间文件数量
ALTER TABLESPACE USERS ADD DATAFILE '+DATA/ora11g/datafile/users.003.dbf' size 500M autoextend on next 50M maxsize 30g;