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)
 

Variables

char g_comment_start [10]
 
char g_comment_end [10]
 
char g_opaque_type [10]
 

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 781 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().

782 {
783  if (dobj->nDeps >= dobj->allocDeps)
784  {
785  if (dobj->allocDeps <= 0)
786  {
787  dobj->allocDeps = 16;
788  dobj->dependencies = (DumpId *)
789  pg_malloc(dobj->allocDeps * sizeof(DumpId));
790  }
791  else
792  {
793  dobj->allocDeps *= 2;
794  dobj->dependencies = (DumpId *)
795  pg_realloc(dobj->dependencies,
796  dobj->allocDeps * sizeof(DumpId));
797  }
798  }
799  dobj->dependencies[dobj->nDeps++] = refId;
800 }
int DumpId
Definition: pg_backup.h:234
DumpId * dependencies
Definition: pg_dump.h:135
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::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->dependencies = NULL;
553  dobj->nDeps = 0;
554  dobj->allocDeps = 0;
555 
556  while (dobj->dumpId >= allocedDumpIds)
557  {
558  int newAlloc;
559 
560  if (allocedDumpIds <= 0)
561  {
562  newAlloc = 256;
564  pg_malloc(newAlloc * sizeof(DumpableObject *));
565  }
566  else
567  {
568  newAlloc = allocedDumpIds * 2;
570  pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
571  }
572  memset(dumpIdMap + allocedDumpIds, 0,
573  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
574  allocedDumpIds = newAlloc;
575  }
576  dumpIdMap[dobj->dumpId] = dobj;
577 
578  /* mark catalogIdMap invalid, but don't rebuild it yet */
579  catalogIdMapValid = false;
580 }
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:135
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
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 872 of file common.c.

References findObjectByOid(), and numCollations.

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

873 {
875 }
static DumpableObject ** collinfoindex
Definition: common.c:52
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:678
static int numCollations
Definition: common.c:59

◆ findExtensionByOid()

ExtensionInfo* findExtensionByOid ( Oid  oid)

Definition at line 894 of file common.c.

References findObjectByOid(), and numExtensions.

Referenced by getExtensionMembership().

895 {
897 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:678
static int numExtensions
Definition: common.c:61
static DumpableObject ** extinfoindex
Definition: common.c:54

◆ findFuncByOid()

FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 850 of file common.c.

References findObjectByOid(), and numFuncs.

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

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

◆ findNamespaceByOid()

NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 883 of file common.c.

References findObjectByOid(), and numNamespaces.

Referenced by findNamespace().

884 {
886 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:678
static int numNamespaces
Definition: common.c:60
static DumpableObject ** nspinfoindex
Definition: common.c:53

◆ findObjectByCatalogId()

DumpableObject* findObjectByCatalogId ( CatalogId  catalogId)

Definition at line 627 of file common.c.

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

Referenced by buildMatViewRefreshDependencies(), and getDependencies().

628 {
629  DumpableObject **low;
630  DumpableObject **high;
631 
632  if (!catalogIdMapValid)
633  {
634  if (catalogIdMap)
637  if (numCatalogIds > 1)
638  qsort((void *) catalogIdMap, numCatalogIds,
640  catalogIdMapValid = true;
641  }
642 
643  /*
644  * We could use bsearch() here, but the notational cruft of calling
645  * bsearch is nearly as bad as doing it ourselves; and the generalized
646  * bsearch function is noticeably slower as well.
647  */
648  if (numCatalogIds <= 0)
649  return NULL;
650  low = catalogIdMap;
651  high = catalogIdMap + (numCatalogIds - 1);
652  while (low <= high)
653  {
654  DumpableObject **middle;
655  int difference;
656 
657  middle = low + (high - low) / 2;
658  /* comparison must match DOCatalogIdCompare, below */
659  difference = oidcmp((*middle)->catId.oid, catalogId.oid);
660  if (difference == 0)
661  difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid);
662  if (difference == 0)
663  return *middle;
664  else if (difference < 0)
665  low = middle + 1;
666  else
667  high = middle - 1;
668  }
669  return NULL;
670 }
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:737
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:488
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition: common.c:759

◆ findObjectByDumpId()

DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 609 of file common.c.

References allocedDumpIds.

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

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

◆ findOprByOid()

OprInfo* findOprByOid ( Oid  oid)

Definition at line 861 of file common.c.

References findObjectByOid(), and numOperators.

Referenced by getFormattedOperatorName().

862 {
864 }
static DumpableObject ** oprinfoindex
Definition: common.c:51
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:678
static int numOperators
Definition: common.c:58

◆ findOwningExtension()

ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 933 of file common.c.

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

Referenced by checkExtensionMembership().

934 {
935  ExtensionMemberId *low;
936  ExtensionMemberId *high;
937 
938  /*
939  * We could use bsearch() here, but the notational cruft of calling
940  * bsearch is nearly as bad as doing it ourselves; and the generalized
941  * bsearch function is noticeably slower as well.
942  */
943  if (numextmembers <= 0)
944  return NULL;
945  low = extmembers;
946  high = extmembers + (numextmembers - 1);
947  while (low <= high)
948  {
949  ExtensionMemberId *middle;
950  int difference;
951 
952  middle = low + (high - low) / 2;
953  /* comparison must match ExtensionMemberIdCompare, below */
954  difference = oidcmp(middle->catId.oid, catalogId.oid);
955  if (difference == 0)
956  difference = oidcmp(middle->catId.tableoid, catalogId.tableoid);
957  if (difference == 0)
958  return middle->ext;
959  else if (difference < 0)
960  low = middle + 1;
961  else
962  high = middle - 1;
963  }
964  return NULL;
965 }
ExtensionInfo * ext
Definition: pg_dump.h:636
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:635

◆ findTableByOid()

TableInfo* findTableByOid ( Oid  oid)

Definition at line 828 of file common.c.

References findObjectByOid(), and numTables.

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

829 {
831 }
static int numTables
Definition: common.c:55
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:678
static DumpableObject ** tblinfoindex
Definition: common.c:48

◆ findTypeByOid()

TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 839 of file common.c.

References findObjectByOid(), and numTypes.

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

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

◆ getAccessMethods()

AccessMethodInfo* getAccessMethods ( Archive fout,
int *  numAccessMethods 
)

Definition at line 5233 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().

5234 {
5235  PGresult *res;
5236  int ntups;
5237  int i;
5238  PQExpBuffer query;
5239  AccessMethodInfo *aminfo;
5240  int i_tableoid;
5241  int i_oid;
5242  int i_amname;
5243  int i_amhandler;
5244  int i_amtype;
5245 
5246  /* Before 9.6, there are no user-defined access methods */
5247  if (fout->remoteVersion < 90600)
5248  {
5249  *numAccessMethods = 0;
5250  return NULL;
5251  }
5252 
5253  query = createPQExpBuffer();
5254 
5255  /* Select all access methods from pg_am table */
5256  appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, amtype, "
5257  "amhandler::pg_catalog.regproc AS amhandler "
5258  "FROM pg_am");
5259 
5260  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5261 
5262  ntups = PQntuples(res);
5263  *numAccessMethods = ntups;
5264 
5265  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
5266 
5267  i_tableoid = PQfnumber(res, "tableoid");
5268  i_oid = PQfnumber(res, "oid");
5269  i_amname = PQfnumber(res, "amname");
5270  i_amhandler = PQfnumber(res, "amhandler");
5271  i_amtype = PQfnumber(res, "amtype");
5272 
5273  for (i = 0; i < ntups; i++)
5274  {
5275  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
5276  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5277  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5278  AssignDumpId(&aminfo[i].dobj);
5279  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
5280  aminfo[i].dobj.namespace = NULL;
5281  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
5282  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
5283 
5284  /* Decide whether we want to dump it */
5285  selectDumpableAccessMethod(&(aminfo[i]), fout);
5286 
5287  /* Access methods do not currently have ACLs. */
5288  aminfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5289  }
5290 
5291  PQclear(res);
5292 
5293  destroyPQExpBuffer(query);
5294 
5295  return aminfo;
5296 }
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:224
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:1694
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:226
#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 5466 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().

5467 {
5468  DumpOptions *dopt = fout->dopt;
5469  PGresult *res;
5470  int ntups;
5471  int i;
5472  PQExpBuffer query = createPQExpBuffer();
5473  AggInfo *agginfo;
5474  int i_tableoid;
5475  int i_oid;
5476  int i_aggname;
5477  int i_aggnamespace;
5478  int i_pronargs;
5479  int i_proargtypes;
5480  int i_rolname;
5481  int i_aggacl;
5482  int i_raggacl;
5483  int i_initaggacl;
5484  int i_initraggacl;
5485 
5486  /*
5487  * Find all interesting aggregates. See comment in getFuncs() for the
5488  * rationale behind the filtering logic.
5489  */
5490  if (fout->remoteVersion >= 90600)
5491  {
5492  PQExpBuffer acl_subquery = createPQExpBuffer();
5493  PQExpBuffer racl_subquery = createPQExpBuffer();
5494  PQExpBuffer initacl_subquery = createPQExpBuffer();
5495  PQExpBuffer initracl_subquery = createPQExpBuffer();
5496  const char *agg_check;
5497 
5498  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5499  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5500  dopt->binary_upgrade);
5501 
5502  agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
5503  : "p.proisagg");
5504 
5505  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5506  "p.proname AS aggname, "
5507  "p.pronamespace AS aggnamespace, "
5508  "p.pronargs, p.proargtypes, "
5509  "(%s p.proowner) AS rolname, "
5510  "%s AS aggacl, "
5511  "%s AS raggacl, "
5512  "%s AS initaggacl, "
5513  "%s AS initraggacl "
5514  "FROM pg_proc p "
5515  "LEFT JOIN pg_init_privs pip ON "
5516  "(p.oid = pip.objoid "
5517  "AND pip.classoid = 'pg_proc'::regclass "
5518  "AND pip.objsubid = 0) "
5519  "WHERE %s AND ("
5520  "p.pronamespace != "
5521  "(SELECT oid FROM pg_namespace "
5522  "WHERE nspname = 'pg_catalog') OR "
5523  "p.proacl IS DISTINCT FROM pip.initprivs",
5525  acl_subquery->data,
5526  racl_subquery->data,
5527  initacl_subquery->data,
5528  initracl_subquery->data,
5529  agg_check);
5530  if (dopt->binary_upgrade)
5531  appendPQExpBufferStr(query,
5532  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5533  "classid = 'pg_proc'::regclass AND "
5534  "objid = p.oid AND "
5535  "refclassid = 'pg_extension'::regclass AND "
5536  "deptype = 'e')");
5537  appendPQExpBufferChar(query, ')');
5538 
5539  destroyPQExpBuffer(acl_subquery);
5540  destroyPQExpBuffer(racl_subquery);
5541  destroyPQExpBuffer(initacl_subquery);
5542  destroyPQExpBuffer(initracl_subquery);
5543  }
5544  else if (fout->remoteVersion >= 80200)
5545  {
5546  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5547  "pronamespace AS aggnamespace, "
5548  "pronargs, proargtypes, "
5549  "(%s proowner) AS rolname, "
5550  "proacl AS aggacl, "
5551  "NULL AS raggacl, "
5552  "NULL AS initaggacl, NULL AS initraggacl "
5553  "FROM pg_proc p "
5554  "WHERE proisagg AND ("
5555  "pronamespace != "
5556  "(SELECT oid FROM pg_namespace "
5557  "WHERE nspname = 'pg_catalog')",
5559  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5560  appendPQExpBufferStr(query,
5561  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5562  "classid = 'pg_proc'::regclass AND "
5563  "objid = p.oid AND "
5564  "refclassid = 'pg_extension'::regclass AND "
5565  "deptype = 'e')");
5566  appendPQExpBufferChar(query, ')');
5567  }
5568  else
5569  {
5570  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5571  "pronamespace AS aggnamespace, "
5572  "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
5573  "proargtypes, "
5574  "(%s proowner) AS rolname, "
5575  "proacl AS aggacl, "
5576  "NULL AS raggacl, "
5577  "NULL AS initaggacl, NULL AS initraggacl "
5578  "FROM pg_proc "
5579  "WHERE proisagg "
5580  "AND pronamespace != "
5581  "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
5583  }
5584 
5585  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5586 
5587  ntups = PQntuples(res);
5588  *numAggs = ntups;
5589 
5590  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5591 
5592  i_tableoid = PQfnumber(res, "tableoid");
5593  i_oid = PQfnumber(res, "oid");
5594  i_aggname = PQfnumber(res, "aggname");
5595  i_aggnamespace = PQfnumber(res, "aggnamespace");
5596  i_pronargs = PQfnumber(res, "pronargs");
5597  i_proargtypes = PQfnumber(res, "proargtypes");
5598  i_rolname = PQfnumber(res, "rolname");
5599  i_aggacl = PQfnumber(res, "aggacl");
5600  i_raggacl = PQfnumber(res, "raggacl");
5601  i_initaggacl = PQfnumber(res, "initaggacl");
5602  i_initraggacl = PQfnumber(res, "initraggacl");
5603 
5604  for (i = 0; i < ntups; i++)
5605  {
5606  agginfo[i].aggfn.dobj.objType = DO_AGG;
5607  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5608  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5609  AssignDumpId(&agginfo[i].aggfn.dobj);
5610  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5611  agginfo[i].aggfn.dobj.namespace =
5612  findNamespace(fout,
5613  atooid(PQgetvalue(res, i, i_aggnamespace)));
5614  agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5615  if (strlen(agginfo[i].aggfn.rolname) == 0)
5616  pg_log_warning("owner of aggregate function \"%s\" appears to be invalid",
5617  agginfo[i].aggfn.dobj.name);
5618  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5619  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5620  agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5621  agginfo[i].aggfn.rproacl = pg_strdup(PQgetvalue(res, i, i_raggacl));
5622  agginfo[i].aggfn.initproacl = pg_strdup(PQgetvalue(res, i, i_initaggacl));
5623  agginfo[i].aggfn.initrproacl = pg_strdup(PQgetvalue(res, i, i_initraggacl));
5624  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5625  if (agginfo[i].aggfn.nargs == 0)
5626  agginfo[i].aggfn.argtypes = NULL;
5627  else
5628  {
5629  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5630  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5631  agginfo[i].aggfn.argtypes,
5632  agginfo[i].aggfn.nargs);
5633  }
5634 
5635  /* Decide whether we want to dump it */
5636  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5637 
5638  /* Do not try to dump ACL if no ACL exists. */
5639  if (PQgetisnull(res, i, i_aggacl) && PQgetisnull(res, i, i_raggacl) &&
5640  PQgetisnull(res, i, i_initaggacl) &&
5641  PQgetisnull(res, i, i_initraggacl))
5642  agginfo[i].aggfn.dobj.dump &= ~DUMP_COMPONENT_ACL;
5643  }
5644 
5645  PQclear(res);
5646 
5647  destroyPQExpBuffer(query);
5648 
5649  return agginfo;
5650 }
Oid * argtypes
Definition: pg_dump.h:199
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:1760
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:198
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4645
char * initrproacl
Definition: pg_dump.h:204
Oid lang
Definition: pg_dump.h:197
DumpableObject dobj
Definition: pg_dump.h:195
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
FuncInfo aggfn
Definition: pg_dump.h:210
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:95
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1048
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:200
char * initproacl
Definition: pg_dump.h:203
char * rolname
Definition: pg_dump.h:196
char * proacl
Definition: pg_dump.h:201
char * rproacl
Definition: pg_dump.h:202
#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 8045 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().

