oracle 管理表空间

表空间:是oracle数据库中最大的逻辑存储结构,与操作系统中的数据文件相对应,用于存储数据库中用户创建的所有内容

表空间>数据文件

4.1创建一个永久性表空间myspace

create tablespace myspace 

datafile 'F:oracleappmyspace.dbf'    //要有引号

size 20m

autoextend on next 5m      //指定自动增长 每次增长5m

maxsize 100m;     //最大为100m

4.2通过数据字典dba_tablespaces查看表空间myspace的部分属性

select tablespace_name,logging,allocation_type,extent_management,segment_space_management

from dba_tablespaces

where tablespace_name='MYSPACE';   //区分大小写

logging:表示是否为表空间创建日志记录

allocation_type :标识表空间的盘区大小的分配方式。字段值为system,自动分配

extent_management:标识表空间盘区的管理方式

segment_space_management:标识表空间中断的管理方式

表空间状态属性

1 online      只有为该状态,才允许访问该表空间中的数据     例如:alter tablespace myspace online;

2offline    不允许访问表空间中的数据  alter tablespace myspace offline parameter;

    parameter有4个参数

   normal 默认情况  

    temporary 可能需要对数据库进行恢复

    immediate 必须对数据库进行恢复  

    for recover 可以使用备份的数据文件覆盖原有的数据文件,然后再根据归档重做日志将表空间恢复到某个时间点的状态

3read only 

注意事项

   1表空间必须处于online状态

   2表空间不能包含任何事务的回退段

    3表空间不能正处于占线数据库备份期间

可以访问但仅限于阅读  alter tablespace myspace read only; 

4read write

  alter tablespace myspace read write;   需要保证表空间处于online状态

四.3 查看当前数据库中的表空间的状态

select tablespace_name ,status from dba_tablespaces;

status 有online,offline和read only

online表示在线且读写

offline离线

read only 表示在线且只读

四 重命名表空间

alter tablespace myspace rename to myspace2;   //这里myspace的状态属性为offline的话,就无法重命名表空间

四 修改表空间中的数据文件大小

通过dba_free_space查看表空的空间空闲信息

select tablespace_name,bytes,blocks

from dba_free_space            

where tablespace_name='MYSPACE';      

四 通过dba_data_files查看myspace表空间的数据文件信息

1看下表空间的空闲情况、

select tablespace,bytes,blocks       //bytes表示以位表示空闲空间大小,blocks以数据库的形式表示大小

from dba_free_space

where tablespace_name='MYSPACE';

2select tablespace_name,file_name,bytes

from dba_data_files

where tablespace_name='MYSPACE';    

//最好格式化下列

修改数据文件大小

alter database 

datafile  'F:oracleappmyspace.dbf'  resize 40m;

四 为myspace表空间增加两个新的数据文件

alter tablespace myspace

add datafile 

'F:oracleappmyspace.dbf2'

size 10m

autoextend on next 5m maxsize 100m;

四 删除表空间的数据文件

在需要时,也可以删除表空间的数据文件,但是该数据文件中不能包含数据

删除myspace表空数据文件

alter tablespace myspace

drop datafile 'F:oracleappmyspace.dbf2';

原文地址:https://www.cnblogs.com/yi-mi-yangguang/p/6706555.html