zoukankan      html  css  js  c++  java
  • Script:常用SQL语句优化脚本

     
    select /*+ dynamic_sampling(b 10) dynamic_sampling_est_cdn(b) gather_plan_statistics*/ count(*) from tvb b;
    SELECT * FROM TABLE(dbms_xplan.display_cursor(NULL,NULL,'ALLSTATS LAST'));
    
    注意dynamic sampling used for this statement (level=2) 显示的level 2不是真的! level 10在这里真的是LEVEL 10!
    
    EXPLAIN PLAN SET STATEMENT_ID = 'abc' FOR
    select count(*) from tvb ;
    
    SELECT * FROM TABLE(dbms_xplan.display('PLAN_TABLE','abc','ALL'));
    
    set linesize 200 pagesize 1400;
    
    select /* FINDSQLID */ SQL_ID,SQL_FULLTEXT from V$SQL  where SQL_TEXT LIKE '%&SQLTEXT%'  and SQL_FULLTEXT NOT LIKE '%FINDSQLID%'
    union all
    select SQL_ID,SQL_TEXT FROM DBA_HIST_SQLTEXT where SQL_TEXT LIKE '%&SQLTEXT%'
    and SQL_TEXT NOT LIKE '%FINDSQLID%';
    
    alter session set events '10046 trace name context forever,level 12';
    alter session set events '10053 trace name context forever,level 1';
    
    alter session set tracefile_identifier='10046';
    alter session set timed_statistics = true;
    alter session set statistics_level=all;
    alter session set max_dump_file_size = unlimited;
    alter session set events '10046 trace name context forever,level 12';
    -- Execute the queries or operations to be traced here --
    
    1.- Please provide AWR and ADDM report from each instance for interval of 30 minutes when the problem is present.
    2.- Upload OS log file /var/log/messages
    3.- Please upload background process trace files for each instance. LMD, LMS, LMON, DBWR, LGWR, diag, pmon, smon, etc.
    
    有问题请去http://t.askmaclean.com/forum-4-1.html提问, 会在一定时间内反馈给你
    提问请写明 数据库版本、OS版本、问题类型
    如果是性能问题请给出 AWR、ASH、ADDM及10046 TRACE
    如果是ORA-600/7445错误请给出ALERT.LOG及其TRACE
    如果是RAC CLUTERWARE问题请给出CRSD.LOG和CSSD.LOG
    
    SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
    FROM SYS.x$ksppi x, SYS.x$ksppcv y
    WHERE x.inst_id = USERENV ('Instance')
    AND y.inst_id = USERENV ('Instance')
    AND x.indx = y.indx
    AND x.ksppinm like '%disable%';
    
    select dbms_rowid.rowid_block_number(rowid),dbms_rowid.rowid_relative_fno(rowid) from test;
    
    select spid,pid from v$process where addr = ( select paddr from v$session where sid=(select distinct sid from v$mystat));
    
    select name,value from v$system_parameter where ISDEFAULT!='TRUE'  order by 1;
    
    set linesize 200 pagesize 1400
    @?/rdbms/admin/utllockt
    
    
    
    
    ==========================================================================================>
    
    执行计划历史
    
    Want to Know if Execution Plan Changed Recently?
     
     
    set lines 150 pages 150
    col BEGIN_INTERVAL_TIME for a23
    col PLAN_HASH_VALUE for 9999999999
    col date_time for a30
    col snap_id heading 'SnapId'
    col executions_delta heading "No. of exec"
    col sql_profile heading "SQL|Profile" for a7
    col date_time heading 'Date time'
    
    col avg_lio heading 'LIO/exec' for 99999999999.99
    col avg_cputime heading 'CPUTIM/exec' for 9999999.99
    col avg_etime heading 'ETIME/exec' for 9999999.99
    col avg_pio heading 'PIO/exec' for 9999999.99
    col avg_row heading 'ROWs/exec' for 9999999.99
    SELECT distinct
    s.snap_id ,
    PLAN_HASH_VALUE,
    to_char(s.BEGIN_INTERVAL_TIME,'mm/dd/yy_hh24mi')|| to_char(s.END_INTERVAL_TIME,'_hh24mi') Date_Time,
    SQL.executions_delta,
    SQL.buffer_gets_delta/decode(nvl(SQL.executions_delta,0),0,1,SQL.executions_delta) avg_lio,
    --SQL.ccwait_delta,
    (SQL.cpu_time_delta/1000000)/decode(nvl(SQL.executions_delta,0),0,1,SQL.executions_delta) avg_cputime ,
    (SQL.elapsed_time_delta/1000000)/decode(nvl(SQL.executions_delta,0),0,1,SQL.executions_delta) avg_etime,
    SQL.DISK_READS_DELTA/decode(nvl(SQL.executions_delta,0),0,1,SQL.executions_delta) avg_pio,
    SQL.rows_processed_total/decode(nvl(SQL.executions_delta,0),0,1,SQL.executions_delta) avg_row
    --,SQL.sql_profile
    FROM
    dba_hist_sqlstat SQL,
    dba_hist_snapshot s
    WHERE
    SQL.instance_number =(select instance_number from v$instance)
    and SQL.dbid =(select dbid from v$database)
    and s.snap_id = SQL.snap_id
    AND sql_id in
    ('&SQLID') order by s.snap_id
    /
     
     
    xp_awr.sql
     
     
    select plan_table_output from table (dbms_xplan.display_awr('&sql_id',null,null,
    'ADVANCED +PEEKED_BINDS'));
    
    
    
    
    
    
  • 相关阅读:
    UVALive 5066 Fire Drill --BFS+DP
    Codeforces 486E LIS of Sequence --树状数组求LIS
    Codeforces 460D Little Victor and Set --分类讨论+构造
    Codeforces Round #285 (Div.1 B & Div.2 D) Misha and Permutations Summation --二分+树状数组
    计算机组成原理知识总结
    HDU 5155 Harry And Magic Box --DP
    【Python数据分析】简单爬虫 爬取知乎神回复
    《查拉图斯特拉如是说》读书笔记
    POJ 3384 Feng Shui --直线切平面
    POJ 2540 Hotter Colder --半平面交
  • 原文地址:https://www.cnblogs.com/macleanoracle/p/2967669.html
Copyright © 2011-2022 走看看