數據庫默認臨時表空間
2024-07-21 02:38:45
供稿:網友
數據庫默認臨時表空間
作者:gototop
在9i之前,假如一個數據庫用戶沒有被指定默認臨時表空間,那么Oracle就會使用system表空間作為該用戶的臨時表空間,這是很危險的。在9i里面,database可以被指定一個默認臨時表空間。這樣假如數據庫用戶沒有被明確指定臨時表空間,oracle 9i就會自動指定database的默認臨時表空間作為該用戶的臨時表空間。
我們可以通過下面的語句來查詢數據庫的默認臨時表空間:
SQL> select * from database_PRoperties where property_name = 'DEFAULT_TEMP_TABLESPACE';
PROPERTY_NAME PROPERTY_VALUE DESCRipTION
--------------------- ------------------- ------------------------
DEFAULT_TEMP_TABLESPACE TEMP Name of default temporary tablespace
默認臨時表空間的限制:
1. 默認臨時表空間必須是TEMPORARY的:
SQL> alter database default temporary tablespace tools;
alter database default temporary tablespace tools
*
ERROR at line 1:
ORA-12902: default temporary tablespace must be SYSTEM or of TEMPORARY type
2. 默認臨時表空間一旦被指定,將無法在改成PERMANET:
SQL> alter tablespace temp2 permanent;
alter tablespace temp2 permanent
*
ERROR at line 1:
ORA-12904: default temporary tablespace cannot be altered to PERMANENT type
3. 在刪除默認臨時表空間必須先重新指定默認臨時表空間:
SQL> drop tablespace temp including contents and datafiles;
drop tablespace temp including contents and datafiles
*
ERROR at line 1:
ORA-12906: cannot drop default temporary tablespace
SQL> create tablespace TEMP2
2 datafile '/data1/ora9data/temp2_01.dbf'
3 size 100k TEMPORARY;
Tablespace created.
SQL> alter database default temporary tablespace TEMP2;
Database altered.
SQL> drop tablespace temp including contents and datafiles;
Tablespace dropped.
4. 默認臨時表空間無法OFFLINE:
SQL> alter tablespace temp offline;
alter tablespace temp offline
*
ERROR at line 1:
ORA-12905: default temporary tablespace cannot be brought OFFLINE
5. 用戶的臨時表空間必須是TEMPORARY的(在9i之前沒有這個限制,可以是PERMANENT):
SQL> alter user scott temporary tablespace TOOLS;
alter user scott temporary tablespace TOOLS
*
ERROR at line 1:
ORA-12911: permanent tablespace cannot be temporary tablespace
SQL> create tablespace temp2
2 datafile '/data1/ora9data/temp2_01.dbf'
3 size 100k temporary;
Tablespace created.
SQL> alter user scott temporary tablespace temp2;
User altered.
6. 假如刪除了用戶的臨時表空間,而這個臨時表空間又不是數據庫的默認臨時表空間(假如是數據庫的默認臨時表空間是刪不掉的),用戶的臨時表空間不會自動轉換到數據庫的默認臨時表空間上:
SQL> select tablespace_name, contents from dba_tablespaces where tablespace_name like 'TEMP%';
TABLESPACE_NAME CONTENTS
------------------------------ ---------
TEMP TEMPORARY
TEMP2 TEMPORARY
SQL> select TEMPORARY_TABLESPACE from dba_users where username='SCOTT';
TEMPORARY_TABLESPACE
------------------------------
TEMP2
SQL> drop tablespace TEMP2 including contents and datafiles;
Tablespace dropped.
SQL> select TEMPORARY_TABLESPACE from dba_users where username='SCOTT';
TEMPORARY_TABLESPACE
------------------------------
TEMP2