agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: Fix concurrency issues with DROP TABLESPACE
7+ messages / 1 participants
[nested] [flat]

* pgsql: Fix concurrency issues with DROP TABLESPACE
@ 2026-09-09 15:34 Andrew Dunstan <andrew@dunslane.net>
  0 siblings, 0 replies; 7+ messages in thread

From: Andrew Dunstan @ 2026-09-09 15:34 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix concurrency issues with DROP TABLESPACE

DROP TABLESPACE checked pg_shdepend for dependent objects without
first locking the tablespace.  A concurrent command that recorded a
shared dependency on the tablespace right after that check could still
commit, leaving an object whose pg_shdepend entry (or, for a relation,
pg_class.reltablespace) pointed to a tablespace that no longer existed.

Close the race by having DropTableSpace() take an AccessExclusiveLock
on the tablespace before calling checkSharedDependencies().  That
conflicts with the AccessShareLock shdepLockAndCheckObject() takes when
recording a new dependency, so the loser of the race blocks and
rechecks once the winner commits.

That AccessExclusiveLock creates a new deadlock: ALTER TABLESPACE
RENAME/SET and the internal ACL/owner updates in DROP OWNED and
REASSIGN OWNED touched the catalog tuple without locking the
tablespace, risking a lock-order cycle with DROP.  Fix by taking an
AccessShareLock first in all four paths, rechecking pg_shdepend after
any wait in the DROP OWNED and REASSIGN OWNED cases.  GRANT, REVOKE,
and ALTER TABLESPACE ... OWNER TO already lock the object.

Add isolation tests covering both orderings of the original race
(dependency-first and drop-first) and all four previously-unlocked
update paths.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/CAJTYsWXjAQFnGKzXsht3XK8KHhyhontwFJw4JAHsUSfs_ptR4g@mail.gmail.com
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a12600b762c36d91450ce085fa25ef75250bc1c2

Modified Files
--------------
src/backend/catalog/pg_shdepend.c                  | 40 +++++++--
src/backend/commands/tablespace.c                  | 16 +++-
.../expected/tablespace-dependency-locking.out     | 84 +++++++++++++++++++
src/test/isolation/isolation_schedule              |  1 +
.../specs/tablespace-dependency-locking.spec       | 98 ++++++++++++++++++++++
5 files changed, 232 insertions(+), 7 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix concurrency issues with DROP TABLESPACE
@ 2026-09-09 15:34 Andrew Dunstan <andrew@dunslane.net>
  0 siblings, 0 replies; 7+ messages in thread

From: Andrew Dunstan @ 2026-09-09 15:34 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix concurrency issues with DROP TABLESPACE

DROP TABLESPACE checked pg_shdepend for dependent objects without
first locking the tablespace.  A concurrent command that recorded a
shared dependency on the tablespace right after that check could still
commit, leaving an object whose pg_shdepend entry (or, for a relation,
pg_class.reltablespace) pointed to a tablespace that no longer existed.

Close the race by having DropTableSpace() take an AccessExclusiveLock
on the tablespace before calling checkSharedDependencies().  That
conflicts with the AccessShareLock shdepLockAndCheckObject() takes when
recording a new dependency, so the loser of the race blocks and
rechecks once the winner commits.

That AccessExclusiveLock creates a new deadlock: ALTER TABLESPACE
RENAME/SET and the internal ACL/owner updates in DROP OWNED and
REASSIGN OWNED touched the catalog tuple without locking the
tablespace, risking a lock-order cycle with DROP.  Fix by taking an
AccessShareLock first in all four paths, rechecking pg_shdepend after
any wait in the DROP OWNED and REASSIGN OWNED cases.  GRANT, REVOKE,
and ALTER TABLESPACE ... OWNER TO already lock the object.

Add isolation tests covering both orderings of the original race
(dependency-first and drop-first) and all four previously-unlocked
update paths.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/CAJTYsWXjAQFnGKzXsht3XK8KHhyhontwFJw4JAHsUSfs_ptR4g@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5dec175fb4c537947faaba504cda394b4ca6b726

