SlideShare une entreprise Scribd logo
1  sur  114
Oracle資料庫效能調整
⼀一天之旅
Oracle 11g/10g/9i OCM
申建忠
Performance Tuning ?
Trouble Shooting
Performance Tuning
Performance Tuning
• Reactive
• 問題已經發⽣生
• 修正問題(TroubleShooting)
• Proactive
• 問題尚未發⽣生,但有些徵兆出現
• 找出潛在瓶頸,提早解決,避免問題發⽣生
Tuning Methodology
• Top Down
• 盡可能在早期開始進⾏行效能調校
• Response Time
• 找出消耗資源最多的SQL敘述句
Top Down
Application Design
Application Development
Database Configuration
OS Configuration
Time
效能問題種類
Performanc
e
OS
DB
Application Code
(SQL) Design &
Architecture
20%
60%
15%
5%
Tuning Cost and Benefit
Time
Low
High
Design Development Production
Cost
Benefit
Response Time
Throughput
Time
Response time
Wait time
Service time
Response time=Service time+wait time
Reduce Service Time
Throughput
Time
Response time
Reduce Wait time
Throughput
Time
Response time
Wait time
Service time
RT Breakdown
User AP Server DB Server Disk
T1
T2
T3
T4
T5
T6
T7
T8
T9
T10
T11
T12
Time
Parse
Execute
Physical I/O
Execute
Execute
Fetch
Process User Request
Generate SQL
Process SQL Result
Generate Web Page
Request
Response
Memory
Logical I/O
Firewall
Physical I/O
Execute
T13
T14
Time
Network filter
OLTP/DW
A Data Warehouse(DW) is a relational database that is designed for query and analysis rather than
for transaction processing. It usually contains historical data derived from transaction data, but it can
include data from other sources. It separates analysis workload from transaction workload and
enables an organization to consolidate data from several sources.
In addition to a relational database, a data warehouse environment includes an extraction,
transportation, transformation, and loading (ETL) solution, an online analytical processing (OLAP)
engine, client analysis tools, and other applications that manage the process of gathering data and
delivering it to business users.
An Online Transaction Processing (OLTP) systems are characterized by high throughput, many users,
and a mix of DML operations (insert, update, and delete) and queries.
Difference between OLTP
and DW
OLTP DW
3rd Normal Form 表格設計 3NF/Star Schema
多 索引 少
多 Join 中
Normalized DB 資料重覆 DeNormalized DB
少
衍⽣生與彙總
資料
多
事先定義 SELECT Ad Hoc
次數多
每次資料量少
DML 次數少
每次資料量⼤大
Response Time⼩小
Throughput⼤大
系統要求 Response Time⼩小
OLTP
OLTP
OLTP
External
Source
DML
DML
DML
DML
DML
DML
DML
Extract
Transform
Load
Data
Mart
Data
Mart
Data
Mart
Data Warehouse
OLAP
BI
Ad
Hoc
Query
Report
Operational
Data Source
OLTP與DW的關聯
Bill Inmon架構
OLTP
OLTP
OLTP
External
Source
DML
DML
DML
DML
DML
DML
DML
Extract
Transform
Load
Data
Mart
(3rd NF)
Data
Mart
(3rd NF)
Data
Mart
(3rd NF)
Data Warehouse
(3rd NF)
OLAP
BI
Ad
Hoc
Query
Report
Operational
Data Source
Ralph Kimball架構
OLTP
OLTP
OLTP
External
Source
DML
DML
DML
DML
DML
DML
DML
Extract
Transform
Load
Data Warehouse
(Star Dimension)
OLAP
BI
Ad
Hoc
Query
Report
Operational
Data Source
Data
Mart
Data
Mart
Data
Mart
Tuning Goals
• 可被測量
• ⼀一秒鐘裡同時執⾏行1,000個SQL敘述句
• Batch操作可以在60分鐘內完成
• ⼀一個Physical I/O可以在5ms之內完成
• 儘快完成
• 可達到
• ⼀一個Physical I/O可以在1ms之內完成
SMON PMON CKPTDBWR LGWR ARCHRECO
Shared
Pool
Buffer Cache
Log
Buffer
Large
Pool
Java
Pool
Streams
pool
Control
file
Data File Data File Data File
Online
Logfile
Online
Logfile
Header Header Header
Group 1 Group 2
User
Process
Server
Process
Archived
Logfile
System Global Area(SGA)
Instance
Database
Program
Global
Area
Block Block
Block
S
Q
L
Redo Entry
Parse
SQL Text
Execution Plan
Execute
Fetch
Redo Entry Redo Entry Redo Entry
Redo Entry
Log Seq:12 Log Seq:11 Log Seq:11Log Seq:12
Log Seq:12Log Seq:12Log Seq:12
Listener
Data Dictionary
Information
Data Dictionary Cache
Library Cache
$ sqlplus hr/hr@orcl
SGA
Background
ProcessesServer
Process
Instance
Non-
Oracle
Process
Non-
Oracle
Process
CPUs
Non-
Oracle
Process
Non-
Oracle
Process
Non-Oracle
Memory
Non-Oracle
Files
Disks
CPU不⾜足
Memory不⾜足
I/O數量過多
SGA分配不當
I/O競爭
SQL沒效率
Non-
Oracle
Process
Non-
Oracle
Process
Fragmentation
Shared
Pool
Buffer
Cache
Log
Buffer
MemoryHard Parse過多
SGA
Database
Datafile Logfile
I/O太慢
P
G
A
PGA⼤大⼩小不當
Oracle Database Performance Tuning Concept
1) background elapsed time
2) background cpu time
3) RMAN cpu time (backup/restore)
1) DB time
2) DB CPU
2) connection management call elapsed time
2) sequence load elapsed time
2) sql execute elapsed time
2) parse time elapsed
3) hard parse elapsed time
4) hard parse (sharing criteria) elapsed time
5) hard parse (bind mismatch) elapsed time
3) failed parse elapsed time
4) failed parse (out of shared memory) elapsed time
2) PL/SQL execution elapsed time
2) inbound PL/SQL rpc elapsed time
2) PL/SQL compilation elapsed time
2) Java execution elapsed time
2) repeated bind elapsed time
Time Model
The relationship between a parent and a child in the tree indicates containment only.
Keep the following in mind with regard to the tree:
• Children do not necessarily add up to the parent.
• Children are not necessarily exclusive (that is, it is possible that they overlap).
• The union of children does not necessarily cover the whole of the parent.
Statistic Name Description
DB Time
Amount of elapsed time (in microseconds) spent performing Database user-level calls.This does not include the elapsed time spent on instance background
processes such as PMON.
DB CPU
Amount of CPU time (in microseconds) spent on database user-level calls.This does not include the CPU time spent on instance background processes such
as PMON.
background
elapsed time
Amount of elapsed time (in microseconds) consumed by database background processes.
background
CPU time
Amount of CPU time (in microseconds) consumed by database background processes.
sequential load
elapsed time
Amount of elapsed time spent getting the next sequence number from the data dictionary. If a sequence is cached, then this is the amount of time spent replenishing the
cache when it runs out. No time is charged when a sequence number is found in the cache. For non-cached sequences, some time will be charged for every nextval call.
parse time elapsed Amount of elapsed time spent parsing SQL statements. It includes both soft and hard parse time.
hard parse
elapsed time
Amount of elapsed time spent hard parsing SQL statements.
SQL execute
elapsed time
Amount of elapsed time SQL statements are executing. Note that for select statements this also includes the amount of time spent performing fetches of
query results.
connection management call
elapsed time
Amount of elapsed time spent performing session connect and disconnect calls.
failed parse
elapsed time
Amount of time spent performing SQL parses which ultimately fail with some parse error.
failed parse(out of shared
memory) elapsed time
Amount of time spent performing SQL parses which ultimately fail with error ORA-04031.
hard parse(sharing criteria)
elapsed time
Amount of elapsed time spent performing SQL hard parses when the hard parse resulted from not being able to share an existing cursor in the SQL cache.
hard parse(bind mismatch)
elapsed time
Amount of elapsed time spent performing SQL hard parses when the hard parse resulted from bind type or bind size mismatch with an existing cursor in
the SQL cache.
PL/SQL execution
elapsed time
Amount of elapsed time spent running the PL/SQL interpreter.This does not include time spent recursively executing/parsing SQL statements or time spent
recursively executing the JavaVM.
PL/SQL compilation
elapsed time
Amount of elapsed time spent running the PL/SQL compiler.
inbound PL/SQL rpc
elapsed time
Time inbound PL/SQL remote procedure calls have spent executing. It includes all time spent recursively executing SQL and JAVA, and therefore is not easily
related to "PL/SQL execution elapsed time".
Java execution elapsed time
Amount of elapsed time spent running the JavaVM.This does not include time spent recursively executing/parsing SQL statements or time spent recursively
executing PL/SQL.
RMAN cpu time
(backup/restore)
Amount of CPU time (in microseconds) spent in RMAN backup and restore operations.
repeated bind elapsed time Amount of elapsed time spent giving new values to bind variables (rebinding).
SQL> SELECT stat_name,value
2 FROM v$sess_time_model
3 WHERE sid=(select sid from v$mystat where rownum=1);
STAT_NAME VALUE
---------------------------------------------------------------- ----------
DB time 154998424
DB CPU 152061882
background elapsed time 0
background cpu time 0
sequence load elapsed time 2553
parse time elapsed 959772
hard parse elapsed time 857517
sql execute elapsed time 27534022
connection management call elapsed time 104349
failed parse elapsed time 74290
failed parse (out of shared memory) elapsed time 0
hard parse (sharing criteria) elapsed time 201941
hard parse (bind mismatch) elapsed time 0
PL/SQL execution elapsed time 147938
inbound PL/SQL rpc elapsed time 0
PL/SQL compilation elapsed time 82522
Java execution elapsed time 0
repeated bind elapsed time 13525
RMAN cpu time (backup/restore) 0
Time Model(session level)
background elapsed time 0
background cpu time 0
RMAN cpu time (backup/restore) 0
DB time 154998424
DB CPU 152061882
connection management call elapsed time 104349
sequence load elapsed time 2553
sql execute elapsed time 27534022
parse time elapsed 959772
hard parse elapsed time 857517
hard parse (sharing criteria) elapsed time 201941
hard parse (bind mismatch) elapsed time 0
failed parse elapsed time 74290
failed parse (out of shared memory) elapsed time 0
PL/SQL execution elapsed time 147938
inbound PL/SQL rpc elapsed time 0
PL/SQL compilation elapsed time 82522
Java execution elapsed time 0
repeated bind elapsed time 13525
問題在哪裡?
High CPU Load SQLs
SQL> SELECT *
2 FROM
3 (SELECT sql_id,elapsed_time,cpu_time,buffer_gets,disk_reads,executions
4 FROM v$sql
5 ORDER BY cpu_time DESC)
7 WHERE ROWNUM<=10;
SQL_ID ELAPSED_TIME CPU_TIME BUFFER_GETS DISK_READS EXECUTIONS
------------- ------------ ---------- ----------- ---------- ----------
6qyqqyg14bm17 4722430672 4566883727 1171553448 1169941510 1
cj8ytxm5hhm4y 82778799 83355256 105 1 10100000
0a59tkkpx31vx 57267687 52511021 6414812 895 7
3ktacv9r56b51 18381236 1381807 109780 1048 6350
cvn54b7yz0s8u 25761776 942843 47660 6616 4142
8swypbbr0m372 7280083 802874 100473 764 6350
ga9j9xk5cy9s0 14530703 493937 24296 752 4142
39m4sx9k63ba2 15383617 449923 22739 1635 4142
c6awqs517jpj0 9019830 340949 13858 512 4142
01uy9sb7w8a9g 37054402 41994 714 83 1
10 rows selected.
background elapsed time 0
background cpu time 0
RMAN cpu time (backup/restore) 0
DB time 216686700
DB CPU 117250174
connection management call elapsed time 40823
sequence load elapsed time 2553
sql execute elapsed time 216630397
parse time elapsed 183779537
hard parse elapsed time 111831471
hard parse (sharing criteria) elapsed time 24630
hard parse (bind mismatch) elapsed time 0
failed parse elapsed time 1704
failed parse (out of shared memory) elapsed time 0
PL/SQL execution elapsed time 13803553
inbound PL/SQL rpc elapsed time 0
PL/SQL compilation elapsed time 4368
Java execution elapsed time 0
repeated bind elapsed time 136
問題在哪裡?
plan_hash_value相同,但是hash_value不相同,不過sql statement除literal外,其餘部分相同
plan_hash_value為hash(execution plan)
hash_value為hash(sql statement)
SQL> SELECT *
2 FROM (SELECT plan_hash_value,count(*)
3 FROM v$sql
4 GROUP BY plan_hash_value
5 ORDER BY count(*) DESC)
6 WHERE ROWNUM<=10;
PLAN_HASH_VALUE COUNT(*)
--------------- ----------
0 286
1327943602 48
1388734953 48
2890534904 30
2363543667 26
417717735 26
2848324471 23
2383372605 20
735420252 19
2365942777 16
10 rows selected.
SQL> SELECT hash_value,sql_id,sql_text
2 FROM v$sql
3 WHERE plan_hash_value='1327943602';
HASH_VALUE SQL_ID
---------- -------------
SQL_TEXT
-------------------------------------------------------------------------------
3262910503 3w43dxr17s417
select object_name,object_type from hr.big1 where object_id=54911
4194570773 9npmsp7x084hp
select object_name,object_type from hr.big1 where object_id=40964
2274762271 ctv0gn23tc7hz
select object_name,object_type from hr.big1 where object_id=92651
4159188012 36frnbbvyhb1c
select object_name,object_type from hr.big1 where object_id=83436
1689400341 0uzss2tkb4d0p
select object_name,object_type from hr.big1 where object_id=56791
SQL> SHOW PARAMETER cursor_sharing
NAME TYPE VALUE
------------------------- ------ ------
cursor_sharing string EXACT
SQL> select last_name from hr.employees where employee_id=100;
LAST_NAME
-------------------------
King
SQL> select last_name from hr.employees where employee_id=200;
LAST_NAME
-------------------------
Whalen
SQL> SELECT hash_value,plan_hash_value,executions,sql_text
2 FROM v$sql
3 WHERE sql_text like 'select last_name from hr.employees where employee_id=%';
HASH_VALUE PLAN_HASH_VALUE EXECUTIONS
---------- --------------- ----------
SQL_TEXT
--------------------------------------------------------------------------------
2627784799 1833546154 1
select last_name from hr.employees where employee_id=200
280342537 1833546154 1
select last_name from hr.employees where employee_id=100
解決Hard Parse-DBA篇
SQL> ALETER SESSION SET cursor_sharing=FORCE;
SQL> SHOW PARAMETER cursor_sharing
NAME TYPE VALUE
------------------------- ------ ------
cursor_sharing string FORCE
SQL> select last_name from hr.employees where employee_id=101;
LAST_NAME
-------------------------
Kochhar
SQL> select last_name from hr.employees where employee_id=201;
LAST_NAME
-------------------------
Hartstein
SQL> SELECT hash_value,plan_hash_value,executions,sql_text
2 FROM v$sql
3 WHERE sql_text like 'select last_name from hr.employees where employee_id=%';
HASH_VALUE PLAN_HASH_VALUE EXECUTIONS
---------- --------------- ----------
SQL_TEXT
--------------------------------------------------------------------------------
1893902718 1833546154 2
select last_name from hr.employees where employee_id=:"SYS_B_0"
2627784799 1833546154 1
select last_name from hr.employees where employee_id=200
280342537 1833546154 1
select last_name from hr.employees where employee_id=100
SQL> SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD:HH24:MI:SS'),COUNT(*)
2 FROM v$session
3 WHERE type != 'BACKGROUND' AND status='ACTIVE';
TO_CHAR(SYSDATE,'YY COUNT(*)
------------------- ----------
2013-01-08:16:29:50 6
SQL> SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD:HH24:MI:SS'),value
2 FROM v$sysstat
3 WHERE name='execute count';
TO_CHAR(SYSDATE,'YY VALUE
------------------- ----------
2013-01-08:16:32:27 21590278
SQL執⾏行數與ACTIVE SESSION數
ACTIVE SESSION數量
少 多
SQL指令
少
可能許多的SQL指
令還沒開始執⾏行
可能堵塞(hang或變慢)
多
 ⺫⽬目前Oracle Sever
還可以應付
可能只是有⼤大量⼯工作
需要被處理
SESSION Status and Event
• V$SESSION.STATUS
• INACTIVE
• ACTIVE
• V$SESSION.EVENT
• SELECT name FROM v$event_name
User
Process
Server
Process
Disk
CPU I/O
or
Other Waits
Idle
Wait
SQL
Result
SQL
ACTIVE
INACTIVE
User
Process
Server
Process
Disk
SQL
Result
User
Process
Server
Process
SQL
Result
SQL
SQL> select sid,serial#,event,seconds_in_wait,wait_time,status
2 from v$session
3 where username='SH';
SID SERIAL# EVENT SECONDS_IN_WAIT WAIT_TIME STATUS
---------- ---------- ------------------------------ --------------- ---------- --------
78 89 SQL*Net message from client 3446 0 INACTIVE
SQL> select sid,serial#,event,seconds_in_wait,wait_time,status
2 from v$session
3 where username='SH';
SID SERIAL# EVENT SECONDS_IN_WAIT WAIT_TIME STATUS
---------- ---------- ------------------------------ --------------- ---------- --------
(S1) 78 89 direct path read 951 -1 ACTIVE
Session1> select count(*) from sh.t1 connect by level<=10000;
SQL> select sid,serial#,event,seconds_in_wait,wait_time,status
2 from v$session
3 where username='SH';
SID SERIAL# EVENT SECONDS_IN_WAIT WAIT_TIME STATUS
---------- ---------- ------------------------------ --------------- ---------- --------
(S2) 73 749 SQL*Net message from client 453 0 INACTIVE
(S1) 78 89 direct path read 951 -1 ACTIVE
(S3) 136 661 enq: TX - row lock contention 393 0 ACTIVE
Session1> select count(*) from sh.t1 connect by level<=10000;
Session2> update sh.t2 set b=‘C99’ where a=99;
Session3> update sh.t2 set b=‘D99’ where a=99;
[oracle@oraDB ~]$ top
top - 12:30:14 up 1:24, 5 users, load average: 1.41, 1.45, 1.28
Tasks: 225 total, 2 running, 223 sleeping, 0 stopped, 0 zombie
Cpu(s): 20.8%us, 3.9%sy, 0.0%ni, 75.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2054636k total, 1951288k used, 103348k free, 24816k buffers
Swap: 4095996k total, 4156k used, 4091840k free, 939340k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
6275 oracle 20 0 743m 93m 86m R 99.7 4.7 13:47.18 oracle
3396 oracle -2 0 733m 15m 13m S 4.3 0.8 7:08.00 oracle
5752 oracle 20 0 672m 148m 27m S 4.3 7.4 6:20.90 firefox
2745 root 20 0 76600 996 712 S 0.3 0.0 0:02.92 VBoxService
3025 root 20 0 121m 35m 6512 S 0.3 1.8 0:15.81 Xorg
3392 oracle 20 0 733m 16m 14m S 0.3 0.8 0:04.58 oracle
3402 oracle 20 0 733m 15m 14m S 0.3 0.8 0:00.44 oracle
4026 oracle 20 0 1247m 268m 21m S 0.3 13.4 1:14.59 java
4455 oracle 20 0 738m 106m 100m S 0.3 5.3 0:11.34 oracle
5001 oracle 20 0 89788 1300 848 S 0.3 0.1 0:25.17 VBoxClient
11712 root 20 0 0 0 0 S 0.3 0.0 0:00.01 kworker/1:2
1 root 20 0 10412 704 588 S 0.0 0.0 0:01.14 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:08.37 ksoftirqd/0
5 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/u:0
6 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
7 root RT 0 0 0 0 S 0.0 0.0 0:00.42 watchdog/0
8 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/1
[oracle@oraDB ~]$ sar 5 10
Linux 2.6.39-400.24.1.el5uek (oraDB) 06/27/2013
12:29:05 PM CPU %user %nice %system %iowait %steal %idle
12:29:10 PM all 21.95 0.00 4.34 0.00 0.00 73.72
12:29:15 PM all 19.64 0.00 4.67 0.00 0.00 75.69
12:29:20 PM all 21.17 0.00 4.91 0.00 0.00 73.92
12:29:25 PM all 20.46 0.00 4.24 0.00 0.00 75.30
12:29:30 PM all 20.15 0.00 4.29 0.00 0.00 75.56
12:29:35 PM all 20.51 0.00 4.21 0.00 0.00 75.28
12:29:40 PM all 19.97 0.00 4.39 1.55 0.00 74.09
12:29:45 PM all 24.01 0.00 8.57 0.00 0.00 67.42
12:29:50 PM all 21.58 0.00 5.91 0.00 0.00 72.51
12:29:55 PM all 20.33 0.00 4.95 0.05 0.00 74.66
Average: all 20.98 0.00 5.05 0.16 0.00 73.80
Session1> select count(*) from sh.t1 connect by level<=10000;
Session2> update sh.t2 set b=‘C99’ where a=99;
Session3> update sh.t2 set b=‘D99’ where a=99;
Session4> select /*+ use_nl(s c) ordered full(s) full(c) */ count(*)
2 from sh.sales s,sh.customers c
3 where s.cust_id=c.cust_id and c.cust_first_name='Dina';
SQL> select sid,serial#,event,seconds_in_wait,wait_time,status
2 from v$session
3 where username='SH';
SID SERIAL# EVENT SECONDS_IN_WAIT WAIT_TIME STATUS
---------- ---------- ------------------------------ --------------- ---------- --------
16 731 direct path read 0 0 ACTIVE
73 749 SQL*Net message from client 453 0 INACTIVE
78 89 direct path read 951 -1 ACTIVE
136 661 enq: TX - row lock contention 393 0 ACTIVE
[oracle@oraDB ~]$ top
top - 12:48:31 up 1:43, 6 users, load average: 2.66, 2.46, 1.95
Tasks: 231 total, 3 running, 228 sleeping, 0 stopped, 0 zombie
Cpu(s): 31.2%us, 21.9%sy, 0.0%ni, 46.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2054636k total, 1962120k used, 92516k free, 25456k buffers
Swap: 4095996k total, 6568k used, 4089428k free, 930208k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
6275 oracle 20 0 743m 93m 86m R 100.0 4.7 32:07.81 oracle
12781 oracle 20 0 755m 59m 49m R 99.7 3.0 8:14.40 oracle
5752 oracle 20 0 672m 152m 27m S 6.0 7.6 7:18.32 firefox
3396 oracle -2 0 733m 15m 13m S 4.7 0.8 7:58.76 oracle
3024 root 20 0 183m 4104 3376 S 0.3 0.2 0:04.09 gdm-rh-security
3025 root 20 0 121m 35m 6512 S 0.3 1.8 0:17.22 Xorg
3392 oracle 20 0 733m 16m 14m S 0.3 0.8 0:05.16 oracle
4004 oracle 20 0 90820 13m 1924 S 0.3 0.7 0:01.13 perl
4026 oracle 20 0 1247m 256m 21m S 0.3 12.8 1:21.03 java
13352 oracle 20 0 12908 1212 836 R 0.3 0.1 0:00.14 top
1 root 20 0 10412 704 588 S 0.0 0.0 0:01.17 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:08.47 ksoftirqd/0
5 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/u:0
6 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
7 root RT 0 0 0 0 S 0.0 0.0 0:00.45 watchdog/0
8 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/1
10 root 20 0 0 0 0 S 0.0 0.0 0:02.58 ksoftirqd/1
[oracle@oraDB ~]$ sar 5 10
Linux 2.6.39-400.24.1.el5uek (oraDB) 06/27/2013
12:48:01 PM CPU %user %nice %system %iowait %steal %idle
12:48:06 PM all 30.62 0.00 24.25 0.30 0.00 44.82
12:48:11 PM all 29.74 0.00 24.01 0.15 0.00 46.10
12:48:16 PM all 28.79 0.00 23.45 0.10 0.00 47.66
12:48:21 PM all 28.76 0.00 23.83 0.00 0.00 47.41
12:48:26 PM all 30.86 0.05 23.05 0.00 0.00 46.04
12:48:31 PM all 35.78 0.00 23.56 0.00 0.00 40.66
12:48:36 PM all 31.34 0.00 21.98 0.05 0.00 46.63
12:48:41 PM all 31.99 0.00 22.47 0.10 0.00 45.44
12:48:46 PM all 31.13 0.00 22.26 0.15 0.00 46.46
12:48:51 PM all 29.36 0.00 22.81 0.20 0.00 47.63
Average: all 30.83 0.01 23.17 0.11 0.00 45.89
SQL> select sid,serial#,event,seconds_in_wait,wait_time,status
2 from v$session
3 where username='SH';
SID SERIAL# EVENT SECONDS_IN_WAIT WAIT_TIME STATUS
---------- ---------- ------------------------------ --------------- ---------- --------
16 731 direct path read 0 0 ACTIVE
17 415 direct path read 283 -1 ACTIVE
73 749 SQL*Net message from client 1817 0 INACTIVE
76 387 db file sequential read 250 -1 ACTIVE
78 89 direct path read 2315 -1 ACTIVE
136 661 enq: TX - row lock contention 1757 0 ACTIVE
top - 12:57:48 up 1:52, 6 users, load average: 4.83, 4.02, 2.91
Tasks: 231 total, 7 running, 224 sleeping, 0 stopped, 0 zombie
Cpu(s): 67.6%us, 32.4%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2054636k total, 1964360k used, 90276k free, 26088k buffers
Swap: 4095996k total, 7572k used, 4088424k free, 918084k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
13591 oracle 20 0 738m 60m 53m R 91.0 3.0 6:37.95 oracle
14005 oracle 20 0 738m 40m 33m R 83.7 2.0 0:31.95 oracle
12781 oracle 20 0 755m 62m 49m R 76.7 3.1 16:59.61 oracle
13622 oracle 20 0 735m 47m 43m R 69.7 2.4 6:07.11 oracle
6275 oracle 20 0 743m 93m 86m R 60.1 4.7 40:51.74 oracle
4080 oracle 20 0 750m 171m 157m S 6.3 8.5 1:16.69 oracle
5752 oracle 20 0 672m 150m 27m R 6.0 7.5 7:51.57 firefox
3396 oracle -2 0 733m 15m 13m S 4.3 0.8 8:23.12 oracle
4026 oracle 20 0 1247m 254m 21m S 0.7 12.7 1:24.61 java
4047 oracle 20 0 290m 38m 15m S 0.7 1.9 0:08.45 emagent
5257 oracle 20 0 278m 11m 7776 S 0.7 0.6 0:13.24 mixer_applet2
3025 root 20 0 121m 35m 6512 S 0.3 1.8 0:17.94 Xorg
3392 oracle 20 0 733m 16m 14m S 0.3 0.8 0:05.42 oracle
3414 oracle 20 0 734m 19m 17m S 0.3 1.0 0:02.86 oracle
3442 oracle 20 0 738m 101m 96m S 0.3 5.0 0:06.65 oracle
5001 oracle 20 0 89788 1300 848 S 0.3 0.1 0:28.68 VBoxClient
9056 root 20 0 0 0 0 S 0.3 0.0 0:00.82 kworker/1:0
14037 oracle 20 0 12804 1128 756 R 0.3 0.1 0:00.09 top
[oracle@oraDB ~]$ sar 5 10
Linux 2.6.39-400.24.1.el5uek (oraDB) 06/27/2013
12:57:16 PM CPU %user %nice %system %iowait %steal %idle
12:57:21 PM all 62.70 0.00 37.30 0.00 0.00 0.00
12:57:26 PM all 69.47 0.00 30.53 0.00 0.00 0.00
12:57:31 PM all 64.38 0.00 35.62 0.00 0.00 0.00
12:57:36 PM all 65.33 0.00 34.67 0.00 0.00 0.00
12:57:41 PM all 64.08 0.00 35.92 0.00 0.00 0.00
12:57:46 PM all 63.50 0.00 36.50 0.00 0.00 0.00
12:57:51 PM all 66.65 0.05 33.30 0.00 0.00 0.00
12:57:56 PM all 72.28 0.00 27.72 0.00 0.00 0.00
12:58:01 PM all 69.79 0.00 30.21 0.00 0.00 0.00
12:58:06 PM all 66.62 0.00 33.38 0.00 0.00 0.00
Average: all 66.48 0.01 33.52 0.00 0.00 0.00
Oracle Database Performance Tuning Concept
SQL> select s.sid,s.serial#,s.event,s.status,
2 (select value from v$sesstat st where st.sid=s.sid and st.statistic#=17) cpu_used_sess
3 from v$session s
4 where s.username='SH';
SID SERIAL# EVENT STATUS CPU_USED_SESS
---------- ---------- ------------------------------ -------- -------------
16 731 direct path read ACTIVE 33
17 415 direct path read ACTIVE 77
73 749 SQL*Net message from client INACTIVE 35
76 387 db file sequential read ACTIVE 17
78 89 direct path read ACTIVE 3075
136 661 enq: TX - row lock contention ACTIVE 13
204 4527 direct path read ACTIVE 6
SQL> select s.sid,s.serial#,s.event,sio.consistent_gets,sio.physical_reads
2 from v$session s,v$sess_io sio
3 where s.sid=sio.sid and s.username='SH';
SID SERIAL# EVENT CONSISTENT_GETS PHYSICAL_READS
---------- ---------- ------------------------------ --------------- --------------
16 731 direct path read 432669473 432071262
17 415 direct path read 3630 2144
73 749 SQL*Net message from client 3673 19
76 387 db file sequential read 1427 4
78 89 direct path read 16159 4606
136 661 enq: TX - row lock contention 1131 0
204 4527 direct path read 1417 1072
Profile Session State
select
case when session_state='ON CPU' THEN 'ON CPU'
when session_state='WAITING' and wait_class='User I/O' then 'I/O'
else 'WAITING'
end session_state,
event,sql_id
from v$active_session_history
where session_id=&session_id and session_serial#=&serial_number
order by sample_time;
SESSION EVENT SQL_ID
------- --------------------------------------- ------------------------
I/O direct path read 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
I/O direct path read 47u05qwhnv8q0
I/O direct path read 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
I/O direct path read 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
I/O direct path read 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
I/O direct path read 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
I/O direct path read 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
I/O direct path read 47u05qwhnv8q0
I/O direct path read 47u05qwhnv8q0
I/O direct path read 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
I/O direct path read 47u05qwhnv8q0
ON CPU 47u05qwhnv8q0
SQL> select * from table(dbms_xplan.display_cursor('47u05qwhnv8q0'));
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID 47u05qwhnv8q0, child number 0
-------------------------------------
select /*+ use_nl(s c) ordered full(s) full(c) */ count(*) from
sh.sales s,sh.customers c where s.cust_id=c.cust_id and
c.cust_first_name='Dina'
Plan hash value: 2043253752
---------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop|
---------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 370M(100)| | | |
| 1 | SORT AGGREGATE | | 1 | 17 | | | | |
| 2 | NESTED LOOPS | | 5557 | 94469 | 370M (1)| 999:59:59 | | |
| 3 | PARTITION RANGE ALL| | 918K| 4486K| 526 (2)| 00:00:07 | 1 | 28 |
| 4 | TABLE ACCESS FULL | SALES | 918K| 4486K| 526 (2)| 00:00:07 | 1 | 28 |
|* 5 | TABLE ACCESS FULL | CUSTOMERS | 1 | 12 | 404 (1)| 00:00:05 | | |
---------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
5 - filter(("C"."CUST_FIRST_NAME"='Dina' AND "S"."CUST_ID"="C"."CUST_ID"))
Memory⾃自動管理
• Automatic Memory Management
• MEMORY_TARGET
• SGA_TARGET
• PGA_AGGREGATE_TARGET
SMO
N
PGA
Shared Pool
Statistics
Buffer Cache
Large
Pool
Java Pool
Stream
s Pool
Fixed
SGA
Log
Buffer
Server
process
PGA
PMO
N
PGA
DBW
R
PGA
LGW
R
PGA
CKPT
PGA
ARCH
PGA
MMO
N
PGA
MMA
N
PGA
Server
process
PGA
Server
process
PGA
Server
process
PGA
Server
process
PGA
MEMORY_TARGET
SGA_TARGETPGA_AGGREGATE_TARGET
Memory
Advisors
取得
呼叫
建議
調整
Server
Parameter file
記錄
SGA
變動
⾃自動管理
STREAMS_POOL_SIZE
JAVA_POOL_SIZE
LARGE_POOL_SIZE
SHARED_POOL_SIZE
DB_CACHE_SIZE
⼈人為管理
DB_KEEP_CACHE_SIZE
DB_RECYCLE_CACHE_SIZE
DB_2K_CACHE_SIZE
DB_4K_CACHE_SIZE
DB_8K_CACHE_SIZE
DB_16K_CACHE_SIZE
DB_32K_CACHE_SIZE
固定
LOG_BUFFER
FIXED SGA
PGA ⾃自動管理 PGA_AGGREGATE_TARGET
MEMORY_TARGET
SGA_TARGET
On a healthy system, physical read waits should be the biggest waits
after the idle waits.
However, also consider whether there are direct read waits
(signifying full table scans with parallel query) or db file scattered
read waits on an operational (OLTP) system that should be doing
small indexed accesses.
Other things that could indicate excessive I/O load on the system
include the following:
• Poor buffer cache hit ratio
• These wait events accruing most of the wait time for a user
experiencing poor response time
However, also consider whether there are db file sequential reads
on a large data warehouse that should be seeing mostly full table
scans with parallel query.
Oracle® Database Performance Tuning Guide
11g Release 2 (11.2) - 10 Instance Tuning Using Performance Views
OLTP應該多數為Index Scan
DW應該多數為Full Table Scan
I/O調校重點
• 降低I/O related wait time
• I/O分散
• 減少I/O量
• 減少Physical I/O
• 增加Buffer Cache Hit Ratio
• 1-((Physical I/O)/(Physical I/O+Logical I/O))
Latency Comparison Numbers
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 1 MB sequentially from memory 250,000 ns 0.25 ms
Round trip within same datacenter 500,000 ns 0.5 ms
Read 1 MB sequentially from SSD 1,000,000 ns 1 ms 4X memory
Disk seek 10,000,000 ns 10 ms 20x datacenter roundtrip
Read 1 MB sequentially from disk 20,000,000 ns 20 ms 80x memory, 20X SSD
Send packet CA->Netherlands->CA 150,000,000 ns 150 ms
Oracle Database Performance Tuning Concept
重要的I/O Waits
• db file scattered read
• This event signifies that the user process is reading buffers into the SGA buffer cache and is waiting
for a physical I/O call to return.A db file scattered read issues a scattered read to read the data into
multiple discontinuous memory locations.A scattered read is usually a multiblock read. It can occur
for a fast full scan (of an index) in addition to a full table scan.
• direct path read
• When a session is reading buffers from disk directly into the PGA (opposed to the buffer cache
in SGA), it waits on this event. If the I/O subsystem does not support asynchronous I/Os, then
each wait corresponds to a physical read request. If the I/O subsystem supports asynchronous I/
O, then the process is able to overlap issuing read requests with processing the blocks already
existing in the PGA.When the process attempts to access a block in the PGA that has not yet
been read from disk, it then issues a wait call and updates the statistics for this event. Hence, the
number of waits is not necessarily the same as the number of read requests (unlike db file
scattered read and db file sequential read).
• db file sequential read
• This event signifies that the user process is reading a buffer into the SGA buffer cache and is waiting
for a physical I/O call to return.A sequential read is a single-block read.
Oracle® Database Performance Tuning Guide
11g Release 2 (11.2) - 10 Instance Tuning Using Performance Views
SQL> SELECT * FROM (
2 SELECT event,total_waits,time_waited,average_wait
3 FROM v$system_event
4 WHERE wait_class != 'Idle'
5 ORDER BY time_waited DESC,total_waits DESC)
6 WHERE rownum<=10;
EVENT TOTAL_WAITS TIME_WAITED AVERAGE_WAIT
------------------------------------------ ----------- ----------- -------------
db file sequential read 7654 75033 9.8
direct path read 46079 48133 1.04
db file scattered read 561 7013 12.5
library cache load lock 42 5821 138.6
cursor: pin S wait on X 24 1034 43.06
db file parallel read 43 826 19.21
Disk file operations I/O 194 636 3.28
control file sequential read 1614 560 .35
ADR block file read 410 463 1.13
control file heartbeat 1 400 400.08
10 rows selected.
百分之⼀一秒
V$SYSTEM_EVENT
Server
Process
Datafile
Buffer Cache
High Water Mark
PGA
Full Table Scan
db file scattered read
v$session_longops
解決db file scattered read
• Index Scan
• Table Compression
• Table Reorganization
• Partitioned table
• db_file_multiblock_read_count
• Multiple Buffer Cache
DB_FILE_MULTIBLOCK_READ
• Full Table Scan
• Index Fast Full Scan
• 10gR2之後,建議由Oracle Server⾃自動選
擇(預設值=OS_MaxIO_Size/Block_Size)
SQL> show parameter db_file_multiblock_read_count
NAME TYPE  VALUE
------------------------------------ ----------- -------
db_file_multiblock_read_count  integer  16
SQL> alter system reset db_file_multiblock_read_count scope=spfile sid='*';
SQL> shutdown immediate;
SQL> startup;
Finding Full Scan SQLs
SQL> select sql_text
2 from v$sqltext t, v$sql_plan p
3 where t.hash_value=p.hash_value and p.operation='TABLE ACCESS'
4 and p.options='FULL'
5 order by p.hash_value, t.piece;
SQL> select sql_text
2 from v$sqltext t, v$sql_plan p
3 where t.hash_value=p.hash_value and p.operation='INDEX'
4 and p.options='FAST FULL SCAN'
5 order by p.hash_value, t.piece;
Server
Process
Datafile
Buffer Cache
High Water Mark
PGA
db file sequential read
Index Scan
SQL> SELECT sid, total_waits, time_waited
2 FROM v$session_event
3 WHERE event='db file sequential read' and total_waits>0
4 ORDER BY 3,2;
解決db file sequential read
• Partitioned Index - Local/Global index
• Index Reorganization
Server
Process
Datafile
Buffer Cache
High Water Mark
PGA
Full Table Scan
direct path read
_small_table_threshold
= (db_cache_size*2%)/data_block_size
blocks>5*_small_table_threshold
Logfile Related Waits
• Log File Sync
•When a user session commits, the session's redo information needs to
be flushed to the redo logfile. The user session will post the LGWR
to write the log buffer to the redo log file. When the LGWR has
finished writing, it will post the user session.
• Log File Parallel Write
•Writing redo records to the redo log files from the log buffer.
Oracle® Database Reference
11g Release 2 (11.2)
E25513-04
User LogBuffer LGWR
T1
T2
T4
T6
T7
Time
Commit
COMMITTED
Logfile
Members
Server
Process
Time
Generate
Commit
Redo Entry
Begin Physical I/Os
Physical I/Os Completed
T5
T8
T3
T9
Server Process Post LGWR
LGWR post Server Process
Copy Commit
Redo Entry to
LogBuffer
Log file Parallel Write
Log File Sync
Sync Commit
Shared
Pool
Buffer Cache
Log
Buffer
Datafile
DBW
R
LGW
R
Server
Process
PMO
N
SMO
N
CKPT RECO
1 A A1
10 J J1
0
17 Q Q
17
2 B B2
18 R R1
8
19 S S1
9
3 C C3
7 G G7
11 K K1
1
4 D D4
12 L L1
2
21 U U
21
6 F F6
13 M M
13
22 V V2
2
8 H H
8
15 O O
15
24 X X
24
5 E E5
14 N N
14
23 W W
23
9 I I9
16 P P1
6
20 T T2
0
A B C
1 A A1
2 B B2
3 C C3
4 D D4
5 E F5
6 F E6
7 G G7
8 H H8
9 I I9
10 J J10
11 K K11
12 L L12
13 M M13
14 N N14
15 O O15
16 P P16
17 Q Q17
18 R R18
19 S S91
20 T T20
21 U U21
22 V V22
23 W W23
24 X X24
User
Process
COMMIT; 1.Parse
Execution Plan
2.Execute
2 B B2
18 R R1
8
19 S S9
1
S1
undo block
undo S1
9
data S9
1
commit
commit
Logfile
group
1
Control
file
Logfile
group
2
undo S1
9
data S9
1
commit
2.5 COMMITTED
2.4 Release Lock
2.1
Generated
Redo Entries
2.2
Copy Redo Entries to Log Buffer
2.3
Write Redo Entries to Log File
Async Commit
batch:當server process執⾏行commit時,並不會觸發lgwr將log buffer的redo entry寫到logfile
lgwr除了commit將觸發寫⼊入操作外,還有redo entry佔log buffer的1/3以上空間或1M,以及每3秒鐘將⾃自動觸發⼀一次.
最後還有dbwr想要將某個dirty buffer內容寫到datafile前,如果redo entry還在log buffer裡尚未被寫到logfile,
也會觸發lgwr將redo entry寫到logfile.
nowait:當server process執⾏行commit時,不需要等到lgwr完成I/O,便可以得到committed的訊息,⽽而且可以開始進⾏行新
的指令
注意,使⽤用nowait可能造成在instance/media recovery後,committed data遺失.
因為lgwr的確尚未將log buffer裡的redo entry寫到logfile
SQL> show parameter commit_write
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
commit_write string --空值為預設值,表⽰示為immediate,wait
immediate wait
batch nowait
SQL> alter system set commit_write=batch,nowait;
**最安全(default)=>immediate,wait
**最快回應=>batch,nowait
**⽐比最安全快,⼜又⽐比最快安全=>immediate,nowait
**最不應該使⽤用=>batch,wait
Batch,NoWait
Shared
Pool
Buffer Cache
Log
Buffer
Datafile
DBW
R
LGW
R
Server
Process
PMO
N
SMO
N
CKPT RECO
1 A A1
10 J J1
0
17 Q Q
17
2 B B2
18 R R1
8
19 S S1
9
3 C C3
7 G G7
11 K K1
1
4 D D4
12 L L1
2
21 U U
21
6 F F6
13 M M
13
22 V V2
2
8 H H
8
15 O O
15
24 X X
24
5 E E5
14 N N
14
23 W W
23
9 I I9
16 P P1
6
20 T T2
0
A B C
1 A A1
2 B B2
3 C C3
4 D D4
5 E F5
6 F E6
7 G G7
8 H H8
9 I I9
10 J J10
11 K K11
12 L L12
13 M M13
14 N N14
15 O O15
16 P P16
17 Q Q17
18 R R18
19 S S91
20 T T20
21 U U21
22 V V22
23 W W23
24 X X24
User
Process
COMMIT; 1.Parse
Execution Plan
2.Execute
2 B B2
18 R R1
8
19 S S9
1
S1
undo block
undo S1
9
data S9
1
commit
commit
Logfile
group
1
Control
file
Logfile
group
2
undo S1
9
data S9
1
commit
2.4 COMMITTED
2.3 Release Lock
2.1
Generated
Redo Entries
2.2
Copy Redo Entries to Log Buffer
Immediate,NoWait
Shared
Pool
Buffer Cache
Log
Buffer
Datafile
DBW
R
LGW
R
Server
Process
PMO
N
SMO
N
CKPT RECO
1 A A1
10 J J1
0
17 Q Q
17
2 B B2
18 R R1
8
19 S S1
9
3 C C3
7 G G7
11 K K1
1
4 D D4
12 L L1
2
21 U U
21
6 F F6
13 M M
13
22 V V2
2
8 H H
8
15 O O
15
24 X X
24
5 E E5
14 N N
14
23 W W
23
9 I I9
16 P P1
6
20 T T2
0
A B C
1 A A1
2 B B2
3 C C3
4 D D4
5 E F5
6 F E6
7 G G7
8 H H8
9 I I9
10 J J10
11 K K11
12 L L12
13 M M13
14 N N14
15 O O15
16 P P16
17 Q Q17
18 R R18
19 S S91
20 T T20
21 U U21
22 V V22
23 W W23
24 X X24
User
Process
COMMIT; 1.Parse
Execution Plan
2.Execute
2 B B2
18 R R1
8
19 S S9
1
S1
undo block
undo S1
9
data S9
1
commit
commit
Logfile
group
1
Control
file
Logfile
group
2
undo S1
9
data S9
1
commit
2.4 COMMITTED
2.3 Release Lock
2.1
Generated
Redo Entries
2.2
Copy Redo Entries to Log Buffer
2.4
Write Redo Entries to Log File
I/O分散
• S.A.M.E(Stripe And Mirror Everything)
• Hardware RAID
• ASM
• 類似RAID 0+1,但單位不相同
• Optimal Flexible Architecture
• Datafile與Logfile
• Logfile與Archived logfile
• Datafile與Backup
Oracle Database Performance Tuning Concept
Oracle Database Performance Tuning Concept
Oracle Database Performance Tuning Concept
Oracle Database Performance Tuning Concept
Oracle Database Performance Tuning Concept
RAID TYPE
Control
File
Datafile
Redo
Logfile
Archived
Logfile
0 Stripe Avoid Ok Avoid Avoid
1 Mirror Ok Ok Recommended Recommended
0+1
(ASM)
Mirror/
Stripe
Ok Recommended Ok Avoid
1+0
Stripe/
Mirror
Ok Recommended Ok Avoid
5
Stripe/
Parity
Check
Ok
Avoid
(Write
Intensive)
Avoid Avoid
OLTP or DW
SQL> SELECT (SELECT tablespace_name FROM dba_data_files WHERE file_id=file#) tablespace_name,
2 phyrds,phyblkrd,ROUND(phyblkrd/phyrds) “BLKS/RDS”,
3 singleblkrds,readtim,singleblkrdtim,avgiotim
4 FROM v$filestat;
TABLESPACE_NAME PHYRDS PHYBLKRD BLKS/RDS SINGLEBLKRDS READTIM SINGLEBLKRDTIM AVGIOTIM
--------------- --------- ---------- -------- ------------ --------- --------------- ---------
SYSTEM 172364 274588 2 164676 34067 31959 0
SYSAUX 110096 193796 2 97437 15088 10918 0
UNDOTBS1 576 576 1 576 53 53 0
USERS 18525608 1343241851 73 35730 860 784 0
EXAMPLE 52382010 4008236424 77 4563 454 344 0
(PHYBLKRD/PHYRDS)=⼀一次Physical I/O平均讀取幾個blocks
百分之⼀一秒
OLTP:⼀一次讀取⼀一個Block
DW:⼀一次讀取多個Blocks
SMON PMON CKPTDBWR LGWR ARCHRECO
Shared
Pool
Buffer Cache
Log
Buffer
Large
Pool
Java
Pool
Streams
pool
Control
file
Data File Data File Data File
Online
Logfile
Online
Logfile
Header Header Header
Group 1 Group 2
Server
Process
Archived
Logfile
System Global Area(SGA)
Instance
Database
Program
Global
Area
Block Block
Block
Redo Entry
SQL Text
Execution Plan
Redo Entry Redo Entry Redo Entry
Redo Entry
Log Seq:12 Log Seq:11 Log Seq:11Log Seq:12
Log Seq:12Log Seq:12Log Seq:12
Data Dictionary
Information
Data Dictionary Cache
Library Cache
OFA
• 建議⾄至少4個Mount Points
• /u01 - Oracle軟體安裝位置
• /u02與/u03 - Oracle Database files存放位
置。同時將controlfile與logfile member放
在/u02與/u03(Multiplexing)
• /u04 - Oracle Database backup file存放位
置
減少I/O-Index
branch branch
root
1 A A1
10 J J10
17 Q Q17
2 B B2
18 R
19 S
3 C C3
7 G G7
11 K K11
4 D D4
12 L L12
21 U U21
6 F F6
13 M M13
22 V V22
8 H H8
15 O O14
24 X X24
5 E E5
14 N N14
23 W W23
9 I I9
16 P P16
20 T T20
1 rowid
2 rowid
3 rowid
4 rowid
5 rowid
6 rowid
7 rowid
8 rowid
9 rowid
10 rowid
11 rowid
12 rowid
13 rowid
14 rowid
15 rowid
16 rowid
17 rowid
18 rowid
19 rowid
20 rowid
21 rowid
22 rowid
23 rowid
24 rowid
full table scan
index scan
減少I/O-Partitioned Table
1 A A1
10 J J10
17 Q Q17
2 B B2
18 R R18
19 S S19
3 C C3
7 G G7
11 K K11
4 D D4
12 L L12
21 U U21
6 F F6
13 M M13
22 V V22
8 H H8
15 O O15
24 X X24
5 E E5
14 N N14
23 W W23
9 I I9
16 P P16
20 T T20
1 A A1
10 J J10
5 E E5
2 B B2
12 L L12
11 K K11
24 X X24
15 O O15
19 S S19
22 V V22
18 R R18
21 U U21
6 F F6
9 I I9
4 D D4
8 H H8
7 G G7
3 C C3
17 Q Q17
14 N N14
23 W W23
13 M M13
16 P P16
20 T T20
Heap Table Partitioned Table
partition(p1) partition(p2)
CEATE TABLE t1_pt
(a NUMBER,
bVARCHAR2(10),
cVARCHAR2(10))
PARTITION BY RANGE(a)
(PARTITION p1VALUES LESS THAN 13
PARTITION p2VALUES LESS THAN 25);
CEATE TABLE t1
(a NUMBER,
bVARCHAR2(10),
cVARCHAR2(10));
SELECT b FROM t1 WHERE a=11; SELECT b FROM t1_pt WHERE a=11;
Improved Block Utilization
• Table Compression
• Defragmentation
• Shrink Segment
• Table
• Export/Drop/Import
• Index
• Rebuild
DBA_TABLES
SQL> DESC dba_tables (省略部分,僅存部份統計值相關欄位)
Name Null? Type
------------------------------------- -------- ----------------------------------------
OWNER NOT NULL VARCHAR2(30)
TABLE_NAME NOT NULL VARCHAR2(30)
TABLESPACE_NAME VARCHAR2(30)
PCT_FREE NUMBER
PCT_USED NUMBER
INI_TRANS NUMBER
MAX_TRANS NUMBER
PCT_INCREASE NUMBER
NUM_ROWS NUMBER
BLOCKS NUMBER
EMPTY_BLOCKS NUMBER
AVG_SPACE NUMBER
CHAIN_CNT NUMBER
AVG_ROW_LEN NUMBER
AVG_SPACE_FREELIST_BLOCKS NUMBER
NUM_FREELIST_BLOCKS NUMBER
SAMPLE_SIZE NUMBER
LAST_ANALYZED DATE
COMPRESSION VARCHAR2(8)
COMPRESS_FOR VARCHAR2(12)
free space佔block的最⼩小⽐比率
used space佔block的最⼩小⽐比率
Table Compression
SQL> CREATE TABLE frank.t1 AS SELECT * FROM dba_objects;
SQL> CREATE TABLE frank.t2 COMPRESS BASIC AS SELECT * FROM frank.t1;
SQL> CREATE TABLE frank.t3 COMPRESS FOR OLTP AS SELECT * FROM frank.t1;
SQL> EXECUTE DBMS_STATS.GATHER_SCHEMA_STATS(‘FRANK’);
SQL> SELECT table_name,num_rows,blocks,compress_for
2 FROM dba_tables
3 WHERE table_name IN ('T1','T2',’T3’) and owner='FRANK';
TABLE_NAME NUM_ROWS BLOCKS COMPRESS_FOR COMPRESSION
---------------------------- ---------- ---------- ------------ -----------
T1 72553 1059 DISABLED
T2 72553 309 BASIC ENABLED
T3 72553 311 OLTP ENABLED
Shrink Segment
SQL> CREATE TABLE frank.t4 AS SELECT * FROM dba_objects;
SQL> EXECUTE DBMS_STATS.GATHER_TABLE_STATS(‘FRANK’,’T4’);
SQL> SELECT table_name,num_rows,blocks
2 FROM dba_tables
3 WHERE table_name=’T4’ and owner='FRANK';
TABLE_NAME NUM_ROWS BLOCKS
------------------------------ ---------- ----------
T4 72556 1059
SQL> DELETE frank.t4 WHERE MOD(object_id,2)=0;
SQL> COMMIT;
SQL> EXECUTE DBMS_STATS.GATHER_TABLE_STATS(‘FRANK’,’T4’);
SQL> SELECT table_name,num_rows,blocks
2 FROM dba_tables
3 WHERE table_name=’T4’ and owner='FRANK';
TABLE_NAME NUM_ROWS BLOCKS
------------------------------ ---------- ----------
T4 36278 1059
Shrink Segment
SQL> ALTER TABLE frank.t4 ENABLE ROW MOVEMENT;
SQL> ALTER TABLE frank.t4 SHRINK SPACE;
SQL> EXECUTE DBMS_STATS.GATHER_TABLE_STATS(‘FRANK’,’T4’);
SQL> SELECT table_name,num_rows,blocks
2 FROM dba_tables
3 WHERE table_name=’T4’ and owner='FRANK';
TABLE_NAME NUM_ROWS BLOCKS
------------------------------ ---------- ----------
T4 36728 530
Buffer Cache Hit Ratio
• 99% hit ratio並不代表這個I/O效能很好
• 50% hit ratio也不代表這個I/O效能很差
• Full Table Scan可能造成cache hit ratio下降
• 重復地讀取某個cached block將能增加
cache hit ratio
Physical I/Os
(Physical I/Os+Logical I/Os)1
Disk
System Global Memory
background processes
Other Applications
Library
System Calls
Virtual File System
File
System
Buffer
Device Driver
Network
Interface
Device Independent Interface
Server
Process
Listener
Other
Processes
Other
Processes
Other
Processes
Other Applications
Other Applications
DiskDisk
Swap
Disk
OS
Disk
Tape
Database
datafile/controlfile/logfile
Network
Virtual
Memory
Memory Manager
RAM
(Physical Memory)
Core
Core
CPU
Core
Core
Inter-Processes
Communication
Management
Scheduler
Network
Service
Manager
Disk Disk
Physical I/O
Logical I/O
DirectI/O
RawDevice
Buffered I/O Swap I/O
N
etwork
I/O
Physical I/O Physical I/O
ASMLib
oracleasm.ko
Run Queue
Sleep Queue
Wait Queue
[oracle@oraDB ~]$ vmstat 5 10
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
6 11 307356 59512 720 273220 0 0 6812 17 19 15 2 6 81 11 0
2 16 307276 60048 708 275096 147 90 6000 3069 3389 6760 77 21 0 2 0
2 16 307036 64304 724 275628 258 2 5669 2953 3389 6925 73 21 0 6 0
5 11 307140 59980 768 279852 144 47 7272 2583 3473 6932 75 23 0 2 0
2 21 307320 59916 816 281512 213 87 9289 435 3551 6818 74 22 0 4 0
2 17 307452 61292 816 282648 251 70 9385 384 3503 6838 75 22 0 3 0
7 18 307508 60284 832 284420 158 89 9531 472 3507 6813 75 23 0 3 0
1 23 307452 81036 844 275992 138 18 9290 322 3182 5623 68 18 0 15 0
2 25 307120 69868 924 287852 345 22 9119 323 2488 3121 57 8 0 36 0
1 21 306976 63144 980 295552 184 12 9148 338 3257 5824 68 18 0 13 0
Ready
to Run
Running Zombie
Uninterruptible
Sleep
(I/O)
Interruptible
Sleep
Createdfork()
Termination
Sleep/Blocked
Running
Stopped
Context Switch
SignalSignal
FREE/MPSTAT/IOSTAT
[oracle@oraDB ~]$ free -m
total used free shared buffers cached
Mem: 2006 1160 846 0 4 443
-/+ buffers/cache: 712 1294
Swap: 3999 341 3658
[oracle@oraDB ~]$ mpstat
Linux 2.6.39-200.32.1.el5uek (oraDB) ⻄西元2013年01⽉月10⽇日
11時24分24秒 CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
11時24分24秒 all 2.31 0.05 5.49 10.99 0.01 0.11 0.00 81.05 1091.41
[oracle@oraDB ~]$ iostat
Linux 2.6.39-200.32.1.el5uek (oraDB) ⻄西元2013年01⽉月10⽇日
avg-cpu: %user %nice %system %iowait %steal %idle
2.30 0.05 5.60 10.99 0.00 81.06
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 43.58 27004.57 68.16 18196434499 45927293
sda1 0.00 0.00 0.00 3148 22
sda2 43.58 27004.57 68.16 18196430727 45927271
dm-0 68.68 27004.04 66.16 18196076663 44578095
dm-1 0.32 0.56 2.00 376144 1349208
SAR[oracle@oraDB ~]$ sar -d 30 5
Linux 2.6.39-200.32.1.el5uek (oraDB) ⻄西元2013年01⽉月10⽇日
11時29分00秒 DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util
11時29分30秒 dev8-0 205.94 112732.69 312.39 548.91 3.36 16.34 4.85 99.97
11時29分30秒 dev8-1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
11時29分30秒 dev8-2 205.94 112732.69 312.39 548.91 3.36 16.34 4.85 99.97
11時29分30秒 dev252-0 258.06 112723.87 33.79 436.94 5.07 19.63 3.87 99.97
11時29分30秒 dev252-1 36.06 9.88 278.60 8.00 0.06 1.56 0.23 0.82
[oracle@oraDB ~]$ sar -b
Linux 2.6.39-200.32.1.el5uek (oraDB) ⻄西元2013年01⽉月10⽇日
00時00分01秒 tps rtps wtps bread/s bwrtn/s
11時00分03秒 751.93 588.14 163.78 251441.46 3793.12
11時10分01秒 662.38 603.04 59.34 312713.48 695.41
11時20分01秒 652.31 641.17 11.15 342666.04 175.35
11時30分02秒 664.00 607.87 56.13 323480.54 1277.80
11時40分01秒 648.15 633.25 14.90 357565.08 192.16
Average: 660.39 641.64 18.75 51282.80 481.63
[oracle@oraDB ~]$ sar
Linux 2.6.39-200.32.1.el5uek (oraDB) ⻄西元2013年01⽉月10⽇日
00時00分01秒 CPU %user %nice %system %iowait %steal %idle
11時00分03秒 all 62.25 0.00 19.44 11.05 0.00 7.26
11時10分01秒 all 74.46 0.00 22.64 2.09 0.00 0.82
11時20分01秒 all 47.64 0.25 6.28 45.77 0.00 0.05
11時30分02秒 all 74.09 0.00 22.45 2.62 0.00 0.84
11時40分01秒 all 67.61 0.00 18.44 13.19 0.00 0.76
Average: all 6.30 0.04 6.01 44.68 0.00 42.97
[oracle@oraDB ~]$ top
top - 10:33:21 up 7 days, 18:20, 4 users, load average: 5.01, 3.63, 1.74
Tasks: 349 total, 2 running, 347 sleeping, 0 stopped, 0 zombie
Cpu(s): 33.3%us, 66.7%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2054904k total, 1951104k used, 103800k free, 42816k buffers
Swap: 4095996k total, 138628k used, 3957368k free, 437160k cached
27580 oracle 20 0 756m 45m 22m R 75.7 2.3 10:27.03 oracle
3931 oracle 20 0 283m 9128 2408 R 64.1 0.4 20:29.39 gnome-terminal
24704 oracle -2 0 733m 2828 2712 S 7.8 0.1 3:45.98 oracle
2995 root 20 0 100m 9140 3916 S 5.8 0.4 40:45.65 Xorg
25022 oracle 20 0 740m 21m 15m S 3.9 1.1 1:27.47 oracle
27028 root 20 0 0 0 0 S 1.9 0.0 0:00.38 kworker/0:0
27688 oracle 20 0 71156 5984 2272 S 1.9 0.3 0:05.12 sqlplus
27717 oracle 20 0 71156 6000 2272 S 1.9 0.3 0:05.11 sqlplus
27720 oracle 20 0 71156 5980 2272 S 1.9 0.3 0:05.03 sqlplus
27743 oracle 20 0 71156 5984 2272 S 1.9 0.3 0:05.02 sqlplus
27787 oracle 20 0 71156 6000 2272 S 1.9 0.3 0:04.91 sqlplus
27798 oracle 20 0 71156 6012 2272 S 1.9 0.3 0:04.95 sqlplus
27803 oracle 20 0 71156 6016 2272 S 1.9 0.3 0:05.01 sqlplus
27823 oracle 20 0 71156 6016 2272 S 1.9 0.3 0:04.89 sqlplus
27880 oracle 20 0 71156 6016 2272 S 1.9 0.3 0:04.91 sqlplus
27904 oracle 20 0 71156 6016 2272 S 1.9 0.3 0:04.85 sqlplus
27950 oracle 20 0 71156 6020 2272 S 1.9 0.3 0:04.34 sqlplus
27963 oracle 20 0 71156 6020 2272 S 1.9 0.3 0:04.36 sqlplus
TOP
v$osstat
SQL> select osstat_id,stat_name,value from v$osstat;
OSSTAT_ID STAT_NAME VALUE
---------- --------------------------------------- ----------
0 NUM_CPUS 2
1 IDLE_TIME 62248
2 BUSY_TIME 3010
3 USER_TIME 286
4 SYS_TIME 2676
5 IOWAIT_TIME 2958
6 NICE_TIME 0
14 RSRC_MGR_CPU_WAIT_TIME 0
15 LOAD .669921875
16 NUM_CPU_CORES 2
17 NUM_CPU_SOCKETS 1
1008 PHYSICAL_MEMORY_BYTES 2104160256
1009 VM_IN_BYTES 0
1010 VM_OUT_BYTES 0
2000 TCP_SEND_SIZE_MIN 4096
2001 TCP_SEND_SIZE_DEFAULT 16384
2002 TCP_SEND_SIZE_MAX 2067936
2003 TCP_RECEIVE_SIZE_MIN 4096
2004 TCP_RECEIVE_SIZE_DEFAULT 87380
2005 TCP_RECEIVE_SIZE_MAX 2067936
2006 GLOBAL_SEND_SIZE_MAX 1048576
2007 GLOBAL_RECEIVE_SIZE_MAX 4194304
CPU不⾜足?
• loading factor=(load average)/cpu#
• <=1表⽰示CPU不是瓶頸
• 1<loading factor<=2表⽰示CPU⾜足夠
• >2表⽰示CPU不⾜足
• 增加CPU
• 減少同時執⾏行的processes數量
How many CPUs I have?
SQL> select value
2 from v$system_parameter
3 where name='cpu_count';
VALUE
----------------------------------
2
SQL> select stat_name,value
2 from v$osstat
3 where stat_name like 'NUM_CPU%';
STAT_NAME VALUE
---------------------------------- ---------
NUM_CPUS 2
NUM_CPU_CORES 2
NUM_CPU_SOCKETS 1
Socket/Core/Thread
Socket 0
Socket 1
Core 0 Core 1 Core 2 Core 3
Core 0 Core 1 Core 2 Core 3
CPU 0 CPU 1 CPU 2 CPU 3
CPU 4 CPU 5 CPU 6 CPU 7
CPU 8 CPU 9 CPU 10 CPU 11
CPU 12 CPU 13 CPU 14 CPU 15
Sockets:2
Cores:8
HyperThreads:16
How many CPUs I have?
[oracle@oraDB ~]$ grep -i "model name" /proc/cpuinfo
model name : Intel(R) Core(TM) i7-2675QM CPU @ 2.20GHz
model name : Intel(R) Core(TM) i7-2675QM CPU @ 2.20GHz
[oracle@oraDB ~]$ grep -i "processor" /proc/cpuinfo
processor : 0
processor : 1
[oracle@oraDB ~]$ grep -i "physical id" /proc/cpuinfo
physical id : 0
physical id : 0
[oracle@oraDB ~]$ grep -i "core id" /proc/cpuinfo
core id : 0
core id : 1
[oracle@oraDB ~]$ grep -i "cpu cores" /proc/cpuinfo | uniq
cpu cores : 2
SQL> show parameter cpu_count
NAME TYPE VALUE
------------------------------------ ----------- ------------------------
cpu_count integer 4
SQL> select stat_name,value from v$osstat where stat_name like 'NUM_CPU%';
STAT_NAME VALUE
---------------------------------------------------------------- ---------
NUM_CPUS 4
NUM_CPU_CORES 4
NUM_CPU_SOCKETS 1
SQL> alter system set cpu_count=2;
SQL> show parameter cpu_count
NAME TYPE VALUE
------------------------------------ ----------- -----------------
cpu_count integer 2
SQL> select name,cpu_managed,instance_caging from v$rsrc_plan;
NAME CPU INS
-------------------------------- --- ---
INTERNAL_PLAN OFF OFF
SQL> alter system set resource_manager_plan=instance_caging_demo;
SQL> select name,cpu_managed,instance_caging from v$rsrc_plan;
NAME CPU INS
-------------------------------- --- ---
INSTANCE_CAGING_DEMO ON ON
SQL> show parameter cpu_count
NAME TYPE VALUE
------------------------------------ ----------- ------------------
cpu_count integer 2
Background Processes
[oracle@oraDB ~]$ ps aux| grep ora_ | grep _orcl
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
oracle 22569 0.0 0.8 750600 18080 ? Ss 09:56 0:00 ora_w000_orcl
oracle 23400 0.0 0.9 751112 18888 ? Ss 10:06 0:00 ora_w001_orcl
oracle 23405 0.0 0.9 751112 18648 ? Ss 10:06 0:00 ora_w002_orcl
oracle 23513 0.4 1.5 751112 31000 ? Ds 10:07 0:00 ora_m000_orcl
oracle 29276 0.0 0.9 752896 20084 ? Ss Jan08 0:24 ora_pmon_orcl
oracle 29280 0.0 0.8 750604 16464 ? Ss Jan08 1:49 ora_psp0_orcl
oracle 29284 9.7 0.7 750604 16068 ? Ss Jan08 5:02ora_vktm_orcl
oracle 29290 0.0 0.7 750604 16336 ? Ss Jan08 0:10 ora_gen0_orcl
oracle 29294 0.0 0.7 750604 16060 ? Ss Jan08 0:13 ora_diag_orcl
oracle 29298 0.0 2.0 751116 41756 ? Ss Jan08 0:10 ora_dbrm_orcl
oracle 29302 0.0 1.0 752140 20768 ? Ss Jan08 1:01 ora_dia0_orcl
oracle 29306 0.0 2.0 750604 42072 ? Ss Jan08 0:09 ora_mman_orcl
oracle 29310 0.0 4.8 758152 100212 ? Ss Jan08 0:27 ora_dbw0_orcl
oracle 29314 0.0 1.3 766156 26808 ? Ss Jan08 0:33 ora_lgwr_orcl
oracle 29318 0.0 1.1 750604 24388 ? Ss Jan08 1:25 ora_ckpt_orcl
oracle 29322 0.0 8.4 754196 173024 ? Ss Jan08 0:18 ora_smon_orcl
oracle 29326 0.0 1.5 751116 31544 ? Ss Jan08 0:03 ora_reco_orcl
oracle 29330 0.0 6.1 756580 125636 ? Ss Jan08 0:48 ora_mmon_orcl
oracle 29334 0.0 1.7 752356 36488 ? Ss Jan08 0:59 ora_mmnl_orcl
oracle 29338 0.0 0.7 752636 16028 ? Ss Jan08 0:07 ora_d000_orcl
oracle 29342 0.0 0.7 751800 14868 ? Ss Jan08 0:06 ora_s000_orcl
oracle 29785 0.0 0.8 750604 17724 ? Ss Jan08 0:03 ora_qmnc_orcl
oracle 29889 0.0 7.0 756312 144344 ? Ss Jan08 0:32 ora_cjq0_orcl
oracle 29893 0.0 1.9 752268 40884 ? Ss Jan08 0:03 ora_q000_orcl
oracle 29897 0.0 3.2 756140 65900 ? Ss Jan08 0:03 ora_q001_orcl
oracle 30496 0.0 1.2 751116 25208 ? Ss Jan08 0:09 ora_smco_orcl
[oracle@oraDB ~]$ ps aux| grep oracleorcl
oracle 24862 0.0 1.4 754428 28856 ? Ss 10:22 0:01 oracleorcl (LOCAL=NO)
oracle 24867 0.0 1.0 754408 20828 ? Ss 10:22 0:00 oracleorcl (LOCAL=NO)
oracle 24920 0.0 1.5 760532 31064 ? Ss 10:23 0:01 oracleorcl (LOCAL=NO)
oracle 24937 0.0 1.0 754368 20608 ? Ss 10:23 0:00 oracleorcl (LOCAL=NO)
oracle 24941 0.0 0.7 753336 16176 ? Ss 10:23 0:00 oracleorcl (LOCAL=NO)
oracle 24946 0.0 3.9 757476 80228 ? Ss 10:23 0:01 oracleorcl (LOCAL=NO)
oracle 25022 3.7 1.0 758580 22540 ? Ss 10:24 1:36 oracleorcl
(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 25243 0.1 6.1 768008 126452 ? Ss 10:27 0:04 oracleorcl (LOCAL=NO)
oracle 25291 0.0 1.5 758500 32720 ? Ss 10:27 0:00 oracleorcl (LOCAL=NO)
oracle 25884 0.2 4.2 756544 88324 ? Ss 10:29 0:05 oracleorcl (LOCAL=NO)
oracle 27580 74.9 2.2 774840 47180 ? Rs 10:51 12:50 oracleorcl
(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 27681 0.0 1.0 766648 22544 ? Ss 10:51 0:00 oracleorcl
(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 27714 0.0 1.0 766648 22052 ? Ss 10:51 0:00 oracleorcl
(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 27715 0.0 1.0 766648 22044 ? Ss 10:51 0:00 oracleorcl
(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 27725 0.0 1.0 766648 22060 ? Ss 10:51 0:00 oracleorcl
(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 27735 0.0 1.0 766648 22232 ? Ss 10:51 0:00 oracleorcl
(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 27745 0.0 1.0 766648 22256 ? Ss 10:51 0:00 oracleorcl
(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
Server Processes
Finding Session
SQL> SELECT sid,serial#,username,sql_id,event,state,wait_time
2 FROM v$session
3 WHERE paddr=(SELECT addr FROM v$process WHERE spid=27580);
SID SERIAL# USERNAME SQL_ID EVENT STATE WAIT_TIME
---------- ---------- -------- ------------- ----------------- -------- ---------
140 1365 FRANK 9c1qvzrdbsd8x direct path read WAITING 0
SQL> SELECT sql_id,COUNT(*)
2 FROM v$active_session_history
3 WHERE session_id=140 AND session_serial#=1365
4 GROUP BY sql_id;
SQL_ID COUNT(*)
------------- ----------
9c1qvzrdbsd8x 12010
SQL> SELECT session_state,event,COUNT(*)
2 FROM v$active_session_history
3 WHERE session_id=140 AND session_serial#=1365 AND sql_id='9c1qvzrdbsd8x'
4 GROUP BY session_state,event;
SESSION EVENT COUNT(*)
------- ------------------------------ ----------
WAITING direct path read 11382
ON CPU 654
Asynchronous I/O Enabled?
SQL> SHOW PARAMETER disk_asynch_io
NAME TYPE VALUE
------------------------------------ -------- -----
disk_asynch_io boolean TRUE
SQL> SHOW PARAMETER filesystemio_options
NAME TYPE VALUE
------------------------------------ -------- -----
filesystemio_options string none
SQL> SELECT value
2 FROM v$parameter_valid_values
3 WHERE name=‘filesystemio_options’;
VALUE
---------------------------------------------------------------
ASYNCH
DIRECTIO
SETALL
NONE
SQL> ALTER SYSTEM SET filesystemio_options=SETALL SCOPE=spfile;
--重新啓動Instance才能讓此參數發⽣生效果
• DISK_ASYNCH_IO
• 位在RAW Device/ASM
• FILESYSTEMIO_OPTIONS
• 位在FileSystem
How Asynchronous I/O Work?
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
55.43 0.863631 861 1003 pread64 --同步I/O read所使⽤用system call
37.46 0.583651 807 723 pwrite64 --同步I/O write所使⽤用system call
5.97 0.092986 30995 3 fsync
0.48 0.007534 1 10706 gettimeofday
0.19 0.003014 54 56 write
0.17 0.002644 0 5316 times
0.07 0.001015 22 46 read
0.06 0.001008 12 81 open
0.06 0.001006 11 89 6 stat64
0.06 0.001000 42 24 getdents
0.03 0.000399 6 62 mmap2
0.01 0.000115 0 308 getrusage
0.01 0.000105 9 12 12 readlink
0.00 0.000032 1 41 fcntl64
0.00 0.000009 0 79 close
0.00 0.000007 0 60 statfs
0.00 0.000005 0 38 fstatfs
0.00 0.000004 0 21 21 ioctl
0.00 0.000003 1 4 semctl
0.00 0.000001 0 4 lstat64
0.00 0.000001 1 1 semtimedop
0.00 0.000000 0 11 lseek
0.00 0.000000 0 63 access
0.00 0.000000 0 3 3 mkdir
0.00 0.000000 0 3 munmap
0.00 0.000000 0 5 _llseek
0.00 0.000000 0 5 ftruncate64
0.00 0.000000 0 2 fstat64
------ ----------- ----------- --------- --------- ----------------
100.00 1.558170 18769 42 total
ASM<->FileSystem
DISK_ASYNCH_IO=TRUE
FILESYSTEMIO_OPTIONS=NONE
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
90.37 0.761650 575 1325 io_submit --⾮非同步I/O的system call
5.87 0.049434 3090 16 pwrite64
2.81 0.023692 76 311 pread64
0.41 0.003453 62 56 write
0.17 0.001460 0 5323 times
0.17 0.001438 0 5664 gettimeofday
0.10 0.000861 19 46 read
0.06 0.000534 67 8 munmap
0.01 0.000117 0 322 getrusage
0.00 0.000026 0 81 open
0.00 0.000024 1 41 mmap2
0.00 0.000023 0 81 close
0.00 0.000022 0 60 statfs
0.00 0.000019 0 94 6 stat64
0.00 0.000015 0 38 fstatfs
0.00 0.000012 0 254 io_getevents --⾮非同步I/O的system call
0.00 0.000010 0 41 fcntl64
0.00 0.000008 0 21 21 ioctl
0.00 0.000004 1 4 semctl
0.00 0.000003 0 11 lseek
0.00 0.000003 2 2 lstat64
0.00 0.000002 1 2 semtimedop
0.00 0.000001 0 73 access
0.00 0.000001 0 5 ftruncate64
0.00 0.000001 1 2 fstat64
0.00 0.000000 0 3 3 mkdir
0.00 0.000000 0 12 12 readlink
0.00 0.000000 0 3 fsync
0.00 0.000000 0 2 _llseek
0.00 0.000000 0 24 getdents
------ ----------- ----------- --------- --------- ----------------
100.00 0.842813 13925 42 total
ASM<->FileSystem
DISK_ASYNCH_IO=TRUE
FILESYSTEMIO_OPTIONS=SETALL/ASYNC
測量I/O效能
SQL> SHOW PARAMETER filesystemio_options
NAME TYPE VALUE
------------------------------------ -------- -----
filesystemio_options string SETALL
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 v_latency NUMBER;
3 v_iops NUMBER;
4 v_mbps NUMBER;
5 BEGIN
6 DBMS_RESOURCE_MANGER.CALIBRATE_IO(4,10,v_iops,v_mbps,v_latency);
7 DBMS_OUTPUT.PUT_LINE('Max IO Operations Per Second = '||v_iops);
8 DBMS_OUTPUT.PUT_LINE('Max IO MegaBytes Per Second = '||v_mbps);
9 DBMS_OUTPUT.PUT_LINE('IO Latency='||v_latency);
10 END;
11 /
Max IO Operations Per Second = 65
Max IO MegaBytes Per Second = 31
IO Latency = 8
Q&A

Contenu connexe

Tendances

Oracle statistics by example
Oracle statistics by exampleOracle statistics by example
Oracle statistics by exampleMauro Pagano
 
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And WhatPerformance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And Whatudaymoogala
 
Oracle 10g Performance: chapter 02 aas
Oracle 10g Performance: chapter 02 aasOracle 10g Performance: chapter 02 aas
Oracle 10g Performance: chapter 02 aasKyle Hailey
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersCarlos Sierra
 
Oracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptOracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptChien Chung Shen
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slidesMohamed Farouk
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsJohn Beresniewicz
 
Adapting and adopting spm v04
Adapting and adopting spm v04Adapting and adopting spm v04
Adapting and adopting spm v04Carlos Sierra
 
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdfOracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdfSrirakshaSrinivasan2
 
Migration to Oracle Multitenant
Migration to Oracle MultitenantMigration to Oracle Multitenant
Migration to Oracle MultitenantJitendra Singh
 
All of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL DeveloperAll of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL DeveloperJeff Smith
 
Oracle Database performance tuning using oratop
Oracle Database performance tuning using oratopOracle Database performance tuning using oratop
Oracle Database performance tuning using oratopSandesh Rao
 
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1SolarWinds
 
Christo kutrovsky oracle, memory & linux
Christo kutrovsky   oracle, memory & linuxChristo kutrovsky   oracle, memory & linux
Christo kutrovsky oracle, memory & linuxKyle Hailey
 
Online index rebuild automation
Online index rebuild automationOnline index rebuild automation
Online index rebuild automationCarlos Sierra
 
Same plan different performance
Same plan different performanceSame plan different performance
Same plan different performanceMauro Pagano
 
Awr + 12c performance tuning
Awr + 12c performance tuningAwr + 12c performance tuning
Awr + 12c performance tuningAiougVizagChapter
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizerMauro Pagano
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuningGuy Harrison
 

Tendances (20)

Oracle statistics by example
Oracle statistics by exampleOracle statistics by example
Oracle statistics by example
 
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And WhatPerformance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
 
Oracle 10g Performance: chapter 02 aas
Oracle 10g Performance: chapter 02 aasOracle 10g Performance: chapter 02 aas
Oracle 10g Performance: chapter 02 aas
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginners
 
Oracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptOracle Database SQL Tuning Concept
Oracle Database SQL Tuning Concept
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
 
Understanding index
Understanding indexUnderstanding index
Understanding index
 
Adapting and adopting spm v04
Adapting and adopting spm v04Adapting and adopting spm v04
Adapting and adopting spm v04
 
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdfOracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
 
Migration to Oracle Multitenant
Migration to Oracle MultitenantMigration to Oracle Multitenant
Migration to Oracle Multitenant
 
All of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL DeveloperAll of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL Developer
 
Oracle Database performance tuning using oratop
Oracle Database performance tuning using oratopOracle Database performance tuning using oratop
Oracle Database performance tuning using oratop
 
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
 
Christo kutrovsky oracle, memory & linux
Christo kutrovsky   oracle, memory & linuxChristo kutrovsky   oracle, memory & linux
Christo kutrovsky oracle, memory & linux
 
Online index rebuild automation
Online index rebuild automationOnline index rebuild automation
Online index rebuild automation
 
Same plan different performance
Same plan different performanceSame plan different performance
Same plan different performance
 
Awr + 12c performance tuning
Awr + 12c performance tuningAwr + 12c performance tuning
Awr + 12c performance tuning
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizer
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuning
 

Similaire à Oracle Database Performance Tuning Concept

Collaborate 2019 - How to Understand an AWR Report
Collaborate 2019 - How to Understand an AWR ReportCollaborate 2019 - How to Understand an AWR Report
Collaborate 2019 - How to Understand an AWR ReportAlfredo Krieg
 
261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part i261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part iNaviSoft
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsCarlos Sierra
 
Analyzing and Interpreting AWR
Analyzing and Interpreting AWRAnalyzing and Interpreting AWR
Analyzing and Interpreting AWRpasalapudi
 
OOW09 Ebs Tuning Final
OOW09 Ebs Tuning FinalOOW09 Ebs Tuning Final
OOW09 Ebs Tuning Finaljucaab
 
Denver SQL Saturday The Next Frontier
Denver SQL Saturday The Next FrontierDenver SQL Saturday The Next Frontier
Denver SQL Saturday The Next FrontierKellyn Pot'Vin-Gorman
 
Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...
Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...
Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...LarryZaman
 
Tracing the Breadcrumbs: Apache Spark Workload Diagnostics
Tracing the Breadcrumbs: Apache Spark Workload DiagnosticsTracing the Breadcrumbs: Apache Spark Workload Diagnostics
Tracing the Breadcrumbs: Apache Spark Workload DiagnosticsDatabricks
 
Oracle GoldenGate Presentation from OTN Virtual Technology Summit - 7/9/14 (PDF)
Oracle GoldenGate Presentation from OTN Virtual Technology Summit - 7/9/14 (PDF)Oracle GoldenGate Presentation from OTN Virtual Technology Summit - 7/9/14 (PDF)
Oracle GoldenGate Presentation from OTN Virtual Technology Summit - 7/9/14 (PDF)Bobby Curtis
 
MySQL Replication: Pros and Cons
MySQL Replication: Pros and ConsMySQL Replication: Pros and Cons
MySQL Replication: Pros and ConsRachel Li
 
What are you waiting for? (#SQLSat211)
What are you waiting for? (#SQLSat211)What are you waiting for? (#SQLSat211)
What are you waiting for? (#SQLSat211)Jason Strate
 
OGG Architecture Performance
OGG Architecture PerformanceOGG Architecture Performance
OGG Architecture PerformanceEnkitec
 
ITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfOrtus Solutions, Corp
 
SQL Server It Just Runs Faster
SQL Server It Just Runs FasterSQL Server It Just Runs Faster
SQL Server It Just Runs FasterBob Ward
 
Performance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Performance Scenario: Diagnosing and resolving sudden slow down on two node RACPerformance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Performance Scenario: Diagnosing and resolving sudden slow down on two node RACKristofferson A
 
Oracle GoldenGate Architecture Performance
Oracle GoldenGate Architecture PerformanceOracle GoldenGate Architecture Performance
Oracle GoldenGate Architecture PerformanceEnkitec
 
Ajuste (tuning) del rendimiento de SQL Server 2008
Ajuste (tuning) del rendimiento de SQL Server 2008Ajuste (tuning) del rendimiento de SQL Server 2008
Ajuste (tuning) del rendimiento de SQL Server 2008Eduardo Castro
 

Similaire à Oracle Database Performance Tuning Concept (20)

Collaborate 2019 - How to Understand an AWR Report
Collaborate 2019 - How to Understand an AWR ReportCollaborate 2019 - How to Understand an AWR Report
Collaborate 2019 - How to Understand an AWR Report
 
261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part i261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part i
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
 
Analyzing and Interpreting AWR
Analyzing and Interpreting AWRAnalyzing and Interpreting AWR
Analyzing and Interpreting AWR
 
OOW09 Ebs Tuning Final
OOW09 Ebs Tuning FinalOOW09 Ebs Tuning Final
OOW09 Ebs Tuning Final
 
Using AWR for IO Subsystem Analysis
Using AWR for IO Subsystem AnalysisUsing AWR for IO Subsystem Analysis
Using AWR for IO Subsystem Analysis
 
Denver SQL Saturday The Next Frontier
Denver SQL Saturday The Next FrontierDenver SQL Saturday The Next Frontier
Denver SQL Saturday The Next Frontier
 
Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...
Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...
Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...
 
Tracing the Breadcrumbs: Apache Spark Workload Diagnostics
Tracing the Breadcrumbs: Apache Spark Workload DiagnosticsTracing the Breadcrumbs: Apache Spark Workload Diagnostics
Tracing the Breadcrumbs: Apache Spark Workload Diagnostics
 
Copy Data Management for the DBA
Copy Data Management for the DBACopy Data Management for the DBA
Copy Data Management for the DBA
 
Oracle GoldenGate Presentation from OTN Virtual Technology Summit - 7/9/14 (PDF)
Oracle GoldenGate Presentation from OTN Virtual Technology Summit - 7/9/14 (PDF)Oracle GoldenGate Presentation from OTN Virtual Technology Summit - 7/9/14 (PDF)
Oracle GoldenGate Presentation from OTN Virtual Technology Summit - 7/9/14 (PDF)
 
MySQL Replication: Pros and Cons
MySQL Replication: Pros and ConsMySQL Replication: Pros and Cons
MySQL Replication: Pros and Cons
 
Analyzing awr report
Analyzing awr reportAnalyzing awr report
Analyzing awr report
 
What are you waiting for? (#SQLSat211)
What are you waiting for? (#SQLSat211)What are you waiting for? (#SQLSat211)
What are you waiting for? (#SQLSat211)
 
OGG Architecture Performance
OGG Architecture PerformanceOGG Architecture Performance
OGG Architecture Performance
 
ITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdf
 
SQL Server It Just Runs Faster
SQL Server It Just Runs FasterSQL Server It Just Runs Faster
SQL Server It Just Runs Faster
 
Performance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Performance Scenario: Diagnosing and resolving sudden slow down on two node RACPerformance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Performance Scenario: Diagnosing and resolving sudden slow down on two node RAC
 
Oracle GoldenGate Architecture Performance
Oracle GoldenGate Architecture PerformanceOracle GoldenGate Architecture Performance
Oracle GoldenGate Architecture Performance
 
Ajuste (tuning) del rendimiento de SQL Server 2008
Ajuste (tuning) del rendimiento de SQL Server 2008Ajuste (tuning) del rendimiento de SQL Server 2008
Ajuste (tuning) del rendimiento de SQL Server 2008
 

Plus de Chien Chung Shen

Oracle管理藝術第1章 在Linux作業體統安裝Oracle 11g
Oracle管理藝術第1章 在Linux作業體統安裝Oracle 11gOracle管理藝術第1章 在Linux作業體統安裝Oracle 11g
Oracle管理藝術第1章 在Linux作業體統安裝Oracle 11gChien Chung Shen
 
Oracle使用者安全設定
Oracle使用者安全設定Oracle使用者安全設定
Oracle使用者安全設定Chien Chung Shen
 
Oracle 資料庫檔案介紹
Oracle 資料庫檔案介紹Oracle 資料庫檔案介紹
Oracle 資料庫檔案介紹Chien Chung Shen
 
Oracle 12cR1 In-Memory Column Store
Oracle 12cR1 In-Memory Column StoreOracle 12cR1 In-Memory Column Store
Oracle 12cR1 In-Memory Column StoreChien Chung Shen
 
Oracle Database Undo Segment Operation Concept
Oracle Database Undo Segment Operation ConceptOracle Database Undo Segment Operation Concept
Oracle Database Undo Segment Operation ConceptChien Chung Shen
 
Hadoop Essential for Oracle Professionals
Hadoop Essential for Oracle ProfessionalsHadoop Essential for Oracle Professionals
Hadoop Essential for Oracle ProfessionalsChien Chung Shen
 
Oracle Database Management - Backup/Recovery
Oracle Database Management - Backup/RecoveryOracle Database Management - Backup/Recovery
Oracle Database Management - Backup/RecoveryChien Chung Shen
 

Plus de Chien Chung Shen (18)

Databases on AWS
Databases on AWSDatabases on AWS
Databases on AWS
 
Awsomeday ntc
Awsomeday ntcAwsomeday ntc
Awsomeday ntc
 
Oracle管理藝術第1章 在Linux作業體統安裝Oracle 11g
Oracle管理藝術第1章 在Linux作業體統安裝Oracle 11gOracle管理藝術第1章 在Linux作業體統安裝Oracle 11g
Oracle管理藝術第1章 在Linux作業體統安裝Oracle 11g
 
Oracle 索引介紹
Oracle 索引介紹Oracle 索引介紹
Oracle 索引介紹
 
Oracle 表格介紹
Oracle 表格介紹Oracle 表格介紹
Oracle 表格介紹
 
Oracle使用者安全設定
Oracle使用者安全設定Oracle使用者安全設定
Oracle使用者安全設定
 
Oracle Tablespace介紹
Oracle Tablespace介紹Oracle Tablespace介紹
Oracle Tablespace介紹
 
Oracle 資料庫建立
Oracle 資料庫建立Oracle 資料庫建立
Oracle 資料庫建立
 
Oracle 資料庫檔案介紹
Oracle 資料庫檔案介紹Oracle 資料庫檔案介紹
Oracle 資料庫檔案介紹
 
Oracle SGA 介紹
Oracle SGA 介紹Oracle SGA 介紹
Oracle SGA 介紹
 
Oracle Instance 介紹
Oracle Instance 介紹Oracle Instance 介紹
Oracle Instance 介紹
 
MySQL SQL Tutorial
MySQL SQL TutorialMySQL SQL Tutorial
MySQL SQL Tutorial
 
Oracle 12cR1 In-Memory Column Store
Oracle 12cR1 In-Memory Column StoreOracle 12cR1 In-Memory Column Store
Oracle 12cR1 In-Memory Column Store
 
Mssql to oracle
Mssql to oracleMssql to oracle
Mssql to oracle
 
Oracle Database Undo Segment Operation Concept
Oracle Database Undo Segment Operation ConceptOracle Database Undo Segment Operation Concept
Oracle Database Undo Segment Operation Concept
 
Oracle SQL 1 Day Tutorial
Oracle SQL 1 Day TutorialOracle SQL 1 Day Tutorial
Oracle SQL 1 Day Tutorial
 
Hadoop Essential for Oracle Professionals
Hadoop Essential for Oracle ProfessionalsHadoop Essential for Oracle Professionals
Hadoop Essential for Oracle Professionals
 
Oracle Database Management - Backup/Recovery
Oracle Database Management - Backup/RecoveryOracle Database Management - Backup/Recovery
Oracle Database Management - Backup/Recovery
 

Dernier

How is Real-Time Analytics Different from Traditional OLAP?
How is Real-Time Analytics Different from Traditional OLAP?How is Real-Time Analytics Different from Traditional OLAP?
How is Real-Time Analytics Different from Traditional OLAP?sonikadigital1
 
Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024
Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024
Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024Guido X Jansen
 
AI for Sustainable Development Goals (SDGs)
AI for Sustainable Development Goals (SDGs)AI for Sustainable Development Goals (SDGs)
AI for Sustainable Development Goals (SDGs)Data & Analytics Magazin
 
CI, CD -Tools to integrate without manual intervention
CI, CD -Tools to integrate without manual interventionCI, CD -Tools to integrate without manual intervention
CI, CD -Tools to integrate without manual interventionajayrajaganeshkayala
 
Cash Is Still King: ATM market research '2023
Cash Is Still King: ATM market research '2023Cash Is Still King: ATM market research '2023
Cash Is Still King: ATM market research '2023Vladislav Solodkiy
 
5 Ds to Define Data Archiving Best Practices
5 Ds to Define Data Archiving Best Practices5 Ds to Define Data Archiving Best Practices
5 Ds to Define Data Archiving Best PracticesDataArchiva
 
Elements of language learning - an analysis of how different elements of lang...
Elements of language learning - an analysis of how different elements of lang...Elements of language learning - an analysis of how different elements of lang...
Elements of language learning - an analysis of how different elements of lang...PrithaVashisht1
 
Mapping the pubmed data under different suptopics using NLP.pptx
Mapping the pubmed data under different suptopics using NLP.pptxMapping the pubmed data under different suptopics using NLP.pptx
Mapping the pubmed data under different suptopics using NLP.pptxVenkatasubramani13
 
MEASURES OF DISPERSION I BSc Botany .ppt
MEASURES OF DISPERSION I BSc Botany .pptMEASURES OF DISPERSION I BSc Botany .ppt
MEASURES OF DISPERSION I BSc Botany .pptaigil2
 
The Universal GTM - how we design GTM and dataLayer
The Universal GTM - how we design GTM and dataLayerThe Universal GTM - how we design GTM and dataLayer
The Universal GTM - how we design GTM and dataLayerPavel Šabatka
 
Master's Thesis - Data Science - Presentation
Master's Thesis - Data Science - PresentationMaster's Thesis - Data Science - Presentation
Master's Thesis - Data Science - PresentationGiorgio Carbone
 
Strategic CX: A Deep Dive into Voice of the Customer Insights for Clarity
Strategic CX: A Deep Dive into Voice of the Customer Insights for ClarityStrategic CX: A Deep Dive into Voice of the Customer Insights for Clarity
Strategic CX: A Deep Dive into Voice of the Customer Insights for ClarityAggregage
 
TINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptx
TINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptxTINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptx
TINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptxDwiAyuSitiHartinah
 
SFBA Splunk Usergroup meeting March 13, 2024
SFBA Splunk Usergroup meeting March 13, 2024SFBA Splunk Usergroup meeting March 13, 2024
SFBA Splunk Usergroup meeting March 13, 2024Becky Burwell
 
ChistaDATA Real-Time DATA Analytics Infrastructure
ChistaDATA Real-Time DATA Analytics InfrastructureChistaDATA Real-Time DATA Analytics Infrastructure
ChistaDATA Real-Time DATA Analytics Infrastructuresonikadigital1
 
YourView Panel Book.pptx YourView Panel Book.
YourView Panel Book.pptx YourView Panel Book.YourView Panel Book.pptx YourView Panel Book.
YourView Panel Book.pptx YourView Panel Book.JasonViviers2
 
Virtuosoft SmartSync Product Introduction
Virtuosoft SmartSync Product IntroductionVirtuosoft SmartSync Product Introduction
Virtuosoft SmartSync Product Introductionsanjaymuralee1
 

Dernier (17)

How is Real-Time Analytics Different from Traditional OLAP?
How is Real-Time Analytics Different from Traditional OLAP?How is Real-Time Analytics Different from Traditional OLAP?
How is Real-Time Analytics Different from Traditional OLAP?
 
Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024
Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024
Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024
 
AI for Sustainable Development Goals (SDGs)
AI for Sustainable Development Goals (SDGs)AI for Sustainable Development Goals (SDGs)
AI for Sustainable Development Goals (SDGs)
 
CI, CD -Tools to integrate without manual intervention
CI, CD -Tools to integrate without manual interventionCI, CD -Tools to integrate without manual intervention
CI, CD -Tools to integrate without manual intervention
 
Cash Is Still King: ATM market research '2023
Cash Is Still King: ATM market research '2023Cash Is Still King: ATM market research '2023
Cash Is Still King: ATM market research '2023
 
5 Ds to Define Data Archiving Best Practices
5 Ds to Define Data Archiving Best Practices5 Ds to Define Data Archiving Best Practices
5 Ds to Define Data Archiving Best Practices
 
Elements of language learning - an analysis of how different elements of lang...
Elements of language learning - an analysis of how different elements of lang...Elements of language learning - an analysis of how different elements of lang...
Elements of language learning - an analysis of how different elements of lang...
 
Mapping the pubmed data under different suptopics using NLP.pptx
Mapping the pubmed data under different suptopics using NLP.pptxMapping the pubmed data under different suptopics using NLP.pptx
Mapping the pubmed data under different suptopics using NLP.pptx
 
MEASURES OF DISPERSION I BSc Botany .ppt
MEASURES OF DISPERSION I BSc Botany .pptMEASURES OF DISPERSION I BSc Botany .ppt
MEASURES OF DISPERSION I BSc Botany .ppt
 
The Universal GTM - how we design GTM and dataLayer
The Universal GTM - how we design GTM and dataLayerThe Universal GTM - how we design GTM and dataLayer
The Universal GTM - how we design GTM and dataLayer
 
Master's Thesis - Data Science - Presentation
Master's Thesis - Data Science - PresentationMaster's Thesis - Data Science - Presentation
Master's Thesis - Data Science - Presentation
 
Strategic CX: A Deep Dive into Voice of the Customer Insights for Clarity
Strategic CX: A Deep Dive into Voice of the Customer Insights for ClarityStrategic CX: A Deep Dive into Voice of the Customer Insights for Clarity
Strategic CX: A Deep Dive into Voice of the Customer Insights for Clarity
 
TINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptx
TINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptxTINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptx
TINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptx
 
SFBA Splunk Usergroup meeting March 13, 2024
SFBA Splunk Usergroup meeting March 13, 2024SFBA Splunk Usergroup meeting March 13, 2024
SFBA Splunk Usergroup meeting March 13, 2024
 
ChistaDATA Real-Time DATA Analytics Infrastructure
ChistaDATA Real-Time DATA Analytics InfrastructureChistaDATA Real-Time DATA Analytics Infrastructure
ChistaDATA Real-Time DATA Analytics Infrastructure
 
YourView Panel Book.pptx YourView Panel Book.
YourView Panel Book.pptx YourView Panel Book.YourView Panel Book.pptx YourView Panel Book.
YourView Panel Book.pptx YourView Panel Book.
 
Virtuosoft SmartSync Product Introduction
Virtuosoft SmartSync Product IntroductionVirtuosoft SmartSync Product Introduction
Virtuosoft SmartSync Product Introduction
 

Oracle Database Performance Tuning Concept

  • 4. Performance Tuning • Reactive • 問題已經發⽣生 • 修正問題(TroubleShooting) • Proactive • 問題尚未發⽣生,但有些徵兆出現 • 找出潛在瓶頸,提早解決,避免問題發⽣生
  • 5. Tuning Methodology • Top Down • 盡可能在早期開始進⾏行效能調校 • Response Time • 找出消耗資源最多的SQL敘述句
  • 6. Top Down Application Design Application Development Database Configuration OS Configuration Time
  • 8. Tuning Cost and Benefit Time Low High Design Development Production Cost Benefit
  • 9. Response Time Throughput Time Response time Wait time Service time Response time=Service time+wait time
  • 11. Reduce Wait time Throughput Time Response time Wait time Service time
  • 12. RT Breakdown User AP Server DB Server Disk T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 Time Parse Execute Physical I/O Execute Execute Fetch Process User Request Generate SQL Process SQL Result Generate Web Page Request Response Memory Logical I/O Firewall Physical I/O Execute T13 T14 Time Network filter
  • 13. OLTP/DW A Data Warehouse(DW) is a relational database that is designed for query and analysis rather than for transaction processing. It usually contains historical data derived from transaction data, but it can include data from other sources. It separates analysis workload from transaction workload and enables an organization to consolidate data from several sources. In addition to a relational database, a data warehouse environment includes an extraction, transportation, transformation, and loading (ETL) solution, an online analytical processing (OLAP) engine, client analysis tools, and other applications that manage the process of gathering data and delivering it to business users. An Online Transaction Processing (OLTP) systems are characterized by high throughput, many users, and a mix of DML operations (insert, update, and delete) and queries.
  • 14. Difference between OLTP and DW OLTP DW 3rd Normal Form 表格設計 3NF/Star Schema 多 索引 少 多 Join 中 Normalized DB 資料重覆 DeNormalized DB 少 衍⽣生與彙總 資料 多 事先定義 SELECT Ad Hoc 次數多 每次資料量少 DML 次數少 每次資料量⼤大 Response Time⼩小 Throughput⼤大 系統要求 Response Time⼩小
  • 16. Bill Inmon架構 OLTP OLTP OLTP External Source DML DML DML DML DML DML DML Extract Transform Load Data Mart (3rd NF) Data Mart (3rd NF) Data Mart (3rd NF) Data Warehouse (3rd NF) OLAP BI Ad Hoc Query Report Operational Data Source
  • 17. Ralph Kimball架構 OLTP OLTP OLTP External Source DML DML DML DML DML DML DML Extract Transform Load Data Warehouse (Star Dimension) OLAP BI Ad Hoc Query Report Operational Data Source Data Mart Data Mart Data Mart
  • 18. Tuning Goals • 可被測量 • ⼀一秒鐘裡同時執⾏行1,000個SQL敘述句 • Batch操作可以在60分鐘內完成 • ⼀一個Physical I/O可以在5ms之內完成 • 儘快完成 • 可達到 • ⼀一個Physical I/O可以在1ms之內完成
  • 19. SMON PMON CKPTDBWR LGWR ARCHRECO Shared Pool Buffer Cache Log Buffer Large Pool Java Pool Streams pool Control file Data File Data File Data File Online Logfile Online Logfile Header Header Header Group 1 Group 2 User Process Server Process Archived Logfile System Global Area(SGA) Instance Database Program Global Area Block Block Block S Q L Redo Entry Parse SQL Text Execution Plan Execute Fetch Redo Entry Redo Entry Redo Entry Redo Entry Log Seq:12 Log Seq:11 Log Seq:11Log Seq:12 Log Seq:12Log Seq:12Log Seq:12 Listener Data Dictionary Information Data Dictionary Cache Library Cache $ sqlplus hr/hr@orcl
  • 22. 1) background elapsed time 2) background cpu time 3) RMAN cpu time (backup/restore) 1) DB time 2) DB CPU 2) connection management call elapsed time 2) sequence load elapsed time 2) sql execute elapsed time 2) parse time elapsed 3) hard parse elapsed time 4) hard parse (sharing criteria) elapsed time 5) hard parse (bind mismatch) elapsed time 3) failed parse elapsed time 4) failed parse (out of shared memory) elapsed time 2) PL/SQL execution elapsed time 2) inbound PL/SQL rpc elapsed time 2) PL/SQL compilation elapsed time 2) Java execution elapsed time 2) repeated bind elapsed time Time Model The relationship between a parent and a child in the tree indicates containment only. Keep the following in mind with regard to the tree: • Children do not necessarily add up to the parent. • Children are not necessarily exclusive (that is, it is possible that they overlap). • The union of children does not necessarily cover the whole of the parent.
  • 23. Statistic Name Description DB Time Amount of elapsed time (in microseconds) spent performing Database user-level calls.This does not include the elapsed time spent on instance background processes such as PMON. DB CPU Amount of CPU time (in microseconds) spent on database user-level calls.This does not include the CPU time spent on instance background processes such as PMON. background elapsed time Amount of elapsed time (in microseconds) consumed by database background processes. background CPU time Amount of CPU time (in microseconds) consumed by database background processes. sequential load elapsed time Amount of elapsed time spent getting the next sequence number from the data dictionary. If a sequence is cached, then this is the amount of time spent replenishing the cache when it runs out. No time is charged when a sequence number is found in the cache. For non-cached sequences, some time will be charged for every nextval call. parse time elapsed Amount of elapsed time spent parsing SQL statements. It includes both soft and hard parse time. hard parse elapsed time Amount of elapsed time spent hard parsing SQL statements. SQL execute elapsed time Amount of elapsed time SQL statements are executing. Note that for select statements this also includes the amount of time spent performing fetches of query results. connection management call elapsed time Amount of elapsed time spent performing session connect and disconnect calls. failed parse elapsed time Amount of time spent performing SQL parses which ultimately fail with some parse error. failed parse(out of shared memory) elapsed time Amount of time spent performing SQL parses which ultimately fail with error ORA-04031. hard parse(sharing criteria) elapsed time Amount of elapsed time spent performing SQL hard parses when the hard parse resulted from not being able to share an existing cursor in the SQL cache. hard parse(bind mismatch) elapsed time Amount of elapsed time spent performing SQL hard parses when the hard parse resulted from bind type or bind size mismatch with an existing cursor in the SQL cache. PL/SQL execution elapsed time Amount of elapsed time spent running the PL/SQL interpreter.This does not include time spent recursively executing/parsing SQL statements or time spent recursively executing the JavaVM. PL/SQL compilation elapsed time Amount of elapsed time spent running the PL/SQL compiler. inbound PL/SQL rpc elapsed time Time inbound PL/SQL remote procedure calls have spent executing. It includes all time spent recursively executing SQL and JAVA, and therefore is not easily related to "PL/SQL execution elapsed time". Java execution elapsed time Amount of elapsed time spent running the JavaVM.This does not include time spent recursively executing/parsing SQL statements or time spent recursively executing PL/SQL. RMAN cpu time (backup/restore) Amount of CPU time (in microseconds) spent in RMAN backup and restore operations. repeated bind elapsed time Amount of elapsed time spent giving new values to bind variables (rebinding).
  • 24. SQL> SELECT stat_name,value 2 FROM v$sess_time_model 3 WHERE sid=(select sid from v$mystat where rownum=1); STAT_NAME VALUE ---------------------------------------------------------------- ---------- DB time 154998424 DB CPU 152061882 background elapsed time 0 background cpu time 0 sequence load elapsed time 2553 parse time elapsed 959772 hard parse elapsed time 857517 sql execute elapsed time 27534022 connection management call elapsed time 104349 failed parse elapsed time 74290 failed parse (out of shared memory) elapsed time 0 hard parse (sharing criteria) elapsed time 201941 hard parse (bind mismatch) elapsed time 0 PL/SQL execution elapsed time 147938 inbound PL/SQL rpc elapsed time 0 PL/SQL compilation elapsed time 82522 Java execution elapsed time 0 repeated bind elapsed time 13525 RMAN cpu time (backup/restore) 0 Time Model(session level)
  • 25. background elapsed time 0 background cpu time 0 RMAN cpu time (backup/restore) 0 DB time 154998424 DB CPU 152061882 connection management call elapsed time 104349 sequence load elapsed time 2553 sql execute elapsed time 27534022 parse time elapsed 959772 hard parse elapsed time 857517 hard parse (sharing criteria) elapsed time 201941 hard parse (bind mismatch) elapsed time 0 failed parse elapsed time 74290 failed parse (out of shared memory) elapsed time 0 PL/SQL execution elapsed time 147938 inbound PL/SQL rpc elapsed time 0 PL/SQL compilation elapsed time 82522 Java execution elapsed time 0 repeated bind elapsed time 13525 問題在哪裡?
  • 26. High CPU Load SQLs SQL> SELECT * 2 FROM 3 (SELECT sql_id,elapsed_time,cpu_time,buffer_gets,disk_reads,executions 4 FROM v$sql 5 ORDER BY cpu_time DESC) 7 WHERE ROWNUM<=10; SQL_ID ELAPSED_TIME CPU_TIME BUFFER_GETS DISK_READS EXECUTIONS ------------- ------------ ---------- ----------- ---------- ---------- 6qyqqyg14bm17 4722430672 4566883727 1171553448 1169941510 1 cj8ytxm5hhm4y 82778799 83355256 105 1 10100000 0a59tkkpx31vx 57267687 52511021 6414812 895 7 3ktacv9r56b51 18381236 1381807 109780 1048 6350 cvn54b7yz0s8u 25761776 942843 47660 6616 4142 8swypbbr0m372 7280083 802874 100473 764 6350 ga9j9xk5cy9s0 14530703 493937 24296 752 4142 39m4sx9k63ba2 15383617 449923 22739 1635 4142 c6awqs517jpj0 9019830 340949 13858 512 4142 01uy9sb7w8a9g 37054402 41994 714 83 1 10 rows selected.
  • 27. background elapsed time 0 background cpu time 0 RMAN cpu time (backup/restore) 0 DB time 216686700 DB CPU 117250174 connection management call elapsed time 40823 sequence load elapsed time 2553 sql execute elapsed time 216630397 parse time elapsed 183779537 hard parse elapsed time 111831471 hard parse (sharing criteria) elapsed time 24630 hard parse (bind mismatch) elapsed time 0 failed parse elapsed time 1704 failed parse (out of shared memory) elapsed time 0 PL/SQL execution elapsed time 13803553 inbound PL/SQL rpc elapsed time 0 PL/SQL compilation elapsed time 4368 Java execution elapsed time 0 repeated bind elapsed time 136 問題在哪裡?
  • 28. plan_hash_value相同,但是hash_value不相同,不過sql statement除literal外,其餘部分相同 plan_hash_value為hash(execution plan) hash_value為hash(sql statement) SQL> SELECT * 2 FROM (SELECT plan_hash_value,count(*) 3 FROM v$sql 4 GROUP BY plan_hash_value 5 ORDER BY count(*) DESC) 6 WHERE ROWNUM<=10; PLAN_HASH_VALUE COUNT(*) --------------- ---------- 0 286 1327943602 48 1388734953 48 2890534904 30 2363543667 26 417717735 26 2848324471 23 2383372605 20 735420252 19 2365942777 16 10 rows selected.
  • 29. SQL> SELECT hash_value,sql_id,sql_text 2 FROM v$sql 3 WHERE plan_hash_value='1327943602'; HASH_VALUE SQL_ID ---------- ------------- SQL_TEXT ------------------------------------------------------------------------------- 3262910503 3w43dxr17s417 select object_name,object_type from hr.big1 where object_id=54911 4194570773 9npmsp7x084hp select object_name,object_type from hr.big1 where object_id=40964 2274762271 ctv0gn23tc7hz select object_name,object_type from hr.big1 where object_id=92651 4159188012 36frnbbvyhb1c select object_name,object_type from hr.big1 where object_id=83436 1689400341 0uzss2tkb4d0p select object_name,object_type from hr.big1 where object_id=56791
  • 30. SQL> SHOW PARAMETER cursor_sharing NAME TYPE VALUE ------------------------- ------ ------ cursor_sharing string EXACT SQL> select last_name from hr.employees where employee_id=100; LAST_NAME ------------------------- King SQL> select last_name from hr.employees where employee_id=200; LAST_NAME ------------------------- Whalen SQL> SELECT hash_value,plan_hash_value,executions,sql_text 2 FROM v$sql 3 WHERE sql_text like 'select last_name from hr.employees where employee_id=%'; HASH_VALUE PLAN_HASH_VALUE EXECUTIONS ---------- --------------- ---------- SQL_TEXT -------------------------------------------------------------------------------- 2627784799 1833546154 1 select last_name from hr.employees where employee_id=200 280342537 1833546154 1 select last_name from hr.employees where employee_id=100 解決Hard Parse-DBA篇
  • 31. SQL> ALETER SESSION SET cursor_sharing=FORCE; SQL> SHOW PARAMETER cursor_sharing NAME TYPE VALUE ------------------------- ------ ------ cursor_sharing string FORCE SQL> select last_name from hr.employees where employee_id=101; LAST_NAME ------------------------- Kochhar SQL> select last_name from hr.employees where employee_id=201; LAST_NAME ------------------------- Hartstein SQL> SELECT hash_value,plan_hash_value,executions,sql_text 2 FROM v$sql 3 WHERE sql_text like 'select last_name from hr.employees where employee_id=%'; HASH_VALUE PLAN_HASH_VALUE EXECUTIONS ---------- --------------- ---------- SQL_TEXT -------------------------------------------------------------------------------- 1893902718 1833546154 2 select last_name from hr.employees where employee_id=:"SYS_B_0" 2627784799 1833546154 1 select last_name from hr.employees where employee_id=200 280342537 1833546154 1 select last_name from hr.employees where employee_id=100
  • 32. SQL> SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD:HH24:MI:SS'),COUNT(*) 2 FROM v$session 3 WHERE type != 'BACKGROUND' AND status='ACTIVE'; TO_CHAR(SYSDATE,'YY COUNT(*) ------------------- ---------- 2013-01-08:16:29:50 6 SQL> SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD:HH24:MI:SS'),value 2 FROM v$sysstat 3 WHERE name='execute count'; TO_CHAR(SYSDATE,'YY VALUE ------------------- ---------- 2013-01-08:16:32:27 21590278 SQL執⾏行數與ACTIVE SESSION數
  • 34. SESSION Status and Event • V$SESSION.STATUS • INACTIVE • ACTIVE • V$SESSION.EVENT • SELECT name FROM v$event_name
  • 37. SQL> select sid,serial#,event,seconds_in_wait,wait_time,status 2 from v$session 3 where username='SH'; SID SERIAL# EVENT SECONDS_IN_WAIT WAIT_TIME STATUS ---------- ---------- ------------------------------ --------------- ---------- -------- 78 89 SQL*Net message from client 3446 0 INACTIVE
  • 38. SQL> select sid,serial#,event,seconds_in_wait,wait_time,status 2 from v$session 3 where username='SH'; SID SERIAL# EVENT SECONDS_IN_WAIT WAIT_TIME STATUS ---------- ---------- ------------------------------ --------------- ---------- -------- (S1) 78 89 direct path read 951 -1 ACTIVE Session1> select count(*) from sh.t1 connect by level<=10000;
  • 39. SQL> select sid,serial#,event,seconds_in_wait,wait_time,status 2 from v$session 3 where username='SH'; SID SERIAL# EVENT SECONDS_IN_WAIT WAIT_TIME STATUS ---------- ---------- ------------------------------ --------------- ---------- -------- (S2) 73 749 SQL*Net message from client 453 0 INACTIVE (S1) 78 89 direct path read 951 -1 ACTIVE (S3) 136 661 enq: TX - row lock contention 393 0 ACTIVE Session1> select count(*) from sh.t1 connect by level<=10000; Session2> update sh.t2 set b=‘C99’ where a=99; Session3> update sh.t2 set b=‘D99’ where a=99;
  • 40. [oracle@oraDB ~]$ top top - 12:30:14 up 1:24, 5 users, load average: 1.41, 1.45, 1.28 Tasks: 225 total, 2 running, 223 sleeping, 0 stopped, 0 zombie Cpu(s): 20.8%us, 3.9%sy, 0.0%ni, 75.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 2054636k total, 1951288k used, 103348k free, 24816k buffers Swap: 4095996k total, 4156k used, 4091840k free, 939340k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 6275 oracle 20 0 743m 93m 86m R 99.7 4.7 13:47.18 oracle 3396 oracle -2 0 733m 15m 13m S 4.3 0.8 7:08.00 oracle 5752 oracle 20 0 672m 148m 27m S 4.3 7.4 6:20.90 firefox 2745 root 20 0 76600 996 712 S 0.3 0.0 0:02.92 VBoxService 3025 root 20 0 121m 35m 6512 S 0.3 1.8 0:15.81 Xorg 3392 oracle 20 0 733m 16m 14m S 0.3 0.8 0:04.58 oracle 3402 oracle 20 0 733m 15m 14m S 0.3 0.8 0:00.44 oracle 4026 oracle 20 0 1247m 268m 21m S 0.3 13.4 1:14.59 java 4455 oracle 20 0 738m 106m 100m S 0.3 5.3 0:11.34 oracle 5001 oracle 20 0 89788 1300 848 S 0.3 0.1 0:25.17 VBoxClient 11712 root 20 0 0 0 0 S 0.3 0.0 0:00.01 kworker/1:2 1 root 20 0 10412 704 588 S 0.0 0.0 0:01.14 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:08.37 ksoftirqd/0 5 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/u:0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 7 root RT 0 0 0 0 S 0.0 0.0 0:00.42 watchdog/0 8 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/1
  • 41. [oracle@oraDB ~]$ sar 5 10 Linux 2.6.39-400.24.1.el5uek (oraDB) 06/27/2013 12:29:05 PM CPU %user %nice %system %iowait %steal %idle 12:29:10 PM all 21.95 0.00 4.34 0.00 0.00 73.72 12:29:15 PM all 19.64 0.00 4.67 0.00 0.00 75.69 12:29:20 PM all 21.17 0.00 4.91 0.00 0.00 73.92 12:29:25 PM all 20.46 0.00 4.24 0.00 0.00 75.30 12:29:30 PM all 20.15 0.00 4.29 0.00 0.00 75.56 12:29:35 PM all 20.51 0.00 4.21 0.00 0.00 75.28 12:29:40 PM all 19.97 0.00 4.39 1.55 0.00 74.09 12:29:45 PM all 24.01 0.00 8.57 0.00 0.00 67.42 12:29:50 PM all 21.58 0.00 5.91 0.00 0.00 72.51 12:29:55 PM all 20.33 0.00 4.95 0.05 0.00 74.66 Average: all 20.98 0.00 5.05 0.16 0.00 73.80
  • 42. Session1> select count(*) from sh.t1 connect by level<=10000; Session2> update sh.t2 set b=‘C99’ where a=99; Session3> update sh.t2 set b=‘D99’ where a=99; Session4> select /*+ use_nl(s c) ordered full(s) full(c) */ count(*) 2 from sh.sales s,sh.customers c 3 where s.cust_id=c.cust_id and c.cust_first_name='Dina'; SQL> select sid,serial#,event,seconds_in_wait,wait_time,status 2 from v$session 3 where username='SH'; SID SERIAL# EVENT SECONDS_IN_WAIT WAIT_TIME STATUS ---------- ---------- ------------------------------ --------------- ---------- -------- 16 731 direct path read 0 0 ACTIVE 73 749 SQL*Net message from client 453 0 INACTIVE 78 89 direct path read 951 -1 ACTIVE 136 661 enq: TX - row lock contention 393 0 ACTIVE
  • 43. [oracle@oraDB ~]$ top top - 12:48:31 up 1:43, 6 users, load average: 2.66, 2.46, 1.95 Tasks: 231 total, 3 running, 228 sleeping, 0 stopped, 0 zombie Cpu(s): 31.2%us, 21.9%sy, 0.0%ni, 46.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 2054636k total, 1962120k used, 92516k free, 25456k buffers Swap: 4095996k total, 6568k used, 4089428k free, 930208k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 6275 oracle 20 0 743m 93m 86m R 100.0 4.7 32:07.81 oracle 12781 oracle 20 0 755m 59m 49m R 99.7 3.0 8:14.40 oracle 5752 oracle 20 0 672m 152m 27m S 6.0 7.6 7:18.32 firefox 3396 oracle -2 0 733m 15m 13m S 4.7 0.8 7:58.76 oracle 3024 root 20 0 183m 4104 3376 S 0.3 0.2 0:04.09 gdm-rh-security 3025 root 20 0 121m 35m 6512 S 0.3 1.8 0:17.22 Xorg 3392 oracle 20 0 733m 16m 14m S 0.3 0.8 0:05.16 oracle 4004 oracle 20 0 90820 13m 1924 S 0.3 0.7 0:01.13 perl 4026 oracle 20 0 1247m 256m 21m S 0.3 12.8 1:21.03 java 13352 oracle 20 0 12908 1212 836 R 0.3 0.1 0:00.14 top 1 root 20 0 10412 704 588 S 0.0 0.0 0:01.17 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:08.47 ksoftirqd/0 5 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/u:0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 7 root RT 0 0 0 0 S 0.0 0.0 0:00.45 watchdog/0 8 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/1 10 root 20 0 0 0 0 S 0.0 0.0 0:02.58 ksoftirqd/1
  • 44. [oracle@oraDB ~]$ sar 5 10 Linux 2.6.39-400.24.1.el5uek (oraDB) 06/27/2013 12:48:01 PM CPU %user %nice %system %iowait %steal %idle 12:48:06 PM all 30.62 0.00 24.25 0.30 0.00 44.82 12:48:11 PM all 29.74 0.00 24.01 0.15 0.00 46.10 12:48:16 PM all 28.79 0.00 23.45 0.10 0.00 47.66 12:48:21 PM all 28.76 0.00 23.83 0.00 0.00 47.41 12:48:26 PM all 30.86 0.05 23.05 0.00 0.00 46.04 12:48:31 PM all 35.78 0.00 23.56 0.00 0.00 40.66 12:48:36 PM all 31.34 0.00 21.98 0.05 0.00 46.63 12:48:41 PM all 31.99 0.00 22.47 0.10 0.00 45.44 12:48:46 PM all 31.13 0.00 22.26 0.15 0.00 46.46 12:48:51 PM all 29.36 0.00 22.81 0.20 0.00 47.63 Average: all 30.83 0.01 23.17 0.11 0.00 45.89
  • 45. SQL> select sid,serial#,event,seconds_in_wait,wait_time,status 2 from v$session 3 where username='SH'; SID SERIAL# EVENT SECONDS_IN_WAIT WAIT_TIME STATUS ---------- ---------- ------------------------------ --------------- ---------- -------- 16 731 direct path read 0 0 ACTIVE 17 415 direct path read 283 -1 ACTIVE 73 749 SQL*Net message from client 1817 0 INACTIVE 76 387 db file sequential read 250 -1 ACTIVE 78 89 direct path read 2315 -1 ACTIVE 136 661 enq: TX - row lock contention 1757 0 ACTIVE
  • 46. top - 12:57:48 up 1:52, 6 users, load average: 4.83, 4.02, 2.91 Tasks: 231 total, 7 running, 224 sleeping, 0 stopped, 0 zombie Cpu(s): 67.6%us, 32.4%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 2054636k total, 1964360k used, 90276k free, 26088k buffers Swap: 4095996k total, 7572k used, 4088424k free, 918084k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 13591 oracle 20 0 738m 60m 53m R 91.0 3.0 6:37.95 oracle 14005 oracle 20 0 738m 40m 33m R 83.7 2.0 0:31.95 oracle 12781 oracle 20 0 755m 62m 49m R 76.7 3.1 16:59.61 oracle 13622 oracle 20 0 735m 47m 43m R 69.7 2.4 6:07.11 oracle 6275 oracle 20 0 743m 93m 86m R 60.1 4.7 40:51.74 oracle 4080 oracle 20 0 750m 171m 157m S 6.3 8.5 1:16.69 oracle 5752 oracle 20 0 672m 150m 27m R 6.0 7.5 7:51.57 firefox 3396 oracle -2 0 733m 15m 13m S 4.3 0.8 8:23.12 oracle 4026 oracle 20 0 1247m 254m 21m S 0.7 12.7 1:24.61 java 4047 oracle 20 0 290m 38m 15m S 0.7 1.9 0:08.45 emagent 5257 oracle 20 0 278m 11m 7776 S 0.7 0.6 0:13.24 mixer_applet2 3025 root 20 0 121m 35m 6512 S 0.3 1.8 0:17.94 Xorg 3392 oracle 20 0 733m 16m 14m S 0.3 0.8 0:05.42 oracle 3414 oracle 20 0 734m 19m 17m S 0.3 1.0 0:02.86 oracle 3442 oracle 20 0 738m 101m 96m S 0.3 5.0 0:06.65 oracle 5001 oracle 20 0 89788 1300 848 S 0.3 0.1 0:28.68 VBoxClient 9056 root 20 0 0 0 0 S 0.3 0.0 0:00.82 kworker/1:0 14037 oracle 20 0 12804 1128 756 R 0.3 0.1 0:00.09 top
  • 47. [oracle@oraDB ~]$ sar 5 10 Linux 2.6.39-400.24.1.el5uek (oraDB) 06/27/2013 12:57:16 PM CPU %user %nice %system %iowait %steal %idle 12:57:21 PM all 62.70 0.00 37.30 0.00 0.00 0.00 12:57:26 PM all 69.47 0.00 30.53 0.00 0.00 0.00 12:57:31 PM all 64.38 0.00 35.62 0.00 0.00 0.00 12:57:36 PM all 65.33 0.00 34.67 0.00 0.00 0.00 12:57:41 PM all 64.08 0.00 35.92 0.00 0.00 0.00 12:57:46 PM all 63.50 0.00 36.50 0.00 0.00 0.00 12:57:51 PM all 66.65 0.05 33.30 0.00 0.00 0.00 12:57:56 PM all 72.28 0.00 27.72 0.00 0.00 0.00 12:58:01 PM all 69.79 0.00 30.21 0.00 0.00 0.00 12:58:06 PM all 66.62 0.00 33.38 0.00 0.00 0.00 Average: all 66.48 0.01 33.52 0.00 0.00 0.00
  • 49. SQL> select s.sid,s.serial#,s.event,s.status, 2 (select value from v$sesstat st where st.sid=s.sid and st.statistic#=17) cpu_used_sess 3 from v$session s 4 where s.username='SH'; SID SERIAL# EVENT STATUS CPU_USED_SESS ---------- ---------- ------------------------------ -------- ------------- 16 731 direct path read ACTIVE 33 17 415 direct path read ACTIVE 77 73 749 SQL*Net message from client INACTIVE 35 76 387 db file sequential read ACTIVE 17 78 89 direct path read ACTIVE 3075 136 661 enq: TX - row lock contention ACTIVE 13 204 4527 direct path read ACTIVE 6 SQL> select s.sid,s.serial#,s.event,sio.consistent_gets,sio.physical_reads 2 from v$session s,v$sess_io sio 3 where s.sid=sio.sid and s.username='SH'; SID SERIAL# EVENT CONSISTENT_GETS PHYSICAL_READS ---------- ---------- ------------------------------ --------------- -------------- 16 731 direct path read 432669473 432071262 17 415 direct path read 3630 2144 73 749 SQL*Net message from client 3673 19 76 387 db file sequential read 1427 4 78 89 direct path read 16159 4606 136 661 enq: TX - row lock contention 1131 0 204 4527 direct path read 1417 1072
  • 50. Profile Session State select case when session_state='ON CPU' THEN 'ON CPU' when session_state='WAITING' and wait_class='User I/O' then 'I/O' else 'WAITING' end session_state, event,sql_id from v$active_session_history where session_id=&session_id and session_serial#=&serial_number order by sample_time;
  • 51. SESSION EVENT SQL_ID ------- --------------------------------------- ------------------------ I/O direct path read 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 I/O direct path read 47u05qwhnv8q0 I/O direct path read 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 I/O direct path read 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 I/O direct path read 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 I/O direct path read 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 I/O direct path read 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 I/O direct path read 47u05qwhnv8q0 I/O direct path read 47u05qwhnv8q0 I/O direct path read 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0 I/O direct path read 47u05qwhnv8q0 ON CPU 47u05qwhnv8q0
  • 52. SQL> select * from table(dbms_xplan.display_cursor('47u05qwhnv8q0')); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------- SQL_ID 47u05qwhnv8q0, child number 0 ------------------------------------- select /*+ use_nl(s c) ordered full(s) full(c) */ count(*) from sh.sales s,sh.customers c where s.cust_id=c.cust_id and c.cust_first_name='Dina' Plan hash value: 2043253752 --------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop| --------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 370M(100)| | | | | 1 | SORT AGGREGATE | | 1 | 17 | | | | | | 2 | NESTED LOOPS | | 5557 | 94469 | 370M (1)| 999:59:59 | | | | 3 | PARTITION RANGE ALL| | 918K| 4486K| 526 (2)| 00:00:07 | 1 | 28 | | 4 | TABLE ACCESS FULL | SALES | 918K| 4486K| 526 (2)| 00:00:07 | 1 | 28 | |* 5 | TABLE ACCESS FULL | CUSTOMERS | 1 | 12 | 404 (1)| 00:00:05 | | | --------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 5 - filter(("C"."CUST_FIRST_NAME"='Dina' AND "S"."CUST_ID"="C"."CUST_ID"))
  • 53. Memory⾃自動管理 • Automatic Memory Management • MEMORY_TARGET • SGA_TARGET • PGA_AGGREGATE_TARGET
  • 54. SMO N PGA Shared Pool Statistics Buffer Cache Large Pool Java Pool Stream s Pool Fixed SGA Log Buffer Server process PGA PMO N PGA DBW R PGA LGW R PGA CKPT PGA ARCH PGA MMO N PGA MMA N PGA Server process PGA Server process PGA Server process PGA Server process PGA MEMORY_TARGET SGA_TARGETPGA_AGGREGATE_TARGET Memory Advisors 取得 呼叫 建議 調整 Server Parameter file 記錄
  • 56. On a healthy system, physical read waits should be the biggest waits after the idle waits. However, also consider whether there are direct read waits (signifying full table scans with parallel query) or db file scattered read waits on an operational (OLTP) system that should be doing small indexed accesses. Other things that could indicate excessive I/O load on the system include the following: • Poor buffer cache hit ratio • These wait events accruing most of the wait time for a user experiencing poor response time However, also consider whether there are db file sequential reads on a large data warehouse that should be seeing mostly full table scans with parallel query. Oracle® Database Performance Tuning Guide 11g Release 2 (11.2) - 10 Instance Tuning Using Performance Views OLTP應該多數為Index Scan DW應該多數為Full Table Scan
  • 57. I/O調校重點 • 降低I/O related wait time • I/O分散 • 減少I/O量 • 減少Physical I/O • 增加Buffer Cache Hit Ratio • 1-((Physical I/O)/(Physical I/O+Logical I/O))
  • 58. Latency Comparison Numbers L1 cache reference 0.5 ns Branch mispredict 5 ns L2 cache reference 7 ns 14x L1 cache Mutex lock/unlock 25 ns Main memory reference 100 ns 20x L2 cache, 200x L1 cache Compress 1K bytes with Zippy 3,000 ns Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms Read 1 MB sequentially from memory 250,000 ns 0.25 ms Round trip within same datacenter 500,000 ns 0.5 ms Read 1 MB sequentially from SSD 1,000,000 ns 1 ms 4X memory Disk seek 10,000,000 ns 10 ms 20x datacenter roundtrip Read 1 MB sequentially from disk 20,000,000 ns 20 ms 80x memory, 20X SSD Send packet CA->Netherlands->CA 150,000,000 ns 150 ms
  • 60. 重要的I/O Waits • db file scattered read • This event signifies that the user process is reading buffers into the SGA buffer cache and is waiting for a physical I/O call to return.A db file scattered read issues a scattered read to read the data into multiple discontinuous memory locations.A scattered read is usually a multiblock read. It can occur for a fast full scan (of an index) in addition to a full table scan. • direct path read • When a session is reading buffers from disk directly into the PGA (opposed to the buffer cache in SGA), it waits on this event. If the I/O subsystem does not support asynchronous I/Os, then each wait corresponds to a physical read request. If the I/O subsystem supports asynchronous I/ O, then the process is able to overlap issuing read requests with processing the blocks already existing in the PGA.When the process attempts to access a block in the PGA that has not yet been read from disk, it then issues a wait call and updates the statistics for this event. Hence, the number of waits is not necessarily the same as the number of read requests (unlike db file scattered read and db file sequential read). • db file sequential read • This event signifies that the user process is reading a buffer into the SGA buffer cache and is waiting for a physical I/O call to return.A sequential read is a single-block read. Oracle® Database Performance Tuning Guide 11g Release 2 (11.2) - 10 Instance Tuning Using Performance Views
  • 61. SQL> SELECT * FROM ( 2 SELECT event,total_waits,time_waited,average_wait 3 FROM v$system_event 4 WHERE wait_class != 'Idle' 5 ORDER BY time_waited DESC,total_waits DESC) 6 WHERE rownum<=10; EVENT TOTAL_WAITS TIME_WAITED AVERAGE_WAIT ------------------------------------------ ----------- ----------- ------------- db file sequential read 7654 75033 9.8 direct path read 46079 48133 1.04 db file scattered read 561 7013 12.5 library cache load lock 42 5821 138.6 cursor: pin S wait on X 24 1034 43.06 db file parallel read 43 826 19.21 Disk file operations I/O 194 636 3.28 control file sequential read 1614 560 .35 ADR block file read 410 463 1.13 control file heartbeat 1 400 400.08 10 rows selected. 百分之⼀一秒 V$SYSTEM_EVENT
  • 62. Server Process Datafile Buffer Cache High Water Mark PGA Full Table Scan db file scattered read v$session_longops
  • 63. 解決db file scattered read • Index Scan • Table Compression • Table Reorganization • Partitioned table • db_file_multiblock_read_count • Multiple Buffer Cache
  • 64. DB_FILE_MULTIBLOCK_READ • Full Table Scan • Index Fast Full Scan • 10gR2之後,建議由Oracle Server⾃自動選 擇(預設值=OS_MaxIO_Size/Block_Size) SQL> show parameter db_file_multiblock_read_count NAME TYPE  VALUE ------------------------------------ ----------- ------- db_file_multiblock_read_count  integer  16 SQL> alter system reset db_file_multiblock_read_count scope=spfile sid='*'; SQL> shutdown immediate; SQL> startup;
  • 65. Finding Full Scan SQLs SQL> select sql_text 2 from v$sqltext t, v$sql_plan p 3 where t.hash_value=p.hash_value and p.operation='TABLE ACCESS' 4 and p.options='FULL' 5 order by p.hash_value, t.piece; SQL> select sql_text 2 from v$sqltext t, v$sql_plan p 3 where t.hash_value=p.hash_value and p.operation='INDEX' 4 and p.options='FAST FULL SCAN' 5 order by p.hash_value, t.piece;
  • 66. Server Process Datafile Buffer Cache High Water Mark PGA db file sequential read Index Scan
  • 67. SQL> SELECT sid, total_waits, time_waited 2 FROM v$session_event 3 WHERE event='db file sequential read' and total_waits>0 4 ORDER BY 3,2; 解決db file sequential read • Partitioned Index - Local/Global index • Index Reorganization
  • 68. Server Process Datafile Buffer Cache High Water Mark PGA Full Table Scan direct path read _small_table_threshold = (db_cache_size*2%)/data_block_size blocks>5*_small_table_threshold
  • 69. Logfile Related Waits • Log File Sync •When a user session commits, the session's redo information needs to be flushed to the redo logfile. The user session will post the LGWR to write the log buffer to the redo log file. When the LGWR has finished writing, it will post the user session. • Log File Parallel Write •Writing redo records to the redo log files from the log buffer. Oracle® Database Reference 11g Release 2 (11.2) E25513-04
  • 70. User LogBuffer LGWR T1 T2 T4 T6 T7 Time Commit COMMITTED Logfile Members Server Process Time Generate Commit Redo Entry Begin Physical I/Os Physical I/Os Completed T5 T8 T3 T9 Server Process Post LGWR LGWR post Server Process Copy Commit Redo Entry to LogBuffer Log file Parallel Write Log File Sync
  • 71. Sync Commit Shared Pool Buffer Cache Log Buffer Datafile DBW R LGW R Server Process PMO N SMO N CKPT RECO 1 A A1 10 J J1 0 17 Q Q 17 2 B B2 18 R R1 8 19 S S1 9 3 C C3 7 G G7 11 K K1 1 4 D D4 12 L L1 2 21 U U 21 6 F F6 13 M M 13 22 V V2 2 8 H H 8 15 O O 15 24 X X 24 5 E E5 14 N N 14 23 W W 23 9 I I9 16 P P1 6 20 T T2 0 A B C 1 A A1 2 B B2 3 C C3 4 D D4 5 E F5 6 F E6 7 G G7 8 H H8 9 I I9 10 J J10 11 K K11 12 L L12 13 M M13 14 N N14 15 O O15 16 P P16 17 Q Q17 18 R R18 19 S S91 20 T T20 21 U U21 22 V V22 23 W W23 24 X X24 User Process COMMIT; 1.Parse Execution Plan 2.Execute 2 B B2 18 R R1 8 19 S S9 1 S1 undo block undo S1 9 data S9 1 commit commit Logfile group 1 Control file Logfile group 2 undo S1 9 data S9 1 commit 2.5 COMMITTED 2.4 Release Lock 2.1 Generated Redo Entries 2.2 Copy Redo Entries to Log Buffer 2.3 Write Redo Entries to Log File
  • 72. Async Commit batch:當server process執⾏行commit時,並不會觸發lgwr將log buffer的redo entry寫到logfile lgwr除了commit將觸發寫⼊入操作外,還有redo entry佔log buffer的1/3以上空間或1M,以及每3秒鐘將⾃自動觸發⼀一次. 最後還有dbwr想要將某個dirty buffer內容寫到datafile前,如果redo entry還在log buffer裡尚未被寫到logfile, 也會觸發lgwr將redo entry寫到logfile. nowait:當server process執⾏行commit時,不需要等到lgwr完成I/O,便可以得到committed的訊息,⽽而且可以開始進⾏行新 的指令 注意,使⽤用nowait可能造成在instance/media recovery後,committed data遺失. 因為lgwr的確尚未將log buffer裡的redo entry寫到logfile SQL> show parameter commit_write NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ commit_write string --空值為預設值,表⽰示為immediate,wait immediate wait batch nowait SQL> alter system set commit_write=batch,nowait; **最安全(default)=>immediate,wait **最快回應=>batch,nowait **⽐比最安全快,⼜又⽐比最快安全=>immediate,nowait **最不應該使⽤用=>batch,wait
  • 73. Batch,NoWait Shared Pool Buffer Cache Log Buffer Datafile DBW R LGW R Server Process PMO N SMO N CKPT RECO 1 A A1 10 J J1 0 17 Q Q 17 2 B B2 18 R R1 8 19 S S1 9 3 C C3 7 G G7 11 K K1 1 4 D D4 12 L L1 2 21 U U 21 6 F F6 13 M M 13 22 V V2 2 8 H H 8 15 O O 15 24 X X 24 5 E E5 14 N N 14 23 W W 23 9 I I9 16 P P1 6 20 T T2 0 A B C 1 A A1 2 B B2 3 C C3 4 D D4 5 E F5 6 F E6 7 G G7 8 H H8 9 I I9 10 J J10 11 K K11 12 L L12 13 M M13 14 N N14 15 O O15 16 P P16 17 Q Q17 18 R R18 19 S S91 20 T T20 21 U U21 22 V V22 23 W W23 24 X X24 User Process COMMIT; 1.Parse Execution Plan 2.Execute 2 B B2 18 R R1 8 19 S S9 1 S1 undo block undo S1 9 data S9 1 commit commit Logfile group 1 Control file Logfile group 2 undo S1 9 data S9 1 commit 2.4 COMMITTED 2.3 Release Lock 2.1 Generated Redo Entries 2.2 Copy Redo Entries to Log Buffer
  • 74. Immediate,NoWait Shared Pool Buffer Cache Log Buffer Datafile DBW R LGW R Server Process PMO N SMO N CKPT RECO 1 A A1 10 J J1 0 17 Q Q 17 2 B B2 18 R R1 8 19 S S1 9 3 C C3 7 G G7 11 K K1 1 4 D D4 12 L L1 2 21 U U 21 6 F F6 13 M M 13 22 V V2 2 8 H H 8 15 O O 15 24 X X 24 5 E E5 14 N N 14 23 W W 23 9 I I9 16 P P1 6 20 T T2 0 A B C 1 A A1 2 B B2 3 C C3 4 D D4 5 E F5 6 F E6 7 G G7 8 H H8 9 I I9 10 J J10 11 K K11 12 L L12 13 M M13 14 N N14 15 O O15 16 P P16 17 Q Q17 18 R R18 19 S S91 20 T T20 21 U U21 22 V V22 23 W W23 24 X X24 User Process COMMIT; 1.Parse Execution Plan 2.Execute 2 B B2 18 R R1 8 19 S S9 1 S1 undo block undo S1 9 data S9 1 commit commit Logfile group 1 Control file Logfile group 2 undo S1 9 data S9 1 commit 2.4 COMMITTED 2.3 Release Lock 2.1 Generated Redo Entries 2.2 Copy Redo Entries to Log Buffer 2.4 Write Redo Entries to Log File
  • 75. I/O分散 • S.A.M.E(Stripe And Mirror Everything) • Hardware RAID • ASM • 類似RAID 0+1,但單位不相同 • Optimal Flexible Architecture • Datafile與Logfile • Logfile與Archived logfile • Datafile與Backup
  • 81. RAID TYPE Control File Datafile Redo Logfile Archived Logfile 0 Stripe Avoid Ok Avoid Avoid 1 Mirror Ok Ok Recommended Recommended 0+1 (ASM) Mirror/ Stripe Ok Recommended Ok Avoid 1+0 Stripe/ Mirror Ok Recommended Ok Avoid 5 Stripe/ Parity Check Ok Avoid (Write Intensive) Avoid Avoid
  • 82. OLTP or DW SQL> SELECT (SELECT tablespace_name FROM dba_data_files WHERE file_id=file#) tablespace_name, 2 phyrds,phyblkrd,ROUND(phyblkrd/phyrds) “BLKS/RDS”, 3 singleblkrds,readtim,singleblkrdtim,avgiotim 4 FROM v$filestat; TABLESPACE_NAME PHYRDS PHYBLKRD BLKS/RDS SINGLEBLKRDS READTIM SINGLEBLKRDTIM AVGIOTIM --------------- --------- ---------- -------- ------------ --------- --------------- --------- SYSTEM 172364 274588 2 164676 34067 31959 0 SYSAUX 110096 193796 2 97437 15088 10918 0 UNDOTBS1 576 576 1 576 53 53 0 USERS 18525608 1343241851 73 35730 860 784 0 EXAMPLE 52382010 4008236424 77 4563 454 344 0 (PHYBLKRD/PHYRDS)=⼀一次Physical I/O平均讀取幾個blocks 百分之⼀一秒 OLTP:⼀一次讀取⼀一個Block DW:⼀一次讀取多個Blocks
  • 83. SMON PMON CKPTDBWR LGWR ARCHRECO Shared Pool Buffer Cache Log Buffer Large Pool Java Pool Streams pool Control file Data File Data File Data File Online Logfile Online Logfile Header Header Header Group 1 Group 2 Server Process Archived Logfile System Global Area(SGA) Instance Database Program Global Area Block Block Block Redo Entry SQL Text Execution Plan Redo Entry Redo Entry Redo Entry Redo Entry Log Seq:12 Log Seq:11 Log Seq:11Log Seq:12 Log Seq:12Log Seq:12Log Seq:12 Data Dictionary Information Data Dictionary Cache Library Cache
  • 84. OFA • 建議⾄至少4個Mount Points • /u01 - Oracle軟體安裝位置 • /u02與/u03 - Oracle Database files存放位 置。同時將controlfile與logfile member放 在/u02與/u03(Multiplexing) • /u04 - Oracle Database backup file存放位 置
  • 85. 減少I/O-Index branch branch root 1 A A1 10 J J10 17 Q Q17 2 B B2 18 R 19 S 3 C C3 7 G G7 11 K K11 4 D D4 12 L L12 21 U U21 6 F F6 13 M M13 22 V V22 8 H H8 15 O O14 24 X X24 5 E E5 14 N N14 23 W W23 9 I I9 16 P P16 20 T T20 1 rowid 2 rowid 3 rowid 4 rowid 5 rowid 6 rowid 7 rowid 8 rowid 9 rowid 10 rowid 11 rowid 12 rowid 13 rowid 14 rowid 15 rowid 16 rowid 17 rowid 18 rowid 19 rowid 20 rowid 21 rowid 22 rowid 23 rowid 24 rowid full table scan index scan
  • 86. 減少I/O-Partitioned Table 1 A A1 10 J J10 17 Q Q17 2 B B2 18 R R18 19 S S19 3 C C3 7 G G7 11 K K11 4 D D4 12 L L12 21 U U21 6 F F6 13 M M13 22 V V22 8 H H8 15 O O15 24 X X24 5 E E5 14 N N14 23 W W23 9 I I9 16 P P16 20 T T20 1 A A1 10 J J10 5 E E5 2 B B2 12 L L12 11 K K11 24 X X24 15 O O15 19 S S19 22 V V22 18 R R18 21 U U21 6 F F6 9 I I9 4 D D4 8 H H8 7 G G7 3 C C3 17 Q Q17 14 N N14 23 W W23 13 M M13 16 P P16 20 T T20 Heap Table Partitioned Table partition(p1) partition(p2) CEATE TABLE t1_pt (a NUMBER, bVARCHAR2(10), cVARCHAR2(10)) PARTITION BY RANGE(a) (PARTITION p1VALUES LESS THAN 13 PARTITION p2VALUES LESS THAN 25); CEATE TABLE t1 (a NUMBER, bVARCHAR2(10), cVARCHAR2(10)); SELECT b FROM t1 WHERE a=11; SELECT b FROM t1_pt WHERE a=11;
  • 87. Improved Block Utilization • Table Compression • Defragmentation • Shrink Segment • Table • Export/Drop/Import • Index • Rebuild
  • 88. DBA_TABLES SQL> DESC dba_tables (省略部分,僅存部份統計值相關欄位) Name Null? Type ------------------------------------- -------- ---------------------------------------- OWNER NOT NULL VARCHAR2(30) TABLE_NAME NOT NULL VARCHAR2(30) TABLESPACE_NAME VARCHAR2(30) PCT_FREE NUMBER PCT_USED NUMBER INI_TRANS NUMBER MAX_TRANS NUMBER PCT_INCREASE NUMBER NUM_ROWS NUMBER BLOCKS NUMBER EMPTY_BLOCKS NUMBER AVG_SPACE NUMBER CHAIN_CNT NUMBER AVG_ROW_LEN NUMBER AVG_SPACE_FREELIST_BLOCKS NUMBER NUM_FREELIST_BLOCKS NUMBER SAMPLE_SIZE NUMBER LAST_ANALYZED DATE COMPRESSION VARCHAR2(8) COMPRESS_FOR VARCHAR2(12) free space佔block的最⼩小⽐比率 used space佔block的最⼩小⽐比率
  • 89. Table Compression SQL> CREATE TABLE frank.t1 AS SELECT * FROM dba_objects; SQL> CREATE TABLE frank.t2 COMPRESS BASIC AS SELECT * FROM frank.t1; SQL> CREATE TABLE frank.t3 COMPRESS FOR OLTP AS SELECT * FROM frank.t1; SQL> EXECUTE DBMS_STATS.GATHER_SCHEMA_STATS(‘FRANK’); SQL> SELECT table_name,num_rows,blocks,compress_for 2 FROM dba_tables 3 WHERE table_name IN ('T1','T2',’T3’) and owner='FRANK'; TABLE_NAME NUM_ROWS BLOCKS COMPRESS_FOR COMPRESSION ---------------------------- ---------- ---------- ------------ ----------- T1 72553 1059 DISABLED T2 72553 309 BASIC ENABLED T3 72553 311 OLTP ENABLED
  • 90. Shrink Segment SQL> CREATE TABLE frank.t4 AS SELECT * FROM dba_objects; SQL> EXECUTE DBMS_STATS.GATHER_TABLE_STATS(‘FRANK’,’T4’); SQL> SELECT table_name,num_rows,blocks 2 FROM dba_tables 3 WHERE table_name=’T4’ and owner='FRANK'; TABLE_NAME NUM_ROWS BLOCKS ------------------------------ ---------- ---------- T4 72556 1059 SQL> DELETE frank.t4 WHERE MOD(object_id,2)=0; SQL> COMMIT; SQL> EXECUTE DBMS_STATS.GATHER_TABLE_STATS(‘FRANK’,’T4’); SQL> SELECT table_name,num_rows,blocks 2 FROM dba_tables 3 WHERE table_name=’T4’ and owner='FRANK'; TABLE_NAME NUM_ROWS BLOCKS ------------------------------ ---------- ---------- T4 36278 1059
  • 91. Shrink Segment SQL> ALTER TABLE frank.t4 ENABLE ROW MOVEMENT; SQL> ALTER TABLE frank.t4 SHRINK SPACE; SQL> EXECUTE DBMS_STATS.GATHER_TABLE_STATS(‘FRANK’,’T4’); SQL> SELECT table_name,num_rows,blocks 2 FROM dba_tables 3 WHERE table_name=’T4’ and owner='FRANK'; TABLE_NAME NUM_ROWS BLOCKS ------------------------------ ---------- ---------- T4 36728 530
  • 92. Buffer Cache Hit Ratio • 99% hit ratio並不代表這個I/O效能很好 • 50% hit ratio也不代表這個I/O效能很差 • Full Table Scan可能造成cache hit ratio下降 • 重復地讀取某個cached block將能增加 cache hit ratio Physical I/Os (Physical I/Os+Logical I/Os)1
  • 93. Disk System Global Memory background processes Other Applications Library System Calls Virtual File System File System Buffer Device Driver Network Interface Device Independent Interface Server Process Listener Other Processes Other Processes Other Processes Other Applications Other Applications DiskDisk Swap Disk OS Disk Tape Database datafile/controlfile/logfile Network Virtual Memory Memory Manager RAM (Physical Memory) Core Core CPU Core Core Inter-Processes Communication Management Scheduler Network Service Manager Disk Disk Physical I/O Logical I/O DirectI/O RawDevice Buffered I/O Swap I/O N etwork I/O Physical I/O Physical I/O ASMLib oracleasm.ko Run Queue Sleep Queue Wait Queue
  • 94. [oracle@oraDB ~]$ vmstat 5 10 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ r b swpd free buff cache si so bi bo in cs us sy id wa st 6 11 307356 59512 720 273220 0 0 6812 17 19 15 2 6 81 11 0 2 16 307276 60048 708 275096 147 90 6000 3069 3389 6760 77 21 0 2 0 2 16 307036 64304 724 275628 258 2 5669 2953 3389 6925 73 21 0 6 0 5 11 307140 59980 768 279852 144 47 7272 2583 3473 6932 75 23 0 2 0 2 21 307320 59916 816 281512 213 87 9289 435 3551 6818 74 22 0 4 0 2 17 307452 61292 816 282648 251 70 9385 384 3503 6838 75 22 0 3 0 7 18 307508 60284 832 284420 158 89 9531 472 3507 6813 75 23 0 3 0 1 23 307452 81036 844 275992 138 18 9290 322 3182 5623 68 18 0 15 0 2 25 307120 69868 924 287852 345 22 9119 323 2488 3121 57 8 0 36 0 1 21 306976 63144 980 295552 184 12 9148 338 3257 5824 68 18 0 13 0 Ready to Run Running Zombie Uninterruptible Sleep (I/O) Interruptible Sleep Createdfork() Termination Sleep/Blocked Running Stopped Context Switch SignalSignal
  • 95. FREE/MPSTAT/IOSTAT [oracle@oraDB ~]$ free -m total used free shared buffers cached Mem: 2006 1160 846 0 4 443 -/+ buffers/cache: 712 1294 Swap: 3999 341 3658 [oracle@oraDB ~]$ mpstat Linux 2.6.39-200.32.1.el5uek (oraDB) ⻄西元2013年01⽉月10⽇日 11時24分24秒 CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s 11時24分24秒 all 2.31 0.05 5.49 10.99 0.01 0.11 0.00 81.05 1091.41 [oracle@oraDB ~]$ iostat Linux 2.6.39-200.32.1.el5uek (oraDB) ⻄西元2013年01⽉月10⽇日 avg-cpu: %user %nice %system %iowait %steal %idle 2.30 0.05 5.60 10.99 0.00 81.06 Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn sda 43.58 27004.57 68.16 18196434499 45927293 sda1 0.00 0.00 0.00 3148 22 sda2 43.58 27004.57 68.16 18196430727 45927271 dm-0 68.68 27004.04 66.16 18196076663 44578095 dm-1 0.32 0.56 2.00 376144 1349208
  • 96. SAR[oracle@oraDB ~]$ sar -d 30 5 Linux 2.6.39-200.32.1.el5uek (oraDB) ⻄西元2013年01⽉月10⽇日 11時29分00秒 DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util 11時29分30秒 dev8-0 205.94 112732.69 312.39 548.91 3.36 16.34 4.85 99.97 11時29分30秒 dev8-1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 11時29分30秒 dev8-2 205.94 112732.69 312.39 548.91 3.36 16.34 4.85 99.97 11時29分30秒 dev252-0 258.06 112723.87 33.79 436.94 5.07 19.63 3.87 99.97 11時29分30秒 dev252-1 36.06 9.88 278.60 8.00 0.06 1.56 0.23 0.82 [oracle@oraDB ~]$ sar -b Linux 2.6.39-200.32.1.el5uek (oraDB) ⻄西元2013年01⽉月10⽇日 00時00分01秒 tps rtps wtps bread/s bwrtn/s 11時00分03秒 751.93 588.14 163.78 251441.46 3793.12 11時10分01秒 662.38 603.04 59.34 312713.48 695.41 11時20分01秒 652.31 641.17 11.15 342666.04 175.35 11時30分02秒 664.00 607.87 56.13 323480.54 1277.80 11時40分01秒 648.15 633.25 14.90 357565.08 192.16 Average: 660.39 641.64 18.75 51282.80 481.63 [oracle@oraDB ~]$ sar Linux 2.6.39-200.32.1.el5uek (oraDB) ⻄西元2013年01⽉月10⽇日 00時00分01秒 CPU %user %nice %system %iowait %steal %idle 11時00分03秒 all 62.25 0.00 19.44 11.05 0.00 7.26 11時10分01秒 all 74.46 0.00 22.64 2.09 0.00 0.82 11時20分01秒 all 47.64 0.25 6.28 45.77 0.00 0.05 11時30分02秒 all 74.09 0.00 22.45 2.62 0.00 0.84 11時40分01秒 all 67.61 0.00 18.44 13.19 0.00 0.76 Average: all 6.30 0.04 6.01 44.68 0.00 42.97
  • 97. [oracle@oraDB ~]$ top top - 10:33:21 up 7 days, 18:20, 4 users, load average: 5.01, 3.63, 1.74 Tasks: 349 total, 2 running, 347 sleeping, 0 stopped, 0 zombie Cpu(s): 33.3%us, 66.7%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 2054904k total, 1951104k used, 103800k free, 42816k buffers Swap: 4095996k total, 138628k used, 3957368k free, 437160k cached 27580 oracle 20 0 756m 45m 22m R 75.7 2.3 10:27.03 oracle 3931 oracle 20 0 283m 9128 2408 R 64.1 0.4 20:29.39 gnome-terminal 24704 oracle -2 0 733m 2828 2712 S 7.8 0.1 3:45.98 oracle 2995 root 20 0 100m 9140 3916 S 5.8 0.4 40:45.65 Xorg 25022 oracle 20 0 740m 21m 15m S 3.9 1.1 1:27.47 oracle 27028 root 20 0 0 0 0 S 1.9 0.0 0:00.38 kworker/0:0 27688 oracle 20 0 71156 5984 2272 S 1.9 0.3 0:05.12 sqlplus 27717 oracle 20 0 71156 6000 2272 S 1.9 0.3 0:05.11 sqlplus 27720 oracle 20 0 71156 5980 2272 S 1.9 0.3 0:05.03 sqlplus 27743 oracle 20 0 71156 5984 2272 S 1.9 0.3 0:05.02 sqlplus 27787 oracle 20 0 71156 6000 2272 S 1.9 0.3 0:04.91 sqlplus 27798 oracle 20 0 71156 6012 2272 S 1.9 0.3 0:04.95 sqlplus 27803 oracle 20 0 71156 6016 2272 S 1.9 0.3 0:05.01 sqlplus 27823 oracle 20 0 71156 6016 2272 S 1.9 0.3 0:04.89 sqlplus 27880 oracle 20 0 71156 6016 2272 S 1.9 0.3 0:04.91 sqlplus 27904 oracle 20 0 71156 6016 2272 S 1.9 0.3 0:04.85 sqlplus 27950 oracle 20 0 71156 6020 2272 S 1.9 0.3 0:04.34 sqlplus 27963 oracle 20 0 71156 6020 2272 S 1.9 0.3 0:04.36 sqlplus TOP
  • 98. v$osstat SQL> select osstat_id,stat_name,value from v$osstat; OSSTAT_ID STAT_NAME VALUE ---------- --------------------------------------- ---------- 0 NUM_CPUS 2 1 IDLE_TIME 62248 2 BUSY_TIME 3010 3 USER_TIME 286 4 SYS_TIME 2676 5 IOWAIT_TIME 2958 6 NICE_TIME 0 14 RSRC_MGR_CPU_WAIT_TIME 0 15 LOAD .669921875 16 NUM_CPU_CORES 2 17 NUM_CPU_SOCKETS 1 1008 PHYSICAL_MEMORY_BYTES 2104160256 1009 VM_IN_BYTES 0 1010 VM_OUT_BYTES 0 2000 TCP_SEND_SIZE_MIN 4096 2001 TCP_SEND_SIZE_DEFAULT 16384 2002 TCP_SEND_SIZE_MAX 2067936 2003 TCP_RECEIVE_SIZE_MIN 4096 2004 TCP_RECEIVE_SIZE_DEFAULT 87380 2005 TCP_RECEIVE_SIZE_MAX 2067936 2006 GLOBAL_SEND_SIZE_MAX 1048576 2007 GLOBAL_RECEIVE_SIZE_MAX 4194304
  • 99. CPU不⾜足? • loading factor=(load average)/cpu# • <=1表⽰示CPU不是瓶頸 • 1<loading factor<=2表⽰示CPU⾜足夠 • >2表⽰示CPU不⾜足 • 增加CPU • 減少同時執⾏行的processes數量
  • 100. How many CPUs I have? SQL> select value 2 from v$system_parameter 3 where name='cpu_count'; VALUE ---------------------------------- 2 SQL> select stat_name,value 2 from v$osstat 3 where stat_name like 'NUM_CPU%'; STAT_NAME VALUE ---------------------------------- --------- NUM_CPUS 2 NUM_CPU_CORES 2 NUM_CPU_SOCKETS 1
  • 101. Socket/Core/Thread Socket 0 Socket 1 Core 0 Core 1 Core 2 Core 3 Core 0 Core 1 Core 2 Core 3 CPU 0 CPU 1 CPU 2 CPU 3 CPU 4 CPU 5 CPU 6 CPU 7 CPU 8 CPU 9 CPU 10 CPU 11 CPU 12 CPU 13 CPU 14 CPU 15 Sockets:2 Cores:8 HyperThreads:16
  • 102. How many CPUs I have? [oracle@oraDB ~]$ grep -i "model name" /proc/cpuinfo model name : Intel(R) Core(TM) i7-2675QM CPU @ 2.20GHz model name : Intel(R) Core(TM) i7-2675QM CPU @ 2.20GHz [oracle@oraDB ~]$ grep -i "processor" /proc/cpuinfo processor : 0 processor : 1 [oracle@oraDB ~]$ grep -i "physical id" /proc/cpuinfo physical id : 0 physical id : 0 [oracle@oraDB ~]$ grep -i "core id" /proc/cpuinfo core id : 0 core id : 1 [oracle@oraDB ~]$ grep -i "cpu cores" /proc/cpuinfo | uniq cpu cores : 2
  • 103. SQL> show parameter cpu_count NAME TYPE VALUE ------------------------------------ ----------- ------------------------ cpu_count integer 4 SQL> select stat_name,value from v$osstat where stat_name like 'NUM_CPU%'; STAT_NAME VALUE ---------------------------------------------------------------- --------- NUM_CPUS 4 NUM_CPU_CORES 4 NUM_CPU_SOCKETS 1
  • 104. SQL> alter system set cpu_count=2; SQL> show parameter cpu_count NAME TYPE VALUE ------------------------------------ ----------- ----------------- cpu_count integer 2 SQL> select name,cpu_managed,instance_caging from v$rsrc_plan; NAME CPU INS -------------------------------- --- --- INTERNAL_PLAN OFF OFF
  • 105. SQL> alter system set resource_manager_plan=instance_caging_demo; SQL> select name,cpu_managed,instance_caging from v$rsrc_plan; NAME CPU INS -------------------------------- --- --- INSTANCE_CAGING_DEMO ON ON SQL> show parameter cpu_count NAME TYPE VALUE ------------------------------------ ----------- ------------------ cpu_count integer 2
  • 106. Background Processes [oracle@oraDB ~]$ ps aux| grep ora_ | grep _orcl USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND oracle 22569 0.0 0.8 750600 18080 ? Ss 09:56 0:00 ora_w000_orcl oracle 23400 0.0 0.9 751112 18888 ? Ss 10:06 0:00 ora_w001_orcl oracle 23405 0.0 0.9 751112 18648 ? Ss 10:06 0:00 ora_w002_orcl oracle 23513 0.4 1.5 751112 31000 ? Ds 10:07 0:00 ora_m000_orcl oracle 29276 0.0 0.9 752896 20084 ? Ss Jan08 0:24 ora_pmon_orcl oracle 29280 0.0 0.8 750604 16464 ? Ss Jan08 1:49 ora_psp0_orcl oracle 29284 9.7 0.7 750604 16068 ? Ss Jan08 5:02ora_vktm_orcl oracle 29290 0.0 0.7 750604 16336 ? Ss Jan08 0:10 ora_gen0_orcl oracle 29294 0.0 0.7 750604 16060 ? Ss Jan08 0:13 ora_diag_orcl oracle 29298 0.0 2.0 751116 41756 ? Ss Jan08 0:10 ora_dbrm_orcl oracle 29302 0.0 1.0 752140 20768 ? Ss Jan08 1:01 ora_dia0_orcl oracle 29306 0.0 2.0 750604 42072 ? Ss Jan08 0:09 ora_mman_orcl oracle 29310 0.0 4.8 758152 100212 ? Ss Jan08 0:27 ora_dbw0_orcl oracle 29314 0.0 1.3 766156 26808 ? Ss Jan08 0:33 ora_lgwr_orcl oracle 29318 0.0 1.1 750604 24388 ? Ss Jan08 1:25 ora_ckpt_orcl oracle 29322 0.0 8.4 754196 173024 ? Ss Jan08 0:18 ora_smon_orcl oracle 29326 0.0 1.5 751116 31544 ? Ss Jan08 0:03 ora_reco_orcl oracle 29330 0.0 6.1 756580 125636 ? Ss Jan08 0:48 ora_mmon_orcl oracle 29334 0.0 1.7 752356 36488 ? Ss Jan08 0:59 ora_mmnl_orcl oracle 29338 0.0 0.7 752636 16028 ? Ss Jan08 0:07 ora_d000_orcl oracle 29342 0.0 0.7 751800 14868 ? Ss Jan08 0:06 ora_s000_orcl oracle 29785 0.0 0.8 750604 17724 ? Ss Jan08 0:03 ora_qmnc_orcl oracle 29889 0.0 7.0 756312 144344 ? Ss Jan08 0:32 ora_cjq0_orcl oracle 29893 0.0 1.9 752268 40884 ? Ss Jan08 0:03 ora_q000_orcl oracle 29897 0.0 3.2 756140 65900 ? Ss Jan08 0:03 ora_q001_orcl oracle 30496 0.0 1.2 751116 25208 ? Ss Jan08 0:09 ora_smco_orcl
  • 107. [oracle@oraDB ~]$ ps aux| grep oracleorcl oracle 24862 0.0 1.4 754428 28856 ? Ss 10:22 0:01 oracleorcl (LOCAL=NO) oracle 24867 0.0 1.0 754408 20828 ? Ss 10:22 0:00 oracleorcl (LOCAL=NO) oracle 24920 0.0 1.5 760532 31064 ? Ss 10:23 0:01 oracleorcl (LOCAL=NO) oracle 24937 0.0 1.0 754368 20608 ? Ss 10:23 0:00 oracleorcl (LOCAL=NO) oracle 24941 0.0 0.7 753336 16176 ? Ss 10:23 0:00 oracleorcl (LOCAL=NO) oracle 24946 0.0 3.9 757476 80228 ? Ss 10:23 0:01 oracleorcl (LOCAL=NO) oracle 25022 3.7 1.0 758580 22540 ? Ss 10:24 1:36 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 25243 0.1 6.1 768008 126452 ? Ss 10:27 0:04 oracleorcl (LOCAL=NO) oracle 25291 0.0 1.5 758500 32720 ? Ss 10:27 0:00 oracleorcl (LOCAL=NO) oracle 25884 0.2 4.2 756544 88324 ? Ss 10:29 0:05 oracleorcl (LOCAL=NO) oracle 27580 74.9 2.2 774840 47180 ? Rs 10:51 12:50 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 27681 0.0 1.0 766648 22544 ? Ss 10:51 0:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 27714 0.0 1.0 766648 22052 ? Ss 10:51 0:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 27715 0.0 1.0 766648 22044 ? Ss 10:51 0:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 27725 0.0 1.0 766648 22060 ? Ss 10:51 0:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 27735 0.0 1.0 766648 22232 ? Ss 10:51 0:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 27745 0.0 1.0 766648 22256 ? Ss 10:51 0:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) Server Processes
  • 108. Finding Session SQL> SELECT sid,serial#,username,sql_id,event,state,wait_time 2 FROM v$session 3 WHERE paddr=(SELECT addr FROM v$process WHERE spid=27580); SID SERIAL# USERNAME SQL_ID EVENT STATE WAIT_TIME ---------- ---------- -------- ------------- ----------------- -------- --------- 140 1365 FRANK 9c1qvzrdbsd8x direct path read WAITING 0 SQL> SELECT sql_id,COUNT(*) 2 FROM v$active_session_history 3 WHERE session_id=140 AND session_serial#=1365 4 GROUP BY sql_id; SQL_ID COUNT(*) ------------- ---------- 9c1qvzrdbsd8x 12010 SQL> SELECT session_state,event,COUNT(*) 2 FROM v$active_session_history 3 WHERE session_id=140 AND session_serial#=1365 AND sql_id='9c1qvzrdbsd8x' 4 GROUP BY session_state,event; SESSION EVENT COUNT(*) ------- ------------------------------ ---------- WAITING direct path read 11382 ON CPU 654
  • 109. Asynchronous I/O Enabled? SQL> SHOW PARAMETER disk_asynch_io NAME TYPE VALUE ------------------------------------ -------- ----- disk_asynch_io boolean TRUE SQL> SHOW PARAMETER filesystemio_options NAME TYPE VALUE ------------------------------------ -------- ----- filesystemio_options string none SQL> SELECT value 2 FROM v$parameter_valid_values 3 WHERE name=‘filesystemio_options’; VALUE --------------------------------------------------------------- ASYNCH DIRECTIO SETALL NONE SQL> ALTER SYSTEM SET filesystemio_options=SETALL SCOPE=spfile; --重新啓動Instance才能讓此參數發⽣生效果
  • 110. • DISK_ASYNCH_IO • 位在RAW Device/ASM • FILESYSTEMIO_OPTIONS • 位在FileSystem How Asynchronous I/O Work?
  • 111. % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 55.43 0.863631 861 1003 pread64 --同步I/O read所使⽤用system call 37.46 0.583651 807 723 pwrite64 --同步I/O write所使⽤用system call 5.97 0.092986 30995 3 fsync 0.48 0.007534 1 10706 gettimeofday 0.19 0.003014 54 56 write 0.17 0.002644 0 5316 times 0.07 0.001015 22 46 read 0.06 0.001008 12 81 open 0.06 0.001006 11 89 6 stat64 0.06 0.001000 42 24 getdents 0.03 0.000399 6 62 mmap2 0.01 0.000115 0 308 getrusage 0.01 0.000105 9 12 12 readlink 0.00 0.000032 1 41 fcntl64 0.00 0.000009 0 79 close 0.00 0.000007 0 60 statfs 0.00 0.000005 0 38 fstatfs 0.00 0.000004 0 21 21 ioctl 0.00 0.000003 1 4 semctl 0.00 0.000001 0 4 lstat64 0.00 0.000001 1 1 semtimedop 0.00 0.000000 0 11 lseek 0.00 0.000000 0 63 access 0.00 0.000000 0 3 3 mkdir 0.00 0.000000 0 3 munmap 0.00 0.000000 0 5 _llseek 0.00 0.000000 0 5 ftruncate64 0.00 0.000000 0 2 fstat64 ------ ----------- ----------- --------- --------- ---------------- 100.00 1.558170 18769 42 total ASM<->FileSystem DISK_ASYNCH_IO=TRUE FILESYSTEMIO_OPTIONS=NONE
  • 112. % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 90.37 0.761650 575 1325 io_submit --⾮非同步I/O的system call 5.87 0.049434 3090 16 pwrite64 2.81 0.023692 76 311 pread64 0.41 0.003453 62 56 write 0.17 0.001460 0 5323 times 0.17 0.001438 0 5664 gettimeofday 0.10 0.000861 19 46 read 0.06 0.000534 67 8 munmap 0.01 0.000117 0 322 getrusage 0.00 0.000026 0 81 open 0.00 0.000024 1 41 mmap2 0.00 0.000023 0 81 close 0.00 0.000022 0 60 statfs 0.00 0.000019 0 94 6 stat64 0.00 0.000015 0 38 fstatfs 0.00 0.000012 0 254 io_getevents --⾮非同步I/O的system call 0.00 0.000010 0 41 fcntl64 0.00 0.000008 0 21 21 ioctl 0.00 0.000004 1 4 semctl 0.00 0.000003 0 11 lseek 0.00 0.000003 2 2 lstat64 0.00 0.000002 1 2 semtimedop 0.00 0.000001 0 73 access 0.00 0.000001 0 5 ftruncate64 0.00 0.000001 1 2 fstat64 0.00 0.000000 0 3 3 mkdir 0.00 0.000000 0 12 12 readlink 0.00 0.000000 0 3 fsync 0.00 0.000000 0 2 _llseek 0.00 0.000000 0 24 getdents ------ ----------- ----------- --------- --------- ---------------- 100.00 0.842813 13925 42 total ASM<->FileSystem DISK_ASYNCH_IO=TRUE FILESYSTEMIO_OPTIONS=SETALL/ASYNC
  • 113. 測量I/O效能 SQL> SHOW PARAMETER filesystemio_options NAME TYPE VALUE ------------------------------------ -------- ----- filesystemio_options string SETALL SQL> SET SERVEROUTPUT ON SQL> DECLARE 2 v_latency NUMBER; 3 v_iops NUMBER; 4 v_mbps NUMBER; 5 BEGIN 6 DBMS_RESOURCE_MANGER.CALIBRATE_IO(4,10,v_iops,v_mbps,v_latency); 7 DBMS_OUTPUT.PUT_LINE('Max IO Operations Per Second = '||v_iops); 8 DBMS_OUTPUT.PUT_LINE('Max IO MegaBytes Per Second = '||v_mbps); 9 DBMS_OUTPUT.PUT_LINE('IO Latency='||v_latency); 10 END; 11 / Max IO Operations Per Second = 65 Max IO MegaBytes Per Second = 31 IO Latency = 8
  • 114. Q&A