Retrieve SQL and Execution Plan from AWR Snapshots
A handy little script. that I have used in the Oracle Database 11g Performance Tuning course this week. It queries the AWR Snapshots for SQL statements and sorts them by elapsed time:
SQL> col parsed format a6 col sql_text format a40 set lines 200 set pages 300 select sql_text, parsing_schema_name as parsed, elapsed_time_delta/1000/1000 as elapsed_sek, stat.snap_id, to_char(snap.end_interval_time,'dd.mm hh24:mi:ss') as snaptime, txt.sql_id from dba_hist_sqlstat stat, dba_hist_sqltext txt, dba_hist_snapshot snap where stat.sql_id=txt.sql_id and stat.snap_id=snap.snap_id and snap.begin_interval_time>=sysdate-1 and lower(sql_text) like '%&t%' and parsing_schema_name not in ('SYS','SYSMAN','MDSYS','WKSYS') order by elapsed_time_delta asc;
sysdate-1 returns SQL up to yesterday and can be modified to retrieve SQL as long as there are AWR snapshots of course. &t is a substring of the SQL, we may be interested in. With the sql_id, we can also retrieve the execution plan from the snapshots:
SQL> select plan_table_output from table (dbms_xplan.display_awr('&sqlid'));
The amount of SQL that gets collected into a snapshot can be modified with
SQL> begin
dbms_workload_repository.modify_snapshot_settings (
topnsql=>'MAXIMUM');
end;
/
MAXIMUM (uppercase!) takes all SQL from the Library Cache into the snapshot – alternative, we can specify a number of Top SQL to collect. The example is from an 11g Database, but it should work the same with 10g already.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/354732/viewspace-665826/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- explain plan VS execution planAI
- SAP ABAP SQL的execution plan和cacheSQL
- oracle execution planOracle
- oracle awr 修改Snapshots設定Oracle
- sql net message from|to client與sql execution countSQLclient
- Explain for the Statistics of Execution PlanAI
- Understanding Parallel Execution PlanParallel
- Script to generate AWR report from remote sql clientREMSQLclient
- zt_oracle11g sql baseline與sql execution plan執行計劃OracleSQL
- oracle 9i啟用Execution PlanOracle
- "The Alberta Plan for AI Research" - "Research Plan" from Richard SuttonAI
- Error: cannot fetch last explain plan from PLAN_TABLEErrorASTAI
- MySQL案例04:Cause: java.sql.SQLException: Could not retrieve transaction read-only status from serverMySqlJavaExceptionServer
- Parallel Execution of SQL StatementsParallelSQL
- SQL Plan ManagementSQL
- [ OCRSRV][21]th_select_handler: Failed to retrieve procctx from......AI
- SQL Plan Management(SPM)SQL
- "The Alberta Plan for AI Research" - "Intro" from Richard SuttonAI
- [ OCRSRV][3736]th_select_handler: Failed to retrieve procctx from htAI
- 適當採用Histogram 讓Oracle達成最優Execution PlanHistogramOracle
- "The Alberta Plan for AI Research" - "Research Vision" from Richard SuttonAI
- SQL Plan Management介紹SQL
- sql_plan_baselineSQL
- SQL PLAN Management的測試SQL
- WRH$_SQL_PLAN 被鎖SQL
- 11g-sql plan managementSQL
- sql plan baselines(一)SQL
- sql plan baseline(二)SQL
- AWR TOP SQL實現SQL
- AWR中的SQL StatisticsSQL
- Oracle AWR Top SQL sectionOracleSQL
- awr的top sql分析SQL
- MySQL 8.0 Reference Manual(讀書筆記59節--Understanding the Query Execution Plan(2))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記58節--Understanding the Query Execution Plan(1))MySql筆記
- 【SQL_PLAN】Oracle 透過檢視sql_plan 格式化執行計劃SQLOracle
- 使用V$SQL_PLAN檢視SQL
- v$sql_plan 檢視解析SQL
- 用EXPLAIN PLAN 分析SQL語句AISQL