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:640
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:639

◆ 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 5385 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().

5386 {
5387  PGresult *res;
5388  int ntups;
5389  int i;
5390  PQExpBuffer query;
5391  AccessMethodInfo *aminfo;
5392  int i_tableoid;
5393  int i_oid;
5394  int i_amname;
5395  int i_amhandler;
5396  int i_amtype;
5397 
5398  /* Before 9.6, there are no user-defined access methods */
5399  if (fout->remoteVersion < 90600)
5400  {
5401  *numAccessMethods = 0;
5402  return NULL;
5403  }
5404 
5405  query = createPQExpBuffer();
5406 
5407  /* Select all access methods from pg_am table */
5408  appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, amtype, "
5409  "amhandler::pg_catalog.regproc AS amhandler "
5410  "FROM pg_am");
5411 
5412  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5413 
5414  ntups = PQntuples(res);
5415  *numAccessMethods = ntups;
5416 
5417  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
5418 
5419  i_tableoid = PQfnumber(res, "tableoid");
5420  i_oid = PQfnumber(res, "oid");
5421  i_amname = PQfnumber(res, "amname");
5422  i_amhandler = PQfnumber(res, "amhandler");
5423  i_amtype = PQfnumber(res, "amtype");
5424 
5425  for (i = 0; i < ntups; i++)
5426  {
5427  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
5428  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5429  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5430  AssignDumpId(&aminfo[i].dobj);
5431  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
5432  aminfo[i].dobj.namespace = NULL;
5433  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
5434  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
5435 
5436  /* Decide whether we want to dump it */
5437  selectDumpableAccessMethod(&(aminfo[i]), fout);
5438 
5439  /* Access methods do not currently have ACLs. */
5440  aminfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5441  }
5442 
5443  PQclear(res);
5444 
5445  destroyPQExpBuffer(query);
5446 
5447  return aminfo;
5448 }
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 5618 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().

5619 {
5620  DumpOptions *dopt = fout->dopt;
5621  PGresult *res;
5622  int ntups;
5623  int i;
5624  PQExpBuffer query = createPQExpBuffer();
5625  AggInfo *agginfo;
5626  int i_tableoid;
5627  int i_oid;
5628  int i_aggname;
5629  int i_aggnamespace;
5630  int i_pronargs;
5631  int i_proargtypes;
5632  int i_rolname;
5633  int i_aggacl;
5634  int i_raggacl;
5635  int i_initaggacl;
5636  int i_initraggacl;
5637 
5638  /*
5639  * Find all interesting aggregates. See comment in getFuncs() for the
5640  * rationale behind the filtering logic.
5641  */
5642  if (fout->remoteVersion >= 90600)
5643  {
5644  PQExpBuffer acl_subquery = createPQExpBuffer();
5645  PQExpBuffer racl_subquery = createPQExpBuffer();
5646  PQExpBuffer initacl_subquery = createPQExpBuffer();
5647  PQExpBuffer initracl_subquery = createPQExpBuffer();
5648  const char *agg_check;
5649 
5650  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5651  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5652  dopt->binary_upgrade);
5653 
5654  agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
5655  : "p.proisagg");
5656 
5657  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5658  "p.proname AS aggname, "
5659  "p.pronamespace AS aggnamespace, "
5660  "p.pronargs, p.proargtypes, "
5661  "(%s p.proowner) AS rolname, "
5662  "%s AS aggacl, "
5663  "%s AS raggacl, "
5664  "%s AS initaggacl, "
5665  "%s AS initraggacl "
5666  "FROM pg_proc p "
5667  "LEFT JOIN pg_init_privs pip ON "
5668  "(p.oid = pip.objoid "
5669  "AND pip.classoid = 'pg_proc'::regclass "
5670  "AND pip.objsubid = 0) "
5671  "WHERE %s AND ("
5672  "p.pronamespace != "
5673  "(SELECT oid FROM pg_namespace "
5674  "WHERE nspname = 'pg_catalog') OR "
5675  "p.proacl IS DISTINCT FROM pip.initprivs",
5677  acl_subquery->data,
5678  racl_subquery->data,
5679  initacl_subquery->data,
5680  initracl_subquery->data,
5681  agg_check);
5682  if (dopt->binary_upgrade)
5683  appendPQExpBufferStr(query,
5684  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5685  "classid = 'pg_proc'::regclass AND "
5686  "objid = p.oid AND "
5687  "refclassid = 'pg_extension'::regclass AND "
5688  "deptype = 'e')");
5689  appendPQExpBufferChar(query, ')');
5690 
5691  destroyPQExpBuffer(acl_subquery);
5692  destroyPQExpBuffer(racl_subquery);
5693  destroyPQExpBuffer(initacl_subquery);
5694  destroyPQExpBuffer(initracl_subquery);
5695  }
5696  else if (fout->remoteVersion >= 80200)
5697  {
5698  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5699  "pronamespace AS aggnamespace, "
5700  "pronargs, proargtypes, "
5701  "(%s proowner) AS rolname, "
5702  "proacl AS aggacl, "
5703  "NULL AS raggacl, "
5704  "NULL AS initaggacl, NULL AS initraggacl "
5705  "FROM pg_proc p "
5706  "WHERE proisagg AND ("
5707  "pronamespace != "
5708  "(SELECT oid FROM pg_namespace "
5709  "WHERE nspname = 'pg_catalog')",
5711  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5712  appendPQExpBufferStr(query,
5713  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5714  "classid = 'pg_proc'::regclass AND "
5715  "objid = p.oid AND "
5716  "refclassid = 'pg_extension'::regclass AND "
5717  "deptype = 'e')");
5718  appendPQExpBufferChar(query, ')');
5719  }
5720  else
5721  {
5722  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5723  "pronamespace AS aggnamespace, "
5724  "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
5725  "proargtypes, "
5726  "(%s proowner) AS rolname, "
5727  "proacl AS aggacl, "
5728  "NULL AS raggacl, "
5729  "NULL AS initaggacl, NULL AS initraggacl "
5730  "FROM pg_proc "
5731  "WHERE proisagg "
5732  "AND pronamespace != "
5733  "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
5735  }
5736 
5737  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5738 
5739  ntups = PQntuples(res);
5740  *numAggs = ntups;
5741 
5742  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5743 
5744  i_tableoid = PQfnumber(res, "tableoid");
5745  i_oid = PQfnumber(res, "oid");
5746  i_aggname = PQfnumber(res, "aggname");
5747  i_aggnamespace = PQfnumber(res, "aggnamespace");
5748  i_pronargs = PQfnumber(res, "pronargs");
5749  i_proargtypes = PQfnumber(res, "proargtypes");
5750  i_rolname = PQfnumber(res, "rolname");
5751  i_aggacl = PQfnumber(res, "aggacl");
5752  i_raggacl = PQfnumber(res, "raggacl");
5753  i_initaggacl = PQfnumber(res, "initaggacl");
5754  i_initraggacl = PQfnumber(res, "initraggacl");
5755 
5756  for (i = 0; i < ntups; i++)
5757  {
5758  agginfo[i].aggfn.dobj.objType = DO_AGG;
5759  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5760  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5761  AssignDumpId(&agginfo[i].aggfn.dobj);
5762  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5763  agginfo[i].aggfn.dobj.namespace =
5764  findNamespace(fout,
5765  atooid(PQgetvalue(res, i, i_aggnamespace)));
5766  agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5767  if (strlen(agginfo[i].aggfn.rolname) == 0)
5768  pg_log_warning("owner of aggregate function \"%s\" appears to be invalid",
5769  agginfo[i].aggfn.dobj.name);
5770  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5771  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5772  agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5773  agginfo[i].aggfn.rproacl = pg_strdup(PQgetvalue(res, i, i_raggacl));
5774  agginfo[i].aggfn.initproacl = pg_strdup(PQgetvalue(res, i, i_initaggacl));
5775  agginfo[i].aggfn.initrproacl = pg_strdup(PQgetvalue(res, i, i_initraggacl));
5776  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5777  if (agginfo[i].aggfn.nargs == 0)
5778  agginfo[i].aggfn.argtypes = NULL;
5779  else
5780  {
5781  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5782  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5783  agginfo[i].aggfn.argtypes,
5784  agginfo[i].aggfn.nargs);
5785  }
5786 
5787  /* Decide whether we want to dump it */
5788  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5789 
5790  /* Do not try to dump ACL if no ACL exists. */
5791  if (PQgetisnull(res, i, i_aggacl) && PQgetisnull(res, i, i_raggacl) &&
5792  PQgetisnull(res, i, i_initaggacl) &&
5793  PQgetisnull(res, i, i_initraggacl))
5794  agginfo[i].aggfn.dobj.dump &= ~DUMP_COMPONENT_ACL;
5795  }
5796 
5797  PQclear(res);
5798 
5799  destroyPQExpBuffer(query);
5800 
5801  return agginfo;
5802 }
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:4797
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 8224 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().

