Re: tiny step toward threading: reduce dependence on setlocale() - Mailing list pgsql-hackers
From | Alexander Kukushkin |
---|---|
Subject | Re: tiny step toward threading: reduce dependence on setlocale() |
Date | |
Msg-id | CAFh8B=nj966ECv5vi_u3RYij12v0j-7NPZCXLYzNwOQp9AcPWQ@mail.gmail.com Whole thread Raw |
In response to | Re: tiny step toward threading: reduce dependence on setlocale() (Jeff Davis <pgsql@j-davis.com>) |
List | pgsql-hackers |
Hi Jeff,
On Thu, 25 Sept 2025 at 11:08, Jeff Davis <pgsql@j-davis.com> wrote:
Committed v2-0001.
06421b084364 commit broke possibility to call GetSharedSecurityLabel() from ClientAuthentication_hook.
Now GetSharedSecurityLabel() calls fail with the error "cannot read pg_class without having selected a database".
Here is gdb stack trace:
#0 ScanPgRelation (targetRelId=3456, indexOK=true, force_non_historic=false) at relcache.c:354
#1 0x0000565eec153a1e in RelationBuildDesc (targetRelId=3456, insertIt=<optimized out>) at relcache.c:1113
#2 0x0000565eec155a7d in RelationIdGetRelation (relationId=<optimized out>, relationId@entry=3456) at relcache.c:2142
#3 0x0000565eebcbafb7 in relation_open (relationId=3456, lockmode=lockmode@entry=1) at relation.c:58
#4 0x0000565eebd2ea69 in table_open (relationId=<optimized out>, lockmode=lockmode@entry=1) at table.c:44
#5 0x0000565eec1434e4 in CatalogCacheInitializeCache (cache=0x565f17d35d80) at catcache.c:1124
#6 0x0000565eec144610 in ConditionalCatalogCacheInitializeCache (cache=0x565f17d35d80) at catcache.c:1084
#7 SearchCatCacheInternal (cache=0x565f17d35d80, nkeys=nkeys@entry=1, v1=v1@entry=950, v2=v2@entry=0, v3=v3@entry=0, v4=v4@entry=0) at catcache.c:1410
#8 0x0000565eec144f65 in SearchCatCache1 (cache=<optimized out>, v1=v1@entry=950) at catcache.c:1360
#9 0x0000565eec158033 in SearchSysCache1 (cacheId=cacheId@entry=16, key1=key1@entry=950) at syscache.c:228
#10 0x0000565eec0d72e8 in create_pg_locale (context=0x565f17cd0b00, collid=950) at ../../../../src/include/postgres.h:259
#11 pg_newlocale_from_collation (collid=950) at pg_locale.c:1226
#12 0x0000565eec1333de in varstr_cmp (arg1=0x770ce64fdf61 "<redacted>", len1=13, arg2=0x565f17ccaacc "<redacted>\252\314\027_V", len2=13, collid=<optimized out>)
at varlena.c:1617
#13 0x0000565eec133c74 in bttextcmp (fcinfo=0x7ffd34181740) at varlena.c:1892
#14 0x0000565eec165ab6 in FunctionCall2Coll (flinfo=flinfo@entry=0x7ffd34182358, collation=<optimized out>, arg1=<optimized out>, arg2=<optimized out>) at fmgr.c:1161
#15 0x0000565eebd13bfe in _bt_compare (rel=<optimized out>, key=0x7ffd341822a0, page=<optimized out>, offnum=<optimized out>) at nbtsearch.c:770
#16 0x0000565eebd13eb2 in _bt_binsrch (rel=rel@entry=0x770ce1cdd0c0, key=key@entry=0x7ffd341822a0, buf=<optimized out>) at nbtsearch.c:402
#17 0x0000565eebd14bab in _bt_first (scan=scan@entry=0x565f17ccaaf0, dir=dir@entry=ForwardScanDirection) at nbtsearch.c:1551
#18 0x0000565eebd10e46 in btgettuple (scan=0x565f17ccaaf0, dir=ForwardScanDirection) at nbtree.c:245
#19 0x0000565eebd063c9 in index_getnext_tid (scan=0x565f17ccaaf0, direction=<optimized out>) at indexam.c:637
#20 0x0000565eebd0651d in index_getnext_slot (scan=0x565f17ccaaf0, direction=direction@entry=ForwardScanDirection, slot=0x565f17cca680) at indexam.c:729
#21 0x0000565eebd05627 in systable_getnext (sysscan=sysscan@entry=0x565f17cca638) at genam.c:520
#22 0x0000565eebe14c65 in GetSharedSecurityLabel (provider=0x770d6bc2a7dd "<redacted>", object=0x7ffd34182e14) at seclabel.c:252
#23 0x0000770d6bc1fb0b in custom_check_auth (port=0x565f17b50788, am_walsender=<optimized out>) at custom_auth.c:2414
#24 0x0000565eebea37fc in ClientAuthentication (port=port@entry=0x565f17b50788) at auth.c:750
#25 0x0000565eec16cc95 in PerformAuthentication (port=0x565f17b50788) at postinit.c:265
#26 InitPostgres (in_dbname=in_dbname@entry=0x565f17c9a930 "postgres", dboid=dboid@entry=0, username=username@entry=0x565f17b51468 "<redacted>",
useroid=useroid@entry=0, flags=1, out_dbname=out_dbname@entry=0x0) at postinit.c:923
#27 0x0000565eec01b2d0 in PostgresMain (dbname=0x565f17c9a930 "postgres", username=0x565f17b51468 "<redacted>") at postgres.c:4289
#28 0x0000565eec0174ef in BackendMain (startup_data=<optimized out>, startup_data_len=<optimized out>) at backend_startup.c:124
#29 0x0000565eebf80152 in postmaster_child_launch (child_type=B_BACKEND, child_slot=1, startup_data=startup_data@entry=0x7ffd34184300,
startup_data_len=startup_data_len@entry=24, client_sock=client_sock@entry=0x7ffd34184320) at launch_backend.c:290
#30 0x0000565eebf83ab7 in BackendStartup (client_sock=0x7ffd34184320) at postmaster.c:3587
#31 ServerLoop () at postmaster.c:1702
#32 0x0000565eebf853e1 in PostmasterMain (argc=argc@entry=1, argv=argv@entry=0x565f17b4f450) at postmaster.c:1400
#33 0x0000565eebcab360 in main (argc=1, argv=0x565f17b4f450) at main.c:227
#1 0x0000565eec153a1e in RelationBuildDesc (targetRelId=3456, insertIt=<optimized out>) at relcache.c:1113
#2 0x0000565eec155a7d in RelationIdGetRelation (relationId=<optimized out>, relationId@entry=3456) at relcache.c:2142
#3 0x0000565eebcbafb7 in relation_open (relationId=3456, lockmode=lockmode@entry=1) at relation.c:58
#4 0x0000565eebd2ea69 in table_open (relationId=<optimized out>, lockmode=lockmode@entry=1) at table.c:44
#5 0x0000565eec1434e4 in CatalogCacheInitializeCache (cache=0x565f17d35d80) at catcache.c:1124
#6 0x0000565eec144610 in ConditionalCatalogCacheInitializeCache (cache=0x565f17d35d80) at catcache.c:1084
#7 SearchCatCacheInternal (cache=0x565f17d35d80, nkeys=nkeys@entry=1, v1=v1@entry=950, v2=v2@entry=0, v3=v3@entry=0, v4=v4@entry=0) at catcache.c:1410
#8 0x0000565eec144f65 in SearchCatCache1 (cache=<optimized out>, v1=v1@entry=950) at catcache.c:1360
#9 0x0000565eec158033 in SearchSysCache1 (cacheId=cacheId@entry=16, key1=key1@entry=950) at syscache.c:228
#10 0x0000565eec0d72e8 in create_pg_locale (context=0x565f17cd0b00, collid=950) at ../../../../src/include/postgres.h:259
#11 pg_newlocale_from_collation (collid=950) at pg_locale.c:1226
#12 0x0000565eec1333de in varstr_cmp (arg1=0x770ce64fdf61 "<redacted>", len1=13, arg2=0x565f17ccaacc "<redacted>\252\314\027_V", len2=13, collid=<optimized out>)
at varlena.c:1617
#13 0x0000565eec133c74 in bttextcmp (fcinfo=0x7ffd34181740) at varlena.c:1892
#14 0x0000565eec165ab6 in FunctionCall2Coll (flinfo=flinfo@entry=0x7ffd34182358, collation=<optimized out>, arg1=<optimized out>, arg2=<optimized out>) at fmgr.c:1161
#15 0x0000565eebd13bfe in _bt_compare (rel=<optimized out>, key=0x7ffd341822a0, page=<optimized out>, offnum=<optimized out>) at nbtsearch.c:770
#16 0x0000565eebd13eb2 in _bt_binsrch (rel=rel@entry=0x770ce1cdd0c0, key=key@entry=0x7ffd341822a0, buf=<optimized out>) at nbtsearch.c:402
#17 0x0000565eebd14bab in _bt_first (scan=scan@entry=0x565f17ccaaf0, dir=dir@entry=ForwardScanDirection) at nbtsearch.c:1551
#18 0x0000565eebd10e46 in btgettuple (scan=0x565f17ccaaf0, dir=ForwardScanDirection) at nbtree.c:245
#19 0x0000565eebd063c9 in index_getnext_tid (scan=0x565f17ccaaf0, direction=<optimized out>) at indexam.c:637
#20 0x0000565eebd0651d in index_getnext_slot (scan=0x565f17ccaaf0, direction=direction@entry=ForwardScanDirection, slot=0x565f17cca680) at indexam.c:729
#21 0x0000565eebd05627 in systable_getnext (sysscan=sysscan@entry=0x565f17cca638) at genam.c:520
#22 0x0000565eebe14c65 in GetSharedSecurityLabel (provider=0x770d6bc2a7dd "<redacted>", object=0x7ffd34182e14) at seclabel.c:252
#23 0x0000770d6bc1fb0b in custom_check_auth (port=0x565f17b50788, am_walsender=<optimized out>) at custom_auth.c:2414
#24 0x0000565eebea37fc in ClientAuthentication (port=port@entry=0x565f17b50788) at auth.c:750
#25 0x0000565eec16cc95 in PerformAuthentication (port=0x565f17b50788) at postinit.c:265
#26 InitPostgres (in_dbname=in_dbname@entry=0x565f17c9a930 "postgres", dboid=dboid@entry=0, username=username@entry=0x565f17b51468 "<redacted>",
useroid=useroid@entry=0, flags=1, out_dbname=out_dbname@entry=0x0) at postinit.c:923
#27 0x0000565eec01b2d0 in PostgresMain (dbname=0x565f17c9a930 "postgres", username=0x565f17b51468 "<redacted>") at postgres.c:4289
#28 0x0000565eec0174ef in BackendMain (startup_data=<optimized out>, startup_data_len=<optimized out>) at backend_startup.c:124
#29 0x0000565eebf80152 in postmaster_child_launch (child_type=B_BACKEND, child_slot=1, startup_data=startup_data@entry=0x7ffd34184300,
startup_data_len=startup_data_len@entry=24, client_sock=client_sock@entry=0x7ffd34184320) at launch_backend.c:290
#30 0x0000565eebf83ab7 in BackendStartup (client_sock=0x7ffd34184320) at postmaster.c:3587
#31 ServerLoop () at postmaster.c:1702
#32 0x0000565eebf853e1 in PostmasterMain (argc=argc@entry=1, argv=argv@entry=0x565f17b4f450) at postmaster.c:1400
#33 0x0000565eebcab360 in main (argc=1, argv=0x565f17b4f450) at main.c:227
Line numbers could be a bit off, but I think it is not very important.
pg_shseclabel.provider data type is TEXT with collation C.
When doing btree lookup by (objoid, classoid, provider) we need to take into account collation.
varstr_cmp() was used to make an exception for C collation, and now it has to do a cache lookup for pg_collation to determine that this is a C collation.
However, caches are not yet initialized at the moment when ClientAuthentication_hook is executed, and they can't be, because database access is not yet allowed.
Or, in other words, this commit made shared pg_catalog relations depend on non shared relations.
Regards,
--
Alexander Kukushkin
pgsql-hackers by date: