oracle筆記整理16——表空間利用率、鎖表、鎖包、dbms_job操作
阿新 • • 發佈:2019-02-19
select * from (select a.TABLESPACE_NAME Tablespace_Name,
sum(a.bytes / 1024 / 1024) total_size,
sum(nvl(b.free_space1 / 1024 / 1024, 0)) nouse_space,
sum(a.bytes / 1024 / 1024) -
sum(nvl(b.free_space1 / 1024 / 1024, 0)) used_space,
round((sum(a.bytes / 1024 / 1024) -
sum(nvl(b.free_space1 / 1024 / 1024, 0))) * 100 /
sum(a.bytes / 1024 / 1024),
2) used_pres
from dba_data_files a,
(select sum(nvl(bytes, 0)) free_space1, file_id
from dba_free_space
group by file_id) b
where a.file_id = b.file_id(+)
and a.tablespace_name not in
(select value
from v$spparameter
where name = 'undo_tablespace')
group by a.TABLESPACE_NAME)
--------------------
union all
select tablespace_name,
(select sum(bytes_used) / 1024 / 1024
from v$temp_space_header
where tablespace_name = a.tablespace_name) total_size,
(select sum(bytes_used) / 1024 / 1024
from v$temp_space_header
where tablespace_name = a.tablespace_name) -
nvl((select sum(su.blocks *
to_number(rtrim(p.value))) / 1024 / 1024 as Space
from v$sort_usage su, v$parameter p
where p.name = 'db_block_size'
and su.TABLESPACE = a.tablespace_name),
0) nouse_space,
nvl((select sum(su.blocks *
to_number(rtrim(p.value))) / 1024 / 1024 as Space
from v$sort_usage su, v$parameter p
where p.name = 'db_block_size'
and su.TABLESPACE = a.tablespace_name),
0) used_space,
round(nvl((select sum(su.blocks *
to_number(rtrim(p.value))) / 1024 / 1024 as Space
from v$sort_usage su,
v$parameter p
where p.name = 'db_block_size'
and su.TABLESPACE =
a.tablespace_name) /
(select sum(bytes_used) / 1024 / 1024
from v$temp_space_header
where tablespace_name =
a.tablespace_name) * 100,
0),
2) used_pres
from (select distinct tablespace_name
from v$temp_space_header) a
union all
-------------------------
select a.tablespace_name,
total_undo total_size,
total_undo - used_undo nouse_space,
used_undo used_space,
trunc(used_undo / total_undo * 100, 2) used_pres
from (select nvl(sum(bytes / 1024 / 1024), 0) used_undo,
tablespace_name
from dba_undo_extents
where status = 'ACTIVE'
group by tablespace_name) a,
(select tablespace_name,
sum(bytes / 1024 / 1024) total_undo
from dba_data_files
where tablespace_name in
(select value
from v$spparameter
where name = 'undo_tablespace')
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name;