8225 {
8226  PGresult *res;
8227  int ntups;
8228  int i;
8229  PQExpBuffer query = createPQExpBuffer();
8230  CastInfo *castinfo;
8231  int i_tableoid;
8232  int i_oid;
8233  int i_castsource;
8234  int i_casttarget;
8235  int i_castfunc;
8236  int i_castcontext;
8237  int i_castmethod;
8238 
8239  if (fout->remoteVersion >= 80400)
8240  {
8241  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8242  "castsource, casttarget, castfunc, castcontext, "
8243  "castmethod "
8244  "FROM pg_cast ORDER BY 3,4");
8245  }
8246  else
8247  {
8248  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8249  "castsource, casttarget, castfunc, castcontext, "
8250  "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
8251  "FROM pg_cast ORDER BY 3,4");
8252  }
8253 
8254  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8255 
8256  ntups = PQntuples(res);
8257 
8258  *numCasts = ntups;
8259 
8260  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
8261 
8262  i_tableoid = PQfnumber(res, "tableoid");
8263  i_oid = PQfnumber(res, "oid");
8264  i_castsource = PQfnumber(res, "castsource");
8265  i_casttarget = PQfnumber(res, "casttarget");
8266  i_castfunc = PQfnumber(res, "castfunc");
8267  i_castcontext = PQfnumber(res, "castcontext");
8268  i_castmethod = PQfnumber(res, "castmethod");
8269 
8270  for (i = 0; i < ntups; i++)
8271  {
8272  PQExpBufferData namebuf;
8273  TypeInfo *sTypeInfo;
8274  TypeInfo *tTypeInfo;
8275 
8276  castinfo[i].dobj.objType = DO_CAST;
8277  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8278  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8279  AssignDumpId(&castinfo[i].dobj);
8280  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
8281  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
8282  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
8283  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
8284  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
8285 
8286  /*
8287  * Try to name cast as concatenation of typnames. This is only used
8288  * for purposes of sorting. If we fail to find either type, the name
8289  * will be an empty string.
8290  */
8291  initPQExpBuffer(&namebuf);
8292  sTypeInfo = findTypeByOid(castinfo[i].castsource);
8293  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
8294  if (sTypeInfo && tTypeInfo)
8295  appendPQExpBuffer(&namebuf, "%s %s",
8296  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
8297  castinfo[i].dobj.name = namebuf.data;
8298 
8299  /* Decide whether we want to dump it */
8300  selectDumpableCast(&(castinfo[i]), fout);
8301 
8302  /* Casts do not currently have ACLs. */
8303  castinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8304  }
8305 
8306  PQclear(res);
8307 
8308  destroyPQExpBuffer(query);
8309 
8310  return castinfo;
8311 }
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 5232 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().

5233 {
5234  PGresult *res;
5235  int ntups;
5236  int i;
5237  PQExpBuffer query;
5238  CollInfo *collinfo;
5239  int i_tableoid;
5240  int i_oid;
5241  int i_collname;
5242  int i_collnamespace;
5243  int i_rolname;
5244 
5245  /* Collations didn't exist pre-9.1 */
5246  if (fout->remoteVersion < 90100)
5247  {
5248  *numCollations = 0;
5249  return NULL;
5250  }
5251 
5252  query = createPQExpBuffer();
5253 
5254  /*
5255  * find all collations, including builtin collations; we filter out
5256  * system-defined collations at dump-out time.
5257  */
5258 
5259  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
5260  "collnamespace, "
5261  "(%s collowner) AS rolname "
5262  "FROM pg_collation",
5264 
5265  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5266 
5267  ntups = PQntuples(res);
5268  *numCollations = ntups;
5269 
5270  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
5271 
5272  i_tableoid = PQfnumber(res, "tableoid");
5273  i_oid = PQfnumber(res, "oid");
5274  i_collname = PQfnumber(res, "collname");
5275  i_collnamespace = PQfnumber(res, "collnamespace");
5276  i_rolname = PQfnumber(res, "rolname");
5277 
5278  for (i = 0; i < ntups; i++)
5279  {
5280  collinfo[i].dobj.objType = DO_COLLATION;
5281  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5282  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5283  AssignDumpId(&collinfo[i].dobj);
5284  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
5285  collinfo[i].dobj.namespace =
5286  findNamespace(fout,
5287  atooid(PQgetvalue(res, i, i_collnamespace)));
5288  collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5289 
5290  /* Decide whether we want to dump it */
5291  selectDumpableObject(&(collinfo[i].dobj), fout);
5292 
5293  /* Collations do not currently have ACLs. */
5294  collinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5295  }
5296 
5297  PQclear(res);
5298 
5299  destroyPQExpBuffer(query);
5300 
5301  return collinfo;
5302 }
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:4797
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 7425 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().

