ITPub博客

首页 > 数据库 > Oracle > [20240309]建立完善fms.sql与dfms.sql脚本.txt

[20240309]建立完善fms.sql与dfms.sql脚本.txt

原创 Oracle 作者:lfree 时间:2024-03-12 09:47:48 0 删除 编辑

[20240309]建立完善fms.sql与dfms.sql脚本.txt

--//自己写一个脚本先收集force_matching_signature相同,sql_id不同的信息.

$ cat fms.sql
-- Copyright 2023 lfree. All rights reserved.
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms and conditions.
--------------------------------------------------------------------------------
--
-- File name:  fms.sql  v1.0
-- Purpose:    Query gv$active_session_history Force_Matching_Signature the same, sql_id different of information
-- Author:     lfree
--
-- Usage:
--    @ fms <count(*)_number> <display_record_number> <fromtime> <totime>
--   <count(*)_number>=2>
--
-- Example:
--    @ fms 5 30 &day
--
-- Other:
--     This script uses only the in-memory GV$ACTIVE_SESSION_HISTORY, use
--     @dfms.sql for accessiong the DBA_HIST_ACTIVE_SESS_HISTORY archive
--
--------------------------------------------------------------------------------
WITH a1 AS (SELECT sql_id,force_matching_signature, count(*) cnt1
  FROM gv$active_session_history
 WHERE force_matching_signature <> 0 AND sample_time BETWEEN &3 AND &4
 GROUP BY sql_id, force_matching_signature ) ,
    a2 AS (SELECT force_matching_signature, count(*) sql_id_count,sum(cnt1) total_seconds
  FROM a1
 GROUP BY force_matching_signature
HAVING count(*) >=  &&1
 ORDER BY 3 desc)
SELECT force_matching_signature, sql_id_count,total_seconds
  FROM a2
 WHERE rownum <= &2;

$ cat dfms.sql
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms and conditions.
--------------------------------------------------------------------------------
--
-- File name:  dfms.sql  v1.0
-- Purpose:    Query dba_hist_active_sess_history Force_Matching_Signature the same, sql_id different of information
-- Author:     lfree
--
-- Usage:
--    @ idfms <count(*)_number> <display_record_number> <fromtime> <totime>
--   <count(*)__number>=2>
--
-- Example:
--    @ fms 5 30 &day
--
-- Other:
--     This script uses only the DBA_HIST_ACTIVE_SESS_HISTORY
--     @ fms.sql for accessiong the in-memory GV$ACTIVE_SESSION_HISTORY
--
--------------------------------------------------------------------------------
WITH a1 AS (SELECT sql_id,force_matching_signature, count(*) cnt1
  FROM dba_hist_active_sess_history
 WHERE force_matching_signature <> 0 AND sample_time BETWEEN &3 AND &4 and dbid = (SELECT d.dbid FROM v$database d)
 GROUP BY sql_id,force_matching_signature ) ,
    a2 AS (SELECT force_matching_signature, count(*) sql_id_count,sum(cnt1)*10 total_seconds
  FROM a1
 GROUP BY force_matching_signature
HAVING count(*) >= &&1
 ORDER BY 3 desc)
SELECT force_matching_signature, sql_id_count,total_seconds
  FROM a2
 WHERE rownum <= &2;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-3008674/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969502