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 <greg@burd.me>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/4416.1773328045@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2026-03-14 13:46:54 -04:00
parent 02eecead86
commit 2eb87345e1

View file

@ -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);
}