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 1tbH6y-009Og7-5z for pgsql-general@arkaria.postgresql.org; Fri, 24 Jan 2025 10:40:28 +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 1tbH6x-00DOhi-8q for pgsql-general@arkaria.postgresql.org; Fri, 24 Jan 2025 10:40:27 +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 1tbH6w-00DOha-Qy for pgsql-general@lists.postgresql.org; Fri, 24 Jan 2025 10:40:26 +0000 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tbH6u-001FV3-0P for pgsql-general@lists.postgresql.org; Fri, 24 Jan 2025 10:40:25 +0000 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-30613037309so19412351fa.3 for ; Fri, 24 Jan 2025 02:40:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737715222; x=1738320022; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=1+s6gN/NGtVJ3UadsRp6IP+efLlo5bP4yLYKn67HdQo=; b=WykpOtY7P7ZDPkzswSJgGXm/tPP2ueD96O/6Zu4Zj/JLILoLLg885QWQrBYfSLGWb9 Lmu8zaR+bhdGg4fK+cP/XTexFcNHEuBqkuTWNzrXjT73R6uZafW41OCIEWbyh7IIwTH2 w8ukiYJJWqVB5vylYChke3xCZ+VOLdvaUshkHIAMP981ucWU5p9G2Fvh0pTyXev93VoY 5cElvII610YhIhwG7/7W/nRZC94Sx9D6SBGVjqKoQwwgf9l8NEWhspSRSt67FL/RIrL3 KT7jjUbs4l98PZaPanEnaa5Fjl3eNYce5P8Me3fILAgU0j5vnWPCleWDabFxRHHyAh/8 tIFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737715222; x=1738320022; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1+s6gN/NGtVJ3UadsRp6IP+efLlo5bP4yLYKn67HdQo=; b=bojCXk5ZT6cyCqiJ1lRr6kuvRwj+W7M9vF298arqmViAwtdPWYXG8OEFMUF9jldxej nA/LXzW1FsUX1kBd+mo01xVFxQUUuGMH0NX/eoNqbigIDfqmH8xI+1EmwwaLdy96BKh/ 7iy0y8iXGlo3uvbLFBcb8U42AQHY1MU/oHbQGY5XK4ZO6XNE/OK52U8lM+W54HnxlYxz 9Eq3sKEiYRzln49wyGV7lQfnRiLkpNYHUTBGfxaQ9PYItDZUSgRfZmoWqQUqaEkhlm9L VA+fdY9x4mXnOO2uEJPOGJcCYCuCbHtZrV478oD7/bOXTJgh4JnDrA2prp8SCPbL486J Ywhw== X-Forwarded-Encrypted: i=1; AJvYcCWSOJ0CyZUQweOD1hTbRDT4wLdGfANAcr++P+y0fHP8h9BEUXcwlIfYMN5Ub3Tsi3wIcpi4qWfF+i4e+9qr@lists.postgresql.org X-Gm-Message-State: AOJu0Yyo1YYQk4MHlYx36M+9uF95l3G3OsaGdWF2PjE5CKRPiHlU3Uq0 4+KiWoO5r12TJwRwa5tVrlE6HEgZER7Ll23LG2VPlqVeaZUa+9DKkpK7YOD7f9W9UWWvfR/e94x 9BSKvL0QkjFxIr12VnmVBgUCW0EW4pH6Kvw== X-Gm-Gg: ASbGnctb5lqZYBrFd10OU+M7GPYG8V36QdxU7M8nJMa3KibDzPHyXrFlzl2V9R5Ywqc 3cs8b5LYTe7JPe0hySloXKhtLfPJcg1s0UhB76/kHz789svFtPr+KnacDf96eDg== X-Google-Smtp-Source: AGHT+IEdUBURbW8aRBiXaFdWDYDcSVd1ZumMJ3K4ZvHRkdbjQddyMAVzivNHyYNU1ZFBCn6Xo2MlWM/+gwDse8TgaDM= X-Received: by 2002:a05:651c:399:b0:302:350c:c630 with SMTP id 38308e7fff4ca-3072caa1527mr85581301fa.22.1737715221739; Fri, 24 Jan 2025 02:40:21 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: =?UTF-8?Q?Torsten_F=C3=B6rtsch?= Date: Fri, 24 Jan 2025 11:40:10 +0100 X-Gm-Features: AWEUYZmtdIT8SBoro15ehVtqo901-stW0_NBG2KiOlSfpR5LR5QzTH7vUWm2Z84 Message-ID: Subject: Re: Is postgresql's json strong consistency or eventually consistency? To: Laurenz Albe Cc: anlex N , pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000008342dd062c715a35" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000008342dd062c715a35 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 16, 2025 at 2:02=E2=80=AFPM Laurenz Albe wrote: > On Thu, 2025-01-16 at 15:25 +0300, anlex N wrote: > > I have searched all archives, but have no results. Please help me. > > That's probably because the question doesn't make much sense. > A single PostgreSQL instance (=3Dcluster) enforces consistency, > and it doesn't matter which data type you are using. > > So I guess the answer should be "strong consistency". I guess what the original author was trying to ask is how many databases have to acknowledge a transaction before it is considered committed, stuff that's called in mongodb write_concern and read_concern. @anlex, PG at its heart is not a distributed system. When you talk about consistency in PG you normally mean foreign key consistency or similar, properties where data in one table is somehow related to data in another table. A slightly different meaning of consistency comes when you talk about transaction isolation levels. All of this is different from Mongodb's read/write consistency. In Mongodb a write can go to one machine while the subsequent read can fetch data from another. So, you worry about linearizability, causal consistency and such things. The only slightly similar question in PG is "Can I see data somehow, on the master or a replica, that has been written to the database but where the master has not yet acknowledged the commit to the client?" The short answer is, yes. As soon as the commit record has been written to the WAL, it is being transferred and replayed on streaming replicas. After that the master might still have to do things like waiting for a synchronous replica to acknowledge the transaction before the transaction becomes visible on the master. On a fast enough replica, the transaction can, hence, become visible before it's visible on the master. https://foertsch.cc/en/postgres/commit-timing You can control that behavior with the `synchronous_commit` setting in combination with `synchronous_standby_names`. You can tell the DB, for instance, a transaction should be considered as committed only when 3 out of 5 replicas have acknowledged it. If you set synchronous_commit=3Dremote_apply and configure N out of N replicas in synchronous_standby_names, that would likely give you a distributed database with strong consistency where you can direct writes to the master and read-only load to the replicas. But I guess nobody in his right mind would do that unless your database is rarely written to. --0000000000008342dd062c715a35 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Jan 16, 2025 at 2:02=E2=80=AFPM L= aurenz Albe <laurenz.albe@cy= bertec.at> wrote:
On Thu, 2025-01-16 at= 15:25 +0300, anlex N wrote:
> I have searched all archives, but have no results. Please help me.

