Re: Allow CLUSTER, VACUUM FULL and REINDEX to change tablespace on the fly
От | Alexey Kondratov |
---|---|
Тема | Re: Allow CLUSTER, VACUUM FULL and REINDEX to change tablespace on the fly |
Дата | |
Msg-id | 55c6c1526b94d2caf54c33262fe00674@postgrespro.ru обсуждение исходный текст |
Ответы |
Re: Allow CLUSTER, VACUUM FULL and REINDEX to change tablespace on the fly
|
Список | pgsql-hackers |
On 2021-01-28 00:36, Alvaro Herrera wrote: > On 2021-Jan-28, Alexey Kondratov wrote: > >> I have read more about lock levels and ShareLock should prevent any >> kind of >> physical modification of indexes. We already hold ShareLock doing >> find_all_inheritors(), which is higher than ShareUpdateExclusiveLock, >> so >> using ShareLock seems to be safe here, but I will look on it closer. > > You can look at lock.c where LockConflicts[] is; that would tell you > that ShareLock indeed conflicts with ShareUpdateExclusiveLock ... but > it > does not conflict with itself! So it would be possible to have more > than one process doing this thing at the same time, which surely makes > no sense. > Thanks for the explanation and pointing me to the LockConflicts[]. This is a good reference. > > I didn't look at the patch closely enough to understand why you're > trying to do something like CLUSTER, VACUUM FULL or REINDEX without > holding full AccessExclusiveLock on the relation. But do keep in mind > that once you hold a lock on a relation, trying to grab a weaker lock > afterwards is pretty pointless. > No, you are right, we are doing REINDEX with AccessExclusiveLock as it was before. This part is a more specific one. It only applies to partitioned indexes, which do not hold any data, so we do not reindex them directly, only their leafs. However, if we are doing a TABLESPACE change, we have to record it in their pg_class entry, so all future leaf partitions were created in the proper tablespace. That way, we open partitioned index relation only for a reference, i.e. read-only, but modify pg_class entry under a proper lock (RowExclusiveLock). That's why I thought that ShareLock will be enough. IIUC, 'ALTER TABLE ... SET TABLESPACE' uses AccessExclusiveLock even for relations with no storage, since AlterTableGetLockLevel() chooses it if AT_SetTableSpace is met. This is very similar to our case, so probably we should do the same? Actually it is not completely clear for me why ShareUpdateExclusiveLock is sufficient for newly added SetRelationTableSpace() as Michael wrote in the comment. Regards -- Alexey Kondratov Postgres Professional https://www.postgrespro.com Russian Postgres Company
В списке pgsql-hackers по дате отправления: