1) 显示段信息
Ø 显示段类型:
a)显示数据库包含的所有段类型:
select distinct segment_type from dba_segments
Ø 建立表、索引和簇时,oracle会为这些对象分配相应的段,并且将段的信息记载到数据字典中。
select tablespace_name,extents,bytes from dba_segments
where ower=’scott’ and segment_name=’emp’
tablespace_name 用于标识段所在表空间,extends用于标识段所包含区个数,bytes用于标识段尺寸,owner用于标识段的所有者,segment_name用于标识段名。
2) 存储参数
a)initial:initial用于指定为段所分配的第一个区的尺寸。
当在本地管理表空间上建立数据库对象时,通过使用initial参数和区尺寸可以确定段的初始尺寸。确定段初始尺寸的方法
create table t1(cola INT) tablespace user01 storage(initial 500k);
其中tablespace选项用于指定段所在表空间,storage用于指定段的存储参数,
initial用于指定段的初始尺寸
a) next:对于字典管理表空间来说,next用于指定为段所分配的第二个区的尺寸。
4)显示区信息
Ø 显示已分配区
select extents_id,file_id,block_id,bytes from dba_extends
where owner=’sys’ and segment_name=’t1’;
extent_id用于标识区编号(0:表示第0个区),file_id用于标识区所在的文件号,
block_id用于标识区的起始块号,bytes用于标识区的尺寸。
Ø 显示空闲区
当在表空间上建立数据对象(表、索引和簇)时,oracle会在表空间的剩余空间中为相应段分配空间。当段不足以容纳更多数据时,oracle会通过分配区来扩展段。
例:显示user01表空间剩余空间为例
select sum(bytes) from dba_free_space where tablespace_name=’user01’
SQL>create index pk_deptno on department(deptno)
pctfree 20 initrans 4;
b) 改变对象的块空间参数
建立了数据对象后,如果空间参数不适合,用户可以使用alter命令修改块空间参数,索引cptfree参数不能修改。
SQL>alter cluster dept_emp_clu pctfree 30 pctused 40 initrans 4;
SQL>alter table department pctfree 30 pctused 40 initrans 4;
SQL>alter index pk_deptno initrans 4;
4) 显示块空间参数
a) 建立簇时,可以指定块空间参数。如果不指定块空间参数,oracle会自动为相应参数提供默认值。通过查询dba_clusters,可以取得簇的块空间参数。
SQL>select pct_free,pct_used,ini_trans,maxtrans
from dba_clusters where owner=’system’ and cluster_name=’dept_emp_
clu’;
b) 显示表的块空间参数
SQL>select pct_free,pct_used,ini_trans,max_trans
from dba_tables
where owner=’system’ and table_name=’department’
c) 显示索引的块空间参数
SQL>select pct_free,ini_trans,max_trans
from dba_indexes
where owner=’system’ and index_name=’pk_deptno’;