]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix aclitemout() to work during early bootstrap.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 14 Mar 2026 17:46:54 +0000 (13:46 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 14 Mar 2026 17:46:54 +0000 (13:46 -0400)
"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

src/backend/utils/adt/acl.c

index 071e3f2c49e8b4f769466eb7f9701a3c00c8c4a9..9e82c1fc1a17bf18d0983c0cb13ec8af9cbf7448 100644 (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);
        }