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 1riDMJ-00FmGP-EC for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Mar 2024 13:00: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 1riDMH-005MG8-Vh for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Mar 2024 13:00:26 +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 1riDMG-005MFz-NU for pgsql-hackers@lists.postgresql.org; Thu, 07 Mar 2024 13:00:26 +0000 Received: from fout1-smtp.messagingengine.com ([103.168.172.144]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1riDMB-003JV4-A1 for pgsql-hackers@postgresql.org; Thu, 07 Mar 2024 13:00:23 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 97DA71380124; Thu, 7 Mar 2024 08:00:17 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 07 Mar 2024 08:00:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1709816417; x= 1709902817; bh=eqKppVfoQ+sAOLntqYBTo3sLfqTlPwV/JzwlNM02uu8=; b=f R52zPRPh5l37CaTq1W1O3oBvEO50FyA56P7Skmcy2R35lpoLgvM9BgLv6pDkPaRh XT5iruG47Q6W87gnRyOHEMJgkB1jRJvhhULSkyvlLRoZuaF/vJgnnMAP0LdKjzHv S54x2hr0UCaBl4eFuGf/TmqGTTkT6oWsOEA3gbh8V6OTVa0S6dCV4Mmq68veCeHf sYrfCyyKRkueimu5DPgwics2ueEABQEBq87PNeiCbYv9vPwVzgEGYm7g6BHQbwW6 tC+wjb4K8Igx6+5su/dcoPzEN70khE4QM12kRmUD5l1MHe1UMdb+hwGmKuiyun1C ScsefQHTmM/3LfT1AwrPQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrieefgdegjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqe enucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfejjefhgfeiueeukeejkeff gfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhh vghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 7 Mar 2024 08:00:16 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1709816415; bh=yhGKLNOxQqOdTRqofESQ1qT+CXR9QElfzj49HMzt+LE=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=KHp7FTM+GrMlL74GzhZX9OdeQDhEPa1/tGwBg12Gg11u8Av2MIaFr/JWiEnH3FRdn ykZQfxkNge8UICmfvFEaUVkzD5HdogKNd6f809Y+ki3/oBrTRPpy8P+37w+RBEZaCO ToGX46LQ13I+T1wlHkXJoVrDJIHgBnwowTEQFPXai7LVnrzAga0dm9bJ92pGGNJ0s0 olCmLK1KYjp3Mu61C67SHDwpUbfasmT0UlBML2ZZsifbJtVPZF8qKqXGq1zghXNzOS ItCnCzb1d2T2pmIVbFpfLDdD3H5gWG7EK1sWUWEBq7Vt0qi00WeYV1QkfexlDAi8OO kMBNugI7WOCsQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 7A885D84; Thu, 7 Mar 2024 14:00:15 +0100 (CET) Date: Thu, 7 Mar 2024 14:00:15 +0100 From: Alvaro Herrera To: Dean Rasheed Cc: Aleksander Alekseev , PostgreSQL-development , Amul Sul , vignesh C Subject: Re: Dump-restore loosing 'attnotnull' bit for DEFERRABLE PRIMARY KEY column(s). Message-ID: <202403071300.74eklgyctmwc@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-Mar-05, Dean Rasheed wrote: > So I think RelationGetIndexAttrBitmap() should include deferrable PKs, I tried this, but it doesn't actually lead to a good place, because if we allow deferrable PKs to identify rows, then they are not useful to find the tuple to update when replicating. Consider the following case: $node_publisher->safe_psql('postgres', 'create table deferred_pk (id int primary key initially deferred, hidden int, value text)'); $node_subscriber->safe_psql('postgres', 'create table deferred_pk (id int primary key initially deferred, hidden int, value text)'); $node_subscriber->safe_psql('postgres', 'alter subscription tap_sub refresh publication'); $node_publisher->safe_psql('postgres', "insert into deferred_pk (id, hidden, value) values (1, 1, 'first')"); $node_publisher->wait_for_catchup('tap_sub'); $node_publisher->safe_psql('postgres', qq{ begin; insert into deferred_pk values (1, 2, 'conflicting'); update deferred_pk set value = value || ', updated' where id = 1 and hidden = 2; update deferred_pk set id = 3, value = value || ', updated' where hidden = 2; commit}); $node_publisher->wait_for_catchup('tap_sub'); my $pubdata = $node_publisher->safe_psql('postgres', 'select * from deferred_pk order by id'); my $subsdata = $node_subscriber->safe_psql('postgres', 'select * from deferred_pk order by id'); is($subsdata, $pubdata, "data is equal"); Here, the publisher's transaction first creates a new record with the same PK, which only works because the PK is deferred; then we update its payload column. When this is replicated, the row is identified by the PK ... but replication actually updates the other row, because it's found first: # Failed test 'data is equal' # at t/003_constraints.pl line 163. # got: '1|2|conflicting # 3|2|conflicting, updated, updated' # expected: '1|1|first # 3|2|conflicting, updated, updated' Actually, is that what happened here? I'm not sure, but clearly this is bogus. So I think the original developers of REPLICA IDENTITY had the right idea here (commit 07cacba983ef), and we mustn't change this aspect, because it'll lead to data corruption in replication. Using a deferred PK for DDL considerations seems OK, but it seems certain that for actual data replication it's going to be a disaster. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/