1、先查询空闲空间
select tablespace_name,file_id,block_id,bytes,blocks from dba_free_space;
2、增加Oracle表空间
先查询数据文件名称、大小和路径的信息,语句如下:
select tablespace_name,file_id,bytes,file_name from dba_data_files;
3、修改文件大小语句如下
alter database datafile '需要增加的数据文件路径,即上面查询出来的路径' resize 800M;
4、创建Oracle表空间
View Code
create tablespace test datafile '/home/app/oracle/oradata/oracle8i/test01.dbf' size 8M autoextend on next 5M maxsize 10M; create tablespace sales datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M autoextend on next 50M maxsize unlimited maxsize unlimited 是大小不受限制 create tablespace sales datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M autoextend on next 50M maxsize 1000M extent management local uniform; unform表示区的大小相同,默认为1M create tablespace sales datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M autoextend on next 50M maxsize 1000M extent management local uniform size 500K; unform size 500K表示区的大小相同,为500K create tablespace sales datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M autoextend on next 50M maxsize 1000M extent management local autoallocate; autoallocate表示区的大小由随表的大小自动动态改变,大表使用大区小表使用小区 create tablespace sales datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M autoextend on next 50M maxsize 1000M temporary; temporary创建字典管理临时表空间 create temporary tablespace sales tempfile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M autoextend on next 50M maxsize 1000M
创建本地管理临时表空间,如果是临时表空间,所有语句中的datafile都换为tempfile
8i系统默认创建字典管理临时表空间,要创建本地管理临时表空间要加temporary tablespace关键字
创建本地管理临时表空间时,不得使用atuoallocate参数,系统默认创建uniform管理方式
5.删除Oracle表空间
DROP TABLESPACE FESCO INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;
6.为表空间增加数据文件:
alter tablespace sales add datafile '/home/app/oracle/oradata/oracle8i/sales02.dbf' size 800M autoextend on next 50M maxsize 1000M;
创建本地管理临时Oracle表空间,如果是临时表空间,所有语句中的datafile都换为tempfile8i系统默认创建字典管理临时表空间,要创建本地管理临时表空间要加temporary tablespace关键字创建本地管理临时表空间时,不得使用atuoallocate参数,系统默认创建uniform管理方式
7、更改自动扩展属性:
alter database datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf', '/home/app/oracle/oradata/oracle8i/sales02.dbf' '/home/app/oracle/oradata/oracle8i/sales01.dbf autoextend off;
8、创建用户并指定表空间:
create user username identified by password default tablespace test_data temporary tablespace test_temp;
9、改变表空间状态
View Code
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;
10、表空间分类:
View Code
1.Permanent tablespace create tablespace ts_something logging datafile '/dbf1/ts_sth.dbf' size 32m autoextend on next 32m maxsize 2048m extent management local; create tablespace data datafile '/home/oracle/databases/ora10/data.dbf' size 10M autoextend on maxsize 200M extent management local uniform size 64K; 2.Temporary tablespace create temporary tablespace temp_mtr tempfile '/dbf1/mtr_temp01.dbf' size 32m autoextend on next 32m maxsize 2048m extent management local; Note, a temporary tablespace has tempfiles, not datafiles. 3.Undo tablespace create undo tablespace ts_undo datafile '/dbf/undo.dbf' size 100M; 4.Misc More than one datafile can be created with a single create tablespace command: create tablespace ts_sth datafile 'c:\xx\sth_01.dbf' size 4M autoextend off, 'c:\xx\sth_02.dbf' size 4M autoextend off, 'c:\xx\sth_03.dbf' size 4M autoextend off logging extent management local;
参考地址:
http://database.51cto.com/art/200910/158936.htm