gpt4 book ai didi

postgresql - Postgres 的可序列化事务阻塞并发写

转载 作者:行者123 更新时间:2023-11-29 12:16:37 25 4
gpt4 key购买 nike

PostgreSQL's isolation levels documentation据称

To guarantee true serializability PostgreSQL uses predicate locking, which means that it keeps locks which allow it to determine when a write would have had an impact on the result of a previous read from a concurrent transaction, had it run first. In PostgreSQL these locks do not cause any blocking and therefore can not play any part in causing a deadlock. They are used to identify and flag dependencies among concurrent Serializable transactions which in certain combinations can lead to serialization anomalies.

当我尝试在隔离级别 SERIALIZABLE 中执行两个更新语句时,似乎第二个写入阻塞,直到第一个事务提交或中止。你可以看到 gif 文件中的交互:

enter image description here

about 语句如何解释这种行为?我希望第二个事务一直持续到提交,然后得到 could not serialize 错误。

顺便说一句,event 表的架构如下:

CREATE TABLE event (
id INT,
created_at timestamp
)

最佳答案

该段落仅描述谓词锁,它是一类特殊的锁,仅用于可序列化隔离级别。

除了这些特殊的锁之外,可序列化的事务还会使用其他隔离级别使用的“普通”锁。

关于postgresql - Postgres 的可序列化事务阻塞并发写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50745282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com