oracle實用sql(7)--單個會話或會話間statistics對比
點選(此處)摺疊或開啟
-
--初始化建表
-
declare
-
v_count number;
-
begin
-
select count(1) into v_count from dba_tables where owner='SCOTT' and table_name='T_STAT_TEMP';
-
if v_count=1 then
-
execute immediate 'truncate table scott.t_stat_temp';
-
else
-
execute immediate 'create table scott.t_stat_temp(snap_id integer,name varchar2(100),value int)';
-
end if;
-
end;
-
-
-
--Run1執行前收集
-
--可從v$mystat中得到當前會話id,或從v$session中得到某會話id
-
insert into scott.t_stat_temp
-
select 1,a.name,b.value
-
from v$statname a,v$sesstat b
-
where a.statistic#=b.statistic# and b.sid=46
-
and a.name in ('table scans (long tables)','bytes received via SQL*Net from client',
-
'bytes received via SQL*Net from dblink','consistent changes','consistent gets',
-
'CPU used by this session','physical reads','physical writes','session pga memory','session pga memory max',
-
'session uga memory','session logical reads','session uga memory max','sorts (disk)','sorts (memory)','table fetch continued row',
-
'opened cursors cumulative','opened cursors current','DDL statements parallelized','DML statements parallelized','queries parallelized',
-
'buffer is not pinned count','parse time cpu','redo blocks written','redo buffer allocation retries','redo entries',
-
'redo log space requests','redo size','redo synch time','redo synch writes','redo wastage','redo write time',
-
'redo writer latching time','redo writes');
-
commit;
-
-
/*執行語句或等待某會話執行*/
-
-
--Run1執行後收集
-
insert into scott.t_stat_temp
-
select 2,a.name,b.value
-
from v$statname a,v$sesstat b
-
where a.statistic#=b.statistic# and b.sid=46
-
and a.name in ('table scans (long tables)','bytes received via SQL*Net from client',
-
'bytes received via SQL*Net from dblink','consistent changes','consistent gets',
-
'CPU used by this session','physical reads','physical writes','session pga memory','session pga memory max',
-
'session uga memory','session logical reads','session uga memory max','sorts (disk)','sorts (memory)','table fetch continued row',
-
'opened cursors cumulative','opened cursors current','DDL statements parallelized','DML statements parallelized','queries parallelized',
-
'buffer is not pinned count','parse time cpu','redo blocks written','redo buffer allocation retries','redo entries',
-
'redo log space requests','redo size','redo synch time','redo synch writes','redo wastage','redo write time',
-
'redo writer latching time','redo writes');
-
commit;
-
-
--檢視Run1的statistics
-
select a.name,a.value begin_value,b.value end_value,b.value-a.value diff
-
from scott.t_stat_temp a, scott.t_stat_temp b
-
where a.name=b.name and a.snap_id=1 and b.snap_id=2
-
order by 1 ;
-
-
-
-
--若要對比Run2,繼續
-
--Run2執行前收集
-
--可從v$mystat中得到當前會話id,或從v$session中得到某會話id
-
insert into scott.t_stat_temp
-
select 3,a.name,b.value
-
from v$statname a,v$sesstat b
-
where a.statistic#=b.statistic# and b.sid=46
-
and a.name in ('table scans (long tables)','bytes received via SQL*Net from client',
-
'bytes received via SQL*Net from dblink','consistent changes','consistent gets',
-
'CPU used by this session','physical reads','physical writes','session pga memory','session pga memory max',
-
'session uga memory','session logical reads','session uga memory max','sorts (disk)','sorts (memory)','table fetch continued row',
-
'opened cursors cumulative','opened cursors current','DDL statements parallelized','DML statements parallelized','queries parallelized',
-
'buffer is not pinned count','parse time cpu','redo blocks written','redo buffer allocation retries','redo entries',
-
'redo log space requests','redo size','redo synch time','redo synch writes','redo wastage','redo write time',
-
'redo writer latching time','redo writes');
-
commit;
-
/*執行語句或等待某會話執行*/
-
-
-
-
--Run2執行後收集
-
insert into scott.t_stat_temp
-
select 4,a.name,b.value
-
from v$statname a,v$sesstat b
-
where a.statistic#=b.statistic# and b.sid=46
-
and a.name in ('table scans (long tables)','bytes received via SQL*Net from client',
-
'bytes received via SQL*Net from dblink','consistent changes','consistent gets',
-
'CPU used by this session','physical reads','physical writes','session pga memory','session pga memory max',
-
'session uga memory','session logical reads','session uga memory max','sorts (disk)','sorts (memory)','table fetch continued row',
-
'opened cursors cumulative','opened cursors current','DDL statements parallelized','DML statements parallelized','queries parallelized',
-
'buffer is not pinned count','parse time cpu','redo blocks written','redo buffer allocation retries','redo entries',
-
'redo log space requests','redo size','redo synch time','redo synch writes','redo wastage','redo write time',
-
'redo writer latching time','redo writes');
-
commit;
-
-
--檢視Run2的statistics
-
select a.name,a.value begin_value,b.value end_value,b.value-a.value diff
-
from scott.t_stat_temp a, scott.t_stat_temp b
-
where a.name=b.name and a.snap_id=3 and b.snap_id=4
-
order by 1 ;
-
-
--Run1,Run2 statistics對比
-
select c.name,c.begin_value run1_begin_value,c.end_value run2_end_value,
-
d.begin_value run2_begin_value,d.end_value run2_end_value,
-
c.end_value-c.begin_value run1_diff,d.end_value-d.begin_value run2_diff,
-
(d.end_value-d.begin_value)-(c.end_value-c.begin_value) run1_run2_diff
-
from ( select a.name,a.value begin_value,b.value end_value,b.value-a.value diff
-
from scott.t_stat_temp a, scott.t_stat_temp b
-
where a.name=b.name and a.snap_id=1 and b.snap_id=2) c,
-
( select a.name,a.value begin_value,b.value end_value,b.value-a.value diff
-
from scott.t_stat_temp a, scott.t_stat_temp b
-
where a.name=b.name and a.snap_id=3 and b.snap_id=4) d
-
where c.name=d.name
- order by 1;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28539951/viewspace-2114789/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle 會話(Session)Oracle會話Session
- oracle鎖會話Oracle會話
- 修改oracle會話時間表達方式Oracle會話
- sql 注入將會是一個笑話SQL
- ?ORACLE會話超時Oracle會話
- Oracle跟蹤會話Oracle會話
- oracle 會話,連線Oracle會話
- 會話級SQL跟蹤會話SQL
- Oracle 查詢佔用臨時表空間大的歷史會話和SQLOracle會話SQL
- 使用Oracle PROFILE控制會話空閒時間Oracle會話
- oracle的會話如何自殺?Oracle會話
- Oracle阻塞會話查詢Oracle會話
- oracle session(會話) 跟蹤OracleSession會話
- 【會話】Oracle kill session系列會話OracleSession
- oracle遭遇大量SNIPED會話Oracle會話
- 查 sql or 會話的進度SQL會話
- 用SQL Server來進行會話狀態管理SQLServer會話
- Oracle:select 或 inactive 會話語句產生鎖?Oracle會話
- Windows下大量SYSMAN會話超出會話限制Windows會話
- 設定SQL*Plus會話環境SQL會話
- 會話管理會話
- Session會話Session會話
- oracle 定期清理inactive會話Oracle會話
- oracle中會話的狀態Oracle會話
- SQL Server Service Broker建立單個資料庫會話(訊息佇列)SQLServer資料庫會話佇列
- 話單sqlSQL
- 用Oracle跟蹤診斷掛起的會話Oracle會話
- SQL Server AlwaysOn可用性副本會話期間的可能故障SQLServer會話
- 10046事件跟蹤會話sql事件會話SQL
- Oracle會話超時退出設定Oracle會話
- oracle 10046當前會話Oracle會話
- Oracle kill會話--sed修改檔案Oracle會話
- oracle會話監控shell指令碼Oracle會話指令碼
- -t【Oracle-故障管理】-Trace跟蹤會話和會話執行慢故障分析Oracle會話
- 讓 sudo 會話時間隨心所欲會話
- MQTT-會話MQQT會話
- 利用sql_trace跟蹤一個指定會話的操作SQL會話
- byobu複用SSH會話的技巧會話