Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django transaction isolation level in mysql & postgresql

Do you know the default isolation level of the transactions used in Django? Is it possible to set the isolation level in the database independent way?

I'm mainly interested in mysql and postgres.

like image 787
Piotr Czapla Avatar asked Feb 17 '10 13:02

Piotr Czapla


3 Answers

You can also change this per client / session using the django database options, like this:

DATABASE_OPTIONS = { "init_command": "SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED", }
like image 152
Peter Lundberg Avatar answered Nov 09 '22 05:11

Peter Lundberg


The isolation level isn't changed by mysql drivers so it depends on the server's default isolation level.

like image 42
Piotr Czapla Avatar answered Nov 09 '22 03:11

Piotr Czapla


At the moment django does not set the isolation level. This is a bug, because of django does not work properly with any higher isolation level than READ COMMITTED. But MySQL is using REPEATABLE READ by default. There are plans to add a setting to set the isolation level (#14026) and a discussion about making READ COMMITTED the default (#13906). I have also written a detailed article about MySQL transactions and django.

like image 37
Sebastian Noack Avatar answered Nov 09 '22 05:11

Sebastian Noack