8046 {
8047  PGresult *res;
8048  int ntups;
8049  int i;
8050  PQExpBuffer query = createPQExpBuffer();
8051  CastInfo *castinfo;
8052  int i_tableoid;
8053  int i_oid;
8054  int i_castsource;
8055  int i_casttarget;
8056  int i_castfunc;
8057  int i_castcontext;
8058  int i_castmethod;
8059 
8060  if (fout->remoteVersion >= 80400)
8061  {
8062  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8063  "castsource, casttarget, castfunc, castcontext, "
8064  "castmethod "
8065  "FROM pg_cast ORDER BY 3,4");
8066  }
8067  else
8068  {
8069  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8070  "castsource, casttarget, castfunc, castcontext, "
8071  "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
8072  "FROM pg_cast ORDER BY 3,4");
8073  }
8074 
8075  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8076 
8077  ntups = PQntuples(res);
8078 
8079  *numCasts = ntups;
8080 
8081  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
8082 
8083  i_tableoid = PQfnumber(res, "tableoid");
8084  i_oid = PQfnumber(res, "oid");
8085  i_castsource = PQfnumber(res, "castsource");
8086  i_casttarget = PQfnumber(res, "casttarget");
8087  i_castfunc = PQfnumber(res, "castfunc");
8088  i_castcontext = PQfnumber(res, "castcontext");
8089  i_castmethod = PQfnumber(res, "castmethod");
8090 
8091  for (i = 0; i < ntups; i++)
8092  {
8093  PQExpBufferData namebuf;
8094  TypeInfo *sTypeInfo;
8095  TypeInfo *tTypeInfo;
8096 
8097  castinfo[i].dobj.objType = DO_CAST;
8098  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8099  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8100  AssignDumpId(&castinfo[i].dobj);
8101  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
8102  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
8103  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
8104  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
8105  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
8106 
8107  /*
8108  * Try to name cast as concatenation of typnames. This is only used
8109  * for purposes of sorting. If we fail to find either type, the name
8110  * will be an empty string.
8111  */
8112  initPQExpBuffer(&namebuf);
8113  sTypeInfo = findTypeByOid(castinfo[i].castsource);
8114  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
8115  if (sTypeInfo && tTypeInfo)
8116  appendPQExpBuffer(&namebuf, "%s %s",
8117  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
8118  castinfo[i].dobj.name = namebuf.data;
8119 
8120  /* Decide whether we want to dump it */
8121  selectDumpableCast(&(castinfo[i]), fout);
8122 
8123  /* Casts do not currently have ACLs. */
8124  castinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8125  }
8126 
8127  PQclear(res);
8128 
8129  destroyPQExpBuffer(query);
8130 
8131  return castinfo;
8132 }
char * name
Definition: pg_dump.h:130
Oid castsource
Definition: pg_dump.h:470
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:1636
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:472
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:469
Oid casttarget
Definition: pg_dump.h:471
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:162
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:474
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:839
DumpableObjectType objType
Definition: pg_dump.h:127
char castcontext
Definition: pg_dump.h:473
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 5080 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().

5081 {
5082  PGresult *res;
5083  int ntups;
5084  int i;
5085  PQExpBuffer query;
5086  CollInfo *collinfo;
5087  int i_tableoid;
5088  int i_oid;
5089  int i_collname;
5090  int i_collnamespace;
5091  int i_rolname;
5092 
5093  /* Collations didn't exist pre-9.1 */
5094  if (fout->remoteVersion < 90100)
5095  {
5096  *numCollations = 0;
5097  return NULL;
5098  }
5099 
5100  query = createPQExpBuffer();
5101 
5102  /*
5103  * find all collations, including builtin collations; we filter out
5104  * system-defined collations at dump-out time.
5105  */
5106 
5107  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
5108  "collnamespace, "
5109  "(%s collowner) AS rolname "
5110  "FROM pg_collation",
5112 
5113  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5114 
5115  ntups = PQntuples(res);
5116  *numCollations = ntups;
5117 
5118  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
5119 
5120  i_tableoid = PQfnumber(res, "tableoid");
5121  i_oid = PQfnumber(res, "oid");
5122  i_collname = PQfnumber(res, "collname");
5123  i_collnamespace = PQfnumber(res, "collnamespace");
5124  i_rolname = PQfnumber(res, "rolname");
5125 
5126  for (i = 0; i < ntups; i++)
5127  {
5128  collinfo[i].dobj.objType = DO_COLLATION;
5129  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5130  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5131  AssignDumpId(&collinfo[i].dobj);
5132  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
5133  collinfo[i].dobj.namespace =
5134  findNamespace(fout,
5135  atooid(PQgetvalue(res, i, i_collnamespace)));
5136  collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5137 
5138  /* Decide whether we want to dump it */
5139  selectDumpableObject(&(collinfo[i].dobj), fout);
5140 
5141  /* Collations do not currently have ACLs. */
5142  collinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5143  }
5144 
5145  PQclear(res);
5146 
5147  destroyPQExpBuffer(query);
5148 
5149  return collinfo;
5150 }
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:1760
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:4645
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
DumpableObject dobj
Definition: pg_dump.h:243
char * rolname
Definition: pg_dump.h:244
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:95
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 7246 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().

