ORA-01950 On Insert but not on Create Table

Sounds weird creating table does not raise any error, but inserting a correct tuple in this table raise a permission error, right? Just take a look:

SQL> create table matheusdba.table_test(a number) tablespace TEST_TABLESPACE;
Table created.
SQL> insert into matheusdba.table_test values (1);
insert into matheusdba.table_test values (1)
*
ERROR at line 1:
ORA-01950: no privileges on tablespace 'TEST_TABLESPACE'

It probably it’s a new user or a tablespace for which user doesn’t has quota. But why table creation doesn’t result in error but only on inserting?

Certainly the database is 11.2 or above, because this mechanism are related to deferred_segment_creation, introduced in this release. This parameter is default setted for true, and means that the segments for tables and their dependent objects (LOBs, indexes) will not be created until the first row is inserted into the table.
So, only when allocating segment for the first insert database will check privileges on tablespace.

It’s a good way to save space. But it causes too some situations when exporting with EXP, like described here.

Anyway, I think Oracle could implement segment validation when create table, it’ll avoid a lot of misunderstanding…
Now, create a table doesn’t implies in the insert will happen successfully, unless you disable the deferred_segment_creation and bring back the behavior from earlier versions:

SQL> show parameters deferred
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
deferred_segment_creation            boolean     TRUE
SQL> alter system set deferred_segment_creation=FALSE;
System altered.
SQL> create table matheusdba.table_test2(a number) tablespace TEST_TABLESPACE;
create table matheusdba.table_test2(a number) tablespace TEST_TABLESPACE
*
ERROR at line 1:
ORA-01950: no privileges on tablespace 'TEST_TABLESPACE'

See ya!
Matheus.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s