PostgreSQL Source Code  git master
pg_dump.h File Reference
#include "pg_backup.h"
Include dependency graph for pg_dump.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _dumpableObject
 
struct  _dumpableAcl
 
struct  _dumpableObjectWithAcl
 
struct  _namespaceInfo
 
struct  _extensionInfo
 
struct  _typeInfo
 
struct  _shellTypeInfo
 
struct  _funcInfo
 
struct  _aggInfo
 
struct  _oprInfo
 
struct  _accessMethodInfo
 
struct  _opclassInfo
 
struct  _opfamilyInfo
 
struct  _collInfo
 
struct  _convInfo
 
struct  _tableInfo
 
struct  _tableAttachInfo
 
struct  _attrDefInfo
 
struct  _tableDataInfo
 
struct  _indxInfo
 
struct  _indexAttachInfo
 
struct  _statsExtInfo
 
struct  _ruleInfo
 
struct  _triggerInfo
 
struct  _evttriggerInfo
 
struct  _constraintInfo
 
struct  _procLangInfo
 
struct  _castInfo
 
struct  _transformInfo
 
struct  _inhInfo
 
struct  _prsInfo
 
struct  _dictInfo
 
struct  _tmplInfo
 
struct  _cfgInfo
 
struct  _fdwInfo
 
struct  _foreignServerInfo
 
struct  _defaultACLInfo
 
struct  _loInfo
 
struct  _policyInfo
 
struct  _PublicationInfo
 
struct  _PublicationRelInfo
 
struct  _PublicationSchemaInfo
 
struct  _SubscriptionInfo
 

Macros

#define oidcmp(x, y)   ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) )
 
#define DUMP_COMPONENT_NONE   (0)
 
#define DUMP_COMPONENT_DEFINITION   (1 << 0)
 
#define DUMP_COMPONENT_DATA   (1 << 1)
 
#define DUMP_COMPONENT_COMMENT   (1 << 2)
 
#define DUMP_COMPONENT_SECLABEL   (1 << 3)
 
#define DUMP_COMPONENT_ACL   (1 << 4)
 
#define DUMP_COMPONENT_POLICY   (1 << 5)
 
#define DUMP_COMPONENT_USERMAP   (1 << 6)
 
#define DUMP_COMPONENT_ALL   (0xFFFF)
 
#define DUMP_COMPONENTS_REQUIRING_LOCK
 

Typedefs

typedef uint32 DumpComponents
 
typedef struct _dumpableObject DumpableObject
 
typedef struct _dumpableAcl DumpableAcl
 
typedef struct _dumpableObjectWithAcl DumpableObjectWithAcl
 
typedef struct _namespaceInfo NamespaceInfo
 
typedef struct _extensionInfo ExtensionInfo
 
typedef struct _typeInfo TypeInfo
 
typedef struct _shellTypeInfo ShellTypeInfo
 
typedef struct _funcInfo FuncInfo
 
typedef struct _aggInfo AggInfo
 
typedef struct _oprInfo OprInfo
 
typedef struct _accessMethodInfo AccessMethodInfo
 
typedef struct _opclassInfo OpclassInfo
 
typedef struct _opfamilyInfo OpfamilyInfo
 
typedef struct _collInfo CollInfo
 
typedef struct _convInfo ConvInfo
 
typedef struct _tableInfo TableInfo
 
typedef struct _tableAttachInfo TableAttachInfo
 
typedef struct _attrDefInfo AttrDefInfo
 
typedef struct _tableDataInfo TableDataInfo
 
typedef struct _indxInfo IndxInfo
 
typedef struct _indexAttachInfo IndexAttachInfo
 
typedef struct _statsExtInfo StatsExtInfo
 
typedef struct _ruleInfo RuleInfo
 
typedef struct _triggerInfo TriggerInfo
 
typedef struct _evttriggerInfo EventTriggerInfo
 
typedef struct _constraintInfo ConstraintInfo
 
typedef struct _procLangInfo ProcLangInfo
 
typedef struct _castInfo CastInfo
 
typedef struct _transformInfo TransformInfo
 
typedef struct _inhInfo InhInfo
 
typedef struct _prsInfo TSParserInfo
 
typedef struct _dictInfo TSDictInfo
 
typedef struct _tmplInfo TSTemplateInfo
 
typedef struct _cfgInfo TSConfigInfo
 
typedef struct _fdwInfo FdwInfo
 
typedef struct _foreignServerInfo ForeignServerInfo
 
typedef struct _defaultACLInfo DefaultACLInfo
 
typedef struct _loInfo LoInfo
 
typedef struct _policyInfo PolicyInfo
 
typedef struct _PublicationInfo PublicationInfo
 
typedef struct _PublicationRelInfo PublicationRelInfo
 
typedef struct _PublicationSchemaInfo PublicationSchemaInfo
 
typedef struct _SubscriptionInfo SubscriptionInfo
 

Enumerations

enum  DumpableObjectType {
  DO_NAMESPACE , DO_EXTENSION , DO_TYPE , DO_SHELL_TYPE ,
  DO_FUNC , DO_AGG , DO_OPERATOR , DO_ACCESS_METHOD ,
  DO_OPCLASS , DO_OPFAMILY , DO_COLLATION , DO_CONVERSION ,
  DO_TABLE , DO_TABLE_ATTACH , DO_ATTRDEF , DO_INDEX ,
  DO_INDEX_ATTACH , DO_STATSEXT , DO_RULE , DO_TRIGGER ,
  DO_CONSTRAINT , DO_FK_CONSTRAINT , DO_PROCLANG , DO_CAST ,
  DO_TABLE_DATA , DO_SEQUENCE_SET , DO_DUMMY_TYPE , DO_TSPARSER ,
  DO_TSDICT , DO_TSTEMPLATE , DO_TSCONFIG , DO_FDW ,
  DO_FOREIGN_SERVER , DO_DEFAULT_ACL , DO_TRANSFORM , DO_LARGE_OBJECT ,
  DO_LARGE_OBJECT_DATA , DO_PRE_DATA_BOUNDARY , DO_POST_DATA_BOUNDARY , DO_EVENT_TRIGGER ,
  DO_REFRESH_MATVIEW , DO_POLICY , DO_PUBLICATION , DO_PUBLICATION_REL ,
  DO_PUBLICATION_TABLE_IN_SCHEMA , DO_SUBSCRIPTION
}
 

Functions

TableInfogetSchemaData (Archive *fout, int *numTablesPtr)
 
void AssignDumpId (DumpableObject *dobj)
 
DumpId createDumpId (void)
 
DumpId getMaxDumpId (void)
 
DumpableObjectfindObjectByDumpId (DumpId dumpId)
 
DumpableObjectfindObjectByCatalogId (CatalogId catalogId)
 
void getDumpableObjects (DumpableObject ***objs, int *numObjs)
 
void addObjectDependency (DumpableObject *dobj, DumpId refId)
 
void removeObjectDependency (DumpableObject *dobj, DumpId refId)
 
TableInfofindTableByOid (Oid oid)
 
TypeInfofindTypeByOid (Oid oid)
 
FuncInfofindFuncByOid (Oid oid)
 
OprInfofindOprByOid (Oid oid)
 
CollInfofindCollationByOid (Oid oid)
 
NamespaceInfofindNamespaceByOid (Oid oid)
 
ExtensionInfofindExtensionByOid (Oid oid)
 
PublicationInfofindPublicationByOid (Oid oid)
 
void recordExtensionMembership (CatalogId catId, ExtensionInfo *ext)
 
ExtensionInfofindOwningExtension (CatalogId catalogId)
 
void parseOidArray (const char *str, Oid *array, int arraysize)
 
void sortDumpableObjects (DumpableObject **objs, int numObjs, DumpId preBoundaryId, DumpId postBoundaryId)
 
void sortDumpableObjectsByTypeName (DumpableObject **objs, int numObjs)
 
NamespaceInfogetNamespaces (Archive *fout, int *numNamespaces)
 
ExtensionInfogetExtensions (Archive *fout, int *numExtensions)
 
TypeInfogetTypes (Archive *fout, int *numTypes)
 
FuncInfogetFuncs (Archive *fout, int *numFuncs)
 
AggInfogetAggregates (Archive *fout, int *numAggs)
 
OprInfogetOperators (Archive *fout, int *numOprs)
 
AccessMethodInfogetAccessMethods (Archive *fout, int *numAccessMethods)
 
OpclassInfogetOpclasses (Archive *fout, int *numOpclasses)
 
OpfamilyInfogetOpfamilies (Archive *fout, int *numOpfamilies)
 
CollInfogetCollations (Archive *fout, int *numCollations)
 
ConvInfogetConversions (Archive *fout, int *numConversions)
 
TableInfogetTables (Archive *fout, int *numTables)
 
void getOwnedSeqs (Archive *fout, TableInfo tblinfo[], int numTables)
 
InhInfogetInherits (Archive *fout, int *numInherits)
 
void getPartitioningInfo (Archive *fout)
 