7247 {
7248  int i,
7249  j;
7250  ConstraintInfo *constrinfo;
7251  PQExpBuffer query;
7252  PGresult *res;
7253  int i_contableoid,
7254  i_conoid,
7255  i_conname,
7256  i_confrelid,
7257  i_conindid,
7258  i_condef;
7259  int ntups;
7260 
7261  query = createPQExpBuffer();
7262 
7263  for (i = 0; i < numTables; i++)
7264  {
7265  TableInfo *tbinfo = &tblinfo[i];
7266 
7267  /*
7268  * For partitioned tables, foreign keys have no triggers so they must
7269  * be included anyway in case some foreign keys are defined.
7270  */
7271  if ((!tbinfo->hastriggers &&
7272  tbinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7273  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
7274  continue;
7275 
7276  pg_log_info("reading foreign key constraints for table \"%s.%s\"",
7277  tbinfo->dobj.namespace->dobj.name,
7278  tbinfo->dobj.name);
7279 
7280  resetPQExpBuffer(query);
7281  if (fout->remoteVersion >= 110000)
7282  appendPQExpBuffer(query,
7283  "SELECT tableoid, oid, conname, confrelid, conindid, "
7284  "pg_catalog.pg_get_constraintdef(oid) AS condef "
7285  "FROM pg_catalog.pg_constraint "
7286  "WHERE conrelid = '%u'::pg_catalog.oid "
7287  "AND conparentid = 0 "
7288  "AND contype = 'f'",
7289  tbinfo->dobj.catId.oid);
7290  else
7291  appendPQExpBuffer(query,
7292  "SELECT tableoid, oid, conname, confrelid, 0 as conindid, "
7293  "pg_catalog.pg_get_constraintdef(oid) AS condef "
7294  "FROM pg_catalog.pg_constraint "
7295  "WHERE conrelid = '%u'::pg_catalog.oid "
7296  "AND contype = 'f'",
7297  tbinfo->dobj.catId.oid);
7298  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7299 
7300  ntups = PQntuples(res);
7301 
7302  i_contableoid = PQfnumber(res, "tableoid");
7303  i_conoid = PQfnumber(res, "oid");
7304  i_conname = PQfnumber(res, "conname");
7305  i_confrelid = PQfnumber(res, "confrelid");
7306  i_conindid = PQfnumber(res, "conindid");
7307  i_condef = PQfnumber(res, "condef");
7308 
7309  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7310 
7311  for (j = 0; j < ntups; j++)
7312  {
7313  TableInfo *reftable;
7314 
7315  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
7316  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7317  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7318  AssignDumpId(&constrinfo[j].dobj);
7319  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7320  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7321  constrinfo[j].contable = tbinfo;
7322  constrinfo[j].condomain = NULL;
7323  constrinfo[j].contype = 'f';
7324  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7325  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
7326  constrinfo[j].conindex = 0;
7327  constrinfo[j].condeferrable = false;
7328  constrinfo[j].condeferred = false;
7329  constrinfo[j].conislocal = true;
7330  constrinfo[j].separate = true;
7331 
7332  /*
7333  * Restoring an FK that points to a partitioned table requires
7334  * that all partition indexes have been attached beforehand.
7335  * Ensure that happens by making the constraint depend on each
7336  * index partition attach object.
7337  */
7338  reftable = findTableByOid(constrinfo[j].confrelid);
7339  if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
7340  {
7341  IndxInfo *refidx;
7342  Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
7343 
7344  if (indexOid != InvalidOid)
7345  {
7346  for (int k = 0; k < reftable->numIndexes; k++)
7347  {
7348  SimplePtrListCell *cell;
7349 
7350  /* not our index? */
7351  if (reftable->indexes[k].dobj.catId.oid != indexOid)
7352  continue;
7353 
7354  refidx = &reftable->indexes[k];
7355  for (cell = refidx->partattaches.head; cell;
7356  cell = cell->next)
7357  addObjectDependency(&constrinfo[j].dobj,
7358  ((DumpableObject *)
7359  cell->ptr)->dumpId);
7360  break;
7361  }
7362  }
7363  }
7364  }
7365 
7366  PQclear(res);
7367  }
7368 
7369  destroyPQExpBuffer(query);
7370 }
char * name
Definition: pg_dump.h:130
TableInfo * findTableByOid(Oid oid)
Definition: common.c:828
char relkind
Definition: pg_dump.h:264
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:274
static int numTables
Definition: common.c:55
unsigned int Oid
Definition: postgres_ext.h:31
DumpId conindex
Definition: pg_dump.h:446
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
DumpableObject dobj
Definition: pg_dump.h:258
char * condef
Definition: pg_dump.h:444
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:440
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:447
TypeInfo * condomain
Definition: pg_dump.h:442
bool conislocal
Definition: pg_dump.h:449
SimplePtrList partattaches
Definition: pg_dump.h:370
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int numIndexes
Definition: pg_dump.h:331
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
TableInfo * contable
Definition: pg_dump.h:441
#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:448
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:781
struct _indxInfo * indexes
Definition: pg_dump.h:332
CatalogId catId
Definition: pg_dump.h:128
SimplePtrListCell * head
Definition: simple_list.h:54
DumpableObject dobj
Definition: pg_dump.h:356
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 5160 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().

5161 {
5162  PGresult *res;
5163  int ntups;
5164  int i;
5165  PQExpBuffer query;
5166  ConvInfo *convinfo;
5167  int i_tableoid;
5168  int i_oid;
5169  int i_conname;
5170  int i_connamespace;
5171  int i_rolname;
5172 
5173  query = createPQExpBuffer();
5174 
5175  /*
5176  * find all conversions, including builtin conversions; we filter out
5177  * system-defined conversions at dump-out time.
5178  */
5179 
5180  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
5181  "connamespace, "
5182  "(%s conowner) AS rolname "
5183  "FROM pg_conversion",
5185 
5186  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5187 
5188  ntups = PQntuples(res);
5189  *numConversions = ntups;
5190 
5191  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
5192 
5193  i_tableoid = PQfnumber(res, "tableoid");
5194  i_oid = PQfnumber(res, "oid");
5195  i_conname = PQfnumber(res, "conname");
5196  i_connamespace = PQfnumber(res, "connamespace");
5197  i_rolname = PQfnumber(res, "rolname");
5198 
5199  for (i = 0; i < ntups; i++)
5200  {
5201  convinfo[i].dobj.objType = DO_CONVERSION;
5202  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5203  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5204  AssignDumpId(&convinfo[i].dobj);
5205  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
5206  convinfo[i].dobj.namespace =
5207  findNamespace(fout,
5208  atooid(PQgetvalue(res, i, i_connamespace)));
5209  convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5210 
5211  /* Decide whether we want to dump it */
5212  selectDumpableObject(&(convinfo[i].dobj), fout);
5213 
5214  /* Conversions do not currently have ACLs. */
5215  convinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5216  }
5217 
5218  PQclear(res);
5219 
5220  destroyPQExpBuffer(query);
5221 
5222  return convinfo;
5223 }
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:1760
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:4645
char * rolname
Definition: pg_dump.h:250
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:95
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:249
#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 9357 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().

9358 {
9359  DumpOptions *dopt = fout->dopt;
9360  DefaultACLInfo *daclinfo;
9361  PQExpBuffer query;
9362  PGresult *res;
9363  int i_oid;
9364  int i_tableoid;
9365  int i_defaclrole;
9366  int i_defaclnamespace;
9367  int i_defaclobjtype;
9368  int i_defaclacl;
9369  int i_rdefaclacl;
9370  int i_initdefaclacl;
9371  int i_initrdefaclacl;
9372  int i,
9373  ntups;
9374 
9375  if (fout->remoteVersion < 90000)
9376  {
9377  *numDefaultACLs = 0;
9378  return NULL;
9379  }
9380 
9381  query = createPQExpBuffer();
9382 
9383  if (fout->remoteVersion >= 90600)
9384  {
9385  PQExpBuffer acl_subquery = createPQExpBuffer();
9386  PQExpBuffer racl_subquery = createPQExpBuffer();
9387  PQExpBuffer initacl_subquery = createPQExpBuffer();
9388  PQExpBuffer initracl_subquery = createPQExpBuffer();
9389 
9390  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9391  initracl_subquery, "defaclacl", "defaclrole",
9392  "CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
9393  dopt->binary_upgrade);
9394 
9395  appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
9396  "(%s d.defaclrole) AS defaclrole, "
9397  "d.defaclnamespace, "
9398  "d.defaclobjtype, "
9399  "%s AS defaclacl, "
9400  "%s AS rdefaclacl, "
9401  "%s AS initdefaclacl, "
9402  "%s AS initrdefaclacl "
9403  "FROM pg_default_acl d "
9404  "LEFT JOIN pg_init_privs pip ON "
9405  "(d.oid = pip.objoid "
9406  "AND pip.classoid = 'pg_default_acl'::regclass "
9407  "AND pip.objsubid = 0) ",
9409  acl_subquery->data,
9410  racl_subquery->data,
9411  initacl_subquery->data,
9412  initracl_subquery->data);
9413  }
9414  else
9415  {
9416  appendPQExpBuffer(query, "SELECT oid, tableoid, "
9417  "(%s defaclrole) AS defaclrole, "
9418  "defaclnamespace, "
9419  "defaclobjtype, "
9420  "defaclacl, "
9421  "NULL AS rdefaclacl, "
9422  "NULL AS initdefaclacl, "
9423  "NULL AS initrdefaclacl "
9424  "FROM pg_default_acl",
9426  }
9427 
9428  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9429 
9430  ntups = PQntuples(res);
9431  *numDefaultACLs = ntups;
9432 
9433  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9434 
9435  i_oid = PQfnumber(res, "oid");
9436  i_tableoid = PQfnumber(res, "tableoid");
9437  i_defaclrole = PQfnumber(res, "defaclrole");
9438  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9439  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9440  i_defaclacl = PQfnumber(res, "defaclacl");
9441  i_rdefaclacl = PQfnumber(res, "rdefaclacl");
9442  i_initdefaclacl = PQfnumber(res, "initdefaclacl");
9443  i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
9444 
9445  for (i = 0; i < ntups; i++)
9446  {
9447  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9448 
9449  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9450  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9451  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9452  AssignDumpId(&daclinfo[i].dobj);
9453  /* cheesy ... is it worth coming up with a better object name? */
9454  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9455 
9456  if (nspid != InvalidOid)
9457  daclinfo[i].dobj.namespace = findNamespace(fout, nspid);
9458  else
9459  daclinfo[i].dobj.namespace = NULL;
9460 
9461  daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
9462  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9463  daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9464  daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
9465  daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
9466  daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
9467 
9468  /* Decide whether we want to dump it */
9469  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9470  }
9471 
9472  PQclear(res);
9473 
9474  destroyPQExpBuffer(query);
9475 
9476  return daclinfo;
9477 }
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:4645
char * rdefaclacl
Definition: pg_dump.h:558
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:1614
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:554
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:95
char * defaclacl
Definition: pg_dump.h:557
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:559
CatalogId catId
Definition: pg_dump.h:128
char * initrdefaclacl
Definition: pg_dump.h:560
int i
char defaclobjtype
Definition: pg_dump.h:556
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:555

◆ getDumpableObjects()

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

Definition at line 759 of file common.c.

References allocedDumpIds, i, and pg_malloc().

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

760 {
761  int i,
762  j;
763 
764  *objs = (DumpableObject **)
766  j = 0;
767  for (i = 1; i < allocedDumpIds; i++)
768  {
769  if (dumpIdMap[i])
770  (*objs)[j++] = dumpIdMap[i];
771  }
772  *numObjs = j;
773 }
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 7776 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().

7777 {
7778  int i;
7779  PQExpBuffer query;
7780  PGresult *res;
7781  EventTriggerInfo *evtinfo;
7782  int i_tableoid,
7783  i_oid,
7784  i_evtname,
7785  i_evtevent,
7786  i_evtowner,
7787  i_evttags,
7788  i_evtfname,
7789  i_evtenabled;
7790  int ntups;
7791 
7792  /* Before 9.3, there are no event triggers */
7793  if (fout->remoteVersion < 90300)
7794  {
7795  *numEventTriggers = 0;
7796  return NULL;
7797  }
7798 
7799  query = createPQExpBuffer();
7800 
7801  appendPQExpBuffer(query,
7802  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
7803  "evtevent, (%s evtowner) AS evtowner, "
7804  "array_to_string(array("
7805  "select quote_literal(x) "
7806  " from unnest(evttags) as t(x)), ', ') as evttags, "
7807  "e.evtfoid::regproc as evtfname "
7808  "FROM pg_event_trigger e "
7809  "ORDER BY e.oid",
7811 
7812  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7813 
7814  ntups = PQntuples(res);
7815 
7816  *numEventTriggers = ntups;
7817 
7818  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
7819 
7820  i_tableoid = PQfnumber(res, "tableoid");
7821  i_oid = PQfnumber(res, "oid");
7822  i_evtname = PQfnumber(res, "evtname");
7823  i_evtevent = PQfnumber(res, "evtevent");
7824  i_evtowner = PQfnumber(res, "evtowner");
7825  i_evttags = PQfnumber(res, "evttags");
7826  i_evtfname = PQfnumber(res, "evtfname");
7827  i_evtenabled = PQfnumber(res, "evtenabled");
7828 
7829  for (i = 0; i < ntups; i++)
7830  {
7831  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
7832  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7833  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7834  AssignDumpId(&evtinfo[i].dobj);
7835  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
7836  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
7837  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
7838  evtinfo[i].evtowner = pg_strdup(PQgetvalue(res, i, i_evtowner));
7839  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
7840  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
7841  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
7842 
7843  /* Decide whether we want to dump it */
7844  selectDumpableObject(&(evtinfo[i].dobj), fout);
7845 
7846  /* Event Triggers do not currently have ACLs. */
7847  evtinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7848  }
7849 
7850  PQclear(res);
7851 
7852  destroyPQExpBuffer(query);
7853 
7854  return evtinfo;
7855 }
char * name
Definition: pg_dump.h:130
char * evtevent
Definition: pg_dump.h:423
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1760
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:424
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:95
char * evtfname
Definition: pg_dump.h:426
char * evttags
Definition: pg_dump.h:425
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
char * evtname
Definition: pg_dump.h:422
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:421
char evtenabled
Definition: pg_dump.h:427
#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 7168 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().

7169 {
7170  PQExpBuffer query;
7171  PGresult *res;
7172  StatsExtInfo *statsextinfo;
7173  int ntups;
7174  int i_tableoid;
7175  int i_oid;
7176  int i_stxname;
7177  int i_stxnamespace;
7178  int i_rolname;
7179  int i_stattarget;
7180  int i;
7181 
7182  /* Extended statistics were new in v10 */
7183  if (fout->remoteVersion < 100000)
7184  return;
7185 
7186  query = createPQExpBuffer();
7187 
7188  if (fout->remoteVersion < 130000)
7189  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7190  "stxnamespace, (%s stxowner) AS rolname, (-1) AS stxstattarget "
7191  "FROM pg_catalog.pg_statistic_ext",
7193  else
7194  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7195  "stxnamespace, (%s stxowner) AS rolname, stxstattarget "
7196  "FROM pg_catalog.pg_statistic_ext",
7198 
7199  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7200 
7201  ntups = PQntuples(res);
7202 
7203  i_tableoid = PQfnumber(res, "tableoid");
7204  i_oid = PQfnumber(res, "oid");
7205  i_stxname = PQfnumber(res, "stxname");
7206  i_stxnamespace = PQfnumber(res, "stxnamespace");
7207  i_rolname = PQfnumber(res, "rolname");
7208  i_stattarget = PQfnumber(res, "stxstattarget");
7209 
7210  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
7211 
7212  for (i = 0; i < ntups; i++)
7213  {
7214  statsextinfo[i].dobj.objType = DO_STATSEXT;
7215  statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7216  statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7217  AssignDumpId(&statsextinfo[i].dobj);
7218  statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
7219  statsextinfo[i].dobj.namespace =
7220  findNamespace(fout,
7221  atooid(PQgetvalue(res, i, i_stxnamespace)));
7222  statsextinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
7223  statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
7224 
7225  /* Decide whether we want to dump it */
7226  selectDumpableObject(&(statsextinfo[i].dobj), fout);
7227 
7228  /* Stats objects do not currently have ACLs. */
7229  statsextinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7230  }
7231 
7232  PQclear(res);
7233  destroyPQExpBuffer(query);
7234 }
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:1760
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:4645
DumpableObject dobj
Definition: pg_dump.h:385
int stattarget
Definition: pg_dump.h:387
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:95
char * rolname
Definition: pg_dump.h:386
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 17688 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().

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

4664 {
4665  DumpOptions *dopt = fout->dopt;
4666  PGresult *res;
4667  int ntups;
4668  int i;
4669  PQExpBuffer query;
4670  ExtensionInfo *extinfo;
4671  int i_tableoid;
4672  int i_oid;
4673  int i_extname;
4674  int i_nspname;
4675  int i_extrelocatable;
4676  int i_extversion;
4677  int i_extconfig;
4678  int i_extcondition;
4679 
4680  /*
4681  * Before 9.1, there are no extensions.
4682  */
4683  if (fout->remoteVersion < 90100)
4684  {
4685  *numExtensions = 0;
4686  return NULL;
4687  }
4688 
4689  query = createPQExpBuffer();
4690 
4691  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
4692  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
4693  "FROM pg_extension x "
4694  "JOIN pg_namespace n ON n.oid = x.extnamespace");
4695 
4696  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4697 
4698  ntups = PQntuples(res);
4699 
4700  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
4701 
4702  i_tableoid = PQfnumber(res, "tableoid");
4703  i_oid = PQfnumber(res, "oid");
4704  i_extname = PQfnumber(res, "extname");
4705  i_nspname = PQfnumber(res, "nspname");
4706  i_extrelocatable = PQfnumber(res, "extrelocatable");
4707  i_extversion = PQfnumber(res, "extversion");
4708  i_extconfig = PQfnumber(res, "extconfig");
4709  i_extcondition = PQfnumber(res, "extcondition");
4710 
4711  for (i = 0; i < ntups; i++)
4712  {
4713  extinfo[i].dobj.objType = DO_EXTENSION;
4714  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4715  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4716  AssignDumpId(&extinfo[i].dobj);
4717  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
4718  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
4719  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
4720  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
4721  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
4722  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
4723 
4724  /* Decide whether we want to dump it */
4725  selectDumpableExtension(&(extinfo[i]), dopt);
4726  }
4727 
4728  PQclear(res);
4729  destroyPQExpBuffer(query);
4730 
4731  *numExtensions = ntups;
4732 
4733  return extinfo;
4734 }
char * name
Definition: pg_dump.h:130
DumpableObject dobj
Definition: pg_dump.h:152
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:156
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:1721
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:157
CatalogId catId
Definition: pg_dump.h:128
int i
DumpableObjectType objType
Definition: pg_dump.h:127
bool relocatable
Definition: pg_dump.h:153
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:155

◆ getForeignDataWrappers()

FdwInfo* getForeignDataWrappers ( Archive fout,
int *  numForeignDataWrappers 
)

Definition at line 9041 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().

9042 {
9043  DumpOptions *dopt = fout->dopt;
9044  PGresult *res;
9045  int ntups;
9046  int i;
9047  PQExpBuffer query;
9048  FdwInfo *fdwinfo;
9049  int i_tableoid;
9050  int i_oid;
9051  int i_fdwname;
9052  int i_rolname;
9053  int i_fdwhandler;
9054  int i_fdwvalidator;
9055  int i_fdwacl;
9056  int i_rfdwacl;
9057  int i_initfdwacl;
9058  int i_initrfdwacl;
9059  int i_fdwoptions;
9060 
9061  /* Before 8.4, there are no foreign-data wrappers */
9062  if (fout->remoteVersion < 80400)
9063  {
9064  *numForeignDataWrappers = 0;
9065  return NULL;
9066  }
9067 
9068  query = createPQExpBuffer();
9069 
9070  if (fout->remoteVersion >= 90600)
9071  {
9072  PQExpBuffer acl_subquery = createPQExpBuffer();
9073  PQExpBuffer racl_subquery = createPQExpBuffer();
9074  PQExpBuffer initacl_subquery = createPQExpBuffer();
9075  PQExpBuffer initracl_subquery = createPQExpBuffer();
9076 
9077  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9078  initracl_subquery, "f.fdwacl", "f.fdwowner", "'F'",
9079  dopt->binary_upgrade);
9080 
9081  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.fdwname, "
9082  "(%s f.fdwowner) AS rolname, "
9083  "f.fdwhandler::pg_catalog.regproc, "
9084  "f.fdwvalidator::pg_catalog.regproc, "
9085  "%s AS fdwacl, "
9086  "%s AS rfdwacl, "
9087  "%s AS initfdwacl, "
9088  "%s AS initrfdwacl, "
9089  "array_to_string(ARRAY("
9090  "SELECT quote_ident(option_name) || ' ' || "
9091  "quote_literal(option_value) "
9092  "FROM pg_options_to_table(f.fdwoptions) "
9093  "ORDER BY option_name"
9094  "), E',\n ') AS fdwoptions "
9095  "FROM pg_foreign_data_wrapper f "
9096  "LEFT JOIN pg_init_privs pip ON "
9097  "(f.oid = pip.objoid "
9098  "AND pip.classoid = 'pg_foreign_data_wrapper'::regclass "
9099  "AND pip.objsubid = 0) ",
9101  acl_subquery->data,
9102  racl_subquery->data,
9103  initacl_subquery->data,
9104  initracl_subquery->data);
9105 
9106  destroyPQExpBuffer(acl_subquery);
9107  destroyPQExpBuffer(racl_subquery);
9108  destroyPQExpBuffer(initacl_subquery);
9109  destroyPQExpBuffer(initracl_subquery);
9110  }
9111  else if (fout->remoteVersion >= 90100)
9112  {
9113  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
9114  "(%s fdwowner) AS rolname, "
9115  "fdwhandler::pg_catalog.regproc, "
9116  "fdwvalidator::pg_catalog.regproc, fdwacl, "
9117  "NULL as rfdwacl, "
9118  "NULL as initfdwacl, NULL AS initrfdwacl, "
9119  "array_to_string(ARRAY("
9120  "SELECT quote_ident(option_name) || ' ' || "
9121  "quote_literal(option_value) "
9122  "FROM pg_options_to_table(fdwoptions) "
9123  "ORDER BY option_name"
9124  "), E',\n ') AS fdwoptions "
9125  "FROM pg_foreign_data_wrapper",
9127  }
9128  else
9129  {
9130  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
9131  "(%s fdwowner) AS rolname, "
9132  "'-' AS fdwhandler, "
9133  "fdwvalidator::pg_catalog.regproc, fdwacl, "
9134  "NULL as rfdwacl, "
9135  "NULL as initfdwacl, NULL AS initrfdwacl, "
9136  "array_to_string(ARRAY("
9137  "SELECT quote_ident(option_name) || ' ' || "
9138  "quote_literal(option_value) "
9139  "FROM pg_options_to_table(fdwoptions) "
9140  "ORDER BY option_name"
9141  "), E',\n ') AS fdwoptions "
9142  "FROM pg_foreign_data_wrapper",
9144  }
9145 
9146  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9147 
9148  ntups = PQntuples(res);
9149  *numForeignDataWrappers = ntups;
9150 
9151  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
9152 
9153  i_tableoid = PQfnumber(res, "tableoid");
9154  i_oid = PQfnumber(res, "oid");
9155  i_fdwname = PQfnumber(res, "fdwname");
9156  i_rolname = PQfnumber(res, "rolname");
9157  i_fdwhandler = PQfnumber(res, "fdwhandler");
9158  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
9159  i_fdwacl = PQfnumber(res, "fdwacl");
9160  i_rfdwacl = PQfnumber(res, "rfdwacl");
9161  i_initfdwacl = PQfnumber(res, "initfdwacl");
9162  i_initrfdwacl = PQfnumber(res, "initrfdwacl");
9163  i_fdwoptions = PQfnumber(res, "fdwoptions");
9164 
9165  for (i = 0; i < ntups; i++)
9166  {
9167  fdwinfo[i].dobj.objType = DO_FDW;
9168  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9169  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9170  AssignDumpId(&fdwinfo[i].dobj);
9171  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
9172  fdwinfo[i].dobj.namespace = NULL;
9173  fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
9174  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
9175  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
9176  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
9177  fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
9178  fdwinfo[i].rfdwacl = pg_strdup(PQgetvalue(res, i, i_rfdwacl));
9179  fdwinfo[i].initfdwacl = pg_strdup(PQgetvalue(res, i, i_initfdwacl));
9180  fdwinfo[i].initrfdwacl = pg_strdup(PQgetvalue(res, i, i_initrfdwacl));
9181 
9182  /* Decide whether we want to dump it */
9183  selectDumpableObject(&(fdwinfo[i].dobj), fout);
9184 
9185  /* Do not try to dump ACL if no ACL exists. */
9186  if (PQgetisnull(res, i, i_fdwacl) && PQgetisnull(res, i, i_rfdwacl) &&
9187  PQgetisnull(res, i, i_initfdwacl) &&
9188  PQgetisnull(res, i, i_initrfdwacl))
9189  fdwinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9190  }
9191 
9192  PQclear(res);
9193 
9194  destroyPQExpBuffer(query);
9195 
9196  return fdwinfo;
9197 }
char * name
Definition: pg_dump.h:130
char * rfdwacl
Definition: pg_dump.h:533
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1760
Oid tableoid
Definition: pg_backup.h:230
char * fdwhandler
Definition: pg_dump.h:529
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:531
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:527
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:530
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:532
static const char * username_subquery
Definition: pg_dump.c:95
char * rolname
Definition: pg_dump.h:528
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:534
Definition: pg_dump.h:70
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
char * initrfdwacl
Definition: pg_dump.h:535
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 9207 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().

