oracle 表空间管理相关(原创)

通过以下几步基本可以查看表空间情况以及处理表空间不足问题。

ASM相关

查看asm空间

select group_number,name,total_mb,free_mb from v$asm_diskgroup;

表空间相关

表空间使用率

注:对于12c多租户数据库,需要先切换至你需要查询的pdb下

方案一:
set linesize
set pages
col TABLESPACENAME for a30
select substr(a.TABLESPACE_NAME,,) TablespaceName,
sum(a.bytes//) as "Totle_size(M)",
sum(nvl(b.free_space1//,)) as "Free_space(M)",
sum(a.bytes//)-sum(nvl(b.free_space1//,)) as "Used_space(M)",
round((sum(a.bytes//)-sum(nvl(b.free_space1//,)))
*/sum(a.bytes//),) as "Used_percent%" from dba_data_files a,(select sum(nvl(bytes,)) 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
SEt pagesize
col file_name format a80
col TABLESPACE_NAME for a30
select tablespace_name,file_id,status,bytes// FileSizeM,file_name from dba_data_files order by tablespace_name;

查看表空间的扩展方式

set linesize
select TABLESPACE_NAME, BLOCK_SIZE, EXTENT_MANAGEMENT, SEGMENT_SPACE_MANAGEMENT
from dba_tablespaces;

查看数据文件扩展方式

set linesize
set pagesize
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
set pages
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;
上一篇:MYSQL索引类型+索引方法


下一篇:[docker]使用quaaga实现(rip ospf)实现主机间容器互通