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  _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  _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  _blobInfo
 
struct  _policyInfo
 
struct  _PublicationInfo
 
struct  _PublicationRelInfo
 
struct  _SubscriptionInfo
 
struct  _extensionMemberId
 

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 _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 _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 _blobInfo BlobInfo
 
typedef struct _policyInfo PolicyInfo
 
typedef struct _PublicationInfo PublicationInfo
 
typedef struct _PublicationRelInfo PublicationRelInfo
 
typedef struct _SubscriptionInfo SubscriptionInfo
 
typedef struct _extensionMemberId ExtensionMemberId
 

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_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_BLOB, DO_BLOB_DATA,
  DO_PRE_DATA_BOUNDARY, DO_POST_DATA_BOUNDARY, DO_EVENT_TRIGGER, DO_REFRESH_MATVIEW,
  DO_POLICY, DO_PUBLICATION, DO_PUBLICATION_REL, 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)
 
void setExtensionMembership (ExtensionMemberId *extmems, int nextmems)
 
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 *numAggregates)
 
OprInfogetOperators (Archive *fout, int *numOperators)
 
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 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 *tbinfo, int numTables)
 
bool shouldPrintColumn (DumpOptions *dopt, 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)
 
void getPublications (Archive *fout)
 
void getPublicationTables (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getSubscriptions (Archive *fout)
 

Macro Definition Documentation

◆ DUMP_COMPONENT_ACL

◆ DUMP_COMPONENT_ALL

◆ DUMP_COMPONENT_COMMENT

◆ DUMP_COMPONENT_DATA

#define DUMP_COMPONENT_DATA   (1 << 1)

◆ DUMP_COMPONENT_DEFINITION

◆ DUMP_COMPONENT_NONE

◆ DUMP_COMPONENT_POLICY

#define DUMP_COMPONENT_POLICY   (1 << 5)

Definition at line 94 of file pg_dump.h.

Referenced by checkExtensionMembership(), dumpPolicy(), and getPolicies().

◆ DUMP_COMPONENT_SECLABEL

◆ DUMP_COMPONENT_USERMAP

#define DUMP_COMPONENT_USERMAP   (1 << 6)

Definition at line 95 of file pg_dump.h.

Referenced by dumpForeignServer().

◆ DUMP_COMPONENTS_REQUIRING_LOCK

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

Definition at line 120 of file pg_dump.h.

Referenced by getTables().

◆ oidcmp

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

Typedef Documentation

◆ AccessMethodInfo

◆ AggInfo

typedef struct _aggInfo AggInfo

◆ AttrDefInfo

typedef struct _attrDefInfo AttrDefInfo

◆ BlobInfo

typedef struct _blobInfo BlobInfo

◆ CastInfo

typedef struct _castInfo CastInfo

◆ CollInfo

typedef struct _collInfo CollInfo

◆ ConstraintInfo

◆ ConvInfo

typedef struct _convInfo ConvInfo

◆ DefaultACLInfo

◆ DumpableObject

◆ DumpComponents

Definition at line 87 of file pg_dump.h.

◆ EventTriggerInfo

◆ ExtensionInfo

typedef struct _extensionInfo ExtensionInfo

◆ ExtensionMemberId

◆ FdwInfo

typedef struct _fdwInfo FdwInfo

◆ ForeignServerInfo

◆ FuncInfo

typedef struct _funcInfo FuncInfo

◆ IndexAttachInfo

◆ IndxInfo

typedef struct _indxInfo IndxInfo

◆ InhInfo

typedef struct _inhInfo InhInfo

◆ 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

◆ RuleInfo

typedef struct _ruleInfo RuleInfo

◆ ShellTypeInfo

typedef struct _shellTypeInfo ShellTypeInfo

◆ StatsExtInfo

typedef struct _statsExtInfo StatsExtInfo

◆ SubscriptionInfo

◆ 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_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_BLOB 
DO_BLOB_DATA 
DO_PRE_DATA_BOUNDARY 
DO_POST_DATA_BOUNDARY 
DO_EVENT_TRIGGER 
DO_REFRESH_MATVIEW 
DO_POLICY 
DO_PUBLICATION 
DO_PUBLICATION_REL 
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,
53  DO_ATTRDEF,
54  DO_INDEX,
57  DO_RULE,
58  DO_TRIGGER,
60  DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
62  DO_CAST,
67  DO_TSDICT,
70  DO_FDW,
74  DO_BLOB,
80  DO_POLICY,
DumpableObjectType
Definition: pg_dump.h:37
Definition: pg_dump.h:45
Definition: pg_dump.h:70

Function Documentation

◆ addObjectDependency()

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

Definition at line 782 of file common.c.

References _dumpableObject::allocDeps, _dumpableObject::dependencies, _dumpableObject::nDeps, pg_malloc(), and pg_realloc().

Referenced by addBoundaryDependencies(), buildMatViewRefreshDependencies(), checkExtensionMembership(), flagInhAttrs(), flagInhIndexes(), getConstraints(), getDependencies(), getDomainConstraints(), getRules(), getTableAttrs(), getTableDataFKConstraints(), makeTableDataInfo(), processExtensionTables(), repairDomainConstraintMultiLoop(), repairTableAttrDefMultiLoop(), repairTableConstraintMultiLoop(), repairTypeFuncLoop(), and repairViewRuleMultiLoop().

783 {
784  if (dobj->nDeps >= dobj->allocDeps)
785  {
786  if (dobj->allocDeps <= 0)
787  {
788  dobj->allocDeps = 16;
789  dobj->dependencies = (DumpId *)
790  pg_malloc(dobj->allocDeps * sizeof(DumpId));
791  }
792  else
793  {
794  dobj->allocDeps *= 2;
795  dobj->dependencies = (DumpId *)
796  pg_realloc(dobj->dependencies,
797  dobj->allocDeps * sizeof(DumpId));
798  }
799  }
800  dobj->dependencies[dobj->nDeps++] = refId;
801 }
int DumpId
Definition: pg_backup.h:234
DumpId * dependencies
Definition: pg_dump.h:136
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65

◆ AssignDumpId()

void AssignDumpId ( DumpableObject dobj)

Definition at line 545 of file common.c.

References _dumpableObject::allocDeps, allocedDumpIds, catalogIdMapValid, _dumpableObject::dependencies, _dumpableObject::depends_on_ext, _dumpableObject::dump, DUMP_COMPONENT_ALL, _dumpableObject::dumpId, _dumpableObject::ext_member, lastDumpId, _dumpableObject::name, _dumpableObject::nDeps, pg_malloc(), and pg_realloc().

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

546 {
547  dobj->dumpId = ++lastDumpId;
548  dobj->name = NULL; /* must be set later */
549  dobj->namespace = NULL; /* may be set later */
550  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
551  dobj->ext_member = false; /* default assumption */
552  dobj->depends_on_ext = false; /* default assumption */
553  dobj->dependencies = NULL;
554  dobj->nDeps = 0;
555  dobj->allocDeps = 0;
556 
557  while (dobj->dumpId >= allocedDumpIds)
558  {
559  int newAlloc;
560 
561  if (allocedDumpIds <= 0)
562  {
563  newAlloc = 256;
565  pg_malloc(newAlloc * sizeof(DumpableObject *));
566  }
567  else
568  {
569  newAlloc = allocedDumpIds * 2;
571  pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
572  }
573  memset(dumpIdMap + allocedDumpIds, 0,
574  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
575  allocedDumpIds = newAlloc;
576  }
577  dumpIdMap[dobj->dumpId] = dobj;
578 
579  /* mark catalogIdMap invalid, but don't rebuild it yet */
580  catalogIdMapValid = false;
581 }
char * name
Definition: pg_dump.h:130
static int allocedDumpIds
Definition: common.c:30
DumpComponents dump
Definition: pg_dump.h:131
static DumpId lastDumpId
Definition: common.c:31
static DumpableObject ** dumpIdMap
Definition: common.c:29
DumpId * dependencies
Definition: pg_dump.h:136
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpId dumpId
Definition: pg_dump.h:129
bool ext_member
Definition: pg_dump.h:134
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
bool depends_on_ext
Definition: pg_dump.h:135
static bool catalogIdMapValid
Definition: common.c:36
#define DUMP_COMPONENT_ALL
Definition: pg_dump.h:96

◆ createDumpId()

◆ findCollationByOid()

CollInfo* findCollationByOid ( Oid  oid)

Definition at line 873 of file common.c.

References findObjectByOid(), and numCollations.

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

874 {
876 }
static DumpableObject ** collinfoindex
Definition: common.c:52
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static int numCollations
Definition: common.c:59

◆ findExtensionByOid()

ExtensionInfo* findExtensionByOid ( Oid  oid)

Definition at line 895 of file common.c.

References findObjectByOid(), and numExtensions.

Referenced by getExtensionMembership().

896 {
898 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static int numExtensions
Definition: common.c:61
static DumpableObject ** extinfoindex
Definition: common.c:54

◆ findFuncByOid()

FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 851 of file common.c.

References findObjectByOid(), and numFuncs.

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

852 {
853  return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs);
854 }
static int numFuncs
Definition: common.c:57
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static DumpableObject ** funinfoindex
Definition: common.c:50

◆ findNamespaceByOid()

NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 884 of file common.c.

References findObjectByOid(), and numNamespaces.

Referenced by findNamespace().

885 {
887 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static int numNamespaces
Definition: common.c:60
static DumpableObject ** nspinfoindex
Definition: common.c:53

◆ findObjectByCatalogId()

DumpableObject* findObjectByCatalogId ( CatalogId  catalogId)

Definition at line 628 of file common.c.

References catalogIdMap, catalogIdMapValid, difference(), DOCatalogIdCompare(), free, getDumpableObjects(), numCatalogIds, CatalogId::oid, oidcmp, qsort, and CatalogId::tableoid.

Referenced by buildMatViewRefreshDependencies(), and getDependencies().

629 {
630  DumpableObject **low;
631  DumpableObject **high;
632 
633  if (!catalogIdMapValid)
634  {
635  if (catalogIdMap)
638  if (numCatalogIds > 1)
639  qsort((void *) catalogIdMap, numCatalogIds,
641  catalogIdMapValid = true;
642  }
643 
644  /*
645  * We could use bsearch() here, but the notational cruft of calling
646  * bsearch is nearly as bad as doing it ourselves; and the generalized
647  * bsearch function is noticeably slower as well.
648  */
649  if (numCatalogIds <= 0)
650  return NULL;
651  low = catalogIdMap;
652  high = catalogIdMap + (numCatalogIds - 1);
653  while (low <= high)
654  {
655  DumpableObject **middle;
656  int difference;
657 
658  middle = low + (high - low) / 2;
659  /* comparison must match DOCatalogIdCompare, below */
660  difference = oidcmp((*middle)->catId.oid, catalogId.oid);
661  if (difference == 0)
662  difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid);
663  if (difference == 0)
664  return *middle;
665  else if (difference < 0)
666  low = middle + 1;
667  else
668  high = middle - 1;
669  }
670  return NULL;
671 }
Oid tableoid
Definition: pg_backup.h:230
#define oidcmp(x, y)
Definition: pg_dump.h:20
static int DOCatalogIdCompare(const void *p1, const void *p2)
Definition: common.c:738
static int numCatalogIds
Definition: common.c:38
Datum difference(PG_FUNCTION_ARGS)
#define free(a)
Definition: header.h:65
static DumpableObject ** catalogIdMap
Definition: common.c:37
static bool catalogIdMapValid
Definition: common.c:36
#define qsort(a, b, c, d)
Definition: port.h:479
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition: common.c:760

◆ findObjectByDumpId()

DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 610 of file common.c.

References allocedDumpIds.

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

611 {
612  if (dumpId <= 0 || dumpId >= allocedDumpIds)
613  return NULL; /* out of range? */
614  return dumpIdMap[dumpId];
615 }
static int allocedDumpIds
Definition: common.c:30
static DumpableObject ** dumpIdMap
Definition: common.c:29

◆ findOprByOid()

OprInfo* findOprByOid ( Oid  oid)

Definition at line 862 of file common.c.

References findObjectByOid(), and numOperators.

Referenced by getFormattedOperatorName().

863 {
865 }
static DumpableObject ** oprinfoindex
Definition: common.c:51
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static int numOperators
Definition: common.c:58

◆ findOwningExtension()

ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 934 of file common.c.

References _extensionMemberId::catId, difference(), _extensionMemberId::ext, extmembers, numextmembers, CatalogId::oid, oidcmp, and CatalogId::tableoid.

Referenced by checkExtensionMembership().

935 {
936  ExtensionMemberId *low;
937  ExtensionMemberId *high;
938 
939  /*
940  * We could use bsearch() here, but the notational cruft of calling
941  * bsearch is nearly as bad as doing it ourselves; and the generalized
942  * bsearch function is noticeably slower as well.
943  */
944  if (numextmembers <= 0)
945  return NULL;
946  low = extmembers;
947  high = extmembers + (numextmembers - 1);
948  while (low <= high)
949  {
950  ExtensionMemberId *middle;
951  int difference;
952 
953  middle = low + (high - low) / 2;
954  /* comparison must match ExtensionMemberIdCompare, below */
955  difference = oidcmp(middle->catId.oid, catalogId.oid);
956  if (difference == 0)
957  difference = oidcmp(middle->catId.tableoid, catalogId.tableoid);
958  if (difference == 0)
959  return middle->ext;
960  else if (difference < 0)
961  low = middle + 1;
962  else
963  high = middle - 1;
964  }
965  return NULL;
966 }
ExtensionInfo * ext
Definition: pg_dump.h:639
Oid tableoid
Definition: pg_backup.h:230
#define oidcmp(x, y)
Definition: pg_dump.h:20
Datum difference(PG_FUNCTION_ARGS)
static ExtensionMemberId * extmembers
Definition: common.c:64
static int numextmembers
Definition: common.c:65
CatalogId catId
Definition: pg_dump.h:638

◆ findTableByOid()

TableInfo* findTableByOid ( Oid  oid)

Definition at line 829 of file common.c.

References findObjectByOid(), and numTables.

Referenced by dumpSequence(), findParentsByOid(), getConstraints(), getOwnedSeqs(), getRules(), getTableDataFKConstraints(), processExtensionTables(), and selectDumpableType().

830 {
832 }
static int numTables
Definition: common.c:55
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static DumpableObject ** tblinfoindex
Definition: common.c:48

◆ findTypeByOid()

TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 840 of file common.c.

References findObjectByOid(), and numTypes.

Referenced by DOTypeNameCompare(), getCasts(), and getTransforms().

841 {
842  return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes);
843 }
static int numTypes
Definition: common.c:56
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static DumpableObject ** typinfoindex
Definition: common.c:49

◆ getAccessMethods()

AccessMethodInfo* getAccessMethods ( Archive fout,
int *  numAccessMethods 
)

Definition at line 5382 of file pg_dump.c.

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

Referenced by getSchemaData().

5383 {
5384  PGresult *res;
5385  int ntups;
5386  int i;
5387  PQExpBuffer query;
5388  AccessMethodInfo *aminfo;
5389  int i_tableoid;
5390  int i_oid;
5391  int i_amname;
5392  int i_amhandler;
5393  int i_amtype;
5394 
5395  /* Before 9.6, there are no user-defined access methods */
5396  if (fout->remoteVersion < 90600)
5397  {
5398  *numAccessMethods = 0;
5399  return NULL;
5400  }
5401 
5402  query = createPQExpBuffer();
5403 
5404  /* Select all access methods from pg_am table */
5405  appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, amtype, "
5406  "amhandler::pg_catalog.regproc AS amhandler "
5407  "FROM pg_am");
5408 
5409  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5410 
5411  ntups = PQntuples(res);
5412  *numAccessMethods = ntups;
5413 
5414  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
5415 
5416  i_tableoid = PQfnumber(res, "tableoid");
5417  i_oid = PQfnumber(res, "oid");
5418  i_amname = PQfnumber(res, "amname");
5419  i_amhandler = PQfnumber(res, "amhandler");
5420  i_amtype = PQfnumber(res, "amtype");
5421 
5422  for (i = 0; i < ntups; i++)
5423  {
5424  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
5425  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5426  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5427  AssignDumpId(&aminfo[i].dobj);
5428  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
5429  aminfo[i].dobj.namespace = NULL;
5430  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
5431  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
5432 
5433  /* Decide whether we want to dump it */
5434  selectDumpableAccessMethod(&(aminfo[i]), fout);
5435 
5436  /* Access methods do not currently have ACLs. */
5437  aminfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5438  }
5439 
5440  PQclear(res);
5441 
5442  destroyPQExpBuffer(query);
5443 
5444  return aminfo;
5445 }
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
DumpableObject dobj
Definition: pg_dump.h:225
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:1751
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * amhandler
Definition: pg_dump.h:227
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
int i
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187

◆ getAggregates()

AggInfo* getAggregates ( Archive fout,
int *  numAggregates 
)

Definition at line 5615 of file pg_dump.c.

References _aggInfo::aggfn, appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), _funcInfo::argtypes, AssignDumpId(), atooid, _dumpOptions::binary_upgrade, buildACLQueries(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_AGG, _funcInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), i, _funcInfo::initproacl, _funcInfo::initrproacl, InvalidOid, _funcInfo::lang, _dumpableObject::name, _funcInfo::nargs, _dumpableObject::objType, CatalogId::oid, parseOidArray(), pg_log_warning, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _funcInfo::proacl, _funcInfo::prorettype, Archive::remoteVersion, _funcInfo::rolname, _funcInfo::rproacl, selectDumpableObject(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

5616 {
5617  DumpOptions *dopt = fout->dopt;
5618  PGresult *res;
5619  int ntups;
5620  int i;
5621  PQExpBuffer query = createPQExpBuffer();
5622  AggInfo *agginfo;
5623  int i_tableoid;
5624  int i_oid;
5625  int i_aggname;
5626  int i_aggnamespace;
5627  int i_pronargs;
5628  int i_proargtypes;
5629  int i_rolname;
5630  int i_aggacl;
5631  int i_raggacl;
5632  int i_initaggacl;
5633  int i_initraggacl;
5634 
5635  /*
5636  * Find all interesting aggregates. See comment in getFuncs() for the
5637  * rationale behind the filtering logic.
5638  */
5639  if (fout->remoteVersion >= 90600)
5640  {
5641  PQExpBuffer acl_subquery = createPQExpBuffer();
5642  PQExpBuffer racl_subquery = createPQExpBuffer();
5643  PQExpBuffer initacl_subquery = createPQExpBuffer();
5644  PQExpBuffer initracl_subquery = createPQExpBuffer();
5645  const char *agg_check;
5646 
5647  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5648  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5649  dopt->binary_upgrade);
5650 
5651  agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
5652  : "p.proisagg");
5653 
5654  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5655  "p.proname AS aggname, "
5656  "p.pronamespace AS aggnamespace, "
5657  "p.pronargs, p.proargtypes, "
5658  "(%s p.proowner) AS rolname, "
5659  "%s AS aggacl, "
5660  "%s AS raggacl, "
5661  "%s AS initaggacl, "
5662  "%s AS initraggacl "
5663  "FROM pg_proc p "
5664  "LEFT JOIN pg_init_privs pip ON "
5665  "(p.oid = pip.objoid "
5666  "AND pip.classoid = 'pg_proc'::regclass "
5667  "AND pip.objsubid = 0) "
5668  "WHERE %s AND ("
5669  "p.pronamespace != "
5670  "(SELECT oid FROM pg_namespace "
5671  "WHERE nspname = 'pg_catalog') OR "
5672  "p.proacl IS DISTINCT FROM pip.initprivs",
5674  acl_subquery->data,
5675  racl_subquery->data,
5676  initacl_subquery->data,
5677  initracl_subquery->data,
5678  agg_check);
5679  if (dopt->binary_upgrade)
5680  appendPQExpBufferStr(query,
5681  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5682  "classid = 'pg_proc'::regclass AND "
5683  "objid = p.oid AND "
5684  "refclassid = 'pg_extension'::regclass AND "
5685  "deptype = 'e')");
5686  appendPQExpBufferChar(query, ')');
5687 
5688  destroyPQExpBuffer(acl_subquery);
5689  destroyPQExpBuffer(racl_subquery);
5690  destroyPQExpBuffer(initacl_subquery);
5691  destroyPQExpBuffer(initracl_subquery);
5692  }
5693  else if (fout->remoteVersion >= 80200)
5694  {
5695  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5696  "pronamespace AS aggnamespace, "
5697  "pronargs, proargtypes, "
5698  "(%s proowner) AS rolname, "
5699  "proacl AS aggacl, "
5700  "NULL AS raggacl, "
5701  "NULL AS initaggacl, NULL AS initraggacl "
5702  "FROM pg_proc p "
5703  "WHERE proisagg AND ("
5704  "pronamespace != "
5705  "(SELECT oid FROM pg_namespace "
5706  "WHERE nspname = 'pg_catalog')",
5708  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5709  appendPQExpBufferStr(query,
5710  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5711  "classid = 'pg_proc'::regclass AND "
5712  "objid = p.oid AND "
5713  "refclassid = 'pg_extension'::regclass AND "
5714  "deptype = 'e')");
5715  appendPQExpBufferChar(query, ')');
5716  }
5717  else
5718  {
5719  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5720  "pronamespace AS aggnamespace, "
5721  "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
5722  "proargtypes, "
5723  "(%s proowner) AS rolname, "
5724  "proacl AS aggacl, "
5725  "NULL AS raggacl, "
5726  "NULL AS initaggacl, NULL AS initraggacl "
5727  "FROM pg_proc "
5728  "WHERE proisagg "
5729  "AND pronamespace != "
5730  "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
5732  }
5733 
5734  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5735 
5736  ntups = PQntuples(res);
5737  *numAggs = ntups;
5738 
5739  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5740 
5741  i_tableoid = PQfnumber(res, "tableoid");
5742  i_oid = PQfnumber(res, "oid");
5743  i_aggname = PQfnumber(res, "aggname");
5744  i_aggnamespace = PQfnumber(res, "aggnamespace");
5745  i_pronargs = PQfnumber(res, "pronargs");
5746  i_proargtypes = PQfnumber(res, "proargtypes");
5747  i_rolname = PQfnumber(res, "rolname");
5748  i_aggacl = PQfnumber(res, "aggacl");
5749  i_raggacl = PQfnumber(res, "raggacl");
5750  i_initaggacl = PQfnumber(res, "initaggacl");
5751  i_initraggacl = PQfnumber(res, "initraggacl");
5752 
5753  for (i = 0; i < ntups; i++)
5754  {
5755  agginfo[i].aggfn.dobj.objType = DO_AGG;
5756  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5757  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5758  AssignDumpId(&agginfo[i].aggfn.dobj);
5759  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5760  agginfo[i].aggfn.dobj.namespace =
5761  findNamespace(fout,
5762  atooid(PQgetvalue(res, i, i_aggnamespace)));
5763  agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5764  if (strlen(agginfo[i].aggfn.rolname) == 0)
5765  pg_log_warning("owner of aggregate function \"%s\" appears to be invalid",
5766  agginfo[i].aggfn.dobj.name);
5767  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5768  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5769  agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5770  agginfo[i].aggfn.rproacl = pg_strdup(PQgetvalue(res, i, i_raggacl));
5771  agginfo[i].aggfn.initproacl = pg_strdup(PQgetvalue(res, i, i_initaggacl));
5772  agginfo[i].aggfn.initrproacl = pg_strdup(PQgetvalue(res, i, i_initraggacl));
5773  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5774  if (agginfo[i].aggfn.nargs == 0)
5775  agginfo[i].aggfn.argtypes = NULL;
5776  else
5777  {
5778  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5779  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5780  agginfo[i].aggfn.argtypes,
5781  agginfo[i].aggfn.nargs);
5782  }
5783 
5784  /* Decide whether we want to dump it */
5785  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5786 
5787  /* Do not try to dump ACL if no ACL exists. */
5788  if (PQgetisnull(res, i, i_aggacl) && PQgetisnull(res, i, i_raggacl) &&
5789  PQgetisnull(res, i, i_initaggacl) &&
5790  PQgetisnull(res, i, i_initraggacl))
5791  agginfo[i].aggfn.dobj.dump &= ~DUMP_COMPONENT_ACL;
5792  }
5793 
5794  PQclear(res);
5795 
5796  destroyPQExpBuffer(query);
5797 
5798  return agginfo;
5799 }
Oid * argtypes
Definition: pg_dump.h:200
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1817
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int nargs
Definition: pg_dump.h:199
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4794
char * initrproacl
Definition: pg_dump.h:205
Oid lang
Definition: pg_dump.h:198
DumpableObject dobj
Definition: pg_dump.h:196
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
FuncInfo aggfn
Definition: pg_dump.h:211
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:135
Definition: pg_dump.h:45
DumpOptions * dopt
Definition: pg_backup.h:182
void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, const char *acl_column, const char *acl_owner, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:742
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1049
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:694
Oid prorettype
Definition: pg_dump.h:201
char * initproacl
Definition: pg_dump.h:204
char * rolname
Definition: pg_dump.h:197
char * proacl
Definition: pg_dump.h:202
char * rproacl
Definition: pg_dump.h:203
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
int i
#define pg_log_warning(...)
Definition: pgfnames.c:24
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3188
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187