void getIndexes (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getExtendedStatistics (Archive *fout)
 
void getConstraints (Archive *fout, TableInfo tblinfo[], int numTables)
 
RuleInfogetRules (Archive *fout, int *numRules)
 
void getTriggers (Archive *fout, TableInfo tblinfo[], int numTables)
 
ProcLangInfogetProcLangs (Archive *fout, int *numProcLangs)
 
CastInfogetCasts (Archive *fout, int *numCasts)
 
TransformInfogetTransforms (Archive *fout, int *numTransforms)
 
void getTableAttrs (Archive *fout, TableInfo *tblinfo, int numTables)
 
bool shouldPrintColumn (const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
 
TSParserInfogetTSParsers (Archive *fout, int *numTSParsers)
 
TSDictInfogetTSDictionaries (Archive *fout, int *numTSDicts)
 
TSTemplateInfogetTSTemplates (Archive *fout, int *numTSTemplates)
 
TSConfigInfogetTSConfigurations (Archive *fout, int *numTSConfigs)
 
FdwInfogetForeignDataWrappers (Archive *fout, int *numForeignDataWrappers)
 
ForeignServerInfogetForeignServers (Archive *fout, int *numForeignServers)
 
DefaultACLInfogetDefaultACLs (Archive *fout, int *numDefaultACLs)
 
void getExtensionMembership (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
void processExtensionTables (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
EventTriggerInfogetEventTriggers (Archive *fout, int *numEventTriggers)
 
void getPolicies (Archive *fout, TableInfo tblinfo[], int numTables)
 
PublicationInfogetPublications (Archive *fout, int *numPublications)
 
void getPublicationNamespaces (Archive *fout)
 
void getPublicationTables (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getSubscriptions (Archive *fout)
 

Macro Definition Documentation

◆ DUMP_COMPONENT_ACL

#define DUMP_COMPONENT_ACL   (1 << 4)

Definition at line 100 of file pg_dump.h.

◆ DUMP_COMPONENT_ALL

#define DUMP_COMPONENT_ALL   (0xFFFF)

Definition at line 103 of file pg_dump.h.

◆ DUMP_COMPONENT_COMMENT

#define DUMP_COMPONENT_COMMENT   (1 << 2)

Definition at line 98 of file pg_dump.h.

◆ DUMP_COMPONENT_DATA

#define DUMP_COMPONENT_DATA   (1 << 1)

Definition at line 97 of file pg_dump.h.

◆ DUMP_COMPONENT_DEFINITION

#define DUMP_COMPONENT_DEFINITION   (1 << 0)

Definition at line 96 of file pg_dump.h.

◆ DUMP_COMPONENT_NONE

#define DUMP_COMPONENT_NONE   (0)

Definition at line 95 of file pg_dump.h.

◆ DUMP_COMPONENT_POLICY

#define DUMP_COMPONENT_POLICY   (1 << 5)

Definition at line 101 of file pg_dump.h.

◆ DUMP_COMPONENT_SECLABEL

#define DUMP_COMPONENT_SECLABEL   (1 << 3)

Definition at line 99 of file pg_dump.h.

◆ DUMP_COMPONENT_USERMAP

#define DUMP_COMPONENT_USERMAP   (1 << 6)

Definition at line 102 of file pg_dump.h.

◆ DUMP_COMPONENTS_REQUIRING_LOCK

#define DUMP_COMPONENTS_REQUIRING_LOCK
Value:
(\
DUMP_COMPONENT_DEFINITION |\
DUMP_COMPONENT_DATA |\
DUMP_COMPONENT_POLICY)

Definition at line 127 of file pg_dump.h.

◆ oidcmp

#define oidcmp (   x,
  y 
)    ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) )

Definition at line 20 of file pg_dump.h.

Typedef Documentation

◆ AccessMethodInfo

◆ AggInfo

typedef struct _aggInfo AggInfo

◆ AttrDefInfo

typedef struct _attrDefInfo AttrDefInfo

◆ CastInfo

typedef struct _castInfo CastInfo

◆ CollInfo

typedef struct _collInfo CollInfo

◆ ConstraintInfo

◆ ConvInfo

typedef struct _convInfo ConvInfo

◆ DefaultACLInfo

◆ DumpableAcl

typedef struct _dumpableAcl DumpableAcl

◆ DumpableObject

◆ DumpableObjectWithAcl

◆ DumpComponents

Definition at line 94 of file pg_dump.h.

◆ EventTriggerInfo

◆ ExtensionInfo

typedef struct _extensionInfo ExtensionInfo

◆ FdwInfo

typedef struct _fdwInfo FdwInfo

◆ ForeignServerInfo

◆ FuncInfo

typedef struct _funcInfo FuncInfo

◆ IndexAttachInfo

◆ IndxInfo

typedef struct _indxInfo IndxInfo

◆ InhInfo

typedef struct _inhInfo InhInfo

◆ LoInfo

typedef struct _loInfo LoInfo

◆ NamespaceInfo

typedef struct _namespaceInfo NamespaceInfo

◆ OpclassInfo

typedef struct _opclassInfo OpclassInfo

◆ OpfamilyInfo

typedef struct _opfamilyInfo OpfamilyInfo

◆ OprInfo

typedef struct _oprInfo OprInfo

◆ PolicyInfo

typedef struct _policyInfo PolicyInfo

◆ ProcLangInfo

typedef struct _procLangInfo ProcLangInfo

◆ PublicationInfo

◆ PublicationRelInfo

◆ PublicationSchemaInfo

◆ RuleInfo

typedef struct _ruleInfo RuleInfo

◆ ShellTypeInfo

typedef struct _shellTypeInfo ShellTypeInfo

◆ StatsExtInfo

typedef struct _statsExtInfo StatsExtInfo

◆ SubscriptionInfo

◆ TableAttachInfo

◆ TableDataInfo

typedef struct _tableDataInfo TableDataInfo

◆ TableInfo

typedef struct _tableInfo TableInfo

◆ TransformInfo

typedef struct _transformInfo TransformInfo

◆ TriggerInfo

typedef struct _triggerInfo TriggerInfo

◆ TSConfigInfo

typedef struct _cfgInfo TSConfigInfo

◆ TSDictInfo

typedef struct _dictInfo TSDictInfo

◆ TSParserInfo

typedef struct _prsInfo TSParserInfo

◆ TSTemplateInfo

typedef struct _tmplInfo TSTemplateInfo

◆ TypeInfo

typedef struct _typeInfo TypeInfo

Enumeration Type Documentation

◆ DumpableObjectType

Enumerator
DO_NAMESPACE 
DO_EXTENSION 
DO_TYPE 
DO_SHELL_TYPE 
DO_FUNC 
DO_AGG 
DO_OPERATOR 
DO_ACCESS_METHOD 
DO_OPCLASS 
DO_OPFAMILY 
DO_COLLATION 
DO_CONVERSION 
DO_TABLE 
DO_TABLE_ATTACH 
DO_ATTRDEF 
DO_INDEX 
DO_INDEX_ATTACH 
DO_STATSEXT 
DO_RULE 
DO_TRIGGER 
DO_CONSTRAINT 
DO_FK_CONSTRAINT 
DO_PROCLANG 
DO_CAST 
DO_TABLE_DATA 
DO_SEQUENCE_SET 
DO_DUMMY_TYPE 
DO_TSPARSER 
DO_TSDICT 
DO_TSTEMPLATE 
DO_TSCONFIG 
DO_FDW 
DO_FOREIGN_SERVER 
DO_DEFAULT_ACL 
DO_TRANSFORM 
DO_LARGE_OBJECT 
DO_LARGE_OBJECT_DATA 
DO_PRE_DATA_BOUNDARY 
DO_POST_DATA_BOUNDARY 
DO_EVENT_TRIGGER 
DO_REFRESH_MATVIEW 
DO_POLICY 
DO_PUBLICATION 
DO_PUBLICATION_REL 
DO_PUBLICATION_TABLE_IN_SCHEMA 
DO_SUBSCRIPTION 

Definition at line 37 of file pg_dump.h.

38 {
39  /* When modifying this enum, update priority tables in pg_dump_sort.c! */
42  DO_TYPE,
44  DO_FUNC,
45  DO_AGG,
48  DO_OPCLASS,
52  DO_TABLE,
54  DO_ATTRDEF,
55  DO_INDEX,
58  DO_RULE,
59  DO_TRIGGER,
61  DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
63  DO_CAST,
68  DO_TSDICT,
71  DO_FDW,
81  DO_POLICY,
DumpableObjectType
Definition: pg_dump.h:38
@ DO_EVENT_TRIGGER
Definition: pg_dump.h:79
@ DO_REFRESH_MATVIEW
Definition: pg_dump.h:80
@ DO_POLICY
Definition: pg_dump.h:81
@ DO_CAST
Definition: pg_dump.h:63
@ DO_FOREIGN_SERVER
Definition: pg_dump.h:72
@ DO_PRE_DATA_BOUNDARY
Definition: pg_dump.h:77
@ DO_PROCLANG
Definition: pg_dump.h:62
@ DO_TYPE
Definition: pg_dump.h:42
@ DO_INDEX
Definition: pg_dump.h:55
@ DO_COLLATION
Definition: pg_dump.h:50
@ DO_LARGE_OBJECT
Definition: pg_dump.h:75
@ DO_TSCONFIG
Definition: pg_dump.h:70
@ DO_OPERATOR
Definition: pg_dump.h:46
@ DO_FK_CONSTRAINT
Definition: pg_dump.h:61
@ DO_CONSTRAINT
Definition: pg_dump.h:60
@ DO_SUBSCRIPTION
Definition: pg_dump.h:85
@ DO_DEFAULT_ACL
Definition: pg_dump.h:73
@ DO_FDW
Definition: pg_dump.h:71
@ DO_SEQUENCE_SET
Definition: pg_dump.h:65
@ DO_ATTRDEF
Definition: pg_dump.h:54
@ DO_PUBLICATION_REL
Definition: pg_dump.h:83
@ DO_TABLE_ATTACH
Definition: pg_dump.h:53
@ DO_OPCLASS
Definition: pg_dump.h:48
@ DO_INDEX_ATTACH
Definition: pg_dump.h:56
@ DO_TSTEMPLATE
Definition: pg_dump.h:69
@ DO_STATSEXT
Definition: pg_dump.h:57
@ DO_FUNC
Definition: pg_dump.h:44
@ DO_POST_DATA_BOUNDARY
Definition: pg_dump.h:78
@ DO_LARGE_OBJECT_DATA
Definition: pg_dump.h:76
@ DO_OPFAMILY
Definition: pg_dump.h:49
@ DO_TRANSFORM
Definition: pg_dump.h:74
@ DO_ACCESS_METHOD
Definition: pg_dump.h:47
@ DO_PUBLICATION_TABLE_IN_SCHEMA
Definition: pg_dump.h:84
@ DO_CONVERSION
Definition: pg_dump.h:51
@ DO_TRIGGER
Definition: pg_dump.h:59
@ DO_RULE
Definition: pg_dump.h:58
@ DO_DUMMY_TYPE
Definition: pg_dump.h:66
@ DO_TSDICT
Definition: pg_dump.h:68
@ DO_TSPARSER
Definition: pg_dump.h:67
@ DO_EXTENSION
Definition: pg_dump.h:41
@ DO_TABLE_DATA
Definition: pg_dump.h:64
@ DO_PUBLICATION
Definition: pg_dump.h:82
@ DO_TABLE
Definition: pg_dump.h:52
@ DO_NAMESPACE
Definition: pg_dump.h:40
@ DO_AGG
Definition: pg_dump.h:45
@ DO_SHELL_TYPE
Definition: pg_dump.h:43

Function Documentation

◆ addObjectDependency()

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

◆ AssignDumpId()

void AssignDumpId ( DumpableObject dobj)

Definition at line 642 of file common.c.

643 {
644  dobj->dumpId = ++lastDumpId;
645  dobj->name = NULL; /* must be set later */
646  dobj->namespace = NULL; /* may be set later */
647  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
648  dobj->dump_contains = DUMP_COMPONENT_ALL; /* default assumption */
649  /* All objects have definitions; we may set more components bits later */
651  dobj->ext_member = false; /* default assumption */
652  dobj->depends_on_ext = false; /* default assumption */
653  dobj->dependencies = NULL;
654  dobj->nDeps = 0;
655  dobj->allocDeps = 0;
656 
657  /* Add object to dumpIdMap[], enlarging that array if need be */
658  while (dobj->dumpId >= allocedDumpIds)
659  {
660  int newAlloc;
661 
662  if (allocedDumpIds <= 0)
663  {
664  newAlloc = 256;
666  }
667  else
668  {
669  newAlloc = allocedDumpIds * 2;
671  }
672  memset(dumpIdMap + allocedDumpIds, 0,
673  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
674  allocedDumpIds = newAlloc;
675  }
676  dumpIdMap[dobj->dumpId] = dobj;
677 
678  /* If it has a valid CatalogId, enter it into the hash table */
679  if (OidIsValid(dobj->catId.tableoid))
680  {
681  CatalogIdMapEntry *entry;
682  bool found;
683 
684  /* Initialize CatalogId hash table if not done yet */
685  if (catalogIdHash == NULL)
686  catalogIdHash = catalogid_create(CATALOGIDHASH_INITIAL_SIZE, NULL);
687 
688  entry = catalogid_insert(catalogIdHash, dobj->catId, &found);
689  if (!found)
690  {
691  entry->dobj = NULL;
692  entry->ext = NULL;
693  }
694  Assert(entry->dobj == NULL);
695  entry->dobj = dobj;
696  }
697 }
static int allocedDumpIds
Definition: common.c:38
static DumpableObject ** dumpIdMap
Definition: common.c:37
#define CATALOGIDHASH_INITIAL_SIZE
Definition: common.c:78
static catalogid_hash * catalogIdHash
Definition: common.c:80
static DumpId lastDumpId
Definition: common.c:39
#define OidIsValid(objectId)
Definition: c.h:764
Assert(fmt[strlen(fmt) - 1] !='\n')
#define DUMP_COMPONENT_ALL
Definition: pg_dump.h:103
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:96
Oid tableoid
Definition: pg_backup.h:264
ExtensionInfo * ext
Definition: common.c:61
DumpableObject * dobj
Definition: common.c:60
DumpComponents dump
Definition: pg_dump.h:138
char * name
Definition: pg_dump.h:137
DumpId dumpId
Definition: pg_dump.h:136
bool ext_member
Definition: pg_dump.h:142
DumpComponents components
Definition: pg_dump.h:141
CatalogId catId
Definition: pg_dump.h:135
DumpComponents dump_contains
Definition: pg_dump.h:140
bool depends_on_ext
Definition: pg_dump.h:143

References _dumpableObject::allocDeps, allocedDumpIds, Assert(), catalogIdHash, CATALOGIDHASH_INITIAL_SIZE, _dumpableObject::catId, _dumpableObject::components, _dumpableObject::dependencies, _dumpableObject::depends_on_ext, _catalogIdMapEntry::dobj, _dumpableObject::dump, DUMP_COMPONENT_ALL, DUMP_COMPONENT_DEFINITION, _dumpableObject::dump_contains, _dumpableObject::dumpId, dumpIdMap, _catalogIdMapEntry::ext, _dumpableObject::ext_member, lastDumpId, _dumpableObject::name, _dumpableObject::nDeps, OidIsValid, pg_malloc_array, pg_realloc_array, and CatalogId::tableoid.

Referenced by createBoundaryObjects(), flagInhAttrs(), flagInhIndexes(), flagInhTables(), getAccessMethods(), getAggregates(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDomainConstraints(), getEventTriggers(), getExtendedStatistics(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), getLOs(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getPolicies(), getProcLangs(), getPublicationNamespaces(), getPublications(), getPublicationTables(), getRules(), getSubscriptions(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), and makeTableDataInfo().

◆ createDumpId()

◆ findCollationByOid()

CollInfo* findCollationByOid ( Oid  oid)

Definition at line 915 of file common.c.

916 {
917  CatalogId catId;
918  DumpableObject *dobj;
919 
920  catId.tableoid = CollationRelationId;
921  catId.oid = oid;
922  dobj = findObjectByCatalogId(catId);
923  Assert(dobj == NULL || dobj->objType == DO_COLLATION);
924  return (CollInfo *) dobj;
925 }
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition: common.c:739
DumpableObjectType objType
Definition: pg_dump.h:134

References Assert(), DO_COLLATION, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by createDummyViewAsClause(), dumpCompositeType(), dumpDomain(), dumpRangeType(), and dumpTableSchema().

◆ findExtensionByOid()

ExtensionInfo* findExtensionByOid ( Oid  oid)

Definition at line 951 of file common.c.

952 {
953  CatalogId catId;
954  DumpableObject *dobj;
955 
956  catId.tableoid = ExtensionRelationId;
957  catId.oid = oid;
958  dobj = findObjectByCatalogId(catId);
959  Assert(dobj == NULL || dobj->objType == DO_EXTENSION);
960  return (ExtensionInfo *) dobj;
961 }

References Assert(), DO_EXTENSION, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getExtensionMembership().

◆ findFuncByOid()

FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 879 of file common.c.

880 {
881  CatalogId catId;
882  DumpableObject *dobj;
883 
884  catId.tableoid = ProcedureRelationId;
885  catId.oid = oid;
886  dobj = findObjectByCatalogId(catId);
887  Assert(dobj == NULL || dobj->objType == DO_FUNC);
888  return (FuncInfo *) dobj;
889 }

References Assert(), DO_FUNC, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by dumpCast(), dumpProcLang(), and dumpTransform().

◆ findNamespaceByOid()

NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 933 of file common.c.

934 {
935  CatalogId catId;
936  DumpableObject *dobj;
937 
938  catId.tableoid = NamespaceRelationId;
939  catId.oid = oid;
940  dobj = findObjectByCatalogId(catId);
941  Assert(dobj == NULL || dobj->objType == DO_NAMESPACE);
942  return (NamespaceInfo *) dobj;
943 }

References Assert(), DO_NAMESPACE, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by findNamespace(), and getPublicationNamespaces().

◆ findObjectByCatalogId()

DumpableObject* findObjectByCatalogId ( CatalogId  catalogId)

Definition at line 739 of file common.c.

740 {
741  CatalogIdMapEntry *entry;
742 
743  if (catalogIdHash == NULL)
744  return NULL; /* no objects exist yet */
745 
746  entry = catalogid_lookup(catalogIdHash, catalogId);
747  if (entry == NULL)
748  return NULL;
749  return entry->dobj;
750 }

References catalogIdHash, and _catalogIdMapEntry::dobj.

Referenced by buildMatViewRefreshDependencies(), collectComments(), collectSecLabels(), findCollationByOid(), findExtensionByOid(), findFuncByOid(), findIndexByOid(), findNamespaceByOid(), findOprByOid(), findPublicationByOid(), findTableByOid(), findTypeByOid(), getAdditionalACLs(), and getDependencies().

◆ findObjectByDumpId()

DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 726 of file common.c.

727 {
728  if (dumpId <= 0 || dumpId >= allocedDumpIds)
729  return NULL; /* out of range? */
730  return dumpIdMap[dumpId];
731 }

References allocedDumpIds, and dumpIdMap.

Referenced by binary_upgrade_extension_member(), BuildArchiveDependencies(), dumpConstraint(), dumpExtension(), findDumpableDependencies(), and findLoop().

◆ findOprByOid()

OprInfo* findOprByOid ( Oid  oid)

Definition at line 897 of file common.c.

898 {
899  CatalogId catId;
900  DumpableObject *dobj;
901 
902  catId.tableoid = OperatorRelationId;
903  catId.oid = oid;
904  dobj = findObjectByCatalogId(catId);
905  Assert(dobj == NULL || dobj->objType == DO_OPERATOR);
906  return (OprInfo *) dobj;
907 }

References Assert(), DO_OPERATOR, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getFormattedOperatorName().

◆ findOwningExtension()

ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 1012 of file common.c.

1013 {
1014  CatalogIdMapEntry *entry;
1015 
1016  if (catalogIdHash == NULL)
1017  return NULL; /* no objects exist yet */
1018 
1019  entry = catalogid_lookup(catalogIdHash, catalogId);
1020  if (entry == NULL)
1021  return NULL;
1022  return entry->ext;
1023 }

References catalogIdHash, and _catalogIdMapEntry::ext.

Referenced by checkExtensionMembership().

◆ findPublicationByOid()

PublicationInfo* findPublicationByOid ( Oid  oid)

Definition at line 969 of file common.c.

970 {
971  CatalogId catId;
972  DumpableObject *dobj;
973 
974  catId.tableoid = PublicationRelationId;
975  catId.oid = oid;
976  dobj = findObjectByCatalogId(catId);
977  Assert(dobj == NULL || dobj->objType == DO_PUBLICATION);
978  return (PublicationInfo *) dobj;
979 }

References Assert(), DO_PUBLICATION, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getPublicationNamespaces(), and getPublicationTables().

◆ findTableByOid()

TableInfo* findTableByOid ( Oid  oid)

Definition at line 824 of file common.c.

825 {
826  CatalogId catId;
827  DumpableObject *dobj;
828 
829  catId.tableoid = RelationRelationId;
830  catId.oid = oid;
831  dobj = findObjectByCatalogId(catId);
832  Assert(dobj == NULL || dobj->objType == DO_TABLE);
833  return (TableInfo *) dobj;
834 }

References Assert(), DO_TABLE, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by dumpSequence(), flagInhTables(), getAdditionalACLs(), getConstraints(), getOwnedSeqs(), getPartitioningInfo(), getPolicies(), getPublicationTables(), getRules(), getTableDataFKConstraints(), processExtensionTables(), and selectDumpableType().

◆ findTypeByOid()

TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 860 of file common.c.

861 {
862  CatalogId catId;
863  DumpableObject *dobj;
864 
865  catId.tableoid = TypeRelationId;
866  catId.oid = oid;
867  dobj = findObjectByCatalogId(catId);
868  Assert(dobj == NULL ||
869  dobj->objType == DO_TYPE || dobj->objType == DO_DUMMY_TYPE);
870  return (TypeInfo *) dobj;
871 }

References Assert(), DO_DUMMY_TYPE, DO_TYPE, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by collectComments(), collectSecLabels(), DOTypeNameCompare(), getCasts(), getFormattedTypeName(), and getTransforms().

◆ getAccessMethods()

AccessMethodInfo* getAccessMethods ( Archive fout,
int *  numAccessMethods 
)

Definition at line 5797 of file pg_dump.c.

5798 {
5799  PGresult *res;
5800  int ntups;
5801  int i;
5802  PQExpBuffer query;
5803  AccessMethodInfo *aminfo;
5804  int i_tableoid;
5805  int i_oid;
5806  int i_amname;
5807  int i_amhandler;
5808  int i_amtype;
5809 
5810  /* Before 9.6, there are no user-defined access methods */
5811  if (fout->remoteVersion < 90600)
5812  {
5813  *numAccessMethods = 0;
5814  return NULL;
5815  }
5816 
5817  query = createPQExpBuffer();
5818 
5819  /* Select all access methods from pg_am table */
5820  appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, amtype, "
5821  "amhandler::pg_catalog.regproc AS amhandler "
5822  "FROM pg_am");
5823 
5824  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5825 
5826  ntups = PQntuples(res);
5827  *numAccessMethods = ntups;
5828 
5829  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
5830 
5831  i_tableoid = PQfnumber(res, "tableoid");
5832  i_oid = PQfnumber(res, "oid");
5833  i_amname = PQfnumber(res, "amname");
5834  i_amhandler = PQfnumber(res, "amhandler");
5835  i_amtype = PQfnumber(res, "amtype");
5836 
5837  for (i = 0; i < ntups; i++)
5838  {
5839  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
5840  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5841  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5842  AssignDumpId(&aminfo[i].dobj);
5843  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
5844  aminfo[i].dobj.namespace = NULL;
5845  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
5846  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
5847 
5848  /* Decide whether we want to dump it */
5849  selectDumpableAccessMethod(&(aminfo[i]), fout);
5850  }
5851 
5852  PQclear(res);
5853 
5854  destroyPQExpBuffer(query);
5855 
5856  return aminfo;
5857 }
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:642
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3422
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3817
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3530
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int i
Definition: isn.c:73
@ PGRES_TUPLES_OK
Definition: libpq-fe.h:100
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:290
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:1979
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:72
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:114
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:367
int remoteVersion
Definition: pg_backup.h:217
char * amhandler
Definition: pg_dump.h:252
DumpableObject dobj
Definition: pg_dump.h:250

References _accessMethodInfo::amhandler, _accessMethodInfo::amtype, appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_ACCESS_METHOD, _accessMethodInfo::dobj, ExecuteSqlQuery(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, selectDumpableAccessMethod(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getAggregates()

AggInfo* getAggregates ( Archive fout,
int *  numAggs 
)

Definition at line 6002 of file pg_dump.c.

6003 {
6004  DumpOptions *dopt = fout->dopt;
6005  PGresult *res;
6006  int ntups;
6007  int i;
6008  PQExpBuffer query = createPQExpBuffer();
6009  AggInfo *agginfo;
6010  int i_tableoid;
6011  int i_oid;
6012  int i_aggname;
6013  int i_aggnamespace;
6014  int i_pronargs;
6015  int i_proargtypes;
6016  int i_proowner;
6017  int i_aggacl;
6018  int i_acldefault;
6019 
6020  /*
6021  * Find all interesting aggregates. See comment in getFuncs() for the
6022  * rationale behind the filtering logic.
6023  */
6024  if (fout->remoteVersion >= 90600)
6025  {
6026  const char *agg_check;
6027 
6028  agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
6029  : "p.proisagg");
6030 
6031  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
6032  "p.proname AS aggname, "
6033  "p.pronamespace AS aggnamespace, "
6034  "p.pronargs, p.proargtypes, "
6035  "p.proowner, "
6036  "p.proacl AS aggacl, "
6037  "acldefault('f', p.proowner) AS acldefault "
6038  "FROM pg_proc p "
6039  "LEFT JOIN pg_init_privs pip ON "
6040  "(p.oid = pip.objoid "
6041  "AND pip.classoid = 'pg_proc'::regclass "
6042  "AND pip.objsubid = 0) "
6043  "WHERE %s AND ("
6044  "p.pronamespace != "
6045  "(SELECT oid FROM pg_namespace "
6046  "WHERE nspname = 'pg_catalog') OR "
6047  "p.proacl IS DISTINCT FROM pip.initprivs",
6048  agg_check);
6049  if (dopt->binary_upgrade)
6050  appendPQExpBufferStr(query,
6051  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6052  "classid = 'pg_proc'::regclass AND "
6053  "objid = p.oid AND "
6054  "refclassid = 'pg_extension'::regclass AND "
6055  "deptype = 'e')");
6056  appendPQExpBufferChar(query, ')');
6057  }
6058  else
6059  {
6060  appendPQExpBufferStr(query, "SELECT tableoid, oid, proname AS aggname, "
6061  "pronamespace AS aggnamespace, "
6062  "pronargs, proargtypes, "
6063  "proowner, "
6064  "proacl AS aggacl, "
6065  "acldefault('f', proowner) AS acldefault "
6066  "FROM pg_proc p "
6067  "WHERE proisagg AND ("
6068  "pronamespace != "
6069  "(SELECT oid FROM pg_namespace "
6070  "WHERE nspname = 'pg_catalog')");
6071  if (dopt->binary_upgrade)
6072  appendPQExpBufferStr(query,
6073  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6074  "classid = 'pg_proc'::regclass AND "
6075  "objid = p.oid AND "
6076  "refclassid = 'pg_extension'::regclass AND "
6077  "deptype = 'e')");
6078  appendPQExpBufferChar(query, ')');
6079  }
6080 
6081  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6082 
6083  ntups = PQntuples(res);
6084  *numAggs = ntups;
6085 
6086  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
6087 
6088  i_tableoid = PQfnumber(res, "tableoid");
6089  i_oid = PQfnumber(res, "oid");
6090  i_aggname = PQfnumber(res, "aggname");
6091  i_aggnamespace = PQfnumber(res, "aggnamespace");
6092  i_pronargs = PQfnumber(res, "pronargs");
6093  i_proargtypes = PQfnumber(res, "proargtypes");
6094  i_proowner = PQfnumber(res, "proowner");
6095  i_aggacl = PQfnumber(res, "aggacl");
6096  i_acldefault = PQfnumber(res, "acldefault");
6097 
6098  for (i = 0; i < ntups; i++)
6099  {
6100  agginfo[i].aggfn.dobj.objType = DO_AGG;
6101  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6102  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6103  AssignDumpId(&agginfo[i].aggfn.dobj);
6104  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
6105  agginfo[i].aggfn.dobj.namespace =
6106  findNamespace(atooid(PQgetvalue(res, i, i_aggnamespace)));
6107  agginfo[i].aggfn.dacl.acl = pg_strdup(PQgetvalue(res, i, i_aggacl));
6108  agginfo[i].aggfn.dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6109  agginfo[i].aggfn.dacl.privtype = 0;
6110  agginfo[i].aggfn.dacl.initprivs = NULL;
6111  agginfo[i].aggfn.rolname = getRoleName(PQgetvalue(res, i, i_proowner));
6112  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
6113  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
6114  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
6115  if (agginfo[i].aggfn.nargs == 0)
6116  agginfo[i].aggfn.argtypes = NULL;
6117  else
6118  {
6119  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
6120  parseOidArray(PQgetvalue(res, i, i_proargtypes),
6121  agginfo[i].aggfn.argtypes,
6122  agginfo[i].aggfn.nargs);
6123  }
6124  agginfo[i].aggfn.postponed_def = false; /* might get set during sort */
6125 
6126  /* Decide whether we want to dump it */
6127  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
6128 
6129  /* Mark whether aggregate has an ACL */
6130  if (!PQgetisnull(res, i, i_aggacl))
6131  agginfo[i].aggfn.dobj.components |= DUMP_COMPONENT_ACL;
6132  }
6133 
6134  PQclear(res);
6135 
6136  destroyPQExpBuffer(query);
6137 
6138  return agginfo;
6139 }
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1036
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3842
static const char * getRoleName(const char *roleoid_str)
Definition: pg_dump.c:9708
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:2056
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:5324
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:100
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:265
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:378
DumpOptions * dopt
Definition: pg_backup.h:212
int binary_upgrade
Definition: pg_backup.h:164

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_AGG, Archive::dopt, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, InvalidOid, parseOidArray(), pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, and selectDumpableObject().

Referenced by getSchemaData().

◆ getCasts()

CastInfo* getCasts ( Archive fout,
int *  numCasts 
)

Definition at line 8183 of file pg_dump.c.

8184 {
8185  PGresult *res;
8186  int ntups;
8187  int i;
8188  PQExpBuffer query = createPQExpBuffer();
8189  CastInfo *castinfo;
8190  int i_tableoid;
8191  int i_oid;
8192  int i_castsource;
8193  int i_casttarget;
8194  int i_castfunc;
8195  int i_castcontext;
8196  int i_castmethod;
8197 
8198  if (fout->remoteVersion >= 140000)
8199  {
8200  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8201  "castsource, casttarget, castfunc, castcontext, "
8202  "castmethod "
8203  "FROM pg_cast c "
8204  "WHERE NOT EXISTS ( "
8205  "SELECT 1 FROM pg_range r "
8206  "WHERE c.castsource = r.rngtypid "
8207  "AND c.casttarget = r.rngmultitypid "
8208  ") "
8209  "ORDER BY 3,4");
8210  }
8211  else
8212  {
8213  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8214  "castsource, casttarget, castfunc, castcontext, "
8215  "castmethod "
8216  "FROM pg_cast ORDER BY 3,4");
8217  }
8218 
8219  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8220 
8221  ntups = PQntuples(res);
8222 
8223  *numCasts = ntups;
8224 
8225  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
8226 
8227  i_tableoid = PQfnumber(res, "tableoid");
8228  i_oid = PQfnumber(res, "oid");
8229  i_castsource = PQfnumber(res, "castsource");
8230  i_casttarget = PQfnumber(res, "casttarget");
8231  i_castfunc = PQfnumber(res, "castfunc");
8232  i_castcontext = PQfnumber(res, "castcontext");
8233  i_castmethod = PQfnumber(res, "castmethod");
8234 
8235  for (i = 0; i < ntups; i++)
8236  {
8237  PQExpBufferData namebuf;
8238  TypeInfo *sTypeInfo;
8239  TypeInfo *tTypeInfo;
8240 
8241  castinfo[i].dobj.objType = DO_CAST;
8242  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8243  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8244  AssignDumpId(&castinfo[i].dobj);
8245  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
8246  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
8247  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
8248  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
8249  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
8250 
8251  /*
8252  * Try to name cast as concatenation of typnames. This is only used
8253  * for purposes of sorting. If we fail to find either type, the name
8254  * will be an empty string.
8255  */
8256  initPQExpBuffer(&namebuf);
8257  sTypeInfo = findTypeByOid(castinfo[i].castsource);
8258  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
8259  if (sTypeInfo && tTypeInfo)
8260  appendPQExpBuffer(&namebuf, "%s %s",
8261  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
8262  castinfo[i].dobj.name = namebuf.data;
8263 
8264  /* Decide whether we want to dump it */
8265  selectDumpableCast(&(castinfo[i]), fout);
8266  }
8267 
8268  PQclear(res);
8269 
8270  destroyPQExpBuffer(query);
8271 
8272  return castinfo;
8273 }
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:860
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:1921
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
char castmethod
Definition: pg_dump.h:512
Oid casttarget
Definition: pg_dump.h:509
char castcontext
Definition: pg_dump.h:511
DumpableObject dobj
Definition: pg_dump.h:507
Oid castsource
Definition: pg_dump.h:508
Oid castfunc
Definition: pg_dump.h:510
DumpableObject dobj
Definition: pg_dump.h:190

References appendPQExpBuffer(), appendPQExpBufferStr(), AssignDumpId(), atooid, _castInfo::castcontext, _castInfo::castfunc, _castInfo::castmethod, _castInfo::castsource, _castInfo::casttarget, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_CAST, _typeInfo::dobj, _castInfo::dobj, ExecuteSqlQuery(), findTypeByOid(), i, initPQExpBuffer(), _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, selectDumpableCast(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getCollations()

CollInfo* getCollations ( Archive fout,
int *  numCollations 
)

Definition at line 5661 of file pg_dump.c.

5662 {
5663  PGresult *res;
5664  int ntups;
5665  int i;
5666  PQExpBuffer query;
5667  CollInfo *collinfo;
5668  int i_tableoid;
5669  int i_oid;
5670  int i_collname;
5671  int i_collnamespace;
5672  int i_collowner;
5673 
5674  query = createPQExpBuffer();
5675 
5676  /*
5677  * find all collations, including builtin collations; we filter out
5678  * system-defined collations at dump-out time.
5679  */
5680 
5681  appendPQExpBufferStr(query, "SELECT tableoid, oid, collname, "
5682  "collnamespace, "
5683  "collowner "
5684  "FROM pg_collation");
5685 
5686  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5687 
5688  ntups = PQntuples(res);
5689  *numCollations = ntups;
5690 
5691  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
5692 
5693  i_tableoid = PQfnumber(res, "tableoid");
5694  i_oid = PQfnumber(res, "oid");
5695  i_collname = PQfnumber(res, "collname");
5696  i_collnamespace = PQfnumber(res, "collnamespace");
5697  i_collowner = PQfnumber(res, "collowner");
5698 
5699  for (i = 0; i < ntups; i++)
5700  {
5701  collinfo[i].dobj.objType = DO_COLLATION;
5702  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5703  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5704  AssignDumpId(&collinfo[i].dobj);
5705  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
5706  collinfo[i].dobj.namespace =
5707  findNamespace(atooid(PQgetvalue(res, i, i_collnamespace)));
5708  collinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_collowner));
5709 
5710  /* Decide whether we want to dump it */
5711  selectDumpableObject(&(collinfo[i].dobj), fout);
5712  }
5713 
5714  PQclear(res);
5715 
5716  destroyPQExpBuffer(query);
5717 
5718  return collinfo;
5719 }
const char * rolname
Definition: pg_dump.h:270
DumpableObject dobj
Definition: pg_dump.h:269

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_COLLATION, _collInfo::dobj, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), res, _collInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getConstraints()

void getConstraints ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 7355 of file pg_dump.c.

7356 {
7357  PQExpBuffer query = createPQExpBuffer();
7358  PQExpBuffer tbloids = createPQExpBuffer();
7359  PGresult *res;
7360  int ntups;
7361  int curtblindx;
7362  TableInfo *tbinfo = NULL;
7363  ConstraintInfo *constrinfo;
7364  int i_contableoid,
7365  i_conoid,
7366  i_conrelid,
7367  i_conname,
7368  i_confrelid,
7369  i_conindid,
7370  i_condef;
7371 
7372  /*
7373  * We want to perform just one query against pg_constraint. However, we
7374  * mustn't try to select every row of the catalog and then sort it out on
7375  * the client side, because some of the server-side functions we need
7376  * would be unsafe to apply to tables we don't have lock on. Hence, we
7377  * build an array of the OIDs of tables we care about (and now have lock
7378  * on!), and use a WHERE clause to constrain which rows are selected.
7379  */
7380  appendPQExpBufferChar(tbloids, '{');
7381  for (int i = 0; i < numTables; i++)
7382  {
7383  TableInfo *tinfo = &tblinfo[i];
7384 
7385  /*
7386  * For partitioned tables, foreign keys have no triggers so they must
7387  * be included anyway in case some foreign keys are defined.
7388  */
7389  if ((!tinfo->hastriggers &&
7390  tinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7391  !(tinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
7392  continue;
7393 
7394  /* OK, we need info for this table */
7395  if (tbloids->len > 1) /* do we have more than the '{'? */
7396  appendPQExpBufferChar(tbloids, ',');
7397  appendPQExpBuffer(tbloids, "%u", tinfo->dobj.catId.oid);
7398  }
7399  appendPQExpBufferChar(tbloids, '}');
7400 
7401  appendPQExpBufferStr(query,
7402  "SELECT c.tableoid, c.oid, "
7403  "conrelid, conname, confrelid, ");
7404  if (fout->remoteVersion >= 110000)
7405  appendPQExpBufferStr(query, "conindid, ");
7406  else
7407  appendPQExpBufferStr(query, "0 AS conindid, ");
7408  appendPQExpBuffer(query,
7409  "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
7410  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7411  "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
7412  "WHERE contype = 'f' ",
7413  tbloids->data);
7414  if (fout->remoteVersion >= 110000)
7415  appendPQExpBufferStr(query,
7416  "AND conparentid = 0 ");
7417  appendPQExpBufferStr(query,
7418  "ORDER BY conrelid, conname");
7419 
7420  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7421 
7422  ntups = PQntuples(res);
7423 
7424  i_contableoid = PQfnumber(res, "tableoid");
7425  i_conoid = PQfnumber(res, "oid");
7426  i_conrelid = PQfnumber(res, "conrelid");
7427  i_conname = PQfnumber(res, "conname");
7428  i_confrelid = PQfnumber(res, "confrelid");
7429  i_conindid = PQfnumber(res, "conindid");
7430  i_condef = PQfnumber(res, "condef");
7431 
7432  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7433 
7434  curtblindx = -1;
7435  for (int j = 0; j < ntups; j++)
7436  {
7437  Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
7438  TableInfo *reftable;
7439 
7440  /*
7441  * Locate the associated TableInfo; we rely on tblinfo[] being in OID
7442  * order.
7443  */
7444  if (tbinfo == NULL || tbinfo->dobj.catId.oid != conrelid)
7445  {
7446  while (++curtblindx < numTables)
7447  {
7448  tbinfo = &tblinfo[curtblindx];
7449  if (tbinfo->dobj.catId.oid == conrelid)
7450  break;
7451  }
7452  if (curtblindx >= numTables)
7453  pg_fatal("unrecognized table OID %u", conrelid);
7454  }
7455 
7456  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
7457  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7458  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7459  AssignDumpId(&constrinfo[j].dobj);
7460  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7461  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7462  constrinfo[j].contable = tbinfo;
7463  constrinfo[j].condomain = NULL;
7464  constrinfo[j].contype = 'f';
7465  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7466  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
7467  constrinfo[j].conindex = 0;
7468  constrinfo[j].condeferrable = false;
7469  constrinfo[j].condeferred = false;
7470  constrinfo[j].conislocal = true;
7471  constrinfo[j].separate = true;
7472 
7473  /*
7474  * Restoring an FK that points to a partitioned table requires that
7475  * all partition indexes have been attached beforehand. Ensure that
7476  * happens by making the constraint depend on each index partition
7477  * attach object.
7478  */
7479  reftable = findTableByOid(constrinfo[j].confrelid);
7480  if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
7481  {
7482  Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
7483 
7484  if (indexOid != InvalidOid)
7485  {
7486  for (int k = 0; k < reftable->numIndexes; k++)
7487  {
7488  IndxInfo *refidx;
7489 
7490  /* not our index? */
7491  if (reftable->indexes[k].dobj.catId.oid != indexOid)
7492  continue;
7493 
7494  refidx = &reftable->indexes[k];
7495  addConstrChildIdxDeps(&constrinfo[j].dobj, refidx);
7496  break;
7497  }
7498  }
7499  }
7500  }
7501 
7502  PQclear(res);
7503 
7504  destroyPQExpBuffer(query);
7505  destroyPQExpBuffer(tbloids);
7506 }
TableInfo * findTableByOid(Oid oid)
Definition: common.c:824
static const gbtree_vinfo tinfo
Definition: btree_bit.c:109
int j
Definition: isn.c:74
#define pg_fatal(...)
static void addConstrChildIdxDeps(DumpableObject *dobj, const IndxInfo *refidx)
Definition: pg_dump.c:7520
TypeInfo * condomain
Definition: pg_dump.h:483
TableInfo * contable
Definition: pg_dump.h:482
bool condeferred
Definition: pg_dump.h:489
bool conislocal
Definition: pg_dump.h:490
DumpableObject dobj
Definition: pg_dump.h:481
DumpId conindex
Definition: pg_dump.h:487
bool condeferrable
Definition: pg_dump.h:488
char * condef
Definition: pg_dump.h:485
DumpableObject dobj
Definition: pg_dump.h:395
struct _indxInfo * indexes
Definition: pg_dump.h:364
DumpableObject dobj
Definition: pg_dump.h:284
char relkind
Definition: pg_dump.h:287
int numIndexes
Definition: pg_dump.h:363

References addConstrChildIdxDeps(), appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _constraintInfo::condef, _constraintInfo::condeferrable, _constraintInfo::condeferred, _constraintInfo::condomain, _constraintInfo::confrelid, _constraintInfo::conindex, _constraintInfo::conislocal, _constraintInfo::contable, _constraintInfo::contype, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FK_CONSTRAINT, _tableInfo::dobj, _indxInfo::dobj, _constraintInfo::dobj, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), findTableByOid(), i, _tableInfo::indexes, InvalidOid, j, PQExpBufferData::len, _dumpableObject::name, _tableInfo::numIndexes, _dumpableObject::objType, CatalogId::oid, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relkind, Archive::remoteVersion, res, _constraintInfo::separate, CatalogId::tableoid, and tinfo.

Referenced by getSchemaData().

◆ getConversions()

ConvInfo* getConversions ( Archive fout,
int *  numConversions 
)

Definition at line 5729 of file pg_dump.c.

5730 {
5731  PGresult *res;
5732  int ntups;
5733  int i;
5734  PQExpBuffer query;
5735  ConvInfo *convinfo;
5736  int i_tableoid;
5737  int i_oid;
5738  int i_conname;
5739  int i_connamespace;
5740  int i_conowner;
5741 
5742  query = createPQExpBuffer();
5743 
5744  /*
5745  * find all conversions, including builtin conversions; we filter out
5746  * system-defined conversions at dump-out time.
5747  */
5748 
5749  appendPQExpBufferStr(query, "SELECT tableoid, oid, conname, "
5750  "connamespace, "
5751  "conowner "
5752  "FROM pg_conversion");
5753 
5754  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5755 
5756  ntups = PQntuples(res);
5757  *numConversions = ntups;
5758 
5759  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
5760 
5761  i_tableoid = PQfnumber(res, "tableoid");
5762  i_oid = PQfnumber(res, "oid");
5763  i_conname = PQfnumber(res, "conname");
5764  i_connamespace = PQfnumber(res, "connamespace");
5765  i_conowner = PQfnumber(res, "conowner");
5766 
5767  for (i = 0; i < ntups; i++)
5768  {
5769  convinfo[i].dobj.objType = DO_CONVERSION;
5770  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5771  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5772  AssignDumpId(&convinfo[i].dobj);
5773  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
5774  convinfo[i].dobj.namespace =
5775  findNamespace(atooid(PQgetvalue(res, i, i_connamespace)));
5776  convinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_conowner));
5777 
5778  /* Decide whether we want to dump it */
5779  selectDumpableObject(&(convinfo[i].dobj), fout);
5780  }
5781 
5782  PQclear(res);
5783 
5784  destroyPQExpBuffer(query);
5785 
5786  return convinfo;
5787 }
DumpableObject dobj
Definition: pg_dump.h:275
const char * rolname
Definition: pg_dump.h:276

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_CONVERSION, _convInfo::dobj, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), res, _convInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getDefaultACLs()

DefaultACLInfo* getDefaultACLs ( Archive fout,
int *  numDefaultACLs 
)

Definition at line 9608 of file pg_dump.c.

9609 {
9610  DumpOptions *dopt = fout->dopt;
9611  DefaultACLInfo *daclinfo;
9612  PQExpBuffer query;
9613  PGresult *res;
9614  int i_oid;
9615  int i_tableoid;
9616  int i_defaclrole;
9617  int i_defaclnamespace;
9618  int i_defaclobjtype;
9619  int i_defaclacl;
9620  int i_acldefault;
9621  int i,
9622  ntups;
9623 
9624  query = createPQExpBuffer();
9625 
9626  /*
9627  * Global entries (with defaclnamespace=0) replace the hard-wired default
9628  * ACL for their object type. We should dump them as deltas from the
9629  * default ACL, since that will be used as a starting point for
9630  * interpreting the ALTER DEFAULT PRIVILEGES commands. On the other hand,
9631  * non-global entries can only add privileges not revoke them. We must
9632  * dump those as-is (i.e., as deltas from an empty ACL).
9633  *
9634  * We can use defaclobjtype as the object type for acldefault(), except
9635  * for the case of 'S' (DEFACLOBJ_SEQUENCE) which must be converted to
9636  * 's'.
9637  */
9638  appendPQExpBufferStr(query,
9639  "SELECT oid, tableoid, "
9640  "defaclrole, "
9641  "defaclnamespace, "
9642  "defaclobjtype, "
9643  "defaclacl, "
9644  "CASE WHEN defaclnamespace = 0 THEN "
9645  "acldefault(CASE WHEN defaclobjtype = 'S' "
9646  "THEN 's'::\"char\" ELSE defaclobjtype END, "
9647  "defaclrole) ELSE '{}' END AS acldefault "
9648  "FROM pg_default_acl");
9649 
9650  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9651 
9652  ntups = PQntuples(res);
9653  *numDefaultACLs = ntups;
9654 
9655  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9656 
9657  i_oid = PQfnumber(res, "oid");
9658  i_tableoid = PQfnumber(res, "tableoid");
9659  i_defaclrole = PQfnumber(res, "defaclrole");
9660  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9661  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9662  i_defaclacl = PQfnumber(res, "defaclacl");
9663  i_acldefault = PQfnumber(res, "acldefault");
9664 
9665  for (i = 0; i < ntups; i++)
9666  {
9667  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9668 
9669  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9670  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9671  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9672  AssignDumpId(&daclinfo[i].dobj);
9673  /* cheesy ... is it worth coming up with a better object name? */
9674  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9675 
9676  if (nspid != InvalidOid)
9677  daclinfo[i].dobj.namespace = findNamespace(nspid);
9678  else
9679  daclinfo[i].dobj.namespace = NULL;
9680 
9681  daclinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9682  daclinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9683  daclinfo[i].dacl.privtype = 0;
9684  daclinfo[i].dacl.initprivs = NULL;
9685  daclinfo[i].defaclrole = getRoleName(PQgetvalue(res, i, i_defaclrole));
9686  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9687 
9688  /* Default ACLs are ACLs, of course */
9689  daclinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9690 
9691  /* Decide whether we want to dump it */
9692  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9693  }
9694 
9695  PQclear(res);
9696 
9697  destroyPQExpBuffer(query);
9698 
9699  return daclinfo;
9700 }
int nspid
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition: pg_dump.c:1899
DumpableObject dobj
Definition: pg_dump.h:586
DumpableAcl dacl
Definition: pg_dump.h:587
const char * defaclrole
Definition: pg_dump.h:588
char defaclobjtype
Definition: pg_dump.h:589
char privtype
Definition: pg_dump.h:158
char * acldefault
Definition: pg_dump.h:156
char * acl
Definition: pg_dump.h:155
char * initprivs
Definition: pg_dump.h:159

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _defaultACLInfo::dacl, PQExpBufferData::data, _defaultACLInfo::defaclobjtype, _defaultACLInfo::defaclrole, destroyPQExpBuffer(), DO_DEFAULT_ACL, _defaultACLInfo::dobj, Archive::dopt, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableAcl::initprivs, InvalidOid, _dumpableObject::name, nspid, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, res, selectDumpableDefaultACL(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getDumpableObjects()

void getDumpableObjects ( DumpableObject ***  objs,
int *  numObjs 
)

Definition at line 758 of file common.c.

759 {
760  int i,
761  j;
762 
764  j = 0;
765  for (i = 1; i < allocedDumpIds; i++)
766  {
767  if (dumpIdMap[i])
768  (*objs)[j++] = dumpIdMap[i];
769  }
770  *numObjs = j;
771 }

References allocedDumpIds, dumpIdMap, i, j, and pg_malloc_array.

Referenced by getTableDataFKConstraints(), and main().

◆ getEventTriggers()

EventTriggerInfo* getEventTriggers ( Archive fout,
int *  numEventTriggers 
)

Definition at line 8006 of file pg_dump.c.

8007 {
8008  int i;
8009  PQExpBuffer query;
8010  PGresult *res;
8011  EventTriggerInfo *evtinfo;
8012  int i_tableoid,
8013  i_oid,
8014  i_evtname,
8015  i_evtevent,
8016  i_evtowner,
8017  i_evttags,
8018  i_evtfname,
8019  i_evtenabled;
8020  int ntups;
8021 
8022  /* Before 9.3, there are no event triggers */
8023  if (fout->remoteVersion < 90300)
8024  {
8025  *numEventTriggers = 0;
8026  return NULL;
8027  }
8028 
8029  query = createPQExpBuffer();
8030 
8031  appendPQExpBufferStr(query,
8032  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8033  "evtevent, evtowner, "
8034  "array_to_string(array("
8035  "select quote_literal(x) "
8036  " from unnest(evttags) as t(x)), ', ') as evttags, "
8037  "e.evtfoid::regproc as evtfname "
8038  "FROM pg_event_trigger e "
8039  "ORDER BY e.oid");
8040 
8041  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8042 
8043  ntups = PQntuples(res);
8044 
8045  *numEventTriggers = ntups;
8046 
8047  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
8048 
8049  i_tableoid = PQfnumber(res, "tableoid");
8050  i_oid = PQfnumber(res, "oid");
8051  i_evtname = PQfnumber(res, "evtname");
8052  i_evtevent = PQfnumber(res, "evtevent");
8053  i_evtowner = PQfnumber(res, "evtowner");
8054  i_evttags = PQfnumber(res, "evttags");
8055  i_evtfname = PQfnumber(res, "evtfname");
8056  i_evtenabled = PQfnumber(res, "evtenabled");
8057 
8058  for (i = 0; i < ntups; i++)
8059  {
8060  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
8061  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8062  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8063  AssignDumpId(&evtinfo[i].dobj);
8064  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
8065  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
8066  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
8067  evtinfo[i].evtowner = getRoleName(PQgetvalue(res, i, i_evtowner));
8068  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
8069  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
8070  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
8071 
8072  /* Decide whether we want to dump it */
8073  selectDumpableObject(&(evtinfo[i].dobj), fout);
8074  }
8075 
8076  PQclear(res);
8077 
8078  destroyPQExpBuffer(query);
8079 
8080  return evtinfo;
8081 }
char * evtevent
Definition: pg_dump.h:464
char * evtfname
Definition: pg_dump.h:467
char evtenabled
Definition: pg_dump.h:468
char * evtname
Definition: pg_dump.h:463
const char * evtowner
Definition: pg_dump.h:465
char * evttags
Definition: pg_dump.h:466
DumpableObject dobj
Definition: pg_dump.h:462

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_EVENT_TRIGGER, _evttriggerInfo::dobj, _evttriggerInfo::evtenabled, _evttriggerInfo::evtevent, _evttriggerInfo::evtfname, _evttriggerInfo::evtname, _evttriggerInfo::evtowner, _evttriggerInfo::evttags, ExecuteSqlQuery(), getRoleName(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getExtendedStatistics()

void getExtendedStatistics ( Archive fout)

Definition at line 7283 of file pg_dump.c.

7284 {
7285  PQExpBuffer query;
7286  PGresult *res;
7287  StatsExtInfo *statsextinfo;
7288  int ntups;
7289  int i_tableoid;
7290  int i_oid;
7291  int i_stxname;
7292  int i_stxnamespace;
7293  int i_stxowner;
7294  int i_stattarget;
7295  int i;
7296 
7297  /* Extended statistics were new in v10 */
7298  if (fout->remoteVersion < 100000)
7299  return;
7300 
7301  query = createPQExpBuffer();
7302 
7303  if (fout->remoteVersion < 130000)
7304  appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
7305  "stxnamespace, stxowner, (-1) AS stxstattarget "
7306  "FROM pg_catalog.pg_statistic_ext");
7307  else
7308  appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
7309  "stxnamespace, stxowner, stxstattarget "
7310  "FROM pg_catalog.pg_statistic_ext");
7311 
7312  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7313 
7314  ntups = PQntuples(res);
7315 
7316  i_tableoid = PQfnumber(res, "tableoid");
7317  i_oid = PQfnumber(res, "oid");
7318  i_stxname = PQfnumber(res, "stxname");
7319  i_stxnamespace = PQfnumber(res, "stxnamespace");
7320  i_stxowner = PQfnumber(res, "stxowner");
7321  i_stattarget = PQfnumber(res, "stxstattarget");
7322 
7323  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
7324 
7325  for (i = 0; i < ntups; i++)
7326  {
7327  statsextinfo[i].dobj.objType = DO_STATSEXT;
7328  statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7329  statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7330  AssignDumpId(&statsextinfo[i].dobj);
7331  statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
7332  statsextinfo[i].dobj.namespace =
7333  findNamespace(atooid(PQgetvalue(res, i, i_stxnamespace)));
7334  statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
7335  statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
7336 
7337  /* Decide whether we want to dump it */
7338  selectDumpableObject(&(statsextinfo[i].dobj), fout);
7339  }
7340 
7341  PQclear(res);
7342  destroyPQExpBuffer(query);
7343 }
int stattarget
Definition: pg_dump.h:427
const char * rolname
Definition: pg_dump.h:426
DumpableObject dobj
Definition: pg_dump.h:425

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_STATSEXT, _statsExtInfo::dobj, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, _statsExtInfo::rolname, selectDumpableObject(), _statsExtInfo::stattarget, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getExtensionMembership()

void getExtensionMembership ( Archive fout,
ExtensionInfo  extinfo[],
int  numExtensions 
)

Definition at line 18015 of file pg_dump.c.

18017 {
18018  PQExpBuffer query;
18019  PGresult *res;
18020  int ntups,
18021  i;
18022  int i_classid,
18023  i_objid,
18024  i_refobjid;
18025  ExtensionInfo *ext;
18026 
18027  /* Nothing to do if no extensions */
18028  if (numExtensions == 0)
18029  return;
18030 
18031  query = createPQExpBuffer();
18032 
18033  /* refclassid constraint is redundant but may speed the search */
18034  appendPQExpBufferStr(query, "SELECT "
18035  "classid, objid, refobjid "
18036  "FROM pg_depend "
18037  "WHERE refclassid = 'pg_extension'::regclass "
18038  "AND deptype = 'e' "
18039  "ORDER BY 3");
18040 
18041  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
18042 
18043  ntups = PQntuples(res);
18044 
18045  i_classid = PQfnumber(res, "classid");
18046  i_objid = PQfnumber(res, "objid");
18047  i_refobjid = PQfnumber(res, "refobjid");
18048 
18049  /*
18050  * Since we ordered the SELECT by referenced ID, we can expect that
18051  * multiple entries for the same extension will appear together; this
18052  * saves on searches.
18053  */
18054  ext = NULL;
18055 
18056  for (i = 0; i < ntups; i++)
18057  {
18058  CatalogId objId;
18059  Oid extId;
18060 
18061  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
18062  objId.oid = atooid(PQgetvalue(res, i, i_objid));
18063  extId = atooid(PQgetvalue(res, i, i_refobjid));
18064 
18065  if (ext == NULL ||
18066  ext->dobj.catId.oid != extId)
18067  ext = findExtensionByOid(extId);
18068 
18069  if (ext == NULL)
18070  {
18071  /* shouldn't happen */
18072  pg_log_warning("could not find referenced extension %u", extId);
18073  continue;
18074  }
18075 
18076  recordExtensionMembership(objId, ext);
18077  }
18078 
18079  PQclear(res);
18080 
18081  destroyPQExpBuffer(query);
18082 }
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition: common.c:988
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:951
#define pg_log_warning(...)
Definition: pgfnames.c:24
DumpableObject dobj
Definition: pg_dump.h:180

References appendPQExpBufferStr(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _extensionInfo::dobj, ExecuteSqlQuery(), findExtensionByOid(), i, CatalogId::oid, pg_log_warning, PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), recordExtensionMembership(), res, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getExtensions()

ExtensionInfo* getExtensions ( Archive fout,
int *  numExtensions 
)

Definition at line 5342 of file pg_dump.c.

5343 {
5344  DumpOptions *dopt = fout->dopt;
5345  PGresult *res;
5346  int ntups;
5347  int i;
5348  PQExpBuffer query;
5349  ExtensionInfo *extinfo;
5350  int i_tableoid;
5351  int i_oid;
5352  int i_extname;
5353  int i_nspname;
5354  int i_extrelocatable;
5355  int i_extversion;
5356  int i_extconfig;
5357  int i_extcondition;
5358 
5359  query = createPQExpBuffer();
5360 
5361  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
5362  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
5363  "FROM pg_extension x "
5364  "JOIN pg_namespace n ON n.oid = x.extnamespace");
5365 
5366  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5367 
5368  ntups = PQntuples(res);
5369 
5370  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
5371 
5372  i_tableoid = PQfnumber(res, "tableoid");
5373  i_oid = PQfnumber(res, "oid");
5374  i_extname = PQfnumber(res, "extname");
5375  i_nspname = PQfnumber(res, "nspname");
5376  i_extrelocatable = PQfnumber(res, "extrelocatable");
5377  i_extversion = PQfnumber(res, "extversion");
5378  i_extconfig = PQfnumber(res, "extconfig");
5379  i_extcondition = PQfnumber(res, "extcondition");
5380 
5381  for (i = 0; i < ntups; i++)
5382  {
5383  extinfo[i].dobj.objType = DO_EXTENSION;
5384  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5385  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5386  AssignDumpId(&extinfo[i].dobj);
5387  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
5388  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
5389  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
5390  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
5391  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
5392  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
5393 
5394  /* Decide whether we want to dump it */
5395  selectDumpableExtension(&(extinfo[i]), dopt);
5396  }
5397 
5398  PQclear(res);
5399  destroyPQExpBuffer(query);
5400 
5401  *numExtensions = ntups;
5402 
5403  return extinfo;
5404 }
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:2007
bool relocatable
Definition: pg_dump.h:181
char * extversion
Definition: pg_dump.h:183
char * extcondition
Definition: pg_dump.h:185
char * extconfig
Definition: pg_dump.h:184

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_EXTENSION, _extensionInfo::dobj, Archive::dopt, ExecuteSqlQuery(), _extensionInfo::extcondition, _extensionInfo::extconfig, _extensionInfo::extversion, i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _extensionInfo::relocatable, res, selectDumpableExtension(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getForeignDataWrappers()

FdwInfo* getForeignDataWrappers ( Archive fout,
int *  numForeignDataWrappers 
)

Definition at line 9424 of file pg_dump.c.

9425 {
9426  PGresult *res;
9427  int ntups;
9428  int i;
9429  PQExpBuffer query;
9430  FdwInfo *fdwinfo;
9431  int i_tableoid;
9432  int i_oid;
9433  int i_fdwname;
9434  int i_fdwowner;
9435  int i_fdwhandler;
9436  int i_fdwvalidator;
9437  int i_fdwacl;
9438  int i_acldefault;
9439  int i_fdwoptions;
9440 
9441  query = createPQExpBuffer();
9442 
9443  appendPQExpBufferStr(query, "SELECT tableoid, oid, fdwname, "
9444  "fdwowner, "
9445  "fdwhandler::pg_catalog.regproc, "
9446  "fdwvalidator::pg_catalog.regproc, "
9447  "fdwacl, "
9448  "acldefault('F', fdwowner) AS acldefault, "
9449  "array_to_string(ARRAY("
9450  "SELECT quote_ident(option_name) || ' ' || "
9451  "quote_literal(option_value) "
9452  "FROM pg_options_to_table(fdwoptions) "
9453  "ORDER BY option_name"
9454  "), E',\n ') AS fdwoptions "
9455  "FROM pg_foreign_data_wrapper");
9456 
9457  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9458 
9459  ntups = PQntuples(res);
9460  *numForeignDataWrappers = ntups;
9461 
9462  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
9463 
9464  i_tableoid = PQfnumber(res, "tableoid");
9465  i_oid = PQfnumber(res, "oid");
9466  i_fdwname = PQfnumber(res, "fdwname");
9467  i_fdwowner = PQfnumber(res, "fdwowner");
9468  i_fdwhandler = PQfnumber(res, "fdwhandler");
9469  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
9470  i_fdwacl = PQfnumber(res, "fdwacl");
9471  i_acldefault = PQfnumber(res, "acldefault");
9472  i_fdwoptions = PQfnumber(res, "fdwoptions");
9473 
9474  for (i = 0; i < ntups; i++)
9475  {
9476  fdwinfo[i].dobj.objType = DO_FDW;
9477  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9478  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9479  AssignDumpId(&fdwinfo[i].dobj);
9480  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
9481  fdwinfo[i].dobj.namespace = NULL;
9482  fdwinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
9483  fdwinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9484  fdwinfo[i].dacl.privtype = 0;
9485  fdwinfo[i].dacl.initprivs = NULL;
9486  fdwinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_fdwowner));
9487  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
9488  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
9489  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
9490 
9491  /* Decide whether we want to dump it */
9492  selectDumpableObject(&(fdwinfo[i].dobj), fout);
9493 
9494  /* Mark whether FDW has an ACL */
9495  if (!PQgetisnull(res, i, i_fdwacl))
9496  fdwinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9497  }
9498 
9499  PQclear(res);
9500 
9501  destroyPQExpBuffer(query);
9502 
9503  return fdwinfo;
9504 }
char * fdwhandler
Definition: pg_dump.h:568
const char * rolname
Definition: pg_dump.h:567
char * fdwvalidator
Definition: pg_dump.h:569
char * fdwoptions
Definition: pg_dump.h:570
DumpableAcl dacl
Definition: pg_dump.h:566
DumpableObject dobj
Definition: pg_dump.h:565

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _fdwInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_FDW, _fdwInfo::dobj, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), _fdwInfo::fdwhandler, _fdwInfo::fdwoptions, _fdwInfo::fdwvalidator, getRoleName(), i, _dumpableAcl::initprivs, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, res, _fdwInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getForeignServers()

