From cb33c8d547f2e7ecf64621c5eaf8dbab45981b84 Mon Sep 17 00:00:00 2001
From: Greg Burd <greg@burd.me>
Date: Thu, 12 Mar 2026 14:51:05 -0400
Subject: [PATCH v20260312c 3/3] Make aclitemout work during bootstrap mode

During bootstrap, aclitemout is called (via array_out) when
InsertOneValue emits DEBUG4-level output for aclitem[] columns. The
function tries to resolve role OIDs to names via SearchSysCache1, which
is not available during bootstrap, causing a crash.

Fix by skipping the syscache lookup when IsBootstrapProcessingMode() is
true, falling through to the existing numeric-OID fallback path. This
mirrors how aclitemin was previously hot-wired for bootstrap.

Reported-by: Greg Burd <greg@burd.me>
Discussion: https://postgr.es/m/470305.1772417108@sss.pgh.pa.us
---
 src/backend/utils/adt/acl.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index 071e3f2c49e..dfb23ea01b5 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -674,7 +674,12 @@ aclitemout(PG_FUNCTION_ARGS)
 
 	if (aip->ai_grantee != ACL_ID_PUBLIC)
 	{
-		htup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(aip->ai_grantee));
+		/*
+		 * During bootstrap the syscache is not yet available, so fall
+		 * through to the numeric-OID output path.
+		 */
+		htup = IsBootstrapProcessingMode() ? NULL :
+			SearchSysCache1(AUTHOID, ObjectIdGetDatum(aip->ai_grantee));
 		if (HeapTupleIsValid(htup))
 		{
 			putid(p, NameStr(((Form_pg_authid) GETSTRUCT(htup))->rolname));
@@ -702,7 +707,10 @@ aclitemout(PG_FUNCTION_ARGS)
 	*p++ = '/';
 	*p = '\0';
 
-	htup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(aip->ai_grantor));
+	/* Same bootstrap-mode guard for the grantor lookup */
+	htup = IsBootstrapProcessingMode() ? NULL :
+		SearchSysCache1(AUTHOID, ObjectIdGetDatum(aip->ai_grantor));
+
 	if (HeapTupleIsValid(htup))
 	{
 		putid(p, NameStr(((Form_pg_authid) GETSTRUCT(htup))->rolname));
-- 
2.51.2

