Heed lock protocol in DROP OWNED BY
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 6 May 2020 16:29:41 +0000 (12:29 -0400)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 6 May 2020 16:29:41 +0000 (12:29 -0400)
commit5be594caf818e0b5e33f8dec191f2707394a6d95
tree70b45229d9dbe7d4ca66da924b413542e11946c0
parentf21599311e50a43c90a3d33ef4f60193a774321a
Heed lock protocol in DROP OWNED BY

We were acquiring object locks then deleting objects one by one, instead
of acquiring all object locks first, ignoring those that did not exist,
and then deleting all objects together.   The latter is the correct
protocol to use, and what this commits changes to code to do.  Failing
to follow that leads to "cache lookup failed for relation XYZ" error
reports when DROP OWNED runs concurrently with other DDL -- for example,
a session termination that removes some temp tables.

Author: Álvaro Herrera
Reported-by: Mithun Chicklore Yogendra (Mithun CY)
Reviewed-by: Ahsan Hadi, Tom Lane
Discussion: https://postgr.es/m/CADq3xVZTbzK4ZLKq+dn_vB4QafXXbmMgDP3trY-GuLnib2Ai1w@mail.gmail.com
src/backend/catalog/dependency.c
src/backend/catalog/pg_shdepend.c
src/backend/commands/subscriptioncmds.c
src/include/catalog/dependency.h