This question has been flagged
1 Reply
21058 Views

Hi Community,

We are facing the error "*could not serialize due to concurrent update*" too 
many times in our production server. 

The errors are occurring due to the "Repeatable Read" isolation level. I 
know that the database default_transaction_isolation is "Read Committed" 
where we don't get these errors. 

But when I monitored the queries the application(ODOO) user is issuing "SET 
default_transaction_isolation to Repeatable Read". So is the cause of these 
errors.  I have explored on the ODOO application side where in which I lost 
somewhere  but found to know that these errors are common for ODOO. 

In one of the ODOO application files named "sql_db.py" the below code I have 
found where I understood the isolation level was set to "Repeatable Read". 

My concern here is if I change this isolation level to "Read Committed" will 
this suffice to stop this error occurrence? 

Avatar
Discard
Hi,

Did you answer my question??

Looking forward to hearing from you.

Regards, 
Pavan Teja, 
9841380956 

On Wed, 17 Apr, 2019, 12:57 PM Mitul Shingala, <shingalamitul0023@gmail.com> wrote:

A new question Repeated Serialization Errors("could not serialize access due to concurrent update") in Postgres Database on Help has been posted. Click here to access the question :

See question


Sent by Odoo S.A. using Odoo.

Best Answer

Frequently we encounter with this problem that when multiple user(transaction) tries to update a same record/row of a table at the same time, the DBMS fail to serialize the access to the record/row hence throws an error saying, 'could not serialize access due to concurrent update'.Below is the solution that can prevent this kind of data race condition.


with self.env.cr.savepoint():
​self.env.cr.execute("SELECT id FROM YOUR_MODEL WHERE id = %s FOR UPDATE", (ID_Of_The_Records_to_lock,))
#​ update Records or Any ORM Operation inside the scope

In the code above, when the code execution enters the scope of the savepoint context, we are executing a query to acquire a row level lock on some rows of the table by their ID so that no other transaction can update/modify the same records until the lock is released. The lock will be released when an explicit commit on the cursor is done or a rollback is done.


Thanks & Regards, 

 

Brain Station 23 Ltd. 

Mobile: (+880) 1404055226 

Email: sales@brainstation-23.com 

Web: https://brainstation-23.com/ 

Address: (Building-1) 8th Floor, 2 Bir Uttam AK Khandakar Road, Mohakhali C/A, Dhaka 1212, Bangladesh 

Avatar
Discard