轉:查詢oracle比較慢的session和sql

来源:http://www.cnblogs.com/tobyzw/archive/2016/05/05/5461511.html
-Advertisement-
Play Games

--查詢最慢的sql select * from (select parsing_user_id,executions,sortscommand_type,disk_reads,sql_text from v$sqlarea order by disk_reads desc)where rownum ...


--查詢最慢的sql

select * from (
select parsing_user_id,executions,sorts
command_type,disk_reads,sql_text from v$sqlarea order by disk_reads desc
)where rownum<10

 --查詢對應session

select SE.SID,SE.SERIAL#,PR.SPID,
SE.USERNAME,SE.STATUS,SE.TERMINAL,
SE.PROGRAM,SE.MODULE,
SE.SQL_ADDRESS,ST.EVENT,
ST.P1TEXT,SI.PHYSICAL_READS,SI.BLOCK_CHANGES from v$session se,v$session_wait st,
v$sess_io si,v$process pr
where st.SID=se.SID and st.SID=si.SID
AND SE.PADDR=PR.ADDR
AND SE.SID>6
AND ST.WAIT_TIME=0
AND ST.EVENT NOT LIKE '%SQL%'
ORDER BY PHYSICAL_READS DESC;
SELECT sql_address FROM V$SESSION SS,V$SQLTEXT TT
WHERE SS.SQL_HASH_VALUE=TT.HASH_VALUE AND SID=439;
 

v$sqltext:存儲的是完整的SQL,SQL被分割

v$sqlarea:存儲的SQL 和一些相關的信息,比如累計的執行次數,邏輯讀,物理讀等統計信息(統計)

v$sql:記憶體共用SQL區域中已經解析的SQL語句。(即時)

 

根據sid查找完整sql語句:

select sql_text from v$sqltext a where a.hash_value = (select sql_hash_value from v$session b where b.sid = '&sid'    )
order by piece asc

 

select a.CPU_TIME,--CPU時間 百萬分之一(微秒)
       a.OPTIMIZER_MODE,--優化方式
       a.EXECUTIONS,--執行次數
       a.DISK_READS,--讀盤次數
       a.SHARABLE_MEM,--占用shared pool的記憶體多少
       a.BUFFER_GETS,--讀取緩衝區的次數
       a.COMMAND_TYPE,--命令類型(3:select,2:insert;6:update;7delete;47:pl/sql程式單元)
       a.SQL_TEXT,--Sql語句
       a.SHARABLE_MEM,
       a.PERSISTENT_MEM,
       a.RUNTIME_MEM,
       a.PARSE_CALLS,
       a.DISK_READS,
       a.DIRECT_WRITES,
       a.CONCURRENCY_WAIT_TIME,
       a.USER_IO_WAIT_TIME
  from SYS.V_$SQLAREA a
 WHERE PARSING_SCHEMA_NAME = 'CHEA_FILL'--表空間
 order by a.CPU_TIME desc

 

引用:http://jenniferok.iteye.com/blog/700985

從V$SQLAREA中查詢最占用資源的查詢 select b.username username,a.disk_reads reads,
    a.executions exec,a.disk_reads/decode(a.executions,0,1,a.executions) rds_exec_ratio,
    a.sql_text Statement
from  v$sqlarea a,dba_users b
where a.parsing_user_id=b.user_id
 and a.disk_reads > 100000
order by a.disk_reads desc; 用buffer_gets列來替換disk_reads列可以得到占用最多記憶體的sql語句的相關信息。   v$sql:記憶體共用SQL區域中已經解析的SQL語句。(即時)
列出使用頻率最高的5個查詢: select sql_text,executions
from (select sql_text,executions,
   rank() over
    (order by executions desc) exec_rank
   from v$sql)
where exec_rank <=5; 消耗磁碟讀取最多的sql top5:
select disk_reads,sql_text
from (select sql_text,disk_reads,
   dense_rank() over
     (order by disk_reads desc) disk_reads_rank
   from v$sql)
