查看Oracle表空間大小的方法
Oracle表空間大小的查看方法應(yīng)該是我們都需要掌握的知識,下面就為您詳細介紹查看Oracle表空間大小的方法,供您參考學(xué)習(xí)。
在數(shù)據(jù)庫管理中,磁盤空間不足是DBA都會遇到的問題,問題比較常見。
--1查看Oracle表空間大小--已經(jīng)使用的百分比。
- select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"
- from
- (select tablespace_name,sum(bytes) bytes from dba_data_files 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
“Sum MB”表示表空間所有的數(shù)據(jù)文件總共在操作系統(tǒng)占用磁盤空間的大小
比如:test表空間有2個數(shù)據(jù)文件,datafile1為300MB,datafile2為400MB,那么test表空間的“Sum MB”就是700MB
“userd MB”表示表空間已經(jīng)使用了多少
“free MB”表示表空間剩余多少
“percent_user”表示已經(jīng)使用的百分比
--2比如從1中查看到MLOG_NORM_SPACE表空間已使用百分比達到90%以上,可以查看該表空間總共有幾個數(shù)據(jù)文件,每個數(shù)據(jù)文件是否自動擴展,可以自動擴展的***值。
- select file_name,tablespace_name,bytes/1024/1024 "bytes MB",maxbytes/1024/1024 "maxbytes MB" from dba_data_files
- where tablespace_name='MLOG_NORM_SPACE';
--3比如MLOG_NORM_SPACE表空間目前的大小為19GB,但***每個數(shù)據(jù)文件只能為20GB,數(shù)據(jù)文件快要寫滿,可以增加表空間的數(shù)據(jù)文件
用操作系統(tǒng)UNIX、Linux中的df -g命令(查看下可以使用的磁盤空間大小)
獲取創(chuàng)建表空間的語句:
- select dbms_metadata.get_ddl('TABLESPACE','MLOG_NORM_SPACE') from dual;
--4確認磁盤空間足夠,增加一個數(shù)據(jù)文件
- alter tablespace MLOG_NORM_SPACE
- add datafile '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'
- size 10M autoextend on maxsize 20G
--5驗證已經(jīng)增加的數(shù)據(jù)文件
- select file_name,file_id,tablespace_name from dba_data_files
- where tablespace_name='MLOG_NORM_SPACE'
--6如果刪除表空間數(shù)據(jù)文件,如下:
- alter tablespace MLOG_NORM_SPACE
- drop datafile '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'
【編輯推薦】