我无法从 PSQL 中的身份验证挂钩读取 pg_auth_members table
I can't read the pg_auth_members table from the authentication hook in PSQL
在身份验证阶段,我试图获取与登录用户属于同一组的角色列表。为此,我使用了系统缓存搜索功能,但由于某种原因,使用 AUTHMEMROLEMEM
syscache id 我得到了错误 " can't read pg_class without selecting the database (relcache.c:320)"
。如果我使用AUTHMEMMEMROLE
,搜索是正常执行的。根据代码,两个 ID 必须引用相同的表,为此设置了 relisshare 标志,并且它们必须在身份验证之前可用。
例如hook中会报错的代码:
HeapTuple role_tup;
role_tup = SearchSysCache2(AUTHMEMROLEMEM, ObjectIdGetDatum(user_oid), ObjectIdGetDatum(search_oid));
并且不会导致:
HeapTuple role_tup;
role_tup = SearchSysCache2(AUTHMEMMEMROLE,ObjectIdGetDatum(user_oid), ObjectIdGetDatum(search_oid));
我是不是遗漏了什么或者是错误?
该索引被认为对身份验证不重要。参见RelationCacheInitializePhase3
中的以下代码:
/*
* Process critical shared indexes too.
*
* DatabaseNameIndexId isn't critical for relcache loading, but rather for
* initial lookup of MyDatabaseId, without which we'll never find any
* non-shared catalogs at all. Autovacuum calls InitPostgres with a
* database OID, so it instead depends on DatabaseOidIndexId. We also
* need to nail up some indexes on pg_authid and pg_auth_members for use
* during client authentication. SharedSecLabelObjectIndexId isn't
* critical for the core system, but authentication hooks might be
* interested in it.
*/
if (!criticalSharedRelcachesBuilt)
{
load_critical_index(DatabaseNameIndexId,
DatabaseRelationId);
load_critical_index(DatabaseOidIndexId,
DatabaseRelationId);
load_critical_index(AuthIdRolnameIndexId,
AuthIdRelationId);
load_critical_index(AuthIdOidIndexId,
AuthIdRelationId);
load_critical_index(AuthMemMemRoleIndexId,
AuthMemRelationId);
load_critical_index(SharedSecLabelObjectIndexId,
SharedSecLabelRelationId);
在身份验证阶段,我试图获取与登录用户属于同一组的角色列表。为此,我使用了系统缓存搜索功能,但由于某种原因,使用 AUTHMEMROLEMEM
syscache id 我得到了错误 " can't read pg_class without selecting the database (relcache.c:320)"
。如果我使用AUTHMEMMEMROLE
,搜索是正常执行的。根据代码,两个 ID 必须引用相同的表,为此设置了 relisshare 标志,并且它们必须在身份验证之前可用。
例如hook中会报错的代码:
HeapTuple role_tup;
role_tup = SearchSysCache2(AUTHMEMROLEMEM, ObjectIdGetDatum(user_oid), ObjectIdGetDatum(search_oid));
并且不会导致:
HeapTuple role_tup;
role_tup = SearchSysCache2(AUTHMEMMEMROLE,ObjectIdGetDatum(user_oid), ObjectIdGetDatum(search_oid));
我是不是遗漏了什么或者是错误?
该索引被认为对身份验证不重要。参见RelationCacheInitializePhase3
中的以下代码:
/*
* Process critical shared indexes too.
*
* DatabaseNameIndexId isn't critical for relcache loading, but rather for
* initial lookup of MyDatabaseId, without which we'll never find any
* non-shared catalogs at all. Autovacuum calls InitPostgres with a
* database OID, so it instead depends on DatabaseOidIndexId. We also
* need to nail up some indexes on pg_authid and pg_auth_members for use
* during client authentication. SharedSecLabelObjectIndexId isn't
* critical for the core system, but authentication hooks might be
* interested in it.
*/
if (!criticalSharedRelcachesBuilt)
{
load_critical_index(DatabaseNameIndexId,
DatabaseRelationId);
load_critical_index(DatabaseOidIndexId,
DatabaseRelationId);
load_critical_index(AuthIdRolnameIndexId,
AuthIdRelationId);
load_critical_index(AuthIdOidIndexId,
AuthIdRelationId);
load_critical_index(AuthMemMemRoleIndexId,
AuthMemRelationId);
load_critical_index(SharedSecLabelObjectIndexId,
SharedSecLabelRelationId);