7426 {
7427  int i,
7428  j;
7429  ConstraintInfo *constrinfo;
7430  PQExpBuffer query;
7431  PGresult *res;
7432  int i_contableoid,
7433  i_conoid,
7434  i_conname,
7435  i_confrelid,
7436  i_conindid,
7437  i_condef;
7438  int ntups;
7439 
7440  query = createPQExpBuffer();
7441 
7442  for (i = 0; i < numTables; i++)
7443  {
7444  TableInfo *tbinfo = &tblinfo[i];
7445 
7446  /*
7447  * For partitioned tables, foreign keys have no triggers so they must
7448  * be included anyway in case some foreign keys are defined.
7449  */
7450  if ((!tbinfo->hastriggers &&
7451  tbinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7452  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
7453  continue;
7454 
7455  pg_log_info("reading foreign key constraints for table \"%s.%s\"",
7456  tbinfo->dobj.namespace->dobj.name,
7457  tbinfo->dobj.name);
7458 
7459  resetPQExpBuffer(query);
7460  if (fout->remoteVersion >= 110000)
7461  appendPQExpBuffer(query,
7462  "SELECT tableoid, oid, conname, confrelid, conindid, "
7463  "pg_catalog.pg_get_constraintdef(oid) AS condef "
7464  "FROM pg_catalog.pg_constraint "
7465  "WHERE conrelid = '%u'::pg_catalog.oid "
7466  "AND conparentid = 0 "
7467  "AND contype = 'f'",
7468  tbinfo->dobj.catId.oid);
7469  else
7470  appendPQExpBuffer(query,
7471  "SELECT tableoid, oid, conname, confrelid, 0 as conindid, "
7472  "pg_catalog.pg_get_constraintdef(oid) AS condef "
7473  "FROM pg_catalog.pg_constraint "
7474  "WHERE conrelid = '%u'::pg_catalog.oid "
7475  "AND contype = 'f'",
7476  tbinfo->dobj.catId.oid);
7477  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7478 
7479  ntups = PQntuples(res);
7480 
7481  i_contableoid = PQfnumber(res, "tableoid");
7482  i_conoid = PQfnumber(res, "oid");
7483  i_conname = PQfnumber(res, "conname");
7484  i_confrelid = PQfnumber(res, "confrelid");
7485  i_conindid = PQfnumber(res, "conindid");
7486  i_condef = PQfnumber(res, "condef");
7487 
7488  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7489 
7490  for (j = 0; j < ntups; j++)
7491  {
7492  TableInfo *reftable;
7493 
7494  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
7495  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7496  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7497  AssignDumpId(&constrinfo[j].dobj);
7498  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7499  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7500  constrinfo[j].contable = tbinfo;
7501  constrinfo[j].condomain = NULL;
7502  constrinfo[j].contype = 'f';
7503  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7504  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
7505  constrinfo[j].conindex = 0;
7506  constrinfo[j].condeferrable = false;
7507  constrinfo[j].condeferred = false;
7508  constrinfo[j].conislocal = true;
7509  constrinfo[j].separate = true;
7510 
7511  /*
7512  * Restoring an FK that points to a partitioned table requires
7513  * that all partition indexes have been attached beforehand.
7514  * Ensure that happens by making the constraint depend on each
7515  * index partition attach object.
7516  */
7517  reftable = findTableByOid(constrinfo[j].confrelid);
7518  if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
7519  {
7520  IndxInfo *refidx;
7521  Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
7522 
7523  if (indexOid != InvalidOid)
7524  {
7525  for (int k = 0; k < reftable->numIndexes; k++)
7526  {
7527  SimplePtrListCell *cell;
7528 
7529  /* not our index? */
7530  if (reftable->indexes[k].dobj.catId.oid != indexOid)
7531  continue;
7532 
7533  refidx = &reftable->indexes[k];
7534  for (cell = refidx->partattaches.head; cell;
7535  cell = cell->next)
7536  addObjectDependency(&constrinfo[j].dobj,
7537  ((DumpableObject *)
7538  cell->ptr)->dumpId);
7539  break;
7540  }
7541  }
7542  }
7543  }
7544 
7545  PQclear(res);
7546  }
7547 
7548  destroyPQExpBuffer(query);
7549 }
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 5312 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().

5313 {
5314  PGresult *res;
5315  int ntups;
5316  int i;
5317  PQExpBuffer query;
5318  ConvInfo *convinfo;
5319  int i_tableoid;
5320  int i_oid;
5321  int i_conname;
5322  int i_connamespace;
5323  int i_rolname;
5324 
5325  query = createPQExpBuffer();
5326 
5327  /*
5328  * find all conversions, including builtin conversions; we filter out
5329  * system-defined conversions at dump-out time.
5330  */
5331 
5332  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
5333  "connamespace, "
5334  "(%s conowner) AS rolname "
5335  "FROM pg_conversion",
5337 
5338  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5339 
5340  ntups = PQntuples(res);
5341  *numConversions = ntups;
5342 
5343  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
5344 
5345  i_tableoid = PQfnumber(res, "tableoid");
5346  i_oid = PQfnumber(res, "oid");
5347  i_conname = PQfnumber(res, "conname");
5348  i_connamespace = PQfnumber(res, "connamespace");
5349  i_rolname = PQfnumber(res, "rolname");
5350 
5351  for (i = 0; i < ntups; i++)
5352  {
5353  convinfo[i].dobj.objType = DO_CONVERSION;
5354  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5355  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5356  AssignDumpId(&convinfo[i].dobj);
5357  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
5358  convinfo[i].dobj.namespace =
5359  findNamespace(fout,
5360  atooid(PQgetvalue(res, i, i_connamespace)));
5361  convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5362 
5363  /* Decide whether we want to dump it */
5364  selectDumpableObject(&(convinfo[i].dobj), fout);
5365 
5366  /* Conversions do not currently have ACLs. */
5367  convinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5368  }
5369 
5370  PQclear(res);
5371 
5372  destroyPQExpBuffer(query);
5373 
5374  return convinfo;
5375 }
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:4797
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 9495 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().

9496 {
9497  DumpOptions *dopt = fout->dopt;
9498  DefaultACLInfo *daclinfo;
9499  PQExpBuffer query;
9500  PGresult *res;
9501  int i_oid;
9502  int i_tableoid;
9503  int i_defaclrole;
9504  int i_defaclnamespace;
9505  int i_defaclobjtype;
9506  int i_defaclacl;
9507  int i_rdefaclacl;
9508  int i_initdefaclacl;
9509  int i_initrdefaclacl;
9510  int i,
9511  ntups;
9512 
9513  if (fout->remoteVersion < 90000)
9514  {
9515  *numDefaultACLs = 0;
9516  return NULL;
9517  }
9518 
9519  query = createPQExpBuffer();
9520 
9521  if (fout->remoteVersion >= 90600)
9522  {
9523  PQExpBuffer acl_subquery = createPQExpBuffer();
9524  PQExpBuffer racl_subquery = createPQExpBuffer();
9525  PQExpBuffer initacl_subquery = createPQExpBuffer();
9526  PQExpBuffer initracl_subquery = createPQExpBuffer();
9527 
9528  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9529  initracl_subquery, "defaclacl", "defaclrole",
9530  "CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
9531  dopt->binary_upgrade);
9532 
9533  appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
9534  "(%s d.defaclrole) AS defaclrole, "
9535  "d.defaclnamespace, "
9536  "d.defaclobjtype, "
9537  "%s AS defaclacl, "
9538  "%s AS rdefaclacl, "
9539  "%s AS initdefaclacl, "
9540  "%s AS initrdefaclacl "
9541  "FROM pg_default_acl d "
9542  "LEFT JOIN pg_init_privs pip ON "
9543  "(d.oid = pip.objoid "
9544  "AND pip.classoid = 'pg_default_acl'::regclass "
9545  "AND pip.objsubid = 0) ",
9547  acl_subquery->data,
9548  racl_subquery->data,
9549  initacl_subquery->data,
9550  initracl_subquery->data);
9551 
9552  destroyPQExpBuffer(acl_subquery);
9553  destroyPQExpBuffer(racl_subquery);
9554  destroyPQExpBuffer(initacl_subquery);
9555  destroyPQExpBuffer(initracl_subquery);
9556  }
9557  else
9558  {
9559  appendPQExpBuffer(query, "SELECT oid, tableoid, "
9560  "(%s defaclrole) AS defaclrole, "
9561  "defaclnamespace, "
9562  "defaclobjtype, "
9563  "defaclacl, "
9564  "NULL AS rdefaclacl, "
9565  "NULL AS initdefaclacl, "
9566  "NULL AS initrdefaclacl "
9567  "FROM pg_default_acl",
9569  }
9570 
9571  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9572 
9573  ntups = PQntuples(res);
9574  *numDefaultACLs = ntups;
9575 
9576  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9577 
9578  i_oid = PQfnumber(res, "oid");
9579  i_tableoid = PQfnumber(res, "tableoid");
9580  i_defaclrole = PQfnumber(res, "defaclrole");
9581  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9582  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9583  i_defaclacl = PQfnumber(res, "defaclacl");
9584  i_rdefaclacl = PQfnumber(res, "rdefaclacl");
9585  i_initdefaclacl = PQfnumber(res, "initdefaclacl");
9586  i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
9587 
9588  for (i = 0; i < ntups; i++)
9589  {
9590  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9591 
9592  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9593  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9594  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9595  AssignDumpId(&daclinfo[i].dobj);
9596  /* cheesy ... is it worth coming up with a better object name? */
9597  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9598 
9599  if (nspid != InvalidOid)
9600  daclinfo[i].dobj.namespace = findNamespace(fout, nspid);
9601  else
9602  daclinfo[i].dobj.namespace = NULL;
9603 
9604  daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
9605  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9606  daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9607  daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
9608  daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
9609  daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
9610 
9611  /* Decide whether we want to dump it */
9612  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9613  }
9614 
9615  PQclear(res);
9616 
9617  destroyPQExpBuffer(query);
9618 
9619  return daclinfo;
9620 }
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:4797
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 7955 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().

7956 {
7957  int i;
7958  PQExpBuffer query;
7959  PGresult *res;
7960  EventTriggerInfo *evtinfo;
7961  int i_tableoid,
7962  i_oid,
7963  i_evtname,
7964  i_evtevent,
7965  i_evtowner,
7966  i_evttags,
7967  i_evtfname,
7968  i_evtenabled;
7969  int ntups;
7970 
7971  /* Before 9.3, there are no event triggers */
7972  if (fout->remoteVersion < 90300)
7973  {
7974  *numEventTriggers = 0;
7975  return NULL;
7976  }
7977 
7978  query = createPQExpBuffer();
7979 
7980  appendPQExpBuffer(query,
7981  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
7982  "evtevent, (%s evtowner) AS evtowner, "
7983  "array_to_string(array("
7984  "select quote_literal(x) "
7985  " from unnest(evttags) as t(x)), ', ') as evttags, "
7986  "e.evtfoid::regproc as evtfname "
7987  "FROM pg_event_trigger e "
7988  "ORDER BY e.oid",
7990 
7991  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7992 
7993  ntups = PQntuples(res);
7994 
7995  *numEventTriggers = ntups;
7996 
7997  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
7998 
7999  i_tableoid = PQfnumber(res, "tableoid");
8000  i_oid = PQfnumber(res, "oid");
8001  i_evtname = PQfnumber(res, "evtname");
8002  i_evtevent = PQfnumber(res, "evtevent");
8003  i_evtowner = PQfnumber(res, "evtowner");
8004  i_evttags = PQfnumber(res, "evttags");
8005  i_evtfname = PQfnumber(res, "evtfname");
8006  i_evtenabled = PQfnumber(res, "evtenabled");
8007 
8008  for (i = 0; i < ntups; i++)
8009  {
8010  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
8011  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8012  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8013  AssignDumpId(&evtinfo[i].dobj);
8014  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
8015  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
8016  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
8017  evtinfo[i].evtowner = pg_strdup(PQgetvalue(res, i, i_evtowner));
8018  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
8019  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
8020  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
8021 
8022  /* Decide whether we want to dump it */
8023  selectDumpableObject(&(evtinfo[i].dobj), fout);
8024 
8025  /* Event Triggers do not currently have ACLs. */
8026  evtinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8027  }
8028 
8029  PQclear(res);
8030 
8031  destroyPQExpBuffer(query);
8032 
8033  return evtinfo;
8034 }
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 7347 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().

7348 {
7349  PQExpBuffer query;
7350  PGresult *res;
7351  StatsExtInfo *statsextinfo;
7352  int ntups;
7353  int i_tableoid;
7354  int i_oid;
7355  int i_stxname;
7356  int i_stxnamespace;
7357  int i_rolname;
7358  int i_stattarget;
7359  int i;
7360 
7361  /* Extended statistics were new in v10 */
7362  if (fout->remoteVersion < 100000)
7363  return;
7364 
7365  query = createPQExpBuffer();
7366 
7367  if (fout->remoteVersion < 130000)
7368  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7369  "stxnamespace, (%s stxowner) AS rolname, (-1) AS stxstattarget "
7370  "FROM pg_catalog.pg_statistic_ext",
7372  else
7373  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7374  "stxnamespace, (%s stxowner) AS rolname, stxstattarget "
7375  "FROM pg_catalog.pg_statistic_ext",
7377 
7378  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7379 
7380  ntups = PQntuples(res);
7381 
7382  i_tableoid = PQfnumber(res, "tableoid");
7383  i_oid = PQfnumber(res, "oid");
7384  i_stxname = PQfnumber(res, "stxname");
7385  i_stxnamespace = PQfnumber(res, "stxnamespace");
7386  i_rolname = PQfnumber(res, "rolname");
7387  i_stattarget = PQfnumber(res, "stxstattarget");
7388 
7389  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
7390 
7391  for (i = 0; i < ntups; i++)
7392  {
7393  statsextinfo[i].dobj.objType = DO_STATSEXT;
7394  statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7395  statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7396  AssignDumpId(&statsextinfo[i].dobj);
7397  statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
7398  statsextinfo[i].dobj.namespace =
7399  findNamespace(fout,
7400  atooid(PQgetvalue(res, i, i_stxnamespace)));
7401  statsextinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
7402  statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
7403 
7404  /* Decide whether we want to dump it */
7405  selectDumpableObject(&(statsextinfo[i].dobj), fout);
7406 
7407  /* Stats objects do not currently have ACLs. */
7408  statsextinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7409  }
7410 
7411  PQclear(res);
7412  destroyPQExpBuffer(query);
7413 }
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:4797
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 17682 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().

17684 {
17685  PQExpBuffer query;
17686  PGresult *res;
17687  int ntups,
17688  nextmembers,
17689  i;
17690  int i_classid,
17691  i_objid,
17692  i_refobjid;
17694  ExtensionInfo *ext;
17695 
17696  /* Nothing to do if no extensions */
17697  if (numExtensions == 0)
17698  return;
17699 
17700  query = createPQExpBuffer();
17701 
17702  /* refclassid constraint is redundant but may speed the search */
17703  appendPQExpBufferStr(query, "SELECT "
17704  "classid, objid, refobjid "
17705  "FROM pg_depend "
17706  "WHERE refclassid = 'pg_extension'::regclass "
17707  "AND deptype = 'e' "
17708  "ORDER BY 3");
17709 
17710  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
17711 
17712  ntups = PQntuples(res);
17713 
17714  i_classid = PQfnumber(res, "classid");
17715  i_objid = PQfnumber(res, "objid");
17716  i_refobjid = PQfnumber(res, "refobjid");
17717 
17718  extmembers = (ExtensionMemberId *) pg_malloc(ntups * sizeof(ExtensionMemberId));
17719  nextmembers = 0;
17720 
17721  /*
17722  * Accumulate data into extmembers[].
17723  *
17724  * Since we ordered the SELECT by referenced ID, we can expect that
17725  * multiple entries for the same extension will appear together; this
17726  * saves on searches.
17727  */
17728  ext = NULL;
17729 
17730  for (i = 0; i < ntups; i++)
17731  {
17732  CatalogId objId;
17733  Oid extId;
17734 
17735  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
17736  objId.oid = atooid(PQgetvalue(res, i, i_objid));
17737  extId = atooid(PQgetvalue(res, i, i_refobjid));
17738 
17739  if (ext == NULL ||
17740  ext->dobj.catId.oid != extId)
17741  ext = findExtensionByOid(extId);
17742 
17743  if (ext == NULL)
17744  {
17745  /* shouldn't happen */
17746  pg_log_warning("could not find referenced extension %u", extId);
17747  continue;
17748  }
17749 
17750  extmembers[nextmembers].catId = objId;
17751  extmembers[nextmembers].ext = ext;
17752  nextmembers++;
17753  }
17754 
17755  PQclear(res);
17756 
17757  /* Remember the data for use later */
17758  setExtensionMembership(extmembers, nextmembers);
17759 
17760  destroyPQExpBuffer(query);
17761 }
ExtensionInfo * ext
Definition: pg_dump.h:640
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:639
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 4815 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().

4816 {
4817  DumpOptions *dopt = fout->dopt;
4818  PGresult *res;
4819  int ntups;
4820  int i;
4821  PQExpBuffer query;
4822  ExtensionInfo *extinfo;
4823  int i_tableoid;
4824  int i_oid;
4825  int i_extname;
4826  int i_nspname;
4827  int i_extrelocatable;
4828  int i_extversion;
4829  int i_extconfig;
4830  int i_extcondition;
4831 
4832  /*
4833  * Before 9.1, there are no extensions.
4834  */
4835  if (fout->remoteVersion < 90100)
4836  {
4837  *numExtensions = 0;
4838  return NULL;
4839  }
4840 
4841  query = createPQExpBuffer();
4842 
4843  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
4844  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
4845  "FROM pg_extension x "
4846  "JOIN pg_namespace n ON n.oid = x.extnamespace");
4847 
4848  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4849 
4850  ntups = PQntuples(res);
4851 
4852  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
4853 
4854  i_tableoid = PQfnumber(res, "tableoid");
4855  i_oid = PQfnumber(res, "oid");
4856  i_extname = PQfnumber(res, "extname");
4857  i_nspname = PQfnumber(res, "nspname");
4858  i_extrelocatable = PQfnumber(res, "extrelocatable");
4859  i_extversion = PQfnumber(res, "extversion");
4860  i_extconfig = PQfnumber(res, "extconfig");
4861  i_extcondition = PQfnumber(res, "extcondition");
4862 
4863  for (i = 0; i < ntups; i++)
4864  {
4865  extinfo[i].dobj.objType = DO_EXTENSION;
4866  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4867  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4868  AssignDumpId(&extinfo[i].dobj);
4869  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
4870  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
4871  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
4872  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
4873  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
4874  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
4875 
4876  /* Decide whether we want to dump it */
4877  selectDumpableExtension(&(extinfo[i]), dopt);
4878  }
4879 
4880  PQclear(res);
4881  destroyPQExpBuffer(query);
4882 
4883  *numExtensions = ntups;
4884 
4885  return extinfo;
4886 }
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 9179 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().

9180 {
9181  DumpOptions *dopt = fout->dopt;
9182  PGresult *res;
9183  int ntups;
9184  int i;
9185  PQExpBuffer query;
9186  FdwInfo *fdwinfo;
9187  int i_tableoid;
9188  int i_oid;
9189  int i_fdwname;
9190  int i_rolname;
9191  int i_fdwhandler;
9192  int i_fdwvalidator;
9193  int i_fdwacl;
9194  int i_rfdwacl;
9195  int i_initfdwacl;
9196  int i_initrfdwacl;
9197  int i_fdwoptions;
9198 
9199  /* Before 8.4, there are no foreign-data wrappers */
9200  if (fout->remoteVersion < 80400)
9201  {
9202  *numForeignDataWrappers = 0;
9203  return NULL;
9204  }
9205 
9206  query = createPQExpBuffer();
9207 
9208  if (fout->remoteVersion >= 90600)
9209  {
9210  PQExpBuffer acl_subquery = createPQExpBuffer();
9211  PQExpBuffer racl_subquery = createPQExpBuffer();
9212  PQExpBuffer initacl_subquery = createPQExpBuffer();
9213  PQExpBuffer initracl_subquery = createPQExpBuffer();
9214 
9215  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9216  initracl_subquery, "f.fdwacl", "f.fdwowner", "'F'",
9217  dopt->binary_upgrade);
9218 
9219  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.fdwname, "
9220  "(%s f.fdwowner) AS rolname, "
9221  "f.fdwhandler::pg_catalog.regproc, "
9222  "f.fdwvalidator::pg_catalog.regproc, "
9223  "%s AS fdwacl, "
9224  "%s AS rfdwacl, "
9225  "%s AS initfdwacl, "
9226  "%s AS initrfdwacl, "
9227  "array_to_string(ARRAY("
9228  "SELECT quote_ident(option_name) || ' ' || "
9229  "quote_literal(option_value) "
9230  "FROM pg_options_to_table(f.fdwoptions) "
9231  "ORDER BY option_name"
9232  "), E',\n ') AS fdwoptions "
9233  "FROM pg_foreign_data_wrapper f "
9234  "LEFT JOIN pg_init_privs pip ON "
9235  "(f.oid = pip.objoid "
9236  "AND pip.classoid = 'pg_foreign_data_wrapper'::regclass "
9237  "AND pip.objsubid = 0) ",
9239  acl_subquery->data,
9240  racl_subquery->data,
9241  initacl_subquery->data,
9242  initracl_subquery->data);
9243 
9244  destroyPQExpBuffer(acl_subquery);
9245  destroyPQExpBuffer(racl_subquery);
9246  destroyPQExpBuffer(initacl_subquery);
9247  destroyPQExpBuffer(initracl_subquery);
9248  }
9249  else if (fout->remoteVersion >= 90100)
9250  {
9251  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
9252  "(%s fdwowner) AS rolname, "
9253  "fdwhandler::pg_catalog.regproc, "
9254  "fdwvalidator::pg_catalog.regproc, fdwacl, "
9255  "NULL as rfdwacl, "
9256  "NULL as initfdwacl, NULL AS initrfdwacl, "
9257  "array_to_string(ARRAY("
9258  "SELECT quote_ident(option_name) || ' ' || "
9259  "quote_literal(option_value) "
9260  "FROM pg_options_to_table(fdwoptions) "
9261  "ORDER BY option_name"
9262  "), E',\n ') AS fdwoptions "
9263  "FROM pg_foreign_data_wrapper",
9265  }
9266  else
9267  {
9268  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
9269  "(%s fdwowner) AS rolname, "
9270  "'-' AS fdwhandler, "
9271  "fdwvalidator::pg_catalog.regproc, fdwacl, "
9272  "NULL as rfdwacl, "
9273  "NULL as initfdwacl, NULL AS initrfdwacl, "
9274  "array_to_string(ARRAY("
9275  "SELECT quote_ident(option_name) || ' ' || "
9276  "quote_literal(option_value) "
9277  "FROM pg_options_to_table(fdwoptions) "
9278  "ORDER BY option_name"
9279  "), E',\n ') AS fdwoptions "
9280  "FROM pg_foreign_data_wrapper",
9282  }
9283 
9284  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9285 
9286  ntups = PQntuples(res);
9287  *numForeignDataWrappers = ntups;
9288 
9289  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
9290 
9291  i_tableoid = PQfnumber(res, "tableoid");
9292  i_oid = PQfnumber(res, "oid");
9293  i_fdwname = PQfnumber(res, "fdwname");
9294  i_rolname = PQfnumber(res, "rolname");
9295  i_fdwhandler = PQfnumber(res, "fdwhandler");
9296  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
9297  i_fdwacl = PQfnumber(res, "fdwacl");
9298  i_rfdwacl = PQfnumber(res, "rfdwacl");
9299  i_initfdwacl = PQfnumber(res, "initfdwacl");
9300  i_initrfdwacl = PQfnumber(res, "initrfdwacl");
9301  i_fdwoptions = PQfnumber(res, "fdwoptions");
9302 
9303  for (i = 0; i < ntups; i++)
9304  {
9305  fdwinfo[i].dobj.objType = DO_FDW;
9306  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9307  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9308  AssignDumpId(&fdwinfo[i].dobj);
9309  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
9310  fdwinfo[i].dobj.namespace = NULL;
9311  fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
9312  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
9313  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
9314  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
9315  fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
9316  fdwinfo[i].rfdwacl = pg_strdup(PQgetvalue(res, i, i_rfdwacl));
9317  fdwinfo[i].initfdwacl = pg_strdup(PQgetvalue(res, i, i_initfdwacl));
9318  fdwinfo[i].initrfdwacl = pg_strdup(PQgetvalue(res, i, i_initrfdwacl));
9319 
9320  /* Decide whether we want to dump it */
9321  selectDumpableObject(&(fdwinfo[i].dobj), fout);
9322 
9323  /* Do not try to dump ACL if no ACL exists. */
9324  if (PQgetisnull(res, i, i_fdwacl) && PQgetisnull(res, i, i_rfdwacl) &&
9325  PQgetisnull(res, i, i_initfdwacl) &&
9326  PQgetisnull(res, i, i_initrfdwacl))
9327  fdwinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9328  }
9329 
9330  PQclear(res);
9331 
9332  destroyPQExpBuffer(query);
9333 
9334  return fdwinfo;
9335 }
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 9345 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().

