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:657
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:656

◆ 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(), getPolicies(), 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(), getFormattedTypeName(), 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 5564 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().

5565 {
5566  PGresult *res;
5567  int ntups;
5568  int i;
5569  PQExpBuffer query;
5570  AccessMethodInfo *aminfo;
5571  int i_tableoid;
5572  int i_oid;
5573  int i_amname;
5574  int i_amhandler;
5575  int i_amtype;
5576 
5577  /* Before 9.6, there are no user-defined access methods */
5578  if (fout->remoteVersion < 90600)
5579  {
5580  *numAccessMethods = 0;
5581  return NULL;
5582  }
5583 
5584  query = createPQExpBuffer();
5585 
5586  /* Select all access methods from pg_am table */
5587  appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, amtype, "
5588  "amhandler::pg_catalog.regproc AS amhandler "
5589  "FROM pg_am");
5590 
5591  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5592 
5593  ntups = PQntuples(res);
5594  *numAccessMethods = ntups;
5595 
5596  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
5597 
5598  i_tableoid = PQfnumber(res, "tableoid");
5599  i_oid = PQfnumber(res, "oid");
5600  i_amname = PQfnumber(res, "amname");
5601  i_amhandler = PQfnumber(res, "amhandler");
5602  i_amtype = PQfnumber(res, "amtype");
5603 
5604  for (i = 0; i < ntups; i++)
5605  {
5606  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
5607  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5608  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5609  AssignDumpId(&aminfo[i].dobj);
5610  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
5611  aminfo[i].dobj.namespace = NULL;
5612  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
5613  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
5614 
5615  /* Decide whether we want to dump it */
5616  selectDumpableAccessMethod(&(aminfo[i]), fout);
5617 
5618  /* Access methods do not currently have ACLs. */
5619  aminfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5620  }
5621 
5622  PQclear(res);
5623 
5624  destroyPQExpBuffer(query);
5625 
5626  return aminfo;
5627 }
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:3642
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:231
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:1825
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:3356
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * amhandler
Definition: pg_dump.h:233
#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 5795 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().

5796 {
5797  DumpOptions *dopt = fout->dopt;
5798  PGresult *res;
5799  int ntups;
5800  int i;
5801  PQExpBuffer query = createPQExpBuffer();
5802  AggInfo *agginfo;
5803  int i_tableoid;
5804  int i_oid;
5805  int i_aggname;
5806  int i_aggnamespace;
5807  int i_pronargs;
5808  int i_proargtypes;
5809  int i_rolname;
5810  int i_aggacl;
5811  int i_raggacl;
5812  int i_initaggacl;
5813  int i_initraggacl;
5814 
5815  /*
5816  * Find all interesting aggregates. See comment in getFuncs() for the
5817  * rationale behind the filtering logic.
5818  */
5819  if (fout->remoteVersion >= 90600)
5820  {
5821  PQExpBuffer acl_subquery = createPQExpBuffer();
5822  PQExpBuffer racl_subquery = createPQExpBuffer();
5823  PQExpBuffer initacl_subquery = createPQExpBuffer();
5824  PQExpBuffer initracl_subquery = createPQExpBuffer();
5825  const char *agg_check;
5826 
5827  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5828  initracl_subquery, "p.proacl", "p.proowner",
5829  "pip.initprivs", "'f'", dopt->binary_upgrade);
5830 
5831  agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
5832  : "p.proisagg");
5833 
5834  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5835  "p.proname AS aggname, "
5836  "p.pronamespace AS aggnamespace, "
5837  "p.pronargs, p.proargtypes, "
5838  "(%s p.proowner) AS rolname, "
5839  "%s AS aggacl, "
5840  "%s AS raggacl, "
5841  "%s AS initaggacl, "
5842  "%s AS initraggacl "
5843  "FROM pg_proc p "
5844  "LEFT JOIN pg_init_privs pip ON "
5845  "(p.oid = pip.objoid "
5846  "AND pip.classoid = 'pg_proc'::regclass "
5847  "AND pip.objsubid = 0) "
5848  "WHERE %s AND ("
5849  "p.pronamespace != "
5850  "(SELECT oid FROM pg_namespace "
5851  "WHERE nspname = 'pg_catalog') OR "
5852  "p.proacl IS DISTINCT FROM pip.initprivs",
5854  acl_subquery->data,
5855  racl_subquery->data,
5856  initacl_subquery->data,
5857  initracl_subquery->data,
5858  agg_check);
5859  if (dopt->binary_upgrade)
5860  appendPQExpBufferStr(query,
5861  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5862  "classid = 'pg_proc'::regclass AND "
5863  "objid = p.oid AND "
5864  "refclassid = 'pg_extension'::regclass AND "
5865  "deptype = 'e')");
5866  appendPQExpBufferChar(query, ')');
5867 
5868  destroyPQExpBuffer(acl_subquery);
5869  destroyPQExpBuffer(racl_subquery);
5870  destroyPQExpBuffer(initacl_subquery);
5871  destroyPQExpBuffer(initracl_subquery);
5872  }
5873  else if (fout->remoteVersion >= 80200)
5874  {
5875  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5876  "pronamespace AS aggnamespace, "
5877  "pronargs, 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 p "
5883  "WHERE proisagg AND ("
5884  "pronamespace != "
5885  "(SELECT oid FROM pg_namespace "
5886  "WHERE nspname = 'pg_catalog')",
5888  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5889  appendPQExpBufferStr(query,
5890  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5891  "classid = 'pg_proc'::regclass AND "
5892  "objid = p.oid AND "
5893  "refclassid = 'pg_extension'::regclass AND "
5894  "deptype = 'e')");
5895  appendPQExpBufferChar(query, ')');
5896  }
5897  else
5898  {
5899  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5900  "pronamespace AS aggnamespace, "
5901  "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
5902  "proargtypes, "
5903  "(%s proowner) AS rolname, "
5904  "proacl AS aggacl, "
5905  "NULL AS raggacl, "
5906  "NULL AS initaggacl, NULL AS initraggacl "
5907  "FROM pg_proc "
5908  "WHERE proisagg "
5909  "AND pronamespace != "
5910  "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
5912  }
5913 
5914  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5915 
5916  ntups = PQntuples(res);
5917  *numAggs = ntups;
5918 
5919  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5920 
5921  i_tableoid = PQfnumber(res, "tableoid");
5922  i_oid = PQfnumber(res, "oid");
5923  i_aggname = PQfnumber(res, "aggname");
5924  i_aggnamespace = PQfnumber(res, "aggnamespace");
5925  i_pronargs = PQfnumber(res, "pronargs");
5926  i_proargtypes = PQfnumber(res, "proargtypes");
5927  i_rolname = PQfnumber(res, "rolname");
5928  i_aggacl = PQfnumber(res, "aggacl");
5929  i_raggacl = PQfnumber(res, "raggacl");
5930  i_initaggacl = PQfnumber(res, "initaggacl");
5931  i_initraggacl = PQfnumber(res, "initraggacl");
5932 
5933  for (i = 0; i < ntups; i++)
5934  {
5935  agginfo[i].aggfn.dobj.objType = DO_AGG;
5936  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5937  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5938  AssignDumpId(&agginfo[i].aggfn.dobj);
5939  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5940  agginfo[i].aggfn.dobj.namespace =
5941  findNamespace(atooid(PQgetvalue(res, i, i_aggnamespace)));
5942  agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5943  if (strlen(agginfo[i].aggfn.rolname) == 0)
5944  pg_log_warning("owner of aggregate function \"%s\" appears to be invalid",
5945  agginfo[i].aggfn.dobj.name);
5946  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5947  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5948  agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5949  agginfo[i].aggfn.rproacl = pg_strdup(PQgetvalue(res, i, i_raggacl));
5950  agginfo[i].aggfn.initproacl = pg_strdup(PQgetvalue(res, i, i_initaggacl));
5951  agginfo[i].aggfn.initrproacl = pg_strdup(PQgetvalue(res, i, i_initraggacl));
5952  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5953  if (agginfo[i].aggfn.nargs == 0)
5954  agginfo[i].aggfn.argtypes = NULL;
5955  else
5956  {
5957  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5958  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5959  agginfo[i].aggfn.argtypes,
5960  agginfo[i].aggfn.nargs);
5961  }
5962 
5963  /* Decide whether we want to dump it */
5964  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5965 
5966  /* Do not try to dump ACL if no ACL exists. */
5967  if (PQgetisnull(res, i, i_aggacl) && PQgetisnull(res, i, i_raggacl) &&
5968  PQgetisnull(res, i, i_initaggacl) &&
5969  PQgetisnull(res, i, i_initraggacl))
5970  agginfo[i].aggfn.dobj.dump &= ~DUMP_COMPONENT_ACL;
5971  }
5972 
5973  PQclear(res);
5974 
5975  destroyPQExpBuffer(query);
5976 
5977  return agginfo;
5978 }
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1901
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3642
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:3248
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 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:97
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:3356
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:694
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 *initprivs_expr, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:725
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4974
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:3667
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 8471 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().

