generating function default settings from pg_proc.dat

Поиск
Список
Период
Сортировка
Искать

generating function default settings from pg_proc.dat

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Вложения:

Motivated by Bug 19409 [1] I decided to do something about a wart that 
has bugged me for a while, namely the requirement to write stuff in 
system_views.sql if you need to specify default values for function 
arguments. Here's my attempt. The first patch here sets up the required 
infrastructure. genbki.pl creates a file called function_defaults.sql 
which is run by initdb at the appropriate time. There are two new fields 
in pg_proc.dat entries: proargdflts,and provariadicdflt. These are 
parsed and the appropriate CREATE OR REPLACE statement is generated and 
placed in function_defaults.sql. The second patch applies this treatment 
to 37 function definitions and removes the corresponding statements from 
system_views.sql. This gets us closer to having pg_proc.dat as a single 
source of truth.


cheers


andrew


[1] 
https://www.postgresql.org/message-id/19409-e16cd2605e59a4af%40postgresql.org

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Re: generating function default settings from pg_proc.dat

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 16 Feb 2026, at 18:31, Andrew Dunstan  wrote:

> Motivated by Bug 19409 [1] I decided to do something about a wart that has bugged me for a while, namely the requirement to write stuff in system_views.sql if you need to specify default values for function arguments.

I haven't studied the patch yet, but a big +many on the idea.  This has bugged
me many times.

--
Daniel Gustafsson



Re: generating function default settings from pg_proc.dat

От:
Corey Huinker <corey.huinker@gmail.com>
Дата:


On Mon, Feb 16, 2026 at 12:31 PM Andrew Dunstan <andrew@dunslane.net> wrote:

Motivated by Bug 19409 [1] I decided to do something about a wart that
has bugged me for a while, namely the requirement to write stuff in
system_views.sql if you need to specify default values for function
arguments. Here's my attempt. The first patch here sets up the required
infrastructure. genbki.pl creates a file called function_defaults.sql
which is run by initdb at the appropriate time. There are two new fields
in pg_proc.dat entries: proargdflts,and provariadicdflt. These are
parsed and the appropriate CREATE OR REPLACE statement is generated and
placed in function_defaults.sql. The second patch applies this treatment
to 37 function definitions and removes the corresponding statements from
system_views.sql. This gets us closer to having pg_proc.dat as a single
source of truth.

+1 for the attempt. My preference would be for allowing CREATE OR REPLACE to specify an oid, but that's a non-starter for bootstrapping purposes, so this is the next best option.

The defaults read a little funny in that a human reader must line up the defaults right-to-left to then determine a given parameter's default, if any. For example:

   proname => 'json_strip_nulls', prorettype => 'json',
-  proargtypes => 'json bool', prosrc => 'json_strip_nulls' },
+  proargtypes => 'json bool',
+  proargnames => '{target,strip_in_arrays}', proargdflts => '{false}',
+  prosrc => 'json_strip_nulls' },

Perhaps we could require proargdflts to pre-pad with empty values 

    proargdflts => '{,false}'

or even be a hash

    proargdflts => { strip_in_arrays => 'false' }

which I will grant you is wordy, but its definitely clearer.

Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Andrew Dunstan  writes:
> Motivated by Bug 19409 [1] I decided to do something about a wart that 
> has bugged me for a while, namely the requirement to write stuff in 
> system_views.sql if you need to specify default values for function 
> arguments. Here's my attempt. The first patch here sets up the required 
> infrastructure. genbki.pl creates a file called function_defaults.sql 
> which is run by initdb at the appropriate time. There are two new fields 
> in pg_proc.dat entries: proargdflts,and provariadicdflt. These are 
> parsed and the appropriate CREATE OR REPLACE statement is generated and 
> placed in function_defaults.sql. The second patch applies this treatment 
> to 37 function definitions and removes the corresponding statements from 
> system_views.sql. This gets us closer to having pg_proc.dat as a single 
> source of truth.

Nice!  I'll review this in more detail later, but it seems like
a great idea.

One nitpick is that it's not clear how someone would discover the
existence of this feature.  We could of course add info to bki.sgml,
but I wish it were more organic.  Is there a way that we could have
these entries appear in "proargdefaults" so that there's an obvious
connection to the actual catalog field?

			regards, tom lane


Re: generating function default settings from pg_proc.dat

От:
Andres Freund <andres@anarazel.de>
Дата:
Hi,

On 2026-02-16 12:31:37 -0500, Andrew Dunstan wrote:
> Motivated by Bug 19409 [1] I decided to do something about a wart that has
> bugged me for a while, namely the requirement to write stuff in
> system_views.sql if you need to specify default values for function
> arguments.

I'm one more person this has been bugging.

A related issue is that we have grants and revokes as part of
system_functions.sql. Perhaps it's worth tackling that at the same time?


> Here's my attempt. The first patch here sets up the required
> infrastructure. genbki.pl creates a file called function_defaults.sql which
> is run by initdb at the appropriate time.

Hm. I don't love that we first insert something into pg_proc, then generate a
full blown CREATE OR REPLACE FUNCTION with all the details to edit it.  It
wouldn't take too much to somehow end up, down the line, with a silent
mismatch between what pg_proc.h contains and what CREATE OR REPLACE FUNCTION
ends up generating.  I'm not sure we'd be likely to notice such a mismatch
immediately.

In fact, I think the current translation may have such an issue, the generated
CREATE OR REPLACE doesn't seem include ROWS, which seems to lead to resetting
prorows to the default 1000, regardless of what it was before.

DROP FUNCTION IF EXISTS foo();
CREATE FUNCTION foo() RETURNS SETOF int LANGUAGE SQL VOLATILE ROWS 10 AS $$SELECT generate_series(1, 10)$$;
SELECT prorows FROM pg_proc WHERE  proname = 'foo';
┌─────────┐
│ prorows │
├─────────┤
│      10 │
└─────────┘

CREATE OR REPLACE FUNCTION foo() RETURNS SETOF int LANGUAGE SQL VOLATILE AS $$SELECT generate_series(1, 10)$$;
SELECT prorows FROM pg_proc WHERE proname = 'foo';
┌─────────┐
│ prorows │
├─────────┤
│    1000 │
└─────────┘


I wish we could just generate the parse-analyzed representation for default
values during bootstrap, but that's probably not realistic.

Although, I guess we don't really need the full machinery. Afaict we just need
a list of simple CONST nodes. There are two current functions (random_normal()
and pg_terminate_backend()), where the default expressions contains casts
implemented via FUNCEXPR, but that's just sloppiness in the DEFAULT
specification we probably should fix independently of everything else.

Greetings,

Andres Freund


Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Andres Freund  writes:
> I wish we could just generate the parse-analyzed representation for default
> values during bootstrap, but that's probably not realistic.

> Although, I guess we don't really need the full machinery. Afaict we just need
> a list of simple CONST nodes.

Const is enough to be problematic.  In particular, the bytes of the
stored Datum are shown in physical order so that the results are
endian-dependent.  We can't have machine dependencies in postgres.bki.
I suppose it might be possible to rethink the printed representation
of Const nodes to dodge that problem, but that's starting to make the
project seem rather complex.  Even without that, hand-maintained
byte-level representations of jsonb, float8, text[] seem like a pretty
bad idea.

I think what we'd really want here is some smarts in backend bootstrap
mode to be able to invoke the correct datatype input function to
convert the type's standard string representation into a Datum.
I wonder how complicated that'd be.

			regards, tom lane


Re: generating function default settings from pg_proc.dat

От:
Andres Freund <andres@anarazel.de>
Дата:
Hi,

On 2026-02-16 14:13:45 -0500, Tom Lane wrote:
> Andres Freund  writes:
> > I wish we could just generate the parse-analyzed representation for default
> > values during bootstrap, but that's probably not realistic.
>
> > Although, I guess we don't really need the full machinery. Afaict we just need
> > a list of simple CONST nodes.
>
> Const is enough to be problematic.  In particular, the bytes of the
> stored Datum are shown in physical order so that the results are
> endian-dependent.  We can't have machine dependencies in postgres.bki.

I was more thinking we would teach bootstrap.c/bootparse.y to generate the
List(Const+) from a simpler representation that would be included in
postgres.bki, rather than include the node tree soup in postgres.bki.


> I think what we'd really want here is some smarts in backend bootstrap
> mode to be able to invoke the correct datatype input function to
> convert the type's standard string representation into a Datum.
> I wonder how complicated that'd be.

Seems we were thinking something roughly similar...

Looks like the slightly difficult bit is that we haven't assembled the pg_proc
row by the time we'd do the OidInputFunctionCall() in InsertOneValue(), so
we'd not trivially know the type of the corresponding column.

But if we made the input something like {'some'::type1, 'value'::type2}, we
wouldn't need to know the corresponding column's type, and genbki could build
it.


I'm starting to wonder if we shouldn't do something more bespoke for all
functions during bootstrap in general, rather than just for the argument
defaults.

Particularly for SRFs, I find it rather painful to keep proargtypes,
proallargtypes, proargmodes, proargnames in sync. Not helped by proargtypes
and proallargtypes/proargmodes/... having a different input syntax.  I've
spent too much time trying to keep the arguments of stats functions in sync.


{ oid => '3786', descr => 'set up a logical replication slot',
  proname => 'pg_create_logical_replication_slot', provolatile => 'v',
  proparallel => 'u', prorettype => 'record',
  proargtypes => 'name name bool bool bool',
  proallargtypes => '{name,name,bool,bool,bool,name,pg_lsn}',
  proargmodes => '{i,i,i,i,i,o,o}',
  proargnames => '{slot_name,plugin,temporary,twophase,failover,slot_name,lsn}',
  prosrc => 'pg_create_logical_replication_slot' },

+

CREATE OR REPLACE FUNCTION pg_create_logical_replication_slot(
    IN slot_name name, IN plugin name,
    IN temporary boolean DEFAULT false,
    IN twophase boolean DEFAULT false,
    IN failover boolean DEFAULT false,
    OUT slot_name name, OUT lsn pg_lsn)
RETURNS RECORD
LANGUAGE INTERNAL
STRICT VOLATILE
AS 'pg_create_logical_replication_slot';

could be

{ oid => '3786', descr => 'set up a logical replication slot',
  proname => 'pg_create_logical_replication_slot', provolatile => 'v',
  proparallel => 'u',
  proargs => [
     {type => 'name', name => 'slot_name'},
     {type => 'name', name => 'plugin'},
     {type => 'bool', name => 'temporary', default => 'false'},
     {type => 'bool', name => 'twophase', default => 'false'},
     {type => 'bool', name => 'failover', default => 'false'},
  ],
  prorettype => [
     {type => 'name', name => 'slot_name'},
     {type => 'pg_lsn', name => 'lsn'},
  ]
}

and then either turn that into something like the current representation, or
perhaps better, into a new top-level 'proc' bootstrap command, which then
would know how to interpret the default literals into the node soup.

Greetings,

Andres Freund


Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Andres Freund  writes:
> On 2026-02-16 14:13:45 -0500, Tom Lane wrote:
>> Const is enough to be problematic.  In particular, the bytes of the
>> stored Datum are shown in physical order so that the results are
>> endian-dependent.  We can't have machine dependencies in postgres.bki.

> I was more thinking we would teach bootstrap.c/bootparse.y to generate the
> List(Const+) from a simpler representation that would be included in
> postgres.bki, rather than include the node tree soup in postgres.bki.

Right, maintaining pg_node_tree strings is exactly what we don't want
to do.

> Looks like the slightly difficult bit is that we haven't assembled the pg_proc
> row by the time we'd do the OidInputFunctionCall() in InsertOneValue(), so
> we'd not trivially know the type of the corresponding column.

Ah, I'd not got far enough to notice that.

> But if we made the input something like {'some'::type1, 'value'::type2}, we
> wouldn't need to know the corresponding column's type, and genbki could build
> it.

Hmm.  Your idea of a bespoke 'proc' command would avoid the need for
duplication, I think, although I'm not sure how to write that without
it becoming its own source of maintenance pain.

> Particularly for SRFs, I find it rather painful to keep proargtypes,
> proallargtypes, proargmodes, proargnames in sync. Not helped by proargtypes
> and proallargtypes/proargmodes/... having a different input syntax.  I've
> spent too much time trying to keep the arguments of stats functions in sync.

Agreed, we could stand to do that better.

>   proargs => [
>      {type => 'name', name => 'slot_name'},
>      {type => 'name', name => 'plugin'},
>      {type => 'bool', name => 'temporary', default => 'false'},
>      {type => 'bool', name => 'twophase', default => 'false'},
>      {type => 'bool', name => 'failover', default => 'false'},
>   ],
>   prorettype => [
>      {type => 'name', name => 'slot_name'},
>      {type => 'pg_lsn', name => 'lsn'},
>   ]
> }

I'd be inclined to keep prorettype separate from the output
arguments, but otherwise something like this seems attractive.

Who's going to work on this?  I'm happy to take a swing at it,
but don't want to duplicate someone else's effort.

			regards, tom lane


Re: generating function default settings from pg_proc.dat

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:

On 2026-02-16 Mo 3:02 PM, Tom Lane wrote:
> Andres Freund  writes:
>> On 2026-02-16 14:13:45 -0500, Tom Lane wrote:
>>> Const is enough to be problematic.  In particular, the bytes of the
>>> stored Datum are shown in physical order so that the results are
>>> endian-dependent.  We can't have machine dependencies in postgres.bki.
>> I was more thinking we would teach bootstrap.c/bootparse.y to generate the
>> List(Const+) from a simpler representation that would be included in
>> postgres.bki, rather than include the node tree soup in postgres.bki.
> Right, maintaining pg_node_tree strings is exactly what we don't want
> to do.
>
>> Looks like the slightly difficult bit is that we haven't assembled the pg_proc
>> row by the time we'd do the OidInputFunctionCall() in InsertOneValue(), so
>> we'd not trivially know the type of the corresponding column.
> Ah, I'd not got far enough to notice that.
>
>> But if we made the input something like {'some'::type1, 'value'::type2}, we
>> wouldn't need to know the corresponding column's type, and genbki could build
>> it.
> Hmm.  Your idea of a bespoke 'proc' command would avoid the need for
> duplication, I think, although I'm not sure how to write that without
> it becoming its own source of maintenance pain.
>
>> Particularly for SRFs, I find it rather painful to keep proargtypes,
>> proallargtypes, proargmodes, proargnames in sync. Not helped by proargtypes
>> and proallargtypes/proargmodes/... having a different input syntax.  I've
>> spent too much time trying to keep the arguments of stats functions in sync.
> Agreed, we could stand to do that better.
>
>>    proargs => [
>>       {type => 'name', name => 'slot_name'},
>>       {type => 'name', name => 'plugin'},
>>       {type => 'bool', name => 'temporary', default => 'false'},
>>       {type => 'bool', name => 'twophase', default => 'false'},
>>       {type => 'bool', name => 'failover', default => 'false'},
>>    ],
>>    prorettype => [
>>       {type => 'name', name => 'slot_name'},
>>       {type => 'pg_lsn', name => 'lsn'},
>>    ]
>> }
> I'd be inclined to keep prorettype separate from the output
> arguments, but otherwise something like this seems attractive.
>
> Who's going to work on this?  I'm happy to take a swing at it,
> but don't want to duplicate someone else's effort.


Go for it. I'm happy to review.


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com



Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Andrew Dunstan  writes:
> On 2026-02-16 Mo 3:02 PM, Tom Lane wrote:
>> Who's going to work on this?  I'm happy to take a swing at it,
>> but don't want to duplicate someone else's effort.

> Go for it. I'm happy to review.

After a little bit of thought, I propose the following sketch
for what to do in the bootstrap backend:

In InsertOneValue(), add a special case for typoid == PG_NODE_TREEOID.
pg_node_tree_in() would just fail anyway so this isn't removing
any useful functionality.  The special-case code would check which
column we are entering a value for and dispatch to appropriate code:

       if (typoid == PG_NODE_TREEOID)
       {
           if (RelationGetRelid(boot_reldesc) == ProcedureRelationId &&
	       i == Anum_pg_proc_proargdefaults - 1)
	       values[i] = ConvertOneProargdefaultsValue(value);
	   else
	       ... maybe other cases later
	   else
	       elog(ERROR, "can't handle pg_node_tree input");
	   return;
       }

This framework would permit special-casing other catalog columns
in future, if we feel a need for that.

Andres was concerned about not having access to the other columns of
pg_proc, but I think that's mistaken: bootstrap.c's values[] array
should hold the already-parsed values of all earlier columns for the
current entry.  So ISTM that we should have enough data to interpret
an input that just looks like an array of input-value strings and
construct a List of Const nodes from that, then flatten it to a
nodetree string.

So with that we'd have enough infrastructure to allow writing
something like

	proargdefaults => '{1,2,true}'

This seems orthogonal to Andres' suggestion about refactoring
the pg_proc.dat representation of arguments to not be parallel
arrays but a list of hashes.  I think that's likely a good
idea, but I don't want to implement it because I'm not a great
Perl programmer.  Do you want to pick up that part?

			regards, tom lane


Re: generating function default settings from pg_proc.dat

От:
Michael Paquier <michael@paquier.xyz>
Дата:
Вложения:
On Mon, Feb 16, 2026 at 01:54:49PM -0500, Andres Freund wrote:
> On 2026-02-16 12:31:37 -0500, Andrew Dunstan wrote:
>> Motivated by Bug 19409 [1] I decided to do something about a wart that has
>> bugged me for a while, namely the requirement to write stuff in
>> system_views.sql if you need to specify default values for function
>> arguments.
> 
> I'm one more person this has been bugging.

Please add me on the stack of people who have been annoyed by that
largely more than once.  Glad to see that this could be enforced in
the bki scripts.
--
Michael

Re: generating function default settings from pg_proc.dat

От:
Álvaro Herrera <alvherre@kurilemu.de>
Дата:
On 2026-Feb-16, Andres Freund wrote:

> could be
> 
> { oid => '3786', descr => 'set up a logical replication slot',
>   proname => 'pg_create_logical_replication_slot', provolatile => 'v',
>   proparallel => 'u',
>   proargs => [
>      {type => 'name', name => 'slot_name'},
>      {type => 'name', name => 'plugin'},
>      {type => 'bool', name => 'temporary', default => 'false'},
>      {type => 'bool', name => 'twophase', default => 'false'},
>      {type => 'bool', name => 'failover', default => 'false'},
>   ],
>   prorettype => [
>      {type => 'name', name => 'slot_name'},
>      {type => 'pg_lsn', name => 'lsn'},
>   ]
> }

This is pretty much the sort of thing I was imagining when I read
Corey's argumentation.  +1 for something along these lines.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
"Pero la cosa no es muy grave ..."     (le petit Nicolas -- René Goscinny)


Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I wrote:
> After a little bit of thought, I propose the following sketch
> for what to do in the bootstrap backend:

Here is a draft patch along those lines.  I've verified that
the initial contents of pg_proc are exactly as before,
except that json[b]_strip_nulls gain the correct provolatile
value, and a few proargdefaults entries no longer involve
cast functions.

The changes in system_functions.sql and pg_proc.dat are nearly
verbatim from your 0002 patch, except that I had to adjust the
quoting conventions in some places because array_in does it
differently.

			regards, tom lane

diff --git a/doc/src/sgml/bki.sgml b/doc/src/sgml/bki.sgml
index 53a982bf60d..0747db98fc0 100644
--- a/doc/src/sgml/bki.sgml
+++ b/doc/src/sgml/bki.sgml
@@ -271,6 +271,21 @@
      
     
 
+    
+     
+      There is a special case for values of the
+      pg_proc.proargdefaults
+      field, which is of type pg_node_tree.  The real
+      contents of that type are too complex for hand-written entries,
+      but what we need for proargdefaults is
+      typically just a list of Const nodes.  Therefore, the bootstrap
+      backend will interpret a value given for that field according to
+      text array syntax, and then feed the array element values to the
+      datatype input routines for the corresponding input parameters' data
+      types, and finally build Const nodes from the datums.
+     
+    
+
     
      
       Since hashes are unordered data structures, field order and line
@@ -817,8 +832,10 @@ $ perl  rewrite_dat_with_prokind.pl  pg_proc.dat
       The following column types are supported directly by
       bootstrap.c: bool,
       bytea, char (1 byte),
-      name, int2,
-      int4, regproc, regclass,
+      int2, int4, int8,
+      float4, float8,
+      name,
+      regproc, regclass,
       regtype, text,
       oid, tid, xid,
       cid, int2vector, oidvector,
@@ -884,7 +901,7 @@ $ perl  rewrite_dat_with_prokind.pl  pg_proc.dat
 
    
     
-     insert ( oid_value value1 value2 ... )
+     insert ( value1 value2 ... )
     
 
     
@@ -902,6 +919,13 @@ $ perl  rewrite_dat_with_prokind.pl  pg_proc.dat
       (To include a single quote in a value, write it twice.
       Escape-string-style backslash escapes are allowed in the string, too.)
      
+
+     
+      In most cases a value
+      string is simply fed to the datatype input routine for the column's
+      data type, after de-quoting if needed.  However there are exceptions
+      for certain fields, as detailed previously.
+     
     
    
 
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 7d32cd0e159..36a3a9f774c 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -26,6 +26,7 @@
 #include "bootstrap/bootstrap.h"
 #include "catalog/index.h"
 #include "catalog/pg_collation.h"
+#include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "common/link-canary.h"
 #include "miscadmin.h"
@@ -45,7 +46,9 @@
 
 static void CheckerModeMain(void);
 static void bootstrap_signals(void);
+static Oid	boot_get_typcollation(Oid typid);
 static Form_pg_attribute AllocateAttribute(void);
+static Datum ConvertOneProargdefaultsValue(char *value);
 static void populate_typ_list(void);
 static Oid	gettype(char *type);
 static void cleanup(void);
@@ -95,8 +98,12 @@ static const struct typinfo TypInfo[] = {
 	F_INT2IN, F_INT2OUT},
 	{"int4", INT4OID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
 	F_INT4IN, F_INT4OUT},
+	{"int8", INT8OID, 0, 8, true, TYPALIGN_DOUBLE, TYPSTORAGE_PLAIN, InvalidOid,
+	F_INT8IN, F_INT8OUT},
 	{"float4", FLOAT4OID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
 	F_FLOAT4IN, F_FLOAT4OUT},
