Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m9XS4-0006wr-1N for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Jul 2021 18:41:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m9XS2-0008Ry-9u for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Jul 2021 18:41:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m9XS1-0008RK-SP for pgsql-bugs@lists.postgresql.org; Fri, 30 Jul 2021 18:41:42 +0000 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m9XRy-0001ft-G2 for pgsql-bugs@lists.postgresql.org; Fri, 30 Jul 2021 18:41:41 +0000 Received: by mail-io1-xd34.google.com with SMTP id r18so12636565iot.4 for ; Fri, 30 Jul 2021 11:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=/V1xQq7aWei1oWaXneVaBQ4YLA5fDUgamxUTl/kQJ58=; b=KyX2Aj4HCDnBvZxzWCf6fgOIVW8zgleJEKmZaZWn4MJTS2VR4TqJ6v3x5lC9cV7uVM +XR3lEXG1z9S/PDcHBfRU72O6dLq14TLTVG76u6BRIwQBO0tGayL/CHX2zeFbMBh8Egu QVf38wW60wBT7Q5RKL0h0q18MLnnYuIcu0OB0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=/V1xQq7aWei1oWaXneVaBQ4YLA5fDUgamxUTl/kQJ58=; b=ggg8O9tNarkdXRFtk6N28aA3uaYEuhdUb8IDxdA8suVT5XAcQpKi6Aid/nfC9hdn0j QUXCL8wcTN/d6kibX1Oh+VsN9GJx2AQn/Rw+8u1Wm464c1Dmzj9G+Zt4rV/mLNDrvy5W ae2oehoTRL85I6wUqK/UFKhJwEmC41GpoC8+g7p4uLNKYmCvWaz1qD8I+QFbVSE0GPZp 7MppkWNhJA54US493+xoHalox7vjQS0zZbgoDHR1BzXxdaVzaIB84XyyJo1VYAD3V6OW poZIX9yE61A3n6GYugDDTvkU1PjuX4q5qft0xcK60D4lxjkmHZbhwL86t5vbPJ80T3hX tlCQ== X-Gm-Message-State: AOAM532PluR5a+pcavcVz0bgLyyrn/hxkqwVP12ITg58VCW5GfoW3s0n LqTpT6HGt4joZTgpbVj9ClJh9A== X-Google-Smtp-Source: ABdhPJzsXRpZnYGVPRLL6GTFQobPlY8ju1cADvMGx0cj/oH77IgQMfx5A+4h3TkyiLZQBDRH0/gCSQ== X-Received: by 2002:a02:ca58:: with SMTP id i24mr3178230jal.101.1627670496670; Fri, 30 Jul 2021 11:41:36 -0700 (PDT) Received: from gust.leadboat.com ([172.243.183.102]) by smtp.gmail.com with ESMTPSA id o13sm1268616ilq.58.2021.07.30.11.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jul 2021 11:41:35 -0700 (PDT) Date: Fri, 30 Jul 2021 14:41:26 -0400 From: Noah Misch To: Andrey Borodin Cc: Michael Paquier , Tom Lane , pgsql-bugs@lists.postgresql.org Subject: Re: CREATE INDEX CONCURRENTLY does not index prepared xact's data Message-ID: <20210730184126.GA2018234@gust.leadboat.com> References: <20210720214936.GA1040253@gust.leadboat.com> <20210721175530.GA1090577@gust.leadboat.com> <946242CB-D63A-4D7B-A5A5-485165F5B78A@yandex-team.ru> <20210723223021.GA1354601@gust.leadboat.com> <845C714B-DBCF-49E9-9F95-238DB042F926@yandex-team.ru> <20210730022548.GA1940096@gust.leadboat.com> 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 Fri, Jul 30, 2021 at 03:42:10PM +0500, Andrey Borodin wrote: > > 30 июля 2021 г., в 07:25, Noah Misch написал(а): > > What alternative fix designs should we consider? > > I observe that provided patch fixes CIC under normal transactions, but test with 2PC still fails similarly. > Unindexed tuple was committed somewhere at the end of Phase 3 or 4. > 2021-07-30 15:35:31.806 +05 [25987] 002_cic_2pc.pl LOG: statement: REINDEX INDEX CONCURRENTLY idx; > 2021-07-30 15:35:31.806 +05 [25987] 002_cic_2pc.pl WARNING: Phase 1 > 2021-07-30 15:35:31.806 +05 [25987] 002_cic_2pc.pl WARNING: Phase 2 > 2021-07-30 15:35:31.806 +05 [25987] 002_cic_2pc.pl WARNING: XXX: VirtualXactLock vxid -1/6735 > 2021-07-30 15:35:31.807 +05 [25987] 002_cic_2pc.pl WARNING: XXX: VirtualXactLock vxid -1/6736 > 2021-07-30 15:35:31.808 +05 [25987] 002_cic_2pc.pl WARNING: Phase 3 > 2021-07-30 15:35:31.808 +05 [25987] 002_cic_2pc.pl WARNING: XXX: VirtualXactLock vxid -1/6750 > 2021-07-30 15:35:31.809 +05 [25987] 002_cic_2pc.pl WARNING: Phase 4 > 2021-07-30 15:35:31.809 +05 [25987] 002_cic_2pc.pl WARNING: Phase 5 > 2021-07-30 15:35:31.809 +05 [25987] 002_cic_2pc.pl WARNING: XXX: VirtualXactLock vxid -1/6762 > 2021-07-30 15:35:31.809 +05 [25987] 002_cic_2pc.pl WARNING: XXX: VirtualXactLock vxid -1/6763 > 2021-07-30 15:35:31.810 +05 [25987] 002_cic_2pc.pl WARNING: Phase 6 > 2021-07-30 15:35:31.810 +05 [25987] 002_cic_2pc.pl WARNING: XXX: VirtualXactLock vxid 6/2166 > 2021-07-30 15:35:31.810 +05 [25987] 002_cic_2pc.pl WARNING: XXX: VirtualXactLock vxid -1/6767 > 2021-07-30 15:35:31.810 +05 [25987] 002_cic_2pc.pl WARNING: XXX: VirtualXactLock vxid -1/6764 > 2021-07-30 15:35:31.810 +05 [25987] 002_cic_2pc.pl WARNING: XXX: VirtualXactLock vxid -1/6765 > 2021-07-30 15:35:31.811 +05 [25987] 002_cic_2pc.pl WARNING: Phase Final > 2021-07-30 15:35:31.811 +05 [25987] 002_cic_2pc.pl LOG: statement: SELECT bt_index_check('idx',true); > 2021-07-30 15:35:31.813 +05 [25987] 002_cic_2pc.pl ERROR: heap tuple (46,16) from table "tbl" lacks matching index tuple within index "idx" xmin 6751 xmax 0 I see a failure, too. Once again, "i:" lines are events within the INSERT backend, and "r:" lines are events within the REINDEX CONCURRENTLY backend: r: Phase 2 begins. i: INSERT. Start PREPARE. r: Phase 2 commits indisready=t for idx_ccnew. r: Start waiting for the INSERT to finish. i: PREPARE finishes. r: Wake up and start validate_index(). This is a problem. It needed to wait for COMMIT PREPARED to finish. This may have a different explanation than the failure you saw, because my INSERT transaction already had a permanent XID before the start of phase 3. I won't have time to study this further in the next several days. Can you find out where things go wrong? The next thing I would study is VirtualXactLock(), specifically what happens if the lock holder is a normal backend (with or without an XID) when VirtualXactLock() starts but becomes a prepared transaction (w/ different PGPROC) before VirtualXactLock() ends.