ORA-08177: can't serialize access for this transaction
My Oracle Support Note : Insert Into Table Fails With ORA-08177 (Doc ID 160593.1)
•symptom: Insert into table fails •symptom: ORA-08177: can't serialize access for this transaction •symptom: transaction isolation level is serializable •symptom: The table has index definitions •symptom: Several transaction insert data into same table •cause: The problem manifest itself when there are indexes on the table to which the rows are being inserted. Without any indexes the problem will not reproduce
Concurrent inserts into a table with index using serializable transactions could lead to an index split that the transaction tries to re-read and cause an error ORA-08177
Reproduce the error
First, as use robla, create the test objects:
SQL> create table emp2 as select * from emp where rownum < 1; Table created. SQL> create index emp2_indx on emp2(empno); Index created.
In two separate SQL sessions, as user robla, enter the following commands, i.e. type each individual command on one session followed immediately on the other session. (Do not connect as sys as you can't set the transaction isolation level as sys):
-- Session 1: SQL_01> set transaction isolation level serializable; Transaction set. SQL> insert into emp2 select * from emp; 14 rows created.
-- Sesssion 2: SQL_02> set transaction isolation level serializable; SQL> insert into emp2 select * from emp; 14 rows created.
-- Session 1: SQL_01> set transaction isolation level serializable; Transaction set. SQL> insert into emp2 select * from emp; ERROR at line 1: ORA-08177: can't serialize access for this transaction
- Insert a smaller number of rows (e.g commit more often)
- or Catch the error code in the application and re-try the operation again
- this can be fixed by implementing "rowdependencies" during normal table creation.
Implement the 3rd solution
This rowdependencies clausechanges the default behavior of Oracle to put an SCN on everyrow within the tables, and not just one SCN for every physicaldata block. This adds a hidden column to each row, taking 6 bytes and storing the SCN on a row-by-row basis with your data. NOTE: This is a CREATE TABLE option only. You can’t modify a table to add rowdependencies, and there are a few restrictions for tables where this is enabled. Check the documentation for your version.