Oracle扩展表空间

Oracle扩展表空间

前言:

Oracle表空间扩展最大为32G,目前我还未找到可以打破限制的办法。

一、查看表空间信息和使用情况

查看表空间的名字及文件所在位置

-- 查看表空间的名字及文件所在位置
select tablespace_name,
file_id,
file_name,
round(bytes / (1024 * 1024), 0) total_space
from sys.dba_data_files
order by tablespace_name

查询表空间信息

-- 查询表空间信息
select username,default_tablespace,t.* from dba_users t

 

查询当前表空间下使用情况

-- 查询当前表空间下使用情况
select a.tablespace_name,
a.bytes / 1024 / 1024 "sum MB",
(a.bytes - b.bytes) / 1024 / 1024 "used MB",
b.bytes / 1024 / 1024 "free MB",
round(((a.bytes - b.bytes) / a.bytes) * 100, 2) "used%"
from (select tablespace_name, sum(bytes) bytes
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;

二、表空间扩展

表空间扩展

-- 表空间扩展 单位m
alter database datafile '表空间位置' resize 新的尺寸
-- 示例
alter database datafile '/vdb2/service/oracle/data/oracle/oradata/orcl/user04.dbf' resize 52100m

此时如果报错:ORA-01144: File size (5242880 blocks) exceeds maximum of 4194303 blocks

那就是前言说的超出最大限制了,如果此时的表空间已经最大化了,建议新增一个对应表空间的数据文件并设定大小

新增数据文件

-- 新增表空间
alter tablespace '表空间名称' add datafile '表空间位置' size '容量大小';
-- 示例
alter tablespace users add datafile '/vdb2/service/oracle/data/oracle/oradata/orcl/users06.dbf' size 32736m;
--删除空的表空间,但是不包含物理文件
drop tablespace tablespace_name;
--删除非空表空间,但是不包含物理文件
drop tablespace tablespace_name including contents;
--删除空表空间,包含物理文件
drop tablespace tablespace_name including datafiles;
--删除非空表空间,包含物理文件
drop tablespace tablespace_name including contents and datafiles;
--如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADE CONSTRAINTS
drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;

注意: 由于Oracle的Rowid中使用22位来代表Block号,这22位最多只能代表2^22-1(4194303)个数据块,而在我们一般情况下使用的数据块大小为8k,所以数据文件的理论大小最大为: 31.9999924G

 

posted @   阿尔法哲  阅读(1063)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示