PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
catalog.c File Reference
#include "postgres.h"
#include <fcntl.h>
#include <unistd.h>
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/table.h"
#include "access/transam.h"
#include "catalog/catalog.h"
#include "catalog/namespace.h"
#include "catalog/pg_auth_members.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_database.h"
#include "catalog/pg_db_role_setting.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_parameter_acl.h"
#include "catalog/pg_replication_origin.h"
#include "catalog/pg_seclabel.h"
#include "catalog/pg_shdepend.h"
#include "catalog/pg_shdescription.h"
#include "catalog/pg_shseclabel.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_type.h"
#include "miscadmin.h"
#include "utils/fmgroids.h"
#include "utils/fmgrprotos.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
Include dependency graph for catalog.c:

Go to the source code of this file.

Macros

#define GETNEWOID_LOG_THRESHOLD   1000000
 
#define GETNEWOID_LOG_MAX_INTERVAL   128000000
 

Functions

bool IsSystemRelation (Relation relation)
 
bool IsSystemClass (Oid relid, Form_pg_class reltuple)
 
bool IsCatalogRelation (Relation relation)
 
bool IsCatalogRelationOid (Oid relid)
 
bool IsCatalogTextUniqueIndexOid (Oid relid)
 
bool IsInplaceUpdateRelation (Relation relation)
 
bool IsInplaceUpdateOid (Oid relid)
 
bool IsToastRelation (Relation relation)
 
bool IsToastClass (Form_pg_class reltuple)
 
bool IsCatalogNamespace (Oid namespaceId)
 
bool IsToastNamespace (Oid namespaceId)
 
bool IsReservedName (const char *name)
 
bool IsSharedRelation (Oid relationId)
 
bool IsPinnedObject (Oid classId, Oid objectId)
 
Oid GetNewOidWithIndex (Relation relation, Oid indexId, AttrNumber oidcolumn)
 
RelFileNumber GetNewRelFileNumber (Oid reltablespace, Relation pg_class, char relpersistence)
 
Datum pg_nextoid (PG_FUNCTION_ARGS)
 