ForeignServerInfo* getForeignServers ( Archive fout,
int *  numForeignServers 
)

Definition at line 9514 of file pg_dump.c.

9515 {
9516  PGresult *res;
9517  int ntups;
9518  int i;
9519  PQExpBuffer query;
9520  ForeignServerInfo *srvinfo;
9521  int i_tableoid;
9522  int i_oid;
9523  int i_srvname;
9524  int i_srvowner;
9525  int i_srvfdw;
9526  int i_srvtype;
9527  int i_srvversion;
9528  int i_srvacl;
9529  int i_acldefault;
9530  int i_srvoptions;
9531 
9532  query = createPQExpBuffer();
9533 
9534  appendPQExpBufferStr(query, "SELECT tableoid, oid, srvname, "
9535  "srvowner, "
9536  "srvfdw, srvtype, srvversion, srvacl, "
9537  "acldefault('S', srvowner) AS acldefault, "
9538  "array_to_string(ARRAY("
9539  "SELECT quote_ident(option_name) || ' ' || "
9540  "quote_literal(option_value) "
9541  "FROM pg_options_to_table(srvoptions) "
9542  "ORDER BY option_name"
9543  "), E',\n ') AS srvoptions "
9544  "FROM pg_foreign_server");
9545 
9546  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9547 
9548  ntups = PQntuples(res);
9549  *numForeignServers = ntups;
9550 
9551  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
9552 
9553  i_tableoid = PQfnumber(res, "tableoid");
9554  i_oid = PQfnumber(res, "oid");
9555  i_srvname = PQfnumber(res, "srvname");
9556  i_srvowner = PQfnumber(res, "srvowner");
9557  i_srvfdw = PQfnumber(res, "srvfdw");
9558  i_srvtype = PQfnumber(res, "srvtype");
9559  i_srvversion = PQfnumber(res, "srvversion");
9560  i_srvacl = PQfnumber(res, "srvacl");
9561  i_acldefault = PQfnumber(res, "acldefault");
9562  i_srvoptions = PQfnumber(res, "srvoptions");
9563 
9564  for (i = 0; i < ntups; i++)
9565  {
9566  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
9567  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9568  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9569  AssignDumpId(&srvinfo[i].dobj);
9570  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
9571  srvinfo[i].dobj.namespace = NULL;
9572  srvinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_srvacl));
9573  srvinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9574  srvinfo[i].dacl.privtype = 0;
9575  srvinfo[i].dacl.initprivs = NULL;
9576  srvinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_srvowner));
9577  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
9578  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
9579  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
9580  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
9581 
9582  /* Decide whether we want to dump it */
9583  selectDumpableObject(&(srvinfo[i].dobj), fout);
9584 
9585  /* Servers have user mappings */
9587 
9588  /* Mark whether server has an ACL */
9589  if (!PQgetisnull(res, i, i_srvacl))
9590  srvinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9591  }
9592 
9593  PQclear(res);
9594 
9595  destroyPQExpBuffer(query);
9596 
9597  return srvinfo;
9598 }
#define DUMP_COMPONENT_USERMAP
Definition: pg_dump.h:102
DumpableAcl dacl
Definition: pg_dump.h:576
char * srvoptions
Definition: pg_dump.h:581
DumpableObject dobj
Definition: pg_dump.h:575
const char * rolname
Definition: pg_dump.h:577
char * srvversion
Definition: pg_dump.h:580

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _foreignServerInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_FOREIGN_SERVER, _foreignServerInfo::dobj, DUMP_COMPONENT_ACL, DUMP_COMPONENT_USERMAP, ExecuteSqlQuery(), getRoleName(), i, _dumpableAcl::initprivs, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, res, _foreignServerInfo::rolname, selectDumpableObject(), _foreignServerInfo::srvfdw, _foreignServerInfo::srvoptions, _foreignServerInfo::srvtype, _foreignServerInfo::srvversion, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getFuncs()

