首页 > 数据库 > Oracle > Oracle 临时表之临时表空间组(TTG)
环境:
sys@ORCL> select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod PL/SQL Release 10.2.0.1.0 - Production CORE 10.2.0.1.0 Production TNS for Linux: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production
在Oracle中,temp犹如win下的虚拟内存和unix下的swap分区
TTG是10g引入的概念,目的就是为了减少IO竞争
只有临时表空间可以定组,普通的表空间无法定组
对待TTG就像对待单个临时表空间一样,无甚区别
TTG本身不能被创建,它随着temp的加入而创建,temp的脱离而删除
alter tablespace temp tablespace group \'\';
我们知道一个用户只能使用一个临时表空间,而一个临时表空间中只存在一个临时段
当一个session在使用临时段时,其他session再请求临时段时需要等到拥有该临时段的session使用完毕之后才能使用
而临时表空间组的出现大大改善了同一用户并发session对临时段的争夺
因为临时表空间组的出现使用户能够使用多个临时表空间了
下面作个简单测试
sys@ORCL> create temporary tablespace temp1 tempfile size 20M tablespace group tempg; Tablespace created. sys@ORCL> create temporary tablespace temp2 tempfile size 20M tablespace group tempg; Tablespace created. sys@ORCL> create temporary tablespace temp3 tempfile size 20M tablespace group tempg; Tablespace created. sys@ORCL> alter database default temporary tablespace tempg; Database altered. sys@ORCL> drop tablespace temp; Tablespace dropped. sys@ORCL> select * from dba_tablespace_groups; GROUP_NAME TABLESPACE_NAME ------------------------------ ------------------------------ TEMPG TEMP1 TEMPG TEMP2 TEMPG TEMP3 sys@ORCL> alter user hr temporary tablespace tempg; User altered. sys@ORCL> conn hr/hr Connected. hr@ORCL> create table t as select * from dba_objects; Table created. hr@ORCL> begin 2 for i in 1..4 3 loop 4 insert into t select * from t; 5 end loop; 6 commit; 7 end; 8 / PL/SQL procedure successfully completed. hr@ORCL> create table tt as select * from t; Table created.
分别打开两个session以用户hr登录对表t和tt同时进行排序,之后通过如下查询监视对临时表空间的使用情况
sys@ORCL> select operation_type ,sql_id , tablespace,tempseg_size,number_passes from v$sql_workarea_active; OPERATION_ SQL_ID TABLESPACE TEMPSEG_SIZE NUMBER_PASSES ---------- ------------- ------------------------------ ------------ ------------- SORT (v2) b7q3tuybvatbt temp1 0 SORT (v2) cn7ucn092pg8s temp3 0 sys@ORCL> select sql_text from v$sql where sql_id in (select sql_id from v$sql_workarea_active); SQL_TEXT --------------------------------------------- select object_id from t order by object_id desc select object_id from tt order by object_id desc
发现来自同一用户hr的不同session同时排序时使用了同一临时表空间组内的不同临时表空间
这样大大减少了之前同一用户只能使用一个临时表空间而产生的请求临时段的等待时间
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26515977/viewspace-1207902/ ,如需转载,请注明出处,否则将追究法律责任。