+	{"float8", FLOAT8OID, 0, 8, true, TYPALIGN_DOUBLE, TYPSTORAGE_PLAIN, InvalidOid,
+	F_FLOAT8IN, F_FLOAT8OUT},
 	{"name", NAMEOID, CHAROID, NAMEDATALEN, false, TYPALIGN_CHAR, TYPSTORAGE_PLAIN, C_COLLATION_OID,
 	F_NAMEIN, F_NAMEOUT},
 	{"regclass", REGCLASSOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
@@ -123,6 +130,8 @@ static const struct typinfo TypInfo[] = {
 	F_XIDIN, F_XIDOUT},
 	{"cid", CIDOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
 	F_CIDIN, F_CIDOUT},
+	{"jsonb", JSONBOID, 0, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
+	F_JSONB_IN, F_JSONB_OUT},
 	{"pg_node_tree", PG_NODE_TREEOID, 0, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, DEFAULT_COLLATION_OID,
 	F_PG_NODE_TREE_IN, F_PG_NODE_TREE_OUT},
 	{"int2vector", INT2VECTOROID, INT2OID, -1, false, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
@@ -673,14 +682,32 @@ InsertOneValue(char *value, int i)
 
 	elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
 
-	typoid = TupleDescAttr(boot_reldesc->rd_att, i)->atttypid;
+	typoid = TupleDescAttr(RelationGetDescr(boot_reldesc), i)->atttypid;
 
 	boot_get_type_io_data(typoid,
 						  &typlen, &typbyval, &typalign,
 						  &typdelim, &typioparam,
 						  &typinput, &typoutput);
 
-	values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
+	/*
+	 * pg_node_tree values can't be inserted normally (pg_node_tree_in would
+	 * just error out), so provide special cases for such columns that we
+	 * would like to fill during bootstrap.
+	 */
+	if (typoid == PG_NODE_TREEOID)
+	{
+		/* pg_proc.proargdefaults */
+		if (RelationGetRelid(boot_reldesc) == ProcedureRelationId &&
+			i == Anum_pg_proc_proargdefaults - 1)
+			values[i] = ConvertOneProargdefaultsValue(value);
+		else					/* maybe other cases later */
+			elog(ERROR, "can't handle pg_node_tree input");
+	}
+	else
+	{
+		/* Normal case */
+		values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
+	}
 
 	/*
 	 * We use ereport not elog here so that parameters aren't evaluated unless
@@ -691,6 +718,110 @@ InsertOneValue(char *value, int i)
 							 OidOutputFunctionCall(typoutput, values[i]))));
 }
 
+/* ----------------
+ *		ConvertOneProargdefaultsValue
+ *
+ * In general, proargdefaults can be a list of any expressions, but
+ * for bootstrap we only support a list of Const nodes.  The input
+ * has the form of a text array, and we feed non-null elements to the
+ * typinput functions for the appropriate parameters.
+ * ----------------
+ */
+static Datum
+ConvertOneProargdefaultsValue(char *value)
+{
+	int			pronargs;
+	oidvector  *proargtypes;
+	Datum		arrayval;
+	Datum	   *array_datums;
+	bool	   *array_nulls;
+	int			array_count;
+	List	   *proargdefaults;
+
+	/* The pg_proc columns we need to use must have been filled already */
+	StaticAssertDecl(Anum_pg_proc_pronargs < Anum_pg_proc_proargdefaults,
+					 "pronargs must come before proargdefaults");
+	StaticAssertDecl(Anum_pg_proc_pronargdefaults < Anum_pg_proc_proargdefaults,
+					 "pronargdefaults must come before proargdefaults");
+	StaticAssertDecl(Anum_pg_proc_proargtypes < Anum_pg_proc_proargdefaults,
+					 "proargtypes must come before proargdefaults");
+	if (Nulls[Anum_pg_proc_pronargs - 1])
+		elog(ERROR, "pronargs must not be null");
+	if (Nulls[Anum_pg_proc_proargtypes - 1])
+		elog(ERROR, "proargtypes must not be null");
+	pronargs = DatumGetInt16(values[Anum_pg_proc_pronargs - 1]);
+	proargtypes = DatumGetPointer(values[Anum_pg_proc_proargtypes - 1]);
+	Assert(pronargs == proargtypes->dim1);
+
+	/* Parse the input string as a text[] value, then deconstruct to Datums */
+	arrayval = OidFunctionCall3(F_ARRAY_IN,
+								CStringGetDatum(value),
+								ObjectIdGetDatum(TEXTOID),
+								Int32GetDatum(-1));
+	deconstruct_array_builtin(DatumGetArrayTypeP(arrayval), TEXTOID,
+							  &array_datums, &array_nulls, &array_count);
+
+	/* The values should correspond to the last N argtypes */
+	if (array_count > pronargs)
+		elog(ERROR, "too many proargdefaults entries");
+
+	/* Build the List of Const nodes */
+	proargdefaults = NIL;
+	for (int i = 0; i < array_count; i++)
+	{
+		Oid			argtype = proargtypes->values[pronargs - array_count + i];
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		char		typdelim;
+		Oid			typioparam;
+		Oid			typinput;
+		Oid			typoutput;
+		Oid			typcollation;
+		Datum		defval;
+		bool		defnull;
+		Const	   *defConst;
+
+		boot_get_type_io_data(argtype,
+							  &typlen, &typbyval, &typalign,
+							  &typdelim, &typioparam,
+							  &typinput, &typoutput);
+		typcollation = boot_get_typcollation(argtype);
+
+		defnull = array_nulls[i];
+		if (defnull)
+			defval = (Datum) 0;
+		else
+		{
+			char	   *defstr = text_to_cstring(DatumGetTextPP(array_datums[i]));
+
+			defval = OidInputFunctionCall(typinput, defstr, typioparam, -1);
+		}
+
+		defConst = makeConst(argtype,
+							 -1,	/* never any typmod */
+							 typcollation,
+							 typlen,
+							 defval,
+							 defnull,
+							 typbyval);
+		proargdefaults = lappend(proargdefaults, defConst);
+	}
+
+	/*
+	 * Hack: fill in pronargdefaults with the right value.  This is surely
+	 * ugly, but it beats making the programmer do it.
+	 */
+	values[Anum_pg_proc_pronargdefaults - 1] = Int16GetDatum(array_count);
+	Nulls[Anum_pg_proc_pronargdefaults - 1] = false;
+
+	/*
+	 * Flatten the List to a node-tree string, then convert to a text datum,
+	 * which is the storage representation of pg_node_tree.
+	 */
+	return CStringGetTextDatum(nodeToString(proargdefaults));
+}
+
 /* ----------------
  *		InsertOneNull
  * ----------------
@@ -907,6 +1038,53 @@ boot_get_type_io_data(Oid typid,
 	}
 }
 
+/* ----------------
+ *		boot_get_typcollation
+ *
+ * Obtain type's collation at bootstrap time.  This intentionally has
+ * the same API as lsyscache.c's get_typcollation.
+ *
+ * XXX would it be better to add another output to boot_get_type_io_data?
+ * ----------------
+ */
+static Oid
+boot_get_typcollation(Oid typid)
+{
+	if (Typ != NIL)
+	{
+		/* We have the boot-time contents of pg_type, so use it */
+		struct typmap *ap = NULL;
+		ListCell   *lc;
+
+		foreach(lc, Typ)
+		{
+			ap = lfirst(lc);
+			if (ap->am_oid == typid)
+				break;
+		}
+
+		if (!ap || ap->am_oid != typid)
+			elog(ERROR, "type OID %u not found in Typ list", typid);
+
+		return ap->am_typ.typcollation;
+	}
+	else
+	{
+		/* We don't have pg_type yet, so use the hard-wired TypInfo array */
+		int			typeindex;
+
+		for (typeindex = 0; typeindex < n_types; typeindex++)
+		{
+			if (TypInfo[typeindex].oid == typid)
+				break;
+		}
+		if (typeindex >= n_types)
+			elog(ERROR, "type OID %u not found in TypInfo", typid);
+
+		return TypInfo[typeindex].collation;
+	}
+}
+
 /* ----------------
  *		AllocateAttribute
  *
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index eb9e31ae1bf..4c20bb380a4 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -7,7 +7,7 @@
  *
  * This file redefines certain built-in functions that are impractical
  * to fully define in pg_proc.dat.  In most cases that's because they use
- * SQL-standard function bodies and/or default expressions.  The node
+ * SQL-standard function bodies.  The node
  * tree representations of those are too unreadable, platform-dependent,
  * and changeable to want to deal with them manually.  Hence, we put stub
  * definitions of such functions into pg_proc.dat and then replace them
@@ -66,13 +66,6 @@ CREATE OR REPLACE FUNCTION bit_length(text)
  IMMUTABLE PARALLEL SAFE STRICT COST 1
 RETURN octet_length($1) * 8;
 
-CREATE OR REPLACE FUNCTION
- random_normal(mean float8 DEFAULT 0, stddev float8 DEFAULT 1)
- RETURNS float8
- LANGUAGE internal
- VOLATILE PARALLEL RESTRICTED STRICT COST 1
-AS 'drandom_normal';
-
 CREATE OR REPLACE FUNCTION log(numeric)
  RETURNS numeric
  LANGUAGE sql
@@ -382,281 +375,6 @@ CREATE OR REPLACE FUNCTION ts_debug(document text,
 BEGIN ATOMIC
     SELECT * FROM ts_debug(get_current_ts_config(), $1);
 END;
-
-CREATE OR REPLACE FUNCTION
-  pg_backup_start(label text, fast boolean DEFAULT false)
-  RETURNS pg_lsn STRICT VOLATILE LANGUAGE internal AS 'pg_backup_start'
-  PARALLEL RESTRICTED;
-
-CREATE OR REPLACE FUNCTION pg_backup_stop (
-        wait_for_archive boolean DEFAULT true, OUT lsn pg_lsn,
-        OUT labelfile text, OUT spcmapfile text)
-  RETURNS record STRICT VOLATILE LANGUAGE internal as 'pg_backup_stop'
-  PARALLEL RESTRICTED;
-
-CREATE OR REPLACE FUNCTION
-  pg_promote(wait boolean DEFAULT true, wait_seconds integer DEFAULT 60)
-  RETURNS boolean STRICT VOLATILE LANGUAGE INTERNAL AS 'pg_promote'
-  PARALLEL SAFE;
-
-CREATE OR REPLACE FUNCTION
-  pg_terminate_backend(pid integer, timeout int8 DEFAULT 0)
-  RETURNS boolean STRICT VOLATILE LANGUAGE INTERNAL AS 'pg_terminate_backend'
-  PARALLEL SAFE;
-
--- legacy definition for compatibility with 9.3
-CREATE OR REPLACE FUNCTION
-  json_populate_record(base anyelement, from_json json, use_json_as_text boolean DEFAULT false)
-  RETURNS anyelement LANGUAGE internal STABLE AS 'json_populate_record' PARALLEL SAFE;
-
--- legacy definition for compatibility with 9.3
-CREATE OR REPLACE FUNCTION
-  json_populate_recordset(base anyelement, from_json json, use_json_as_text boolean DEFAULT false)
-  RETURNS SETOF anyelement LANGUAGE internal STABLE ROWS 100  AS 'json_populate_recordset' PARALLEL SAFE;
-
-CREATE OR REPLACE FUNCTION pg_logical_slot_get_changes(
-    IN slot_name name, IN upto_lsn pg_lsn, IN upto_nchanges int, VARIADIC options text[] DEFAULT '{}',
-    OUT lsn pg_lsn, OUT xid xid, OUT data text)
-RETURNS SETOF RECORD
-LANGUAGE INTERNAL
-VOLATILE ROWS 1000 COST 1000
-AS 'pg_logical_slot_get_changes';
-
-CREATE OR REPLACE FUNCTION pg_logical_slot_peek_changes(
-    IN slot_name name, IN upto_lsn pg_lsn, IN upto_nchanges int, VARIADIC options text[] DEFAULT '{}',
-    OUT lsn pg_lsn, OUT xid xid, OUT data text)
-RETURNS SETOF RECORD
-LANGUAGE INTERNAL
-VOLATILE ROWS 1000 COST 1000
-AS 'pg_logical_slot_peek_changes';
-
-CREATE OR REPLACE FUNCTION pg_logical_slot_get_binary_changes(
-    IN slot_name name, IN upto_lsn pg_lsn, IN upto_nchanges int, VARIADIC options text[] DEFAULT '{}',
-    OUT lsn pg_lsn, OUT xid xid, OUT data bytea)
-RETURNS SETOF RECORD
-LANGUAGE INTERNAL
-VOLATILE ROWS 1000 COST 1000
-AS 'pg_logical_slot_get_binary_changes';
-
-CREATE OR REPLACE FUNCTION pg_logical_slot_peek_binary_changes(
-    IN slot_name name, IN upto_lsn pg_lsn, IN upto_nchanges int, VARIADIC options text[] DEFAULT '{}',
-    OUT lsn pg_lsn, OUT xid xid, OUT data bytea)
-RETURNS SETOF RECORD
-LANGUAGE INTERNAL
-VOLATILE ROWS 1000 COST 1000
-AS 'pg_logical_slot_peek_binary_changes';
-
-CREATE OR REPLACE FUNCTION pg_logical_emit_message(
-    transactional boolean,
-    prefix text,
-    message text,
-    flush boolean DEFAULT false)
-RETURNS pg_lsn
-LANGUAGE INTERNAL
-STRICT VOLATILE
-AS 'pg_logical_emit_message_text';
-
-CREATE OR REPLACE FUNCTION pg_logical_emit_message(
-    transactional boolean,
-    prefix text,
-    message bytea,
-    flush boolean DEFAULT false)
-RETURNS pg_lsn
-LANGUAGE INTERNAL
-STRICT VOLATILE
-AS 'pg_logical_emit_message_bytea';
-
-CREATE OR REPLACE FUNCTION pg_create_physical_replication_slot(
-    IN slot_name name, IN immediately_reserve boolean DEFAULT false,
-    IN temporary boolean DEFAULT false,
-    OUT slot_name name, OUT lsn pg_lsn)
-RETURNS RECORD
-LANGUAGE INTERNAL
-STRICT VOLATILE
-AS 'pg_create_physical_replication_slot';
-
-CREATE OR REPLACE FUNCTION pg_create_logical_replication_slot(
-    IN slot_name name, IN plugin name,
-    IN temporary boolean DEFAULT false,
-    IN twophase boolean DEFAULT false,
-    IN failover boolean DEFAULT false,
-    OUT slot_name name, OUT lsn pg_lsn)
-RETURNS RECORD
-LANGUAGE INTERNAL
-STRICT VOLATILE
-AS 'pg_create_logical_replication_slot';
-
-CREATE OR REPLACE FUNCTION
-  make_interval(years int4 DEFAULT 0, months int4 DEFAULT 0, weeks int4 DEFAULT 0,
-                days int4 DEFAULT 0, hours int4 DEFAULT 0, mins int4 DEFAULT 0,
-                secs double precision DEFAULT 0.0)
-RETURNS interval
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'make_interval';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_set(jsonb_in jsonb, path text[] , replacement jsonb,
-            create_if_missing boolean DEFAULT true)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_set';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_set_lax(jsonb_in jsonb, path text[] , replacement jsonb,
-            create_if_missing boolean DEFAULT true,
-            null_value_treatment text DEFAULT 'use_json_null')
-RETURNS jsonb
-LANGUAGE INTERNAL
-CALLED ON NULL INPUT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_set_lax';
-
-CREATE OR REPLACE FUNCTION
-  parse_ident(str text, strict boolean DEFAULT true)
-RETURNS text[]
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'parse_ident';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_insert(jsonb_in jsonb, path text[] , replacement jsonb,
-            insert_after boolean DEFAULT false)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_insert';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_exists(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                    silent boolean DEFAULT false)
-RETURNS boolean
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_path_exists';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_match(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                   silent boolean DEFAULT false)
-RETURNS boolean
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_path_match';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_query(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                   silent boolean DEFAULT false)
-RETURNS SETOF jsonb
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_path_query';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_query_array(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                         silent boolean DEFAULT false)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_path_query_array';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_query_first(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                         silent boolean DEFAULT false)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_path_query_first';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_exists_tz(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                    silent boolean DEFAULT false)
-RETURNS boolean
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'jsonb_path_exists_tz';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_match_tz(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                   silent boolean DEFAULT false)
-RETURNS boolean
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'jsonb_path_match_tz';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_query_tz(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                   silent boolean DEFAULT false)
-RETURNS SETOF jsonb
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'jsonb_path_query_tz';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_query_array_tz(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                         silent boolean DEFAULT false)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'jsonb_path_query_array_tz';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_query_first_tz(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                         silent boolean DEFAULT false)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'jsonb_path_query_first_tz';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_strip_nulls(target jsonb, strip_in_arrays boolean DEFAULT false)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'jsonb_strip_nulls';
-
-CREATE OR REPLACE FUNCTION
-  json_strip_nulls(target json, strip_in_arrays boolean DEFAULT false)
-RETURNS json
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'json_strip_nulls';
-
--- default normalization form is NFC, per SQL standard
-CREATE OR REPLACE FUNCTION
-  "normalize"(text, text DEFAULT 'NFC')
-RETURNS text
-LANGUAGE internal
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'unicode_normalize_func';
-
-CREATE OR REPLACE FUNCTION
-  is_normalized(text, text DEFAULT 'NFC')
-RETURNS boolean
-LANGUAGE internal
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'unicode_is_normalized';
-
-CREATE OR REPLACE FUNCTION
-  pg_stat_reset_shared(target text DEFAULT NULL)
-RETURNS void
-LANGUAGE INTERNAL
-CALLED ON NULL INPUT VOLATILE PARALLEL SAFE
-AS 'pg_stat_reset_shared';
-
-CREATE OR REPLACE FUNCTION
-  pg_stat_reset_slru(target text DEFAULT NULL)
-RETURNS void
-LANGUAGE INTERNAL
-CALLED ON NULL INPUT VOLATILE PARALLEL SAFE
-AS 'pg_stat_reset_slru';
-
-CREATE OR REPLACE FUNCTION
-  pg_replication_origin_session_setup(node_name text, pid integer DEFAULT 0)
-RETURNS void
-LANGUAGE INTERNAL
-STRICT VOLATILE PARALLEL UNSAFE
-AS 'pg_replication_origin_session_setup';
-
 --
 -- The default permissions for functions mean that anyone can execute them.
 -- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 83f6501df38..dac40992cbc 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3499,6 +3499,7 @@
 { oid => '6212', descr => 'random value from normal distribution',
   proname => 'random_normal', provolatile => 'v', proparallel => 'r',
   prorettype => 'float8', proargtypes => 'float8 float8',
+  proargnames => '{mean,stddev}', proargdefaults => '{0,1}',
   prosrc => 'drandom_normal' },
 { oid => '6339', descr => 'random integer in range',
   proname => 'random', provolatile => 'v', proparallel => 'r',
@@ -6174,6 +6175,7 @@
   descr => 'statistics: reset collected statistics shared across the cluster',
   proname => 'pg_stat_reset_shared', proisstrict => 'f', provolatile => 'v',
   prorettype => 'void', proargtypes => 'text',
+  proargnames => '{target}', proargdefaults => '{NULL}',
   prosrc => 'pg_stat_reset_shared' },
 { oid => '3776',
   descr => 'statistics: reset collected statistics for a single table or index in the current database or shared across all databases in the cluster',
@@ -6193,6 +6195,7 @@
   descr => 'statistics: reset collected statistics for a single SLRU',
   proname => 'pg_stat_reset_slru', proisstrict => 'f', provolatile => 'v',
   prorettype => 'void', proargtypes => 'text', proargnames => '{target}',
+  proargdefaults => '{NULL}',
   prosrc => 'pg_stat_reset_slru' },
 { oid => '6170',
   descr => 'statistics: reset collected statistics for a single replication slot',
@@ -6728,20 +6731,24 @@
 { oid => '2096', descr => 'terminate a server process',
   proname => 'pg_terminate_backend', provolatile => 'v', prorettype => 'bool',
   proargtypes => 'int4 int8', proargnames => '{pid,timeout}',
+  proargdefaults => '{0}',
   prosrc => 'pg_terminate_backend' },
 { oid => '2172', descr => 'prepare for taking an online backup',
   proname => 'pg_backup_start', provolatile => 'v', proparallel => 'r',
   prorettype => 'pg_lsn', proargtypes => 'text bool',
+  proargnames => '{label,fast}', proargdefaults => '{false}',
   prosrc => 'pg_backup_start' },
 { oid => '2739', descr => 'finish taking an online backup',
   proname => 'pg_backup_stop', provolatile => 'v', proparallel => 'r',
   prorettype => 'record', proargtypes => 'bool',
   proallargtypes => '{bool,pg_lsn,text,text}', proargmodes => '{i,o,o,o}',
   proargnames => '{wait_for_archive,lsn,labelfile,spcmapfile}',
+  proargdefaults => '{true}',
   prosrc => 'pg_backup_stop' },
 { oid => '3436', descr => 'promote standby server',
   proname => 'pg_promote', provolatile => 'v', prorettype => 'bool',
   proargtypes => 'bool int4', proargnames => '{wait,wait_seconds}',
+  proargdefaults => '{true,60}',
   prosrc => 'pg_promote' },
 { oid => '2848', descr => 'switch to new wal file',
   proname => 'pg_switch_wal', provolatile => 'v', prorettype => 'pg_lsn',
@@ -7517,7 +7524,8 @@
 { oid => '1268',
   descr => 'parse qualified identifier to array of identifiers',
   proname => 'parse_ident', prorettype => '_text', proargtypes => 'text bool',
-  proargnames => '{str,strict}', prosrc => 'parse_ident' },
+  proargnames => '{str,strict}', proargdefaults => '{true}',
+  prosrc => 'parse_ident' },
 
 { oid => '2246', descr => '(internal)',
   proname => 'fmgr_internal_validator', provolatile => 's',
@@ -9423,7 +9431,9 @@
   proargtypes => 'anyelement', prosrc => 'to_json' },
 { oid => '3261', descr => 'remove object fields with null values from json',
   proname => 'json_strip_nulls', prorettype => 'json',
-  proargtypes => 'json bool', prosrc => 'json_strip_nulls' },
+  proargtypes => 'json bool',
+  proargnames => '{target,strip_in_arrays}', proargdefaults => '{false}',
+  prosrc => 'json_strip_nulls' },
 
 { oid => '3947',
   proname => 'json_object_field', prorettype => 'json',
@@ -9480,12 +9490,17 @@
 { oid => '3960', descr => 'get record fields from a json object',
   proname => 'json_populate_record', proisstrict => 'f', provolatile => 's',
   prorettype => 'anyelement', proargtypes => 'anyelement json bool',
+  proargnames => '{base,from_json,use_json_as_text}',
+  proargdefaults => '{false}',
   prosrc => 'json_populate_record' },
 { oid => '3961',
   descr => 'get set of records with fields from a json array of objects',
   proname => 'json_populate_recordset', prorows => '100', proisstrict => 'f',
   proretset => 't', provolatile => 's', prorettype => 'anyelement',
-  proargtypes => 'anyelement json bool', prosrc => 'json_populate_recordset' },
+  proargtypes => 'anyelement json bool',
+  proargnames => '{base,from_json,use_json_as_text}',
+  proargdefaults => '{false}',
+  prosrc => 'json_populate_recordset' },
 { oid => '3204', descr => 'get record fields from a json object',
   proname => 'json_to_record', provolatile => 's', prorettype => 'record',
   proargtypes => 'json', prosrc => 'json_to_record' },
@@ -10364,7 +10379,9 @@
   prosrc => 'jsonb_build_object_noargs' },
 { oid => '3262', descr => 'remove object fields with null values from jsonb',
   proname => 'jsonb_strip_nulls', prorettype => 'jsonb',
-  proargtypes => 'jsonb bool', prosrc => 'jsonb_strip_nulls' },
+  proargtypes => 'jsonb bool',
+  proargnames => '{target,strip_in_arrays}', proargdefaults => '{false}',
+  prosrc => 'jsonb_strip_nulls' },
 
 { oid => '3478',
   proname => 'jsonb_object_field', prorettype => 'jsonb',
@@ -10538,16 +10555,25 @@
   proargtypes => 'jsonb _text', prosrc => 'jsonb_delete_path' },
 { oid => '5054', descr => 'Set part of a jsonb, handle NULL value',
   proname => 'jsonb_set_lax', proisstrict => 'f', prorettype => 'jsonb',
-  proargtypes => 'jsonb _text jsonb bool text', prosrc => 'jsonb_set_lax' },
+  proargtypes => 'jsonb _text jsonb bool text',
+  proargnames => '{jsonb_in,path,replacement,create_if_missing,null_value_treatment}',
+  proargdefaults => '{true,use_json_null}',
+  prosrc => 'jsonb_set_lax' },
 { oid => '3305', descr => 'Set part of a jsonb',
   proname => 'jsonb_set', prorettype => 'jsonb',
-  proargtypes => 'jsonb _text jsonb bool', prosrc => 'jsonb_set' },
+  proargtypes => 'jsonb _text jsonb bool',
+  proargnames => '{jsonb_in,path,replacement,create_if_missing}',
+  proargdefaults => '{true}',
+  prosrc => 'jsonb_set' },
 { oid => '3306', descr => 'Indented text from jsonb',
   proname => 'jsonb_pretty', prorettype => 'text', proargtypes => 'jsonb',
   prosrc => 'jsonb_pretty' },
 { oid => '3579', descr => 'Insert value into a jsonb',
   proname => 'jsonb_insert', prorettype => 'jsonb',
-  proargtypes => 'jsonb _text jsonb bool', prosrc => 'jsonb_insert' },
+  proargtypes => 'jsonb _text jsonb bool',
+  proargnames => '{jsonb_in,path,replacement,insert_after}',
+  proargdefaults => '{false}',
+  prosrc => 'jsonb_insert' },
 
 # jsonpath
 { oid => '4001', descr => 'I/O',
@@ -10565,42 +10591,66 @@
 
 { oid => '4005', descr => 'jsonpath exists test',
   proname => 'jsonb_path_exists', prorettype => 'bool',
-  proargtypes => 'jsonb jsonpath jsonb bool', prosrc => 'jsonb_path_exists' },
+  proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
+  prosrc => 'jsonb_path_exists' },
 { oid => '4006', descr => 'jsonpath query',
   proname => 'jsonb_path_query', prorows => '1000', proretset => 't',
   prorettype => 'jsonb', proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
   prosrc => 'jsonb_path_query' },
 { oid => '4007', descr => 'jsonpath query wrapped into array',
   proname => 'jsonb_path_query_array', prorettype => 'jsonb',
   proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
   prosrc => 'jsonb_path_query_array' },
 { oid => '4008', descr => 'jsonpath query first item',
   proname => 'jsonb_path_query_first', prorettype => 'jsonb',
   proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
   prosrc => 'jsonb_path_query_first' },
 { oid => '4009', descr => 'jsonpath match',
   proname => 'jsonb_path_match', prorettype => 'bool',
-  proargtypes => 'jsonb jsonpath jsonb bool', prosrc => 'jsonb_path_match' },
+  proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
+  prosrc => 'jsonb_path_match' },
 
 { oid => '1177', descr => 'jsonpath exists test with timezone',
   proname => 'jsonb_path_exists_tz', provolatile => 's', prorettype => 'bool',
   proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
   prosrc => 'jsonb_path_exists_tz' },
 { oid => '1179', descr => 'jsonpath query with timezone',
   proname => 'jsonb_path_query_tz', prorows => '1000', proretset => 't',
   provolatile => 's', prorettype => 'jsonb',
-  proargtypes => 'jsonb jsonpath jsonb bool', prosrc => 'jsonb_path_query_tz' },
+  proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
+  prosrc => 'jsonb_path_query_tz' },
 { oid => '1180', descr => 'jsonpath query wrapped into array with timezone',
   proname => 'jsonb_path_query_array_tz', provolatile => 's',
   prorettype => 'jsonb', proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
   prosrc => 'jsonb_path_query_array_tz' },
 { oid => '2023', descr => 'jsonpath query first item with timezone',
   proname => 'jsonb_path_query_first_tz', provolatile => 's',
   prorettype => 'jsonb', proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
   prosrc => 'jsonb_path_query_first_tz' },
 { oid => '2030', descr => 'jsonpath match with timezone',
   proname => 'jsonb_path_match_tz', provolatile => 's', prorettype => 'bool',
-  proargtypes => 'jsonb jsonpath jsonb bool', prosrc => 'jsonb_path_match_tz' },
+  proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
+  prosrc => 'jsonb_path_match_tz' },
 
 { oid => '4010', descr => 'implementation of @? operator',
   proname => 'jsonb_path_exists_opr', prorettype => 'bool',
@@ -11411,6 +11461,7 @@
   proname => 'make_interval', prorettype => 'interval',
   proargtypes => 'int4 int4 int4 int4 int4 int4 float8',
   proargnames => '{years,months,weeks,days,hours,mins,secs}',
+  proargdefaults => '{0,0,0,0,0,0,0.0}',
   prosrc => 'make_interval' },
 
 # spgist opclasses
@@ -11511,6 +11562,7 @@
   proallargtypes => '{name,bool,bool,name,pg_lsn}',
   proargmodes => '{i,i,i,o,o}',
   proargnames => '{slot_name,immediately_reserve,temporary,slot_name,lsn}',
+  proargdefaults => '{false,false}',
   prosrc => 'pg_create_physical_replication_slot' },
 { oid => '4220',
   descr => 'copy a physical replication slot, changing temporality',
@@ -11546,6 +11598,7 @@
   proallargtypes => '{name,name,bool,bool,bool,name,pg_lsn}',
   proargmodes => '{i,i,i,i,i,o,o}',
   proargnames => '{slot_name,plugin,temporary,twophase,failover,slot_name,lsn}',
+  proargdefaults => '{false,false,false}',
   prosrc => 'pg_create_logical_replication_slot' },
 { oid => '4222',
   descr => 'copy a logical replication slot, changing temporality and plugin',
@@ -11578,6 +11631,7 @@
   proallargtypes => '{name,pg_lsn,int4,_text,pg_lsn,xid,text}',
   proargmodes => '{i,i,i,v,o,o,o}',
   proargnames => '{slot_name,upto_lsn,upto_nchanges,options,lsn,xid,data}',
+  proargdefaults => '{"{}"}',
   prosrc => 'pg_logical_slot_get_changes' },
 { oid => '3783', descr => 'get binary changes from replication slot',
   proname => 'pg_logical_slot_get_binary_changes', procost => '1000',
@@ -11587,6 +11641,7 @@
   proallargtypes => '{name,pg_lsn,int4,_text,pg_lsn,xid,bytea}',
   proargmodes => '{i,i,i,v,o,o,o}',
   proargnames => '{slot_name,upto_lsn,upto_nchanges,options,lsn,xid,data}',
+  proargdefaults => '{"{}"}',
   prosrc => 'pg_logical_slot_get_binary_changes' },
 { oid => '3784', descr => 'peek at changes from replication slot',
   proname => 'pg_logical_slot_peek_changes', procost => '1000',
@@ -11596,6 +11651,7 @@
   proallargtypes => '{name,pg_lsn,int4,_text,pg_lsn,xid,text}',
   proargmodes => '{i,i,i,v,o,o,o}',
   proargnames => '{slot_name,upto_lsn,upto_nchanges,options,lsn,xid,data}',
+  proargdefaults => '{"{}"}',
   prosrc => 'pg_logical_slot_peek_changes' },
 { oid => '3785', descr => 'peek at binary changes from replication slot',
   proname => 'pg_logical_slot_peek_binary_changes', procost => '1000',
@@ -11605,6 +11661,7 @@
   proallargtypes => '{name,pg_lsn,int4,_text,pg_lsn,xid,bytea}',
   proargmodes => '{i,i,i,v,o,o,o}',
   proargnames => '{slot_name,upto_lsn,upto_nchanges,options,lsn,xid,data}',
+  proargdefaults => '{"{}"}',
   prosrc => 'pg_logical_slot_peek_binary_changes' },
 { oid => '3878', descr => 'advance logical replication slot',
   proname => 'pg_replication_slot_advance', provolatile => 'v',
@@ -11615,10 +11672,14 @@
 { oid => '3577', descr => 'emit a textual logical decoding message',
   proname => 'pg_logical_emit_message', provolatile => 'v', proparallel => 'u',
   prorettype => 'pg_lsn', proargtypes => 'bool text text bool',
+  proargnames => '{transactional,prefix,message,flush}',
+  proargdefaults => '{false}',
   prosrc => 'pg_logical_emit_message_text' },
 { oid => '3578', descr => 'emit a binary logical decoding message',
   proname => 'pg_logical_emit_message', provolatile => 'v', proparallel => 'u',
   prorettype => 'pg_lsn', proargtypes => 'bool text bytea bool',
+  proargnames => '{transactional,prefix,message,flush}',
+  proargdefaults => '{false}',
   prosrc => 'pg_logical_emit_message_bytea' },
 { oid => '6344',
   descr => 'sync replication slots from the primary to the standby',
@@ -12268,6 +12329,7 @@
   descr => 'configure session to maintain replication progress tracking for the passed in origin',
   proname => 'pg_replication_origin_session_setup', provolatile => 'v',
   proparallel => 'u', prorettype => 'void', proargtypes => 'text int4',
+  proargnames => '{node_name,pid}', proargdefaults => '{0}',
   prosrc => 'pg_replication_origin_session_setup' },
 
 { oid => '6007', descr => 'teardown configured replication progress tracking',
@@ -12518,10 +12580,12 @@
 
 { oid => '4350', descr => 'Unicode normalization',
   proname => 'normalize', prorettype => 'text', proargtypes => 'text text',
+  proargdefaults => '{NFC}',
   prosrc => 'unicode_normalize_func' },
 
 { oid => '4351', descr => 'check Unicode normalization',
   proname => 'is_normalized', prorettype => 'bool', proargtypes => 'text text',
+  proargdefaults => '{NFC}',
   prosrc => 'unicode_is_normalized' },
 
 { oid => '6198', descr => 'unescape Unicode characters',

Re: generating function default settings from pg_proc.dat

От:
Corey Huinker <corey.huinker@gmail.com>
Дата:


On Tue, Feb 17, 2026 at 1:37 AM Álvaro Herrera <alvherre@kurilemu.de> wrote:
On 2026-Feb-16, Andres Freund wrote:

> could be
>
> { oid => '3786', descr => 'set up a logical replication slot',
>   proname => 'pg_create_logical_replication_slot', provolatile => 'v',
>   proparallel => 'u',
>   proargs => [
>      {type => 'name', name => 'slot_name'},
>      {type => 'name', name => 'plugin'},
>      {type => 'bool', name => 'temporary', default => 'false'},
>      {type => 'bool', name => 'twophase', default => 'false'},
>      {type => 'bool', name => 'failover', default => 'false'},
>   ],
>   prorettype => [
>      {type => 'name', name => 'slot_name'},
>      {type => 'pg_lsn', name => 'lsn'},
>   ]
> }

This is pretty much the sort of thing I was imagining when I read
Corey's argumentation.  +1 for something along these lines.

I like this a lot too, but I'm noticing that with each iteration we're getting closer to re-inventing SQL. Would it make sense in the long run to have a mode on the CREATE FUNCTION command that cues initdb to create the minimal function skeleton with prescribed oid on the first pass, but then stores the defer-able parts (if any) for a later pass, perhaps in parallel? Then we wouldn't have to worry about how to model all future additions to CREATE FUNCTION, and instead focus on what parts of creating the function need to be in the bootstrap pass.

Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Corey Huinker  writes:
> I like this a lot too, but I'm noticing that with each iteration we're
> getting closer to re-inventing SQL.

Really?  Neither pg_proc.dat nor the constructed postgres.bki file
look anything like SQL to my eye.

> Would it make sense in the long run to
> have a mode on the CREATE FUNCTION command that cues initdb to create the
> minimal function skeleton with prescribed oid on the first pass, but then
> stores the defer-able parts (if any) for a later pass, perhaps in parallel?

I seriously, seriously doubt it.  That would involve allowing large
amounts of the parser to run in bootstrap mode, and would probably
end in plastering warts all over backend/parser/ to say "do this
in one way normally but some other way in bootstrap".  Also, it's
really just syntactic sugar and does nothing for the harder problems
that bootstrap mode has to solve, such as supporting references to
objects that've not been created yet.

			regards, tom lane


Re: generating function default settings from pg_proc.dat

От:
Andres Freund <andres@anarazel.de>
Дата:
Hi,

On 2026-02-16 20:36:25 -0500, Tom Lane wrote:
> Here is a draft patch along those lines.  I've verified that
> the initial contents of pg_proc are exactly as before,
> except that json[b]_strip_nulls gain the correct provolatile
> value, and a few proargdefaults entries no longer involve
> cast functions.

Nice.


> @@ -817,8 +832,10 @@ $ perl  rewrite_dat_with_prokind.pl  pg_proc.dat
>        The following column types are supported directly by
>        bootstrap.c: bool,
>        bytea, char (1 byte),
> -      name, int2,
> -      int4, regproc, regclass,
> +      int2, int4, int8,
> +      float4, float8,
> +      name,
> +      regproc, regclass,
>        regtype, text,
>        oid, tid, xid,
>        cid, int2vector, oidvector,

Don't you also add jsonb support below?


> +	/*
> +	 * pg_node_tree values can't be inserted normally (pg_node_tree_in would
> +	 * just error out), so provide special cases for such columns that we
> +	 * would like to fill during bootstrap.
> +	 */
> +	if (typoid == PG_NODE_TREEOID)
> +	{
> +		/* pg_proc.proargdefaults */
> +		if (RelationGetRelid(boot_reldesc) == ProcedureRelationId &&
> +			i == Anum_pg_proc_proargdefaults - 1)
> +			values[i] = ConvertOneProargdefaultsValue(value);
> +		else					/* maybe other cases later */
> +			elog(ERROR, "can't handle pg_node_tree input");

Perhaps add the relid to the ERROR?


> +/* ----------------
> + *		ConvertOneProargdefaultsValue
> + *
> + * In general, proargdefaults can be a list of any expressions, but
> + * for bootstrap we only support a list of Const nodes.  The input
> + * has the form of a text array, and we feed non-null elements to the
> + * typinput functions for the appropriate parameters.
> + * ----------------
> + */
> +static Datum
> +ConvertOneProargdefaultsValue(char *value)
> +{
> +	int			pronargs;
> +	oidvector  *proargtypes;
> +	Datum		arrayval;
> +	Datum	   *array_datums;
> +	bool	   *array_nulls;
> +	int			array_count;
> +	List	   *proargdefaults;
> +
> +	/* The pg_proc columns we need to use must have been filled already */
> +	StaticAssertDecl(Anum_pg_proc_pronargs < Anum_pg_proc_proargdefaults,
> +					 "pronargs must come before proargdefaults");
> +	StaticAssertDecl(Anum_pg_proc_pronargdefaults < Anum_pg_proc_proargdefaults,
> +					 "pronargdefaults must come before proargdefaults");
> +	StaticAssertDecl(Anum_pg_proc_proargtypes < Anum_pg_proc_proargdefaults,
> +					 "proargtypes must come before proargdefaults");
> +	if (Nulls[Anum_pg_proc_pronargs - 1])
> +		elog(ERROR, "pronargs must not be null");
> +	if (Nulls[Anum_pg_proc_proargtypes - 1])
> +		elog(ERROR, "proargtypes must not be null");
> +	pronargs = DatumGetInt16(values[Anum_pg_proc_pronargs - 1]);
> +	proargtypes = DatumGetPointer(values[Anum_pg_proc_proargtypes - 1]);
> +	Assert(pronargs == proargtypes->dim1);
> +
> +	/* Parse the input string as a text[] value, then deconstruct to Datums */
> +	arrayval = OidFunctionCall3(F_ARRAY_IN,
> +								CStringGetDatum(value),
> +								ObjectIdGetDatum(TEXTOID),
> +								Int32GetDatum(-1));
>
> +	deconstruct_array_builtin(DatumGetArrayTypeP(arrayval), TEXTOID,
> +							  &array_datums, &array_nulls, &array_count);

If we convert to cstring below anyway, why not make it a cstring array?


> +	/* The values should correspond to the last N argtypes */
> +	if (array_count > pronargs)
> +		elog(ERROR, "too many proargdefaults entries");
> +
> +	/* Build the List of Const nodes */
> +	proargdefaults = NIL;
> +	for (int i = 0; i < array_count; i++)
> +	{
> +		Oid			argtype = proargtypes->values[pronargs - array_count + i];
> +		int16		typlen;
> +		bool		typbyval;
> +		char		typalign;
> +		char		typdelim;
> +		Oid			typioparam;
> +		Oid			typinput;
> +		Oid			typoutput;
> +		Oid			typcollation;
> +		Datum		defval;
> +		bool		defnull;
> +		Const	   *defConst;
> +
> +		boot_get_type_io_data(argtype,
> +							  &typlen, &typbyval, &typalign,
> +							  &typdelim, &typioparam,
> +							  &typinput, &typoutput);
> +		typcollation = boot_get_typcollation(argtype);
> +		defnull = array_nulls[i];
> +		if (defnull)
> +			defval = (Datum) 0;
> +		else
> +		{
> +			char	   *defstr = text_to_cstring(DatumGetTextPP(array_datums[i]));
> +
> +			defval = OidInputFunctionCall(typinput, defstr, typioparam, -1);
> +		}
> +
> +		defConst = makeConst(argtype,
> +							 -1,	/* never any typmod */
> +							 typcollation,
> +							 typlen,
> +							 defval,
> +							 defnull,
> +							 typbyval);
> +		proargdefaults = lappend(proargdefaults, defConst);
> +	}
> +
> +	/*
> +	 * Hack: fill in pronargdefaults with the right value.  This is surely
> +	 * ugly, but it beats making the programmer do it.
> +	 */
> +	values[Anum_pg_proc_pronargdefaults - 1] = Int16GetDatum(array_count);
> +	Nulls[Anum_pg_proc_pronargdefaults - 1] = false;

I don't mind the hack, but I wonder about it location. It's odd that the
caller puts the return value of ConvertOneProargdefaultsValue() into the
values array, but then ConvertOneProargdefaultsValue() also sets
pronargdefaults?


> +/* ----------------
> + *		boot_get_typcollation
> + *
> + * Obtain type's collation at bootstrap time.  This intentionally has
> + * the same API as lsyscache.c's get_typcollation.
> + *
> + * XXX would it be better to add another output to boot_get_type_io_data?

Yes, it seems like it would? There aren't many callers for it...


Greetings,

Andres Freund


Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Andres Freund  writes:
> If we convert to cstring below anyway, why not make it a cstring array?

Ha, I'd forgotten that cstring[] is a thing.  Yup, that'd save one
step.

> I don't mind the hack, but I wonder about it location. It's odd that the
> caller puts the return value of ConvertOneProargdefaultsValue() into the
> values array, but then ConvertOneProargdefaultsValue() also sets
> pronargdefaults?

Yeah, I'd gone back and forth about whether this function ought to
return the converted datum or just shove it into values[] directly.
Given that it's also filling the pronargdefaults entry, it probably
should take the latter approach.

I'll post a v2 in a bit.  Thanks for reviewing!

			regards, tom lane


Re: generating function default settings from pg_proc.dat

От:
Corey Huinker <corey.huinker@gmail.com>
Дата:
On Tue, Feb 17, 2026 at 10:00 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Corey Huinker <corey.huinker@gmail.com> writes:
> I like this a lot too, but I'm noticing that with each iteration we're
> getting closer to re-inventing SQL.

Really?  Neither pg_proc.dat nor the constructed postgres.bki file
look anything like SQL to my eye.

It doesn't _look_ like SQL, but we're trying to cover all things that a CREATE FUNCTION can do, and if we don't model them all, then we're back to needing CREATE OR REPLACE overlays.
 
> Would it make sense in the long run to
> have a mode on the CREATE FUNCTION command that cues initdb to create the
> minimal function skeleton with prescribed oid on the first pass, but then
> stores the defer-able parts (if any) for a later pass, perhaps in parallel?

I seriously, seriously doubt it.  That would involve allowing large
amounts of the parser to run in bootstrap mode, and would probably
end in plastering warts all over backend/parser/ to say "do this
in one way normally but some other way in bootstrap".  Also, it's
really just syntactic sugar and does nothing for the harder problems
that bootstrap mode has to solve, such as supporting references to
objects that've not been created yet.

Fair enough. But in the interest of keeping a single source of truth, what if we reversed the process, having a build-time perl script parse system_functions.sql to build a minimal pg_proc.dat-like file just for bootstrap? We would probably want to break up system_functions.sql into several files, (admin functions go here, adt-related functions go there, etc), but we'd have total clarity on all function definitions, and we wouldn't have to modify the generation of pg_proc.dat unless a new function syntax feature affected bootstrapping.

Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Here's the promised v2, which addresses all your review comments.

With respect to the list of supported types in bki.sgml: I wonder if
we should just drop that, because it evidently hasn't been maintained
well.  It wasn't at all in sync with the actual contents of TypInfo[].
I made it be so, but ...

Poking further at that, I found that there were a lot of TypInfo[]
entries that were not actually used and seem to have just been
cargo-culted in.  So this patch removes all the ones that aren't
demonstrably necessary to get through initdb.  Maybe that's too
aggressive, but in view of the potential for maintenance errors
(cf 7cdb633c8) I don't think we should be carrying unused entries
there.

			regards, tom lane

From fa818e3fa7c74019c2b6ffc3a0050db719581852 Mon Sep 17 00:00:00 2001
From: Tom Lane 
Date: Tue, 17 Feb 2026 13:31:56 -0500
Subject: [PATCH v2] Simplify creation of built-in functions with default
 arguments.

Up to now, to create such a function, one had to make a pg_proc.dat
entry and then overwrite it with a CREATE OR REPLACE command in
system_functions.sql.  That's error-prone (cf. bug #19409) and
results in leaving dead rows in the initial contents of pg_proc.

Manual maintenance of pg_node_tree strings seems entirely impractical,
and parsing expressions during bootstrap would be extremely difficult
as well.  But Andres Freund observed that all the current use-cases
are simple constants, and building a Const node is well within the
capabilities of bootstrap mode.  So this patch invents a special case:
if bootstrap mode is asked to ingest a non-null value for
pg_proc.proargdefaults (which would otherwise fail in
pg_node_tree_in), it parses the value as an array literal and then
feeds the element strings to the input functions for the corresponding
parameter types.  Then we can build a suitable pg_node_tree string
with just a few more lines of code.

This allows removing all the system_functions.sql entries that are
just there to set up default arguments, replacing them with
proargdefaults fields in pg_proc.dat entries.  The old technique
remains available in case someone needs a non-constant default.

The initial contents of pg_proc are demonstrably the same after
this patch, except that (1) json_strip_nulls and jsonb_strip_nulls
now have the correct provolatile setting, as per bug #19409;
(2) pg_terminate_backend, make_interval, and drandom_normal
now have defaults that don't include a type coercion, which is
how they should have been all along.

Author: Tom Lane 
Author: Andrew Dunstan 
Reviewed-by: Andres Freund 
Discussion: https://postgr.es/m/183292bb-4891-4c96-a3ca-e78b5e0e1358@dunslane.net
---
 doc/src/sgml/bki.sgml                    |  34 ++-
 src/backend/bootstrap/bootstrap.c        | 177 ++++++++++++--
 src/backend/catalog/system_functions.sql | 285 +----------------------
 src/backend/utils/cache/lsyscache.c      |   4 +-
 src/include/bootstrap/bootstrap.h        |   3 +-
 src/include/catalog/pg_proc.dat          |  86 ++++++-
 6 files changed, 262 insertions(+), 327 deletions(-)

diff --git a/doc/src/sgml/bki.sgml b/doc/src/sgml/bki.sgml
index 53a982bf60d..087a6827b00 100644
--- a/doc/src/sgml/bki.sgml
+++ b/doc/src/sgml/bki.sgml
@@ -271,6 +271,21 @@
      
     
 
+    
+     
+      There is a special case for values of the
+      pg_proc.proargdefaults
+      field, which is of type pg_node_tree.  The real
+      contents of that type are too complex for hand-written entries,
+      but what we need for proargdefaults is
+      typically just a list of Const nodes.  Therefore, the bootstrap
+      backend will interpret a value given for that field according to
+      text array syntax, and then feed the array element values to the
+      datatype input routines for the corresponding input parameters' data
+      types, and finally build Const nodes from the datums.
+     
+    
+
     
      
       Since hashes are unordered data structures, field order and line
@@ -817,11 +832,11 @@ $ perl  rewrite_dat_with_prokind.pl  pg_proc.dat
       The following column types are supported directly by
       bootstrap.c: bool,
       bytea, char (1 byte),
-      name, int2,
-      int4, regproc, regclass,
-      regtype, text,
-      oid, tid, xid,
-      cid, int2vector, oidvector,
+      int2, int4, int8,
+      float4, float8,
+      name, regproc, text,
+      jsonb, oid, pg_node_tree,
+      int2vector, oidvector,
       _int4 (array), _text (array),
       _oid (array), _char (array),
       _aclitem (array).  Although it is possible to create
@@ -884,7 +899,7 @@ $ perl  rewrite_dat_with_prokind.pl  pg_proc.dat
 
    
     
-     insert ( oid_value value1 value2 ... )
+     insert ( value1 value2 ... )
     
 
     
@@ -902,6 +917,13 @@ $ perl  rewrite_dat_with_prokind.pl  pg_proc.dat
       (To include a single quote in a value, write it twice.
       Escape-string-style backslash escapes are allowed in the string, too.)
      
+
+     
+      In most cases a value
+      string is simply fed to the datatype input routine for the column's
+      data type, after de-quoting if needed.  However there are exceptions
+      for certain fields, as detailed previously.
+     
     
    
 
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 7d32cd0e159..8d601c363b4 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -26,6 +26,7 @@
 #include "bootstrap/bootstrap.h"
 #include "catalog/index.h"
 #include "catalog/pg_collation.h"
+#include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "common/link-canary.h"
 #include "miscadmin.h"
@@ -46,6 +47,7 @@
 static void CheckerModeMain(void);
 static void bootstrap_signals(void);
 static Form_pg_attribute AllocateAttribute(void);
+static void InsertOneProargdefaultsValue(char *value);
 static void populate_typ_list(void);
 static Oid	gettype(char *type);
 static void cleanup(void);
@@ -91,38 +93,28 @@ static const struct typinfo TypInfo[] = {
 	F_BYTEAIN, F_BYTEAOUT},
 	{"char", CHAROID, 0, 1, true, TYPALIGN_CHAR, TYPSTORAGE_PLAIN, InvalidOid,
 	F_CHARIN, F_CHAROUT},
+	{"cstring", CSTRINGOID, 0, -2, false, TYPALIGN_CHAR, TYPSTORAGE_PLAIN, InvalidOid,
+	F_CSTRING_IN, F_CSTRING_OUT},
 	{"int2", INT2OID, 0, 2, true, TYPALIGN_SHORT, TYPSTORAGE_PLAIN, InvalidOid,
 	F_INT2IN, F_INT2OUT},
 	{"int4", INT4OID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
 	F_INT4IN, F_INT4OUT},
+	{"int8", INT8OID, 0, 8, true, TYPALIGN_DOUBLE, TYPSTORAGE_PLAIN, InvalidOid,
+	F_INT8IN, F_INT8OUT},
 	{"float4", FLOAT4OID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
 	F_FLOAT4IN, F_FLOAT4OUT},
+	{"float8", FLOAT8OID, 0, 8, true, TYPALIGN_DOUBLE, TYPSTORAGE_PLAIN, InvalidOid,
+	F_FLOAT8IN, F_FLOAT8OUT},
 	{"name", NAMEOID, CHAROID, NAMEDATALEN, false, TYPALIGN_CHAR, TYPSTORAGE_PLAIN, C_COLLATION_OID,
 	F_NAMEIN, F_NAMEOUT},
-	{"regclass", REGCLASSOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
-	F_REGCLASSIN, F_REGCLASSOUT},
 	{"regproc", REGPROCOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
 	F_REGPROCIN, F_REGPROCOUT},
-	{"regtype", REGTYPEOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
-	F_REGTYPEIN, F_REGTYPEOUT},
-	{"regrole", REGROLEOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
-	F_REGROLEIN, F_REGROLEOUT},
-	{"regnamespace", REGNAMESPACEOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
-	F_REGNAMESPACEIN, F_REGNAMESPACEOUT},
-	{"regdatabase", REGDATABASEOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
-	F_REGDATABASEIN, F_REGDATABASEOUT},
 	{"text", TEXTOID, 0, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, DEFAULT_COLLATION_OID,
 	F_TEXTIN, F_TEXTOUT},
+	{"jsonb", JSONBOID, 0, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
+	F_JSONB_IN, F_JSONB_OUT},
 	{"oid", OIDOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
 	F_OIDIN, F_OIDOUT},
-	{"oid8", OID8OID, 0, 8, true, TYPALIGN_DOUBLE, TYPSTORAGE_PLAIN, InvalidOid,
-	F_OID8IN, F_OID8OUT},
-	{"tid", TIDOID, 0, 6, false, TYPALIGN_SHORT, TYPSTORAGE_PLAIN, InvalidOid,
-	F_TIDIN, F_TIDOUT},
-	{"xid", XIDOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
-	F_XIDIN, F_XIDOUT},
-	{"cid", CIDOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
-	F_CIDIN, F_CIDOUT},
 	{"pg_node_tree", PG_NODE_TREEOID, 0, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, DEFAULT_COLLATION_OID,
 	F_PG_NODE_TREE_IN, F_PG_NODE_TREE_OUT},
 	{"int2vector", INT2VECTOROID, INT2OID, -1, false, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
@@ -660,6 +652,7 @@ InsertOneTuple(void)
 void
 InsertOneValue(char *value, int i)
 {
+	Form_pg_attribute attr;
 	Oid			typoid;
 	int16		typlen;
 	bool		typbyval;
@@ -668,19 +661,42 @@ InsertOneValue(char *value, int i)
 	Oid			typioparam;
 	Oid			typinput;
 	Oid			typoutput;
+	Oid			typcollation;
 
 	Assert(i >= 0 && i < MAXATTR);
 
 	elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
 
-	typoid = TupleDescAttr(boot_reldesc->rd_att, i)->atttypid;
+	attr = TupleDescAttr(RelationGetDescr(boot_reldesc), i);
+	typoid = attr->atttypid;
 
 	boot_get_type_io_data(typoid,
 						  &typlen, &typbyval, &typalign,
 						  &typdelim, &typioparam,
-						  &typinput, &typoutput);
+						  &typinput, &typoutput,
+						  &typcollation);
 
-	values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
+	/*
+	 * pg_node_tree values can't be inserted normally (pg_node_tree_in would
+	 * just error out), so provide special cases for such columns that we
+	 * would like to fill during bootstrap.
+	 */
+	if (typoid == PG_NODE_TREEOID)
+	{
+		/* pg_proc.proargdefaults */
+		if (RelationGetRelid(boot_reldesc) == ProcedureRelationId &&
+			i == Anum_pg_proc_proargdefaults - 1)
+			InsertOneProargdefaultsValue(value);
+		else					/* maybe other cases later */
+			elog(ERROR, "can't handle pg_node_tree input for %s.%s",
+				 RelationGetRelationName(boot_reldesc),
+				 NameStr(attr->attname));
+	}
+	else
+	{
+		/* Normal case */
+		values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
+	}
 
 	/*
 	 * We use ereport not elog here so that parameters aren't evaluated unless
@@ -691,6 +707,111 @@ InsertOneValue(char *value, int i)
 							 OidOutputFunctionCall(typoutput, values[i]))));
 }
 
+/* ----------------
+ *		InsertOneProargdefaultsValue
+ *
+ * In general, proargdefaults can be a list of any expressions, but
+ * for bootstrap we only support a list of Const nodes.  The input
+ * has the form of a text array, and we feed non-null elements to the
+ * typinput functions for the appropriate parameters.
+ * ----------------
+ */
+static void
+InsertOneProargdefaultsValue(char *value)
+{
+	int			pronargs;
+	oidvector  *proargtypes;
+	Datum		arrayval;
+	Datum	   *array_datums;
+	bool	   *array_nulls;
+	int			array_count;
+	List	   *proargdefaults;
+	char	   *nodestring;
+
+	/* The pg_proc columns we need to use must have been filled already */
+	StaticAssertDecl(Anum_pg_proc_pronargs < Anum_pg_proc_proargdefaults,
+					 "pronargs must come before proargdefaults");
+	StaticAssertDecl(Anum_pg_proc_pronargdefaults < Anum_pg_proc_proargdefaults,
+					 "pronargdefaults must come before proargdefaults");
+	StaticAssertDecl(Anum_pg_proc_proargtypes < Anum_pg_proc_proargdefaults,
+					 "proargtypes must come before proargdefaults");
+	if (Nulls[Anum_pg_proc_pronargs - 1])
+		elog(ERROR, "pronargs must not be null");
+	if (Nulls[Anum_pg_proc_proargtypes - 1])
+		elog(ERROR, "proargtypes must not be null");
+	pronargs = DatumGetInt16(values[Anum_pg_proc_pronargs - 1]);
+	proargtypes = DatumGetPointer(values[Anum_pg_proc_proargtypes - 1]);
+	Assert(pronargs == proargtypes->dim1);
+
+	/* Parse the input string as an array value, then deconstruct to Datums */
+	arrayval = OidFunctionCall3(F_ARRAY_IN,
+								CStringGetDatum(value),
+								ObjectIdGetDatum(CSTRINGOID),
+								Int32GetDatum(-1));
+	deconstruct_array_builtin(DatumGetArrayTypeP(arrayval), CSTRINGOID,
+							  &array_datums, &array_nulls, &array_count);
+
+	/* The values should correspond to the last N argtypes */
+	if (array_count > pronargs)
+		elog(ERROR, "too many proargdefaults entries");
+
+	/* Build the List of Const nodes */
+	proargdefaults = NIL;
+	for (int i = 0; i < array_count; i++)
+	{
+		Oid			argtype = proargtypes->values[pronargs - array_count + i];
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		char		typdelim;
+		Oid			typioparam;
+		Oid			typinput;
+		Oid			typoutput;
+		Oid			typcollation;
+		Datum		defval;
+		bool		defnull;
+		Const	   *defConst;
+
+		boot_get_type_io_data(argtype,
+							  &typlen, &typbyval, &typalign,
+							  &typdelim, &typioparam,
+							  &typinput, &typoutput,
+							  &typcollation);
+
+		defnull = array_nulls[i];
+		if (defnull)
+			defval = (Datum) 0;
+		else
+			defval = OidInputFunctionCall(typinput,
+										  DatumGetCString(array_datums[i]),
+										  typioparam, -1);
+
+		defConst = makeConst(argtype,
+							 -1,	/* never any typmod */
+							 typcollation,
+							 typlen,
+							 defval,
+							 defnull,
+							 typbyval);
+		proargdefaults = lappend(proargdefaults, defConst);
+	}
+
+	/*
+	 * Flatten the List to a node-tree string, then convert to a text datum,
+	 * which is the storage representation of pg_node_tree.
+	 */
+	nodestring = nodeToString(proargdefaults);
+	values[Anum_pg_proc_proargdefaults - 1] = CStringGetTextDatum(nodestring);
+	Nulls[Anum_pg_proc_proargdefaults - 1] = false;
+
+	/*
+	 * Hack: fill in pronargdefaults with the right value.  This is surely
+	 * ugly, but it beats making the programmer do it.
+	 */
+	values[Anum_pg_proc_pronargdefaults - 1] = Int16GetDatum(array_count);
+	Nulls[Anum_pg_proc_pronargdefaults - 1] = false;
+}
+
 /* ----------------
  *		InsertOneNull
  * ----------------
@@ -831,10 +952,11 @@ gettype(char *type)
  *		boot_get_type_io_data
  *
  * Obtain type I/O information at bootstrap time.  This intentionally has
- * almost the same API as lsyscache.c's get_type_io_data, except that
+ * an API very close to that of lsyscache.c's get_type_io_data, except that
  * we only support obtaining the typinput and typoutput routines, not
- * the binary I/O routines.  It is exported so that array_in and array_out
- * can be made to work during early bootstrap.
+ * the binary I/O routines, and we also return the type's collation.
+ * This is exported so that array_in and array_out can be made to work
+ * during early bootstrap.
  * ----------------
  */
 void
@@ -845,7 +967,8 @@ boot_get_type_io_data(Oid typid,
 					  char *typdelim,
 					  Oid *typioparam,
 					  Oid *typinput,
-					  Oid *typoutput)
+					  Oid *typoutput,
+					  Oid *typcollation)
 {
 	if (Typ != NIL)
 	{
@@ -876,6 +999,8 @@ boot_get_type_io_data(Oid typid,
 
 		*typinput = ap->am_typ.typinput;
 		*typoutput = ap->am_typ.typoutput;
+
+		*typcollation = ap->am_typ.typcollation;
 	}
 	else
 	{
@@ -904,6 +1029,8 @@ boot_get_type_io_data(Oid typid,
 
 		*typinput = TypInfo[typeindex].inproc;
 		*typoutput = TypInfo[typeindex].outproc;
+
+		*typcollation = TypInfo[typeindex].collation;
 	}
 }
 
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index eb9e31ae1bf..4e24d6b55fa 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -7,7 +7,8 @@
  *
  * This file redefines certain built-in functions that are impractical
  * to fully define in pg_proc.dat.  In most cases that's because they use
- * SQL-standard function bodies and/or default expressions.  The node
+ * SQL-standard function bodies and/or default expressions.  (But defaults
+ * that are just constants can be entered in pg_proc.dat.)  The node
  * tree representations of those are too unreadable, platform-dependent,
  * and changeable to want to deal with them manually.  Hence, we put stub
  * definitions of such functions into pg_proc.dat and then replace them
@@ -66,13 +67,6 @@ CREATE OR REPLACE FUNCTION bit_length(text)
  IMMUTABLE PARALLEL SAFE STRICT COST 1
 RETURN octet_length($1) * 8;
 
-CREATE OR REPLACE FUNCTION
- random_normal(mean float8 DEFAULT 0, stddev float8 DEFAULT 1)
- RETURNS float8
- LANGUAGE internal
- VOLATILE PARALLEL RESTRICTED STRICT COST 1
-AS 'drandom_normal';
-
 CREATE OR REPLACE FUNCTION log(numeric)
  RETURNS numeric
  LANGUAGE sql
@@ -382,281 +376,6 @@ CREATE OR REPLACE FUNCTION ts_debug(document text,
 BEGIN ATOMIC
     SELECT * FROM ts_debug(get_current_ts_config(), $1);
 END;
-
-CREATE OR REPLACE FUNCTION
-  pg_backup_start(label text, fast boolean DEFAULT false)
-  RETURNS pg_lsn STRICT VOLATILE LANGUAGE internal AS 'pg_backup_start'
-  PARALLEL RESTRICTED;
-
-CREATE OR REPLACE FUNCTION pg_backup_stop (
-        wait_for_archive boolean DEFAULT true, OUT lsn pg_lsn,
-        OUT labelfile text, OUT spcmapfile text)
-  RETURNS record STRICT VOLATILE LANGUAGE internal as 'pg_backup_stop'
-  PARALLEL RESTRICTED;
-
-CREATE OR REPLACE FUNCTION
-  pg_promote(wait boolean DEFAULT true, wait_seconds integer DEFAULT 60)
-  RETURNS boolean STRICT VOLATILE LANGUAGE INTERNAL AS 'pg_promote'
-  PARALLEL SAFE;
-
-CREATE OR REPLACE FUNCTION
-  pg_terminate_backend(pid integer, timeout int8 DEFAULT 0)
-  RETURNS boolean STRICT VOLATILE LANGUAGE INTERNAL AS 'pg_terminate_backend'
-  PARALLEL SAFE;
-
--- legacy definition for compatibility with 9.3
-CREATE OR REPLACE FUNCTION
-  json_populate_record(base anyelement, from_json json, use_json_as_text boolean DEFAULT false)
-  RETURNS anyelement LANGUAGE internal STABLE AS 'json_populate_record' PARALLEL SAFE;
-
--- legacy definition for compatibility with 9.3
-CREATE OR REPLACE FUNCTION
-  json_populate_recordset(base anyelement, from_json json, use_json_as_text boolean DEFAULT false)
-  RETURNS SETOF anyelement LANGUAGE internal STABLE ROWS 100  AS 'json_populate_recordset' PARALLEL SAFE;
-
-CREATE OR REPLACE FUNCTION pg_logical_slot_get_changes(
-    IN slot_name name, IN upto_lsn pg_lsn, IN upto_nchanges int, VARIADIC options text[] DEFAULT '{}',
-    OUT lsn pg_lsn, OUT xid xid, OUT data text)
-RETURNS SETOF RECORD
-LANGUAGE INTERNAL
-VOLATILE ROWS 1000 COST 1000
-AS 'pg_logical_slot_get_changes';
-
-CREATE OR REPLACE FUNCTION pg_logical_slot_peek_changes(
-    IN slot_name name, IN upto_lsn pg_lsn, IN upto_nchanges int, VARIADIC options text[] DEFAULT '{}',
-    OUT lsn pg_lsn, OUT xid xid, OUT data text)
-RETURNS SETOF RECORD
-LANGUAGE INTERNAL
-VOLATILE ROWS 1000 COST 1000
-AS 'pg_logical_slot_peek_changes';
-
-CREATE OR REPLACE FUNCTION pg_logical_slot_get_binary_changes(
-    IN slot_name name, IN upto_lsn pg_lsn, IN upto_nchanges int, VARIADIC options text[] DEFAULT '{}',
-    OUT lsn pg_lsn, OUT xid xid, OUT data bytea)
-RETURNS SETOF RECORD
-LANGUAGE INTERNAL
-VOLATILE ROWS 1000 COST 1000
-AS 'pg_logical_slot_get_binary_changes';
-
-CREATE OR REPLACE FUNCTION pg_logical_slot_peek_binary_changes(
-    IN slot_name name, IN upto_lsn pg_lsn, IN upto_nchanges int, VARIADIC options text[] DEFAULT '{}',
-    OUT lsn pg_lsn, OUT xid xid, OUT data bytea)
-RETURNS SETOF RECORD
-LANGUAGE INTERNAL
-VOLATILE ROWS 1000 COST 1000
-AS 'pg_logical_slot_peek_binary_changes';
-
-CREATE OR REPLACE FUNCTION pg_logical_emit_message(
-    transactional boolean,
-    prefix text,
-    message text,
-    flush boolean DEFAULT false)
-RETURNS pg_lsn
-LANGUAGE INTERNAL
-STRICT VOLATILE
-AS 'pg_logical_emit_message_text';
-
-CREATE OR REPLACE FUNCTION pg_logical_emit_message(
-    transactional boolean,
-    prefix text,
-    message bytea,
-    flush boolean DEFAULT false)
-RETURNS pg_lsn
-LANGUAGE INTERNAL
-STRICT VOLATILE
-AS 'pg_logical_emit_message_bytea';
-
-CREATE OR REPLACE FUNCTION pg_create_physical_replication_slot(
-    IN slot_name name, IN immediately_reserve boolean DEFAULT false,
-    IN temporary boolean DEFAULT false,
-    OUT slot_name name, OUT lsn pg_lsn)
-RETURNS RECORD
-LANGUAGE INTERNAL
-STRICT VOLATILE
-AS 'pg_create_physical_replication_slot';
-
-CREATE OR REPLACE FUNCTION pg_create_logical_replication_slot(
-    IN slot_name name, IN plugin name,
-    IN temporary boolean DEFAULT false,
-    IN twophase boolean DEFAULT false,
-    IN failover boolean DEFAULT false,
-    OUT slot_name name, OUT lsn pg_lsn)
-RETURNS RECORD
-LANGUAGE INTERNAL
-STRICT VOLATILE
-AS 'pg_create_logical_replication_slot';
-
-CREATE OR REPLACE FUNCTION
-  make_interval(years int4 DEFAULT 0, months int4 DEFAULT 0, weeks int4 DEFAULT 0,
-                days int4 DEFAULT 0, hours int4 DEFAULT 0, mins int4 DEFAULT 0,
-                secs double precision DEFAULT 0.0)
-RETURNS interval
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'make_interval';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_set(jsonb_in jsonb, path text[] , replacement jsonb,
-            create_if_missing boolean DEFAULT true)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_set';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_set_lax(jsonb_in jsonb, path text[] , replacement jsonb,
-            create_if_missing boolean DEFAULT true,
-            null_value_treatment text DEFAULT 'use_json_null')
-RETURNS jsonb
-LANGUAGE INTERNAL
-CALLED ON NULL INPUT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_set_lax';
-
-CREATE OR REPLACE FUNCTION
-  parse_ident(str text, strict boolean DEFAULT true)
-RETURNS text[]
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'parse_ident';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_insert(jsonb_in jsonb, path text[] , replacement jsonb,
-            insert_after boolean DEFAULT false)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_insert';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_exists(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                    silent boolean DEFAULT false)
-RETURNS boolean
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_path_exists';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_match(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                   silent boolean DEFAULT false)
-RETURNS boolean
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_path_match';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_query(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                   silent boolean DEFAULT false)
-RETURNS SETOF jsonb
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_path_query';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_query_array(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                         silent boolean DEFAULT false)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_path_query_array';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_query_first(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                         silent boolean DEFAULT false)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'jsonb_path_query_first';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_exists_tz(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                    silent boolean DEFAULT false)
-RETURNS boolean
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'jsonb_path_exists_tz';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_match_tz(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                   silent boolean DEFAULT false)
-RETURNS boolean
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'jsonb_path_match_tz';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_query_tz(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                   silent boolean DEFAULT false)
-RETURNS SETOF jsonb
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'jsonb_path_query_tz';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_query_array_tz(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                         silent boolean DEFAULT false)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'jsonb_path_query_array_tz';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_path_query_first_tz(target jsonb, path jsonpath, vars jsonb DEFAULT '{}',
-                         silent boolean DEFAULT false)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'jsonb_path_query_first_tz';
-
-CREATE OR REPLACE FUNCTION
-  jsonb_strip_nulls(target jsonb, strip_in_arrays boolean DEFAULT false)
-RETURNS jsonb
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'jsonb_strip_nulls';
-
-CREATE OR REPLACE FUNCTION
-  json_strip_nulls(target json, strip_in_arrays boolean DEFAULT false)
-RETURNS json
-LANGUAGE INTERNAL
-STRICT STABLE PARALLEL SAFE
-AS 'json_strip_nulls';
-
--- default normalization form is NFC, per SQL standard
-CREATE OR REPLACE FUNCTION
-  "normalize"(text, text DEFAULT 'NFC')
-RETURNS text
-LANGUAGE internal
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'unicode_normalize_func';
-
-CREATE OR REPLACE FUNCTION
-  is_normalized(text, text DEFAULT 'NFC')
-RETURNS boolean
-LANGUAGE internal
-STRICT IMMUTABLE PARALLEL SAFE
-AS 'unicode_is_normalized';
-
-CREATE OR REPLACE FUNCTION
-  pg_stat_reset_shared(target text DEFAULT NULL)
-RETURNS void
-LANGUAGE INTERNAL
-CALLED ON NULL INPUT VOLATILE PARALLEL SAFE
-AS 'pg_stat_reset_shared';
-
-CREATE OR REPLACE FUNCTION
-  pg_stat_reset_slru(target text DEFAULT NULL)
-RETURNS void
-LANGUAGE INTERNAL
-CALLED ON NULL INPUT VOLATILE PARALLEL SAFE
-AS 'pg_stat_reset_slru';
-
-CREATE OR REPLACE FUNCTION
-  pg_replication_origin_session_setup(node_name text, pid integer DEFAULT 0)
-RETURNS void
-LANGUAGE INTERNAL
-STRICT VOLATILE PARALLEL UNSAFE
-AS 'pg_replication_origin_session_setup';
-
 --
 -- The default permissions for functions mean that anyone can execute them.
 -- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
index b924a2d900b..1913b009d40 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -2492,6 +2492,7 @@ get_type_io_data(Oid typid,
 	{
 		Oid			typinput;
 		Oid			typoutput;
+		Oid			typcollation;
 
 		boot_get_type_io_data(typid,
 							  typlen,
@@ -2500,7 +2501,8 @@ get_type_io_data(Oid typid,
 							  typdelim,
 							  typioparam,
 							  &typinput,
-							  &typoutput);
+							  &typoutput,
+							  &typcollation);
 		switch (which_func)
 		{
 			case IOFunc_input:
diff --git a/src/include/bootstrap/bootstrap.h b/src/include/bootstrap/bootstrap.h
index 51680522afc..21447a3d661 100644
--- a/src/include/bootstrap/bootstrap.h
+++ b/src/include/bootstrap/bootstrap.h
@@ -53,7 +53,8 @@ extern void boot_get_type_io_data(Oid typid,
 								  char *typdelim,
 								  Oid *typioparam,
 								  Oid *typinput,
-								  Oid *typoutput);
+								  Oid *typoutput,
+								  Oid *typcollation);
 
 union YYSTYPE;
 typedef void *yyscan_t;
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 83f6501df38..dac40992cbc 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3499,6 +3499,7 @@
 { oid => '6212', descr => 'random value from normal distribution',
   proname => 'random_normal', provolatile => 'v', proparallel => 'r',
   prorettype => 'float8', proargtypes => 'float8 float8',
+  proargnames => '{mean,stddev}', proargdefaults => '{0,1}',
   prosrc => 'drandom_normal' },
 { oid => '6339', descr => 'random integer in range',
   proname => 'random', provolatile => 'v', proparallel => 'r',
@@ -6174,6 +6175,7 @@
   descr => 'statistics: reset collected statistics shared across the cluster',
   proname => 'pg_stat_reset_shared', proisstrict => 'f', provolatile => 'v',
   prorettype => 'void', proargtypes => 'text',
+  proargnames => '{target}', proargdefaults => '{NULL}',
   prosrc => 'pg_stat_reset_shared' },
 { oid => '3776',
   descr => 'statistics: reset collected statistics for a single table or index in the current database or shared across all databases in the cluster',
@@ -6193,6 +6195,7 @@
   descr => 'statistics: reset collected statistics for a single SLRU',
   proname => 'pg_stat_reset_slru', proisstrict => 'f', provolatile => 'v',
   prorettype => 'void', proargtypes => 'text', proargnames => '{target}',
+  proargdefaults => '{NULL}',
   prosrc => 'pg_stat_reset_slru' },
 { oid => '6170',
   descr => 'statistics: reset collected statistics for a single replication slot',
@@ -6728,20 +6731,24 @@
 { oid => '2096', descr => 'terminate a server process',
   proname => 'pg_terminate_backend', provolatile => 'v', prorettype => 'bool',
   proargtypes => 'int4 int8', proargnames => '{pid,timeout}',
+  proargdefaults => '{0}',
   prosrc => 'pg_terminate_backend' },
 { oid => '2172', descr => 'prepare for taking an online backup',
   proname => 'pg_backup_start', provolatile => 'v', proparallel => 'r',
   prorettype => 'pg_lsn', proargtypes => 'text bool',
+  proargnames => '{label,fast}', proargdefaults => '{false}',
   prosrc => 'pg_backup_start' },
 { oid => '2739', descr => 'finish taking an online backup',
   proname => 'pg_backup_stop', provolatile => 'v', proparallel => 'r',
   prorettype => 'record', proargtypes => 'bool',
   proallargtypes => '{bool,pg_lsn,text,text}', proargmodes => '{i,o,o,o}',
   proargnames => '{wait_for_archive,lsn,labelfile,spcmapfile}',
+  proargdefaults => '{true}',
   prosrc => 'pg_backup_stop' },
 { oid => '3436', descr => 'promote standby server',
   proname => 'pg_promote', provolatile => 'v', prorettype => 'bool',
   proargtypes => 'bool int4', proargnames => '{wait,wait_seconds}',
+  proargdefaults => '{true,60}',
   prosrc => 'pg_promote' },
 { oid => '2848', descr => 'switch to new wal file',
   proname => 'pg_switch_wal', provolatile => 'v', prorettype => 'pg_lsn',
@@ -7517,7 +7524,8 @@
 { oid => '1268',
   descr => 'parse qualified identifier to array of identifiers',
   proname => 'parse_ident', prorettype => '_text', proargtypes => 'text bool',
-  proargnames => '{str,strict}', prosrc => 'parse_ident' },
+  proargnames => '{str,strict}', proargdefaults => '{true}',
+  prosrc => 'parse_ident' },
 
 { oid => '2246', descr => '(internal)',
   proname => 'fmgr_internal_validator', provolatile => 's',
@@ -9423,7 +9431,9 @@
   proargtypes => 'anyelement', prosrc => 'to_json' },
 { oid => '3261', descr => 'remove object fields with null values from json',
   proname => 'json_strip_nulls', prorettype => 'json',
-  proargtypes => 'json bool', prosrc => 'json_strip_nulls' },
+  proargtypes => 'json bool',
+  proargnames => '{target,strip_in_arrays}', proargdefaults => '{false}',
+  prosrc => 'json_strip_nulls' },
 
 { oid => '3947',
   proname => 'json_object_field', prorettype => 'json',
@@ -9480,12 +9490,17 @@
 { oid => '3960', descr => 'get record fields from a json object',
   proname => 'json_populate_record', proisstrict => 'f', provolatile => 's',
   prorettype => 'anyelement', proargtypes => 'anyelement json bool',
+  proargnames => '{base,from_json,use_json_as_text}',
+  proargdefaults => '{false}',
   prosrc => 'json_populate_record' },
 { oid => '3961',
   descr => 'get set of records with fields from a json array of objects',
   proname => 'json_populate_recordset', prorows => '100', proisstrict => 'f',
   proretset => 't', provolatile => 's', prorettype => 'anyelement',
-  proargtypes => 'anyelement json bool', prosrc => 'json_populate_recordset' },
+  proargtypes => 'anyelement json bool',
+  proargnames => '{base,from_json,use_json_as_text}',
+  proargdefaults => '{false}',
+  prosrc => 'json_populate_recordset' },
 { oid => '3204', descr => 'get record fields from a json object',
   proname => 'json_to_record', provolatile => 's', prorettype => 'record',
   proargtypes => 'json', prosrc => 'json_to_record' },
@@ -10364,7 +10379,9 @@
   prosrc => 'jsonb_build_object_noargs' },
 { oid => '3262', descr => 'remove object fields with null values from jsonb',
   proname => 'jsonb_strip_nulls', prorettype => 'jsonb',
-  proargtypes => 'jsonb bool', prosrc => 'jsonb_strip_nulls' },
+  proargtypes => 'jsonb bool',
+  proargnames => '{target,strip_in_arrays}', proargdefaults => '{false}',
+  prosrc => 'jsonb_strip_nulls' },
 
 { oid => '3478',
   proname => 'jsonb_object_field', prorettype => 'jsonb',
@@ -10538,16 +10555,25 @@
   proargtypes => 'jsonb _text', prosrc => 'jsonb_delete_path' },
 { oid => '5054', descr => 'Set part of a jsonb, handle NULL value',
   proname => 'jsonb_set_lax', proisstrict => 'f', prorettype => 'jsonb',
-  proargtypes => 'jsonb _text jsonb bool text', prosrc => 'jsonb_set_lax' },
+  proargtypes => 'jsonb _text jsonb bool text',
+  proargnames => '{jsonb_in,path,replacement,create_if_missing,null_value_treatment}',
+  proargdefaults => '{true,use_json_null}',
+  prosrc => 'jsonb_set_lax' },
 { oid => '3305', descr => 'Set part of a jsonb',
   proname => 'jsonb_set', prorettype => 'jsonb',
-  proargtypes => 'jsonb _text jsonb bool', prosrc => 'jsonb_set' },
+  proargtypes => 'jsonb _text jsonb bool',
+  proargnames => '{jsonb_in,path,replacement,create_if_missing}',
+  proargdefaults => '{true}',
+  prosrc => 'jsonb_set' },
 { oid => '3306', descr => 'Indented text from jsonb',
   proname => 'jsonb_pretty', prorettype => 'text', proargtypes => 'jsonb',
   prosrc => 'jsonb_pretty' },
 { oid => '3579', descr => 'Insert value into a jsonb',
   proname => 'jsonb_insert', prorettype => 'jsonb',
-  proargtypes => 'jsonb _text jsonb bool', prosrc => 'jsonb_insert' },
+  proargtypes => 'jsonb _text jsonb bool',
+  proargnames => '{jsonb_in,path,replacement,insert_after}',
+  proargdefaults => '{false}',
+  prosrc => 'jsonb_insert' },
 
 # jsonpath
 { oid => '4001', descr => 'I/O',
@@ -10565,42 +10591,66 @@
 
 { oid => '4005', descr => 'jsonpath exists test',
   proname => 'jsonb_path_exists', prorettype => 'bool',
-  proargtypes => 'jsonb jsonpath jsonb bool', prosrc => 'jsonb_path_exists' },
+  proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
+  prosrc => 'jsonb_path_exists' },
 { oid => '4006', descr => 'jsonpath query',
   proname => 'jsonb_path_query', prorows => '1000', proretset => 't',
   prorettype => 'jsonb', proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
   prosrc => 'jsonb_path_query' },
 { oid => '4007', descr => 'jsonpath query wrapped into array',
   proname => 'jsonb_path_query_array', prorettype => 'jsonb',
   proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
   prosrc => 'jsonb_path_query_array' },
 { oid => '4008', descr => 'jsonpath query first item',
   proname => 'jsonb_path_query_first', prorettype => 'jsonb',
   proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
   prosrc => 'jsonb_path_query_first' },
 { oid => '4009', descr => 'jsonpath match',
   proname => 'jsonb_path_match', prorettype => 'bool',
-  proargtypes => 'jsonb jsonpath jsonb bool', prosrc => 'jsonb_path_match' },
+  proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
+  prosrc => 'jsonb_path_match' },
 
 { oid => '1177', descr => 'jsonpath exists test with timezone',
   proname => 'jsonb_path_exists_tz', provolatile => 's', prorettype => 'bool',
   proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
   prosrc => 'jsonb_path_exists_tz' },
 { oid => '1179', descr => 'jsonpath query with timezone',
   proname => 'jsonb_path_query_tz', prorows => '1000', proretset => 't',
   provolatile => 's', prorettype => 'jsonb',
-  proargtypes => 'jsonb jsonpath jsonb bool', prosrc => 'jsonb_path_query_tz' },
+  proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
+  prosrc => 'jsonb_path_query_tz' },
 { oid => '1180', descr => 'jsonpath query wrapped into array with timezone',
   proname => 'jsonb_path_query_array_tz', provolatile => 's',
   prorettype => 'jsonb', proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
   prosrc => 'jsonb_path_query_array_tz' },
 { oid => '2023', descr => 'jsonpath query first item with timezone',
   proname => 'jsonb_path_query_first_tz', provolatile => 's',
   prorettype => 'jsonb', proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
   prosrc => 'jsonb_path_query_first_tz' },
 { oid => '2030', descr => 'jsonpath match with timezone',
   proname => 'jsonb_path_match_tz', provolatile => 's', prorettype => 'bool',
-  proargtypes => 'jsonb jsonpath jsonb bool', prosrc => 'jsonb_path_match_tz' },
+  proargtypes => 'jsonb jsonpath jsonb bool',
+  proargnames => '{target,path,vars,silent}',
+  proargdefaults => '{"{}",false}',
+  prosrc => 'jsonb_path_match_tz' },
 
 { oid => '4010', descr => 'implementation of @? operator',
   proname => 'jsonb_path_exists_opr', prorettype => 'bool',
@@ -11411,6 +11461,7 @@
   proname => 'make_interval', prorettype => 'interval',
   proargtypes => 'int4 int4 int4 int4 int4 int4 float8',
   proargnames => '{years,months,weeks,days,hours,mins,secs}',
+  proargdefaults => '{0,0,0,0,0,0,0.0}',
   prosrc => 'make_interval' },
 
 # spgist opclasses
