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  _tableAttachInfo
 
struct  _attrDefInfo
 
struct  _tableDataInfo
 
struct  _indxInfo
 
struct  _indexAttachInfo
 
struct  _statsExtInfo
 
struct  _ruleInfo
 
struct  _triggerInfo
 
struct  _evttriggerInfo
 
struct  _constraintInfo
 
struct  _procLangInfo
 
struct  _castInfo
 
struct  _transformInfo
 
struct  _inhInfo
 
struct  _prsInfo
 
struct  _dictInfo
 
struct  _tmplInfo
 
struct  _cfgInfo
 
struct  _fdwInfo
 
struct  _foreignServerInfo
 
struct  _defaultACLInfo
 
struct  _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 _tableAttachInfo TableAttachInfo
 
typedef struct _attrDefInfo AttrDefInfo
 
typedef struct _tableDataInfo TableDataInfo
 
typedef struct _indxInfo IndxInfo
 
typedef struct _indexAttachInfo IndexAttachInfo
 
typedef struct _statsExtInfo StatsExtInfo
 
typedef struct _ruleInfo RuleInfo
 
typedef struct _triggerInfo TriggerInfo
 
typedef struct _evttriggerInfo EventTriggerInfo
 
typedef struct _constraintInfo ConstraintInfo
 
typedef struct _procLangInfo ProcLangInfo
 
typedef struct _castInfo CastInfo
 
typedef struct _transformInfo TransformInfo
 
typedef struct _inhInfo InhInfo
 
typedef struct _prsInfo TSParserInfo
 
typedef struct _dictInfo TSDictInfo
 
typedef struct _tmplInfo TSTemplateInfo
 
typedef struct _cfgInfo TSConfigInfo
 
typedef struct _fdwInfo FdwInfo
 
typedef struct _foreignServerInfo ForeignServerInfo
 
typedef struct _defaultACLInfo DefaultACLInfo
 
typedef struct _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_TABLE_ATTACH, DO_ATTRDEF, DO_INDEX,
  DO_INDEX_ATTACH, DO_STATSEXT, DO_RULE, DO_TRIGGER,
  DO_CONSTRAINT, DO_FK_CONSTRAINT, DO_PROCLANG, DO_CAST,
  DO_TABLE_DATA, DO_SEQUENCE_SET, DO_DUMMY_TYPE, DO_TSPARSER,
  DO_TSDICT, DO_TSTEMPLATE, DO_TSCONFIG, DO_FDW,
  DO_FOREIGN_SERVER, DO_DEFAULT_ACL, DO_TRANSFORM, DO_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)
 
