PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_db_role_setting.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/tableam.h"
#include "catalog/indexing.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_db_role_setting.h"
#include "utils/fmgroids.h"
#include "utils/rel.h"
Include dependency graph for pg_db_role_setting.c:

Go to the source code of this file.

Functions

void AlterSetting (Oid databaseid, Oid roleid, VariableSetStmt *setstmt)
 
void DropSetting (Oid databaseid, Oid roleid)
 
void ApplySetting (Snapshot snapshot, Oid databaseid, Oid roleid, Relation relsetting, GucSource source)
 

Function Documentation

◆ AlterSetting()

void AlterSetting ( Oid  databaseid,
Oid  roleid,
VariableSetStmt setstmt 
)

Definition at line 24 of file pg_db_role_setting.c.

25{
26 char *valuestr;
27 HeapTuple tuple;
28 Relation rel;
30 SysScanDesc scan;
31
33
34 /* Get the old tuple, if any. */
35
44 ObjectIdGetDatum(roleid));
46 NULL, 2, scankey);
47 tuple = systable_getnext(scan);
48
49 /*
50 * There are three cases:
51 *
52 * - in RESET ALL, request GUC to reset the settings array and update the
53 * catalog if there's anything left, delete it otherwise
54 *
55 * - in other commands, if there's a tuple in pg_db_role_setting, update
56 * it; if it ends up empty, delete it
57 *
58 * - otherwise, insert a new pg_db_role_setting tuple, but only if the
59 * command is not RESET
60 */
61 if (setstmt->kind == VAR_RESET_ALL)
62 {
63 if (HeapTupleIsValid(tuple))
64 {
65 ArrayType *new = NULL;
66 Datum datum;
67 bool isnull;
68
70 RelationGetDescr(rel), &isnull);
71
72 if (!isnull)
74
75 if (new)
76 {
80 HeapTuple newtuple;
81
82 memset(repl_repl, false, sizeof(repl_repl));
83
85 PointerGetDatum(new);
88
89 newtuple = heap_modify_tuple(tuple, RelationGetDescr(rel),
91 CatalogTupleUpdate(rel, &tuple->t_self, newtuple);
92 }
93 else
94 CatalogTupleDelete(rel, &tuple->t_self);
95 }
96 }
97 else if (HeapTupleIsValid(tuple))
98 {
102 HeapTuple newtuple;
103 Datum datum;
104 bool isnull;
105 ArrayType *a;
106
107 memset(repl_repl, false, sizeof(repl_repl));
110
111 /* Extract old value of setconfig */
113 RelationGetDescr(rel), &isnull);
114 a = isnull ? NULL : DatumGetArrayTypeP(datum);
115
116 /* Update (valuestr is NULL in RESET cases) */
117 if (valuestr)
118 a = GUCArrayAdd(a, setstmt->name, valuestr);
119 else
120 a = GUCArrayDelete(a, setstmt->name);
121
122 if (a)
123 {
126
127 newtuple = heap_modify_tuple(tuple, RelationGetDescr(rel),
129 CatalogTupleUpdate(rel, &tuple->t_self, newtuple);
130 }
131 else
132 CatalogTupleDelete(rel, &tuple->t_self);
133 }
134 else if (valuestr)
135 {
136 /* non-null valuestr means it's not RESET, so insert a new tuple */
137 HeapTuple newtuple;
139 bool nulls[Natts_pg_db_role_setting];
140 ArrayType *a;
141
142 memset(nulls, false, sizeof(nulls));
143
144 a = GUCArrayAdd(NULL, setstmt->name, valuestr);
145
150 newtuple = heap_form_tuple(RelationGetDescr(rel), values, nulls);
151
152 CatalogTupleInsert(rel, newtuple);
153 }
154 else
155 {
156 /*
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.
160 */
161 (void) GUCArrayDelete(NULL, setstmt->name);
162 }
163
165 databaseid, 0, roleid, false);
166
167 systable_endscan(scan);
168
169 /* Close pg_db_role_setting, but keep lock till commit */
170 table_close(rel, NoLock);
171}
#define DatumGetArrayTypeP(X)
Definition array.h:261
static Datum values[MAXATTR]
Definition bootstrap.c:155
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:603
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:514
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition genam.c:388
ArrayType * GUCArrayAdd(ArrayType *array, const char *name, const char *value)
Definition guc.c:6328
ArrayType * GUCArrayReset(ArrayType *array)
Definition guc.c:6474
ArrayType * GUCArrayDelete(ArrayType *array, const char *name)
Definition guc.c:6405
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition guc_funcs.c:167
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
Definition heaptuple.c:1210
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1117
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
void CatalogTupleUpdate(Relation heapRel, const ItemPointerData *otid, HeapTuple tup)
Definition indexing.c:313
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition indexing.c:233
void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)
Definition indexing.c:365
int a
Definition isn.c:73
#define NoLock
Definition lockdefs.h:34
#define RowExclusiveLock
Definition lockdefs.h:38
#define InvokeObjectPostAlterHookArg(classId, objectId, subId, auxiliaryId, is_internal)
@ VAR_RESET_ALL
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
#define RelationGetDescr(relation)
Definition rel.h:540
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition scankey.c:76
#define BTEqualStrategyNumber
Definition stratnum.h:31
ItemPointerData t_self
Definition htup.h:65
VariableSetKind kind
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40