Datum pg_stop_making_pinned_objects (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ GETNEWOID_LOG_MAX_INTERVAL

#define GETNEWOID_LOG_MAX_INTERVAL   128000000

Definition at line 56 of file catalog.c.

◆ GETNEWOID_LOG_THRESHOLD

#define GETNEWOID_LOG_THRESHOLD   1000000

Definition at line 55 of file catalog.c.

Function Documentation

◆ GetNewOidWithIndex()

Oid GetNewOidWithIndex ( Relation  relation,
Oid  indexId,
AttrNumber  oidcolumn 
)

Definition at line 450 of file catalog.c.

451{
452 Oid newOid;
453 SysScanDesc scan;
455 bool collides;
456 uint64 retries = 0;
457 uint64 retries_before_log = GETNEWOID_LOG_THRESHOLD;
458
459 /* Only system relations are supported */
460 Assert(IsSystemRelation(relation));
461
462 /* In bootstrap mode, we don't have any indexes to use */
464 return GetNewObjectId();
465
466 /*
467 * We should never be asked to generate a new pg_type OID during
468 * pg_upgrade; doing so would risk collisions with the OIDs it wants to
469 * assign. Hitting this assert means there's some path where we failed to
470 * ensure that a type OID is determined by commands in the dump script.
471 */
472 Assert(!IsBinaryUpgrade || RelationGetRelid(relation) != TypeRelationId);
473
474 /* Generate new OIDs until we find one not in the table */
475 do
476 {
478
479 newOid = GetNewObjectId();
480
482 oidcolumn,
483 BTEqualStrategyNumber, F_OIDEQ,
484 ObjectIdGetDatum(newOid));
485
486 /* see notes above about using SnapshotAny */
487 scan = systable_beginscan(relation, indexId, true,
488 SnapshotAny, 1, &key);
489
490 collides = HeapTupleIsValid(systable_getnext(scan));
491
492 systable_endscan(scan);
493
494 /*
495 * Log that we iterate more than GETNEWOID_LOG_THRESHOLD but have not
496 * yet found OID unused in the relation. Then repeat logging with
497 * exponentially increasing intervals until we iterate more than
498 * GETNEWOID_LOG_MAX_INTERVAL. Finally repeat logging every
499 * GETNEWOID_LOG_MAX_INTERVAL unless an unused OID is found. This
500 * logic is necessary not to fill up the server log with the similar
501 * messages.
502 */
503 if (retries >= retries_before_log)
504 {
505 ereport(LOG,
506 (errmsg("still searching for an unused OID in relation \"%s\"",
507 RelationGetRelationName(relation)),
508 errdetail_plural("OID candidates have been checked %" PRIu64 " time, but no unused OID has been found yet.",
509 "OID candidates have been checked %" PRIu64 " times, but no unused OID has been found yet.",
510 retries,
511 retries)));
512
513 /*
514 * Double the number of retries to do before logging next until it
515 * reaches GETNEWOID_LOG_MAX_INTERVAL.
516 */
517 if (retries_before_log * 2 <= GETNEWOID_LOG_MAX_INTERVAL)
518 retries_before_log *= 2;
519 else
520 retries_before_log += GETNEWOID_LOG_MAX_INTERVAL;
521 }
522
523 retries++;
524 } while (collides);
525
526 /*
527 * If at least one log message is emitted, also log the completion of OID
528 * assignment.
529 */
530 if (retries > GETNEWOID_LOG_THRESHOLD)
531 {
532 ereport(LOG,
533 (errmsg_plural("new OID has been assigned in relation \"%s\" after %" PRIu64 " retry",
534 "new OID has been assigned in relation \"%s\" after %" PRIu64 " retries",
535 retries,
536 RelationGetRelationName(relation), retries)));
537 }
538
539 return newOid;
540}
uint64_t uint64
Definition: c.h:503
#define GETNEWOID_LOG_THRESHOLD
Definition: catalog.c:55
bool IsSystemRelation(Relation relation)
Definition: catalog.c:74
#define GETNEWOID_LOG_MAX_INTERVAL
Definition: catalog.c:56
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1181
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1296
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define LOG
Definition: elog.h:31
#define ereport(elevel,...)
Definition: elog.h:149
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 IsBinaryUpgrade
Definition: globals.c:122
Assert(PointerIsAligned(start, uint64))
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:477
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:123
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
unsigned int Oid
Definition: postgres_ext.h:30
#define RelationGetRelid(relation)
Definition: rel.h:516
#define RelationGetRelationName(relation)
Definition: rel.h:550
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define SnapshotAny
Definition: snapmgr.h:33
#define BTEqualStrategyNumber
Definition: stratnum.h:31
Oid GetNewObjectId(void)
Definition: varsup.c:555

References Assert(), BTEqualStrategyNumber, CHECK_FOR_INTERRUPTS, ereport, errdetail_plural(), errmsg(), errmsg_plural(), GetNewObjectId(), GETNEWOID_LOG_MAX_INTERVAL, GETNEWOID_LOG_THRESHOLD, HeapTupleIsValid, IsBinaryUpgrade, IsBootstrapProcessingMode, IsSystemRelation(), sort-test::key, LOG, ObjectIdGetDatum(), RelationGetRelationName, RelationGetRelid, ScanKeyInit(), SnapshotAny, systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by AddEnumLabel(), AddRoleMems(), AssignTypeArrayOid(), AssignTypeMultirangeArrayOid(), AssignTypeMultirangeOid(), CastCreate(), CollationCreate(), ConversionCreate(), CreateAccessMethod(), CreateConstraintEntry(), createdb(), CreateForeignDataWrapper(), CreateForeignServer(), CreateOpFamily(), CreatePolicy(), CreateProceduralLanguage(), CreatePublication(), CreateRole(), CreateStatistics(), CreateSubscription(), CreateTableSpace(), CreateTransform(), CreateTriggerFiringOn(), CreateUserMapping(), DefineOpClass(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), EnumValuesCreate(), GetNewRelFileNumber(), insert_event_trigger_tuple(), InsertExtensionTuple(), InsertRule(), LargeObjectCreate(), NamespaceCreate(), OperatorCreate(), OperatorShellMake(), ParameterAclCreate(), pg_nextoid(), ProcedureCreate(), publication_add_relation(), publication_add_schema(), SetDefaultACL(), StoreAttrDefault(), storeOperators(), storeProcedures(), toast_save_datum(), TypeCreate(), and TypeShellMake().