◆ getCasts()

CastInfo* getCasts ( Archive fout,
int *  numCasts 
)

Definition at line 8221 of file pg_dump.c.

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, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findTypeByOid(), i, initPQExpBuffer(), _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, selectDumpableCast(), and CatalogId::tableoid.

Referenced by getSchemaData().

8222 {
8223  PGresult *res;
8224  int ntups;
8225  int i;
8226  PQExpBuffer query = createPQExpBuffer();
8227  CastInfo *castinfo;
8228  int i_tableoid;
8229  int i_oid;
8230  int i_castsource;
8231  int i_casttarget;
8232  int i_castfunc;
8233  int i_castcontext;
8234  int i_castmethod;
8235 
8236  if (fout->remoteVersion >= 80400)
8237  {
8238  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8239  "castsource, casttarget, castfunc, castcontext, "
8240  "castmethod "
8241  "FROM pg_cast ORDER BY 3,4");
8242  }
8243  else
8244  {
8245  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8246  "castsource, casttarget, castfunc, castcontext, "
8247  "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
8248  "FROM pg_cast ORDER BY 3,4");
8249  }
8250 
8251  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8252 
8253  ntups = PQntuples(res);
8254 
8255  *numCasts = ntups;
8256 
8257  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
8258 
8259  i_tableoid = PQfnumber(res, "tableoid");
8260  i_oid = PQfnumber(res, "oid");
8261  i_castsource = PQfnumber(res, "castsource");
8262  i_casttarget = PQfnumber(res, "casttarget");
8263  i_castfunc = PQfnumber(res, "castfunc");
8264  i_castcontext = PQfnumber(res, "castcontext");
8265  i_castmethod = PQfnumber(res, "castmethod");
8266 
8267  for (i = 0; i < ntups; i++)
8268  {
8269  PQExpBufferData namebuf;
8270  TypeInfo *sTypeInfo;
8271  TypeInfo *tTypeInfo;
8272 
8273  castinfo[i].dobj.objType = DO_CAST;
8274  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8275  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8276  AssignDumpId(&castinfo[i].dobj);
8277  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
8278  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
8279  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
8280  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
8281  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
8282 
8283  /*
8284  * Try to name cast as concatenation of typnames. This is only used
8285  * for purposes of sorting. If we fail to find either type, the name
8286  * will be an empty string.
8287  */
8288  initPQExpBuffer(&namebuf);
8289  sTypeInfo = findTypeByOid(castinfo[i].castsource);
8290  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
8291  if (sTypeInfo && tTypeInfo)
8292  appendPQExpBuffer(&namebuf, "%s %s",
8293  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
8294  castinfo[i].dobj.name = namebuf.data;
8295 
8296  /* Decide whether we want to dump it */
8297  selectDumpableCast(&(castinfo[i]), fout);
8298 
8299  /* Casts do not currently have ACLs. */
8300  castinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8301  }
8302 
8303  PQclear(res);
8304 
8305  destroyPQExpBuffer(query);
8306 
8307  return castinfo;
8308 }
char * name
Definition: pg_dump.h:130
Oid castsource
Definition: pg_dump.h:472
DumpComponents dump
Definition: pg_dump.h:131
Oid tableoid
Definition: pg_backup.h:230
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:1693
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
Oid castfunc
Definition: pg_dump.h:474
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:471
Oid casttarget
Definition: pg_dump.h:473
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
#define atooid(x)
Definition: postgres_ext.h:42
DumpableObject dobj
Definition: pg_dump.h:163
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
int i
char castmethod
Definition: pg_dump.h:476
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:840
DumpableObjectType objType
Definition: pg_dump.h:127
char castcontext
Definition: pg_dump.h:475
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187

