• 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'));
    
    
    
    
    
    
  • 相关阅读:
    js 的防抖与节流
    Vue---图形二维码、rules校验规则、el-dialog展示图片
    vue ----弹框
    vue的背景加载--旋转*号
    利用ES6新特性将时间戳转换为yyyy-mm-dd格式
    路由守卫之离开守卫
    Java的运行环境与开发环境
    list<map<string,object>> 按照某字段排序
    没有CSRF保护的HTML表单 漏洞解决办法
    通过mybatis-plus的分页插件,实现分页
  • 原文地址:https://www.cnblogs.com/macleanoracle/p/2967669.html
Copyright © 2020-2023  润新知