@@ -11511,6 +11562,7 @@
   proallargtypes => '{name,bool,bool,name,pg_lsn}',
   proargmodes => '{i,i,i,o,o}',
   proargnames => '{slot_name,immediately_reserve,temporary,slot_name,lsn}',
+  proargdefaults => '{false,false}',
   prosrc => 'pg_create_physical_replication_slot' },
 { oid => '4220',
   descr => 'copy a physical replication slot, changing temporality',
@@ -11546,6 +11598,7 @@
   proallargtypes => '{name,name,bool,bool,bool,name,pg_lsn}',
   proargmodes => '{i,i,i,i,i,o,o}',
   proargnames => '{slot_name,plugin,temporary,twophase,failover,slot_name,lsn}',
+  proargdefaults => '{false,false,false}',
   prosrc => 'pg_create_logical_replication_slot' },
 { oid => '4222',
   descr => 'copy a logical replication slot, changing temporality and plugin',
@@ -11578,6 +11631,7 @@
   proallargtypes => '{name,pg_lsn,int4,_text,pg_lsn,xid,text}',
   proargmodes => '{i,i,i,v,o,o,o}',
   proargnames => '{slot_name,upto_lsn,upto_nchanges,options,lsn,xid,data}',
+  proargdefaults => '{"{}"}',
   prosrc => 'pg_logical_slot_get_changes' },
 { oid => '3783', descr => 'get binary changes from replication slot',
   proname => 'pg_logical_slot_get_binary_changes', procost => '1000',
@@ -11587,6 +11641,7 @@
   proallargtypes => '{name,pg_lsn,int4,_text,pg_lsn,xid,bytea}',
   proargmodes => '{i,i,i,v,o,o,o}',
   proargnames => '{slot_name,upto_lsn,upto_nchanges,options,lsn,xid,data}',
+  proargdefaults => '{"{}"}',
   prosrc => 'pg_logical_slot_get_binary_changes' },
 { oid => '3784', descr => 'peek at changes from replication slot',
   proname => 'pg_logical_slot_peek_changes', procost => '1000',
@@ -11596,6 +11651,7 @@
   proallargtypes => '{name,pg_lsn,int4,_text,pg_lsn,xid,text}',
   proargmodes => '{i,i,i,v,o,o,o}',
   proargnames => '{slot_name,upto_lsn,upto_nchanges,options,lsn,xid,data}',
+  proargdefaults => '{"{}"}',
   prosrc => 'pg_logical_slot_peek_changes' },
 { oid => '3785', descr => 'peek at binary changes from replication slot',
   proname => 'pg_logical_slot_peek_binary_changes', procost => '1000',
@@ -11605,6 +11661,7 @@
   proallargtypes => '{name,pg_lsn,int4,_text,pg_lsn,xid,bytea}',
   proargmodes => '{i,i,i,v,o,o,o}',
   proargnames => '{slot_name,upto_lsn,upto_nchanges,options,lsn,xid,data}',
+  proargdefaults => '{"{}"}',
   prosrc => 'pg_logical_slot_peek_binary_changes' },
 { oid => '3878', descr => 'advance logical replication slot',
   proname => 'pg_replication_slot_advance', provolatile => 'v',
@@ -11615,10 +11672,14 @@
 { oid => '3577', descr => 'emit a textual logical decoding message',
   proname => 'pg_logical_emit_message', provolatile => 'v', proparallel => 'u',
   prorettype => 'pg_lsn', proargtypes => 'bool text text bool',
+  proargnames => '{transactional,prefix,message,flush}',
+  proargdefaults => '{false}',
   prosrc => 'pg_logical_emit_message_text' },
 { oid => '3578', descr => 'emit a binary logical decoding message',
   proname => 'pg_logical_emit_message', provolatile => 'v', proparallel => 'u',
   prorettype => 'pg_lsn', proargtypes => 'bool text bytea bool',
+  proargnames => '{transactional,prefix,message,flush}',
+  proargdefaults => '{false}',
   prosrc => 'pg_logical_emit_message_bytea' },
 { oid => '6344',
   descr => 'sync replication slots from the primary to the standby',
@@ -12268,6 +12329,7 @@
   descr => 'configure session to maintain replication progress tracking for the passed in origin',
   proname => 'pg_replication_origin_session_setup', provolatile => 'v',
   proparallel => 'u', prorettype => 'void', proargtypes => 'text int4',
+  proargnames => '{node_name,pid}', proargdefaults => '{0}',
   prosrc => 'pg_replication_origin_session_setup' },
 
 { oid => '6007', descr => 'teardown configured replication progress tracking',
@@ -12518,10 +12580,12 @@
 
 { oid => '4350', descr => 'Unicode normalization',
   proname => 'normalize', prorettype => 'text', proargtypes => 'text text',
+  proargdefaults => '{NFC}',
   prosrc => 'unicode_normalize_func' },
 
 { oid => '4351', descr => 'check Unicode normalization',
   proname => 'is_normalized', prorettype => 'bool', proargtypes => 'text text',
+  proargdefaults => '{NFC}',
   prosrc => 'unicode_is_normalized' },
 
 { oid => '6198', descr => 'unescape Unicode characters',
-- 
2.43.7

Re: generating function default settings from pg_proc.dat

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:

On 2026-02-17 Tu 1:41 PM, Tom Lane wrote:
> Here's the promised v2, which addresses all your review comments.
>
> With respect to the list of supported types in bki.sgml: I wonder if
> we should just drop that, because it evidently hasn't been maintained
> well.  It wasn't at all in sync with the actual contents of TypInfo[].
> I made it be so, but ...
>
> Poking further at that, I found that there were a lot of TypInfo[]
> entries that were not actually used and seem to have just been
> cargo-culted in.  So this patch removes all the ones that aren't
> demonstrably necessary to get through initdb.  Maybe that's too
> aggressive, but in view of the potential for maintenance errors
> (cf 7cdb633c8) I don't think we should be carrying unused entries
> there.
>
> 			


That makes sense. I haven't tested it, but the code looks pretty sane. 
Nice job. I guess if we ever want to specify a default that's not a 
Const for some reason we'd have to fall back on the system_views 
mechanism. But that's not very likely.


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com



Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Andrew Dunstan  writes:
> That makes sense. I haven't tested it, but the code looks pretty sane. 
> Nice job. I guess if we ever want to specify a default that's not a 
> Const for some reason we'd have to fall back on the system_views 
> mechanism. But that's not very likely.

Right, the idea of this patch is to make the common cases easy
without making uncommon cases any worse than they were.  We have
enough experience now with default arguments to be pretty sure
that this will cover 90%-plus of the need.

			regards, tom lane


Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Corey Huinker  writes:
> Fair enough. But in the interest of keeping a single source of truth, what
> if we reversed the process, having a build-time perl script parse
> system_functions.sql to build a minimal pg_proc.dat-like file just for
> bootstrap? We would probably want to break up system_functions.sql into
> several files, (admin functions go here, adt-related functions go there,
> etc), but we'd have total clarity on all function definitions, and we
> wouldn't have to modify the generation of pg_proc.dat unless a new function
> syntax feature affected bootstrapping.

Seems like an awful lot of work compared to the benefit.  We are
down to two kinds of entries in system_functions.sql:

1. New-style SQL-language functions.  To my mind, for those functions
system_functions.sql *is* the source of truth; the pg_proc entry is
vestigial and present mostly to reserve the OID.  If we decided it's
okay to not have nailed-down OIDs for those functions, we could drop
their pg_proc entries altogether.  But even as things stand, those
entries all say
    prosrc => 'see system_functions.sql' },
which I think makes it pretty clear where the primary definition is.

2. GRANT/REVOKE operations.  Andres muttered something about trying
to integrate those into pg_proc.dat too, and I'm going to go look
at the idea.

			regards, tom lane


Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I wrote:
> 2. GRANT/REVOKE operations.  Andres muttered something about trying
> to integrate those into pg_proc.dat too, and I'm going to go look
> at the idea.

Here's a draft patch for that.  It's pretty simple in concept: in
bootstrap mode, let aclitemin() look into a hard-wired table of role
names, just as we do for pg_type data before that catalog has been
loaded.  Everything then basically just works.  However, the project
bloated on me a little bit, because after removing all the function
revoke/grant commands from system_functions.sql, I was left with

GRANT pg_read_all_settings TO pg_monitor;
GRANT pg_read_all_stats TO pg_monitor;
GRANT pg_stat_scan_tables TO pg_monitor;

There was some excuse for those to live in system_functions.sql
as long as they were beside grants establishing special privileges
for those roles, but with those grants gone this seemed like an
unacceptably random place for them.  So I moved that knowledge
into a new catalog data file pg_auth_members.dat.

This accomplishes the goal Andres had of eliminating pg_proc
update operations during initdb, except for the new-style
SQL-language functions set up in system_functions.sql:

postgres=# select xmin, oid, oid::regprocedure from pg_proc where xmin != 1 and prosqlbody is null;
 xmin |  oid  |                          oid                          
------+-------+-------------------------------------------------------
  261 | 14095 | dsnowball_init(internal)
  262 | 14096 | dsnowball_lexize(internal,internal,internal,internal)
  459 | 14161 | information_schema._pg_expandarray(anyarray)
  612 | 14511 | plpgsql_call_handler()
  612 | 14512 | plpgsql_inline_handler(internal)
  612 | 14513 | plpgsql_validator(oid)
(6 rows)

However, I'm not sure I love it in this form, because what it
asks developers to do is populate proacl using aclitemin's
notation, eg

@@ -8602,7 +8641,8 @@
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,int8,int8,int8}', proargmodes => '{o,o,o,o}',
   proargnames => '{name,off,size,allocated_size}',
-  prosrc => 'pg_get_shmem_allocations' },
+  prosrc => 'pg_get_shmem_allocations',
+  proacl => '{postgres=X/postgres,pg_read_all_stats=X/postgres}' },
 
 { oid => '4099', descr => 'Is NUMA support available?',
   proname => 'pg_numa_available', provolatile => 's', prorettype => 'bool',

That's verbose, and not very pretty, and potentially confusing because
it's predicated on the assumption that the bootstrap user's name is
'postgres'.  This patch does work when the bootstrap user's name is
something else, but I don't really like hard-wiring things that way.

Is it worth putting in some additional kluge to allow this field
to be spelled in a different way, and if so what notation do we
want to adopt?

One thing we could do for free is to drop the "/postgres" grantor
notations, since aclitemin will default to assuming the grantor
is the bootstrap superuser.  That makes things more compact but
doesn't move the needle far otherwise.

Another potential objection is specific to the functions that
underlie system views: before, their special grants/revokes lived
beside similar grants for the associated views.  Now those are in
two different files with completely different notations.  So maybe
this has taken the "single source of truth" idea too far, and we
should leave system_views.sql alone.

Comments welcome.

			regards, tom lane

From 28afb7041102eb0b8657746106533a7780aaddc0 Mon Sep 17 00:00:00 2001
From: Tom Lane 
Date: Wed, 18 Feb 2026 17:38:30 -0500
Subject: [PATCH v1] Simplify creation of built-in functions with non-default
 ACLs.

Up to now, to create such a function, one had to make a pg_proc.dat
entry and then modify it with GRANT/REVOKE commands, which we put in
system_functions.sql.  That seems a little ugly though, because it
violates the idea of having a single source of truth about the initial
contents of pg_proc, and it results in leaving dead rows in the
initial contents of pg_proc.

This patch improves matters by allowing aclitemin() to work during
early bootstrap, before pg_authid has been loaded.  On the same
principle that we use for early access to pg_type details, put
a table of known built-in role names into bootstrap.c, and use
that in bootstrap mode.

In this form of the patch, one must write verbatim ACL lists in
proacl entries in pg_proc.dat.  That seems less than ideal:
it requires assuming a particular name for the bootstrap superuser
(here "postgres"), and it is a notation that many developers may
not be familiar with.  Maybe we can think of a better notation.

Author: Tom Lane 
Discussion: https://postgr.es/m/183292bb-4891-4c96-a3ca-e78b5e0e1358@dunslane.net
---
 src/backend/bootstrap/bootstrap.c        |  59 +++++++
 src/backend/catalog/system_functions.sql | 166 +------------------
 src/backend/catalog/system_views.sql     |  14 --
 src/backend/utils/adt/acl.c              |  14 +-
 src/include/bootstrap/bootstrap.h        |   2 +
 src/include/catalog/Makefile             |   1 +
 src/include/catalog/meson.build          |   1 +
 src/include/catalog/pg_auth_members.dat  |  20 +++
 src/include/catalog/pg_auth_members.h    |  27 ++-
 src/include/catalog/pg_authid.dat        |   3 +
 src/include/catalog/pg_proc.dat          | 201 +++++++++++++++--------
 11 files changed, 254 insertions(+), 254 deletions(-)
 create mode 100644 src/include/catalog/pg_auth_members.dat

diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 8d601c363b4..e34b157b6de 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -25,6 +25,7 @@
 #include "access/xact.h"
 #include "bootstrap/bootstrap.h"
 #include "catalog/index.h"
+#include "catalog/pg_authid.h"
 #include "catalog/pg_collation.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
@@ -115,6 +116,8 @@ static const struct typinfo TypInfo[] = {
 	F_JSONB_IN, F_JSONB_OUT},
 	{"oid", OIDOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
 	F_OIDIN, F_OIDOUT},
+	{"aclitem", ACLITEMOID, 0, 16, false, TYPALIGN_DOUBLE, TYPSTORAGE_PLAIN, InvalidOid,
+	F_ACLITEMIN, F_ACLITEMOUT},
 	{"pg_node_tree", PG_NODE_TREEOID, 0, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, DEFAULT_COLLATION_OID,
 	F_PG_NODE_TREE_IN, F_PG_NODE_TREE_OUT},
 	{"int2vector", INT2VECTOROID, INT2OID, -1, false, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
@@ -144,6 +147,43 @@ struct typmap
 static List *Typ = NIL;			/* List of struct typmap* */
 static struct typmap *Ap = NULL;
 
+/*
+ * Basic information about built-in roles.
+ *
+ * Presently, this need only list roles that are mentioned in aclitem arrays
+ * in the catalog .dat files.  We might as well list everything that is in
+ * pg_authid.dat, since there aren't that many.  We assume that the bootstrap
+ * superuser's name is "postgres", even though it might not be that in the
+ * finished installation; this means aclitem entries in .dat files must spell
+ * it like that.
+ */
+struct rolinfo
+{
+	const char *rolname;
+	Oid			oid;
+};
+
+static const struct rolinfo RolInfo[] = {
+	{"postgres", BOOTSTRAP_SUPERUSERID},
+	{"pg_database_owner", ROLE_PG_DATABASE_OWNER},
+	{"pg_read_all_data", ROLE_PG_READ_ALL_DATA},
+	{"pg_write_all_data", ROLE_PG_WRITE_ALL_DATA},
+	{"pg_monitor", ROLE_PG_MONITOR},
+	{"pg_read_all_settings", ROLE_PG_READ_ALL_SETTINGS},
+	{"pg_read_all_stats", ROLE_PG_READ_ALL_STATS},
+	{"pg_stat_scan_tables", ROLE_PG_STAT_SCAN_TABLES},
+	{"pg_read_server_files", ROLE_PG_READ_SERVER_FILES},
+	{"pg_write_server_files", ROLE_PG_WRITE_SERVER_FILES},
+	{"pg_execute_server_program", ROLE_PG_EXECUTE_SERVER_PROGRAM},
+	{"pg_signal_backend", ROLE_PG_SIGNAL_BACKEND},
+	{"pg_checkpoint", ROLE_PG_CHECKPOINT},
+	{"pg_maintain", ROLE_PG_MAINTAIN},
+	{"pg_use_reserved_connections", ROLE_PG_USE_RESERVED_CONNECTIONS},
+	{"pg_create_subscription", ROLE_PG_CREATE_SUBSCRIPTION},
+	{"pg_signal_autovacuum_worker", ROLE_PG_SIGNAL_AUTOVACUUM_WORKER}
+};
+
+
 static Datum values[MAXATTR];	/* current row's attribute values */
 static bool Nulls[MAXATTR];
 
@@ -1034,6 +1074,25 @@ boot_get_type_io_data(Oid typid,
 	}
 }
 
+/* ----------------
+ *		boot_get_role_oid
+ *
+ * Look up a role name at bootstrap time.  This is equivalent to
+ * get_role_oid(rolname, true): return the role OID or InvalidOid if
+ * not found.  We only need to cope with built-in role names.
+ * ----------------
+ */
+Oid
+boot_get_role_oid(const char *rolname)
+{
+	for (int i = 0; i < lengthof(RolInfo); i++)
+	{
+		if (strcmp(RolInfo[i].rolname, rolname) == 0)
+			return RolInfo[i].oid;
+	}
+	return InvalidOid;
+}
+
 /* ----------------
  *		AllocateAttribute
  *
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 69699f8830a..1c5b6d6df05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -14,12 +14,8 @@
  * definitions of such functions into pg_proc.dat and then replace them
  * here.  The stub definitions would be unnecessary were it not that we'd
  * like these functions to have stable OIDs, the same as other built-in
- * functions.
- *
- * This file also takes care of adjusting privileges for those functions
- * that should not have the default public-EXECUTE privileges.  (However,
- * a small number of functions that exist mainly to underlie system views
- * are dealt with in system_views.sql, instead.)
+ * functions.  (That's important, for example, to their treatment by
+ * postgres_fdw.)
  *
  * Note: this file is read in single-user -j mode, which means that the
  * command terminator is semicolon-newline-newline; whenever the backend
@@ -376,161 +372,3 @@ CREATE OR REPLACE FUNCTION ts_debug(document text,
 BEGIN ATOMIC
     SELECT * FROM ts_debug(get_current_ts_config(), $1);
 END;
-
-
---
--- The default permissions for functions mean that anyone can execute them.
--- A number of functions shouldn't be executable by just anyone, but rather
--- than use explicit 'superuser()' checks in those functions, we use the GRANT
--- system to REVOKE access to those functions at initdb time.  Administrators
--- can later change who can access these functions, or leave them as only
--- available to superuser / cluster owner, if they choose.
---
-
-REVOKE EXECUTE ON FUNCTION pg_backup_start(text, boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_backup_stop(boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_create_restore_point(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_switch_wal() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_log_standby_snapshot() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_wal_replay_pause() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_wal_replay_resume() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_rotate_logfile() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_reload_conf() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_current_logfile() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_current_logfile(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_promote(boolean, integer) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_shared(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_slru(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_single_table_counters(oid) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_single_function_counters(oid) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_backend_stats(integer) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_replication_slot(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_have_stats(text, oid, int8) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_subscription_stats(oid) FROM public;
-
-REVOKE EXECUTE ON FUNCTION lo_import(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION lo_import(text, oid) FROM public;
-
-REVOKE EXECUTE ON FUNCTION lo_export(oid, text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_logdir() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_waldir() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_archive_statusdir() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_summariesdir() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_tmpdir() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_tmpdir(oid) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_file(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_file(text,boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_file(text,bigint,bigint) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_file(text,bigint,bigint,boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_binary_file(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_binary_file(text,boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_binary_file(text,bigint,bigint) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_binary_file(text,bigint,bigint,boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_advance(text, pg_lsn) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_create(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_drop(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_oid(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_progress(text, boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_is_setup() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_progress(boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_reset() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_setup(text, integer) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_xact_reset() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_xact_setup(pg_lsn, timestamp with time zone) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_show_replication_origin_status() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_file(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_file(text,boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_dir(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_dir(text,boolean,boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_log_backend_memory_contexts(integer) FROM PUBLIC;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_logicalsnapdir() FROM PUBLIC;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_logicalmapdir() FROM PUBLIC;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_replslotdir(text) FROM PUBLIC;
-
---
--- We also set up some things as accessible to standard roles.
---
-
-GRANT EXECUTE ON FUNCTION pg_ls_logdir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_waldir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_archive_statusdir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_summariesdir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_tmpdir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_tmpdir(oid) TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_logicalsnapdir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_logicalmapdir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_replslotdir(text) TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_current_logfile() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_current_logfile(text) TO pg_monitor;
-
-GRANT pg_read_all_settings TO pg_monitor;
-
-GRANT pg_read_all_stats TO pg_monitor;
-
-GRANT pg_stat_scan_tables TO pg_monitor;
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 1ea8f1faa9e..56106d92eaf 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -650,19 +650,16 @@ CREATE VIEW pg_file_settings AS
    SELECT * FROM pg_show_all_file_settings() AS A;
 
 REVOKE ALL ON pg_file_settings FROM PUBLIC;
-REVOKE EXECUTE ON FUNCTION pg_show_all_file_settings() FROM PUBLIC;
 
 CREATE VIEW pg_hba_file_rules AS
    SELECT * FROM pg_hba_file_rules() AS A;
 
 REVOKE ALL ON pg_hba_file_rules FROM PUBLIC;
-REVOKE EXECUTE ON FUNCTION pg_hba_file_rules() FROM PUBLIC;
 
 CREATE VIEW pg_ident_file_mappings AS
    SELECT * FROM pg_ident_file_mappings() AS A;
 
 REVOKE ALL ON pg_ident_file_mappings FROM PUBLIC;
-REVOKE EXECUTE ON FUNCTION pg_ident_file_mappings() FROM PUBLIC;
 
 CREATE VIEW pg_timezone_abbrevs AS
     SELECT * FROM pg_timezone_abbrevs_zone() z
@@ -679,39 +676,30 @@ CREATE VIEW pg_config AS
     SELECT * FROM pg_config();
 
 REVOKE ALL ON pg_config FROM PUBLIC;
-REVOKE EXECUTE ON FUNCTION pg_config() FROM PUBLIC;
 
 CREATE VIEW pg_shmem_allocations AS
     SELECT * FROM pg_get_shmem_allocations();
 
 REVOKE ALL ON pg_shmem_allocations FROM PUBLIC;
 GRANT SELECT ON pg_shmem_allocations TO pg_read_all_stats;
-REVOKE EXECUTE ON FUNCTION pg_get_shmem_allocations() FROM PUBLIC;
-GRANT EXECUTE ON FUNCTION pg_get_shmem_allocations() TO pg_read_all_stats;
 
 CREATE VIEW pg_shmem_allocations_numa AS
     SELECT * FROM pg_get_shmem_allocations_numa();
 
 REVOKE ALL ON pg_shmem_allocations_numa FROM PUBLIC;
 GRANT SELECT ON pg_shmem_allocations_numa TO pg_read_all_stats;
-REVOKE EXECUTE ON FUNCTION pg_get_shmem_allocations_numa() FROM PUBLIC;
-GRANT EXECUTE ON FUNCTION pg_get_shmem_allocations_numa() TO pg_read_all_stats;
 
 CREATE VIEW pg_dsm_registry_allocations AS
     SELECT * FROM pg_get_dsm_registry_allocations();
 
 REVOKE ALL ON pg_dsm_registry_allocations FROM PUBLIC;
 GRANT SELECT ON pg_dsm_registry_allocations TO pg_read_all_stats;
-REVOKE EXECUTE ON FUNCTION pg_get_dsm_registry_allocations() FROM PUBLIC;
-GRANT EXECUTE ON FUNCTION pg_get_dsm_registry_allocations() TO pg_read_all_stats;
 
 CREATE VIEW pg_backend_memory_contexts AS
     SELECT * FROM pg_get_backend_memory_contexts();
 
 REVOKE ALL ON pg_backend_memory_contexts FROM PUBLIC;
 GRANT SELECT ON pg_backend_memory_contexts TO pg_read_all_stats;
-REVOKE EXECUTE ON FUNCTION pg_get_backend_memory_contexts() FROM PUBLIC;
-GRANT EXECUTE ON FUNCTION pg_get_backend_memory_contexts() TO pg_read_all_stats;
 
 -- Statistics views
 
@@ -1471,5 +1459,3 @@ CREATE VIEW pg_aios AS
     SELECT * FROM pg_get_aios();
 REVOKE ALL ON pg_aios FROM PUBLIC;
 GRANT SELECT ON pg_aios TO pg_read_all_stats;
-REVOKE EXECUTE ON FUNCTION pg_get_aios() FROM PUBLIC;
-GRANT EXECUTE ON FUNCTION pg_get_aios() TO pg_read_all_stats;
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index 641673f0b0e..31067f1f51e 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -17,6 +17,7 @@
 #include 
 
 #include "access/htup_details.h"
+#include "bootstrap/bootstrap.h"
 #include "catalog/catalog.h"
 #include "catalog/namespace.h"
 #include "catalog/pg_auth_members.h"
@@ -261,6 +262,9 @@ putid(char *p, const char *s)
  *		This routine is called by the parser as well as aclitemin(), hence
  *		the added generality.
  *
+ *		In bootstrap mode, we consult a hard-wired list of role names
+ *		(see bootstrap.c) rather than trying to access the catalogs.
+ *
  * RETURNS:
  *		the string position in 's' immediately following the ACL
  *		specification.  Also:
@@ -376,7 +380,10 @@ aclparse(const char *s, AclItem *aip, Node *escontext)
 		aip->ai_grantee = ACL_ID_PUBLIC;
 	else
 	{
-		aip->ai_grantee = get_role_oid(name, true);
+		if (IsBootstrapProcessingMode())
+			aip->ai_grantee = boot_get_role_oid(name);
+		else
+			aip->ai_grantee = get_role_oid(name, true);
 		if (!OidIsValid(aip->ai_grantee))
 			ereturn(escontext, NULL,
 					(errcode(ERRCODE_UNDEFINED_OBJECT),
@@ -396,7 +403,10 @@ aclparse(const char *s, AclItem *aip, Node *escontext)
 			ereturn(escontext, NULL,
 					(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
 					 errmsg("a name must follow the \"/\" sign")));
-		aip->ai_grantor = get_role_oid(name2, true);
+		if (IsBootstrapProcessingMode())
+			aip->ai_grantor = boot_get_role_oid(name2);
+		else
+			aip->ai_grantor = get_role_oid(name2, true);
 		if (!OidIsValid(aip->ai_grantor))
 			ereturn(escontext, NULL,
 					(errcode(ERRCODE_UNDEFINED_OBJECT),
diff --git a/src/include/bootstrap/bootstrap.h b/src/include/bootstrap/bootstrap.h
index 21447a3d661..e967b2b1885 100644
--- a/src/include/bootstrap/bootstrap.h
+++ b/src/include/bootstrap/bootstrap.h
@@ -56,6 +56,8 @@ extern void boot_get_type_io_data(Oid typid,
 								  Oid *typoutput,
 								  Oid *typcollation);
 
+extern Oid	boot_get_role_oid(const char *rolname);
+
 union YYSTYPE;
 typedef void *yyscan_t;
 
diff --git a/src/include/catalog/Makefile b/src/include/catalog/Makefile
index 24b527230d4..444fc76eed6 100644
--- a/src/include/catalog/Makefile
+++ b/src/include/catalog/Makefile
@@ -94,6 +94,7 @@ POSTGRES_BKI_DATA = \
 	pg_amop.dat \
 	pg_amproc.dat \
 	pg_authid.dat \
+	pg_auth_members.dat \
 	pg_cast.dat \
 	pg_class.dat \
 	pg_collation.dat \
diff --git a/src/include/catalog/meson.build b/src/include/catalog/meson.build
index 433bcc908ad..bcc01c87c2e 100644
--- a/src/include/catalog/meson.build
+++ b/src/include/catalog/meson.build
@@ -78,6 +78,7 @@ bki_data = [
   'pg_amop.dat',
   'pg_amproc.dat',
   'pg_authid.dat',
+  'pg_auth_members.dat',
   'pg_cast.dat',
   'pg_class.dat',
   'pg_collation.dat',
diff --git a/src/include/catalog/pg_auth_members.dat b/src/include/catalog/pg_auth_members.dat
new file mode 100644
index 00000000000..246373251d4
--- /dev/null
+++ b/src/include/catalog/pg_auth_members.dat
@@ -0,0 +1,20 @@
+#----------------------------------------------------------------------
+#
+# pg_auth_members.dat
+#    Initial contents of the pg_auth_members system catalog.
+#
+# Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
+# Portions Copyright (c) 1994, Regents of the University of California
+#
+# src/include/catalog/pg_auth_members.dat
+#
+#----------------------------------------------------------------------
+
+[
+
+# We grant these roles to pg_monitor.
+{ roleid => 'pg_read_all_settings', member => 'pg_monitor' },
+{ roleid => 'pg_read_all_stats', member => 'pg_monitor' },
+{ roleid => 'pg_stat_scan_tables', member => 'pg_monitor' },
+
+]
diff --git a/src/include/catalog/pg_auth_members.h b/src/include/catalog/pg_auth_members.h
index 92cf5271496..15806df95bf 100644
--- a/src/include/catalog/pg_auth_members.h
+++ b/src/include/catalog/pg_auth_members.h
@@ -29,13 +29,26 @@
  */
 CATALOG(pg_auth_members,1261,AuthMemRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(2843,AuthMemRelation_Rowtype_Id) BKI_SCHEMA_MACRO
 {
-	Oid			oid;			/* oid */
-	Oid			roleid BKI_LOOKUP(pg_authid);	/* ID of a role */
-	Oid			member BKI_LOOKUP(pg_authid);	/* ID of a member of that role */
-	Oid			grantor BKI_LOOKUP(pg_authid);	/* who granted the membership */
-	bool		admin_option;	/* granted with admin option? */
-	bool		inherit_option; /* exercise privileges without SET ROLE? */
-	bool		set_option;		/* use SET ROLE to the target role? */
+	/* OID for this record (needed for dependencies) */
+	Oid			oid;
+
+	/* ID of a role */
+	Oid			roleid BKI_LOOKUP(pg_authid);
+
+	/* ID of a member of that role */
+	Oid			member BKI_LOOKUP(pg_authid);
+
+	/* who granted the membership */
+	Oid			grantor BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
+
+	/* granted with admin option? */
+	bool		admin_option BKI_DEFAULT(f);
+
+	/* exercise privileges without SET ROLE? */
+	bool		inherit_option BKI_DEFAULT(t);
+
+	/* use SET ROLE to the target role? */
+	bool		set_option BKI_DEFAULT(t);
 } FormData_pg_auth_members;
 
 /* ----------------
diff --git a/src/include/catalog/pg_authid.dat b/src/include/catalog/pg_authid.dat
index 26b5c9971a4..3d376479cbe 100644
--- a/src/include/catalog/pg_authid.dat
+++ b/src/include/catalog/pg_authid.dat
@@ -18,6 +18,9 @@
 # The bootstrap superuser is named POSTGRES according to this data and
 # according to BKI_DEFAULT entries in other catalogs.  However, initdb
 # will replace that at database initialization time.
+# Inconsistently with that, the bootstrap superuser is called "postgres"
+# in ACL entries within the catalog .dat files, because boot_get_role_oid()
+# will translate it that way.
 
 { oid => '10', oid_symbol => 'BOOTSTRAP_SUPERUSERID',
   rolname => 'POSTGRES', rolsuper => 't', rolinherit => 't',
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index dac40992cbc..5399044451e 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -1822,14 +1822,17 @@
 
 { oid => '764', descr => 'large object import',
   proname => 'lo_import', provolatile => 'v', proparallel => 'u',
-  prorettype => 'oid', proargtypes => 'text', prosrc => 'be_lo_import' },
+  prorettype => 'oid', proargtypes => 'text', prosrc => 'be_lo_import',
+  proacl => '{postgres=X/postgres}' },
 { oid => '767', descr => 'large object import',
   proname => 'lo_import', provolatile => 'v', proparallel => 'u',
   prorettype => 'oid', proargtypes => 'text oid',
-  prosrc => 'be_lo_import_with_oid' },
+  prosrc => 'be_lo_import_with_oid',
+  proacl => '{postgres=X/postgres}' },
 { oid => '765', descr => 'large object export',
   proname => 'lo_export', provolatile => 'v', proparallel => 'u',
-  prorettype => 'int4', proargtypes => 'oid text', prosrc => 'be_lo_export' },
+  prorettype => 'int4', proargtypes => 'oid text', prosrc => 'be_lo_export',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '766', descr => 'increment',
   proname => 'int4inc', prorettype => 'int4', proargtypes => 'int4',
@@ -5709,7 +5712,8 @@
 { oid => '6230', descr => 'statistics: check if a stats object exists',
   proname => 'pg_stat_have_stats', provolatile => 'v', proparallel => 'r',
   prorettype => 'bool', proargtypes => 'text oid int8',
-  prosrc => 'pg_stat_have_stats' },
+  prosrc => 'pg_stat_have_stats',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '6231', descr => 'statistics: information about subscription stats',
   proname => 'pg_stat_get_subscription_stats', provolatile => 's',
@@ -6170,43 +6174,51 @@
 { oid => '2274',
   descr => 'statistics: reset collected statistics for current database',
   proname => 'pg_stat_reset', proisstrict => 'f', provolatile => 'v',
-  prorettype => 'void', proargtypes => '', prosrc => 'pg_stat_reset' },
+  prorettype => 'void', proargtypes => '', prosrc => 'pg_stat_reset',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3775',
   descr => 'statistics: reset collected statistics shared across the cluster',
   proname => 'pg_stat_reset_shared', proisstrict => 'f', provolatile => 'v',
   prorettype => 'void', proargtypes => 'text',
   proargnames => '{target}', proargdefaults => '{NULL}',
-  prosrc => 'pg_stat_reset_shared' },
+  prosrc => 'pg_stat_reset_shared',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3776',
   descr => 'statistics: reset collected statistics for a single table or index in the current database or shared across all databases in the cluster',
   proname => 'pg_stat_reset_single_table_counters', provolatile => 'v',
   prorettype => 'void', proargtypes => 'oid',
-  prosrc => 'pg_stat_reset_single_table_counters' },
+  prosrc => 'pg_stat_reset_single_table_counters',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3777',
   descr => 'statistics: reset collected statistics for a single function in the current database',
   proname => 'pg_stat_reset_single_function_counters', provolatile => 'v',
   prorettype => 'void', proargtypes => 'oid',
-  prosrc => 'pg_stat_reset_single_function_counters' },
+  prosrc => 'pg_stat_reset_single_function_counters',
+  proacl => '{postgres=X/postgres}' },
 { oid => '6387', descr => 'statistics: reset statistics for a single backend',
   proname => 'pg_stat_reset_backend_stats', provolatile => 'v',
   prorettype => 'void', proargtypes => 'int4',
-  prosrc => 'pg_stat_reset_backend_stats' },
+  prosrc => 'pg_stat_reset_backend_stats',
+  proacl => '{postgres=X/postgres}' },
 { oid => '2307',
   descr => 'statistics: reset collected statistics for a single SLRU',
   proname => 'pg_stat_reset_slru', proisstrict => 'f', provolatile => 'v',
   prorettype => 'void', proargtypes => 'text', proargnames => '{target}',
   proargdefaults => '{NULL}',
-  prosrc => 'pg_stat_reset_slru' },
+  prosrc => 'pg_stat_reset_slru',
+  proacl => '{postgres=X/postgres}' },
 { oid => '6170',
   descr => 'statistics: reset collected statistics for a single replication slot',
   proname => 'pg_stat_reset_replication_slot', proisstrict => 'f',
   provolatile => 'v', prorettype => 'void', proargtypes => 'text',
-  prosrc => 'pg_stat_reset_replication_slot' },
+  prosrc => 'pg_stat_reset_replication_slot',
+  proacl => '{postgres=X/postgres}' },
 { oid => '6232',
   descr => 'statistics: reset collected statistics for a single subscription',
   proname => 'pg_stat_reset_subscription_stats', proisstrict => 'f',
   provolatile => 'v', prorettype => 'void', proargtypes => 'oid',
-  prosrc => 'pg_stat_reset_subscription_stats' },
+  prosrc => 'pg_stat_reset_subscription_stats',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '3163', descr => 'current trigger depth',
   proname => 'pg_trigger_depth', provolatile => 's', proparallel => 'r',
@@ -6553,21 +6565,24 @@
   proallargtypes => '{text,int4,int4,text,text,bool,text}',
   proargmodes => '{o,o,o,o,o,o,o}',
   proargnames => '{sourcefile,sourceline,seqno,name,setting,applied,error}',
-  prosrc => 'show_all_file_settings' },
+  prosrc => 'show_all_file_settings',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3401', descr => 'show pg_hba.conf rules',
   proname => 'pg_hba_file_rules', prorows => '1000', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{int4,text,int4,text,_text,_text,text,text,text,_text,text}',
   proargmodes => '{o,o,o,o,o,o,o,o,o,o,o}',
   proargnames => '{rule_number,file_name,line_number,type,database,user_name,address,netmask,auth_method,options,error}',
-  prosrc => 'pg_hba_file_rules' },
+  prosrc => 'pg_hba_file_rules',
+  proacl => '{postgres=X/postgres}' },
 { oid => '6250', descr => 'show pg_ident.conf mappings',
   proname => 'pg_ident_file_mappings', prorows => '1000', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{int4,text,int4,text,text,text,text}',
   proargmodes => '{o,o,o,o,o,o,o}',
   proargnames => '{map_number,file_name,line_number,map_name,sys_name,pg_username,error}',
-  prosrc => 'pg_ident_file_mappings' },
+  prosrc => 'pg_ident_file_mappings',
+  proacl => '{postgres=X/postgres}' },
 { oid => '1371', descr => 'view system lock information',
   proname => 'pg_lock_status', prorows => '1000', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => '',
@@ -6737,30 +6752,36 @@
   proname => 'pg_backup_start', provolatile => 'v', proparallel => 'r',
   prorettype => 'pg_lsn', proargtypes => 'text bool',
   proargnames => '{label,fast}', proargdefaults => '{false}',
-  prosrc => 'pg_backup_start' },
+  prosrc => 'pg_backup_start',
+  proacl => '{postgres=X/postgres}' },
 { oid => '2739', descr => 'finish taking an online backup',
   proname => 'pg_backup_stop', provolatile => 'v', proparallel => 'r',
   prorettype => 'record', proargtypes => 'bool',
   proallargtypes => '{bool,pg_lsn,text,text}', proargmodes => '{i,o,o,o}',
   proargnames => '{wait_for_archive,lsn,labelfile,spcmapfile}',
   proargdefaults => '{true}',
-  prosrc => 'pg_backup_stop' },
+  prosrc => 'pg_backup_stop',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3436', descr => 'promote standby server',
   proname => 'pg_promote', provolatile => 'v', prorettype => 'bool',
   proargtypes => 'bool int4', proargnames => '{wait,wait_seconds}',
   proargdefaults => '{true,60}',
-  prosrc => 'pg_promote' },
+  prosrc => 'pg_promote',
+  proacl => '{postgres=X/postgres}' },
 { oid => '2848', descr => 'switch to new wal file',
   proname => 'pg_switch_wal', provolatile => 'v', prorettype => 'pg_lsn',
-  proargtypes => '', prosrc => 'pg_switch_wal' },
+  proargtypes => '', prosrc => 'pg_switch_wal',
+  proacl => '{postgres=X/postgres}' },
 { oid => '6305', descr => 'log details of the current snapshot to WAL',
   proname => 'pg_log_standby_snapshot', provolatile => 'v',
   prorettype => 'pg_lsn', proargtypes => '',
-  prosrc => 'pg_log_standby_snapshot' },
+  prosrc => 'pg_log_standby_snapshot',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3098', descr => 'create a named restore point',
   proname => 'pg_create_restore_point', provolatile => 'v',
   prorettype => 'pg_lsn', proargtypes => 'text',
-  prosrc => 'pg_create_restore_point' },
+  prosrc => 'pg_create_restore_point',
+  proacl => '{postgres=X/postgres}' },
 { oid => '2849', descr => 'current wal write location',
   proname => 'pg_current_wal_lsn', provolatile => 'v', prorettype => 'pg_lsn',
   proargtypes => '', prosrc => 'pg_current_wal_lsn' },
@@ -6816,10 +6837,12 @@
 
 { oid => '3071', descr => 'pause wal replay',
   proname => 'pg_wal_replay_pause', provolatile => 'v', prorettype => 'void',
-  proargtypes => '', prosrc => 'pg_wal_replay_pause' },
+  proargtypes => '', prosrc => 'pg_wal_replay_pause',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3072', descr => 'resume wal replay, if it was paused',
   proname => 'pg_wal_replay_resume', provolatile => 'v', prorettype => 'void',
-  proargtypes => '', prosrc => 'pg_wal_replay_resume' },
+  proargtypes => '', prosrc => 'pg_wal_replay_resume',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3073', descr => 'true if wal replay is paused',
   proname => 'pg_is_wal_replay_paused', provolatile => 'v',
   prorettype => 'bool', proargtypes => '',
@@ -6845,17 +6868,21 @@
 
 { oid => '2621', descr => 'reload configuration files',
   proname => 'pg_reload_conf', provolatile => 'v', prorettype => 'bool',
-  proargtypes => '', prosrc => 'pg_reload_conf' },
+  proargtypes => '', prosrc => 'pg_reload_conf',
+  proacl => '{postgres=X/postgres}' },
 { oid => '2622', descr => 'rotate log file',
   proname => 'pg_rotate_logfile', provolatile => 'v', prorettype => 'bool',
-  proargtypes => '', prosrc => 'pg_rotate_logfile' },
+  proargtypes => '', prosrc => 'pg_rotate_logfile',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3800', descr => 'current logging collector file location',
   proname => 'pg_current_logfile', proisstrict => 'f', provolatile => 'v',
-  prorettype => 'text', proargtypes => '', prosrc => 'pg_current_logfile' },
+  prorettype => 'text', proargtypes => '', prosrc => 'pg_current_logfile',
+  proacl => '{postgres=X/postgres,pg_monitor=X/postgres}' },
 { oid => '3801', descr => 'current logging collector file location',
   proname => 'pg_current_logfile', proisstrict => 'f', provolatile => 'v',
   prorettype => 'text', proargtypes => 'text',
-  prosrc => 'pg_current_logfile_1arg' },
+  prosrc => 'pg_current_logfile_1arg',
+  proacl => '{postgres=X/postgres,pg_monitor=X/postgres}' },
 
 { oid => '2623', descr => 'get information about file',
   proname => 'pg_stat_file', provolatile => 'v', prorettype => 'record',
@@ -6863,48 +6890,60 @@
   proallargtypes => '{text,int8,timestamptz,timestamptz,timestamptz,timestamptz,bool}',
   proargmodes => '{i,o,o,o,o,o,o}',
   proargnames => '{filename,size,access,modification,change,creation,isdir}',
-  prosrc => 'pg_stat_file_1arg' },
+  prosrc => 'pg_stat_file_1arg',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3307', descr => 'get information about file',
   proname => 'pg_stat_file', provolatile => 'v', prorettype => 'record',
   proargtypes => 'text bool',
   proallargtypes => '{text,bool,int8,timestamptz,timestamptz,timestamptz,timestamptz,bool}',
   proargmodes => '{i,i,o,o,o,o,o,o}',
   proargnames => '{filename,missing_ok,size,access,modification,change,creation,isdir}',
-  prosrc => 'pg_stat_file' },
+  prosrc => 'pg_stat_file',
+  proacl => '{postgres=X/postgres}' },
 { oid => '2624', descr => 'read text from a file',
   proname => 'pg_read_file', provolatile => 'v', prorettype => 'text',
-  proargtypes => 'text int8 int8', prosrc => 'pg_read_file_off_len' },
+  proargtypes => 'text int8 int8', prosrc => 'pg_read_file_off_len',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3293', descr => 'read text from a file',
   proname => 'pg_read_file', provolatile => 'v', prorettype => 'text',
   proargtypes => 'text int8 int8 bool',
-  prosrc => 'pg_read_file_off_len_missing' },
+  prosrc => 'pg_read_file_off_len_missing',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3826', descr => 'read text from a file',
   proname => 'pg_read_file', provolatile => 'v', prorettype => 'text',
-  proargtypes => 'text', prosrc => 'pg_read_file_all' },
+  proargtypes => 'text', prosrc => 'pg_read_file_all',
+  proacl => '{postgres=X/postgres}' },
 { oid => '6208', descr => 'read text from a file',
   proname => 'pg_read_file', provolatile => 'v', prorettype => 'text',
-  proargtypes => 'text bool', prosrc => 'pg_read_file_all_missing' },
+  proargtypes => 'text bool', prosrc => 'pg_read_file_all_missing',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3827', descr => 'read bytea from a file',
   proname => 'pg_read_binary_file', provolatile => 'v', prorettype => 'bytea',
-  proargtypes => 'text int8 int8', prosrc => 'pg_read_binary_file_off_len' },
+  proargtypes => 'text int8 int8', prosrc => 'pg_read_binary_file_off_len',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3295', descr => 'read bytea from a file',
   proname => 'pg_read_binary_file', provolatile => 'v', prorettype => 'bytea',
   proargtypes => 'text int8 int8 bool',
-  prosrc => 'pg_read_binary_file_off_len_missing' },
+  prosrc => 'pg_read_binary_file_off_len_missing',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3828', descr => 'read bytea from a file',
   proname => 'pg_read_binary_file', provolatile => 'v', prorettype => 'bytea',
-  proargtypes => 'text', prosrc => 'pg_read_binary_file_all' },
+  proargtypes => 'text', prosrc => 'pg_read_binary_file_all',
+  proacl => '{postgres=X/postgres}' },
 { oid => '6209', descr => 'read bytea from a file',
   proname => 'pg_read_binary_file', provolatile => 'v', prorettype => 'bytea',
-  proargtypes => 'text bool', prosrc => 'pg_read_binary_file_all_missing' },
+  proargtypes => 'text bool', prosrc => 'pg_read_binary_file_all_missing',
+  proacl => '{postgres=X/postgres}' },
 { oid => '2625', descr => 'list all files in a directory',
   proname => 'pg_ls_dir', prorows => '1000', proretset => 't',
   provolatile => 'v', prorettype => 'text', proargtypes => 'text',
-  prosrc => 'pg_ls_dir_1arg' },
+  prosrc => 'pg_ls_dir_1arg',
+  proacl => '{postgres=X/postgres}' },
 { oid => '3297', descr => 'list all files in a directory',
   proname => 'pg_ls_dir', prorows => '1000', proretset => 't',
   provolatile => 'v', prorettype => 'text', proargtypes => 'text bool bool',
-  prosrc => 'pg_ls_dir' },
+  prosrc => 'pg_ls_dir',
+  proacl => '{postgres=X/postgres}' },
 { oid => '2626', descr => 'sleep for the specified time in seconds',
   proname => 'pg_sleep', provolatile => 'v', prorettype => 'void',
   proargtypes => 'float8', prosrc => 'pg_sleep' },
@@ -8602,7 +8641,8 @@
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,int8,int8,int8}', proargmodes => '{o,o,o,o}',
   proargnames => '{name,off,size,allocated_size}',
-  prosrc => 'pg_get_shmem_allocations' },
+  prosrc => 'pg_get_shmem_allocations',
+  proacl => '{postgres=X/postgres,pg_read_all_stats=X/postgres}' },
 
 { oid => '4099', descr => 'Is NUMA support available?',
   proname => 'pg_numa_available', provolatile => 's', prorettype => 'bool',
@@ -8614,7 +8654,8 @@
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,int4,int8}', proargmodes => '{o,o,o}',
   proargnames => '{name,numa_node,size}',
-  prosrc => 'pg_get_shmem_allocations_numa' },
+  prosrc => 'pg_get_shmem_allocations_numa',
+  proacl => '{postgres=X/postgres,pg_read_all_stats=X/postgres}' },
 
 { oid => '9314',
   descr => 'shared memory allocations tracked in the DSM registry',
@@ -8622,7 +8663,8 @@
   proretset => 't', provolatile => 'v', prorettype => 'record',
   proargtypes => '', proallargtypes => '{text,text,int8}',
   proargmodes => '{o,o,o}', proargnames => '{name,type,size}',
-  prosrc => 'pg_get_dsm_registry_allocations' },
+  prosrc => 'pg_get_dsm_registry_allocations',
+  proacl => '{postgres=X/postgres,pg_read_all_stats=X/postgres}' },
 
 # memory context of local backend
 { oid => '2282',
@@ -8633,13 +8675,15 @@
   proallargtypes => '{text,text,text,int4,_int4,int8,int8,int8,int8,int8}',
   proargmodes => '{o,o,o,o,o,o,o,o,o,o}',
   proargnames => '{name, ident, type, level, path, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes}',
-  prosrc => 'pg_get_backend_memory_contexts' },
+  prosrc => 'pg_get_backend_memory_contexts',
+  proacl => '{postgres=X/postgres,pg_read_all_stats=X/postgres}' },
 
 # logging memory contexts of the specified backend
 { oid => '4543', descr => 'log memory contexts of the specified backend',
   proname => 'pg_log_backend_memory_contexts', provolatile => 'v',
   prorettype => 'bool', proargtypes => 'int4',
-  prosrc => 'pg_log_backend_memory_contexts' },
+  prosrc => 'pg_log_backend_memory_contexts',
+  proacl => '{postgres=X/postgres}' },
 
 # non-persistent series generator
 { oid => '1066', descr => 'non-persistent series generator',
@@ -12312,63 +12356,74 @@
 { oid => '6003', descr => 'create a replication origin',
   proname => 'pg_replication_origin_create', provolatile => 'v',
   proparallel => 'u', prorettype => 'oid', proargtypes => 'text',
-  prosrc => 'pg_replication_origin_create' },
+  prosrc => 'pg_replication_origin_create',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '6004', descr => 'drop replication origin identified by its name',
   proname => 'pg_replication_origin_drop', provolatile => 'v',
   proparallel => 'u', prorettype => 'void', proargtypes => 'text',
-  prosrc => 'pg_replication_origin_drop' },
+  prosrc => 'pg_replication_origin_drop',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '6005',
   descr => 'translate the replication origin\'s name to its id',
   proname => 'pg_replication_origin_oid', provolatile => 's',
   prorettype => 'oid', proargtypes => 'text',
-  prosrc => 'pg_replication_origin_oid' },
+  prosrc => 'pg_replication_origin_oid',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '6006',
   descr => 'configure session to maintain replication progress tracking for the passed in origin',
   proname => 'pg_replication_origin_session_setup', provolatile => 'v',
   proparallel => 'u', prorettype => 'void', proargtypes => 'text int4',
   proargnames => '{node_name,pid}', proargdefaults => '{0}',
-  prosrc => 'pg_replication_origin_session_setup' },
+  prosrc => 'pg_replication_origin_session_setup',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '6007', descr => 'teardown configured replication progress tracking',
   proname => 'pg_replication_origin_session_reset', provolatile => 'v',
   proparallel => 'u', prorettype => 'void', proargtypes => '',
-  prosrc => 'pg_replication_origin_session_reset' },
+  prosrc => 'pg_replication_origin_session_reset',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '6008',
   descr => 'is a replication origin configured in this session',
   proname => 'pg_replication_origin_session_is_setup', provolatile => 'v',
   proparallel => 'r', prorettype => 'bool', proargtypes => '',
-  prosrc => 'pg_replication_origin_session_is_setup' },
+  prosrc => 'pg_replication_origin_session_is_setup',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '6009',
   descr => 'get the replication progress of the current session',
   proname => 'pg_replication_origin_session_progress', provolatile => 'v',
   proparallel => 'u', prorettype => 'pg_lsn', proargtypes => 'bool',
-  prosrc => 'pg_replication_origin_session_progress' },
+  prosrc => 'pg_replication_origin_session_progress',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '6010', descr => 'setup the transaction\'s origin lsn and timestamp',
   proname => 'pg_replication_origin_xact_setup', provolatile => 'v',
   proparallel => 'r', prorettype => 'void', proargtypes => 'pg_lsn timestamptz',
-  prosrc => 'pg_replication_origin_xact_setup' },
+  prosrc => 'pg_replication_origin_xact_setup',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '6011', descr => 'reset the transaction\'s origin lsn and timestamp',
   proname => 'pg_replication_origin_xact_reset', provolatile => 'v',
   proparallel => 'r', prorettype => 'void', proargtypes => '',
-  prosrc => 'pg_replication_origin_xact_reset' },
+  prosrc => 'pg_replication_origin_xact_reset',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '6012', descr => 'advance replication origin to specific location',
   proname => 'pg_replication_origin_advance', provolatile => 'v',
   proparallel => 'u', prorettype => 'void', proargtypes => 'text pg_lsn',
-  prosrc => 'pg_replication_origin_advance' },
+  prosrc => 'pg_replication_origin_advance',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '6013',
   descr => 'get an individual replication origin\'s replication progress',
   proname => 'pg_replication_origin_progress', provolatile => 'v',
   proparallel => 'u', prorettype => 'pg_lsn', proargtypes => 'text bool',
-  prosrc => 'pg_replication_origin_progress' },
+  prosrc => 'pg_replication_origin_progress',
+  proacl => '{postgres=X/postgres}' },
 
 { oid => '6014', descr => 'get progress for all replication origins',
   proname => 'pg_show_replication_origin_status', prorows => '100',
@@ -12376,7 +12431,8 @@
   prorettype => 'record', proargtypes => '',
   proallargtypes => '{oid,text,pg_lsn,pg_lsn}', proargmodes => '{o,o,o,o}',
   proargnames => '{local_id, external_id, remote_lsn, local_lsn}',
-  prosrc => 'pg_show_replication_origin_status' },
+  prosrc => 'pg_show_replication_origin_status',
+  proacl => '{postgres=X/postgres}' },
 
 # publications
 { oid => '6119',
@@ -12414,7 +12470,8 @@
   proname => 'pg_config', prorows => '23', proretset => 't', provolatile => 's',
   proparallel => 'r', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,text}', proargmodes => '{o,o}',
-  proargnames => '{name,setting}', prosrc => 'pg_config' },
+  proargnames => '{name,setting}', prosrc => 'pg_config',
+  proacl => '{postgres=X/postgres}' },
 
 # pg_controldata related functions
 { oid => '3441',
@@ -12489,49 +12546,57 @@
   proname => 'pg_ls_logdir', procost => '10', prorows => '20', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,int8,timestamptz}', proargmodes => '{o,o,o}',
-  proargnames => '{name,size,modification}', prosrc => 'pg_ls_logdir' },
+  proargnames => '{name,size,modification}', prosrc => 'pg_ls_logdir',
+  proacl => '{postgres=X/postgres,pg_monitor=X/postgres}' },
 { oid => '3354', descr => 'list of files in the WAL directory',
   proname => 'pg_ls_waldir', procost => '10', prorows => '20', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,int8,timestamptz}', proargmodes => '{o,o,o}',
-  proargnames => '{name,size,modification}', prosrc => 'pg_ls_waldir' },
+  proargnames => '{name,size,modification}', prosrc => 'pg_ls_waldir',
+  proacl => '{postgres=X/postgres,pg_monitor=X/postgres}' },
 { oid => '6400', descr => 'list of files in the pg_wal/summaries directory',
   proname => 'pg_ls_summariesdir', procost => '10', prorows => '20',
   proretset => 't', provolatile => 'v', prorettype => 'record',
   proargtypes => '', proallargtypes => '{text,int8,timestamptz}',
   proargmodes => '{o,o,o}', proargnames => '{name,size,modification}',
-  prosrc => 'pg_ls_summariesdir' },
+  prosrc => 'pg_ls_summariesdir',
+  proacl => '{postgres=X/postgres,pg_monitor=X/postgres}' },
 { oid => '5031', descr => 'list of files in the archive_status directory',
   proname => 'pg_ls_archive_statusdir', procost => '10', prorows => '20',
   proretset => 't', provolatile => 'v', prorettype => 'record',
   proargtypes => '', proallargtypes => '{text,int8,timestamptz}',
   proargmodes => '{o,o,o}', proargnames => '{name,size,modification}',
-  prosrc => 'pg_ls_archive_statusdir' },
+  prosrc => 'pg_ls_archive_statusdir',
+  proacl => '{postgres=X/postgres,pg_monitor=X/postgres}' },
 { oid => '5029', descr => 'list files in the pgsql_tmp directory',
   proname => 'pg_ls_tmpdir', procost => '10', prorows => '20', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,int8,timestamptz}', proargmodes => '{o,o,o}',
-  proargnames => '{name,size,modification}', prosrc => 'pg_ls_tmpdir_noargs' },
+  proargnames => '{name,size,modification}', prosrc => 'pg_ls_tmpdir_noargs',
+  proacl => '{postgres=X/postgres,pg_monitor=X/postgres}' },
 { oid => '5030', descr => 'list files in the pgsql_tmp directory',
   proname => 'pg_ls_tmpdir', procost => '10', prorows => '20', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => 'oid',
   proallargtypes => '{oid,text,int8,timestamptz}', proargmodes => '{i,o,o,o}',
   proargnames => '{tablespace,name,size,modification}',
-  prosrc => 'pg_ls_tmpdir_1arg' },
+  prosrc => 'pg_ls_tmpdir_1arg',
+  proacl => '{postgres=X/postgres,pg_monitor=X/postgres}' },
 { oid => '6270',
   descr => 'list of files in the pg_logical/snapshots directory',
   proname => 'pg_ls_logicalsnapdir', procost => '10', prorows => '20',
   proretset => 't', provolatile => 'v', prorettype => 'record',
   proargtypes => '', proallargtypes => '{text,int8,timestamptz}',
   proargmodes => '{o,o,o}', proargnames => '{name,size,modification}',
-  prosrc => 'pg_ls_logicalsnapdir' },
+  prosrc => 'pg_ls_logicalsnapdir',
+  proacl => '{postgres=X/postgres,pg_monitor=X/postgres}' },
 { oid => '6271',
   descr => 'list of files in the pg_logical/mappings directory',
   proname => 'pg_ls_logicalmapdir', procost => '10', prorows => '20',
   proretset => 't', provolatile => 'v', prorettype => 'record',
   proargtypes => '', proallargtypes => '{text,int8,timestamptz}',
   proargmodes => '{o,o,o}', proargnames => '{name,size,modification}',
-  prosrc => 'pg_ls_logicalmapdir' },
+  prosrc => 'pg_ls_logicalmapdir',
+  proacl => '{postgres=X/postgres,pg_monitor=X/postgres}' },
 { oid => '6272',
   descr => 'list of files in the pg_replslot/slot_name directory',
   proname => 'pg_ls_replslotdir', procost => '10', prorows => '20',
@@ -12539,7 +12604,8 @@
   proargtypes => 'text', proallargtypes => '{text,text,int8,timestamptz}',
   proargmodes => '{i,o,o,o}',
   proargnames => '{slot_name,name,size,modification}',
-  prosrc => 'pg_ls_replslotdir' },
+  prosrc => 'pg_ls_replslotdir',
+  proacl => '{postgres=X/postgres,pg_monitor=X/postgres}' },
 
 # hash partitioning constraint function
 { oid => '5028', descr => 'hash partition CHECK constraint',
@@ -12702,7 +12768,8 @@
   proallargtypes => '{int4,int4,int8,text,text,int8,int8,text,int2,int4,text,text,bool,bool,bool}',
   proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
   proargnames => '{pid,io_id,io_generation,state,operation,off,length,target,handle_data_len,raw_result,result,target_desc,f_sync,f_localmem,f_buffered}',
-  prosrc => 'pg_get_aios' },
+  prosrc => 'pg_get_aios',
+  proacl => '{postgres=X/postgres,pg_read_all_stats=X/postgres}' },
 
 # oid8 related functions
 { oid => '8255', descr => 'convert oid to oid8',
-- 
2.43.7

Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I wrote:
> However, I'm not sure I love it in this form, because what it
> asks developers to do is populate proacl using aclitemin's
> notation, eg
> +  proacl => '{postgres=X/postgres,pg_read_all_stats=X/postgres}' },

After sleeping on it, I decided that much of the cognitive dissonance
here comes from the fact that elsewhere in the catalog data files
we represent the bootstrap user's name as POSTGRES, making it more
obvious that that's a placeholder and not the real value.  If we do
that here and also drop the redundant grantor specifications, we get

+  proacl => '{POSTGRES=X,pg_read_all_stats=X}' },

which is still not the world's prettiest notation, but it feels
manageable for this purpose.

I tried to write it that way and found that it failed miserably,
because initdb tried to substitute the real superuser's name
for POSTGRES, and we don't want that here (the bootstrap backend
can't possibly know what that is yet).  So 0001 attached is a
preliminary patch to tighten initdb so it only replaces complete
tokens bounded by whitespace, rather than any arbitrary substrings
of postgres.bki lines.  (Note this depends on 2f248ad57.)  Then
0002 is the same patch as before plus this notational adjustment.

			regards, tom lane

From 041f37c0980eec91edb6924726d3806d37426e25 Mon Sep 17 00:00:00 2001
From: Tom Lane 
Date: Thu, 19 Feb 2026 12:00:25 -0500
Subject: [PATCH v2 1/2] Be more wary of false matches in initdb's
 replace_token().

Do not replace the target string unless the occurrence is surrounded
by whitespace or line start/end.  This avoids potential false match
to a substring of a field.  While we've not had trouble with that
up to now, the next patch creates hazards of false matches to
POSTGRES within an ACL field.

There is one call site that needs adjustment, as it was presuming
it could write "::1" and have that match "::1/128".  For all the
others, this restriction is okay and strictly safer.

Author: Tom Lane 
Discussion: https://postgr.es/m/183292bb-4891-4c96-a3ca-e78b5e0e1358@dunslane.net
---
 src/bin/initdb/initdb.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 7c49dd433a7..e9e1014bce9 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -461,7 +461,8 @@ add_stringlist_item(_stringlist **listhead, const char *str)
 
 /*
  * Modify the array of lines, replacing "token" by "replacement"
- * the first time it occurs on each line.
+ * the first time it occurs on each line.  To prevent false matches, the
+ * occurrence of "token" must be surrounded by whitespace or line start/end.
  *
  * The array must be a malloc'd array of individually malloc'd strings.
  * We free any discarded strings.
@@ -483,6 +484,7 @@ replace_token(char **lines, const char *token, const char *replacement)
 	for (int i = 0; lines[i]; i++)
 	{
 		char	   *where;
+		char	   *endwhere;
 		char	   *newline;
 		int			pre;
 
@@ -490,6 +492,17 @@ replace_token(char **lines, const char *token, const char *replacement)
 		if ((where = strstr(lines[i], token)) == NULL)
 			continue;
 
+		/*
+		 * Reject false match.  Note a blind spot: we don't check for a valid
+		 * match following a false match.  That case can't occur at present,
+		 * so not worth complicating this code for it.
+		 */
+		if (!(where == lines[i] || isspace((unsigned char) where[-1])))
+			continue;
+		endwhere = where + strlen(token);
+		if (!(*endwhere == '\0' || isspace((unsigned char) *endwhere)))
+			continue;
+
 		/* if we get here a change is needed - set up new line */
 
 		newline = (char *) pg_malloc(strlen(lines[i]) + diff + 1);
@@ -1496,11 +1509,11 @@ setup_config(void)
 			getaddrinfo("::1", NULL, &hints, &gai_result) != 0)
 		{
 			conflines = replace_token(conflines,
-									  "host    all             all             ::1",
-									  "#host    all             all             ::1");
+									  "host    all             all             ::1/128",
+									  "#host    all             all             ::1/128");
 			conflines = replace_token(conflines,
-									  "host    replication     all             ::1",
-									  "#host    replication     all             ::1");
+									  "host    replication     all             ::1/128",
+									  "#host    replication     all             ::1/128");
 		}
 	}
 
