首页 > 代码库 > DBA巡检常用的SQL语句

DBA巡检常用的SQL语句

1.查看当前数据库有多少process

select count(1) from v$process;


2.查看当前数据库有多少session(session=process*1.1)

select count(1) from v$session;


3.查看当前执行的SQL语句

select a.program,b.spid,c.sql_text,c.sql_id from v$session a,v$process b,v$sqlarea c where a.paddr=b.addr and a.sql_hash_value=http://www.mamicode.com/c.hash_value; --如果SQL语句没有显示完就执行下面语句

select a.* from v$sql a where a.SQL_ID=‘686nqabc8sgs2‘    --686nqabc8sgs2为上面语句的sql_id


4.查看表空间名称及大小

select t.tablespace_name, round(SUM(bytes/(1024 * 1024)),0) ts_size from dba_tablespaces t, dba_data_files d where t.tablespace_name = d.tablespace_name group by t.tablespace_name;

--显示表空间名和表空间大小,大小是多少M.


5. 计算表空间数据文件使用情况

select a.tablespace_name, total, free, total-free as used from (select tablespace_name, sum(bytes)/1024/1024 as total from dba_data_files group by tablespace_name) a,(select tablespace_name, sum(bytes)/1024/1024 as free from dba_free_space group by tablespace_name) b where a.tablespace_name = b.tablespace_name;

本文出自 “一起走过的日子” 博客,请务必保留此出处http://tongcheng.blog.51cto.com/6214144/1928457

DBA巡检常用的SQL语句