PublicationInfofindPublicationByOid (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 (const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
 
TSParserInfogetTSParsers (Archive *fout, int *numTSParsers)
 
TSDictInfogetTSDictionaries (Archive *fout, int *numTSDicts)
 
TSTemplateInfogetTSTemplates (Archive *fout, int *numTSTemplates)
 
TSConfigInfogetTSConfigurations (Archive *fout, int *numTSConfigs)
 
FdwInfogetForeignDataWrappers (Archive *fout, int *numForeignDataWrappers)
 
ForeignServerInfogetForeignServers (Archive *fout, int *numForeignServers)
 
DefaultACLInfogetDefaultACLs (Archive *fout, int *numDefaultACLs)
 
void getExtensionMembership (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
void processExtensionTables (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
EventTriggerInfogetEventTriggers (Archive *fout, int *numEventTriggers)
 
void getPolicies (Archive *fout, TableInfo tblinfo[], int numTables)
 
PublicationInfogetPublications (Archive *fout, int *numPublications)
 
void getPublicationTables (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getSubscriptions (Archive *fout)
 

Macro Definition Documentation

◆ DUMP_COMPONENT_ACL

◆ DUMP_COMPONENT_ALL

◆ DUMP_COMPONENT_COMMENT

◆ DUMP_COMPONENT_DATA

#define DUMP_COMPONENT_DATA   (1 << 1)

◆ DUMP_COMPONENT_DEFINITION

◆ DUMP_COMPONENT_NONE

◆ DUMP_COMPONENT_POLICY

#define DUMP_COMPONENT_POLICY   (1 << 5)

Definition at line 95 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 96 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 121 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 88 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

◆ TableAttachInfo

◆ TableDataInfo

typedef struct _tableDataInfo TableDataInfo

◆ TableInfo

typedef struct _tableInfo TableInfo

◆ TransformInfo

typedef struct _transformInfo TransformInfo

◆ TriggerInfo

typedef struct _triggerInfo TriggerInfo

◆ TSConfigInfo

typedef struct _cfgInfo TSConfigInfo

◆ TSDictInfo

typedef struct _dictInfo TSDictInfo

◆ TSParserInfo

typedef struct _prsInfo TSParserInfo

◆ TSTemplateInfo

typedef struct _tmplInfo TSTemplateInfo

◆ TypeInfo

typedef struct _typeInfo TypeInfo

Enumeration Type Documentation

◆ DumpableObjectType

Enumerator
DO_NAMESPACE 
DO_EXTENSION 
DO_TYPE 
DO_SHELL_TYPE 
DO_FUNC 
DO_AGG 
DO_OPERATOR 
DO_ACCESS_METHOD 
DO_OPCLASS 
DO_OPFAMILY 
DO_COLLATION 
DO_CONVERSION 
DO_TABLE 
DO_TABLE_ATTACH 
DO_ATTRDEF 
DO_INDEX 
DO_INDEX_ATTACH 
DO_STATSEXT 
DO_RULE 
DO_TRIGGER 
DO_CONSTRAINT 
DO_FK_CONSTRAINT 
DO_PROCLANG 
DO_CAST 
DO_TABLE_DATA 
DO_SEQUENCE_SET 
DO_DUMMY_TYPE 
DO_TSPARSER 
DO_TSDICT 
DO_TSTEMPLATE 
DO_TSCONFIG 
DO_FDW 
DO_FOREIGN_SERVER 
DO_DEFAULT_ACL 
DO_TRANSFORM 
DO_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,
54  DO_ATTRDEF,
55  DO_INDEX,
58  DO_RULE,
59  DO_TRIGGER,
61  DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
63  DO_CAST,
68  DO_TSDICT,
71  DO_FDW,
75  DO_BLOB,
81  DO_POLICY,
DumpableObjectType
Definition: pg_dump.h:37
Definition: pg_dump.h:45
Definition: pg_dump.h:71

Function Documentation

◆ addObjectDependency()

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

Definition at line 846 of file common.c.

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

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

847 {
848  if (dobj->nDeps >= dobj->allocDeps)
849  {
850  if (dobj->allocDeps <= 0)
851  {
852  dobj->allocDeps = 16;
853  dobj->dependencies = (DumpId *)
854  pg_malloc(dobj->allocDeps * sizeof(DumpId));
855  }
856  else
857  {
858  dobj->allocDeps *= 2;
859  dobj->dependencies = (DumpId *)
860  pg_realloc(dobj->dependencies,
861  dobj->allocDeps * sizeof(DumpId));
862  }
863  }
864  dobj->dependencies[dobj->nDeps++] = refId;
865 }
int DumpId
Definition: pg_backup.h:243
DumpId * dependencies
Definition: pg_dump.h:137
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 605 of file common.c.

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

Referenced by createBoundaryObjects(), flagInhAttrs(), flagInhIndexes(), flagInhTables(), 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().

606 {
607  dobj->dumpId = ++lastDumpId;
608  dobj->name = NULL; /* must be set later */
609  dobj->namespace = NULL; /* may be set later */
610  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
611  dobj->dump_contains = DUMP_COMPONENT_ALL; /* default assumption */
612  dobj->ext_member = false; /* default assumption */
613  dobj->depends_on_ext = false; /* default assumption */
614  dobj->dependencies = NULL;
615  dobj->nDeps = 0;
616  dobj->allocDeps = 0;
617 
618  while (dobj->dumpId >= allocedDumpIds)
619  {
620  int newAlloc;
621 
622  if (allocedDumpIds <= 0)
623  {
624  newAlloc = 256;
626  pg_malloc(newAlloc * sizeof(DumpableObject *));
627  }
628  else
629  {
630  newAlloc = allocedDumpIds * 2;
632  pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
633  }
634  memset(dumpIdMap + allocedDumpIds, 0,
635  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
636  allocedDumpIds = newAlloc;
637  }
638  dumpIdMap[dobj->dumpId] = dobj;
639 
640  /* mark catalogIdMap invalid, but don't rebuild it yet */
641  catalogIdMapValid = false;
642 }
char * name
Definition: pg_dump.h:131
static int allocedDumpIds
Definition: common.c:30
DumpComponents dump
Definition: pg_dump.h:132
static DumpId lastDumpId
Definition: common.c:31
static DumpableObject ** dumpIdMap
Definition: common.c:29
DumpId * dependencies
Definition: pg_dump.h:137
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpId dumpId
Definition: pg_dump.h:130
bool ext_member
Definition: pg_dump.h:135
DumpComponents dump_contains
Definition: pg_dump.h:134
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
bool depends_on_ext
Definition: pg_dump.h:136
static bool catalogIdMapValid
Definition: common.c:36
#define DUMP_COMPONENT_ALL
Definition: pg_dump.h:97

◆ createDumpId()

◆ findCollationByOid()

CollInfo* findCollationByOid ( Oid  oid)

Definition at line 937 of file common.c.

References findObjectByOid(), and numCollations.

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

938 {
940 }
static DumpableObject ** collinfoindex
Definition: common.c:52
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:740
static int numCollations
Definition: common.c:60

◆ findExtensionByOid()

ExtensionInfo* findExtensionByOid ( Oid  oid)

Definition at line 959 of file common.c.

References findObjectByOid(), and numExtensions.

Referenced by getExtensionMembership().

960 {
962 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:740
static int numExtensions
Definition: common.c:62
static DumpableObject ** extinfoindex
Definition: common.c:54

◆ findFuncByOid()

FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 915 of file common.c.

References findObjectByOid(), and numFuncs.

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

916 {
917  return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs);
918 }
static int numFuncs
Definition: common.c:58
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:740
static DumpableObject ** funinfoindex
Definition: common.c:50

◆ findNamespaceByOid()

NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 948 of file common.c.

References findObjectByOid(), and numNamespaces.

Referenced by findNamespace().

949 {
951 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:740
static int numNamespaces
Definition: common.c:61
static DumpableObject ** nspinfoindex
Definition: common.c:53

◆ findObjectByCatalogId()

DumpableObject* findObjectByCatalogId ( CatalogId  catalogId)

Definition at line 689 of file common.c.

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

Referenced by buildMatViewRefreshDependencies(), and getDependencies().

690 {
691  DumpableObject **low;
692  DumpableObject **high;
693 
694  if (!catalogIdMapValid)
695  {
696  if (catalogIdMap)
699  if (numCatalogIds > 1)
700  qsort((void *) catalogIdMap, numCatalogIds,
702  catalogIdMapValid = true;
703  }
704 
705  /*
706  * We could use bsearch() here, but the notational cruft of calling
707  * bsearch is nearly as bad as doing it ourselves; and the generalized
708  * bsearch function is noticeably slower as well.
709  */
710  if (numCatalogIds <= 0)
711  return NULL;
712  low = catalogIdMap;
713  high = catalogIdMap + (numCatalogIds - 1);
714  while (low <= high)
715  {
716  DumpableObject **middle;
717  int difference;
718 
719  middle = low + (high - low) / 2;
720  /* comparison must match DOCatalogIdCompare, below */
721  difference = oidcmp((*middle)->catId.oid, catalogId.oid);
722  if (difference == 0)
723  difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid);
724  if (difference == 0)
725  return *middle;
726  else if (difference < 0)
727  low = middle + 1;
728  else
729  high = middle - 1;
730  }
731  return NULL;
732 }
Oid tableoid
Definition: pg_backup.h:239
#define oidcmp(x, y)
Definition: pg_dump.h:20
static int DOCatalogIdCompare(const void *p1, const void *p2)
Definition: common.c:802
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:504
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition: common.c:824

◆ findObjectByDumpId()

DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 671 of file common.c.

References allocedDumpIds.

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

672 {
673  if (dumpId <= 0 || dumpId >= allocedDumpIds)
674  return NULL; /* out of range? */
675  return dumpIdMap[dumpId];
676 }
static int allocedDumpIds
Definition: common.c:30
static DumpableObject ** dumpIdMap
Definition: common.c:29

◆ findOprByOid()

OprInfo* findOprByOid ( Oid  oid)

Definition at line 926 of file common.c.

References findObjectByOid(), and numOperators.

Referenced by getFormattedOperatorName().

927 {
929 }
static DumpableObject ** oprinfoindex
Definition: common.c:51
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:740
static int numOperators
Definition: common.c:59

◆ findOwningExtension()

ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 1009 of file common.c.

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

Referenced by checkExtensionMembership().

1010 {
1011  ExtensionMemberId *low;
1012  ExtensionMemberId *high;
1013 
1014  /*
1015  * We could use bsearch() here, but the notational cruft of calling
1016  * bsearch is nearly as bad as doing it ourselves; and the generalized
1017  * bsearch function is noticeably slower as well.
1018  */
1019  if (numextmembers <= 0)
1020  return NULL;
1021  low = extmembers;
1022  high = extmembers + (numextmembers - 1);
1023  while (low <= high)
1024  {
1025  ExtensionMemberId *middle;
1026  int difference;
1027 
1028  middle = low + (high - low) / 2;
1029  /* comparison must match ExtensionMemberIdCompare, below */
1030  difference = oidcmp(middle->catId.oid, catalogId.oid);
1031  if (difference == 0)
1032  difference = oidcmp(middle->catId.tableoid, catalogId.tableoid);
1033  if (difference == 0)
1034  return middle->ext;
1035  else if (difference < 0)
1036  low = middle + 1;
1037  else
1038  high = middle - 1;
1039  }
1040  return NULL;
1041 }
ExtensionInfo * ext
Definition: pg_dump.h:651
Oid tableoid
Definition: pg_backup.h:239
#define oidcmp(x, y)
Definition: pg_dump.h:20
Datum difference(PG_FUNCTION_ARGS)
static ExtensionMemberId * extmembers
Definition: common.c:66
static int numextmembers
Definition: common.c:67
CatalogId catId
Definition: pg_dump.h:650

◆ findPublicationByOid()

PublicationInfo* findPublicationByOid ( Oid  oid)

Definition at line 970 of file common.c.

References findObjectByOid(), and numPublications.

Referenced by getPublicationTables().

971 {
973 }
static DumpableObject ** pubinfoindex
Definition: common.c:55
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:740
static int numPublications
Definition: common.c:63

◆ findTableByOid()

TableInfo* findTableByOid ( Oid  oid)

Definition at line 893 of file common.c.

References findObjectByOid(), and numTables.

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

894 {
896 }
static int numTables
Definition: common.c:56
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:740
static DumpableObject ** tblinfoindex
Definition: common.c:48

◆ findTypeByOid()

TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 904 of file common.c.

References findObjectByOid(), and numTypes.

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

905 {
906  return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes);
907 }
static int numTypes
Definition: common.c:57
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:740
static DumpableObject ** typinfoindex
Definition: common.c:49

◆ getAccessMethods()

AccessMethodInfo* getAccessMethods ( Archive fout,
int *  numAccessMethods 
)

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

5540 {
5541  PGresult *res;
5542  int ntups;
5543  int i;
5544  PQExpBuffer query;
5545  AccessMethodInfo *aminfo;
5546  int i_tableoid;
5547  int i_oid;
5548  int i_amname;
5549  int i_amhandler;
5550  int i_amtype;
5551 
5552  /* Before 9.6, there are no user-defined access methods */
5553  if (fout->remoteVersion < 90600)
5554  {
5555  *numAccessMethods = 0;
5556  return NULL;
5557  }
5558 
5559  query = createPQExpBuffer();
5560 
5561  /* Select all access methods from pg_am table */
5562  appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, amtype, "
5563  "amhandler::pg_catalog.regproc AS amhandler "
5564  "FROM pg_am");
5565 
5566  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5567 
5568  ntups = PQntuples(res);
5569  *numAccessMethods = ntups;
5570 
5571  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
5572 
5573  i_tableoid = PQfnumber(res, "tableoid");
5574  i_oid = PQfnumber(res, "oid");
5575  i_amname = PQfnumber(res, "amname");
5576  i_amhandler = PQfnumber(res, "amhandler");
5577  i_amtype = PQfnumber(res, "amtype");
5578 
5579  for (i = 0; i < ntups; i++)
5580  {
5581  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
5582  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5583  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5584  AssignDumpId(&aminfo[i].dobj);
5585  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
5586  aminfo[i].dobj.namespace = NULL;
5587  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
5588  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
5589 
5590  /* Decide whether we want to dump it */
5591  selectDumpableAccessMethod(&(aminfo[i]), fout);
5592 
5593  /* Access methods do not currently have ACLs. */
5594  aminfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5595  }
5596 
5597  PQclear(res);
5598 
5599  destroyPQExpBuffer(query);
5600 
5601  return aminfo;
5602 }
char * name
Definition: pg_dump.h:131
DumpComponents dump
Definition: pg_dump.h:132
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
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:227
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:1832
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:3284
void PQclear(PGresult *res)
Definition: fe-exec.c:680
char * amhandler
Definition: pg_dump.h:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
CatalogId catId
Definition: pg_dump.h:129
int i
DumpableObjectType objType
Definition: pg_dump.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196

◆ getAggregates()

AggInfo* getAggregates ( Archive fout,
int *  numAggregates 
)

Definition at line 5770 of file pg_dump.c.

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

Referenced by getSchemaData().

5771 {
5772  DumpOptions *dopt = fout->dopt;
5773  PGresult *res;
5774  int ntups;
5775  int i;
5776  PQExpBuffer query = createPQExpBuffer();
5777  AggInfo *agginfo;
5778  int i_tableoid;
5779  int i_oid;
5780  int i_aggname;
5781  int i_aggnamespace;
5782  int i_pronargs;
5783  int i_proargtypes;
5784  int i_rolname;
5785  int i_aggacl;
5786  int i_raggacl;
5787  int i_initaggacl;
5788  int i_initraggacl;
5789 
5790  /*
5791  * Find all interesting aggregates. See comment in getFuncs() for the
5792  * rationale behind the filtering logic.
5793  */
5794  if (fout->remoteVersion >= 90600)
5795  {
5796  PQExpBuffer acl_subquery = createPQExpBuffer();
5797  PQExpBuffer racl_subquery = createPQExpBuffer();
5798  PQExpBuffer initacl_subquery = createPQExpBuffer();
5799  PQExpBuffer initracl_subquery = createPQExpBuffer();
5800  const char *agg_check;
5801 
5802  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5803  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5804  dopt->binary_upgrade);
5805 
5806  agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
5807  : "p.proisagg");
5808 
5809  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5810  "p.proname AS aggname, "
5811  "p.pronamespace AS aggnamespace, "
5812  "p.pronargs, p.proargtypes, "
5813  "(%s p.proowner) AS rolname, "
5814  "%s AS aggacl, "
5815  "%s AS raggacl, "
5816  "%s AS initaggacl, "
5817  "%s AS initraggacl "
5818  "FROM pg_proc p "
5819  "LEFT JOIN pg_init_privs pip ON "
5820  "(p.oid = pip.objoid "
5821  "AND pip.classoid = 'pg_proc'::regclass "
5822  "AND pip.objsubid = 0) "
5823  "WHERE %s AND ("
5824  "p.pronamespace != "
5825  "(SELECT oid FROM pg_namespace "
5826  "WHERE nspname = 'pg_catalog') OR "
5827  "p.proacl IS DISTINCT FROM pip.initprivs",
5829  acl_subquery->data,
5830  racl_subquery->data,
5831  initacl_subquery->data,
5832  initracl_subquery->data,
5833  agg_check);
5834  if (dopt->binary_upgrade)
5835  appendPQExpBufferStr(query,
5836  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5837  "classid = 'pg_proc'::regclass AND "
5838  "objid = p.oid AND "
5839  "refclassid = 'pg_extension'::regclass AND "
5840  "deptype = 'e')");
5841  appendPQExpBufferChar(query, ')');
5842 
5843  destroyPQExpBuffer(acl_subquery);
5844  destroyPQExpBuffer(racl_subquery);
5845  destroyPQExpBuffer(initacl_subquery);
5846  destroyPQExpBuffer(initracl_subquery);
5847  }
5848  else if (fout->remoteVersion >= 80200)
5849  {
5850  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5851  "pronamespace AS aggnamespace, "
5852  "pronargs, proargtypes, "
5853  "(%s proowner) AS rolname, "
5854  "proacl AS aggacl, "
5855  "NULL AS raggacl, "
5856  "NULL AS initaggacl, NULL AS initraggacl "
5857  "FROM pg_proc p "
5858  "WHERE proisagg AND ("
5859  "pronamespace != "
5860  "(SELECT oid FROM pg_namespace "
5861  "WHERE nspname = 'pg_catalog')",
5863  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5864  appendPQExpBufferStr(query,
5865  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5866  "classid = 'pg_proc'::regclass AND "
5867  "objid = p.oid AND "
5868  "refclassid = 'pg_extension'::regclass AND "
5869  "deptype = 'e')");
5870  appendPQExpBufferChar(query, ')');
5871  }
5872  else
5873  {
5874  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5875  "pronamespace AS aggnamespace, "
5876  "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
5877  "proargtypes, "
5878  "(%s proowner) AS rolname, "
5879  "proacl AS aggacl, "
5880  "NULL AS raggacl, "
5881  "NULL AS initaggacl, NULL AS initraggacl "
5882  "FROM pg_proc "
5883  "WHERE proisagg "
5884  "AND pronamespace != "
5885  "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
5887  }
5888 
5889  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5890 
5891  ntups = PQntuples(res);
5892  *numAggs = ntups;
5893 
5894  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5895 
5896  i_tableoid = PQfnumber(res, "tableoid");
5897  i_oid = PQfnumber(res, "oid");
5898  i_aggname = PQfnumber(res, "aggname");
5899  i_aggnamespace = PQfnumber(res, "aggnamespace");
5900  i_pronargs = PQfnumber(res, "pronargs");
5901  i_proargtypes = PQfnumber(res, "proargtypes");
5902  i_rolname = PQfnumber(res, "rolname");
5903  i_aggacl = PQfnumber(res, "aggacl");
5904  i_raggacl = PQfnumber(res, "raggacl");
5905  i_initaggacl = PQfnumber(res, "initaggacl");
5906  i_initraggacl = PQfnumber(res, "initraggacl");
5907 
5908  for (i = 0; i < ntups; i++)
5909  {
5910  agginfo[i].aggfn.dobj.objType = DO_AGG;
5911  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5912  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5913  AssignDumpId(&agginfo[i].aggfn.dobj);
5914  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5915  agginfo[i].aggfn.dobj.namespace =
5916  findNamespace(atooid(PQgetvalue(res, i, i_aggnamespace)));
5917  agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5918  if (strlen(agginfo[i].aggfn.rolname) == 0)
5919  pg_log_warning("owner of aggregate function \"%s\" appears to be invalid",
5920  agginfo[i].aggfn.dobj.name);
5921  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5922  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5923  agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5924  agginfo[i].aggfn.rproacl = pg_strdup(PQgetvalue(res, i, i_raggacl));
5925  agginfo[i].aggfn.initproacl = pg_strdup(PQgetvalue(res, i, i_initaggacl));
5926  agginfo[i].aggfn.initrproacl = pg_strdup(PQgetvalue(res, i, i_initraggacl));
5927  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5928  if (agginfo[i].aggfn.nargs == 0)
5929  agginfo[i].aggfn.argtypes = NULL;
5930  else
5931  {
5932  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5933  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5934  agginfo[i].aggfn.argtypes,
5935  agginfo[i].aggfn.nargs);
5936  }
5937 
5938  /* Decide whether we want to dump it */
5939  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5940 
5941  /* Do not try to dump ACL if no ACL exists. */
5942  if (PQgetisnull(res, i, i_aggacl) && PQgetisnull(res, i, i_raggacl) &&
5943  PQgetisnull(res, i, i_initaggacl) &&
5944  PQgetisnull(res, i, i_initraggacl))
5945  agginfo[i].aggfn.dobj.dump &= ~DUMP_COMPONENT_ACL;
5946  }
5947 
5948  PQclear(res);
5949 
5950  destroyPQExpBuffer(query);
5951 
5952  return agginfo;
5953 }
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1908
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
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:3176
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:143
Definition: pg_dump.h:45
DumpOptions * dopt
Definition: pg_backup.h:191
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:725
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1124
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
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:680
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4950
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:3595
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196

◆ getCasts()

CastInfo* getCasts ( Archive fout,
int *  numCasts 
)

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

8397 {
8398  PGresult *res;
8399  int ntups;
8400  int i;
8401  PQExpBuffer query = createPQExpBuffer();
8402  CastInfo *castinfo;
8403  int i_tableoid;
8404  int i_oid;
8405  int i_castsource;
8406  int i_casttarget;
8407  int i_castfunc;
8408  int i_castcontext;
8409  int i_castmethod;
8410 
8411  if (fout->remoteVersion >= 140000)
8412  {
8413  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8414  "castsource, casttarget, castfunc, castcontext, "
8415  "castmethod "
8416  "FROM pg_cast c "
8417  "WHERE NOT EXISTS ( "
8418  "SELECT 1 FROM pg_range r "
8419  "WHERE c.castsource = r.rngtypid "
8420  "AND c.casttarget = r.rngmultitypid "
8421  ") "
8422  "ORDER BY 3,4");
8423  }
8424  else if (fout->remoteVersion >= 80400)
8425  {
8426  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8427  "castsource, casttarget, castfunc, castcontext, "
8428  "castmethod "
8429  "FROM pg_cast ORDER BY 3,4");
8430  }
8431  else
8432  {
8433  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8434  "castsource, casttarget, castfunc, castcontext, "
8435  "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
8436  "FROM pg_cast ORDER BY 3,4");
8437  }
8438 
8439  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8440 
8441  ntups = PQntuples(res);
8442 
8443  *numCasts = ntups;
8444 
8445  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
8446 
8447  i_tableoid = PQfnumber(res, "tableoid");
8448  i_oid = PQfnumber(res, "oid");
8449  i_castsource = PQfnumber(res, "castsource");
8450  i_casttarget = PQfnumber(res, "casttarget");
8451  i_castfunc = PQfnumber(res, "castfunc");
8452  i_castcontext = PQfnumber(res, "castcontext");
8453  i_castmethod = PQfnumber(res, "castmethod");
8454 
8455  for (i = 0; i < ntups; i++)
8456  {
8457  PQExpBufferData namebuf;
8458  TypeInfo *sTypeInfo;
8459  TypeInfo *tTypeInfo;
8460 
8461  castinfo[i].dobj.objType = DO_CAST;
8462  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8463  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8464  AssignDumpId(&castinfo[i].dobj);
8465  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
8466  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
8467  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
8468  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
8469  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
8470 
8471  /*
8472  * Try to name cast as concatenation of typnames. This is only used
8473  * for purposes of sorting. If we fail to find either type, the name
8474  * will be an empty string.
8475  */
8476  initPQExpBuffer(&namebuf);
8477  sTypeInfo = findTypeByOid(castinfo[i].castsource);
8478  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
8479  if (sTypeInfo && tTypeInfo)
8480  appendPQExpBuffer(&namebuf, "%s %s",
8481  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
8482  castinfo[i].dobj.name = namebuf.data;
8483 
8484  /* Decide whether we want to dump it */
8485  selectDumpableCast(&(castinfo[i]), fout);
8486 
8487  /* Casts do not currently have ACLs. */
8488  castinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8489  }
8490 
8491  PQclear(res);
8492 
8493  destroyPQExpBuffer(query);
8494 
8495  return castinfo;
8496 }
char * name
Definition: pg_dump.h:131
Oid castsource
Definition: pg_dump.h:482
DumpComponents dump
Definition: pg_dump.h:132
Oid tableoid
Definition: pg_backup.h:239
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:1774
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
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:3176
Oid castfunc
Definition: pg_dump.h:484
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:481
Oid casttarget
Definition: pg_dump.h:483
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:164
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
void PQclear(PGresult *res)
Definition: fe-exec.c:680
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
CatalogId catId
Definition: pg_dump.h:129
int i
char castmethod
Definition: pg_dump.h:486
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:904
DumpableObjectType objType
Definition: pg_dump.h:128
char castcontext
Definition: pg_dump.h:485
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196