8472 {
8473  PGresult *res;
8474  int ntups;
8475  int i;
8476  PQExpBuffer query = createPQExpBuffer();
8477  CastInfo *castinfo;
8478  int i_tableoid;
8479  int i_oid;
8480  int i_castsource;
8481  int i_casttarget;
8482  int i_castfunc;
8483  int i_castcontext;
8484  int i_castmethod;
8485 
8486  if (fout->remoteVersion >= 140000)
8487  {
8488  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8489  "castsource, casttarget, castfunc, castcontext, "
8490  "castmethod "
8491  "FROM pg_cast c "
8492  "WHERE NOT EXISTS ( "
8493  "SELECT 1 FROM pg_range r "
8494  "WHERE c.castsource = r.rngtypid "
8495  "AND c.casttarget = r.rngmultitypid "
8496  ") "
8497  "ORDER BY 3,4");
8498  }
8499  else if (fout->remoteVersion >= 80400)
8500  {
8501  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8502  "castsource, casttarget, castfunc, castcontext, "
8503  "castmethod "
8504  "FROM pg_cast ORDER BY 3,4");
8505  }
8506  else
8507  {
8508  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8509  "castsource, casttarget, castfunc, castcontext, "
8510  "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
8511  "FROM pg_cast ORDER BY 3,4");
8512  }
8513 
8514  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8515 
8516  ntups = PQntuples(res);
8517 
8518  *numCasts = ntups;
8519 
8520  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
8521 
8522  i_tableoid = PQfnumber(res, "tableoid");
8523  i_oid = PQfnumber(res, "oid");
8524  i_castsource = PQfnumber(res, "castsource");
8525  i_casttarget = PQfnumber(res, "casttarget");
8526  i_castfunc = PQfnumber(res, "castfunc");
8527  i_castcontext = PQfnumber(res, "castcontext");
8528  i_castmethod = PQfnumber(res, "castmethod");
8529 
8530  for (i = 0; i < ntups; i++)
8531  {
8532  PQExpBufferData namebuf;
8533  TypeInfo *sTypeInfo;
8534  TypeInfo *tTypeInfo;
8535 
8536  castinfo[i].dobj.objType = DO_CAST;
8537  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8538  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8539  AssignDumpId(&castinfo[i].dobj);
8540  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
8541  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
8542  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
8543  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
8544  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
8545 
8546  /*
8547  * Try to name cast as concatenation of typnames. This is only used
8548  * for purposes of sorting. If we fail to find either type, the name
8549  * will be an empty string.
8550  */
8551  initPQExpBuffer(&namebuf);
8552  sTypeInfo = findTypeByOid(castinfo[i].castsource);
8553  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
8554  if (sTypeInfo && tTypeInfo)
8555  appendPQExpBuffer(&namebuf, "%s %s",
8556  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
8557  castinfo[i].dobj.name = namebuf.data;
8558 
8559  /* Decide whether we want to dump it */
8560  selectDumpableCast(&(castinfo[i]), fout);
8561 
8562  /* Casts do not currently have ACLs. */
8563  castinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8564  }
8565 
8566  PQclear(res);
8567 
8568  destroyPQExpBuffer(query);
8569 
8570  return castinfo;
8571 }
char * name
Definition: pg_dump.h:131
Oid castsource
Definition: pg_dump.h:487
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:1767
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3642
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:3248
Oid castfunc
Definition: pg_dump.h:489
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:486
Oid casttarget
Definition: pg_dump.h:488
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:166
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
CatalogId catId
Definition: pg_dump.h:129
int i
char castmethod
Definition: pg_dump.h:491
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:904
DumpableObjectType objType
Definition: pg_dump.h:128
char castcontext
Definition: pg_dump.h:490
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 5413 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().

5414 {
5415  PGresult *res;
5416  int ntups;
5417  int i;
5418  PQExpBuffer query;
5419  CollInfo *collinfo;
5420  int i_tableoid;
5421  int i_oid;
5422  int i_collname;
5423  int i_collnamespace;
5424  int i_rolname;
5425 
5426  /* Collations didn't exist pre-9.1 */
5427  if (fout->remoteVersion < 90100)
5428  {
5429  *numCollations = 0;
5430  return NULL;
5431  }
5432 
5433  query = createPQExpBuffer();
5434 
5435  /*
5436  * find all collations, including builtin collations; we filter out
5437  * system-defined collations at dump-out time.
5438  */
5439 
5440  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
5441  "collnamespace, "
5442  "(%s collowner) AS rolname "
5443  "FROM pg_collation",
5445 
5446  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5447 
5448  ntups = PQntuples(res);
5449  *numCollations = ntups;
5450 
5451  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
5452 
5453  i_tableoid = PQfnumber(res, "tableoid");
5454  i_oid = PQfnumber(res, "oid");
5455  i_collname = PQfnumber(res, "collname");
5456  i_collnamespace = PQfnumber(res, "collnamespace");
5457  i_rolname = PQfnumber(res, "rolname");
5458 
5459  for (i = 0; i < ntups; i++)
5460  {
5461  collinfo[i].dobj.objType = DO_COLLATION;
5462  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5463  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5464  AssignDumpId(&collinfo[i].dobj);
5465  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
5466  collinfo[i].dobj.namespace =
5467  findNamespace(atooid(PQgetvalue(res, i, i_collnamespace)));
5468  collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5469 
5470  /* Decide whether we want to dump it */
5471  selectDumpableObject(&(collinfo[i].dobj), fout);
5472 
5473  /* Collations do not currently have ACLs. */
5474  collinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5475  }
5476 
5477  PQclear(res);
5478 
5479  destroyPQExpBuffer(query);
5480 
5481  return collinfo;
5482 }
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:1901
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:3642
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
DumpableObject dobj
Definition: pg_dump.h:250
char * rolname
Definition: pg_dump.h:251
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:97
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
void PQclear(PGresult *res)
Definition: fe-exec.c:694
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:4974
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 7596 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().

