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 1l7FVV-0002Hf-L0 for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Feb 2021 10:35:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l7FVU-000777-IS for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Feb 2021 10:35:32 +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 1l7FVU-000770-8O for pgsql-hackers@lists.postgresql.org; Wed, 03 Feb 2021 10:35:32 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l7FVP-0002Vp-Tp for pgsql-hackers@lists.postgresql.org; Wed, 03 Feb 2021 10:35:31 +0000 Received: from mail.postgrespro.ru (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 70B3B21C55CB; Wed, 3 Feb 2021 13:35:26 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1612348526; bh=3XXBnVs6vVYr1zFEIn7Zce2QKu81v1eLADo0wXt6HZs=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=Z7d+StluHYwQ4UIoR2ptuNfW8Lmz2ca57fga0TySSE9CJFwahoqfWy/kECxttqcOr VFnmDCqNuQL76eTxmx6V5nk0Qm6gQhHrAZvsJXnef3DlGM9F1O+6kSTyPxAsp8eWyP IrFgwb9oJjvGo+XWrRn8xg7xpTzZtLJg/psyParQ= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 03 Feb 2021 13:35:26 +0300 From: Alexey Kondratov To: Michael Paquier Cc: Alvaro Herrera , Justin Pryzby , 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 In-Reply-To: References: <20210127213658.GA736@alvherre.pgsql> <55c6c1526b94d2caf54c33262fe00674@postgrespro.ru> <1c506564e2a732ec17790bd8c34f042e@postgrespro.ru> User-Agent: Roundcube Webmail/1.4.0 Message-ID: <66bad38beb87fb32952d89602e467444@postgrespro.ru> X-Sender: a.kondratov@postgrespro.ru List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2021-02-03 09:37, Michael Paquier wrote: > On Tue, Feb 02, 2021 at 10:32:19AM +0900, Michael Paquier wrote: >> On Mon, Feb 01, 2021 at 06:28:57PM +0300, Alexey Kondratov wrote: >> > Hm, IIUC, REINDEX CONCURRENTLY doesn't use either of them. It directly uses >> > index_create() with a proper tablespaceOid instead of >> > SetRelationTableSpace(). And its checks structure is more restrictive even >> > without tablespace change, so it doesn't use CheckRelationTableSpaceMove(). >> >> Sure. I have not checked the patch in details, but even with that it >> would be much safer to me if we apply the same sanity checks >> everywhere. That's less potential holes to worry about. > > Thanks Alexey for the new patch. I have been looking at the main > patch in details. > > /* > - * Don't allow reindex on temp tables of other backends ... their > local > - * buffer manager is not going to cope. > + * We don't support moving system relations into different > tablespaces > + * unless allow_system_table_mods=1. > */ > If you remove the check on RELATION_IS_OTHER_TEMP() in > reindex_index(), you would allow the reindex of a temp relation owned > by a different session if its tablespace is not changed, so this > cannot be removed. > > + !allowSystemTableMods && IsSystemRelation(iRel)) > ereport(ERROR, > - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), > - errmsg("cannot reindex temporary tables of other > sessions"))); > + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), > + errmsg("permission denied: \"%s\" is a system > catalog", > + RelationGetRelationName(iRel)))); > Indeed, a system relation with a relfilenode should be allowed to move > under allow_system_table_mods. I think that we had better move this > check into CheckRelationTableSpaceMove() instead of reindex_index() to > centralize the logic. ALTER TABLE does this business in > RangeVarCallbackForAlterRelation(), but our code path opening the > relation is different for the non-concurrent case. > > + if (OidIsValid(params->tablespaceOid) && > + IsSystemClass(relid, classtuple)) > + { > + if (!allowSystemTableMods) > + { > + /* Skip all system relations, if not > allowSystemTableMods * > I don't see the need for having two warnings here to say the same > thing if a relation is mapped or not mapped, so let's keep it simple. > Yeah, I just wanted to separate mapped and system relations, but probably it is too complicated. > > I have found that the test suite was rather messy in its > organization. Table creations were done first with a set of tests not > really ordered, so that was really hard to follow. This has also led > to a set of tests that were duplicated, while other tests have been > missed, mainly some cross checks for the concurrent and non-concurrent > behaviors. I have reordered the whole so as tests on catalogs, normal > tables and partitions are done separately with relations created and > dropped for each set. Partitions use a global check for tablespaces > and relfilenodes after one concurrent reindex (didn't see the point in > doubling with the non-concurrent case as the same code path to select > the relations from the partition tree is taken). An ACL test has been > added at the end. > > The case of partitioned indexes was kind of interesting and I thought > about that a couple of days, and I took the decision to ignore > relations that have no storage as you did, documenting that ALTER > TABLE can be used to update the references of the partitioned > relations. The command is still useful with this behavior, and the > tests I have added track that. > > Finally, I have reworked the docs, separating the limitations related > to system catalogs and partitioned relations, to be more consistent > with the notes at the end of the page. > Thanks for working on this. + if (tablespacename != NULL) + { + params.tablespaceOid = get_tablespace_oid(tablespacename, false); + + /* Check permissions except when moving to database's default */ + if (OidIsValid(params.tablespaceOid) && This check for OidIsValid() seems to be excessive, since you moved the whole ACL check under 'if (tablespacename != NULL)' here. + params.tablespaceOid != MyDatabaseTableSpace) + { + AclResult aclresult; +CREATE INDEX regress_tblspace_test_tbl_idx ON regress_tblspace_test_tbl (num1); +-- move to global tablespace move fails Maybe 'move to global tablespace, fail', just to match a style of the previous comments. +REINDEX (TABLESPACE pg_global) INDEX regress_tblspace_test_tbl_idx; +SELECT relid, parentrelid, level FROM pg_partition_tree('tbspace_reindex_part_index') + ORDER BY relid, level; +SELECT relid, parentrelid, level FROM pg_partition_tree('tbspace_reindex_part_index') + ORDER BY relid, level; Why do you do the same twice in a row? It looks like a typo. Maybe it was intended to be called for partitioned table AND index. Regards -- Alexey Kondratov Postgres Professional https://www.postgrespro.com Russian Postgres Company