Django / MySQL: how to perform autonomous transactions (commit only a subset of queries)?

I am using Django and MySQL. I need to be able to do what Oracle calls an autonomous transaction, that is, it only completes part of the transaction (or, rather, has a transaction inside the transaction). I need this for two cases (although I think the solution will be the same):

  • Registration of errors. I am logging errors in the error table and want to commit these inserts, even if all other transactions are rolled back.

  • I use a table to create a sequence (using the TABLE sequence and LAST_INSERT_ID (), as described here: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html ). I want to get / update this sequence, and then commit the statement, thereby unlocking the table for other transactions that need the sequence. This is normal if the table grows even if I roll back other transactions.

+4
source share
1 answer

An interesting subject, apparently, in mysql there is no such thing, but the guy recommends using (for your logs table) the myisam table, since these are external transactions, the data is still published.


I am adding a second answer, as I just figured out this alternative: what you can do is process the log transaction from another connection with another user in your database.

Mysql processes the connection pool for each user, so it will never use the same connection for basic operations and log operations, which allows you to record the connection of logs independently.

+1
source

All Articles