您好,欢迎访问一九零五行业门户网

Oracle表空间(Tablespace)

1、查看表空间的名称及大小select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizefrom dba_tablespaces t, dba_d
1、查看表空间的名称及大小
select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
2、查看表空间物理文件的名称及大小
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_temp_files
order by tablespace_name;
3、查看表空间的使用情况
select sum(bytes)/(1024*1024) as free_space,tablespace_name
from dba_free_space
group by tablespace_name;
select * from dba_temp_free_space;
4、查看/修改database的default temporary tablespace
select property_name, property_value from database_properties where
property_name='default_temp_tablespace';
alter database default temporary tablespace tablespace_name;
tablespace是oracle空间管理上的逻辑单位,实体上存放数据的是tablespace里面的档案(data file);而我们所熟悉的table就放在这一个一个的档案里面。所以tablespace可以看成是data file的群组。tablespace可进一步分为segments、extents和blocks。一个datafile只属于一个数据库的一个tablespace。
当数据库刚建立起来,系统会建立一个叫做system的系统tablespace,存放sys、system等user重要的系统数据(ex:数据字典与预储程序等)如果我们建立oracle user时,不指定预设的tablespace,则此user则会以system tablespace作为预设的tablespace。这将造成管理上的混乱与严重的效能问题,这是必须特别注意的。
tablespace的类型:permanent、undo、temporary
§ permanent tablespace
一般我们创建给ap使用的都是permanent tablespace。里面对象的生命周期不会随着交易或者用户的session结束而消失。
§ undo tablespace
undo tablespace是系统用的特殊的tablespace,用来取代过去的rollback segement的机制,主要的功用是提供用户修改数据未commit之前的read consistency的功能以及rollback交易的功能。也因为undo tablespace主要是取代过去的rollback segement的机制,所以不能存放其他种类的segement。undo tablespace只能是local managed。
§ temporary tablespace
temporary tablespace也是系统用的特殊的tablespace。当使用者需要做排序时,有时就会使用temporary tablespace,因此里面的segement的生命周期都很短,可能交易结束或者user的session结束就会消失。每个系统都必须要有一个预设的temporary tablespace(default temporary tablespace),the default temporary tablespace clause of the create database statement creates a default temporary tablespace for the database. 如果没有default temporary tablespace,create user的时候又忘了指定使用哪个temporary tablespace,会以system tablespace来当作temporary tablespace,这样就很糟糕。以下列出几个temporary tablespace的特性。
1. temporary tablespace是nologging模式,因此若数据库损毁,做recovery不需要恢复temporary tablespace。
2. temporary最好是使用local managed tablespace
3. 若使用local managed模式,uniform. size参数最好是sort_area_size的参数,这样效能比较好。
4. uniform. size预设1024k,而sort_area_size预设是512k
5. temporary tablespace不能使用local managed的autoallocate参数。
tablespace的extent空间管理:local managed与dictionary managed
local managed与dictionary managed最主要的分别,在于空间管理方式的不同。local managed的管理方式是让每个tablespace自己利用bitmaps去管理他自己的空间,而dictionary managed则是利用system tablespace的数据字典来做空间管理。这两者最大的不同在于local managed大大的改善了oracle做空间管理(例如:产生新的exten或释放extent...等)时,抢夺system tablespace资源的问题。所以oracle从8i以后已经朝local managed的方向去走了,所以我们应该尽量使用local managed的方式才对,所以dictionary managed的方式不多做介绍了。
§ local managed tablespace
1. local managed使用bitmaps做空间管理。
2. bitmaps中每个bit代表一个data block或者一堆相邻的data block(extent)
3. 从10g开始,system tablespace预设使用local managed-->oracle建议使用local managed的证据。
4. 假如system tablespace是local managed,那么其他tablespace必须是local managed。
5. 若没指定使用local managed或者dictionary managed,,则预设使用local managed。
6. 使用local managed可以增进效能,因为减少了system tablespace的效能竞争。
7. 使用local managed则不需要做空间缝合(loalescing),因为相邻的不同大小的extent,辨识extent使用状态的bits也在一起,oracle可以直接使用这些相邻的extent。不需要先进行缝合才可以使用。这也可以增进部份效能。
§ local managed的extent空间管理(extent management):autoallocate与uniform
autoallocate与uniform这两个参数,是用来设定local managed的extent大小的参数。autoallocate是让oracle自己来决定extent的大小;而uniform则是强制规定tablespace中extent的为固定的大小。通常若你明确的知道extent必须多大,才会使用uniform,使用uniform的好处是每个extent的大小都相同,不会产生空间破碎的问题。但是如果无法预知extent必须多大,使用autoallocate会比较好,让oracle自己决定使用extent的大小,可以比较符合实际的需求,因此会比较节省空间,但是这可能会产生部分空间破碎的问题。使用autoextent,oracle会使用的extent大小为64k、1m、8m、64m。根据我系统上使用的结果,99.95%的extent都是使用64k、只有少部分使用1m的extent,所以其实破碎的情况不严重,使用autoallocate在我的系统上其实就够用了。想知道你的tablespace所使用的extent有几种,请用下列的语法:
select bytes,count(*) from dba_extents where tablespace_name='your_tablespace_name' group by bytes
§ local managed中的segment的空间管理(segment space management ):auto与manual
tablespace中的segment的空间管理上,可以设置的参数为auto与manual。manual是使用我们熟悉的pctused、freelists、freelist groups的方式来管理segment中的data block;而auto则是使用bitmaps来管理data block。使用auto来管理的话,以往create tablespace或create table时设定的storage的参数设定都不需要再设定了,因为data block的管理已经是bitmaps了,不再是free list了。如果没有特别的需求话,使用auto会比使用manual有更好的空间利用率,与效能上的提升。
其它类似信息

推荐信息