Difference between revisions of "ORA-08177: can't serialize access for this transaction"

From Robs_Wiki
Jump to: navigation, search
(Reproduce the error)
(Solutions)
Line 67: Line 67:
 
* or Catch the error code in the application and re-try the operation again
 
* 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.
 
* this can be fixed by implementing "rowdependencies" during normal table creation.
 +
== Implement the 3rd solution ==
 +
=== Explanation ===
 +
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.

Revision as of 14:49, 6 February 2020

Reference

My Oracle Support Note : Insert Into Table Fails With ORA-08177 (Doc ID 160593.1)

Error Explanation

Symptoms:

•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     

Cause:
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

Solutions

  • 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

Explanation

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.