9346 {
9347  DumpOptions *dopt = fout->dopt;
9348  PGresult *res;
9349  int ntups;
9350  int i;
9351  PQExpBuffer query;
9352  ForeignServerInfo *srvinfo;
9353  int i_tableoid;
9354  int i_oid;
9355  int i_srvname;
9356  int i_rolname;
9357  int i_srvfdw;
9358  int i_srvtype;
9359  int i_srvversion;
9360  int i_srvacl;
9361  int i_rsrvacl;
9362  int i_initsrvacl;
9363  int i_initrsrvacl;
9364  int i_srvoptions;
9365 
9366  /* Before 8.4, there are no foreign servers */
9367  if (fout->remoteVersion < 80400)
9368  {
9369  *numForeignServers = 0;
9370  return NULL;
9371  }
9372 
9373  query = createPQExpBuffer();
9374 
9375  if (fout->remoteVersion >= 90600)
9376  {
9377  PQExpBuffer acl_subquery = createPQExpBuffer();
9378  PQExpBuffer racl_subquery = createPQExpBuffer();
9379  PQExpBuffer initacl_subquery = createPQExpBuffer();
9380  PQExpBuffer initracl_subquery = createPQExpBuffer();
9381 
9382  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9383  initracl_subquery, "f.srvacl", "f.srvowner", "'S'",
9384  dopt->binary_upgrade);
9385 
9386  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.srvname, "
9387  "(%s f.srvowner) AS rolname, "
9388  "f.srvfdw, f.srvtype, f.srvversion, "
9389  "%s AS srvacl, "
9390  "%s AS rsrvacl, "
9391  "%s AS initsrvacl, "
9392  "%s AS initrsrvacl, "
9393  "array_to_string(ARRAY("
9394  "SELECT quote_ident(option_name) || ' ' || "
9395  "quote_literal(option_value) "
9396  "FROM pg_options_to_table(f.srvoptions) "
9397  "ORDER BY option_name"
9398  "), E',\n ') AS srvoptions "
9399  "FROM pg_foreign_server f "
9400  "LEFT JOIN pg_init_privs pip "
9401  "ON (f.oid = pip.objoid "
9402  "AND pip.classoid = 'pg_foreign_server'::regclass "
9403  "AND pip.objsubid = 0) ",
9405  acl_subquery->data,
9406  racl_subquery->data,
9407  initacl_subquery->data,
9408  initracl_subquery->data);
9409 
9410  destroyPQExpBuffer(acl_subquery);
9411  destroyPQExpBuffer(racl_subquery);
9412  destroyPQExpBuffer(initacl_subquery);
9413  destroyPQExpBuffer(initracl_subquery);
9414  }
9415  else
9416  {
9417  appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
9418  "(%s srvowner) AS rolname, "
9419  "srvfdw, srvtype, srvversion, srvacl, "
9420  "NULL AS rsrvacl, "
9421  "NULL AS initsrvacl, NULL AS initrsrvacl, "
9422  "array_to_string(ARRAY("
9423  "SELECT quote_ident(option_name) || ' ' || "
9424  "quote_literal(option_value) "
9425  "FROM pg_options_to_table(srvoptions) "
9426  "ORDER BY option_name"
9427  "), E',\n ') AS srvoptions "
9428  "FROM pg_foreign_server",
9430  }
9431 
9432  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9433 
9434  ntups = PQntuples(res);
9435  *numForeignServers = ntups;
9436 
9437  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
9438 
9439  i_tableoid = PQfnumber(res, "tableoid");
9440  i_oid = PQfnumber(res, "oid");
9441  i_srvname = PQfnumber(res, "srvname");
9442  i_rolname = PQfnumber(res, "rolname");
9443  i_srvfdw = PQfnumber(res, "srvfdw");
9444  i_srvtype = PQfnumber(res, "srvtype");
9445  i_srvversion = PQfnumber(res, "srvversion");
9446  i_srvacl = PQfnumber(res, "srvacl");
9447  i_rsrvacl = PQfnumber(res, "rsrvacl");
9448  i_initsrvacl = PQfnumber(res, "initsrvacl");
9449  i_initrsrvacl = PQfnumber(res, "initrsrvacl");
9450  i_srvoptions = PQfnumber(res, "srvoptions");
9451 
9452  for (i = 0; i < ntups; i++)
9453  {
9454  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
9455  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9456  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9457  AssignDumpId(&srvinfo[i].dobj);
9458  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
9459  srvinfo[i].dobj.namespace = NULL;
9460  srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
9461  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
9462  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
9463  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
9464  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
9465  srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl));
9466  srvinfo[i].rsrvacl = pg_strdup(PQgetvalue(res, i, i_rsrvacl));
9467  srvinfo[i].initsrvacl = pg_strdup(PQgetvalue(res, i, i_initsrvacl));
9468  srvinfo[i].initrsrvacl = pg_strdup(PQgetvalue(res, i, i_initrsrvacl));
9469 
9470  /* Decide whether we want to dump it */
9471  selectDumpableObject(&(srvinfo[i].dobj), fout);
9472 
9473  /* Do not try to dump ACL if no ACL exists. */
9474  if (PQgetisnull(res, i, i_srvacl) && PQgetisnull(res, i, i_rsrvacl) &&
9475  PQgetisnull(res, i, i_initsrvacl) &&
9476  PQgetisnull(res, i, i_initrsrvacl))
9477  srvinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9478  }
9479 
9480  PQclear(res);
9481 
9482  destroyPQExpBuffer(query);
9483 
9484  return srvinfo;
9485 }
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 5812 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().

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

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

