一、先查看数据库表空间
--查看空间占比
SELECT a.tablespace_name "表空间名",
a.bytes / 1024 / 1024 "表空间大小(M)",
(a.bytes - b.bytes) / 1024 / 1024 "已使用空间(M)",
b.bytes / 1024 / 1024 "空闲空间(M)",
round(((a.bytes - b.bytes) / a.bytes) * 100, 2) "使用比"
,a.max / 1024 / 1024 "允许增加的最大内存(M)"
FROM (SELECT tablespace_name, sum(bytes) bytes,sum(MAXBYTES) max
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, sum(bytes) bytes, max(bytes) largest
FROM dba_free_space
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name
ORDER BY ((a.bytes - b.bytes) / a.bytes) DESC;
“已使用空间”接近“允许增加的最大值”,则表示表空间不足。需要增加表空间。
二、查看表空间文件路径
select
tablespace_name,
file_id,
file_name,
autoextensible,
round(bytes/(1024*1024),0) total_space ,increment_by,MAXBYTES/(1024*1024)
from
dba_data_files
order by
tablespace_name;
三、增加指定表空间
假设SYSTEM 需要增加20G的表空间。
alter tablespace SYSTEM add datafile '/home/oracle/app/oracle/oradata/helowin/system01.dbf_20200102_20G' size 200m autoextend on next 10m maxsize 20480m
其中200m表示初始时该空间扩展的大小,往后按照10m来扩展,直到内存达到20480m(就是20G)
四、如果不想等到数据库每次空间不足是再去手动增加表空间,也可以把表空间设置为自动增长。
ALTER DATABASE DATAFILE '/home/oracle/app/oracle/oradata/helowin/system01.dbf' AUTOEXTEND ON NEXT <incremental size>;
ALTER TABLESPACE命令将指定的数据文件设置为自动增长模式,是每次自动增长时的递增量大小,单位可以是M或G。据系统性能和存储容量情况,合理调整自动增长参数。
注意事项:建议操作前做好数据备份。