◆ getCollations()

CollInfo* getCollations ( Archive fout,
int *  numCollations 
)

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

5389 {
5390  PGresult *res;
5391  int ntups;
5392  int i;
5393  PQExpBuffer query;
5394  CollInfo *collinfo;
5395  int i_tableoid;
5396  int i_oid;
5397  int i_collname;
5398  int i_collnamespace;
5399  int i_rolname;
5400 
5401  /* Collations didn't exist pre-9.1 */
5402  if (fout->remoteVersion < 90100)
5403  {
5404  *numCollations = 0;
5405  return NULL;
5406  }
5407 
5408  query = createPQExpBuffer();
5409 
5410  /*
5411  * find all collations, including builtin collations; we filter out
5412  * system-defined collations at dump-out time.
5413  */
5414 
5415  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
5416  "collnamespace, "
5417  "(%s collowner) AS rolname "
5418  "FROM pg_collation",
5420 
5421  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5422 
5423  ntups = PQntuples(res);
5424  *numCollations = ntups;
5425 
5426  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
5427 
5428  i_tableoid = PQfnumber(res, "tableoid");
5429  i_oid = PQfnumber(res, "oid");
5430  i_collname = PQfnumber(res, "collname");
5431  i_collnamespace = PQfnumber(res, "collnamespace");
5432  i_rolname = PQfnumber(res, "rolname");
5433 
5434  for (i = 0; i < ntups; i++)
5435  {
5436  collinfo[i].dobj.objType = DO_COLLATION;
5437  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5438  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5439  AssignDumpId(&collinfo[i].dobj);
5440  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
5441  collinfo[i].dobj.namespace =
5442  findNamespace(atooid(PQgetvalue(res, i, i_collnamespace)));
5443  collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5444 
5445  /* Decide whether we want to dump it */
5446  selectDumpableObject(&(collinfo[i].dobj), fout);
5447 
5448  /* Collations do not currently have ACLs. */
5449  collinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5450  }
5451 
5452  PQclear(res);
5453 
5454  destroyPQExpBuffer(query);
5455 
5456  return collinfo;
5457 }
char * name
Definition: pg_dump.h:131
DumpComponents dump
Definition: pg_dump.h:132
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1908
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
DumpableObject dobj
Definition: pg_dump.h:246
char * rolname
Definition: pg_dump.h:247
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
void PQclear(PGresult *res)
Definition: fe-exec.c:680
static int numCollations
Definition: common.c:60
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4950
CatalogId catId
Definition: pg_dump.h:129
int i
DumpableObjectType objType
Definition: pg_dump.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196

◆ getConstraints()

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

Definition at line 7570 of file pg_dump.c.

References addConstrChildIdxDeps(), 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, i, _tableInfo::indexes, InvalidOid, _dumpableObject::name, _tableInfo::numIndexes, numTables, _dumpableObject::objType, CatalogId::oid, pg_log_info, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relkind, Archive::remoteVersion, resetPQExpBuffer(), _constraintInfo::separate, and CatalogId::tableoid.

Referenced by getSchemaData().

