問題描述:
開發人員報告系統運行緩慢
使用vmstat檢查
bash
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr s
觀察進程CPU耗用
$ top
last pid:
CPU states:
Memory:
PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND
bash
bash
bash
bash
bash
bash
發現系統存在大量Oracle進程
查詢v$session_wait獲取各進程等待事件
SQL> select sid
SID EVENT P
SID EVENT P
SID EVENT P
SID EVENT P
SID EVENT P
SID EVENT P
SID EVENT P
SID EVENT P
SID EVENT P
SID EVENT P
SID EVENT P
SID EVENT P
SID EVENT P
發現存在大量db file scattered read及db file sequential read等待
這裡用到了我的以下腳本getsqlbysid
SELECT sql_text
FROM v$sqltext a
WHERE a
FROM v$session b
WHERE b
ORDER BY piece ASC
/
SQL> @getsql
Enter value for sid:
old
new
SQL_TEXT
select i
ledflag =
sysdate and i
esc
SQL> /
Enter value for sid:
old
new
SQL_TEXT
select i
ledflag =
sysdate and i
c
SQL> /
Enter value for sid:
old
new
SQL_TEXT
select i
ledflag =
sysdate and i
c
對幾個全表掃描進程跟蹤以後
以上語句如果良好編碼應該使用綁定變量
使用該應用用戶連接
SQL> set autotrace trace explain
SQL> select i
Execution Plan
SQL> select count(*) from hs_info;
COUNT(*)
該表這裡有
檢查該表
SQL> select index_name
INDEX_NAME INDEX_TYPE
HSIDX_INFO
HSIDX_INFO_SEARCHKEY DOMAIN
PK_HS_INFO NORMAL
檢查索引鍵值:
SQL> select index_name
INDEX_NAME COLUMN_NAME
HSIDX_INFO
HSIDX_INFO
HSIDX_INFO_SEARCHKEY VC
PK_HS_INFO NUMINFOGUID
SQL> desc hs_info
Name Null? Type
NUMINFOGUID NOT NULL NUMBER(
NUMCATALOGGUID NOT NULL NUMBER(
INTTEXTTYPE NOT NULL NUMBER(
VC
VC
NUMPREVINFOGUID NUMBER(
NUMNEXTINFOGUID NUMBER(
NUMORDER NOT NULL NUMBER(
DATPUBLISHDATE NOT NULL DATE
INTPUBLISHSTATE NOT NULL NUMBER(
VC
VC
VC
VC
VC
NUMVISITED NOT NULL NUMBER(
INTENABLEDFLAG NOT NULL NUMBER(
DATCREATETIME NOT NULL DATE
DATMODIFYTIME NOT NULL DATE
VC
INTINFOTYPE NOT NULL NUMBER(
VC
VC
SQL> create index hs_info_NUMCATALOGGUID on hs_info(NUMCATALOGGUID);
Index created
SQL> set autotrace trace explain
SQL> select i
Execution Plan
原大量等待消失
SQL> select sid
SID EVENT P
SID EVENT P
持續觀察的CPU使用情況
bash
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr s
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr s
至此
From:http://tw.wingwit.com/Article/program/SQL/201311/16417.html