Oracle-Segment space management

Oracle段空间管理
segment space management
表空间中空闲段的不同管理方式
auto:即为自动管理,Oracle的建议选项。省掉了pctfree/pctused等参数的管理,因此
使得表空间的管理更加高效。
区大小由系统自动确定,由于Oracle可确定各个区的最佳大小,因此各个区的大小是变
化的。
如果需要指定固定的大小,则需要指定uniform参数:
22:55:44 sys@ORCL> create tablespace ttbs001 datafile '/oracle/oradata/lyon/ttbs001.dbf' size 5m uniform. size 1m segment space management auto;
Tablespace created.
按照默认条件建立表空间的时候,其实已经是segment space management已经auto了:
23:07:01 sys@ORCL> create tablespace ttbs001 datafile '/oracle/oradata/lyon/ttbs001.dbf' size 5m;
Tablespace created.
23:07:24 sys@ORCL> select tablespace_name, segment_space_management from dba_tablespaces;
TABLESPACE_NAME                                                                            SEGMENT_SPACE_MANA
------------------------------------------------------------------------------------------ ------------------
SYSTEM                                                                                     MANUAL
UNDOTBS1                                                                                   MANUAL
SYSAUX                                                                                     AUTO
TEMP                                                                                       MANUAL
USERS                                                                                      AUTO
EXAMPLE                                                                                    AUTO
INDX                                                                                       AUTO
LYONTBS                                                                                    AUTO
PERFSTAT                                                                                   AUTO
TTBS001                                                                                    AUTO
 
参考文章:

Automatic Segment Space Management

October 16,  2003
Don Burleson

 

Automatic segment-space management is a simpler and more efficient way of managing space within a segment. It completely eliminates any need to specify and tune the pctused, freelists, and freelist groups storage parameters for schema objects created in the tablespace. If any of these attributes are specified, they are ignored.

When you create a locally managed tablespace using the create TABLESPACE statement, the SEGMENT SPACE MANAGEMENT clause lets you specify how free and used space within a segment is to be managed.

For example, the following statement creates tablespace mytbs1 with automatic segment-space management:

CREATE TABLESPACE mytbs1
DATAFILE '/u01/oracle/data/mytbs01.dbf' SIZE 500M
EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO;

When an object such as a table or index is created using the locally managed tablespace, with automatic segment-space management enabled, there is no need to specify the pctfree or freelists.

The in-segment free/used space is tracked using bitmaps as opposed to the free lists. When you cannot use the locally managed tablespace, and therefore the automatic management space feature, you have to depend on the traditional method of managing free lists and free lists groups.

Automatic segment-space management offers the following benefits:

  • It provides administrative ease of use by avoiding the specification of storage parameters.
  • It is a good method for handling objects with varying row sizes.
  • It provides better run-time adjustment for variations in concurrent access and avoids tedious tuning methods.
  • It provides better multi-instance behavior. in terms of performance/space utilization.

However, note that this automatic feature of segment space management is available only with locally managed tablespaces and their objects. A new column called SEGMENT_SPACE_MANAGEMENT has been added to the dba_tablespaces view to indicate the segment space management mode used by a tablespace.

Use the Oracle procedure dbms_space.space_usage to provide the space usage ratio within each block in the Bitmap Managed Block (BMB) segments. It provides information regarding the number of blocks in a segment with the following range of free space.

0-25% free space within a block
25-50% free space within a block
50-75% free space within a block
75-100% free space within a block

RAC Related Advantages

The performance and manageability gains provided by the automatic segment space management feature are particularly noticeable in a Real Application Cluster environment. It eliminates the need to alter the number of freelists and freelist groups when new instances are brought online, thereby saving the downtime associated with such table reorganizations. It also avoids the tuning effort previously required for multiple instance environments.

An Oracle internal benchmark comparing the performance of automatic and manual segment space management, conducted on a two node Real Application Cluster database by inserting about 3 million rows in a table, showed that automatic segment space management provided a 35% performance gain over an optimally tuned segment (8 freelist groups, 20 freelists) using the manual mode. (For more details, refer to Oracle Metalink Note 180608.1)

Use the new dbms_space.space_usage procedure for reporting the space position in BMB segments. This procedure provides the space usage ratio within each block. It is preferred over the dbms_space.free_blocks procedure. Let us look at an example (a SQL Block) of how to get information about the blocks:

block_count.sql

