oracle 表空间 相关

查看当前表空间:

select * from dba_tablespaces;


查看剩余表空间:

select tablespace_name,file_id,block_id,bytes/1024/1024,blocks from dba_free_space; 

查询数据文件名称、大小和路径的信息:
select tablespace_name,file_id,bytes/1024/1024,file_name from dba_data_files; 

以MB的形式表示空间大小:bytes/1024/1024


创建表空间:

create tablespace test01
datafile 'D:\ORACLE\ORADATA\ORCL\test01.DBF' size 500M
extent management local
autoallocate
segment space management auto;

select * from dba_tablespaces where tablespace_name = 'TEST01'  

在Linux下,datafile '/oracle/oradata/orcl/test01.dbf'

Oracle关键字 不区分大小写,数据区分大小写


增加表空间的大小:

alter tablespace test01
add datafile 'D:\ORACLE\ORADATA\ORCL\test01.DBF' size 650M;

alter tablespace TEST01 
add datafile 'D:\ORACLE\ORADATA\ORCL\test01.DBF' size 650M
autoextend on 
next 10M
maxsize 1000M

增加数据文件的大小:

alter database datafile 'D:\ORACLE\ORADATA\ORCL\data_01.DBF'

删除表空间:

#表空间中包括 表或者索引 下面的命令将会出错
drop tablespace test01;

#下面的命令删除表空间和表空间的所有对象,但不能删除物理文件
drop tablespace test01 including contents;

#连同数据文件一起删除
drop tablespace test01 including contents and datafiles;


重命名表空间:

alter tablespace test02 rename to test01;

只读表空间:

alter tablespace test01 read only
alter tablespace test01 read write;

进行只读的操作时,表空间状态如下图:status变成read only

select tablespace_name, 
       block_size/1024, 
       initial_extent/1024,
       max_extents/1024/1024,
       extent_management,
       allocation_type, 
       status
    from dba_tablespaces
oracle 表空间 相关_第1张图片


BLOCK_SIZE:块空间大小,Oracle中数据存放的单位,默认为8K

INITIAL_EXTENT:区的初始化大小,默认为64K

MAX_EXTENTS:最大区大小,默认为2G

EXTENT_MANAGERMENT:区管理方式,本地管理,相对于10G之前的字典管理

ALLOCATION_TYPE:区尺寸 的分配,除TEMP表空间之外,其余都是自动分配


创建临时表空间:

create temporary 
tablespace temp_demo4 tempfile 'D:\ORACLE\ORADATA\ORCL\test04.DBF' size 200M 
autoextend on

#windows 默认位置:
如果temofile 'test04.dbf',默认防在下面的路径
$ORACLE_HOME\PRODUCT\10.2.0\DB_1\DATABASE\TEMP03.DBF


查看临时表空间:

select * from v$tempfile


更改临时表空间:

alter tablespace temp add tempfile 'D:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\TEMP05.DBF' size 500M reuse

重置一个临时文件的大小:

alter database tempfile 'D:\ORACLE\ORADATA\ORCL\test04.DBF' resize 255M

收缩临时表空间:






1.区管理

oracle 需要增加尺寸的时候,空间就以区的方式添加给对象

区的尺寸管理有两种选择:

  • 数据库自动选择区尺寸 : 通过AUTOALLOCATE选项  -----这是表空间区管理的默认选项
  • 指定表空间统一尺寸区方式管理 :通过UNIFORM选项

UNIFORM选项,需要使用SIZE字句指定区的实际尺寸 ,如果省略SIZE子句,默认1MB统一尺寸创建区

Oracle区尺寸 选择:小段64KB   中段1MB  大段64MB


2.段管理

  • 手动段空间管理 :MANUAL
使用可用列表(Free List)和一对存储参数(PCTFREE和PCTUSED)
  • 自动段空间管理 :AUTO     

使用位图管理

select initial_extent,next_extent,extent_management,allocation_type,
       segment_space_management from dba_tablespaces



你可能感兴趣的:(oracle 表空间 相关)