[oracle]表空间情况查看占用扩容使用情况空间维护等操作
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[oracle]表空间情况查看占用扩容使用情况空间维护等操作相关的知识,希望对你有一定的参考价值。
--查询表空间使用情况
SELECT Upper(F.TABLESPACE_NAME) "表空间名",
D.TOT_GROOTTE_MB "表空间大小(M)",
D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
To_char(Round(( D.TOT_GROOTTE_MB - F.TOTAL_BYTES ) / D.TOT_GROOTTE_MB * 100, 2), ‘990.99‘)
|| ‘%‘ "使用比",
F.TOTAL_BYTES "空闲空间(M)",
F.MAX_BYTES "最大块(M)"
FROM (SELECT TABLESPACE_NAME,
Round(Sum(BYTES) / ( 1024 * 1024 ), 2) TOTAL_BYTES,
Round(Max(BYTES) / ( 1024 * 1024 ), 2) MAX_BYTES
FROM SYS.DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F,
(SELECT DD.TABLESPACE_NAME,
Round(Sum(DD.BYTES) / ( 1024 * 1024 ), 2) TOT_GROOTTE_MB
FROM SYS.DBA_DATA_FILES DD
GROUP BY DD.TABLESPACE_NAME) D
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
ORDER BY 1;
-- 查看表空间对象占用情况
Select Segment_Name "段名",
Segment_Type "段类型",
TableSpace_Name "表空间",
Sum(bytes) / 1024 / 1024 "空间占用(MB)"
From User_Extents
Group By Segment_Type, Segment_Name, TableSpace_Name
order by Sum(bytes) / 1024 / 1024 desc;
--查询表空间的free space
select tablespace_name, count(*) AS extends,round(sum(bytes) / 1024 / 1024, 2) AS MB,sum(blocks) AS blocks from dba_free_space group BY tablespace_name;
--查询表空间的总容量
select tablespace_name, sum(bytes) / 1024 / 1024 as MB from dba_data_files group by tablespace_name;
--查询表空间使用率
SELECT total.tablespace_name,
Round(total.MB, 2) AS Total_MB,
Round(total.MB - free.MB, 2) AS Used_MB,
Round(( 1 - free.MB / total.MB ) * 100, 2)
|| ‘%‘ AS Used_Pct
FROM (SELECT tablespace_name,
Sum(bytes) / 1024 / 1024 AS MB
FROM dba_free_space
GROUP BY tablespace_name) free,
(SELECT tablespace_name,
Sum(bytes) / 1024 / 1024 AS MB
FROM dba_data_files
GROUP BY tablespace_name) total
WHERE free.tablespace_name = total.tablespace_name;
-- 查看表空间使用情况
select sum(bytes/1024/1024) sizeMB from dba_free_space z where z.tablespace_name=‘DATA6‘;
-- 查看索引表空间占用
select s.index_name,
s.table_name,
s.tablespace_name,
s.initial_extent,
s.next_extent
from user_indexes s
where s.index_name = ‘PK_LOG_INTER_CALLED_DETAIL‘;
-- 查看表空间文件
select file_name,tablespace_name,bytes/1024/1024 from dba_data_files where tablespace_name=‘USERS‘;
-- 查看表空间剩余
select sum(bytes/1024/1024) sizeMB from dba_free_space z where z.tablespace_name=‘USERS‘;
-- 修改表空间文件大小
alter database datafile ‘/home/oracle/oradata/easyweb/data3_01.dbf‘ resize 10000M MAXSIZE UNLIMITED;
alter database datafile ‘/home/oracle/oradata/easyweb/data6_01.dbf‘ AUTOEXTEND ON NEXT 200M MAXSIZE UNLIMITED;
-- 查看所有表空间文件
SELECT FILE_NAME,TABLESPACE_NAME,AUTOEXTENSIBLE FROM dba_data_files;
-- 设置表空间自动增加
ALTER DATABASE DATAFILE ‘/data/oradata/easyweb/users01.dbf‘ AUTOEXTEND ON; --打开自动增长
ALTER DATABASE DATAFILE ‘/data/oradata/easyweb/users01.dbf‘ AUTOEXTEND ON NEXT 200M ; --每次自动增长200m
ALTER DATABASE DATAFILE ‘/home/oracle/oradata/easyweb/users01.dbf‘ AUTOEXTEND ON NEXT 200M MAXSIZE 10000M; --每次自动增长200m,数据表最大不超过1G
--MAXSIZE UNLIMITED;
--一个表空间最大为32g,超过32g需要增加,例如:
alter tablespace ZSK ADD datafile ‘/mc_data/oradata/zsk/zsk_01.dbf‘ SIZE 30G;
以上是关于[oracle]表空间情况查看占用扩容使用情况空间维护等操作的主要内容,如果未能解决你的问题,请参考以下文章