ORACLE檢視表空間使用率

2021-05-22 20:44:08 字數 1514 閱讀 8770

之前寫程式需要實現乙個查詢資料庫表空間使用率的功能,雖然不知道做它的意義有多大,專案要求就得做。

寫了乙個,只能查到永久表空間,temp表空間不知道怎麼查詢,今天上網找了找,把sql補充完整了,其實都是找來現有的資源用的,收藏一下。

select *

from (select a.tablespace_name tablespacename,

nvl(a.bytes / 1024 / 1024,0) totalsize,

nvl(b.largest / 1024 / 1024,0) freesize,

nvl((a.bytes - b.bytes) / 1024 / 1024,0) usedsize,

round(nvl((a.bytes - b.bytes) / a.bytes * 100, 0), 2) usedpercent

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.tablespace_name)

union

select d.tablespace_name tablespacename,

nvl(a.bytes / 1024 / 1024, 0) totalsize,

nvl(a.bytes / 1024 / 1024, 0) - nvl(t.bytes, 0) / 1024 / 1024 freesize,

nvl(t.bytes, 0) / 1024 / 1024 usedsize,

round(nvl(t.bytes / a.bytes * 100, 0), 2) usedpercent

from sys.dba_tablespaces d,

(select tablespace_name, sum(bytes) bytes

from dba_temp_files

group by tablespace_name) a,

(select tablespace_name, sum(bytes_cached) bytes

from v$temp_extent_pool

group by tablespace_name) t

where d.tablespace_name = a.tablespace_name(+)

and d.tablespace_name = t.tablespace_name(+)

and d.extent_management like 'local'

and d.contents like 'temporary'

Oracle 檢視表空間使用率 SQL 指令碼

sql 語句 formatted on 2012 5 31 14 51 13 qp5 v5.185.11230.41888 select d.tablespace name,space m sum space m blocks sum blocks space nvl free space,0 m ...

oracle檢視表空間使用率及擴容

oracle表空間使用率檢視,首先登入,sysdba使用者,select tablespace name 表空間 to char round bytes 1024,2 99990.00 實有 to char round free 1024,2 99990.00 g 現有 to char round ...

檢視 Oracle 表空間使用率

1 用到了 sys.dba free space sys.dba data files 兩個檢視,需要被賦予在這兩個檢視物件上的查詢許可權。connect as sysdba grant select on sys.dba free space to forrest grant select on ...