表空間、段、區、塊的相關總結

lusklusklusk發表於2017-09-15
總結
1、建立表空間後,並不會對錶空間中的segments馬上進行初始分配多個extents的空間,只有當真正的資料寫入時才會按區的分配方式慢慢產生一個個extents,當資料檔案沒有可用空間了才會使用autoextend增長,當資料檔案沒有autoextend時則資料檔案不再增長

2、段的ASSM方式下,建表時pctfree預設是10,putused預設是0即這個引數無效(個人理解的是不管PCTUSED是多少都是由ASSM自己來管理塊是否可以繼續insert重用,以此理解為這個引數無效),段的手工管理方式下,pctfree預設是10,putused預設是40
個人的實驗經歷:ASSM時pctused為0,固定表對應的資料檔案的大小,往表中不停插入資料後dba_segments.bytes增大,再刪除剛剛插入的資料後dba_segments.bytes不變,沒有因為刪除後變小,按理解這時候應該不再可以插入了因為PCTUSED不再有效,就算剛剛執行了刪除操作空出了一些塊,但是實驗發現可以繼續插入,所以個人認為不管PCTUSED是多少都是由ASSM自己來管理塊是否可以繼續insert重用,以此理解為這個引數無效。當然再插入後dba_segments.bytes依然不變,除非手工降低高水位線。

3、預設情況下,表空間的管理方式是local即本地管理(針對區而言,對立的就是字典管理),段的管理方式是auto(針對塊而已,對立的就是manual),區的分配方式autoallocate(即表空間欄位allocation_type顯示system,對立的就是uniform)

4、create tablespace test6 datafile size 30M autoextend on next 10M uniform size 3M說明資料檔案的自增長和區的分配方式沒有關係(以前一直以為只要加了uniform欄位就認為資料檔案會按uniform的大小進行自增長)

5、一般表空間最多含有1024個資料檔案,8kb塊時,每個資料檔案最大32G,16kb塊時64G,32kb塊時128G,64kb塊時256G,4kb塊時16G

6、非ASM環境下建立表空間一定要註明資料檔案和大小,否則會報如下錯誤
ORA-17610: file '/u01/app/oracle/oradata/testdb/test1.dbf' does not exist and no size specified

7、11g預設初始分配為64K,之後每次都是一次性分配1M的大小,即autoallocate時表storeage的INITIAL為64K,NEXT為1M

8、如果uniform size 5M,則初始分配為5M,之後每次都是一次性分配5M大小,即表storeage的INITIAL為5M,NEXT為5M

9、區分配方式而言,TEMP表空間不能為AUTOALLOCATE,UNDO表空間不能UNIFORM

10、不指定AUTOALLOCATE或UNIFORM,則預設值臨時表空間為UNIFORM,所有其他型別表空間為AUTOALLOCATE

11、資料檔案自動擴充套件autoextend on不加next表示每次增加1個塊





DBA_DATA_FILES.INCREMENT_BY:Number of Oracle blocks used as autoextension increment
資料檔案自動擴充套件autoextend on不加next表示每次增加1個塊

當使用extent management local uniform size 2M時,
select INITIAL_EXTENT,NEXT_EXTENT from dba_tablespaces;兩者值一致


實驗驗證
create tablespace test1 datafile '/db/oracle/oradata/TESTDB/test1.dbf' size 10M autoextend on next 1M maxsize 1G extent management local uniform size 6M segment space management auto;
create tablespace test2 datafile '/db/oracle/oradata/TESTDB/test2.dbf' size 10M autoextend on next 1M maxsize 1G extent management local uniform size 7M segment space management manual;
create tablespace test3 datafile '/db/oracle/oradata/TESTDB/test3.dbf' size 10M autoextend on next 1M  maxsize 1G extent management local autoallocate segment space management manual;
create tablespace test4 datafile '/db/oracle/oradata/TESTDB/test4.dbf' size 10M autoextend on next 1M maxsize 1G extent management local autoallocate segment space management auto;