◆ getCollations()

CollInfo* getCollations ( Archive fout,
int *  numCollations 
)

Definition at line 5229 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_COLLATION, _collInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _collInfo::rolname, selectDumpableObject(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

5230 {
5231  PGresult *res;
5232  int ntups;
5233  int i;
5234  PQExpBuffer query;
5235  CollInfo *collinfo;
5236  int i_tableoid;
5237  int i_oid;
5238  int i_collname;
5239  int i_collnamespace;
5240  int i_rolname;
5241 
5242  /* Collations didn't exist pre-9.1 */
5243  if (fout->remoteVersion < 90100)
5244  {
5245  *numCollations = 0;
5246  return NULL;
5247  }
5248 
5249  query = createPQExpBuffer();
5250 
5251  /*
5252  * find all collations, including builtin collations; we filter out
5253  * system-defined collations at dump-out time.
5254  */
5255 
5256  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
5257  "collnamespace, "
5258  "(%s collowner) AS rolname "
5259  "FROM pg_collation",
5261 
5262  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5263 
5264  ntups = PQntuples(res);
5265  *numCollations = ntups;
5266 
5267  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
5268 
5269  i_tableoid = PQfnumber(res, "tableoid");
5270  i_oid = PQfnumber(res, "oid");
5271  i_collname = PQfnumber(res, "collname");
5272  i_collnamespace = PQfnumber(res, "collnamespace");
5273  i_rolname = PQfnumber(res, "rolname");
5274 
5275  for (i = 0; i < ntups; i++)
5276  {
5277  collinfo[i].dobj.objType = DO_COLLATION;
5278  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5279  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5280  AssignDumpId(&collinfo[i].dobj);
5281  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
5282  collinfo[i].dobj.namespace =
5283  findNamespace(fout,
5284  atooid(PQgetvalue(res, i, i_collnamespace)));
5285  collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5286 
5287  /* Decide whether we want to dump it */
5288  selectDumpableObject(&(collinfo[i].dobj), fout);
5289 
5290  /* Collations do not currently have ACLs. */
5291  collinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5292  }
5293 
5294  PQclear(res);
5295 
5296  destroyPQExpBuffer(query);
5297 
5298  return collinfo;
5299 }
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1817
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4794
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
DumpableObject dobj
Definition: pg_dump.h:244
char * rolname
Definition: pg_dump.h:245
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void PQclear(PGresult *res)
Definition: fe-exec.c:694
static int numCollations
Definition: common.c:59
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
int i
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187

◆ getConstraints()

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

Definition at line 7422 of file pg_dump.c.

References addObjectDependency(), appendPQExpBuffer(), 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, _dumpableObject::dump, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), findTableByOid(), _tableInfo::hastriggers, SimplePtrList::head, i, _tableInfo::indexes, InvalidOid, _dumpableObject::name, SimplePtrListCell::next, _tableInfo::numIndexes, numTables, _dumpableObject::objType, CatalogId::oid, _indxInfo::partattaches, pg_log_info, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), SimplePtrListCell::ptr, _tableInfo::relkind, Archive::remoteVersion, resetPQExpBuffer(), _constraintInfo::separate, and CatalogId::tableoid.

Referenced by getSchemaData().

