--查找表空间IO情况
set linesize 200
set feedback off
set verify off
col tablespace for a20
--drop temporary table
drop table TEMP_HIST_FILESTATXS;
drop table TEMP_HIST_TEMPSTATXS;
--create temporary table
CREATE GLOBAL TEMPORARY TABLE TEMP_HIST_FILESTATXS(SNAP_ID NUMBER,
FILE# NUMBER NOT NULL
ENABLE,
CREATION_CHANGE#
NUMBER,
FILENAME VARCHAR2(600),
TS# NUMBER NOT NULL
ENABLE,
TSNAME VARCHAR2(30)
NOT NULL ENABLE,
BLOCK_SIZE NUMBER
NOT NULL ENABLE,
PHYRDS NUMBER,
PHYWRTS NUMBER,
SINGLEBLKRDS NUMBER,
READTIM NUMBER,
WRITETIM NUMBER,
SINGLEBLKRDTIM NUMBER,
PHYBLKRD NUMBER,
PHYBLKWRT NUMBER,
WAIT_COUNT NUMBER,
TIME NUMBER) ON COMMIT PRESERVE ROWS;
CREATE GLOBAL TEMPORARY TABLE TEMP_HIST_TEMPSTATXS(SNAP_ID NUMBER,
FILE# NUMBER NOT NULL
ENABLE,
CREATION_CHANGE#
NUMBER,
FILENAME VARCHAR2(600),
TS# NUMBER NOT NULL
ENABLE,
TSNAME VARCHAR2(30)
NOT NULL ENABLE,
BLOCK_SIZE NUMBER
NOT NULL ENABLE,
PHYRDS NUMBER,
PHYWRTS NUMBER,
SINGLEBLKRDS NUMBER,
READTIM NUMBER,
WRITETIM NUMBER,
SINGLEBLKRDTIM NUMBER,
PHYBLKRD NUMBER,
PHYBLKWRT NUMBER,
WAIT_COUNT NUMBER,
TIME NUMBER) ON COMMIT PRESERVE ROWS;
--first snapshot
insert into TEMP_HIST_FILESTATXS
select 1 snap_id,
f.file#,
f.creation_change#,
fn.filename,
fn.ts#,
fn.tsname,
fn.block_size,
phyrds,
phywrts,
singleblkrds,
readtim,
writetim,
singleblkrdtim,
phyblkrd,
phyblkwrt,
wait_count,
time
from (select df.file#,
(df.crscnbas + (df.crscnwrp * power(2, 32))) creation_change#,
fs.kcfiopyr phyrds,
fs.kcfiopyw phywrts,
fs.kcfiosbr singleblkrds,
fs.kcfioprt readtim,
fs.kcfiopwt writetim,
fs.kcfiosbt singleblkrdtim,
fs.kcfiopbr phyblkrd,
fs.kcfiopbw phyblkwrt,
fw.count wait_count,
fw.time time
from x$kcfio fs, file$ df, x$kcbfwait fw
where fw.indx + 1 = fs.kcfiofno
and df.file# = fs.kcfiofno
and df.status$ = 2) f,
(select file#,
creation_change#,
filename,
ts#,
tsname,
block_size
from (SELECT /*+ ordered index(f) index(ts) */
f.file# file#,
f.crscnbas + (f.crscnwrp * power(2, 32)) creation_change#,
v.name filename,
ts.ts# ts#,
ts.name tsname,
ts.blocksize block_size
FROM v$dbfile v, file$ f, ts$ ts
WHERE f.file# = v.file#
and f.status$ = 2
and f.ts# = ts.ts#)) fn
where f.file# = fn.file#
and f.creation_change# = fn.creation_change#;
commit;
insert into TEMP_HIST_TEMPSTATXS
select 1 snap_id,
t.file#,
t.creation_change#,
tn.filename,
tn.ts#,
tn.tsname,
tn.block_size,
phyrds,
phywrts,
singleblkrds,
readtim,
writetim,
singleblkrdtim,
phyblkrd,
phyblkwrt,
wait_count,
time
from (select tf.tfnum file#,
to_number(tf.tfcrc_scn) creation_change#,
ts.kcftiopyr phyrds,
ts.kcftiopyw phywrts,
ts.kcftiosbr singleblkrds,
ts.kcftioprt readtim,
ts.kcftiopwt writetim,
ts.kcftiosbt singleblkrdtim,
ts.kcftiopbr phyblkrd,
ts.kcftiopbw phyblkwrt,
fw.count wait_count,
fw.time time
from x$kcftio ts, x$kcctf tf, x$kcbfwait fw
where tf.tfdup != 0
and tf.tfnum = ts.kcftiofno
and fw.indx + 1 =
(ts.kcftiofno +
(select value from v$parameter where name = 'db_files'))) t,
(select file#,
creation_change#,
filename,
ts#,
tsname,
block_size
from (SELECT tf.file# file#,
tf.creation_change# creation_change#,
tf.name filename,
ts.ts# ts#,
ts.name tsname,
tf.block_size block_size
FROM v$tempfile tf, ts$ ts
WHERE tf.ts# = ts.ts#)) tn
where t.file# = tn.file#
and t.creation_change# = tn.creation_change#;
commit;
--wait 30 seconds
exec sys.dbms_lock.sleep(30);
--second snapshot
insert into TEMP_HIST_FILESTATXS
select 2 snap_id,
f.file#,
f.creation_change#,
fn.filename,
fn.ts#,
fn.tsname,
fn.block_size,
phyrds,
phywrts,
singleblkrds,
readtim,
writetim,
singleblkrdtim,
phyblkrd,
phyblkwrt,
wait_count,
time
from (select df.file#,
(df.crscnbas + (df.crscnwrp * power(2, 32))) creation_change#,
fs.kcfiopyr phyrds,
fs.kcfiopyw phywrts,
fs.kcfiosbr singleblkrds,
fs.kcfioprt readtim,
fs.kcfiopwt writetim,
fs.kcfiosbt singleblkrdtim,
fs.kcfiopbr phyblkrd,
fs.kcfiopbw phyblkwrt,
fw.count wait_count,
fw.time time
from x$kcfio fs, file$ df, x$kcbfwait fw
where fw.indx + 1 = fs.kcfiofno
and df.file# = fs.kcfiofno
and df.status$ = 2) f,
(select file#,
creation_change#,
filename,
ts#,
tsname,
block_size
from (SELECT /*+ ordered index(f) index(ts) */
f.file# file#,
f.crscnbas + (f.crscnwrp * power(2, 32)) creation_change#,
v.name filename,
ts.ts# ts#,
ts.name tsname,
ts.blocksize block_size
FROM v$dbfile v, file$ f, ts$ ts
WHERE f.file# = v.file#
and f.status$ = 2
and f.ts# = ts.ts#)) fn
where f.file# = fn.file#
and f.creation_change# = fn.creation_change#;
commit;
insert into TEMP_HIST_TEMPSTATXS
select 2 snap_id,
t.file#,
t.creation_change#,
tn.filename,
tn.ts#,
tn.tsname,
tn.block_size,
phyrds,
phywrts,
singleblkrds,
readtim,
writetim,
singleblkrdtim,
phyblkrd,
phyblkwrt,
wait_count,
time
from (select tf.tfnum file#,
to_number(tf.tfcrc_scn) creation_change#,
ts.kcftiopyr phyrds,
ts.kcftiopyw phywrts,
ts.kcftiosbr singleblkrds,
ts.kcftioprt readtim,
ts.kcftiopwt writetim,
ts.kcftiosbt singleblkrdtim,
ts.kcftiopbr phyblkrd,
ts.kcftiopbw phyblkwrt,
fw.count wait_count,
fw.time time
from x$kcftio ts, x$kcctf tf, x$kcbfwait fw
where tf.tfdup != 0
and tf.tfnum = ts.kcftiofno
and fw.indx + 1 =
(ts.kcftiofno +
(select value from v$parameter where name = 'db_files'))) t,
(select file#,
creation_change#,
filename,
ts#,
tsname,
block_size
from (SELECT tf.file# file#,
tf.creation_change# creation_change#,
tf.name filename,
ts.ts# ts#,
ts.name tsname,
tf.block_size block_size
FROM v$tempfile tf, ts$ ts
WHERE tf.ts# = ts.ts#)) tn
where t.file# = tn.file#
and t.creation_change# = tn.creation_change#;
commit;
--tablespace_io_result
prompt the normal value of "Av Rd(ms)" is always 20~30ms
select e.tsname "Tablespace",
sum(e.phyrds - nvl(b.phyrds, 0)) "reads",
round(sum(e.phyrds - nvl(b.phyrds, 0)) / 30, 0) "Av Reads/s",
round(decode(sum(e.phyrds - nvl(b.phyrds, 0)),
0,
0,
10 * (sum(e.readtim - nvl(b.readtim, 0)) /
sum(e.phyrds - nvl(b.phyrds, 0)))),
2) "Av Rd(ms)",
round(decode(sum(e.phyrds - nvl(b.phyrds, 0)),
0,
0,
sum(e.phyblkrd - nvl(b.phyblkrd, 0)) /
sum(e.phyrds - nvl(b.phyrds, 0))),
2) "Av Blks/Rd",
sum(e.phywrts - nvl(b.phywrts, 0)) "writes",
round(sum(e.phywrts - nvl(b.phywrts, 0)) / 30, 0) "Av Writes/s",
sum(e.wait_count - nvl(b.wait_count, 0)) "Buffer Waits",
round(decode(sum(e.wait_count - nvl(b.wait_count, 0)),
0,
0,
10 * (sum(e.time - nvl(b.time, 0)) /
sum(e.wait_count - nvl(b.wait_count, 0)))),
2) "Av Buf Wt(ms)",
sum(e.phyrds - nvl(b.phyrds, 0)) +
sum(e.phywrts - nvl(b.phywrts, 0)) "Reads + Writes"
from TEMP_HIST_FILESTATXS e, TEMP_HIST_FILESTATXS b
where b.snap_id(+) = 1
and e.snap_id = 2
and b.tsname(+) = e.tsname
and b.file#(+) = e.file#
and b.creation_change#(+) = e.creation_change#
and ((e.phyrds - nvl(b.phyrds, 0)) + (e.phywrts - nvl(b.phywrts, 0))) > 0
group by e.tsname
union all
select e.tsname "Tablespace",
sum(e.phyrds - nvl(b.phyrds, 0)) "reads",
sum(e.phyrds - nvl(b.phyrds, 0)) / 30 "Av Reads/s",
decode(sum(e.phyrds - nvl(b.phyrds, 0)),
0,
0,
10 * (sum(e.readtim - nvl(b.readtim, 0)) /
sum(e.phyrds - nvl(b.phyrds, 0)))) "Av Rd(ms)",
decode(sum(e.phyrds - nvl(b.phyrds, 0)),
0,
0,
sum(e.phyblkrd - nvl(b.phyblkrd, 0)) /
sum(e.phyrds - nvl(b.phyrds, 0))) "Av Blks/Rd",
sum(e.phywrts - nvl(b.phywrts, 0)) "writes",
sum(e.phywrts - nvl(b.phywrts, 0)) / 30 "Av Writes/s",
sum(e.wait_count - nvl(b.wait_count, 0)) "Buffer Waits",
decode(sum(e.wait_count - nvl(b.wait_count, 0)),
0,
0,
10 * (sum(e.time - nvl(b.time, 0)) /
sum(e.wait_count - nvl(b.wait_count, 0)))) "Av Buf Wt(ms)",
sum(e.phyrds - nvl(b.phyrds, 0)) +
sum(e.phywrts - nvl(b.phywrts, 0)) "Reads + Writes"
from TEMP_HIST_TEMPSTATXS e, TEMP_HIST_TEMPSTATXS b
where b.snap_id(+) = 1
and e.snap_id = 2
and b.tsname(+) = e.tsname
and b.file#(+) = e.file#
and b.creation_change#(+) = e.creation_change#
and ((e.phyrds - nvl(b.phyrds, 0)) + (e.phywrts - nvl(b.phywrts, 0))) > 0
group by e.tsname
order by "Reads + Writes" desc, "Tablespace";
exit;
|