一线运维 dba 五年经验常用 sql 大全(一)
作者:jiekexu
原文链接:https://mp.weixin.qq.com/s/yrtqgr9nk-yx4bkth9nvxq
来源 | jiekexu dba之路(id: jiekexu_it)
转载请联系授权 | (微信id:jiekexu_dba)
本文 sql 均是在运维工作中总结整理而成的,对于运维 dba 来说可提高很大工作效率,当然如果你全部能
够背下来那就牛逼了,
如果不能,建议收藏下来慢慢看,每条 sql 的使用频率都很高,肯定能够帮助到你。
当然,由于本编辑器原因以下 sql 可能出现格式错误不能执行,导致出错,这里将其保存至文本文件中方便
复制粘贴执行,
如有小伙伴感觉不错,可关注公众号【jiekexu dba之路】一起交流学习。
1.查看表空间使用率。
set line 220
select total.tablespace_name,round(total.mb, 2) as total_mb,round(total.mb -
free.mb, 2) as used_mb,round((1 - free.mb / total.mb) * 100, 2) || '%' as
used_pct
from (select tablespace_name,sum(bytes) / 1024 / 1024 as mb from dba_free_space
group by tablespace_name) free,
(select tablespace_name,sum(bytes) / 1024 / 1024 as mb from dba_data_files group
by tablespace_name) total
where free.tablespace_name = total.tablespace_name order by used_pct desc;
1.1查询单个表空间使用率。
select total.tablespace_name,
round(total.mb, 2) as total_mb,
round(total.mb - free.mb, 2) as used_mb,
round((1 - free.mb / total.mb) * 100, 2) || '%' as used_pct from
(select tablespace_name,sum(bytes) / 1024 / 1024 as mb from dba_free_space where
tablespace_name='tbl_space' group by tablespace_name) free,
(select tablespace_name,sum(bytes) / 1024 / 1024 as mb from dba_data_files where
tablespace_name='tbl_space' group by tablespace_name) total
where free.tablespace_name = total.tablespace_name order by used_pct desc;
2.查看临时表空间数据文件位置,大小,及是否自动扩展。
select tablespace_name,file_name,bytes/1024/1024 mb ,autoextensible from
dba_data_files where tablespace_name in ('') order by tablespace_name;
select tablespace_name,file_name,bytes/1024/1024 file_size,autoextensible from
dba_temp_files;
--查看所有临时表空间大小
select d.tablespace_name,space "sum_space(m)",blocks sum_blocks,
used_space "used_space(m)",round(nvl(used_space,0)/space*100,2) "used_rate(%)",
nvl(free_space,0) "free_space(m)"
from
(select tablespace_name,round(sum(bytes)/(1024*1024),2) space,sum(blocks) blocks
from dba_temp_files
group by tablespace_name) d,
(select tablespace_name,round(sum(bytes_used)/(1024*1024),2) used_space,
round(sum(bytes_free)/(1024*1024),2) free_space
from v$temp_space_header
group by tablespace_name) f
where d.tablespace_name = f.tablespace_name( );
3.查看asm磁盘空间。
select name,state,type,free_mb,total_mb,usable_file_mb from v$asm_diskgroup;
4.查询oracle的连接数
select count(*) from v$session;
5.查看不同用户的连接数
select username,count(username) from v$session where username is not null group
by username;
6.查看回收站
show recyclebin
7.清空回收站
文档被以下合辑收录
评论