where disk_reads_rank <=5;
找出需要大量緩衝讀取(邏輯讀)操作的查詢: select buffer_gets,sql_text
from (select sql_text,buffer_gets,
   dense_rank() over
     (order by buffer_gets desc) buffer_gets_rank
   from v$sql)
where buffer_gets_rank<=5;   v$sqlarea欄位定義:http://happyhou.blog.sohu.com/60494432.html

 

SQL_TEXT VARCHAR2(1000) First thousand characters of the SQL text for the current cursor
SQL_ID VARCHAR2(13) SQL identifier of the parent cursor in the library cache
SHARABLE_MEM NUMBER Amount of shared memory used by a cursor. If multiple child cursors exist, then the sum of all shared memory used by all child cursors.
PERSISTENT_MEM NUMBER Fixed amount of memory used for the lifetime of an open cursor. If multiple child cursors exist, the fixed sum of memory used for the lifetime of all the child cursors.
RUNTIME_MEM NUMBER Fixed amount of memory required during execution of a cursor. If multiple child cursors exist, the fixed sum of all memory required during execution of all the child cursors.
SORTS NUMBER Sum of the number of sorts that were done for all the child cursors
VERSION_COUNT NUMBER Number of child cursors that are present in the cache under this parent
LOADED_VERSIONS NUMBER Number of child cursors that are present in the cache and have their context heap (KGL heap 6) loaded
OPEN_VERSIONS NUMBER The number of child cursors that are currently open under this current parent
USERS_OPENING NUMBER Number of users that have any of the child cursors open
FETCHES NUMBER Number of fetches associated with the SQL statement
EXECUTIONS NUMBER Total number of executions, totalled over all the child cursors
END_OF_FETCH_COUNT NUMBER Number of times this cursor was fully executed since the cursor was brought into the library cache. The value of this statistic is not incremented when the cursor is partially executed, either because it failed during the execution or because only the first few rows produced by this cursor are fetched before the cursor is closed or re-executed. By definition, the value of theEND_OF_FETCH_COUNT column should be less or equal to the value of the EXECUTIONS column.
USERS_EXECUTING NUMBER Total number of users executing the statement over all child cursors
LOADS NUMBER Number of times the object was loaded or reloaded
FIRST_LOAD_TIME VARCHAR2(19) Timestamp of the parent creation time
INVALIDATIONS NUMBER Total number of invalidations over all the child cursors
PARSE_CALLS NUMBER Sum of all parse calls to all the child cursors under this parent
DISK_READS NUMBER Sum of the number of disk reads over all child cursors
DIRECT_WRITES NUMBER Sum of the number of direct writes over all child cursors
BUFFER_GETS NUMBER Sum of buffer gets over all child cursors
APPLICATION_WAIT_TIME NUMBER Application wait time
CONCURRENCY_WAIT_TIME NUMBER Concurrency wait time
CLUSTER_WAIT_TIME NUMBER Cluster wait time
USER_IO_WAIT_TIME NUMBER User I/O Wait Time
PLSQL_EXEC_TIME NUMBER PL/SQL execution time
JAVA_EXEC_TIME NUMBER Java execution time
ROWS_PROCESSED NUMBER Total number of rows processed on behalf of this SQL statement
COMMAND_TYPE NUMBER Oracle command type definition
OPTIMIZER_MODE VARCHAR2(25) Mode under which the SQL statement was executed
PARSING_USER_ID NUMBER User ID of the user that has parsed the very first cursor under this parent
PARSING_SCHEMA_ID NUMBER Schema ID that was used to parse this child cursor
KEPT_VERSIONS NUMBER Number of child cursors that have been marked to be kept using the DBMS_SHARED_POOL package
ADDRESS RAW(4 | 8) Address of the handle to the parent for this cursor
HASH_VALUE NUMBER Hash value of the parent statement in the library cache
OLD_HASH_VALUE NUMBER Old SQL hash value
MODULE VARCHAR2(64) Contains the name of the module that was executing at the time that the SQL statement was first parsed as set by calling DBMS_APPLICATION_INFO .SET_MODULE
MODULE_HASH NUMBER Hash value of the module that is named in the MODULEcolumn
ACTION VARCHAR2(64) Contains the name of the action that was executing at the time that the SQL statement was first parsed as set by calling DBMS_APPLICATION_INFO .SET_ACTION
ACTION_HASH NUMBER Hash value of the action that is named in the ACTIONcolumn
SERIALIZABLE_ABORTS NUMBER Number of times the transaction fails to serialize, producing ORA-08177 errors, totalled over all the child cursors
CPU_TIME NUMBER CPU time (in microseconds) used by this cursor for parsing/executing/fetching
ELAPSED_TIME NUMBER Elapsed time (in microseconds) used by this cursor for parsing/executing/fetching
IS_OBSOLETE VARCHAR2(1) Indicates whether the cursor has become obsolete (Y ) or not (N ). This can happen if the number of child cursors is too large.
CHILD_LATCH NUMBER Child latch number that is protecting the cursor
PROGRAM_ID NUMBER

