diff --git a/change log.txt b/change log.txt index a82aa705..4a55e37e 100644 --- a/change log.txt +++ b/change log.txt @@ -1,4 +1,4 @@ -2016-06-21: ! oracle: fix issue for 'loadtrace' in 10g +2016-06-21: ! oracle: fix error for command 'loadtrace' in 10g 2016-06-16: + oracle: new "-d" option for "ora awrstat" + public: new setting "set echo on/off" ! public: fix invalid cursor position when 'Ctrl+C' in Win10 diff --git a/dbcli.bat b/dbcli.bat index 83407f30..a20b574a 100644 --- a/dbcli.bat +++ b/dbcli.bat @@ -4,8 +4,11 @@ cd /d "%~dp0" SET JAVA_HOME= SET CLASSPATH= SET JAVA_TOOL_OPTIONS= +set ANSICOLOR=off if not defined CONSOLE_COLOR SET CONSOLE_COLOR=0A if not defined ANSICON_CMD SET ANSICON_CMD=.\lib\x64\ansicon.exe +if !ANSICOLOR!==off set ANSICON_CMD= + if not defined JRE_HOME SET JRE_HOME=d:\soft\java if not defined TNS_ADM SET TNS_ADM=d:\Soft\InstanceClient\network\admin SET DBCLI_ENCODING=UTF-8 diff --git a/lib/dbcli.jar b/lib/dbcli.jar index 94155107..7c76bf34 100644 Binary files a/lib/dbcli.jar and b/lib/dbcli.jar differ diff --git a/oracle/chart/awr/sysmetric.chart b/oracle/chart/awr/sysmetric.chart index c660c7ee..d5945b63 100644 --- a/oracle/chart/awr/sysmetric.chart +++ b/oracle/chart/awr/sysmetric.chart @@ -10,15 +10,15 @@ &TITLE: V={GV$SYSMETRIC_HISTORY}, D={DBA_HIST_SYSMETRIC_SUMMARY} &CAT : { default={1=1}, - eff={METRIC_NAME in ('CPU Usage Per Sec','CPU Usage Per Txn','Database CPU Time Ratio', - 'Database Wait Time Ratio','Executions Per Sec','Executions Per Txn', - 'Response Time Per Txn','SQL Service Response Time','User Transaction Per Sec')} + eff={METRIC_NAME in ('Host CPU Utilization (%)','Database CPU Time Ratio', + 'Database Wait Time Ratio','Executions Per Sec', + 'SQL Service Response Time','Physical Read Total IO Requests Per Sec','Physical Write Total IO Requests Per Sec')} } ]]-- ]]*/ { - _attrs=[[select 'Sysmetric History(&TITLE)' title from dual]], + _attrs=[[select 'System Metric History(&TITLE)' title from dual]], _sql=[[ SELECT sample_time, REPLACE(METRIC_NAME, ' Per ', ' / ') metric_name, diff --git a/oracle/ora/ash/ashtop.sql b/oracle/ora/ash/ashtop.sql index c70ed8aa..02cc96da 100644 --- a/oracle/ora/ash/ashtop.sql +++ b/oracle/ora/ash/ashtop.sql @@ -1,7 +1,16 @@ /*[[ Get ASH top event, type 'help @@NAME' for more info. Usage: @@NAME [-sql|-p|-none|-pr|-o|-plan|-ash|-dash|-snap|-f] {[fields] [filters]} --[[ - &fields: sql={sql_id},e={null}, p={p1,p2,p3,p3text},pr={p1raw,p2raw,p3raw}, o={obj},plan={plan_hash,current_obj#,SQL_PLAN_LINE_ID} none={1} + &fields: { + sql={sql_id}, + e={null}, + p={p1,p2,p3,p3text}, + pr={p1raw,p2raw,p3raw}, + o={obj}, + plan={plan_hash,current_obj#,SQL_PLAN_LINE_ID} + none={1}, + proc={sql_id,PLSQL_ENTRY_OBJECT_ID}, + } &View: ash={gv$active_session_history}, dash={Dba_Hist_Active_Sess_History} &BASE: ash={1}, dash={10} &Range: default={sample_time+0 between nvl(to_date(nvl(:V2,:starttime),'YYMMDDHH24MISS'),sysdate-1) and nvl(to_date(nvl(:V3,:endtime),'YYMMDDHH24MISS'),sysdate)} @@ -22,6 +31,7 @@ -pr : group by event+p1raw,p2raw,p3raw -o : group by event+object_id -plan: group by sql plan line(for 11g) + -proc: group by procedure name DataSource: -ash : source table is gv$active_session_history(default) -dash: source table is dba_hist_active_sess_history diff --git a/oracle/ora/block.sql b/oracle/ora/block.sql index 86935bc6..d48d5a47 100644 --- a/oracle/ora/block.sql +++ b/oracle/ora/block.sql @@ -1,8 +1,15 @@ -/*[[Show object info for the input block in bh. Usage: @@NAME ]]*/ +/*[[Show object info for the input block in bh. Usage: @@NAME + --[[ + @CHECK_ACCESS_SEG: { + sys.seg$={select HWMINCR objd,file# from sys.seg$ where :V2 between block# and block#-1+blocks}, + default={select objd,file# from gv$bh where block#=:V2} + } + @CHECK_ACCESS_OBJ: dba_objects={dba_objects}, default={all_objects} + --]] +]]*/ SELECT b.* -FROM gv$bh a, all_objects b +FROM (&CHECK_ACCESS_SEG) a, &CHECK_ACCESS_OBJ b WHERE rownum < 2 AND file# = :V1 -AND block# = :V2 -AND objd IN (object_id, data_object_id) +AND objd = data_object_id diff --git a/oracle/snap/sesstat.snap b/oracle/snap/sesstat.snap index e57151f8..3d783e7c 100644 --- a/oracle/snap/sesstat.snap +++ b/oracle/snap/sesstat.snap @@ -1,4 +1,4 @@ -/*[[Generate delta values based on gv$sesstat. Usage: @@NAME {[] [] []}]]*/ +/*[[Generate delta values based on gv$sesstat. Usage: @@NAME {[0|] [] []}]]*/ { sql=[[ SELECT A.*,VALUE DELTA FROM( @@ -35,7 +35,7 @@ USING (inst_id, statistic#) WHERE (VALUE > 0 OR :V3 IS NOT NULL) AND (:V3 IS NULL OR lower(name) like lower('%&V3%')) - AND (:V1 IS NULL OR sid=:V1) + AND (:V1 IS NULL OR sid=decode(:V1,'0',userenv('sid'),:V1)) AND (:V2 IS NULL OR inst_id=:V2)) A ORDER BY NAME]], agg_cols="Delta", diff --git a/oracle/snap/sestime.snap b/oracle/snap/sestime.snap index a23aba5e..b85d46de 100644 --- a/oracle/snap/sestime.snap +++ b/oracle/snap/sestime.snap @@ -1,4 +1,4 @@ -/*[[Generate delta values based on gv$session_event,gv$sess_time_model. Usage: @@NAME { [] [keyword]}]]*/ +/*[[Generate delta values based on gv$session_event,gv$sess_time_model. Usage: @@NAME {<0|sid> [] [keyword]}]]*/ { sql=[[ SELECT /*+no_expand*/ a.* @@ -9,7 +9,7 @@ SELECT inst_id, SID, 'Event', event,total_waits, TIME_WAITED_MICRO * 1e-6 t FROM gv$session_event where wait_class!='Idle' or :V3 is not null) a - WHERE (sid = :V1 or :V1 IS NULL) and (:V2 IS NULL OR inst_id=:V2) and (:V3 is null or lower(name) like '%&V3%') + WHERE (:V1 IS NULL or sid=decode(:V1,'0',userenv('sid'),:V1)) and (:V2 IS NULL OR inst_id=:V2) and (:V3 is null or lower(name) like '%&V3%') ]], agg_cols="secs,count", grp_cols="inst_id,sid,class#,name", diff --git a/oracle/sqlplus/xplan_ash.sql b/oracle/sqlplus/xplan_ash.sql index a3601ddc..084a4731 100644 --- a/oracle/sqlplus/xplan_ash.sql +++ b/oracle/sqlplus/xplan_ash.sql @@ -1,6 +1,6 @@ -- Store current SQL*Plus environment -- This requires at least a 10.2 SQL*Plus version to work -store set .xplan_settings replace +--store set .xplan_settings replace set echo off verify off termout off timing off define "&" concat "." trimspool on -- If you need to debug, uncomment the following line -- set echo on verify on termout on @@ -14231,4 +14231,4 @@ end; / -- Restore previous SQL*Plus environment -@.xplan_settings \ No newline at end of file +--@.xplan_settings \ No newline at end of file diff --git a/oracle/tracefile.lua b/oracle/tracefile.lua index 33bc3b16..58582425 100644 --- a/oracle/tracefile.lua +++ b/oracle/tracefile.lua @@ -1,6 +1,7 @@ local env=env local db,grid=env.getdb(),env.grid local trace={} +local tracefile function trace.get_trace(filename,mb,from_mb) local sql=[[ DECLARE @@ -95,18 +96,24 @@ function trace.get_trace(filename,mb,from_mb) if filename=="default" or lv then if lv then db:internal_call("alter session set tracefile_identifier='dbcli_"..math.random(1e6).."'"); + tracefile=nil end - if db.props.db_version>'11' then - filename=db:get_value[[select value from v$diag_info where name='Default Trace File']] + if not tracefile then + if db.props.db_version>'11' then + filename=db:get_value[[select value from v$diag_info where name='Default Trace File']] + else + filename=db:get_value[[SELECT u_dump.value || '/' || SYS_CONTEXT('userenv','instance_name') || '_ora_' || p.spid || + nvl2(p.traceid, '_' || p.traceid, NULL) || '.trc' "Trace File" + FROM v$parameter u_dump + CROSS JOIN v$process p + JOIN v$session s + ON p.addr = s.paddr + WHERE u_dump.name = 'user_dump_dest' + AND s.audsid = sys_context('userenv', 'sessionid')]] + end + tracefile=filename else - filename=db:get_value[[SELECT u_dump.value || '/' || SYS_CONTEXT('userenv','instance_name') || '_ora_' || p.spid || - nvl2(p.traceid, '_' || p.traceid, NULL) || '.trc' "Trace File" - FROM v$parameter u_dump - CROSS JOIN v$process p - JOIN v$session s - ON p.addr = s.paddr - WHERE u_dump.name = 'user_dump_dest' - AND s.audsid = sys_context('userenv', 'sessionid')]] + filename,tracefile=tracefile,nil end if lv then if lv > 0 then @@ -133,16 +140,23 @@ function trace.get_trace(filename,mb,from_mb) print("Result written to file "..env.write_cache(args[2],args[3])) end -env.set_command(nil,{"loadtrace","dumptrace"},[[ - Download Oracle trace file into local directory. Usage: @@NAME { [MB] [begin_MB]} - This command requires the "create directory" privilige. - Parameters: - trace_file: 1) The absolute path of the target trace file, or - 2) "default" to extract current session's trace, or - 4) 0/1/4/8/12 to enable 10046 trace with specific level - 3) "alert" to extract local instance's alert log. - MB : MegaBytes to extract, default as 2 MB. - begin_MB : The start file position(in MB) to extract, default as "total_MB - " - ]],trace.get_trace,false,4) +function trace.reset() + tracefile=nil +end + +function trace.onload() + env.set_command(nil,{"loadtrace","dumptrace"},[[ + Download Oracle trace file into local directory. Usage: @@NAME { [MB] [begin_MB]} + This command requires the "create directory" privilige. + Parameters: + trace_file: 1) The absolute path of the target trace file, or + 2) "default" to extract current session's trace, or + 4) 0/1/4/8/12 to enable 10046 trace with specific level + 3) "alert" to extract local instance's alert log. + MB : MegaBytes to extract, default as 2 MB. + begin_MB : The start file position(in MB) to extract, default as "total_MB - " + ]],trace.get_trace,false,4) + env.event.snoop("AFTER_ORACLE_CONNECT",trace.reset) +end return trace \ No newline at end of file diff --git a/oracle/xplan.lua b/oracle/xplan.lua index 72510137..758b76ee 100644 --- a/oracle/xplan.lua +++ b/oracle/xplan.lua @@ -3,8 +3,8 @@ local xplan={} local default_fmt,e10053,prof="ALLSTATS ALL -PROJECTION OUTLINE REMOTE" function xplan.explain(fmt,sql) local ora,sqltext=db.C.ora - e10053=false env.checkhelp(fmt) + e10053=false if fmt:sub(1,1)=='-' then if not sql then return end fmt=fmt:sub(2)