-- 
2.43.7

From 02cf96109455d9aff9775dbb665474a20eea1352 Mon Sep 17 00:00:00 2001
From: Tom Lane 
Date: Thu, 19 Feb 2026 12:25:05 -0500
Subject: [PATCH v2 2/2] Simplify creation of built-in functions with
 non-default ACLs.

Up to now, to create such a function, one had to make a pg_proc.dat
entry and then modify it with GRANT/REVOKE commands, which we put in
system_functions.sql.  That seems a little ugly though, because it
violates the idea of having a single source of truth about the initial
contents of pg_proc, and it results in leaving dead rows in the
initial contents of pg_proc.

This patch improves matters by allowing aclitemin to work during
early bootstrap, before pg_authid has been loaded.  On the same
principle that we use for early access to pg_type details, put
a table of known built-in role names into bootstrap.c, and use
that in bootstrap mode.

In this form of the patch, one must write ACL lists in pg_proc.dat
proacl entries in a simplified version of aclitemout's notation:
omit the grantor (if it is the bootstrap superuser, which it
pretty much always should be) and spell the bootstrap superuser's
name as POSTGRES, similarly to the notation used elsewhere in
src/include/catalog.  This results in entries like
  proacl => '{POSTGRES=X,pg_monitor=X}'

In addition to fixing up pg_proc.dat entries, I got rid of some
role grants that had been stuck into system_functions.sql,
and instead put them into a new file pg_auth_members.dat;
that seems like a far less random place to put the information.

