Oracle表空间扩展


一、查看表空间及其数据文件位置(file_name)

SELECT tablespace_name
,file_id
,file_name
,round(bytes / (1024 * 1024), 0) total_MB
FROM dba_data_files
ORDER BY tablespace_name;

二、表空间扩展的三种方式

1. 更改数据文件

alter tablespace 表空间名称 add datafile ‘新的数据文件位置’ size 数据文件大小;
举例:

SQL> 
alter tablespace CUX_ARCH add datafile ‘/erp/TEST/db/data/cux_arch_02.dbf’ size 16000M;
SQL> 
alter tablespace CUX_ARCH add datafile ‘/erp/TEST/db/data/cux_arch_02.dbf’ size 16G;

2. 增加数据文件

alter tablespace 表空间名称 add datafile ‘新的数据文件位置’ size 数据文件大小;举例:

SQL> 
alter tablespace CUX_ARCH add datafile ‘/erp/TEST/db/data/cux_arch_02.dbf’ size 16000M;
SQL> 
alter tablespace CUX_ARCH add datafile ‘/erp/TEST/db/data/cux_arch_02.dbf’ size 16G;

3. 设置自动扩展

alter database datafile ‘数据文件位置’ autoextend on next 自动扩展大小 maxsize 最大扩展;
举例:

SQL> 
alter database datafile ‘/erp/TEST/db/data/cux_arch_03.dbf’ autoextend on next 1000M maxsize 16000M;

三、查看表空间使用情况:

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 5 DESC;

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注