查詢所有表空間的總容量、已經使用、剩餘、已經使用的百分比,增加容量!
/* 2008/06/16 星期一
*蒙昭良
*環境:linux5 + Oracle10gR2
*某系統出現空間不足,報錯!
*/
查詢所有表空間的總容量、已經使用、剩餘、已經使用的百分比!
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
一般來說可以把上面的複雜的查詢語句放入一個檔案中,需要時再呼叫,或者建立一個試圖,需要時可以查詢。
1 寫入檔案:#vi /home/mzl/percent_used_tablespace.sql
內容:
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
2 匯入:
SQL> @/home/mzl/percent_used_tablespace.sql
SQL> l
1 select a.tablespace_name,a.bytes "Sum",a.bytes-b.bytes "used",b.bytes "free",
2 round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"
3 from
4 (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
5 (select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
6 where a.tablespace_name=b.tablespace_name
7* order by ((a.bytes-b.bytes)/a.bytes) desc
SQL> /
TABLESPACE_NAME Sum used free percent_used
------------------------------ ---------- ---------- ---------- ------------
SYSTEM 513802240 510656512 3145728 99.39
SYSAUX 262144000 251199488 10944512 95.83
PIONEER_INDX 6291456 5242880 1048576 83.33
UNDOTBS2 52428800 40960000 11468800 78.13
PIONEER_DATA 8388608 6291456 2097152 75
EXAMPLE 104857600 71565312 33292288 68.25
USERS 5242880 3473408 1769472 66.25
PERFSTAT 524288000 150798336 373489664 28.76
PIONEER_UNDO 7340032 1376256 5963776 18.75
PAUL 5242880 65536 5177344 1.25
WENCHUAN 20971520 262144 20709376 1.25
11 rows selected.
或者建立檢視:
SQL>create view percent
SQL>as
SQL>select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",
SQL>round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"
SQL>from
SQL>(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
SQL>(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
SQL>where a.tablespace_name=b.tablespace_name
SQL>order by ((a.bytes-b.bytes)/a.bytes) desc;
SQL> select * from percent;
TABLESPACE_NAME Sum MB used MB free MB percent_used
------------------------------ ---------- ---------- ---------- ------------
SYSTEM 490 487 3 99.39
SYSAUX 250 239.5625 10.4375 95.83
PIONEER_INDX 6 5 1 83.33
UNDOTBS2 50 39.0625 10.9375 78.13
PIONEER_DATA 8 6 2 75
EXAMPLE 100 68.25 31.75 68.25
USERS 5 3.3125 1.6875 66.25
PERFSTAT 500 143.8125 356.1875 28.76
PIONEER_UNDO 7 1.3125 5.6875 18.75
PAUL 5 .0625 4.9375 1.25
WENCHUAN 20 .25 19.75 1.25
11 rows selected.
檢視錶空間的資料檔案是否是自動擴充套件:
SQL> l
1* select file_name,tablespace_name,autoextensible from dba_data_files
SQL> /
FILE_NAME TABLESPACE_NAME AUT
--------------------------------------------- ------------------------------ ---
/u01/app/oracle/oradata/orcl/risenet.dbf RISENET
/u01/app/oracle/oradata/orcl/perfstat.dbf PERFSTAT NO
/u01/app/oracle/oradata/orcl/example01.dbf EXAMPLE YES
/u01/disk1/users01.dbf USERS YES
/u01/app/oracle/oradata/orcl/sysaux01.dbf SYSAUX YES
/u01/app/oracle/oradata/orcl/undotbs01.dbf UNDOTBS1
/u01/disk2/system01.dbf SYSTEM YES
/u01/app/oracle/oradata/orcl/undotbs02.dbf UNDOTBS2 NO
/u01/disk1/pioneer_data.dbf PIONEER_DATA YES
/u01/disk2/pioneer_indx.dbf PIONEER_INDX NO
/u01/disk3/pioneer_undo.dbf PIONEER_UNDO NO
FILE_NAME TABLESPACE_NAME AUT
--------------------------------------------- ------------------------------ ---
/u01/app/oracle/oradata/orcl/paul01.dbf PAUL NO
/u01/disk1/wenchuan.dbf WENCHUAN NO
13 rows selected.
比如表空間PIONEER_INDX已經用了83.33%,資料檔案不能自動擴充套件,可以修改成自動擴充套件,以免資料寫滿資料檔案。
SQL> alter database
2 datafile '/u01/disk2/pioneer_indx.dbf' autoextend on;
Database altered.
SQL> select file_name,tablespace_name,autoextensible from dba_data_files
2 where tablespace_name='PIONEER_INDX';
FILE_NAME TABLESPACE_NAME AUT
--------------------------------------------- ------------------------------ ---
/u01/disk2/pioneer_indx.dbf PIONEER_INDX YES
或者給表空間多加一個自動擴充套件的資料檔案,如果有多個硬碟,可以增加多個資料檔案(這樣多資料庫系統的併發性比較好)
SQL> alter tablespace pioneer_indx
2 add datafile size 30M;
Tablespace altered.
SQL> select file_name,tablespace_name,bytes/1024/1024 "MB" from dba_data_files
2 where tablespace_name='PIONEER_INDX';
FILE_NAME TABLESPACE_NAME
--------------------------------------------- ------------------------------
MB
----------
/u01/disk2/pioneer_indx.dbf PIONEER_INDX
6
/u01/disk5/ORCL/datafile/o1_mf_pioneer__45dpy PIONEER_INDX
fty_.dbf
30
*蒙昭良
*環境:linux5 + Oracle10gR2
*某系統出現空間不足,報錯!
*/
查詢所有表空間的總容量、已經使用、剩餘、已經使用的百分比!
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
一般來說可以把上面的複雜的查詢語句放入一個檔案中,需要時再呼叫,或者建立一個試圖,需要時可以查詢。
1 寫入檔案:#vi /home/mzl/percent_used_tablespace.sql
內容:
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
2 匯入:
SQL> @/home/mzl/percent_used_tablespace.sql
SQL> l
1 select a.tablespace_name,a.bytes "Sum",a.bytes-b.bytes "used",b.bytes "free",
2 round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"
3 from
4 (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
5 (select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
6 where a.tablespace_name=b.tablespace_name
7* order by ((a.bytes-b.bytes)/a.bytes) desc
SQL> /
TABLESPACE_NAME Sum used free percent_used
------------------------------ ---------- ---------- ---------- ------------
SYSTEM 513802240 510656512 3145728 99.39
SYSAUX 262144000 251199488 10944512 95.83
PIONEER_INDX 6291456 5242880 1048576 83.33
UNDOTBS2 52428800 40960000 11468800 78.13
PIONEER_DATA 8388608 6291456 2097152 75
EXAMPLE 104857600 71565312 33292288 68.25
USERS 5242880 3473408 1769472 66.25
PERFSTAT 524288000 150798336 373489664 28.76
PIONEER_UNDO 7340032 1376256 5963776 18.75
PAUL 5242880 65536 5177344 1.25
WENCHUAN 20971520 262144 20709376 1.25
11 rows selected.
或者建立檢視:
SQL>create view percent
SQL>as
SQL>select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",
SQL>round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"
SQL>from
SQL>(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
SQL>(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
SQL>where a.tablespace_name=b.tablespace_name
SQL>order by ((a.bytes-b.bytes)/a.bytes) desc;
SQL> select * from percent;
TABLESPACE_NAME Sum MB used MB free MB percent_used
------------------------------ ---------- ---------- ---------- ------------
SYSTEM 490 487 3 99.39
SYSAUX 250 239.5625 10.4375 95.83
PIONEER_INDX 6 5 1 83.33
UNDOTBS2 50 39.0625 10.9375 78.13
PIONEER_DATA 8 6 2 75
EXAMPLE 100 68.25 31.75 68.25
USERS 5 3.3125 1.6875 66.25
PERFSTAT 500 143.8125 356.1875 28.76
PIONEER_UNDO 7 1.3125 5.6875 18.75
PAUL 5 .0625 4.9375 1.25
WENCHUAN 20 .25 19.75 1.25
11 rows selected.
檢視錶空間的資料檔案是否是自動擴充套件:
SQL> l
1* select file_name,tablespace_name,autoextensible from dba_data_files
SQL> /
FILE_NAME TABLESPACE_NAME AUT
--------------------------------------------- ------------------------------ ---
/u01/app/oracle/oradata/orcl/risenet.dbf RISENET
/u01/app/oracle/oradata/orcl/perfstat.dbf PERFSTAT NO
/u01/app/oracle/oradata/orcl/example01.dbf EXAMPLE YES
/u01/disk1/users01.dbf USERS YES
/u01/app/oracle/oradata/orcl/sysaux01.dbf SYSAUX YES
/u01/app/oracle/oradata/orcl/undotbs01.dbf UNDOTBS1
/u01/disk2/system01.dbf SYSTEM YES
/u01/app/oracle/oradata/orcl/undotbs02.dbf UNDOTBS2 NO
/u01/disk1/pioneer_data.dbf PIONEER_DATA YES
/u01/disk2/pioneer_indx.dbf PIONEER_INDX NO
/u01/disk3/pioneer_undo.dbf PIONEER_UNDO NO
FILE_NAME TABLESPACE_NAME AUT
--------------------------------------------- ------------------------------ ---
/u01/app/oracle/oradata/orcl/paul01.dbf PAUL NO
/u01/disk1/wenchuan.dbf WENCHUAN NO
13 rows selected.
比如表空間PIONEER_INDX已經用了83.33%,資料檔案不能自動擴充套件,可以修改成自動擴充套件,以免資料寫滿資料檔案。
SQL> alter database
2 datafile '/u01/disk2/pioneer_indx.dbf' autoextend on;
Database altered.
SQL> select file_name,tablespace_name,autoextensible from dba_data_files
2 where tablespace_name='PIONEER_INDX';
FILE_NAME TABLESPACE_NAME AUT
--------------------------------------------- ------------------------------ ---
/u01/disk2/pioneer_indx.dbf PIONEER_INDX YES
或者給表空間多加一個自動擴充套件的資料檔案,如果有多個硬碟,可以增加多個資料檔案(這樣多資料庫系統的併發性比較好)
SQL> alter tablespace pioneer_indx
2 add datafile size 30M;
Tablespace altered.
SQL> select file_name,tablespace_name,bytes/1024/1024 "MB" from dba_data_files
2 where tablespace_name='PIONEER_INDX';
FILE_NAME TABLESPACE_NAME
--------------------------------------------- ------------------------------
MB
----------
/u01/disk2/pioneer_indx.dbf PIONEER_INDX
6
/u01/disk5/ORCL/datafile/o1_mf_pioneer__45dpy PIONEER_INDX
fty_.dbf
30
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12778571/viewspace-349398/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- sql 查詢當前使用者所有表的容量SQL
- 查詢表空間容量時顯示大小為空的問題
- db2檢視錶空間和增加表空間容量DB2
- 通過MOVE PARTITION來回收已經使用的空間
- oracle 剩餘表空間查詢慢,解決辦法Oracle
- Oracle查詢表空間使用情況(經典篇)Oracle
- ORACLE查詢所有表空間使用情況Oracle
- ZT 透過MOVE PARTITION來回收已經使用的空間
- 詳細顯示資料表空間的使用率與剩餘空間的SQLSQL
- 查詢表空間的使用率
- 查詢已經刪除的procedure,view,functionViewFunction
- 臨時表空間的空間使用情況查詢
- 表空間使用量查詢
- 查詢表空間使用情況
- 查詢表的大小及表空間的使用情況
- 怎麼檢視oracle表空間,剩餘大小,表空間利用Oracle
- 查詢表空間使用情況的指令碼指令碼
- 查詢使用表空間的TABLE,INDEX,INDEX SUBPARTITIONIndex
- 查詢表空間的大小和使用率
- oracle 表空間,臨時表空間使用率查詢Oracle
- Softpedia:83%的受調查者已經在使用Windows 10FTPWindows
- oracle表空間使用率查詢Oracle
- Oracle查詢表空間使用情況Oracle
- 查詢表空間已使用空間和空閒空間的簡單檢視
- 查使用表空間的sessionSession
- 表空間使用情況查詢慢的處理
- oracle 查詢表空間使用率的語句Oracle
- 查詢資料庫已經安裝元件資料庫元件
- SQL Server如何查詢鎖已經kill lockSQLServer
- win10如何給系統盤增加容量 win10怎麼給已分配系統盤加容量Win10
- 臨時表空間和回滾表空間使用率查詢
- mysql資料庫容量查詢MySql資料庫
- 查詢表空間使用情況的簡單檢視
- Oracle 19c 線上縮減 UNDO 表空間 容量Oracle
- MYSQL中查詢資料庫設定多大,剩餘空間是多少(轉)MySql資料庫
- Oracle 查詢表大小以及表空間使用率Oracle
- oracle11g 查詢臨時表空間的使用率和正在使用臨時表空間的使用者Oracle
- boot分割槽剩餘空間不足boot