create table test1 (hid number) tablespace test1;
create table test2 (hid number) tablespace test2;
create table test3 (hid number) tablespace test3;
create table test4 (hid number) tablespace test4;

test1
INITIAL    6M
NEXT       6M
PCTUSED    0
PCTFREE    10

test2
INITIAL    7M
NEXT       7M
PCTUSED    40
PCTFREE    10

test3
INITIAL    64K
NEXT       1M
PCTUSED    40
PCTFREE    10

test4
INITIAL    64K
NEXT       1M
PCTUSED    0
PCTFREE    10


select tablespace_name,INITIAL_EXTENT,NEXT_EXTENT,MAX_SIZE,ALLOCATION_TYPE,extent_management,SEGMENT_SPACE_MANAGEMENT from dba_tablespaces where tablespace_name like 'TEST%';
TABLESPACE_NAME INITIAL_EXTENT NEXT_EXTENT MAX_SIZE ALLOCATION_TYPE EXTENT_MANAGEMENT SEGMENT_SPACE_MANAGEMENT
TEST1 6291456 6291456 2147483645 UNIFORM LOCAL AUTO
TEST2 7340032 7340032 2147483645 UNIFORM LOCAL MANUAL
TEST3 65536 2147483645 SYSTEM LOCAL MANUAL
TEST4 65536 2147483645 SYSTEM LOCAL AUTO


select segment_name,segment_subtype from dba_segments where segment_name like 'TEST%' order by 1
SEGMENT_NAME SEGMENT_SUBTYPE
TEST1 ASSM
TEST2 MSSM
TEST3 MSSM
TEST4 ASSM




extent_management_clause 
The extent_management_clause lets you specify how the extents of the tablespace will be managed.
AUTOALLOCATE specifies that the tablespace is system managed. Users cannot specify an extent size. You cannot specify AUTOALLOCATE for a temporary tablespace.
UNIFORM specifies that the tablespace is managed with uniform extents of SIZE bytes.The default SIZE is 1 megabyte. All extents of temporary tablespaces are of uniform size, so this keyword is optional for a temporary tablespace. However, you must specify UNIFORM in order to specify SIZE. You cannot specify UNIFORM for an undo tablespace.
If you do not specify AUTOALLOCATE or UNIFORM, then the default is UNIFORM for temporary tablespaces and AUTOALLOCATE for all other types of tablespaces.
If you do not specify the extent_management_clause, then Oracle Database interprets the MINIMUM EXTENT clause and the DEFAULT storage_clause to determine extent management.
The DICTIONARY keyword is deprecated. It is still supported for backward compatibility. However, Oracle recommends that you create locally managed tablespaces. Locally managed tablespaces are much more efficiently managed than dictionary-managed tablespaces. The creation of new dictionary-managed tablespaces is scheduled for desupport.
extent_management_clause可以指定如何管理表空間的extents。
AUTOALLOCATE指定表空間是系統管理的。使用者無法指定extent大小。您不能為臨時表空間指定AUTOALLOCATE。
UNIFORM指定表空間以SIZE位元組的uniform extents進行管理。預設SIZE為1兆位元組。臨時表空間的所有extents 都是uniform size,所以這個關鍵字對於臨時表空間是可選的。但是,為了指定SIZE,您必須指定UNIFORM。您不能為UNDO表空間指定UNIFORM。
如果不指定AUTOALLOCATE或UNIFORM,則預設值臨時表空間為UNIFORM,所有其他型別表空間為AUTOALLOCATE。
如果沒有指定extent_management_clause,則Oracle資料庫會解釋MINIMUM EXTENT子句和DEFAULT storage_clause以確定擴充套件級別管理。
不推薦使用DICTIONARY關鍵字。它仍然支援向後相容性。但是,Oracle建議您建立本地管理的表空間。本地管理的表空間比字典管理的表空間更有效地進行管理。新的字典管理的表空間的建立計劃不受支援。