FuncInfo* getFuncs ( Archive fout,
int *  numFuncs 
)

Definition at line 6149 of file pg_dump.c.

6150 {
6151  DumpOptions *dopt = fout->dopt;
6152  PGresult *res;
6153  int ntups;
6154  int i;
6155  PQExpBuffer query = createPQExpBuffer();
6156  FuncInfo *finfo;
6157  int i_tableoid;
6158  int i_oid;
6159  int i_proname;
6160  int i_pronamespace;
6161  int i_proowner;
6162  int i_prolang;
6163  int i_pronargs;
6164  int i_proargtypes;
6165  int i_prorettype;
6166  int i_proacl;
6167  int i_acldefault;
6168 
6169  /*
6170  * Find all interesting functions. This is a bit complicated:
6171  *
6172  * 1. Always exclude aggregates; those are handled elsewhere.
6173  *
6174  * 2. Always exclude functions that are internally dependent on something
6175  * else, since presumably those will be created as a result of creating
6176  * the something else. This currently acts only to suppress constructor
6177  * functions for range types. Note this is OK only because the
6178  * constructors don't have any dependencies the range type doesn't have;
6179  * otherwise we might not get creation ordering correct.
6180  *
6181  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
6182  * they're members of extensions and we are in binary-upgrade mode then
6183  * include them, since we want to dump extension members individually in
6184  * that mode. Also, if they are used by casts or transforms then we need
6185  * to gather the information about them, though they won't be dumped if
6186  * they are built-in. Also, in 9.6 and up, include functions in
6187  * pg_catalog if they have an ACL different from what's shown in
6188  * pg_init_privs (so we have to join to pg_init_privs; annoying).
6189  */
6190  if (fout->remoteVersion >= 90600)
6191  {
6192  const char *not_agg_check;
6193 
6194  not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
6195  : "NOT p.proisagg");
6196 
6197  appendPQExpBuffer(query,
6198  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6199  "p.pronargs, p.proargtypes, p.prorettype, "
6200  "p.proacl, "
6201  "acldefault('f', p.proowner) AS acldefault, "
6202  "p.pronamespace, "
6203  "p.proowner "
6204  "FROM pg_proc p "
6205  "LEFT JOIN pg_init_privs pip ON "
6206  "(p.oid = pip.objoid "
6207  "AND pip.classoid = 'pg_proc'::regclass "
6208  "AND pip.objsubid = 0) "
6209  "WHERE %s"
6210  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6211  "WHERE classid = 'pg_proc'::regclass AND "
6212  "objid = p.oid AND deptype = 'i')"
6213  "\n AND ("
6214  "\n pronamespace != "
6215  "(SELECT oid FROM pg_namespace "
6216  "WHERE nspname = 'pg_catalog')"
6217  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6218  "\n WHERE pg_cast.oid > %u "
6219  "\n AND p.oid = pg_cast.castfunc)"
6220  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6221  "\n WHERE pg_transform.oid > %u AND "
6222  "\n (p.oid = pg_transform.trffromsql"
6223  "\n OR p.oid = pg_transform.trftosql))",
6224  not_agg_check,
6227  if (dopt->binary_upgrade)
6228  appendPQExpBufferStr(query,
6229  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6230  "classid = 'pg_proc'::regclass AND "
6231  "objid = p.oid AND "
6232  "refclassid = 'pg_extension'::regclass AND "
6233  "deptype = 'e')");
6234  appendPQExpBufferStr(query,
6235  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
6236  appendPQExpBufferChar(query, ')');
6237  }
6238  else
6239  {
6240  appendPQExpBuffer(query,
6241  "SELECT tableoid, oid, proname, prolang, "
6242  "pronargs, proargtypes, prorettype, proacl, "
6243  "acldefault('f', proowner) AS acldefault, "
6244  "pronamespace, "
6245  "proowner "
6246  "FROM pg_proc p "
6247  "WHERE NOT proisagg"
6248  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6249  "WHERE classid = 'pg_proc'::regclass AND "
6250  "objid = p.oid AND deptype = 'i')"
6251  "\n AND ("
6252  "\n pronamespace != "
6253  "(SELECT oid FROM pg_namespace "
6254  "WHERE nspname = 'pg_catalog')"
6255  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6256  "\n WHERE pg_cast.oid > '%u'::oid"
6257  "\n AND p.oid = pg_cast.castfunc)",
6259 
6260  if (fout->remoteVersion >= 90500)
6261  appendPQExpBuffer(query,
6262  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6263  "\n WHERE pg_transform.oid > '%u'::oid"
6264  "\n AND (p.oid = pg_transform.trffromsql"
6265  "\n OR p.oid = pg_transform.trftosql))",
6267 
6268  if (dopt->binary_upgrade)
6269  appendPQExpBufferStr(query,
6270  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6271  "classid = 'pg_proc'::regclass AND "
6272  "objid = p.oid AND "
6273  "refclassid = 'pg_extension'::regclass AND "
6274  "deptype = 'e')");
6275  appendPQExpBufferChar(query, ')');
6276  }
6277 
6278  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6279 
6280  ntups = PQntuples(res);
6281 
6282  *numFuncs = ntups;
6283 
6284  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
6285 
6286  i_tableoid = PQfnumber(res, "tableoid");
6287  i_oid = PQfnumber(res, "oid");
6288  i_proname = PQfnumber(res, "proname");
6289  i_pronamespace = PQfnumber(res, "pronamespace");
6290  i_proowner = PQfnumber(res, "proowner");
6291  i_prolang = PQfnumber(res, "prolang");
6292  i_pronargs = PQfnumber(res, "pronargs");
6293  i_proargtypes = PQfnumber(res, "proargtypes");
6294  i_prorettype = PQfnumber(res, "prorettype");
6295  i_proacl = PQfnumber(res, "proacl");
6296  i_acldefault = PQfnumber(res, "acldefault");
6297 
6298  for (i = 0; i < ntups; i++)
6299  {
6300  finfo[i].dobj.objType = DO_FUNC;
6301  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6302  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6303  AssignDumpId(&finfo[i].dobj);
6304  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
6305  finfo[i].dobj.namespace =
6306  findNamespace(atooid(PQgetvalue(res, i, i_pronamespace)));
6307  finfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_proacl));
6308  finfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6309  finfo[i].dacl.privtype = 0;
6310  finfo[i].dacl.initprivs = NULL;
6311  finfo[i].rolname = getRoleName(PQgetvalue(res, i, i_proowner));
6312  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
6313  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
6314  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
6315  if (finfo[i].nargs == 0)
6316  finfo[i].argtypes = NULL;
6317  else
6318  {
6319  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
6320  parseOidArray(PQgetvalue(res, i, i_proargtypes),
6321  finfo[i].argtypes, finfo[i].nargs);
6322  }
6323  finfo[i].postponed_def = false; /* might get set during sort */
6324 
6325  /* Decide whether we want to dump it */
6326  selectDumpableObject(&(finfo[i].dobj), fout);
6327 
6328  /* Mark whether function has an ACL */
6329  if (!PQgetisnull(res, i, i_proacl))
6330  finfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6331  }
6332 
6333  PQclear(res);
6334 
6335  destroyPQExpBuffer(query);
6336 
6337  return finfo;
6338 }
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
static Oid g_last_builtin_oid
Definition: pg_dump.c:105
bool postponed_def
Definition: pg_dump.h:230
Oid lang
Definition: pg_dump.h:226
const char * rolname
Definition: pg_dump.h:225
Oid * argtypes
Definition: pg_dump.h:228
Oid prorettype
Definition: pg_dump.h:229
DumpableObject dobj
Definition: pg_dump.h:223
int nargs
Definition: pg_dump.h:227
DumpableAcl dacl
Definition: pg_dump.h:224

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), _funcInfo::argtypes, AssignDumpId(), atooid, _dumpOptions::binary_upgrade, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _funcInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_FUNC, _funcInfo::dobj, Archive::dopt, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), g_last_builtin_oid, getRoleName(), i, _dumpableAcl::initprivs, _funcInfo::lang, _dumpableObject::name, _funcInfo::nargs, _dumpableObject::objType, CatalogId::oid, parseOidArray(), pg_malloc(), pg_malloc0(), pg_strdup(), PGRES_TUPLES_OK, _funcInfo::postponed_def, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, _funcInfo::prorettype, Archive::remoteVersion, res, _funcInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getIndexes()

