查詢最佔資源、CPU、記憶體、和執行最長的SQL語句
--當前執行sql語句
select a.SID,
a.SERIAL#,
a.USERNAME,
b.PARSE_CALLS,
b.PARSING_SCHEMA_NAME,
b.CPU_TIME/1000000,
b.ELAPSED_TIME/1000000,
b.DISK_READS,
b.DIRECT_WRITES,
b.BUFFER_GETS,
a.event,
b.sql_text,
b.SQL_FULLTEXT
from v$session a inner join v$sqlarea b
on a.SQL_HASH_VALUE = b. hash_value and b.PARSING_SCHEMA_NAME=upper('smsdb')
--物理讀最高sql語句
select a.USERNAME,
a. USER_ID,
b.PARSE_CALLS,
b.PARSING_SCHEMA_NAME,
b.CPU_TIME/1000000,
b.ELAPSED_TIME/1000000,
b.DISK_READS,
b.DIRECT_WRITES,
b.BUFFER_GETS,
b.sql_text,
b.SQL_FULLTEXT
from dba_users a inner join v$sqlarea b
on a.USER_ID = b.PARSING_USER_ID and b.PARSING_SCHEMA_NAME=upper('smsdb') and disk_reads>1000000
--查詢前10名執行最多次數SQL語句
select sql_text "SQL語句", executions "執行次數"
from (select sql_text,
executions,
rank() over
(order by executions desc) exec_rank
from v$sqlarea)
where exec_rank <= 10;
--查詢前10名佔用CPU最高的SQL語句
select sql_text "SQL語句",
c_t "SQL執行時間(秒)",executions "執行次數",cs "每次執行時間(秒)" from (select sql_text,
cpu_time /1000000 c_t,executions,ceil(executions/(cpu_time/1000000))cs,
rank() over(order by cpu_time desc) top_time
from v$sqlarea) where top_time <= 10
--查詢前10名執行時間最長SQL語句
select sql_text "SQL語句",
c_t "處理時間(秒)",executions "執行次數",cs "每次執行時間(秒)"
from (select sql_text,
ELAPSED_TIME / 1000000 c_t,executions,ceil(executions/(ELAPSED_TIME/1000000))cs,
rank() over(order by ELAPSED_TIME desc) top_time
from v$sqlarea) where top_time <= 10
--查詢前10名最耗資源SQL語句
select sql_text "SQL語句",
DISK_READS "物理讀次數",cs "每次執行時間(秒)"
from (select sql_text,
ELAPSED_TIME / 1000000 c_t,executions,ceil(executions/(ELAPSED_TIME/1000000))cs,DISK_READS,
rank() over(order by DISK_READS desc) top_disk
from v$sqlarea) where top_disk <= 10
--查詢前10名最耗記憶體SQL語句
select sql_text "SQL語句",
BUFFER_GETS "記憶體讀次數",cs "每次執行時間(秒)"
from (select sql_text,
ELAPSED_TIME / 1000000 c_t,executions,ceil(executions/(ELAPSED_TIME/1000000))cs,BUFFER_GETS,
rank() over(order by BUFFER_GETS desc) top_mem
from v$sqlarea) where top_mem <= 10
--檢視鎖表語句
Select
c.sid,
c.serial#,
d.name,
b.object_name,
c.username,
c.program,
c.osuser
from gv$Locked_object a, All_objects b, gv$session c, audit_actions d
where a.object_id = b.object_id
and a.inst_id = c.inst_id(+)
and a.session_id = c.sid(+)
and c.command = d.action;
select a.SID,
a.SERIAL#,
a.USERNAME,
b.PARSE_CALLS,
b.PARSING_SCHEMA_NAME,
b.CPU_TIME/1000000,
b.ELAPSED_TIME/1000000,
b.DISK_READS,
b.DIRECT_WRITES,
b.BUFFER_GETS,
a.event,
b.sql_text,
b.SQL_FULLTEXT
from v$session a inner join v$sqlarea b
on a.SQL_HASH_VALUE = b. hash_value and b.PARSING_SCHEMA_NAME=upper('smsdb')
--物理讀最高sql語句
select a.USERNAME,
a. USER_ID,
b.PARSE_CALLS,
b.PARSING_SCHEMA_NAME,
b.CPU_TIME/1000000,
b.ELAPSED_TIME/1000000,
b.DISK_READS,
b.DIRECT_WRITES,
b.BUFFER_GETS,
b.sql_text,
b.SQL_FULLTEXT
from dba_users a inner join v$sqlarea b
on a.USER_ID = b.PARSING_USER_ID and b.PARSING_SCHEMA_NAME=upper('smsdb') and disk_reads>1000000
--查詢前10名執行最多次數SQL語句
select sql_text "SQL語句", executions "執行次數"
from (select sql_text,
executions,
rank() over
(order by executions desc) exec_rank
from v$sqlarea)
where exec_rank <= 10;
--查詢前10名佔用CPU最高的SQL語句
select sql_text "SQL語句",
c_t "SQL執行時間(秒)",executions "執行次數",cs "每次執行時間(秒)" from (select sql_text,
cpu_time /1000000 c_t,executions,ceil(executions/(cpu_time/1000000))cs,
rank() over(order by cpu_time desc) top_time
from v$sqlarea) where top_time <= 10
--查詢前10名執行時間最長SQL語句
select sql_text "SQL語句",
c_t "處理時間(秒)",executions "執行次數",cs "每次執行時間(秒)"
from (select sql_text,
ELAPSED_TIME / 1000000 c_t,executions,ceil(executions/(ELAPSED_TIME/1000000))cs,
rank() over(order by ELAPSED_TIME desc) top_time
from v$sqlarea) where top_time <= 10
--查詢前10名最耗資源SQL語句
select sql_text "SQL語句",
DISK_READS "物理讀次數",cs "每次執行時間(秒)"
from (select sql_text,
ELAPSED_TIME / 1000000 c_t,executions,ceil(executions/(ELAPSED_TIME/1000000))cs,DISK_READS,
rank() over(order by DISK_READS desc) top_disk
from v$sqlarea) where top_disk <= 10
--查詢前10名最耗記憶體SQL語句
select sql_text "SQL語句",
BUFFER_GETS "記憶體讀次數",cs "每次執行時間(秒)"
from (select sql_text,
ELAPSED_TIME / 1000000 c_t,executions,ceil(executions/(ELAPSED_TIME/1000000))cs,BUFFER_GETS,
rank() over(order by BUFFER_GETS desc) top_mem
from v$sqlarea) where top_mem <= 10
--檢視鎖表語句
Select
c.sid,
c.serial#,
d.name,
b.object_name,
c.username,
c.program,
c.osuser
from gv$Locked_object a, All_objects b, gv$session c, audit_actions d
where a.object_id = b.object_id
and a.inst_id = c.inst_id(+)
and a.session_id = c.sid(+)
and c.command = d.action;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28211342/viewspace-2138131/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 實時查詢最耗CPU資源的SQL語句SQL
- 檢視資料庫最佔資源或記憶體的查詢SQL資料庫記憶體SQL
- 透過DMV查詢CPU時間最長的語句和查詢計劃
- linux 查詢最消耗CPU和記憶體的程式Linux記憶體
- 查詢UNIX/LINUX 下的佔用CPU資源的SQL語句LinuxSQL
- 實時獲得最耗CPU資源的SQL語句(zt)SQL
- 查詢orcale執行的SQL語句記錄SQL
- 查詢Oracle正在執行和執行過的SQL語句OracleSQL
- 查詢執行慢的SQL語句SQL
- 查詢正在執行的SQL語句SQL
- 查詢操作佔用cpu很高語句
- Laravel 框架查詢執行的 SQL 語句Laravel框架SQL
- 查詢Oracle正在執行的SQL語句OracleSQL
- 查詢sql語句執行次數SQL
- SQL Server 查詢歷史執行的SQL語句SQLServer
- 查詢正在執行的sql語句及該語句執行的時間SQL
- SQL 查詢語句的執行順序解析SQL
- MySQL查詢select語句的執行流程以及InnoDB記憶體結構MySql記憶體
- 查詢Oracle正在執行的sql語句及執行該語句的使用者OracleSQL
- 一條 SQL 查詢語句是如何執行的?SQL
- T-sql語句查詢執行順序SQL
- GaussDB SQL查詢語句執行過程解析SQL
- 解碼Redis最易被忽視的CPU和記憶體佔用高問題Redis記憶體
- 輸入的查詢 SQL 語句,是如何執行的?SQL
- 查詢當前正在執行的SQL語句並KILLSQL
- Oracle 查詢某個session正在執行的sql語句OracleSessionSQL
- SQLServer如何查詢近3分鐘最消耗CPU的SQLSQLServer
- Oracle 查耗CPU資源sql語句及程式代號-轉OracleSQL
- OEM模組審計查詢語句佔用較大資源
- MySQL資料庫詳解(一)SQL查詢語句是如何執行的?MySql資料庫
- sql語句引起的CPU佔用國高SQL
- 資料庫查詢優化:使用explain分析sql語句執行效率資料庫優化AISQL
- 一條查詢語句的執行流程
- 最簡單的sql語句(增刪改查統計)SQL
- 資源記憶體佔用記憶體
- MySQL系列之一條SQL查詢語句的執行過程MySql
- Oracle中SQL語句執行效率的查詢與解決 (3)OracleSQL
- Oracle中SQL語句執行效率的查詢與解決 (2)OracleSQL