V$datafile 数据文件视图
V$tablespace 表空间视图
V$tempfile; 临时表空间视图
SQL>Select TS#,name from v$tablespace;
SQL>Select TS#,FILE#,STATUS from v$datafile;
SQL>Drop tablespace test;
SQL>Drop tablespace test including contents;
SQL>drop tablespace app including contents and datafiles; 删除表空间定义及数据文件
strings spfileVDEDU.ora 查看二进制的spfile文件
Strings spfileVDEDU.ora > initVDEDU.ora 写到pfile里面,注意不要有断行
将表空间设置成只读形式
alter user hr default tablespace erhei;
Alter table space erhei read only;
Insert into t2 values(1);
会报错,因为表空间是只读,无法写入
Alter tablespace erhei read write;将表空间设置为读写
收缩临时表空间
Alter tablespace temp shrink space
Alter tablespace tmp_III shrink keep 30M
注意:如果缩小到的数值大于现在的数值,则命令不报错,但无效
扩大临时表空间
SQL>alter database tempfile ‘/u01/app/oracle/oradata/kingsql/temp_III01.dbf’ resize 300M;
或者增加临时数据文件
Alter database set default bigfile tablespace;创建表空间时默认为大文件表空间(慎用)
Alter database set default smallfile tablespace;
查询表空间是否为大文件表空间
SQL> select tablespace_name,bigfile from dba_tablespaces;
TABLESPACE_NAME BIG
------------------------------ ---
SYSTEM NO
SYSAUX NO
UNDOTBS1 NO
TEMP NO
USERS NO
EXAMPLE NO
TEST NO
TEST2 NO
TEMPTEST NO
TEST3 NO
HRTBS NO
指定表使用表空间
先创建表空间
SYS@kingsql%> create tablespace tbs1
2 datafile '/u01/app/oracle/oradata/kingsql/tbs101.dbf' size 100M autoextend on
3 extent management local autoallocate
4 segment space management auto;
Tablespace created.
SYS@kingsql%> create tablespace tbs2
2 datafile '/u01/app/oracle/oradata/kingsql/tbs201.dbf' size 100M autoextend on
3 extent management local uniform size 1M
4 segment space management auto;
Tablespace created.
创建表指定使用表空间
SYS@kingsql%> create table t1 tablespace tbs1 as select * from dba_objects where 1=2;
Table created.
SYS@kingsql%> create table t2 tablespace tbs2 as select * from dba_objects where 1=2;
Table created.
查看表使用的表空间信息
SQL> select owner,SEGMENT_NAME,TABLESPACE_NAME,BYTES,BLOCKS from dba_extents where SEGMENT_NAME='T1' and owner='SYS';
SQL> select owner,SEGMENT_NAME,TABLESPACE_NAME,BYTES,BLOCKS from dba_extents where SEGMENT_NAME='T2' and owner='SYS';