9208 {
9209  DumpOptions *dopt = fout->dopt;
9210  PGresult *res;
9211  int ntups;
9212  int i;
9213  PQExpBuffer query;
9214  ForeignServerInfo *srvinfo;
9215  int i_tableoid;
9216  int i_oid;
9217  int i_srvname;
9218  int i_rolname;
9219  int i_srvfdw;
9220  int i_srvtype;
9221  int i_srvversion;
9222  int i_srvacl;
9223  int i_rsrvacl;
9224  int i_initsrvacl;
9225  int i_initrsrvacl;
9226  int i_srvoptions;
9227 
9228  /* Before 8.4, there are no foreign servers */
9229  if (fout->remoteVersion < 80400)
9230  {
9231  *numForeignServers = 0;
9232  return NULL;
9233  }
9234 
9235  query = createPQExpBuffer();
9236 
9237  if (fout->remoteVersion >= 90600)
9238  {
9239  PQExpBuffer acl_subquery = createPQExpBuffer();
9240  PQExpBuffer racl_subquery = createPQExpBuffer();
9241  PQExpBuffer initacl_subquery = createPQExpBuffer();
9242  PQExpBuffer initracl_subquery = createPQExpBuffer();
9243 
9244  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9245  initracl_subquery, "f.srvacl", "f.srvowner", "'S'",
9246  dopt->binary_upgrade);
9247 
9248  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.srvname, "
9249  "(%s f.srvowner) AS rolname, "
9250  "f.srvfdw, f.srvtype, f.srvversion, "
9251  "%s AS srvacl, "
9252  "%s AS rsrvacl, "
9253  "%s AS initsrvacl, "
9254  "%s AS initrsrvacl, "
9255  "array_to_string(ARRAY("
9256  "SELECT quote_ident(option_name) || ' ' || "
9257  "quote_literal(option_value) "
9258  "FROM pg_options_to_table(f.srvoptions) "
9259  "ORDER BY option_name"
9260  "), E',\n ') AS srvoptions "
9261  "FROM pg_foreign_server f "
9262  "LEFT JOIN pg_init_privs pip "
9263  "ON (f.oid = pip.objoid "
9264  "AND pip.classoid = 'pg_foreign_server'::regclass "
9265  "AND pip.objsubid = 0) ",
9267  acl_subquery->data,
9268  racl_subquery->data,
9269  initacl_subquery->data,
9270  initracl_subquery->data);
9271 
9272  destroyPQExpBuffer(acl_subquery);
9273  destroyPQExpBuffer(racl_subquery);
9274  destroyPQExpBuffer(initacl_subquery);
9275  destroyPQExpBuffer(initracl_subquery);
9276  }
9277  else
9278  {
9279  appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
9280  "(%s srvowner) AS rolname, "
9281  "srvfdw, srvtype, srvversion, srvacl, "
9282  "NULL AS rsrvacl, "
9283  "NULL AS initsrvacl, NULL AS initrsrvacl, "
9284  "array_to_string(ARRAY("
9285  "SELECT quote_ident(option_name) || ' ' || "
9286  "quote_literal(option_value) "
9287  "FROM pg_options_to_table(srvoptions) "
9288  "ORDER BY option_name"
9289  "), E',\n ') AS srvoptions "
9290  "FROM pg_foreign_server",
9292  }
9293 
9294  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9295 
9296  ntups = PQntuples(res);
9297  *numForeignServers = ntups;
9298 
9299  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
9300 
9301  i_tableoid = PQfnumber(res, "tableoid");
9302  i_oid = PQfnumber(res, "oid");
9303  i_srvname = PQfnumber(res, "srvname");
9304  i_rolname = PQfnumber(res, "rolname");
9305  i_srvfdw = PQfnumber(res, "srvfdw");
9306  i_srvtype = PQfnumber(res, "srvtype");
9307  i_srvversion = PQfnumber(res, "srvversion");
9308  i_srvacl = PQfnumber(res, "srvacl");
9309  i_rsrvacl = PQfnumber(res, "rsrvacl");
9310  i_initsrvacl = PQfnumber(res, "initsrvacl");
9311  i_initrsrvacl = PQfnumber(res, "initrsrvacl");
9312  i_srvoptions = PQfnumber(res, "srvoptions");
9313 
9314  for (i = 0; i < ntups; i++)
9315  {
9316  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
9317  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9318  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9319  AssignDumpId(&srvinfo[i].dobj);
9320  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
9321  srvinfo[i].dobj.namespace = NULL;
9322  srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
9323  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
9324  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
9325  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
9326  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
9327  srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl));
9328  srvinfo[i].rsrvacl = pg_strdup(PQgetvalue(res, i, i_rsrvacl));
9329  srvinfo[i].initsrvacl = pg_strdup(PQgetvalue(res, i, i_initsrvacl));
9330  srvinfo[i].initrsrvacl = pg_strdup(PQgetvalue(res, i, i_initrsrvacl));
9331 
9332  /* Decide whether we want to dump it */
9333  selectDumpableObject(&(srvinfo[i].dobj), fout);
9334 
9335  /* Do not try to dump ACL if no ACL exists. */
9336  if (PQgetisnull(res, i, i_srvacl) && PQgetisnull(res, i, i_rsrvacl) &&
9337  PQgetisnull(res, i, i_initsrvacl) &&
9338  PQgetisnull(res, i, i_initrsrvacl))
9339  srvinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9340  }
9341 
9342  PQclear(res);
9343 
9344  destroyPQExpBuffer(query);
9345 
9346  return srvinfo;
9347 }
char * srvoptions
Definition: pg_dump.h:549
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:1760
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:548
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:95
char * srvversion
Definition: pg_dump.h:544
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:540
int i
char * initsrvacl
Definition: pg_dump.h:547
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 5660 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().