The correctness of the data changes can be verified by comparing
the initial contents of pg_proc and pg_auth_members before and
after.  pg_proc should match exactly, but the OID column of
pg_auth_members will probably be different because those OIDs
now get assigned a little earlier in bootstrap.

Author: Tom Lane 
Discussion: https://postgr.es/m/183292bb-4891-4c96-a3ca-e78b5e0e1358@dunslane.net
---
 src/backend/bootstrap/bootstrap.c        |  59 +++++++
 src/backend/catalog/system_functions.sql | 166 +------------------
 src/backend/catalog/system_views.sql     |  14 --
 src/backend/utils/adt/acl.c              |  26 ++-
 src/include/bootstrap/bootstrap.h        |   2 +
 src/include/catalog/Makefile             |   1 +
 src/include/catalog/meson.build          |   1 +
 src/include/catalog/pg_auth_members.dat  |  20 +++
 src/include/catalog/pg_auth_members.h    |  27 ++-
 src/include/catalog/pg_authid.dat        |   6 +-
 src/include/catalog/pg_proc.dat          | 201 +++++++++++++++--------
 11 files changed, 262 insertions(+), 261 deletions(-)
 create mode 100644 src/include/catalog/pg_auth_members.dat

diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index e7699be55aa..17118f2fe76 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -25,6 +25,7 @@
 #include "access/xact.h"
 #include "bootstrap/bootstrap.h"
 #include "catalog/index.h"
