【oracle】表空间的延迟分配

版权声明:原创手打 转载请注明来源 https://blog.csdn.net/qq_42774325/article/details/81948349

表空间的延迟分配

  1. 登录sys
    conn / as syadba
     
     
  2. 打开表空间的延迟分配
    alter system ser deferred_segment_creation = true;
     
     
  3. 删除之前创建的表空间及文件
    drop tablespace tbs3 including contents and datafiles;
     
     
  4. 创建表空间
    create tablespace tbs3
    datafile
    ‘/u02/app/oracle/oradata/orcl/tbs301.dbf’ size 10M reuse logging
    segment space management auto
    extent management local autoallocate;
     
     
  5. 创建一个名为u3的用户设置密码为oracle,设置表空间为tbs3,临时表空间为temp;
    create user u3 identified by oracle default tablespace tbs3 temporary tablespace temp;
     
     
  6. 授予表空间connect,resource,unlimited tablespace三个权限
    grant connect,resource,unlimited tablespace to u3;
     
     
  7. 登录u3 查询信息
    select object_name,object_type from user_objects;
    查询对象,这里为空说明用户下数据库中还没表
    select segment_name from user_segments;
    查询段信息,这里为空因为还没有段
     
     
  8. 创建一个表名为t3,再查看段信息
    create table t3 (id number(3),name varchar2(100));
    select segment_name from user_segments;
    因为开启了表空间延迟分配,所以表中没数据时,没有给表分配空间,也查不到段信息
     
     
  9. 向表中插入数据后,再查看段信息
    insert into t3 values(1,’aaaaaa’);
    select segment_name from user_segments;
    当向表中插入数据以后,系统就给表分配了空间,这样就能查到段信息了
     
  10. 切换到sys用户,关闭表空间的延迟分配
    conn / as sysdba
    alter system set deferred_segment_creation = false;
     
     
  11. 此时再回到用户u3创建一个表,看不插入数据是否能查询到段信息
    conn u3
    create table t4 (id number(3),name varchar2(100));
    select segment_name from user_segments;
    如图可看出,关闭表空间的延迟分配后,不插入数据也能查到段信息了
     
     

猜你喜欢

转载自blog.csdn.net/qq_42774325/article/details/81948349
今日推荐