Modified Files
--------------
src/backend/catalog/pg_shdepend.c                  | 40 +++++++--
src/backend/commands/tablespace.c                  | 16 +++-
.../expected/tablespace-dependency-locking.out     | 84 +++++++++++++++++++
src/test/isolation/isolation_schedule              |  1 +
.../specs/tablespace-dependency-locking.spec       | 98 ++++++++++++++++++++++
5 files changed, 232 insertions(+), 7 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix concurrency issues with DROP TABLESPACE
@ 2026-09-09 15:34 Andrew Dunstan <andrew@dunslane.net>
  0 siblings, 0 replies; 7+ messages in thread

From: Andrew Dunstan @ 2026-09-09 15:34 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix concurrency issues with DROP TABLESPACE

DROP TABLESPACE checked pg_shdepend for dependent objects without
first locking the tablespace.  A concurrent command that recorded a
shared dependency on the tablespace right after that check could still
commit, leaving an object whose pg_shdepend entry (or, for a relation,
pg_class.reltablespace) pointed to a tablespace that no longer existed.

Close the race by having DropTableSpace() take an AccessExclusiveLock
on the tablespace before calling checkSharedDependencies().  That
conflicts with the AccessShareLock shdepLockAndCheckObject() takes when
recording a new dependency, so the loser of the race blocks and
rechecks once the winner commits.

That AccessExclusiveLock creates a new deadlock: ALTER TABLESPACE
RENAME/SET and the internal ACL/owner updates in DROP OWNED and
REASSIGN OWNED touched the catalog tuple without locking the
tablespace, risking a lock-order cycle with DROP.  Fix by taking an
AccessShareLock first in all four paths, rechecking pg_shdepend after
any wait in the DROP OWNED and REASSIGN OWNED cases.  GRANT, REVOKE,
and ALTER TABLESPACE ... OWNER TO already lock the object.

Add isolation tests covering both orderings of the original race
(dependency-first and drop-first) and all four previously-unlocked
update paths.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/CAJTYsWXjAQFnGKzXsht3XK8KHhyhontwFJw4JAHsUSfs_ptR4g@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d77627daac5baa895a1d37d2d12666bbf55585a5

Modified Files
--------------
src/backend/catalog/pg_shdepend.c                  | 40 +++++++--
src/backend/commands/tablespace.c                  | 18 +++-
.../expected/tablespace-dependency-locking.out     | 84 +++++++++++++++++++
src/test/isolation/isolation_schedule              |  1 +
.../specs/tablespace-dependency-locking.spec       | 98 ++++++++++++++++++++++
5 files changed, 234 insertions(+), 7 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix concurrency issues with DROP TABLESPACE
@ 2026-09-09 15:34 Andrew Dunstan <andrew@dunslane.net>
  0 siblings, 0 replies; 7+ messages in thread

From: Andrew Dunstan @ 2026-09-09 15:34 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix concurrency issues with DROP TABLESPACE

DROP TABLESPACE checked pg_shdepend for dependent objects without
first locking the tablespace.  A concurrent command that recorded a
shared dependency on the tablespace right after that check could still
commit, leaving an object whose pg_shdepend entry (or, for a relation,
pg_class.reltablespace) pointed to a tablespace that no longer existed.

Close the race by having DropTableSpace() take an AccessExclusiveLock
on the tablespace before calling checkSharedDependencies().  That
conflicts with the AccessShareLock shdepLockAndCheckObject() takes when
recording a new dependency, so the loser of the race blocks and
rechecks once the winner commits.

That AccessExclusiveLock creates a new deadlock: ALTER TABLESPACE
RENAME/SET and the internal ACL/owner updates in DROP OWNED and
REASSIGN OWNED touched the catalog tuple without locking the
tablespace, risking a lock-order cycle with DROP.  Fix by taking an
AccessShareLock first in all four paths, rechecking pg_shdepend after
any wait in the DROP OWNED and REASSIGN OWNED cases.  GRANT, REVOKE,
and ALTER TABLESPACE ... OWNER TO already lock the object.