7571 {
7572  int i,
7573  j;
7574  ConstraintInfo *constrinfo;
7575  PQExpBuffer query;
7576  PGresult *res;
7577  int i_contableoid,
7578  i_conoid,
7579  i_conname,
7580  i_confrelid,
7581  i_conindid,
7582  i_condef;
7583  int ntups;
7584 
7585  query = createPQExpBuffer();
7586 
7587  for (i = 0; i < numTables; i++)
7588  {
7589  TableInfo *tbinfo = &tblinfo[i];
7590 
7591  /*
7592  * For partitioned tables, foreign keys have no triggers so they must
7593  * be included anyway in case some foreign keys are defined.
7594  */
7595  if ((!tbinfo->hastriggers &&
7596  tbinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7597  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
7598  continue;
7599 
7600  pg_log_info("reading foreign key constraints for table \"%s.%s\"",
7601  tbinfo->dobj.namespace->dobj.name,
7602  tbinfo->dobj.name);
7603 
7604  resetPQExpBuffer(query);
7605  if (fout->remoteVersion >= 110000)
7606  appendPQExpBuffer(query,
7607  "SELECT tableoid, oid, conname, confrelid, conindid, "
7608  "pg_catalog.pg_get_constraintdef(oid) AS condef "
7609  "FROM pg_catalog.pg_constraint "
7610  "WHERE conrelid = '%u'::pg_catalog.oid "
7611  "AND conparentid = 0 "
7612  "AND contype = 'f'",
7613  tbinfo->dobj.catId.oid);
7614  else
7615  appendPQExpBuffer(query,
7616  "SELECT tableoid, oid, conname, confrelid, 0 as conindid, "
7617  "pg_catalog.pg_get_constraintdef(oid) AS condef "
7618  "FROM pg_catalog.pg_constraint "
7619  "WHERE conrelid = '%u'::pg_catalog.oid "
7620  "AND contype = 'f'",
7621  tbinfo->dobj.catId.oid);
7622  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7623 
7624  ntups = PQntuples(res);
7625 
7626  i_contableoid = PQfnumber(res, "tableoid");
7627  i_conoid = PQfnumber(res, "oid");
7628  i_conname = PQfnumber(res, "conname");
7629  i_confrelid = PQfnumber(res, "confrelid");
7630  i_conindid = PQfnumber(res, "conindid");
7631  i_condef = PQfnumber(res, "condef");
7632 
7633  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7634 
7635  for (j = 0; j < ntups; j++)
7636  {
7637  TableInfo *reftable;
7638 
7639  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
7640  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7641  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7642  AssignDumpId(&constrinfo[j].dobj);
7643  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7644  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7645  constrinfo[j].contable = tbinfo;
7646  constrinfo[j].condomain = NULL;
7647  constrinfo[j].contype = 'f';
7648  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7649  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
7650  constrinfo[j].conindex = 0;
7651  constrinfo[j].condeferrable = false;
7652  constrinfo[j].condeferred = false;
7653  constrinfo[j].conislocal = true;
7654  constrinfo[j].separate = true;
7655 
7656  /*
7657  * Restoring an FK that points to a partitioned table requires
7658  * that all partition indexes have been attached beforehand.
7659  * Ensure that happens by making the constraint depend on each
7660  * index partition attach object.
7661  */
7662  reftable = findTableByOid(constrinfo[j].confrelid);
7663  if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
7664  {
7665  Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
7666 
7667  if (indexOid != InvalidOid)
7668  {
7669  for (int k = 0; k < reftable->numIndexes; k++)
7670  {
7671  IndxInfo *refidx;
7672 
7673  /* not our index? */
7674  if (reftable->indexes[k].dobj.catId.oid != indexOid)
7675  continue;
7676 
7677  refidx = &reftable->indexes[k];
7678  addConstrChildIdxDeps(&constrinfo[j].dobj, refidx);
7679  break;
7680  }
7681  }
7682  }
7683  }
7684 
7685  PQclear(res);
7686  }
7687 
7688  destroyPQExpBuffer(query);
7689 }
char * name
Definition: pg_dump.h:131
TableInfo * findTableByOid(Oid oid)
Definition: common.c:893
static void addConstrChildIdxDeps(DumpableObject *dobj, const IndxInfo *refidx)
Definition: pg_dump.c:7703
char relkind
Definition: pg_dump.h:267
DumpComponents dump
Definition: pg_dump.h:132
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
bool hastriggers
Definition: pg_dump.h:277
static int numTables
Definition: common.c:56
unsigned int Oid
Definition: postgres_ext.h:31
DumpId conindex
Definition: pg_dump.h:458
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
DumpableObject dobj
Definition: pg_dump.h:261
char * condef
Definition: pg_dump.h:456
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:452
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:459
TypeInfo * condomain
Definition: pg_dump.h:454
bool conislocal
Definition: pg_dump.h:461
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int numIndexes
Definition: pg_dump.h:336
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
TableInfo * contable
Definition: pg_dump.h:453
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:680
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:90
bool condeferred
Definition: pg_dump.h:460
struct _indxInfo * indexes
Definition: pg_dump.h:337
CatalogId catId
Definition: pg_dump.h:129
DumpableObject dobj
Definition: pg_dump.h:368
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148
DumpableObjectType objType
Definition: pg_dump.h:128
#define pg_log_info(...)
Definition: logging.h:88
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196

◆ getConversions()

ConvInfo* getConversions ( Archive fout,
int *  numConversions 
)

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

5468 {
5469  PGresult *res;
5470  int ntups;
5471  int i;
5472  PQExpBuffer query;
5473  ConvInfo *convinfo;
5474  int i_tableoid;
5475  int i_oid;
5476  int i_conname;
5477  int i_connamespace;
5478  int i_rolname;
5479 
5480  query = createPQExpBuffer();
5481 
5482  /*
5483  * find all conversions, including builtin conversions; we filter out
5484  * system-defined conversions at dump-out time.
5485  */
5486 
5487  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
5488  "connamespace, "
5489  "(%s conowner) AS rolname "
5490  "FROM pg_conversion",
5492 
5493  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5494 
5495  ntups = PQntuples(res);
5496  *numConversions = ntups;
5497 
5498  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
5499 
5500  i_tableoid = PQfnumber(res, "tableoid");
5501  i_oid = PQfnumber(res, "oid");
5502  i_conname = PQfnumber(res, "conname");
5503  i_connamespace = PQfnumber(res, "connamespace");
5504  i_rolname = PQfnumber(res, "rolname");
5505 
5506  for (i = 0; i < ntups; i++)
5507  {
5508  convinfo[i].dobj.objType = DO_CONVERSION;
5509  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5510  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5511  AssignDumpId(&convinfo[i].dobj);
5512  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
5513  convinfo[i].dobj.namespace =
5514  findNamespace(atooid(PQgetvalue(res, i, i_connamespace)));
5515  convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5516 
5517  /* Decide whether we want to dump it */
5518  selectDumpableObject(&(convinfo[i].dobj), fout);
5519 
5520  /* Conversions do not currently have ACLs. */
5521  convinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5522  }
5523 
5524  PQclear(res);
5525 
5526  destroyPQExpBuffer(query);
5527 
5528  return convinfo;
5529 }
char * name
Definition: pg_dump.h:131
DumpComponents dump
Definition: pg_dump.h:132
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1908
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * rolname
Definition: pg_dump.h:253
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
void PQclear(PGresult *res)
Definition: fe-exec.c:680
DumpableObject dobj
Definition: pg_dump.h:252
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4950
CatalogId catId
Definition: pg_dump.h:129
int i
DumpableObjectType objType
Definition: pg_dump.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294

◆ getDefaultACLs()

DefaultACLInfo* getDefaultACLs ( Archive fout,
int *  numDefaultACLs 
)

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

9715 {
9716  DumpOptions *dopt = fout->dopt;
9717  DefaultACLInfo *daclinfo;
9718  PQExpBuffer query;
9719  PGresult *res;
9720  int i_oid;
9721  int i_tableoid;
9722  int i_defaclrole;
9723  int i_defaclnamespace;
9724  int i_defaclobjtype;
9725  int i_defaclacl;
9726  int i_rdefaclacl;
9727  int i_initdefaclacl;
9728  int i_initrdefaclacl;
9729  int i,
9730  ntups;
9731 
9732  if (fout->remoteVersion < 90000)
9733  {
9734  *numDefaultACLs = 0;
9735  return NULL;
9736  }
9737 
9738  query = createPQExpBuffer();
9739 
9740  if (fout->remoteVersion >= 90600)
9741  {
9742  PQExpBuffer acl_subquery = createPQExpBuffer();
9743  PQExpBuffer racl_subquery = createPQExpBuffer();
9744  PQExpBuffer initacl_subquery = createPQExpBuffer();
9745  PQExpBuffer initracl_subquery = createPQExpBuffer();
9746 
9747  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9748  initracl_subquery, "defaclacl", "defaclrole",
9749  "CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
9750  dopt->binary_upgrade);
9751 
9752  appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
9753  "(%s d.defaclrole) AS defaclrole, "
9754  "d.defaclnamespace, "
9755  "d.defaclobjtype, "
9756  "%s AS defaclacl, "
9757  "%s AS rdefaclacl, "
9758  "%s AS initdefaclacl, "
9759  "%s AS initrdefaclacl "
9760  "FROM pg_default_acl d "
9761  "LEFT JOIN pg_init_privs pip ON "
9762  "(d.oid = pip.objoid "
9763  "AND pip.classoid = 'pg_default_acl'::regclass "
9764  "AND pip.objsubid = 0) ",
9766  acl_subquery->data,
9767  racl_subquery->data,
9768  initacl_subquery->data,
9769  initracl_subquery->data);
9770 
9771  destroyPQExpBuffer(acl_subquery);
9772  destroyPQExpBuffer(racl_subquery);
9773  destroyPQExpBuffer(initacl_subquery);
9774  destroyPQExpBuffer(initracl_subquery);
9775  }
9776  else
9777  {
9778  appendPQExpBuffer(query, "SELECT oid, tableoid, "
9779  "(%s defaclrole) AS defaclrole, "
9780  "defaclnamespace, "
9781  "defaclobjtype, "
9782  "defaclacl, "
9783  "NULL AS rdefaclacl, "
9784  "NULL AS initdefaclacl, "
9785  "NULL AS initrdefaclacl "
9786  "FROM pg_default_acl",
9788  }
9789 
9790  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9791 
9792  ntups = PQntuples(res);
9793  *numDefaultACLs = ntups;
9794 
9795  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9796 
9797  i_oid = PQfnumber(res, "oid");
9798  i_tableoid = PQfnumber(res, "tableoid");
9799  i_defaclrole = PQfnumber(res, "defaclrole");
9800  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9801  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9802  i_defaclacl = PQfnumber(res, "defaclacl");
9803  i_rdefaclacl = PQfnumber(res, "rdefaclacl");
9804  i_initdefaclacl = PQfnumber(res, "initdefaclacl");
9805  i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
9806 
9807  for (i = 0; i < ntups; i++)
9808  {
9809  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9810 
9811  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9812  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9813  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9814  AssignDumpId(&daclinfo[i].dobj);
9815  /* cheesy ... is it worth coming up with a better object name? */
9816  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9817 
9818  if (nspid != InvalidOid)
9819  daclinfo[i].dobj.namespace = findNamespace(nspid);
9820  else
9821  daclinfo[i].dobj.namespace = NULL;
9822 
9823  daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
9824  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9825  daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9826  daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
9827  daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
9828  daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
9829 
9830  /* Decide whether we want to dump it */
9831  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9832  }
9833 
9834  PQclear(res);
9835 
9836  destroyPQExpBuffer(query);
9837 
9838  return daclinfo;
9839 }
char * name
Definition: pg_dump.h:131
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * rdefaclacl
Definition: pg_dump.h:570
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition: pg_dump.c:1752
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:143
DumpOptions * dopt
Definition: pg_backup.h:191
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:725
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:566
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
char * defaclacl
Definition: pg_dump.h:569
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:680
char * initdefaclacl
Definition: pg_dump.h:571
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4950
CatalogId catId
Definition: pg_dump.h:129
char * initrdefaclacl
Definition: pg_dump.h:572
int i
char defaclobjtype
Definition: pg_dump.h:568
DumpableObjectType objType
Definition: pg_dump.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196
char * defaclrole
Definition: pg_dump.h:567

◆ getDumpableObjects()

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

Definition at line 824 of file common.c.

References allocedDumpIds, i, and pg_malloc().

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

825 {
826  int i,
827  j;
828 
829  *objs = (DumpableObject **)
831  j = 0;
832  for (i = 1; i < allocedDumpIds; i++)
833  {
834  if (dumpIdMap[i])
835  (*objs)[j++] = dumpIdMap[i];
836  }
837  *numObjs = j;
838 }
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 8124 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().

8125 {
8126  int i;
8127  PQExpBuffer query;
8128  PGresult *res;
8129  EventTriggerInfo *evtinfo;
8130  int i_tableoid,
8131  i_oid,
8132  i_evtname,
8133  i_evtevent,
8134  i_evtowner,
8135  i_evttags,
8136  i_evtfname,
8137  i_evtenabled;
8138  int ntups;
8139 
8140  /* Before 9.3, there are no event triggers */
8141  if (fout->remoteVersion < 90300)
8142  {
8143  *numEventTriggers = 0;
8144  return NULL;
8145  }
8146 
8147  query = createPQExpBuffer();
8148 
8149  appendPQExpBuffer(query,
8150  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8151  "evtevent, (%s evtowner) AS evtowner, "
8152  "array_to_string(array("
8153  "select quote_literal(x) "
8154  " from unnest(evttags) as t(x)), ', ') as evttags, "
8155  "e.evtfoid::regproc as evtfname "
8156  "FROM pg_event_trigger e "
8157  "ORDER BY e.oid",
8159 
8160  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8161 
8162  ntups = PQntuples(res);
8163 
8164  *numEventTriggers = ntups;
8165 
8166  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
8167 
8168  i_tableoid = PQfnumber(res, "tableoid");
8169  i_oid = PQfnumber(res, "oid");
8170  i_evtname = PQfnumber(res, "evtname");
8171  i_evtevent = PQfnumber(res, "evtevent");
8172  i_evtowner = PQfnumber(res, "evtowner");
8173  i_evttags = PQfnumber(res, "evttags");
8174  i_evtfname = PQfnumber(res, "evtfname");
8175  i_evtenabled = PQfnumber(res, "evtenabled");
8176 
8177  for (i = 0; i < ntups; i++)
8178  {
8179  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
8180  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8181  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8182  AssignDumpId(&evtinfo[i].dobj);
8183  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
8184  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
8185  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
8186  evtinfo[i].evtowner = pg_strdup(PQgetvalue(res, i, i_evtowner));
8187  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
8188  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
8189  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
8190 
8191  /* Decide whether we want to dump it */
8192  selectDumpableObject(&(evtinfo[i].dobj), fout);
8193 
8194  /* Event Triggers do not currently have ACLs. */
8195  evtinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8196  }
8197 
8198  PQclear(res);
8199 
8200  destroyPQExpBuffer(query);
8201 
8202  return evtinfo;
8203 }
char * name
Definition: pg_dump.h:131
char * evtevent
Definition: pg_dump.h:435
DumpComponents dump
Definition: pg_dump.h:132
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1908
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
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:436
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
char * evtfname
Definition: pg_dump.h:438
char * evttags
Definition: pg_dump.h:437
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
char * evtname
Definition: pg_dump.h:434
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
void PQclear(PGresult *res)
Definition: fe-exec.c:680
DumpableObject dobj
Definition: pg_dump.h:433
char evtenabled
Definition: pg_dump.h:439
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
CatalogId catId
Definition: pg_dump.h:129
int i
DumpableObjectType objType
Definition: pg_dump.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196

◆ getExtendedStatistics()

void getExtendedStatistics ( Archive fout)

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

7494 {
7495  PQExpBuffer query;
7496  PGresult *res;
7497  StatsExtInfo *statsextinfo;
7498  int ntups;
7499  int i_tableoid;
7500  int i_oid;
7501  int i_stxname;
7502  int i_stxnamespace;
7503  int i_rolname;
7504  int i_stattarget;
7505  int i;
7506 
7507  /* Extended statistics were new in v10 */
7508  if (fout->remoteVersion < 100000)
7509  return;
7510 
7511  query = createPQExpBuffer();
7512 
7513  if (fout->remoteVersion < 130000)
7514  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7515  "stxnamespace, (%s stxowner) AS rolname, (-1) AS stxstattarget "
7516  "FROM pg_catalog.pg_statistic_ext",
7518  else
7519  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7520  "stxnamespace, (%s stxowner) AS rolname, stxstattarget "
7521  "FROM pg_catalog.pg_statistic_ext",
7523 
7524  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7525 
7526  ntups = PQntuples(res);
7527 
7528  i_tableoid = PQfnumber(res, "tableoid");
7529  i_oid = PQfnumber(res, "oid");
7530  i_stxname = PQfnumber(res, "stxname");
7531  i_stxnamespace = PQfnumber(res, "stxnamespace");
7532  i_rolname = PQfnumber(res, "rolname");
7533  i_stattarget = PQfnumber(res, "stxstattarget");
7534 
7535  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
7536 
7537  for (i = 0; i < ntups; i++)
7538  {
7539  statsextinfo[i].dobj.objType = DO_STATSEXT;
7540  statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7541  statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7542  AssignDumpId(&statsextinfo[i].dobj);
7543  statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
7544  statsextinfo[i].dobj.namespace =
7545  findNamespace(atooid(PQgetvalue(res, i, i_stxnamespace)));
7546  statsextinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
7547  statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
7548 
7549  /* Decide whether we want to dump it */
7550  selectDumpableObject(&(statsextinfo[i].dobj), fout);
7551 
7552  /* Stats objects do not currently have ACLs. */
7553  statsextinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7554  }
7555 
7556  PQclear(res);
7557  destroyPQExpBuffer(query);
7558 }
char * name
Definition: pg_dump.h:131
DumpComponents dump
Definition: pg_dump.h:132
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1908
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpableObject dobj
Definition: pg_dump.h:397
int stattarget
Definition: pg_dump.h:399
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
char * rolname
Definition: pg_dump.h:398
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
void PQclear(PGresult *res)
Definition: fe-exec.c:680
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4950
CatalogId catId
Definition: pg_dump.h:129
int i
DumpableObjectType objType
Definition: pg_dump.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196

◆ getExtensionMembership()

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

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

18009 {
18010  PQExpBuffer query;
18011  PGresult *res;
18012  int ntups,
18013  nextmembers,
18014  i;
18015  int i_classid,
18016  i_objid,
18017  i_refobjid;
18019  ExtensionInfo *ext;
18020 
18021  /* Nothing to do if no extensions */
18022  if (numExtensions == 0)
18023  return;
18024 
18025  query = createPQExpBuffer();
18026 
18027  /* refclassid constraint is redundant but may speed the search */
18028  appendPQExpBufferStr(query, "SELECT "
18029  "classid, objid, refobjid "
18030  "FROM pg_depend "
18031  "WHERE refclassid = 'pg_extension'::regclass "
18032  "AND deptype = 'e' "
18033  "ORDER BY 3");
18034 
18035  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
18036 
18037  ntups = PQntuples(res);
18038 
18039  i_classid = PQfnumber(res, "classid");
18040  i_objid = PQfnumber(res, "objid");
18041  i_refobjid = PQfnumber(res, "refobjid");
18042 
18043  extmembers = (ExtensionMemberId *) pg_malloc(ntups * sizeof(ExtensionMemberId));
18044  nextmembers = 0;
18045 
18046  /*
18047  * Accumulate data into extmembers[].
18048  *
18049  * Since we ordered the SELECT by referenced ID, we can expect that
18050  * multiple entries for the same extension will appear together; this
18051  * saves on searches.
18052  */
18053  ext = NULL;
18054 
18055  for (i = 0; i < ntups; i++)
18056  {
18057  CatalogId objId;
18058  Oid extId;
18059 
18060  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
18061  objId.oid = atooid(PQgetvalue(res, i, i_objid));
18062  extId = atooid(PQgetvalue(res, i, i_refobjid));
18063 
18064  if (ext == NULL ||
18065  ext->dobj.catId.oid != extId)
18066  ext = findExtensionByOid(extId);
18067 
18068  if (ext == NULL)
18069  {
18070  /* shouldn't happen */
18071  pg_log_warning("could not find referenced extension %u", extId);
18072  continue;
18073  }
18074 
18075  extmembers[nextmembers].catId = objId;
18076  extmembers[nextmembers].ext = ext;
18077  nextmembers++;
18078  }
18079 
18080  PQclear(res);
18081 
18082  /* Remember the data for use later */
18083  setExtensionMembership(extmembers, nextmembers);
18084 
18085  destroyPQExpBuffer(query);
18086 }
ExtensionInfo * ext
Definition: pg_dump.h:651
DumpableObject dobj
Definition: pg_dump.h:154
Oid tableoid
Definition: pg_backup.h:239
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
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:3176
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void setExtensionMembership(ExtensionMemberId *extmems, int nextmems)
Definition: common.c:993
static int numExtensions
Definition: common.c:62
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
static ExtensionMemberId * extmembers
Definition: common.c:66
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:959
void PQclear(PGresult *res)
Definition: fe-exec.c:680
CatalogId catId
Definition: pg_dump.h:129
CatalogId catId
Definition: pg_dump.h:650
int i
#define pg_log_warning(...)
Definition: pgfnames.c:24
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294

◆ getExtensions()

ExtensionInfo* getExtensions ( Archive fout,
int *  numExtensions 
)

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

4969 {
4970  DumpOptions *dopt = fout->dopt;
4971  PGresult *res;
4972  int ntups;
4973  int i;
4974  PQExpBuffer query;
4975  ExtensionInfo *extinfo;
4976  int i_tableoid;
4977  int i_oid;
4978  int i_extname;
4979  int i_nspname;
4980  int i_extrelocatable;
4981  int i_extversion;
4982  int i_extconfig;
4983  int i_extcondition;
4984 
4985  /*
4986  * Before 9.1, there are no extensions.
4987  */
4988  if (fout->remoteVersion < 90100)
4989  {
4990  *numExtensions = 0;
4991  return NULL;
4992  }
4993 
4994  query = createPQExpBuffer();
4995 
4996  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
4997  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
4998  "FROM pg_extension x "
4999  "JOIN pg_namespace n ON n.oid = x.extnamespace");
5000 
5001  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5002 
5003  ntups = PQntuples(res);
5004 
5005  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
5006 
5007  i_tableoid = PQfnumber(res, "tableoid");
5008  i_oid = PQfnumber(res, "oid");
5009  i_extname = PQfnumber(res, "extname");
5010  i_nspname = PQfnumber(res, "nspname");
5011  i_extrelocatable = PQfnumber(res, "extrelocatable");
5012  i_extversion = PQfnumber(res, "extversion");
5013  i_extconfig = PQfnumber(res, "extconfig");
5014  i_extcondition = PQfnumber(res, "extcondition");
5015 
5016  for (i = 0; i < ntups; i++)
5017  {
5018  extinfo[i].dobj.objType = DO_EXTENSION;
5019  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5020  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5021  AssignDumpId(&extinfo[i].dobj);
5022  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
5023  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
5024  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
5025  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
5026  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
5027  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
5028 
5029  /* Decide whether we want to dump it */
5030  selectDumpableExtension(&(extinfo[i]), dopt);
5031  }
5032 
5033  PQclear(res);
5034  destroyPQExpBuffer(query);
5035 
5036  *numExtensions = ntups;
5037 
5038  return extinfo;
5039 }
char * name
Definition: pg_dump.h:131
DumpableObject dobj
Definition: pg_dump.h:154
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
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:3176
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpOptions * dopt
Definition: pg_backup.h:191
char * extconfig
Definition: pg_dump.h:158
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static int numExtensions
Definition: common.c:62
#define atooid(x)
Definition: postgres_ext.h:42
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:1860
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
void PQclear(PGresult *res)
Definition: fe-exec.c:680
char * extcondition
Definition: pg_dump.h:159
CatalogId catId
Definition: pg_dump.h:129
int i
DumpableObjectType objType
Definition: pg_dump.h:128
bool relocatable
Definition: pg_dump.h:155
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196
char * extversion
Definition: pg_dump.h:157

◆ getForeignDataWrappers()

FdwInfo* getForeignDataWrappers ( Archive fout,
int *  numForeignDataWrappers 
)

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

9399 {
9400  DumpOptions *dopt = fout->dopt;
9401  PGresult *res;
9402  int ntups;
9403  int i;
9404  PQExpBuffer query;
9405  FdwInfo *fdwinfo;
9406  int i_tableoid;
9407  int i_oid;
9408  int i_fdwname;
9409  int i_rolname;
9410  int i_fdwhandler;
9411  int i_fdwvalidator;
9412  int i_fdwacl;
9413  int i_rfdwacl;
9414  int i_initfdwacl;
9415  int i_initrfdwacl;
9416  int i_fdwoptions;
9417 
9418  /* Before 8.4, there are no foreign-data wrappers */
9419  if (fout->remoteVersion < 80400)
9420  {
9421  *numForeignDataWrappers = 0;
9422  return NULL;
9423  }
9424 
9425  query = createPQExpBuffer();
9426 
9427  if (fout->remoteVersion >= 90600)
9428  {
9429  PQExpBuffer acl_subquery = createPQExpBuffer();
9430  PQExpBuffer racl_subquery = createPQExpBuffer();
9431  PQExpBuffer initacl_subquery = createPQExpBuffer();
9432  PQExpBuffer initracl_subquery = createPQExpBuffer();
9433 
9434  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9435  initracl_subquery, "f.fdwacl", "f.fdwowner", "'F'",
9436  dopt->binary_upgrade);
9437 
9438  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.fdwname, "
9439  "(%s f.fdwowner) AS rolname, "
9440  "f.fdwhandler::pg_catalog.regproc, "
9441  "f.fdwvalidator::pg_catalog.regproc, "
9442  "%s AS fdwacl, "
9443  "%s AS rfdwacl, "
9444  "%s AS initfdwacl, "
9445  "%s AS initrfdwacl, "
9446  "array_to_string(ARRAY("
9447  "SELECT quote_ident(option_name) || ' ' || "
9448  "quote_literal(option_value) "
9449  "FROM pg_options_to_table(f.fdwoptions) "
9450  "ORDER BY option_name"
9451  "), E',\n ') AS fdwoptions "
9452  "FROM pg_foreign_data_wrapper f "
9453  "LEFT JOIN pg_init_privs pip ON "
9454  "(f.oid = pip.objoid "
9455  "AND pip.classoid = 'pg_foreign_data_wrapper'::regclass "
9456  "AND pip.objsubid = 0) ",
9458  acl_subquery->data,
9459  racl_subquery->data,
9460  initacl_subquery->data,
9461  initracl_subquery->data);
9462 
9463  destroyPQExpBuffer(acl_subquery);
9464  destroyPQExpBuffer(racl_subquery);
9465  destroyPQExpBuffer(initacl_subquery);
9466  destroyPQExpBuffer(initracl_subquery);
9467  }
9468  else if (fout->remoteVersion >= 90100)
9469  {
9470  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
9471  "(%s fdwowner) AS rolname, "
9472  "fdwhandler::pg_catalog.regproc, "
9473  "fdwvalidator::pg_catalog.regproc, fdwacl, "
9474  "NULL as rfdwacl, "
9475  "NULL as initfdwacl, NULL AS initrfdwacl, "
9476  "array_to_string(ARRAY("
9477  "SELECT quote_ident(option_name) || ' ' || "
9478  "quote_literal(option_value) "
9479  "FROM pg_options_to_table(fdwoptions) "
9480  "ORDER BY option_name"
9481  "), E',\n ') AS fdwoptions "
9482  "FROM pg_foreign_data_wrapper",
9484  }
9485  else
9486  {
9487  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
9488  "(%s fdwowner) AS rolname, "
9489  "'-' AS fdwhandler, "
9490  "fdwvalidator::pg_catalog.regproc, fdwacl, "
9491  "NULL as rfdwacl, "
9492  "NULL as initfdwacl, NULL AS initrfdwacl, "
9493  "array_to_string(ARRAY("
9494  "SELECT quote_ident(option_name) || ' ' || "
9495  "quote_literal(option_value) "
9496  "FROM pg_options_to_table(fdwoptions) "
9497  "ORDER BY option_name"
9498  "), E',\n ') AS fdwoptions "
9499  "FROM pg_foreign_data_wrapper",
9501  }
9502 
9503  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9504 
9505  ntups = PQntuples(res);
9506  *numForeignDataWrappers = ntups;
9507 
9508  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
9509 
9510  i_tableoid = PQfnumber(res, "tableoid");
9511  i_oid = PQfnumber(res, "oid");
9512  i_fdwname = PQfnumber(res, "fdwname");
9513  i_rolname = PQfnumber(res, "rolname");
9514  i_fdwhandler = PQfnumber(res, "fdwhandler");
9515  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
9516  i_fdwacl = PQfnumber(res, "fdwacl");
9517  i_rfdwacl = PQfnumber(res, "rfdwacl");
9518  i_initfdwacl = PQfnumber(res, "initfdwacl");
9519  i_initrfdwacl = PQfnumber(res, "initrfdwacl");
9520  i_fdwoptions = PQfnumber(res, "fdwoptions");
9521 
9522  for (i = 0; i < ntups; i++)
9523  {
9524  fdwinfo[i].dobj.objType = DO_FDW;
9525  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9526  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9527  AssignDumpId(&fdwinfo[i].dobj);
9528  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
9529  fdwinfo[i].dobj.namespace = NULL;
9530  fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
9531  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
9532  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
9533  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
9534  fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
9535  fdwinfo[i].rfdwacl = pg_strdup(PQgetvalue(res, i, i_rfdwacl));
9536  fdwinfo[i].initfdwacl = pg_strdup(PQgetvalue(res, i, i_initfdwacl));
9537  fdwinfo[i].initrfdwacl = pg_strdup(PQgetvalue(res, i, i_initrfdwacl));
9538 
9539  /* Decide whether we want to dump it */
9540  selectDumpableObject(&(fdwinfo[i].dobj), fout);
9541 
9542  /* Do not try to dump ACL if no ACL exists. */
9543  if (PQgetisnull(res, i, i_fdwacl) && PQgetisnull(res, i, i_rfdwacl) &&
9544  PQgetisnull(res, i, i_initfdwacl) &&
9545  PQgetisnull(res, i, i_initrfdwacl))
9546  fdwinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9547  }
9548 
9549  PQclear(res);
9550 
9551  destroyPQExpBuffer(query);
9552 
9553  return fdwinfo;
9554 }
char * name
Definition: pg_dump.h:131
char * rfdwacl
Definition: pg_dump.h:545
DumpComponents dump
Definition: pg_dump.h:132
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1908
Oid tableoid
Definition: pg_backup.h:239
char * fdwhandler
Definition: pg_dump.h:541
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * fdwoptions
Definition: pg_dump.h:543
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:539
int binary_upgrade
Definition: pg_backup.h:143
DumpOptions * dopt
Definition: pg_backup.h:191
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:725
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * fdwvalidator
Definition: pg_dump.h:542
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:544
static const char * username_subquery
Definition: pg_dump.c:94
char * rolname
Definition: pg_dump.h:540
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
void PQclear(PGresult *res)
Definition: fe-exec.c:680
char * initfdwacl
Definition: pg_dump.h:546
Definition: pg_dump.h:71
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
char * initrfdwacl
Definition: pg_dump.h:547
CatalogId catId
Definition: pg_dump.h:129
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3595
DumpableObjectType objType
Definition: pg_dump.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196

