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 1nDdZM-0005sa-Ip for pgsql-bugs@arkaria.postgresql.org; Sat, 29 Jan 2022 02:34:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nDdZJ-0004MR-Jp for pgsql-bugs@arkaria.postgresql.org; Sat, 29 Jan 2022 02:34:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nDdZI-0004MH-Sp for pgsql-bugs@lists.postgresql.org; Sat, 29 Jan 2022 02:34:25 +0000 Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nDdZF-00042g-U2 for pgsql-bugs@lists.postgresql.org; Sat, 29 Jan 2022 02:34:23 +0000 Received: by mail-qt1-x82b.google.com with SMTP id j12so6544999qtr.2 for ; Fri, 28 Jan 2022 18:34:21 -0800 (PST) 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:in-reply-to:user-agent; bh=8e+pJ/4haOwGxEFizYGPjhQSr6tka5dpM9llwNGCiz8=; b=erPGzE/3yEbvqMlOeW2A80ML0LTLcJpj2Cd6s0UStHrA6ZueHG/a1pOkBWOIFIXpSO wsnFvU7eCUn49t/vveB4VVjuBpDE/4VAwW6ECraTISUbfK9CfHqg8Ft8jRjc6PJHgRMX ndJtOhE2gNONVdXf/fRGlw3p8fKB8+dLMesuw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=8e+pJ/4haOwGxEFizYGPjhQSr6tka5dpM9llwNGCiz8=; b=QSFUOHTW5dkf8P6BVN+dkWH5TWeZtUoE5IX7KwExrm4uISB7sdlA9LNM32m8IRA4U6 6zza44mv8DgcjgoxTSyVSXhh/pExxE1afT3j789PZ7nXBbmehsjnpZH381F12R/PcWrW KbZRw+4TE47FTVhwkG89hC1ldb9GfNuhksPCYbUvsAraCw1TfM6m6Dd9qwTGOtGGpzXt 3NcyIh+K+XrDZQ3MCFtKIeOMx0XWzAjq36vQHnnfLhRqJb32cIe3K6RZ1x02A8vD53NP WXEZIvRsk9mahDKX96+9QKsnKq+C9LITGVGM/ZiDUX7JWbgGU04jX2L0KBKJ8aOrcJAD S4kA== X-Gm-Message-State: AOAM530s1sIhgRYzx3m5eWf2LWaGiWiBG/2+0WtSkwXk5v9MAlUkk2u9 oBMZcJqPTcbcEW0jrYfINty51CXYErN4hA== X-Google-Smtp-Source: ABdhPJw85k1IOHicOFfBGObfTKY57HR2LRkLhSEv5hdhK7xSj6GVFFcRYT9/9zmFIRsxOloRNCxltQ== X-Received: by 2002:ac8:7f86:: with SMTP id z6mr8404455qtj.686.1643423660766; Fri, 28 Jan 2022 18:34:20 -0800 (PST) Received: from rfd.leadboat.com ([2600:1702:a20:5750::2e]) by smtp.gmail.com with ESMTPSA id bj24sm2282331qkb.115.2022.01.28.18.34.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Jan 2022 18:34:20 -0800 (PST) Date: Fri, 28 Jan 2022 18:34:18 -0800 From: Noah Misch To: Maxim Boguk Cc: PostgreSQL mailing lists Subject: Re: BUG #17386: btree index corruption after reindex concurrently on write heavy table Message-ID: <20220129023418.GA2452893@rfd.leadboat.com> References: <17386-2227568627fb44ce@postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="VS++wcV0S1rZb1Fb" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --VS++wcV0S1rZb1Fb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Jan 28, 2022 at 04:17:28PM +0200, Maxim Boguk wrote: > On Fri, Jan 28, 2022 at 3:42 PM PG Bug reporting form wrote: > > PostgreSQL version: 14.1 > Seems something broken in combination of HOT update and REINDEX > CONCURRENTLY. Agreed. Can you create a self-contained test case, perhaps by adapting contrib/amcheck/t/002_cic.pl? If this bug is like the ones fixed between 14.0 and 14.1, the base backup and WAL won't help us, unfortunately. The transient states are what matter. I did try modifying the test to have elements of your scenario, including HOT updates, KEY SHARE locks, and frozen tuples. That didn't reproduce the bug. I'm attaching what I tried. --VS++wcV0S1rZb1Fb Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="repro-reindex-hot-v0.patch" Author: Noah Misch Commit: Noah Misch diff --git a/contrib/amcheck/t/002_cic.pl b/contrib/amcheck/t/002_cic.pl index f6b91e8..831395f 100644 --- a/contrib/amcheck/t/002_cic.pl +++ b/contrib/amcheck/t/002_cic.pl @@ -21,8 +21,9 @@ $node->init; $node->append_conf('postgresql.conf', 'lock_timeout = 180000'); $node->start; $node->safe_psql('postgres', q(CREATE EXTENSION amcheck)); -$node->safe_psql('postgres', q(CREATE TABLE tbl(i int))); -$node->safe_psql('postgres', q(CREATE INDEX idx ON tbl(i))); +$node->safe_psql('postgres', q(CREATE TABLE tbl(k int, v int))); +$node->safe_psql('postgres', q(INSERT INTO tbl SELECT n, 0 FROM generate_series(0,9) t(n))); +$node->safe_psql('postgres', q(CREATE INDEX idx ON tbl(k))); # # Stress CIC with pgbench. @@ -32,33 +33,39 @@ $node->safe_psql('postgres', q(CREATE INDEX idx ON tbl(i))); # lock to ensure only one CIC runs at a time. # $node->pgbench( - '--no-vacuum --client=5 --transactions=100', + '--no-vacuum --client=5 --transactions=20000', 0, [qr{actually processed}], [qr{^$}], 'concurrent INSERTs and CIC', { - '002_pgbench_concurrent_transaction' => q( - BEGIN; - INSERT INTO tbl VALUES(0); - COMMIT; + 'hot_update_commit' => q( + UPDATE tbl SET v = v + 1 WHERE k = :client_id; ), - '002_pgbench_concurrent_transaction_savepoints' => q( + 'hot_update_rollback' => q( BEGIN; - SAVEPOINT s1; - INSERT INTO tbl VALUES(0); - COMMIT; + UPDATE tbl SET v = v + 1 WHERE k = :client_id; + ROLLBACK; + ), + 'vacuum' => q( + VACUUM FREEZE tbl; + ), + 'key_share' => q( + SELECT * FROM tbl FOR KEY SHARE; ), '002_pgbench_concurrent_cic' => q( SELECT pg_try_advisory_lock(42)::integer AS gotlock \gset \if :gotlock - DROP INDEX CONCURRENTLY idx; - CREATE INDEX CONCURRENTLY idx ON tbl(i); + REINDEX INDEX CONCURRENTLY idx; SELECT bt_index_check('idx',true); SELECT pg_advisory_unlock(42); \endif ) }); +print $node->safe_psql('postgres', + q(SELECT * FROM pg_stat_all_tables where relname = 'tbl'), + extra_params => ['--expanded']); + $node->stop; done_testing(); --VS++wcV0S1rZb1Fb--