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 1kFrMs-00087v-Ra for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Sep 2020 04:05:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kFrMr-0002zi-91 for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Sep 2020 04:05:57 +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 1kFrMq-0002yk-PN for pgsql-hackers@lists.postgresql.org; Wed, 09 Sep 2020 04:05:57 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kFrMj-00086m-KO for pgsql-hackers@postgresql.org; Wed, 09 Sep 2020 04:05:56 +0000 Received: by mail-pg1-x544.google.com with SMTP id t14so1078429pgl.10 for ; Tue, 08 Sep 2020 21:05:49 -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:in-reply-to:user-agent; bh=gVreuzI/2ZlKO3GtnP8tQjh84/McAYdRDwLe9kawfF8=; b=PSP/pScRiUHenYvtM/ktb+rhXhqakoNHAtN4gvEX4QexXAsXW0t2gf7shidBcg9pt9 tFPM8v1xqIYIKjf1v+liIQbX77lUG8vIvYP0cytXObDzF0A1q6wovAho6KPCc+FbqwnE OpcA4WDLlwF6dUw5L3KPgUWIz8/N/Ekm4QQfs= 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:in-reply-to:user-agent; bh=gVreuzI/2ZlKO3GtnP8tQjh84/McAYdRDwLe9kawfF8=; b=QhpSLyWzJ0iWUYLnb/6rqAqLBjaQl3AOwWONFZG0F4gZXI2suFr2Si/m+1vs87kmPK LtkMoLXCZg7/+7dH8gcrRvFV10ykvX+lQ91mBr36NeJLdZVfy9nYakWBHKKmVCZJiVZA sOgztxMbtcfEi80dGTsY4XBI0fmUkBT9IkorokcHLOCiP2Vzooawfu4TOENdwqZQG2Sw Wij3r6EX0xIDYONs3Nu5/ILCOd1v/To/KpUaxNx80hSgKydoAYPYFmTM6++0zeBpfrHs OweNGjJnFSPk9j1De0xG3Y/CYANBVhMtiySBX60rDri0tODjLp/xANTdoG/6PUlmi2a0 /v+g== X-Gm-Message-State: AOAM531A7BI4d7cw+IyNypINUmvvKbiGPKAdSDBMyNO8GX/vUvF6rNbd jEkTggEYosDKeShtrn5UpV8nzw== X-Google-Smtp-Source: ABdhPJyKGcAx9pEPj02LSIXt5oZF+qvmTQZEvA4kNA8wlEKkdOQwELO71bs0PsA63jgWvd+i3Pksog== X-Received: by 2002:a63:4cc:: with SMTP id 195mr1519012pge.376.1599624346621; Tue, 08 Sep 2020 21:05:46 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::43]) by smtp.gmail.com with ESMTPSA id k24sm818163pfg.148.2020.09.08.21.05.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Sep 2020 21:05:45 -0700 (PDT) Date: Tue, 8 Sep 2020 21:05:43 -0700 From: Noah Misch To: Kyotaro Horiguchi Cc: tgl@sss.pgh.pa.us, pryzby@telsasoft.com, pgsql-hackers@postgresql.org Subject: Re: v13: CLUSTER segv with wal_level=minimal and parallel index creation Message-ID: <20200909040543.GA15541@rfd.leadboat.com> References: <20200907.174036.603784943439284546.horikyota.ntt@gmail.com> <20200907093255.GA3609623@rfd.leadboat.com> <20200908.091353.1505164218636547516.horikyota.ntt@gmail.com> <20200908.104332.1790214922230554649.horikyota.ntt@gmail.com> <20200908024709.GA3640955@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="pf9I7BMVVzbSWLtt" Content-Disposition: inline In-Reply-To: <20200908024709.GA3640955@rfd.leadboat.com> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --pf9I7BMVVzbSWLtt Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Sep 07, 2020 at 07:47:09PM -0700, Noah Misch wrote: > On Tue, Sep 08, 2020 at 10:43:32AM +0900, Kyotaro Horiguchi wrote: > > At Tue, 08 Sep 2020 09:13:53 +0900 (JST), Kyotaro Horiguchi wrote in > > > At Mon, 7 Sep 2020 02:32:55 -0700, Noah Misch wrote in > > > > As a PoC, this looks promising. Thanks. Would you add a test case such that > > > > the following demonstrates the bug in the absence of your PoC? > > > > > > > > printf '%s\n%s\n%s\n' 'log_statement = all' 'wal_level = minimal' 'max_wal_senders = 0' >/tmp/minimal.conf > > > > make check TEMP_CONFIG=/tmp/minimal.conf > > > > > > Mmm. I was close to add some tests to 018_wal_optimize.pl but your > > > suggestion seems better. I added several ines to create_index.sql. After looking closer, I've moved the test to reindex_catalog.sql; see that file's header comment for the reasons. One now needs this command: printf '%s\n%s\n%s\n' 'log_statement = all' 'wal_level = minimal' 'max_wal_senders = 0' >/tmp/minimal.conf make check-tests TESTS=reindex_catalog TEMP_CONFIG=/tmp/minimal.conf > > > > Please have the test try both a nailed-and-mapped relation and a "nailed, but > > > > not mapped" relation. I am fairly confident that your PoC fixes the former > > > > case, but the latter may need additional code. > > > > > > Mmm. You're right. I choosed pg_amproc_fam_proc_index as > > > nailed-but-not-mapped index. > > > > I fixed a typo (s/staring/starting/). > > At a glance, this looks reasonable. If a closer look doesn't reveal problems, > I'll push this. RelationBuildDesc() calls RelationInitPhysicalAddr(), so RelationBuildDesc() can stop calling RelFileNodeSkippingWAL(). The attached version makes it so, and I plan to push it. --pf9I7BMVVzbSWLtt Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="skip-wal-nailed-v3.patch" Author: Noah Misch Commit: Noah Misch Fix rd_firstRelfilenodeSubid for nailed relations, in parallel workers. Move applicable code out of RelationBuildDesc(), which nailed relations bypass. Non-assert builds experienced no known problems. Back-patch to v13, where commit c6b92041d38512a4176ed76ad06f713d2e6c01a8 introduced rd_firstRelfilenodeSubid. Kyotaro Horiguchi. Reported by Justin Pryzby. Discussion: https://postgr.es/m/20200907023737.GA7158@telsasoft.com diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 96ecad0..9061af8 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1243,14 +1243,6 @@ RelationBuildDesc(Oid targetRelId, bool insertIt) if (insertIt) RelationCacheInsert(relation, true); - /* - * For RelationNeedsWAL() to answer correctly on parallel workers, restore - * rd_firstRelfilenodeSubid. No subtransactions start or end while in - * parallel mode, so the specific SubTransactionId does not matter. - */ - if (IsParallelWorker() && RelFileNodeSkippingWAL(relation->rd_node)) - relation->rd_firstRelfilenodeSubid = TopSubTransactionId; - /* It's fully valid */ relation->rd_isvalid = true; @@ -1273,6 +1265,8 @@ RelationBuildDesc(Oid targetRelId, bool insertIt) static void RelationInitPhysicalAddr(Relation relation) { + Oid oldnode = relation->rd_node.relNode; + /* these relations kinds never have storage */ if (!RELKIND_HAS_STORAGE(relation->rd_rel->relkind)) return; @@ -1330,6 +1324,19 @@ RelationInitPhysicalAddr(Relation relation) elog(ERROR, "could not find relation mapping for relation \"%s\", OID %u", RelationGetRelationName(relation), relation->rd_id); } + + /* + * For RelationNeedsWAL() to answer correctly on parallel workers, restore + * rd_firstRelfilenodeSubid. No subtransactions start or end while in + * parallel mode, so the specific SubTransactionId does not matter. + */ + if (IsParallelWorker() && oldnode != relation->rd_node.relNode) + { + if (RelFileNodeSkippingWAL(relation->rd_node)) + relation->rd_firstRelfilenodeSubid = TopSubTransactionId; + else + relation->rd_firstRelfilenodeSubid = InvalidSubTransactionId; + } } /* diff --git a/src/test/regress/expected/reindex_catalog.out b/src/test/regress/expected/reindex_catalog.out index 4b5fba4..204f056 100644 --- a/src/test/regress/expected/reindex_catalog.out +++ b/src/test/regress/expected/reindex_catalog.out @@ -36,3 +36,13 @@ REINDEX INDEX pg_index_indexrelid_index; -- non-mapped, non-shared, critical REINDEX INDEX pg_index_indrelid_index; -- non-mapped, non-shared, non-critical REINDEX INDEX pg_database_oid_index; -- mapped, shared, critical REINDEX INDEX pg_shdescription_o_c_index; -- mapped, shared, non-critical +-- Check the same REINDEX INDEX statements under parallelism. +BEGIN; +SET min_parallel_table_scan_size = 0; +REINDEX INDEX pg_class_oid_index; -- mapped, non-shared, critical +REINDEX INDEX pg_class_relname_nsp_index; -- mapped, non-shared, non-critical +REINDEX INDEX pg_index_indexrelid_index; -- non-mapped, non-shared, critical +REINDEX INDEX pg_index_indrelid_index; -- non-mapped, non-shared, non-critical +REINDEX INDEX pg_database_oid_index; -- mapped, shared, critical +REINDEX INDEX pg_shdescription_o_c_index; -- mapped, shared, non-critical +ROLLBACK; diff --git a/src/test/regress/sql/reindex_catalog.sql b/src/test/regress/sql/reindex_catalog.sql index 87ecf52..8203641 100644 --- a/src/test/regress/sql/reindex_catalog.sql +++ b/src/test/regress/sql/reindex_catalog.sql @@ -39,3 +39,14 @@ REINDEX INDEX pg_index_indexrelid_index; -- non-mapped, non-shared, critical REINDEX INDEX pg_index_indrelid_index; -- non-mapped, non-shared, non-critical REINDEX INDEX pg_database_oid_index; -- mapped, shared, critical REINDEX INDEX pg_shdescription_o_c_index; -- mapped, shared, non-critical + +-- Check the same REINDEX INDEX statements under parallelism. +BEGIN; +SET min_parallel_table_scan_size = 0; +REINDEX INDEX pg_class_oid_index; -- mapped, non-shared, critical +REINDEX INDEX pg_class_relname_nsp_index; -- mapped, non-shared, non-critical +REINDEX INDEX pg_index_indexrelid_index; -- non-mapped, non-shared, critical +REINDEX INDEX pg_index_indrelid_index; -- non-mapped, non-shared, non-critical +REINDEX INDEX pg_database_oid_index; -- mapped, shared, critical +REINDEX INDEX pg_shdescription_o_c_index; -- mapped, shared, non-critical +ROLLBACK; --pf9I7BMVVzbSWLtt--