今天在用户kf下面删除一条数据时:
delete from kf_gongnengtx where texingid=2736;
报错:
ORA-01536: space quota exceeded for tablespace 'TS_HIS3'
根据网上资料,该问题是由于用户在使用表空间时候受到了权限的限制.
解决方案很简单,修改这个用户的使用这个表空间的空间的权限就可以了
oracle提供二种方法:
1. Increase the tablespace quota allocated to that user or role by using the following command(即增加具体的大小限额):
ALTER USER <username> QUOTA <integer> [K/M] ON <tablespacename>
2. suggest QUOTA UNLIMITED(即去掉配额限制,unlimited,推荐使用这种,否则当第一个方法用后,如果再不够,那岂不是要再进行分配限额!):
ALTER USER <username> QUOTA UNLIMITED ON <tablespacename>
方法2的另外一种写法:
grant unlimited tablespace to <username>;
于是在sqlplus下面以sysdba权限登陆操作:
SQL> grant unlimited tablespace to kf;
Grant succeeded.
SQL> delete from kf_gongnengtx where texingid=2736;
1 row deleted
操作成功,问题解决!
本来到这里也告一段落,结果在一篇文章上面(http://www.dbasupport.com/forums/archive/index.php/t-47410.html)发现产生这个问题可能与role是DBA和RESOURCE被revoke有关,
里面有一段关键的话:
UNLIMITED TABLESPACE is kind of "wierd" system privilege. It is not granted to any role (and in fact it CAN NOT BE GRANTED to any role!), yet when you grant some powerfull roles (like DBA and I think RESOURCE too - it might even be version dependand AFAIK) to user, Oracle "silently" adds that UNLIMITED TABLESPACE privilege to that user directly. And when you revoke such role from user, Oracle silently revokes UNLIMITED TABLESPACE privilege from user too!
Now, when someone gets UNLIMITED TABLESPACE granted, it doesn't meen taht quotas on all tablespaces are set to unlimited to him. His quotas on tablespaces remain exactly the same - if he had quota 0 on tablespace USERS before, he still has quota 0 on that tablespace now. But when he has UNLIMITED TABLESPACE privilege, this takes priority over any quota settings and therefore he will be able to use space in that tablespace for new extents. However, if you later revoke UNLIMITED TABLESPACE from that user, his quota 0 will be put in effect and he will no longer be able to use any additional available space from tablespace USERS.
继续深入:
在metalink上面找到ORA-01536 After Revoking DBA Role [ID 465737.1]的文档,原来grant 或者revoke role DBA 或者 RESOURCE会导致该问题,然后我做了metalink上面的实验,果然如此,当你revoke DBA from <username>或者revoke resource from <username>时,如果空间不够,就会产生该问题
下面是相关描述:
ORA-01536: space quota exceeded for tablespace '<Tablespace_Name>'
After revoking DBA or Resource Role from a user
Example:
SQL> conn /as sysdba
Connected.
SQL> create user testrights identified by testos;
User created.
SQL> grant connect, resource to testrights;
Grant succeeded.
SQL> connect testrights/testos;
Connected.
SQL> CREATE TABLE "TESTRIGHTS"."TESTTAB" ( "TESTFIELD" VARCHAR2(200) NOT NULL
, CONSTRAINT "TESTPK" PRIMARY KEY ("TESTFIELD") VALIDATE ) TABLESPACE "USERS" STORAGE ( INITIAL 64M) ;
Table created.
SQL> conn /as sysdba
Connected.
SQL> grant dba to testrights;
Grant succeeded.
SQL> revoke dba from testrights;
Revoke succeeded.
SQL> show user
USER is "SYS"
SQL> drop table testrights.testtab;
Table dropped.
SQL> conn testrights/testos;
Connected.
SQL> CREATE TABLE "TESTRIGHTS"."TESTTAB" ( "TESTFIELD" VARCHAR2(200) NOT NULL
, CONSTRAINT "TESTPK" PRIMARY KEY ("TESTFIELD") VALIDATE ) TABLESPACE "USERS" STORAGE ( INITIAL 64M) ;
CREATE TABLE "TESTRIGHTS"."TESTTAB" ( "TESTFIELD" VARCHAR2(200) NOT NULL ,
CONSTRAINT "TESTPK" PRIMARY KEY ("TESTFIELD") VALIDATE ) TABLESPACE "USERS"
STORAGE ( INITIAL 64M)
*
ERROR at line 1:
ORA-1536: space quota exceeded for tablespace 'USERS'
SQL> conn /as sysdba
Connected.
SQL> grant connect, resource to testrights;
Grant succeeded.
SQL> conn testrights/testos;
Connected.
SQL>
SQL> CREATE TABLE "TESTRIGHTS"."TESTTAB" ( "TESTFIELD" VARCHAR2(200) NOT NULL , CONSTRAINT "TESTPK" PRIMARY KEY ("TESTFIELD") VALIDATE ) TABLESPACE "USERS"
STORAGE ( INITIAL 64M) ;
Table created.
This issue has been discussed in Bug 6494010.
The behavior seen in the above example is expected and not a bug
When roles were first introduced into Oracle in 7.0, the old Oracle V6 privileges of RESOURCE and DBA were migrated to use the new role functionality. But because the RESOURCE and DBA roles are not allowed to be granted UNLIMITED TABLESPACE, in order to preserve the backwards compatibility with V6, the parser automatically transforms statements such that "grant resource to abc" automatically becomes "grant resource, unlimited tablespace to abc" and "revoke resource from abc" automatically becomes "revoke resource, unlimited tablespace from abc". The same is true when granting and revoking the DBA role. This behaviour used to be well documented in the SQL reference guide which read:
To Resolve this issue you need to :
1] Grant DBA or Resource Role back to the user from whom it was revoked.