Oracle表空間維護
表空間維護
(1)創建表空間
CREATE TABLESPACE SUNTX DATAFILE
'/app1/oracle/oradata/SUNTX/SUNTX01.dbf' SIZE 10240M AUTOEXTEND OFF,
'/app1/oracle/oradata/SUNTX/SUNTX02.dbf' SIZE 10240M AUTOEXTEND OFF;
創建新undo表空間
CREATE UNDO TABLESPACE UNDO_NEW DATAFILE
'/app1/oracle/oradata/SUNTX/UNDO_NEW1.dbf' SIZE 10240M AUTOEXTEND OFF,
'/app1/oracle/oradata/SUNTX/UNDO_NEW2.dbf' SIZE 10240M AUTOEXTEND OFF,
'/app1/oracle/oradata/SUNTX/UNDO_NEW3.dbf' SIZE 10240M AUTOEXTEND OFF;
#注意:在OPEN狀態下某些時刻只能用一個UNDO表空間,如果要用新建的表空間,必須切換
ALTER SYSTEM SET UNDO_TABLESPACE = UNDO_NEW;
建立臨時表空間
CREATE TEMPORARY TABLESPACE temp_data TEMPFILE
'/oracle/oradata/db/TEMP_DATA.dbf' SIZE 50M
(2)擴展表空間
首先查看表空間的名字和所屬文件
select tablespace_name, file_id, file_name, round(bytes/(1024*1024),0)
total_space from dba_data_files order by tablespace_name;
1.增加數據文件 ALTER TABLESPACE game ADD DATAFILE
'/oracle/oradata/db/GAME02.dbf' SIZE 1000M;
2.手動增加數據文件尺寸 ALTER DATABASE DATAFILE '/oracle/oradata/db/GAME.dbf'
RESIZE 4000M;
3.設定數據文件自動擴展 ALTER DATABASE DATAFILE '/oracle/oradata/db/GAME.dbf
AUTOEXTEND ON NEXT 100M MAXSIZE 10000M;
設定后查看表空間信息
SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES FREE,
(B.BYTES*100)/A.BYTES "% USED",(C.BYTES*100)/A.BYTES "% FREE" FROM
SYS.SM$TS_AVAIL A,SYS.SM$TS_USED B,SYS.SM$TS_FREE C WHERE
A.TABLESPACE_NAME=B.TABLESPACE_NAME AND A.TABLESPACE_NAME=C.TABLESPACE_NAME;
===================縮小TEMP(新建TEMP-》切換-》刪除舊的|重復操作)
1.create temporary tablespace TEMP2 TEMPFILE
’/oradata/test/temp02.dbf’ SIZE 512M REUSE AUTOEXTEND ON NEXT 640K
MAXSIZE UNLIMITED;
2.alter database default temporary tablespace temp2;
3.drop tablespace temp including contents and datafiles;
4.create temporary tablespace TEMP TEMPFILE '/oradata/test/temp01.dbf'
SIZE 2048M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED;
5.alter database default temporary tablespace temp;
6.drop tablespace temp2 including contents and datafiles;
===================縮小UNDO(新建UNDO-》切換-》刪除舊的|重復操作)
1.create undo tablespace apps_undots2 DATAFILE
'/oradata/test/undo03.dbf' SIZE 2000M;
2.alter system set undo_tablespace=apps_undots2;
3.drop tablespace apps_undots1 including contents and datafiles;
4.create undo tablespace apps_undots1 DATAFILE '/oradata/test/undo01.dbf' SIZE
4000M autoextend on;
5.alter system set undo_tablespace=apps_undots1;
6.drop tablespace apps_undots2 including contents and datafiles;
(3)改變表空間狀態
1.使表空間脫機
ALTER TABLESPACE game OFFLINE;
如果是意外刪除了數據文件,則必須帶有RECOVER選項
ALTER TABLESPACE game OFFLINE FOR RECOVER;
2.使表空間聯機
ALTER TABLESPACE game ONLINE;
3.使數據文件脫機
ALTER DATABASE DATAFILE 3 OFFLINE;
4.使數據文件聯機
ALTER DATABASE DATAFILE 3 ONLINE;
5.使表空間只讀
ALTER TABLESPACE game READ ONLY;
6.使表空間可讀寫
ALTER TABLESPACE game READ WRITE;
(4)刪除表空間
DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;