segment_management_clause 
The segment_management_clause is relevant only for permanent, locally managed tablespaces 
Specify AUTO if you want the database to manage the free space of segments in the tablespace using a bitmap. If you specify AUTO, then the database ignores any specification for PCTUSED, FREELIST, and FREELIST GROUPS in subsequent storage specifications for objects in this tablespace. This setting is called automatic segment-space management and is the default.
Specify MANUAL if you want the database to manage the free space of segments in the tablespace using free lists. Oracle strongly recommends that you do not use this setting and that you create tablespaces with automatic segment-space management.
If you specify AUTO segment management, then: 
If you set extent management to LOCAL UNIFORM, then you must ensure that each extent contains at least 5 database blocks.
If you set extent management to LOCAL AUTOALLOCATE, and if the database block size is 16K or greater, then Oracle manages segment space by creating extents with a minimum size of 5 blocks rounded up to 64K
segment_management_clause僅適用於永久的本地管理表空間
如果希望資料庫使用點陣圖管理表空間中的段的可用空間,請指定AUTO。 如果指定AUTO,則資料庫將在此表空間中的物件的後續儲存規範中忽略PCTUSED,FREELIST和FREELIST GROUPS的任何規範。 此設定稱為自動段空間管理,是預設設定。
如果希望資料庫使用免費列表管理表空間中的段的可用空間,請指定MANUAL。 Oracle強烈建議您不要使用此設定,並建立具有自動分段空間管理的表空間。
如果指定AUTO段管理,則:
如果將區域管理設定為LOCAL UNIFORM,則必須確保每個區段至少包含5個資料庫塊。
如果將範圍管理設定為LOCAL AUTOALLOCATE,並且如果資料庫塊大小為16K或更大,則Oracle將透過建立擴充套件資料塊來管理段空間,最小大小為5個塊,最大為64K



storage_clause

INITIAL 
Specify the size of the first extent of the object. Oracle allocates space for this extent when you create the schema object. Refer to size_clause for information on that clause.
In locally managed tablespaces, Oracle uses the value of INITIAL, in conjunction with the type of local management—AUTOALLOCATE or UNIFORM—and the values of MINEXTENTS, NEXT and PCTINCREASE, to determine the initial size of the segment.
With AUTOALLOCATE extent management, Oracle uses the INITIAL setting to optimize the number of extents allocated. Extents of 64K, 1M, 8M, and 64M can be allocated. During segment creation, the system chooses the greatest of these four sizes that is equal to or smaller than INITIAL, and allocates as many extents of that size as are needed to reach the INITIAL setting. For example, if you set INITIAL to 4M, then the database creates four 1M extents.
For UNIFORM extent management, the number of extents is determined from initial segment size and the uniform extent size specified at tablespace creation time. For example, in a uniform locally managed tablespace with 1M extents, if you specify an INITIAL value of 5M, then Oracle creates five 1M extents.
Consider this comparison: With AUTOALLOCATE, if you set INITAL to 72K, then the initial segment size will be 128K (greater than INITIAL). The database cannot allocate an extent smaller than 64K, so it must allocate two 64K extents. If you set INITIAL to 72K with a UNIFORM extent size of 24K, then the database will allocate three 24K extents to equal 72K.
In dictionary managed tablespaces, the default initial extent size is 5 blocks, and all subsequent extents are rounded to 5 blocks. If MINIMUM EXTENT was specified at tablespace creation time, then the extent sizes are rounded to the value of MINIMUM EXTENT.
指定物件的第一個範圍的大小。當您建立模式物件時,Oracle會為此擴充套件區分配空間。有關該條款的資訊,請參閱size_clause。
在本地管理的表空間中,Oracle使用INITIAL的值與本地管理的型別AUTOALLOCATE或UNIFORM以及MINEXTENTS,NEXT和PCTINCREASE的值來確定段的初始大小。
使用AUTOALLOCATE擴充套件管理,Oracle使用INITIAL設定來最佳化分配的擴充套件數量。可以分配64K,1M,8M和64M的範圍。在段建立期間,系統選擇這四個大小中最大的等於或小於INITIAL,並分配與達到INITIAL設定所需的那樣大小的區段。例如,如果將INITIAL設定為4M,則資料庫將建立四個1M範圍。
對於UNIFORM範圍管理,擴充套件區的數量由初始段大小和在表空間建立時指定的統一區段大小確定。例如,在具有1M範圍的統一本地管理的表空間中,如果指定INITIAL值為5M,則Oracle將建立5個1M範圍。
— — 除了紅色字型外,以下這些描述inital的內容都是垃圾,還會誤導人,見個人下面test5、test6的實驗驗證
考慮這個比較:使用AUTOALLOCATE,如果將INITAL設定為72K,則初始段大小將為128K(大於INITIAL)。資料庫不能分配小於64K的盤區,所以它必須分配兩個64K盤區。如果將INITIAL設定為72K,UNIFORM擴充套件大小為24K,那麼資料庫將分配三個24K的區域,等於72K。
在字典管理的表空間中,預設的初始擴充套件區大小為5個塊,所有後續擴充套件區四捨五入為5個塊。如果在表空間建立時指定了MINIMUM EXTENT,則擴充套件區大小將舍入為MINIMUM EXTENT的值。
create tablespace test5 datafile '/db/oracle/oradata/TESTDB/test5.dbf' size 10M autoextend on next 1M maxsize 1G extent management local uniform size 72K segment space management auto;
create tablespace test6 datafile '/db/oracle/oradata/TESTDB/test6.dbf' size 10M autoextend on next 1M maxsize 1G extent management local uniform size 48K segment space management auto;
create table test5 (hid number) tablespace test5;
create table test6 (hid number) tablespace test6;
test5
INITIAL    72K
NEXT       72K