◆ getForeignServers()

ForeignServerInfo* getForeignServers ( Archive fout,
int *  numForeignServers 
)

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

9565 {
9566  DumpOptions *dopt = fout->dopt;
9567  PGresult *res;
9568  int ntups;
9569  int i;
9570  PQExpBuffer query;
9571  ForeignServerInfo *srvinfo;
9572  int i_tableoid;
9573  int i_oid;
9574  int i_srvname;
9575  int i_rolname;
9576  int i_srvfdw;
9577  int i_srvtype;
9578  int i_srvversion;
9579  int i_srvacl;
9580  int i_rsrvacl;
9581  int i_initsrvacl;
9582  int i_initrsrvacl;
9583  int i_srvoptions;
9584 
9585  /* Before 8.4, there are no foreign servers */
9586  if (fout->remoteVersion < 80400)
9587  {
9588  *numForeignServers = 0;
9589  return NULL;
9590  }
9591 
9592  query = createPQExpBuffer();
9593 
9594  if (fout->remoteVersion >= 90600)
9595  {
9596  PQExpBuffer acl_subquery = createPQExpBuffer();
9597  PQExpBuffer racl_subquery = createPQExpBuffer();
9598  PQExpBuffer initacl_subquery = createPQExpBuffer();
9599  PQExpBuffer initracl_subquery = createPQExpBuffer();
9600 
9601  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9602  initracl_subquery, "f.srvacl", "f.srvowner", "'S'",
9603  dopt->binary_upgrade);
9604 
9605  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.srvname, "
9606  "(%s f.srvowner) AS rolname, "
9607  "f.srvfdw, f.srvtype, f.srvversion, "
9608  "%s AS srvacl, "
9609  "%s AS rsrvacl, "
9610  "%s AS initsrvacl, "
9611  "%s AS initrsrvacl, "
9612  "array_to_string(ARRAY("
9613  "SELECT quote_ident(option_name) || ' ' || "
9614  "quote_literal(option_value) "
9615  "FROM pg_options_to_table(f.srvoptions) "
9616  "ORDER BY option_name"
9617  "), E',\n ') AS srvoptions "
9618  "FROM pg_foreign_server f "
9619  "LEFT JOIN pg_init_privs pip "
9620  "ON (f.oid = pip.objoid "
9621  "AND pip.classoid = 'pg_foreign_server'::regclass "
9622  "AND pip.objsubid = 0) ",
9624  acl_subquery->data,
9625  racl_subquery->data,
9626  initacl_subquery->data,
9627  initracl_subquery->data);
9628 
9629  destroyPQExpBuffer(acl_subquery);
9630  destroyPQExpBuffer(racl_subquery);
9631  destroyPQExpBuffer(initacl_subquery);
9632  destroyPQExpBuffer(initracl_subquery);
9633  }
9634  else
9635  {
9636  appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
9637  "(%s srvowner) AS rolname, "
9638  "srvfdw, srvtype, srvversion, srvacl, "
9639  "NULL AS rsrvacl, "
9640  "NULL AS initsrvacl, NULL AS initrsrvacl, "
9641  "array_to_string(ARRAY("
9642  "SELECT quote_ident(option_name) || ' ' || "
9643  "quote_literal(option_value) "
9644  "FROM pg_options_to_table(srvoptions) "
9645  "ORDER BY option_name"
9646  "), E',\n ') AS srvoptions "
9647  "FROM pg_foreign_server",
9649  }
9650 
9651  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9652 
9653  ntups = PQntuples(res);
9654  *numForeignServers = ntups;
9655 
9656  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
9657 
9658  i_tableoid = PQfnumber(res, "tableoid");
9659  i_oid = PQfnumber(res, "oid");
9660  i_srvname = PQfnumber(res, "srvname");
9661  i_rolname = PQfnumber(res, "rolname");
9662  i_srvfdw = PQfnumber(res, "srvfdw");
9663  i_srvtype = PQfnumber(res, "srvtype");
9664  i_srvversion = PQfnumber(res, "srvversion");
9665  i_srvacl = PQfnumber(res, "srvacl");
9666  i_rsrvacl = PQfnumber(res, "rsrvacl");
9667  i_initsrvacl = PQfnumber(res, "initsrvacl");
9668  i_initrsrvacl = PQfnumber(res, "initrsrvacl");
9669  i_srvoptions = PQfnumber(res, "srvoptions");
9670 
9671  for (i = 0; i < ntups; i++)
9672  {
9673  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
9674  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9675  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9676  AssignDumpId(&srvinfo[i].dobj);
9677  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
9678  srvinfo[i].dobj.namespace = NULL;
9679  srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
9680  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
9681  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
9682  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
9683  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
9684  srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl));
9685  srvinfo[i].rsrvacl = pg_strdup(PQgetvalue(res, i, i_rsrvacl));
9686  srvinfo[i].initsrvacl = pg_strdup(PQgetvalue(res, i, i_initsrvacl));
9687  srvinfo[i].initrsrvacl = pg_strdup(PQgetvalue(res, i, i_initrsrvacl));
9688 
9689  /* Decide whether we want to dump it */
9690  selectDumpableObject(&(srvinfo[i].dobj), fout);
9691 
9692  /* Do not try to dump ACL if no ACL exists. */
9693  if (PQgetisnull(res, i, i_srvacl) && PQgetisnull(res, i, i_rsrvacl) &&
9694  PQgetisnull(res, i, i_initsrvacl) &&
9695  PQgetisnull(res, i, i_initrsrvacl))
9696  srvinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9697  }
9698 
9699  PQclear(res);
9700 
9701  destroyPQExpBuffer(query);
9702 
9703  return srvinfo;
9704 }
char * srvoptions
Definition: pg_dump.h:561
char * name
Definition: pg_dump.h:131
DumpComponents dump
Definition: pg_dump.h:132
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1908
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
char * initrsrvacl
Definition: pg_dump.h:560
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:143
DumpOptions * dopt
Definition: pg_backup.h:191
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:725
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
char * srvversion
Definition: pg_dump.h:556
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
void PQclear(PGresult *res)
Definition: fe-exec.c:680
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
CatalogId catId
Definition: pg_dump.h:129
DumpableObject dobj
Definition: pg_dump.h:552
int i
char * initsrvacl
Definition: pg_dump.h:559
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3595
DumpableObjectType objType
Definition: pg_dump.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196

