暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PostgreSQL 14 preview - 支持startup(恢复)进程与backend(用户)进程死锁检测 - backpatch到9.6版本

digoal 2021-01-01
468

作者

digoal

日期

2021-01-07

标签

PostgreSQL , 死锁检测 , startup and backend process


背景

PostgreSQL 9.6以及以后的所有版本, 支持startup(恢复)进程与backend(用户)进程死锁检测, 应用于基于PG流复制的只读实例场景.

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=8900b5a9d59a645b3485f5b046c4c7871b2c4026

```
Detect the deadlocks between backends and the startup process.
author Fujii Masao fujii@postgresql.org
Wed, 6 Jan 2021 03:39:18 +0000 (12:39 +0900)
committer Fujii Masao fujii@postgresql.org
Wed, 6 Jan 2021 03:39:18 +0000 (12:39 +0900)
commit 8900b5a9d59a645b3485f5b046c4c7871b2c4026
tree 87e55d7e0c47c3d0506c7bb7782355c5c22c0d37 tree | snapshot
parent e02e840ff7787d4798fca9f6a5b8b3657f45cf0c commit | diff
Detect the deadlocks between backends and the startup process.

The deadlocks that the recovery conflict on lock is involved in can
happen between hot-standby backends and the startup process.
If a backend takes an access exclusive lock on the table and which
finally triggers the deadlock, that deadlock can be detected
as expected. On the other hand, previously, if the startup process
took an access exclusive lock and which finally triggered the deadlock,
that deadlock could not be detected and could remain even after
deadlock_timeout passed. This is a bug.

The cause of this bug was that the code for handling the recovery
conflict on lock didn't take care of deadlock case at all. It assumed
that deadlocks involving the startup process and backends were able
to be detected by the deadlock detector invoked within backends.
But this assumption was incorrect. The startup process also should
have invoked the deadlock detector if necessary.

To fix this bug, this commit makes the startup process invoke
the deadlock detector if deadlock_timeout is reached while handling
the recovery conflict on lock. Specifically, in that case, the startup
process requests all the backends holding the conflicting locks to
check themselves for deadlocks.

Back-patch to v9.6. v9.5 has also this bug, but per discussion we decided
not to back-patch the fix to v9.5. Because v9.5 doesn't have some
infrastructure codes (e.g., 37c54863cf) that this bug fix patch depends on.
We can apply those codes for the back-patch, but since the next minor
version release is the final one for v9.5, it's risky to do that. If we
unexpectedly introduce new bug to v9.5 by the back-patch, there is no
chance to fix that. We determined that the back-patch to v9.5 would give
more risk than gain.

Author: Fujii Masao
Reviewed-by: Bertrand Drouvot, Masahiko Sawada, Kyotaro Horiguchi
Discussion: https://postgr.es/m/4041d6b6-cf24-a120-36fa-1294220f8243@oss.nttdata.com
```

PostgreSQL 许愿链接

您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.

9.9元购买3个月阿里云RDS PostgreSQL实例

PostgreSQL 解决方案集合

德哥 / digoal's github - 公益是一辈子的事.

digoal's wechat

文章转载自digoal,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论