何时在PostgreSQL中选择“ Query Aquire exclusivelock和RowexClusivelock”?
根据官方文档,选择ShareLock只需要ShareLock ,但我发现我的选择查询获得了独家锁。它是怎么发生的?这是我的选择查询:
select gc.id
from group_access_strategy ga
left outer join person_group pg on gp.person_group_id=pg.id
where gp.id=3
According to official documentation, select query only need sharelock, but I found my select query acquired Exclusive lock. How did it happen? Here is my select query:
select gc.id
from group_access_strategy ga
left outer join person_group pg on gp.person_group_id=pg.id
where gp.id=3
what is different from official documentation is that I added left join.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您很可能会运行另一个命令,例如
Alter Table Person_Group ...
(访问独家)或update> update
/insert
/delete
delete (row exclusive)在相同的 Transaction 。锁将一直持续到交易完成或中止。因此,如果您运行:
update
语句将创建一个行的独家锁定,该锁将在您结束交易之前不会发布:通过以下方式保存所有更改,因为
begin
:或
将语句的任何效果删除,因为
开始
,如果您是Postgres的新手,并且通常在PG Admin或DataGrip等IDE中运行查询,则
begin> begin
/<代码>提示回滚
命令在您单击相应的UI按钮时为您发出。Most likely you ran another command like
ALTER TABLE person_group ...
(Access Exclusive) or anUPDATE
/INSERT
/DELETE
(Row exclusive) in the same transaction. Locks will persist until a transaction is completed or aborted.So if you ran:
The
UPDATE
statement would have created a Row Exclusive Lock that will not be released until you end the transaction by:Saving all of the changes made since
BEGIN
:OR
nullifying any of the effects of statements since
BEGIN
withIf you're new to Postgres and typically run your queries in an IDE like PG Admin or DataGrip, the
BEGIN
/COMMIT
ROLLBACK
commands are issued behind the scenes for you when you click the corresponding UI buttons.