1 /*-------------------------------------------------------------------------
4 * routines to support manipulation of the pg_parameter_acl relation
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/catalog/pg_parameter_acl.c
13 *-------------------------------------------------------------------------
17 #include "access/table.h"
18 #include "catalog/catalog.h"
19 #include "catalog/indexing.h"
20 #include "catalog/pg_parameter_acl.h"
21 #include "utils/builtins.h"
22 #include "utils/guc.h"
23 #include "utils/rel.h"
24 #include "utils/syscache.h"
28 * ParameterAclLookup - Given a configuration parameter name,
29 * look up the associated configuration parameter ACL's OID.
31 * If missing_ok is false, throw an error if ACL entry not found. If
32 * true, just return InvalidOid.
35 ParameterAclLookup(const char *parameter
, bool missing_ok
)
40 /* Convert name to the form it should have in pg_parameter_acl... */
41 parname
= convert_GUC_name_for_parameter_acl(parameter
);
43 /* ... and look it up */
44 oid
= GetSysCacheOid1(PARAMETERACLNAME
, Anum_pg_parameter_acl_oid
,
45 PointerGetDatum(cstring_to_text(parname
)));
47 if (!OidIsValid(oid
) && !missing_ok
)
49 (errcode(ERRCODE_UNDEFINED_OBJECT
),
50 errmsg("parameter ACL \"%s\" does not exist", parameter
)));
60 * Add a new tuple to pg_parameter_acl.
62 * parameter: the parameter name to create an entry for.
63 * Caller should have verified that there's no such entry already.
65 * Returns the new entry's OID.
68 ParameterAclCreate(const char *parameter
)
75 Datum values
[Natts_pg_parameter_acl
] = {0};
76 bool nulls
[Natts_pg_parameter_acl
] = {0};
79 * To prevent cluttering pg_parameter_acl with useless entries, insist
80 * that the name be valid.
82 check_GUC_name_for_parameter_acl(parameter
);
84 /* Convert name to the form it should have in pg_parameter_acl. */
85 parname
= convert_GUC_name_for_parameter_acl(parameter
);
88 * Create and insert a new record containing a null ACL.
90 * We don't take a strong enough lock to prevent concurrent insertions,
91 * relying instead on the unique index.
93 rel
= table_open(ParameterAclRelationId
, RowExclusiveLock
);
94 tupDesc
= RelationGetDescr(rel
);
95 parameterId
= GetNewOidWithIndex(rel
,
96 ParameterAclOidIndexId
,
97 Anum_pg_parameter_acl_oid
);
98 values
[Anum_pg_parameter_acl_oid
- 1] = ObjectIdGetDatum(parameterId
);
99 values
[Anum_pg_parameter_acl_parname
- 1] =
100 PointerGetDatum(cstring_to_text(parname
));
101 nulls
[Anum_pg_parameter_acl_paracl
- 1] = true;
102 tuple
= heap_form_tuple(tupDesc
, values
, nulls
);
103 CatalogTupleInsert(rel
, tuple
);
105 /* Close pg_parameter_acl, but keep lock till commit. */
106 heap_freetuple(tuple
);
107 table_close(rel
, NoLock
);