===============
临时表空间作用
===============
1 索引create或rebuild;
2 Order by 或 group by;
3 Distinct 操作;
4 Union 或 intersect 或 minus;
5 Sort-merge joins;
6 analyze。
创建数据库时没有定义默认的临时表空间(temporary tablespace),那么Oracle将 SYSTEM 表空间作为默认的临时存储空间使用。
此时用户在 ALERT.LOG 文件中会发现一条警告:建议创建默认的临时表空间,以后的Oracle版本将会需要。
如果临时表空间没有设置为自动扩展,则临时表空间不够时事务执行将会报ora-01652 无法扩展临时段的错误。
解决方法比较简单:
1、设置临时数据文件自动扩展。
2、增大临时表空间。
Oracle临时表空间主要用来做查询和存放一些缓冲区数据。临时表空间消耗的主要原因是需要对查询的中间结果进行排序。
===================
查询临时表空间状态
===================
SQL> select tablespace_name,file_name,bytes/1024/1024||'M' B,maxbytes/1024/1024||'M' M,autoextensible from dba_temp_files;
TABLESPACE FILE_NAME B M AUT
---------- ---------------------------------------- ----- --------------- ---
TEMP /u01/app/oracle/oradata/orcl/temp01.dbf 29M 32767.984375M YES
=================
减小临时文件大小
=================
SQL> alter database tempfile '/u01/app/oracle/oradata/orcl/temp01.dbf' resize 10M;
Database altered.
SQL>select tablespace_name,file_name,bytes/1024/1024||'M' B,maxbytes/1024/1024/1024||'G' M,autoextensible from dba_temp_files;
TABLESPACE FILE_NAME B M AUT
---------- ---------------------------------------- ----- --------------- ---
TEMP /u01/app/oracle/oradata/orcl/temp01.dbf 10M 31.999984741210 YES
9375G
=================
增大临时文件大小
=================
SQL> alter database tempfile '/u01/app/oracle/oradata/orcl/temp01.dbf' resize 35M;
Database altered.
SQL> select tablespace_name,file_name,bytes/1024/1024||'M' B,maxbytes/1024/1024/1024||'G' M,autoextensible from dba_temp_files;
TABLESPACE FILE_NAME B M AUT
---------- ---------------------------------------- ----- --------------- ---
TEMP /u01/app/oracle/oradata/orcl/temp01.dbf 35M 31.999984741210 YES
9375G
===========================
向临时表空间中添加数据文件
===========================
SQL> alter tablespace temp add tempfile '/u01/app/oracle/oradata/orcl/ltemp02.dbf' size 10M;
Tablespace altered.
SQL> select tablespace_name,file_name,bytes/1024/1024||'M' B,maxbytes/1024/1024/1024||'G' M,autoextensible from dba_temp_files;
TABLESPACE FILE_NAME B M AUT
---------- ---------------------------------------- ----- --------------- ---
TEMP /u01/app/oracle/oradata/orcl/temp01.dbf 35M 31.999984741210 YES
9375G
TEMP /u01/app/oracle/oradata/orcl/temp02.dbf 10M 0G NO
===========================
将临时数据文件设为自动扩展
===========================
SQL> alter database tempfile '/u01/app/oracle/oradata/orcl/temp02.dbf' autoextend on next 3M maxsize 20M;
Database altered.
SQL> select tablespace_name,file_name,bytes/1024/1024||'M' B,maxbytes/1024/1024/1024||'G' M,autoextensible from dba_temp_files;
TABLESPACE FILE_NAME B M AUT
---------- ---------------------------------------- ----- --------------- ---
TEMP /u01/app/oracle/oradata/orcl/temp01.dbf 35M 31.999984741210 YES
9375G
TEMP /u01/app/oracle/oradata/orcl/temp02.dbf 10M .01953125G YES
===============
创建临时表空间
===============
SQL> create temporary tablespace tempa tempfile '/u01/app/oracle/oradata/tempa01.dbf' size 10M;
Tablespace created.
SQL> select tablespace_name,file_name,bytes/1024/1024||'M' B,maxbytes/1024/1024/1024||'G' M,autoextensible from dba_temp_files;
TABLESPACE FILE_NAME B M AUT
---------- ---------------------------------------- ----- --------------- ---
TEMP /u01/app/oracle/oradata/orcl/temp01.dbf 35M 31.999984741210 YES
9375G
TEMP /u01/app/oracle/oradata/orcl/temp02.dbf 10M .01953125G YES
TEMPA /u01/app/oracle/oradata/tempa01.dbf 10M 0G NO
=========================
更改系统的默认临时表空间
=========================
SQL> select * from database_properties where property_name like 'DEFAULT%';
PROPERTY_NAME PROPERTY_V DESCRIPTION
------------------------------ ---------- --------------------------------------
DEFAULT_TEMP_TABLESPACE TEMP Name of default temporary tablespace
DEFAULT_PERMANENT_TABLESPACE USERS Name of default permanent tablespace
DEFAULT_EDITION ORA$BASE Name of the database default edition
DEFAULT_TBS_TYPE SMALLFILE Default tablespace type
SQL> alter database default temporary tablespace tempa;
Database altered.
SQL> select * from database_properties where property_name like 'DEFAULT%';
PROPERTY_NAME PROPERTY_V DESCRIPTION
------------------------------ ---------- --------------------------------------
DEFAULT_TEMP_TABLESPACE TEMPA Name of default temporary tablespace
DEFAULT_PERMANENT_TABLESPACE USERS Name of default permanent tablespace
DEFAULT_EDITION ORA$BASE Name of the database default edition
DEFAULT_TBS_TYPE SMALLFILE Default tablespace type
=========================
更改某一用户的临时表空间
=========================
SQL> conn scott/tiger
Connected.
SQL> select username,temporary_tablespace from user_users;
USERNAME TEMPORARY_TABLESPACE
------------------------------ ------------------------------
SCOTT TEMPA
SQL> conn /as sysdba
Connected.
SQL> alter user scott temporary tablespace temp;
User altered.
SQL> conn scott/tiger
Connected.
SQL> select username,temporary_tablespace from user_users;
USERNAME TEMPORARY_TABLESPACE
------------------------------ ------------------------------
SCOTT TEMP
=======================================
对临时表空间进行shrink(11g新增的功能)
=======================================
SQL> alter tablespace tempa shrink space keep 5M;
Tablespace altered.
SQL> alter tablespace temp shrink space keep 15M;
Tablespace altered.
SQL> select tablespace_name,file_name,bytes/1024/1024||'M' B,maxbytes/1024/1024/1024||'G' M,autoextensible from dba_temp_files;
TABLESPACE FILE_NAME B M AUT
---------- ---------------------------------------- ----- --------------- ---
TEMP /u01/app/oracle/oradata/orcl/temp01.dbf 14.00 31.999984741210 YES
78125 9375G
M
TEMP /u01/app/oracle/oradata/orcl/temp02.dbf 1.992 .01953125G YES
1875M
TEMPA /u01/app/oracle/oradata/tempa01.dbf 6M 0G NO
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29785807/viewspace-1314648/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29785807/viewspace-1314648/