PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_largeobject.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pg_largeobject.c
4 * routines to support manipulation of the pg_largeobject relation
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/catalog/pg_largeobject.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"
24#include "miscadmin.h"
25#include "utils/acl.h"
26#include "utils/fmgroids.h"
27#include "utils/rel.h"
28
29
30/*
31 * Create a large object having the given LO identifier.
32 *
33 * We create a new large object by inserting an entry into
34 * pg_largeobject_metadata without any data pages, so that the object
35 * will appear to exist with size 0.
36 */
37Oid
91
92/*
93 * Drop a large object having the given LO identifier. Both the data pages
94 * and metadata must be dropped.
95 */
96void
98{
101 ScanKeyData skey[1];
102 SysScanDesc scan;
103 HeapTuple tuple;
104
107
110
111 /*
112 * Delete an entry from pg_largeobject_metadata
113 */
114 ScanKeyInit(&skey[0],
118
121 NULL, 1, skey);
122
123 tuple = systable_getnext(scan);
124 if (!HeapTupleIsValid(tuple))
127 errmsg("large object %u does not exist", loid)));
128
130
131 systable_endscan(scan);
132
133 /*
134 * Delete all the associated entries from pg_largeobject
135 */
136 ScanKeyInit(&skey[0],
140
143 NULL, 1, skey);
144 while (HeapTupleIsValid(tuple = systable_getnext(scan)))
145 {
147 }
148
149 systable_endscan(scan);
150
152
154}
155
156/*
157 * LargeObjectExists
158 *
159 * We don't use the system cache for large object metadata, for fear of
160 * using too much local memory.
161 *
162 * This function always scans the system catalog using an up-to-date snapshot,
163 * so it should not be used when a large object is opened in read-only mode
164 * (because large objects opened in read only mode are supposed to be viewed
165 * relative to the caller's snapshot, whereas in read-write mode they are
166 * relative to a current snapshot).
167 */
168bool
173
174/*
175 * Same as LargeObjectExists(), except snapshot to read with can be specified.
176 */
177bool
179{
181 ScanKeyData skey[1];
183 HeapTuple tuple;
184 bool retval = false;
185
186 ScanKeyInit(&skey[0],
190
193
196 snapshot, 1, skey);
197
198 tuple = systable_getnext(sd);
199 if (HeapTupleIsValid(tuple))
200 retval = true;
201
203
205
206 return retval;
207}
void recordDependencyOnNewAcl(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, Acl *acl)
Definition aclchk.c:4327
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
Definition aclchk.c:4247
static Datum values[MAXATTR]
Definition bootstrap.c:155
#define OidIsValid(objectId)
Definition c.h:788
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition catalog.c:448
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#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
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1117
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1435
#define HeapTupleIsValid(tuple)
Definition htup.h:78
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition indexing.c:233
void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)
Definition indexing.c:365
#define AccessShareLock
Definition lockdefs.h:36
#define RowExclusiveLock
Definition lockdefs.h:38
Oid GetUserId(void)
Definition miscinit.c:469
@ OBJECT_LARGEOBJECT
void LargeObjectDrop(Oid loid)
bool LargeObjectExistsWithSnapshot(Oid loid, Snapshot snapshot)
bool LargeObjectExists(Oid loid)
Oid LargeObjectCreate(Oid loid)
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
#define InvalidOid
unsigned int Oid
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
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40