7597 {
7598  int i,
7599  j;
7600  ConstraintInfo *constrinfo;
7601  PQExpBuffer query;
7602  PGresult *res;
7603  int i_contableoid,
7604  i_conoid,
7605  i_conname,
7606  i_confrelid,
7607  i_conindid,
7608  i_condef;
7609  int ntups;
7610 
7611  query = createPQExpBuffer();
7612 
7613  for (i = 0; i < numTables; i++)
7614  {
7615  TableInfo *tbinfo = &tblinfo[i];
7616 
7617  /*
7618  * For partitioned tables, foreign keys have no triggers so they must
7619  * be included anyway in case some foreign keys are defined.
7620  */
7621  if ((!tbinfo->hastriggers &&
7622  tbinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7623  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
7624  continue;
7625 
7626  pg_log_info("reading foreign key constraints for table \"%s.%s\"",
7627  tbinfo->dobj.namespace->dobj.name,
7628  tbinfo->dobj.name);
7629 
7630  resetPQExpBuffer(query);
7631  if (fout->remoteVersion >= 110000)
7632  appendPQExpBuffer(query,
7633  "SELECT tableoid, oid, conname, confrelid, conindid, "
7634  "pg_catalog.pg_get_constraintdef(oid) AS condef "
7635  "FROM pg_catalog.pg_constraint "
7636  "WHERE conrelid = '%u'::pg_catalog.oid "
7637  "AND conparentid = 0 "
7638  "AND contype = 'f'",
7639  tbinfo->dobj.catId.oid);
7640  else
7641  appendPQExpBuffer(query,
7642  "SELECT tableoid, oid, conname, confrelid, 0 as conindid, "
7643  "pg_catalog.pg_get_constraintdef(oid) AS condef "
7644  "FROM pg_catalog.pg_constraint "
7645  "WHERE conrelid = '%u'::pg_catalog.oid "
7646  "AND contype = 'f'",
7647  tbinfo->dobj.catId.oid);
7648  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7649 
7650  ntups = PQntuples(res);
7651 
7652  i_contableoid = PQfnumber(res, "tableoid");
7653  i_conoid = PQfnumber(res, "oid");
7654  i_conname = PQfnumber(res, "conname");
7655  i_confrelid = PQfnumber(res, "confrelid");
7656  i_conindid = PQfnumber(res, "conindid");
7657  i_condef = PQfnumber(res, "condef");
7658 
7659  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7660 
7661  for (j = 0; j < ntups; j++)
7662  {
7663  TableInfo *reftable;
7664 
7665  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
7666  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7667  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7668  AssignDumpId(&constrinfo[j].dobj);
7669  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7670  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7671  constrinfo[j].contable = tbinfo;
7672  constrinfo[j].condomain = NULL;
7673  constrinfo[j].contype = 'f';
7674  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7675  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
7676  constrinfo[j].conindex = 0;
7677  constrinfo[j].condeferrable = false;
7678  constrinfo[j].condeferred = false;
7679  constrinfo[j].conislocal = true;
7680  constrinfo[j].separate = true;
7681 
7682  /*
7683  * Restoring an FK that points to a partitioned table requires
7684  * that all partition indexes have been attached beforehand.
7685  * Ensure that happens by making the constraint depend on each
7686  * index partition attach object.
7687  */
7688  reftable = findTableByOid(constrinfo[j].confrelid);
7689  if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
7690  {
7691  Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
7692 
7693  if (indexOid != InvalidOid)
7694  {
7695  for (int k = 0; k < reftable->numIndexes; k++)
7696  {
7697  IndxInfo *refidx;
7698 
7699  /* not our index? */
7700  if (reftable->indexes[k].dobj.catId.oid != indexOid)
7701  continue;
7702 
7703  refidx = &reftable->indexes[k];
7704  addConstrChildIdxDeps(&constrinfo[j].dobj, refidx);
7705  break;
7706  }
7707  }
7708  }
7709  }
7710 
7711  PQclear(res);
7712  }
7713 
7714  destroyPQExpBuffer(query);
7715 }
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:7729
char relkind
Definition: pg_dump.h:271
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:3642
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
bool hastriggers
Definition: pg_dump.h:281
static int numTables
Definition: common.c:56
unsigned int Oid
Definition: postgres_ext.h:31
DumpId conindex
Definition: pg_dump.h:463
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
DumpableObject dobj
Definition: pg_dump.h:265
char * condef
Definition: pg_dump.h:461
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:457
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:464
TypeInfo * condomain
Definition: pg_dump.h:459
bool conislocal
Definition: pg_dump.h:466
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int numIndexes
Definition: pg_dump.h:340
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
TableInfo * contable
Definition: pg_dump.h:458
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:90
bool condeferred
Definition: pg_dump.h:465
struct _indxInfo * indexes
Definition: pg_dump.h:341
CatalogId catId
Definition: pg_dump.h:129
DumpableObject dobj
Definition: pg_dump.h:372
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 5492 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().

5493 {
5494  PGresult *res;
5495  int ntups;
5496  int i;
5497  PQExpBuffer query;
5498  ConvInfo *convinfo;
5499  int i_tableoid;
5500  int i_oid;
5501  int i_conname;
5502  int i_connamespace;
5503  int i_rolname;
5504 
5505  query = createPQExpBuffer();
5506 
5507  /*
5508  * find all conversions, including builtin conversions; we filter out
5509  * system-defined conversions at dump-out time.
5510  */
5511 
5512  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
5513  "connamespace, "
5514  "(%s conowner) AS rolname "
5515  "FROM pg_conversion",
5517 
5518  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5519 
5520  ntups = PQntuples(res);
5521  *numConversions = ntups;
5522 
5523  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
5524 
5525  i_tableoid = PQfnumber(res, "tableoid");
5526  i_oid = PQfnumber(res, "oid");
5527  i_conname = PQfnumber(res, "conname");
5528  i_connamespace = PQfnumber(res, "connamespace");
5529  i_rolname = PQfnumber(res, "rolname");
5530 
5531  for (i = 0; i < ntups; i++)
5532  {
5533  convinfo[i].dobj.objType = DO_CONVERSION;
5534  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5535  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5536  AssignDumpId(&convinfo[i].dobj);
5537  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
5538  convinfo[i].dobj.namespace =
5539  findNamespace(atooid(PQgetvalue(res, i, i_connamespace)));
5540  convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5541 
5542  /* Decide whether we want to dump it */
5543  selectDumpableObject(&(convinfo[i].dobj), fout);
5544 
5545  /* Conversions do not currently have ACLs. */
5546  convinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5547  }
5548 
5549  PQclear(res);
5550 
5551  destroyPQExpBuffer(query);
5552 
5553  return convinfo;
5554 }
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:1901
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:3642
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * rolname
Definition: pg_dump.h:257
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
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:97
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
void PQclear(PGresult *res)
Definition: fe-exec.c:694
DumpableObject dobj
Definition: pg_dump.h:256
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4974
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 9830 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().

9831 {
9832  DumpOptions *dopt = fout->dopt;
9833  DefaultACLInfo *daclinfo;
9834  PQExpBuffer query;
9835  PGresult *res;
9836  int i_oid;
9837  int i_tableoid;
9838  int i_defaclrole;
9839  int i_defaclnamespace;
9840  int i_defaclobjtype;
9841  int i_defaclacl;
9842  int i_rdefaclacl;
9843  int i_initdefaclacl;
9844  int i_initrdefaclacl;
9845  int i,
9846  ntups;
9847 
9848  if (fout->remoteVersion < 90000)
9849  {
9850  *numDefaultACLs = 0;
9851  return NULL;
9852  }
9853 
9854  query = createPQExpBuffer();
9855 
9856  if (fout->remoteVersion >= 90600)
9857  {
9858  PQExpBuffer acl_subquery = createPQExpBuffer();
9859  PQExpBuffer racl_subquery = createPQExpBuffer();
9860  PQExpBuffer initacl_subquery = createPQExpBuffer();
9861  PQExpBuffer initracl_subquery = createPQExpBuffer();
9862 
9863  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9864  initracl_subquery, "defaclacl", "defaclrole",
9865  "pip.initprivs",
9866  "CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
9867  dopt->binary_upgrade);
9868 
9869  appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
9870  "(%s d.defaclrole) AS defaclrole, "
9871  "d.defaclnamespace, "
9872  "d.defaclobjtype, "
9873  "%s AS defaclacl, "
9874  "%s AS rdefaclacl, "
9875  "%s AS initdefaclacl, "
9876  "%s AS initrdefaclacl "
9877  "FROM pg_default_acl d "
9878  "LEFT JOIN pg_init_privs pip ON "
9879  "(d.oid = pip.objoid "
9880  "AND pip.classoid = 'pg_default_acl'::regclass "
9881  "AND pip.objsubid = 0) ",
9883  acl_subquery->data,
9884  racl_subquery->data,
9885  initacl_subquery->data,
9886  initracl_subquery->data);
9887 
9888  destroyPQExpBuffer(acl_subquery);
9889  destroyPQExpBuffer(racl_subquery);
9890  destroyPQExpBuffer(initacl_subquery);
9891  destroyPQExpBuffer(initracl_subquery);
9892  }
9893  else
9894  {
9895  appendPQExpBuffer(query, "SELECT oid, tableoid, "
9896  "(%s defaclrole) AS defaclrole, "
9897  "defaclnamespace, "
9898  "defaclobjtype, "
9899  "defaclacl, "
9900  "NULL AS rdefaclacl, "
9901  "NULL AS initdefaclacl, "
9902  "NULL AS initrdefaclacl "
9903  "FROM pg_default_acl",
9905  }
9906 
9907  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9908 
9909  ntups = PQntuples(res);
9910  *numDefaultACLs = ntups;
9911 
9912  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9913 
9914  i_oid = PQfnumber(res, "oid");
9915  i_tableoid = PQfnumber(res, "tableoid");
9916  i_defaclrole = PQfnumber(res, "defaclrole");
9917  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9918  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9919  i_defaclacl = PQfnumber(res, "defaclacl");
9920  i_rdefaclacl = PQfnumber(res, "rdefaclacl");
9921  i_initdefaclacl = PQfnumber(res, "initdefaclacl");
9922  i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
9923 
9924  for (i = 0; i < ntups; i++)
9925  {
9926  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9927 
9928  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9929  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9930  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9931  AssignDumpId(&daclinfo[i].dobj);
9932  /* cheesy ... is it worth coming up with a better object name? */
9933  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9934 
9935  if (nspid != InvalidOid)
9936  daclinfo[i].dobj.namespace = findNamespace(nspid);
9937  else
9938  daclinfo[i].dobj.namespace = NULL;
9939 
9940  daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
9941  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9942  daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9943  daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
9944  daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
9945  daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
9946 
9947  /* Decide whether we want to dump it */
9948  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9949  }
9950 
9951  PQclear(res);
9952 
9953  destroyPQExpBuffer(query);
9954 
9955  return daclinfo;
9956 }
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:3642
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * rdefaclacl
Definition: pg_dump.h:575
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition: pg_dump.c:1745
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:143
DumpOptions * dopt
Definition: pg_backup.h:191
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:571
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:97
char * defaclacl
Definition: pg_dump.h:574
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * initdefaclacl
Definition: pg_dump.h:576
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 *initprivs_expr, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:725
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4974
CatalogId catId
Definition: pg_dump.h:129
char * initrdefaclacl
Definition: pg_dump.h:577
int i
char defaclobjtype
Definition: pg_dump.h:573
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:572

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

8200 {
8201  int i;
8202  PQExpBuffer query;
8203  PGresult *res;
8204  EventTriggerInfo *evtinfo;
8205  int i_tableoid,
8206  i_oid,
8207  i_evtname,
8208  i_evtevent,
8209  i_evtowner,
8210  i_evttags,
8211  i_evtfname,
8212  i_evtenabled;
8213  int ntups;
8214 
8215  /* Before 9.3, there are no event triggers */
8216  if (fout->remoteVersion < 90300)
8217  {
8218  *numEventTriggers = 0;
8219  return NULL;
8220  }
8221 
8222  query = createPQExpBuffer();
8223 
8224  appendPQExpBuffer(query,
8225  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8226  "evtevent, (%s evtowner) AS evtowner, "
8227  "array_to_string(array("
8228  "select quote_literal(x) "
8229  " from unnest(evttags) as t(x)), ', ') as evttags, "
8230  "e.evtfoid::regproc as evtfname "
8231  "FROM pg_event_trigger e "
8232  "ORDER BY e.oid",
8234 
8235  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8236 
8237  ntups = PQntuples(res);
8238 
8239  *numEventTriggers = ntups;
8240 
8241  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
8242 
8243  i_tableoid = PQfnumber(res, "tableoid");
8244  i_oid = PQfnumber(res, "oid");
8245  i_evtname = PQfnumber(res, "evtname");
8246  i_evtevent = PQfnumber(res, "evtevent");
8247  i_evtowner = PQfnumber(res, "evtowner");
8248  i_evttags = PQfnumber(res, "evttags");
8249  i_evtfname = PQfnumber(res, "evtfname");
8250  i_evtenabled = PQfnumber(res, "evtenabled");
8251 
8252  for (i = 0; i < ntups; i++)
8253  {
8254  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
8255  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8256  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8257  AssignDumpId(&evtinfo[i].dobj);
8258  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
8259  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
8260  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
8261  evtinfo[i].evtowner = pg_strdup(PQgetvalue(res, i, i_evtowner));
8262  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
8263  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
8264  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
8265 
8266  /* Decide whether we want to dump it */
8267  selectDumpableObject(&(evtinfo[i].dobj), fout);
8268 
8269  /* Event Triggers do not currently have ACLs. */
8270  evtinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8271  }
8272 
8273  PQclear(res);
8274 
8275  destroyPQExpBuffer(query);
8276 
8277  return evtinfo;
8278 }
char * name
Definition: pg_dump.h:131
char * evtevent
Definition: pg_dump.h:440
DumpComponents dump
Definition: pg_dump.h:132
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1901
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:3642
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
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:441
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:97
char * evtfname
Definition: pg_dump.h:443
char * evttags
Definition: pg_dump.h:442
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
char * evtname
Definition: pg_dump.h:439
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
void PQclear(PGresult *res)
Definition: fe-exec.c:694
DumpableObject dobj
Definition: pg_dump.h:438
char evtenabled
Definition: pg_dump.h:444
#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 7519 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().

7520 {
7521  PQExpBuffer query;
7522  PGresult *res;
7523  StatsExtInfo *statsextinfo;
7524  int ntups;
7525  int i_tableoid;
7526  int i_oid;
7527  int i_stxname;
7528  int i_stxnamespace;
7529  int i_rolname;
7530  int i_stattarget;
7531  int i;
7532 
7533  /* Extended statistics were new in v10 */
7534  if (fout->remoteVersion < 100000)
7535  return;
7536 
7537  query = createPQExpBuffer();
7538 
7539  if (fout->remoteVersion < 130000)
7540  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7541  "stxnamespace, (%s stxowner) AS rolname, (-1) AS stxstattarget "
7542  "FROM pg_catalog.pg_statistic_ext",
7544  else
7545  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7546  "stxnamespace, (%s stxowner) AS rolname, stxstattarget "
7547  "FROM pg_catalog.pg_statistic_ext",
7549 
7550  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7551 
7552  ntups = PQntuples(res);
7553 
7554  i_tableoid = PQfnumber(res, "tableoid");
7555  i_oid = PQfnumber(res, "oid");
7556  i_stxname = PQfnumber(res, "stxname");
7557  i_stxnamespace = PQfnumber(res, "stxnamespace");
7558  i_rolname = PQfnumber(res, "rolname");
7559  i_stattarget = PQfnumber(res, "stxstattarget");
7560 
7561  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
7562 
7563  for (i = 0; i < ntups; i++)
7564  {
7565  statsextinfo[i].dobj.objType = DO_STATSEXT;
7566  statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7567  statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7568  AssignDumpId(&statsextinfo[i].dobj);
7569  statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
7570  statsextinfo[i].dobj.namespace =
7571  findNamespace(atooid(PQgetvalue(res, i, i_stxnamespace)));
7572  statsextinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
7573  statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
7574 
7575  /* Decide whether we want to dump it */
7576  selectDumpableObject(&(statsextinfo[i].dobj), fout);
7577 
7578  /* Stats objects do not currently have ACLs. */
7579  statsextinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7580  }
7581 
7582  PQclear(res);
7583  destroyPQExpBuffer(query);
7584 }
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:1901
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:3642
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpableObject dobj
Definition: pg_dump.h:401
int stattarget
Definition: pg_dump.h:403
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
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:97
char * rolname
Definition: pg_dump.h:402
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4974
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 18196 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().

18198 {
18199  PQExpBuffer query;
18200  PGresult *res;
18201  int ntups,
18202  nextmembers,
18203  i;
18204  int i_classid,
18205  i_objid,
18206  i_refobjid;
18208  ExtensionInfo *ext;
18209 
18210  /* Nothing to do if no extensions */
18211  if (numExtensions == 0)
18212  return;
18213 
18214  query = createPQExpBuffer();
18215 
18216  /* refclassid constraint is redundant but may speed the search */
18217  appendPQExpBufferStr(query, "SELECT "
18218  "classid, objid, refobjid "
18219  "FROM pg_depend "
18220  "WHERE refclassid = 'pg_extension'::regclass "
18221  "AND deptype = 'e' "
18222  "ORDER BY 3");
18223 
18224  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
18225 
18226  ntups = PQntuples(res);
18227 
18228  i_classid = PQfnumber(res, "classid");
18229  i_objid = PQfnumber(res, "objid");
18230  i_refobjid = PQfnumber(res, "refobjid");
18231 
18232  extmembers = (ExtensionMemberId *) pg_malloc(ntups * sizeof(ExtensionMemberId));
18233  nextmembers = 0;
18234 
18235  /*
18236  * Accumulate data into extmembers[].
18237  *
18238  * Since we ordered the SELECT by referenced ID, we can expect that
18239  * multiple entries for the same extension will appear together; this
18240  * saves on searches.
18241  */
18242  ext = NULL;
18243 
18244  for (i = 0; i < ntups; i++)
18245  {
18246  CatalogId objId;
18247  Oid extId;
18248 
18249  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
18250  objId.oid = atooid(PQgetvalue(res, i, i_objid));
18251  extId = atooid(PQgetvalue(res, i, i_refobjid));
18252 
18253  if (ext == NULL ||
18254  ext->dobj.catId.oid != extId)
18255  ext = findExtensionByOid(extId);
18256 
18257  if (ext == NULL)
18258  {
18259  /* shouldn't happen */
18260  pg_log_warning("could not find referenced extension %u", extId);
18261  continue;
18262  }
18263 
18264  extmembers[nextmembers].catId = objId;
18265  extmembers[nextmembers].ext = ext;
18266  nextmembers++;
18267  }
18268 
18269  PQclear(res);
18270 
18271  /* Remember the data for use later */
18272  setExtensionMembership(extmembers, nextmembers);
18273 
18274  destroyPQExpBuffer(query);
18275 }
ExtensionInfo * ext
Definition: pg_dump.h:657
DumpableObject dobj
Definition: pg_dump.h:156
Oid tableoid
Definition: pg_backup.h:239
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3642
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:3248
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:3356
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:959
void PQclear(PGresult *res)
Definition: fe-exec.c:694
CatalogId catId
Definition: pg_dump.h:129
CatalogId catId
Definition: pg_dump.h:656
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 4992 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().

4993 {
4994  DumpOptions *dopt = fout->dopt;
4995  PGresult *res;
4996  int ntups;
4997  int i;
4998  PQExpBuffer query;
4999  ExtensionInfo *extinfo;
5000  int i_tableoid;
5001  int i_oid;
5002  int i_extname;
5003  int i_nspname;
5004  int i_extrelocatable;
5005  int i_extversion;
5006  int i_extconfig;
5007  int i_extcondition;
5008 
5009  /*
5010  * Before 9.1, there are no extensions.
5011  */
5012  if (fout->remoteVersion < 90100)
5013  {
5014  *numExtensions = 0;
5015  return NULL;
5016  }
5017 
5018  query = createPQExpBuffer();
5019 
5020  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
5021  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
5022  "FROM pg_extension x "
5023  "JOIN pg_namespace n ON n.oid = x.extnamespace");
5024 
5025  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5026 
5027  ntups = PQntuples(res);
5028 
5029  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
5030 
5031  i_tableoid = PQfnumber(res, "tableoid");
5032  i_oid = PQfnumber(res, "oid");
5033  i_extname = PQfnumber(res, "extname");
5034  i_nspname = PQfnumber(res, "nspname");
5035  i_extrelocatable = PQfnumber(res, "extrelocatable");
5036  i_extversion = PQfnumber(res, "extversion");
5037  i_extconfig = PQfnumber(res, "extconfig");
5038  i_extcondition = PQfnumber(res, "extcondition");
5039 
5040  for (i = 0; i < ntups; i++)
5041  {
5042  extinfo[i].dobj.objType = DO_EXTENSION;
5043  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5044  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5045  AssignDumpId(&extinfo[i].dobj);
5046  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
5047  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
5048  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
5049  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
5050  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
5051  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
5052 
5053  /* Decide whether we want to dump it */
5054  selectDumpableExtension(&(extinfo[i]), dopt);
5055  }
5056 
5057  PQclear(res);
5058  destroyPQExpBuffer(query);
5059 
5060  *numExtensions = ntups;
5061 
5062  return extinfo;
5063 }
char * name
Definition: pg_dump.h:131
DumpableObject dobj
Definition: pg_dump.h:156
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:3642
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:3248
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpOptions * dopt
Definition: pg_backup.h:191
char * extconfig
Definition: pg_dump.h:160
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:1853
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * extcondition
Definition: pg_dump.h:161
CatalogId catId
Definition: pg_dump.h:129
int i
DumpableObjectType objType
Definition: pg_dump.h:128
bool relocatable
Definition: pg_dump.h:157
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:159

◆ getForeignDataWrappers()

FdwInfo* getForeignDataWrappers ( Archive fout,
int *  numForeignDataWrappers 
)

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

9515 {
9516  DumpOptions *dopt = fout->dopt;
9517  PGresult *res;
9518  int ntups;
9519  int i;
9520  PQExpBuffer query;
9521  FdwInfo *fdwinfo;
9522  int i_tableoid;
9523  int i_oid;
9524  int i_fdwname;
9525  int i_rolname;
9526  int i_fdwhandler;
9527  int i_fdwvalidator;
9528  int i_fdwacl;
9529  int i_rfdwacl;
9530  int i_initfdwacl;
9531  int i_initrfdwacl;
9532  int i_fdwoptions;
9533 
9534  /* Before 8.4, there are no foreign-data wrappers */
9535  if (fout->remoteVersion < 80400)
9536  {
9537  *numForeignDataWrappers = 0;
9538  return NULL;
9539  }
9540 
9541  query = createPQExpBuffer();
9542 
9543  if (fout->remoteVersion >= 90600)
9544  {
9545  PQExpBuffer acl_subquery = createPQExpBuffer();
9546  PQExpBuffer racl_subquery = createPQExpBuffer();
9547  PQExpBuffer initacl_subquery = createPQExpBuffer();
9548  PQExpBuffer initracl_subquery = createPQExpBuffer();
9549 
9550  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9551  initracl_subquery, "f.fdwacl", "f.fdwowner",
9552  "pip.initprivs", "'F'", dopt->binary_upgrade);
9553 
9554  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.fdwname, "
9555  "(%s f.fdwowner) AS rolname, "
9556  "f.fdwhandler::pg_catalog.regproc, "
9557  "f.fdwvalidator::pg_catalog.regproc, "
9558  "%s AS fdwacl, "
9559  "%s AS rfdwacl, "
9560  "%s AS initfdwacl, "
9561  "%s AS initrfdwacl, "
9562  "array_to_string(ARRAY("
9563  "SELECT quote_ident(option_name) || ' ' || "
9564  "quote_literal(option_value) "
9565  "FROM pg_options_to_table(f.fdwoptions) "
9566  "ORDER BY option_name"
9567  "), E',\n ') AS fdwoptions "
9568  "FROM pg_foreign_data_wrapper f "
9569  "LEFT JOIN pg_init_privs pip ON "
9570  "(f.oid = pip.objoid "
9571  "AND pip.classoid = 'pg_foreign_data_wrapper'::regclass "
9572  "AND pip.objsubid = 0) ",
9574  acl_subquery->data,
9575  racl_subquery->data,
9576  initacl_subquery->data,
9577  initracl_subquery->data);
9578 
9579  destroyPQExpBuffer(acl_subquery);
9580  destroyPQExpBuffer(racl_subquery);
9581  destroyPQExpBuffer(initacl_subquery);
9582  destroyPQExpBuffer(initracl_subquery);
9583  }
9584  else if (fout->remoteVersion >= 90100)
9585  {
9586  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
9587  "(%s fdwowner) AS rolname, "
9588  "fdwhandler::pg_catalog.regproc, "
9589  "fdwvalidator::pg_catalog.regproc, fdwacl, "
9590  "NULL as rfdwacl, "
9591  "NULL as initfdwacl, NULL AS initrfdwacl, "
9592  "array_to_string(ARRAY("
9593  "SELECT quote_ident(option_name) || ' ' || "
9594  "quote_literal(option_value) "
9595  "FROM pg_options_to_table(fdwoptions) "
9596  "ORDER BY option_name"
9597  "), E',\n ') AS fdwoptions "
9598  "FROM pg_foreign_data_wrapper",
9600  }
9601  else
9602  {
9603  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
9604  "(%s fdwowner) AS rolname, "
9605  "'-' AS fdwhandler, "
9606  "fdwvalidator::pg_catalog.regproc, fdwacl, "
9607  "NULL as rfdwacl, "
9608  "NULL as initfdwacl, NULL AS initrfdwacl, "
9609  "array_to_string(ARRAY("
9610  "SELECT quote_ident(option_name) || ' ' || "
9611  "quote_literal(option_value) "
9612  "FROM pg_options_to_table(fdwoptions) "
9613  "ORDER BY option_name"
9614  "), E',\n ') AS fdwoptions "
9615  "FROM pg_foreign_data_wrapper",
9617  }
9618 
9619  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9620 
9621  ntups = PQntuples(res);
9622  *numForeignDataWrappers = ntups;
9623 
9624  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
9625 
9626  i_tableoid = PQfnumber(res, "tableoid");
9627  i_oid = PQfnumber(res, "oid");
9628  i_fdwname = PQfnumber(res, "fdwname");
9629  i_rolname = PQfnumber(res, "rolname");
9630  i_fdwhandler = PQfnumber(res, "fdwhandler");
9631  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
9632  i_fdwacl = PQfnumber(res, "fdwacl");
9633  i_rfdwacl = PQfnumber(res, "rfdwacl");
9634  i_initfdwacl = PQfnumber(res, "initfdwacl");
9635  i_initrfdwacl = PQfnumber(res, "initrfdwacl");
9636  i_fdwoptions = PQfnumber(res, "fdwoptions");
9637 
9638  for (i = 0; i < ntups; i++)
9639  {
9640  fdwinfo[i].dobj.objType = DO_FDW;
9641  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9642  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9643  AssignDumpId(&fdwinfo[i].dobj);
9644  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
9645  fdwinfo[i].dobj.namespace = NULL;
9646  fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
9647  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
9648  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
9649  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
9650  fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
9651  fdwinfo[i].rfdwacl = pg_strdup(PQgetvalue(res, i, i_rfdwacl));
9652  fdwinfo[i].initfdwacl = pg_strdup(PQgetvalue(res, i, i_initfdwacl));
9653  fdwinfo[i].initrfdwacl = pg_strdup(PQgetvalue(res, i, i_initrfdwacl));
9654 
9655  /* Decide whether we want to dump it */
9656  selectDumpableObject(&(fdwinfo[i].dobj), fout);
9657 
9658  /* Do not try to dump ACL if no ACL exists. */
9659  if (PQgetisnull(res, i, i_fdwacl) && PQgetisnull(res, i, i_rfdwacl) &&
9660  PQgetisnull(res, i, i_initfdwacl) &&
9661  PQgetisnull(res, i, i_initrfdwacl))
9662  fdwinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9663  }
9664 
9665  PQclear(res);
9666 
9667  destroyPQExpBuffer(query);
9668 
9669  return fdwinfo;
9670 }
char * name
Definition: pg_dump.h:131
char * rfdwacl
Definition: pg_dump.h:550
DumpComponents dump
Definition: pg_dump.h:132
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1901
Oid tableoid
Definition: pg_backup.h:239
char * fdwhandler
Definition: pg_dump.h:546
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:605
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3642
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * fdwoptions
Definition: pg_dump.h:548
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:544
int binary_upgrade
Definition: pg_backup.h:143
DumpOptions * dopt
Definition: pg_backup.h:191
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * fdwvalidator
Definition: pg_dump.h:547
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:549
static const char * username_subquery
Definition: pg_dump.c:97
char * rolname
Definition: pg_dump.h:545
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * initfdwacl
Definition: pg_dump.h:551
Definition: pg_dump.h:71
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 *initprivs_expr, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:725
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
char * initrfdwacl
Definition: pg_dump.h:552
CatalogId catId
Definition: pg_dump.h:129
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3667
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 9680 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().