DECLARE
v_unformatted_blocks number;
v_unformatted_bytes number;
v_fs1_blocks number;
v_fs1_bytes number;
v_fs2_blocks number;
v_fs2_bytes number;
v_fs3_blocks number;
v_fs3_bytes number;
v_fs4_blocks number;
v_fs4_bytes number;
v_full_blocks number;
v_full_bytes number;
BEGIN
dbms_space.space_usage ('SYSTEM', 'TEST', 'TABLE', v_unformatted_blocks, v_unformatted_bytes, v_fs1_blocks, v_fs1_bytes, v_fs2_blocks, v_fs2_bytes, v_fs3_blocks, v_fs3_bytes, v_fs4_blocks, v_fs4_bytes, v_full_blocks, v_full_bytes);
dbms_output.put_line('Unformatted Blocks = '||v_unformatted_blocks);
dbms_output.put_line('FS1 Blocks = '||v_fs1_blocks);
dbms_output.put_line('FS2 Blocks = '||v_fs2_blocks);
dbms_output.put_line('FS3 Blocks = '||v_fs3_blocks);
dbms_output.put_line('FS4 Blocks = '||v_fs4_blocks);
dbms_output.put_line('Full Blocks = '||v_full_blocks);
end;

It yields the following output:

Unformatted Blocks = 0
FS1 Blocks = 0
FS2 Blocks = 0
FS3 Blocks = 0
FS4 Blocks = 1
Full Blocks = 9

Where:
FS1 means 0-25% free space within a block
FS2 means 25-50% free space within a block
FS3 means 50-75% free space within a block
FS4 means 75-100% free space within a block

 

另外参考:

select * from dba_tables where WNER='peter'
CREATE TABLESPACE data01 DATAFILE 'D:\oracle\ora92\oradata\db\DATA01.dbf' SIZE 200M UNIFORM. SIZE 128k;

#指定区尺寸为128k,如不指定,区尺寸默认为64k

CREATE TEMPORARY TABLESPACE temp_data TEMPFILE 'D:\oracle\ora92\oradata\db\TEMP_DATA.dbf' SIZE100M

