搜尋
首頁資料庫mysql教程如何利用ash监控会话

如何利用ash监控会话

Jun 07, 2016 pm 04:10 PM
會話使用如何有效監控

ash是非常有效的监控工具之一,1秒抓一次select max(sample_time)over(),min(sample_time)over() from dba_hist_active_sess_history; --8天 select max(sample_time)over(),min(sample_time)over() from v$active_session_history; --当天首先先了解几个视

ash是非常有效的监控工具之一,1秒抓一次
select max(sample_time)over(),min(sample_time)over() from dba_hist_active_sess_history;  --8天   
select max(sample_time)over(),min(sample_time)over() from v$active_session_history;  --当天

首先先了解几个视图:
V$ACTIVE_SESSION_HISTORY: 是ASH的核心,用以记录活动SESSION的历史等待信息,每秒采样一次,这部分内容记录在内存中,期望值是记录一个小时的内容。
WRH#_ACTIVE_SESSION_HISTORY : 是V$ACTIVE_SESSION_HISTORY在AWR的存储地。 
V$ACTIVE_SESSION_HISTORY: 中的信息会被定期(每小时一次)的刷新到负载库中,并缺省保留一个星期用于分析。
DBA_HIST_ACTIVE_SESS_HISTORY: 视图是WRH#_ACTIVE_SESSION_HISTORY视图和其他几个视图的联合展现,通常通过这个视图进行历史数据的访问。

------------------------------------
--V$ACTIVE_SESSION_HISTORY的监控:--
------------------------------------

------------session:1-----------------


SQL> @big

       SID
----------
       131

Elapsed: 00:00:00.00
drop table big
           *
ERROR at line 1:
ORA-00942: table or view does not exist


Elapsed: 00:00:00.03
Elapsed: 00:00:00.31
Elapsed: 00:00:00.34
Elapsed: 00:00:00.29
Elapsed: 00:00:00.73
Elapsed: 00:00:01.75
Elapsed: 00:00:10.59
Elapsed: 00:00:24.62
Elapsed: 00:00:00.01

     BIG_M
----------
       522
Elapsed: 00:00:00.36

  COUNT(*)
----------
   4650368
Elapsed: 00:00:26.70


------------session:2-----------------

SQL> @getash_sid
Enter value for sid: 131

SESSION_ID NAME                                                             P_NAME          P_VALUE      SQL_ID    WAIT_TIME CURRENT_OBJ# CURRENT_FILE# CURRENT_BLOCK#
---------- ---------------------------------------------------------------- --------------- --------------- ------------- ---------- ------------ ------------- ---------
       131 db file sequential read                                          file#           1            d2wbn28rdk8z4     0          547             1           3604
                                                                            block#          53206
                                                                            blocks          1

       131 db file sequential read                                          file#           1            d2wbn28rdk8z4     0           -1             0              0
                                                                            block#          3009
                                                                            blocks          1

       131 db file scattered read                                           file#           4            03b71c07nsc1a     0          134             1           1064
                                                                            block#          4845
                                                                            blocks          8

       131 log buffer space                                                                 0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch completion                                                       0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4           4995
                                                                            block#          4995
                                                                            blocks          5

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           7170
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           7170
                                                                                            0
                                                                                            0

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4           8578
                                                                            block#          8578
                                                                            blocks          126

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          12802
                                                                            block#          12802
                                                                            blocks          126

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4          12930
                                                                                            0
                                                                                            0

       131 db file sequential read                                          file#           1            aq32z6wjx1s4h     0        65921           201           3585
                                                                            block#          2854
                                                                            blocks          1

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          14084
                                                                            block#          14084
                                                                            blocks          124

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          18436
                                                                            block#          18436
                                                                            blocks          128

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          19972
                                                                            block#          19972
                                                                            blocks          128

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          21252
                                                                            block#          21252
                                                                            blocks          124

       131 db file parallel read                                            files           1            aq32z6wjx1s4h     0        76851             4          23424
                                                                            blocks          29
                                                                            requests        29

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4          24320
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4          24320
                                                                                            0
                                                                                            0

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          25856
                                                                            block#          25856
                                                                            blocks          128

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          27652
                                                                            block#          27652
                                                                            blocks          124

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          29312
                                                                            block#          29312
                                                                            blocks          32

       131 Disk file operations I/O                                         FileOperation   2            aq32z6wjx1s4h     0        76851             4          29952
                                                                            fileno          0
                                                                            filetype        2

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          30724
                                                                            block#          30724
                                                                            blocks          124

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          34530
                                                                            block#          34530
                                                                            blocks          14

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4          35716
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4          35716
                                                                                            0
                                                                                            0

       131 Disk file operations I/O                                         FileOperation   5            aq32z6wjx1s4h     0        76851             4          37632
                                                                            fileno          0
                                                                            filetype        2

       131 db file sequential read                                          file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          4999
                                                                            blocks          1

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          10344
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          17409
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          22083
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          28549
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          34733
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          39217
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          45114
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          48836
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          52391
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4           5196
                                                                            block#          5196
                                                                            blocks          6

       131 db file sequential read                                          file#           4            fqcxb1n33642x     0        76851             4           8261
                                                                            block#          8261
                                                                            blocks          1

       131 db file sequential read                                          file#           4            fqcxb1n33642x     0        76851             4          11318
                                                                            block#          11318
                                                                            blocks          1

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          14489
                                                                            block#          14489
                                                                            blocks          56

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          17935
                                                                            block#          17935
                                                                            blocks          50

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          21195
                                                                            block#          21195
                                                                            blocks          20

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          25170
                                                                            block#          25170
                                                                            blocks          2

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          28453
                                                                            block#          28453
                                                                            blocks          34

       131 db file sequential read                                          file#           4            fqcxb1n33642x     0        76851             4          33067
                                                                            block#          33067
                                                                            blocks          1

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          36991
                                                                            block#          36991
                                                                            blocks          13

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          41616
                                                                            block#          41616
                                                                            blocks          21

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          44055
                                                                            block#          44055
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4           2723
                                                                            block#          2723
                                                                            blocks          44

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          50056
                                                                            block#          50056
                                                                            blocks          9

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          53658
                                                                            block#          53658
                                                                            blocks          102

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          56580
                                                                            block#          56580
                                                                            blocks          128

       131 db file sequential read                                          file#           4            fqcxb1n33642x     0        76851             4          60256
                                                                            block#          60256
                                                                            blocks          1


