database-deadlocks

Avoid exclusive access locks on referenced tables when DROPping in PostgreSQL

感情迁移 提交于 2021-02-18 22:45:22
问题 Why does dropping a table in PostgreSQL require ACCESS EXCLUSIVE locks on any referenced tables? How can I reduce this to an ACCESS SHARED lock or no lock at all? i.e. is there a way to drop a relation without locking the referenced table? I can't find any mention of which locks are required in the documentation, but unless I explicitly get locks in the correct order when dropping multiple tables during concurrent operations, I can see deadlocks waiting on an AccessExclusiveLock in the logs,

MSSQL Deadlock when update withc (updlock)

谁说胖子不能爱 提交于 2021-02-08 06:25:18
问题 I got deadlock while updating. The transaction level is set to Read Committed . How to avoid deadlock in such situation? In other cases WITH (NOLOCK) and WITH (UPDLOCK) helped. I got the following T-SQL query: IF EXISTS (SELECT 1 FROM DEBTORS_CUSTOMERS WITH (NOLOCK) WHERE DebtorId = @DebtorId AND ClientFCCustomerNumber = @CustomerNumber) UPDATE DEBTORS_CUSTOMERS WITH (UPDLOCK) SET StatusId = @StatusId WHERE DebtorId = @DebtorId AND ClientFCCustomerNumber = @CustomerNumber ELSE INSERT INTO

Deadlock graph from Extended Events not showing

北战南征 提交于 2021-01-01 13:40:55
问题 I have this query which is from "Sql Server 2017 Query Performance Tuning"(a book). Code for the book can be found here: https://github.com/Apress/sql-server-2017-query-perf-tuning DECLARE @path NVARCHAR(260) --to retrieve the local path of system_health files SELECT @path = dosdlc.path FROM sys.dm_os_server_diagnostics_log_configurations AS dosdlc; SELECT @path = @path + N'system_health_*'; WITH fxd AS (SELECT CAST(fx.event_data AS XML) AS Event_Data FROM sys.fn_xe_file_target_read_file(

Deadlock graph from Extended Events not showing

喜欢而已 提交于 2021-01-01 13:35:14
问题 I have this query which is from "Sql Server 2017 Query Performance Tuning"(a book). Code for the book can be found here: https://github.com/Apress/sql-server-2017-query-perf-tuning DECLARE @path NVARCHAR(260) --to retrieve the local path of system_health files SELECT @path = dosdlc.path FROM sys.dm_os_server_diagnostics_log_configurations AS dosdlc; SELECT @path = @path + N'system_health_*'; WITH fxd AS (SELECT CAST(fx.event_data AS XML) AS Event_Data FROM sys.fn_xe_file_target_read_file(

MySQL deadlocks explanation

▼魔方 西西 提交于 2020-12-07 08:34:08
问题 I need help solving a deadlock situation I'm facing. Thanks for your help. I think the deadlock is related to the SELECT subquery of transaction 2, but I don't understand several things: Why is it holding a S lock and then waiting for a X lock of the same row... why didn't it get an X lock to begin with? In any case, why is transaction 1 blocking anything? I would expect it to just need one lock, therefore not get a lock of anything else, and just wait until that lock is available to be

MySQL: A deadlock occurred when deleting the same row twice in the (unique) secondary index

假如想象 提交于 2020-08-08 05:27:29
问题 Recently I encountered a deadlock when deleting records (Note that the isolation level is REPEATABLE READ , MySQL 5.7) Here is the repro steps 1 Create a new table CREATE TABLE `t` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), KEY `p_name` (`name`) ) ENGINE=InnoDB CHARSET=utf8; 2 Prepare 3 records insert into t (name) value ('A'), ('C'), ('D'); 3 +====================================+============================================================+ |

How to replicate a SCH_S, SCH_M deadlock

大城市里の小女人 提交于 2020-07-15 20:56:04
问题 I have a large migration script (about 2000 lines) that fails because of a deadlock on some metadata, and the lock types are SCH_S and SCH_M according to some xEvents data I've captured on it. The script is quite complicated, so I'm trying to recreate the same scenario using minimal scripting, so I can investigate it further. One difference between my scenario and some of the ones I've found online is that my migration script is being executed in a single process, as opposed to many examples

SQL Server deadlock when using PreparedStatements

房东的猫 提交于 2020-02-15 10:12:10
问题 I have a java servlet application and I'm using a prepared query to update a record in a SQL Server Database table. Lets say I want to execute UPDATE MyTable SET name = 'test' WHERE id = '10' . (Yes, id is a varchar) I used the following code to make this happen: PreparedStatement pstmt = con.prepareStatement("UPDATE MyTable SET name = ? WHERE id = ?"); pstmt.setString(1, getName() ); pstmt.setString(2, getID() ); pstmt.executeUpdate(); I found out that while I was running a JMeter script to