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;