7423 {
7424  int i,
7425  j;
7426  ConstraintInfo *constrinfo;
7427  PQExpBuffer query;
7428  PGresult *res;
7429  int i_contableoid,
7430  i_conoid,
7431  i_conname,
7432  i_confrelid,
7433  i_conindid,
7434  i_condef;
7435  int ntups;
7436 
7437  query = createPQExpBuffer();
7438 
7439  for (i = 0; i < numTables; i++)
7440  {
7441  TableInfo *tbinfo = &tblinfo[i];
7442 
7443  /*
7444  * For partitioned tables, foreign keys have no triggers so they must
7445  * be included anyway in case some foreign keys are defined.
7446  */
7447  if ((!tbinfo->hastriggers &&
7448  tbinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7449  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
7450  continue;
7451 
7452  pg_log_info("reading foreign key constraints for table \"%s.%s\"",
7453  tbinfo->dobj.namespace->dobj.name,
7454  tbinfo->dobj.name);
7455 
7456  resetPQExpBuffer(query);
7457  if (fout->remoteVersion >= 110000)
7458  appendPQExpBuffer(query,
7459  "SELECT tableoid, oid, conname, confrelid, conindid, "
7460  "pg_catalog.pg_get_constraintdef(oid) AS condef "
7461  "FROM pg_catalog.pg_constraint "
7462  "WHERE conrelid = '%u'::pg_catalog.oid "
7463  "AND conparentid = 0 "
7464  "AND contype = 'f'",
7465  tbinfo->dobj.catId.oid);
7466  else
7467  appendPQExpBuffer(query,
7468  "SELECT tableoid, oid, conname, confrelid, 0 as conindid, "
7469  "pg_catalog.pg_get_constraintdef(oid) AS condef "
7470  "FROM pg_catalog.pg_constraint "
7471  "WHERE conrelid = '%u'::pg_catalog.oid "
7472  "AND contype = 'f'",
7473  tbinfo->dobj.catId.oid);
7474  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7475 
7476  ntups = PQntuples(res);
7477 
7478  i_contableoid = PQfnumber(res, "tableoid");
7479  i_conoid = PQfnumber(res, "oid");
7480  i_conname = PQfnumber(res, "conname");
7481  i_confrelid = PQfnumber(res, "confrelid");
7482  i_conindid = PQfnumber(res, "conindid");
7483  i_condef = PQfnumber(res, "condef");
7484 
7485  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7486 
7487  for (j = 0; j < ntups; j++)
7488  {
7489  TableInfo *reftable;
7490 
7491  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
7492  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7493  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7494  AssignDumpId(&constrinfo[j].dobj);
7495  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7496  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7497  constrinfo[j].contable = tbinfo;
7498  constrinfo[j].condomain = NULL;
7499  constrinfo[j].contype = 'f';
7500  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7501  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
7502  constrinfo[j].conindex = 0;
7503  constrinfo[j].condeferrable = false;
7504  constrinfo[j].condeferred = false;
7505  constrinfo[j].conislocal = true;
7506  constrinfo[j].separate = true;
7507 
7508  /*
7509  * Restoring an FK that points to a partitioned table requires
7510  * that all partition indexes have been attached beforehand.
7511  * Ensure that happens by making the constraint depend on each
7512  * index partition attach object.
7513  */
7514  reftable = findTableByOid(constrinfo[j].confrelid);
7515  if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
7516  {
7517  IndxInfo *refidx;
7518  Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
7519 
7520  if (indexOid != InvalidOid)
7521  {
7522  for (int k = 0; k < reftable->numIndexes; k++)
7523  {
7524  SimplePtrListCell *cell;
7525 
7526  /* not our index? */
7527  if (reftable->indexes[k].dobj.catId.oid != indexOid)
7528  continue;
7529 
7530  refidx = &reftable->indexes[k];
7531  for (cell = refidx->partattaches.head; cell;
7532  cell = cell->next)
7533  addObjectDependency(&constrinfo[j].dobj,
7534  ((DumpableObject *)
7535  cell->ptr)->dumpId);
7536  break;
7537  }
7538  }
7539  }
7540  }
7541 
7542  PQclear(res);
7543  }
7544 
7545  destroyPQExpBuffer(query);
7546 }
char * name
Definition: pg_dump.h:130
TableInfo * findTableByOid(Oid oid)
Definition: common.c:829
char relkind
Definition: pg_dump.h:265
DumpComponents dump
Definition: pg_dump.h:131
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
bool hastriggers
Definition: pg_dump.h:275
static int numTables
Definition: common.c:55
unsigned int Oid
Definition: postgres_ext.h:31
DumpId conindex
Definition: pg_dump.h:448
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
DumpableObject dobj
Definition: pg_dump.h:259
char * condef
Definition: pg_dump.h:446
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:442
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
bool condeferrable
Definition: pg_dump.h:449
TypeInfo * condomain
Definition: pg_dump.h:444
bool conislocal
Definition: pg_dump.h:451
SimplePtrList partattaches
Definition: pg_dump.h:372
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int numIndexes
Definition: pg_dump.h:333
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
TableInfo * contable
Definition: pg_dump.h:443
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:89
struct SimplePtrListCell * next
Definition: simple_list.h:48
bool condeferred
Definition: pg_dump.h:450
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:782
struct _indxInfo * indexes
Definition: pg_dump.h:334
CatalogId catId
Definition: pg_dump.h:128
SimplePtrListCell * head
Definition: simple_list.h:54
DumpableObject dobj
Definition: pg_dump.h:358
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148
DumpableObjectType objType
Definition: pg_dump.h:127
#define pg_log_info(...)
Definition: logging.h:87
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187

◆ getConversions()

ConvInfo* getConversions ( Archive fout,
int *  numConversions 
)

Definition at line 5309 of file pg_dump.c.

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

Referenced by getSchemaData().

5310 {
5311  PGresult *res;
5312  int ntups;
5313  int i;
5314  PQExpBuffer query;
5315  ConvInfo *convinfo;
5316  int i_tableoid;
5317  int i_oid;
5318  int i_conname;
5319  int i_connamespace;
5320  int i_rolname;
5321 
5322  query = createPQExpBuffer();
5323 
5324  /*
5325  * find all conversions, including builtin conversions; we filter out
5326  * system-defined conversions at dump-out time.
5327  */
5328 
5329  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
5330  "connamespace, "
5331  "(%s conowner) AS rolname "
5332  "FROM pg_conversion",
5334 
5335  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5336 
5337  ntups = PQntuples(res);
5338  *numConversions = ntups;
5339 
5340  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
5341 
5342  i_tableoid = PQfnumber(res, "tableoid");
5343  i_oid = PQfnumber(res, "oid");
5344  i_conname = PQfnumber(res, "conname");
5345  i_connamespace = PQfnumber(res, "connamespace");
5346  i_rolname = PQfnumber(res, "rolname");
5347 
5348  for (i = 0; i < ntups; i++)
5349  {
5350  convinfo[i].dobj.objType = DO_CONVERSION;
5351  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5352  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5353  AssignDumpId(&convinfo[i].dobj);
5354  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
5355  convinfo[i].dobj.namespace =
5356  findNamespace(fout,
5357  atooid(PQgetvalue(res, i, i_connamespace)));
5358  convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5359 
5360  /* Decide whether we want to dump it */
5361  selectDumpableObject(&(convinfo[i].dobj), fout);
5362 
5363  /* Conversions do not currently have ACLs. */
5364  convinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5365  }
5366 
5367  PQclear(res);
5368 
5369  destroyPQExpBuffer(query);
5370 
5371  return convinfo;
5372 }
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1817
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4794
char * rolname
Definition: pg_dump.h:251
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void PQclear(PGresult *res)
Definition: fe-exec.c:694
DumpableObject dobj
Definition: pg_dump.h:250
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
int i
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401

◆ getDefaultACLs()

DefaultACLInfo* getDefaultACLs ( Archive fout,
int *  numDefaultACLs 
)

Definition at line 9533 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, buildACLQueries(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, _defaultACLInfo::defaclacl, _defaultACLInfo::defaclobjtype, _defaultACLInfo::defaclrole, destroyPQExpBuffer(), DO_DEFAULT_ACL, _defaultACLInfo::dobj, Archive::dopt, ExecuteSqlQuery(), findNamespace(), i, _defaultACLInfo::initdefaclacl, _defaultACLInfo::initrdefaclacl, InvalidOid, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _defaultACLInfo::rdefaclacl, Archive::remoteVersion, selectDumpableDefaultACL(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

9534 {
9535  DumpOptions *dopt = fout->dopt;
9536  DefaultACLInfo *daclinfo;
9537  PQExpBuffer query;
9538  PGresult *res;
9539  int i_oid;
9540  int i_tableoid;
9541  int i_defaclrole;
9542  int i_defaclnamespace;
9543  int i_defaclobjtype;
9544  int i_defaclacl;
9545  int i_rdefaclacl;
9546  int i_initdefaclacl;
9547  int i_initrdefaclacl;
9548  int i,
9549  ntups;
9550 
9551  if (fout->remoteVersion < 90000)
9552  {
9553  *numDefaultACLs = 0;
9554  return NULL;
9555  }
9556 
9557  query = createPQExpBuffer();
9558 
9559  if (fout->remoteVersion >= 90600)
9560  {
9561  PQExpBuffer acl_subquery = createPQExpBuffer();
9562  PQExpBuffer racl_subquery = createPQExpBuffer();
9563  PQExpBuffer initacl_subquery = createPQExpBuffer();
9564  PQExpBuffer initracl_subquery = createPQExpBuffer();
9565 
9566  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9567  initracl_subquery, "defaclacl", "defaclrole",
9568  "CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
9569  dopt->binary_upgrade);
9570 
9571  appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
9572  "(%s d.defaclrole) AS defaclrole, "
9573  "d.defaclnamespace, "
9574  "d.defaclobjtype, "
9575  "%s AS defaclacl, "
9576  "%s AS rdefaclacl, "
9577  "%s AS initdefaclacl, "
9578  "%s AS initrdefaclacl "
9579  "FROM pg_default_acl d "
9580  "LEFT JOIN pg_init_privs pip ON "
9581  "(d.oid = pip.objoid "
9582  "AND pip.classoid = 'pg_default_acl'::regclass "
9583  "AND pip.objsubid = 0) ",
9585  acl_subquery->data,
9586  racl_subquery->data,
9587  initacl_subquery->data,
9588  initracl_subquery->data);
9589 
9590  destroyPQExpBuffer(acl_subquery);
9591  destroyPQExpBuffer(racl_subquery);
9592  destroyPQExpBuffer(initacl_subquery);
9593  destroyPQExpBuffer(initracl_subquery);
9594  }
9595  else
9596  {
9597  appendPQExpBuffer(query, "SELECT oid, tableoid, "
9598  "(%s defaclrole) AS defaclrole, "
9599  "defaclnamespace, "
9600  "defaclobjtype, "
9601  "defaclacl, "
9602  "NULL AS rdefaclacl, "
9603  "NULL AS initdefaclacl, "
9604  "NULL AS initrdefaclacl "
9605  "FROM pg_default_acl",
9607  }
9608 
9609  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9610 
9611  ntups = PQntuples(res);
9612  *numDefaultACLs = ntups;
9613 
9614  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9615 
9616  i_oid = PQfnumber(res, "oid");
9617  i_tableoid = PQfnumber(res, "tableoid");
9618  i_defaclrole = PQfnumber(res, "defaclrole");
9619  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9620  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9621  i_defaclacl = PQfnumber(res, "defaclacl");
9622  i_rdefaclacl = PQfnumber(res, "rdefaclacl");
9623  i_initdefaclacl = PQfnumber(res, "initdefaclacl");
9624  i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
9625 
9626  for (i = 0; i < ntups; i++)
9627  {
9628  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9629 
9630  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9631  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9632  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9633  AssignDumpId(&daclinfo[i].dobj);
9634  /* cheesy ... is it worth coming up with a better object name? */
9635  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9636 
9637  if (nspid != InvalidOid)
9638  daclinfo[i].dobj.namespace = findNamespace(fout, nspid);
9639  else
9640  daclinfo[i].dobj.namespace = NULL;
9641 
9642  daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
9643  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9644  daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9645  daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
9646  daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
9647  daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
9648 
9649  /* Decide whether we want to dump it */
9650  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9651  }
9652 
9653  PQclear(res);
9654 
9655  destroyPQExpBuffer(query);
9656 
9657  return daclinfo;
9658 }
char * name
Definition: pg_dump.h:130
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4794
char * rdefaclacl
Definition: pg_dump.h:560
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition: pg_dump.c:1671
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:182
void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, const char *acl_column, const char *acl_owner, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:742
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
DumpableObject dobj
Definition: pg_dump.h:556
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
char * defaclacl
Definition: pg_dump.h:559
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * initdefaclacl
Definition: pg_dump.h:561
CatalogId catId
Definition: pg_dump.h:128
char * initrdefaclacl
Definition: pg_dump.h:562
int i
char defaclobjtype
Definition: pg_dump.h:558
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187
char * defaclrole
Definition: pg_dump.h:557

◆ getDumpableObjects()

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

Definition at line 760 of file common.c.

References allocedDumpIds, i, and pg_malloc().

Referenced by findObjectByCatalogId(), getTableDataFKConstraints(), and main().

761 {
762  int i,
763  j;
764 
765  *objs = (DumpableObject **)
767  j = 0;
768  for (i = 1; i < allocedDumpIds; i++)
769  {
770  if (dumpIdMap[i])
771  (*objs)[j++] = dumpIdMap[i];
772  }
773  *numObjs = j;
774 }
static int allocedDumpIds
Definition: common.c:30
static DumpableObject ** dumpIdMap
Definition: common.c:29
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int i

◆ getEventTriggers()

EventTriggerInfo* getEventTriggers ( Archive fout,
int *  numEventTriggers 
)

Definition at line 7952 of file pg_dump.c.

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

Referenced by getSchemaData().

7953 {
7954  int i;
7955  PQExpBuffer query;
7956  PGresult *res;
7957  EventTriggerInfo *evtinfo;
7958  int i_tableoid,
7959  i_oid,
7960  i_evtname,
7961  i_evtevent,
7962  i_evtowner,
7963  i_evttags,
7964  i_evtfname,
7965  i_evtenabled;
7966  int ntups;
7967 
7968  /* Before 9.3, there are no event triggers */
7969  if (fout->remoteVersion < 90300)
7970  {
7971  *numEventTriggers = 0;
7972  return NULL;
7973  }
7974 
7975  query = createPQExpBuffer();
7976 
7977  appendPQExpBuffer(query,
7978  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
7979  "evtevent, (%s evtowner) AS evtowner, "
7980  "array_to_string(array("
7981  "select quote_literal(x) "
7982  " from unnest(evttags) as t(x)), ', ') as evttags, "
7983  "e.evtfoid::regproc as evtfname "
7984  "FROM pg_event_trigger e "
7985  "ORDER BY e.oid",
7987 
7988  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7989 
7990  ntups = PQntuples(res);
7991 
7992  *numEventTriggers = ntups;
7993 
7994  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
7995 
7996  i_tableoid = PQfnumber(res, "tableoid");
7997  i_oid = PQfnumber(res, "oid");
7998  i_evtname = PQfnumber(res, "evtname");
7999  i_evtevent = PQfnumber(res, "evtevent");
8000  i_evtowner = PQfnumber(res, "evtowner");
8001  i_evttags = PQfnumber(res, "evttags");
8002  i_evtfname = PQfnumber(res, "evtfname");
8003  i_evtenabled = PQfnumber(res, "evtenabled");
8004 
8005  for (i = 0; i < ntups; i++)
8006  {
8007  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
8008  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8009  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8010  AssignDumpId(&evtinfo[i].dobj);
8011  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
8012  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
8013  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
8014  evtinfo[i].evtowner = pg_strdup(PQgetvalue(res, i, i_evtowner));
8015  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
8016  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
8017  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
8018 
8019  /* Decide whether we want to dump it */
8020  selectDumpableObject(&(evtinfo[i].dobj), fout);
8021 
8022  /* Event Triggers do not currently have ACLs. */
8023  evtinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8024  }
8025 
8026  PQclear(res);
8027 
8028  destroyPQExpBuffer(query);
8029 
8030  return evtinfo;
8031 }
char * name
Definition: pg_dump.h:130
char * evtevent
Definition: pg_dump.h:425
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1817
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * evtowner
Definition: pg_dump.h:426
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
char * evtfname
Definition: pg_dump.h:428
char * evttags
Definition: pg_dump.h:427
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
char * evtname
Definition: pg_dump.h:424
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void PQclear(PGresult *res)
Definition: fe-exec.c:694
DumpableObject dobj
Definition: pg_dump.h:423
char evtenabled
Definition: pg_dump.h:429
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
int i
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187

◆ getExtendedStatistics()

void getExtendedStatistics ( Archive fout)

Definition at line 7344 of file pg_dump.c.

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

Referenced by getSchemaData().

7345 {
7346  PQExpBuffer query;
7347  PGresult *res;
7348  StatsExtInfo *statsextinfo;
7349  int ntups;
7350  int i_tableoid;
7351  int i_oid;
7352  int i_stxname;
7353  int i_stxnamespace;
7354  int i_rolname;
7355  int i_stattarget;
7356  int i;
7357 
7358  /* Extended statistics were new in v10 */
7359  if (fout->remoteVersion < 100000)
7360  return;
7361 
7362  query = createPQExpBuffer();
7363 
7364  if (fout->remoteVersion < 130000)
7365  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7366  "stxnamespace, (%s stxowner) AS rolname, (-1) AS stxstattarget "
7367  "FROM pg_catalog.pg_statistic_ext",
7369  else
7370  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7371  "stxnamespace, (%s stxowner) AS rolname, stxstattarget "
7372  "FROM pg_catalog.pg_statistic_ext",
7374 
7375  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7376 
7377  ntups = PQntuples(res);
7378 
7379  i_tableoid = PQfnumber(res, "tableoid");
7380  i_oid = PQfnumber(res, "oid");
7381  i_stxname = PQfnumber(res, "stxname");
7382  i_stxnamespace = PQfnumber(res, "stxnamespace");
7383  i_rolname = PQfnumber(res, "rolname");
7384  i_stattarget = PQfnumber(res, "stxstattarget");
7385 
7386  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
7387 
7388  for (i = 0; i < ntups; i++)
7389  {
7390  statsextinfo[i].dobj.objType = DO_STATSEXT;
7391  statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7392  statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7393  AssignDumpId(&statsextinfo[i].dobj);
7394  statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
7395  statsextinfo[i].dobj.namespace =
7396  findNamespace(fout,
7397  atooid(PQgetvalue(res, i, i_stxnamespace)));
7398  statsextinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
7399  statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
7400 
7401  /* Decide whether we want to dump it */
7402  selectDumpableObject(&(statsextinfo[i].dobj), fout);
7403 
7404  /* Stats objects do not currently have ACLs. */
7405  statsextinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7406  }
7407 
7408  PQclear(res);
7409  destroyPQExpBuffer(query);
7410 }
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1817
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4794
DumpableObject dobj
Definition: pg_dump.h:387
int stattarget
Definition: pg_dump.h:389
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
char * rolname
Definition: pg_dump.h:388
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
int i
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187

◆ getExtensionMembership()

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

Definition at line 17895 of file pg_dump.c.

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

Referenced by getSchemaData().

17897 {
17898  PQExpBuffer query;
17899  PGresult *res;
17900  int ntups,
17901  nextmembers,
17902  i;
17903  int i_classid,
17904  i_objid,
17905  i_refobjid;
17907  ExtensionInfo *ext;
17908 
17909  /* Nothing to do if no extensions */
17910  if (numExtensions == 0)
17911  return;
17912 
17913  query = createPQExpBuffer();
17914 
17915  /* refclassid constraint is redundant but may speed the search */
17916  appendPQExpBufferStr(query, "SELECT "
17917  "classid, objid, refobjid "
17918  "FROM pg_depend "
17919  "WHERE refclassid = 'pg_extension'::regclass "
17920  "AND deptype = 'e' "
17921  "ORDER BY 3");
17922 
17923  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
17924 
17925  ntups = PQntuples(res);
17926 
17927  i_classid = PQfnumber(res, "classid");
17928  i_objid = PQfnumber(res, "objid");
17929  i_refobjid = PQfnumber(res, "refobjid");
17930 
17931  extmembers = (ExtensionMemberId *) pg_malloc(ntups * sizeof(ExtensionMemberId));
17932  nextmembers = 0;
17933 
17934  /*
17935  * Accumulate data into extmembers[].
17936  *
17937  * Since we ordered the SELECT by referenced ID, we can expect that
17938  * multiple entries for the same extension will appear together; this
17939  * saves on searches.
17940  */
17941  ext = NULL;
17942 
17943  for (i = 0; i < ntups; i++)
17944  {
17945  CatalogId objId;
17946  Oid extId;
17947 
17948  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
17949  objId.oid = atooid(PQgetvalue(res, i, i_objid));
17950  extId = atooid(PQgetvalue(res, i, i_refobjid));
17951 
17952  if (ext == NULL ||
17953  ext->dobj.catId.oid != extId)
17954  ext = findExtensionByOid(extId);
17955 
17956  if (ext == NULL)
17957  {
17958  /* shouldn't happen */
17959  pg_log_warning("could not find referenced extension %u", extId);
17960  continue;
17961  }
17962 
17963  extmembers[nextmembers].catId = objId;
17964  extmembers[nextmembers].ext = ext;
17965  nextmembers++;
17966  }
17967 
17968  PQclear(res);
17969 
17970  /* Remember the data for use later */
17971  setExtensionMembership(extmembers, nextmembers);
17972 
17973  destroyPQExpBuffer(query);
17974 }
ExtensionInfo * ext
Definition: pg_dump.h:639
DumpableObject dobj
Definition: pg_dump.h:153
Oid tableoid
Definition: pg_backup.h:230
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void setExtensionMembership(ExtensionMemberId *extmems, int nextmems)
Definition: common.c:918
static int numExtensions
Definition: common.c:61
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
static ExtensionMemberId * extmembers
Definition: common.c:64
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:895
void PQclear(PGresult *res)
Definition: fe-exec.c:694
CatalogId catId
Definition: pg_dump.h:128
CatalogId catId
Definition: pg_dump.h:638
int i
#define pg_log_warning(...)
Definition: pgfnames.c:24
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401

◆ getExtensions()

ExtensionInfo* getExtensions ( Archive fout,
int *  numExtensions 
)

Definition at line 4812 of file pg_dump.c.

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, Archive::remoteVersion, selectDumpableExtension(), and CatalogId::tableoid.

Referenced by getSchemaData().

4813 {
4814  DumpOptions *dopt = fout->dopt;
4815  PGresult *res;
4816  int ntups;
4817  int i;
4818  PQExpBuffer query;
4819  ExtensionInfo *extinfo;
4820  int i_tableoid;
4821  int i_oid;
4822  int i_extname;
4823  int i_nspname;
4824  int i_extrelocatable;
4825  int i_extversion;
4826  int i_extconfig;
4827  int i_extcondition;
4828 
4829  /*
4830  * Before 9.1, there are no extensions.
4831  */
4832  if (fout->remoteVersion < 90100)
4833  {
4834  *numExtensions = 0;
4835  return NULL;
4836  }
4837 
4838  query = createPQExpBuffer();
4839 
4840  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
4841  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
4842  "FROM pg_extension x "
4843  "JOIN pg_namespace n ON n.oid = x.extnamespace");
4844 
4845  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4846 
4847  ntups = PQntuples(res);
4848 
4849  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
4850 
4851  i_tableoid = PQfnumber(res, "tableoid");
4852  i_oid = PQfnumber(res, "oid");
4853  i_extname = PQfnumber(res, "extname");
4854  i_nspname = PQfnumber(res, "nspname");
4855  i_extrelocatable = PQfnumber(res, "extrelocatable");
4856  i_extversion = PQfnumber(res, "extversion");
4857  i_extconfig = PQfnumber(res, "extconfig");
4858  i_extcondition = PQfnumber(res, "extcondition");
4859 
4860  for (i = 0; i < ntups; i++)
4861  {
4862  extinfo[i].dobj.objType = DO_EXTENSION;
4863  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4864  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4865  AssignDumpId(&extinfo[i].dobj);
4866  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
4867  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
4868  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
4869  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
4870  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
4871  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
4872 
4873  /* Decide whether we want to dump it */
4874  selectDumpableExtension(&(extinfo[i]), dopt);
4875  }
4876 
4877  PQclear(res);
4878  destroyPQExpBuffer(query);
4879 
4880  *numExtensions = ntups;
4881 
4882  return extinfo;
4883 }
char * name
Definition: pg_dump.h:130
DumpableObject dobj
Definition: pg_dump.h:153
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpOptions * dopt
Definition: pg_backup.h:182
char * extconfig
Definition: pg_dump.h:157
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static int numExtensions
Definition: common.c:61
#define atooid(x)
Definition: postgres_ext.h:42
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:1778
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * extcondition
Definition: pg_dump.h:158
CatalogId catId
Definition: pg_dump.h:128
int i
DumpableObjectType objType
Definition: pg_dump.h:127
bool relocatable
Definition: pg_dump.h:154
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187
char * extversion
Definition: pg_dump.h:156

◆ getForeignDataWrappers()

FdwInfo* getForeignDataWrappers ( Archive fout,
int *  numForeignDataWrappers 
)

Definition at line 9217 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, buildACLQueries(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FDW, _fdwInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), _fdwInfo::fdwacl, _fdwInfo::fdwhandler, _fdwInfo::fdwoptions, _fdwInfo::fdwvalidator, i, _fdwInfo::initfdwacl, _fdwInfo::initrfdwacl, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _fdwInfo::rfdwacl, _fdwInfo::rolname, selectDumpableObject(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

9218 {
9219  DumpOptions *dopt = fout->dopt;
9220  PGresult *res;
9221  int ntups;
9222  int i;
9223  PQExpBuffer query;
9224  FdwInfo *fdwinfo;
9225  int i_tableoid;
9226  int i_oid;
9227  int i_fdwname;
9228  int i_rolname;
9229  int i_fdwhandler;
9230  int i_fdwvalidator;
9231  int i_fdwacl;
9232  int i_rfdwacl;
9233  int i_initfdwacl;
9234  int i_initrfdwacl;
9235  int i_fdwoptions;
9236 
9237  /* Before 8.4, there are no foreign-data wrappers */
9238  if (fout->remoteVersion < 80400)
9239  {
9240  *numForeignDataWrappers = 0;
9241  return NULL;
9242  }
9243 
9244  query = createPQExpBuffer();
9245 
9246  if (fout->remoteVersion >= 90600)
9247  {
9248  PQExpBuffer acl_subquery = createPQExpBuffer();
9249  PQExpBuffer racl_subquery = createPQExpBuffer();
9250  PQExpBuffer initacl_subquery = createPQExpBuffer();
9251  PQExpBuffer initracl_subquery = createPQExpBuffer();
9252 
9253  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9254  initracl_subquery, "f.fdwacl", "f.fdwowner", "'F'",
9255  dopt->binary_upgrade);
9256 
9257  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.fdwname, "
9258  "(%s f.fdwowner) AS rolname, "
9259  "f.fdwhandler::pg_catalog.regproc, "
9260  "f.fdwvalidator::pg_catalog.regproc, "
9261  "%s AS fdwacl, "
9262  "%s AS rfdwacl, "
9263  "%s AS initfdwacl, "
9264  "%s AS initrfdwacl, "
9265  "array_to_string(ARRAY("
9266  "SELECT quote_ident(option_name) || ' ' || "
9267  "quote_literal(option_value) "
9268  "FROM pg_options_to_table(f.fdwoptions) "
9269  "ORDER BY option_name"
9270  "), E',\n ') AS fdwoptions "
9271  "FROM pg_foreign_data_wrapper f "
9272  "LEFT JOIN pg_init_privs pip ON "
9273  "(f.oid = pip.objoid "
9274  "AND pip.classoid = 'pg_foreign_data_wrapper'::regclass "
9275  "AND pip.objsubid = 0) ",
9277  acl_subquery->data,
9278  racl_subquery->data,
9279  initacl_subquery->data,
9280  initracl_subquery->data);
9281 
9282  destroyPQExpBuffer(acl_subquery);
9283  destroyPQExpBuffer(racl_subquery);
9284  destroyPQExpBuffer(initacl_subquery);
9285  destroyPQExpBuffer(initracl_subquery);
9286  }
9287  else if (fout->remoteVersion >= 90100)
9288  {
9289  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
9290  "(%s fdwowner) AS rolname, "
9291  "fdwhandler::pg_catalog.regproc, "
9292  "fdwvalidator::pg_catalog.regproc, fdwacl, "
9293  "NULL as rfdwacl, "
9294  "NULL as initfdwacl, NULL AS initrfdwacl, "
9295  "array_to_string(ARRAY("
9296  "SELECT quote_ident(option_name) || ' ' || "
9297  "quote_literal(option_value) "
9298  "FROM pg_options_to_table(fdwoptions) "
9299  "ORDER BY option_name"
9300  "), E',\n ') AS fdwoptions "
9301  "FROM pg_foreign_data_wrapper",
9303  }
9304  else
9305  {
9306  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
9307  "(%s fdwowner) AS rolname, "
9308  "'-' AS fdwhandler, "
9309  "fdwvalidator::pg_catalog.regproc, fdwacl, "
9310  "NULL as rfdwacl, "
9311  "NULL as initfdwacl, NULL AS initrfdwacl, "
9312  "array_to_string(ARRAY("
9313  "SELECT quote_ident(option_name) || ' ' || "
9314  "quote_literal(option_value) "
9315  "FROM pg_options_to_table(fdwoptions) "
9316  "ORDER BY option_name"
9317  "), E',\n ') AS fdwoptions "
9318  "FROM pg_foreign_data_wrapper",
9320  }
9321 
9322  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9323 
9324  ntups = PQntuples(res);
9325  *numForeignDataWrappers = ntups;
9326 
9327  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
9328 
9329  i_tableoid = PQfnumber(res, "tableoid");
9330  i_oid = PQfnumber(res, "oid");
9331  i_fdwname = PQfnumber(res, "fdwname");
9332  i_rolname = PQfnumber(res, "rolname");
9333  i_fdwhandler = PQfnumber(res, "fdwhandler");
9334  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
9335  i_fdwacl = PQfnumber(res, "fdwacl");
9336  i_rfdwacl = PQfnumber(res, "rfdwacl");
9337  i_initfdwacl = PQfnumber(res, "initfdwacl");
9338  i_initrfdwacl = PQfnumber(res, "initrfdwacl");
9339  i_fdwoptions = PQfnumber(res, "fdwoptions");
9340 
9341  for (i = 0; i < ntups; i++)
9342  {
9343  fdwinfo[i].dobj.objType = DO_FDW;
9344  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9345  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9346  AssignDumpId(&fdwinfo[i].dobj);
9347  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
9348  fdwinfo[i].dobj.namespace = NULL;
9349  fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
9350  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
9351  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
9352  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
9353  fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
9354  fdwinfo[i].rfdwacl = pg_strdup(PQgetvalue(res, i, i_rfdwacl));
9355  fdwinfo[i].initfdwacl = pg_strdup(PQgetvalue(res, i, i_initfdwacl));
9356  fdwinfo[i].initrfdwacl = pg_strdup(PQgetvalue(res, i, i_initrfdwacl));
9357 
9358  /* Decide whether we want to dump it */
9359  selectDumpableObject(&(fdwinfo[i].dobj), fout);
9360 
9361  /* Do not try to dump ACL if no ACL exists. */
9362  if (PQgetisnull(res, i, i_fdwacl) && PQgetisnull(res, i, i_rfdwacl) &&
9363  PQgetisnull(res, i, i_initfdwacl) &&
9364  PQgetisnull(res, i, i_initrfdwacl))
9365  fdwinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9366  }
9367 
9368  PQclear(res);
9369 
9370  destroyPQExpBuffer(query);
9371 
9372  return fdwinfo;
9373 }
char * name
Definition: pg_dump.h:130
char * rfdwacl
Definition: pg_dump.h:535
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1817
Oid tableoid
Definition: pg_backup.h:230
char * fdwhandler
Definition: pg_dump.h:531
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * fdwoptions
Definition: pg_dump.h:533
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:529
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:182
void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, const char *acl_column, const char *acl_owner, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:742
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * fdwvalidator
Definition: pg_dump.h:532
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
char * fdwacl
Definition: pg_dump.h:534
static const char * username_subquery
Definition: pg_dump.c:94
char * rolname
Definition: pg_dump.h:530
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * initfdwacl
Definition: pg_dump.h:536
Definition: pg_dump.h:70
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
char * initrfdwacl
Definition: pg_dump.h:537
CatalogId catId
Definition: pg_dump.h:128
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3188
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187

◆ getForeignServers()

ForeignServerInfo* getForeignServers ( Archive fout,
int *  numForeignServers 
)

Definition at line 9383 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, buildACLQueries(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FOREIGN_SERVER, _foreignServerInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), i, _foreignServerInfo::initrsrvacl, _foreignServerInfo::initsrvacl, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _foreignServerInfo::rolname, _foreignServerInfo::rsrvacl, selectDumpableObject(), _foreignServerInfo::srvacl, _foreignServerInfo::srvfdw, _foreignServerInfo::srvoptions, _foreignServerInfo::srvtype, _foreignServerInfo::srvversion, CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

9384 {
9385  DumpOptions *dopt = fout->dopt;
9386  PGresult *res;
9387  int ntups;
9388  int i;
9389  PQExpBuffer query;
9390  ForeignServerInfo *srvinfo;
9391  int i_tableoid;
9392  int i_oid;
9393  int i_srvname;
9394  int i_rolname;
9395  int i_srvfdw;
9396  int i_srvtype;
9397  int i_srvversion;
9398  int i_srvacl;
9399  int i_rsrvacl;
9400  int i_initsrvacl;
9401  int i_initrsrvacl;
9402  int i_srvoptions;
9403 
9404  /* Before 8.4, there are no foreign servers */
9405  if (fout->remoteVersion < 80400)
9406  {
9407  *numForeignServers = 0;
9408  return NULL;
9409  }
9410 
9411  query = createPQExpBuffer();
9412 
9413  if (fout->remoteVersion >= 90600)
9414  {
9415  PQExpBuffer acl_subquery = createPQExpBuffer();
9416  PQExpBuffer racl_subquery = createPQExpBuffer();
9417  PQExpBuffer initacl_subquery = createPQExpBuffer();
9418  PQExpBuffer initracl_subquery = createPQExpBuffer();
9419 
9420  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9421  initracl_subquery, "f.srvacl", "f.srvowner", "'S'",
9422  dopt->binary_upgrade);
9423 
9424  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.srvname, "
9425  "(%s f.srvowner) AS rolname, "
9426  "f.srvfdw, f.srvtype, f.srvversion, "
9427  "%s AS srvacl, "
9428  "%s AS rsrvacl, "
9429  "%s AS initsrvacl, "
9430  "%s AS initrsrvacl, "
9431  "array_to_string(ARRAY("
9432  "SELECT quote_ident(option_name) || ' ' || "
9433  "quote_literal(option_value) "
9434  "FROM pg_options_to_table(f.srvoptions) "
9435  "ORDER BY option_name"
9436  "), E',\n ') AS srvoptions "
9437  "FROM pg_foreign_server f "
9438  "LEFT JOIN pg_init_privs pip "
9439  "ON (f.oid = pip.objoid "
9440  "AND pip.classoid = 'pg_foreign_server'::regclass "
9441  "AND pip.objsubid = 0) ",
9443  acl_subquery->data,
9444  racl_subquery->data,
9445  initacl_subquery->data,
9446  initracl_subquery->data);
9447 
9448  destroyPQExpBuffer(acl_subquery);
9449  destroyPQExpBuffer(racl_subquery);
9450  destroyPQExpBuffer(initacl_subquery);
9451  destroyPQExpBuffer(initracl_subquery);
9452  }
9453  else
9454  {
9455  appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
9456  "(%s srvowner) AS rolname, "
9457  "srvfdw, srvtype, srvversion, srvacl, "
9458  "NULL AS rsrvacl, "
9459  "NULL AS initsrvacl, NULL AS initrsrvacl, "
9460  "array_to_string(ARRAY("
9461  "SELECT quote_ident(option_name) || ' ' || "
9462  "quote_literal(option_value) "
9463  "FROM pg_options_to_table(srvoptions) "
9464  "ORDER BY option_name"
9465  "), E',\n ') AS srvoptions "
9466  "FROM pg_foreign_server",
9468  }
9469 
9470  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9471 
9472  ntups = PQntuples(res);
9473  *numForeignServers = ntups;
9474 
9475  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
9476 
9477  i_tableoid = PQfnumber(res, "tableoid");
9478  i_oid = PQfnumber(res, "oid");
9479  i_srvname = PQfnumber(res, "srvname");
9480  i_rolname = PQfnumber(res, "rolname");
9481  i_srvfdw = PQfnumber(res, "srvfdw");
9482  i_srvtype = PQfnumber(res, "srvtype");
9483  i_srvversion = PQfnumber(res, "srvversion");
9484  i_srvacl = PQfnumber(res, "srvacl");
9485  i_rsrvacl = PQfnumber(res, "rsrvacl");
9486  i_initsrvacl = PQfnumber(res, "initsrvacl");
9487  i_initrsrvacl = PQfnumber(res, "initrsrvacl");
9488  i_srvoptions = PQfnumber(res, "srvoptions");
9489 
9490  for (i = 0; i < ntups; i++)
9491  {
9492  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
9493  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9494  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9495  AssignDumpId(&srvinfo[i].dobj);
9496  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
9497  srvinfo[i].dobj.namespace = NULL;
9498  srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
9499  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
9500  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
9501  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
9502  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
9503  srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl));
9504  srvinfo[i].rsrvacl = pg_strdup(PQgetvalue(res, i, i_rsrvacl));
9505  srvinfo[i].initsrvacl = pg_strdup(PQgetvalue(res, i, i_initsrvacl));
9506  srvinfo[i].initrsrvacl = pg_strdup(PQgetvalue(res, i, i_initrsrvacl));
9507 
9508  /* Decide whether we want to dump it */
9509  selectDumpableObject(&(srvinfo[i].dobj), fout);
9510 
9511  /* Do not try to dump ACL if no ACL exists. */
9512  if (PQgetisnull(res, i, i_srvacl) && PQgetisnull(res, i, i_rsrvacl) &&
9513  PQgetisnull(res, i, i_initsrvacl) &&
9514  PQgetisnull(res, i, i_initrsrvacl))
9515  srvinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9516  }
9517 
9518  PQclear(res);
9519 
9520  destroyPQExpBuffer(query);
9521 
9522  return srvinfo;
9523 }
char * srvoptions
Definition: pg_dump.h:551
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1817
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
char * initrsrvacl
Definition: pg_dump.h:550
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:182
void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, const char *acl_column, const char *acl_owner, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:742
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
char * srvversion
Definition: pg_dump.h:546
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
DumpableObject dobj
Definition: pg_dump.h:542
int i
char * initsrvacl
Definition: pg_dump.h:549
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3188
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187