Add isolation tests covering both orderings of the original race
(dependency-first and drop-first) and all four previously-unlocked
update paths.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/CAJTYsWXjAQFnGKzXsht3XK8KHhyhontwFJw4JAHsUSfs_ptR4g@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/960b6b53241e41ec4c0e960b23c718c8aaba076b

Modified Files
--------------
src/backend/catalog/pg_shdepend.c                  | 40 +++++++--
src/backend/commands/tablespace.c                  | 18 +++-
.../expected/tablespace-dependency-locking.out     | 84 +++++++++++++++++++
src/test/isolation/isolation_schedule              |  1 +
.../specs/tablespace-dependency-locking.spec       | 98 ++++++++++++++++++++++
5 files changed, 234 insertions(+), 7 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix concurrency issues with DROP TABLESPACE
@ 2026-09-09 15:34 Andrew Dunstan <andrew@dunslane.net>
  0 siblings, 0 replies; 7+ messages in thread

From: Andrew Dunstan @ 2026-09-09 15:34 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix concurrency issues with DROP TABLESPACE

DROP TABLESPACE checked pg_shdepend for dependent objects without
first locking the tablespace.  A concurrent command that recorded a
shared dependency on the tablespace right after that check could still
commit, leaving an object whose pg_shdepend entry (or, for a relation,
pg_class.reltablespace) pointed to a tablespace that no longer existed.

Close the race by having DropTableSpace() take an AccessExclusiveLock
on the tablespace before calling checkSharedDependencies().  That
conflicts with the AccessShareLock shdepLockAndCheckObject() takes when
recording a new dependency, so the loser of the race blocks and
rechecks once the winner commits.

That AccessExclusiveLock creates a new deadlock: ALTER TABLESPACE
RENAME/SET and the internal ACL/owner updates in DROP OWNED and
REASSIGN OWNED touched the catalog tuple without locking the
tablespace, risking a lock-order cycle with DROP.  Fix by taking an
AccessShareLock first in all four paths, rechecking pg_shdepend after
any wait in the DROP OWNED and REASSIGN OWNED cases.  GRANT, REVOKE,
and ALTER TABLESPACE ... OWNER TO already lock the object.

Add isolation tests covering both orderings of the original race
(dependency-first and drop-first) and all four previously-unlocked
update paths.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/CAJTYsWXjAQFnGKzXsht3XK8KHhyhontwFJw4JAHsUSfs_ptR4g@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/749dd8d1f2cf8ae261122b8db397bc5dafcb99bb

Modified Files
--------------
src/backend/catalog/pg_shdepend.c                  | 42 ++++++++--
src/backend/commands/tablespace.c                  | 17 +++-
.../expected/tablespace-dependency-locking.out     | 84 +++++++++++++++++++
src/test/isolation/isolation_schedule              |  1 +
.../specs/tablespace-dependency-locking.spec       | 98 ++++++++++++++++++++++
5 files changed, 235 insertions(+), 7 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix concurrency issues with DROP TABLESPACE
@ 2026-09-09 15:34 Andrew Dunstan <andrew@dunslane.net>
  0 siblings, 0 replies; 7+ messages in thread

From: Andrew Dunstan @ 2026-09-09 15:34 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix concurrency issues with DROP TABLESPACE

DROP TABLESPACE checked pg_shdepend for dependent objects without
first locking the tablespace.  A concurrent command that recorded a
shared dependency on the tablespace right after that check could still
commit, leaving an object whose pg_shdepend entry (or, for a relation,
pg_class.reltablespace) pointed to a tablespace that no longer existed.

Close the race by having DropTableSpace() take an AccessExclusiveLock
on the tablespace before calling checkSharedDependencies().  That
conflicts with the AccessShareLock shdepLockAndCheckObject() takes when
recording a new dependency, so the loser of the race blocks and
rechecks once the winner commits.

That AccessExclusiveLock creates a new deadlock: ALTER TABLESPACE
RENAME/SET and the internal ACL/owner updates in DROP OWNED and
REASSIGN OWNED touched the catalog tuple without locking the
tablespace, risking a lock-order cycle with DROP.  Fix by taking an
AccessShareLock first in all four paths, rechecking pg_shdepend after
any wait in the DROP OWNED and REASSIGN OWNED cases.  GRANT, REVOKE,
and ALTER TABLESPACE ... OWNER TO already lock the object.

