学习笔记九(storage structure and relationship)

 storage structure and relationship [@more@]

--9 storage structure and relationship
---types of segments
1.table:(常规表)表的数据是随机存放的,建一个表时如果不做特别声明则默认为常

规表
2.partition table:数据量很大的表从物理上分成几个小表,即几个分区,每个分区

对应一个段,物理上可以认为是几张小表每个分区可以放在不同的段上,从逻辑上他们

是一个完整的table,作用是为了优化大数据量的table
Scalability and availability are major concerns when there is a table in a

database with high concurrent usage. In such cases, data within a table may

be stored in several partitions, each of which resides in a different

tablespace. The Oracle server currently supports partitioning by a range of

key values, by a hashing algorithm, and by a list of values. If a table is

partitioned, each partition is a segment, and the storage parameters can be

specified to control them independently. Use of this type of segment

requires the partitioning option within the Oracle9i Enterprise Edition.

3.cluster :把几张表根据他们共用的栏位组合在一起同一个段里面
4.index
5.index-organized table(索引组织表)表里面的数据是按照index key值得的大小以

升序or 降序顺序进行物理数据的排列,类似sql server的群集索引
6.index partition :索引数据分区类似table partition
7.undo segment:orale数据库运行中数据改变时存放old value,用来实现读一致性,

rollback trasaction or recovery
8.temporary segment 用来支持sort
9.LOB segment:在创建表时可以在表里面放置大的数据对象比如blob 数据类型or

clob数据类型的文字or 图像,在oracle里面这些大的数据类型不是直接放在表内部,

而是用一个单独的单独的独立的数据段来存放,也就是说在表里面虽然定义了图像栏位

在这里,但是在表里面只是记录了指针,这个指针指到另外一个段,另外一个段独立存

放了我们的图像or 文本,这类段在系统里面称lob段,这个段是附属于某表的一部分而

来的
10.nested table:(牵套表),从oracle 8i开始引入了对对象的支持,对象的支持有一

种是牵套表,也就是在这个表的某个栏位不是真正意义上的栏位而是嵌入了一张表。
11.bootstrap segment:用来帮助我们初始化我们的instance的,是oracle在创建数据

库时自动产生的,在oracle启动过程中加以使用,启动后自动消失,对他而言不需要维

护,也不需要管理。
/
---storage clause precedence
sql>create table yh (id int) tablespace users storage (initial 100k next

100k)
oracle里对存储参数有三个等级
A.oracle default级:例如在创建tablespace or segment 时不指定存储参数则此时

oracle 会采用oracle default存储参数大小进行空间分配,在oracle里面default 的

存储参数大小(即初始分区的大小)为当前数据库的5个block size的大小
B.tablespace
C.segment
优先级:从oracle default---tablespace----segment的优先级依次递增,也就是创建

数据对象时制定的存储参数会覆盖表空间所指定的存储参数,同时表空间指定的存储参

数会覆盖oracle default的存储参数
exp
sql>create tabelspace yh datafile 'd:oracleyh.dbf' size 10M;没指定存储参数
SQL>create table yh (id int) tablespace yh
在enterprise manager里面看到table yh的存储参数采用了oracle default (9i里面

oracle default 初始参数大小为64k)
需要注意的是,在创建数据对象的时候不管怎样他的初始参数大小一定会分配的。(所

以在你建完数据对象后select 其空间大小虽然没有往对象里面放资料可是已经有了多

少k的空间被占用了就这个道理)
/
---extent allocation and deallocation

1。An extent is a chunk of space used by a segment within a tablespace.
An extent is allocated when the segment is:
-Created 创建对象的时候初始空间大小一定会分配的
-Extended 当初始分配完了后需要申请空间的扩展
-Altered  系统允许强制给当前对象一个空间则采用alter,在强制的给段申请空间分

配的时候你所指定空间一定来自于我们段原有的表空间下的数据文件,因为段可以跨数

据文件但是不可以跨表空间。
exp
sql>alter table yh allocate extent(size 1M datafile 'd:oracleyh.dbf');
error ora-03284数据文件d:oracleyh.dbf不是表空间users的成员

