Django transaction isolation level in mysql & postgresql

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

I am mainly interested in mysql and postgres.

+4
source share
5 answers

The isolation level is not changed by mysql drivers, so it depends on the default isolation level of the server.

+3
source

You can also change this to each client / session using the django database options, for example:

DATABASE_OPTIONS = { "init_command": "SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED", } 
+9
source

Django does not currently set the isolation level. This is a mistake because django does not work properly with a higher isolation level than READ COMMITTED. But MySQL uses REPEATABLE READ by default. It is planned to add a parameter to set the isolation level ( # 14026 ) and a discussion of how to perform READ COMMITTED by default ( # 13906 ). I also wrote a detailed article on MySQL and django transactions .

+1
source

(Sorry, I can not comment on Danhip) This is a wotked solution for me (mySQL), I added Peter code in the DATABASE field:

 DATABASES = { 'default': { (...) 'OPTIONS': { (...), "init_command": "SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED" }, } } 
0
source

if you want to use uncommited reading level.

You add an “isolation level”: “read unaccepted” to “OPTIONS” in the database connection configuration.

 DATABASES = { 'read-uncommited': { 'OPTIONS': { 'isolation_level': 'read uncommitted' }, }, } 

you can find at https://docs.djangoproject.com/en/2.1/ref/databases/

0
source

Source: https://habr.com/ru/post/1301573/


All Articles