Thread: WARNING: missing lock on database "postgres" (OID 5) @ TID (0,4)

WARNING: missing lock on database "postgres" (OID 5) @ TID (0,4)

From
Alexander Kukushkin
Date:
Hello Hacker,

When Postgres is compiled with --enable-cassert I get subj when doing the following:
postgres=# create user test;
CREATE ROLE
postgres=# alter database postgres owner to test;
ALTER DATABASE
postgres=# reassign owned by test to postgres;
WARNING:  missing lock on database "postgres" (OID 5) @ TID (0,4)
REASSIGN OWNED

It was discovered on 16.6, however the master shows the same behaviour.
I suspect it to be due to aac2c9b4fde889d13f859c233c2523345e72d32b.

Regards,
--
Alexander Kukushkin

Re: WARNING: missing lock on database "postgres" (OID 5) @ TID (0,4)

From
Noah Misch
Date:
On Mon, Dec 09, 2024 at 04:50:16PM +0500, Kirill Reshke wrote:
> On Mon, 9 Dec 2024 at 15:27, Alexander Kukushkin <cyberdemn@gmail.com> wrote:
> > postgres=# reassign owned by test to postgres;
> > WARNING:  missing lock on database "postgres" (OID 5) @ TID (0,4)
> > REASSIGN OWNED

Thanks for the report.

> --- a/src/backend/commands/alter.c
> +++ b/src/backend/commands/alter.c
> @@ -991,6 +991,8 @@ AlterObjectOwner_internal(Oid classId, Oid objectId, Oid new_ownerId)
>              }
>          }
>  
> +        LockTuple(rel, &oldtup->t_self, InplaceUpdateTupleLock);
> +
>          /* Build a modified tuple */

This silences the warning, but it doesn't generally satisfy the locking
protocol at README.tuplock section "Locking to write inplace-updated tables".
The specific problem is that this locks the tuple after copying it from shared
buffers.  If getting oldtup from a syscache, use SearchSysCacheLocked1().
Otherwise, lock before systable_endscan() and before any copying, like
AlterDatabaseOwner() does.

A fix for $SUBJECT also warrants a test in database.sql.



Re: WARNING: missing lock on database "postgres" (OID 5) @ TID (0,4)

From
Kirill Reshke
Date:
On Tue, 10 Dec 2024 at 10:45, Kirill Reshke <reshkekirill@gmail.com> wrote:

> PFA v2.
Also CF entry https://commitfest.postgresql.org/51/5430/ to get CI feedback.


-- 
Best regards,
Kirill Reshke



Re: WARNING: missing lock on database "postgres" (OID 5) @ TID (0,4)

From
Noah Misch
Date:
On Wed, Dec 11, 2024 at 11:37:49AM +0500, Kirill Reshke wrote:
> PFAv4
> 
> regressdeptestdb1 -> regressiondeptestdb1

The reason I said databases.sql for the test is that CREATE DATABASE is
expensive.  We currently have just one successful CREATE DATABASE in the
src/test/regress suite, and we shouldn't add more that reasonably could
instead harness the existing one.  Would you do it that way?