温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

DBA巡检常用的SQL语句

发布时间:2020-06-03 05:56:35 来源:网络 阅读:1474 作者:z597011036 栏目:数据库

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=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;


6.查看临时表空间的使用率

select * from v$temp_space_header;


7.查看当前oracle用户的会话数

select username,count(username) from v$session where username is not null group by username;


8.查询表中某行在哪个数据文件

select a,rowid,dbms_rowid.rowid_relative_fno(rowid) || '_' || dbms_rowid.rowid_block_number(rowid) || '_' || dbms_rowid.rowid_row_number(rowid) as f_b_n from t where a=4;
A           ROWID           F_B_N
4    AAAUCYAABAAAXEpAAB       1_94505_1      --1表示第1个数据文件,94505表示第多少个块,1表示数据在表中每2行,因为每1行是0


9.通过sql_id找用户的id值

select distinct USER_ID from dba_hist_active_sess_history where sql_id='44u0yksh46aq2';


10.通过user_id查找用户

select user_id,username from dba_users where user_id=98;



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI