PostgreSQL Source Code git master
Loading...
Searching...
No Matches
rewriteRemove.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * rewriteRemove.c
4 * routines for removing rewrite rules
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/backend/rewrite/rewriteRemove.c
12 *
13 *-------------------------------------------------------------------------
14 */
15#include "postgres.h"
16
17#include "access/genam.h"
18#include "access/htup_details.h"
19#include "access/table.h"
20#include "catalog/catalog.h"
21#include "catalog/indexing.h"
22#include "catalog/pg_rewrite.h"
23#include "miscadmin.h"
25#include "utils/fmgroids.h"
26#include "utils/inval.h"
27#include "utils/rel.h"
28
29/*
30 * Guts of rule deletion.
31 */
32void
34{
39 HeapTuple tuple;
41
42 /*
43 * Open the pg_rewrite relation.
44 */
46
47 /*
48 * Find the tuple for the target rule.
49 */
50 ScanKeyInit(&skey[0],
54
56 NULL, 1, skey);
57
58 tuple = systable_getnext(rcscan);
59
60 if (!HeapTupleIsValid(tuple))
61 elog(ERROR, "could not find tuple for rule %u", ruleOid);
62
63 /*
64 * We had better grab AccessExclusiveLock to ensure that no queries are
65 * going on that might depend on this rule. (Note: a weaker lock would
66 * suffice if it's not an ON SELECT rule.)
67 */
70
74 errmsg("permission denied: \"%s\" is a system catalog",
76
77 /*
78 * Now delete the pg_rewrite tuple for the rule
79 */
81
83
85
86 /*
87 * Issue shared-inval notice to force all backends (including me!) to
88 * update relcache entries with the new rule set.
89 */
91
92 /* Close rel, but keep lock till commit... */
94}
bool IsSystemRelation(Relation relation)
Definition catalog.c:74
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
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
bool allowSystemTableMods
Definition globals.c:130
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)
Definition indexing.c:365
void CacheInvalidateRelcache(Relation relation)
Definition inval.c:1635
#define NoLock
Definition lockdefs.h:34
#define AccessExclusiveLock
Definition lockdefs.h:43
#define RowExclusiveLock
Definition lockdefs.h:38
FormData_pg_rewrite * Form_pg_rewrite
Definition pg_rewrite.h:52
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
unsigned int Oid
static int fb(int x)
#define RelationGetRelationName(relation)
Definition rel.h:548
void RemoveRewriteRuleById(Oid ruleOid)
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
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40