Oracle管理监控之Oracle数据库存储空间监控
1、监控表空间使用率
基表:dba_data_files、dba_free_space
脚本:
select a.tablespace_name,
round((a.maxbytes / 1024 / 1024 / 1024), 2) "sum G",
round((a.bytes / 1024 / 1024 / 1024), 2) "datafile G",
round(((a.bytes - b.bytes) / 1024 / 1024 / 1024), 2) "used G",
round(((a.maxbytes - a.bytes + b.bytes) / 1024 / 1024 / 1024), 2) "free G",
round(((a.bytes - b.bytes) / a.maxbytes) * 100, 2) "percent_used(%)"
from (select tablespace_name, sum(sumnow) bytes, sum(summax) maxbytes
from (select t1.tablespace_name,
sum(t1.bytes) sumnow,
sum(t1.maxbytes) summax
from dba_data_files t1
where t1.maxbytes <> 0
group by t1.tablespace_name
union all
select t2.tablespace_name,
sum(t2.bytes) sumnow,
sum(t2.bytes) summax
from dba_data_files t2
where t2.maxbytes = 0
group by t2.tablespace_name)
group by tablespace_name) a,
(select tablespace_name, sum(bytes) bytes
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name
order by ((a.bytes - b.bytes) / a.maxbytes) desc;
2、创建表空间时指定最大值时查询表空间使用率脚本:
select a.tablespace_name,
round((a.maxbytes / 1024 / 1024 / 1024), 2) "sum G",
round((a.bytes / 1024 / 1024 / 1024), 2) "datafile G",
round(((a.bytes - b.bytes) / 1024 / 1024 / 1024), 2) "used G",
round(((a.maxbytes - a.bytes + b.bytes) / 1024 / 1024 / 1024), 2) "free G",
round(((a.bytes - b.bytes) / a.maxbytes) * 100, 2) "percent_used(%)"
from (select tablespace_name, sum(bytes) bytes, sum(maxbytes) maxbytes
from dba_data_files
where maxbytes != 0
group by tablespace_name) a,
(select tablespace_name, sum(bytes) bytes
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name
order by ((a.bytes - b.bytes) / a.maxbytes) desc;
3、查看数据文件状态
select t.tablespace_name,
t.file_id,
t.file_name,
t.autoextensible,
ROUND(t.maxbytes / 1024 / 1024 / 1024, 2) || 'G' AS MAXBYTES,
ROUND(t.bytes / 1024 / 1024 / 1024, 2) || 'G' AS BYTES,
ROUND(t.user_bytes / 1024 / 1024 / 1024, 2) || 'G' AS USER_BYTES
from dba_data_files t;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了