5661 {
5662  DumpOptions *dopt = fout->dopt;
5663  PGresult *res;
5664  int ntups;
5665  int i;
5666  PQExpBuffer query = createPQExpBuffer();
5667  FuncInfo *finfo;
5668  int i_tableoid;
5669  int i_oid;
5670  int i_proname;
5671  int i_pronamespace;
5672  int i_rolname;
5673  int i_prolang;
5674  int i_pronargs;
5675  int i_proargtypes;
5676  int i_prorettype;
5677  int i_proacl;
5678  int i_rproacl;
5679  int i_initproacl;
5680  int i_initrproacl;
5681 
5682  /*
5683  * Find all interesting functions. This is a bit complicated:
5684  *
5685  * 1. Always exclude aggregates; those are handled elsewhere.
5686  *
5687  * 2. Always exclude functions that are internally dependent on something
5688  * else, since presumably those will be created as a result of creating
5689  * the something else. This currently acts only to suppress constructor
5690  * functions for range types (so we only need it in 9.2 and up). Note
5691  * this is OK only because the constructors don't have any dependencies
5692  * the range type doesn't have; otherwise we might not get creation
5693  * ordering correct.
5694  *
5695  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
5696  * they're members of extensions and we are in binary-upgrade mode then
5697  * include them, since we want to dump extension members individually in
5698  * that mode. Also, if they are used by casts or transforms then we need
5699  * to gather the information about them, though they won't be dumped if
5700  * they are built-in. Also, in 9.6 and up, include functions in
5701  * pg_catalog if they have an ACL different from what's shown in
5702  * pg_init_privs.
5703  */
5704  if (fout->remoteVersion >= 90600)
5705  {
5706  PQExpBuffer acl_subquery = createPQExpBuffer();
5707  PQExpBuffer racl_subquery = createPQExpBuffer();
5708  PQExpBuffer initacl_subquery = createPQExpBuffer();
5709  PQExpBuffer initracl_subquery = createPQExpBuffer();
5710  const char *not_agg_check;
5711 
5712  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5713  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5714  dopt->binary_upgrade);
5715 
5716  not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
5717  : "NOT p.proisagg");
5718 
5719  appendPQExpBuffer(query,
5720  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
5721  "p.pronargs, p.proargtypes, p.prorettype, "
5722  "%s AS proacl, "
5723  "%s AS rproacl, "
5724  "%s AS initproacl, "
5725  "%s AS initrproacl, "
5726  "p.pronamespace, "
5727  "(%s p.proowner) AS rolname "
5728  "FROM pg_proc p "
5729  "LEFT JOIN pg_init_privs pip ON "
5730  "(p.oid = pip.objoid "
5731  "AND pip.classoid = 'pg_proc'::regclass "
5732  "AND pip.objsubid = 0) "
5733  "WHERE %s"
5734  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5735  "WHERE classid = 'pg_proc'::regclass AND "
5736  "objid = p.oid AND deptype = 'i')"
5737  "\n AND ("
5738  "\n pronamespace != "
5739  "(SELECT oid FROM pg_namespace "
5740  "WHERE nspname = 'pg_catalog')"
5741  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5742  "\n WHERE pg_cast.oid > %u "
5743  "\n AND p.oid = pg_cast.castfunc)"
5744  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5745  "\n WHERE pg_transform.oid > %u AND "
5746  "\n (p.oid = pg_transform.trffromsql"
5747  "\n OR p.oid = pg_transform.trftosql))",
5748  acl_subquery->data,
5749  racl_subquery->data,
5750  initacl_subquery->data,
5751  initracl_subquery->data,
5753  not_agg_check,
5756  if (dopt->binary_upgrade)
5757  appendPQExpBufferStr(query,
5758  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5759  "classid = 'pg_proc'::regclass AND "
5760  "objid = p.oid AND "
5761  "refclassid = 'pg_extension'::regclass AND "
5762  "deptype = 'e')");
5763  appendPQExpBufferStr(query,
5764  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
5765  appendPQExpBufferChar(query, ')');
5766 
5767  destroyPQExpBuffer(acl_subquery);
5768  destroyPQExpBuffer(racl_subquery);
5769  destroyPQExpBuffer(initacl_subquery);
5770  destroyPQExpBuffer(initracl_subquery);
5771  }
5772  else
5773  {
5774  appendPQExpBuffer(query,
5775  "SELECT tableoid, oid, proname, prolang, "
5776  "pronargs, proargtypes, prorettype, proacl, "
5777  "NULL as rproacl, "
5778  "NULL as initproacl, NULL AS initrproacl, "
5779  "pronamespace, "
5780  "(%s proowner) AS rolname "
5781  "FROM pg_proc p "
5782  "WHERE NOT proisagg",
5784  if (fout->remoteVersion >= 90200)
5785  appendPQExpBufferStr(query,
5786  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5787  "WHERE classid = 'pg_proc'::regclass AND "
5788  "objid = p.oid AND deptype = 'i')");
5789  appendPQExpBuffer(query,
5790  "\n AND ("
5791  "\n pronamespace != "
5792  "(SELECT oid FROM pg_namespace "
5793  "WHERE nspname = 'pg_catalog')"
5794  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5795  "\n WHERE pg_cast.oid > '%u'::oid"
5796  "\n AND p.oid = pg_cast.castfunc)",
5798 
5799  if (fout->remoteVersion >= 90500)
5800  appendPQExpBuffer(query,
5801  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5802  "\n WHERE pg_transform.oid > '%u'::oid"
5803  "\n AND (p.oid = pg_transform.trffromsql"
5804  "\n OR p.oid = pg_transform.trftosql))",
5806 
5807  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5808  appendPQExpBufferStr(query,
5809  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5810  "classid = 'pg_proc'::regclass AND "
5811  "objid = p.oid AND "
5812  "refclassid = 'pg_extension'::regclass AND "
5813  "deptype = 'e')");
5814  appendPQExpBufferChar(query, ')');
5815  }
5816 
5817  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5818 
5819  ntups = PQntuples(res);
5820 
5821  *numFuncs = ntups;
5822 
5823  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
5824 
5825  i_tableoid = PQfnumber(res, "tableoid");
5826  i_oid = PQfnumber(res, "oid");
5827  i_proname = PQfnumber(res, "proname");
5828  i_pronamespace = PQfnumber(res, "pronamespace");
5829  i_rolname = PQfnumber(res, "rolname");
5830  i_prolang = PQfnumber(res, "prolang");
5831  i_pronargs = PQfnumber(res, "pronargs");
5832  i_proargtypes = PQfnumber(res, "proargtypes");
5833  i_prorettype = PQfnumber(res, "prorettype");
5834  i_proacl = PQfnumber(res, "proacl");
5835  i_rproacl = PQfnumber(res, "rproacl");
5836  i_initproacl = PQfnumber(res, "initproacl");
5837  i_initrproacl = PQfnumber(res, "initrproacl");
5838 
5839  for (i = 0; i < ntups; i++)
5840  {
5841  finfo[i].dobj.objType = DO_FUNC;
5842  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5843  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5844  AssignDumpId(&finfo[i].dobj);
5845  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
5846  finfo[i].dobj.namespace =
5847  findNamespace(fout,
5848  atooid(PQgetvalue(res, i, i_pronamespace)));
5849  finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5850  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
5851  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
5852  finfo[i].proacl = pg_strdup(PQgetvalue(res, i, i_proacl));
5853  finfo[i].rproacl = pg_strdup(PQgetvalue(res, i, i_rproacl));
5854  finfo[i].initproacl = pg_strdup(PQgetvalue(res, i, i_initproacl));
5855  finfo[i].initrproacl = pg_strdup(PQgetvalue(res, i, i_initrproacl));
5856  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
5857  if (finfo[i].nargs == 0)
5858  finfo[i].argtypes = NULL;
5859  else
5860  {
5861  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
5862  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5863  finfo[i].argtypes, finfo[i].nargs);
5864  }
5865 
5866  /* Decide whether we want to dump it */
5867  selectDumpableObject(&(finfo[i].dobj), fout);
5868 
5869  /* Do not try to dump ACL if no ACL exists. */
5870  if (PQgetisnull(res, i, i_proacl) && PQgetisnull(res, i, i_rproacl) &&
5871  PQgetisnull(res, i, i_initproacl) &&
5872  PQgetisnull(res, i, i_initrproacl))
5873  finfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5874 
5875  if (strlen(finfo[i].rolname) == 0)
5876  pg_log_warning("owner of function \"%s\" appears to be invalid",
5877  finfo[i].dobj.name);
5878  }
5879 
5880  PQclear(res);
5881 
5882  destroyPQExpBuffer(query);
5883 
5884  return finfo;
5885 }
Oid * argtypes
Definition: pg_dump.h:199
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:1760
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:198
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:4645
static int numFuncs
Definition: common.c:57
char * initrproacl
Definition: pg_dump.h:204
Oid lang
Definition: pg_dump.h:197
DumpableObject dobj
Definition: pg_dump.h:195
unsigned int Oid
Definition: postgres_ext.h:31
static Oid g_last_builtin_oid
Definition: pg_dump.c:101
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:95
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1048
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:200
char * initproacl
Definition: pg_dump.h:203
char * rolname
Definition: pg_dump.h:196
char * proacl
Definition: pg_dump.h:201
char * rproacl
Definition: pg_dump.h:202
#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 6816 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().

6817 {
6818  int i,
6819  j;
6820  PQExpBuffer query = createPQExpBuffer();
6821  PGresult *res;
6822  IndxInfo *indxinfo;
6823  ConstraintInfo *constrinfo;
6824  int i_tableoid,
6825  i_oid,
6826  i_indexname,
6827  i_parentidx,
6828  i_indexdef,
6829  i_indnkeyatts,
6830  i_indnatts,
6831  i_indkey,
6832  i_indisclustered,
6833  i_indisreplident,
6834  i_contype,
6835  i_conname,
6836  i_condeferrable,
6837  i_condeferred,
6838  i_contableoid,
6839  i_conoid,
6840  i_condef,
6841  i_tablespace,
6842  i_indreloptions,
6843  i_indstatcols,
6844  i_indstatvals;
6845  int ntups;
6846 
6847  for (i = 0; i < numTables; i++)
6848  {
6849  TableInfo *tbinfo = &tblinfo[i];
6850 
6851  if (!tbinfo->hasindex)
6852  continue;
6853 
6854  /*
6855  * Ignore indexes of tables whose definitions are not to be dumped.
6856  *
6857  * We also need indexes on partitioned tables which have partitions to
6858  * be dumped, in order to dump the indexes on the partitions.
6859  */
6860  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) &&
6861  !tbinfo->interesting)
6862  continue;
6863 
6864  pg_log_info("reading indexes for table \"%s.%s\"",
6865  tbinfo->dobj.namespace->dobj.name,
6866  tbinfo->dobj.name);
6867 
6868  /*
6869  * The point of the messy-looking outer join is to find a constraint
6870  * that is related by an internal dependency link to the index. If we
6871  * find one, create a CONSTRAINT entry linked to the INDEX entry. We
6872  * assume an index won't have more than one internal dependency.
6873  *
6874  * As of 9.0 we don't need to look at pg_depend but can check for a
6875  * match to pg_constraint.conindid. The check on conrelid is
6876  * redundant but useful because that column is indexed while conindid
6877  * is not.
6878  */
6879  resetPQExpBuffer(query);
6880  if (fout->remoteVersion >= 110000)
6881  {
6882  appendPQExpBuffer(query,
6883  "SELECT t.tableoid, t.oid, "
6884  "t.relname AS indexname, "
6885  "inh.inhparent AS parentidx, "
6886  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6887  "i.indnkeyatts AS indnkeyatts, "
6888  "i.indnatts AS indnatts, "
6889  "i.indkey, i.indisclustered, "
6890  "i.indisreplident, "
6891  "c.contype, c.conname, "
6892  "c.condeferrable, c.condeferred, "
6893  "c.tableoid AS contableoid, "
6894  "c.oid AS conoid, "
6895  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6896  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6897  "t.reloptions AS indreloptions, "
6898  "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
6899  " FROM pg_catalog.pg_attribute "
6900  " WHERE attrelid = i.indexrelid AND "
6901  " attstattarget >= 0) AS indstatcols,"
6902  "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
6903  " FROM pg_catalog.pg_attribute "
6904  " WHERE attrelid = i.indexrelid AND "
6905  " attstattarget >= 0) AS indstatvals "
6906  "FROM pg_catalog.pg_index i "
6907  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6908  "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
6909  "LEFT JOIN pg_catalog.pg_constraint c "
6910  "ON (i.indrelid = c.conrelid AND "
6911  "i.indexrelid = c.conindid AND "
6912  "c.contype IN ('p','u','x')) "
6913  "LEFT JOIN pg_catalog.pg_inherits inh "
6914  "ON (inh.inhrelid = indexrelid) "
6915  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6916  "AND (i.indisvalid OR t2.relkind = 'p') "
6917  "AND i.indisready "
6918  "ORDER BY indexname",
6919  tbinfo->dobj.catId.oid);
6920  }
6921  else if (fout->remoteVersion >= 90400)
6922  {
6923  /*
6924  * the test on indisready is necessary in 9.2, and harmless in
6925  * earlier/later versions
6926  */
6927  appendPQExpBuffer(query,
6928  "SELECT t.tableoid, t.oid, "
6929  "t.relname AS indexname, "
6930  "0 AS parentidx, "
6931  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6932  "i.indnatts AS indnkeyatts, "
6933  "i.indnatts AS indnatts, "
6934  "i.indkey, i.indisclustered, "
6935  "i.indisreplident, "
6936  "c.contype, c.conname, "
6937  "c.condeferrable, c.condeferred, "
6938  "c.tableoid AS contableoid, "
6939  "c.oid AS conoid, "
6940  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6941  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6942  "t.reloptions AS indreloptions, "
6943  "'' AS indstatcols, "
6944  "'' AS indstatvals "
6945  "FROM pg_catalog.pg_index i "
6946  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6947  "LEFT JOIN pg_catalog.pg_constraint c "
6948  "ON (i.indrelid = c.conrelid AND "
6949  "i.indexrelid = c.conindid AND "
6950  "c.contype IN ('p','u','x')) "
6951  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6952  "AND i.indisvalid AND i.indisready "
6953  "ORDER BY indexname",
6954  tbinfo->dobj.catId.oid);
6955  }
6956  else if (fout->remoteVersion >= 90000)
6957  {
6958  /*
6959  * the test on indisready is necessary in 9.2, and harmless in
6960  * earlier/later versions
6961  */
6962  appendPQExpBuffer(query,
6963  "SELECT t.tableoid, t.oid, "
6964  "t.relname AS indexname, "
6965  "0 AS parentidx, "
6966  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6967  "i.indnatts AS indnkeyatts, "
6968  "i.indnatts AS indnatts, "
6969  "i.indkey, i.indisclustered, "
6970  "false AS indisreplident, "
6971  "c.contype, c.conname, "
6972  "c.condeferrable, c.condeferred, "
6973  "c.tableoid AS contableoid, "
6974  "c.oid AS conoid, "
6975  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6976  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6977  "t.reloptions AS indreloptions, "
6978  "'' AS indstatcols, "
6979  "'' AS indstatvals "
6980  "FROM pg_catalog.pg_index i "
6981  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6982  "LEFT JOIN pg_catalog.pg_constraint c "
6983  "ON (i.indrelid = c.conrelid AND "
6984  "i.indexrelid = c.conindid AND "
6985  "c.contype IN ('p','u','x')) "
6986  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6987  "AND i.indisvalid AND i.indisready "
6988  "ORDER BY indexname",
6989  tbinfo->dobj.catId.oid);
6990  }
6991  else if (fout->remoteVersion >= 80200)
6992  {
6993  appendPQExpBuffer(query,
6994  "SELECT t.tableoid, t.oid, "
6995  "t.relname AS indexname, "
6996  "0 AS parentidx, "
6997  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6998  "i.indnatts AS indnkeyatts, "
6999  "i.indnatts AS indnatts, "
7000  "i.indkey, i.indisclustered, "
7001  "false AS indisreplident, "
7002  "c.contype, c.conname, "
7003  "c.condeferrable, c.condeferred, "
7004  "c.tableoid AS contableoid, "
7005  "c.oid AS conoid, "
7006  "null AS condef, "
7007  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7008  "t.reloptions AS indreloptions, "
7009  "'' AS indstatcols, "
7010  "'' AS indstatvals "
7011  "FROM pg_catalog.pg_index i "
7012  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7013  "LEFT JOIN pg_catalog.pg_depend d "
7014  "ON (d.classid = t.tableoid "
7015  "AND d.objid = t.oid "
7016  "AND d.deptype = 'i') "
7017  "LEFT JOIN pg_catalog.pg_constraint c "
7018  "ON (d.refclassid = c.tableoid "
7019  "AND d.refobjid = c.oid) "
7020  "WHERE i.indrelid = '%u'::pg_catalog.oid "
7021  "AND i.indisvalid "
7022  "ORDER BY indexname",
7023  tbinfo->dobj.catId.oid);
7024  }
7025  else
7026  {
7027  appendPQExpBuffer(query,
7028  "SELECT t.tableoid, t.oid, "
7029  "t.relname AS indexname, "
7030  "0 AS parentidx, "
7031  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7032  "t.relnatts AS indnkeyatts, "
7033  "t.relnatts AS indnatts, "
7034  "i.indkey, i.indisclustered, "
7035  "false AS indisreplident, "
7036  "c.contype, c.conname, "
7037  "c.condeferrable, c.condeferred, "
7038  "c.tableoid AS contableoid, "
7039  "c.oid AS conoid, "
7040  "null AS condef, "
7041  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7042  "null AS indreloptions, "
7043  "'' AS indstatcols, "
7044  "'' AS indstatvals "
7045  "FROM pg_catalog.pg_index i "
7046  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7047  "LEFT JOIN pg_catalog.pg_depend d "
7048  "ON (d.classid = t.tableoid "
7049  "AND d.objid = t.oid "
7050  "AND d.deptype = 'i') "
7051  "LEFT JOIN pg_catalog.pg_constraint c "
7052  "ON (d.refclassid = c.tableoid "
7053  "AND d.refobjid = c.oid) "
7054  "WHERE i.indrelid = '%u'::pg_catalog.oid "
7055  "ORDER BY indexname",
7056  tbinfo->dobj.catId.oid);
7057  }
7058 
7059  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7060 
7061  ntups = PQntuples(res);
7062 
7063  i_tableoid = PQfnumber(res, "tableoid");
7064  i_oid = PQfnumber(res, "oid");
7065  i_indexname = PQfnumber(res, "indexname");
7066  i_parentidx = PQfnumber(res, "parentidx");
7067  i_indexdef = PQfnumber(res, "indexdef");
7068  i_indnkeyatts = PQfnumber(res, "indnkeyatts");
7069  i_indnatts = PQfnumber(res, "indnatts");
7070  i_indkey = PQfnumber(res, "indkey");
7071  i_indisclustered = PQfnumber(res, "indisclustered");
7072  i_indisreplident = PQfnumber(res, "indisreplident");
7073  i_contype = PQfnumber(res, "contype");
7074  i_conname = PQfnumber(res, "conname");
7075  i_condeferrable = PQfnumber(res, "condeferrable");
7076  i_condeferred = PQfnumber(res, "condeferred");
7077  i_contableoid = PQfnumber(res, "contableoid");
7078  i_conoid = PQfnumber(res, "conoid");
7079  i_condef = PQfnumber(res, "condef");
7080  i_tablespace = PQfnumber(res, "tablespace");
7081  i_indreloptions = PQfnumber(res, "indreloptions");
7082  i_indstatcols = PQfnumber(res, "indstatcols");
7083  i_indstatvals = PQfnumber(res, "indstatvals");
7084 
7085  tbinfo->indexes = indxinfo =
7086  (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
7087  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7088  tbinfo->numIndexes = ntups;
7089 
7090  for (j = 0; j < ntups; j++)
7091  {
7092  char contype;
7093 
7094  indxinfo[j].dobj.objType = DO_INDEX;
7095  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
7096  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
7097  AssignDumpId(&indxinfo[j].dobj);
7098  indxinfo[j].dobj.dump = tbinfo->dobj.dump;
7099  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
7100  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7101  indxinfo[j].indextable = tbinfo;
7102  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
7103  indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
7104  indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
7105  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
7106  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
7107  indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
7108  indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
7109  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
7110  parseOidArray(PQgetvalue(res, j, i_indkey),
7111  indxinfo[j].indkeys, indxinfo[j].indnattrs);
7112  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
7113  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
7114  indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
7115  indxinfo[j].partattaches = (SimplePtrList) { NULL, NULL };
7116  contype = *(PQgetvalue(res, j, i_contype));
7117 
7118  if (contype == 'p' || contype == 'u' || contype == 'x')
7119  {
7120  /*
7121  * If we found a constraint matching the index, create an
7122  * entry for it.
7123  */
7124  constrinfo[j].dobj.objType = DO_CONSTRAINT;
7125  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7126  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7127  AssignDumpId(&constrinfo[j].dobj);
7128  constrinfo[j].dobj.dump = tbinfo->dobj.dump;
7129  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7130  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7131  constrinfo[j].contable = tbinfo;
7132  constrinfo[j].condomain = NULL;
7133  constrinfo[j].contype = contype;
7134  if (contype == 'x')
7135  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7136  else
7137  constrinfo[j].condef = NULL;
7138  constrinfo[j].confrelid = InvalidOid;
7139  constrinfo[j].conindex = indxinfo[j].dobj.dumpId;
7140  constrinfo[j].condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
7141  constrinfo[j].condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
7142  constrinfo[j].conislocal = true;
7143  constrinfo[j].separate = true;
7144 
7145  indxinfo[j].indexconstraint = constrinfo[j].dobj.dumpId;
7146  }
7147  else
7148  {
7149  /* Plain secondary index */
7150  indxinfo[j].indexconstraint = 0;
7151  }
7152  }
7153 
7154  PQclear(res);
7155  }
7156 
7157  destroyPQExpBuffer(query);
7158 }
char * tablespace
Definition: pg_dump.h:359
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:272
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:446
DumpId indexconstraint
Definition: pg_dump.h:373
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
char * indexdef
Definition: pg_dump.h:358
DumpableObject dobj
Definition: pg_dump.h:258
Oid parentidx
Definition: pg_dump.h:369
char * condef
Definition: pg_dump.h:444
bool indisreplident
Definition: pg_dump.h:368
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:440
TableInfo * indextable
Definition: pg_dump.h:357
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
Oid * indkeys
Definition: pg_dump.h:365
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:447
char * indreloptions
Definition: pg_dump.h:360
TypeInfo * condomain
Definition: pg_dump.h:442
bool conislocal
Definition: pg_dump.h:449
SimplePtrList partattaches
Definition: pg_dump.h:370
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1048
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int numIndexes
Definition: pg_dump.h:331
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
TableInfo * contable
Definition: pg_dump.h:441
#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:448
int indnkeyattrs
Definition: pg_dump.h:363
char * indstatvals
Definition: pg_dump.h:362
int indnattrs
Definition: pg_dump.h:364
struct _indxInfo * indexes
Definition: pg_dump.h:332
CatalogId catId
Definition: pg_dump.h:128
DumpableObject dobj
Definition: pg_dump.h:356
char * indstatcols
Definition: pg_dump.h:361
bool interesting
Definition: pg_dump.h:291
int i
bool indisclustered
Definition: pg_dump.h:367
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 6767 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().

6768 {
6769  PGresult *res;
6770  int ntups;
6771  int i;
6772  PQExpBuffer query = createPQExpBuffer();
6773  InhInfo *inhinfo;
6774 
6775  int i_inhrelid;
6776  int i_inhparent;
6777 
6778  /*
6779  * Find all the inheritance information, excluding implicit inheritance
6780  * via partitioning.
6781  */
6782  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
6783 
6784  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6785 
6786  ntups = PQntuples(res);
6787 
6788  *numInherits = ntups;
6789 
6790  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6791 
6792  i_inhrelid = PQfnumber(res, "inhrelid");
6793  i_inhparent = PQfnumber(res, "inhparent");
6794 
6795  for (i = 0; i < ntups; i++)
6796  {
6797  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6798  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6799  }
6800 
6801  PQclear(res);
6802 
6803  destroyPQExpBuffer(query);
6804 
6805  return inhinfo;
6806 }
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:489
#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:490
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:401

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )

