pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Carlos Alves <carlos.alves@tecnisys.com.br>
To: pgsql-general@lists.postgresql.org
Subject: Re: Question about tuple´s lock
Date: Tue, 24 Oct 2023 13:33:10 -0300
Message-ID: <03df282dff2b539f8c182fb14bcc5361@tecnisys.com.br> (raw)
In-Reply-To: <2fa29bee5e4a7c369f54f02198423814@tecnisys.com.br>
References: <2fa29bee5e4a7c369f54f02198423814@tecnisys.com.br>

Em 24/10/2023 13:27, Carlos Alves escreveu:

> Hi! 
> 
> I need some help to understand why a transaction wiht a row delete aquire a AccessExclusiveLock and a row update a ExclusiveLock. 
> 
> To ilustrate, a made this scenario: 
> 
> create table tblock 
> 
> ( 
> 
> id int primary key, 
> 
> value text 
> 
> ); 
> 
> insert into tblock values (1, 'somevalue'); 
> 
> First start Transaction 1: 
> 
> begin; 
> 
> update tblock set value = 'othervalue' where id = 1; 
> 
> -- keep this transaction opened 
> 
> After, start Transaction 2: 
> 
> begin; 
> 
> update tblock set value = 'onemorevalue' where id = 1; 
> 
> -- at this point, this transaction assumes a ExclusiveLock in the tuple; 
> 
> -- keep this transaction opend 
> 
> Then, start Transaction 3: 
> 
> begin; 
> 
> update tblock set value = 'lastofthevalues' where id = 1; 
> 
> -- here i can see this transaction trying to aquire a AccessExclusiveLock in this tuple 
> 
> So, my question is: why a delete row requires a AccessExclusiveLock in the tuple insteead of ExclusiveLock? 
> 
> Bellow, a image of a query over pg_locks: 
> 
> PostgreSQL version: 13 
> 
> OS: Centos 7 
> 
> Thanks in advance.

I typed the last command wrong. Should be:

Transaction 3: 

begin; 

delete from tblock where id = 1; 

Sorry!

Attachments:

b9879537.png (image/png, 73.1K) download view image
f62593aa.gif (image/gif, 43B) download view image
04237a95.gif (image/gif, 3.1K) download view image

view thread (4+ messages)  latest in thread

Message-ID: <03df282dff2b539f8c182fb14bcc5361@tecnisys.com.br>
Permalink:  ../03df282dff2b539f8c182fb14bcc5361@tecnisys.com.br/
Also on:    postgresql.org/message-id/03df282dff2b539f8c182fb14bcc5361@tecnisys.com.br

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: carlos.alves@tecnisys.com.br
  Subject: Re: Question about tuple´s lock
  In-Reply-To: <03df282dff2b539f8c182fb14bcc5361@tecnisys.com.br>
  References: <2fa29bee5e4a7c369f54f02198423814@tecnisys.com.br> <03df282dff2b539f8c182fb14bcc5361@tecnisys.com.br>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox