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⼩小
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
問題在哪裡?
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
問題在哪裡?
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數
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
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
48.
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"))
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
59.
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
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;
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
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
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
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
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
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;
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
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
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才能讓此參數發⽣生效果
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