Add isolation tests covering both orderings of the original race
(dependency-first and drop-first) and all four previously-unlocked
update paths.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/CAJTYsWXjAQFnGKzXsht3XK8KHhyhontwFJw4JAHsUSfs_ptR4g@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/00126dedef74dc8588938328d162771800a98fcb

Modified Files
--------------
src/backend/catalog/pg_shdepend.c                  | 46 ++++++++--
src/backend/commands/tablespace.c                  | 17 +++-
.../expected/tablespace-dependency-locking.out     | 84 +++++++++++++++++++
src/test/isolation/isolation_schedule              |  1 +
.../specs/tablespace-dependency-locking.spec       | 98 ++++++++++++++++++++++
5 files changed, 239 insertions(+), 7 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix concurrency issues with DROP TABLESPACE
@ 2026-09-09 15:34 Andrew Dunstan <andrew@dunslane.net>
  0 siblings, 0 replies; 7+ messages in thread

From: Andrew Dunstan @ 2026-09-09 15:34 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix concurrency issues with DROP TABLESPACE

DROP TABLESPACE checked pg_shdepend for dependent objects without
first locking the tablespace.  A concurrent command that recorded a
shared dependency on the tablespace right after that check could still
commit, leaving an object whose pg_shdepend entry (or, for a relation,
pg_class.reltablespace) pointed to a tablespace that no longer existed.

Close the race by having DropTableSpace() take an AccessExclusiveLock
on the tablespace before calling checkSharedDependencies().  That
conflicts with the AccessShareLock shdepLockAndCheckObject() takes when
recording a new dependency, so the loser of the race blocks and
rechecks once the winner commits.

That AccessExclusiveLock creates a new deadlock: ALTER TABLESPACE
RENAME/SET and the internal ACL/owner updates in DROP OWNED and
REASSIGN OWNED touched the catalog tuple without locking the
tablespace, risking a lock-order cycle with DROP.  Fix by taking an
AccessShareLock first in all four paths, rechecking pg_shdepend after
any wait in the DROP OWNED and REASSIGN OWNED cases.  GRANT, REVOKE,
and ALTER TABLESPACE ... OWNER TO already lock the object.

Add isolation tests covering both orderings of the original race
(dependency-first and drop-first) and all four previously-unlocked
update paths.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/CAJTYsWXjAQFnGKzXsht3XK8KHhyhontwFJw4JAHsUSfs_ptR4g@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/539b7e8290e71a253ac4b70faed75e38a7125d97

Modified Files
--------------
src/backend/catalog/pg_shdepend.c                  | 46 ++++++++--
src/backend/commands/tablespace.c                  | 17 +++-
.../expected/tablespace-dependency-locking.out     | 84 +++++++++++++++++++
src/test/isolation/isolation_schedule              |  1 +
.../specs/tablespace-dependency-locking.spec       | 98 ++++++++++++++++++++++
5 files changed, 239 insertions(+), 7 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2026-09-09 15:34 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-09 15:34 pgsql: Fix concurrency issues with DROP TABLESPACE Andrew Dunstan <andrew@dunslane.net>
2026-09-09 15:34 pgsql: Fix concurrency issues with DROP TABLESPACE Andrew Dunstan <andrew@dunslane.net>
2026-09-09 15:34 pgsql: Fix concurrency issues with DROP TABLESPACE Andrew Dunstan <andrew@dunslane.net>
2026-09-09 15:34 pgsql: Fix concurrency issues with DROP TABLESPACE Andrew Dunstan <andrew@dunslane.net>
2026-09-09 15:34 pgsql: Fix concurrency issues with DROP TABLESPACE Andrew Dunstan <andrew@dunslane.net>
2026-09-09 15:34 pgsql: Fix concurrency issues with DROP TABLESPACE Andrew Dunstan <andrew@dunslane.net>
2026-09-09 15:34 pgsql: Fix concurrency issues with DROP TABLESPACE Andrew Dunstan <andrew@dunslane.net>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox