From: Tom Lane Date: Sat, 14 Mar 2026 17:46:54 +0000 (-0400) Subject: Fix aclitemout() to work during early bootstrap. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2eb87345e18e18395bc5051f72c9f4ca30d70c38;p=thirdparty%2Fpostgresql.git Fix aclitemout() to work during early bootstrap. "initdb -d" has been broken since commit f95d73ed4, because I changed aclitemin to work in bootstrap mode but failed to consider aclitemout. That routine isn't reached by default, but it is if the elog message level is high enough, so it needs to work without catalog access too. This patch just makes it use its existing code paths to print role OIDs numerically. We could alternatively invent an inverse of boot_get_role_oid() and print them symbolically, but that would take more code and it's not apparent that it'd be any better for debugging purposes. Reported-by: Greg Burd Author: Tom Lane Discussion: https://postgr.es/m/4416.1773328045@sss.pgh.pa.us --- diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 071e3f2c49e..9e82c1fc1a1 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -652,6 +652,10 @@ aclitemin(PG_FUNCTION_ARGS) * Allocates storage for, and fills in, a new null-delimited string * containing a formatted ACL specification. See aclparse for details. * + * In bootstrap mode, this is called for debug printouts (initdb -d). + * We could ask bootstrap.c to provide an inverse of boot_get_role_oid(), + * but it seems at least as useful to just print numeric role OIDs. + * * RETURNS: * the new string */ @@ -674,7 +678,10 @@ aclitemout(PG_FUNCTION_ARGS) if (aip->ai_grantee != ACL_ID_PUBLIC) { - htup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(aip->ai_grantee)); + if (!IsBootstrapProcessingMode()) + htup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(aip->ai_grantee)); + else + htup = NULL; if (HeapTupleIsValid(htup)) { putid(p, NameStr(((Form_pg_authid) GETSTRUCT(htup))->rolname)); @@ -682,7 +689,7 @@ aclitemout(PG_FUNCTION_ARGS) } else { - /* Generate numeric OID if we don't find an entry */ + /* No such entry, or bootstrap mode: print numeric OID */ sprintf(p, "%u", aip->ai_grantee); } } @@ -702,7 +709,10 @@ aclitemout(PG_FUNCTION_ARGS) *p++ = '/'; *p = '\0'; - htup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(aip->ai_grantor)); + if (!IsBootstrapProcessingMode()) + htup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(aip->ai_grantor)); + else + htup = NULL; if (HeapTupleIsValid(htup)) { putid(p, NameStr(((Form_pg_authid) GETSTRUCT(htup))->rolname)); @@ -710,7 +720,7 @@ aclitemout(PG_FUNCTION_ARGS) } else { - /* Generate numeric OID if we don't find an entry */ + /* No such entry, or bootstrap mode: print numeric OID */ sprintf(p, "%u", aip->ai_grantor); }