That's probably because the question doesn't make much sense.
A single PostgreSQL instance (=3Dcluster) enforces consistency,
and it doesn't matter which data type you are using.

So I guess the answer should be "strong consistency".

I guess what the=C2=A0original author was trying to as= k is how many databases have to acknowledge a transaction before it is cons= idered committed, stuff that's called in mongodb write_concern and read= _concern.

@anlex, PG at its heart is not a distrib= uted system. When you talk about consistency in PG you normally mean foreig= n key consistency or similar, properties where data in one table is somehow= related to data in another table. A slightly different meaning of consiste= ncy comes when you talk about transaction isolation levels.

<= /div>
All of this is different from Mongodb's read/write consistenc= y. In Mongodb a write can go to one machine while the subsequent read can f= etch data from another. So, you worry about linearizability, causal consist= ency and such things. The only slightly similar question in PG is "Can= I see data somehow, on the master or a replica, that has been written to t= he database but where the master has not yet acknowledged the commit to the= client?"

The short answer is, yes. As soon a= s the commit record has been written to the WAL, it is being transferred an= d replayed on streaming replicas. After that the master might still have to= do things like waiting for a synchronous replica to acknowledge the transa= ction before the transaction becomes visible on the master. On a fast enoug= h replica, the transaction can, hence, become visible before it's visib= le on the master.


You can control that behavior with the `synchrono= us_commit` setting in combination with `synchronous_standby_names`. You can= tell the DB, for instance, a transaction should be considered as committed= only when 3 out of 5 replicas have acknowledged it.

If you set synchronous_commit=3Dremote_apply and configure N out of N re= plicas in synchronous_standby_names, that would likely give you a distribut= ed database with strong consistency where you can direct writes to the mast= er and read-only load to the replicas. But I guess nobody in his right mind= would do that unless your database is rarely written to.
--0000000000008342dd062c715a35--