Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tyFYC-004FiT-AR for pgsql-general@arkaria.postgresql.org; Fri, 28 Mar 2025 19:39:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tyFY9-00FMRe-4j for pgsql-general@arkaria.postgresql.org; Fri, 28 Mar 2025 19:39:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tyFY8-00FMRV-MW for pgsql-general@lists.postgresql.org; Fri, 28 Mar 2025 19:39:28 +0000 Received: from mail-ua1-x92c.google.com ([2607:f8b0:4864:20::92c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tyFY7-001fww-0B for pgsql-general@postgresql.org; Fri, 28 Mar 2025 19:39:27 +0000 Received: by mail-ua1-x92c.google.com with SMTP id a1e0cc1a2514c-86b9b1def28so2307459241.3 for ; Fri, 28 Mar 2025 12:39:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743190766; x=1743795566; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=jAXuFcrpESm6YsZ7RYc1tfgB3eWQknsE4Ou32GUWBtE=; b=e3YAVH9ZlMG5AifiEswWcprMjyheNlYvKqS2uMMJhJv+AtHrxLOgPtgDhBap2Hujre sH05b/9QIed9qjk1U4fCpJLaErNu9Opx9MLdBF3/OzK4c3COBNX1SVMuG4kfhbN0NjoM 3omyaVWVuy88uA9jjsplWrnGDg/gG0ubhKqbuUeXV2/F/D+hmVsneaCsJFMmS9lczYSc k6fRT+s55b//LO5VPgBsGAx0BiewTFUhPmovHTyG2V+E6el9Q8YwG7H9nkv6NIXAZ0nr I04vsBoi/wS3dK24Z9cA7Mc1YzppHz4wQg+rPhRglc2HouIZSmUZM6xF94RHBMlAoQuB qwug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743190766; x=1743795566; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jAXuFcrpESm6YsZ7RYc1tfgB3eWQknsE4Ou32GUWBtE=; b=XPNG2jeOO87sUx3NRr90fYKU7Uo3j4L20qRCL+afbh2UePYDrKqWRCEs0fSAYFI6Ik znGqCL+2zu2jl/th5NeJQvYM2yL1Iwqp+Ej1VvMAlhFJpqDSas0/BVCJQcXdnoYVX5vP iSv1wVKHY5FhPZFXnf8RsFP2CnbBYaQRNI1Gn0hxV4iOg2ET2Mxwfr1gJN20UN7xmXPR N4UdpgD3uF/aGS5RroAWUbCShS91s/aKf8QSEtdIFWTHK8AlV8YKt7BVYsPB6Gyeycht NAIPYHFO9KLTy9z9tKsYdKVmZJGlD0J+FvZk8Sm+vg/tNcC0stii01qmxVOrk1yIaHM9 wixA== X-Gm-Message-State: AOJu0Yzpb5PPVk+jJVncQo07YtZWeV4GQxoc9aMZhs6C+aE6PIUWpH6i RTEBOpNmXMNXvU2g667rr0UIL1XUnZZ7EcK4I+CelS4UkjarXa6QhbIxfCKf7bX0nMdHFAdajce SGn30pajpBRtcr10AfYWtcRYGmO1ZRQLp0ko= X-Gm-Gg: ASbGncvaRpdccTKYCkIRUA8nIoFDFRArsF8w/39Gxo+YXvTTearUiDyH522LqI4wJuS aU5qbzgZpCXgckGZKIFn+uml9wCEZBwEbObmxoPxXiDm2SVmr0RudVH+COJ8Al6oG/lDSBi3R89 2l2i89/IZGp5lnb0hWtoDqH2NhHi0= X-Google-Smtp-Source: AGHT+IHMCop3hWsxMXLJuKfTxiU2D2nTTjoKsPmI+wnvunK+ooa08yLtIdYEjlQlM2afK4APBStKeUpSMh/g+VxRVGI= X-Received: by 2002:a05:6102:2d08:b0:4bb:cbbc:38 with SMTP id ada2fe7eead31-4c6d38369d1mr981097137.5.1743190765923; Fri, 28 Mar 2025 12:39:25 -0700 (PDT) MIME-Version: 1.0 From: Sasa Vilic Date: Fri, 28 Mar 2025 20:38:50 +0100 X-Gm-Features: AQ5f1JrkY0IgU6nGyRDOU1AZ8G1gUcKXX78qtjrmF2UMIHtfRhcdzj6ZWIsEAnI Message-ID: Subject: Concurrent delete and insert on same key, potentially a bug To: pgsql-general@postgresql.org Content-Type: multipart/alternative; boundary="00000000000060fb2a06316c3abc" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000060fb2a06316c3abc Content-Type: text/plain; charset="UTF-8" Hello, Please excuse my ignorance, because I might be missing something obvious, but how is this not a bug? I simply open 2 terminals and connect to the same database. **TERMINAL 1:** sasa=# create table tst1(id int primary key); CREATE TABLE sasa=# insert into tst1(id) values(1); INSERT 0 1 sasa=# begin; BEGIN sasa=# select * from tst1 where id = 1; id ---- 1 (1 row) **TERMINAL 2:** sasa=# begin; BEGIN sasa=# select * from tst1 where id = 1; id ---- 1 (1 row) **TERMINAL 1:** sasa=# delete from tst1 where id = 1; DELETE 1 sasa=# insert into tst1(id) values(1); INSERT 0 1 **TERMINAL 2:** sasa=# delete from tst1 where id = 1; // client is blocked due to row lock/index lock **TERMINAL 1:** sasa=# commit; COMMIT **TERMINAL 2:** // resumes because terminal 1 committed transaction DELETE 0 sasa=# insert into tst1(id) values(1); ERROR: duplicate key value violates unique constraint "tst1_pkey" DETAIL: Key (id)=(1) already exists. To my understanding, the second client (terminal 2) should already see changes from the first client, because the transaction isolation level is READ COMMITTED and the first client did commit its transaction. Thanks in advance! Kind Regards Sasa Vilic --00000000000060fb2a06316c3abc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

Please excuse my= ignorance, because I might be missing something obvious, but how is this n= ot a bug?

I simply open 2 terminals and conne= ct to the same database.

**TERMINAL 1:**

sasa=3D# create table tst1(id int primary key);
CREATE T= ABLE
sasa=3D# insert into tst1(id) values(1);
INSERT 0 1
sasa=3D# = begin;
BEGIN
sasa=3D# select * from tst1 where id =3D 1;<= br>=C2=A0id
----
=C2=A0 1
(1 row)

**= TERMINAL 2:**

sasa=3D# begin;
BEGIN
sasa=3D#= select * from tst1 where id =3D 1;
=C2=A0id
----
=C2=A0 1
(1 = row)

**TERMINAL 1:**

sasa=3D# delete = from tst1 where id =3D 1;
DELETE 1
sasa=3D# insert into tst1(id) valu= es(1);
INSERT 0 1

**TERMINAL 2:**
sasa=3D# delete from tst1 where id =3D 1;
// client is bloc= ked due to row lock/index lock

**TERMINAL 1:**

sasa=3D# commit;
COMMIT

*= *TERMINAL 2:**
// resumes because terminal 1 committed transactio= n
DELETE 0
sasa=3D# insert into tst1(id) values(1);
ERROR: = =C2=A0duplicate key value violates unique constraint "tst1_pkey"<= br>DETAIL: =C2=A0Key (id)=3D(1) already exists.

To my understanding, the second client (terminal 2) should already see ch= anges from the first client, because the transaction isolation level is REA= D COMMITTED and the first client did commit its transaction.

=
Thanks in advance!

Kind Regards
Sasa Vilic



--00000000000060fb2a06316c3abc--