database-deadlocks

What are 'best practices' for dealing with transient database errors in a highly concurrent Rails system?

ε祈祈猫儿з 提交于 2019-12-11 06:57:01
问题 While researching a deadlock issue, I found the following post: https://rails.lighthouseapp.com/projects/8994/tickets/6596 The gist of it is as follows: the MySQL docs say: Deadlocks are a classic problem in transactional databases, but they are not dangerous unless they are so frequent that you cannot run certain transactions at all. Normally, you must write your applications so that they are always prepared to re-issue a transaction if it gets rolled back because of a deadlock . Therefore

Why do two concurrent delete + insert statements deadlock on an empty table?

半城伤御伤魂 提交于 2019-12-10 17:25:41
问题 I'm curious to know why two concurrent DELETE followed by INSERT statements that use primary keys causes a deadlock in MySQL when the primary keys don't exist. The example is contrived to illustrate the issue in it's simplest form. Here is the setup. > SELECT @@GLOBAL.tx_isolation, @@tx_isolation; +-------------------------+------------------+ | @@GLOBAL.tx_isolation | @@tx_isolation | |-------------------------+------------------| | REPEATABLE-READ | REPEATABLE-READ | +----------------------

SQL Server deadlock between two update statements

断了今生、忘了曾经 提交于 2019-12-10 15:07:24
问题 I have a website that has a very popular forum on it and occasionally throughout the day I see several deadlocks happening between two identical (minus the data within them) update statements on the same forum. I'm not exactly sure why this is happening on this query as there are many other queries on the site that run with high concurrency without issue. Full Image The query between the two processes is nearly identical, the graph shows it as: update [Forum] set [DateModified] =

Is it appropriate to return HTTP 503 in response to a database deadlock?

匆匆过客 提交于 2019-12-10 14:47:27
问题 Is it appropriate for a server to return 503 ("Service Unavailable") when the requested operation resulted in a database deadlock? Here is my reasoning: Initially I tried avoiding database deadlocks, but I ran across https://stackoverflow.com/a/112256/14731 Next, I tried repeating the request on the server-side, but I ran across Java Servlets: How to repeat an HTTP request?. Technically speaking I can buffer the request entity but scalability will suffer and clients are more likely to see 503

Identifying and Resolving Oracle ITL Deadlock

心已入冬 提交于 2019-12-10 13:27:55
问题 I have an Oracle DB package that is routinely causing what I believe is an ITL (Interested Transaction List) deadlock. The relevant portion of a trace file is below. Deadlock graph: ---------Blocker(s)-------- ---------Waiter(s)--------- Resource Name process session holds waits process session holds waits TM-0000cb52-00000000 22 131 S 23 143 SS TM-0000ceec-00000000 23 143 SX 32 138 SX SSX TM-0000cb52-00000000 30 138 SX 22 131 S session 131: DID 0001-0016-00000D1C session 143: DID 0001-0017

SQL deadlock on multithreaded massive delete query and bulk insert batches

谁说我不能喝 提交于 2019-12-10 11:07:32
问题 I have a batch in .NET that reads a lot of files and stores their content into a single MySQL InnoDB table with the following structure: `id` int(11) NOT NULL AUTO_INCREMENT, `Source` varchar(2) NOT NULL, `Period` char(1) NOT NULL, `idItem` int(11) NOT NULL, `StartDate` datetime NOT NULL, `MoreData` varchar(255) PRIMARY KEY (`id`), UNIQUE KEY `Combination` (`Source`,`Period`,`idItem`,`StartDate`), Where idItem is a foreign key Source, Period, and idItem are indices Combination is a unique

Deadlock puzzle : Victim doesn't own any resource, used to kill to resolve deadlock

青春壹個敷衍的年華 提交于 2019-12-10 10:54:54
问题 I've strange deadlock graph where the victim chosen by MSSQL server 2008 isn't part of the deadlock loop. This deadlock is between select and insert . The deadlock resource is a single table where all select s want waitresource = "KEY: 6:72057594098810880 (ffffffffffff)" Question1 : Does ffffffffffff here mean they want a full range lock on whole table? Or whole key range? Or something else? We are following a rule where table will never have a row with primary key id = 0. There are few

Deadlock error on same table with two Update SQL statements

陌路散爱 提交于 2019-12-09 16:08:17
问题 I have a C# project which writes data to a TSQL database. There are two update statements which run within a loop, eg.: for (int i = 0; i < customersProducts.Count; i++) { CustomerProducts c = customersProducts[i]; // Update product dimensions for (int j = 0; j < c.Count; j++) { Product p = c[j]; updateProductDimensions(p); } // ... some processing // Update product for (int j = 0; j < c.Count; j++) { Product p = c[j]; updateProduct(p); } } The updateProductDimensions() and updateProduct()

Can two concurrent but identical DELETE statements cause a deadlock?

时间秒杀一切 提交于 2019-12-09 10:20:56
问题 Assume some_table has two rows, with primary key 1 and 2 . The following sequence of statements can cause a deadlock: session 1: begin; session 2: begin; session 1: DELETE FROM my_table WHERE my_key = 1; session 2: DELETE FROM my_table WHERE my_key = 2; session 1: DELETE FROM my_table WHERE my_key = 2; session 2: DELETE FROM my_table WHERE my_key = 1; The deadlock would not have occurred if both sessions deleted in the same order. Now, coming to my question, what happens if the DELETE

SELECT FOR UPDATE with Subquery results in Deadlock

倖福魔咒の 提交于 2019-12-08 14:00:39
I have query when executed from different session is resulting in deadlock. TAB1 (ID, TARGET, STATE, NEXT) AND ID is primary key Column ID is the primary key. SELECT * FROM TAB1 WHERE NEXT = (SELECT MIN(NEXT) FROM TAB1 WHERE TARGET=? AND STATE=?) AND TARGET=? AND STATE=? FOR UPDATE In the Oracle trace file, I see the statement: DEADLOCK DETECTED Current SQL statement for this session: SELECT ID, TARGET, NEXT, STATE FROM TAB1 WHERE NEXT=(SELECT MIN(NEXT) FROM TAB1 WHERE (TARGET='$any') AND ( STATE = 0)) AND (TARGET='$any') AND (STATE = 0) FOR UPDATE The following deadlock is not an ORACLE error