64 rows selected.

Elapsed: 00:00:00.40
SQL> @getsql_sqlid
Enter 1 for curr sql, 2 for hist sql,default 1:

Enter value for sqlid: fqcxb1n33642x

SQL_FULLTEXT
---------------------------------------------------------------------------------------------
select count(*) from big
Elapsed: 00:00:00.00
Elapsed: 00:00:00.00
SQL> @getobj_id
Enter value for dblink:
Enter value for obj_id: 76851

OWNER                OBJECT_NAME                    OBJECT_TYPE         CREATED             STATUS
-------------------- ------------------------------ ------------------- ------------------- -------
SCOTT                BIG                            TABLE               2014-11-20 15:56:23 VALID

1 row selected.

Elapsed: 00:00:00.01
SQL> @getobj_fb
Enter value for file_id: 4
Enter value for block_id: 60256

OWNER           SEGMENT_NAME         SEGMENT_TY
--------------- -------------------- ----------
SCOTT           BIG                  TABLE

1 row selected.

Elapsed: 00:00:00.37




--------------------------@脚本--------------------


--@big 

@sid
set feedback off
drop table big;
create table big as select * from dba_objects;
insert into big select * from big;
/
/
/
/
/
commit;
select SUM(bytes) / 1024 / 1024  big_M  from dba_segments where segment_name = 'BIG';
select count(*) from big;
set feedback on


--@getash_sid
col p_name for a15
col p_value for a15
select SESSION_ID,
       NAME,
       P1TEXT||chr(10)||P2TEXT||chr(10)||P3TEXT p_name,
       p1||chr(10)||p2||chr(10)||p3 p_value,
       sql_id,
       WAIT_TIME,
       CURRENT_OBJ#,
       CURRENT_FILE#,
       CURRENT_BLOCK#
  from v$active_session_history ash, v$event_name enm
 where ash.event# = enm.event#
   and SESSION_ID = &sid
 order by sample_time; 
 
 

----------------------------------------
--DBA_HIST_ACTIVE_SESS_HISTORY的监控:--
----------------------------------------

--查当前时间
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

--根据时间找到snap_id(8天内,1小时前),因为基表非常大,利用snap_id的索引才能快速查询
select distinct snap_id from dba_hist_snapshot b where to_date('2014-11-20 14:08:12','yyyy-mm-dd hh24:mi:ss') between b.begin_interval_time and b.end_interval_time;

--top instance
select /*+parallel(a,8)*/instance_number,count(*) from dba_hist_active_sess_history a where a.snap_id=67421 group by instance_number;