◆ GetNewRelFileNumber()

RelFileNumber GetNewRelFileNumber ( Oid  reltablespace,
Relation  pg_class,
char  relpersistence 
)

Definition at line 559 of file catalog.c.

560{
561 RelFileLocatorBackend rlocator;
562 RelPathStr rpath;
563 bool collides;
564 ProcNumber procNumber;
565
566 /*
567 * If we ever get here during pg_upgrade, there's something wrong; all
568 * relfilenumber assignments during a binary-upgrade run should be
569 * determined by commands in the dump script.
570 */
572
573 switch (relpersistence)
574 {
575 case RELPERSISTENCE_TEMP:
576 procNumber = ProcNumberForTempRelations();
577 break;
578 case RELPERSISTENCE_UNLOGGED:
579 case RELPERSISTENCE_PERMANENT:
580 procNumber = INVALID_PROC_NUMBER;
581 break;
582 default:
583 elog(ERROR, "invalid relpersistence: %c", relpersistence);
584 return InvalidRelFileNumber; /* placate compiler */
585 }
586
587 /* This logic should match RelationInitPhysicalAddr */
588 rlocator.locator.spcOid = reltablespace ? reltablespace : MyDatabaseTableSpace;
589 rlocator.locator.dbOid =
590 (rlocator.locator.spcOid == GLOBALTABLESPACE_OID) ?
592
593 /*
594 * The relpath will vary based on the backend number, so we must
595 * initialize that properly here to make sure that any collisions based on
596 * filename are properly detected.
597 */
598 rlocator.backend = procNumber;
599
600 do
601 {
603
604 /* Generate the OID */
605 if (pg_class)
606 rlocator.locator.relNumber = GetNewOidWithIndex(pg_class, ClassOidIndexId,
607 Anum_pg_class_oid);
608 else
609 rlocator.locator.relNumber = GetNewObjectId();
610
611 /* Check for existing file of same name */
612 rpath = relpath(rlocator, MAIN_FORKNUM);
613
614 if (access(rpath.str, F_OK) == 0)
615 {
616 /* definite collision */
617 collides = true;
618 }
619 else
620 {
621 /*
622 * Here we have a little bit of a dilemma: if errno is something
623 * other than ENOENT, should we declare a collision and loop? In
624 * practice it seems best to go ahead regardless of the errno. If
625 * there is a colliding file we will get an smgr failure when we
626 * attempt to create the new relation file.
627 */
628 collides = false;
629 }
630 } while (collides);
631
632 return rlocator.locator.relNumber;
633}
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:450
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
Oid MyDatabaseTableSpace
Definition: globals.c:97
Oid MyDatabaseId
Definition: globals.c:95
#define InvalidOid
Definition: postgres_ext.h:35
short access
Definition: preproc-type.c:36
#define INVALID_PROC_NUMBER
Definition: procnumber.h:26
int ProcNumber
Definition: procnumber.h:24
#define ProcNumberForTempRelations()
Definition: procnumber.h:53
@ MAIN_FORKNUM
Definition: relpath.h:58
#define relpath(rlocator, forknum)
Definition: relpath.h:150
#define InvalidRelFileNumber
Definition: relpath.h:26
RelFileLocator locator
RelFileNumber relNumber
char str[REL_PATH_STR_MAXLEN+1]
Definition: relpath.h:123

