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