--top event
select /*+parallel(a,8)*/event,count(*) from dba_hist_active_sess_history a 
where a.snap_id=67421
and instance_number=2
and sample_time>=to_timestamp('2014-11-20 14:07:12','yyyy-mm-dd hh24:mi:ss')
and sample_time<=to_timestamp(&#39;2014-11-20 14:08:12&#39;,&#39;yyyy-mm-dd hh24:mi:ss&#39;)
group by event
order by count(*) desc;

--top user
select /*+parallel(a,8)*/user_id,(select username from dba_users b where b.user_id=a.user_id) username,count(*) from dba_hist_active_sess_history a 
where a.snap_id=67421
and instance_number=2
and sample_time>=to_timestamp(&#39;2014-11-20 14:07:12&#39;,&#39;yyyy-mm-dd hh24:mi:ss&#39;)
and sample_time<=to_timestamp(&#39;2014-11-20 14:08:12&#39;,&#39;yyyy-mm-dd hh24:mi:ss&#39;)
group by user_id
order by count(*) desc;

--top sql
select /*+parallel(a,8)*/sql_id,count(*) from dba_hist_active_sess_history a 
where a.snap_id=67421
and instance_number=2
and sample_time>=to_timestamp(&#39;2014-11-20 14:07:12&#39;,&#39;yyyy-mm-dd hh24:mi:ss&#39;)
and sample_time<=to_timestamp(&#39;2014-11-20 14:08:12&#39;,&#39;yyyy-mm-dd hh24:mi:ss&#39;)
group by sql_id
order by count(*) desc;

--   select SQL_TEXT from dba_hist_sqltext where sql_id=&#39;49p4hfj6azw19&#39;;


--top program
select /*+parallel(a,8)*/program,count(*) from dba_hist_active_sess_history a 
where a.snap_id=67421
and instance_number=2
and sample_time>=to_timestamp(&#39;2014-11-20 14:07:12&#39;,&#39;yyyy-mm-dd hh24:mi:ss&#39;)
and sample_time<=to_timestamp(&#39;2014-11-20 14:08:12&#39;,&#39;yyyy-mm-dd hh24:mi:ss&#39;)
group by program
order by count(*) desc;



陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
您什麼時候應該使用複合索引與多個單列索引?您什麼時候應該使用複合索引與多個單列索引?Apr 11, 2025 am 12:06 AM

在數據庫優化中,應根據查詢需求選擇索引策略:1.當查詢涉及多個列且條件順序固定時,使用複合索引;2.當查詢涉及多個列但條件順序不固定時,使用多個單列索引。複合索引適用於優化多列查詢,單列索引則適合單列查詢。

如何識別和優化MySQL中的慢速查詢? (慢查詢日誌,performance_schema)如何識別和優化MySQL中的慢速查詢? (慢查詢日誌,performance_schema)Apr 10, 2025 am 09:36 AM

要優化MySQL慢查詢,需使用slowquerylog和performance_schema:1.啟用slowquerylog並設置閾值,記錄慢查詢;2.利用performance_schema分析查詢執行細節,找出性能瓶頸並優化。

MySQL和SQL:開發人員的基本技能MySQL和SQL:開發人員的基本技能Apr 10, 2025 am 09:30 AM

MySQL和SQL是開發者必備技能。 1.MySQL是開源的關係型數據庫管理系統,SQL是用於管理和操作數據庫的標準語言。 2.MySQL通過高效的數據存儲和檢索功能支持多種存儲引擎,SQL通過簡單語句完成複雜數據操作。 3.使用示例包括基本查詢和高級查詢,如按條件過濾和排序。 4.常見錯誤包括語法錯誤和性能問題,可通過檢查SQL語句和使用EXPLAIN命令優化。 5.性能優化技巧包括使用索引、避免全表掃描、優化JOIN操作和提升代碼可讀性。

描述MySQL異步主奴隸複製過程。描述MySQL異步主奴隸複製過程。Apr 10, 2025 am 09:30 AM

MySQL異步主從復制通過binlog實現數據同步,提升讀性能和高可用性。 1)主服務器記錄變更到binlog;2)從服務器通過I/O線程讀取binlog;3)從服務器的SQL線程應用binlog同步數據。

mysql:簡單的概念,用於輕鬆學習mysql:簡單的概念,用於輕鬆學習Apr 10, 2025 am 09:29 AM

MySQL是一個開源的關係型數據庫管理系統。 1)創建數據庫和表:使用CREATEDATABASE和CREATETABLE命令。 2)基本操作:INSERT、UPDATE、DELETE和SELECT。 3)高級操作:JOIN、子查詢和事務處理。 4)調試技巧:檢查語法、數據類型和權限。 5)優化建議:使用索引、避免SELECT*和使用事務。

MySQL:數據庫的用戶友好介紹MySQL:數據庫的用戶友好介紹Apr 10, 2025 am 09:27 AM

MySQL的安裝和基本操作包括:1.下載並安裝MySQL,設置根用戶密碼;2.使用SQL命令創建數據庫和表,如CREATEDATABASE和CREATETABLE;3.執行CRUD操作,使用INSERT,SELECT,UPDATE,DELETE命令;4.創建索引和存儲過程以優化性能和實現複雜邏輯。通過這些步驟,你可以從零開始構建和管理MySQL數據庫。

InnoDB緩衝池如何工作,為什麼對性能至關重要?InnoDB緩衝池如何工作,為什麼對性能至關重要?Apr 09, 2025 am 12:12 AM

InnoDBBufferPool通過將數據和索引頁加載到內存中來提升MySQL數據庫的性能。 1)數據頁加載到BufferPool中,減少磁盤I/O。 2)臟頁被標記並定期刷新到磁盤。 3)LRU算法管理數據頁淘汰。 4)預讀機制提前加載可能需要的數據頁。

MySQL:初學者的數據管理易用性MySQL:初學者的數據管理易用性Apr 09, 2025 am 12:07 AM

MySQL適合初學者使用,因為它安裝簡單、功能強大且易於管理數據。 1.安裝和配置簡單,適用於多種操作系統。 2.支持基本操作如創建數據庫和表、插入、查詢、更新和刪除數據。 3.提供高級功能如JOIN操作和子查詢。 4.可以通過索引、查詢優化和分錶分區來提升性能。 5.支持備份、恢復和安全措施,確保數據的安全和一致性。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具