test6
INITIAL    48K
NEXT       48K


NEXT 
Specify in bytes the size of the next extent to be allocated to the object. Refer to size_clause for information on that clause.
In locally managed tablespaces, any user-supplied value for NEXT is ignored and the size of NEXT is determined by Oracle if the tablespace is set for autoallocate extent management. In UNIFORM tablespaces, the size of NEXT is the uniform extent size specified at tablespace creation time.
In dictionary-managed tablespaces, the default value is the size of 5 data blocks. The minimum value is the size of 1 data block. The maximum value depends on your operating system. Oracle rounds values up to the next multiple of the data block size for values less than 5 data blocks. For values greater than 5 data blocks, Oracle rounds up to a value that minimizes fragmentation.
以位元組指定要分配給物件的下一個區段的大小。 有關該條款的資訊,請參閱size_clause。
在本地管理的表空間中,如果將表空間設定為自動分配盤區管理,則NEXT的任何使用者提供的值將被忽略,並且由Oracle確定NEXT的大小。 在UNIFORM表空間中,NEXT的大小是在表空間建立時指定的uniform extent size大小。
在字典管理的表空間中,預設值是5個資料塊的大小。 最小值是1個資料塊的大小。 最大值取決於您的作業系統。 Oracle將數值舍入到資料塊大小的下一個倍數,數值小於5個資料塊。 對於大於5個資料塊的值,Oracle將舍入到最小化碎片的值。



CREATE TABLE TEST6
(
  HID  NUMBER
)
TABLESPACE TEST6
RESULT_CACHE (MODE DEFAULT)
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          48K
            NEXT             48K
            MAXSIZE          UNLIMITED
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
            FLASH_CACHE      DEFAULT
            CELL_FLASH_CACHE DEFAULT
           )
LOGGING 
NOCOMPRESS 
NOCACHE
NOPARALLEL
MONITORING;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30126024/viewspace-2145044/,如需轉載,請註明出處,否則將追究法律責任。

相關文章