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

Oracle扩展表空间

查询表空间信息

-- 查询表空间信息
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;

Oracle扩展表空间

二、表空间扩展

表空间扩展

-- 表空间扩展 单位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

Original: https://www.cnblogs.com/aerfazhe/p/15838748.html
Author: 阿尔法哲
Title: Oracle扩展表空间

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/643450/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球