檢視所有表空間大小

2021-09-30 10:05:53 字數 4222 閱讀 1009

1. 檢視所有表空間大小

sql> select tablespace_name,sum(bytes)/1024/1024from dba_data_files

2  group by tablespace_name;

2. 已經使用的表空間大小

sql> select tablespace_name,sum(bytes)/1024/1024from dba_free_space

2  group by tablespace_name;

3. 所以使用空間可以這樣計算

select a.tablespace_name,total,free,total-free usedfrom

( select tablespace_name,sum(bytes)/1024/1024 totalfrom dba_data_files

group bytablespace_name) a,

( select tablespace_name,sum(bytes)/1024/1024 freefrom dba_free_space

group bytablespace_name) b

where a.tablespace_name=b.tablespace_name;

4. 下面這條語句檢視所有segment的大小。

select segment_name,sum(bytes)/1024/1024 fromuser_extents group by segment_name

5. 還有在命令**況下如何將結果放到乙個檔案裡。

sql> spool out.txt

sql> select * from v$database;

sql> spool off

select upper(f.tablespace_name) "表空間名",

d.tot_grootte_mb"表空間大小(m)",

d.tot_grootte_mb -f.total_bytes "已使用空間(m)",

to_char(round((d.tot_grootte_mb- f.total_bytes) / d.tot_grootte_mb * 100,

2),

'990.99') "使用比",

f.total_bytes "空閒空間(m)",

f.max_bytes "最大塊(m)"

from (selecttablespace_name,

round(sum(bytes) /(1024 * 1024), 2) total_bytes,

round(max(bytes) /(1024 * 1024), 2) max_bytes

fromsys.dba_free_space

group bytablespace_name) f,

(selectdd.tablespace_name,

round(sum(dd.bytes) /(1024 * 1024), 2) tot_grootte_mb

from sys.dba_data_filesdd

group bydd.tablespace_name) d

whered.tablespace_name = f.tablespace_name

order by 4 desc

--查詢表空間使用情況

selectupper(f.tablespace_name) "表空間名",

d.tot_grootte_mb"表空間小(m)",

d.tot_grootte_mb -f.total_bytes "已使用空間(m)",

to_char(round((d.tot_grootte_mb- f.total_bytes) / d.tot_grootte_mb * 100,2),'990.99') || '%' "使用比",

f.total_bytes "空閒空間(m)",

f.max_bytes "最塊(m)"

from (selecttablespace_name,

round(sum(bytes) /(1024 * 1024), 2) total_bytes,

round(max(bytes) /(1024 * 1024), 2) max_bytes

fromsys.dba_free_space

group bytablespace_name) f,

(selectdd.tablespace_name,

round(sum(dd.bytes)/ (1024 * 1024), 2) tot_grootte_mb

fromsys.dba_data_files dd

group bydd.tablespace_name) d

where d.tablespace_name= f.tablespace_name

order by 1

--查詢表空間的free space

selecttablespace_name,

count(*) as extends,

round(sum(bytes) /1024 / 1024, 2) as mb,

sum(blocks) as blocks

from dba_free_space

group bytablespace_name;

--查詢表空間的總容量

select tablespace_name,sum(bytes) / 1024 / 1024 as mb

from dba_data_files

group bytablespace_name;

--查詢表空間使用率

selecttotal.tablespace_name,

round(total.mb, 2) astotal_mb,

round(total.mb -free.mb, 2) as used_mb,

round((1 - free.mb /total.mb) * 100, 2) || '%' as used_pct

from (selecttablespace_name, sum(bytes) / 1024 / 1024 as mb

from dba_free_space

group bytablespace_name) free,

(selecttablespace_name, sum(bytes) / 1024 / 1024 as mb

from dba_data_files

group bytablespace_name) total

wherefree.tablespace_name = total.tablespace_name;

selectupper(f.tablespace_name) "表空間名",

d.tot_grootte_mb"表空間大小(m)",

d.tot_grootte_mb- f.total_bytes "已使用空間(m)",

to_char(round((d.tot_grootte_mb- f.total_bytes) /

d.tot_grootte_mb * 100,

2),'990.99') "使用比",

f.total_bytes"空閒空間(m)",

f.max_bytes"最大塊(m)"   from (selecttablespace_name,

round(sum(bytes)/

(1024 * 1024),

2) total_bytes,

round(max(bytes) /

(1024 * 1024),

2) max_bytes   fromsys.dba_free_space  groupbytablespace_name) f,

(selectdd.tablespace_name,

round(sum(dd.bytes)/ (1024 * 1024), 2) tot_grootte_mb   fromsys.dba_data_files dd   groupbydd.tablespace_name) d   where d.tablespace_name =f.tablespace_name   orderby4desc

檢視oracle表空間大小

1.檢視所有表空間大小 sql select tablespace name,sum bytes 1024 1024 from dba data files group by tablespace name 2.已經使用的表空間大小 sql select tablespace name,sum by...

檢視oracle表空間大小

select upper f.tablespace name 表空間名 d.tot grootte mb 表空間大小 m d.tot grootte mb f.total bytes 已使用空間 m to char round d.tot grootte mb f.total bytes d.tot...

DB2 檢視所有表空間占用磁碟空間大小

db2 檢視表空間使用情況,占用磁碟空間大小 select a.snapshot timestamp,a.tbsp name,b.tbsp type,a.tbsp state,a.tbsp usable pages b.tbsp page size 1024 1024 1024 as total,a...