◆ getFuncs()

FuncInfo* getFuncs ( Archive fout,
int *  numFuncs 
)

Definition at line 5809 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), _funcInfo::argtypes, AssignDumpId(), atooid, _dumpOptions::binary_upgrade, buildACLQueries(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FUNC, _funcInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), g_last_builtin_oid, i, _funcInfo::initproacl, _funcInfo::initrproacl, _funcInfo::lang, _dumpableObject::name, _funcInfo::nargs, _dumpableObject::objType, CatalogId::oid, parseOidArray(), pg_log_warning, pg_malloc(), pg_malloc0(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _funcInfo::proacl, _funcInfo::prorettype, Archive::remoteVersion, rolname, _funcInfo::rolname, _funcInfo::rproacl, selectDumpableObject(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

5810 {
5811  DumpOptions *dopt = fout->dopt;
5812  PGresult *res;
5813  int ntups;
5814  int i;
5815  PQExpBuffer query = createPQExpBuffer();
5816  FuncInfo *finfo;
5817  int i_tableoid;
5818  int i_oid;
5819  int i_proname;
5820  int i_pronamespace;
5821  int i_rolname;
5822  int i_prolang;
5823  int i_pronargs;
5824  int i_proargtypes;
5825  int i_prorettype;
5826  int i_proacl;
5827  int i_rproacl;
5828  int i_initproacl;
5829  int i_initrproacl;
5830 
5831  /*
5832  * Find all interesting functions. This is a bit complicated:
5833  *
5834  * 1. Always exclude aggregates; those are handled elsewhere.
5835  *
5836  * 2. Always exclude functions that are internally dependent on something
5837  * else, since presumably those will be created as a result of creating
5838  * the something else. This currently acts only to suppress constructor
5839  * functions for range types (so we only need it in 9.2 and up). Note
5840  * this is OK only because the constructors don't have any dependencies
5841  * the range type doesn't have; otherwise we might not get creation
5842  * ordering correct.
5843  *
5844  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
5845  * they're members of extensions and we are in binary-upgrade mode then
5846  * include them, since we want to dump extension members individually in
5847  * that mode. Also, if they are used by casts or transforms then we need
5848  * to gather the information about them, though they won't be dumped if
5849  * they are built-in. Also, in 9.6 and up, include functions in
5850  * pg_catalog if they have an ACL different from what's shown in
5851  * pg_init_privs.
5852  */
5853  if (fout->remoteVersion >= 90600)
5854  {
5855  PQExpBuffer acl_subquery = createPQExpBuffer();
5856  PQExpBuffer racl_subquery = createPQExpBuffer();
5857  PQExpBuffer initacl_subquery = createPQExpBuffer();
5858  PQExpBuffer initracl_subquery = createPQExpBuffer();
5859  const char *not_agg_check;
5860 
5861  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5862  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5863  dopt->binary_upgrade);
5864 
5865  not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
5866  : "NOT p.proisagg");
5867 
5868  appendPQExpBuffer(query,
5869  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
5870  "p.pronargs, p.proargtypes, p.prorettype, "
5871  "%s AS proacl, "
5872  "%s AS rproacl, "
5873  "%s AS initproacl, "
5874  "%s AS initrproacl, "
5875  "p.pronamespace, "
5876  "(%s p.proowner) AS rolname "
5877  "FROM pg_proc p "
5878  "LEFT JOIN pg_init_privs pip ON "
5879  "(p.oid = pip.objoid "
5880  "AND pip.classoid = 'pg_proc'::regclass "
5881  "AND pip.objsubid = 0) "
5882  "WHERE %s"
5883  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5884  "WHERE classid = 'pg_proc'::regclass AND "
5885  "objid = p.oid AND deptype = 'i')"
5886  "\n AND ("
5887  "\n pronamespace != "
5888  "(SELECT oid FROM pg_namespace "
5889  "WHERE nspname = 'pg_catalog')"
5890  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5891  "\n WHERE pg_cast.oid > %u "
5892  "\n AND p.oid = pg_cast.castfunc)"
5893  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5894  "\n WHERE pg_transform.oid > %u AND "
5895  "\n (p.oid = pg_transform.trffromsql"
5896  "\n OR p.oid = pg_transform.trftosql))",
5897  acl_subquery->data,
5898  racl_subquery->data,
5899  initacl_subquery->data,
5900  initracl_subquery->data,
5902  not_agg_check,
5905  if (dopt->binary_upgrade)
5906  appendPQExpBufferStr(query,
5907  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5908  "classid = 'pg_proc'::regclass AND "
5909  "objid = p.oid AND "
5910  "refclassid = 'pg_extension'::regclass AND "
5911  "deptype = 'e')");
5912  appendPQExpBufferStr(query,
5913  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
5914  appendPQExpBufferChar(query, ')');
5915 
5916  destroyPQExpBuffer(acl_subquery);
5917  destroyPQExpBuffer(racl_subquery);
5918  destroyPQExpBuffer(initacl_subquery);
5919  destroyPQExpBuffer(initracl_subquery);
5920  }
5921  else
5922  {
5923  appendPQExpBuffer(query,
5924  "SELECT tableoid, oid, proname, prolang, "
5925  "pronargs, proargtypes, prorettype, proacl, "
5926  "NULL as rproacl, "
5927  "NULL as initproacl, NULL AS initrproacl, "
5928  "pronamespace, "
5929  "(%s proowner) AS rolname "
5930  "FROM pg_proc p "
5931  "WHERE NOT proisagg",
5933  if (fout->remoteVersion >= 90200)
5934  appendPQExpBufferStr(query,
5935  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5936  "WHERE classid = 'pg_proc'::regclass AND "
5937  "objid = p.oid AND deptype = 'i')");
5938  appendPQExpBuffer(query,
5939  "\n AND ("
5940  "\n pronamespace != "
5941  "(SELECT oid FROM pg_namespace "
5942  "WHERE nspname = 'pg_catalog')"
5943  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5944  "\n WHERE pg_cast.oid > '%u'::oid"
5945  "\n AND p.oid = pg_cast.castfunc)",
5947 
5948  if (fout->remoteVersion >= 90500)
5949  appendPQExpBuffer(query,
5950  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5951  "\n WHERE pg_transform.oid > '%u'::oid"
5952  "\n AND (p.oid = pg_transform.trffromsql"
5953  "\n OR p.oid = pg_transform.trftosql))",
5955 
5956  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5957  appendPQExpBufferStr(query,
5958  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5959  "classid = 'pg_proc'::regclass AND "
5960  "objid = p.oid AND "
5961  "refclassid = 'pg_extension'::regclass AND "
5962  "deptype = 'e')");
5963  appendPQExpBufferChar(query, ')');
5964  }
5965 
5966  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5967 
5968  ntups = PQntuples(res);
5969 
5970  *numFuncs = ntups;
5971 
5972  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
5973 
5974  i_tableoid = PQfnumber(res, "tableoid");
5975  i_oid = PQfnumber(res, "oid");
5976  i_proname = PQfnumber(res, "proname");
5977  i_pronamespace = PQfnumber(res, "pronamespace");
5978  i_rolname = PQfnumber(res, "rolname");
5979  i_prolang = PQfnumber(res, "prolang");
5980  i_pronargs = PQfnumber(res, "pronargs");
5981  i_proargtypes = PQfnumber(res, "proargtypes");
5982  i_prorettype = PQfnumber(res, "prorettype");
5983  i_proacl = PQfnumber(res, "proacl");
5984  i_rproacl = PQfnumber(res, "rproacl");
5985  i_initproacl = PQfnumber(res, "initproacl");
5986  i_initrproacl = PQfnumber(res, "initrproacl");
5987 
5988  for (i = 0; i < ntups; i++)
5989  {
5990  finfo[i].dobj.objType = DO_FUNC;
5991  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5992  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5993  AssignDumpId(&finfo[i].dobj);
5994  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
5995  finfo[i].dobj.namespace =
5996  findNamespace(fout,
5997  atooid(PQgetvalue(res, i, i_pronamespace)));
5998  finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5999  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
6000  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
6001  finfo[i].proacl = pg_strdup(PQgetvalue(res, i, i_proacl));
6002  finfo[i].rproacl = pg_strdup(PQgetvalue(res, i, i_rproacl));
6003  finfo[i].initproacl = pg_strdup(PQgetvalue(res, i, i_initproacl));
6004  finfo[i].initrproacl = pg_strdup(PQgetvalue(res, i, i_initrproacl));
6005  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
6006  if (finfo[i].nargs == 0)
6007  finfo[i].argtypes = NULL;
6008  else
6009  {
6010  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
6011  parseOidArray(PQgetvalue(res, i, i_proargtypes),
6012  finfo[i].argtypes, finfo[i].nargs);
6013  }
6014 
6015  /* Decide whether we want to dump it */
6016  selectDumpableObject(&(finfo[i].dobj), fout);
6017 
6018  /* Do not try to dump ACL if no ACL exists. */
6019  if (PQgetisnull(res, i, i_proacl) && PQgetisnull(res, i, i_rproacl) &&
6020  PQgetisnull(res, i, i_initproacl) &&
6021  PQgetisnull(res, i, i_initrproacl))
6022  finfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
6023 
6024  if (strlen(finfo[i].rolname) == 0)
6025  pg_log_warning("owner of function \"%s\" appears to be invalid",
6026  finfo[i].dobj.name);
6027  }
6028 
6029  PQclear(res);
6030 
6031  destroyPQExpBuffer(query);
6032 
6033  return finfo;
6034 }
Oid * argtypes
Definition: pg_dump.h:200
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1817
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int nargs
Definition: pg_dump.h:199
NameData rolname
Definition: pg_authid.h:34
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4794
static int numFuncs
Definition: common.c:57
char * initrproacl
Definition: pg_dump.h:205
Oid lang
Definition: pg_dump.h:198
DumpableObject dobj
Definition: pg_dump.h:196
unsigned int Oid
Definition: postgres_ext.h:31
static Oid g_last_builtin_oid
Definition: pg_dump.c:100
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:135
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
DumpOptions * dopt
Definition: pg_backup.h:182
void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, const char *acl_column, const char *acl_owner, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:742
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1049
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
void PQclear(PGresult *res)
Definition: fe-exec.c:694
Oid prorettype
Definition: pg_dump.h:201
char * initproacl
Definition: pg_dump.h:204
char * rolname
Definition: pg_dump.h:197
char * proacl
Definition: pg_dump.h:202
char * rproacl
Definition: pg_dump.h:203
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
int i
#define pg_log_warning(...)
Definition: pgfnames.c:24
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3188
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187

◆ getIndexes()

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

Definition at line 6989 of file pg_dump.c.

References appendPQExpBuffer(), 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, DUMP_COMPONENT_DEFINITION, _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::indreloptions, _indxInfo::indstatcols, _indxInfo::indstatvals, _tableInfo::interesting, InvalidOid, _dumpableObject::name, _tableInfo::numIndexes, numTables, _dumpableObject::objType, CatalogId::oid, _indxInfo::parentidx, parseOidArray(), _indxInfo::partattaches, pg_log_info, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, resetPQExpBuffer(), _constraintInfo::separate, CatalogId::tableoid, and _indxInfo::tablespace.

Referenced by getSchemaData().

6990 {
6991  int i,
6992  j;
6993  PQExpBuffer query = createPQExpBuffer();
6994  PGresult *res;
6995  IndxInfo *indxinfo;
6996  ConstraintInfo *constrinfo;
6997  int i_tableoid,
6998  i_oid,
6999  i_indexname,
7000  i_parentidx,
7001  i_indexdef,
7002  i_indnkeyatts,
7003  i_indnatts,
7004  i_indkey,
7005  i_indisclustered,
7006  i_indisreplident,
7007  i_contype,
7008  i_conname,
7009  i_condeferrable,
7010  i_condeferred,
7011  i_contableoid,
7012  i_conoid,
7013  i_condef,
7014  i_tablespace,
7015  i_indreloptions,
7016  i_indstatcols,
7017  i_indstatvals;
7018  int ntups;
7019 
7020  for (i = 0; i < numTables; i++)
7021  {
7022  TableInfo *tbinfo = &tblinfo[i];
7023 
7024  if (!tbinfo->hasindex)
7025  continue;
7026 
7027  /*
7028  * Ignore indexes of tables whose definitions are not to be dumped.
7029  *
7030  * We also need indexes on partitioned tables which have partitions to
7031  * be dumped, in order to dump the indexes on the partitions.
7032  */
7033  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) &&
7034  !tbinfo->interesting)
7035  continue;
7036 
7037  pg_log_info("reading indexes for table \"%s.%s\"",
7038  tbinfo->dobj.namespace->dobj.name,
7039  tbinfo->dobj.name);
7040 
7041  /*
7042  * The point of the messy-looking outer join is to find a constraint
7043  * that is related by an internal dependency link to the index. If we
7044  * find one, create a CONSTRAINT entry linked to the INDEX entry. We
7045  * assume an index won't have more than one internal dependency.
7046  *
7047  * As of 9.0 we don't need to look at pg_depend but can check for a
7048  * match to pg_constraint.conindid. The check on conrelid is
7049  * redundant but useful because that column is indexed while conindid
7050  * is not.
7051  */
7052  resetPQExpBuffer(query);
7053  if (fout->remoteVersion >= 110000)
7054  {
7055  appendPQExpBuffer(query,
7056  "SELECT t.tableoid, t.oid, "
7057  "t.relname AS indexname, "
7058  "inh.inhparent AS parentidx, "
7059  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7060  "i.indnkeyatts AS indnkeyatts, "
7061  "i.indnatts AS indnatts, "
7062  "i.indkey, i.indisclustered, "
7063  "i.indisreplident, "
7064  "c.contype, c.conname, "
7065  "c.condeferrable, c.condeferred, "
7066  "c.tableoid AS contableoid, "
7067  "c.oid AS conoid, "
7068  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7069  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7070  "t.reloptions AS indreloptions, "
7071  "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
7072  " FROM pg_catalog.pg_attribute "
7073  " WHERE attrelid = i.indexrelid AND "
7074  " attstattarget >= 0) AS indstatcols,"
7075  "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
7076  " FROM pg_catalog.pg_attribute "
7077  " WHERE attrelid = i.indexrelid AND "
7078  " attstattarget >= 0) AS indstatvals "
7079  "FROM pg_catalog.pg_index i "
7080  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7081  "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
7082  "LEFT JOIN pg_catalog.pg_constraint c "
7083  "ON (i.indrelid = c.conrelid AND "
7084  "i.indexrelid = c.conindid AND "
7085  "c.contype IN ('p','u','x')) "
7086  "LEFT JOIN pg_catalog.pg_inherits inh "
7087  "ON (inh.inhrelid = indexrelid) "
7088  "WHERE i.indrelid = '%u'::pg_catalog.oid "
7089  "AND (i.indisvalid OR t2.relkind = 'p') "
7090  "AND i.indisready "
7091  "ORDER BY indexname",
7092  tbinfo->dobj.catId.oid);
7093  }
7094  else if (fout->remoteVersion >= 90400)
7095  {
7096  /*
7097  * the test on indisready is necessary in 9.2, and harmless in
7098  * earlier/later versions
7099  */
7100  appendPQExpBuffer(query,
7101  "SELECT t.tableoid, t.oid, "
7102  "t.relname AS indexname, "
7103  "0 AS parentidx, "
7104  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7105  "i.indnatts AS indnkeyatts, "
7106  "i.indnatts AS indnatts, "
7107  "i.indkey, i.indisclustered, "
7108  "i.indisreplident, "
7109  "c.contype, c.conname, "
7110  "c.condeferrable, c.condeferred, "
7111  "c.tableoid AS contableoid, "
7112  "c.oid AS conoid, "
7113  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7114  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7115  "t.reloptions AS indreloptions, "
7116  "'' AS indstatcols, "
7117  "'' AS indstatvals "
7118  "FROM pg_catalog.pg_index i "
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.indrelid = '%u'::pg_catalog.oid "
7125  "AND i.indisvalid AND i.indisready "
7126  "ORDER BY indexname",
7127  tbinfo->dobj.catId.oid);
7128  }
7129  else if (fout->remoteVersion >= 90000)
7130  {
7131  /*
7132  * the test on indisready is necessary in 9.2, and harmless in
7133  * earlier/later versions
7134  */
7135  appendPQExpBuffer(query,
7136  "SELECT t.tableoid, t.oid, "
7137  "t.relname AS indexname, "
7138  "0 AS parentidx, "
7139  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7140  "i.indnatts AS indnkeyatts, "
7141  "i.indnatts AS indnatts, "
7142  "i.indkey, i.indisclustered, "
7143  "false AS indisreplident, "
7144  "c.contype, c.conname, "
7145  "c.condeferrable, c.condeferred, "
7146  "c.tableoid AS contableoid, "
7147  "c.oid AS conoid, "
7148  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7149  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7150  "t.reloptions AS indreloptions, "
7151  "'' AS indstatcols, "
7152  "'' AS indstatvals "
7153  "FROM pg_catalog.pg_index i "
7154  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7155  "LEFT JOIN pg_catalog.pg_constraint c "
7156  "ON (i.indrelid = c.conrelid AND "
7157  "i.indexrelid = c.conindid AND "
7158  "c.contype IN ('p','u','x')) "
7159  "WHERE i.indrelid = '%u'::pg_catalog.oid "
7160  "AND i.indisvalid AND i.indisready "
7161  "ORDER BY indexname",
7162  tbinfo->dobj.catId.oid);
7163  }
7164  else if (fout->remoteVersion >= 80200)
7165  {
7166  appendPQExpBuffer(query,
7167  "SELECT t.tableoid, t.oid, "
7168  "t.relname AS indexname, "
7169  "0 AS parentidx, "
7170  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7171  "i.indnatts AS indnkeyatts, "
7172  "i.indnatts AS indnatts, "
7173  "i.indkey, i.indisclustered, "
7174  "false AS indisreplident, "
7175  "c.contype, c.conname, "
7176  "c.condeferrable, c.condeferred, "
7177  "c.tableoid AS contableoid, "
7178  "c.oid AS conoid, "
7179  "null AS condef, "
7180  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7181  "t.reloptions AS indreloptions, "
7182  "'' AS indstatcols, "
7183  "'' AS indstatvals "
7184  "FROM pg_catalog.pg_index i "
7185  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7186  "LEFT JOIN pg_catalog.pg_depend d "
7187  "ON (d.classid = t.tableoid "
7188  "AND d.objid = t.oid "
7189  "AND d.deptype = 'i') "
7190  "LEFT JOIN pg_catalog.pg_constraint c "
7191  "ON (d.refclassid = c.tableoid "
7192  "AND d.refobjid = c.oid) "
7193  "WHERE i.indrelid = '%u'::pg_catalog.oid "
7194  "AND i.indisvalid "
7195  "ORDER BY indexname",
7196  tbinfo->dobj.catId.oid);
7197  }
7198  else
7199  {
7200  appendPQExpBuffer(query,
7201  "SELECT t.tableoid, t.oid, "
7202  "t.relname AS indexname, "
7203  "0 AS parentidx, "
7204  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7205  "t.relnatts AS indnkeyatts, "
7206  "t.relnatts AS indnatts, "
7207  "i.indkey, i.indisclustered, "
7208  "false AS indisreplident, "
7209  "c.contype, c.conname, "
7210  "c.condeferrable, c.condeferred, "
7211  "c.tableoid AS contableoid, "
7212  "c.oid AS conoid, "
7213  "null AS condef, "
7214  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7215  "null AS indreloptions, "
7216  "'' AS indstatcols, "
7217  "'' AS indstatvals "
7218  "FROM pg_catalog.pg_index i "
7219  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7220  "LEFT JOIN pg_catalog.pg_depend d "
7221  "ON (d.classid = t.tableoid "
7222  "AND d.objid = t.oid "
7223  "AND d.deptype = 'i') "
7224  "LEFT JOIN pg_catalog.pg_constraint c "
7225  "ON (d.refclassid = c.tableoid "
7226  "AND d.refobjid = c.oid) "
7227  "WHERE i.indrelid = '%u'::pg_catalog.oid "
7228  "ORDER BY indexname",
7229  tbinfo->dobj.catId.oid);
7230  }
7231 
7232  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7233 
7234  ntups = PQntuples(res);
7235 
7236  i_tableoid = PQfnumber(res, "tableoid");
7237  i_oid = PQfnumber(res, "oid");
7238  i_indexname = PQfnumber(res, "indexname");
7239  i_parentidx = PQfnumber(res, "parentidx");
7240  i_indexdef = PQfnumber(res, "indexdef");
7241  i_indnkeyatts = PQfnumber(res, "indnkeyatts");
7242  i_indnatts = PQfnumber(res, "indnatts");
7243  i_indkey = PQfnumber(res, "indkey");
7244  i_indisclustered = PQfnumber(res, "indisclustered");
7245  i_indisreplident = PQfnumber(res, "indisreplident");
7246  i_contype = PQfnumber(res, "contype");
7247  i_conname = PQfnumber(res, "conname");
7248  i_condeferrable = PQfnumber(res, "condeferrable");
7249  i_condeferred = PQfnumber(res, "condeferred");
7250  i_contableoid = PQfnumber(res, "contableoid");
7251  i_conoid = PQfnumber(res, "conoid");
7252  i_condef = PQfnumber(res, "condef");
7253  i_tablespace = PQfnumber(res, "tablespace");
7254  i_indreloptions = PQfnumber(res, "indreloptions");
7255  i_indstatcols = PQfnumber(res, "indstatcols");
7256  i_indstatvals = PQfnumber(res, "indstatvals");
7257 
7258  tbinfo->indexes = indxinfo =
7259  (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
7260  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7261  tbinfo->numIndexes = ntups;
7262 
7263  for (j = 0; j < ntups; j++)
7264  {
7265  char contype;
7266 
7267  indxinfo[j].dobj.objType = DO_INDEX;
7268  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
7269  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
7270  AssignDumpId(&indxinfo[j].dobj);
7271  indxinfo[j].dobj.dump = tbinfo->dobj.dump;
7272  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
7273  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7274  indxinfo[j].indextable = tbinfo;
7275  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
7276  indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
7277  indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
7278  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
7279  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
7280  indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
7281  indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
7282  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
7283  parseOidArray(PQgetvalue(res, j, i_indkey),
7284  indxinfo[j].indkeys, indxinfo[j].indnattrs);
7285  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
7286  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
7287  indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
7288  indxinfo[j].partattaches = (SimplePtrList)
7289  {
7290  NULL, NULL
7291  };
7292  contype = *(PQgetvalue(res, j, i_contype));
7293 
7294  if (contype == 'p' || contype == 'u' || contype == 'x')
7295  {
7296  /*
7297  * If we found a constraint matching the index, create an
7298  * entry for it.
7299  */
7300  constrinfo[j].dobj.objType = DO_CONSTRAINT;
7301  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7302  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7303  AssignDumpId(&constrinfo[j].dobj);
7304  constrinfo[j].dobj.dump = tbinfo->dobj.dump;
7305  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7306  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7307  constrinfo[j].contable = tbinfo;
7308  constrinfo[j].condomain = NULL;
7309  constrinfo[j].contype = contype;
7310  if (contype == 'x')
7311  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7312  else
7313  constrinfo[j].condef = NULL;
7314  constrinfo[j].confrelid = InvalidOid;
7315  constrinfo[j].conindex = indxinfo[j].dobj.dumpId;
7316  constrinfo[j].condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
7317  constrinfo[j].condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
7318  constrinfo[j].conislocal = true;
7319  constrinfo[j].separate = true;
7320 
7321  indxinfo[j].indexconstraint = constrinfo[j].dobj.dumpId;
7322  }
7323  else
7324  {
7325  /* Plain secondary index */
7326  indxinfo[j].indexconstraint = 0;
7327  }
7328  }
7329 
7330  PQclear(res);
7331  }
7332 
7333  destroyPQExpBuffer(query);
7334 }
char * tablespace
Definition: pg_dump.h:361
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
struct SimplePtrList SimplePtrList
bool hasindex
Definition: pg_dump.h:273
DumpId dumpId
Definition: pg_dump.h:129
static int numTables
Definition: common.c:55
unsigned int Oid
Definition: postgres_ext.h:31
DumpId conindex
Definition: pg_dump.h:448
DumpId indexconstraint
Definition: pg_dump.h:375
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
char * indexdef
Definition: pg_dump.h:360
DumpableObject dobj
Definition: pg_dump.h:259
Oid parentidx
Definition: pg_dump.h:371
char * condef
Definition: pg_dump.h:446
bool indisreplident
Definition: pg_dump.h:370
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:442
TableInfo * indextable
Definition: pg_dump.h:359
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
Oid * indkeys
Definition: pg_dump.h:367
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
bool condeferrable
Definition: pg_dump.h:449
char * indreloptions
Definition: pg_dump.h:362
TypeInfo * condomain
Definition: pg_dump.h:444
bool conislocal
Definition: pg_dump.h:451
SimplePtrList partattaches
Definition: pg_dump.h:372
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1049
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int numIndexes
Definition: pg_dump.h:333
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
TableInfo * contable
Definition: pg_dump.h:443
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:89
bool condeferred
Definition: pg_dump.h:450
int indnkeyattrs
Definition: pg_dump.h:365
char * indstatvals
Definition: pg_dump.h:364
int indnattrs
Definition: pg_dump.h:366
struct _indxInfo * indexes
Definition: pg_dump.h:334
CatalogId catId
Definition: pg_dump.h:128
DumpableObject dobj
Definition: pg_dump.h:358
char * indstatcols
Definition: pg_dump.h:363
bool interesting
Definition: pg_dump.h:293
int i
bool indisclustered
Definition: pg_dump.h:369
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148
DumpableObjectType objType
Definition: pg_dump.h:127
#define pg_log_info(...)
Definition: logging.h:87
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187

◆ getInherits()

InhInfo* getInherits ( Archive fout,
int *  numInherits 
)

Definition at line 6940 of file pg_dump.c.

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

Referenced by getSchemaData().

6941 {
6942  PGresult *res;
6943  int ntups;
6944  int i;
6945  PQExpBuffer query = createPQExpBuffer();
6946  InhInfo *inhinfo;
6947 
6948  int i_inhrelid;
6949  int i_inhparent;
6950 
6951  /*
6952  * Find all the inheritance information, excluding implicit inheritance
6953  * via partitioning.
6954  */
6955  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
6956 
6957  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6958 
6959  ntups = PQntuples(res);
6960 
6961  *numInherits = ntups;
6962 
6963  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6964 
6965  i_inhrelid = PQfnumber(res, "inhrelid");
6966  i_inhparent = PQfnumber(res, "inhparent");
6967 
6968  for (i = 0; i < ntups; i++)
6969  {
6970  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6971  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6972  }
6973 
6974  PQclear(res);
6975 
6976  destroyPQExpBuffer(query);
6977 
6978  return inhinfo;
6979 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
Oid inhrelid
Definition: pg_dump.h:491
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void PQclear(PGresult *res)
Definition: fe-exec.c:694
Oid inhparent
Definition: pg_dump.h:492
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )

Definition at line 599 of file common.c.

References lastDumpId.

Referenced by findDependencyLoops(), flagInhIndexes(), and TopoSort().

600 {
601  return lastDumpId;
602 }
static DumpId lastDumpId
Definition: common.c:31

◆ getNamespaces()

NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

Definition at line 4666 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, buildACLQueries(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_NAMESPACE, _namespaceInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), i, _namespaceInfo::initnspacl, _namespaceInfo::initrnspacl, _dumpableObject::name, _namespaceInfo::nspacl, _dumpableObject::objType, CatalogId::oid, pg_log_warning, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _namespaceInfo::rnspacl, rolname, _namespaceInfo::rolname, selectDumpableNamespace(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

4667 {
4668  DumpOptions *dopt = fout->dopt;
4669  PGresult *res;
4670  int ntups;
4671  int i;
4672  PQExpBuffer query;
4673  NamespaceInfo *nsinfo;
4674  int i_tableoid;
4675  int i_oid;
4676  int i_nspname;
4677  int i_rolname;
4678  int i_nspacl;
4679  int i_rnspacl;
4680  int i_initnspacl;
4681  int i_initrnspacl;
4682 
4683  query = createPQExpBuffer();
4684 
4685  /*
4686  * we fetch all namespaces including system ones, so that every object we
4687  * read in can be linked to a containing namespace.
4688  */
4689  if (fout->remoteVersion >= 90600)
4690  {
4691  PQExpBuffer acl_subquery = createPQExpBuffer();
4692  PQExpBuffer racl_subquery = createPQExpBuffer();
4693  PQExpBuffer init_acl_subquery = createPQExpBuffer();
4694  PQExpBuffer init_racl_subquery = createPQExpBuffer();
4695 
4696  buildACLQueries(acl_subquery, racl_subquery, init_acl_subquery,
4697  init_racl_subquery, "n.nspacl", "n.nspowner", "'n'",
4698  dopt->binary_upgrade);
4699 
4700  appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, "
4701  "(%s nspowner) AS rolname, "
4702  "%s as nspacl, "
4703  "%s as rnspacl, "
4704  "%s as initnspacl, "
4705  "%s as initrnspacl "
4706  "FROM pg_namespace n "
4707  "LEFT JOIN pg_init_privs pip "
4708  "ON (n.oid = pip.objoid "
4709  "AND pip.classoid = 'pg_namespace'::regclass "
4710  "AND pip.objsubid = 0",
4712  acl_subquery->data,
4713  racl_subquery->data,
4714  init_acl_subquery->data,
4715  init_racl_subquery->data);
4716 
4717  appendPQExpBufferStr(query, ") ");
4718 
4719  destroyPQExpBuffer(acl_subquery);
4720  destroyPQExpBuffer(racl_subquery);
4721  destroyPQExpBuffer(init_acl_subquery);
4722  destroyPQExpBuffer(init_racl_subquery);
4723  }
4724  else
4725  appendPQExpBuffer(query, "SELECT tableoid, oid, nspname, "
4726  "(%s nspowner) AS rolname, "
4727  "nspacl, NULL as rnspacl, "
4728  "NULL AS initnspacl, NULL as initrnspacl "
4729  "FROM pg_namespace",
4731 
4732  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4733 
4734  ntups = PQntuples(res);
4735 
4736  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
4737 
4738  i_tableoid = PQfnumber(res, "tableoid");
4739  i_oid = PQfnumber(res, "oid");
4740  i_nspname = PQfnumber(res, "nspname");
4741  i_rolname = PQfnumber(res, "rolname");
4742  i_nspacl = PQfnumber(res, "nspacl");
4743  i_rnspacl = PQfnumber(res, "rnspacl");
4744  i_initnspacl = PQfnumber(res, "initnspacl");
4745  i_initrnspacl = PQfnumber(res, "initrnspacl");
4746 
4747  for (i = 0; i < ntups; i++)
4748  {
4749  nsinfo[i].dobj.objType = DO_NAMESPACE;
4750  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4751  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4752  AssignDumpId(&nsinfo[i].dobj);
4753  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
4754  nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4755  nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl));
4756  nsinfo[i].rnspacl = pg_strdup(PQgetvalue(res, i, i_rnspacl));
4757  nsinfo[i].initnspacl = pg_strdup(PQgetvalue(res, i, i_initnspacl));
4758  nsinfo[i].initrnspacl = pg_strdup(PQgetvalue(res, i, i_initrnspacl));
4759 
4760  /* Decide whether to dump this namespace */
4761  selectDumpableNamespace(&nsinfo[i], fout);
4762 
4763  /*
4764  * Do not try to dump ACL if the ACL is empty or the default.
4765  *
4766  * This is useful because, for some schemas/objects, the only
4767  * component we are going to try and dump is the ACL and if we can
4768  * remove that then 'dump' goes to zero/false and we don't consider
4769  * this object for dumping at all later on.
4770  */
4771  if (PQgetisnull(res, i, i_nspacl) && PQgetisnull(res, i, i_rnspacl) &&
4772  PQgetisnull(res, i, i_initnspacl) &&
4773  PQgetisnull(res, i, i_initrnspacl))
4774  nsinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4775 
4776  if (strlen(nsinfo[i].rolname) == 0)
4777  pg_log_warning("owner of schema \"%s\" appears to be invalid",
4778  nsinfo[i].dobj.name);
4779  }
4780 
4781  PQclear(res);
4782  destroyPQExpBuffer(query);
4783 
4784  *numNamespaces = ntups;
4785 
4786  return nsinfo;
4787 }
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
NameData rolname
Definition: pg_authid.h:34
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
char * rnspacl
Definition: pg_dump.h:146
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:182
void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, const char *acl_column, const char *acl_owner, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:742
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * rolname
Definition: pg_dump.h:144
char * initnspacl
Definition: pg_dump.h:147
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static int numNamespaces
Definition: common.c:60
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1518
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
char * initrnspacl
Definition: pg_dump.h:148
CatalogId catId
Definition: pg_dump.h:128
int i
char * nspacl
Definition: pg_dump.h:145
DumpableObject dobj
Definition: pg_dump.h:143
#define pg_log_warning(...)
Definition: pgfnames.c:24
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3188
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
int remoteVersion
Definition: pg_backup.h:187

◆ getOpclasses()

OpclassInfo* getOpclasses ( Archive fout,
int *  numOpclasses 
)

Definition at line 5456 of file pg_dump.c.

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

Referenced by getSchemaData().

5457 {
5458  PGresult *res;
5459  int ntups;
5460  int i;
5461  PQExpBuffer query = createPQExpBuffer();
5462  OpclassInfo *opcinfo;
5463  int i_tableoid;
5464  int i_oid;
5465  int i_opcname;
5466  int i_opcnamespace;
5467  int i_rolname;
5468 
5469  /*
5470  * find all opclasses, including builtin opclasses; we filter out
5471  * system-defined opclasses at dump-out time.
5472  */
5473 
5474  appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
5475  "opcnamespace, "
5476  "(%s opcowner) AS rolname "
5477  "FROM pg_opclass",
5479 
5480  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5481 
5482  ntups = PQntuples(res);
5483  *numOpclasses = ntups;
5484 
5485  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
5486 
5487  i_tableoid = PQfnumber(res, "tableoid");
5488  i_oid = PQfnumber(res, "oid");
5489  i_opcname = PQfnumber(res, "opcname");
5490  i_opcnamespace = PQfnumber(res, "opcnamespace");
5491  i_rolname = PQfnumber(res, "rolname");
5492 
5493  for (i = 0; i < ntups; i++)
5494  {
5495  opcinfo[i].dobj.objType = DO_OPCLASS;
5496  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5497  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5498  AssignDumpId(&opcinfo[i].dobj);
5499  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
5500  opcinfo[i].dobj.namespace =
5501  findNamespace(fout,
5502  atooid(PQgetvalue(res, i, i_opcnamespace)));
5503  opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5504 
5505  /* Decide whether we want to dump it */
5506  selectDumpableObject(&(opcinfo[i].dobj), fout);
5507 
5508  /* Op Classes do not currently have ACLs. */
5509  opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5510 
5511  if (strlen(opcinfo[i].rolname) == 0)
5512  pg_log_warning("owner of operator class \"%s\" appears to be invalid",
5513  opcinfo[i].dobj.name);
5514  }
5515 
5516  PQclear(res);
5517 
5518  destroyPQExpBuffer(query);
5519 
5520  return opcinfo;
5521 }
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1817
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
NameData rolname
Definition: pg_authid.h:34
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4794
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
char * rolname
Definition: pg_dump.h:233
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
DumpableObject dobj
Definition: pg_dump.h:232
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
int i
#define pg_log_warning(...)
Definition: pgfnames.c:24
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401

◆ getOperators()

OprInfo* getOperators ( Archive fout,
int *  numOperators 
)

Definition at line 5146 of file pg_dump.c.

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

Referenced by getSchemaData().

5147 {
5148  PGresult *res;
5149  int ntups;
5150  int i;
5151  PQExpBuffer query = createPQExpBuffer();
5152  OprInfo *oprinfo;
5153  int i_tableoid;
5154  int i_oid;
5155  int i_oprname;
5156  int i_oprnamespace;
5157  int i_rolname;
5158  int i_oprkind;
5159  int i_oprcode;
5160 
5161  /*
5162  * find all operators, including builtin operators; we filter out
5163  * system-defined operators at dump-out time.
5164  */
5165 
5166  appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
5167  "oprnamespace, "
5168  "(%s oprowner) AS rolname, "
5169  "oprkind, "
5170  "oprcode::oid AS oprcode "
5171  "FROM pg_operator",
5173 
5174  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5175 
5176  ntups = PQntuples(res);
5177  *numOprs = ntups;
5178 
5179  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
5180 
5181  i_tableoid = PQfnumber(res, "tableoid");
5182  i_oid = PQfnumber(res, "oid");
5183  i_oprname = PQfnumber(res, "oprname");
5184  i_oprnamespace = PQfnumber(res, "oprnamespace");
5185  i_rolname = PQfnumber(res, "rolname");
5186  i_oprkind = PQfnumber(res, "oprkind");
5187  i_oprcode = PQfnumber(res, "oprcode");
5188 
5189  for (i = 0; i < ntups; i++)
5190  {
5191  oprinfo[i].dobj.objType = DO_OPERATOR;
5192  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5193  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5194  AssignDumpId(&oprinfo[i].dobj);
5195  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
5196  oprinfo[i].dobj.namespace =
5197  findNamespace(fout,
5198  atooid(PQgetvalue(res, i, i_oprnamespace)));
5199  oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5200  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
5201  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
5202 
5203  /* Decide whether we want to dump it */
5204  selectDumpableObject(&(oprinfo[i].dobj), fout);
5205 
5206  /* Operators do not currently have ACLs. */
5207  oprinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5208 
5209  if (strlen(oprinfo[i].rolname) == 0)
5210  pg_log_warning("owner of operator \"%s\" appears to be invalid",
5211  oprinfo[i].dobj.name);
5212  }
5213 
5214  PQclear(res);
5215 
5216  destroyPQExpBuffer(query);
5217 
5218  return oprinfo;
5219 }
char * name
Definition: pg_dump.h:130
DumpableObject dobj
Definition: pg_dump.h:217
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1817
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
NameData rolname
Definition: pg_authid.h:34
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4794
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
char * rolname
Definition: pg_dump.h:218
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char oprkind
Definition: pg_dump.h:219
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
int i
#define pg_log_warning(...)
Definition: pgfnames.c:24
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401
Oid oprcode
Definition: pg_dump.h:220

◆ getOpfamilies()

OpfamilyInfo* getOpfamilies ( Archive fout,
int *  numOpfamilies 
)

Definition at line 5531 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPFAMILY, _opfamilyInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_log_warning, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, rolname, _opfamilyInfo::rolname, selectDumpableObject(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

5532 {
5533  PGresult *res;
5534  int ntups;
5535  int i;
5536  PQExpBuffer query;
5537  OpfamilyInfo *opfinfo;
5538  int i_tableoid;
5539  int i_oid;
5540  int i_opfname;
5541  int i_opfnamespace;
5542  int i_rolname;
5543 
5544  /* Before 8.3, there is no separate concept of opfamilies */
5545  if (fout->remoteVersion < 80300)
5546  {
5547  *numOpfamilies = 0;
5548  return NULL;
5549  }
5550 
5551  query = createPQExpBuffer();
5552 
5553  /*
5554  * find all opfamilies, including builtin opfamilies; we filter out
5555  * system-defined opfamilies at dump-out time.
5556  */
5557 
5558  appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, "
5559  "opfnamespace, "
5560  "(%s opfowner) AS rolname "
5561  "FROM pg_opfamily",
5563 
5564  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5565 
5566  ntups = PQntuples(res);
5567  *numOpfamilies = ntups;
5568 
5569  opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
5570 
5571  i_tableoid = PQfnumber(res, "tableoid");
5572  i_oid = PQfnumber(res, "oid");
5573  i_opfname = PQfnumber(res, "opfname");
5574  i_opfnamespace = PQfnumber(res, "opfnamespace");
5575  i_rolname = PQfnumber(res, "rolname");
5576 
5577  for (i = 0; i < ntups; i++)
5578  {
5579  opfinfo[i].dobj.objType = DO_OPFAMILY;
5580  opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5581  opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5582  AssignDumpId(&opfinfo[i].dobj);
5583  opfinfo[