pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix risk of deadlock failure while dropping a partitioned index.
5+ messages / 1 participants
[nested] [flat]

* pgsql: Fix risk of deadlock failure while dropping a partitioned index.
@ 2022-03-21 16:22  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2022-03-21 16:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix risk of deadlock failure while dropping a partitioned index.

DROP INDEX needs to lock the index's table before the index itself,
else it will deadlock against ordinary queries that acquire the
relation locks in that order.  This is correctly mechanized for
plain indexes by RangeVarCallbackForDropRelation; but in the case of
a partitioned index, we neglected to lock the child tables in advance
of locking the child indexes.  We can fix that by traversing the
inheritance tree and acquiring the needed locks in RemoveRelations,
after we have acquired our locks on the parent partitioned table and
index.

While at it, do some refactoring to eliminate confusion between
the actual and expected relkind in RangeVarCallbackForDropRelation.
We can save a couple of syscache lookups too, by having that function
pass back info that RemoveRelations will need.

Back-patch to v11 where partitioned indexes were added.

Jimmy Yih, Gaurab Dey, Tom Lane

Discussion: https://postgr.es/m/BYAPR05MB645402330042E17D91A70C12BD5F9@BYAPR05MB6454.namprd05.prod.outlook.com

Branch
------
REL_11_STABLE

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

Modified Files
--------------
src/backend/commands/tablecmds.c                   |  59 ++++++++----
.../expected/partition-drop-index-locking.out      | 100 +++++++++++++++++++++
src/test/isolation/isolation_schedule              |   1 +
.../specs/partition-drop-index-locking.spec        |  47 ++++++++++
4 files changed, 190 insertions(+), 17 deletions(-)



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

* pgsql: Fix risk of deadlock failure while dropping a partitioned index.
@ 2022-03-21 16:22  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2022-03-21 16:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix risk of deadlock failure while dropping a partitioned index.

DROP INDEX needs to lock the index's table before the index itself,
else it will deadlock against ordinary queries that acquire the
relation locks in that order.  This is correctly mechanized for
plain indexes by RangeVarCallbackForDropRelation; but in the case of
a partitioned index, we neglected to lock the child tables in advance
of locking the child indexes.  We can fix that by traversing the
inheritance tree and acquiring the needed locks in RemoveRelations,
after we have acquired our locks on the parent partitioned table and
index.

While at it, do some refactoring to eliminate confusion between
the actual and expected relkind in RangeVarCallbackForDropRelation.
We can save a couple of syscache lookups too, by having that function
pass back info that RemoveRelations will need.

Back-patch to v11 where partitioned indexes were added.

Jimmy Yih, Gaurab Dey, Tom Lane

Discussion: https://postgr.es/m/BYAPR05MB645402330042E17D91A70C12BD5F9@BYAPR05MB6454.namprd05.prod.outlook.com

Branch
------
REL_12_STABLE

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

Modified Files
--------------
src/backend/commands/tablecmds.c                   |  61 +++++++++----
.../expected/partition-drop-index-locking.out      | 100 +++++++++++++++++++++
src/test/isolation/isolation_schedule              |   1 +
.../specs/partition-drop-index-locking.spec        |  47 ++++++++++
4 files changed, 191 insertions(+), 18 deletions(-)



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

* pgsql: Fix risk of deadlock failure while dropping a partitioned index.
@ 2022-03-21 16:22  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2022-03-21 16:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix risk of deadlock failure while dropping a partitioned index.

DROP INDEX needs to lock the index's table before the index itself,
else it will deadlock against ordinary queries that acquire the
relation locks in that order.  This is correctly mechanized for
plain indexes by RangeVarCallbackForDropRelation; but in the case of
a partitioned index, we neglected to lock the child tables in advance
of locking the child indexes.  We can fix that by traversing the
inheritance tree and acquiring the needed locks in RemoveRelations,
after we have acquired our locks on the parent partitioned table and
index.

While at it, do some refactoring to eliminate confusion between
the actual and expected relkind in RangeVarCallbackForDropRelation.
We can save a couple of syscache lookups too, by having that function
pass back info that RemoveRelations will need.

Back-patch to v11 where partitioned indexes were added.

Jimmy Yih, Gaurab Dey, Tom Lane

Discussion: https://postgr.es/m/BYAPR05MB645402330042E17D91A70C12BD5F9@BYAPR05MB6454.namprd05.prod.outlook.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7b6ec86532c2ca585d671239bba867fe380448ed