+#include "catalog/pg_authid.h"
 #include "catalog/pg_collation.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
@@ -115,6 +116,8 @@ static const struct typinfo TypInfo[] = {
 	F_JSONB_IN, F_JSONB_OUT},
 	{"oid", OIDOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
 	F_OIDIN, F_OIDOUT},
+	{"aclitem", ACLITEMOID, 0, 16, false, TYPALIGN_DOUBLE, TYPSTORAGE_PLAIN, InvalidOid,
+	F_ACLITEMIN, F_ACLITEMOUT},
 	{"pg_node_tree", PG_NODE_TREEOID, 0, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, DEFAULT_COLLATION_OID,
 	F_PG_NODE_TREE_IN, F_PG_NODE_TREE_OUT},
 	{"int2vector", INT2VECTOROID, INT2OID, -1, false, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
@@ -144,6 +147,43 @@ struct typmap
 static List *Typ = NIL;			/* List of struct typmap* */
 static struct typmap *Ap = NULL;
 
+/*
+ * Basic information about built-in roles.
+ *
+ * Presently, this need only list roles that are mentioned in aclitem arrays
+ * in the catalog .dat files.  We might as well list everything that is in
+ * pg_authid.dat, since there aren't that many.  Like pg_authid.dat, we
+ * represent the bootstrap superuser's name as "POSTGRES", even though it
+ * (probably) won't be that in the finished installation; this means aclitem
+ * entries in .dat files must spell it like that.
+ */
+struct rolinfo
+{
+	const char *rolname;
+	Oid			oid;
+};
+
+static const struct rolinfo RolInfo[] = {
+	{"POSTGRES", BOOTSTRAP_SUPERUSERID},
+	{"pg_database_owner", ROLE_PG_DATABASE_OWNER},
+	{"pg_read_all_data", ROLE_PG_READ_ALL_DATA},
+	{"pg_write_all_data", ROLE_PG_WRITE_ALL_DATA},
+	{"pg_monitor", ROLE_PG_MONITOR},
+	{"pg_read_all_settings", ROLE_PG_READ_ALL_SETTINGS},
+	{"pg_read_all_stats", ROLE_PG_READ_ALL_STATS},
+	{"pg_stat_scan_tables", ROLE_PG_STAT_SCAN_TABLES},
+	{"pg_read_server_files", ROLE_PG_READ_SERVER_FILES},
+	{"pg_write_server_files", ROLE_PG_WRITE_SERVER_FILES},
+	{"pg_execute_server_program", ROLE_PG_EXECUTE_SERVER_PROGRAM},
+	{"pg_signal_backend", ROLE_PG_SIGNAL_BACKEND},
+	{"pg_checkpoint", ROLE_PG_CHECKPOINT},
+	{"pg_maintain", ROLE_PG_MAINTAIN},
+	{"pg_use_reserved_connections", ROLE_PG_USE_RESERVED_CONNECTIONS},
+	{"pg_create_subscription", ROLE_PG_CREATE_SUBSCRIPTION},
+	{"pg_signal_autovacuum_worker", ROLE_PG_SIGNAL_AUTOVACUUM_WORKER}
+};
+
+
 static Datum values[MAXATTR];	/* current row's attribute values */
 static bool Nulls[MAXATTR];
 
@@ -1034,6 +1074,25 @@ boot_get_type_io_data(Oid typid,
 	}
 }
 
