Ø 临时表空间 临时表空间(temp tablespace)主要用于存储oracle数据库运行期间所产生的历史数据,及用于进行排序。数据库关闭后,临时表空间中所有数据将全部被清除,故临时表空间外地其他所有表空间都属于永久性表空间 数据库创建时默认建立一临时表空间temp。包含一数据文件temp01.dbf,对于大型操作(大型查询,大型分类查询,大型统计分析等)频繁的环境,应建立多个临时表空间,并分别归属不同临时表空间,以避免多用户及多任务竞争该临时表空间 SQL> select tablespace_name from dba_tablespaces; SQL> select * from dba_temp_files; 查看系统默认临时表空间及对应数据文件 SQL> create temporary tablespace temp02 Tempfile '/u01/app/oracle/oradata/ora10/temp02.dbf' size 50M; 新建临时表空间 SQL> select tablespace_name,allocation_type from dba_tablespaces; 临时表空间只能使用uniform管理方式 SQL> create temporary tablespace temp1 tempfile '/u01/temp1.dbf' size 50M tablespace group group1; SQL> create temporary tablespace temp2 tempfile '/u01/temp2.dbf' size 5M tablespace group group1; SQL> select * from dba_tablespace_groups; 创建并查看临时表空间 SQL> select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE'; SQL> select username,temporary_tablespace from dba_users; 查看系统默认使用的临时表空间,及所有用户使用的默认临时表空间 SQL> conn sqlplus kitty/123456 SQL> select username,temporary_tablespace from user_users; USERNAME TEMPORARY_TABLESPACE ------------------------------ ------------------------------ KITTY TEMP SQL> conn sqlplus / as sysdba SQL> alter user kitty temporary tablespace group1; SQL> conn sqlplus kitty/123456 SQL> select username,temporary_tablespace from user_users; USERNAME TEMPORARY_TABLESPACE ------------------------------ ------------------------------ KITTY GROUP1 SQL> conn sqlplus / as sysdba SQL> select username,session_num,tablespace from v$sort_usage; no rows selected 查看临时表空间使用情况 $ sqlplus kitty/123456 SQL> select a.table_name,b.table_name from dict A,dict B order by a.table_name; 发起排序使其使用表空间 SQL> select username,session_num,tablespace from v$sort_usage; USERNAME SESSION_NUM TABLESPACE ------------------------------ ----------- ------------------------------- KITTY 111 TEMP1 $ sqlplus kitty/123456 SQL> select a.table_name,b.table_name from dict A,dict B order by b.table_name; 发起另一个排序 SQL> select username,session_num,tablespace from v$sort_usage; USERNAME SESSION_NUM TABLESPACE ------------------------------ ----------- ------------------------------- KITTY 116 TEMP1 KITTY 135 TEMP2 同一用户的不同session可以使用临时表空间组中的不同临时表空间 SQL> alter tablespace temp2 tablespace group group2; SQL> select * from dba_tablespace_groups; GROUP_NAME TABLESPACE_NAME ------------------------------ ------------------------------ GROUP1 TEMP1 GROUP2 TEMP2 移动临时表空间到新的临时表空间组(新的组不存在则自动创建) SQL> alter tablespace temp2 tablespace group ''; 将临时表空间从组中移出(组中的历史表空间全部移出则自动删除)。 SQL> alter database default temporary tablespace group1; 更改系统默认使用的临时表空间 SQL> select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE'; SQL> select username,temporary_tablespace from dba_users; 再查系统默认使用的临时表空间,及所有用户的默认临时表空间 二.段(segment) Ø 概述 ·为特定的数据库的对象(如表,索引等)分配的一系列数据存储区域 ·默认段名与数据库对象名相同 ·一个对象一般只对应一个段 ·一个段segment只能属于一个表空间,但可以跨多个数文件 ·段分为数据段,索引段,回滚段,临时段等类型 SQL> select segment_name,segment_type,tablespace_name,bytes from dba_segments; 查询系统中所有段 SQL> select segment_type from dba_segments group by segment_type; 查询系统中所有段种类 Ø 段管理方式 MSSM(manual segment space management)在每个段中以freelist链表方式管理段中空闲数据块(块中空闲区高于pctfree值),是oracle 9.2以前的数据块管理方式。 ASSM(automatic segment space management,默认)以位图BMB(bitmap managed segments)方式管理段中的空闲数据块(块中空闲区高于pctfree值)以避免freelist链表竞争,是oracle 9.2开始新出现的数据块管理方式。 区别:1.注意ASSM与内存管理中的ASMM不同 2.DMT/LMT和MSSM/ASSM的联系与区别: 两者都在建立表空间是指定 DMT/LMT用于管理(segment中)空闲的extent MSSM/ASSM用于管理(extent中的)空闲的block SQL> select tablespace_name,extent_management,allocation_type,segment_space_m anagement from dba_tablespaces; 查询表空间的空闲extent管理方式(DMT/LMT)和空闲block管理方式(MSSM/ASSM) SQL> create tablespace tb1 datafile '/u01/tb1.dbf' size 10M segment space management manual; 指定表空间的段空间管理方式为MSSM (1) 数据段 数据段也称为表段,它包含数据并且与表和簇相关。当创建一个表时,系统自动创建一个以该表的名字命名的数据段。 数据段是用于存储数据的段,其存储在数据表空间中,每一个表都有一个数据段,表的数据存储在数据段中,默认情况下段名与表名相同。 SQL> create table lj tablespace data01 as select * from dba_objects; 在指定表空间中建表 SQL> select segment_name,segment_type,tablespace_name,bytes from dba_segments where segment_name='LJ'; 查询随建表而建立的数据段 (2) 索引段 索引段用于存储索引,包含了用于提高系统性能的索引。一旦建立索引,系统自动创建一个以该索引段名字命名的索引段。 SQL> create index liuj on lj (object_id); 对表建立索引 SQL> select index_name,table_name,tablespace_name from dba_indexes where index_name='LIUJ'; 转载请保留固定链接: https://linuxeye.com/database/666.html |