References Assert(), RelFileLocatorBackend::backend, CHECK_FOR_INTERRUPTS, RelFileLocator::dbOid, elog, ERROR, GetNewObjectId(), GetNewOidWithIndex(), INVALID_PROC_NUMBER, InvalidOid, InvalidRelFileNumber, IsBinaryUpgrade, RelFileLocatorBackend::locator, MAIN_FORKNUM, MyDatabaseId, MyDatabaseTableSpace, ProcNumberForTempRelations, RelFileLocator::relNumber, relpath, RelFileLocator::spcOid, and RelPathStr::str.

Referenced by ATExecSetTableSpace(), heap_create_with_catalog(), index_create(), and RelationSetNewRelfilenumber().

◆ IsCatalogNamespace()

bool IsCatalogNamespace ( Oid  namespaceId)

Definition at line 243 of file catalog.c.

244{
245 return namespaceId == PG_CATALOG_NAMESPACE;
246}

Referenced by AlterTableMoveAll(), check_publication_add_schema(), heap_create(), and RelationBuildLocalRelation().

◆ IsCatalogRelation()

◆ IsCatalogRelationOid()

bool IsCatalogRelationOid ( Oid  relid)

Definition at line 121 of file catalog.c.

122{
123 /*
124 * We consider a relation to be a system catalog if it has a pinned OID.
125 * This includes all the defined catalogs, their indexes, and their TOAST
126 * tables and indexes.
127 *
128 * This rule excludes the relations in information_schema, which are not
129 * integral to the system and can be treated the same as user relations.
130 * (Since it's valid to drop and recreate information_schema, any rule
131 * that did not act this way would be wrong.)
132 *
133 * This test is reliable since an OID wraparound will skip this range of
134 * OIDs; see GetNewObjectId().
135 */
136 return (relid < (Oid) FirstUnpinnedObjectId);
137}
#define FirstUnpinnedObjectId
Definition: transam.h:196

References FirstUnpinnedObjectId.

Referenced by check_relation_privileges(), is_publishable_class(), IsCatalogRelation(), IsSystemClass(), populate_compact_attribute_internal(), read_stream_begin_impl(), ReindexMultipleTables(), and ReindexRelationConcurrently().

◆ IsCatalogTextUniqueIndexOid()

bool IsCatalogTextUniqueIndexOid ( Oid  relid)

Definition at line 156 of file catalog.c.

157{
158 switch (relid)
159 {
160 case ParameterAclParnameIndexId:
161 case ReplicationOriginNameIndex:
162 case SecLabelObjectIndexId:
163 case SharedSecLabelObjectIndexId:
164 return true;
165 }
166 return false;
167}

Referenced by is_catalog_text_unique_index_oid().

◆ IsInplaceUpdateOid()

bool IsInplaceUpdateOid ( Oid  relid)

Definition at line 193 of file catalog.c.

194{
195 return (relid == RelationRelationId ||
196 relid == DatabaseRelationId);
197}

Referenced by IsInplaceUpdateRelation().

◆ IsInplaceUpdateRelation()

bool IsInplaceUpdateRelation ( Relation  relation)

Definition at line 183 of file catalog.c.

184{
185 return IsInplaceUpdateOid(RelationGetRelid(relation));
186}
bool IsInplaceUpdateOid(Oid relid)
Definition: catalog.c:193

References IsInplaceUpdateOid(), and RelationGetRelid.

Referenced by CheckValidResultRel(), InitResultRelInfo(), and systable_inplace_update_begin().

◆ IsPinnedObject()

bool IsPinnedObject ( Oid  classId,
Oid  objectId 
)

Definition at line 372 of file catalog.c.