◆ getFuncs()

FuncInfo* getFuncs ( Archive fout,
int *  numFuncs 
)

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

5964 {
5965  DumpOptions *dopt = fout->dopt;
5966  PGresult *res;
5967  int ntups;
5968  int i;
5969  PQExpBuffer query = createPQExpBuffer();
5970  FuncInfo *finfo;
5971  int i_tableoid;
5972  int i_oid;
5973  int i_proname;
5974  int i_pronamespace;
5975  int i_rolname;
5976  int i_prolang;
5977  int i_pronargs;
5978  int i_proargtypes;
5979  int i_prorettype;
5980  int i_proacl;
5981  int i_rproacl;
5982  int i_initproacl;
5983  int i_initrproacl;
5984 
5985  /*
5986  * Find all interesting functions. This is a bit complicated:
5987  *
5988  * 1. Always exclude aggregates; those are handled elsewhere.
5989  *
5990  * 2. Always exclude functions that are internally dependent on something
5991  * else, since presumably those will be created as a result of creating
5992  * the something else. This currently acts only to suppress constructor
5993  * functions for range types (so we only need it in 9.2 and up). Note
5994  * this is OK only because the constructors don't have any dependencies
5995  * the range type doesn't have; otherwise we might not get creation
5996  * ordering correct.
5997  *
5998  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
5999  * they're members of extensions and we are in binary-upgrade mode then
6000  * include them, since we want to dump extension members individually in
6001  * that mode. Also, if they are used by casts or transforms then we need
6002  * to gather the information about them, though they won't be dumped if
6003  * they are built-in. Also, in 9.6 and up, include functions in
6004  * pg_catalog if they have an ACL different from what's shown in
6005  * pg_init_privs.
6006  */
6007  if (fout->remoteVersion >= 90600)
6008  {
6009  PQExpBuffer acl_subquery = createPQExpBuffer();
6010  PQExpBuffer racl_subquery = createPQExpBuffer();
6011  PQExpBuffer initacl_subquery = createPQExpBuffer();
6012  PQExpBuffer initracl_subquery = createPQExpBuffer();
6013  const char *not_agg_check;
6014 
6015  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
6016  initracl_subquery, "p.proacl", "p.proowner", "'f'",
6017  dopt->binary_upgrade);
6018 
6019  not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
6020  : "NOT p.proisagg");
6021 
6022  appendPQExpBuffer(query,
6023  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6024  "p.pronargs, p.proargtypes, p.prorettype, "
6025  "%s AS proacl, "
6026  "%s AS rproacl, "
6027  "%s AS initproacl, "
6028  "%s AS initrproacl, "
6029  "p.pronamespace, "
6030  "(%s p.proowner) AS rolname "
6031  "FROM pg_proc p "
6032  "LEFT JOIN pg_init_privs pip ON "
6033  "(p.oid = pip.objoid "
6034  "AND pip.classoid = 'pg_proc'::regclass "
6035  "AND pip.objsubid = 0) "
6036  "WHERE %s"
6037  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6038  "WHERE classid = 'pg_proc'::regclass AND "
6039  "objid = p.oid AND deptype = 'i')"
6040  "\n AND ("
6041  "\n pronamespace != "
6042  "(SELECT oid FROM pg_namespace "
6043  "WHERE nspname = 'pg_catalog')"
6044  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6045  "\n WHERE pg_cast.oid > %u "
6046  "\n AND p.oid = pg_cast.castfunc)"
6047  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6048  "\n WHERE pg_transform.oid > %u AND "
6049  "\n (p.oid = pg_transform.trffromsql"
6050  "\n OR p.oid = pg_transform.trftosql))",
6051  acl_subquery->data,
6052  racl_subquery->data,
6053  initacl_subquery->data,
6054  initracl_subquery->data,
6056  not_agg_check,
6059  if (dopt->binary_upgrade)
6060  appendPQExpBufferStr(query,
6061  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6062  "classid = 'pg_proc'::regclass AND "
6063  "objid = p.oid AND "
6064  "refclassid = 'pg_extension'::regclass AND "
6065  "deptype = 'e')");
6066  appendPQExpBufferStr(query,
6067  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
6068  appendPQExpBufferChar(query, ')');
6069 
6070  destroyPQExpBuffer(acl_subquery);
6071  destroyPQExpBuffer(racl_subquery);
6072  destroyPQExpBuffer(initacl_subquery);
6073  destroyPQExpBuffer(initracl_subquery);
6074  }
6075  else
6076  {
6077  appendPQExpBuffer(query,
6078  "SELECT tableoid, oid, proname, prolang, "
6079  "pronargs, proargtypes, prorettype, proacl, "
6080  "NULL as rproacl, "
6081  "NULL as initproacl, NULL AS initrproacl, "
6082  "pronamespace, "
6083  "(%s proowner) AS rolname "
6084  "FROM pg_proc p "
6085  "WHERE NOT proisagg",
6087  if (fout->remoteVersion >= 90200)
6088  appendPQExpBufferStr(query,
6089  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6090  "WHERE classid = 'pg_proc'::regclass AND "
6091  "objid = p.oid AND deptype = 'i')");
6092  appendPQExpBuffer(query,
6093  "\n AND ("
6094  "\n pronamespace != "
6095  "(SELECT oid FROM pg_namespace "
6096  "WHERE nspname = 'pg_catalog')"
6097  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6098  "\n WHERE pg_cast.oid > '%u'::oid"
6099  "\n AND p.oid = pg_cast.castfunc)",
6101 
6102  if (fout->remoteVersion >= 90500)
6103  appendPQExpBuffer(query,
6104  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6105  "\n WHERE pg_transform.oid > '%u'::oid"
6106  "\n AND (p.oid = pg_transform.trffromsql"
6107  "\n OR p.oid = pg_transform.trftosql))",
6109 
6110  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
6111  appendPQExpBufferStr(query,
6112  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6113  "classid = 'pg_proc'::regclass AND "
6114  "objid = p.oid AND "
6115  "refclassid = 'pg_extension'::regclass AND "
6116  "deptype = 'e')");
6117  appendPQExpBufferChar(query, ')');
6118  }
6119 
6120  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6121 
6122  ntups = PQntuples(res);
6123 
6124  *numFuncs = ntups;
6125 
6126  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
6127 
6128  i_tableoid = PQfnumber(res, "tableoid");
6129  i_oid = PQfnumber(res, "oid");
6130  i_proname = PQfnumber(res, "proname");
6131  i_pronamespace = PQfnumber(res, "pronamespace");
6132  i_rolname = PQfnumber(res, "rolname");
6133  i_prolang = PQfnumber(res, "prolang");
6134  i_pronargs = PQfnumber(res, "pronargs");
6135  i_proargtypes = PQfnumber(res, "proargtypes");
6136  i_prorettype = PQfnumber(res, "prorettype");
6137  i_proacl = PQfnumber(res, "proacl");
6138  i_rproacl = PQfnumber(res, "rproacl");
6139  i_initproacl = PQfnumber(res, "initproacl");
6140  i_initrproacl = PQfnumber(res, "initrproacl");
6141 
6142  for (i = 0; i < ntups; i++)
6143  {
6144  finfo[i].dobj.objType = DO_FUNC;
6145  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6146  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6147  AssignDumpId(&finfo[i].dobj);
6148  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
6149  finfo[i].dobj.namespace =
6150  findNamespace(atooid(PQgetvalue(res, i, i_pronamespace)));
6151  finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
6152  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
6153  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
6154  finfo[i].proacl = pg_strdup(PQgetvalue(res, i, i_proacl));
6155  finfo[i].rproacl = pg_strdup(PQgetvalue(res, i, i_rproacl));
6156  finfo[i].initproacl = pg_strdup(PQgetvalue(res, i, i_initproacl));
6157  finfo[i].initrproacl = pg_strdup(PQgetvalue(res, i, i_initrproacl));
6158  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
6159  if (finfo[i].nargs == 0)
6160  finfo[i].argtypes = NULL;
6161  else
6162  {
6163  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
6164  parseOidArray(PQgetvalue(res, i, i_proargtypes),
6165  finfo[i].argtypes, finfo[i].nargs);
6166  }
6167 
6168  /* Decide whether we want to dump it */
6169  selectDumpableObject(&(finfo[i].dobj), fout);
6170 
6171  /* Do not try to dump ACL if no ACL exists. */
6172  if (PQgetisnull(res, i, i_proacl) && PQgetisnull(res, i, i_rproacl) &&
6173  PQgetisnull(res, i, i_initproacl) &&
6174  PQgetisnull(res, i, i_initrproacl))
6175  finfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
6176 
6177  if (strlen(finfo[i].rolname) == 0)
6178  pg_log_warning("owner of function \"%s\" appears to be invalid",
6179  finfo[i].dobj.name);
6180  }
6181 
6182  PQclear(res);
6183 
6184  destroyPQExpBuffer(query);
6185 
6186  return finfo;
6187 }
Oid * argtypes
Definition: pg_dump.h:202
char * name
Definition: pg_dump.h:131
DumpComponents dump
Definition: pg_dump.h:132
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1908
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int nargs
Definition: pg_dump.h:201
NameData rolname
Definition: pg_authid.h:34
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
static int numFuncs
Definition: common.c:58
char * initrproacl
Definition: pg_dump.h:207
Oid lang
Definition: pg_dump.h:200
DumpableObject dobj
Definition: pg_dump.h:198
unsigned int Oid
Definition: postgres_ext.h:31
static Oid g_last_builtin_oid
Definition: pg_dump.c:100
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:143
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
DumpOptions * dopt
Definition: pg_backup.h:191
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:725
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1124
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
void PQclear(PGresult *res)
Definition: fe-exec.c:680
Oid prorettype
Definition: pg_dump.h:203
char * initproacl
Definition: pg_dump.h:206
char * rolname
Definition: pg_dump.h:199
char * proacl
Definition: pg_dump.h:204
char * rproacl
Definition: pg_dump.h:205
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4950
CatalogId catId
Definition: pg_dump.h:129
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:3595
DumpableObjectType objType
Definition: pg_dump.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196

◆ getIndexes()

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

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

7139 {
7140  int i,
7141  j;
7142  PQExpBuffer query = createPQExpBuffer();
7143  PGresult *res;
7144  IndxInfo *indxinfo;
7145  ConstraintInfo *constrinfo;
7146  int i_tableoid,
7147  i_oid,
7148  i_indexname,
7149  i_parentidx,
7150  i_indexdef,
7151  i_indnkeyatts,
7152  i_indnatts,
7153  i_indkey,
7154  i_indisclustered,
7155  i_indisreplident,
7156  i_contype,
7157  i_conname,
7158  i_condeferrable,
7159  i_condeferred,
7160  i_contableoid,
7161  i_conoid,
7162  i_condef,
7163  i_tablespace,
7164  i_indreloptions,
7165  i_indstatcols,
7166  i_indstatvals;
7167  int ntups;
7168 
7169  for (i = 0; i < numTables; i++)
7170  {
7171  TableInfo *tbinfo = &tblinfo[i];
7172 
7173  if (!tbinfo->hasindex)
7174  continue;
7175 
7176  /*
7177  * Ignore indexes of tables whose definitions are not to be dumped.
7178  *
7179  * We also need indexes on partitioned tables which have partitions to
7180  * be dumped, in order to dump the indexes on the partitions.
7181  */
7182  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) &&
7183  !tbinfo->interesting)
7184  continue;
7185 
7186  pg_log_info("reading indexes for table \"%s.%s\"",
7187  tbinfo->dobj.namespace->dobj.name,
7188  tbinfo->dobj.name);
7189 
7190  /*
7191  * The point of the messy-looking outer join is to find a constraint
7192  * that is related by an internal dependency link to the index. If we
7193  * find one, create a CONSTRAINT entry linked to the INDEX entry. We
7194  * assume an index won't have more than one internal dependency.
7195  *
7196  * As of 9.0 we don't need to look at pg_depend but can check for a
7197  * match to pg_constraint.conindid. The check on conrelid is
7198  * redundant but useful because that column is indexed while conindid
7199  * is not.
7200  */
7201  resetPQExpBuffer(query);
7202  if (fout->remoteVersion >= 110000)
7203  {
7204  appendPQExpBuffer(query,
7205  "SELECT t.tableoid, t.oid, "
7206  "t.relname AS indexname, "
7207  "inh.inhparent AS parentidx, "
7208  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7209  "i.indnkeyatts AS indnkeyatts, "
7210  "i.indnatts AS indnatts, "
7211  "i.indkey, i.indisclustered, "
7212  "i.indisreplident, "
7213  "c.contype, c.conname, "
7214  "c.condeferrable, c.condeferred, "
7215  "c.tableoid AS contableoid, "
7216  "c.oid AS conoid, "
7217  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7218  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7219  "t.reloptions AS indreloptions, "
7220  "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
7221  " FROM pg_catalog.pg_attribute "
7222  " WHERE attrelid = i.indexrelid AND "
7223  " attstattarget >= 0) AS indstatcols,"
7224  "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
7225  " FROM pg_catalog.pg_attribute "
7226  " WHERE attrelid = i.indexrelid AND "
7227  " attstattarget >= 0) AS indstatvals "
7228  "FROM pg_catalog.pg_index i "
7229  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7230  "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
7231  "LEFT JOIN pg_catalog.pg_constraint c "
7232  "ON (i.indrelid = c.conrelid AND "
7233  "i.indexrelid = c.conindid AND "
7234  "c.contype IN ('p','u','x')) "
7235  "LEFT JOIN pg_catalog.pg_inherits inh "
7236  "ON (inh.inhrelid = indexrelid) "
7237  "WHERE i.indrelid = '%u'::pg_catalog.oid "
7238  "AND (i.indisvalid OR t2.relkind = 'p') "
7239  "AND i.indisready "
7240  "ORDER BY indexname",
7241  tbinfo->dobj.catId.oid);
7242  }
7243  else if (fout->remoteVersion >= 90400)
7244  {
7245  /*
7246  * the test on indisready is necessary in 9.2, and harmless in
7247  * earlier/later versions
7248  */
7249  appendPQExpBuffer(query,
7250  "SELECT t.tableoid, t.oid, "
7251  "t.relname AS indexname, "
7252  "0 AS parentidx, "
7253  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7254  "i.indnatts AS indnkeyatts, "
7255  "i.indnatts AS indnatts, "
7256  "i.indkey, i.indisclustered, "
7257  "i.indisreplident, "
7258  "c.contype, c.conname, "
7259  "c.condeferrable, c.condeferred, "
7260  "c.tableoid AS contableoid, "
7261  "c.oid AS conoid, "
7262  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7263  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7264  "t.reloptions AS indreloptions, "
7265  "'' AS indstatcols, "
7266  "'' AS indstatvals "
7267  "FROM pg_catalog.pg_index i "
7268  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7269  "LEFT JOIN pg_catalog.pg_constraint c "
7270  "ON (i.indrelid = c.conrelid AND "
7271  "i.indexrelid = c.conindid AND "
7272  "c.contype IN ('p','u','x')) "
7273  "WHERE i.indrelid = '%u'::pg_catalog.oid "
7274  "AND i.indisvalid AND i.indisready "
7275  "ORDER BY indexname",
7276  tbinfo->dobj.catId.oid);
7277  }
7278  else if (fout->remoteVersion >= 90000)
7279  {
7280  /*
7281  * the test on indisready is necessary in 9.2, and harmless in
7282  * earlier/later versions
7283  */
7284  appendPQExpBuffer(query,
7285  "SELECT t.tableoid, t.oid, "
7286  "t.relname AS indexname, "
7287  "0 AS parentidx, "
7288  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7289  "i.indnatts AS indnkeyatts, "
7290  "i.indnatts AS indnatts, "
7291  "i.indkey, i.indisclustered, "
7292  "false AS indisreplident, "
7293  "c.contype, c.conname, "
7294  "c.condeferrable, c.condeferred, "
7295  "c.tableoid AS contableoid, "
7296  "c.oid AS conoid, "
7297  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7298  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7299  "t.reloptions AS indreloptions, "
7300  "'' AS indstatcols, "
7301  "'' AS indstatvals "
7302  "FROM pg_catalog.pg_index i "
7303  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7304  "LEFT JOIN pg_catalog.pg_constraint c "
7305  "ON (i.indrelid = c.conrelid AND "
7306  "i.indexrelid = c.conindid AND "
7307  "c.contype IN ('p','u','x')) "
7308  "WHERE i.indrelid = '%u'::pg_catalog.oid "
7309  "AND i.indisvalid AND i.indisready "
7310  "ORDER BY indexname",
7311  tbinfo->dobj.catId.oid);
7312  }
7313  else if (fout->remoteVersion >= 80200)
7314  {
7315  appendPQExpBuffer(query,
7316  "SELECT t.tableoid, t.oid, "
7317  "t.relname AS indexname, "
7318  "0 AS parentidx, "
7319  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7320  "i.indnatts AS indnkeyatts, "
7321  "i.indnatts AS indnatts, "
7322  "i.indkey, i.indisclustered, "
7323  "false AS indisreplident, "
7324  "c.contype, c.conname, "
7325  "c.condeferrable, c.condeferred, "
7326  "c.tableoid AS contableoid, "
7327  "c.oid AS conoid, "
7328  "null AS condef, "
7329  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7330  "t.reloptions AS indreloptions, "
7331  "'' AS indstatcols, "
7332  "'' AS indstatvals "
7333  "FROM pg_catalog.pg_index i "
7334  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7335  "LEFT JOIN pg_catalog.pg_depend d "
7336  "ON (d.classid = t.tableoid "
7337  "AND d.objid = t.oid "
7338  "AND d.deptype = 'i') "
7339  "LEFT JOIN pg_catalog.pg_constraint c "
7340  "ON (d.refclassid = c.tableoid "
7341  "AND d.refobjid = c.oid) "
7342  "WHERE i.indrelid = '%u'::pg_catalog.oid "
7343  "AND i.indisvalid "
7344  "ORDER BY indexname",
7345  tbinfo->dobj.catId.oid);
7346  }
7347  else
7348  {
7349  appendPQExpBuffer(query,
7350  "SELECT t.tableoid, t.oid, "
7351  "t.relname AS indexname, "
7352  "0 AS parentidx, "
7353  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7354  "t.relnatts AS indnkeyatts, "
7355  "t.relnatts AS indnatts, "
7356  "i.indkey, i.indisclustered, "
7357  "false AS indisreplident, "
7358  "c.contype, c.conname, "
7359  "c.condeferrable, c.condeferred, "
7360  "c.tableoid AS contableoid, "
7361  "c.oid AS conoid, "
7362  "null AS condef, "
7363  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7364  "null AS indreloptions, "
7365  "'' AS indstatcols, "
7366  "'' AS indstatvals "
7367  "FROM pg_catalog.pg_index i "
7368  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7369  "LEFT JOIN pg_catalog.pg_depend d "
7370  "ON (d.classid = t.tableoid "
7371  "AND d.objid = t.oid "
7372  "AND d.deptype = 'i') "
7373  "LEFT JOIN pg_catalog.pg_constraint c "
7374  "ON (d.refclassid = c.tableoid "
7375  "AND d.refobjid = c.oid) "
7376  "WHERE i.indrelid = '%u'::pg_catalog.oid "
7377  "ORDER BY indexname",
7378  tbinfo->dobj.catId.oid);
7379  }
7380 
7381  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7382 
7383  ntups = PQntuples(res);
7384 
7385  i_tableoid = PQfnumber(res, "tableoid");
7386  i_oid = PQfnumber(res, "oid");
7387  i_indexname = PQfnumber(res, "indexname");
7388  i_parentidx = PQfnumber(res, "parentidx");
7389  i_indexdef = PQfnumber(res, "indexdef");
7390  i_indnkeyatts = PQfnumber(res, "indnkeyatts");
7391  i_indnatts = PQfnumber(res, "indnatts");
7392  i_indkey = PQfnumber(res, "indkey");
7393  i_indisclustered = PQfnumber(res, "indisclustered");
7394  i_indisreplident = PQfnumber(res, "indisreplident");
7395  i_contype = PQfnumber(res, "contype");
7396  i_conname = PQfnumber(res, "conname");
7397  i_condeferrable = PQfnumber(res, "condeferrable");
7398  i_condeferred = PQfnumber(res, "condeferred");
7399  i_contableoid = PQfnumber(res, "contableoid");
7400  i_conoid = PQfnumber(res, "conoid");
7401  i_condef = PQfnumber(res, "condef");
7402  i_tablespace = PQfnumber(res, "tablespace");
7403  i_indreloptions = PQfnumber(res, "indreloptions");
7404  i_indstatcols = PQfnumber(res, "indstatcols");
7405  i_indstatvals = PQfnumber(res, "indstatvals");
7406 
7407  tbinfo->indexes = indxinfo =
7408  (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
7409  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7410  tbinfo->numIndexes = ntups;
7411 
7412  for (j = 0; j < ntups; j++)
7413  {
7414  char contype;
7415 
7416  indxinfo[j].dobj.objType = DO_INDEX;
7417  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
7418  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
7419  AssignDumpId(&indxinfo[j].dobj);
7420  indxinfo[j].dobj.dump = tbinfo->dobj.dump;
7421  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
7422  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7423  indxinfo[j].indextable = tbinfo;
7424  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
7425  indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
7426  indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
7427  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
7428  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
7429  indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
7430  indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
7431  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
7432  parseOidArray(PQgetvalue(res, j, i_indkey),
7433  indxinfo[j].indkeys, indxinfo[j].indnattrs);
7434  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
7435  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
7436  indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
7437  indxinfo[j].partattaches = (SimplePtrList)
7438  {
7439  NULL, NULL
7440  };
7441  contype = *(PQgetvalue(res, j, i_contype));
7442 
7443  if (contype == 'p' || contype == 'u' || contype == 'x')
7444  {
7445  /*
7446  * If we found a constraint matching the index, create an
7447  * entry for it.
7448  */
7449  constrinfo[j].dobj.objType = DO_CONSTRAINT;
7450  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7451  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7452  AssignDumpId(&constrinfo[j].dobj);
7453  constrinfo[j].dobj.dump = tbinfo->dobj.dump;
7454  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7455  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7456  constrinfo[j].contable = tbinfo;
7457  constrinfo[j].condomain = NULL;
7458  constrinfo[j].contype = contype;
7459  if (contype == 'x')
7460  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7461  else
7462  constrinfo[j].condef = NULL;
7463  constrinfo[j].confrelid = InvalidOid;
7464  constrinfo[j].conindex = indxinfo[j].dobj.dumpId;
7465  constrinfo[j].condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
7466  constrinfo[j].condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
7467  constrinfo[j].conislocal = true;
7468  constrinfo[j].separate = true;
7469 
7470  indxinfo[j].indexconstraint = constrinfo[j].dobj.dumpId;
7471  }
7472  else
7473  {
7474  /* Plain secondary index */
7475  indxinfo[j].indexconstraint = 0;
7476  }
7477  }
7478 
7479  PQclear(res);
7480  }
7481 
7482  destroyPQExpBuffer(query);
7483 }
char * tablespace
Definition: pg_dump.h:371
char * name
Definition: pg_dump.h:131
DumpComponents dump
Definition: pg_dump.h:132
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
struct SimplePtrList SimplePtrList
bool hasindex
Definition: pg_dump.h:275
DumpId dumpId
Definition: pg_dump.h:130
static int numTables
Definition: common.c:56
unsigned int Oid
Definition: postgres_ext.h:31
DumpId conindex
Definition: pg_dump.h:458
DumpId indexconstraint
Definition: pg_dump.h:385
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
char * indexdef
Definition: pg_dump.h:370
DumpableObject dobj
Definition: pg_dump.h:261
Oid parentidx
Definition: pg_dump.h:381
char * condef
Definition: pg_dump.h:456
bool indisreplident
Definition: pg_dump.h:380
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:452
TableInfo * indextable
Definition: pg_dump.h:369
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
Oid * indkeys
Definition: pg_dump.h:377
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:459
char * indreloptions
Definition: pg_dump.h:372
TypeInfo * condomain
Definition: pg_dump.h:454
bool conislocal
Definition: pg_dump.h:461
SimplePtrList partattaches
Definition: pg_dump.h:382
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1124
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int numIndexes
Definition: pg_dump.h:336
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
TableInfo * contable
Definition: pg_dump.h:453
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:680
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:90
bool condeferred
Definition: pg_dump.h:460
int indnkeyattrs
Definition: pg_dump.h:375
char * indstatvals
Definition: pg_dump.h:374
int indnattrs
Definition: pg_dump.h:376
struct _indxInfo * indexes
Definition: pg_dump.h:337
CatalogId catId
Definition: pg_dump.h:129
DumpableObject dobj
Definition: pg_dump.h:368
char * indstatcols
Definition: pg_dump.h:373
bool interesting
Definition: pg_dump.h:295
int i
bool indisclustered
Definition: pg_dump.h:379
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148
DumpableObjectType objType
Definition: pg_dump.h:128
#define pg_log_info(...)
Definition: logging.h:88
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196

◆ getInherits()

InhInfo* getInherits ( Archive fout,
int *  numInherits 
)

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

7093 {
7094  PGresult *res;
7095  int ntups;
7096  int i;
7097  PQExpBuffer query = createPQExpBuffer();
7098  InhInfo *inhinfo;
7099 
7100  int i_inhrelid;
7101  int i_inhparent;
7102 
7103  /* find all the inheritance information */
7104  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
7105 
7106  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7107 
7108  ntups = PQntuples(res);
7109 
7110  *numInherits = ntups;
7111 
7112  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
7113 
7114  i_inhrelid = PQfnumber(res, "inhrelid");
7115  i_inhparent = PQfnumber(res, "inhparent");
7116 
7117  for (i = 0; i < ntups; i++)
7118  {
7119  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
7120  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
7121  }
7122 
7123  PQclear(res);
7124 
7125  destroyPQExpBuffer(query);
7126 
7127  return inhinfo;
7128 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
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:3176
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
Oid inhrelid
Definition: pg_dump.h:501
#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:3284
void PQclear(PGresult *res)
Definition: fe-exec.c:680
Oid inhparent
Definition: pg_dump.h:502
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )

Definition at line 660 of file common.c.

References lastDumpId.

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

661 {
662  return lastDumpId;
663 }
static DumpId lastDumpId
Definition: common.c:31

◆ getNamespaces()

NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

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

4823 {
4824  DumpOptions *dopt = fout->dopt;
4825  PGresult *res;
4826  int ntups;
4827  int i;
4828  PQExpBuffer query;
4829  NamespaceInfo *nsinfo;
4830  int i_tableoid;
4831  int i_oid;
4832  int i_nspname;
4833  int i_rolname;
4834  int i_nspacl;
4835  int i_rnspacl;
4836  int i_initnspacl;
4837  int i_initrnspacl;
4838 
4839  query = createPQExpBuffer();
4840 
4841  /*
4842  * we fetch all namespaces including system ones, so that every object we
4843  * read in can be linked to a containing namespace.
4844  */
4845  if (fout->remoteVersion >= 90600)
4846  {
4847  PQExpBuffer acl_subquery = createPQExpBuffer();
4848  PQExpBuffer racl_subquery = createPQExpBuffer();
4849  PQExpBuffer init_acl_subquery = createPQExpBuffer();
4850  PQExpBuffer init_racl_subquery = createPQExpBuffer();
4851 
4852  buildACLQueries(acl_subquery, racl_subquery, init_acl_subquery,
4853  init_racl_subquery, "n.nspacl", "n.nspowner", "'n'",
4854  dopt->binary_upgrade);
4855 
4856  appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, "
4857  "(%s nspowner) AS rolname, "
4858  "%s as nspacl, "
4859  "%s as rnspacl, "
4860  "%s as initnspacl, "
4861  "%s as initrnspacl "
4862  "FROM pg_namespace n "
4863  "LEFT JOIN pg_init_privs pip "
4864  "ON (n.oid = pip.objoid "
4865  "AND pip.classoid = 'pg_namespace'::regclass "
4866  "AND pip.objsubid = 0",
4868  acl_subquery->data,
4869  racl_subquery->data,
4870  init_acl_subquery->data,
4871  init_racl_subquery->data);
4872 
4873  appendPQExpBufferStr(query, ") ");
4874 
4875  destroyPQExpBuffer(acl_subquery);
4876  destroyPQExpBuffer(racl_subquery);
4877  destroyPQExpBuffer(init_acl_subquery);
4878  destroyPQExpBuffer(init_racl_subquery);
4879  }
4880  else
4881  appendPQExpBuffer(query, "SELECT tableoid, oid, nspname, "
4882  "(%s nspowner) AS rolname, "
4883  "nspacl, NULL as rnspacl, "
4884  "NULL AS initnspacl, NULL as initrnspacl "
4885  "FROM pg_namespace",
4887 
4888  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4889 
4890  ntups = PQntuples(res);
4891 
4892  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
4893 
4894  i_tableoid = PQfnumber(res, "tableoid");
4895  i_oid = PQfnumber(res, "oid");
4896  i_nspname = PQfnumber(res, "nspname");
4897  i_rolname = PQfnumber(res, "rolname");
4898  i_nspacl = PQfnumber(res, "nspacl");
4899  i_rnspacl = PQfnumber(res, "rnspacl");
4900  i_initnspacl = PQfnumber(res, "initnspacl");
4901  i_initrnspacl = PQfnumber(res, "initrnspacl");
4902 
4903  for (i = 0; i < ntups; i++)
4904  {
4905  nsinfo[i].dobj.objType = DO_NAMESPACE;
4906  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4907  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4908  AssignDumpId(&nsinfo[i].dobj);
4909  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
4910  nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4911  nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl));
4912  nsinfo[i].rnspacl = pg_strdup(PQgetvalue(res, i, i_rnspacl));
4913  nsinfo[i].initnspacl = pg_strdup(PQgetvalue(res, i, i_initnspacl));
4914  nsinfo[i].initrnspacl = pg_strdup(PQgetvalue(res, i, i_initrnspacl));
4915 
4916  /* Decide whether to dump this namespace */
4917  selectDumpableNamespace(&nsinfo[i], fout);
4918 
4919  /*
4920  * Do not try to dump ACL if the ACL is empty or the default.
4921  *
4922  * This is useful because, for some schemas/objects, the only
4923  * component we are going to try and dump is the ACL and if we can
4924  * remove that then 'dump' goes to zero/false and we don't consider
4925  * this object for dumping at all later on.
4926  */
4927  if (PQgetisnull(res, i, i_nspacl) && PQgetisnull(res, i, i_rnspacl) &&
4928  PQgetisnull(res, i, i_initnspacl) &&
4929  PQgetisnull(res, i, i_initrnspacl))
4930  nsinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4931 
4932  if (strlen(nsinfo[i].rolname) == 0)
4933  pg_log_warning("owner of schema \"%s\" appears to be invalid",
4934  nsinfo[i].dobj.name);
4935  }
4936 
4937  PQclear(res);
4938  destroyPQExpBuffer(query);
4939 
4940  *numNamespaces = ntups;
4941 
4942  return nsinfo;
4943 }
char * name
Definition: pg_dump.h:131
DumpComponents dump
Definition: pg_dump.h:132
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
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:3176
char * rnspacl
Definition: pg_dump.h:147
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:143
DumpOptions * dopt
Definition: pg_backup.h:191
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:725
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * rolname
Definition: pg_dump.h:145
char * initnspacl
Definition: pg_dump.h:148
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static int numNamespaces
Definition: common.c:61
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1599
void PQclear(PGresult *res)
Definition: fe-exec.c:680
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
char * initrnspacl
Definition: pg_dump.h:149
CatalogId catId
Definition: pg_dump.h:129
int i
char * nspacl
Definition: pg_dump.h:146
DumpableObject dobj
Definition: pg_dump.h:144
#define pg_log_warning(...)
Definition: pgfnames.c:24
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3595
DumpableObjectType objType
Definition: pg_dump.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
int remoteVersion
Definition: pg_backup.h:196