9681 {
9682  DumpOptions *dopt = fout->dopt;
9683  PGresult *res;
9684  int ntups;
9685  int i;
9686  PQExpBuffer query;
9687  ForeignServerInfo *srvinfo;
9688  int i_tableoid;
9689  int i_oid;
9690  int i_srvname;
9691  int i_rolname;
9692  int i_srvfdw;
9693  int i_srvtype;
9694  int i_srvversion;
9695  int i_srvacl;
9696  int i_rsrvacl;
9697  int i_initsrvacl;
9698  int i_initrsrvacl;
9699  int i_srvoptions;
9700 
9701  /* Before 8.4, there are no foreign servers */
9702  if (fout->remoteVersion < 80400)
9703  {
9704  *numForeignServers = 0;
9705  return NULL;
9706  }
9707 
9708  query = createPQExpBuffer();
9709 
9710  if (fout->remoteVersion >= 90600)
9711  {
9712  PQExpBuffer acl_subquery = createPQExpBuffer();
9713  PQExpBuffer racl_subquery = createPQExpBuffer();
9714  PQExpBuffer initacl_subquery = createPQExpBuffer();
9715  PQExpBuffer initracl_subquery = createPQExpBuffer();
9716 
9717  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9718  initracl_subquery, "f.srvacl", "f.srvowner",
9719  "pip.initprivs", "'S'", dopt->binary_upgrade);
9720 
9721  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.srvname, "
9722  "(%s f.srvowner) AS rolname, "
9723  "f.srvfdw, f.srvtype, f.srvversion, "
9724  "%s AS srvacl, "
9725  "%s AS rsrvacl, "
9726  "%s AS initsrvacl, "
9727  "%s AS initrsrvacl, "
9728  "array_to_string(ARRAY("
9729  "SELECT quote_ident(option_name) || ' ' || "
9730  "quote_literal(option_value) "
9731  "FROM pg_options_to_table(f.srvoptions) "
9732  "ORDER BY option_name"
9733  "), E',\n ') AS srvoptions "
9734  "FROM pg_foreign_server f "
9735  "LEFT JOIN pg_init_privs pip "
9736  "ON (f.oid = pip.objoid "
9737  "AND pip.classoid = 'pg_foreign_server'::regclass "
9738  "AND pip.objsubid = 0) ",
9740  acl_subquery->data,
9741  racl_subquery->data,
9742  initacl_subquery->data,
9743  initracl_subquery->data);
9744 
9745  destroyPQExpBuffer(acl_subquery);
9746  destroyPQExpBuffer(racl_subquery);
9747  destroyPQExpBuffer(initacl_subquery);
9748  destroyPQExpBuffer(initracl_subquery);
9749  }
9750  else
9751  {
9752  appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
9753  "(%s srvowner) AS rolname, "
9754  "srvfdw, srvtype, srvversion, srvacl, "
9755  "NULL AS rsrvacl, "
9756  "NULL AS initsrvacl, NULL AS initrsrvacl, "
9757  "array_to_string(ARRAY("
9758  "SELECT quote_ident(option_name) || ' ' || "
9759  "quote_literal(option_value) "
9760  "FROM pg_options_to_table(srvoptions) "
9761  "ORDER BY option_name"
9762  "), E',\n ') AS srvoptions "
9763  "FROM pg_foreign_server",
9765  }
9766 
9767  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9768 
9769  ntups = PQntuples(res);
9770  *numForeignServers = ntups;
9771 
9772  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
9773 
9774  i_tableoid = PQfnumber(res, "tableoid");
9775  i_oid = PQfnumber(res, "oid");
9776  i_srvname = PQfnumber(res, "srvname");
9777  i_rolname = PQfnumber(res, "rolname");
9778  i_srvfdw = PQfnumber(res, "srvfdw");
9779  i_srvtype = PQfnumber(res, "srvtype");
9780  i_srvversion = PQfnumber(res, "srvversion");
9781  i_srvacl = PQfnumber(res, "srvacl");
9782  i_rsrvacl = PQfnumber(res, "rsrvacl");
9783  i_initsrvacl = PQfnumber(res, "initsrvacl");
9784  i_initrsrvacl = PQfnumber(res, "initrsrvacl");
9785  i_srvoptions = PQfnumber(res, "srvoptions");
9786 
9787  for (i = 0; i < ntups; i++)
9788  {
9789  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
9790  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9791  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9792  AssignDumpId(&srvinfo[i].dobj);
9793  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
9794  srvinfo[i].dobj.namespace = NULL;
9795  srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
9796  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
9797  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
9798  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
9799  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
9800  srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl));
9801  srvinfo[i].rsrvacl = pg_strdup(PQgetvalue(res, i, i_rsrvacl));
9802  srvinfo[i].initsrvacl = pg_strdup(PQgetvalue(res, i, i_initsrvacl));
9803  srvinfo[i].initrsrvacl = pg_strdup(PQgetvalue(res, i, i_initrsrvacl));
9804 
9805  /* Decide whether we want to dump it */
9806  selectDumpableObject(&(srvinfo[i].dobj), fout);
9807 
9808  /* Do not try to dump ACL if no ACL exists. */
9809  if (PQgetisnull(res, i, i_srvacl) && PQgetisnull(res, i, i_rsrvacl) &&
9810  PQgetisnull(res, i, i_initsrvacl) &&
9811  PQgetisnull(res, i, i_initrsrvacl))
9812  srvinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9813  }
9814 
9815  PQclear(res);
9816 
9817  destroyPQExpBuffer(query);
9818 
9819  return srvinfo;
9820 }
char * srvoptions
Definition: pg_dump.h:566
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:1901
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:3642
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
char * initrsrvacl
Definition: pg_dump.h:565
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:143
DumpOptions * dopt
Definition: pg_backup.h:191
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:97
char * srvversion
Definition: pg_dump.h:561
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
void PQclear(PGresult *res)
Definition: fe-exec.c:694
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 *initprivs_expr, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:725
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
CatalogId catId
Definition: pg_dump.h:129
DumpableObject dobj
Definition: pg_dump.h:557
int i
char * initsrvacl
Definition: pg_dump.h:564
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3667
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 5988 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().