373{
374 /*
375 * Objects with OIDs above FirstUnpinnedObjectId are never pinned. Since
376 * the OID generator skips this range when wrapping around, this check
377 * guarantees that user-defined objects are never considered pinned.
378 */
379 if (objectId >= FirstUnpinnedObjectId)
380 return false;
381
382 /*
383 * Large objects are never pinned. We need this special case because
384 * their OIDs can be user-assigned.
385 */
386 if (classId == LargeObjectRelationId)
387 return false;
388
389 /*
390 * There are a few objects defined in the catalog .dat files that, as a
391 * matter of policy, we prefer not to treat as pinned. We used to handle
392 * that by excluding them from pg_depend, but it's just as easy to
393 * hard-wire their OIDs here. (If the user does indeed drop and recreate
394 * them, they'll have new but certainly-unpinned OIDs, so no problem.)
395 *
396 * Checking both classId and objectId is overkill, since OIDs below
397 * FirstGenbkiObjectId should be globally unique, but do it anyway for
398 * robustness.
399 */
400
401 /* the public namespace is not pinned */
402 if (classId == NamespaceRelationId &&
403 objectId == PG_PUBLIC_NAMESPACE)
404 return false;
405
406 /*
407 * Databases are never pinned. It might seem that it'd be prudent to pin
408 * at least template0; but we do this intentionally so that template0 and
409 * template1 can be rebuilt from each other, thus letting them serve as
410 * mutual backups (as long as you've not modified template1, anyway).
411 */
412 if (classId == DatabaseRelationId)
413 return false;
414
415 /*
416 * All other initdb-created objects are pinned. This is overkill (the
417 * system doesn't really depend on having every last weird datatype, for
418 * instance) but generating only the minimum required set of dependencies
419 * seems hard, and enforcing an accurate list would be much more expensive
420 * than the simple range test used here.
421 */
422 return true;
423}

References FirstUnpinnedObjectId.

Referenced by checkSharedDependencies(), DropTableSpace(), findDependentObjects(), isObjectPinned(), recordSharedDependencyOn(), shdepChangeDep(), shdepDropOwned(), shdepReassignOwned(), typeDepNeeded(), and updateAclDependenciesWorker().

◆ IsReservedName()

bool IsReservedName ( const char *  name)

Definition at line 278 of file catalog.c.

279{
280 /* ugly coding for speed */
281 return (name[0] == 'p' &&
282 name[1] == 'g' &&
283 name[2] == '_');
284}
const char * name

References name.

Referenced by check_rolespec_name(), CreateRole(), CreateSchemaCommand(), CreateTableSpace(), pg_replication_origin_create(), RenameRole(), RenameSchema(), and RenameTableSpace().

◆ IsSharedRelation()

bool IsSharedRelation ( Oid  relationId)

Definition at line 304 of file catalog.c.