◆ getOpclasses()

OpclassInfo* getOpclasses ( Archive fout,
int *  numOpclasses 
)

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

5614 {
5615  PGresult *res;
5616  int ntups;
5617  int i;
5618  PQExpBuffer query = createPQExpBuffer();
5619  OpclassInfo *opcinfo;
5620  int i_tableoid;
5621  int i_oid;
5622  int i_opcname;
5623  int i_opcnamespace;
5624  int i_rolname;
5625 
5626  /*
5627  * find all opclasses, including builtin opclasses; we filter out
5628  * system-defined opclasses at dump-out time.
5629  */
5630 
5631  appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
5632  "opcnamespace, "
5633  "(%s opcowner) AS rolname "
5634  "FROM pg_opclass",
5636 
5637  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5638 
5639  ntups = PQntuples(res);
5640  *numOpclasses = ntups;
5641 
5642  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
5643 
5644  i_tableoid = PQfnumber(res, "tableoid");
5645  i_oid = PQfnumber(res, "oid");
5646  i_opcname = PQfnumber(res, "opcname");
5647  i_opcnamespace = PQfnumber(res, "opcnamespace");
5648  i_rolname = PQfnumber(res, "rolname");
5649 
5650  for (i = 0; i < ntups; i++)
5651  {
5652  opcinfo[i].dobj.objType = DO_OPCLASS;
5653  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5654  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5655  AssignDumpId(&opcinfo[i].dobj);
5656  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
5657  opcinfo[i].dobj.namespace =
5658  findNamespace(atooid(PQgetvalue(res, i, i_opcnamespace)));
5659  opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5660 
5661  /* Decide whether we want to dump it */
5662  selectDumpableObject(&(opcinfo[i].dobj), fout);
5663 
5664  /* Op Classes do not currently have ACLs. */
5665  opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5666 
5667  if (strlen(opcinfo[i].rolname) == 0)
5668  pg_log_warning("owner of operator class \"%s\" appears to be invalid",
5669  opcinfo[i].dobj.name);
5670  }
5671 
5672  PQclear(res);
5673 
5674  destroyPQExpBuffer(query);
5675 
5676  return opcinfo;
5677 }
char * name
Definition: pg_dump.h:131
DumpComponents dump
Definition: pg_dump.h:132
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1908
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
NameData rolname
Definition: pg_authid.h:34
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
char * rolname
Definition: pg_dump.h:235
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
DumpableObject dobj
Definition: pg_dump.h:234
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
void PQclear(PGresult *res)
Definition: fe-exec.c:680
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4950
CatalogId catId
Definition: pg_dump.h:129
int i
#define pg_log_warning(...)
Definition: pgfnames.c:24
DumpableObjectType objType
Definition: pg_dump.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294