CREATE USER peter IDENTIFIED BY peter

  DEFAULT TABLESPACE data01 TEMPORARY TABLESPACE temp_data;

  grant connect,resource,dba to peter;

  

  一、建立表空间

  CREATE TABLESPACE data01

  DATAFILE '/oracle/oradata/db/DATA01.dbf' SIZE 500M

  UNIFORM. SIZE128k; #指定区尺寸为128k,如不指定,区尺寸默认为64k

  二、建立UNDO表空间

  CREATE UNDO TABLESPACE UNDOTBS02

  DATAFILE '/oracle/oradata/db/UNDOTBS02.dbf' SIZE 50M

  #注意:在OPEN状态下某些时刻只能用一个UNDO表空间,如果要用新建的表空间,必须切换到该表空间:

  ALTER SYSTEM SET undo_tablespace=UNDOTBS02;

  三、建立临时表空间

  CREATE TEMPORARY TABLESPACE temp_data

  TEMPFILE '/oracle/oradata/db/TEMP_DATA.dbf' SIZE 50M

  四、改变表空间状态

  1.使表空间脱机

  ALTER TABLESPACE game OFFLINE;

  如果是意外删除了数据文件,则必须带有RECOVER选项

  ALTER TABLESPACE game OFFLINE FOR RECOVER;

  2.使表空间联机

  ALTER TABLESPACE game ONLINE;

  3.使数据文件脱机

  ALTER DATABASE DATAFILE 3 OFFLINE;

  4.使数据文件联机

  ALTER DATABASE DATAFILE 3 ONLINE;

  5.使表空间只读

  ALTER TABLESPACE game READ ONLY;

  6.使表空间可读写

  ALTER TABLESPACE game READ WRITE;

  五、删除表空间

  DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;

  六、扩展表空间

  首先查看表空间的名字和所属文件

  select tablespace_name, file_id, file_name,

  round(bytes/(1024*1024),0) total_space

  from dba_data_files

  order by tablespace_name;

  1.增加数据文件

  ALTER TABLESPACE game

  ADD DATAFILE '/oracle/oradata/db/GAME02.dbf' SIZE 1000M;

  2.手动增加数据文件尺寸

  ALTER DATABASE DATAFILE '/oracle/oradata/db/GAME.dbf'

  RESIZE 4000M;

  3.设定数据文件自动扩展

  ALTER DATABASE DATAFILE '/oracle/oradata/db/GAME.dbf

  AUTOEXTEND ON NEXT 100M

  MAXSIZE 10000M;

  设定后查看表空间信息

  SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES FREE,

  (B.BYTES*100)/A.BYTES "% USED",(C.BYTES*100)/A.BYTES "% FREE"

  FROM SYS.SM$TS_AVAIL A,SYS.SM$TS_USED B,SYS.SM$TS_FREE C

  WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME AND A.TABLESPACE_NAME=C.TABLESPACE_NAME;

  

  -----------------------------------------------------------------------------------------------------------------------------------

  CREATE TABLESPACE命令

  

  CREATE [UNDO] TABLESPACE tablespace_name

  [DATAFILE datefile_spec1 [,datefile_spec2] ......

  [ {MININUM EXTENT integer [k|m] | BLOCKSIZE integer [k] |logging clause|FORCE LOGGING |DEFAULT{data_segment_compression } storage_clause

  |[online|offline]|[PERMANENT|TEMPORARY]|extent_manager_clause|segment_manager_clause}]

  1、undo

  说明系统将创建一个回滚表空间。

  在9i中数据库管理员可以不必管理回滚段,只有建立了undo表空间,系统就会自动管理回滚段的分配,回收的工作。当然,也可以创建一般的表空间,在上面创建回滚段.不过对于用户来说,系统管理比自己管理要好很多.如果需要自己管理,请参见回滚段管理的命令详解.

  当没有为系统指定回滚表空间时,系统将使用system系统回滚段来进行事务管理。

  2、tablespace

  指出表空间的名称。

  3、datafile datefile_spec1

  指出表空间包含什么空间文件。datefile_spec1 是形如 ['filename'][SIZEinteger [ K|M]] [REUSE][autoextend_clause]

  [autoextend_clause]切稳纾?AUTOEXTEND{OFF| ON[ NEXTinteger [ K| M] ][maxsize_clause] }

  其中filename是数据文件的全路径名,size是文件的大小,REUSE表示文件是否被重用.

  AUTOEXTEND表明是否自动扩展. OFF|ON表示自动扩展是否被关闭.NEXT表示数据文件满了以后,扩展的大小.

  maxsize_clause表示数据文件的最大大小.形如MAXSIZE{UNLIMITED| integer [ K|M] }.UNLIMITED表示无限的表空间.integer是数据文件的最大大小.

  

  

  

  4、MININUM EXTENT integer [k|m]

  指出在表空间中范围的最小值。这个参数可以减小空间碎片,保证在表空间的范围是这个数值的整数倍。

  5、BLOCKSIZE integer [k]

  这个参数可以设定一个不标准的块的大小。如果要设置这个参数,必须设置db_block_size,至少一个db_nk_block_size,并且声明的integer的值必须等于db_nk_block_size.

  注意:在临时表空间不能设置这个参数。

  6、logging clause

  这个子句声明这个表空间上所有的用户对象的日志属性(缺省是logging),包括表,索引,分区,物化视图,物化视图上的索引,分区。

  7、FORCE LOGGING

  使用这个子句指出表空间进入强制日志模式。此时,系统将记录表空间上对象的所有改变,除了临时段的改变。这个参数高于对象的nologging选项。

  注意:设置这个参数数据库不行open并且出于读写模式。而且,在临时表空间和回滚表空间中不能使用这个选项。

  8、DEFAULT storage_clause

  声明缺省的存储子句。

  9、online|offline

  改变表空间的状态。online使表空间创建后立即有效.这是缺省值.offline使表空间创建后无效.这个值,可以从dba_tablespace中得到。

  10、PERMANENT|TEMPORARY

  指出表空间的属性,是永久表空间还是临时表空间。永久表空间存放的是永久对象,临时表空间存放的是session生命期中存在的临时对象。这个参数生成的临时表空间创建后一直都是字典管理,不能使用extent management local选项。如果要创建本地管理表空间,必须使用create temporary tablespace

  注意,声明了这个参数后,不能声明block size

  11、extent_management_clause

  这是最重要的子句,说明了表空间如何管理范围。一旦你声明了这个子句,只能通过移植的方式改变这些参数。

  如果希望表空间本地管理的话,声明local选项。本地管理表空间是通过位图管理的。autoallocate说明表空间自动分配范围,用户不能指定范围的大小。只有9.0以上的版本具有这个功能。uniform说明表空间的范围的固定大小,缺省是1m。

  不能将本地管理的数据库的system表空间设置成字典管理。

  oracle公司推荐使用本地管理表空间。

  如果没有设置extent_management_clause,oracle会给他设置一个默认值。如果初始化参数compatible小于9.0.0,那么系统创建字典管理表空间。如果大于9.0.0,那么按照如下设置:

  如果没有指定default storage_clause,oracle创建一个自动分配的本地管理表空间。

  否则,如果指定了mininum extent,那么oracle判断mininum extent、initial、next是否相等,以及pctincrease是否=0.如果满足以上的条件,oracle创建一个本地管理表空间,extent size是initial.如果不满足以上条件,那么oracle将创建一个自动分配的本地管理表空间。

  如果没有指定mininum extent。initial、那么oracle判断next是否相等,以及pctincrease是否=0。如果满足oracle创建一个本地管理表空间并指定uniform。否则oracle将创建一个自动分配的本地管理表空间。

  注意:本地管理表空间只能存储永久对象。如果你声明了local,将不能声明default storage_clause,mininum extent、temporary.

  12、segment_management_clause  

  建立表空间

  CREATE TABLESPACE data01

  DATAFILE '/oracle/oradata/db/DATA01.dbf' SIZE 500M

  UNIFORM. SIZE128k; #指定区尺寸为128k,如不指定,区尺寸默认为64k

  删除表空间

  DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12932950/viewspace-611345/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/12932950/viewspace-611345/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值