305{
306 /* These are the shared catalogs (look for BKI_SHARED_RELATION) */
307 if (relationId == AuthIdRelationId ||
308 relationId == AuthMemRelationId ||
309 relationId == DatabaseRelationId ||
310 relationId == DbRoleSettingRelationId ||
311 relationId == ParameterAclRelationId ||
312 relationId == ReplicationOriginRelationId ||
313 relationId == SharedDependRelationId ||
314 relationId == SharedDescriptionRelationId ||
315 relationId == SharedSecLabelRelationId ||
316 relationId == SubscriptionRelationId ||
317 relationId == TableSpaceRelationId)
318 return true;
319 /* These are their indexes */
320 if (relationId == AuthIdOidIndexId ||
321 relationId == AuthIdRolnameIndexId ||
322 relationId == AuthMemMemRoleIndexId ||
323 relationId == AuthMemRoleMemIndexId ||
324 relationId == AuthMemOidIndexId ||
325 relationId == AuthMemGrantorIndexId ||
326 relationId == DatabaseNameIndexId ||
327 relationId == DatabaseOidIndexId ||
328 relationId == DbRoleSettingDatidRolidIndexId ||
329 relationId == ParameterAclOidIndexId ||
330 relationId == ParameterAclParnameIndexId ||
331 relationId == ReplicationOriginIdentIndex ||
332 relationId == ReplicationOriginNameIndex ||
333 relationId == SharedDependDependerIndexId ||
334 relationId == SharedDependReferenceIndexId ||
335 relationId == SharedDescriptionObjIndexId ||
336 relationId == SharedSecLabelObjectIndexId ||
337 relationId == SubscriptionNameIndexId ||
338 relationId == SubscriptionObjectIndexId ||
339 relationId == TablespaceNameIndexId ||
340 relationId == TablespaceOidIndexId)
341 return true;
342 /* These are their toast tables and toast indexes */
343 if (relationId == PgDatabaseToastTable ||
344 relationId == PgDatabaseToastIndex ||
345 relationId == PgDbRoleSettingToastTable ||
346 relationId == PgDbRoleSettingToastIndex ||
347 relationId == PgParameterAclToastTable ||
348 relationId == PgParameterAclToastIndex ||
349 relationId == PgReplicationOriginToastTable ||
350 relationId == PgReplicationOriginToastIndex ||
351 relationId == PgShdescriptionToastTable ||
352 relationId == PgShdescriptionToastIndex ||
353 relationId == PgShseclabelToastTable ||
354 relationId == PgShseclabelToastIndex ||
355 relationId == PgSubscriptionToastTable ||
356 relationId == PgSubscriptionToastIndex ||
357 relationId == PgTablespaceToastTable ||
358 relationId == PgTablespaceToastIndex)
359 return true;
360 return false;
361}

Referenced by CacheInvalidateCatalog(), CacheInvalidateHeapTupleCommon(), classIdGetDbId(), DeleteSecurityLabel(), get_object_address(), GetSecurityLabel(), pg_stat_reset_single_table_counters(), pgstat_fetch_stat_tabentry(), RelationBuildLocalRelation(), SetLocktagRelationOid(), SetSecurityLabel(), and UpdateLogicalMappings().

◆ IsSystemClass()

bool IsSystemClass ( Oid  relid,
Form_pg_class  reltuple 
)

◆ IsSystemRelation()

◆ IsToastClass()

bool IsToastClass ( Form_pg_class  reltuple)

Definition at line 226 of file catalog.c.

227{
228 Oid relnamespace = reltuple->relnamespace;
229
230 return IsToastNamespace(relnamespace);
231}
bool IsToastNamespace(Oid namespaceId)
Definition: catalog.c:261

References IsToastNamespace().

Referenced by IsSystemClass().

◆ IsToastNamespace()

bool IsToastNamespace ( Oid  namespaceId)

Definition at line 261 of file catalog.c.

262{
263 return (namespaceId == PG_TOAST_NAMESPACE) ||
264 isTempToastNamespace(namespaceId);
265}
bool isTempToastNamespace(Oid namespaceId)
Definition: namespace.c:3661

References isTempToastNamespace().

Referenced by AlterTableMoveAll(), check_publication_add_schema(), heap_create(), IsToastClass(), IsToastRelation(), reindex_index(), reindex_relation(), and ReindexRelationConcurrently().

◆ IsToastRelation()

bool IsToastRelation ( Relation  relation)

Definition at line 206 of file catalog.c.

207{
208 /*
209 * What we actually check is whether the relation belongs to a pg_toast
210 * namespace. This should be equivalent because of restrictions that are
211 * enforced elsewhere against creating user relations in, or moving
212 * relations into/out of, a pg_toast namespace. Notice also that this
213 * will not say "true" for toast tables belonging to other sessions' temp
214 * tables; we expect that other mechanisms will prevent access to those.
215 */
216 return IsToastNamespace(RelationGetNamespace(relation));
217}
#define RelationGetNamespace(relation)
Definition: rel.h:557

References IsToastNamespace(), and RelationGetNamespace.

Referenced by CacheInvalidateHeapTupleCommon(), heap_abort_speculative(), heap_insert(), ReorderBufferProcessTXN(), and ReorderBufferToastAppendChunk().

◆ pg_nextoid()

Datum pg_nextoid ( PG_FUNCTION_ARGS  )

