oracle临时表空间组,证明临时表空间组在并发session时的作用
本帖最后由 zcs0237 于 2013-7-16 20:26 編輯
a.感謝對本帖補充、建議、錯誤更正
b.為節省篇幅,部分輸出結果做了精簡
c.可按本文先后順序復制文中代碼進程調試
d.測試環境:Ora10.2.0.1.0(Ora11.2.0.1.0暫時還沒測)
****************************證明不同session會調用臨時組中不同的臨時表空間********************************************
說明:oracle查詢時優先使用內存排序,內存(sort_area_size)不足時才會調用臨時表空間。
一、改為手動管理
SQL> show parameter workarea_size_policy
NAME? ?? ?? ?? ?? ?? ? TYPE? ?? ???VALUE
-------------------- ----------- ------------
workarea_size_policy? ?string? ?? ?AUTO
SQL> alter system set workarea_size_policy=manual;
System altered.
二、減小sort_area_size
SQL> show parameter sort_area_size
NAME? ?? ?? ?? ?? ?TYPE? ?? ???VALUE
------------------ ----------- -----------
sort_area_size? ???integer? ???65536
SQL> alter system set sort_area_size=20480 scope=spfile;
SQL> shutdown immediate
SQL> startup
SQL> show parameter sort_area_size
NAME? ?? ?? ?? ?? ?TYPE? ?? ???VALUE
------------------ ----------- -----------
sort_area_size? ???integer? ???20480
三、將臨時表空間組指定為用戶級默認臨時表空間
臨時表空間組中可以包含無數個臨時表空間,防止一個臨時表空間出現空間不足的問題。
同一個用戶同時連接多個session時可以使用臨時表空間組中不同的臨時表空間,提高系統的性能。
SQL> create temporary tablespace tmp1 tempfile '/tmp/tmp1.dbf' size 33M autoextend on tablespace group tmpgrp1;? ?? ???//建表空間同時加入tgroup1
SQL> create temporary tablespace tmp2 tempfile '/tmp/tmp2.dbf' size 33m autoextend on tablespace group tmpgrp1;? ?? ???//reuse=文件若存在則重用
SQL> select * from dba_tablespace_groups;? ?? ?//列出臨時表空間組及表空間
GROUP_NAME? ?? ?? ?? ?? ?? ?? ?TABLESPACE_NAME
------------------------------ ------------------------------
TGROUP1? ?? ?? ?? ?? ?? ?? ?? ?TEMP1
TGROUP1? ?? ?? ?? ?? ?? ?? ?? ?TEMP2
SQL> create user zcs2 identified by zcs2;? ?設置用戶級默認表空間
SQL> alter user zcs2 temporary tablespace tmpgrp1;
SQL> grant connect,resource to zcs2;
SQL> select username,temporary_tablespace from dba_users where username = 'ZCS2';
USERNAME TEMPORARY_TABLESPACE
-------- ----------------------
ZCS? ?? ?TGROUP2
SQL> select username, session_num, tablespace from v$sort_usage;
no rows selected? ?? ?? ?? ?? ?? ? //現在沒有磁盤排序
四、驗證同一用戶不同session調用不同臨時表空間
$ sqlplus zcs2/zcs2? ?? ? //secureCRT會話2
SQL> select a.table_name, b.table_name from dict A, dict B order by a.table_name;
$ sqlplus zcs2/zcs2? ?? ? //secureCRT會話3
SQL> select a.table_name, b.table_name from dict A, dict B order by a.table_name;
$ sqlplus zcs2/zcs2? ?? ? //secureCRT會話4
SQL> select a.table_name, b.table_name from dict A, dict B order by a.table_name;
$ sqlplus /? ?as sysdba??//secureCRT會話1
SQL> select a.table_name, b.table_name from dict A, dict B order by a.table_name;
//證明結果:zcs3的3個session把臨時表空間組中的兩個會話都調用了
SQL>select username, session_num, tablespace from v$sort_usage;
USERNAME? ?? ?SESSION_NUM TABLESPACE
-------- ----------- -------------------------------
ZCS2? ?? ?? ?? ?14? ?? ?? ?? ?TMP2
ZCS2? ?? ?? ?? ?13? ?? ?? ?? ?TMP1
ZCS2? ?? ?? ?? ?6? ?? ?? ?? ? TMP2
***************************************************************************************************
補充:退出臨時表空間組
SQL> select * from dba_tablespace_groups;? ?? ?//列出臨時表空間組及表空間
GROUP_NAME? ?? ?? ?? ?? ?? ?? ?TABLESPACE_NAME
------------------------------ ------------------------------
TGROUP1? ?? ?? ?? ?? ?? ?? ?? ?TEMP1
TGROUP1? ?? ?? ?? ?? ?? ?? ?? ?TEMP2
SQL> drop tablespace tmp2 INCLUDING CONTENTS and datafiles;
Tablespace dropped.
SQL> alter tablespace tmp1 tablespace group '';
Tablespace dropped.? ?? ?? ?//將組中的臨時表空間從組中移出
SQL> select * from dba_tablespace_groups;
no rows selected? ?? ?? ???//組員沒組自動沒
SQL> drop tablespace tmp1 INCLUDING CONTENTS and datafiles;
Tablespace dropped.
***************************************************************************************************
最近itpub發帖:
無GUI智能部署oracle腳本及視頻http://www.itpub.net/thread-1778735-1-1.html
總結
以上是生活随笔為你收集整理的oracle临时表空间组,证明临时表空间组在并发session时的作用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 银行下血本,利率接近5%的保本理财来了,
- 下一篇: golang 包含 数组_Golang数