查看表空间利用率及相关及脚本

-- 查看表空间利用率

select
b.file_id file_id,
b.tablespace_name,
b.bytes,
b.maxbytes,
(b.bytes-sum(nvl(a.bytes,0))) used,
sum(nvl(a.bytes,0)) unused,
sum(nvl(a.bytes,0))/(b.bytes)*100 percentage
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_id,b.bytes,b.maxbytes
order by b.file_id;

or

select tablespace_name,sum(bytes)/1024/1024/1024 GB
from dba_data_files group by tablespace_name
union all
select tablespace_name,sum(bytes)/1024/1024/1024 GB
from dba_temp_files group by tablespace_name order by GB;

-- 查看数据文件表空间的对应关系

select t.name,t1.name
 from v$tablespace t,
    v$datafile t1
 where t.ts# = t1.ts#
;

-- 创建表空间

1.表空间

create tablespace tablespacename datafile 'datafilepath/datafilename ' size 10g;

--删除

drop tablespace tablespacename including contents and datafiles;--删除表空间及操作系统的数据文件

2.临时表空间

create temporary tablespace TEMP2 TEMPFILE ''/home2/oracle/oradata/sysmon/temp02.dbf'' SIZE 10

g;

-- 删除

drop tablespace temp including contents and datafiles;--删除临时表空间及操作系统的数据文件

3.undo表空间

create undo tablespace undotbs_01
 datafile '/u01/oracle/rbdb1/undo0201.dbf' size 2g;

-- 我们创建表空间时要以tbs_业务类型进行命名.

 

你可能感兴趣的:(查看表空间利用率及相关及脚本)