Django Transaction Transaction Columns

I need to speed up, add and remove rows from the auth.models.User table, unfortunately ...

when I do this, the table is locked and I cannot execute any SELECT queries on the table.


I surround these @transaction.commit_manually queries, which may have something to do with table locking.

The transaction is as follows:

 for row in csv_reader: update_sql = "UPDATE auth_user SET last_name = '%s' WHERE username = '%s'" %(row[2], row[0] ) cursor.execute(update_sql) if not index % 100: print index: print index transaction.commit() 

I also use Sql Server 2008 , I would like to know if it could be specific to Sql Server or if such actions would block the table in PostgreSQL and MySQL too.


Any ideas guys? :)

+4
source share
1 answer

Yes, you specifically lock tables. I would suggest studying transaction isolation because it is one of the basic concepts of databases.

As for your problem, you can do a few things for the UPDATE and SELECT statements:

  • You can set the transaction isolation level to something lower for the rest of the database connection.
  • Perhaps you could do the same with other mechanisms .
  • You can try changing your queries to read the baseline data first and then start changing the data. This may allow you to lock the table, but allow the operation.
  • You can again consider what queries are important for transactions.
  • You can also steer SQL Server with "Tooltip Blocking . "
+2
source

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


All Articles