Definition at line 598 of file common.c.

References lastDumpId.

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

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

◆ getNamespaces()

NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

Definition at line 4517 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().

4518 {
4519  DumpOptions *dopt = fout->dopt;
4520  PGresult *res;
4521  int ntups;
4522  int i;
4523  PQExpBuffer query;
4524  NamespaceInfo *nsinfo;
4525  int i_tableoid;
4526  int i_oid;
4527  int i_nspname;
4528  int i_rolname;
4529  int i_nspacl;
4530  int i_rnspacl;
4531  int i_initnspacl;
4532  int i_initrnspacl;
4533 
4534  query = createPQExpBuffer();
4535 
4536  /*
4537  * we fetch all namespaces including system ones, so that every object we
4538  * read in can be linked to a containing namespace.
4539  */
4540  if (fout->remoteVersion >= 90600)
4541  {
4542  PQExpBuffer acl_subquery = createPQExpBuffer();
4543  PQExpBuffer racl_subquery = createPQExpBuffer();
4544  PQExpBuffer init_acl_subquery = createPQExpBuffer();
4545  PQExpBuffer init_racl_subquery = createPQExpBuffer();
4546 
4547  buildACLQueries(acl_subquery, racl_subquery, init_acl_subquery,
4548  init_racl_subquery, "n.nspacl", "n.nspowner", "'n'",
4549  dopt->binary_upgrade);
4550 
4551  appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, "
4552  "(%s nspowner) AS rolname, "
4553  "%s as nspacl, "
4554  "%s as rnspacl, "
4555  "%s as initnspacl, "
4556  "%s as initrnspacl "
4557  "FROM pg_namespace n "
4558  "LEFT JOIN pg_init_privs pip "
4559  "ON (n.oid = pip.objoid "
4560  "AND pip.classoid = 'pg_namespace'::regclass "
4561  "AND pip.objsubid = 0",
4563  acl_subquery->data,
4564  racl_subquery->data,
4565  init_acl_subquery->data,
4566  init_racl_subquery->data);
4567 
4568  appendPQExpBufferStr(query, ") ");
4569 
4570  destroyPQExpBuffer(acl_subquery);
4571  destroyPQExpBuffer(racl_subquery);
4572  destroyPQExpBuffer(init_acl_subquery);
4573  destroyPQExpBuffer(init_racl_subquery);
4574  }
4575  else
4576  appendPQExpBuffer(query, "SELECT tableoid, oid, nspname, "
4577  "(%s nspowner) AS rolname, "
4578  "nspacl, NULL as rnspacl, "
4579  "NULL AS initnspacl, NULL as initrnspacl "
4580  "FROM pg_namespace",
4582 
4583  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4584 
4585  ntups = PQntuples(res);
4586 
4587  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
4588 
4589  i_tableoid = PQfnumber(res, "tableoid");
4590  i_oid = PQfnumber(res, "oid");
4591  i_nspname = PQfnumber(res, "nspname");
4592  i_rolname = PQfnumber(res, "rolname");
4593  i_nspacl = PQfnumber(res, "nspacl");
4594  i_rnspacl = PQfnumber(res, "rnspacl");
4595  i_initnspacl = PQfnumber(res, "initnspacl");
4596  i_initrnspacl = PQfnumber(res, "initrnspacl");
4597 
4598  for (i = 0; i < ntups; i++)
4599  {
4600  nsinfo[i].dobj.objType = DO_NAMESPACE;
4601  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4602  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4603  AssignDumpId(&nsinfo[i].dobj);
4604  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
4605  nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4606  nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl));
4607  nsinfo[i].rnspacl = pg_strdup(PQgetvalue(res, i, i_rnspacl));
4608  nsinfo[i].initnspacl = pg_strdup(PQgetvalue(res, i, i_initnspacl));
4609  nsinfo[i].initrnspacl = pg_strdup(PQgetvalue(res, i, i_initrnspacl));
4610 
4611  /* Decide whether to dump this namespace */
4612  selectDumpableNamespace(&nsinfo[i], fout);
4613 
4614  /*
4615  * Do not try to dump ACL if the ACL is empty or the default.
4616  *
4617  * This is useful because, for some schemas/objects, the only
4618  * component we are going to try and dump is the ACL and if we can
4619  * remove that then 'dump' goes to zero/false and we don't consider
4620  * this object for dumping at all later on.
4621  */
4622  if (PQgetisnull(res, i, i_nspacl) && PQgetisnull(res, i, i_rnspacl) &&
4623  PQgetisnull(res, i, i_initnspacl) &&
4624  PQgetisnull(res, i, i_initrnspacl))
4625  nsinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4626 
4627  if (strlen(nsinfo[i].rolname) == 0)
4628  pg_log_warning("owner of schema \"%s\" appears to be invalid",
4629  nsinfo[i].dobj.name);
4630  }
4631 
4632  PQclear(res);
4633  destroyPQExpBuffer(query);
4634 
4635  *numNamespaces = ntups;
4636 
4637  return nsinfo;
4638 }
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:145
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:143
char * initnspacl
Definition: pg_dump.h:146
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:95
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:1461
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
char * initrnspacl
Definition: pg_dump.h:147
CatalogId catId
Definition: pg_dump.h:128
int i
char * nspacl
Definition: pg_dump.h:144
DumpableObject dobj
Definition: pg_dump.h:142
#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 5307 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().