sql>c /yh/users/
sql>run
就可以了
2。An extent is deallocated when the segment is:
-Dropped
-Altered
-Truncated
sql>drop table yh;
sql>truncate table yh;
sql>alter table yh deallocate unused;(释放掉没有用到的空间)
/
---used and free extents
Used and Free Extents
When a tablespace is created, the data files in the tablespace contains a

header, which is the first block or blocks in the file.
As segments are created, they are allocated space from the free extents in a

tablespace. Contiguous space used by a segment is referred to as a used

extent. When segments release space, the extents that are released are added

to the pool of free extents available in the tablespace.
/
---database block
1.minimum unit of I/O(Databse BLOCK是oracle读写的最小单位,假定block里面放

了100行数据,在查找的时候在这个块里面只有一行数据符合我们的要求,这个时候

oracle不是只读一行到内存里面而是将整个这个块读到内存里面,意思就是说block是

最小I/O单位,所以ORACLE里面使用内存也是以相应块大小为单位)

SQL>create tablespace yh1 datafile 'd:oracleyh1.dbf' size 10M blocksize

8k;
error ora-29339 表空间块大小8192与配置的块大小不匹配
因为:
sql>show parameter db;
可以看见db_block_size等于4096
对应的db_cache_size 也是33554432即4k
虽然oracle现在支持多块大小的使用,但是在建立多块大小的表空间之前,则必须设定

相应的内存区域即指定对应块大小的cache区
Minimum unit of I/O
Consists of one or more operating system blocks
Set at tablespace creation (db_block_size是在创建表空间的时候建立)
DB_BLOCK_SIZE is the default block size(db_block_size指定了缺省块的大小)
db_cache_size参数所指定的内存区域是给default block大小所使用的。
 

不管是表空间在使用I/O的单位或者内存使用I/O的单位的时候都是以块为单位,所以我

们在系统里面要支持不同的块大小的话在系统里面我们需要设定相应的CACHE区
Sql>alter system set db_8k_cache_size=10m;
这样相当于我们已经将相应的内存区域已经设定好了
SQL>create tablespace yh1 datafile 'd:oracleyh1.dbf' size 10M blocksize

8k;
这样就不像前面建立时出现错误了
/
---database block contents
1.header:header记录这个block里面有多少行等信息,按照从上往下的顺序书写资料
2.data 从下往上的顺序写资料,当你刚开始从block里面写数据时他是从下往上写,不

停的往上涨,
3.free space:header从上往下,(top down)data从下往上,(bottom up)中间空余的

空间就是free space
/
/
---block space utilization parameters
在块这一级来控制空间的使用
initrans
maxtrans  在enterprise manager里面看到table yh 存储里面看到的事务处理数量初始值1 最大值255就是initrans 和maxtrans的值
以上这两个参数用来控制在我们块里面预留的transaction mumberd的空间
pctfree 用来在我们往块里面写资料时预留多少空间来满足这个快的改动时候用,例如该块里面放了varchar2(10) 然后改为varchar)(30)此时如果该快的空间不够用了则row migration则。
pctused  在数据删除到还剩多少空间时该快就可以再使用了
/
---automatic segment space management
Automatic segment-space management can be enabled at the tablespace level only, for locally managed tablespaces.

CREATE TABLESPACE yh2
DATAFILE ‘d:oradatayh2.dbf’ SIZE 5M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 64K
SEGMENT SPACE MANAGEMENT AUTO;


After a tablespace is created, the specifications apply to all segments created in the tablespace.


ex:
sql>create table scott.yh12 (id int) tablesapce yh2;
此时在enterprise manager得schema下面看到这个表的:空间列表值为空,因为它已经采用了自动管理
/
---Manual Data Block Management
Allows you to configure data blocks manually using parameters such as:
PCTFREE
PCTUSED
FREELIST
The only method available in previous Oracle versions
/
---Obtaining Storage Information
Information about storage can be obtained by querying the following views:
DBA_EXTENTS
DBA_SEGMENTS
DBA_TABLESPACES
DBA_DATA_FILES
DBA_FREE_SPACE

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

转载于:http://blog.itpub.net/202861/viewspace-797339/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值