Oracle 暫存資料表之暫存資料表空間組(TTG)

來源:互聯網
上載者:User

環境:

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同時排序時使用了同一暫存資料表空間組內的不同暫存資料表空間

這樣大大減少了之前同一使用者只能使用一個暫存資料表空間而產生的請求臨時段的等待時間

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.