◆ getOperators()

OprInfo* getOperators ( Archive fout,
int *  numOperators 
)

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

5307 {
5308  PGresult *res;
5309  int ntups;
5310  int i;
5311  PQExpBuffer query = createPQExpBuffer();
5312  OprInfo *oprinfo;
5313  int i_tableoid;
5314  int i_oid;
5315  int i_oprname;
5316  int i_oprnamespace;
5317  int i_rolname;
5318  int i_oprkind;
5319  int i_oprcode;
5320 
5321  /*
5322  * find all operators, including builtin operators; we filter out
5323  * system-defined operators at dump-out time.
5324  */
5325 
5326  appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
5327  "oprnamespace, "
5328  "(%s oprowner) AS rolname, "
5329  "oprkind, "
5330  "oprcode::oid AS oprcode "
5331  "FROM pg_operator",
5333 
5334  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5335 
5336  ntups = PQntuples(res);
5337  *numOprs = ntups;
5338 
5339  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
5340 
5341  i_tableoid = PQfnumber(res, "tableoid");
5342  i_oid = PQfnumber(res, "oid");
5343  i_oprname = PQfnumber(res, "oprname");
5344  i_oprnamespace = PQfnumber(res, "oprnamespace");
5345  i_rolname = PQfnumber(res, "rolname");
5346  i_oprkind = PQfnumber(res, "oprkind");
5347  i_oprcode = PQfnumber(res, "oprcode");
5348 
5349  for (i = 0; i < ntups; i++)
5350  {
5351  oprinfo[i].dobj.objType = DO_OPERATOR;
5352  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5353  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5354  AssignDumpId(&oprinfo[i].dobj);
5355  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
5356  oprinfo[i].dobj.namespace =
5357  findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)));
5358  oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5359  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
5360  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
5361 
5362  /* Decide whether we want to dump it */
5363  selectDumpableObject(&(oprinfo[i].dobj), fout);
5364 
5365  /* Operators do not currently have ACLs. */
5366  oprinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5367 
5368  if (strlen(oprinfo[i].rolname) == 0)
5369  pg_log_warning("owner of operator \"%s\" appears to be invalid",
5370  oprinfo[i].dobj.name);
5371  }
5372 
5373  PQclear(res);
5374 
5375  destroyPQExpBuffer(query);
5376 
5377  return oprinfo;
5378 }
char * name
Definition: pg_dump.h:131
DumpableObject dobj
Definition: pg_dump.h:219
DumpComponents dump
Definition: pg_dump.h:132
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1908
Oid tableoid
Definition: pg_backup.h:239
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3570
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
NameData rolname
Definition: pg_authid.h:34
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3176
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:94
char * rolname
Definition: pg_dump.h:220
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3284
void PQclear(PGresult *res)
Definition: fe-exec.c:680
char oprkind
Definition: pg_dump.h:221
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4950
CatalogId catId
Definition: pg_dump.h:129
int i
#define pg_log_warning(...)
Definition: pgfnames.c:24
DumpableObjectType objType
Definition: pg_dump.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:294
Oid oprcode
Definition: pg_dump.h:222

◆ getOpfamilies()

OpfamilyInfo* getOpfamilies ( Archive fout,
int *  numOpfamilies 
)

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

5688 {
5689  PGresult *res;
5690  int ntups;
5691  int i;
5692  PQExpBuffer query;
5693  OpfamilyInfo *opfinfo;
5694  int i_tableoid;
5695  int i_oid;
5696  int i_opfname;
5697  int i_opfnamespace;
5698  int i_rolname;
5699 
5700  /* Before 8.3, there is no separate concept of opfamilies */
5701  if (fout->remoteVersion < 80300)
5702  {
5703  *numOpfamilies = 0;
5704  return NULL;
5705  }
5706 
5707  query = createPQExpBuffer();
5708 
5709  /*
5710  * find all opfamilies, including builtin opfamilies; we filter out
5711  * system-defined opfamilies at dump-out time.
5712  */
5713 
5714  appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, "
5715  "opfnamespace, "
5716  "(%s opfowner) AS rolname "
5717  "FROM pg_opfamily",
5719 
5720  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5721 
5722  ntups = PQntuples(res);
5723  *numOpfamilies = ntups;
5724 
5725  opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
5726 
5727  i_tableoid = PQfnumber(res, "tableoid");
5728  i_oid = PQfnumber(res, "oid");
5729  i_opfname = PQfnumber(res, "opfname");
5730  i_opfnamespace = PQfnumber(res, "opfnamespace");
5731  i_rolname = PQfnumber(res, "rolname");
5732 
5733  for (i = 0; i < ntups; i++)
5734  {
5735  opfinfo[i].dobj.objType = DO_OPFAMILY;
5736  opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5737  opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5738  AssignDumpId(&opfinfo[i].dobj);
5739  opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
5740  opfinfo[i].dobj.namespace =
5741  findNamespace(atooid(PQgetvalue(res, i, i_opfnamespace)));
5742  opfinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5743 
5744  /* Decide whether we want to dump it */
5745  selectDumpableObject(&(opfinfo[i].dobj), fout);
5746 
5747  /* Extensions do not currently have ACLs. */
5748  opfinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5749 
5750  if (strlen(opfinfo[i].rolname) == 0)
5751  pg_log_warning("owner of operator family \"%s\" appears to be invalid",
5752  opfinfo[i].dobj.name);
5753  }
5754 
5755  PQclear(res);
5756 
5757  destroyPQExpBuffer(query);
5758 
5759  return opfinfo;
5760 }
char * name
Definition: pg_dump.h:131
DumpableObject dobj
Definition: pg_dump.h:240
DumpComponents dump
Definition: pg_dump.h:132