Modified Files
--------------
src/backend/commands/tablecmds.c                   |  61 +++++++++----
.../expected/partition-drop-index-locking.out      | 100 +++++++++++++++++++++
src/test/isolation/isolation_schedule              |   1 +
.../specs/partition-drop-index-locking.spec        |  47 ++++++++++
4 files changed, 191 insertions(+), 18 deletions(-)



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

* pgsql: Fix risk of deadlock failure while dropping a partitioned index.
@ 2022-03-21 16:22  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2022-03-21 16:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix risk of deadlock failure while dropping a partitioned index.

DROP INDEX needs to lock the index's table before the index itself,
else it will deadlock against ordinary queries that acquire the
relation locks in that order.  This is correctly mechanized for
plain indexes by RangeVarCallbackForDropRelation; but in the case of
a partitioned index, we neglected to lock the child tables in advance
of locking the child indexes.  We can fix that by traversing the
inheritance tree and acquiring the needed locks in RemoveRelations,
after we have acquired our locks on the parent partitioned table and
index.

While at it, do some refactoring to eliminate confusion between
the actual and expected relkind in RangeVarCallbackForDropRelation.
We can save a couple of syscache lookups too, by having that function
pass back info that RemoveRelations will need.

Back-patch to v11 where partitioned indexes were added.

Jimmy Yih, Gaurab Dey, Tom Lane

Discussion: https://postgr.es/m/BYAPR05MB645402330042E17D91A70C12BD5F9@BYAPR05MB6454.namprd05.prod.outlook.com

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/05ccf974cd75d3a95869c4ce4b96fdbc10e663cf

Modified Files
--------------
src/backend/commands/tablecmds.c                   |  61 +++++++++----
.../expected/partition-drop-index-locking.out      | 100 +++++++++++++++++++++
src/test/isolation/isolation_schedule              |   1 +
.../specs/partition-drop-index-locking.spec        |  47 ++++++++++
4 files changed, 191 insertions(+), 18 deletions(-)



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

* pgsql: Fix risk of deadlock failure while dropping a partitioned index.
@ 2022-03-21 16:22  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2022-03-21 16:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix risk of deadlock failure while dropping a partitioned index.

DROP INDEX needs to lock the index's table before the index itself,
else it will deadlock against ordinary queries that acquire the
relation locks in that order.  This is correctly mechanized for
plain indexes by RangeVarCallbackForDropRelation; but in the case of
a partitioned index, we neglected to lock the child tables in advance
of locking the child indexes.  We can fix that by traversing the
inheritance tree and acquiring the needed locks in RemoveRelations,
after we have acquired our locks on the parent partitioned table and
index.

While at it, do some refactoring to eliminate confusion between
the actual and expected relkind in RangeVarCallbackForDropRelation.
We can save a couple of syscache lookups too, by having that function
pass back info that RemoveRelations will need.

Back-patch to v11 where partitioned indexes were added.

Jimmy Yih, Gaurab Dey, Tom Lane

Discussion: https://postgr.es/m/BYAPR05MB645402330042E17D91A70C12BD5F9@BYAPR05MB6454.namprd05.prod.outlook.com

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2241e5ceda2febd90b06e6cbc02a8b51e9e070e4

Modified Files
--------------
src/backend/commands/tablecmds.c                   |  61 +++++++++----
.../expected/partition-drop-index-locking.out      | 100 +++++++++++++++++++++
src/test/isolation/isolation_schedule              |   1 +
.../specs/partition-drop-index-locking.spec        |  47 ++++++++++
4 files changed, 191 insertions(+), 18 deletions(-)



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


end of thread, other threads:[~2022-03-21 16:22 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-03-21 16:22 pgsql: Fix risk of deadlock failure while dropping a partitioned index. Tom Lane <tgl@sss.pgh.pa.us>
2022-03-21 16:22 pgsql: Fix risk of deadlock failure while dropping a partitioned index. Tom Lane <tgl@sss.pgh.pa.us>
2022-03-21 16:22 pgsql: Fix risk of deadlock failure while dropping a partitioned index. Tom Lane <tgl@sss.pgh.pa.us>
2022-03-21 16:22 pgsql: Fix risk of deadlock failure while dropping a partitioned index. Tom Lane <tgl@sss.pgh.pa.us>
2022-03-21 16:22 pgsql: Fix risk of deadlock failure while dropping a partitioned index. Tom Lane <tgl@sss.pgh.pa.us>

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