6944 {
6945  PGresult *res;
6946  int ntups;
6947  int i;
6948  PQExpBuffer query = createPQExpBuffer();
6949  InhInfo *inhinfo;
6950 
6951  int i_inhrelid;
6952  int i_inhparent;
6953 
6954  /*
6955  * Find all the inheritance information, excluding implicit inheritance
6956  * via partitioning.
6957  */
6958  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
6959 
6960  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6961 
6962  ntups = PQntuples(res);
6963 
6964  *numInherits = ntups;
6965 
6966  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6967 
6968  i_inhrelid = PQfnumber(res, "inhrelid");
6969  i_inhparent = PQfnumber(res, "inhparent");
6970 
6971  for (i = 0; i < ntups; i++)
6972  {
6973  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6974  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6975  }
6976 
6977  PQclear(res);
6978 
6979  destroyPQExpBuffer(query);
6980 
6981  return inhinfo;
6982 }
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 4669 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().

4670 {
4671  DumpOptions *dopt = fout->dopt;
4672  PGresult *res;
4673  int ntups;
4674  int i;
4675  PQExpBuffer query;
4676  NamespaceInfo *nsinfo;
4677  int i_tableoid;
4678  int i_oid;
4679  int i_nspname;
4680  int i_rolname;
4681  int i_nspacl;
4682  int i_rnspacl;
4683  int i_initnspacl;
4684  int i_initrnspacl;
4685 
4686  query = createPQExpBuffer();
4687 
4688  /*
4689  * we fetch all namespaces including system ones, so that every object we
4690  * read in can be linked to a containing namespace.
4691  */
4692  if (fout->remoteVersion >= 90600)
4693  {
4694  PQExpBuffer acl_subquery = createPQExpBuffer();
4695  PQExpBuffer racl_subquery = createPQExpBuffer();
4696  PQExpBuffer init_acl_subquery = createPQExpBuffer();
4697  PQExpBuffer init_racl_subquery = createPQExpBuffer();
4698 
4699  buildACLQueries(acl_subquery, racl_subquery, init_acl_subquery,
4700  init_racl_subquery, "n.nspacl", "n.nspowner", "'n'",
4701  dopt->binary_upgrade);
4702 
4703  appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, "
4704  "(%s nspowner) AS rolname, "
4705  "%s as nspacl, "
4706  "%s as rnspacl, "
4707  "%s as initnspacl, "
4708  "%s as initrnspacl "
4709  "FROM pg_namespace n "
4710  "LEFT JOIN pg_init_privs pip "
4711  "ON (n.oid = pip.objoid "
4712  "AND pip.classoid = 'pg_namespace'::regclass "
4713  "AND pip.objsubid = 0",
4715  acl_subquery->data,
4716  racl_subquery->data,
4717  init_acl_subquery->data,
4718  init_racl_subquery->data);
4719 
4720  appendPQExpBufferStr(query, ") ");
4721 
4722  destroyPQExpBuffer(acl_subquery);
4723  destroyPQExpBuffer(racl_subquery);
4724  destroyPQExpBuffer(init_acl_subquery);
4725  destroyPQExpBuffer(init_racl_subquery);
4726  }
4727  else
4728  appendPQExpBuffer(query, "SELECT tableoid, oid, nspname, "
4729  "(%s nspowner) AS rolname, "
4730  "nspacl, NULL as rnspacl, "
4731  "NULL AS initnspacl, NULL as initrnspacl "
4732  "FROM pg_namespace",
4734 
4735  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4736 
4737  ntups = PQntuples(res);
4738 
4739  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
4740 
4741  i_tableoid = PQfnumber(res, "tableoid");
4742  i_oid = PQfnumber(res, "oid");
4743  i_nspname = PQfnumber(res, "nspname");
4744  i_rolname = PQfnumber(res, "rolname");
4745  i_nspacl = PQfnumber(res, "nspacl");
4746  i_rnspacl = PQfnumber(res, "rnspacl");
4747  i_initnspacl = PQfnumber(res, "initnspacl");
4748  i_initrnspacl = PQfnumber(res, "initrnspacl");
4749 
4750  for (i = 0; i < ntups; i++)
4751  {
4752  nsinfo[i].dobj.objType = DO_NAMESPACE;
4753  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4754  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4755  AssignDumpId(&nsinfo[i].dobj);
4756  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
4757  nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4758  nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl));
4759  nsinfo[i].rnspacl = pg_strdup(PQgetvalue(res, i, i_rnspacl));
4760  nsinfo[i].initnspacl = pg_strdup(PQgetvalue(res, i, i_initnspacl));
4761  nsinfo[i].initrnspacl = pg_strdup(PQgetvalue(res, i, i_initrnspacl));
4762 
4763  /* Decide whether to dump this namespace */
4764  selectDumpableNamespace(&nsinfo[i], fout);
4765 
4766  /*
4767  * Do not try to dump ACL if the ACL is empty or the default.
4768  *
4769  * This is useful because, for some schemas/objects, the only
4770  * component we are going to try and dump is the ACL and if we can
4771  * remove that then 'dump' goes to zero/false and we don't consider
4772  * this object for dumping at all later on.
4773  */
4774  if (PQgetisnull(res, i, i_nspacl) && PQgetisnull(res, i, i_rnspacl) &&
4775  PQgetisnull(res, i, i_initnspacl) &&
4776  PQgetisnull(res, i, i_initrnspacl))
4777  nsinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4778 
4779  if (strlen(nsinfo[i].rolname) == 0)
4780  pg_log_warning("owner of schema \"%s\" appears to be invalid",
4781  nsinfo[i].dobj.name);
4782  }
4783 
4784  PQclear(res);
4785  destroyPQExpBuffer(query);
4786 
4787  *numNamespaces = ntups;
4788 
4789  return nsinfo;
4790 }
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 5459 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().