void getIndexes ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 6973 of file pg_dump.c.

6974 {
6975  PQExpBuffer query = createPQExpBuffer();
6976  PQExpBuffer tbloids = createPQExpBuffer();
6977  PGresult *res;
6978  int ntups;
6979  int curtblindx;
6980  IndxInfo *indxinfo;
6981  int i_tableoid,
6982  i_oid,
6983  i_indrelid,
6984  i_indexname,
6985  i_parentidx,
6986  i_indexdef,
6987  i_indnkeyatts,
6988  i_indnatts,
6989  i_indkey,
6990  i_indisclustered,
6991  i_indisreplident,
6992  i_indnullsnotdistinct,
6993  i_contype,
6994  i_conname,
6995  i_condeferrable,
6996  i_condeferred,
6997  i_contableoid,
6998  i_conoid,
6999  i_condef,
7000  i_tablespace,
7001  i_indreloptions,
7002  i_indstatcols,
7003  i_indstatvals;
7004 
7005  /*
7006  * We want to perform just one query against pg_index. However, we
7007  * mustn't try to select every row of the catalog and then sort it out on
7008  * the client side, because some of the server-side functions we need
7009  * would be unsafe to apply to tables we don't have lock on. Hence, we
7010  * build an array of the OIDs of tables we care about (and now have lock
7011  * on!), and use a WHERE clause to constrain which rows are selected.
7012  */
7013  appendPQExpBufferChar(tbloids, '{');
7014  for (int i = 0; i < numTables; i++)
7015  {
7016  TableInfo *tbinfo = &tblinfo[i];
7017 
7018  if (!tbinfo->hasindex)
7019  continue;
7020 
7021  /*
7022  * We can ignore indexes of uninteresting tables.
7023  */
7024  if (!tbinfo->interesting)
7025  continue;
7026 
7027  /* OK, we need info for this table */
7028  if (tbloids->len > 1) /* do we have more than the '{'? */
7029  appendPQExpBufferChar(tbloids, ',');
7030  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
7031  }
7032  appendPQExpBufferChar(tbloids, '}');
7033 
7034  appendPQExpBufferStr(query,
7035  "SELECT t.tableoid, t.oid, i.indrelid, "
7036  "t.relname AS indexname, "
7037  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7038  "i.indkey, i.indisclustered, "
7039  "c.contype, c.conname, "
7040  "c.condeferrable, c.condeferred, "
7041  "c.tableoid AS contableoid, "
7042  "c.oid AS conoid, "
7043  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7044  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7045  "t.reloptions AS indreloptions, ");
7046 
7047 
7048  if (fout->remoteVersion >= 90400)
7049  appendPQExpBufferStr(query,
7050  "i.indisreplident, ");
7051  else
7052  appendPQExpBufferStr(query,
7053  "false AS indisreplident, ");
7054 
7055  if (fout->remoteVersion >= 110000)
7056  appendPQExpBufferStr(query,
7057  "inh.inhparent AS parentidx, "
7058  "i.indnkeyatts AS indnkeyatts, "
7059  "i.indnatts AS indnatts, "
7060  "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
7061  " FROM pg_catalog.pg_attribute "
7062  " WHERE attrelid = i.indexrelid AND "
7063  " attstattarget >= 0) AS indstatcols, "
7064  "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
7065  " FROM pg_catalog.pg_attribute "
7066  " WHERE attrelid = i.indexrelid AND "
7067  " attstattarget >= 0) AS indstatvals, ");
7068  else
7069  appendPQExpBufferStr(query,
7070  "0 AS parentidx, "
7071  "i.indnatts AS indnkeyatts, "
7072  "i.indnatts AS indnatts, "
7073  "'' AS indstatcols, "
7074  "'' AS indstatvals, ");
7075 
7076  if (fout->remoteVersion >= 150000)
7077  appendPQExpBufferStr(query,
7078  "i.indnullsnotdistinct ");
7079  else
7080  appendPQExpBufferStr(query,
7081  "false AS indnullsnotdistinct ");
7082 
7083  /*
7084  * The point of the messy-looking outer join is to find a constraint that
7085  * is related by an internal dependency link to the index. If we find one,
7086  * create a CONSTRAINT entry linked to the INDEX entry. We assume an
7087  * index won't have more than one internal dependency.
7088  *
7089  * Note: the check on conrelid is redundant, but useful because that
7090  * column is indexed while conindid is not.
7091  */
7092  if (fout->remoteVersion >= 110000)
7093  {
7094  appendPQExpBuffer(query,
7095  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7096  "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7097  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7098  "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
7099  "LEFT JOIN pg_catalog.pg_constraint c "
7100  "ON (i.indrelid = c.conrelid AND "
7101  "i.indexrelid = c.conindid AND "
7102  "c.contype IN ('p','u','x')) "
7103  "LEFT JOIN pg_catalog.pg_inherits inh "
7104  "ON (inh.inhrelid = indexrelid) "
7105  "WHERE (i.indisvalid OR t2.relkind = 'p') "
7106  "AND i.indisready "
7107  "ORDER BY i.indrelid, indexname",
7108  tbloids->data);
7109  }
7110  else
7111  {
7112  /*
7113  * the test on indisready is necessary in 9.2, and harmless in
7114  * earlier/later versions
7115  */
7116  appendPQExpBuffer(query,
7117  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7118  "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7119  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7120  "LEFT JOIN pg_catalog.pg_constraint c "
7121  "ON (i.indrelid = c.conrelid AND "
7122  "i.indexrelid = c.conindid AND "
7123  "c.contype IN ('p','u','x')) "
7124  "WHERE i.indisvalid AND i.indisready "
7125  "ORDER BY i.indrelid, indexname",
7126  tbloids->data);
7127  }
7128 
7129  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7130 
7131  ntups = PQntuples(res);
7132 
7133  i_tableoid = PQfnumber(res, "tableoid");
7134  i_oid = PQfnumber(res, "oid");
7135  i_indrelid = PQfnumber(res, "indrelid");
7136  i_indexname = PQfnumber(res, "indexname");
7137  i_parentidx = PQfnumber(res, "parentidx");
7138  i_indexdef = PQfnumber(res, "indexdef");
7139  i_indnkeyatts = PQfnumber(res, "indnkeyatts");
7140  i_indnatts = PQfnumber(res, "indnatts");
7141  i_indkey = PQfnumber(res, "indkey");
7142  i_indisclustered = PQfnumber(res, "indisclustered");
7143  i_indisreplident = PQfnumber(res, "indisreplident");
7144  i_indnullsnotdistinct = PQfnumber(res, "indnullsnotdistinct");
7145  i_contype = PQfnumber(res, "contype");
7146  i_conname = PQfnumber(res, "conname");
7147  i_condeferrable = PQfnumber(res, "condeferrable");
7148  i_condeferred = PQfnumber(res, "condeferred");
7149  i_contableoid = PQfnumber(res, "contableoid");
7150  i_conoid = PQfnumber(res, "conoid");
7151  i_condef = PQfnumber(res, "condef");
7152  i_tablespace = PQfnumber(res, "tablespace");
7153  i_indreloptions = PQfnumber(res, "indreloptions");
7154  i_indstatcols = PQfnumber(res, "indstatcols");
7155  i_indstatvals = PQfnumber(res, "indstatvals");
7156 
7157  indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
7158 
7159  /*
7160  * Outer loop iterates once per table, not once per row. Incrementing of
7161  * j is handled by the inner loop.
7162  */
7163  curtblindx = -1;
7164  for (int j = 0; j < ntups;)
7165  {
7166  Oid indrelid = atooid(PQgetvalue(res, j, i_indrelid));
7167  TableInfo *tbinfo = NULL;
7168  int numinds;
7169 
7170  /* Count rows for this table */
7171  for (numinds = 1; numinds < ntups - j; numinds++)
7172  if (atooid(PQgetvalue(res, j + numinds, i_indrelid)) != indrelid)
7173  break;
7174 
7175  /*
7176  * Locate the associated TableInfo; we rely on tblinfo[] being in OID
7177  * order.
7178  */
7179  while (++curtblindx < numTables)
7180  {
7181  tbinfo = &tblinfo[curtblindx];
7182  if (tbinfo->dobj.catId.oid == indrelid)
7183  break;
7184  }
7185  if (curtblindx >= numTables)
7186  pg_fatal("unrecognized table OID %u", indrelid);
7187  /* cross-check that we only got requested tables */
7188  if (!tbinfo->hasindex ||
7189  !tbinfo->interesting)
7190  pg_fatal("unexpected index data for table \"%s\"",
7191  tbinfo->dobj.name);
7192 
7193  /* Save data for this table */
7194  tbinfo->indexes = indxinfo + j;
7195  tbinfo->numIndexes = numinds;
7196 
7197  for (int c = 0; c < numinds; c++, j++)
7198  {
7199  char contype;
7200 
7201  indxinfo[j].dobj.objType = DO_INDEX;
7202  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
7203  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
7204  AssignDumpId(&indxinfo[j].dobj);
7205  indxinfo[j].dobj.dump = tbinfo->dobj.dump;
7206  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
7207  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7208  indxinfo[j].indextable = tbinfo;
7209  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
7210  indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
7211  indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
7212  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
7213  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
7214  indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
7215  indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
7216  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
7217  parseOidArray(PQgetvalue(res, j, i_indkey),
7218  indxinfo[j].indkeys, indxinfo[j].indnattrs);
7219  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
7220  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
7221  indxinfo[j].indnullsnotdistinct = (PQgetvalue(res, j, i_indnullsnotdistinct)[0] == 't');
7222  indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
7223  indxinfo[j].partattaches = (SimplePtrList)
7224  {
7225  NULL, NULL
7226  };
7227  contype = *(PQgetvalue(res, j, i_contype));
7228 
7229  if (contype == 'p' || contype == 'u' || contype == 'x')
7230  {
7231  /*
7232  * If we found a constraint matching the index, create an
7233  * entry for it.
7234  */
7235  ConstraintInfo *constrinfo;
7236 
7237  constrinfo = (ConstraintInfo *) pg_malloc(sizeof(ConstraintInfo));
7238  constrinfo->dobj.objType = DO_CONSTRAINT;
7239  constrinfo->dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7240  constrinfo->dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7241  AssignDumpId(&constrinfo->dobj);
7242  constrinfo->dobj.dump = tbinfo->dobj.dump;
7243  constrinfo->dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7244  constrinfo->dobj.namespace = tbinfo->dobj.namespace;
7245  constrinfo->contable = tbinfo;
7246  constrinfo->condomain = NULL;
7247  constrinfo->contype = contype;
7248  if (contype == 'x')
7249  constrinfo->condef = pg_strdup(PQgetvalue(res, j, i_condef));
7250  else
7251  constrinfo->condef = NULL;
7252  constrinfo->confrelid = InvalidOid;
7253  constrinfo->conindex = indxinfo[j].dobj.dumpId;
7254  constrinfo->condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
7255  constrinfo->condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
7256  constrinfo->conislocal = true;
7257  constrinfo->separate = true;
7258 
7259  indxinfo[j].indexconstraint = constrinfo->dobj.dumpId;
7260  }
7261  else
7262  {
7263  /* Plain secondary index */
7264  indxinfo[j].indexconstraint = 0;
7265  }
7266  }
7267  }
7268 
7269  PQclear(res);
7270 
7271  destroyPQExpBuffer(query);
7272  destroyPQExpBuffer(tbloids);
7273 }
char * c
struct SimplePtrList SimplePtrList
bool indisreplident
Definition: pg_dump.h:407
int indnkeyattrs
Definition: pg_dump.h:402
char * indstatvals
Definition: pg_dump.h:401
char * indstatcols
Definition: pg_dump.h:400
int indnattrs
Definition: pg_dump.h:403
TableInfo * indextable
Definition: pg_dump.h:396
Oid parentidx
Definition: pg_dump.h:409
Oid * indkeys
Definition: pg_dump.h:404
char * indreloptions
Definition: pg_dump.h:399
DumpId indexconstraint
Definition: pg_dump.h:413
bool indisclustered
Definition: pg_dump.h:406
SimplePtrList partattaches
Definition: pg_dump.h:410
char * tablespace
Definition: pg_dump.h:398
bool indnullsnotdistinct
Definition: pg_dump.h:408
char * indexdef
Definition: pg_dump.h:397
bool interesting
Definition: pg_dump.h:318
bool hasindex
Definition: pg_dump.h:295

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _constraintInfo::condef, _constraintInfo::condeferrable, _constraintInfo::condeferred, _constraintInfo::condomain, _constraintInfo::confrelid, _constraintInfo::conindex, _constraintInfo::conislocal, _constraintInfo::contable, _constraintInfo::contype, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_CONSTRAINT, DO_INDEX, _tableInfo::dobj, _indxInfo::dobj, _constraintInfo::dobj, _dumpableObject::dump, _dumpableObject::dumpId, ExecuteSqlQuery(), _tableInfo::hasindex, i, _indxInfo::indexconstraint, _indxInfo::indexdef, _tableInfo::indexes, _indxInfo::indextable, _indxInfo::indisclustered, _indxInfo::indisreplident, _indxInfo::indkeys, _indxInfo::indnattrs, _indxInfo::indnkeyattrs, _indxInfo::indnullsnotdistinct, _indxInfo::indreloptions, _indxInfo::indstatcols, _indxInfo::indstatvals, _tableInfo::interesting, InvalidOid, j, PQExpBufferData::len, _dumpableObject::name, _tableInfo::numIndexes, _dumpableObject::objType, CatalogId::oid, _indxInfo::parentidx, parseOidArray(), _indxInfo::partattaches, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, _constraintInfo::separate, CatalogId::tableoid, and _indxInfo::tablespace.