5308 {
5309  PGresult *res;
5310  int ntups;
5311  int i;
5312  PQExpBuffer query = createPQExpBuffer();
5313  OpclassInfo *opcinfo;
5314  int i_tableoid;
5315  int i_oid;
5316  int i_opcname;
5317  int i_opcnamespace;
5318  int i_rolname;
5319 
5320  /*
5321  * find all opclasses, including builtin opclasses; we filter out
5322  * system-defined opclasses at dump-out time.
5323  */
5324 
5325  appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
5326  "opcnamespace, "
5327  "(%s opcowner) AS rolname "
5328  "FROM pg_opclass",
5330 
5331  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5332 
5333  ntups = PQntuples(res);
5334  *numOpclasses = ntups;
5335 
5336  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
5337 
5338  i_tableoid = PQfnumber(res, "tableoid");
5339  i_oid = PQfnumber(res, "oid");
5340  i_opcname = PQfnumber(res, "opcname");
5341  i_opcnamespace = PQfnumber(res, "opcnamespace");
5342  i_rolname = PQfnumber(res, "rolname");
5343 
5344  for (i = 0; i < ntups; i++)
5345  {
5346  opcinfo[i].dobj.objType = DO_OPCLASS;
5347  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5348  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5349  AssignDumpId(&opcinfo[i].dobj);
5350  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
5351  opcinfo[i].dobj.namespace =
5352  findNamespace(fout,
5353  atooid(PQgetvalue(res, i, i_opcnamespace)));
5354  opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5355 
5356  /* Decide whether we want to dump it */
5357  selectDumpableObject(&(opcinfo[i].dobj), fout);
5358 
5359  /* Op Classes do not currently have ACLs. */
5360  opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5361 
5362  if (strlen(opcinfo[i].rolname) == 0)
5363  pg_log_warning("owner of operator class \"%s\" appears to be invalid",
5364  opcinfo[i].dobj.name);
5365  }
5366 
5367  PQclear(res);
5368 
5369  destroyPQExpBuffer(query);
5370 
5371  return opcinfo;
5372 }
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1760
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:4645
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
char * rolname
Definition: pg_dump.h:232
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:95
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
DumpableObject dobj
Definition: pg_dump.h:231
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 4997 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().