References a, BTEqualStrategyNumber, CatalogTupleDelete(), CatalogTupleInsert(), CatalogTupleUpdate(), DatumGetArrayTypeP, ExtractSetVariableArgs(), fb(), GUCArrayAdd(), GUCArrayDelete(), GUCArrayReset(), heap_form_tuple(), heap_getattr(), heap_modify_tuple(), HeapTupleIsValid, InvokeObjectPostAlterHookArg, VariableSetStmt::kind, VariableSetStmt::name, NoLock, ObjectIdGetDatum(), PointerGetDatum(), RelationGetDescr, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), table_open(), values, and VAR_RESET_ALL.

Referenced by AlterDatabaseSet(), and AlterRoleSet().

◆ ApplySetting()

void ApplySetting ( Snapshot  snapshot,
Oid  databaseid,
Oid  roleid,
Relation  relsetting,
GucSource  source 
)

Definition at line 229 of file pg_db_role_setting.c.

231{
232 SysScanDesc scan;
233 ScanKeyData keys[2];
235
236 ScanKeyInit(&keys[0],
239 F_OIDEQ,
241 ScanKeyInit(&keys[1],
244 F_OIDEQ,
245 ObjectIdGetDatum(roleid));
246
248 snapshot, 2, keys);
249 while (HeapTupleIsValid(tup = systable_getnext(scan)))
250 {
251 bool isnull;
252 Datum datum;
253
255 RelationGetDescr(relsetting), &isnull);
256 if (!isnull)
257 {
259
260 /*
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.
264 */
266 }
267 }
268
269 systable_endscan(scan);
270}
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
Definition guc.c:6296
@ GUC_ACTION_SET
Definition guc.h:203
@ PGC_SUSET
Definition guc.h:78
static rewind_source * source
Definition pg_rewind.c:89

References a, BTEqualStrategyNumber, DatumGetArrayTypeP, fb(), GUC_ACTION_SET, heap_getattr(), HeapTupleIsValid, ObjectIdGetDatum(), PGC_SUSET, ProcessGUCArray(), RelationGetDescr, ScanKeyInit(), source, systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by process_settings().

◆ DropSetting()

void DropSetting ( Oid  databaseid,
Oid  roleid 
)

Definition at line 179 of file pg_db_role_setting.c.

180{
182 TableScanDesc scan;
183 ScanKeyData keys[2];
185 int numkeys = 0;
186
188
190 {
191 ScanKeyInit(&keys[numkeys],
194 F_OIDEQ,
196 numkeys++;
197 }
198 if (OidIsValid(roleid))
199 {
200 ScanKeyInit(&keys[numkeys],
203 F_OIDEQ,
204 ObjectIdGetDatum(roleid));
205 numkeys++;
206 }
207
208 scan = table_beginscan_catalog(relsetting, numkeys, keys);
210 {
212 }
213 table_endscan(scan);
214
216}
#define OidIsValid(objectId)
Definition c.h:788
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition heapam.c:1409
@ ForwardScanDirection
Definition sdir.h:28
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, ScanKeyData *key)
Definition tableam.c:113
static void table_endscan(TableScanDesc scan)
Definition tableam.h:1005

References BTEqualStrategyNumber, CatalogTupleDelete(), fb(), ForwardScanDirection, heap_getnext(), HeapTupleIsValid, ObjectIdGetDatum(), OidIsValid, RowExclusiveLock, ScanKeyInit(), table_beginscan_catalog(), table_close(), table_endscan(), and table_open().

Referenced by dropdb(), and DropRole().