Referenced by getSchemaData().

◆ getInherits()

InhInfo* getInherits ( Archive fout,
int *  numInherits 
)

Definition at line 6857 of file pg_dump.c.

6858 {
6859  PGresult *res;
6860  int ntups;
6861  int i;
6862  PQExpBuffer query = createPQExpBuffer();
6863  InhInfo *inhinfo;
6864 
6865  int i_inhrelid;
6866  int i_inhparent;
6867 
6868  /* find all the inheritance information */
6869  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
6870 
6871  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6872 
6873  ntups = PQntuples(res);
6874 
6875  *numInherits = ntups;
6876 
6877  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6878 
6879  i_inhrelid = PQfnumber(res, "inhrelid");
6880  i_inhparent = PQfnumber(res, "inhparent");
6881 
6882  for (i = 0; i < ntups; i++)
6883  {
6884  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6885  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6886  }
6887 
6888  PQclear(res);
6889 
6890  destroyPQExpBuffer(query);
6891 
6892  return inhinfo;
6893 }
Oid inhparent
Definition: pg_dump.h:528
Oid inhrelid
Definition: pg_dump.h:527

References appendPQExpBufferStr(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), ExecuteSqlQuery(), i, _inhInfo::inhparent, _inhInfo::inhrelid, pg_malloc(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), and res.

Referenced by getSchemaData().

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )

Definition at line 715 of file common.c.

716 {
717  return lastDumpId;
718 }

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

◆ getNamespaces()

NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

Definition at line 5206 of file pg_dump.c.

5207 {
5208  PGresult *res;
5209  int ntups;
5210  int i;
5211  PQExpBuffer query;
5212  NamespaceInfo *nsinfo;
5213  int i_tableoid;
5214  int i_oid;
5215  int i_nspname;
5216  int i_nspowner;
5217  int i_nspacl;
5218  int i_acldefault;
5219 
5220  query = createPQExpBuffer();
5221 
5222  /*
5223  * we fetch all namespaces including system ones, so that every object we
5224  * read in can be linked to a containing namespace.
5225  */
5226  appendPQExpBufferStr(query, "SELECT n.tableoid, n.oid, n.nspname, "
5227  "n.nspowner, "
5228  "n.nspacl, "
5229  "acldefault('n', n.nspowner) AS acldefault "
5230  "FROM pg_namespace n");
5231 
5232  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5233 
5234  ntups = PQntuples(res);
5235 
5236  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
5237 
5238  i_tableoid = PQfnumber(res, "tableoid");
5239  i_oid = PQfnumber(res, "oid");
5240  i_nspname = PQfnumber(res, "nspname");
5241  i_nspowner = PQfnumber(res, "nspowner");
5242  i_nspacl = PQfnumber(res, "nspacl");
5243  i_acldefault = PQfnumber(res, "acldefault");
5244 
5245  for (i = 0; i < ntups; i++)
5246  {
5247  const char *nspowner;
5248 
5249  nsinfo[i].dobj.objType = DO_NAMESPACE;
5250  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5251  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5252  AssignDumpId(&nsinfo[i].dobj);
5253  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
5254  nsinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_nspacl));
5255  nsinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
5256  nsinfo[i].dacl.privtype = 0;
5257  nsinfo[i].dacl.initprivs = NULL;
5258  nspowner = PQgetvalue(res, i, i_nspowner);
5259  nsinfo[i].nspowner = atooid(nspowner);
5260  nsinfo[i].rolname = getRoleName(nspowner);
5261 
5262  /* Decide whether to dump this namespace */
5263  selectDumpableNamespace(&nsinfo[i], fout);
5264 
5265  /* Mark whether namespace has an ACL */
5266  if (!PQgetisnull(res, i, i_nspacl))
5267  nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
5268 
5269  /*
5270  * We ignore any pg_init_privs.initprivs entry for the public schema
5271  * and assume a predetermined default, for several reasons. First,
5272  * dropping and recreating the schema removes its pg_init_privs entry,
5273  * but an empty destination database starts with this ACL nonetheless.
5274  * Second, we support dump/reload of public schema ownership changes.
5275  * ALTER SCHEMA OWNER filters nspacl through aclnewowner(), but
5276  * initprivs continues to reflect the initial owner. Hence,
5277  * synthesize the value that nspacl will have after the restore's
5278  * ALTER SCHEMA OWNER. Third, this makes the destination database
5279  * match the source's ACL, even if the latter was an initdb-default
5280  * ACL, which changed in v15. An upgrade pulls in changes to most
5281  * system object ACLs that the DBA had not customized. We've made the
5282  * public schema depart from that, because changing its ACL so easily
5283  * breaks applications.
5284  */
5285  if (strcmp(nsinfo[i].dobj.name, "public") == 0)
5286  {
5287  PQExpBuffer aclarray = createPQExpBuffer();
5288  PQExpBuffer aclitem = createPQExpBuffer();
5289 
5290  /* Standard ACL as of v15 is {owner=UC/owner,=U/owner} */
5291  appendPQExpBufferChar(aclarray, '{');
5292  quoteAclUserName(aclitem, nsinfo[i].rolname);
5293  appendPQExpBufferStr(aclitem, "=UC/");
5294  quoteAclUserName(aclitem, nsinfo[i].rolname);
5295  appendPGArray(aclarray, aclitem->data);
5296  resetPQExpBuffer(aclitem);
5297  appendPQExpBufferStr(aclitem, "=U/");
5298  quoteAclUserName(aclitem, nsinfo[i].rolname);
5299  appendPGArray(aclarray, aclitem->data);
5300  appendPQExpBufferChar(aclarray, '}');
5301 
5302  nsinfo[i].dacl.privtype = 'i';
5303  nsinfo[i].dacl.initprivs = pstrdup(aclarray->data);
5304  nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
5305 
5306  destroyPQExpBuffer(aclarray);
5307  destroyPQExpBuffer(aclitem);
5308  }
5309  }
5310 
5311  PQclear(res);
5312  destroyPQExpBuffer(query);
5313 
5314  *numNamespaces = ntups;
5315 
5316  return nsinfo;
5317 }
void quoteAclUserName(PQExpBuffer output, const char *input)
Definition: dumputils.c:543
char * pstrdup(const char *in)
Definition: mcxt.c:1644
NameData rolname
Definition: pg_authid.h:34
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1729
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:146
void appendPGArray(PQExpBuffer buffer, const char *value)
Definition: string_utils.c:740
DumpableObject dobj
Definition: pg_dump.h:171
DumpableAcl dacl
Definition: pg_dump.h:172
const char * rolname
Definition: pg_dump.h:175

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPGArray(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _namespaceInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_NAMESPACE, _namespaceInfo::dobj, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), getRoleName(), i, _dumpableAcl::initprivs, _dumpableObject::name, _namespaceInfo::nspowner, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, pstrdup(), quoteAclUserName(), res, resetPQExpBuffer(), _namespaceInfo::rolname, rolname, selectDumpableNamespace(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getOpclasses()

OpclassInfo* getOpclasses ( Archive fout,
int *  numOpclasses 
)

Definition at line 5868 of file pg_dump.c.

5869 {
5870  PGresult *res;
5871  int ntups;
5872  int i;
5873  PQExpBuffer query = createPQExpBuffer();
5874  OpclassInfo *opcinfo;
5875  int i_tableoid;
5876  int i_oid;
5877  int i_opcname;
5878  int i_opcnamespace;
5879  int i_opcowner;
5880 
5881  /*
5882  * find all opclasses, including builtin opclasses; we filter out
5883  * system-defined opclasses at dump-out time.
5884  */
5885 
5886  appendPQExpBufferStr(query, "SELECT tableoid, oid, opcname, "
5887  "opcnamespace, "
5888  "opcowner "
5889  "FROM pg_opclass");
5890 
5891  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5892 
5893  ntups = PQntuples(res);
5894  *numOpclasses = ntups;
5895 
5896  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
5897 
5898  i_tableoid = PQfnumber(res, "tableoid");
5899  i_oid = PQfnumber(res, "oid");
5900  i_opcname = PQfnumber(res, "opcname");
5901  i_opcnamespace = PQfnumber(res, "opcnamespace");
5902  i_opcowner = PQfnumber(res, "opcowner");
5903 
5904  for (i = 0; i < ntups; i++)
5905  {
5906  opcinfo[i].dobj.objType = DO_OPCLASS;
5907  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5908  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5909  AssignDumpId(&opcinfo[i].dobj);
5910  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
5911  opcinfo[i].dobj.namespace =
5912  findNamespace(atooid(PQgetvalue(res, i, i_opcnamespace)));
5913  opcinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opcowner));
5914 
5915  /* Decide whether we want to dump it */
5916  selectDumpableObject(&(opcinfo[i].dobj), fout);
5917  }
5918 
5919  PQclear(res);
5920 
5921  destroyPQExpBuffer(query);
5922 
5923  return opcinfo;
5924 }
DumpableObject dobj
Definition: pg_dump.h:257
const char * rolname
Definition: pg_dump.h:258

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPCLASS, _opclassInfo::dobj, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), res, _opclassInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getOperators()

OprInfo* getOperators ( Archive fout,
int *  numOprs 
)

Definition at line 5587 of file pg_dump.c.

5588 {
5589  PGresult *res;
5590  int ntups;
5591  int i;
5592  PQExpBuffer query = createPQExpBuffer();
5593  OprInfo *oprinfo;
5594  int i_tableoid;
5595  int i_oid;
5596  int i_oprname;
5597  int i_oprnamespace;
5598  int i_oprowner;
5599  int i_oprkind;
5600  int i_oprcode;
5601 
5602  /*
5603  * find all operators, including builtin operators; we filter out
5604  * system-defined operators at dump-out time.
5605  */
5606 
5607  appendPQExpBufferStr(query, "SELECT tableoid, oid, oprname, "
5608  "oprnamespace, "
5609  "oprowner, "
5610  "oprkind, "
5611  "oprcode::oid AS oprcode "
5612  "FROM pg_operator");
5613 
5614  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5615 
5616  ntups = PQntuples(res);
5617  *numOprs = ntups;
5618 
5619  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
5620 
5621  i_tableoid = PQfnumber(res, "tableoid");
5622  i_oid = PQfnumber(res, "oid");
5623  i_oprname = PQfnumber(res, "oprname");
5624  i_oprnamespace = PQfnumber(res, "oprnamespace");
5625  i_oprowner = PQfnumber(res, "oprowner");
5626  i_oprkind = PQfnumber(res, "oprkind");
5627  i_oprcode = PQfnumber(res, "oprcode");
5628 
5629  for (i = 0; i < ntups; i++)
5630  {
5631  oprinfo[i].dobj.objType = DO_OPERATOR;
5632  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5633  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5634  AssignDumpId(&oprinfo[i].dobj);
5635  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
5636  oprinfo[i].dobj.namespace =
5637  findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)));
5638  oprinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_oprowner));
5639  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
5640  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
5641 
5642  /* Decide whether we want to dump it */
5643  selectDumpableObject(&(oprinfo[i].dobj), fout);
5644  }
5645 
5646  PQclear(res);
5647 
5648  destroyPQExpBuffer(query);
5649 
5650  return oprinfo;
5651 }
DumpableObject dobj
Definition: pg_dump.h:242
char oprkind
Definition: pg_dump.h:244
Oid oprcode
Definition: pg_dump.h:245
const char * rolname
Definition: pg_dump.h:243

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPERATOR, _oprInfo::dobj, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, _oprInfo::oprcode, _oprInfo::oprkind, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), res, _oprInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getOpfamilies()

OpfamilyInfo* getOpfamilies ( Archive fout,
int *  numOpfamilies 
)

Definition at line 5934 of file pg_dump.c.

5935 {
5936  PGresult *res;
5937  int ntups;
5938  int i;
5939  PQExpBuffer query;
5940  OpfamilyInfo *opfinfo;
5941  int i_tableoid;
5942  int i_oid;
5943  int i_opfname;
5944  int i_opfnamespace;
5945  int i_opfowner;
5946 
5947  query = createPQExpBuffer();
5948 
5949  /*
5950  * find all opfamilies, including builtin opfamilies; we filter out
5951  * system-defined opfamilies at dump-out time.
5952  */
5953 
5954  appendPQExpBufferStr(query, "SELECT tableoid, oid, opfname, "
5955  "opfnamespace, "
5956  "opfowner "
5957  "FROM pg_opfamily");
5958 
5959  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5960 
5961  ntups = PQntuples(res);
5962  *numOpfamilies = ntups;
5963 
5964  opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
5965 
5966  i_tableoid = PQfnumber(res, "tableoid");
5967  i_oid = PQfnumber(res, "oid");
5968  i_opfname = PQfnumber(res, "opfname");
5969  i_opfnamespace = PQfnumber(res, "opfnamespace");
5970  i_opfowner = PQfnumber(res, "opfowner");
5971 
5972  for (i = 0; i < ntups; i++)
5973  {
5974  opfinfo[i].dobj.objType = DO_OPFAMILY;
5975  opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5976  opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5977  AssignDumpId(&opfinfo[i].dobj);
5978  opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
5979  opfinfo[i].dobj.namespace =
5980  findNamespace(atooid(PQgetvalue(res, i, i_opfnamespace)));
5981  opfinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opfowner));
5982 
5983  /* Decide whether we want to dump it */
5984  selectDumpableObject(&(opfinfo[i].dobj), fout);
5985  }
5986 
5987  PQclear(res);
5988 
5989  destroyPQExpBuffer(query);
5990 
5991  return opfinfo;
5992 }
const char * rolname
Definition: pg_dump.h:264
DumpableObject dobj
Definition: pg_dump.h:263

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPFAMILY, _opfamilyInfo::dobj, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), res, _opfamilyInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getOwnedSeqs()

void getOwnedSeqs ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 6794 of file pg_dump.c.