5989 {
5990  DumpOptions *dopt = fout->dopt;
5991  PGresult *res;
5992  int ntups;
5993  int i;
5994  PQExpBuffer query = createPQExpBuffer();
5995  FuncInfo *finfo;
5996  int i_tableoid;
5997  int i_oid;
5998  int i_proname;
5999  int i_pronamespace;
6000  int i_rolname;
6001  int i_prolang;
6002  int i_pronargs;
6003  int i_proargtypes;
6004  int i_prorettype;
6005  int i_proacl;
6006  int i_rproacl;
6007  int i_initproacl;
6008  int i_initrproacl;
6009 
6010  /*
6011  * Find all interesting functions. This is a bit complicated:
6012  *
6013  * 1. Always exclude aggregates; those are handled elsewhere.
6014  *
6015  * 2. Always exclude functions that are internally dependent on something
6016  * else, since presumably those will be created as a result of creating
6017  * the something else. This currently acts only to suppress constructor
6018  * functions for range types (so we only need it in 9.2 and up). Note
6019  * this is OK only because the constructors don't have any dependencies
6020  * the range type doesn't have; otherwise we might not get creation
6021  * ordering correct.
6022  *
6023  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
6024  * they're members of extensions and we are in binary-upgrade mode then
6025  * include them, since we want to dump extension members individually in
6026  * that mode. Also, if they are used by casts or transforms then we need
6027  * to gather the information about them, though they won't be dumped if
6028  * they are built-in. Also, in 9.6 and up, include functions in
6029  * pg_catalog if they have an ACL different from what's shown in
6030  * pg_init_privs.
6031  */
6032  if (fout->remoteVersion >= 90600)
6033  {
6034  PQExpBuffer acl_subquery = createPQExpBuffer();
6035  PQExpBuffer racl_subquery = createPQExpBuffer();
6036  PQExpBuffer initacl_subquery = createPQExpBuffer();
6037  PQExpBuffer initracl_subquery = createPQExpBuffer();
6038  const char *not_agg_check;
6039 
6040  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
6041  initracl_subquery, "p.proacl", "p.proowner",
6042  "pip.initprivs", "'f'", dopt->binary_upgrade);
6043 
6044  not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
6045  : "NOT p.proisagg");
6046 
6047  appendPQExpBuffer(query,
6048  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6049  "p.pronargs, p.proargtypes, p.prorettype, "
6050  "%s AS proacl, "
6051  "%s AS rproacl, "
6052  "%s AS initproacl, "
6053  "%s AS initrproacl, "
6054  "p.pronamespace, "
6055  "(%s p.proowner) AS rolname "
6056  "FROM pg_proc p "
6057  "LEFT JOIN pg_init_privs pip ON "
6058  "(p.oid = pip.objoid "
6059  "AND pip.classoid = 'pg_proc'::regclass "
6060  "AND pip.objsubid = 0) "
6061  "WHERE %s"
6062  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6063  "WHERE classid = 'pg_proc'::regclass AND "
6064  "objid = p.oid AND deptype = 'i')"
6065  "\n AND ("
6066  "\n pronamespace != "
6067  "(SELECT oid FROM pg_namespace "
6068  "WHERE nspname = 'pg_catalog')"
6069  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6070  "\n WHERE pg_cast.oid > %u "
6071  "\n AND p.oid = pg_cast.castfunc)"
6072  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6073  "\n WHERE pg_transform.oid > %u AND "
6074  "\n (p.oid = pg_transform.trffromsql"
6075  "\n OR p.oid = pg_transform.trftosql))",
6076  acl_subquery->data,
6077  racl_subquery->data,
6078  initacl_subquery->data,
6079  initracl_subquery->data,
6081  not_agg_check,
6084  if (dopt->binary_upgrade)
6085  appendPQExpBufferStr(query,
6086  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6087  "classid = 'pg_proc'::regclass AND "
6088  "objid = p.oid AND "
6089  "refclassid = 'pg_extension'::regclass AND "
6090  "deptype = 'e')");
6091  appendPQExpBufferStr(query,
6092  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
6093  appendPQExpBufferChar(query, ')');
6094 
6095  destroyPQExpBuffer(acl_subquery);
6096  destroyPQExpBuffer(racl_subquery);
6097  destroyPQExpBuffer(initacl_subquery);
6098  destroyPQExpBuffer(initracl_subquery);
6099  }
6100  else
6101  {
6102  appendPQExpBuffer(query,
6103  "SELECT tableoid, oid, proname, prolang, "
6104  "pronargs, proargtypes, prorettype, proacl, "
6105  "NULL as rproacl, "
6106  "NULL as initproacl, NULL AS initrproacl, "
6107  "pronamespace, "
6108  "(%s proowner) AS rolname "
6109  "FROM pg_proc p "
6110  "WHERE NOT proisagg",
6112  if (fout->remoteVersion >= 90200)
6113  appendPQExpBufferStr(query,
6114  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6115  "WHERE classid = 'pg_proc'::regclass AND "
6116  "objid = p.oid AND deptype = 'i')");
6117  appendPQExpBuffer(query,
6118  "\n AND ("
6119  "\n pronamespace != "
6120  "(SELECT oid FROM pg_namespace "
6121  "WHERE nspname = 'pg_catalog')"
6122  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6123  "\n WHERE pg_cast.oid > '%u'::oid"
6124  "\n AND p.oid = pg_cast.castfunc)",
6126 
6127  if (fout->remoteVersion >= 90500)
6128  appendPQExpBuffer(query,
6129  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6130  "\n WHERE pg_transform.oid > '%u'::oid"
6131  "\n AND (p.oid = pg_transform.trffromsql"
6132  "\n OR p.oid = pg_transform.trftosql))",
6134 
6135  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
6136  appendPQExpBufferStr(query,
6137  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6138  "classid = 'pg_proc'::regclass AND "
6139  "objid = p.oid AND "
6140  "refclassid = 'pg_extension'::regclass AND "
6141  "deptype = 'e')");
6142  appendPQExpBufferChar(query, ')');
6143  }
6144 
6145  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6146 
6147  ntups = PQntuples(res);
6148 
6149  *numFuncs = ntups;
6150 
6151  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
6152 
6153  i_tableoid = PQfnumber(res, "tableoid");
6154  i_oid = PQfnumber(res, "oid");
6155  i_proname = PQfnumber(res, "proname");
6156  i_pronamespace = PQfnumber(res, "pronamespace");
6157  i_rolname = PQfnumber(res, "rolname");
6158  i_prolang = PQfnumber(res, "prolang");
6159  i_pronargs = PQfnumber(res, "pronargs");
6160  i_proargtypes = PQfnumber(res, "proargtypes");
6161  i_prorettype = PQfnumber(res, "prorettype");
6162  i_proacl = PQfnumber(res, "proacl");
6163  i_rproacl = PQfnumber(res, "rproacl");
6164  i_initproacl = PQfnumber(res, "initproacl");
6165  i_initrproacl = PQfnumber(res, "initrproacl");
6166 
6167  for (i = 0; i < ntups; i++)
6168  {
6169  finfo[i].dobj.objType = DO_FUNC;
6170  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6171  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6172  AssignDumpId(&finfo[i].dobj);
6173  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
6174  finfo[i].dobj.namespace =
6175  findNamespace(atooid(PQgetvalue(res, i, i_pronamespace)));
6176  finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
6177  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
6178  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
6179  finfo[i].proacl = pg_strdup(PQgetvalue(res, i, i_proacl));
6180  finfo[i].rproacl = pg_strdup(PQgetvalue(res, i, i_rproacl));
6181  finfo[i].initproacl = pg_strdup(PQgetvalue(res, i, i_initproacl));
6182  finfo[i].initrproacl = pg_strdup(PQgetvalue(res, i, i_initrproacl));
6183  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
6184  if (finfo[i].nargs == 0)
6185  finfo[i].argtypes = NULL;
6186  else
6187  {
6188  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
6189  parseOidArray(PQgetvalue(res, i, i_proargtypes),
6190  finfo[i].argtypes, finfo[i].nargs);
6191  }
6192 
6193  /* Decide whether we want to dump it */
6194  selectDumpableObject(&(finfo[i].dobj), fout);
6195 
6196  /* Do not try to dump ACL if no ACL exists. */
6197  if (PQgetisnull(res, i, i_proacl) && PQgetisnull(res, i, i_rproacl) &&
6198  PQgetisnull(res, i, i_initproacl) &&
6199  PQgetisnull(res, i, i_initrproacl))
6200  finfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
6201 
6202  if (strlen(finfo[i].rolname) == 0)
6203  pg_log_warning("owner of function \"%s\" appears to be invalid",
6204  finfo[i].dobj.name);
6205  }
6206 
6207  PQclear(res);
6208 
6209  destroyPQExpBuffer(query);
6210 
6211  return finfo;
6212 }
Oid * argtypes
Definition: pg_dump.h:206
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:1901
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:3642
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int nargs
Definition: pg_dump.h:205
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:211
Oid lang
Definition: pg_dump.h:204
DumpableObject dobj
Definition: pg_dump.h:202
unsigned int Oid
Definition: postgres_ext.h:31
static Oid g_last_builtin_oid
Definition: pg_dump.c:103
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
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 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:97
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:3356
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
void PQclear(PGresult *res)
Definition: fe-exec.c:694
Oid prorettype
Definition: pg_dump.h:207
char * initproacl
Definition: pg_dump.h:210
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 *initprivs_expr, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:725
char * rolname
Definition: pg_dump.h:203
char * proacl
Definition: pg_dump.h:208
char * rproacl
Definition: pg_dump.h:209
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4974
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:3667
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 7164 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().

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

7119 {
7120  PGresult *res;
7121  int ntups;
7122  int i;
7123  PQExpBuffer query = createPQExpBuffer();
7124  InhInfo *inhinfo;
7125 
7126  int i_inhrelid;
7127  int i_inhparent;
7128 
7129  /* find all the inheritance information */
7130  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
7131 
7132  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7133 
7134  ntups = PQntuples(res);
7135 
7136  *numInherits = ntups;
7137 
7138  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
7139 
7140  i_inhrelid = PQfnumber(res, "inhrelid");
7141  i_inhparent = PQfnumber(res, "inhparent");
7142 
7143  for (i = 0; i < ntups; i++)
7144  {
7145  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
7146  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
7147  }
7148 
7149  PQclear(res);
7150 
7151  destroyPQExpBuffer(query);
7152 
7153  return inhinfo;
7154 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3642
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:3248
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
Oid inhrelid
Definition: pg_dump.h:506
#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:3356
void PQclear(PGresult *res)
Definition: fe-exec.c:694
Oid inhparent
Definition: pg_dump.h:507
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, _namespaceInfo::nspowner, _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_nspowner;
4834  int i_rolname;
4835  int i_nspacl;
4836  int i_rnspacl;
4837  int i_initnspacl;
4838  int i_initrnspacl;
4839 
4840  query = createPQExpBuffer();
4841 
4842  /*
4843  * we fetch all namespaces including system ones, so that every object we
4844  * read in can be linked to a containing namespace.
4845  */
4846  if (fout->remoteVersion >= 90600)
4847  {
4848  PQExpBuffer acl_subquery = createPQExpBuffer();
4849  PQExpBuffer racl_subquery = createPQExpBuffer();
4850  PQExpBuffer init_acl_subquery = createPQExpBuffer();
4851  PQExpBuffer init_racl_subquery = createPQExpBuffer();
4852 
4853  /*
4854  * Bypass pg_init_privs.initprivs for the public schema, for several
4855  * reasons. First, dropping and recreating the schema detaches it
4856  * from its pg_init_privs row, but an empty destination database
4857  * starts with this ACL nonetheless. Second, we support dump/reload
4858  * of public schema ownership changes. ALTER SCHEMA OWNER filters
4859  * nspacl through aclnewowner(), but initprivs continues to reflect
4860  * the initial owner. Hence, synthesize the value that nspacl will
4861  * have after the restore's ALTER SCHEMA OWNER. Third, this makes the
4862  * destination database match the source's ACL, even if the latter was
4863  * an initdb-default ACL, which changed in v15. An upgrade pulls in
4864  * changes to most system object ACLs that the DBA had not customized.
4865  * We've made the public schema depart from that, because changing its
4866  * ACL so easily breaks applications.
4867  */
4868  buildACLQueries(acl_subquery, racl_subquery, init_acl_subquery,
4869  init_racl_subquery, "n.nspacl", "n.nspowner",
4870  "CASE WHEN n.nspname = 'public' THEN array["
4871  " format('%s=UC/%s', "
4872  " n.nspowner::regrole, n.nspowner::regrole),"
4873  " format('=U/%s', n.nspowner::regrole)]::aclitem[] "
4874  "ELSE pip.initprivs END",
4875  "'n'", dopt->binary_upgrade);
4876 
4877  appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, "
4878  "n.nspowner, "
4879  "(%s nspowner) AS rolname, "
4880  "%s as nspacl, "
4881  "%s as rnspacl, "
4882  "%s as initnspacl, "
4883  "%s as initrnspacl "
4884  "FROM pg_namespace n "
4885  "LEFT JOIN pg_init_privs pip "
4886  "ON (n.oid = pip.objoid "
4887  "AND pip.classoid = 'pg_namespace'::regclass "
4888  "AND pip.objsubid = 0",
4890  acl_subquery->data,
4891  racl_subquery->data,
4892  init_acl_subquery->data,
4893  init_racl_subquery->data);
4894 
4895  appendPQExpBufferStr(query, ") ");
4896 
4897  destroyPQExpBuffer(acl_subquery);
4898  destroyPQExpBuffer(racl_subquery);
4899  destroyPQExpBuffer(init_acl_subquery);
4900  destroyPQExpBuffer(init_racl_subquery);
4901  }
4902  else
4903  appendPQExpBuffer(query, "SELECT tableoid, oid, nspname, nspowner, "
4904  "(%s nspowner) AS rolname, "
4905  "nspacl, NULL as rnspacl, "
4906  "NULL AS initnspacl, NULL as initrnspacl "
4907  "FROM pg_namespace",
4909 
4910  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4911 
4912  ntups = PQntuples(res);
4913 
4914  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
4915 
4916  i_tableoid = PQfnumber(res, "tableoid");
4917  i_oid = PQfnumber(res, "oid");
4918  i_nspname = PQfnumber(res, "nspname");
4919  i_nspowner = PQfnumber(res, "nspowner");
4920  i_rolname = PQfnumber(res, "rolname");
4921  i_nspacl = PQfnumber(res, "nspacl");
4922  i_rnspacl = PQfnumber(res, "rnspacl");
4923  i_initnspacl = PQfnumber(res, "initnspacl");
4924  i_initrnspacl = PQfnumber(res, "initrnspacl");
4925 
4926  for (i = 0; i < ntups; i++)
4927  {
4928  nsinfo[i].dobj.objType = DO_NAMESPACE;
4929  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4930  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4931  AssignDumpId(&nsinfo[i].dobj);
4932  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
4933  nsinfo[i].nspowner = atooid(PQgetvalue(res, i, i_nspowner));
4934  nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4935  nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl));
4936  nsinfo[i].rnspacl = pg_strdup(PQgetvalue(res, i, i_rnspacl));
4937  nsinfo[i].initnspacl = pg_strdup(PQgetvalue(res, i, i_initnspacl));
4938  nsinfo[i].initrnspacl = pg_strdup(PQgetvalue(res, i, i_initrnspacl));
4939 
4940  /* Decide whether to dump this namespace */
4941  selectDumpableNamespace(&nsinfo[i], fout);
4942 
4943  /*
4944  * Do not try to dump ACL if the ACL is empty or the default.
4945  *
4946  * This is useful because, for some schemas/objects, the only
4947  * component we are going to try and dump is the ACL and if we can
4948  * remove that then 'dump' goes to zero/false and we don't consider
4949  * this object for dumping at all later on.
4950  */
4951  if (PQgetisnull(res, i, i_nspacl) && PQgetisnull(res, i, i_rnspacl) &&
4952  PQgetisnull(res, i, i_initnspacl) &&
4953  PQgetisnull(res, i, i_initrnspacl))
4954  nsinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4955 
4956  if (strlen(nsinfo[i].rolname) == 0)
4957  pg_log_warning("owner of schema \"%s\" appears to be invalid",
4958  nsinfo[i].dobj.name);
4959  }
4960 
4961  PQclear(res);
4962  destroyPQExpBuffer(query);
4963 
4964  *numNamespaces = ntups;
4965 
4966  return nsinfo;
4967 }
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:3642
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:3248
char * rnspacl
Definition: pg_dump.h:149
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:143
DumpOptions * dopt
Definition: pg_backup.h:191
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * rolname
Definition: pg_dump.h:147
char * initnspacl
Definition: pg_dump.h:150
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:97
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1582
void PQclear(PGresult *res)
Definition: fe-exec.c:694
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 *initprivs_expr, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:725
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
char * initrnspacl
Definition: pg_dump.h:151
CatalogId catId
Definition: pg_dump.h:129
int i
char * nspacl
Definition: pg_dump.h:148
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:3667
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 5638 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().

5639 {
5640  PGresult *res;
5641  int ntups;
5642  int i;
5643  PQExpBuffer query = createPQExpBuffer();
5644  OpclassInfo *opcinfo;
5645  int i_tableoid;
5646  int i_oid;
5647  int i_opcname;
5648  int i_opcnamespace;
5649  int i_rolname;
5650 
5651  /*
5652  * find all opclasses, including builtin opclasses; we filter out
5653  * system-defined opclasses at dump-out time.
5654  */
5655 
5656  appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
5657  "opcnamespace, "
5658  "(%s opcowner) AS rolname "
5659  "FROM pg_opclass",
5661 
5662  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5663 
5664  ntups = PQntuples(res);
5665  *numOpclasses = ntups;
5666 
5667  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
5668 
5669  i_tableoid = PQfnumber(res, "tableoid");
5670  i_oid = PQfnumber(res, "oid");
5671  i_opcname = PQfnumber(res, "opcname");
5672  i_opcnamespace = PQfnumber(res, "opcnamespace");
5673  i_rolname = PQfnumber(res, "rolname");
5674 
5675  for (i = 0; i < ntups; i++)
5676  {
5677  opcinfo[i].dobj.objType = DO_OPCLASS;
5678  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5679  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5680  AssignDumpId(&opcinfo[i].dobj);
5681  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
5682  opcinfo[i].dobj.namespace =
5683  findNamespace(atooid(PQgetvalue(res, i, i_opcnamespace)));
5684  opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5685 
5686  /* Decide whether we want to dump it */
5687  selectDumpableObject(&(opcinfo[i].dobj), fout);
5688 
5689  /* Op Classes do not currently have ACLs. */
5690  opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5691 
5692  if (strlen(opcinfo[i].rolname) == 0)
5693  pg_log_warning("owner of operator class \"%s\" appears to be invalid",
5694  opcinfo[i].dobj.name);
5695  }
5696 
5697  PQclear(res);
5698 
5699  destroyPQExpBuffer(query);
5700 
5701  return opcinfo;
5702 }
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:1901
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:3642
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:3248
char * rolname
Definition: pg_dump.h:239
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:97
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
DumpableObject dobj
Definition: pg_dump.h:238
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4974
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 5331 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().

5332 {
5333  PGresult *res;
5334  int ntups;
5335  int i;
5336  PQExpBuffer query = createPQExpBuffer();
5337  OprInfo *oprinfo;
5338  int i_tableoid;
5339  int i_oid;
5340  int i_oprname;
5341  int i_oprnamespace;
5342  int i_rolname;
5343  int i_oprkind;
5344  int i_oprcode;
5345 
5346  /*
5347  * find all operators, including builtin operators; we filter out
5348  * system-defined operators at dump-out time.
5349  */
5350 
5351  appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
5352  "oprnamespace, "
5353  "(%s oprowner) AS rolname, "
5354  "oprkind, "
5355  "oprcode::oid AS oprcode "
5356  "FROM pg_operator",
5358 
5359  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5360 
5361  ntups = PQntuples(res);
5362  *numOprs = ntups;
5363 
5364  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
5365 
5366  i_tableoid = PQfnumber(res, "tableoid");
5367  i_oid = PQfnumber(res, "oid");
5368  i_oprname = PQfnumber(res, "oprname");
5369  i_oprnamespace = PQfnumber(res, "oprnamespace");
5370  i_rolname = PQfnumber(res, "rolname");
5371  i_oprkind = PQfnumber(res, "oprkind");
5372  i_oprcode = PQfnumber(res, "oprcode");
5373 
5374  for (i = 0; i < ntups; i++)
5375  {
5376  oprinfo[i].dobj.objType = DO_OPERATOR;
5377  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5378  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5379  AssignDumpId(&oprinfo[i].dobj);
5380  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
5381  oprinfo[i].dobj.namespace =
5382  findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)));
5383  oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5384  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
5385  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
5386 
5387  /* Decide whether we want to dump it */
5388  selectDumpableObject(&(oprinfo[i].dobj), fout);
5389 
5390  /* Operators do not currently have ACLs. */
5391  oprinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5392 
5393  if (strlen(oprinfo[i].rolname) == 0)
5394  pg_log_warning("owner of operator \"%s\" appears to be invalid",
5395  oprinfo[i].dobj.name);
5396  }
5397 
5398  PQclear(res);
5399 
5400  destroyPQExpBuffer(query);
5401 
5402  return oprinfo;
5403 }
char * name
Definition: pg_dump.h:131
DumpableObject dobj
Definition: pg_dump.h:223
DumpComponents dump
Definition: pg_dump.h:132
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1901
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:3642
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:3248
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:97
char * rolname
Definition: pg_dump.h:224
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char oprkind
Definition: pg_dump.h:225
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:94
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:4974
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:226

