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 1r8DZX-008om5-QD for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Nov 2023 05:57:20 +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 1r8DZV-009CO2-LR for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Nov 2023 05:57:17 +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 1r8DZU-009CMN-Qf for pgsql-bugs@lists.postgresql.org; Wed, 29 Nov 2023 05:57:17 +0000 Received: from m15.mail.163.com ([45.254.50.219]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r8DZM-007syS-Jm for pgsql-bugs@lists.postgresql.org; Wed, 29 Nov 2023 05:57:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=7bGcuZWZcrsPXStSTLz0zEw6nDufE+udr9m+iVQ3g5E=; b=kZvAmw+rle/l0f50BHRQwxaRh5RZAob73hhak+6xAD8P/Y9FFwfSrhoL2FYGTW RmrEC2H8N/z7yh3o9QqxC+3sVMKYUASV+SRlFnBuJuyXA0odlCOVBciOh/02hmln H/azA29sKHSi8gVvv3egdtp62c/NNVBI5eJPvni3RVe10= Received: from b97369165980 (unknown [140.205.118.163]) by zwqz-smtp-mta-g2-1 (Coremail) with SMTP id _____wAX7yeo0mZlmATpEA--.49465S3; Wed, 29 Nov 2023 13:56:57 +0800 (CST) References: <18213-dbcf8d67b0e687f5@postgresql.org> User-agent: mu4e 1.10.7; emacs 29.1 From: zhihuifan1213@163.com To: feichanghong@qq.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18213: Standby's repeatable read isolation level transaction encountered a "nonrepeatable read" problem Date: Wed, 29 Nov 2023 13:26:52 +0800 In-reply-to: <18213-dbcf8d67b0e687f5@postgresql.org> Message-ID: <87cyvtkspj.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID: _____wAX7yeo0mZlmATpEA--.49465S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7ury7GFWUXFWDGr48XFWDJwb_yoW8Aw15pF WFk3W09a95Ja48Gw1kXw18XFyj9rZ5Gw13Gr4UGaykArW5CF1fAFWvgr17ArW5GrWvvFy2 vFs2yFykJw1q93DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zR-Aw-UUUUU= X-Originating-IP: [140.205.118.163] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbBnhI3U1etezfWSwABsC List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, Thanks for the report! PG Bug reporting form writes: > Standby executes select again (still within the existing repeatable read > transaction). We expect that the results of the two select should be the > same, but the second select did not get any data. > ``` > postgres=*# select a, b from t where a = 5; > a | b > ---+--- > 5 | 5 > (1 row) > > postgres=*# set enable_seqscan to off; > SET > postgres=*# select a, b from t where a = 5; > a | b > ---+--- > (0 rows) > ``` I can confirm this bug in the current master and continue with your test: postgres=*# set enable_seqscan to off; SET postgres=*# select a, b from t where a = 5; a | b ---+--- (0 rows) postgres=*# set enable_seqscan to on; SET postgres=*# select a, b from t where a = 5; a | b ---+--- 5 | 5 (1 row) Different plan yieds different result is bad. > We have several ideas to fix this problem, but they all have obvious > flaws: > 1. In the WaitForOlderSnapshots function in the final stage of "create index > concurrently", wait for replication_slot_xmin to exceed limitXmin. In this > solution, when there are long transactions on Standby, "create index > concurrently" operations may be blocked. +1 for this one. The current code doesn't take the advice from the comments for validate_index, where it says.. * .... Also, we index only tuples that are valid * as of the start of the scan (see table_index_build_scan), whereas a normal * build takes care to include recently-dead tuples. This is OK because * we won't mark the index valid until all transactions that might be able * to see those tuples are gone. The reason for doing that is ... In the current code, it doesn't consider the sessiones in standby. I guess you have worked out a fix for this, if so, could you provide one for review / test? -- Best Regards Andy Fan