6795 {
6796  int i;
6797 
6798  /*
6799  * Force sequences that are "owned" by table columns to be dumped whenever
6800  * their owning table is being dumped.
6801  */
6802  for (i = 0; i < numTables; i++)
6803  {
6804  TableInfo *seqinfo = &tblinfo[i];
6805  TableInfo *owning_tab;
6806 
6807  if (!OidIsValid(seqinfo->owning_tab))
6808  continue; /* not an owned sequence */
6809 
6810  owning_tab = findTableByOid(seqinfo->owning_tab);
6811  if (owning_tab == NULL)
6812  pg_fatal("failed sanity check, parent table with OID %u of sequence with OID %u not found",
6813  seqinfo->owning_tab, seqinfo->dobj.catId.oid);
6814 
6815  /*
6816  * Only dump identity sequences if we're going to dump the table that
6817  * it belongs to.
6818  */
6819  if (owning_tab->dobj.dump == DUMP_COMPONENT_NONE &&
6820  seqinfo->is_identity_sequence)
6821  {
6822  seqinfo->dobj.dump = DUMP_COMPONENT_NONE;
6823  continue;
6824  }
6825 
6826  /*
6827  * Otherwise we need to dump the components that are being dumped for
6828  * the table and any components which the sequence is explicitly
6829  * marked with.
6830  *
6831  * We can't simply use the set of components which are being dumped
6832  * for the table as the table might be in an extension (and only the
6833  * non-extension components, eg: ACLs if changed, security labels, and
6834  * policies, are being dumped) while the sequence is not (and
6835  * therefore the definition and other components should also be
6836  * dumped).
6837  *
6838  * If the sequence is part of the extension then it should be properly
6839  * marked by checkExtensionMembership() and this will be a no-op as
6840  * the table will be equivalently marked.
6841  */
6842  seqinfo->dobj.dump = seqinfo->dobj.dump | owning_tab->dobj.dump;
6843 
6844  if (seqinfo->dobj.dump != DUMP_COMPONENT_NONE)
6845  seqinfo->interesting = true;
6846  }
6847 }
#define DUMP_COMPONENT_NONE
Definition: pg_dump.h:95
bool is_identity_sequence
Definition: pg_dump.h:314
Oid owning_tab
Definition: pg_dump.h:312

References _dumpableObject::catId, _tableInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_NONE, findTableByOid(), i, _tableInfo::interesting, _tableInfo::is_identity_sequence, CatalogId::oid, OidIsValid, _tableInfo::owning_tab, and pg_fatal.

Referenced by getSchemaData().

◆ getPartitioningInfo()

void getPartitioningInfo ( Archive fout)

Definition at line 6913 of file pg_dump.c.

6914 {
6915  PQExpBuffer query;
6916  PGresult *res;
6917  int ntups;
6918 
6919  /* hash partitioning didn't exist before v11 */
6920  if (fout->remoteVersion < 110000)
6921  return;
6922  /* needn't bother if schema-only dump */
6923  if (fout->dopt->schemaOnly)
6924  return;
6925 
6926  query = createPQExpBuffer();
6927 
6928  /*
6929  * Unsafe partitioning schemes are exactly those for which hash enum_ops
6930  * appears among the partition opclasses. We needn't check partstrat.
6931  *
6932  * Note that this query may well retrieve info about tables we aren't
6933  * going to dump and hence have no lock on. That's okay since we need not
6934  * invoke any unsafe server-side functions.
6935  */
6936  appendPQExpBufferStr(query,
6937  "SELECT partrelid FROM pg_partitioned_table WHERE\n"
6938  "(SELECT c.oid FROM pg_opclass c JOIN pg_am a "
6939  "ON c.opcmethod = a.oid\n"
6940  "WHERE opcname = 'enum_ops' "
6941  "AND opcnamespace = 'pg_catalog'::regnamespace "
6942  "AND amname = 'hash') = ANY(partclass)");
6943 
6944  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6945 
6946  ntups = PQntuples(res);
6947 
6948  for (int i = 0; i < ntups; i++)
6949  {
6950  Oid tabrelid = atooid(PQgetvalue(res, i, 0));
6951  TableInfo *tbinfo;
6952 
6953  tbinfo = findTableByOid(tabrelid);
6954  if (tbinfo == NULL)
6955  pg_fatal("failed sanity check, table OID %u appearing in pg_partitioned_table not found",
6956  tabrelid);
6957  tbinfo->unsafe_partitions = true;
6958  }
6959 
6960  PQclear(res);
6961 
6962  destroyPQExpBuffer(query);
6963 }
bool schemaOnly
Definition: pg_backup.h:167
bool unsafe_partitions
Definition: pg_dump.h:322

References appendPQExpBufferStr(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), Archive::dopt, ExecuteSqlQuery(), findTableByOid(), i, pg_fatal, PGRES_TUPLES_OK, PQclear(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, _dumpOptions::schemaOnly, and _tableInfo::unsafe_partitions.

Referenced by getSchemaData().

◆ getPolicies()

void getPolicies ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 3774 of file pg_dump.c.

3775 {
3776  PQExpBuffer query;
3777  PQExpBuffer tbloids;
3778  PGresult *res;
3779  PolicyInfo *polinfo;
3780  int i_oid;
3781  int i_tableoid;
3782  int i_polrelid;
3783  int i_polname;
3784  int i_polcmd;
3785  int i_polpermissive;
3786  int i_polroles;
3787  int i_polqual;
3788  int i_polwithcheck;
3789  int i,
3790  j,
3791  ntups;
3792 
3793  /* No policies before 9.5 */
3794  if (fout->remoteVersion < 90500)
3795  return;
3796 
3797  query = createPQExpBuffer();
3798  tbloids = createPQExpBuffer();
3799 
3800  /*
3801  * Identify tables of interest, and check which ones have RLS enabled.
3802  */
3803  appendPQExpBufferChar(tbloids, '{');
3804  for (i = 0; i < numTables; i++)
3805  {
3806  TableInfo *tbinfo = &tblinfo[i];
3807 
3808  /* Ignore row security on tables not to be dumped */
3809  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_POLICY))
3810  continue;
3811 
3812  /* It can't have RLS or policies if it's not a table */
3813  if (tbinfo->relkind != RELKIND_RELATION &&
3814  tbinfo->relkind != RELKIND_PARTITIONED_TABLE)
3815  continue;
3816 
3817  /* Add it to the list of table OIDs to be probed below */
3818  if (tbloids->len > 1) /* do we have more than the '{'? */
3819  appendPQExpBufferChar(tbloids, ',');
3820  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
3821 
3822  /* Is RLS enabled? (That's separate from whether it has policies) */
3823  if (tbinfo->rowsec)
3824  {
3826 
3827  /*
3828  * We represent RLS being enabled on a table by creating a
3829  * PolicyInfo object with null polname.
3830  *
3831  * Note: use tableoid 0 so that this object won't be mistaken for
3832  * something that pg_depend entries apply to.
3833  */
3834  polinfo = pg_malloc(sizeof(PolicyInfo));
3835  polinfo->dobj.objType = DO_POLICY;
3836  polinfo->dobj.catId.tableoid = 0;
3837  polinfo->dobj.catId.oid = tbinfo->dobj.catId.oid;
3838  AssignDumpId(&polinfo->dobj);
3839  polinfo->dobj.namespace = tbinfo->dobj.namespace;
3840  polinfo->dobj.name = pg_strdup(tbinfo->dobj.name);
3841  polinfo->poltable = tbinfo;
3842  polinfo->polname = NULL;
3843  polinfo->polcmd = '\0';
3844  polinfo->polpermissive = 0;
3845  polinfo->polroles = NULL;
3846  polinfo->polqual = NULL;
3847  polinfo->polwithcheck = NULL;
3848  }
3849  }
3850  appendPQExpBufferChar(tbloids, '}');
3851 
3852  /*
3853  * Now, read all RLS policies belonging to the tables of interest, and
3854  * create PolicyInfo objects for them. (Note that we must filter the
3855  * results server-side not locally, because we dare not apply pg_get_expr
3856  * to tables we don't have lock on.)
3857  */
3858  pg_log_info("reading row-level security policies");
3859 
3860  printfPQExpBuffer(query,
3861  "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
3862  if (fout->remoteVersion >= 100000)
3863  appendPQExpBufferStr(query, "pol.polpermissive, ");
3864  else
3865  appendPQExpBufferStr(query, "'t' as polpermissive, ");
3866  appendPQExpBuffer(query,
3867  "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
3868  " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, "
3869  "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
3870  "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
3871  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
3872  "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
3873  tbloids->data);
3874 
3875  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
3876 
3877  ntups = PQntuples(res);
3878  if (ntups > 0)
3879  {
3880  i_oid = PQfnumber(res, "oid");
3881  i_tableoid = PQfnumber(res, "tableoid");
3882  i_polrelid = PQfnumber(res, "polrelid");
3883  i_polname = PQfnumber(res, "polname");
3884  i_polcmd = PQfnumber(res, "polcmd");
3885  i_polpermissive = PQfnumber(res, "polpermissive");
3886  i_polroles = PQfnumber(res, "polroles");
3887  i_polqual = PQfnumber(res, "polqual");
3888  i_polwithcheck = PQfnumber(res, "polwithcheck");
3889 
3890  polinfo = pg_malloc(ntups * sizeof(PolicyInfo));
3891 
3892  for (j = 0; j < ntups; j++)
3893  {
3894  Oid polrelid = atooid(PQgetvalue(res, j, i_polrelid));
3895  TableInfo *tbinfo = findTableByOid(polrelid);
3896 
3898 
3899  polinfo[j].dobj.objType = DO_POLICY;
3900  polinfo[j].dobj.catId.tableoid =
3901  atooid(PQgetvalue(res, j, i_tableoid));
3902  polinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
3903  AssignDumpId(&polinfo[j].dobj);
3904  polinfo[j].dobj.namespace = tbinfo->dobj.namespace;
3905  polinfo[j].poltable = tbinfo;
3906  polinfo[j].polname = pg_strdup(PQgetvalue(res, j, i_polname));
3907  polinfo[j].dobj.name = pg_strdup(polinfo[j].polname);
3908 
3909  polinfo[j].polcmd = *(PQgetvalue(res, j, i_polcmd));
3910  polinfo[j].polpermissive = *(PQgetvalue(res, j, i_polpermissive)) == 't';
3911 
3912  if (PQgetisnull(res, j, i_polroles))
3913  polinfo[j].polroles = NULL;
3914  else
3915  polinfo[j].polroles = pg_strdup(PQgetvalue(res, j, i_polroles));
3916 
3917  if (PQgetisnull(res, j, i_polqual))
3918  polinfo[j].polqual = NULL;
3919  else
3920  polinfo[j].polqual = pg_strdup(PQgetvalue(res, j, i_polqual));
3921 
3922  if (PQgetisnull(res, j, i_polwithcheck))
3923  polinfo[j].polwithcheck = NULL;
3924  else
3925  polinfo[j].polwithcheck
3926  = pg_strdup(PQgetvalue(res, j, i_polwithcheck));
3927  }
3928  }
3929 
3930  PQclear(res);
3931 
3932  destroyPQExpBuffer(query);
3933  destroyPQExpBuffer(tbloids);
3934 }
#define pg_log_info(...)
Definition: logging.h:124
#define DUMP_COMPONENT_POLICY
Definition: pg_dump.h:101
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:235
TableInfo * poltable
Definition: pg_dump.h:608
char * polqual
Definition: pg_dump.h:613
char polcmd
Definition: pg_dump.h:610
char * polroles
Definition: pg_dump.h:612
char * polwithcheck
Definition: pg_dump.h:614
DumpableObject dobj
Definition: pg_dump.h:607
bool polpermissive
Definition: pg_dump.h:611
char * polname
Definition: pg_dump.h:609
bool rowsec
Definition: pg_dump.h:299

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_POLICY, _tableInfo::dobj, _policyInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_POLICY, ExecuteSqlQuery(), findTableByOid(), i, j, PQExpBufferData::len, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_log_info, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, _policyInfo::polcmd, _policyInfo::polname, _policyInfo::polpermissive, _policyInfo::polqual, _policyInfo::polroles, _policyInfo::poltable, _policyInfo::polwithcheck, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), _tableInfo::relkind, Archive::remoteVersion, res, _tableInfo::rowsec, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getProcLangs()

ProcLangInfo* getProcLangs ( Archive fout,
int *  numProcLangs 
)

Definition at line 8093 of file pg_dump.c.

8094 {
8095  PGresult *res;
8096  int ntups;
8097  int i;
8098  PQExpBuffer query = createPQExpBuffer();
8099  ProcLangInfo *planginfo;
8100  int i_tableoid;
8101  int i_oid;
8102  int i_lanname;
8103  int i_lanpltrusted;
8104  int i_lanplcallfoid;
8105  int i_laninline;
8106  int i_lanvalidator;
8107  int i_lanacl;
8108  int i_acldefault;
8109  int i_lanowner;
8110 
8111  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8112  "lanname, lanpltrusted, lanplcallfoid, "
8113  "laninline, lanvalidator, "
8114  "lanacl, "
8115  "acldefault('l', lanowner) AS acldefault, "
8116  "lanowner "
8117  "FROM pg_language "
8118  "WHERE lanispl "
8119  "ORDER BY oid");
8120 
8121  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8122 
8123  ntups = PQntuples(res);
8124 
8125  *numProcLangs = ntups;
8126 
8127  planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo));
8128 
8129  i_tableoid = PQfnumber(res, "tableoid");
8130  i_oid = PQfnumber(res, "oid");
8131  i_lanname = PQfnumber(res, "lanname");
8132  i_lanpltrusted = PQfnumber(res, "lanpltrusted");
8133  i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
8134  i_laninline = PQfnumber(res, "laninline");
8135  i_lanvalidator = PQfnumber(res, "lanvalidator");
8136  i_lanacl = PQfnumber(res, "lanacl");
8137  i_acldefault = PQfnumber(res, "acldefault");
8138  i_lanowner = PQfnumber(res, "lanowner");
8139 
8140  for (i = 0; i < ntups; i++)
8141  {
8142  planginfo[i].dobj.objType = DO_PROCLANG;
8143  planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8144  planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8145  AssignDumpId(&planginfo[i].dobj);
8146 
8147  planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
8148  planginfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_lanacl));
8149  planginfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
8150  planginfo[i].dacl.privtype = 0;
8151  planginfo[i].dacl.initprivs = NULL;
8152  planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
8153  planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
8154  planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
8155  planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
8156  planginfo[i].lanowner = getRoleName(PQgetvalue(res, i, i_lanowner));
8157 
8158  /* Decide whether we want to dump it */
8159  selectDumpableProcLang(&(planginfo[i]), fout);
8160 
8161  /* Mark whether language has an ACL */
8162  if (!PQgetisnull(res, i, i_lanacl))
8163  planginfo[i].dobj.components |= DUMP_COMPONENT_ACL;
8164  }
8165 
8166  PQclear(res);
8167 
8168  destroyPQExpBuffer(query);
8169 
8170  return planginfo;
8171 }
static void selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
Definition: pg_dump.c:1946
Oid lanvalidator
Definition: pg_dump.h:501
DumpableAcl dacl
Definition: pg_dump.h:497
DumpableObject dobj
Definition: pg_dump.h:496
Oid laninline
Definition: pg_dump.h:500
const char * lanowner
Definition: pg_dump.h:502
Oid lanplcallfoid
Definition: pg_dump.h:499
bool lanpltrusted
Definition: pg_dump.h:498

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _procLangInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_PROCLANG, _procLangInfo::dobj, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), getRoleName(), i, _dumpableAcl::initprivs, _procLangInfo::laninline, _procLangInfo::lanowner, _procLangInfo::lanplcallfoid, _procLangInfo::lanpltrusted, _procLangInfo::lanvalidator, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, res, selectDumpableProcLang(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getPublicationNamespaces()

void getPublicationNamespaces ( Archive fout)

Definition at line 4259 of file pg_dump.c.

4260 {
4261  PQExpBuffer query;
4262  PGresult *res;
4263  PublicationSchemaInfo *pubsinfo;
4264  DumpOptions *dopt = fout->dopt;
4265  int i_tableoid;
4266  int i_oid;
4267  int i_pnpubid;
4268  int i_pnnspid;
4269  int i,
4270  j,
4271  ntups;
4272 
4273  if (dopt->no_publications || fout->remoteVersion < 150000)
4274  return;
4275 
4276  query = createPQExpBuffer();
4277 
4278  /* Collect all publication membership info. */
4279  appendPQExpBufferStr(query,
4280  "SELECT tableoid, oid, pnpubid, pnnspid "
4281  "FROM pg_catalog.pg_publication_namespace");
4282  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4283 
4284  ntups = PQntuples(res);
4285 
4286  i_tableoid = PQfnumber(res, "tableoid");
4287  i_oid = PQfnumber(res, "oid");
4288  i_pnpubid = PQfnumber(res, "pnpubid");
4289  i_pnnspid = PQfnumber(res, "pnnspid");
4290 
4291  /* this allocation may be more than we need */
4292  pubsinfo = pg_malloc(ntups * sizeof(PublicationSchemaInfo));
4293  j = 0;
4294 
4295  for (i = 0; i < ntups; i++)
4296  {
4297  Oid pnpubid = atooid(PQgetvalue(res, i, i_pnpubid));
4298  Oid pnnspid = atooid(PQgetvalue(res, i, i_pnnspid));
4299  PublicationInfo *pubinfo;
4300  NamespaceInfo *nspinfo;
4301 
4302  /*
4303  * Ignore any entries for which we aren't interested in either the
4304  * publication or the rel.
4305  */
4306  pubinfo = findPublicationByOid(pnpubid);
4307  if (pubinfo == NULL)
4308  continue;
4309  nspinfo = findNamespaceByOid(pnnspid);
4310  if (nspinfo == NULL)
4311  continue;
4312 
4313  /*
4314  * We always dump publication namespaces unless the corresponding
4315  * namespace is excluded from the dump.
4316  */
4317  if (nspinfo->dobj.dump == DUMP_COMPONENT_NONE)
4318  continue;
4319 
4320  /* OK, make a DumpableObject for this relationship */
4322  pubsinfo[j].dobj.catId.tableoid =
4323  atooid(PQgetvalue(res, i, i_tableoid));
4324  pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4325  AssignDumpId(&pubsinfo[j].dobj);
4326  pubsinfo[j].dobj.namespace = nspinfo->dobj.namespace;
4327  pubsinfo[j].dobj.name = nspinfo->dobj.name;
4328  pubsinfo[j].publication = pubinfo;
4329  pubsinfo[j].pubschema = nspinfo;
4330 
4331  /* Decide whether we want to dump it */
4332  selectDumpablePublicationObject(&(pubsinfo[j].dobj), fout);
4333 
4334  j++;
4335  }
4336 
4337  PQclear(res);
4338  destroyPQExpBuffer(query);
4339 }
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition: common.c:933
PublicationInfo * findPublicationByOid(Oid oid)
Definition: common.c:969
static void selectDumpablePublicationObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:2040
NamespaceInfo * pubschema
Definition: pg_dump.h:653
DumpableObject dobj
Definition: pg_dump.h:651
PublicationInfo * publication
Definition: pg_dump.h:652
int no_publications
Definition: pg_backup.h:180

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PUBLICATION_TABLE_IN_SCHEMA, _namespaceInfo::dobj, _PublicationSchemaInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_NONE, ExecuteSqlQuery(), findNamespaceByOid(), findPublicationByOid(), i, j, _dumpableObject::name, _dumpOptions::no_publications, _dumpableObject::objType, CatalogId::oid, pg_malloc(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _PublicationSchemaInfo::publication, _PublicationSchemaInfo::pubschema, Archive::remoteVersion, res, selectDumpablePublicationObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getPublications()

PublicationInfo* getPublications ( Archive fout,
int *  numPublications 
)

Definition at line 4059 of file pg_dump.c.

4060 {
4061  DumpOptions *dopt = fout->dopt;
4062  PQExpBuffer query;
4063  PGresult *res;
4064  PublicationInfo *pubinfo;
4065  int i_tableoid;
4066  int i_oid;
4067  int i_pubname;
4068  int i_pubowner;
4069  int i_puballtables;
4070  int i_pubinsert;
4071  int i_pubupdate;
4072  int i_pubdelete;
4073  int i_pubtruncate;
4074  int i_pubviaroot;
4075  int i,
4076  ntups;
4077 
4078  if (dopt->no_publications || fout->remoteVersion < 100000)
4079  {
4080  *numPublications = 0;
4081  return NULL;
4082  }
4083 
4084  query = createPQExpBuffer();
4085 
4086  resetPQExpBuffer(query);
4087 
4088  /* Get the publications. */
4089  if (fout->remoteVersion >= 130000)
4090  appendPQExpBufferStr(query,
4091  "SELECT p.tableoid, p.oid, p.pubname, "
4092  "p.pubowner, "
4093  "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, p.pubviaroot "
4094  "FROM pg_publication p");
4095  else if (fout->remoteVersion >= 110000)
4096  appendPQExpBufferStr(query,
4097  "SELECT p.tableoid, p.oid, p.pubname, "
4098  "p.pubowner, "
4099  "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, false AS pubviaroot "
4100  "FROM pg_publication p");
4101  else
4102  appendPQExpBufferStr(query,
4103  "SELECT p.tableoid, p.oid, p.pubname, "
4104  "p.pubowner, "
4105  "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, false AS pubtruncate, false AS pubviaroot "
4106  "FROM pg_publication p");
4107 
4108  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4109 
4110  ntups = PQntuples(res);
4111 
4112  i_tableoid = PQfnumber(res, "tableoid");
4113  i_oid = PQfnumber(res, "oid");
4114  i_pubname = PQfnumber(res, "pubname");
4115  i_pubowner = PQfnumber(res, "pubowner");
4116  i_puballtables = PQfnumber(res, "puballtables");
4117  i_pubinsert = PQfnumber(res, "pubinsert");
4118  i_pubupdate = PQfnumber(res, "pubupdate");
4119  i_pubdelete = PQfnumber(res, "pubdelete");
4120  i_pubtruncate = PQfnumber(res, "pubtruncate");
4121  i_pubviaroot = PQfnumber(res, "pubviaroot");
4122 
4123  pubinfo = pg_malloc(ntups * sizeof(PublicationInfo));
4124 
4125  for (i = 0; i < ntups; i++)
4126  {
4127  pubinfo[i].dobj.objType = DO_PUBLICATION;
4128  pubinfo[i].dobj.catId.tableoid =
4129  atooid(PQgetvalue(res, i, i_tableoid));
4130  pubinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4131  AssignDumpId(&pubinfo[i].dobj);
4132  pubinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_pubname));
4133  pubinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_pubowner));
4134  pubinfo[i].puballtables =
4135  (strcmp(PQgetvalue(res, i, i_puballtables), "t") == 0);
4136  pubinfo[i].pubinsert =
4137  (strcmp(PQgetvalue(res, i, i_pubinsert), "t") == 0);
4138  pubinfo[i].pubupdate =
4139  (strcmp(PQgetvalue(res, i, i_pubupdate), "t") == 0);
4140  pubinfo[i].pubdelete =
4141  (strcmp(PQgetvalue(res, i, i_pubdelete), "t") == 0);
4142  pubinfo[i].pubtruncate =
4143  (strcmp(PQgetvalue(res, i, i_pubtruncate), "t") == 0);
4144  pubinfo[i].pubviaroot =
4145  (strcmp(PQgetvalue(res, i, i_pubviaroot), "t") == 0);
4146 
4147  /* Decide whether we want to dump it */
4148  selectDumpableObject(&(pubinfo[i].dobj), fout);
4149  }
4150  PQclear(res);
4151 
4152  destroyPQExpBuffer(query);
4153 
4154  *numPublications = ntups;
4155  return pubinfo;
4156 }
const char * rolname
Definition: pg_dump.h:623
bool puballtables
Definition: pg_dump.h:624
bool pubtruncate
Definition: pg_dump.h:628
DumpableObject dobj
Definition: pg_dump.h:622

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PUBLICATION, _PublicationInfo::dobj, Archive::dopt, ExecuteSqlQuery(), getRoleName(), i, _dumpableObject::name, _dumpOptions::no_publications, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _PublicationInfo::puballtables, _PublicationInfo::pubdelete, _PublicationInfo::pubinsert, _PublicationInfo::pubtruncate, _PublicationInfo::pubupdate, _PublicationInfo::pubviaroot, Archive::remoteVersion, res, resetPQExpBuffer(), _PublicationInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getPublicationTables()

