查看用户表空间:
相关的数据字典:dba_tablespaces user_tablespaces
例如:connect system/oracle
select tablespace_name from dba_tablespaces;
connect scott/tiger
select tablespace_name from user_tablespaces;
数据字典:dba_users user_users
例如:connect system/oracle
select default_tablespace,temporary_tablespace from dba_users where username=’SYSTEM’(查看system用户的表空间信息)
select username,default_tablespace,temporary_tablespace from dba_users;
设置用户默认或临时表空间
alter user user01 default tablespace TEST1_TABLESPACE temporary tablespace IEMPTEST1_TABLESPACE;
select default_tablespace,temporary_tablespace from dba_users where username=’USER01’
修改表空间状态
设置联机或脱机状态:alter tablespace tablespace_name ONLINE/OFFLINE;
alter tablespace test1_tablespace offline;
select status from dba_tablespaces where tablespace_name=’TEST1_TABLESPACE’;
设置只读或可读写状态:alter tablespace tablespace_name READ ONLY/READ WRITE;(默认是可读写状态)
alter tablespace test1_tablespace read write;
select status from dba_tablespaces where tablespace_name=’TEST1_TABLESPACE’;
修改数据文件:增加数据文件、删除数据文件
增加数据文件:alter tablespace tablespace_name add datafile ‘filename.dbf’ SIZE xx;
(在已创建的表空间上增加数据文件)
删除数据文件:alter tablespace tablespace_name drop datafile ‘filename.dbf’;
(不能删除表空间的第一个创建的数据文件,如果要删除的话,我们需要把整个表空间删掉)
例如:alter tablespace test1_tablespace add datafile ‘test2_datafile.dbf’ size 10m;
select file_name from dba_data_files where tablespace_name=’TEST1_TABLESPACE’;
alter tablespace test1_tablespace drop datafile ‘test2_datafile.dbf’;
select file_name from dba_data_files where tablespace_name=’TEST1_TABLESPACE’;
删除表空间:
drop tablespace tablespace_name (including contents)
说明:如果删除表空间,不删除数据文件
drop tablespace tablespace_name
如果删除表空间,并删除数据文件
drop tablespace tablesapce_name (including contents)
例如:drop tablespace test1_tablespace including contents;
