ORA-01536:表空间不足

  当用户创建表或向已有的表中插入数据时,提示Ora-01536:表空间不足。用户使用grant resource,解决问题。这不是一种好的作法,特别是在8I及以前的版本的数据中。在理解这一点之前,我们先来看以下几个概念: 

  •     表空间(tablespace)        在逻辑组成上,数据库首先是由若干个表空间组成的。用来保存用户的各种对象,包括表、索引等等。用户在建立数据库对象时,可以指定保存的目标表空间,如果没有指定,将保存至创建用户时的默认表空间。在创建用户时,管理员可以指定默认表空间,如果不批定,系统将选择系统表空间为用户的默认表空间。
  •     系统表空间(system tablespace)        保存数据库数据字典信息、PL/SQL包、过程定义、序列、同义词、视图定义等。每个数据库都必须有一个系统表空间。为了减少系统表空间碎片的发生,用户的数据不应被保存在系统表空间。           
  •     限额(quota)        就如在UNIX操作系统中可以设定用户可使用的空间限制,在ORACLE中,也可以限定用户可使用空间的最大限额。管理员可以在创建用户时用QUOTA字句进行设定,也可以创建用户可用ALTER TABLE语句修改。
  •     角色(ROLE)        用户操作数据库必须有相应的权限。角色是一组数据库权限的集合。可以用GRANT语句授予用户角色的权限。其中RESOUCE角色有点特殊,它隐含了一个叫UNLIMITED TABLESPACE的数据库系统权限。一旦用户被授予此角色,用户将可以在任何表空间创建对象,不再受限额的限止,包括系统表空间(9I中已有所改变)。
  1.  

         
    现在我们重新回到主题。当用户使用授予RESOURCE角色时,他相应地就会冒一个可能在系统表空间建立对象的风险。下面的例子将为大家揭示隐含的问题:

  Code:[Copy to clipboard]  
        
     system@test816.world>create user rudolf identified by nix
       2  /        
      
     User created.
      
     system@test816.world>grant connect to rudolf;
      
     Grant succeeded.
      
     system@test816.world>alter user rudolf quota 1M on tools;
      
     User altered.
      
     system@test816.world>connect rudolf/nix     
     Connected.     
     rudolf@test816.world>create table t (id number) storage (initial 2M) tablespace tools;
     create table t (id number) storage (initial 2M) tablespace tools
     *
     ERROR at line 1:
     ORA-01536: space quota exceeded for tablespace 'TOOLS'

很好,我们碰到了问题:

  Code:[Copy to clipboard]  

     rudolf@test816.world>connect system/alibaba
     Connected.     
     system@test816.world>
     system@test816.world>
     system@test816.world>grant resource to rudolf
       2  /
      
     Grant succeeded.
      
     system@test816.world>connect rudolf/nix
     Connected.
     rudolf@test816.world>create table t (id number) storage (initial 2M)
       2  /
      
     Table created.
      
     rudolf@test816.world>

正如所料,授予RESOURCE权限后,一切正常,可是我们的麻烦也从此开始:

  Code:[Copy to clipboard]  

     rudolf@test816.world>select tablespace_name,table_name from user_tables where table_name = 'T';
      
     TABLESPACE_NAME                TABLE_NAME
     ------------------------------ ------------------------------
     SYSTEM                         T
      
     rudolf@test816.world>

由于疏忽或其实原因,在建表时,没有加上TABLESPACE子句,直接导致对象被创建在系统表空单,而这在ORACLE中是应当绝对的被避免的。为了避免些种情况,我们建议在建立用户时请务必作用default tablespace字句与quota字句,同时,如果您要授予用户RESOURCE、DBA等隐含UNLIMITED TABLESPACE系统权限的角色时,请用REVOKE子句去掉unlimited tablespace 权限:

  Code:[Copy to clipboard]  
  
      system@test816.world>l
       1  create user rudolf
       2  identified by nix
       3  default tablespace tools           -- suggest,repace 'tools' with your own tablespace
       4  temporary tablespace temp          -- suggest
       5  quota 0 on system                  -- suggest
       6* quota unlimited on tools           -- suggest, you can have multiline such as this one, also replace 'unlimted', 'tools' as your need
     system@test816.world>/
      
     User created.
      
     system@test816.world>grant connect,resource to rudolf;
      
     Grant succeeded.
      
     system@test816.world>revoke unlimited tablespace from rudolf -- suggest
     /
      
     Revoke succeeded.        

如果用户已创建,可以:

  Code:[Copy to clipboard]  

     system@test816.world>alter user rudolf default tablespace tools
       2  quota 0 on system
       3  quota unlimited on tools        
       4  /
      
     User altered.

如果仅为解决ORA-01536错误,用户可以根据错误所示的表空间,看情况加大你的空间限额:

  Code:[Copy to clipboard]  

     rudolf@test816.world>create table t (id number) storage (initial 2M) tablespace tools;
     create table t (id number) storage (initial 2M) tablespace tools
     *
     ERROR at line 1:
     ORA-01536: space quota exceeded for tablespace 'TOOLS'

此处提示TOOLS表空间,因此:

  Code:[Copy to clipboard]  
   
       system@test816.world>alter user rudolf default tablespace tools
       2  quota 0 on system
       3  quota 10M on tools        
       4  /
      
     User altered.   
  
     system@test816.world>connect rudolf/nix
     Connected.
     rudolf@test816.world>create table t (id number) storage (initial 2M) tablespace tools
       2  /
      
     Table created.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值