1.查看當前數據庫有多少process
sql
select count(1) from v$process;數據庫
2.查看當前數據庫有多少session(session=process*1.1)session
select count(1) from v$session;oracle
3.查看當前執行的SQL語句ide
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語句沒有顯示完就執行下面語句spa
select a.* from v$sql a where a.SQL_ID='686nqabc8sgs2' --686nqabc8sgs2爲上面語句的sql_idhash
4.查看錶空間名稱及大小it
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;io
--顯示錶空間名和表空間大小,大小是多少M.table
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='44u0yksh36aq2';
10.經過user_id查找用戶
select user_id,username from dba_users where user_id=98;