In REASSIGN OWNED of a database, lock the tuple as mandated.
authorNoah Misch <noah@leadboat.com>
Sat, 28 Dec 2024 15:16:22 +0000 (07:16 -0800)
committerNoah Misch <noah@leadboat.com>
Sat, 28 Dec 2024 15:16:27 +0000 (07:16 -0800)
commit536acda0bc7900c407c76c6ca6293e0ac2041f8b
tree667da1a6e9dcac1452e8f83b8d2540e21c3c80f2
parentcfd6cbcf9be078fbdf9587014231a5772039b386
In REASSIGN OWNED of a database, lock the tuple as mandated.

Commit aac2c9b4fde889d13f859c233c2523345e72d32b mandated such locking
and attempted to fulfill that mandate, but it missed REASSIGN OWNED.
Hence, it remained possible to lose VACUUM's inplace update of
datfrozenxid if a REASSIGN OWNED processed that database at the same
time.  This didn't affect the other inplace-updated catalog, pg_class.
For pg_class, REASSIGN OWNED calls ATExecChangeOwner() instead of the
generic AlterObjectOwner_internal(), and ATExecChangeOwner() fulfills
the locking mandate.

Like in GRANT, implement this by following the locking protocol for any
catalog subject to the generic AlterObjectOwner_internal().  It would
suffice to do this for IsInplaceUpdateOid() catalogs only.  Back-patch
to v13 (all supported versions).

Kirill Reshke.  Reported by Alexander Kukushkin.

Discussion: http://postgr.es/m/CAFh8B=mpKjAy4Cuun-HP-f_vRzh2HSvYFG3rhVfYbfEBUhBAGg@mail.gmail.com
src/backend/catalog/objectaddress.c
src/backend/commands/alter.c
src/include/catalog/objectaddress.h
src/test/regress/expected/database.out
src/test/regress/sql/database.sql