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 1l2hTn-0005gX-8c for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jan 2021 21:26: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 1l2hTm-00060G-74 for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jan 2021 21:26:58 +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 1l2hTl-000609-RX for pgsql-hackers@lists.postgresql.org; Thu, 21 Jan 2021 21:26:58 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l2hTi-0003lJ-Rm for pgsql-hackers@lists.postgresql.org; Thu, 21 Jan 2021 21:26:56 +0000 Received: by mail-io1-xd31.google.com with SMTP id y19so7051341iov.2 for ; Thu, 21 Jan 2021 13:26:54 -0800 (PST) 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=nyI/wP/BUrsUebpVyR9oyftdC+mOlSyKzdhTiYTi7AQ=; b=R/gSub17ofjyqgmcE7rEViVzmle+TCuEZdqCC6BJH5l5ripOsOrr7KJdwOGYeZzn3V gc1aj+zFDGkQPXlQls76Huh4AihKouZ78Mo9yHkIevai+fUXUWDlQDuN9SAI5QcQnt5w s9r6eGl+RyKWyN5YQB9MSb0ZqkbTcybVphdOxC37y/bEMbpRj19C7ZShvBJRykDpDPQg yNGQJuDUxu/L1Hh9b9kbZHHgJjZsFnw/ISmitAmYWgj0ggCY7f6Zv5WxrJD+FjOkhLVt 6K6N4VcfMgB+AjGDTrSi1qBb3tthV5ovoV5O9MG4mL+URpHeZLM3y6SFdb5IdOcglnsg gvZg== 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=nyI/wP/BUrsUebpVyR9oyftdC+mOlSyKzdhTiYTi7AQ=; b=LrTa2Pt3Vl3VNsGPZQc6m9zFe23eTAeRr5xEv3W1euz/1UT53512ZuvpwdGnI/TmOV TVnqH0eBjuraPnwDYs+Y/CR84e4xUnJ2b58cT0AS/+uA0OyYE75e8C+saO+CbB5T+0oi lvqq9ZTTJTxx3cmLy9j2i3jN2J1ZA/39/RWGLp7R6qsFdo7e1YMMhHbkk1YrvM0pErjJ 5y59W3vn+jozVWL6daEq+ot6tCsdwd+ytTGN1uWTp1VG8hVo+TVZ/DlOR6CFBdQ9sUs1 zl3xXTtxqA8D0PkHNroEkGApa4CqC88vKFOrzZ5fCx/uLpP5VBU2TUTh3aYQfuwFB7vx iJpw== X-Gm-Message-State: AOAM533VZuPcyLT0JsPBsIYhfBgX88qSANNeeMQaINOMBcv+tkQ9Uekg mv1iXZI1cflR6HPvKn4gXxcULQ== X-Google-Smtp-Source: ABdhPJwmalkVSRcnsW3PRxA/Wno+9zpysMPjvWG7/+RPwDLrYQ9wjkr+q4DWjKhrkUb6E6DyBXifdw== X-Received: by 2002:a92:850a:: with SMTP id f10mr1454970ilh.269.1611264413912; Thu, 21 Jan 2021 13:26:53 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id x2sm3228205ior.42.2021.01.21.13.26.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jan 2021 13:26:52 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 065F880090D; Thu, 21 Jan 2021 15:26:51 -0600 (CST) Date: Thu, 21 Jan 2021 15:26:51 -0600 From: Justin Pryzby To: Alexey Kondratov Cc: Michael Paquier , Alvaro Herrera , Peter Eisentraut , Masahiko Sawada , Steve Singer , pgsql-hackers@lists.postgresql.org, 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: <20210121212651.GY8560@telsasoft.com> References: <03f88f70618ce73e75837b6125a143f7@postgrespro.ru> <20210120183439.GA21339@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Jan 21, 2021 at 11:48:08PM +0300, Alexey Kondratov wrote: > Attached is a new patch set of first two patches, that should resolve all > the issues raised before (ACL, docs, tests) excepting TOAST. Double thanks > for suggestion to add more tests with nested partitioning. I have found and > squashed a huge bug related to the returning back to the default tablespace > using newly added tests. > > Regarding TOAST. Now we skip moving toast indexes or throw error if someone > wants to move TOAST index directly. I had a look on ALTER TABLE SET > TABLESPACE and it has a bit complicated logic: > > 1) You cannot move TOAST table directly. > 2) But if you move basic relation that TOAST table belongs to, then they are > moved altogether. > 3) Same logic as 2) happens if one does ALTER TABLE ALL IN TABLESPACE ... > > That way, ALTER TABLE allows moving TOAST tables (with indexes) implicitly, > but does not allow doing that explicitly. In the same time I found docs to > be vague about such behavior it only says: > > All tables in the current database in a tablespace can be moved > by using the ALL IN TABLESPACE ... Note that system catalogs are > not moved by this command > > Changing any part of a system catalog table is not permitted. > > So actually ALTER TABLE treats TOAST relations as system sometimes, but > sometimes not. > > From the end user perspective it makes sense to move TOAST with main table > when doing ALTER TABLE SET TABLESPACE. But should we touch indexes on TOAST > table with REINDEX? We cannot move TOAST relation itself, since we are doing > only a reindex, so we end up in the state when TOAST table and its index are > placed in the different tablespaces. This state is not reachable with ALTER > TABLE/INDEX, so it seem we should not allow it with REINDEX as well, should > we? > + * Even if a table's indexes were moved to a new tablespace, the index > + * on its toast table is not normally moved. > */ > ReindexParams newparams = *params; > > newparams.options &= ~(REINDEXOPT_MISSING_OK); > + if (!allowSystemTableMods) > + newparams.tablespaceOid = InvalidOid; I think you're right. So actually TOAST should never move, even if allowSystemTableMods, right ? > @@ -292,7 +315,11 @@ REINDEX [ ( option [, ...] ) ] { IN > with REINDEX INDEX or REINDEX TABLE, > respectively. Each partition of the specified partitioned relation is > reindexed in a separate transaction. Those commands cannot be used inside > - a transaction block when working on a partitioned table or index. > + a transaction block when working on a partitioned table or index. If > + REINDEX with TABLESPACE executed > + on partitioned relation fails it may have moved some partitions to the new > + tablespace. Repeated command will still reindex all partitions even if they > + are already in the new tablespace. Minor corrections here: If a REINDEX command fails when run on a partitioned relation, and TABLESPACE was specified, then it may have moved indexes on some partitions to the new tablespace. Re-running the command will reindex all partitions and move previously-unprocessed indexes to the new tablespace. -- Justin