段空间管理:
手动段空间管理manual segment space management (MSSM).
MSSM是Oracle的遗留实现,原先需要对控制空间分配和提供高并发性的参数数不胜数,并且需要对这些参数进行细致地调整,而大家并不希望继续这么做。当使用MSSM表空间时,
oracle会使用自由列表(FREELIST)来维护他们的HWM之下的块。
自动段空间管理automatic segment space management (ASSM).
ASSM在Oracle 9i才首次被引入。你只需要控制与空间使用相关的一个参数:PCTFREE。
FREELIST:
一个对象可以有多个FREELIST。使用块时,可能会根据需要把块放在FREELIST上或者从FREELIST上去除。只有位于HWM以下的对象块才会出现在FREELIST中,只有当FREELIST为空才会使用HWM之上的块,此时Oracle会推进HWM,并把这些块增加到FREELIST中。如果预料到会有很多并发用户在一个对象上执行大量的INSERT或UPDATE,就可以去配置多个FREELIST,这对性能提升很有好处(但是可能要以额外的存储空间为代价)。
--使用5个并发会话进行疯狂插入查看statspack
--实验环境准备
EODA@PROD1> create tablespace mssm datafile '/u01/app/oracle/oradata/PROD1/mssm.dbf' size 1m autoextend on next 1m segment space management manual;
Tablespace created.
EODA@PROD1> create tablespace assm datafile '/u01/app/oracle/oradata/PROD1/assm.dbf' size 1m autoextend on next 1m segment space management auto;
Tablespace created.
EODA@PROD1> drop table t purge;
Table dropped.
EODA@PROD1> set echo off
--EODA@PROD1> !echo begin for i in 1 .. 100000 loop insert into t values \(i,\'x\'\)\; end loop\; commit\; end\; > test.sql
EODA@PROD1> !echo / >> test.sql
EODA@PROD1> !echo exit >> test.sql
EODA@PROD1> !echo \#\!/bin/bash > test.sh
EODA@PROD1> !echo sqlplus eoda/foo @test.sql \&>> test.sh
EODA@PROD1> !echo sqlplus eoda/foo @test.sql \&>> test.sh
EODA@PROD1> !echo sqlplus eoda/foo @test.sql \&>> test.sh
EODA@PROD1> !echo sqlplus eoda/foo @test.sql \&>> test.sh
EODA@PROD1> !echo sqlplus eoda/foo @test.sql \&>> test.sh
EODA@PROD1> !echo wait >> test.sh
EODA@PROD1> set echo on
EODA@PROD1> !chmod 755 test.sh
--第一个实验assm
EODA@PROD1> create table t ( x int, y char(50) ) tablespace assm;
Table created.
EODA@PROD1> exec statspack.snap
PL/SQL procedure successfully completed.
EODA@PROD1> !/bin/bash ./test.sh
SQL*Plus: Release 11.2.0.3.0 Production on Sat Oct 22 18:29:53 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
SQL*Plus: Release 11.2.0.3.0 Production on Sat Oct 22 18:29:53 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
SQL*Plus: Release 11.2.0.3.0 Production on Sat Oct 22 18:29:53 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
SQL*Plus: Release 11.2.0.3.0 Production on Sat Oct 22 18:29:53 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL*Plus: Release 11.2.0.3.0 Production on Sat Oct 22 18:29:53 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
PL/SQL procedure successfully completed.
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
PL/SQL procedure successfully completed.
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
PL/SQL procedure successfully completed.
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
PL/SQL procedure successfully completed.
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
PL/SQL procedure successfully completed.
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
EODA@PROD1> exec statspack.snap
PL/SQL procedure successfully completed.
EODA@PROD1> @?/rdbms/admin/spreport
Current Instance
~~~~~~~~~~~~~~~~
DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
2133791648 PROD1 1 PROD1
SP2-0311: string expected but not found
Instances in this Statspack schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Id Inst Num DB Name Instance Host
----------- -------- ------------ ------------ ------------
2133791648 1 PROD1 PROD1 ocm1
Using 2133791648 for database Id
Using 1 for instance number
Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing without
specifying a number lists all completed snapshots.
Listing all Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level Comment
------------ ------------ --------- ----------------- ----- --------------------
PROD1 PROD1 1 22 Oct 2016 18:24 5
2 22 Oct 2016 18:29 5
3 22 Oct 2016 18:32 5
4 22 Oct 2016 18:41 5
5 22 Oct 2016 18:42 5
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 4
Begin Snapshot Id specified: 4
Enter value for end_snap: 5
End Snapshot Id specified: 5
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is sp_4_5. To use this name,
press to continue, otherwise enter an alternative.
ASSM结果:
Snapshot Snap Id Snap Time Sessions Curs/Sess Comment
~~~~~~~~ ---------- ------------------ -------- --------- ------------------
Begin Snap: 4 22-Oct-16 18:41:20 29 1.1
End Snap: 5 22-Oct-16 18:42:50 27 1.2
Elapsed: 1.50 (mins) Av Act Sess: 2.1
DB time: 3.09 (mins) DB CPU: 0.23 (mins)
Cache Sizes Begin End
~~~~~~~~~~~ ---------- ----------
Buffer Cache: 292M Std Block Size: 8K
Shared Pool: 292M Log Buffer: 832K
Load Profile Per Second Per Transaction Per Exec Per Call
~~~~~~~~~~~~ ------------------ ----------------- ----------- -----------
DB time(s): 2.1 20.6 0.00 1.29
DB CPU(s): 0.2 1.5 0.00 0.09
Redo size: 1,704,508.5 17,045,085.3
Logical reads: 6,275.6 62,755.8
Block changes: 11,448.3 114,482.8
Physical reads: 0.0 0.0
Physical writes: 61.0 609.9
User calls: 1.6 16.0
Parses: 2.4 23.7
Hard parses: 0.0 0.4
W/A MB processed: 0.2 2.4
Logons: 0.1 0.9
Executes: 5,562.6 55,625.8
Rollbacks: 0.0 0.0
Transactions: 0.1
Instance Efficiency Indicators
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Buffer Nowait %: 99.97 Redo NoWait %: 99.99
Buffer Hit %: 100.00 Optimal W/A Exec %: 100.00
Library Hit %: 100.00 Soft Parse %: 98.12
Execute to Parse %: 99.96 Latch Hit %: 100.00
Parse CPU to Parse Elapsd %: 150.00 % Non-Parse CPU: 99.57
Shared Pool Statistics Begin End
------ ------
Memory Usage %: 72.65 72.64
% SQL with executions>1: 42.04 42.08
% Memory for SQL w/exec>1: 39.33 39.35
Top 5 Timed Events Avg %Total
~~~~~~~~~~~~~~~~~~ wait Call
Event Waits Time (s) (ms) Time
----------------------------------------- ------------ ----------- ------ ------
Log archive I/O 300 55 184 20.5
log buffer space 483 43 89 15.9
enq: TX - contention 37 36 967 13.3
log file parallel write 310 21 69 7.9
cursor: pin S 8 17 2074 6.2
-------------------------------------------------------------
--第二个实验 mssm freelists 5
EODA@PROD1> drop table t purge;
Table dropped.
EODA@PROD1> create table t ( x int, y char(50) ) storage( freelists 5 ) tablespace mssm;
Table created.
EODA@PROD1> exec statspack.snap
PL/SQL procedure successfully completed.
EODA@PROD1> !/bin/bash ./test.sh
EODA@PROD1> exec statspack.snap
PL/SQL procedure successfully completed.
EODA@PROD1> @?/rdbms/admin/spreport
MSSM FRSSLIST 5结果:
Snapshot Snap Id Snap Time Sessions Curs/Sess Comment
~~~~~~~~ ---------- ------------------ -------- --------- ------------------
Begin Snap: 6 22-Oct-16 18:46:45 30 1.1
End Snap: 7 22-Oct-16 18:48:52 30 1.1
Elapsed: 2.12 (mins) Av Act Sess: 2.1
DB time: 4.35 (mins) DB CPU: 0.24 (mins)
Cache Sizes Begin End
~~~~~~~~~~~ ---------- ----------
Buffer Cache: 292M Std Block Size: 8K
Shared Pool: 292M Log Buffer: 832K
Load Profile Per Second Per Transaction Per Exec Per Call
~~~~~~~~~~~~ ------------------ ----------------- ----------- -----------
DB time(s): 2.1 17.4 0.00 1.70
DB CPU(s): 0.1 0.9 0.00 0.09
Redo size: 1,207,759.2 10,225,694.7
Logical reads: 4,494.2 38,050.9
Block changes: 8,107.4 68,642.5
Physical reads: 0.2 1.6
Physical writes: 55.8 472.3
User calls: 1.2 10.3
Parses: 3.2 27.5
Hard parses: 0.0 0.3
W/A MB processed: 0.2 1.5
Logons: 0.1 0.8
Executes: 3,952.9 33,467.5
Rollbacks: 0.0 0.0
Transactions: 0.1
Instance Efficiency Indicators
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Buffer Nowait %: 99.90 Redo NoWait %: 100.00
Buffer Hit %: 100.00 Optimal W/A Exec %: 100.00
Library Hit %: 100.00 Soft Parse %: 99.03
Execute to Parse %: 99.92 Latch Hit %: 100.00
Parse CPU to Parse Elapsd %: 16.67 % Non-Parse CPU: 99.65
Shared Pool Statistics Begin End
------ ------
Memory Usage %: 72.95 72.95
% SQL with executions>1: 46.60 46.60
% Memory for SQL w/exec>1: 45.50 45.50
Top 5 Timed Events Avg %Total
~~~~~~~~~~~~~~~~~~ wait Call
Event Waits Time (s) (ms) Time
----------------------------------------- ------------ ----------- ------ ------
Log archive I/O 294 55 185 15.4
log buffer space 508 54 107 15.4
enq: HW - contention 534 49 91 13.8
enq: TX - contention 96 49 507 13.8
buffer busy waits 389 38 96 10.6 --看这里!
--第三个实验mssm
EODA@PROD1> create table t ( x int, y char(50) ) tablespace mssm;
MSSM实验结果:
Snapshot Snap Id Snap Time Sessions Curs/Sess Comment
~~~~~~~~ ---------- ------------------ -------- --------- ------------------
Begin Snap: 8 22-Oct-16 18:57:14 28 1.2
End Snap: 9 22-Oct-16 18:59:00 30 1.1
Elapsed: 1.77 (mins) Av Act Sess: 1.6
DB time: 2.86 (mins) DB CPU: 0.19 (mins)
Cache Sizes Begin End
~~~~~~~~~~~ ---------- ----------
Buffer Cache: 292M Std Block Size: 8K
Shared Pool: 292M Log Buffer: 832K
Load Profile Per Second Per Transaction Per Exec Per Call
~~~~~~~~~~~~ ------------------ ----------------- ----------- -----------
DB time(s): 1.6 11.5 0.00 1.11
DB CPU(s): 0.1 0.8 0.00 0.07
Redo size: 1,442,344.9 10,192,570.9
Logical reads: 5,049.7 35,684.7
Block changes: 9,680.2 68,406.5
Physical reads: 0.4 2.9
Physical writes: 41.4 292.8
User calls: 1.5 10.3
Parses: 2.4 16.7
Hard parses: 0.1 0.3
W/A MB processed: 0.2 1.5
Logons: 0.1 0.9
Executes: 4,722.2 33,370.4
Rollbacks: 0.0 0.0
Transactions: 0.1
Instance Efficiency Indicators
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Buffer Nowait %: 99.79 Redo NoWait %: 99.99
Buffer Hit %: 99.99 Optimal W/A Exec %: 100.00
Library Hit %: 100.00 Soft Parse %: 98.01
Execute to Parse %: 99.95 Latch Hit %: 100.00
Parse CPU to Parse Elapsd %: 80.00 % Non-Parse CPU: 99.64
Shared Pool Statistics Begin End
------ ------
Memory Usage %: 73.07 73.10
% SQL with executions>1: 46.42 46.42
% Memory for SQL w/exec>1: 45.37 45.38
Top 5 Timed Events Avg %Total
~~~~~~~~~~~~~~~~~~ wait Call
Event Waits Time (s) (ms) Time
----------------------------------------- ------------ ----------- ------ ------
buffer busy waits 854 108 127 45.4 --看这里!
Log archive I/O 300 23 75 9.5
log buffer space 218 22 102 9.3
log file parallel write 254 21 84 8.9
db file async I/O submit 6 12 1954 4.9
总体分析这三个实验情况来看,重点关注事件中的
buffer busy waits ,在MSSM环境中总共等待了108秒,平均每个会话22秒左右,导致这些等待的主要原因就是FREELIST配置不够无法来应付这种并发活动。而在MSSM(FREELIST 5)环境中,等待时间降低到了38秒,平均每个会话8秒左右大幅下降。在ASSM环境中Top5已经查看不到这个等待事件,ASMM就像是为段配置了最合适的FREELIST一样,让我们无需手动去计算。
在某些情况下与MSSM相比,ASSM会额外使用一些空间,因为他视图讲插入分布到多个块上,不过大多数情况下额外使用的空间量都是微不足道的,减少并发性能问题远比这点损失更重要。但在
数据仓库这类不重视并发性的环境下ASSM并不一定能够获益。
--参考来源《Oracle编程艺术深入理解 数据库
体系结构(第三版)》