5460 {
5461  PGresult *res;
5462  int ntups;
5463  int i;
5464  PQExpBuffer query = createPQExpBuffer();
5465  OpclassInfo *opcinfo;
5466  int i_tableoid;
5467  int i_oid;
5468  int i_opcname;
5469  int i_opcnamespace;
5470  int i_rolname;
5471 
5472  /*
5473  * find all opclasses, including builtin opclasses; we filter out
5474  * system-defined opclasses at dump-out time.
5475  */
5476 
5477  appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
5478  "opcnamespace, "
5479  "(%s opcowner) AS rolname "
5480  "FROM pg_opclass",
5482 
5483  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5484 
5485  ntups = PQntuples(res);
5486  *numOpclasses = ntups;
5487 
5488  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
5489 
5490  i_tableoid = PQfnumber(res, "tableoid");
5491  i_oid = PQfnumber(res, "oid");
5492  i_opcname = PQfnumber(res, "opcname");
5493  i_opcnamespace = PQfnumber(res, "opcnamespace");
5494  i_rolname = PQfnumber(res, "rolname");
5495 
5496  for (i = 0; i < ntups; i++)
5497  {
5498  opcinfo[i].dobj.objType = DO_OPCLASS;
5499  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5500  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5501  AssignDumpId(&opcinfo[i].dobj);
5502  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
5503  opcinfo[i].dobj.namespace =
5504  findNamespace(fout,
5505  atooid(PQgetvalue(res, i, i_opcnamespace)));
5506  opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5507 
5508  /* Decide whether we want to dump it */
5509  selectDumpableObject(&(opcinfo[i].dobj), fout);
5510 
5511  /* Op Classes do not currently have ACLs. */
5512  opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5513 
5514  if (strlen(opcinfo[i].rolname) == 0)
5515  pg_log_warning("owner of operator class \"%s\" appears to be invalid",
5516  opcinfo[i].dobj.name);
5517  }
5518 
5519  PQclear(res);
5520 
5521  destroyPQExpBuffer(query);
5522 
5523  return opcinfo;
5524 }
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:4797
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 5149 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().