◆ getOpfamilies()

OpfamilyInfo* getOpfamilies ( Archive fout,
int *  numOpfamilies 
)

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

5713 {
5714  PGresult *res;
5715  int ntups;
5716  int i;
5717  PQExpBuffer query;
5718  OpfamilyInfo *opfinfo;
5719  int i_tableoid;
5720  int i_oid;
5721  int i_opfname;
5722  int i_opfnamespace;
5723  int i_rolname;
5724 
5725  /* Before 8.3, there is no separate concept of opfamilies */
5726  if (fout->remoteVersion < 80300)
5727  {
5728  *numOpfamilies = 0;
5729  return NULL;
5730  }
5731 
5732  query = createPQExpBuffer();
5733 
5734  /*
5735  * find all opfamilies, including builtin opfamilies; we filter out
5736  * system-defined opfamilies at dump-out time.
5737  */
5738 
5739  appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, "
5740  "opfnamespace, "
5741  "(%s opfowner) AS rolname "
5742  "FROM pg_opfamily",
5744 
5745  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5746 
5747  ntups = PQntuples(res);
5748  *numOpfamilies = ntups;
5749 
5750  opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
5751 
5752  i_tableoid = PQfnumber(res, "tableoid");
5753  i_oid = PQfnumber(res, "oid");
5754  i_opfname = PQfnumber(res, "opfname");
5755  i_opfnamespace = PQfnumber(res, "opfnamespace");
5756  i_rolname = PQfnumber(res, "rolname");
5757 
5758  for (i = 0; i < ntups; i++)
5759  {
5760  opfinfo[i].dobj.objType = DO_OPFAMILY;
5761  opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5762  opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));