• 表空间的创建、日常维护管理


    01 创建数据表空间

    本地管理的表空间:

    create tablespace test01 
      datafile '/oracle/oradata/orcl/test01a.dbf' 
      size 2m 
      autoextend off 
      segment space management auto;
    

      

    autoextend off —不自动扩展

    segment space management auto —自动段管理,推荐

    不自动扩展表空间

    CREATE TABLESPACE test02 LOGGING DATAFILE 
      '/oracle/oradata/orcl/test02a.dbf' SIZE 2M AUTOEXTEND OFF, 
      '/oracle/oradata/orcl/test02b.dbf' SIZE 2M AUTOEXTEND OFF 
      EXTENT MANAGEMENT LOCAL 
      SEGMENT SPACE MANAGEMENT AUTO;
    

      

    自动扩展表空间

    CREATE TABLESPACE test03 LOGGING DATAFILE 
        '/oracle/oradata/orcl/test03a.dbf' SIZE 2M AUTOEXTEND ON NEXT 1M MAXSIZE 20M, 
        '/oracle/oradata/orcl/test03b.dbf' SIZE 2M AUTOEXTEND ON NEXT 1M MAXSIZE 20M 
        EXTENT MANAGEMENT LOCAL 
        SEGMENT SPACE MANAGEMENT AUTO;
    

      

     创建大表空间:

    CREATE BIGFILE TABLESPACE bigtbs DATAFILE 
        '/u02/oracle/data/bigtbs01.dbf' SIZE 50G;
    

      

    02 创建临时表空间

    create temporary tablespace temp1 
        tempfile '/oracle/oradata/orcl/temp1.dbf' size 5m autoextend off;
    

      

    03 创建UNDO表空间

    create undo tablespace testundo1 
        datafile '/oracle/oradata/orcl/testundo1.dbf' size 2m autoextend off;
    

      

    04 表空间的扩展与修改大小

    表空间添加数据文件

    alter tablespace temp1 
        add tempfile '/oracle/oradata/orcl/temp1b.dbf' size 5m autoextend off;
    

      

    alter tablespace test01 
        add datafile '/oracle/oradata/orcl/test01b.dbf' size 1m autoextend off;
    

      

    修改表空间文件大小

    alter database 
        datafile '/oracle/oradata/orcl/test02b.dbf' resize 2m;
    

      

    select name, bytes from v$tempfile;
    

      

    alter database 
        tempfile '/oracle/oradata/orcl/temp1.dbf' resize 5m;
    

    05 表空间重命名

    ALTER TABLESPACE test03 RENAME TO test04;
    

      

    06 删除表空间

    drop tablespace testundo1; -- 直接删除表空间,而不删除对应的数据文件
    

      

    drop tablespace test04 including contents and datafiles; --加上该选项 则连同数据文件 一起删除了
    

      

    如果出现:ORA-02449: unique/primary keys in table referenced by foreign keys

    select p.owner,
    
      p.table_name,
    
      p.constraint_name,
    
      f.table_name referencing_table,
    
      f.constraint_name foreign_key_name,
    
      f.status fk_status
    
    from dba_constraints P,
    
      dba_constraints F,
    
      dba_tables T
    
    where p.constraint_name = f.r_constraint_name
    
      and f.constraint_type = 'R'
    
      and p.table_name = t.table_name
    
      and t.tablespace_name = UPPER('&tablespace_name')
    
    order by 1,2,3,4,5;
    

      

    删除表空间和对应的表空间文件

    drop tablespace test04 including contents and datafiles cascade constraints;
    

      

    07 更改表空间的读写模式

    alter tablespace test01 read only; --test01表空间只读
    alter tablespace test01 read write;--test01表空间可读写

      

    查看表空间的状态

    select tablespace_name,status from dba_tablespaces;
    

      

    表的读写模式

    alter table test read only;--让表只读
    alter table test read write;--让表可读写
    

      

    08 更改表空间的在线模式

    alter tablespace users offline;--离线user表空间
    
    alter database datafile 6 offline;--离线6号数据文件
    
    alter database datafile 6 offline for drop;--离线6号数据文件,并需要恢复
    
    alter database datafile 6 online;--使6号文件在线
    
    recover datafile 6;--恢复6号文件
    

       

  • 相关阅读:
    CentOS 6.5 源码安装subversion-1.8.8,附加mod_dav_svn模块
    MySQL建表设置外键提示错误
    Servlet3.0提供的异步处理
    Servlet3.0使用@WebServlet注解配置问题记录
    我的博客开通啦!
    关于Wii的蓝牙接收
    关于Wii的软件制作
    提升学习算法简述:AdaBoost, GBDT和XGBoost
    决策树中的熵和基尼指数
    机器学习排序算法:RankNet to LambdaRank to LambdaMART
  • 原文地址:https://www.cnblogs.com/black-start/p/11021675.html
Copyright © 2020-2023  润新知