Oracle查詢表空間使用情況
轉載於-->>http://www.cnblogs.com/askjacklin/archive/2012/06/04/2534571.html
SELECT UPPER(F.TABLESPACE_NAME) "表空間名",
D.TOT_GROOTTE_MB "表空間大小(M)",
D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空間(M)",
TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2),'990.99') || '%' "使用比",
F.TOTAL_BYTES "空閒空間(M)",
F.MAX_BYTES "最大塊(M)"
FROM (SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,
ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
FROM SYS.DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F,
(SELECT DD.TABLESPACE_NAME,
ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
FROM SYS.DBA_DATA_FILES DD
GROUP BY DD.TABLESPACE_NAME) D
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
ORDER BY 1;
--查詢表空間的free space
select tablespace_name,
count(*) as extends,
round(sum(bytes) / 1024 / 1024, 2) as MB,
sum(blocks) as blocks
from dba_free_space
group by tablespace_name;
--查詢表空間的總容量
select tablespace_name, sum(bytes) / 1024 / 1024 as MB
from dba_data_files
group by tablespace_name;
--查詢表空間使用率
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;
1.查詢當前表級鎖的SQL如下:
select sess.sid,
sess.serial#,
lo.oracle_username,
lo.os_user_name,
ao.object_name,
lo.locked_mode
from v$locked_object lo,
dba_objects ao,
v$session sess
where ao.object_id = lo.object_id and lo.session_id = sess.sid;
2.殺掉鎖表程式:
alter system kill session '436,35123';
3.RAC環境中鎖查詢:
SELECT inst_id,DECODE(request,0,'Holder: ','Waiter: ')||sid sess,
id1, id2, lmode, request, type,block,ctime
FROM GV$LOCK
WHERE (id1, id2, type) IN
(SELECT id1, id2, type FROM GV$LOCK WHERE request>0)
ORDER BY id1, request;
4.監控當前資料庫誰在執行什麼SQL語句
select osuser, username, sql_text
from v$session a, v$sqltext b
where a.sql_address =b.address order by address, piece;
5.找使用CPU多的使用者session
select a.sid,spid,status,substr(a.program,1,40) prog, a.terminal,osuser,value/60/100 value
from v$session a,v$process b,v$sesstat c
where c.statistic#=12 and
c.sid=a.sid and
a.paddr=b.addr
order by value desc;
6.檢視死鎖資訊
SELECT (SELECT username
FROM v$session
WHERE SID = a.SID) blocker, a.SID, 'is blocking',
(SELECT username
FROM v$session
WHERE SID = b.SID) blockee, b.SID
FROM v$lock a, v$lock b
WHERE a.BLOCK = 1 AND b.request > 0 AND a.id1 = b.id1 AND a.id2 = b.id2;
7.具有最高等待的物件
SELECT o.OWNER,o.object_name, o.object_type, a.event,
SUM (a.wait_time + a.time_waited) total_wait_time
FROM v$active_session_history a, dba_objects o
WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE
AND a.current_obj# = o.object_id
GROUP BY o.OWNER,o.object_name, o.object_type, a.event
ORDER BY total_wait_time DESC;
SELECT a.session_id, s.osuser, s.machine, s.program, o.owner, o.object_name,
o.object_type, a.event,
SUM (a.wait_time + a.time_waited) total_wait_time
FROM v$active_session_history a, dba_objects o, v$session s
WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE
AND a.current_obj# = o.object_id
AND a.session_id = s.SID
GROUP BY o.owner,
o.object_name,
o.object_type,
a.event,
a.session_id,
s.program,
s.machine,
s.osuser
ORDER BY total_wait_time DESC;
8.查詢當前連線會話數
select s.value,s.sid,a.username
from
v$sesstat S,v$statname N,v$session A
where
n.statistic#=s.statistic# and
name='session pga memory'
and s.sid=a.sid
order by s.value;
9.等待最多的使用者
SELECT s.SID, s.username, SUM (a.wait_time + a.time_waited) total_wait_time
FROM v$active_session_history a, v$session s
WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE
GROUP BY s.SID, s.username
ORDER BY total_wait_time DESC;
10.等待最多的SQL
SELECT a.program, a.session_id, a.user_id, d.username, s.sql_text,
SUM (a.wait_time + a.time_waited) total_wait_time
FROM v$active_session_history a, v$sqlarea s, dba_users d
WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE
AND a.sql_id = s.sql_id
AND a.user_id = d.user_id
GROUP BY a.program, a.session_id, a.user_id, s.sql_text, d.username;
11.檢視消耗資源最多的SQL
SELECT hash_value, executions, buffer_gets, disk_reads, parse_calls
FROM V$SQLAREA
WHERE buffer_gets > 10000000 OR disk_reads > 1000000
ORDER BY buffer_gets + 100 * disk_reads DESC;
12.檢視某條SQL語句的資源消耗
SELECT hash_value, buffer_gets, disk_reads, executions, parse_calls
FROM V$SQLAREA
WHERE hash_Value = 228801498 AND address = hextoraw('CBD8E4B0');
13.查詢會話執行的實際SQL
SELECT a.SID, a.username, s.sql_text
FROM v$session a, v$sqltext s
WHERE a.sql_address = s.address
AND a.sql_hash_value = s.hash_value
AND a.status = 'ACTIVE'
ORDER BY a.username, a.SID, s.piece;
14.顯示正在等待鎖的所有會話
SELECT * FROM DBA_WAITERS;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29119536/viewspace-1126879/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 查詢表空間使用情況
- 查詢表空間使用情況的指令碼指令碼
- CentOS 系統的磁碟空間佔用情況查詢CentOS
- oracle表空間使用率查詢Oracle
- Oracle查詢表空間的每日增長量Oracle
- 每天自動統計表空間的使用情況
- 關於oracle的空間查詢Oracle
- oracle 剩餘表空間查詢慢,解決辦法Oracle
- 表空間使用量查詢
- 臨時表空間和回滾表空間使用率查詢
- Oracle表空間Oracle
- oracle 表空間Oracle
- 兩種檢視錶空間使用情況的方法
- 【UNDO】Oracle undo表空間使用率過高,因為一個查詢Oracle
- 增加oracle表空間Oracle
- oracle temp 表空間Oracle
- oracle 臨時表空間的增刪改查Oracle
- oracle11g 查詢臨時表空間的使用率和正在使用臨時表空間的使用者Oracle
- oracle 表移動表空間Oracle
- Oracle表移動表空間Oracle
- Oracle 查詢佔用臨時表空間大的歷史會話和SQLOracle會話SQL
- 華納雲:如何檢視Linux硬碟空間使用情況Linux硬碟
- 達夢資料庫表空間等空間大小查詢方法總結資料庫
- oracle表空間的整理Oracle
- Oracle 批量建表空間Oracle
- Oracle清理SYSAUX表空間OracleUX
- 臨時表空間被佔滿的原因查詢
- Oracle 歸檔使用情況分析Oracle
- Linux伺服器磁碟空間佔用情況分析與清理指南Linux伺服器
- 依靠dba_hist_tbspc_space_usage檢視獲得表空間的歷史使用情況
- Oracle11g新增檢視查詢表空間使用率DBA_TABLESPACE_USAGE_METRICSOracle
- Oracle Temp 表空間切換Oracle
- Oracle 表空間增加檔案Oracle
- Oracle OCP(49):表空間管理Oracle
- Oracle表空間收縮方案Oracle
- Oracle RMAN 表空間恢復Oracle
- oracle 例項表查詢Oracle
- oracle表複雜查詢Oracle
- Oracle新建使用者、表空間、表Oracle