『ORACLE』 對臨時表空間相關操作(11g)

1、查看臨時表空間 (dba_temp_files視圖)(v_$tempfile視圖)
select tablespace_name,file_name,bytes/1024/1024 file_size,autoextensible from dba_temp_files;
select status,enabled, name, bytes/1024/1024 file_size from v_$tempfile;--sys用戶查看

2、縮小臨時表空間大小
alter database tempfile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\TELEMT\TEMP01.DBF' resize 100M;

3、擴展臨時表空間:
方法一、增大臨時文件大小:
SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp01.dbf’ resize 100m;
方法二、將臨時數據文件設爲自動擴展:
SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp01.dbf’ autoextend on next 5m maxsize unlimited;
方法三、向臨時表空間中添加數據文件:
SQL> alter tablespace temp add tempfile ‘/u01/app/oracle/oradata/orcl/temp02.dbf’ size 100m;

4、創建臨時表空間:
SQL> create temporary tablespace temp1 tempfile ‘/u01/app/oracle/oradata/orcl/temp11.dbf’ size 10M;

5、更改系統的默認臨時表空間:
--查詢默認臨時表空間
select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE';
--修改默認臨時表空間
alter database default temporary tablespace temp1;
所有用戶的默認臨時表空間都將切換爲新的臨時表空間:
select username,temporary_tablespace,default_ from dba_users;
--更改某一用戶的臨時表空間:
alter user scott temporary tablespace temp;

6、刪除臨時表空間
刪除臨時表空間的一個數據文件:
SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp02.dbf’ drop;
刪除臨時表空間(徹底刪除):
SQL> drop tablespace temp1 including contents and datafiles cascade constraints;

7、查看臨時表空間的使用情況(GV_$TEMP_SPACE_HEADER視圖必須在sys用戶下才能查詢)
GV_$TEMP_SPACE_HEADER視圖記錄了臨時表空間的使用大小與未使用的大小
dba_temp_files視圖的bytes字段記錄的是臨時表空間的總大小
SELECT temp_used.tablespace_name,
       total - used as "Free",
       total as "Total",
       round(nvl(total - used, 0) * 100 / total, 3) "Free percent"
  FROM (SELECT tablespace_name, SUM(bytes_used) / 1024 / 1024 used
          FROM GV_$TEMP_SPACE_HEADER
         GROUP BY tablespace_name) temp_used,
       (SELECT tablespace_name, SUM(bytes) / 1024 / 1024 total
          FROM dba_temp_files
         GROUP BY tablespace_name) temp_total
 WHERE temp_used.tablespace_name = temp_total.tablespace_name
 ORDER BY B.TABLESPACE, B.SEGFILE#, B.SEGBLK#, B.BLOCKS;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章