3 * Routines to support manipulation of the pg_db_role_setting relation
5 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
6 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/backend/catalog/pg_db_role_setting.c
20#include "utils/fmgroids.h"
34 /* Get the old tuple, if any. */
38 Anum_pg_db_role_setting_setdatabase,
42 Anum_pg_db_role_setting_setrole,
50 * There are three cases:
52 * - in RESET ALL, request GUC to reset the settings array and update the
53 * catalog if there's anything left, delete it otherwise
55 * - in other commands, if there's a tuple in pg_db_role_setting, update
56 * it; if it ends up empty, delete it
58 * - otherwise, insert a new pg_db_role_setting tuple, but only if the
59 * command is not RESET
69 datum =
heap_getattr(tuple, Anum_pg_db_role_setting_setconfig,
77 Datum repl_val[Natts_pg_db_role_setting];
78 bool repl_null[Natts_pg_db_role_setting];
79 bool repl_repl[Natts_pg_db_role_setting];
82 memset(repl_repl,
false,
sizeof(repl_repl));
84 repl_val[Anum_pg_db_role_setting_setconfig - 1] =
86 repl_repl[Anum_pg_db_role_setting_setconfig - 1] =
true;
87 repl_null[Anum_pg_db_role_setting_setconfig - 1] =
false;
90 repl_val, repl_null, repl_repl);
99 Datum repl_val[Natts_pg_db_role_setting];
100 bool repl_null[Natts_pg_db_role_setting];
101 bool repl_repl[Natts_pg_db_role_setting];
107 memset(repl_repl,
false,
sizeof(repl_repl));
108 repl_repl[Anum_pg_db_role_setting_setconfig - 1] =
true;
109 repl_null[Anum_pg_db_role_setting_setconfig - 1] =
false;
111 /* Extract old value of setconfig */
112 datum =
heap_getattr(tuple, Anum_pg_db_role_setting_setconfig,
116 /* Update (valuestr is NULL in RESET cases) */
124 repl_val[Anum_pg_db_role_setting_setconfig - 1] =
128 repl_val, repl_null, repl_repl);
136 /* non-null valuestr means it's not RESET, so insert a new tuple */
139 bool nulls[Natts_pg_db_role_setting];
142 memset(nulls,
false,
sizeof(nulls));
146 values[Anum_pg_db_role_setting_setdatabase - 1] =
157 * RESET doesn't need to change any state if there's no pre-existing
158 * pg_db_role_setting entry, but for consistency we should still check
159 * that the option is valid and we're allowed to set it.
165 databaseid, 0, roleid,
false);
169 /* Close pg_db_role_setting, but keep lock till commit */
174 * Drop some settings from the catalog. These can be for a particular
175 * database, or for a particular role. (It is of course possible to do both
176 * too, but it doesn't make sense for current uses.)
192 Anum_pg_db_role_setting_setdatabase,
201 Anum_pg_db_role_setting_setrole,
219 * Scan pg_db_role_setting looking for applicable settings, and load them on
220 * the current process.
222 * relsetting is pg_db_role_setting, already opened and locked.
224 * Note: we only consider setting for the exact databaseid/roleid combination.
225 * This probably needs to be called more than once, with InvalidOid passed as
237 Anum_pg_db_role_setting_setdatabase,
242 Anum_pg_db_role_setting_setrole,
254 datum =
heap_getattr(tup, Anum_pg_db_role_setting_setconfig,
261 * We process all the options at SUSET level. We assume that the
262 * right to insert an option into pg_db_role_setting was checked
263 * when it was inserted.
#define DatumGetArrayTypeP(X)
static Datum values[MAXATTR]
#define OidIsValid(objectId)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
ArrayType * GUCArrayAdd(ArrayType *array, const char *name, const char *value)
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
ArrayType * GUCArrayReset(ArrayType *array)
ArrayType * GUCArrayDelete(ArrayType *array, const char *name)
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
#define InvokeObjectPostAlterHookArg(classId, objectId, subId, auxiliaryId, is_internal)
void DropSetting(Oid databaseid, Oid roleid)
void AlterSetting(Oid databaseid, Oid roleid, VariableSetStmt *setstmt)
void ApplySetting(Snapshot snapshot, Oid databaseid, Oid roleid, Relation relsetting, GucSource source)
static rewind_source * source
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
#define RelationGetDescr(relation)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
#define BTEqualStrategyNumber
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, ScanKeyData *key)
static void table_endscan(TableScanDesc scan)