Wednesday, July 4, 2012

ORA-01536: space quota exceeded for tablespace

One of our testing database schema got this error.
It means that users is trying to use more space than the Database Administrator assigned to him. Quota is a maximum number of bytes that a user can allocate in particular tablespace. Implementing quotas in database is a reasonable approach because it prevents buggy or malicious code to fill the tablespace.
Database Administrators should remember that after they setup quotas for users they are responsible for constantly monitoring and extending quotes if required.
ORA-01536: space quota exceeded for tablespace is a common error in Oracle Database.
It is worth to mentioned that prior to Oracle 11g quotas in Oracle could be assigned to both permanent and temporary tablespaces. Starting from Oracle 11g quotas can only be set on permanent tablespaces.
here is a solution to fix this error.
first we need to check the usage of quota and allocated quota in dictionary views, use the below query to check the usage and allocation.
connect  to a database with system privileged user. 
sql>select TABLESPACE_NAME,USERNAME,BYTES/1048576 used_bytes,MAX_BYTES/1048576 allocated_bytes from dba_ts_quotas where username='your_problem_facing_username';
in the results if u get allocated and used bytes are equal then you have to allocate more bytes of quota to that particular user.
The below syntax tells how to allocate quota to a particular user.
sql> alter user  username quota bytes(in mb, gb) on tablespace_name;
example:- sql>alter user user1 quota 25m on user;
the above example allocates 25 mb of quota (space)  to user1 in user tablespace.