4998 {
4999  PGresult *res;
5000  int ntups;
5001  int i;
5002  PQExpBuffer query = createPQExpBuffer();
5003  OprInfo *oprinfo;
5004  int i_tableoid;
5005  int i_oid;
5006  int i_oprname;
5007  int i_oprnamespace;
5008  int i_rolname;
5009  int i_oprkind;
5010  int i_oprcode;
5011 
5012  /*
5013  * find all operators, including builtin operators; we filter out
5014  * system-defined operators at dump-out time.
5015  */
5016 
5017  appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
5018  "oprnamespace, "
5019  "(%s oprowner) AS rolname, "
5020  "oprkind, "
5021  "oprcode::oid AS oprcode "
5022  "FROM pg_operator",
5024 
5025  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5026 
5027  ntups = PQntuples(res);
5028  *numOprs = ntups;
5029 
5030  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
5031 
5032  i_tableoid = PQfnumber(res, "tableoid");
5033  i_oid = PQfnumber(res, "oid");
5034  i_oprname = PQfnumber(res, "oprname");
5035  i_oprnamespace = PQfnumber(res, "oprnamespace");
5036  i_rolname = PQfnumber(res, "rolname");
5037  i_oprkind = PQfnumber(res, "oprkind");
5038  i_oprcode = PQfnumber(res, "oprcode");
5039 
5040  for (i = 0; i < ntups; i++)
5041  {
5042  oprinfo[i].dobj.objType = DO_OPERATOR;
5043  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5044  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5045  AssignDumpId(&oprinfo[i].dobj);
5046  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
5047  oprinfo[i].dobj.namespace =
5048  findNamespace(fout,
5049  atooid(PQgetvalue(res, i, i_oprnamespace)));
5050  oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5051  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
5052  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
5053 
5054  /* Decide whether we want to dump it */
5055  selectDumpableObject(&(oprinfo[i].dobj), fout);
5056 
5057  /* Operators do not currently have ACLs. */
5058  oprinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5059 
5060  if (strlen(oprinfo[i].rolname) == 0)
5061  pg_log_warning("owner of operator \"%s\" appears to be invalid",
5062  oprinfo[i].dobj.name);
5063  }
5064 
5065  PQclear(res);
5066 
5067  destroyPQExpBuffer(query);
5068 
5069  return oprinfo;
5070 }
char * name
Definition: pg_dump.h:130
DumpableObject dobj
Definition: pg_dump.h:216
DumpComponents dump
Definition: pg_dump.h:131
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1760
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:4645
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:95
char * rolname
Definition: pg_dump.h:217
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:218
#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:219

◆ getOpfamilies()

OpfamilyInfo* getOpfamilies ( Archive fout,
int *  numOpfamilies 
)

Definition at line 5382 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().

5383 {
5384  PGresult *res;
5385  int ntups;
5386  int i;
5387  PQExpBuffer query;
5388  OpfamilyInfo *opfinfo;
5389  int i_tableoid;
5390  int i_oid;
5391  int i_opfname;
5392  int i_opfnamespace;
5393  int i_rolname;
5394 
5395  /* Before 8.3, there is no separate concept of opfamilies */
5396  if (fout->remoteVersion < 80300)
5397  {
5398  *numOpfamilies = 0;
5399  return NULL;
5400  }
5401 
5402  query = createPQExpBuffer();
5403 
5404  /*
5405  * find all opfamilies, including builtin opfamilies; we filter out
5406  * system-defined opfamilies at dump-out time.
5407  */
5408 
5409  appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, "
5410  "opfnamespace, "
5411  "(%s opfowner) AS rolname "
5412  "FROM pg_opfamily",
5414 
5415  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5416 
5417  ntups = PQntuples(res);
5418  *numOpfamilies = ntups;
5419 
5420  opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
5421 
5422  i_tableoid = PQfnumber(res, "tableoid");
5423  i_oid = PQfnumber(res, "oid");
5424  i_opfname = PQfnumber(res, "opfname");
5425  i_opfnamespace = PQfnumber(res, "opfnamespace");
5426  i_rolname = PQfnumber(res, "rolname");
5427 
5428  for (i = 0; i < ntups; i++)
5429  {
5430  opfinfo[i].dobj.objType = DO_OPFAMILY;
5431  opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5432  opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5433  AssignDumpId(&opfinfo[i].dobj);
5434  opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
5435  opfinfo[i].