Definition at line 643 of file catalog.c.

644{
645 Oid reloid = PG_GETARG_OID(0);
647 Oid idxoid = PG_GETARG_OID(2);
648 Relation rel;
650 HeapTuple atttuple;
651 Form_pg_attribute attform;
652 AttrNumber attno;
653 Oid newoid;
654
655 /*
656 * As this function is not intended to be used during normal running, and
657 * only supports system catalogs (which require superuser permissions to
658 * modify), just checking for superuser ought to not obstruct valid
659 * usecases.
660 */
661 if (!superuser())
663 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
664 errmsg("must be superuser to call %s()",
665 "pg_nextoid")));
666
667 rel = table_open(reloid, RowExclusiveLock);
669
670 if (!IsSystemRelation(rel))
672 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
673 errmsg("pg_nextoid() can only be used on system catalogs")));
674
675 if (idx->rd_index->indrelid != RelationGetRelid(rel))
677 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
678 errmsg("index \"%s\" does not belong to table \"%s\"",
681
682 atttuple = SearchSysCacheAttName(reloid, NameStr(*attname));
683 if (!HeapTupleIsValid(atttuple))
685 (errcode(ERRCODE_UNDEFINED_COLUMN),
686 errmsg("column \"%s\" of relation \"%s\" does not exist",
688
689 attform = ((Form_pg_attribute) GETSTRUCT(atttuple));
690 attno = attform->attnum;
691
692 if (attform->atttypid != OIDOID)
694 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
695 errmsg("column \"%s\" is not of type oid",
696 NameStr(*attname))));
697
699 idx->rd_index->indkey.values[0] != attno)
701 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
702 errmsg("index \"%s\" is not the index for column \"%s\"",
704 NameStr(*attname))));
705
706 newoid = GetNewOidWithIndex(rel, idxoid, attno);
707
708 ReleaseSysCache(atttuple);
711
712 PG_RETURN_OID(newoid);
713}
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:262
int16 AttrNumber
Definition: attnum.h:21
#define NameStr(name)
Definition: c.h:717
int errcode(int sqlerrcode)
Definition: elog.c:854
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_NAME(n)
Definition: fmgr.h:278
#define PG_RETURN_OID(x)
Definition: fmgr.h:360
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:177
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:133
#define RowExclusiveLock
Definition: lockdefs.h:38
NameData attname
Definition: pg_attribute.h:41
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:202
#define IndexRelationGetNumberOfKeyAttributes(relation)
Definition: rel.h:535
Definition: c.h:712
bool superuser(void)
Definition: superuser.c:46
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Definition: syscache.c:480
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

References attname, ereport, errcode(), errmsg(), ERROR, GetNewOidWithIndex(), GETSTRUCT(), HeapTupleIsValid, idx(), index_close(), index_open(), IndexRelationGetNumberOfKeyAttributes, IsSystemRelation(), NameStr, PG_GETARG_NAME, PG_GETARG_OID, PG_RETURN_OID, RelationGetRelationName, RelationGetRelid, ReleaseSysCache(), RowExclusiveLock, SearchSysCacheAttName(), superuser(), table_close(), and table_open().

◆ pg_stop_making_pinned_objects()

Datum pg_stop_making_pinned_objects ( PG_FUNCTION_ARGS  )

Definition at line 722 of file catalog.c.

723{
724 /*
725 * Belt-and-suspenders check, since StopGeneratingPinnedObjectIds will
726 * fail anyway in non-single-user mode.
727 */
728 if (!superuser())
730 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
731 errmsg("must be superuser to call %s()",
732 "pg_stop_making_pinned_objects")));
733
735
737}
#define PG_RETURN_VOID()
Definition: fmgr.h:349
void StopGeneratingPinnedObjectIds(void)
Definition: varsup.c:652

References ereport, errcode(), errmsg(), ERROR, PG_RETURN_VOID, StopGeneratingPinnedObjectIds(), and superuser().