pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5
5+ messages / 2 participants
[nested] [flat]
Commits from this thread:
2024-11-25 4ba84de459 718af10dab c1285bbeb9 941e0c0df2 01745fb04d 2690a4f5dd Avoid "you don't own a lock of type ExclusiveLock" in GRANT TABLESPACE.
* 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5
@ 2024-11-20 05:11 Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>
2024-11-20 06:27 ` Re: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Noah Misch <noah@leadboat.com>
0 siblings, 1 reply; 5+ messages in thread
From: Aya Iwata (Fujitsu) @ 2024-11-20 05:11 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Hi developers,
During our tests on November release,
we discovered a "WARNING: you don't own a lock of type ExclusiveLock" that occurred at a strange time in GRANT command.
[Details]
Version:
16.5
OS:
Linux
Build options:
--prefix=/xxx/xxx/xxx' '--with-ssl=openssl' '--without-icu
Build and install command:
make all
make install
Reproduction procedure:
1. Set binaries bin and lib path
2. Initiate the server using initdb command
3. create folder for tablespace
4. start the server usaing pg_ctl command
5. execute the following commands:
This is only possible when psql executes each command individually.
$ psql -d postgres -c "CREATE USER nmluser1;"
CREATE ROLE
$ psql -d postgres -c "CREATE TABLESPACE test_tblspace LOCATION '/xxx /xxx/pgsql16.5/tbs';"
CREATE TABLESPACE
$ psql -d postgres -c "CREATE DATABASE enc_testdb;"
CREATE DATABASE
$ psql -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE postgres TO nmluser1;"
GRANT
$ psql -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE enc_testdb TO nmluser1;"
GRANT
$ psql -d postgres -c "GRANT CREATE ON TABLESPACE test_tblspace TO nmluser1;"
WARNING: you don't own a lock of type ExclusiveLock
GRANT
[Investigated]
- This WARNING did not occur when tested with FEP16.4 using the same "Reproduction procedure:"
- This WARNING did not occur when running CREATE ROLE through GRANT in a single session connected to psql.
- Also, it did not happen when running 'psql -f' with an .sql file
- We have run similar tests in the November releases of v12 through v17, but this is not reported by the tester in those releases.
-- Therefore, we have not tried this "Reproduction procedure:" on versions other than 16.5 and 16.4.
- This WARNING message appears in several places, and after modifying the source code to know which elog it is,
seemed to come from ReleaseSysCache() in ExecGrant_common()
Regards,
Aya Iwata
Fujitsu
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5
2024-11-20 05:11 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>
@ 2024-11-20 06:27 ` Noah Misch <noah@leadboat.com>
2024-11-21 01:11 ` Re: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Noah Misch <noah@leadboat.com>
0 siblings, 1 reply; 5+ messages in thread
From: Noah Misch @ 2024-11-20 06:27 UTC (permalink / raw)
To: Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>; +Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
On Wed, Nov 20, 2024 at 05:11:07AM +0000, Aya Iwata (Fujitsu) wrote:
> During our tests on November release,
> we discovered a "WARNING: you don't own a lock of type ExclusiveLock" that occurred at a strange time in GRANT command.
>
> [Details]
> Version:
> 16.5
> 1. Set binaries bin and lib path
> 2. Initiate the server using initdb command
> 3. create folder for tablespace
> 4. start the server usaing pg_ctl command
> 5. execute the following commands:
>
> This is only possible when psql executes each command individually.
> $ psql -d postgres -c "CREATE USER nmluser1;"
> CREATE ROLE
> $ psql -d postgres -c "CREATE TABLESPACE test_tblspace LOCATION '/xxx /xxx/pgsql16.5/tbs';"
> CREATE TABLESPACE
> $ psql -d postgres -c "CREATE DATABASE enc_testdb;"
> CREATE DATABASE
> $ psql -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE postgres TO nmluser1;"
> GRANT
> $ psql -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE enc_testdb TO nmluser1;"
> GRANT
> $ psql -d postgres -c "GRANT CREATE ON TABLESPACE test_tblspace TO nmluser1;"
> WARNING: you don't own a lock of type ExclusiveLock
> GRANT
>
>
> [Investigated]
> - This WARNING did not occur when tested with FEP16.4 using the same "Reproduction procedure:"
> - This WARNING did not occur when running CREATE ROLE through GRANT in a single session connected to psql.
> - Also, it did not happen when running 'psql -f' with an .sql file
> - We have run similar tests in the November releases of v12 through v17, but this is not reported by the tester in those releases.
> -- Therefore, we have not tried this "Reproduction procedure:" on versions other than 16.5 and 16.4.
> - This WARNING message appears in several places, and after modifying the source code to know which elog it is,
> seemed to come from ReleaseSysCache() in ExecGrant_common()
Thanks for the report. This seems reasonably likely to come from a defect in
commit 51ff46d. I will look into it.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5
2024-11-20 05:11 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>
2024-11-20 06:27 ` Re: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Noah Misch <noah@leadboat.com>
@ 2024-11-21 01:11 ` Noah Misch <noah@leadboat.com>
2024-11-25 05:54 ` RE: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>
0 siblings, 1 reply; 5+ messages in thread
From: Noah Misch @ 2024-11-21 01:11 UTC (permalink / raw)
To: Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>; +Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
On Tue, Nov 19, 2024 at 10:27:42PM -0800, Noah Misch wrote:
> On Wed, Nov 20, 2024 at 05:11:07AM +0000, Aya Iwata (Fujitsu) wrote:
> > During our tests on November release,
> > we discovered a "WARNING: you don't own a lock of type ExclusiveLock" that occurred at a strange time in GRANT command.
> > This is only possible when psql executes each command individually.
> > $ psql -d postgres -c "CREATE USER nmluser1;"
> > CREATE ROLE
> > $ psql -d postgres -c "CREATE TABLESPACE test_tblspace LOCATION '/xxx /xxx/pgsql16.5/tbs';"
> > CREATE TABLESPACE
> > $ psql -d postgres -c "CREATE DATABASE enc_testdb;"
> > CREATE DATABASE
> > $ psql -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE postgres TO nmluser1;"
> > GRANT
> > $ psql -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE enc_testdb TO nmluser1;"
> > GRANT
> > $ psql -d postgres -c "GRANT CREATE ON TABLESPACE test_tblspace TO nmluser1;"
> > WARNING: you don't own a lock of type ExclusiveLock
> > GRANT
Did you ever see the WARNING with a DATABASE command, or just with a
TABLESPACE command?
> Thanks for the report. This seems reasonably likely to come from a defect in
> commit 51ff46d. I will look into it.
Yes, that commit had us reading cc_relisshared before that field got
initialized. I can reproduce the WARNING in v16+, with GRANT TABLESPACE.
Before a cache's initialization cc_relisshared==false, so
SearchSysCacheLocked1() used the wrong locktag. The attached patch is about
right. At a minimum, I still need to work on the details in its log message.
Attachments:
inplace250-catcache-init-SearchSysCacheLocked1-v1.patch (text/plain, 3.7K) download
Author: Noah Misch <noah@leadboat.com>
Commit: Noah Misch <noah@leadboat.com>
Avoid "you don't own a lock of type ExclusiveLock" in GRANT TABLESPACE.
FIXME look for other user-visible implications:
- other commands that can reach this warning
- commands that actually need the protection of the LOCKTAG_TUPLE and
don't get it as a result of setting the wrong dboid in the locktag.
These would be commands involving pg_database.
This happened because SearchSysCacheLocked1() read cc_relisshared before
cache initialization, so the locktag for a shared catalog incorrectly
contained dboid==MyDatabaseId. Only shared catalogs were affected.
Back-patch to v13 (all supported versions). This has no known impact
before v16, where ExecGrant_common() first appeared. Earlier branches
have a separate ExecGrant_Tablespace() that doesn't use LOCKTAG_TUPLE,
and ExecGrant_Database() seems to get a correctly-initialized cache
FIXMEconfirm. Even so it's not very future-proof to assume v15 won't
get impact in the future.
Reported by Aya Iwata. Reviewed by FIXME.
Discussion: https://postgr.es/m/OS7PR01MB11964507B5548245A7EE54E70EA212@OS7PR01MB11964.jpnprd01.prod.outlook.com
diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c
index f41b1c2..f7f4f56 100644
--- a/src/backend/utils/cache/syscache.c
+++ b/src/backend/utils/cache/syscache.c
@@ -287,11 +287,9 @@ HeapTuple
SearchSysCacheLocked1(int cacheId,
Datum key1)
{
+ CatCache *cache = SysCache[cacheId];
ItemPointerData tid;
LOCKTAG tag;
- Oid dboid =
- SysCache[cacheId]->cc_relisshared ? InvalidOid : MyDatabaseId;
- Oid reloid = cacheinfo[cacheId].reloid;
/*----------
* Since inplace updates may happen just before our LockTuple(), we must
@@ -343,8 +341,15 @@ SearchSysCacheLocked1(int cacheId,
tid = tuple->t_self;
ReleaseSysCache(tuple);
- /* like: LockTuple(rel, &tid, lockmode) */
- SET_LOCKTAG_TUPLE(tag, dboid, reloid,
+
+ /*
+ * Do like LockTuple(rel, &tid, lockmode). While cc_relisshared won't
+ * change from one iteration to another, it may have been a temporary
+ * "false" until our first SearchSysCache1().
+ */
+ SET_LOCKTAG_TUPLE(tag,
+ cache->cc_relisshared ? InvalidOid : MyDatabaseId,
+ cache->cc_reloid,
ItemPointerGetBlockNumber(&tid),
ItemPointerGetOffsetNumber(&tid));
(void) LockAcquire(&tag, lockmode, false, false);
diff --git a/src/test/regress/expected/tablespace.out b/src/test/regress/expected/tablespace.out
index dd535d4..a90e39e 100644
--- a/src/test/regress/expected/tablespace.out
+++ b/src/test/regress/expected/tablespace.out
@@ -927,6 +927,11 @@ ALTER INDEX testschema.part_a_idx SET TABLESPACE pg_default;
-- Fail, not empty
DROP TABLESPACE regress_tblspace;
ERROR: tablespace "regress_tblspace" is not empty
+-- Adequate cache initialization before GRANT
+\c -
+BEGIN;
+GRANT ALL ON TABLESPACE regress_tblspace TO PUBLIC;
+ROLLBACK;
CREATE ROLE regress_tablespace_user1 login;
CREATE ROLE regress_tablespace_user2 login;
GRANT USAGE ON SCHEMA testschema TO regress_tablespace_user2;
diff --git a/src/test/regress/sql/tablespace.sql b/src/test/regress/sql/tablespace.sql
index c8b8378..dfe3db0 100644
--- a/src/test/regress/sql/tablespace.sql
+++ b/src/test/regress/sql/tablespace.sql
@@ -396,6 +396,12 @@ ALTER INDEX testschema.part_a_idx SET TABLESPACE pg_default;
-- Fail, not empty
DROP TABLESPACE regress_tblspace;
+-- Adequate cache initialization before GRANT
+\c -
+BEGIN;
+GRANT ALL ON TABLESPACE regress_tblspace TO PUBLIC;
+ROLLBACK;
+
CREATE ROLE regress_tablespace_user1 login;
CREATE ROLE regress_tablespace_user2 login;
GRANT USAGE ON SCHEMA testschema TO regress_tablespace_user2;
^ permalink raw reply [nested|flat] 5+ messages in thread
* RE: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5
2024-11-20 05:11 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>
2024-11-20 06:27 ` Re: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Noah Misch <noah@leadboat.com>
2024-11-21 01:11 ` Re: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Noah Misch <noah@leadboat.com>
@ 2024-11-25 05:54 ` Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>
2024-11-26 02:17 ` Re: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Noah Misch <noah@leadboat.com>
0 siblings, 1 reply; 5+ messages in thread
From: Aya Iwata (Fujitsu) @ 2024-11-25 05:54 UTC (permalink / raw)
To: Noah Misch <noah@leadboat.com>; +Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Hi,
>Did you ever see the WARNING with a DATABASE command, or just with a
>TABLESPACE command?
We tried this, but there is no WARNING on GRANT xxx ON DATABASE command.
But I did notice a warning while REVOKE xxx ON TABLESPACE.
$ psql -x -p 5432 -d postgres -c "REVOKE CREATE ON TABLESPACE test_tbl_spc FROM nmluser1;"
WARNING: you don't own a lock of type ExclusiveLock
REVOKE
So both GRANT and REVOKE command on TABLESPACE seems to throw an WARNING.
Best Regards,
Aya Iwata
Fujitsu
> -----Original Message-----
> From: Noah Misch <noah@leadboat.com>
> Sent: Thursday, November 21, 2024 10:11 AM
> To: Iwata, Aya/岩田 彩 <iwata.aya@fujitsu.com>
> Cc: pgsql-bugs@lists.postgresql.org
> Subject: Re: 'WARNING: you don't own a lock of type ExclusiveLock' is printed
> during the GRANT command on PostgreSQL16.5
>
> On Tue, Nov 19, 2024 at 10:27:42PM -0800, Noah Misch wrote:
> > On Wed, Nov 20, 2024 at 05:11:07AM +0000, Aya Iwata (Fujitsu) wrote:
> > > During our tests on November release,
> > > we discovered a "WARNING: you don't own a lock of type ExclusiveLock"
> that occurred at a strange time in GRANT command.
>
> > > This is only possible when psql executes each command individually.
> > > $ psql -d postgres -c "CREATE USER nmluser1;"
> > > CREATE ROLE
> > > $ psql -d postgres -c "CREATE TABLESPACE test_tblspace LOCATION
> '/xxx /xxx/pgsql16.5/tbs';"
> > > CREATE TABLESPACE
> > > $ psql -d postgres -c "CREATE DATABASE enc_testdb;"
> > > CREATE DATABASE
> > > $ psql -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE postgres
> TO nmluser1;"
> > > GRANT
> > > $ psql -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE
> enc_testdb TO nmluser1;"
> > > GRANT
> > > $ psql -d postgres -c "GRANT CREATE ON TABLESPACE test_tblspace TO
> nmluser1;"
> > > WARNING: you don't own a lock of type ExclusiveLock
> > > GRANT
>
> Did you ever see the WARNING with a DATABASE command, or just with a
> TABLESPACE command?
>
> > Thanks for the report. This seems reasonably likely to come from a defect in
> > commit 51ff46d. I will look into it.
>
> Yes, that commit had us reading cc_relisshared before that field got
> initialized. I can reproduce the WARNING in v16+, with GRANT TABLESPACE.
> Before a cache's initialization cc_relisshared==false, so
> SearchSysCacheLocked1() used the wrong locktag. The attached patch is
> about
> right. At a minimum, I still need to work on the details in its log message.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5
2024-11-20 05:11 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>
2024-11-20 06:27 ` Re: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Noah Misch <noah@leadboat.com>
2024-11-21 01:11 ` Re: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Noah Misch <noah@leadboat.com>
2024-11-25 05:54 ` RE: 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>
@ 2024-11-26 02:17 ` Noah Misch <noah@leadboat.com>
0 siblings, 0 replies; 5+ messages in thread
From: Noah Misch @ 2024-11-26 02:17 UTC (permalink / raw)
To: Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>; +Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
On Mon, Nov 25, 2024 at 05:54:50AM +0000, Aya Iwata (Fujitsu) wrote:
> >Did you ever see the WARNING with a DATABASE command, or just with a
> >TABLESPACE command?
>
> We tried this, but there is no WARNING on GRANT xxx ON DATABASE command.
>
> But I did notice a warning while REVOKE xxx ON TABLESPACE.
>
> $ psql -x -p 5432 -d postgres -c "REVOKE CREATE ON TABLESPACE test_tbl_spc FROM nmluser1;"
> WARNING: you don't own a lock of type ExclusiveLock
> REVOKE
>
> So both GRANT and REVOKE command on TABLESPACE seems to throw an WARNING.
That makes sense. I've pushed postgr.es/c/4ba84de for this.
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2024-11-26 02:17 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-11-20 05:11 'WARNING: you don't own a lock of type ExclusiveLock' is printed during the GRANT command on PostgreSQL16.5 Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>
2024-11-20 06:27 ` Noah Misch <noah@leadboat.com>
2024-11-21 01:11 ` Noah Misch <noah@leadboat.com>
2024-11-25 05:54 ` Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com>
2024-11-26 02:17 ` Noah Misch <noah@leadboat.com>
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