Oracle表空间管理

1、永久性表空间
  • 创建表空间
        语法:系统默认值创建表空间
                  create tablespace 表空间名称
                  datafile '数据文件名称'
                   size  数据文件大小
        例子:
                  create tablespace test01
                  datafile  '/home/oracle/app/oracle/oradata/orcl/t01.dbf'
                  size 100M

        语法:自定义值创建表空间
                  create tablespace 表空间名称
                 datafile '数据文件名称'
                  size 数据文件大小
                  extend management local
                  autolocation 分配大小
                  segment space management  参数2

                 备注: 参数2:auto、manual

       例子:
               create tablespace test02
               datafile '/home/oracle/app/oracle/oradata/orcl/t02.dbf'
               size 200M
               extend management local 
               autolocation 10M
               segment space management auto                
  • 删除表空间
         语法:drop tablespace 表空间名称
                    including contents
                   and datafiles
                   cascade constraints
        备注:including contents 表示删除对象
                  datafiles 表示删除数据文件
                  cascade constraints 表示级联删除索引、约束等
        例子:
                  drop tablespace test02
                  including contents
                  and datafiles
                  cascade contraints
       备注:如果只删除数据文件,alter tablespace 表空间名称 drop datafile 数据文件名称
                 
  • 修改表空间
         语法:增加表空间容量--增加数据文件数量
                    alter tablespace 表空间名称
                    add datafile '数据文件名称'
                    size  数据文件大小
          例子:alter tablespace test01
                     add  datafile '/home/oracle/app/oracle/oradata/orcl/t01_01.dbf'
                     size 100M
          语法:增加表空间容量--修改数据文件大小
                    alter database  数据文件名称
                     size 数据文件大小
          例子:alter database '/home/oracle/app/oracle/oradata/orcl/t01_01.dbf'
                     size 200M
           语法:重命名表空间
                     alter tablespace 表空间名称 rename to 新表空间名称
           例如:alter tablespace test01 rename to test01_01
           语法:重命名数据文件
                      先表空间脱机,在重命名操作系统中的数据文件,最后重命名数据库中的数据文件
                     脱机命令:alter tablespace 表空间名称 offline 脱机方式
                     联机命令:alter tablespace 表空间名称 online
                    重命名操作系统中数据文件:mv 数据文件名  新数据文件名称
                    重命名数据库中的数据文件 :alter tablespace 表空间名称 rename datafile '数据文件名' to '新数据文件名'
          备注:脱机方式:normal、temporary、 immediate、for recorver
                  normal:对数据文件一边检查一边将他们脱机,如果表空间数据文件有错误,那么表空间所有数据文 件不能脱机
                  temporary:临时脱机,即使数据文件有错误也能脱机,然而当表空间联机时,需要介质恢复
                  immediate:立即脱机,不对数据文件做任何检查,当表空间联机时需要介质恢复,在非日志归档模式不能脱机
                  for recovery :将在恢复集中的数据库表空间脱机,以便进行时间点恢复  
        例如:alter tablespace test01 offline normal
                     mv /home/oracle/app/oracle/oradata/orcl/t01.dbf /home/oracle/app/oracle/oradata/orcl/t01_01.dbf;
                     alter tablespace test01
                          rename datafile '/home/oracle/app/oracle/oradata/orcl/t01.dbf'
                         to '/home/oracle/app/oracle/oradata/orcl/t01_01.dbf';
                     alter tablespace test01 online
          备注:查询表空间状态:select tablespace_name,status from dba_tablespaces;
                     查询表空间相关的数据文件      
                 select ts.ts#,ts.name,df.name  from v$tablespace ts,v$datafile df  where ts.ts#=df.ts#
  • 查询表空间
           涉及到表v$datafile,dba_tablespaces,v$tablespace
            select ts.ts#,ts.name,df.name
           from v$tablespace ts,v$datafile df
            where ts.ts#=df.ts#

2、临时表空间
  • 创建表空间
        语法:create temporary tablespace 表空间名称
                   tempfile '临时数据文件名称'
                   size 文件大小
       例子:create temporary tablespace temp01
                  tempfile '/home/oracle/app/oracle/oradata/orcl/temp01_01.dbf'
                  size 100M;
  • 删除表空间
         语法:drop tablespace 表空间名称
                    including contents
                   and datafiles
                   cascade constraints
        备注:including contents 表示删除对象
                  datafiles 表示删除数据文件
                  cascade constraints 表示级联删除索引、约束等
        例子:
                  drop tablespace test02
                  including contents
                  and datafiles
                  cascade contraints
  • 修改表空间
        语法:增加临时表空间容量---增加临时数据文件数量
        alter tablespace 表空间名称  
          add  tempfile '数据文件名称'  
           size 数据文件大小

      例子:alter tablespace temp01
                   add tempfile '/home/oracle/app/oracle/oradata/orcl/temp01_02.dbf'
                   size 100M;

       语法:增加临时表空间容量---增加单个数据文件大小
        alter database 表空间名称 tempfile '数据文件名' size 数据文件大小
       例子:alter database temp01 
                   tempfile '/home/oracle/app/oracle/oradata/orcl/temp01_02.dbf'
                  size 100M;

     语法:减小临时表空间容量
         alter tablespace 表空间名称 shrink space  (默认减小到1M)
         alter tablespace 表空间名称 shrink space keep 空间大小
     例子:alter tablespace temp01 shrink space keep 10M;

   语法:修改默认表空间
   alter database default temporary tablespace 表空间名称
   例子:alter database default temporary tablespace temp01
   备注:查询默认表空间select property_name,property_vlaue from database_properties 
                                   where property_name='DEFAULT_TEMP_TABLESPACE'
  • 查询表空间
    涉及到的表dba_tablespaces 、v$tempfile
  select tablespace_name from dba_tablespaces
 select name ,bytes from v$tempfile;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值