数据库
首页 > 数据库> > Oracle数据库多个表空间使用情况查询

Oracle数据库多个表空间使用情况查询

作者:互联网

-- 1. 统计数据表空间
select a.tablespace_name,a.total_tbs,b.one_tbs,f_data_div(one_tbs,total_tbs) from
(select tablespace_name,round(sum(bytes)/1024/1024,0) total_tbs from dba_data_files
where tablespace_name in ('xxxx_TABLESPACE','xxxx','xxxx_TABLESPACE')
group by tablespace_name) a
LEFT JOIN
(select tablespace_name,round(sum(bytes)/1024/1024,0) one_tbs from dba_segments
where tablespace_name in ('xxxx_TABLESPACE','xxxx','xxxx_TABLESPACE')
group by tablespace_name) b
ON a.tablespace_name = b.tablespace_name
order by f_data_div(one_tbs,total_tbs) desc;

-- 2. 查看正在执行的SQL脚本
select b.sql_text,a.* from gv$session a,gv$sqlarea b
where a.sql_id = b.sql_id
and b.sql_text <> 'SELECT sysdate FROM dual' ;

-- 3. 查询死锁
select c.sid,
c.SERIAL#,
a.OBJECT_ID,
a.ORACLE_USERNAME,
a.OS_USER_NAME,
b.object_name,
d.sql_text
from gv$locked_object a, dba_objects b, gv$session c,gv$sqlarea d
where a.OBJECT_Id = b.object_id
and a.SESSION_ID = c.SId
and c.sql_id=d.sql_id ;

-- 4. 查询当前数据库连接数(1节点1690;2节点230,如果1节点超过2000,需要预警)
select inst_id,count(*)  from gv$session
group by inst_id;

标签:gv,name,数据库,查询,tablespace,sql,Oracle,tbs,select
来源: https://www.cnblogs.com/zhangkaimin/p/15348569.html