+/* ----------------
+ *		boot_get_role_oid
+ *
+ * Look up a role name at bootstrap time.  This is equivalent to
+ * get_role_oid(rolname, true): return the role OID or InvalidOid if
+ * not found.  We only need to cope with built-in role names.
+ * ----------------
+ */
+Oid
+boot_get_role_oid(const char *rolname)
+{
+	for (int i = 0; i < lengthof(RolInfo); i++)
+	{
+		if (strcmp(RolInfo[i].rolname, rolname) == 0)
+			return RolInfo[i].oid;
+	}
+	return InvalidOid;
+}
+
 /* ----------------
  *		AllocateAttribute
  *
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 69699f8830a..1c5b6d6df05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -14,12 +14,8 @@
  * definitions of such functions into pg_proc.dat and then replace them
  * here.  The stub definitions would be unnecessary were it not that we'd
  * like these functions to have stable OIDs, the same as other built-in
- * functions.
- *
- * This file also takes care of adjusting privileges for those functions
- * that should not have the default public-EXECUTE privileges.  (However,
- * a small number of functions that exist mainly to underlie system views
- * are dealt with in system_views.sql, instead.)
+ * functions.  (That's important, for example, to their treatment by
+ * postgres_fdw.)
  *
  * Note: this file is read in single-user -j mode, which means that the
  * command terminator is semicolon-newline-newline; whenever the backend
@@ -376,161 +372,3 @@ CREATE OR REPLACE FUNCTION ts_debug(document text,
 BEGIN ATOMIC
     SELECT * FROM ts_debug(get_current_ts_config(), $1);
 END;
-
-
---
--- The default permissions for functions mean that anyone can execute them.
--- A number of functions shouldn't be executable by just anyone, but rather
--- than use explicit 'superuser()' checks in those functions, we use the GRANT
--- system to REVOKE access to those functions at initdb time.  Administrators
--- can later change who can access these functions, or leave them as only
--- available to superuser / cluster owner, if they choose.
---
-
-REVOKE EXECUTE ON FUNCTION pg_backup_start(text, boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_backup_stop(boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_create_restore_point(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_switch_wal() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_log_standby_snapshot() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_wal_replay_pause() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_wal_replay_resume() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_rotate_logfile() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_reload_conf() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_current_logfile() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_current_logfile(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_promote(boolean, integer) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_shared(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_slru(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_single_table_counters(oid) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_single_function_counters(oid) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_backend_stats(integer) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_replication_slot(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_have_stats(text, oid, int8) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_reset_subscription_stats(oid) FROM public;
-
-REVOKE EXECUTE ON FUNCTION lo_import(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION lo_import(text, oid) FROM public;
-
-REVOKE EXECUTE ON FUNCTION lo_export(oid, text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_logdir() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_waldir() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_archive_statusdir() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_summariesdir() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_tmpdir() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_tmpdir(oid) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_file(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_file(text,boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_file(text,bigint,bigint) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_file(text,bigint,bigint,boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_binary_file(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_binary_file(text,boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_binary_file(text,bigint,bigint) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_read_binary_file(text,bigint,bigint,boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_advance(text, pg_lsn) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_create(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_drop(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_oid(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_progress(text, boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_is_setup() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_progress(boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_reset() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_setup(text, integer) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_xact_reset() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_replication_origin_xact_setup(pg_lsn, timestamp with time zone) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_show_replication_origin_status() FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_file(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_stat_file(text,boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_dir(text) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_dir(text,boolean,boolean) FROM public;
-
-REVOKE EXECUTE ON FUNCTION pg_log_backend_memory_contexts(integer) FROM PUBLIC;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_logicalsnapdir() FROM PUBLIC;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_logicalmapdir() FROM PUBLIC;
-
-REVOKE EXECUTE ON FUNCTION pg_ls_replslotdir(text) FROM PUBLIC;
-
---
--- We also set up some things as accessible to standard roles.
---
-
-GRANT EXECUTE ON FUNCTION pg_ls_logdir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_waldir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_archive_statusdir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_summariesdir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_tmpdir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_tmpdir(oid) TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_logicalsnapdir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_logicalmapdir() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_ls_replslotdir(text) TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_current_logfile() TO pg_monitor;
-
-GRANT EXECUTE ON FUNCTION pg_current_logfile(text) TO pg_monitor;
-
-GRANT pg_read_all_settings TO pg_monitor;
-
-GRANT pg_read_all_stats TO pg_monitor;
-
-GRANT pg_stat_scan_tables TO pg_monitor;
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 1ea8f1faa9e..56106d92eaf 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -650,19 +650,16 @@ CREATE VIEW pg_file_settings AS
    SELECT * FROM pg_show_all_file_settings() AS A;
 
 REVOKE ALL ON pg_file_settings FROM PUBLIC;
-REVOKE EXECUTE ON FUNCTION pg_show_all_file_settings() FROM PUBLIC;
 
 CREATE VIEW pg_hba_file_rules AS
    SELECT * FROM pg_hba_file_rules() AS A;
 
 REVOKE ALL ON pg_hba_file_rules FROM PUBLIC;
-REVOKE EXECUTE ON FUNCTION pg_hba_file_rules() FROM PUBLIC;
 
 CREATE VIEW pg_ident_file_mappings AS
    SELECT * FROM pg_ident_file_mappings() AS A;
 
 REVOKE ALL ON pg_ident_file_mappings FROM PUBLIC;
-REVOKE EXECUTE ON FUNCTION pg_ident_file_mappings() FROM PUBLIC;
 
 CREATE VIEW pg_timezone_abbrevs AS
     SELECT * FROM pg_timezone_abbrevs_zone() z
@@ -679,39 +676,30 @@ CREATE VIEW pg_config AS
     SELECT * FROM pg_config();
 
 REVOKE ALL ON pg_config FROM PUBLIC;
-REVOKE EXECUTE ON FUNCTION pg_config() FROM PUBLIC;
 
 CREATE VIEW pg_shmem_allocations AS
     SELECT * FROM pg_get_shmem_allocations();
 
 REVOKE ALL ON pg_shmem_allocations FROM PUBLIC;
 GRANT SELECT ON pg_shmem_allocations TO pg_read_all_stats;
-REVOKE EXECUTE ON FUNCTION pg_get_shmem_allocations() FROM PUBLIC;
-GRANT EXECUTE ON FUNCTION pg_get_shmem_allocations() TO pg_read_all_stats;
 
 CREATE VIEW pg_shmem_allocations_numa AS
     SELECT * FROM pg_get_shmem_allocations_numa();
 
 REVOKE ALL ON pg_shmem_allocations_numa FROM PUBLIC;
 GRANT SELECT ON pg_shmem_allocations_numa TO pg_read_all_stats;
-REVOKE EXECUTE ON FUNCTION pg_get_shmem_allocations_numa() FROM PUBLIC;
-GRANT EXECUTE ON FUNCTION pg_get_shmem_allocations_numa() TO pg_read_all_stats;
 
 CREATE VIEW pg_dsm_registry_allocations AS
     SELECT * FROM pg_get_dsm_registry_allocations();
 
 REVOKE ALL ON pg_dsm_registry_allocations FROM PUBLIC;
 GRANT SELECT ON pg_dsm_registry_allocations TO pg_read_all_stats;
-REVOKE EXECUTE ON FUNCTION pg_get_dsm_registry_allocations() FROM PUBLIC;
-GRANT EXECUTE ON FUNCTION pg_get_dsm_registry_allocations() TO pg_read_all_stats;
 
 CREATE VIEW pg_backend_memory_contexts AS
     SELECT * FROM pg_get_backend_memory_contexts();
 
 REVOKE ALL ON pg_backend_memory_contexts FROM PUBLIC;
 GRANT SELECT ON pg_backend_memory_contexts TO pg_read_all_stats;
-REVOKE EXECUTE ON FUNCTION pg_get_backend_memory_contexts() FROM PUBLIC;
-GRANT EXECUTE ON FUNCTION pg_get_backend_memory_contexts() TO pg_read_all_stats;
 
 -- Statistics views
 
@@ -1471,5 +1459,3 @@ CREATE VIEW pg_aios AS
     SELECT * FROM pg_get_aios();
 REVOKE ALL ON pg_aios FROM PUBLIC;
 GRANT SELECT ON pg_aios TO pg_read_all_stats;
-REVOKE EXECUTE ON FUNCTION pg_get_aios() FROM PUBLIC;
-GRANT EXECUTE ON FUNCTION pg_get_aios() TO pg_read_all_stats;
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index 641673f0b0e..071e3f2c49e 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -17,6 +17,7 @@
 #include 
 
 #include "access/htup_details.h"
+#include "bootstrap/bootstrap.h"
 #include "catalog/catalog.h"
 #include "catalog/namespace.h"
 #include "catalog/pg_auth_members.h"
@@ -261,6 +262,9 @@ putid(char *p, const char *s)
  *		This routine is called by the parser as well as aclitemin(), hence
  *		the added generality.
  *
+ *		In bootstrap mode, we consult a hard-wired list of role names
+ *		(see bootstrap.c) rather than trying to access the catalogs.
+ *
  * RETURNS:
  *		the string position in 's' immediately following the ACL
  *		specification.  Also:
@@ -376,7 +380,10 @@ aclparse(const char *s, AclItem *aip, Node *escontext)
 		aip->ai_grantee = ACL_ID_PUBLIC;
 	else
 	{
-		aip->ai_grantee = get_role_oid(name, true);
+		if (IsBootstrapProcessingMode())
+			aip->ai_grantee = boot_get_role_oid(name);
+		else
+			aip->ai_grantee = get_role_oid(name, true);
 		if (!OidIsValid(aip->ai_grantee))
 			ereturn(escontext, NULL,
 					(errcode(ERRCODE_UNDEFINED_OBJECT),
@@ -385,7 +392,8 @@ aclparse(const char *s, AclItem *aip, Node *escontext)
 
 	/*
 	 * XXX Allow a degree of backward compatibility by defaulting the grantor
-	 * to the superuser.
+	 * to the superuser.  We condone that practice in the catalog .dat files
+	 * (i.e., in bootstrap mode) for brevity; otherwise, issue a warning.
 	 */
 	if (*s == '/')
 	{
@@ -396,7 +404,10 @@ aclparse(const char *s, AclItem *aip, Node *escontext)
 			ereturn(escontext, NULL,
 					(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
 					 errmsg("a name must follow the \"/\" sign")));
-		aip->ai_grantor = get_role_oid(name2, true);
+		if (IsBootstrapProcessingMode())
+			aip->ai_grantor = boot_get_role_oid(name2);
+		else
+			aip->ai_grantor = get_role_oid(name2, true);
 		if (!OidIsValid(aip->ai_grantor))
 			ereturn(escontext, NULL,
 					(errcode(ERRCODE_UNDEFINED_OBJECT),
@@ -405,10 +416,11 @@ aclparse(const char *s, AclItem *aip, Node *escontext)
 	else
 	{
 		aip->ai_grantor = BOOTSTRAP_SUPERUSERID;
-		ereport(WARNING,
-				(errcode(ERRCODE_INVALID_GRANTOR),
-				 errmsg("defaulting grantor to user ID %u",
-						BOOTSTRAP_SUPERUSERID)));
+		if (!IsBootstrapProcessingMode())
+			ereport(WARNING,
+					(errcode(ERRCODE_INVALID_GRANTOR),
+					 errmsg("defaulting grantor to user ID %u",
+							BOOTSTRAP_SUPERUSERID)));
 	}
 
 	ACLITEM_SET_PRIVS_GOPTIONS(*aip, privs, goption);
diff --git a/src/include/bootstrap/bootstrap.h b/src/include/bootstrap/bootstrap.h
index 21447a3d661..e967b2b1885 100644
--- a/src/include/bootstrap/bootstrap.h
+++ b/src/include/bootstrap/bootstrap.h
@@ -56,6 +56,8 @@ extern void boot_get_type_io_data(Oid typid,
 								  Oid *typoutput,
 								  Oid *typcollation);
 
+extern Oid	boot_get_role_oid(const char *rolname);
+
 union YYSTYPE;
 typedef void *yyscan_t;
 
diff --git a/src/include/catalog/Makefile b/src/include/catalog/Makefile
index 24b527230d4..444fc76eed6 100644
--- a/src/include/catalog/Makefile
+++ b/src/include/catalog/Makefile
@@ -94,6 +94,7 @@ POSTGRES_BKI_DATA = \
 	pg_amop.dat \
 	pg_amproc.dat \
 	pg_authid.dat \
+	pg_auth_members.dat \
 	pg_cast.dat \
 	pg_class.dat \
 	pg_collation.dat \
diff --git a/src/include/catalog/meson.build b/src/include/catalog/meson.build
index 433bcc908ad..bcc01c87c2e 100644
--- a/src/include/catalog/meson.build
+++ b/src/include/catalog/meson.build
@@ -78,6 +78,7 @@ bki_data = [
   'pg_amop.dat',
   'pg_amproc.dat',
   'pg_authid.dat',
+  'pg_auth_members.dat',
   'pg_cast.dat',
   'pg_class.dat',
   'pg_collation.dat',
diff --git a/src/include/catalog/pg_auth_members.dat b/src/include/catalog/pg_auth_members.dat
new file mode 100644
index 00000000000..246373251d4
--- /dev/null
+++ b/src/include/catalog/pg_auth_members.dat
@@ -0,0 +1,20 @@
+#----------------------------------------------------------------------
+#
+# pg_auth_members.dat
+#    Initial contents of the pg_auth_members system catalog.
+#
+# Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
+# Portions Copyright (c) 1994, Regents of the University of California
+#
+# src/include/catalog/pg_auth_members.dat
+#
+#----------------------------------------------------------------------
+
+[
+
+# We grant these roles to pg_monitor.
+{ roleid => 'pg_read_all_settings', member => 'pg_monitor' },
+{ roleid => 'pg_read_all_stats', member => 'pg_monitor' },
+{ roleid => 'pg_stat_scan_tables', member => 'pg_monitor' },
+
+]
diff --git a/src/include/catalog/pg_auth_members.h b/src/include/catalog/pg_auth_members.h
index 92cf5271496..15806df95bf 100644
--- a/src/include/catalog/pg_auth_members.h
+++ b/src/include/catalog/pg_auth_members.h
@@ -29,13 +29,26 @@
  */
 CATALOG(pg_auth_members,1261,AuthMemRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(2843,AuthMemRelation_Rowtype_Id) BKI_SCHEMA_MACRO
 {
-	Oid			oid;			/* oid */
-	Oid			roleid BKI_LOOKUP(pg_authid);	/* ID of a role */
-	Oid			member BKI_LOOKUP(pg_authid);	/* ID of a member of that role */
-	Oid			grantor BKI_LOOKUP(pg_authid);	/* who granted the membership */
-	bool		admin_option;	/* granted with admin option? */
-	bool		inherit_option; /* exercise privileges without SET ROLE? */
-	bool		set_option;		/* use SET ROLE to the target role? */
+	/* OID for this record (needed for dependencies) */
+	Oid			oid;
+
+	/* ID of a role */
+	Oid			roleid BKI_LOOKUP(pg_authid);
+
+	/* ID of a member of that role */
+	Oid			member BKI_LOOKUP(pg_authid);
+
+	/* who granted the membership */
+	Oid			grantor BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
+
+	/* granted with admin option? */
+	bool		admin_option BKI_DEFAULT(f);
+
+	/* exercise privileges without SET ROLE? */
+	bool		inherit_option BKI_DEFAULT(t);
+
+	/* use SET ROLE to the target role? */
+	bool		set_option BKI_DEFAULT(t);
 } FormData_pg_auth_members;
 
 /* ----------------
diff --git a/src/include/catalog/pg_authid.dat b/src/include/catalog/pg_authid.dat
index 26b5c9971a4..2960707c729 100644
--- a/src/include/catalog/pg_authid.dat
+++ b/src/include/catalog/pg_authid.dat
@@ -16,8 +16,10 @@
 # so make sure every entry has an oid_symbol value.
 
 # The bootstrap superuser is named POSTGRES according to this data and
-# according to BKI_DEFAULT entries in other catalogs.  However, initdb
-# will replace that at database initialization time.
+# according to BKI_DEFAULT entries and ACL entries in other catalogs.
+# initdb will replace that at database initialization time for standalone
+# references (the rolname below and various owner-OID columns), while
+# boot_get_role_oid() deals with it for ACL entries.
 
 { oid => '10', oid_symbol => 'BOOTSTRAP_SUPERUSERID',
   rolname => 'POSTGRES', rolsuper => 't', rolinherit => 't',
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index dac40992cbc..4950bff2804 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -1822,14 +1822,17 @@
 
 { oid => '764', descr => 'large object import',
   proname => 'lo_import', provolatile => 'v', proparallel => 'u',
-  prorettype => 'oid', proargtypes => 'text', prosrc => 'be_lo_import' },
+  prorettype => 'oid', proargtypes => 'text', prosrc => 'be_lo_import',
+  proacl => '{POSTGRES=X}' },
 { oid => '767', descr => 'large object import',
   proname => 'lo_import', provolatile => 'v', proparallel => 'u',
   prorettype => 'oid', proargtypes => 'text oid',
-  prosrc => 'be_lo_import_with_oid' },
+  prosrc => 'be_lo_import_with_oid',
+  proacl => '{POSTGRES=X}' },
 { oid => '765', descr => 'large object export',
   proname => 'lo_export', provolatile => 'v', proparallel => 'u',
-  prorettype => 'int4', proargtypes => 'oid text', prosrc => 'be_lo_export' },
+  prorettype => 'int4', proargtypes => 'oid text', prosrc => 'be_lo_export',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '766', descr => 'increment',
   proname => 'int4inc', prorettype => 'int4', proargtypes => 'int4',
@@ -5709,7 +5712,8 @@
 { oid => '6230', descr => 'statistics: check if a stats object exists',
   proname => 'pg_stat_have_stats', provolatile => 'v', proparallel => 'r',
   prorettype => 'bool', proargtypes => 'text oid int8',
-  prosrc => 'pg_stat_have_stats' },
+  prosrc => 'pg_stat_have_stats',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '6231', descr => 'statistics: information about subscription stats',
   proname => 'pg_stat_get_subscription_stats', provolatile => 's',
@@ -6170,43 +6174,51 @@
 { oid => '2274',
   descr => 'statistics: reset collected statistics for current database',
   proname => 'pg_stat_reset', proisstrict => 'f', provolatile => 'v',
-  prorettype => 'void', proargtypes => '', prosrc => 'pg_stat_reset' },
+  prorettype => 'void', proargtypes => '', prosrc => 'pg_stat_reset',
+  proacl => '{POSTGRES=X}' },
 { oid => '3775',
   descr => 'statistics: reset collected statistics shared across the cluster',
   proname => 'pg_stat_reset_shared', proisstrict => 'f', provolatile => 'v',
   prorettype => 'void', proargtypes => 'text',
   proargnames => '{target}', proargdefaults => '{NULL}',
-  prosrc => 'pg_stat_reset_shared' },
+  prosrc => 'pg_stat_reset_shared',
+  proacl => '{POSTGRES=X}' },
 { oid => '3776',
   descr => 'statistics: reset collected statistics for a single table or index in the current database or shared across all databases in the cluster',
   proname => 'pg_stat_reset_single_table_counters', provolatile => 'v',
   prorettype => 'void', proargtypes => 'oid',
-  prosrc => 'pg_stat_reset_single_table_counters' },
+  prosrc => 'pg_stat_reset_single_table_counters',
+  proacl => '{POSTGRES=X}' },
 { oid => '3777',
   descr => 'statistics: reset collected statistics for a single function in the current database',
   proname => 'pg_stat_reset_single_function_counters', provolatile => 'v',
   prorettype => 'void', proargtypes => 'oid',
-  prosrc => 'pg_stat_reset_single_function_counters' },
+  prosrc => 'pg_stat_reset_single_function_counters',
+  proacl => '{POSTGRES=X}' },
 { oid => '6387', descr => 'statistics: reset statistics for a single backend',
   proname => 'pg_stat_reset_backend_stats', provolatile => 'v',
   prorettype => 'void', proargtypes => 'int4',
-  prosrc => 'pg_stat_reset_backend_stats' },
+  prosrc => 'pg_stat_reset_backend_stats',
+  proacl => '{POSTGRES=X}' },
 { oid => '2307',
   descr => 'statistics: reset collected statistics for a single SLRU',
   proname => 'pg_stat_reset_slru', proisstrict => 'f', provolatile => 'v',
   prorettype => 'void', proargtypes => 'text', proargnames => '{target}',
   proargdefaults => '{NULL}',
-  prosrc => 'pg_stat_reset_slru' },
+  prosrc => 'pg_stat_reset_slru',
+  proacl => '{POSTGRES=X}' },
 { oid => '6170',
   descr => 'statistics: reset collected statistics for a single replication slot',
   proname => 'pg_stat_reset_replication_slot', proisstrict => 'f',
   provolatile => 'v', prorettype => 'void', proargtypes => 'text',
-  prosrc => 'pg_stat_reset_replication_slot' },
+  prosrc => 'pg_stat_reset_replication_slot',
+  proacl => '{POSTGRES=X}' },
 { oid => '6232',
   descr => 'statistics: reset collected statistics for a single subscription',
   proname => 'pg_stat_reset_subscription_stats', proisstrict => 'f',
   provolatile => 'v', prorettype => 'void', proargtypes => 'oid',
-  prosrc => 'pg_stat_reset_subscription_stats' },
+  prosrc => 'pg_stat_reset_subscription_stats',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '3163', descr => 'current trigger depth',
   proname => 'pg_trigger_depth', provolatile => 's', proparallel => 'r',
@@ -6553,21 +6565,24 @@
   proallargtypes => '{text,int4,int4,text,text,bool,text}',
   proargmodes => '{o,o,o,o,o,o,o}',
   proargnames => '{sourcefile,sourceline,seqno,name,setting,applied,error}',
-  prosrc => 'show_all_file_settings' },
+  prosrc => 'show_all_file_settings',
+  proacl => '{POSTGRES=X}' },
 { oid => '3401', descr => 'show pg_hba.conf rules',
   proname => 'pg_hba_file_rules', prorows => '1000', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{int4,text,int4,text,_text,_text,text,text,text,_text,text}',
   proargmodes => '{o,o,o,o,o,o,o,o,o,o,o}',
   proargnames => '{rule_number,file_name,line_number,type,database,user_name,address,netmask,auth_method,options,error}',
-  prosrc => 'pg_hba_file_rules' },
+  prosrc => 'pg_hba_file_rules',
+  proacl => '{POSTGRES=X}' },
 { oid => '6250', descr => 'show pg_ident.conf mappings',
   proname => 'pg_ident_file_mappings', prorows => '1000', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{int4,text,int4,text,text,text,text}',
   proargmodes => '{o,o,o,o,o,o,o}',
   proargnames => '{map_number,file_name,line_number,map_name,sys_name,pg_username,error}',
-  prosrc => 'pg_ident_file_mappings' },
+  prosrc => 'pg_ident_file_mappings',
+  proacl => '{POSTGRES=X}' },
 { oid => '1371', descr => 'view system lock information',
   proname => 'pg_lock_status', prorows => '1000', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => '',
@@ -6737,30 +6752,36 @@
   proname => 'pg_backup_start', provolatile => 'v', proparallel => 'r',
   prorettype => 'pg_lsn', proargtypes => 'text bool',
   proargnames => '{label,fast}', proargdefaults => '{false}',
-  prosrc => 'pg_backup_start' },
+  prosrc => 'pg_backup_start',
+  proacl => '{POSTGRES=X}' },
 { oid => '2739', descr => 'finish taking an online backup',
   proname => 'pg_backup_stop', provolatile => 'v', proparallel => 'r',
   prorettype => 'record', proargtypes => 'bool',
   proallargtypes => '{bool,pg_lsn,text,text}', proargmodes => '{i,o,o,o}',
   proargnames => '{wait_for_archive,lsn,labelfile,spcmapfile}',
   proargdefaults => '{true}',
-  prosrc => 'pg_backup_stop' },
+  prosrc => 'pg_backup_stop',
+  proacl => '{POSTGRES=X}' },
 { oid => '3436', descr => 'promote standby server',
   proname => 'pg_promote', provolatile => 'v', prorettype => 'bool',
   proargtypes => 'bool int4', proargnames => '{wait,wait_seconds}',
   proargdefaults => '{true,60}',
-  prosrc => 'pg_promote' },
+  prosrc => 'pg_promote',
+  proacl => '{POSTGRES=X}' },
 { oid => '2848', descr => 'switch to new wal file',
   proname => 'pg_switch_wal', provolatile => 'v', prorettype => 'pg_lsn',
-  proargtypes => '', prosrc => 'pg_switch_wal' },
+  proargtypes => '', prosrc => 'pg_switch_wal',
+  proacl => '{POSTGRES=X}' },
 { oid => '6305', descr => 'log details of the current snapshot to WAL',
   proname => 'pg_log_standby_snapshot', provolatile => 'v',
   prorettype => 'pg_lsn', proargtypes => '',
-  prosrc => 'pg_log_standby_snapshot' },
+  prosrc => 'pg_log_standby_snapshot',
+  proacl => '{POSTGRES=X}' },
 { oid => '3098', descr => 'create a named restore point',
   proname => 'pg_create_restore_point', provolatile => 'v',
   prorettype => 'pg_lsn', proargtypes => 'text',
-  prosrc => 'pg_create_restore_point' },
+  prosrc => 'pg_create_restore_point',
+  proacl => '{POSTGRES=X}' },
 { oid => '2849', descr => 'current wal write location',
   proname => 'pg_current_wal_lsn', provolatile => 'v', prorettype => 'pg_lsn',
   proargtypes => '', prosrc => 'pg_current_wal_lsn' },
@@ -6816,10 +6837,12 @@
 
 { oid => '3071', descr => 'pause wal replay',
   proname => 'pg_wal_replay_pause', provolatile => 'v', prorettype => 'void',
-  proargtypes => '', prosrc => 'pg_wal_replay_pause' },
+  proargtypes => '', prosrc => 'pg_wal_replay_pause',
+  proacl => '{POSTGRES=X}' },
 { oid => '3072', descr => 'resume wal replay, if it was paused',
   proname => 'pg_wal_replay_resume', provolatile => 'v', prorettype => 'void',
-  proargtypes => '', prosrc => 'pg_wal_replay_resume' },
+  proargtypes => '', prosrc => 'pg_wal_replay_resume',
+  proacl => '{POSTGRES=X}' },
 { oid => '3073', descr => 'true if wal replay is paused',
   proname => 'pg_is_wal_replay_paused', provolatile => 'v',
   prorettype => 'bool', proargtypes => '',
@@ -6845,17 +6868,21 @@
 
 { oid => '2621', descr => 'reload configuration files',
   proname => 'pg_reload_conf', provolatile => 'v', prorettype => 'bool',
-  proargtypes => '', prosrc => 'pg_reload_conf' },
+  proargtypes => '', prosrc => 'pg_reload_conf',
+  proacl => '{POSTGRES=X}' },
 { oid => '2622', descr => 'rotate log file',
   proname => 'pg_rotate_logfile', provolatile => 'v', prorettype => 'bool',
-  proargtypes => '', prosrc => 'pg_rotate_logfile' },
+  proargtypes => '', prosrc => 'pg_rotate_logfile',
+  proacl => '{POSTGRES=X}' },
 { oid => '3800', descr => 'current logging collector file location',
   proname => 'pg_current_logfile', proisstrict => 'f', provolatile => 'v',
-  prorettype => 'text', proargtypes => '', prosrc => 'pg_current_logfile' },
+  prorettype => 'text', proargtypes => '', prosrc => 'pg_current_logfile',
+  proacl => '{POSTGRES=X,pg_monitor=X}' },
 { oid => '3801', descr => 'current logging collector file location',
   proname => 'pg_current_logfile', proisstrict => 'f', provolatile => 'v',
   prorettype => 'text', proargtypes => 'text',
-  prosrc => 'pg_current_logfile_1arg' },
+  prosrc => 'pg_current_logfile_1arg',
+  proacl => '{POSTGRES=X,pg_monitor=X}' },
 
 { oid => '2623', descr => 'get information about file',
   proname => 'pg_stat_file', provolatile => 'v', prorettype => 'record',
@@ -6863,48 +6890,60 @@
   proallargtypes => '{text,int8,timestamptz,timestamptz,timestamptz,timestamptz,bool}',
   proargmodes => '{i,o,o,o,o,o,o}',
   proargnames => '{filename,size,access,modification,change,creation,isdir}',
-  prosrc => 'pg_stat_file_1arg' },
+  prosrc => 'pg_stat_file_1arg',
+  proacl => '{POSTGRES=X}' },
 { oid => '3307', descr => 'get information about file',
   proname => 'pg_stat_file', provolatile => 'v', prorettype => 'record',
   proargtypes => 'text bool',
   proallargtypes => '{text,bool,int8,timestamptz,timestamptz,timestamptz,timestamptz,bool}',
   proargmodes => '{i,i,o,o,o,o,o,o}',
   proargnames => '{filename,missing_ok,size,access,modification,change,creation,isdir}',
-  prosrc => 'pg_stat_file' },
+  prosrc => 'pg_stat_file',
+  proacl => '{POSTGRES=X}' },
 { oid => '2624', descr => 'read text from a file',
   proname => 'pg_read_file', provolatile => 'v', prorettype => 'text',
-  proargtypes => 'text int8 int8', prosrc => 'pg_read_file_off_len' },
+  proargtypes => 'text int8 int8', prosrc => 'pg_read_file_off_len',
+  proacl => '{POSTGRES=X}' },
 { oid => '3293', descr => 'read text from a file',
   proname => 'pg_read_file', provolatile => 'v', prorettype => 'text',
   proargtypes => 'text int8 int8 bool',
-  prosrc => 'pg_read_file_off_len_missing' },
+  prosrc => 'pg_read_file_off_len_missing',
+  proacl => '{POSTGRES=X}' },
 { oid => '3826', descr => 'read text from a file',
   proname => 'pg_read_file', provolatile => 'v', prorettype => 'text',
-  proargtypes => 'text', prosrc => 'pg_read_file_all' },
+  proargtypes => 'text', prosrc => 'pg_read_file_all',
+  proacl => '{POSTGRES=X}' },
 { oid => '6208', descr => 'read text from a file',
   proname => 'pg_read_file', provolatile => 'v', prorettype => 'text',
-  proargtypes => 'text bool', prosrc => 'pg_read_file_all_missing' },
+  proargtypes => 'text bool', prosrc => 'pg_read_file_all_missing',
+  proacl => '{POSTGRES=X}' },
 { oid => '3827', descr => 'read bytea from a file',
   proname => 'pg_read_binary_file', provolatile => 'v', prorettype => 'bytea',
-  proargtypes => 'text int8 int8', prosrc => 'pg_read_binary_file_off_len' },
+  proargtypes => 'text int8 int8', prosrc => 'pg_read_binary_file_off_len',
+  proacl => '{POSTGRES=X}' },
 { oid => '3295', descr => 'read bytea from a file',
   proname => 'pg_read_binary_file', provolatile => 'v', prorettype => 'bytea',
   proargtypes => 'text int8 int8 bool',
-  prosrc => 'pg_read_binary_file_off_len_missing' },
+  prosrc => 'pg_read_binary_file_off_len_missing',
+  proacl => '{POSTGRES=X}' },
 { oid => '3828', descr => 'read bytea from a file',
   proname => 'pg_read_binary_file', provolatile => 'v', prorettype => 'bytea',
-  proargtypes => 'text', prosrc => 'pg_read_binary_file_all' },
+  proargtypes => 'text', prosrc => 'pg_read_binary_file_all',
+  proacl => '{POSTGRES=X}' },
 { oid => '6209', descr => 'read bytea from a file',
   proname => 'pg_read_binary_file', provolatile => 'v', prorettype => 'bytea',
-  proargtypes => 'text bool', prosrc => 'pg_read_binary_file_all_missing' },
+  proargtypes => 'text bool', prosrc => 'pg_read_binary_file_all_missing',
+  proacl => '{POSTGRES=X}' },
 { oid => '2625', descr => 'list all files in a directory',
   proname => 'pg_ls_dir', prorows => '1000', proretset => 't',
   provolatile => 'v', prorettype => 'text', proargtypes => 'text',
-  prosrc => 'pg_ls_dir_1arg' },
+  prosrc => 'pg_ls_dir_1arg',
+  proacl => '{POSTGRES=X}' },
 { oid => '3297', descr => 'list all files in a directory',
   proname => 'pg_ls_dir', prorows => '1000', proretset => 't',
   provolatile => 'v', prorettype => 'text', proargtypes => 'text bool bool',
-  prosrc => 'pg_ls_dir' },
+  prosrc => 'pg_ls_dir',
+  proacl => '{POSTGRES=X}' },
 { oid => '2626', descr => 'sleep for the specified time in seconds',
   proname => 'pg_sleep', provolatile => 'v', prorettype => 'void',
   proargtypes => 'float8', prosrc => 'pg_sleep' },
@@ -8602,7 +8641,8 @@
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,int8,int8,int8}', proargmodes => '{o,o,o,o}',
   proargnames => '{name,off,size,allocated_size}',
-  prosrc => 'pg_get_shmem_allocations' },
+  prosrc => 'pg_get_shmem_allocations',
+  proacl => '{POSTGRES=X,pg_read_all_stats=X}' },
 
 { oid => '4099', descr => 'Is NUMA support available?',
   proname => 'pg_numa_available', provolatile => 's', prorettype => 'bool',
@@ -8614,7 +8654,8 @@
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,int4,int8}', proargmodes => '{o,o,o}',
   proargnames => '{name,numa_node,size}',
-  prosrc => 'pg_get_shmem_allocations_numa' },
+  prosrc => 'pg_get_shmem_allocations_numa',
+  proacl => '{POSTGRES=X,pg_read_all_stats=X}' },
 
 { oid => '9314',
   descr => 'shared memory allocations tracked in the DSM registry',
@@ -8622,7 +8663,8 @@
   proretset => 't', provolatile => 'v', prorettype => 'record',
   proargtypes => '', proallargtypes => '{text,text,int8}',
   proargmodes => '{o,o,o}', proargnames => '{name,type,size}',
-  prosrc => 'pg_get_dsm_registry_allocations' },
+  prosrc => 'pg_get_dsm_registry_allocations',
+  proacl => '{POSTGRES=X,pg_read_all_stats=X}' },
 
 # memory context of local backend
 { oid => '2282',
@@ -8633,13 +8675,15 @@
   proallargtypes => '{text,text,text,int4,_int4,int8,int8,int8,int8,int8}',
   proargmodes => '{o,o,o,o,o,o,o,o,o,o}',
   proargnames => '{name, ident, type, level, path, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes}',
-  prosrc => 'pg_get_backend_memory_contexts' },
+  prosrc => 'pg_get_backend_memory_contexts',
+  proacl => '{POSTGRES=X,pg_read_all_stats=X}' },
 
 # logging memory contexts of the specified backend
 { oid => '4543', descr => 'log memory contexts of the specified backend',
   proname => 'pg_log_backend_memory_contexts', provolatile => 'v',
   prorettype => 'bool', proargtypes => 'int4',
-  prosrc => 'pg_log_backend_memory_contexts' },
+  prosrc => 'pg_log_backend_memory_contexts',
+  proacl => '{POSTGRES=X}' },
 
 # non-persistent series generator
 { oid => '1066', descr => 'non-persistent series generator',
@@ -12312,63 +12356,74 @@
 { oid => '6003', descr => 'create a replication origin',
   proname => 'pg_replication_origin_create', provolatile => 'v',
   proparallel => 'u', prorettype => 'oid', proargtypes => 'text',
-  prosrc => 'pg_replication_origin_create' },
+  prosrc => 'pg_replication_origin_create',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '6004', descr => 'drop replication origin identified by its name',
   proname => 'pg_replication_origin_drop', provolatile => 'v',
   proparallel => 'u', prorettype => 'void', proargtypes => 'text',
-  prosrc => 'pg_replication_origin_drop' },
+  prosrc => 'pg_replication_origin_drop',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '6005',
   descr => 'translate the replication origin\'s name to its id',
   proname => 'pg_replication_origin_oid', provolatile => 's',
   prorettype => 'oid', proargtypes => 'text',
-  prosrc => 'pg_replication_origin_oid' },
+  prosrc => 'pg_replication_origin_oid',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '6006',
   descr => 'configure session to maintain replication progress tracking for the passed in origin',
   proname => 'pg_replication_origin_session_setup', provolatile => 'v',
   proparallel => 'u', prorettype => 'void', proargtypes => 'text int4',
   proargnames => '{node_name,pid}', proargdefaults => '{0}',
-  prosrc => 'pg_replication_origin_session_setup' },
+  prosrc => 'pg_replication_origin_session_setup',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '6007', descr => 'teardown configured replication progress tracking',
   proname => 'pg_replication_origin_session_reset', provolatile => 'v',
   proparallel => 'u', prorettype => 'void', proargtypes => '',
-  prosrc => 'pg_replication_origin_session_reset' },
+  prosrc => 'pg_replication_origin_session_reset',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '6008',
   descr => 'is a replication origin configured in this session',
   proname => 'pg_replication_origin_session_is_setup', provolatile => 'v',
   proparallel => 'r', prorettype => 'bool', proargtypes => '',
-  prosrc => 'pg_replication_origin_session_is_setup' },
+  prosrc => 'pg_replication_origin_session_is_setup',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '6009',
   descr => 'get the replication progress of the current session',
   proname => 'pg_replication_origin_session_progress', provolatile => 'v',
   proparallel => 'u', prorettype => 'pg_lsn', proargtypes => 'bool',
-  prosrc => 'pg_replication_origin_session_progress' },
+  prosrc => 'pg_replication_origin_session_progress',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '6010', descr => 'setup the transaction\'s origin lsn and timestamp',
   proname => 'pg_replication_origin_xact_setup', provolatile => 'v',
   proparallel => 'r', prorettype => 'void', proargtypes => 'pg_lsn timestamptz',
-  prosrc => 'pg_replication_origin_xact_setup' },
+  prosrc => 'pg_replication_origin_xact_setup',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '6011', descr => 'reset the transaction\'s origin lsn and timestamp',
   proname => 'pg_replication_origin_xact_reset', provolatile => 'v',
   proparallel => 'r', prorettype => 'void', proargtypes => '',
-  prosrc => 'pg_replication_origin_xact_reset' },
+  prosrc => 'pg_replication_origin_xact_reset',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '6012', descr => 'advance replication origin to specific location',
   proname => 'pg_replication_origin_advance', provolatile => 'v',
   proparallel => 'u', prorettype => 'void', proargtypes => 'text pg_lsn',
-  prosrc => 'pg_replication_origin_advance' },
+  prosrc => 'pg_replication_origin_advance',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '6013',
   descr => 'get an individual replication origin\'s replication progress',
   proname => 'pg_replication_origin_progress', provolatile => 'v',
   proparallel => 'u', prorettype => 'pg_lsn', proargtypes => 'text bool',
-  prosrc => 'pg_replication_origin_progress' },
+  prosrc => 'pg_replication_origin_progress',
+  proacl => '{POSTGRES=X}' },
 
 { oid => '6014', descr => 'get progress for all replication origins',
   proname => 'pg_show_replication_origin_status', prorows => '100',
@@ -12376,7 +12431,8 @@
   prorettype => 'record', proargtypes => '',
   proallargtypes => '{oid,text,pg_lsn,pg_lsn}', proargmodes => '{o,o,o,o}',
   proargnames => '{local_id, external_id, remote_lsn, local_lsn}',
-  prosrc => 'pg_show_replication_origin_status' },
+  prosrc => 'pg_show_replication_origin_status',
+  proacl => '{POSTGRES=X}' },
 
 # publications
 { oid => '6119',
@@ -12414,7 +12470,8 @@
   proname => 'pg_config', prorows => '23', proretset => 't', provolatile => 's',
   proparallel => 'r', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,text}', proargmodes => '{o,o}',
-  proargnames => '{name,setting}', prosrc => 'pg_config' },
+  proargnames => '{name,setting}', prosrc => 'pg_config',
+  proacl => '{POSTGRES=X}' },
 
 # pg_controldata related functions
 { oid => '3441',
@@ -12489,49 +12546,57 @@
   proname => 'pg_ls_logdir', procost => '10', prorows => '20', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,int8,timestamptz}', proargmodes => '{o,o,o}',
-  proargnames => '{name,size,modification}', prosrc => 'pg_ls_logdir' },
+  proargnames => '{name,size,modification}', prosrc => 'pg_ls_logdir',
+  proacl => '{POSTGRES=X,pg_monitor=X}' },
 { oid => '3354', descr => 'list of files in the WAL directory',
   proname => 'pg_ls_waldir', procost => '10', prorows => '20', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,int8,timestamptz}', proargmodes => '{o,o,o}',
-  proargnames => '{name,size,modification}', prosrc => 'pg_ls_waldir' },
+  proargnames => '{name,size,modification}', prosrc => 'pg_ls_waldir',
+  proacl => '{POSTGRES=X,pg_monitor=X}' },
 { oid => '6400', descr => 'list of files in the pg_wal/summaries directory',
   proname => 'pg_ls_summariesdir', procost => '10', prorows => '20',
   proretset => 't', provolatile => 'v', prorettype => 'record',
   proargtypes => '', proallargtypes => '{text,int8,timestamptz}',
   proargmodes => '{o,o,o}', proargnames => '{name,size,modification}',
-  prosrc => 'pg_ls_summariesdir' },
+  prosrc => 'pg_ls_summariesdir',
+  proacl => '{POSTGRES=X,pg_monitor=X}' },
 { oid => '5031', descr => 'list of files in the archive_status directory',
   proname => 'pg_ls_archive_statusdir', procost => '10', prorows => '20',
   proretset => 't', provolatile => 'v', prorettype => 'record',
   proargtypes => '', proallargtypes => '{text,int8,timestamptz}',
   proargmodes => '{o,o,o}', proargnames => '{name,size,modification}',
-  prosrc => 'pg_ls_archive_statusdir' },
+  prosrc => 'pg_ls_archive_statusdir',
+  proacl => '{POSTGRES=X,pg_monitor=X}' },
 { oid => '5029', descr => 'list files in the pgsql_tmp directory',
   proname => 'pg_ls_tmpdir', procost => '10', prorows => '20', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,int8,timestamptz}', proargmodes => '{o,o,o}',
-  proargnames => '{name,size,modification}', prosrc => 'pg_ls_tmpdir_noargs' },
+  proargnames => '{name,size,modification}', prosrc => 'pg_ls_tmpdir_noargs',
+  proacl => '{POSTGRES=X,pg_monitor=X}' },
 { oid => '5030', descr => 'list files in the pgsql_tmp directory',
   proname => 'pg_ls_tmpdir', procost => '10', prorows => '20', proretset => 't',
   provolatile => 'v', prorettype => 'record', proargtypes => 'oid',
   proallargtypes => '{oid,text,int8,timestamptz}', proargmodes => '{i,o,o,o}',
   proargnames => '{tablespace,name,size,modification}',
-  prosrc => 'pg_ls_tmpdir_1arg' },
+  prosrc => 'pg_ls_tmpdir_1arg',
+  proacl => '{POSTGRES=X,pg_monitor=X}' },
 { oid => '6270',
   descr => 'list of files in the pg_logical/snapshots directory',
   proname => 'pg_ls_logicalsnapdir', procost => '10', prorows => '20',
   proretset => 't', provolatile => 'v', prorettype => 'record',
   proargtypes => '', proallargtypes => '{text,int8,timestamptz}',
   proargmodes => '{o,o,o}', proargnames => '{name,size,modification}',
-  prosrc => 'pg_ls_logicalsnapdir' },
+  prosrc => 'pg_ls_logicalsnapdir',
+  proacl => '{POSTGRES=X,pg_monitor=X}' },
 { oid => '6271',
   descr => 'list of files in the pg_logical/mappings directory',
   proname => 'pg_ls_logicalmapdir', procost => '10', prorows => '20',
   proretset => 't', provolatile => 'v', prorettype => 'record',
   proargtypes => '', proallargtypes => '{text,int8,timestamptz}',
   proargmodes => '{o,o,o}', proargnames => '{name,size,modification}',
-  prosrc => 'pg_ls_logicalmapdir' },
+  prosrc => 'pg_ls_logicalmapdir',
+  proacl => '{POSTGRES=X,pg_monitor=X}' },
 { oid => '6272',
   descr => 'list of files in the pg_replslot/slot_name directory',
   proname => 'pg_ls_replslotdir', procost => '10', prorows => '20',
@@ -12539,7 +12604,8 @@
   proargtypes => 'text', proallargtypes => '{text,text,int8,timestamptz}',
   proargmodes => '{i,o,o,o}',
   proargnames => '{slot_name,name,size,modification}',
-  prosrc => 'pg_ls_replslotdir' },
+  prosrc => 'pg_ls_replslotdir',
+  proacl => '{POSTGRES=X,pg_monitor=X}' },
 
 # hash partitioning constraint function
 { oid => '5028', descr => 'hash partition CHECK constraint',
@@ -12702,7 +12768,8 @@
   proallargtypes => '{int4,int4,int8,text,text,int8,int8,text,int2,int4,text,text,bool,bool,bool}',
   proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
   proargnames => '{pid,io_id,io_generation,state,operation,off,length,target,handle_data_len,raw_result,result,target_desc,f_sync,f_localmem,f_buffered}',
-  prosrc => 'pg_get_aios' },
+  prosrc => 'pg_get_aios',
+  proacl => '{POSTGRES=X,pg_read_all_stats=X}' },
 
 # oid8 related functions
 { oid => '8255', descr => 'convert oid to oid8',
-- 
2.43.7

Re: generating function default settings from pg_proc.dat

От:
Álvaro Herrera <alvherre@kurilemu.de>
Дата:
On 2026-Feb-19, Tom Lane wrote:

> After sleeping on it, I decided that much of the cognitive dissonance
> here comes from the fact that elsewhere in the catalog data files
> we represent the bootstrap user's name as POSTGRES, making it more
> obvious that that's a placeholder and not the real value.  If we do
> that here and also drop the redundant grantor specifications, we get
> 
> +  proacl => '{POSTGRES=X,pg_read_all_stats=X}' },
> 
> which is still not the world's prettiest notation, but it feels
> manageable for this purpose.

Yeah, I like this better, for exactly that reason -- looking at the
previous one I was worried that my setup would no longer work or behave
differently, because my PG superusers are all called something not
"postgres", and on first sight these ACL lines seemed like they wouldn't
work properly.

I tested this patch here and it seems to behave as intended.  I like the
tightening of ::1 processing as well, though maybe that should be its
own preliminary commit, to make it clear that it isn't in fact changing
anything.


The deal with system_views.sql is not clear to me.  Previously, the
function underlying each view was in pg_proc.dat and the ACL was tweaked
in system_views.sql together with the place where the function was used
to define the view; now it seems the whole of the function (incl its
ACL) is in pg_proc.dat, and only the view itself is in system_views.sql.
I think this is an OK arrangement, but perhaps there should be a comment
in system_views.sql about it.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
"Ninguna manada de bestias tiene una voz tan horrible como la humana" (Orual)


Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
=?utf-8?Q?=C3=81lvaro?= Herrera  writes:
> I tested this patch here and it seems to behave as intended.

Thanks for looking!

> The deal with system_views.sql is not clear to me.  Previously, the
> function underlying each view was in pg_proc.dat and the ACL was tweaked
> in system_views.sql together with the place where the function was used
> to define the view; now it seems the whole of the function (incl its
> ACL) is in pg_proc.dat, and only the view itself is in system_views.sql.

Yeah, as I mentioned upthread, I'm not totally pleased with that.
It seemed to make sense to adjust the permissions of the views and
their underlying functions together.  This patch loses that, but
keeps consistency with other built-in functions and promotes
"single source of truth".  Is that a good tradeoff?  I'm not sure.
I think there's a case to be made for continuing to handle these
specific functions' ACLs as we do now.

> I think this is an OK arrangement, but perhaps there should be a comment
> in system_views.sql about it.

Yeah, that'd be a good thing to do if we keep it like this.  Perhaps
more or less

 * Some of these views are not meant to be publicly readable.  The
 * underlying function(s) for such a view should not be publicly
 * executable either --- but by default they will be.  Don't forget to
 * adjust function permissions (in pg_proc.dat) when adding a new view.

			regards, tom lane


Re: generating function default settings from pg_proc.dat

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I wrote:
> =?utf-8?Q?=C3=81lvaro?= Herrera  writes:
>> I think this is an OK arrangement, but perhaps there should be a comment
>> in system_views.sql about it.

> Yeah, that'd be a good thing to do if we keep it like this.  Perhaps
> more or less

>  * Some of these views are not meant to be publicly readable.  The
>  * underlying function(s) for such a view should not be publicly
>  * executable either --- but by default they will be.  Don't forget to
>  * adjust function permissions (in pg_proc.dat) when adding a new view.

Hearing no further comments, pushed like that.

			regards, tom lane


Re: generating function default settings from pg_proc.dat

От:
Andres Freund <andres@anarazel.de>
Дата:
Hi,

On 2026-03-05 17:44:06 -0500, Tom Lane wrote:
> I wrote:
> > =?utf-8?Q?=C3=81lvaro?= Herrera  writes:
> >> I think this is an OK arrangement, but perhaps there should be a comment
> >> in system_views.sql about it.
> 
> > Yeah, that'd be a good thing to do if we keep it like this.  Perhaps
> > more or less
> 
> >  * Some of these views are not meant to be publicly readable.  The
> >  * underlying function(s) for such a view should not be publicly
> >  * executable either --- but by default they will be.  Don't forget to
> >  * adjust function permissions (in pg_proc.dat) when adding a new view.
> 
> Hearing no further comments, pushed like that.

Thanks a lot for working on this!

Greetings,

Andres Freund


FAQ