數據緩沖區的命中率已經不是性能調整中的主要問題了但是過低的命中率肯定是不可以的在任何情況下我們必須保證有一個大的data buffer和一個高的命中率
這個語句可以獲得整體的數據緩沖命中率
越高越好
Code: [Copy to clipboard]
SELECT a
VALUE + b
VALUE logical_reads
c
VALUE phys_reads
round(
*(
c
value/(a
value+b
value))
) hit_ratio
FROM v$sysstat a
v$sysstat b
v$sysstat c
WHERE a
NAME=
db block gets
AND b
NAME=
consistent gets
AND c
NAME=
physical reads
庫緩沖說明了SQL語句的重載率當然一個SQL語句應當被執行的越多越好如果重載率比較高就考慮增加共享池大小或者是提高Bind變量的使用以下語句查詢了Sql語句的重載率越低越好
Code: [Copy to clipboard]
SELECT SUM(pins) total_pins
SUM(reloads) total_reloads
SUM(reloads)/SUM(pins)*
libcache_reload_ratio
FROM v$librarycache
用戶鎖數據庫的鎖有的時候是比較耗費資源的特別是發生鎖等待的時候我們必須找到發生等待的鎖有可能的話殺掉該進程
這個語句將查找到數據庫中所有的DML語句產生的鎖
還可以發現
任何DML語句其實產生了兩個鎖
一個是表鎖
一個是行鎖
可以通過alter system kill session
sid
serial#
來殺掉會話
Code: [Copy to clipboard]
SELECT /*+ rule */ s
username
decode(l
type
TM
TABLE LOCK
TX
ROW LOCK
NULL) LOCK_LEVEL
o
owner
o
object_name
o
object_type
s
sid
s
serial#
s
terminal
s
machine
s
program
s
osuser
FROM v$session s
v$lock l
dba_objects o
WHERE l
sid = s
sid
AND l
id
= o
object_id(+)
AND s
username is NOT NULL
鎖與等待如果發生了鎖等待我們可能更想知道是誰鎖了表而引起誰的等待以下的語句可以查詢到誰鎖了表而誰在等待
Code: [Copy to clipboard]
SELECT /*+ rule */ lpad(
decode(l
xidusn
))||l
oracle_username User_name
o
owner
o
object_name
o
object_type
s
sid
s
serial#
FROM v$locked_object l
dba_objects o
v$session s
WHERE l
object_id=o
object_id
AND l
session_id=s
sid
ORDER BY o
object_id
xidusn DESC
以上查詢結果是一個樹狀結構
如果有子節點
則表示有等待發生
如果想知道鎖用了哪個回滾段
還可以關聯到V$rollname
其中xidusn就是回滾段的USN
如果發生了事務或鎖想知道哪些回滾段正在被使用嗎?其實通過事務表我們可以詳細的查詢到事務與回滾段之間的關系同時如果關聯會話表我們則可以知道是哪個會話發動了這個事務
Code: [Copy to clipboard]
SELECT s
USERNAME
s
SID
s
SERIAL#
t
UBAFIL
UBA filenum
t
UBABLK
UBA Block number
t
USED_UBLK
Number os undo Blocks Used
t
START_TIME
t
STATUS
t
START_SCNB
t
XIDUSN RollID
r
NAME RollName
FROM v$session s
v$transaction t
v$rollname r
WHERE s
SADDR=t
SES_ADDR
AND t
XIDUSN=r
usn
如果利用會話跟蹤或者是想查看某個會話的跟蹤文件那麼查詢到OS上的進程或線程號是非常重要的因為文件的令名中就包含這個信息以下的語句可以查詢到進程或線程號由此就可以找到對應的文件
Code: [Copy to clipboard]
SELECT p
value||
\
||p
value||
_ora_
||p
spid filename
FROM
v$process p
v$session s
v$parameter p
v$parameter p
WHERE p
name =
user_dump_dest
AND p
name =
db_name
AND p
addr = s
paddr
AND s
audsid = USERENV (
SESSIONID
);
在ORACLE i中可以監控索引的使用如果沒有使用到的索引完全可以刪除掉減少DML操作時的操作
以下就是開始索引監控與停止索引監控的腳本
Code: [Copy to clipboard]
set heading off
set echo off
set feedback off
set pages
spool start_index_monitor
sql
SELECT
alter index
||owner||
||index_name||
monitoring usage;
FROM dba_indexes
WHERE owner = USER;
spool off
set heading on
set echo on
set feedback on
set heading off
set echo off
set feedback off
set pages
spool stop_index_monitor
sql
SELECT
alter index
||owner||
||index_name||
nomonitoring usage;
FROM dba_indexes
WHERE owner = USER;
spool off
set heading on
set echo on
set feedback on
如果需要監控更多的用戶
可以將owner=User改寫成別的監控結果在視圖v$object_usage中查詢
Code: [Copy to clipboard]
CREATE OR REPLACE PROCEDURE show_space
( p_segname IN VARCHAR
p_owner IN VARCHAR
DEFAULT USER
p_type IN VARCHAR
DEFAULT
TABLE
p_partition IN VARCHAR
DEFAULT NULL )
This procedure uses AUTHID CURRENT USER so it can query DBA_*
views using privileges from a ROLE and so it can be installed
once per database
instead of once per user who wanted to use it
AUTHID CURRENT_USER
as
l_free_blks number;
l_total_blocks number;
l_total_bytes number;
l_unused_blocks number;
l_unused_bytes number;
l_LastUsedExtFileId number;
l_LastUsedExtBlockId number;
l_LAST_USED_BLOCK number;
l_segment_space_mgmt varchar
(
);
l_unformatted_blocks number;
l_unformatted_bytes number;
l_fs
_blocks number; l_fs
_bytes number;
l_fs
_blocks number; l_fs
_bytes number;
l_fs
_blocks number; l_fs
_bytes number;
l_fs
_blocks number; l_fs
_bytes number;
l_full_blocks number; l_full_bytes number;
Inline procedure to print out numbers nicely formatted
with a simple label
PROCEDURE p( p_label in varchar
p_num in number )
IS
BEGIN
dbms_output
put_line( rpad(p_label
) ||
to_char(p_num
) );
END;
BEGIN
This query is executed dynamically in order to allow this procedure
to be created by a user who has access to DBA_SEGMENTS/TABLESPACES
via a role as is customary
NOTE: at runtime
the invoker MUST have access to these two
views!
This query determines if the object is an ASSM object or not
BEGIN
EXECUTE IMMEDIATE
select ts
segment_space_management
FROM dba_segments seg
dba_tablespaces ts
WHERE seg
segment_name = :p_segname
AND (:p_partition is null or
seg
partition_name = :p_partition)
AND seg
owner = :p_owner
AND seg
tablespace_name = ts
tablespace_name
INTO l_segment_space_mgmt
USING p_segname
p_partition
p_partition
p_owner;
EXCEPTION
WHEN too_many_rows THEN
dbms_output
put_line
(
This must be a partitioned table
use p_partition =>
);
RETURN;
END;
If the object is in an ASSM tablespace
we must use this API
call to get space information; else we use the FREE_BLOCKS
API for the user managed segments
IF l_segment_space_mgmt =
AUTO
THEN
dbms_space
space_usage
( p_owner
p_segname
p_type
l_unformatted_blocks
l_unformatted_bytes
l_fs
_blocks
l_fs
_bytes
l_fs
_blocks
l_fs
_bytes
l_fs
_blocks
l_fs
_bytes
l_fs
_blocks
l_fs
_bytes
l_full_blocks
l_full_bytes
p_partition);
p(
Unformatted Blocks
l_unformatted_blocks );
p(
FS
Blocks (
)
l_fs
_blocks );
p(
FS
Blocks (
)
l_fs
_blocks );
p(
FS
Blocks (
)
l_fs
_blocks );
p(
FS
Blocks (
)
l_fs
_blocks );
p(
Full Blocks
l_full_blocks );
ELSE
dbms_space
free_blocks(
segment_owner => p_owner
segment_name => p_segname
segment_type => p_type
freelist_group_id =>
free_blks => l_free_blks);
p(
Free Blocks
l_free_blks );
END IF;
And then the unused space API call to get the rest of the
information
dbms_space
unused_space
( segment_owner => p_owner
segment_name => p_segname
segment_type => p_type
partition_name => p_partition
total_blocks => l_total_blocks
total_bytes => l_total_bytes
unused_blocks => l_unused_blocks
unused_bytes => l_unused_bytes
LAST_USED_EXTENT_FILE_ID => l_LastUsedExtFileId
LAST_USED_EXTENT_BLOCK_ID => l_LastUsedExtBlockId
LAST_USED_BLOCK => l_LAST_USED_BLOCK );
p(
Total Blocks
l_total_blocks );
p(
Total Bytes
l_total_bytes );
p(
Total MBytes
trunc(l_total_bytes/
/
) );
p(
Unused Blocks
l_unused_blocks );
p(
Unused Bytes
l_unused_bytes );
p(
Last Used Ext FileId
l_LastUsedExtFileId );
p(
Last Used Ext BlockId
l_LastUsedExtBlockId );
p(
Last Used Block
l_LAST_USED_BLOCK );
END;
From:http://tw.wingwit.com/Article/program/Oracle/201311/18788.html