void getPublicationTables ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 4346 of file pg_dump.c.

4347 {
4348  PQExpBuffer query;
4349  PGresult *res;
4350  PublicationRelInfo *pubrinfo;
4351  DumpOptions *dopt = fout->dopt;
4352  int i_tableoid;
4353  int i_oid;
4354  int i_prpubid;
4355  int i_prrelid;
4356  int i_prrelqual;
4357  int i_prattrs;
4358  int i,
4359  j,
4360  ntups;
4361 
4362  if (dopt->no_publications || fout->remoteVersion < 100000)
4363  return;
4364 
4365  query = createPQExpBuffer();
4366 
4367  /* Collect all publication membership info. */
4368  if (fout->remoteVersion >= 150000)
4369  appendPQExpBufferStr(query,
4370  "SELECT tableoid, oid, prpubid, prrelid, "
4371  "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4372  "(CASE\n"
4373  " WHEN pr.prattrs IS NOT NULL THEN\n"
4374  " (SELECT array_agg(attname)\n"
4375  " FROM\n"
4376  " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4377  " pg_catalog.pg_attribute\n"
4378  " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4379  " ELSE NULL END) prattrs "
4380  "FROM pg_catalog.pg_publication_rel pr");
4381  else
4382  appendPQExpBufferStr(query,
4383  "SELECT tableoid, oid, prpubid, prrelid, "
4384  "NULL AS prrelqual, NULL AS prattrs "
4385  "FROM pg_catalog.pg_publication_rel");
4386  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4387 
4388  ntups = PQntuples(res);
4389 
4390  i_tableoid = PQfnumber(res, "tableoid");
4391  i_oid = PQfnumber(res, "oid");
4392  i_prpubid = PQfnumber(res, "prpubid");
4393  i_prrelid = PQfnumber(res, "prrelid");
4394  i_prrelqual = PQfnumber(res, "prrelqual");
4395  i_prattrs = PQfnumber(res, "prattrs");
4396 
4397  /* this allocation may be more than we need */
4398  pubrinfo = pg_malloc(ntups * sizeof(PublicationRelInfo));
4399  j = 0;
4400 
4401  for (i = 0; i < ntups; i++)
4402  {
4403  Oid prpubid = atooid(PQgetvalue(res, i, i_prpubid));
4404  Oid prrelid = atooid(PQgetvalue(res, i, i_prrelid));
4405  PublicationInfo *pubinfo;
4406  TableInfo *tbinfo;
4407 
4408  /*
4409  * Ignore any entries for which we aren't interested in either the
4410  * publication or the rel.
4411  */
4412  pubinfo = findPublicationByOid(prpubid);
4413  if (pubinfo == NULL)
4414  continue;
4415  tbinfo = findTableByOid(prrelid);
4416  if (tbinfo == NULL)
4417  continue;
4418 
4419  /*
4420  * Ignore publication membership of tables whose definitions are not
4421  * to be dumped.
4422  */
4423  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
4424  continue;
4425 
4426  /* OK, make a DumpableObject for this relationship */
4427  pubrinfo[j].dobj.objType = DO_PUBLICATION_REL;
4428  pubrinfo[j].dobj.catId.tableoid =
4429  atooid(PQgetvalue(res, i, i_tableoid));
4430  pubrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4431  AssignDumpId(&pubrinfo[j].dobj);
4432  pubrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4433  pubrinfo[j].dobj.name = tbinfo->dobj.name;
4434  pubrinfo[j].publication = pubinfo;
4435  pubrinfo[j].pubtable = tbinfo;
4436  if (PQgetisnull(res, i, i_prrelqual))
4437  pubrinfo[j].pubrelqual = NULL;
4438  else
4439  pubrinfo[j].pubrelqual = pg_strdup(PQgetvalue(res, i, i_prrelqual));
4440 
4441  if (!PQgetisnull(res, i, i_prattrs))
4442  {
4443  char **attnames;
4444  int nattnames;
4445  PQExpBuffer attribs;
4446 
4447  if (!parsePGArray(PQgetvalue(res, i, i_prattrs),
4448  &attnames, &nattnames))
4449  pg_fatal("could not parse %s array", "prattrs");
4450  attribs = createPQExpBuffer();
4451  for (int k = 0; k < nattnames; k++)
4452  {
4453  if (k > 0)
4454  appendPQExpBufferStr(attribs, ", ");
4455 
4456  appendPQExpBufferStr(attribs, fmtId(attnames[k]));
4457  }
4458  pubrinfo[j].pubrattrs = attribs->data;
4459  }
4460  else
4461  pubrinfo[j].pubrattrs = NULL;
4462 
4463  /* Decide whether we want to dump it */
4464  selectDumpablePublicationObject(&(pubrinfo[j].dobj), fout);
4465 
4466  j++;
4467  }
4468 
4469  PQclear(res);
4470  destroyPQExpBuffer(query);
4471 }
const char * fmtId(const char *rawid)
Definition: string_utils.c:64
bool parsePGArray(const char *atext, char ***itemarray, int *nitems)
Definition: string_utils.c:657

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PUBLICATION_REL, _tableInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), findPublicationByOid(), findTableByOid(), fmtId(), i, j, _dumpableObject::name, _dumpOptions::no_publications, parsePGArray(), pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, and selectDumpablePublicationObject().

Referenced by getSchemaData().

◆ getRules()

RuleInfo* getRules ( Archive fout,
int *  numRules 
)

Definition at line 7635 of file pg_dump.c.

7636 {
7637  PGresult *res;
7638  int ntups;
7639  int i;
7640  PQExpBuffer query = createPQExpBuffer();
7641  RuleInfo *ruleinfo;
7642  int i_tableoid;
7643  int i_oid;
7644  int i_rulename;
7645  int i_ruletable;
7646  int i_ev_type;
7647  int i_is_instead;
7648  int i_ev_enabled;
7649 
7650  appendPQExpBufferStr(query, "SELECT "
7651  "tableoid, oid, rulename, "
7652  "ev_class AS ruletable, ev_type, is_instead, "
7653  "ev_enabled "
7654  "FROM pg_rewrite "
7655  "ORDER BY oid");
7656 
7657  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7658 
7659  ntups = PQntuples(res);
7660 
7661  *numRules = ntups;
7662 
7663  ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo));
7664 
7665  i_tableoid = PQfnumber(res, "tableoid");
7666  i_oid = PQfnumber(res, "oid");
7667  i_rulename = PQfnumber(res, "rulename");
7668  i_ruletable = PQfnumber(res, "ruletable");
7669  i_ev_type = PQfnumber(res, "ev_type");
7670  i_is_instead = PQfnumber(res, "is_instead");
7671  i_ev_enabled = PQfnumber(res, "ev_enabled");
7672 
7673  for (i = 0; i < ntups; i++)
7674  {
7675  Oid ruletableoid;
7676 
7677  ruleinfo[i].dobj.objType = DO_RULE;
7678  ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7679  ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7680  AssignDumpId(&ruleinfo[i].dobj);
7681  ruleinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_rulename));
7682  ruletableoid = atooid(PQgetvalue(res, i, i_ruletable));
7683  ruleinfo[i].ruletable = findTableByOid(ruletableoid);
7684  if (ruleinfo[i].ruletable == NULL)
7685  pg_fatal("failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
7686  ruletableoid, ruleinfo[i].dobj.catId.oid);
7687  ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace;
7688  ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump;
7689  ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type));
7690  ruleinfo[i].is_instead = *(PQgetvalue(res, i, i_is_instead)) == 't';
7691  ruleinfo[i].ev_enabled = *(PQgetvalue(res, i, i_ev_enabled));
7692  if (ruleinfo[i].ruletable)
7693  {
7694  /*
7695  * If the table is a view or materialized view, force its ON
7696  * SELECT rule to be sorted before the view itself --- this
7697  * ensures that any dependencies for the rule affect the table's
7698  * positioning. Other rules are forced to appear after their
7699  * table.
7700  */
7701  if ((ruleinfo[i].ruletable->relkind == RELKIND_VIEW ||
7702  ruleinfo[i].ruletable->relkind == RELKIND_MATVIEW) &&
7703  ruleinfo[i].ev_type == '1' && ruleinfo[i].is_instead)
7704  {
7705  addObjectDependency(&ruleinfo[i].ruletable->dobj,
7706  ruleinfo[i].dobj.dumpId);
7707  /* We'll merge the rule into CREATE VIEW, if possible */
7708  ruleinfo[i].separate = false;
7709  }
7710  else
7711  {
7712  addObjectDependency(&ruleinfo[i].dobj,
7713  ruleinfo[i].ruletable->dobj.dumpId);
7714  ruleinfo[i].separate = true;
7715  }
7716  }
7717  else
7718  ruleinfo[i].separate = true;
7719  }
7720 
7721  PQclear(res);
7722 
7723  destroyPQExpBuffer(query);
7724 
7725  return ruleinfo;
7726 }
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:779
DumpableObject dobj
Definition: pg_dump.h:432
bool separate
Definition: pg_dump.h:437
char ev_enabled
Definition: pg_dump.h:436
bool is_instead
Definition: pg_dump.h:435
TableInfo * ruletable
Definition: pg_dump.h:433
char ev_type
Definition: pg_dump.h:434

References addObjectDependency(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_RULE, _tableInfo::dobj, _ruleInfo::dobj, _dumpableObject::dump, _dumpableObject::dumpId, _ruleInfo::ev_enabled, _ruleInfo::ev_type, ExecuteSqlQuery(), findTableByOid(), i, _ruleInfo::is_instead, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relkind, res, _ruleInfo::ruletable, _ruleInfo::separate, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getSchemaData()

TableInfo* getSchemaData ( Archive fout,
int *  numTablesPtr 
)

Definition at line 96 of file common.c.

97 {
98  TableInfo *tblinfo;
99  ExtensionInfo *extinfo;
100  InhInfo *inhinfo;
101  int numTables;
102  int numTypes;
103  int numFuncs;
104  int numOperators;
105  int numCollations;
106  int numNamespaces;
107  int numExtensions;
108  int numPublications;
109  int numAggregates;
110  int numInherits;
111  int numRules;
112  int numProcLangs;
113  int numCasts;
114  int numTransforms;
115  int numAccessMethods;
116  int numOpclasses;
117  int numOpfamilies;
118  int numConversions;
119  int numTSParsers;
120  int numTSTemplates;
121  int numTSDicts;
122  int numTSConfigs;
123  int numForeignDataWrappers;
124  int numForeignServers;
125  int numDefaultACLs;
126  int numEventTriggers;
127 
128  /*
129  * We must read extensions and extension membership info first, because
130  * extension membership needs to be consultable during decisions about
131  * whether other objects are to be dumped.
132  */
133  pg_log_info("reading extensions");
134  extinfo = getExtensions(fout, &numExtensions);
135 
136  pg_log_info("identifying extension members");
137  getExtensionMembership(fout, extinfo, numExtensions);
138 
139  pg_log_info("reading schemas");
140  (void) getNamespaces(fout, &numNamespaces);
141 
142  /*
143  * getTables should be done as soon as possible, so as to minimize the
144  * window between starting our transaction and acquiring per-table locks.
145  * However, we have to do getNamespaces first because the tables get
146  * linked to their containing namespaces during getTables.
147  */
148  pg_log_info("reading user-defined tables");
149  tblinfo = getTables(fout, &numTables);
150 
151  getOwnedSeqs(fout, tblinfo, numTables);
152 
153  pg_log_info("reading user-defined functions");
154  (void) getFuncs(fout, &numFuncs);
155 
156  /* this must be after getTables and getFuncs */
157  pg_log_info("reading user-defined types");
158  (void) getTypes(fout, &numTypes);
159 
160  /* this must be after getFuncs, too */
161  pg_log_info("reading procedural languages");
162  getProcLangs(fout, &numProcLangs);
163 
164  pg_log_info("reading user-defined aggregate functions");
165  getAggregates(fout, &numAggregates);
166 
167  pg_log_info("reading user-defined operators");
168  (void) getOperators(fout, &numOperators);
169 
170  pg_log_info("reading user-defined access methods");
171  getAccessMethods(fout, &numAccessMethods);
172 
173  pg_log_info("reading user-defined operator classes");
174  getOpclasses(fout, &numOpclasses);
175 
176  pg_log_info("reading user-defined operator families");
177  getOpfamilies(fout, &numOpfamilies);
178 
179  pg_log_info("reading user-defined text search parsers");
180  getTSParsers(fout, &numTSParsers);
181 
182  pg_log_info("reading user-defined text search templates");
183  getTSTemplates(fout, &numTSTemplates);
184 
185  pg_log_info("reading user-defined text search dictionaries");
186  getTSDictionaries(fout, &numTSDicts);
187 
188  pg_log_info("reading user-defined text search configurations");
189  getTSConfigurations(fout, &numTSConfigs);
190 
191  pg_log_info("reading user-defined foreign-data wrappers");
192  getForeignDataWrappers(fout, &numForeignDataWrappers);
193 
194  pg_log_info("reading user-defined foreign servers");
195  getForeignServers(fout, &numForeignServers);
196 
197  pg_log_info("reading default privileges");
198  getDefaultACLs(fout, &numDefaultACLs);
199 
200  pg_log_info(