WARNING: missing lock on database "postgres" (OID 5) @ TID (0,4)
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
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
Hi!
Looks like PFA should fix that.
--
Best regards,
Kirill Reshke
Attachments:
v1-0001-Lock-tuple-for-inplace-update-when-moidfying.patchapplication/octet-stream; name=v1-0001-Lock-tuple-for-inplace-update-when-moidfying.patchDownload+4-1
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.
On Mon, 9 Dec 2024 at 23:13, Noah Misch <noah@leadboat.com> wrote:
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.
Yes, I just copied LockTuple from AlterDatabaseOwner, but it turns out
that the problem is more complex than I first believed.
PFA v2. I tried to follow your suggestion.
The get_catalog_object_by_oid_extended method, which I added to v2,
acts similarly to get_catalog_object_by_oid but locks the tuple being
searched.
Do you think this design looks good?
A fix for $SUBJECT also warrants a test in database.sql.
Sure. I added one test case to dependency.sql (for DATABASE ownership
change), do we need more (other catalog classes)?
--
Best regards,
Kirill Reshke
Attachments:
v2-0001-When-making-dependency-changes-lock-the-tuple-for.patchapplication/octet-stream; name=v2-0001-When-making-dependency-changes-lock-the-tuple-for.patchDownload+35-3
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
On Tue, 10 Dec 2024 at 10:47, Kirill Reshke <reshkekirill@gmail.com> wrote:
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.
CI fails due to bad naming in the regression test.
The change is deptestdb1 -> regressdeptestdb1
PFA v3.
--
Best regards,
Kirill Reshke
Attachments:
v3-0001-When-making-dependency-changes-lock-the-tuple-for.patchapplication/octet-stream; name=v3-0001-When-making-dependency-changes-lock-the-tuple-for.patchDownload+35-3
On Tue, 10 Dec 2024 at 14:14, Kirill Reshke <reshkekirill@gmail.com> wrote:
CI fails due to bad naming in the regression test.
The change is deptestdb1 -> regressdeptestdb1
I'm very sorry for spam.
PFAv4
regressdeptestdb1 -> regressiondeptestdb1
--
Best regards,
Kirill Reshke
Attachments:
v4-0001-When-making-dependency-changes-lock-the-tuple-for.patchapplication/octet-stream; name=v4-0001-When-making-dependency-changes-lock-the-tuple-for.patchDownload+35-3
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?
On Tue, 17 Dec 2024 at 04:43, Noah Misch <noah@leadboat.com> wrote:
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?
Sure, my bad, I missed this part of your message. PFA v5 with
database.sql changes.
--
Best regards,
Kirill Reshke