檢視 Oracle 表空間使用率

2021-04-27 23:28:41 字數 1279 閱讀 7436

1、 用到了 sys.dba_free_space、sys.dba_data_files 兩個檢視,需要被賦予在這兩個檢視物件上的查詢許可權。

-- connect as sysdba

grant select on sys.dba_free_space to forrest; 

grant select on sys.dba_data_files to forrest; 

檢視 oracle 表空間使用率 

-- connect as forrest

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 (select tablespace_name, round(sum(bytes) / (1024 * 1024), 2) total_bytes, round(max(bytes) / (1024 * 1024), 2) max_bytes from sys.dba_free_space group by tablespace_name) f, (select dd.tablespace_name, round(sum(dd.bytes) / (1024 * 1024), 2) tot_grootte_mb from sys.dba_data_files dd group by dd.tablespace_name) d where d.tablespace_name = f.tablespace_name order by f.tablespace_name;

2、select b.file_id 檔案id,b.tablespace_name 表空間,b.file_name 物理檔名,b.bytes/1024/1024 總位元組數,(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 已使用,sum(nvl(a.bytes,0))/1024/1024 剩餘,sum(nvl(a.bytes,0))/(b.bytes)*100 剩餘百分比 from dba_free_space a,dba_data_files b where a.file_id=b.file_id group by b.tablespace_name,b.file_name,b.file_id,b.bytes order by b.file_name

ORACLE檢視表空間使用率

之前寫程式需要實現乙個查詢資料庫表空間使用率的功能,雖然不知道做它的意義有多大,專案要求就得做。寫了乙個,只能查到永久表空間,temp表空間不知道怎麼查詢,今天上網找了找,把sql補充完整了,其實都是找來現有的資源用的,收藏一下。select from select a.tablespace nam...

表空間使用率

檢視表空間名稱 大小 使用大小 剩餘大小和使用率 select a.tablespace name 表空間名稱 total 1024 1024 表空間大小 m free 1024 1024 表空間剩餘大小 m total free 1024 1024 表空間使用大小 m total 1024 102...

表空間使用率查詢

select a.file id 檔案號,a.tablespace name 表空間名稱,b.file name 物理檔名,b.autoextensible 自動擴充套件,b.maxbytes 1024 1024 1024 最大空間g,total 1024 1024 表空間mb,free 1024 ...