我如何解释 postgresql 死锁消息?

How do I interpret postgresql deadlock message?

我是 运行 Postgresql 9.5.2 服务器,偶尔会看到如下消息:

ERROR: deadlock detected
Detail: Process 1234 waits for ShareLock on transaction 3042999324; blocked by process 5678.
Process 5678 waits for ShareLock on transaction 3042999328; blocked by process 1234.
Hint: See server log for query details.
Where: while locking tuple (5389,30) in relation "asset"

如果它包含有关导致死锁的行或列的任何信息,它将帮助我调试首先导致错误的丑陋 common-table expression

我在问我的问题时查找要使用的正确术语时弄明白了:元组指的是该行的 ctid, a system column on every row indicating the physical location of the version of the row in question. (When a row is updated, Postgresql keeps the old version around for a while in order to fulfill ACID 保证。)

您可以 select 数据只需使用:

SELECT * from "asset" where ctid = '(5389,30)';

但是,如果您等待的时间过长(就像我一样),autovacuum 作业可能会清理不再使用的那个版本的行。