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 1kD3HD-0000kt-8B for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Sep 2020 10:12:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kD3HC-0007no-5O for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Sep 2020 10:12:30 +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 1kD3HB-0007nh-Qt for pgsql-hackers@lists.postgresql.org; Tue, 01 Sep 2020 10:12:29 +0000 Received: from mail-il1-x143.google.com ([2607:f8b0:4864:20::143]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kD3H4-0006TM-Go for pgsql-hackers@lists.postgresql.org; Tue, 01 Sep 2020 10:12:28 +0000 Received: by mail-il1-x143.google.com with SMTP id x2so692875ilm.0 for ; Tue, 01 Sep 2020 03:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=eLTqC9Qkn3z+n9FvPZr8jsloXhFX1xkn/csW0TSlxcI=; b=ykKecmZYlAR58B4KQvseV8rotU/mcI7zMx7zBHZGwyRJPE2cr9uiUMOZj+0cAkq+aY bJLUc0p66t2zirVMd9ewzhAnj23uAJVJL+ixg0h6MGIKOOr18i6H41OXBmBE3mebJEgC I9GmD/c+wejPOvT+FO73HN9bBHXAWeTTB8Rs/fPRj4ECVyjTUbbMwVPv7iym7GcQYu7z 7nOCCL7HHWtBfjhZhM8rNVvWmLdh/tWKlaeaE/mfBDF0HDDKaMOPm4Jbhskc6w0V4zWy xBUkaxmpzfp/qNesso8zkJti8/poJPIAO5Mi/3ES8SjV90kDGmviPYKU/gmW2L0AFRWf c0ew== 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=eLTqC9Qkn3z+n9FvPZr8jsloXhFX1xkn/csW0TSlxcI=; b=nnFGx0efXl0MahQNktnOv7XvBDJKU5w1YIL+a3wSOVp0fQBvcUbu3mu2Wc0dKZlp43 egE3LtmqlDcm0YYzLbTOaacT0lRxPnocOp0aGx5aY9jw1fkALH4cwlKQLr2v2Gx8ClWN XuowjCj/7atik6CVejvlqDTRJsI9SR+mxhx8UrD1dr8J8U+/iPFULaJLmiAygEv8JmC7 urMNE4Rrty3QVuG5iaRtuGwedXdDSCOqo8tM6ROnbUdRY+4VjW6VMmlJ+lZxVWM0WT+B VeZTN9Cg8DxpRDbLq37aGL4vY6SMp8zTLBhPHoqiS8OA+16r8FELy+v6QYanXLBmIZff Nudg== X-Gm-Message-State: AOAM530/Zk+nI+UH+0NBNPBkXl0WhjPPIPQ3rkdjf/FP5rPNb6soycnz CDnZJ7W5B39N98UOQ4/59b9yaA== X-Google-Smtp-Source: ABdhPJxfHnJdraHcvPJ8H6Wo4QTC90/MBuGxP3bqzFCRb0ftFXEP+/W59MLFsaOgY9gAkR3eCgdwOQ== X-Received: by 2002:a92:d988:: with SMTP id r8mr645726iln.51.1598955141550; Tue, 01 Sep 2020 03:12:21 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id o1sm360539ilo.32.2020.09.01.03.12.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Sep 2020 03:12:20 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 9F73680015B; Tue, 1 Sep 2020 05:12:19 -0500 (CDT) Date: Tue, 1 Sep 2020 05:12:19 -0500 From: Justin Pryzby To: Michael Paquier Cc: Alexey Kondratov , Masahiko Sawada , Steve Singer , pgsql-hackers@lists.postgresql.org, Alvaro Herrera , Robert Haas , Alexander Korotkov , Masahiko Sawada , Jose Luis Tallon Subject: Re: Allow CLUSTER, VACUUM FULL and REINDEX to change tablespace on the fly Message-ID: <20200901101219.GB5450@telsasoft.com> References: <20200406184406.GF2228@telsasoft.com> <9b6a6cec134451550b74aa2ffd1446d0@postgrespro.ru> <20200407204406.GR2228@telsasoft.com> <20200412013352.GA2491@telsasoft.com> <20200426175614.GT28974@telsasoft.com> <20200809110252.GD17986@paquier.xyz> <20200810022443.GI20473@telsasoft.com> <20200811053945.GG17986@paquier.xyz> <20200811070922.GP20473@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200811070922.GP20473@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This patch seems to be missing a call to RelationAssumeNewRelfilenode() in reindex_index(). That's maybe the related to the cause of the crashes I pointed out earlier this year. Alexey's v4 patch changed RelationSetNewRelfilenode() to accept a tablespace parameter, but Michael seemed to object to that. However that seems cleaner and ~30 line shorter. Michael, would you comment on that ? The v4 patch and your comments are here. https://www.postgresql.org/message-id/attachment/105574/v4-0001-Allow-REINDEX-and-REINDEX-CONCURRENTLY-to-change-tablespace.patch https://www.postgresql.org/message-id/20191127035416.GG5435%40paquier.xyz > --- a/src/backend/catalog/index.c > +++ b/src/backend/catalog/index.c > @@ -3480,6 +3518,47 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, > */ > CheckTableNotInUse(iRel, "REINDEX INDEX"); > > + if (tablespaceOid == MyDatabaseTableSpace) > + tablespaceOid = InvalidOid; > + > + /* > + * Set the new tablespace for the relation. Do that only in the > + * case where the reindex caller wishes to enforce a new tablespace. > + */ > + if (set_tablespace && > + tablespaceOid != iRel->rd_rel->reltablespace) > + { > + Relation pg_class; > + Form_pg_class rd_rel; > + HeapTuple tuple; > + > + /* First get a modifiable copy of the relation's pg_class row */ > + pg_class = table_open(RelationRelationId, RowExclusiveLock); > + > + tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(indexId)); > + if (!HeapTupleIsValid(tuple)) > + elog(ERROR, "cache lookup failed for relation %u", indexId); > + rd_rel = (Form_pg_class) GETSTRUCT(tuple); > + > + /* > + * Mark the relation as ready to be dropped at transaction commit, > + * before making visible the new tablespace change so as this won't > + * miss things. > + */ > + RelationDropStorage(iRel); > + > + /* Update the pg_class row */ > + rd_rel->reltablespace = tablespaceOid; > + CatalogTupleUpdate(pg_class, &tuple->t_self, tuple); > + > + heap_freetuple(tuple); > + > + table_close(pg_class, RowExclusiveLock); > + > + /* Make sure the reltablespace change is visible */ > + CommandCounterIncrement();