postgresql/src/include/catalog
Tom Lane 5342874039 Fix failure to track role dependencies of pg_init_privs entries.
If an ACL recorded in pg_init_privs mentions a non-pinned role,
that reference must also be noted in pg_shdepend so that we know
that the role can't go away without removing the ACL reference.
Otherwise, DROP ROLE could succeed and leave dangling entries
behind, which is what's causing the recent upgrade-check failures
on buildfarm member copperhead.

This has been wrong since pg_init_privs was introduced, but it's
escaped notice because typical pg_init_privs entries would only
mention the bootstrap superuser (pinned) or at worst the owner
of the extension (who can't go away before the extension does).

We lack even a representation of such a role reference for
pg_shdepend.  My first thought for a solution was entries listing
pg_init_privs in classid, but that doesn't work because then there's
noplace to put the granted-on object's classid.  Rather than adding
a new column to pg_shdepend, let's add a new deptype code
SHARED_DEPENDENCY_INITACL.  Much of the associated boilerplate
code can be cribbed from code for SHARED_DEPENDENCY_ACL.

A lot of the bulk of this patch just stems from the new need to pass
the object's owner ID to recordExtensionInitPriv, so that we can
consult it while updating pg_shdepend.  While many callers have that
at hand already, a few places now need to fetch the owner ID of an
arbitrary privilege-bearing object.  For that, we assume that there
is a catcache on the relevant catalog's OID column, which is an
assumption already made in ExecGrant_common so it seems okay here.

We do need an entirely new routine RemoveRoleFromInitPriv to perform
cleanup of pg_init_privs ACLs during DROP OWNED BY.  It's analogous
to RemoveRoleFromObjectACL, but we can't share logic because that
function operates by building a command parsetree and invoking
existing GRANT/REVOKE infrastructure.  There is of course no SQL
command that would update pg_init_privs entries when we're not in
process of creating their extension, so we need a routine that can
do the updates directly.

catversion bump because this changes the expected contents of
pg_shdepend.  For the same reason, there's no hope of back-patching
this, even though it fixes a longstanding bug.  Fortunately, the
case where it's a problem seems to be near nonexistent in the field.
If it weren't for the buildfarm breakage, I'd have been content to
leave this for v18.

Patch by me; thanks to Daniel Gustafsson for review and discussion.

Discussion: https://postgr.es/m/1745535.1712358659@sss.pgh.pa.us
2024-04-29 19:26:19 -04:00
..
.gitignore Put genbki.pl output into src/include/catalog/ directly 2024-03-14 07:11:21 +01:00
Makefile Put genbki.pl output into src/include/catalog/ directly 2024-03-14 07:11:21 +01:00
binary_upgrade.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
catalog.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
catversion.h Fix failure to track role dependencies of pg_init_privs entries. 2024-04-29 19:26:19 -04:00
dependency.h Fix failure to track role dependencies of pg_init_privs entries. 2024-04-29 19:26:19 -04:00
duplicate_oids Update copyright for 2024 2024-01-03 20:49:05 -05:00
genbki.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
heap.h Generalize handling of nullable pg_attribute columns in DDL 2024-03-17 12:30:51 +01:00
index.h Add attstattarget to FormExtraData_pg_attribute 2024-03-17 12:38:27 +01:00
indexing.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
meson.build Put genbki.pl output into src/include/catalog/ directly 2024-03-14 07:11:21 +01:00
namespace.h Replace BackendIds with 0-based ProcNumbers 2024-03-03 19:38:22 +02:00
objectaccess.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
objectaddress.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
partition.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_aggregate.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_aggregate.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_am.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_am.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_amop.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_amop.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_amproc.dat Add stratnum GiST support function 2024-01-19 15:42:13 +01:00
pg_amproc.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_attrdef.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_attribute.h Add attstattarget to FormExtraData_pg_attribute 2024-03-17 12:38:27 +01:00
pg_auth_members.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_authid.dat Reintroduce MAINTAIN privilege and pg_maintain predefined role. 2024-03-13 14:49:26 -05:00
pg_authid.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_cast.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_cast.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_class.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_class.h Allow specifying an access method for partitioned tables 2024-03-25 16:30:36 +01:00
pg_collation.dat Use version for builtin collations. 2024-03-29 10:53:26 -07:00
pg_collation.h Introduce "builtin" collation provider. 2024-03-13 23:33:44 -07:00
pg_constraint.h Fix restore of not-null constraints with inheritance 2024-04-18 15:35:15 +02:00
pg_control.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_conversion.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_conversion.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_database.dat Catalog changes preparing for builtin collation provider. 2024-03-09 14:48:18 -08:00
pg_database.h Catalog changes preparing for builtin collation provider. 2024-03-09 14:48:18 -08:00
pg_db_role_setting.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_default_acl.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_depend.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_description.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_enum.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_event_trigger.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_extension.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_foreign_data_wrapper.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_foreign_server.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_foreign_table.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_index.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_inherits.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_init_privs.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_language.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_language.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_largeobject.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_largeobject_metadata.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_namespace.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_namespace.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_opclass.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_opclass.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_operator.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_operator.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_opfamily.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_opfamily.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_parameter_acl.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_partitioned_table.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_policy.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_proc.dat Revert: Implement pg_wal_replay_wait() stored procedure 2024-04-11 17:28:15 +03:00
pg_proc.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_publication.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_publication_namespace.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_publication_rel.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_range.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_range.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_replication_origin.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_rewrite.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_seclabel.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_sequence.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_shdepend.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_shdescription.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_shseclabel.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_statistic.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_statistic_ext.h Make stxstattarget nullable 2024-03-17 12:26:26 +01:00
pg_statistic_ext_data.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_subscription.h Add a failover option to subscriptions. 2024-01-30 16:49:28 +05:30
pg_subscription_rel.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_tablespace.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_tablespace.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_transform.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_trigger.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ts_config.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ts_config.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_ts_config_map.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ts_config_map.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_ts_dict.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ts_dict.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_ts_parser.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ts_parser.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_ts_template.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ts_template.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_type.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_type.h Revert "Improve compression and storage support with inheritance" 2024-02-20 11:10:59 +01:00
pg_user_mapping.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
reformat_dat_file.pl Update copyright for 2024 2024-01-03 20:49:05 -05:00
renumber_oids.pl Update copyright for 2024 2024-01-03 20:49:05 -05:00
storage.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
storage_xlog.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
toasting.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
unused_oids Update copyright for 2024 2024-01-03 20:49:05 -05:00