Program identifie


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • T-SQL解析json字元串函數及其使用示例 參考博文:http://www.cnblogs.com/huangtailang/p/4277809.html 1、解析json字元串函數,返回表變數 2、存儲過程調用示例 ... ...
  • 1. Upgrading to MySQL 5.7, focusing on temporal types 在MySQL 5.6.4中,對TIME, TIMESTAMP and DATETIME三種時間類型進行了擴充,支持了微秒,並且DATETIME的存儲由之前的8個位元組縮小到5個位元組。 如果從My ...
  • 對於設計和創建資料庫完全是個新手?沒關係,Joe Celko,世界上讀者數量最多的SQL作者之一,會告訴你這些基礎。和往常一樣,即使是最專業的資料庫老手,也會給他們帶來驚喜。Joe是DMBS雜誌是多年來最受讀者喜愛的作者。他在美國、英國,北歐,南美及非洲傳授SQL知識。他在ANSI / ISO SQ ...
  • 1 數據表結構的設計與性能優化 1.1 、數據表的存儲原理 SQL Server每次讀取1個存儲塊,每個存儲塊大小為8KB,每讀取1個存儲塊計算為1個邏輯讀。 問題:如果數據內容非常大,像我們系統中的Feeling欄位非常大,就會導致每個存儲塊存放的數據行數會非常少,這樣當我們讀取數據時,要讀取許多 ...
  • MySQL資料庫伺服器的架設 MySQL資料庫伺服器的架設 MySQL資料庫伺服器的架設 導讀 MySQL資料庫是Linux操作系統上用得最多的資料庫系統,它可以非常方便的與其它伺服器集成在一起,如Apache、Vsftpd、Postfix等。下麵介紹RHEL 6平臺MySQL資料庫伺服器的安裝方法 ...
  • SQLServer 2012 Always on是針對高可用性和災難恢復的新解決方案。可以配置一個或多個輔助副本以支持對輔助資料庫進行只讀訪問,並且可以將任何輔助副本配置為允許對輔助資料庫進行備份。 這樣就提供了硬體的使用效率。 “可用性組”針對一組離散的用戶資料庫(稱為“可用性資料庫”,它們共同實 ...
  • 18 複製 18 複製... 1 18.1 複製配置... 3 18.1.1 基於Binary Log的資料庫複製配置... 3 18.1.2 配置基於Binary log的複製... 3 18.1.2.1 設置複製master的配置... 3 18.1.2.2 創建複製要用的用戶... 4 18. ...
  • 今天因為畢業設計要用到MySql資料庫,所以就準備自己安裝一個MySQL資料庫,但是因為MySQL Install MSI只有32位,所以最後選擇使用Windows (x86, 64-bit), ZIP Archive版的安裝使用,下麵本人來介紹自己安裝MySQL的過程,僅供參考。 添加完之後保存, ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...