5150 {
5151  PGresult *res;
5152  int ntups;
5153  int i;
5154  PQExpBuffer query = createPQExpBuffer();
5155  OprInfo *oprinfo;
5156  int i_tableoid;
5157  int i_oid;
5158  int i_oprname;
5159  int i_oprnamespace;
5160  int i_rolname;
5161  int i_oprkind;
5162  int i_oprcode;
5163 
5164  /*
5165  * find all operators, including builtin operators; we filter out
5166  * system-defined operators at dump-out time.
5167  */
5168 
5169  appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
5170  "oprnamespace, "
5171  "(%s oprowner) AS rolname, "
5172  "oprkind, "
5173  "oprcode::oid AS oprcode "
5174  "FROM pg_operator",
5176 
5177  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5178 
5179  ntups = PQntuples(res);
5180  *numOprs = ntups;
5181 
5182  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
5183 
5184  i_tableoid = PQfnumber(res, "tableoid");
5185  i_oid = PQfnumber(res, "oid");
5186  i_oprname = PQfnumber(res, "oprname");
5187  i_oprnamespace = PQfnumber(res, "oprnamespace");
5188  i_rolname = PQfnumber(res, "rolname");
5189  i_oprkind = PQfnumber(res, "oprkind");
5190  i_oprcode = PQfnumber(res, "oprcode");
5191 
5192  for (i = 0; i < ntups; i++)
5193  {
5194  oprinfo[i].dobj.objType = DO_OPERATOR;
5195  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5196  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5197  AssignDumpId(&oprinfo[i].dobj);
5198  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
5199  oprinfo[i].dobj.namespace =
5200  findNamespace(fout,
5201  atooid(PQgetvalue(res, i, i_oprnamespace)));
5202  oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5203  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
5204  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
5205 
5206  /* Decide whether we want to dump it */
5207  selectDumpableObject(&(oprinfo[i].dobj), fout);
5208 
5209  /* Operators do not currently have ACLs. */
5210  oprinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5211 
5212  if (strlen(oprinfo[i].rolname) == 0)
5213  pg_log_warning("owner of operator \"%s\" appears to be invalid",
5214  oprinfo[i].dobj.name);
5215  }
5216 
5217  PQclear(res);
5218 
5219  destroyPQExpBuffer(query);
5220 
5221  return oprinfo;
5222 }
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:4797
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 5534 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().

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