oracle 表空间管理相关
通过以下几步基本可以查看表空间情况以及处理表空间不足问题。
ASM相关
查看asm空间
select group_number,name,total_mb,free_mb from v$asm_diskgroup;
表空间相关
表空间使用率
注:对于12c多租户数据库,需要先切换至你需要查询的pdb下
方案一:
set linesize 200 set pages 2000 col TABLESPACENAME for a30 select substr(a.TABLESPACE_NAME,1,30) TablespaceName, sum(a.bytes/1024/1024) as "Totle_size(M)", sum(nvl(b.free_space1/1024/1024,0)) as "Free_space(M)", sum(a.bytes/1024/1024)-sum(nvl(b.free_space1/1024/1024,0)) as "Used_space(M)", round((sum(a.bytes/1024/1024)-sum(nvl(b.free_space1/1024/1024,0))) *100/sum(a.bytes/1024/1024),2) as "Used_percent%" from dba_data_files a,(select sum(nvl(bytes,0)) free_space1,file_id from dba_free_space group by file_id) b where a.file_id = b.file_id(+) group by a.TABLESPACE_NAME order by "Used_percent%";
方案二:(包含了临时表空间) select * from ( Select a.tablespace_name, to_char(a.bytes/1024/1024,'99,999.999') total_bytes, to_char(b.bytes/1024/1024,'99,999.999') free_bytes, to_char(a.bytes/1024/1024 - b.bytes/1024/1024,'99,999.999') use_bytes, to_char((1 - b.bytes/a.bytes)*100,'99.99') || '%' use from (select tablespace_name, sum(bytes) bytes from dba_data_files group by tablespace_name) a, (select tablespace_name, sum(bytes) bytes from dba_free_space group by tablespace_name) b where a.tablespace_name = b.tablespace_name union all select c.tablespace_name, to_char(c.bytes/1024/1024,'99,999.999') total_bytes, to_char( (c.bytes-d.bytes_used)/1024/1024,'99,999.999') free_bytes, to_char(d.bytes_used/1024/1024,'99,999.999') use_bytes, to_char(d.bytes_used*100/c.bytes,'99.99') || '%' use from (select tablespace_name,sum(bytes) bytes from dba_temp_files group by tablespace_name) c, (select tablespace_name,sum(bytes_cached) bytes_used from v$temp_extent_pool group by tablespace_name) d where c.tablespace_name = d.tablespace_name );
查看数据文件
set linesize 300 SEt pagesize 500 col file_name format a80 col TABLESPACE_NAME for a30 select tablespace_name,file_id,status,bytes/1024/1024 FileSizeM,file_name from dba_data_files order by tablespace_name;
查看表空间的扩展方式
set linesize 120 select TABLESPACE_NAME, BLOCK_SIZE, EXTENT_MANAGEMENT, SEGMENT_SPACE_MANAGEMENT from dba_tablespaces;
查看数据文件扩展方式
set linesize 300 set pagesize 500 col FILE_NAME for a60 col TABLESPACE_NAME for a30 select file_id,file_name,tablespace_name,autoextensible from dba_data_files order by file_id;
查看用户默认表空间
set lines 200 set pages 2000 col username for a20 col default_tablespace for a30 col temporary_tablespace for a30 select username, default_tablespace, temporary_tablespace from dba_users;
表空间、数据文件修改
进行表空间扩展
通过添加数据文件扩展表空间
alter tablespace users add datafile '+DATA/GNNT/DATAFILE/users08.dbf' SIZE 5G autoextend on NEXT 50M maxsize 31G; 建议11c rac数据库添加数据库文件不必自定义数据文件名,由数据库文件系统自动生成 alter tablespace users add datafile size xxxG;
修改数据文件大小
alter database datafile '+DATA/GNNT/DATAFILE/users08.dbf' RESIZE 10G;
修改数据文件的自动增长值
alter database datafile '+DATA/GNNT/DATAFILE/users08.dbf'autoextend on NEXT 5G;
关闭数据文件的自动增长
alter database datafile '+DATA/GNNT/DATAFILE/users08.dbf' autoextend off;
作者:运维·拖拉斯基
作者水平很低, 如果有错误及时指出, 如果你觉得本文写的好请点一波赞~(≧▽≦)/~
出处:https://www.cnblogs.com/-abm/
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。