PostgreSQL Source Code  git master
pg_dump.h File Reference
#include "pg_backup.h"
Include dependency graph for pg_dump.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _dumpableObject
 
struct  _namespaceInfo
 
struct  _extensionInfo
 
struct  _typeInfo
 
struct  _shellTypeInfo
 
struct  _funcInfo
 
struct  _aggInfo
 
struct  _oprInfo
 
struct  _accessMethodInfo
 
struct  _opclassInfo
 
struct  _opfamilyInfo
 
struct  _collInfo
 
struct  _convInfo
 
struct  _tableInfo
 
struct  _attrDefInfo
 
struct  _tableDataInfo
 
struct  _indxInfo
 
struct  _indexAttachInfo
 
struct  _statsExtInfo
 
struct  _ruleInfo
 
struct  _triggerInfo
 
struct  _evttriggerInfo
 
struct  _constraintInfo
 
struct  _procLangInfo
 
struct  _castInfo
 
struct  _transformInfo
 
struct  _inhInfo
 
struct  _prsInfo
 
struct  _dictInfo
 
struct  _tmplInfo
 
struct  _cfgInfo
 
struct  _fdwInfo
 
struct  _foreignServerInfo
 
struct  _defaultACLInfo
 
struct  _blobInfo
 
struct  _policyInfo
 
struct  _PublicationInfo
 
struct  _PublicationRelInfo
 
struct  _SubscriptionInfo
 
struct  _extensionMemberId
 

Macros

#define oidcmp(x, y)   ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) )
 
#define oideq(x, y)   ( (x) == (y) )
 
#define oidle(x, y)   ( (x) <= (y) )
 
#define oidge(x, y)   ( (x) >= (y) )
 
#define oidzero(x)   ( (x) == 0 )
 
#define DUMP_COMPONENT_NONE   (0)
 
#define DUMP_COMPONENT_DEFINITION   (1 << 0)
 
#define DUMP_COMPONENT_DATA   (1 << 1)
 
#define DUMP_COMPONENT_COMMENT   (1 << 2)
 
#define DUMP_COMPONENT_SECLABEL   (1 << 3)
 
#define DUMP_COMPONENT_ACL   (1 << 4)
 
#define DUMP_COMPONENT_POLICY   (1 << 5)
 
#define DUMP_COMPONENT_USERMAP   (1 << 6)
 
#define DUMP_COMPONENT_ALL   (0xFFFF)
 
#define DUMP_COMPONENTS_REQUIRING_LOCK
 

Typedefs

typedef uint32 DumpComponents
 
typedef struct _dumpableObject DumpableObject
 
typedef struct _namespaceInfo NamespaceInfo
 
typedef struct _extensionInfo ExtensionInfo
 
typedef struct _typeInfo TypeInfo
 
typedef struct _shellTypeInfo ShellTypeInfo
 
typedef struct _funcInfo FuncInfo
 
typedef struct _aggInfo AggInfo
 
typedef struct _oprInfo OprInfo
 
typedef struct _accessMethodInfo AccessMethodInfo
 
typedef struct _opclassInfo OpclassInfo
 
typedef struct _opfamilyInfo OpfamilyInfo
 
typedef struct _collInfo CollInfo
 
typedef struct _convInfo ConvInfo
 
typedef struct _tableInfo TableInfo
 
typedef struct _attrDefInfo AttrDefInfo
 
typedef struct _tableDataInfo TableDataInfo
 
typedef struct _indxInfo IndxInfo
 
typedef struct _indexAttachInfo IndexAttachInfo
 
typedef struct _statsExtInfo StatsExtInfo
 
typedef struct _ruleInfo RuleInfo
 
typedef struct _triggerInfo TriggerInfo
 
typedef struct _evttriggerInfo EventTriggerInfo
 
typedef struct _constraintInfo ConstraintInfo
 
typedef struct _procLangInfo ProcLangInfo
 
typedef struct _castInfo CastInfo
 
typedef struct _transformInfo TransformInfo
 
typedef struct _inhInfo InhInfo
 
typedef struct _prsInfo TSParserInfo
 
typedef struct _dictInfo TSDictInfo
 
typedef struct _tmplInfo TSTemplateInfo
 
typedef struct _cfgInfo TSConfigInfo
 
typedef struct _fdwInfo FdwInfo
 
typedef struct _foreignServerInfo ForeignServerInfo
 
typedef struct _defaultACLInfo DefaultACLInfo
 
typedef struct _blobInfo BlobInfo
 
typedef struct _policyInfo PolicyInfo
 
typedef struct _PublicationInfo PublicationInfo
 
typedef struct _PublicationRelInfo PublicationRelInfo
 
typedef struct _SubscriptionInfo SubscriptionInfo
 
typedef struct _extensionMemberId ExtensionMemberId
 

Enumerations

enum  DumpableObjectType {
  DO_NAMESPACE, DO_EXTENSION, DO_TYPE, DO_SHELL_TYPE,
  DO_FUNC, DO_AGG, DO_OPERATOR, DO_ACCESS_METHOD,
  DO_OPCLASS, DO_OPFAMILY, DO_COLLATION, DO_CONVERSION,
  DO_TABLE, DO_ATTRDEF, DO_INDEX, DO_INDEX_ATTACH,
  DO_STATSEXT, DO_RULE, DO_TRIGGER, DO_CONSTRAINT,
  DO_FK_CONSTRAINT, DO_PROCLANG, DO_CAST, DO_TABLE_DATA,
  DO_SEQUENCE_SET, DO_DUMMY_TYPE, DO_TSPARSER, DO_TSDICT,
  DO_TSTEMPLATE, DO_TSCONFIG, DO_FDW, DO_FOREIGN_SERVER,
  DO_DEFAULT_ACL, DO_TRANSFORM, DO_BLOB, DO_BLOB_DATA,
  DO_PRE_DATA_BOUNDARY, DO_POST_DATA_BOUNDARY, DO_EVENT_TRIGGER, DO_REFRESH_MATVIEW,
  DO_POLICY, DO_PUBLICATION, DO_PUBLICATION_REL, DO_SUBSCRIPTION
}
 

Functions

TableInfogetSchemaData (Archive *fout, int *numTablesPtr)
 
void AssignDumpId (DumpableObject *dobj)
 
DumpId createDumpId (void)
 
DumpId getMaxDumpId (void)
 
DumpableObjectfindObjectByDumpId (DumpId dumpId)
 
DumpableObjectfindObjectByCatalogId (CatalogId catalogId)
 
void getDumpableObjects (DumpableObject ***objs, int *numObjs)
 
void addObjectDependency (DumpableObject *dobj, DumpId refId)
 
void removeObjectDependency (DumpableObject *dobj, DumpId refId)
 
TableInfofindTableByOid (Oid oid)
 
TypeInfofindTypeByOid (Oid oid)
 
FuncInfofindFuncByOid (Oid oid)
 
OprInfofindOprByOid (Oid oid)
 
CollInfofindCollationByOid (Oid oid)
 
NamespaceInfofindNamespaceByOid (Oid oid)
 
ExtensionInfofindExtensionByOid (Oid oid)
 
void setExtensionMembership (ExtensionMemberId *extmems, int nextmems)
 
ExtensionInfofindOwningExtension (CatalogId catalogId)
 
void parseOidArray (const char *str, Oid *array, int arraysize)
 
void sortDumpableObjects (DumpableObject **objs, int numObjs, DumpId preBoundaryId, DumpId postBoundaryId)
 
void sortDumpableObjectsByTypeName (DumpableObject **objs, int numObjs)
 
void sortDataAndIndexObjectsBySize (DumpableObject **objs, int numObjs)
 
NamespaceInfogetNamespaces (Archive *fout, int *numNamespaces)
 
ExtensionInfogetExtensions (Archive *fout, int *numExtensions)
 
TypeInfogetTypes (Archive *fout, int *numTypes)
 
FuncInfogetFuncs (Archive *fout, int *numFuncs)
 
AggInfogetAggregates (Archive *fout, int *numAggregates)
 
OprInfogetOperators (Archive *fout, int *numOperators)
 
AccessMethodInfogetAccessMethods (Archive *fout, int *numAccessMethods)
 
OpclassInfogetOpclasses (Archive *fout, int *numOpclasses)
 
OpfamilyInfogetOpfamilies (Archive *fout, int *numOpfamilies)
 
CollInfogetCollations (Archive *fout, int *numCollations)
 
ConvInfogetConversions (Archive *fout, int *numConversions)
 
TableInfogetTables (Archive *fout, int *numTables)
 
void getOwnedSeqs (Archive *fout, TableInfo tblinfo[], int numTables)
 
InhInfogetInherits (Archive *fout, int *numInherits)
 
void getIndexes (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getExtendedStatistics (Archive *fout)
 
void getConstraints (Archive *fout, TableInfo tblinfo[], int numTables)
 
RuleInfogetRules (Archive *fout, int *numRules)
 
void getTriggers (Archive *fout, TableInfo tblinfo[], int numTables)
 
ProcLangInfogetProcLangs (Archive *fout, int *numProcLangs)
 
CastInfogetCasts (Archive *fout, int *numCasts)
 
TransformInfogetTransforms (Archive *fout, int *numTransforms)
 
void getTableAttrs (Archive *fout, TableInfo *tbinfo, int numTables)
 
bool shouldPrintColumn (DumpOptions *dopt, TableInfo *tbinfo, int colno)
 
TSParserInfogetTSParsers (Archive *fout, int *numTSParsers)
 
TSDictInfogetTSDictionaries (Archive *fout, int *numTSDicts)
 
TSTemplateInfogetTSTemplates (Archive *fout, int *numTSTemplates)
 
TSConfigInfogetTSConfigurations (Archive *fout, int *numTSConfigs)
 
FdwInfogetForeignDataWrappers (Archive *fout, int *numForeignDataWrappers)
 
ForeignServerInfogetForeignServers (Archive *fout, int *numForeignServers)
 
DefaultACLInfogetDefaultACLs (Archive *fout, int *numDefaultACLs)
 
void getExtensionMembership (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
void processExtensionTables (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
EventTriggerInfogetEventTriggers (Archive *fout, int *numEventTriggers)
 
void getPolicies (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getPublications (Archive *fout)
 
void getPublicationTables (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getSubscriptions (Archive *fout)
 

Variables

bool force_quotes
 
bool g_verbose
 
char g_comment_start [10]
 
char g_comment_end [10]
 
char g_opaque_type [10]
 

Macro Definition Documentation

◆ DUMP_COMPONENT_ACL

◆ DUMP_COMPONENT_ALL

◆ DUMP_COMPONENT_COMMENT

◆ DUMP_COMPONENT_DATA

#define DUMP_COMPONENT_DATA   (1 << 1)

◆ DUMP_COMPONENT_DEFINITION

◆ DUMP_COMPONENT_NONE

◆ DUMP_COMPONENT_POLICY

#define DUMP_COMPONENT_POLICY   (1 << 5)

Definition at line 98 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 99 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 124 of file pg_dump.h.

Referenced by getTables().

◆ oidcmp

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

◆ oideq

#define oideq (   x,
 
)    ( (x) == (y) )

Definition at line 21 of file pg_dump.h.

◆ oidge

#define oidge (   x,
 
)    ( (x) >= (y) )

Definition at line 23 of file pg_dump.h.

◆ oidle

#define oidle (   x,
 
)    ( (x) <= (y) )

Definition at line 22 of file pg_dump.h.

◆ oidzero

#define oidzero (   x)    ( (x) == 0 )

Definition at line 24 of file pg_dump.h.

Typedef Documentation

◆ AccessMethodInfo

◆ AggInfo

◆ AttrDefInfo

◆ BlobInfo

◆ CastInfo

◆ CollInfo

◆ ConstraintInfo

◆ ConvInfo

◆ DefaultACLInfo

◆ DumpableObject

◆ DumpComponents

Definition at line 91 of file pg_dump.h.

◆ EventTriggerInfo

◆ ExtensionInfo

◆ ExtensionMemberId

◆ FdwInfo

◆ ForeignServerInfo

◆ FuncInfo

◆ IndexAttachInfo

◆ IndxInfo

◆ InhInfo

◆ NamespaceInfo

◆ OpclassInfo

◆ OpfamilyInfo

◆ OprInfo

◆ PolicyInfo

◆ ProcLangInfo

◆ PublicationInfo

◆ PublicationRelInfo

◆ RuleInfo

◆ ShellTypeInfo

◆ StatsExtInfo

◆ SubscriptionInfo

◆ TableDataInfo

◆ TableInfo

◆ TransformInfo

◆ TriggerInfo

◆ TSConfigInfo

◆ TSDictInfo

◆ TSParserInfo

◆ TSTemplateInfo

◆ TypeInfo

Enumeration Type Documentation

◆ DumpableObjectType

Enumerator
DO_NAMESPACE 
DO_EXTENSION 
DO_TYPE 
DO_SHELL_TYPE 
DO_FUNC 
DO_AGG 
DO_OPERATOR 
DO_ACCESS_METHOD 
DO_OPCLASS 
DO_OPFAMILY 
DO_COLLATION 
DO_CONVERSION 
DO_TABLE 
DO_ATTRDEF 
DO_INDEX 
DO_INDEX_ATTACH 
DO_STATSEXT 
DO_RULE 
DO_TRIGGER 
DO_CONSTRAINT 
DO_FK_CONSTRAINT 
DO_PROCLANG 
DO_CAST 
DO_TABLE_DATA 
DO_SEQUENCE_SET 
DO_DUMMY_TYPE 
DO_TSPARSER 
DO_TSDICT 
DO_TSTEMPLATE 
DO_TSCONFIG 
DO_FDW 
DO_FOREIGN_SERVER 
DO_DEFAULT_ACL 
DO_TRANSFORM 
DO_BLOB 
DO_BLOB_DATA 
DO_PRE_DATA_BOUNDARY 
DO_POST_DATA_BOUNDARY 
DO_EVENT_TRIGGER 
DO_REFRESH_MATVIEW 
DO_POLICY 
DO_PUBLICATION 
DO_PUBLICATION_REL 
DO_SUBSCRIPTION 

Definition at line 41 of file pg_dump.h.

42 {
43  /* When modifying this enum, update priority tables in pg_dump_sort.c! */
46  DO_TYPE,
48  DO_FUNC,
49  DO_AGG,
52  DO_OPCLASS,
56  DO_TABLE,
57  DO_ATTRDEF,
58  DO_INDEX,
61  DO_RULE,
62  DO_TRIGGER,
64  DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
66  DO_CAST,
71  DO_TSDICT,
74  DO_FDW,
78  DO_BLOB,
84  DO_POLICY,
DumpableObjectType
Definition: pg_dump.h:41
Definition: pg_dump.h:49
Definition: pg_dump.h:74

Function Documentation

◆ addObjectDependency()

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

Definition at line 805 of file common.c.

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

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

806 {
807  if (dobj->nDeps >= dobj->allocDeps)
808  {
809  if (dobj->allocDeps <= 0)
810  {
811  dobj->allocDeps = 16;
812  dobj->dependencies = (DumpId *)
813  pg_malloc(dobj->allocDeps * sizeof(DumpId));
814  }
815  else
816  {
817  dobj->allocDeps *= 2;
818  dobj->dependencies = (DumpId *)
819  pg_realloc(dobj->dependencies,
820  dobj->allocDeps * sizeof(DumpId));
821  }
822  }
823  dobj->dependencies[dobj->nDeps++] = refId;
824 }
int DumpId
Definition: pg_backup.h:235
DumpId * dependencies
Definition: pg_dump.h:139
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 569 of file common.c.

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

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

570 {
571  dobj->dumpId = ++lastDumpId;
572  dobj->name = NULL; /* must be set later */
573  dobj->namespace = NULL; /* may be set later */
574  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
575  dobj->ext_member = false; /* default assumption */
576  dobj->dependencies = NULL;
577  dobj->nDeps = 0;
578  dobj->allocDeps = 0;
579 
580  while (dobj->dumpId >= allocedDumpIds)
581  {
582  int newAlloc;
583 
584  if (allocedDumpIds <= 0)
585  {
586  newAlloc = 256;
588  pg_malloc(newAlloc * sizeof(DumpableObject *));
589  }
590  else
591  {
592  newAlloc = allocedDumpIds * 2;
594  pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
595  }
596  memset(dumpIdMap + allocedDumpIds, 0,
597  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
598  allocedDumpIds = newAlloc;
599  }
600  dumpIdMap[dobj->dumpId] = dobj;
601 
602  /* mark catalogIdMap invalid, but don't rebuild it yet */
603  catalogIdMapValid = false;
604 }
char * name
Definition: pg_dump.h:134
static int allocedDumpIds
Definition: common.c:32
DumpComponents dump
Definition: pg_dump.h:135
static DumpId lastDumpId
Definition: common.c:33
static DumpableObject ** dumpIdMap
Definition: common.c:31
DumpId * dependencies
Definition: pg_dump.h:139
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpId dumpId
Definition: pg_dump.h:133
bool ext_member
Definition: pg_dump.h:138
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
static bool catalogIdMapValid
Definition: common.c:38
#define DUMP_COMPONENT_ALL
Definition: pg_dump.h:100

◆ createDumpId()

◆ findCollationByOid()

CollInfo* findCollationByOid ( Oid  oid)

Definition at line 896 of file common.c.

References findObjectByOid(), and numCollations.

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

897 {
899 }
static DumpableObject ** collinfoindex
Definition: common.c:54
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static int numCollations
Definition: common.c:61

◆ findExtensionByOid()

ExtensionInfo* findExtensionByOid ( Oid  oid)

Definition at line 918 of file common.c.

References findObjectByOid(), and numExtensions.

Referenced by getExtensionMembership().

919 {
921 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static int numExtensions
Definition: common.c:63
static DumpableObject ** extinfoindex
Definition: common.c:56

◆ findFuncByOid()

FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 874 of file common.c.

References findObjectByOid(), and numFuncs.

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

875 {
876  return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs);
877 }
static int numFuncs
Definition: common.c:59
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static DumpableObject ** funinfoindex
Definition: common.c:52

◆ findNamespaceByOid()

NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 907 of file common.c.

References findObjectByOid(), and numNamespaces.

Referenced by findNamespace().

908 {
910 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static int numNamespaces
Definition: common.c:62
static DumpableObject ** nspinfoindex
Definition: common.c:55

◆ findObjectByCatalogId()

DumpableObject* findObjectByCatalogId ( CatalogId  catalogId)

Definition at line 651 of file common.c.

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

Referenced by buildMatViewRefreshDependencies(), and getDependencies().

652 {
653  DumpableObject **low;
654  DumpableObject **high;
655 
656  if (!catalogIdMapValid)
657  {
658  if (catalogIdMap)
661  if (numCatalogIds > 1)
662  qsort((void *) catalogIdMap, numCatalogIds,
664  catalogIdMapValid = true;
665  }
666 
667  /*
668  * We could use bsearch() here, but the notational cruft of calling
669  * bsearch is nearly as bad as doing it ourselves; and the generalized
670  * bsearch function is noticeably slower as well.
671  */
672  if (numCatalogIds <= 0)
673  return NULL;
674  low = catalogIdMap;
675  high = catalogIdMap + (numCatalogIds - 1);
676  while (low <= high)
677  {
678  DumpableObject **middle;
679  int difference;
680 
681  middle = low + (high - low) / 2;
682  /* comparison must match DOCatalogIdCompare, below */
683  difference = oidcmp((*middle)->catId.oid, catalogId.oid);
684  if (difference == 0)
685  difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid);
686  if (difference == 0)
687  return *middle;
688  else if (difference < 0)
689  low = middle + 1;
690  else
691  high = middle - 1;
692  }
693  return NULL;
694 }
Oid tableoid
Definition: pg_backup.h:231
#define oidcmp(x, y)
Definition: pg_dump.h:20
static int DOCatalogIdCompare(const void *p1, const void *p2)
Definition: common.c:761
static int numCatalogIds
Definition: common.c:40
Datum difference(PG_FUNCTION_ARGS)
#define free(a)
Definition: header.h:65
static DumpableObject ** catalogIdMap
Definition: common.c:39
static bool catalogIdMapValid
Definition: common.c:38
#define qsort(a, b, c, d)
Definition: port.h:421
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition: common.c:783

◆ findObjectByDumpId()

DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 633 of file common.c.

References allocedDumpIds.

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

634 {
635  if (dumpId <= 0 || dumpId >= allocedDumpIds)
636  return NULL; /* out of range? */
637  return dumpIdMap[dumpId];
638 }
static int allocedDumpIds
Definition: common.c:32
static DumpableObject ** dumpIdMap
Definition: common.c:31

◆ findOprByOid()

OprInfo* findOprByOid ( Oid  oid)

Definition at line 885 of file common.c.

References findObjectByOid(), and numOperators.

Referenced by getFormattedOperatorName().

886 {
888 }
static DumpableObject ** oprinfoindex
Definition: common.c:53
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static int numOperators
Definition: common.c:60

◆ findOwningExtension()

ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 957 of file common.c.

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

Referenced by checkExtensionMembership().

958 {
959  ExtensionMemberId *low;
960  ExtensionMemberId *high;
961 
962  /*
963  * We could use bsearch() here, but the notational cruft of calling
964  * bsearch is nearly as bad as doing it ourselves; and the generalized
965  * bsearch function is noticeably slower as well.
966  */
967  if (numextmembers <= 0)
968  return NULL;
969  low = extmembers;
970  high = extmembers + (numextmembers - 1);
971  while (low <= high)
972  {
973  ExtensionMemberId *middle;
974  int difference;
975 
976  middle = low + (high - low) / 2;
977  /* comparison must match ExtensionMemberIdCompare, below */
978  difference = oidcmp(middle->catId.oid, catalogId.oid);
979  if (difference == 0)
980  difference = oidcmp(middle->catId.tableoid, catalogId.tableoid);
981  if (difference == 0)
982  return middle->ext;
983  else if (difference < 0)
984  low = middle + 1;
985  else
986  high = middle - 1;
987  }
988  return NULL;
989 }
ExtensionInfo * ext
Definition: pg_dump.h:634
Oid tableoid
Definition: pg_backup.h:231
#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:633

◆ findTableByOid()

TableInfo* findTableByOid ( Oid  oid)

Definition at line 852 of file common.c.

References findObjectByOid(), and numTables.

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

853 {
855 }
static int numTables
Definition: common.c:57
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static DumpableObject ** tblinfoindex
Definition: common.c:50

◆ findTypeByOid()

TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 863 of file common.c.

References findObjectByOid(), and numTypes.

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

864 {
865  return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes);
866 }
static int numTypes
Definition: common.c:58
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static DumpableObject ** typinfoindex
Definition: common.c:51

◆ getAccessMethods()

AccessMethodInfo* getAccessMethods ( Archive fout,
int *  numAccessMethods 
)

Definition at line 5164 of file pg_dump.c.

References _accessMethodInfo::amhandler, _accessMethodInfo::amtype, appendPQExpBuffer(), 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().

5165 {
5166  PGresult *res;
5167  int ntups;
5168  int i;
5169  PQExpBuffer query;
5170  AccessMethodInfo *aminfo;
5171  int i_tableoid;
5172  int i_oid;
5173  int i_amname;
5174  int i_amhandler;
5175  int i_amtype;
5176 
5177  /* Before 9.6, there are no user-defined access methods */
5178  if (fout->remoteVersion < 90600)
5179  {
5180  *numAccessMethods = 0;
5181  return NULL;
5182  }
5183 
5184  query = createPQExpBuffer();
5185 
5186  /* Select all access methods from pg_am table */
5187  appendPQExpBuffer(query, "SELECT tableoid, oid, amname, amtype, "
5188  "amhandler::pg_catalog.regproc AS amhandler "
5189  "FROM pg_am");
5190 
5191  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5192 
5193  ntups = PQntuples(res);
5194  *numAccessMethods = ntups;
5195 
5196  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
5197 
5198  i_tableoid = PQfnumber(res, "tableoid");
5199  i_oid = PQfnumber(res, "oid");
5200  i_amname = PQfnumber(res, "amname");
5201  i_amhandler = PQfnumber(res, "amhandler");
5202  i_amtype = PQfnumber(res, "amtype");
5203 
5204  for (i = 0; i < ntups; i++)
5205  {
5206  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
5207  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5208  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5209  AssignDumpId(&aminfo[i].dobj);
5210  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
5211  aminfo[i].dobj.namespace = NULL;
5212  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
5213  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
5214 
5215  /* Decide whether we want to dump it */
5216  selectDumpableAccessMethod(&(aminfo[i]), fout);
5217 
5218  /* Access methods do not currently have ACLs. */
5219  aminfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5220  }
5221 
5222  PQclear(res);
5223 
5224  destroyPQExpBuffer(query);
5225 
5226  return aminfo;
5227 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpableObject dobj
Definition: pg_dump.h:228
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:1647
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
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:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * amhandler
Definition: pg_dump.h:230
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
int i
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ getAggregates()

AggInfo* getAggregates ( Archive fout,
int *  numAggregates 
)

Definition at line 5397 of file pg_dump.c.

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

Referenced by getSchemaData().

5398 {
5399  DumpOptions *dopt = fout->dopt;
5400  PGresult *res;
5401  int ntups;
5402  int i;
5403  PQExpBuffer query = createPQExpBuffer();
5404  AggInfo *agginfo;
5405  int i_tableoid;
5406  int i_oid;
5407  int i_aggname;
5408  int i_aggnamespace;
5409  int i_pronargs;
5410  int i_proargtypes;
5411  int i_rolname;
5412  int i_aggacl;
5413  int i_raggacl;
5414  int i_initaggacl;
5415  int i_initraggacl;
5416 
5417  /*
5418  * Find all interesting aggregates. See comment in getFuncs() for the
5419  * rationale behind the filtering logic.
5420  */
5421  if (fout->remoteVersion >= 90600)
5422  {
5423  PQExpBuffer acl_subquery = createPQExpBuffer();
5424  PQExpBuffer racl_subquery = createPQExpBuffer();
5425  PQExpBuffer initacl_subquery = createPQExpBuffer();
5426  PQExpBuffer initracl_subquery = createPQExpBuffer();
5427  const char *agg_check;
5428 
5429  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5430  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5431  dopt->binary_upgrade);
5432 
5433  agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
5434  : "p.proisagg");
5435 
5436  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5437  "p.proname AS aggname, "
5438  "p.pronamespace AS aggnamespace, "
5439  "p.pronargs, p.proargtypes, "
5440  "(%s p.proowner) AS rolname, "
5441  "%s AS aggacl, "
5442  "%s AS raggacl, "
5443  "%s AS initaggacl, "
5444  "%s AS initraggacl "
5445  "FROM pg_proc p "
5446  "LEFT JOIN pg_init_privs pip ON "
5447  "(p.oid = pip.objoid "
5448  "AND pip.classoid = 'pg_proc'::regclass "
5449  "AND pip.objsubid = 0) "
5450  "WHERE %s AND ("
5451  "p.pronamespace != "
5452  "(SELECT oid FROM pg_namespace "
5453  "WHERE nspname = 'pg_catalog') OR "
5454  "p.proacl IS DISTINCT FROM pip.initprivs",
5456  acl_subquery->data,
5457  racl_subquery->data,
5458  initacl_subquery->data,
5459  initracl_subquery->data,
5460  agg_check);
5461  if (dopt->binary_upgrade)
5462  appendPQExpBufferStr(query,
5463  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5464  "classid = 'pg_proc'::regclass AND "
5465  "objid = p.oid AND "
5466  "refclassid = 'pg_extension'::regclass AND "
5467  "deptype = 'e')");
5468  appendPQExpBufferChar(query, ')');
5469 
5470  destroyPQExpBuffer(acl_subquery);
5471  destroyPQExpBuffer(racl_subquery);
5472  destroyPQExpBuffer(initacl_subquery);
5473  destroyPQExpBuffer(initracl_subquery);
5474  }
5475  else if (fout->remoteVersion >= 80200)
5476  {
5477  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5478  "pronamespace AS aggnamespace, "
5479  "pronargs, proargtypes, "
5480  "(%s proowner) AS rolname, "
5481  "proacl AS aggacl, "
5482  "NULL AS raggacl, "
5483  "NULL AS initaggacl, NULL AS initraggacl "
5484  "FROM pg_proc p "
5485  "WHERE proisagg AND ("
5486  "pronamespace != "
5487  "(SELECT oid FROM pg_namespace "
5488  "WHERE nspname = 'pg_catalog')",
5490  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5491  appendPQExpBufferStr(query,
5492  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5493  "classid = 'pg_proc'::regclass AND "
5494  "objid = p.oid AND "
5495  "refclassid = 'pg_extension'::regclass AND "
5496  "deptype = 'e')");
5497  appendPQExpBufferChar(query, ')');
5498  }
5499  else
5500  {
5501  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5502  "pronamespace AS aggnamespace, "
5503  "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
5504  "proargtypes, "
5505  "(%s proowner) AS rolname, "
5506  "proacl AS aggacl, "
5507  "NULL AS raggacl, "
5508  "NULL AS initaggacl, NULL AS initraggacl "
5509  "FROM pg_proc "
5510  "WHERE proisagg "
5511  "AND pronamespace != "
5512  "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
5514  }
5515 
5516  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5517 
5518  ntups = PQntuples(res);
5519  *numAggs = ntups;
5520 
5521  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5522 
5523  i_tableoid = PQfnumber(res, "tableoid");
5524  i_oid = PQfnumber(res, "oid");
5525  i_aggname = PQfnumber(res, "aggname");
5526  i_aggnamespace = PQfnumber(res, "aggnamespace");
5527  i_pronargs = PQfnumber(res, "pronargs");
5528  i_proargtypes = PQfnumber(res, "proargtypes");
5529  i_rolname = PQfnumber(res, "rolname");
5530  i_aggacl = PQfnumber(res, "aggacl");
5531  i_raggacl = PQfnumber(res, "raggacl");
5532  i_initaggacl = PQfnumber(res, "initaggacl");
5533  i_initraggacl = PQfnumber(res, "initraggacl");
5534 
5535  for (i = 0; i < ntups; i++)
5536  {
5537  agginfo[i].aggfn.dobj.objType = DO_AGG;
5538  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5539  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5540  AssignDumpId(&agginfo[i].aggfn.dobj);
5541  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5542  agginfo[i].aggfn.dobj.namespace =
5543  findNamespace(fout,
5544  atooid(PQgetvalue(res, i, i_aggnamespace)));
5545  agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5546  if (strlen(agginfo[i].aggfn.rolname) == 0)
5547  write_msg(NULL, "WARNING: owner of aggregate function \"%s\" appears to be invalid\n",
5548  agginfo[i].aggfn.dobj.name);
5549  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5550  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5551  agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5552  agginfo[i].aggfn.rproacl = pg_strdup(PQgetvalue(res, i, i_raggacl));
5553  agginfo[i].aggfn.initproacl = pg_strdup(PQgetvalue(res, i, i_initaggacl));
5554  agginfo[i].aggfn.initrproacl = pg_strdup(PQgetvalue(res, i, i_initraggacl));
5555  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5556  if (agginfo[i].aggfn.nargs == 0)
5557  agginfo[i].aggfn.argtypes = NULL;
5558  else
5559  {
5560  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5561  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5562  agginfo[i].aggfn.argtypes,
5563  agginfo[i].aggfn.nargs);
5564  }
5565 
5566  /* Decide whether we want to dump it */
5567  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5568 
5569  /* Do not try to dump ACL if no ACL exists. */
5570  if (PQgetisnull(res, i, i_aggacl) && PQgetisnull(res, i, i_raggacl) &&
5571  PQgetisnull(res, i, i_initaggacl) &&
5572  PQgetisnull(res, i, i_initraggacl))
5573  agginfo[i].aggfn.dobj.dump &= ~DUMP_COMPONENT_ACL;
5574  }
5575 
5576  PQclear(res);
5577 
5578  destroyPQExpBuffer(query);
5579 
5580  return agginfo;
5581 }
Oid * argtypes
Definition: pg_dump.h:203
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1713
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int nargs
Definition: pg_dump.h:202
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4576
char * initrproacl
Definition: pg_dump.h:208
Oid lang
Definition: pg_dump.h:201
DumpableObject dobj
Definition: pg_dump.h:199
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
FuncInfo aggfn
Definition: pg_dump.h:214
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:136
Definition: pg_dump.h:49
DumpOptions * dopt
Definition: pg_backup.h:183
void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, const char *acl_column, const char *acl_owner, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:740
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
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:98
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1072
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:671
void write_msg(const char *modulename, const char *fmt,...)
Oid prorettype
Definition: pg_dump.h:204
char * initproacl
Definition: pg_dump.h:207
char * rolname
Definition: pg_dump.h:200
char * proacl
Definition: pg_dump.h:205
char * rproacl
Definition: pg_dump.h:206
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ getCasts()

CastInfo* getCasts ( Archive fout,
int *  numCasts 
)

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

7874 {
7875  PGresult *res;
7876  int ntups;
7877  int i;
7878  PQExpBuffer query = createPQExpBuffer();
7879  CastInfo *castinfo;
7880  int i_tableoid;
7881  int i_oid;
7882  int i_castsource;
7883  int i_casttarget;
7884  int i_castfunc;
7885  int i_castcontext;
7886  int i_castmethod;
7887 
7888  if (fout->remoteVersion >= 80400)
7889  {
7890  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7891  "castsource, casttarget, castfunc, castcontext, "
7892  "castmethod "
7893  "FROM pg_cast ORDER BY 3,4");
7894  }
7895  else
7896  {
7897  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7898  "castsource, casttarget, castfunc, castcontext, "
7899  "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
7900  "FROM pg_cast ORDER BY 3,4");
7901  }
7902 
7903  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7904 
7905  ntups = PQntuples(res);
7906 
7907  *numCasts = ntups;
7908 
7909  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
7910 
7911  i_tableoid = PQfnumber(res, "tableoid");
7912  i_oid = PQfnumber(res, "oid");
7913  i_castsource = PQfnumber(res, "castsource");
7914  i_casttarget = PQfnumber(res, "casttarget");
7915  i_castfunc = PQfnumber(res, "castfunc");
7916  i_castcontext = PQfnumber(res, "castcontext");
7917  i_castmethod = PQfnumber(res, "castmethod");
7918 
7919  for (i = 0; i < ntups; i++)
7920  {
7921  PQExpBufferData namebuf;
7922  TypeInfo *sTypeInfo;
7923  TypeInfo *tTypeInfo;
7924 
7925  castinfo[i].dobj.objType = DO_CAST;
7926  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7927  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7928  AssignDumpId(&castinfo[i].dobj);
7929  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
7930  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
7931  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
7932  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
7933  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
7934 
7935  /*
7936  * Try to name cast as concatenation of typnames. This is only used
7937  * for purposes of sorting. If we fail to find either type, the name
7938  * will be an empty string.
7939  */
7940  initPQExpBuffer(&namebuf);
7941  sTypeInfo = findTypeByOid(castinfo[i].castsource);
7942  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
7943  if (sTypeInfo && tTypeInfo)
7944  appendPQExpBuffer(&namebuf, "%s %s",
7945  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
7946  castinfo[i].dobj.name = namebuf.data;
7947 
7948  /* Decide whether we want to dump it */
7949  selectDumpableCast(&(castinfo[i]), fout);
7950 
7951  /* Casts do not currently have ACLs. */
7952  castinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7953  }
7954 
7955  PQclear(res);
7956 
7957  destroyPQExpBuffer(query);
7958 
7959  return castinfo;
7960 }
char * name
Definition: pg_dump.h:134
Oid castsource
Definition: pg_dump.h:468
DumpComponents dump
Definition: pg_dump.h:135
Oid tableoid
Definition: pg_backup.h:231
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:1589
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
Oid castfunc
Definition: pg_dump.h:470
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:467
Oid casttarget
Definition: pg_dump.h:469
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define atooid(x)
Definition: postgres_ext.h:42
DumpableObject dobj
Definition: pg_dump.h:166
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
int i
char castmethod
Definition: pg_dump.h:472
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:863
DumpableObjectType objType
Definition: pg_dump.h:131
char castcontext
Definition: pg_dump.h:471
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ getCollations()

CollInfo* getCollations ( Archive fout,
int *  numCollations 
)

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

5012 {
5013  PGresult *res;
5014  int ntups;
5015  int i;
5016  PQExpBuffer query;
5017  CollInfo *collinfo;
5018  int i_tableoid;
5019  int i_oid;
5020  int i_collname;
5021  int i_collnamespace;
5022  int i_rolname;
5023 
5024  /* Collations didn't exist pre-9.1 */
5025  if (fout->remoteVersion < 90100)
5026  {
5027  *numCollations = 0;
5028  return NULL;
5029  }
5030 
5031  query = createPQExpBuffer();
5032 
5033  /*
5034  * find all collations, including builtin collations; we filter out
5035  * system-defined collations at dump-out time.
5036  */
5037 
5038  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
5039  "collnamespace, "
5040  "(%s collowner) AS rolname "
5041  "FROM pg_collation",
5043 
5044  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5045 
5046  ntups = PQntuples(res);
5047  *numCollations = ntups;
5048 
5049  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
5050 
5051  i_tableoid = PQfnumber(res, "tableoid");
5052  i_oid = PQfnumber(res, "oid");
5053  i_collname = PQfnumber(res, "collname");
5054  i_collnamespace = PQfnumber(res, "collnamespace");
5055  i_rolname = PQfnumber(res, "rolname");
5056 
5057  for (i = 0; i < ntups; i++)
5058  {
5059  collinfo[i].dobj.objType = DO_COLLATION;
5060  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5061  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5062  AssignDumpId(&collinfo[i].dobj);
5063  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
5064  collinfo[i].dobj.namespace =
5065  findNamespace(fout,
5066  atooid(PQgetvalue(res, i, i_collnamespace)));
5067  collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5068 
5069  /* Decide whether we want to dump it */
5070  selectDumpableObject(&(collinfo[i].dobj), fout);
5071 
5072  /* Collations do not currently have ACLs. */
5073  collinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5074  }
5075 
5076  PQclear(res);
5077 
5078  destroyPQExpBuffer(query);
5079 
5080  return collinfo;
5081 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1713
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4576
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
DumpableObject dobj
Definition: pg_dump.h:247
char * rolname
Definition: pg_dump.h:248
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
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:98
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
static int numCollations
Definition: common.c:61
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
int i
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ getConstraints()

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

Definition at line 7114 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_FK_CONSTRAINT, _tableInfo::dobj, _constraintInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), g_verbose, _tableInfo::hastriggers, i, _dumpableObject::name, numTables, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, resetPQExpBuffer(), _constraintInfo::separate, CatalogId::tableoid, and write_msg().

Referenced by getSchemaData().

7115 {
7116  int i,
7117  j;
7118  ConstraintInfo *constrinfo;
7119  PQExpBuffer query;
7120  PGresult *res;
7121  int i_contableoid,
7122  i_conoid,
7123  i_conname,
7124  i_confrelid,
7125  i_condef;
7126  int ntups;
7127 
7128  query = createPQExpBuffer();
7129 
7130  for (i = 0; i < numTables; i++)
7131  {
7132  TableInfo *tbinfo = &tblinfo[i];
7133 
7134  if (!tbinfo->hastriggers ||
7135  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
7136  continue;
7137 
7138  if (g_verbose)
7139  write_msg(NULL, "reading foreign key constraints for table \"%s.%s\"\n",
7140  tbinfo->dobj.namespace->dobj.name,
7141  tbinfo->dobj.name);
7142 
7143  resetPQExpBuffer(query);
7144  if (fout->remoteVersion >= 110000)
7145  appendPQExpBuffer(query,
7146  "SELECT tableoid, oid, conname, confrelid, "
7147  "pg_catalog.pg_get_constraintdef(oid) AS condef "
7148  "FROM pg_catalog.pg_constraint "
7149  "WHERE conrelid = '%u'::pg_catalog.oid "
7150  "AND conparentid = 0 "
7151  "AND contype = 'f'",
7152  tbinfo->dobj.catId.oid);
7153  else
7154  appendPQExpBuffer(query,
7155  "SELECT tableoid, oid, conname, confrelid, "
7156  "pg_catalog.pg_get_constraintdef(oid) AS condef "
7157  "FROM pg_catalog.pg_constraint "
7158  "WHERE conrelid = '%u'::pg_catalog.oid "
7159  "AND contype = 'f'",
7160  tbinfo->dobj.catId.oid);
7161  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7162 
7163  ntups = PQntuples(res);
7164 
7165  i_contableoid = PQfnumber(res, "tableoid");
7166  i_conoid = PQfnumber(res, "oid");
7167  i_conname = PQfnumber(res, "conname");
7168  i_confrelid = PQfnumber(res, "confrelid");
7169  i_condef = PQfnumber(res, "condef");
7170 
7171  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7172 
7173  for (j = 0; j < ntups; j++)
7174  {
7175  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
7176  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7177  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7178  AssignDumpId(&constrinfo[j].dobj);
7179  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7180  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7181  constrinfo[j].contable = tbinfo;
7182  constrinfo[j].condomain = NULL;
7183  constrinfo[j].contype = 'f';
7184  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7185  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
7186  constrinfo[j].conindex = 0;
7187  constrinfo[j].condeferrable = false;
7188  constrinfo[j].condeferred = false;
7189  constrinfo[j].conislocal = true;
7190  constrinfo[j].separate = true;
7191  }
7192 
7193  PQclear(res);
7194  }
7195 
7196  destroyPQExpBuffer(query);
7197 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
bool hastriggers
Definition: pg_dump.h:278
static int numTables
Definition: common.c:57
DumpId conindex
Definition: pg_dump.h:444
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
DumpableObject dobj
Definition: pg_dump.h:262
char * condef
Definition: pg_dump.h:442
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:438
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
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:445
TypeInfo * condomain
Definition: pg_dump.h:440
bool conislocal
Definition: pg_dump.h:447
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
TableInfo * contable
Definition: pg_dump.h:439
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:93
void write_msg(const char *modulename, const char *fmt,...)
bool condeferred
Definition: pg_dump.h:446
CatalogId catId
Definition: pg_dump.h:132
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
DumpableObjectType objType
Definition: pg_dump.h:131
bool g_verbose
Definition: pg_dump.c:93
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ getConversions()

ConvInfo* getConversions ( Archive fout,
int *  numConversions 
)

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

5092 {
5093  PGresult *res;
5094  int ntups;
5095  int i;
5096  PQExpBuffer query;
5097  ConvInfo *convinfo;
5098  int i_tableoid;
5099  int i_oid;
5100  int i_conname;
5101  int i_connamespace;
5102  int i_rolname;
5103 
5104  query = createPQExpBuffer();
5105 
5106  /*
5107  * find all conversions, including builtin conversions; we filter out
5108  * system-defined conversions at dump-out time.
5109  */
5110 
5111  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
5112  "connamespace, "
5113  "(%s conowner) AS rolname "
5114  "FROM pg_conversion",
5116 
5117  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5118 
5119  ntups = PQntuples(res);
5120  *numConversions = ntups;
5121 
5122  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
5123 
5124  i_tableoid = PQfnumber(res, "tableoid");
5125  i_oid = PQfnumber(res, "oid");
5126  i_conname = PQfnumber(res, "conname");
5127  i_connamespace = PQfnumber(res, "connamespace");
5128  i_rolname = PQfnumber(res, "rolname");
5129 
5130  for (i = 0; i < ntups; i++)
5131  {
5132  convinfo[i].dobj.objType = DO_CONVERSION;
5133  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5134  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5135  AssignDumpId(&convinfo[i].dobj);
5136  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
5137  convinfo[i].dobj.namespace =
5138  findNamespace(fout,
5139  atooid(PQgetvalue(res, i, i_connamespace)));
5140  convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5141 
5142  /* Decide whether we want to dump it */
5143  selectDumpableObject(&(convinfo[i].dobj), fout);
5144 
5145  /* Conversions do not currently have ACLs. */
5146  convinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5147  }
5148 
5149  PQclear(res);
5150 
5151  destroyPQExpBuffer(query);
5152 
5153  return convinfo;
5154 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1713
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4576
char * rolname
Definition: pg_dump.h:254
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
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:98
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
DumpableObject dobj
Definition: pg_dump.h:253
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
int i
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405

◆ getDefaultACLs()

DefaultACLInfo* getDefaultACLs ( Archive fout,
int *  numDefaultACLs 
)

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

9210 {
9211  DumpOptions *dopt = fout->dopt;
9212  DefaultACLInfo *daclinfo;
9213  PQExpBuffer query;
9214  PGresult *res;
9215  int i_oid;
9216  int i_tableoid;
9217  int i_defaclrole;
9218  int i_defaclnamespace;
9219  int i_defaclobjtype;
9220  int i_defaclacl;
9221  int i_rdefaclacl;
9222  int i_initdefaclacl;
9223  int i_initrdefaclacl;
9224  int i,
9225  ntups;
9226 
9227  if (fout->remoteVersion < 90000)
9228  {
9229  *numDefaultACLs = 0;
9230  return NULL;
9231  }
9232 
9233  query = createPQExpBuffer();
9234 
9235  if (fout->remoteVersion >= 90600)
9236  {
9237  PQExpBuffer acl_subquery = createPQExpBuffer();
9238  PQExpBuffer racl_subquery = createPQExpBuffer();
9239  PQExpBuffer initacl_subquery = createPQExpBuffer();
9240  PQExpBuffer initracl_subquery = createPQExpBuffer();
9241 
9242  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9243  initracl_subquery, "defaclacl", "defaclrole",
9244  "CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
9245  dopt->binary_upgrade);
9246 
9247  appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
9248  "(%s d.defaclrole) AS defaclrole, "
9249  "d.defaclnamespace, "
9250  "d.defaclobjtype, "
9251  "%s AS defaclacl, "
9252  "%s AS rdefaclacl, "
9253  "%s AS initdefaclacl, "
9254  "%s AS initrdefaclacl "
9255  "FROM pg_default_acl d "
9256  "LEFT JOIN pg_init_privs pip ON "
9257  "(d.oid = pip.objoid "
9258  "AND pip.classoid = 'pg_default_acl'::regclass "
9259  "AND pip.objsubid = 0) ",
9261  acl_subquery->data,
9262  racl_subquery->data,
9263  initacl_subquery->data,
9264  initracl_subquery->data);
9265  }
9266  else
9267  {
9268  appendPQExpBuffer(query, "SELECT oid, tableoid, "
9269  "(%s defaclrole) AS defaclrole, "
9270  "defaclnamespace, "
9271  "defaclobjtype, "
9272  "defaclacl, "
9273  "NULL AS rdefaclacl, "
9274  "NULL AS initdefaclacl, "
9275  "NULL AS initrdefaclacl "
9276  "FROM pg_default_acl",
9278  }
9279 
9280  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9281 
9282  ntups = PQntuples(res);
9283  *numDefaultACLs = ntups;
9284 
9285  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9286 
9287  i_oid = PQfnumber(res, "oid");
9288  i_tableoid = PQfnumber(res, "tableoid");
9289  i_defaclrole = PQfnumber(res, "defaclrole");
9290  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9291  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9292  i_defaclacl = PQfnumber(res, "defaclacl");
9293  i_rdefaclacl = PQfnumber(res, "rdefaclacl");
9294  i_initdefaclacl = PQfnumber(res, "initdefaclacl");
9295  i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
9296 
9297  for (i = 0; i < ntups; i++)
9298  {
9299  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9300 
9301  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9302  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9303  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9304  AssignDumpId(&daclinfo[i].dobj);
9305  /* cheesy ... is it worth coming up with a better object name? */
9306  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9307 
9308  if (nspid != InvalidOid)
9309  daclinfo[i].dobj.namespace = findNamespace(fout, nspid);
9310  else
9311  daclinfo[i].dobj.namespace = NULL;
9312 
9313  daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
9314  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9315  daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9316  daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
9317  daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
9318  daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
9319 
9320  /* Decide whether we want to dump it */
9321  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9322  }
9323 
9324  PQclear(res);
9325 
9326  destroyPQExpBuffer(query);
9327 
9328  return daclinfo;
9329 }
char * name
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4576
char * rdefaclacl
Definition: pg_dump.h:556
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition: pg_dump.c:1567
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:136
DumpOptions * dopt
Definition: pg_backup.h:183
void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, const char *acl_column, const char *acl_owner, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:740
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
DumpableObject dobj
Definition: pg_dump.h:552
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:98
char * defaclacl
Definition: pg_dump.h:555
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * initdefaclacl
Definition: pg_dump.h:557
CatalogId catId
Definition: pg_dump.h:132
char * initrdefaclacl
Definition: pg_dump.h:558
int i
char defaclobjtype
Definition: pg_dump.h:554
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188
char * defaclrole
Definition: pg_dump.h:553

◆ getDumpableObjects()

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

Definition at line 783 of file common.c.

References allocedDumpIds, i, and pg_malloc().

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

784 {
785  int i,
786  j;
787 
788  *objs = (DumpableObject **)
790  j = 0;
791  for (i = 1; i < allocedDumpIds; i++)
792  {
793  if (dumpIdMap[i])
794  (*objs)[j++] = dumpIdMap[i];
795  }
796  *numObjs = j;
797 }
static int allocedDumpIds
Definition: common.c:32
static DumpableObject ** dumpIdMap
Definition: common.c:31
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int i

◆ getEventTriggers()

EventTriggerInfo* getEventTriggers ( Archive fout,
int *  numEventTriggers 
)

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

7605 {
7606  int i;
7607  PQExpBuffer query;
7608  PGresult *res;
7609  EventTriggerInfo *evtinfo;
7610  int i_tableoid,
7611  i_oid,
7612  i_evtname,
7613  i_evtevent,
7614  i_evtowner,
7615  i_evttags,
7616  i_evtfname,
7617  i_evtenabled;
7618  int ntups;
7619 
7620  /* Before 9.3, there are no event triggers */
7621  if (fout->remoteVersion < 90300)
7622  {
7623  *numEventTriggers = 0;
7624  return NULL;
7625  }
7626 
7627  query = createPQExpBuffer();
7628 
7629  appendPQExpBuffer(query,
7630  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
7631  "evtevent, (%s evtowner) AS evtowner, "
7632  "array_to_string(array("
7633  "select quote_literal(x) "
7634  " from unnest(evttags) as t(x)), ', ') as evttags, "
7635  "e.evtfoid::regproc as evtfname "
7636  "FROM pg_event_trigger e "
7637  "ORDER BY e.oid",
7639 
7640  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7641 
7642  ntups = PQntuples(res);
7643 
7644  *numEventTriggers = ntups;
7645 
7646  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
7647 
7648  i_tableoid = PQfnumber(res, "tableoid");
7649  i_oid = PQfnumber(res, "oid");
7650  i_evtname = PQfnumber(res, "evtname");
7651  i_evtevent = PQfnumber(res, "evtevent");
7652  i_evtowner = PQfnumber(res, "evtowner");
7653  i_evttags = PQfnumber(res, "evttags");
7654  i_evtfname = PQfnumber(res, "evtfname");
7655  i_evtenabled = PQfnumber(res, "evtenabled");
7656 
7657  for (i = 0; i < ntups; i++)
7658  {
7659  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
7660  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7661  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7662  AssignDumpId(&evtinfo[i].dobj);
7663  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
7664  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
7665  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
7666  evtinfo[i].evtowner = pg_strdup(PQgetvalue(res, i, i_evtowner));
7667  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
7668  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
7669  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
7670 
7671  /* Decide whether we want to dump it */
7672  selectDumpableObject(&(evtinfo[i].dobj), fout);
7673 
7674  /* Event Triggers do not currently have ACLs. */
7675  evtinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7676  }
7677 
7678  PQclear(res);
7679 
7680  destroyPQExpBuffer(query);
7681 
7682  return evtinfo;
7683 }
char * name
Definition: pg_dump.h:134
char * evtevent
Definition: pg_dump.h:421
DumpComponents dump
Definition: pg_dump.h:135
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1713
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * evtowner
Definition: pg_dump.h:422
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:98
char * evtfname
Definition: pg_dump.h:424
char * evttags
Definition: pg_dump.h:423
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
char * evtname
Definition: pg_dump.h:420
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
DumpableObject dobj
Definition: pg_dump.h:419
char evtenabled
Definition: pg_dump.h:425
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
int i
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ getExtendedStatistics()

void getExtendedStatistics ( Archive fout)

Definition at line 7045 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(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

7046 {
7047  PQExpBuffer query;
7048  PGresult *res;
7049  StatsExtInfo *statsextinfo;
7050  int ntups;
7051  int i_tableoid;
7052  int i_oid;
7053  int i_stxname;
7054  int i_stxnamespace;
7055  int i_rolname;
7056  int i;
7057 
7058  /* Extended statistics were new in v10 */
7059  if (fout->remoteVersion < 100000)
7060  return;
7061 
7062  query = createPQExpBuffer();
7063 
7064  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7065  "stxnamespace, (%s stxowner) AS rolname "
7066  "FROM pg_catalog.pg_statistic_ext",
7068 
7069  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7070 
7071  ntups = PQntuples(res);
7072 
7073  i_tableoid = PQfnumber(res, "tableoid");
7074  i_oid = PQfnumber(res, "oid");
7075  i_stxname = PQfnumber(res, "stxname");
7076  i_stxnamespace = PQfnumber(res, "stxnamespace");
7077  i_rolname = PQfnumber(res, "rolname");
7078 
7079  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
7080 
7081  for (i = 0; i < ntups; i++)
7082  {
7083  statsextinfo[i].dobj.objType = DO_STATSEXT;
7084  statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7085  statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7086  AssignDumpId(&statsextinfo[i].dobj);
7087  statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
7088  statsextinfo[i].dobj.namespace =
7089  findNamespace(fout,
7090  atooid(PQgetvalue(res, i, i_stxnamespace)));
7091  statsextinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
7092 
7093  /* Decide whether we want to dump it */
7094  selectDumpableObject(&(statsextinfo[i].dobj), fout);
7095 
7096  /* Stats objects do not currently have ACLs. */
7097  statsextinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7098  }
7099 
7100  PQclear(res);
7101  destroyPQExpBuffer(query);
7102 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1713
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4576
DumpableObject dobj
Definition: pg_dump.h:384
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
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:98
char * rolname
Definition: pg_dump.h:385
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
int i
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ getExtensionMembership()

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

Definition at line 17383 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_malloc(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), setExtensionMembership(), and CatalogId::tableoid.

Referenced by getSchemaData().

17385 {
17386  PQExpBuffer query;
17387  PGresult *res;
17388  int ntups,
17389  nextmembers,
17390  i;
17391  int i_classid,
17392  i_objid,
17393  i_refobjid;
17395  ExtensionInfo *ext;
17396 
17397  /* Nothing to do if no extensions */
17398  if (numExtensions == 0)
17399  return;
17400 
17401  query = createPQExpBuffer();
17402 
17403  /* refclassid constraint is redundant but may speed the search */
17404  appendPQExpBufferStr(query, "SELECT "
17405  "classid, objid, refobjid "
17406  "FROM pg_depend "
17407  "WHERE refclassid = 'pg_extension'::regclass "
17408  "AND deptype = 'e' "
17409  "ORDER BY 3");
17410 
17411  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
17412 
17413  ntups = PQntuples(res);
17414 
17415  i_classid = PQfnumber(res, "classid");
17416  i_objid = PQfnumber(res, "objid");
17417  i_refobjid = PQfnumber(res, "refobjid");
17418 
17419  extmembers = (ExtensionMemberId *) pg_malloc(ntups * sizeof(ExtensionMemberId));
17420  nextmembers = 0;
17421 
17422  /*
17423  * Accumulate data into extmembers[].
17424  *
17425  * Since we ordered the SELECT by referenced ID, we can expect that
17426  * multiple entries for the same extension will appear together; this
17427  * saves on searches.
17428  */
17429  ext = NULL;
17430 
17431  for (i = 0; i < ntups; i++)
17432  {
17433  CatalogId objId;
17434  Oid extId;
17435 
17436  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
17437  objId.oid = atooid(PQgetvalue(res, i, i_objid));
17438  extId = atooid(PQgetvalue(res, i, i_refobjid));
17439 
17440  if (ext == NULL ||
17441  ext->dobj.catId.oid != extId)
17442  ext = findExtensionByOid(extId);
17443 
17444  if (ext == NULL)
17445  {
17446  /* shouldn't happen */
17447  fprintf(stderr, "could not find referenced extension %u\n", extId);
17448  continue;
17449  }
17450 
17451  extmembers[nextmembers].catId = objId;
17452  extmembers[nextmembers].ext = ext;
17453  nextmembers++;
17454  }
17455 
17456  PQclear(res);
17457 
17458  /* Remember the data for use later */
17459  setExtensionMembership(extmembers, nextmembers);
17460 
17461  destroyPQExpBuffer(query);
17462 }
ExtensionInfo * ext
Definition: pg_dump.h:634
DumpableObject dobj
Definition: pg_dump.h:156
Oid tableoid
Definition: pg_backup.h:231
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void setExtensionMembership(ExtensionMemberId *extmems, int nextmems)
Definition: common.c:941
static int numExtensions
Definition: common.c:63
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
static ExtensionMemberId * extmembers
Definition: common.c:66
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:918
void PQclear(PGresult *res)
Definition: fe-exec.c:671
CatalogId catId
Definition: pg_dump.h:132
CatalogId catId
Definition: pg_dump.h:633
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405

◆ getExtensions()

ExtensionInfo* getExtensions ( Archive fout,
int *  numExtensions 
)

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

4595 {
4596  DumpOptions *dopt = fout->dopt;
4597  PGresult *res;
4598  int ntups;
4599  int i;
4600  PQExpBuffer query;
4601  ExtensionInfo *extinfo;
4602  int i_tableoid;
4603  int i_oid;
4604  int i_extname;
4605  int i_nspname;
4606  int i_extrelocatable;
4607  int i_extversion;
4608  int i_extconfig;
4609  int i_extcondition;
4610 
4611  /*
4612  * Before 9.1, there are no extensions.
4613  */
4614  if (fout->remoteVersion < 90100)
4615  {
4616  *numExtensions = 0;
4617  return NULL;
4618  }
4619 
4620  query = createPQExpBuffer();
4621 
4622  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
4623  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
4624  "FROM pg_extension x "
4625  "JOIN pg_namespace n ON n.oid = x.extnamespace");
4626 
4627  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4628 
4629  ntups = PQntuples(res);
4630 
4631  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
4632 
4633  i_tableoid = PQfnumber(res, "tableoid");
4634  i_oid = PQfnumber(res, "oid");
4635  i_extname = PQfnumber(res, "extname");
4636  i_nspname = PQfnumber(res, "nspname");
4637  i_extrelocatable = PQfnumber(res, "extrelocatable");
4638  i_extversion = PQfnumber(res, "extversion");
4639  i_extconfig = PQfnumber(res, "extconfig");
4640  i_extcondition = PQfnumber(res, "extcondition");
4641 
4642  for (i = 0; i < ntups; i++)
4643  {
4644  extinfo[i].dobj.objType = DO_EXTENSION;
4645  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4646  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4647  AssignDumpId(&extinfo[i].dobj);
4648  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
4649  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
4650  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
4651  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
4652  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
4653  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
4654 
4655  /* Decide whether we want to dump it */
4656  selectDumpableExtension(&(extinfo[i]), dopt);
4657  }
4658 
4659  PQclear(res);
4660  destroyPQExpBuffer(query);
4661 
4662  *numExtensions = ntups;
4663 
4664  return extinfo;
4665 }
char * name
Definition: pg_dump.h:134
DumpableObject dobj
Definition: pg_dump.h:156
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpOptions * dopt
Definition: pg_backup.h:183
char * extconfig
Definition: pg_dump.h:160
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static int numExtensions
Definition: common.c:63
#define atooid(x)
Definition: postgres_ext.h:42
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:1674
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * extcondition
Definition: pg_dump.h:161
CatalogId catId
Definition: pg_dump.h:132
int i
DumpableObjectType objType
Definition: pg_dump.h:131
bool relocatable
Definition: pg_dump.h:157
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188
char * extversion
Definition: pg_dump.h:159

◆ getForeignDataWrappers()

FdwInfo* getForeignDataWrappers ( Archive fout,
int *  numForeignDataWrappers 
)

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

8894 {
8895  DumpOptions *dopt = fout->dopt;
8896  PGresult *res;
8897  int ntups;
8898  int i;
8899  PQExpBuffer query;
8900  FdwInfo *fdwinfo;
8901  int i_tableoid;
8902  int i_oid;
8903  int i_fdwname;
8904  int i_rolname;
8905  int i_fdwhandler;
8906  int i_fdwvalidator;
8907  int i_fdwacl;
8908  int i_rfdwacl;
8909  int i_initfdwacl;
8910  int i_initrfdwacl;
8911  int i_fdwoptions;
8912 
8913  /* Before 8.4, there are no foreign-data wrappers */
8914  if (fout->remoteVersion < 80400)
8915  {
8916  *numForeignDataWrappers = 0;
8917  return NULL;
8918  }
8919 
8920  query = createPQExpBuffer();
8921 
8922  if (fout->remoteVersion >= 90600)
8923  {
8924  PQExpBuffer acl_subquery = createPQExpBuffer();
8925  PQExpBuffer racl_subquery = createPQExpBuffer();
8926  PQExpBuffer initacl_subquery = createPQExpBuffer();
8927  PQExpBuffer initracl_subquery = createPQExpBuffer();
8928 
8929  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8930  initracl_subquery, "f.fdwacl", "f.fdwowner", "'F'",
8931  dopt->binary_upgrade);
8932 
8933  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.fdwname, "
8934  "(%s f.fdwowner) AS rolname, "
8935  "f.fdwhandler::pg_catalog.regproc, "
8936  "f.fdwvalidator::pg_catalog.regproc, "
8937  "%s AS fdwacl, "
8938  "%s AS rfdwacl, "
8939  "%s AS initfdwacl, "
8940  "%s AS initrfdwacl, "
8941  "array_to_string(ARRAY("
8942  "SELECT quote_ident(option_name) || ' ' || "
8943  "quote_literal(option_value) "
8944  "FROM pg_options_to_table(f.fdwoptions) "
8945  "ORDER BY option_name"
8946  "), E',\n ') AS fdwoptions "
8947  "FROM pg_foreign_data_wrapper f "
8948  "LEFT JOIN pg_init_privs pip ON "
8949  "(f.oid = pip.objoid "
8950  "AND pip.classoid = 'pg_foreign_data_wrapper'::regclass "
8951  "AND pip.objsubid = 0) ",
8953  acl_subquery->data,
8954  racl_subquery->data,
8955  initacl_subquery->data,
8956  initracl_subquery->data);
8957 
8958  destroyPQExpBuffer(acl_subquery);
8959  destroyPQExpBuffer(racl_subquery);
8960  destroyPQExpBuffer(initacl_subquery);
8961  destroyPQExpBuffer(initracl_subquery);
8962  }
8963  else if (fout->remoteVersion >= 90100)
8964  {
8965  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8966  "(%s fdwowner) AS rolname, "
8967  "fdwhandler::pg_catalog.regproc, "
8968  "fdwvalidator::pg_catalog.regproc, fdwacl, "
8969  "NULL as rfdwacl, "
8970  "NULL as initfdwacl, NULL AS initrfdwacl, "
8971  "array_to_string(ARRAY("
8972  "SELECT quote_ident(option_name) || ' ' || "
8973  "quote_literal(option_value) "
8974  "FROM pg_options_to_table(fdwoptions) "
8975  "ORDER BY option_name"
8976  "), E',\n ') AS fdwoptions "
8977  "FROM pg_foreign_data_wrapper",
8979  }
8980  else
8981  {
8982  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8983  "(%s fdwowner) AS rolname, "
8984  "'-' AS fdwhandler, "
8985  "fdwvalidator::pg_catalog.regproc, fdwacl, "
8986  "NULL as rfdwacl, "
8987  "NULL as initfdwacl, NULL AS initrfdwacl, "
8988  "array_to_string(ARRAY("
8989  "SELECT quote_ident(option_name) || ' ' || "
8990  "quote_literal(option_value) "
8991  "FROM pg_options_to_table(fdwoptions) "
8992  "ORDER BY option_name"
8993  "), E',\n ') AS fdwoptions "
8994  "FROM pg_foreign_data_wrapper",
8996  }
8997 
8998  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8999 
9000  ntups = PQntuples(res);
9001  *numForeignDataWrappers = ntups;
9002 
9003  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
9004 
9005  i_tableoid = PQfnumber(res, "tableoid");
9006  i_oid = PQfnumber(res, "oid");
9007  i_fdwname = PQfnumber(res, "fdwname");
9008  i_rolname = PQfnumber(res, "rolname");
9009  i_fdwhandler = PQfnumber(res, "fdwhandler");
9010  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
9011  i_fdwacl = PQfnumber(res, "fdwacl");
9012  i_rfdwacl = PQfnumber(res, "rfdwacl");
9013  i_initfdwacl = PQfnumber(res, "initfdwacl");
9014  i_initrfdwacl = PQfnumber(res, "initrfdwacl");
9015  i_fdwoptions = PQfnumber(res, "fdwoptions");
9016 
9017  for (i = 0; i < ntups; i++)
9018  {
9019  fdwinfo[i].dobj.objType = DO_FDW;
9020  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9021  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9022  AssignDumpId(&fdwinfo[i].dobj);
9023  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
9024  fdwinfo[i].dobj.namespace = NULL;
9025  fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
9026  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
9027  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
9028  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
9029  fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
9030  fdwinfo[i].rfdwacl = pg_strdup(PQgetvalue(res, i, i_rfdwacl));
9031  fdwinfo[i].initfdwacl = pg_strdup(PQgetvalue(res, i, i_initfdwacl));
9032  fdwinfo[i].initrfdwacl = pg_strdup(PQgetvalue(res, i, i_initrfdwacl));
9033 
9034  /* Decide whether we want to dump it */
9035  selectDumpableObject(&(fdwinfo[i].dobj), fout);
9036 
9037  /* Do not try to dump ACL if no ACL exists. */
9038  if (PQgetisnull(res, i, i_fdwacl) && PQgetisnull(res, i, i_rfdwacl) &&
9039  PQgetisnull(res, i, i_initfdwacl) &&
9040  PQgetisnull(res, i, i_initrfdwacl))
9041  fdwinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9042  }
9043 
9044  PQclear(res);
9045 
9046  destroyPQExpBuffer(query);
9047 
9048  return fdwinfo;
9049 }
char * name
Definition: pg_dump.h:134
char * rfdwacl
Definition: pg_dump.h:531
DumpComponents dump
Definition: pg_dump.h:135
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1713
Oid tableoid
Definition: pg_backup.h:231
char * fdwhandler
Definition: pg_dump.h:527
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * fdwoptions
Definition: pg_dump.h:529
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:525
int binary_upgrade
Definition: pg_backup.h:136
DumpOptions * dopt
Definition: pg_backup.h:183
void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, const char *acl_column, const char *acl_owner, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:740
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * fdwvalidator
Definition: pg_dump.h:528
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:530
static const char * username_subquery
Definition: pg_dump.c:98
char * rolname
Definition: pg_dump.h:526
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * initfdwacl
Definition: pg_dump.h:532
Definition: pg_dump.h:74
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
char * initrfdwacl
Definition: pg_dump.h:533
CatalogId catId
Definition: pg_dump.h:132
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ getForeignServers()

ForeignServerInfo* getForeignServers ( Archive fout,
int *  numForeignServers 
)

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

9060 {
9061  DumpOptions *dopt = fout->dopt;
9062  PGresult *res;
9063  int ntups;
9064  int i;
9065  PQExpBuffer query;
9066  ForeignServerInfo *srvinfo;
9067  int i_tableoid;
9068  int i_oid;
9069  int i_srvname;
9070  int i_rolname;
9071  int i_srvfdw;
9072  int i_srvtype;
9073  int i_srvversion;
9074  int i_srvacl;
9075  int i_rsrvacl;
9076  int i_initsrvacl;
9077  int i_initrsrvacl;
9078  int i_srvoptions;
9079 
9080  /* Before 8.4, there are no foreign servers */
9081  if (fout->remoteVersion < 80400)
9082  {
9083  *numForeignServers = 0;
9084  return NULL;
9085  }
9086 
9087  query = createPQExpBuffer();
9088 
9089  if (fout->remoteVersion >= 90600)
9090  {
9091  PQExpBuffer acl_subquery = createPQExpBuffer();
9092  PQExpBuffer racl_subquery = createPQExpBuffer();
9093  PQExpBuffer initacl_subquery = createPQExpBuffer();
9094  PQExpBuffer initracl_subquery = createPQExpBuffer();
9095 
9096  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9097  initracl_subquery, "f.srvacl", "f.srvowner", "'S'",
9098  dopt->binary_upgrade);
9099 
9100  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.srvname, "
9101  "(%s f.srvowner) AS rolname, "
9102  "f.srvfdw, f.srvtype, f.srvversion, "
9103  "%s AS srvacl, "
9104  "%s AS rsrvacl, "
9105  "%s AS initsrvacl, "
9106  "%s AS initrsrvacl, "
9107  "array_to_string(ARRAY("
9108  "SELECT quote_ident(option_name) || ' ' || "
9109  "quote_literal(option_value) "
9110  "FROM pg_options_to_table(f.srvoptions) "
9111  "ORDER BY option_name"
9112  "), E',\n ') AS srvoptions "
9113  "FROM pg_foreign_server f "
9114  "LEFT JOIN pg_init_privs pip "
9115  "ON (f.oid = pip.objoid "
9116  "AND pip.classoid = 'pg_foreign_server'::regclass "
9117  "AND pip.objsubid = 0) ",
9119  acl_subquery->data,
9120  racl_subquery->data,
9121  initacl_subquery->data,
9122  initracl_subquery->data);
9123 
9124  destroyPQExpBuffer(acl_subquery);
9125  destroyPQExpBuffer(racl_subquery);
9126  destroyPQExpBuffer(initacl_subquery);
9127  destroyPQExpBuffer(initracl_subquery);
9128  }
9129  else
9130  {
9131  appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
9132  "(%s srvowner) AS rolname, "
9133  "srvfdw, srvtype, srvversion, srvacl, "
9134  "NULL AS rsrvacl, "
9135  "NULL AS initsrvacl, NULL AS initrsrvacl, "
9136  "array_to_string(ARRAY("
9137  "SELECT quote_ident(option_name) || ' ' || "
9138  "quote_literal(option_value) "
9139  "FROM pg_options_to_table(srvoptions) "
9140  "ORDER BY option_name"
9141  "), E',\n ') AS srvoptions "
9142  "FROM pg_foreign_server",
9144  }
9145 
9146  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9147 
9148  ntups = PQntuples(res);
9149  *numForeignServers = ntups;
9150 
9151  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
9152 
9153  i_tableoid = PQfnumber(res, "tableoid");
9154  i_oid = PQfnumber(res, "oid");
9155  i_srvname = PQfnumber(res, "srvname");
9156  i_rolname = PQfnumber(res, "rolname");
9157  i_srvfdw = PQfnumber(res, "srvfdw");
9158  i_srvtype = PQfnumber(res, "srvtype");
9159  i_srvversion = PQfnumber(res, "srvversion");
9160  i_srvacl = PQfnumber(res, "srvacl");
9161  i_rsrvacl = PQfnumber(res, "rsrvacl");
9162  i_initsrvacl = PQfnumber(res, "initsrvacl");
9163  i_initrsrvacl = PQfnumber(res, "initrsrvacl");
9164  i_srvoptions = PQfnumber(res, "srvoptions");
9165 
9166  for (i = 0; i < ntups; i++)
9167  {
9168  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
9169  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9170  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9171  AssignDumpId(&srvinfo[i].dobj);
9172  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
9173  srvinfo[i].dobj.namespace = NULL;
9174  srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
9175  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
9176  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
9177  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
9178  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
9179  srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl));
9180  srvinfo[i].rsrvacl = pg_strdup(PQgetvalue(res, i, i_rsrvacl));
9181  srvinfo[i].initsrvacl = pg_strdup(PQgetvalue(res, i, i_initsrvacl));
9182  srvinfo[i].initrsrvacl = pg_strdup(PQgetvalue(res, i, i_initrsrvacl));
9183 
9184  /* Decide whether we want to dump it */
9185  selectDumpableObject(&(srvinfo[i].dobj), fout);
9186 
9187  /* Do not try to dump ACL if no ACL exists. */
9188  if (PQgetisnull(res, i, i_srvacl) && PQgetisnull(res, i, i_rsrvacl) &&
9189  PQgetisnull(res, i, i_initsrvacl) &&
9190  PQgetisnull(res, i, i_initrsrvacl))
9191  srvinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9192  }
9193 
9194  PQclear(res);
9195 
9196  destroyPQExpBuffer(query);
9197 
9198  return srvinfo;
9199 }
char * srvoptions
Definition: pg_dump.h:547
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1713
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
char * initrsrvacl
Definition: pg_dump.h:546
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:136
DumpOptions * dopt
Definition: pg_backup.h:183
void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, const char *acl_column, const char *acl_owner, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:740
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
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:98
char * srvversion
Definition: pg_dump.h:542
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
DumpableObject dobj
Definition: pg_dump.h:538
int i
char * initsrvacl
Definition: pg_dump.h:545
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ getFuncs()

FuncInfo* getFuncs ( Archive fout,
int *  numFuncs 
)

Definition at line 5591 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_malloc(), pg_malloc0(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _funcInfo::proacl, _funcInfo::prorettype, Archive::remoteVersion, _funcInfo::rolname, _funcInfo::rproacl, selectDumpableObject(), CatalogId::tableoid, username_subquery, and write_msg().

Referenced by getSchemaData().

5592 {
5593  DumpOptions *dopt = fout->dopt;
5594  PGresult *res;
5595  int ntups;
5596  int i;
5597  PQExpBuffer query = createPQExpBuffer();
5598  FuncInfo *finfo;
5599  int i_tableoid;
5600  int i_oid;
5601  int i_proname;
5602  int i_pronamespace;
5603  int i_rolname;
5604  int i_prolang;
5605  int i_pronargs;
5606  int i_proargtypes;
5607  int i_prorettype;
5608  int i_proacl;
5609  int i_rproacl;
5610  int i_initproacl;
5611  int i_initrproacl;
5612 
5613  /*
5614  * Find all interesting functions. This is a bit complicated:
5615  *
5616  * 1. Always exclude aggregates; those are handled elsewhere.
5617  *
5618  * 2. Always exclude functions that are internally dependent on something
5619  * else, since presumably those will be created as a result of creating
5620  * the something else. This currently acts only to suppress constructor
5621  * functions for range types (so we only need it in 9.2 and up). Note
5622  * this is OK only because the constructors don't have any dependencies
5623  * the range type doesn't have; otherwise we might not get creation
5624  * ordering correct.
5625  *
5626  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
5627  * they're members of extensions and we are in binary-upgrade mode then
5628  * include them, since we want to dump extension members individually in
5629  * that mode. Also, if they are used by casts or transforms then we need
5630  * to gather the information about them, though they won't be dumped if
5631  * they are built-in. Also, in 9.6 and up, include functions in
5632  * pg_catalog if they have an ACL different from what's shown in
5633  * pg_init_privs.
5634  */
5635  if (fout->remoteVersion >= 90600)
5636  {
5637  PQExpBuffer acl_subquery = createPQExpBuffer();
5638  PQExpBuffer racl_subquery = createPQExpBuffer();
5639  PQExpBuffer initacl_subquery = createPQExpBuffer();
5640  PQExpBuffer initracl_subquery = createPQExpBuffer();
5641  const char *not_agg_check;
5642 
5643  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5644  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5645  dopt->binary_upgrade);
5646 
5647  not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
5648  : "NOT p.proisagg");
5649 
5650  appendPQExpBuffer(query,
5651  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
5652  "p.pronargs, p.proargtypes, p.prorettype, "
5653  "%s AS proacl, "
5654  "%s AS rproacl, "
5655  "%s AS initproacl, "
5656  "%s AS initrproacl, "
5657  "p.pronamespace, "
5658  "(%s p.proowner) AS rolname "
5659  "FROM pg_proc p "
5660  "LEFT JOIN pg_init_privs pip ON "
5661  "(p.oid = pip.objoid "
5662  "AND pip.classoid = 'pg_proc'::regclass "
5663  "AND pip.objsubid = 0) "
5664  "WHERE %s"
5665  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5666  "WHERE classid = 'pg_proc'::regclass AND "
5667  "objid = p.oid AND deptype = 'i')"
5668  "\n AND ("
5669  "\n pronamespace != "
5670  "(SELECT oid FROM pg_namespace "
5671  "WHERE nspname = 'pg_catalog')"
5672  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5673  "\n WHERE pg_cast.oid > %u "
5674  "\n AND p.oid = pg_cast.castfunc)"
5675  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5676  "\n WHERE pg_transform.oid > %u AND "
5677  "\n (p.oid = pg_transform.trffromsql"
5678  "\n OR p.oid = pg_transform.trftosql))",
5679  acl_subquery->data,
5680  racl_subquery->data,
5681  initacl_subquery->data,
5682  initracl_subquery->data,
5684  not_agg_check,
5687  if (dopt->binary_upgrade)
5688  appendPQExpBufferStr(query,
5689  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5690  "classid = 'pg_proc'::regclass AND "
5691  "objid = p.oid AND "
5692  "refclassid = 'pg_extension'::regclass AND "
5693  "deptype = 'e')");
5694  appendPQExpBufferStr(query,
5695  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
5696  appendPQExpBufferChar(query, ')');
5697 
5698  destroyPQExpBuffer(acl_subquery);
5699  destroyPQExpBuffer(racl_subquery);
5700  destroyPQExpBuffer(initacl_subquery);
5701  destroyPQExpBuffer(initracl_subquery);
5702  }
5703  else
5704  {
5705  appendPQExpBuffer(query,
5706  "SELECT tableoid, oid, proname, prolang, "
5707  "pronargs, proargtypes, prorettype, proacl, "
5708  "NULL as rproacl, "
5709  "NULL as initproacl, NULL AS initrproacl, "
5710  "pronamespace, "
5711  "(%s proowner) AS rolname "
5712  "FROM pg_proc p "
5713  "WHERE NOT proisagg",
5715  if (fout->remoteVersion >= 90200)
5716  appendPQExpBufferStr(query,
5717  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5718  "WHERE classid = 'pg_proc'::regclass AND "
5719  "objid = p.oid AND deptype = 'i')");
5720  appendPQExpBuffer(query,
5721  "\n AND ("
5722  "\n pronamespace != "
5723  "(SELECT oid FROM pg_namespace "
5724  "WHERE nspname = 'pg_catalog')"
5725  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5726  "\n WHERE pg_cast.oid > '%u'::oid"
5727  "\n AND p.oid = pg_cast.castfunc)",
5729 
5730  if (fout->remoteVersion >= 90500)
5731  appendPQExpBuffer(query,
5732  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5733  "\n WHERE pg_transform.oid > '%u'::oid"
5734  "\n AND (p.oid = pg_transform.trffromsql"
5735  "\n OR p.oid = pg_transform.trftosql))",
5737 
5738  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5739  appendPQExpBufferStr(query,
5740  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5741  "classid = 'pg_proc'::regclass AND "
5742  "objid = p.oid AND "
5743  "refclassid = 'pg_extension'::regclass AND "
5744  "deptype = 'e')");
5745  appendPQExpBufferChar(query, ')');
5746  }
5747 
5748  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5749 
5750  ntups = PQntuples(res);
5751 
5752  *numFuncs = ntups;
5753 
5754  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
5755 
5756  i_tableoid = PQfnumber(res, "tableoid");
5757  i_oid = PQfnumber(res, "oid");
5758  i_proname = PQfnumber(res, "proname");
5759  i_pronamespace = PQfnumber(res, "pronamespace");
5760  i_rolname = PQfnumber(res, "rolname");
5761  i_prolang = PQfnumber(res, "prolang");
5762  i_pronargs = PQfnumber(res, "pronargs");
5763  i_proargtypes = PQfnumber(res, "proargtypes");
5764  i_prorettype = PQfnumber(res, "prorettype");
5765  i_proacl = PQfnumber(res, "proacl");
5766  i_rproacl = PQfnumber(res, "rproacl");
5767  i_initproacl = PQfnumber(res, "initproacl");
5768  i_initrproacl = PQfnumber(res, "initrproacl");
5769 
5770  for (i = 0; i < ntups; i++)
5771  {
5772  finfo[i].dobj.objType = DO_FUNC;
5773  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5774  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5775  AssignDumpId(&finfo[i].dobj);
5776  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
5777  finfo[i].dobj.namespace =
5778  findNamespace(fout,
5779  atooid(PQgetvalue(res, i, i_pronamespace)));
5780  finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5781  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
5782  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
5783  finfo[i].proacl = pg_strdup(PQgetvalue(res, i, i_proacl));
5784  finfo[i].rproacl = pg_strdup(PQgetvalue(res, i, i_rproacl));
5785  finfo[i].initproacl = pg_strdup(PQgetvalue(res, i, i_initproacl));
5786  finfo[i].initrproacl = pg_strdup(PQgetvalue(res, i, i_initrproacl));
5787  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
5788  if (finfo[i].nargs == 0)
5789  finfo[i].argtypes = NULL;
5790  else
5791  {
5792  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
5793  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5794  finfo[i].argtypes, finfo[i].nargs);
5795  }
5796 
5797  /* Decide whether we want to dump it */
5798  selectDumpableObject(&(finfo[i].dobj), fout);
5799 
5800  /* Do not try to dump ACL if no ACL exists. */
5801  if (PQgetisnull(res, i, i_proacl) && PQgetisnull(res, i, i_rproacl) &&
5802  PQgetisnull(res, i, i_initproacl) &&
5803  PQgetisnull(res, i, i_initrproacl))
5804  finfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5805 
5806  if (strlen(finfo[i].rolname) == 0)
5807  write_msg(NULL,
5808  "WARNING: owner of function \"%s\" appears to be invalid\n",
5809  finfo[i].dobj.name);
5810  }
5811 
5812  PQclear(res);
5813 
5814  destroyPQExpBuffer(query);
5815 
5816  return finfo;
5817 }
Oid * argtypes
Definition: pg_dump.h:203
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1713
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int nargs
Definition: pg_dump.h:202
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4576
static int numFuncs
Definition: common.c:59
char * initrproacl
Definition: pg_dump.h:208
Oid lang
Definition: pg_dump.h:201
DumpableObject dobj
Definition: pg_dump.h:199
unsigned int Oid
Definition: postgres_ext.h:31
static Oid g_last_builtin_oid
Definition: pg_dump.c:104
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:136
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
DumpOptions * dopt
Definition: pg_backup.h:183
void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, const char *acl_column, const char *acl_owner, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:740
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
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:98
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1072
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
void PQclear(PGresult *res)
Definition: fe-exec.c:671
void write_msg(const char *modulename, const char *fmt,...)
Oid prorettype
Definition: pg_dump.h:204
char * initproacl
Definition: pg_dump.h:207
char * rolname
Definition: pg_dump.h:200
char * proacl
Definition: pg_dump.h:205
char * rproacl
Definition: pg_dump.h:206
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ getIndexes()

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

Definition at line 6712 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(), g_verbose, _tableInfo::hasindex, i, _indxInfo::indexconstraint, _indxInfo::indexdef, _tableInfo::indexes, _indxInfo::indextable, _indxInfo::indisclustered, _indxInfo::indisreplident, _indxInfo::indkeys, _indxInfo::indnattrs, _indxInfo::indnkeyattrs, _indxInfo::indreloptions, _tableInfo::interesting, InvalidOid, _dumpableObject::name, _tableInfo::numIndexes, numTables, _dumpableObject::objType, CatalogId::oid, _indxInfo::parentidx, parseOidArray(), pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _indxInfo::relpages, Archive::remoteVersion, resetPQExpBuffer(), _constraintInfo::separate, CatalogId::tableoid, _indxInfo::tablespace, and write_msg().

Referenced by getSchemaData().

6713 {
6714  int i,
6715  j;
6716  PQExpBuffer query = createPQExpBuffer();
6717  PGresult *res;
6718  IndxInfo *indxinfo;
6719  ConstraintInfo *constrinfo;
6720  int i_tableoid,
6721  i_oid,
6722  i_indexname,
6723  i_parentidx,
6724  i_indexdef,
6725  i_indnkeyatts,
6726  i_indnatts,
6727  i_indkey,
6728  i_indisclustered,
6729  i_indisreplident,
6730  i_contype,
6731  i_conname,
6732  i_condeferrable,
6733  i_condeferred,
6734  i_contableoid,
6735  i_conoid,
6736  i_condef,
6737  i_tablespace,
6738  i_indreloptions,
6739  i_relpages;
6740  int ntups;
6741 
6742  for (i = 0; i < numTables; i++)
6743  {
6744  TableInfo *tbinfo = &tblinfo[i];
6745 
6746  if (!tbinfo->hasindex)
6747  continue;
6748 
6749  /*
6750  * Ignore indexes of tables whose definitions are not to be dumped.
6751  *
6752  * We also need indexes on partitioned tables which have partitions to
6753  * be dumped, in order to dump the indexes on the partitions.
6754  */
6755  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) &&
6756  !tbinfo->interesting)
6757  continue;
6758 
6759  if (g_verbose)
6760  write_msg(NULL, "reading indexes for table \"%s.%s\"\n",
6761  tbinfo->dobj.namespace->dobj.name,
6762  tbinfo->dobj.name);
6763 
6764  /*
6765  * The point of the messy-looking outer join is to find a constraint
6766  * that is related by an internal dependency link to the index. If we
6767  * find one, create a CONSTRAINT entry linked to the INDEX entry. We
6768  * assume an index won't have more than one internal dependency.
6769  *
6770  * As of 9.0 we don't need to look at pg_depend but can check for a
6771  * match to pg_constraint.conindid. The check on conrelid is
6772  * redundant but useful because that column is indexed while conindid
6773  * is not.
6774  */
6775  resetPQExpBuffer(query);
6776  if (fout->remoteVersion >= 110000)
6777  {
6778  appendPQExpBuffer(query,
6779  "SELECT t.tableoid, t.oid, "
6780  "t.relname AS indexname, "
6781  "inh.inhparent AS parentidx, "
6782  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6783  "i.indnkeyatts AS indnkeyatts, "
6784  "i.indnatts AS indnatts, "
6785  "i.indkey, i.indisclustered, "
6786  "i.indisreplident, t.relpages, "
6787  "c.contype, c.conname, "
6788  "c.condeferrable, c.condeferred, "
6789  "c.tableoid AS contableoid, "
6790  "c.oid AS conoid, "
6791  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6792  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6793  "t.reloptions AS indreloptions "
6794  "FROM pg_catalog.pg_index i "
6795  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6796  "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
6797  "LEFT JOIN pg_catalog.pg_constraint c "
6798  "ON (i.indrelid = c.conrelid AND "
6799  "i.indexrelid = c.conindid AND "
6800  "c.contype IN ('p','u','x')) "
6801  "LEFT JOIN pg_catalog.pg_inherits inh "
6802  "ON (inh.inhrelid = indexrelid) "
6803  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6804  "AND (i.indisvalid OR t2.relkind = 'p') "
6805  "AND i.indisready "
6806  "ORDER BY indexname",
6807  tbinfo->dobj.catId.oid);
6808  }
6809  else if (fout->remoteVersion >= 90400)
6810  {
6811  /*
6812  * the test on indisready is necessary in 9.2, and harmless in
6813  * earlier/later versions
6814  */
6815  appendPQExpBuffer(query,
6816  "SELECT t.tableoid, t.oid, "
6817  "t.relname AS indexname, "
6818  "0 AS parentidx, "
6819  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6820  "i.indnatts AS indnkeyatts, "
6821  "i.indnatts AS indnatts, "
6822  "i.indkey, i.indisclustered, "
6823  "i.indisreplident, t.relpages, "
6824  "c.contype, c.conname, "
6825  "c.condeferrable, c.condeferred, "
6826  "c.tableoid AS contableoid, "
6827  "c.oid AS conoid, "
6828  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6829  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6830  "t.reloptions AS indreloptions "
6831  "FROM pg_catalog.pg_index i "
6832  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6833  "LEFT JOIN pg_catalog.pg_constraint c "
6834  "ON (i.indrelid = c.conrelid AND "
6835  "i.indexrelid = c.conindid AND "
6836  "c.contype IN ('p','u','x')) "
6837  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6838  "AND i.indisvalid AND i.indisready "
6839  "ORDER BY indexname",
6840  tbinfo->dobj.catId.oid);
6841  }
6842  else if (fout->remoteVersion >= 90000)
6843  {
6844  /*
6845  * the test on indisready is necessary in 9.2, and harmless in
6846  * earlier/later versions
6847  */
6848  appendPQExpBuffer(query,
6849  "SELECT t.tableoid, t.oid, "
6850  "t.relname AS indexname, "
6851  "0 AS parentidx, "
6852  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6853  "i.indnatts AS indnkeyatts, "
6854  "i.indnatts AS indnatts, "
6855  "i.indkey, i.indisclustered, "
6856  "false AS indisreplident, t.relpages, "
6857  "c.contype, c.conname, "
6858  "c.condeferrable, c.condeferred, "
6859  "c.tableoid AS contableoid, "
6860  "c.oid AS conoid, "
6861  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6862  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6863  "t.reloptions AS indreloptions "
6864  "FROM pg_catalog.pg_index i "
6865  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6866  "LEFT JOIN pg_catalog.pg_constraint c "
6867  "ON (i.indrelid = c.conrelid AND "
6868  "i.indexrelid = c.conindid AND "
6869  "c.contype IN ('p','u','x')) "
6870  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6871  "AND i.indisvalid AND i.indisready "
6872  "ORDER BY indexname",
6873  tbinfo->dobj.catId.oid);
6874  }
6875  else if (fout->remoteVersion >= 80200)
6876  {
6877  appendPQExpBuffer(query,
6878  "SELECT t.tableoid, t.oid, "
6879  "t.relname AS indexname, "
6880  "0 AS parentidx, "
6881  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6882  "i.indnatts AS indnkeyatts, "
6883  "i.indnatts AS indnatts, "
6884  "i.indkey, i.indisclustered, "
6885  "false AS indisreplident, t.relpages, "
6886  "c.contype, c.conname, "
6887  "c.condeferrable, c.condeferred, "
6888  "c.tableoid AS contableoid, "
6889  "c.oid AS conoid, "
6890  "null AS condef, "
6891  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6892  "t.reloptions AS indreloptions "
6893  "FROM pg_catalog.pg_index i "
6894  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6895  "LEFT JOIN pg_catalog.pg_depend d "
6896  "ON (d.classid = t.tableoid "
6897  "AND d.objid = t.oid "
6898  "AND d.deptype = 'i') "
6899  "LEFT JOIN pg_catalog.pg_constraint c "
6900  "ON (d.refclassid = c.tableoid "
6901  "AND d.refobjid = c.oid) "
6902  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6903  "AND i.indisvalid "
6904  "ORDER BY indexname",
6905  tbinfo->dobj.catId.oid);
6906  }
6907  else
6908  {
6909  appendPQExpBuffer(query,
6910  "SELECT t.tableoid, t.oid, "
6911  "t.relname AS indexname, "
6912  "0 AS parentidx, "
6913  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6914  "t.relnatts AS indnkeyatts, "
6915  "t.relnatts AS indnatts, "
6916  "i.indkey, i.indisclustered, "
6917  "false AS indisreplident, t.relpages, "
6918  "c.contype, c.conname, "
6919  "c.condeferrable, c.condeferred, "
6920  "c.tableoid AS contableoid, "
6921  "c.oid AS conoid, "
6922  "null AS condef, "
6923  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6924  "null AS indreloptions "
6925  "FROM pg_catalog.pg_index i "
6926  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6927  "LEFT JOIN pg_catalog.pg_depend d "
6928  "ON (d.classid = t.tableoid "
6929  "AND d.objid = t.oid "
6930  "AND d.deptype = 'i') "
6931  "LEFT JOIN pg_catalog.pg_constraint c "
6932  "ON (d.refclassid = c.tableoid "
6933  "AND d.refobjid = c.oid) "
6934  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6935  "ORDER BY indexname",
6936  tbinfo->dobj.catId.oid);
6937  }
6938 
6939  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6940 
6941  ntups = PQntuples(res);
6942 
6943  i_tableoid = PQfnumber(res, "tableoid");
6944  i_oid = PQfnumber(res, "oid");
6945  i_indexname = PQfnumber(res, "indexname");
6946  i_parentidx = PQfnumber(res, "parentidx");
6947  i_indexdef = PQfnumber(res, "indexdef");
6948  i_indnkeyatts = PQfnumber(res, "indnkeyatts");
6949  i_indnatts = PQfnumber(res, "indnatts");
6950  i_indkey = PQfnumber(res, "indkey");
6951  i_indisclustered = PQfnumber(res, "indisclustered");
6952  i_indisreplident = PQfnumber(res, "indisreplident");
6953  i_relpages = PQfnumber(res, "relpages");
6954  i_contype = PQfnumber(res, "contype");
6955  i_conname = PQfnumber(res, "conname");
6956  i_condeferrable = PQfnumber(res, "condeferrable");
6957  i_condeferred = PQfnumber(res, "condeferred");
6958  i_contableoid = PQfnumber(res, "contableoid");
6959  i_conoid = PQfnumber(res, "conoid");
6960  i_condef = PQfnumber(res, "condef");
6961  i_tablespace = PQfnumber(res, "tablespace");
6962  i_indreloptions = PQfnumber(res, "indreloptions");
6963 
6964  tbinfo->indexes = indxinfo =
6965  (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
6966  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
6967  tbinfo->numIndexes = ntups;
6968 
6969  for (j = 0; j < ntups; j++)
6970  {
6971  char contype;
6972 
6973  indxinfo[j].dobj.objType = DO_INDEX;
6974  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
6975  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
6976  AssignDumpId(&indxinfo[j].dobj);
6977  indxinfo[j].dobj.dump = tbinfo->dobj.dump;
6978  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
6979  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6980  indxinfo[j].indextable = tbinfo;
6981  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
6982  indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
6983  indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
6984  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
6985  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
6986  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
6987  parseOidArray(PQgetvalue(res, j, i_indkey),
6988  indxinfo[j].indkeys, indxinfo[j].indnattrs);
6989  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
6990  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
6991  indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
6992  indxinfo[j].relpages = atoi(PQgetvalue(res, j, i_relpages));
6993  contype = *(PQgetvalue(res, j, i_contype));
6994 
6995  if (contype == 'p' || contype == 'u' || contype == 'x')
6996  {
6997  /*
6998  * If we found a constraint matching the index, create an
6999  * entry for it.
7000  */
7001  constrinfo[j].dobj.objType = DO_CONSTRAINT;
7002  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7003  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7004  AssignDumpId(&constrinfo[j].dobj);
7005  constrinfo[j].dobj.dump = tbinfo->dobj.dump;
7006  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7007  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7008  constrinfo[j].contable = tbinfo;
7009  constrinfo[j].condomain = NULL;
7010  constrinfo[j].contype = contype;
7011  if (contype == 'x')
7012  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7013  else
7014  constrinfo[j].condef = NULL;
7015  constrinfo[j].confrelid = InvalidOid;
7016  constrinfo[j].conindex = indxinfo[j].dobj.dumpId;
7017  constrinfo[j].condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
7018  constrinfo[j].condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
7019  constrinfo[j].conislocal = true;
7020  constrinfo[j].separate = true;
7021 
7022  indxinfo[j].indexconstraint = constrinfo[j].dobj.dumpId;
7023  }
7024  else
7025  {
7026  /* Plain secondary index */
7027  indxinfo[j].indexconstraint = 0;
7028  }
7029  }
7030 
7031  PQclear(res);
7032  }
7033 
7034  destroyPQExpBuffer(query);
7035 }
char * tablespace
Definition: pg_dump.h:361
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
int relpages
Definition: pg_dump.h:372
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
bool hasindex
Definition: pg_dump.h:276
DumpId dumpId
Definition: pg_dump.h:133
static int numTables
Definition: common.c:57
unsigned int Oid
Definition: postgres_ext.h:31
DumpId conindex
Definition: pg_dump.h:444
DumpId indexconstraint
Definition: pg_dump.h:371
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
char * indexdef
Definition: pg_dump.h:360
DumpableObject dobj
Definition: pg_dump.h:262
Oid parentidx
Definition: pg_dump.h:369
char * condef
Definition: pg_dump.h:442
bool indisreplident
Definition: pg_dump.h:368
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:438
TableInfo * indextable
Definition: pg_dump.h:359
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
Oid * indkeys
Definition: pg_dump.h:365
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
bool condeferrable
Definition: pg_dump.h:445
char * indreloptions
Definition: pg_dump.h:362
TypeInfo * condomain
Definition: pg_dump.h:440
bool conislocal
Definition: pg_dump.h:447
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1072
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int numIndexes
Definition: pg_dump.h:332
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
TableInfo * contable
Definition: pg_dump.h:439
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:93
void write_msg(const char *modulename, const char *fmt,...)
bool condeferred
Definition: pg_dump.h:446
int indnkeyattrs
Definition: pg_dump.h:363
int indnattrs
Definition: pg_dump.h:364
struct _indxInfo * indexes
Definition: pg_dump.h:333
CatalogId catId
Definition: pg_dump.h:132
DumpableObject dobj
Definition: pg_dump.h:358
bool interesting
Definition: pg_dump.h:295
int i
bool indisclustered
Definition: pg_dump.h:367
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
DumpableObjectType objType
Definition: pg_dump.h:131
bool g_verbose
Definition: pg_dump.c:93
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ getInherits()

InhInfo* getInherits ( Archive fout,
int *  numInherits 
)

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

6662 {
6663  PGresult *res;
6664  int ntups;
6665  int i;
6666  PQExpBuffer query = createPQExpBuffer();
6667  InhInfo *inhinfo;
6668 
6669  int i_inhrelid;
6670  int i_inhparent;
6671 
6672  /*
6673  * Find all the inheritance information, excluding implicit inheritance
6674  * via partitioning. We handle that case using getPartitions(), because
6675  * we want more information about partitions than just the parent-child
6676  * relationship.
6677  */
6678  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
6679 
6680  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6681 
6682  ntups = PQntuples(res);
6683 
6684  *numInherits = ntups;
6685 
6686  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6687 
6688  i_inhrelid = PQfnumber(res, "inhrelid");
6689  i_inhparent = PQfnumber(res, "inhparent");
6690 
6691  for (i = 0; i < ntups; i++)
6692  {
6693  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6694  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6695  }
6696 
6697  PQclear(res);
6698 
6699  destroyPQExpBuffer(query);
6700 
6701  return inhinfo;
6702 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
Oid inhrelid
Definition: pg_dump.h:487
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
Oid inhparent
Definition: pg_dump.h:488
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )

Definition at line 622 of file common.c.

References lastDumpId.

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

623 {
624  return lastDumpId;
625 }
static DumpId lastDumpId
Definition: common.c:33

◆ getNamespaces()

NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

Definition at line 4448 of file pg_dump.c.

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

Referenced by getSchemaData().

4449 {
4450  DumpOptions *dopt = fout->dopt;
4451  PGresult *res;
4452  int ntups;
4453  int i;
4454  PQExpBuffer query;
4455  NamespaceInfo *nsinfo;
4456  int i_tableoid;
4457  int i_oid;
4458  int i_nspname;
4459  int i_rolname;
4460  int i_nspacl;
4461  int i_rnspacl;
4462  int i_initnspacl;
4463  int i_initrnspacl;
4464 
4465  query = createPQExpBuffer();
4466 
4467  /*
4468  * we fetch all namespaces including system ones, so that every object we
4469  * read in can be linked to a containing namespace.
4470  */
4471  if (fout->remoteVersion >= 90600)
4472  {
4473  PQExpBuffer acl_subquery = createPQExpBuffer();
4474  PQExpBuffer racl_subquery = createPQExpBuffer();
4475  PQExpBuffer init_acl_subquery = createPQExpBuffer();
4476  PQExpBuffer init_racl_subquery = createPQExpBuffer();
4477 
4478  buildACLQueries(acl_subquery, racl_subquery, init_acl_subquery,
4479  init_racl_subquery, "n.nspacl", "n.nspowner", "'n'",
4480  dopt->binary_upgrade);
4481 
4482  appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, "
4483  "(%s nspowner) AS rolname, "
4484  "%s as nspacl, "
4485  "%s as rnspacl, "
4486  "%s as initnspacl, "
4487  "%s as initrnspacl "
4488  "FROM pg_namespace n "
4489  "LEFT JOIN pg_init_privs pip "
4490  "ON (n.oid = pip.objoid "
4491  "AND pip.classoid = 'pg_namespace'::regclass "
4492  "AND pip.objsubid = 0",
4494  acl_subquery->data,
4495  racl_subquery->data,
4496  init_acl_subquery->data,
4497  init_racl_subquery->data);
4498 
4499  appendPQExpBuffer(query, ") ");
4500 
4501  destroyPQExpBuffer(acl_subquery);
4502  destroyPQExpBuffer(racl_subquery);
4503  destroyPQExpBuffer(init_acl_subquery);
4504  destroyPQExpBuffer(init_racl_subquery);
4505  }
4506  else
4507  appendPQExpBuffer(query, "SELECT tableoid, oid, nspname, "
4508  "(%s nspowner) AS rolname, "
4509  "nspacl, NULL as rnspacl, "
4510  "NULL AS initnspacl, NULL as initrnspacl "
4511  "FROM pg_namespace",
4513 
4514  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4515 
4516  ntups = PQntuples(res);
4517 
4518  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
4519 
4520  i_tableoid = PQfnumber(res, "tableoid");
4521  i_oid = PQfnumber(res, "oid");
4522  i_nspname = PQfnumber(res, "nspname");
4523  i_rolname = PQfnumber(res, "rolname");
4524  i_nspacl = PQfnumber(res, "nspacl");
4525  i_rnspacl = PQfnumber(res, "rnspacl");
4526  i_initnspacl = PQfnumber(res, "initnspacl");
4527  i_initrnspacl = PQfnumber(res, "initrnspacl");
4528 
4529  for (i = 0; i < ntups; i++)
4530  {
4531  nsinfo[i].dobj.objType = DO_NAMESPACE;
4532  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4533  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4534  AssignDumpId(&nsinfo[i].dobj);
4535  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
4536  nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4537  nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl));
4538  nsinfo[i].rnspacl = pg_strdup(PQgetvalue(res, i, i_rnspacl));
4539  nsinfo[i].initnspacl = pg_strdup(PQgetvalue(res, i, i_initnspacl));
4540  nsinfo[i].initrnspacl = pg_strdup(PQgetvalue(res, i, i_initrnspacl));
4541 
4542  /* Decide whether to dump this namespace */
4543  selectDumpableNamespace(&nsinfo[i], fout);
4544 
4545  /*
4546  * Do not try to dump ACL if the ACL is empty or the default.
4547  *
4548  * This is useful because, for some schemas/objects, the only
4549  * component we are going to try and dump is the ACL and if we can
4550  * remove that then 'dump' goes to zero/false and we don't consider
4551  * this object for dumping at all later on.
4552  */
4553  if (PQgetisnull(res, i, i_nspacl) && PQgetisnull(res, i, i_rnspacl) &&
4554  PQgetisnull(res, i, i_initnspacl) &&
4555  PQgetisnull(res, i, i_initrnspacl))
4556  nsinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4557 
4558  if (strlen(nsinfo[i].rolname) == 0)
4559  write_msg(NULL, "WARNING: owner of schema \"%s\" appears to be invalid\n",
4560  nsinfo[i].dobj.name);
4561  }
4562 
4563  PQclear(res);
4564  destroyPQExpBuffer(query);
4565 
4566  *numNamespaces = ntups;
4567 
4568  return nsinfo;
4569 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
char * rnspacl
Definition: pg_dump.h:149
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:136
DumpOptions * dopt
Definition: pg_backup.h:183
void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, const char *acl_column, const char *acl_owner, const char *obj_kind, bool binary_upgrade)
Definition: dumputils.c:740
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
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:62
#define atooid(x)
Definition: postgres_ext.h:42
static const char * username_subquery
Definition: pg_dump.c:98
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1414
void PQclear(PGresult *res)
Definition: fe-exec.c:671
void write_msg(const char *modulename, const char *fmt,...)
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
char * initrnspacl
Definition: pg_dump.h:151
CatalogId catId
Definition: pg_dump.h:132
int i
char * nspacl
Definition: pg_dump.h:148
DumpableObject dobj
Definition: pg_dump.h:146
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ getOpclasses()

OpclassInfo* getOpclasses ( Archive fout,
int *  numOpclasses 
)

Definition at line 5238 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_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _opclassInfo::rolname, selectDumpableObject(), CatalogId::tableoid, username_subquery, and write_msg().

Referenced by getSchemaData().

5239 {
5240  PGresult *res;
5241  int ntups;
5242  int i;
5243  PQExpBuffer query = createPQExpBuffer();
5244  OpclassInfo *opcinfo;
5245  int i_tableoid;
5246  int i_oid;
5247  int i_opcname;
5248  int i_opcnamespace;
5249  int i_rolname;
5250 
5251  /*
5252  * find all opclasses, including builtin opclasses; we filter out
5253  * system-defined opclasses at dump-out time.
5254  */
5255 
5256  appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
5257  "opcnamespace, "
5258  "(%s opcowner) AS rolname "
5259  "FROM pg_opclass",
5261 
5262  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5263 
5264  ntups = PQntuples(res);
5265  *numOpclasses = ntups;
5266 
5267  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
5268 
5269  i_tableoid = PQfnumber(res, "tableoid");
5270  i_oid = PQfnumber(res, "oid");
5271  i_opcname = PQfnumber(res, "opcname");
5272  i_opcnamespace = PQfnumber(res, "opcnamespace");
5273  i_rolname = PQfnumber(res, "rolname");
5274 
5275  for (i = 0; i < ntups; i++)
5276  {
5277  opcinfo[i].dobj.objType = DO_OPCLASS;
5278  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5279  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5280  AssignDumpId(&opcinfo[i].dobj);
5281  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
5282  opcinfo[i].dobj.namespace =
5283  findNamespace(fout,
5284  atooid(PQgetvalue(res, i, i_opcnamespace)));
5285  opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5286 
5287  /* Decide whether we want to dump it */
5288  selectDumpableObject(&(opcinfo[i].dobj), fout);
5289 
5290  /* Op Classes do not currently have ACLs. */
5291  opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5292 
5293  if (strlen(opcinfo[i].rolname) == 0)
5294  write_msg(NULL, "WARNING: owner of operator class \"%s\" appears to be invalid\n",
5295  opcinfo[i].dobj.name);
5296  }
5297 
5298  PQclear(res);
5299 
5300  destroyPQExpBuffer(query);
5301 
5302  return opcinfo;
5303 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1713
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4576
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
char * rolname
Definition: pg_dump.h:236
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
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:98
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
DumpableObject dobj
Definition: pg_dump.h:235
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
void write_msg(const char *modulename, const char *fmt,...)
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
int i
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405

◆ getOperators()

OprInfo* getOperators ( Archive fout,
int *  numOperators 
)

Definition at line 4928 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_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _oprInfo::rolname, selectDumpableObject(), CatalogId::tableoid, username_subquery, and write_msg().

Referenced by getSchemaData().

4929 {
4930  PGresult *res;
4931  int ntups;
4932  int i;
4933  PQExpBuffer query = createPQExpBuffer();
4934  OprInfo *oprinfo;
4935  int i_tableoid;
4936  int i_oid;
4937  int i_oprname;
4938  int i_oprnamespace;
4939  int i_rolname;
4940  int i_oprkind;
4941  int i_oprcode;
4942 
4943  /*
4944  * find all operators, including builtin operators; we filter out
4945  * system-defined operators at dump-out time.
4946  */
4947 
4948  appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
4949  "oprnamespace, "
4950  "(%s oprowner) AS rolname, "
4951  "oprkind, "
4952  "oprcode::oid AS oprcode "
4953  "FROM pg_operator",
4955 
4956  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4957 
4958  ntups = PQntuples(res);
4959  *numOprs = ntups;
4960 
4961  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
4962 
4963  i_tableoid = PQfnumber(res, "tableoid");
4964  i_oid = PQfnumber(res, "oid");
4965  i_oprname = PQfnumber(res, "oprname");
4966  i_oprnamespace = PQfnumber(res, "oprnamespace");
4967  i_rolname = PQfnumber(res, "rolname");
4968  i_oprkind = PQfnumber(res, "oprkind");
4969  i_oprcode = PQfnumber(res, "oprcode");
4970 
4971  for (i = 0; i < ntups; i++)
4972  {
4973  oprinfo[i].dobj.objType = DO_OPERATOR;
4974  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4975  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4976  AssignDumpId(&oprinfo[i].dobj);
4977  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
4978  oprinfo[i].dobj.namespace =
4979  findNamespace(fout,
4980  atooid(PQgetvalue(res, i, i_oprnamespace)));
4981  oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4982  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
4983  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
4984 
4985  /* Decide whether we want to dump it */
4986  selectDumpableObject(&(oprinfo[i].dobj), fout);
4987 
4988  /* Operators do not currently have ACLs. */
4989  oprinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4990 
4991  if (strlen(oprinfo[i].rolname) == 0)
4992  write_msg(NULL, "WARNING: owner of operator \"%s\" appears to be invalid\n",
4993  oprinfo[i].dobj.name);
4994  }
4995 
4996  PQclear(res);
4997 
4998  destroyPQExpBuffer(query);
4999 
5000  return oprinfo;
5001 }
char * name
Definition: pg_dump.h:134
DumpableObject dobj
Definition: pg_dump.h:220
DumpComponents dump
Definition: pg_dump.h:135
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1713
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4576
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
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:98
char * rolname
Definition: pg_dump.h:221
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char oprkind
Definition: pg_dump.h:222
void write_msg(const char *modulename, const char *fmt,...)
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
int i
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
Oid oprcode
Definition: pg_dump.h:223

◆ getOpfamilies()

OpfamilyInfo* getOpfamilies ( Archive fout,
int *  numOpfamilies 
)

Definition at line 5313 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_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _opfamilyInfo::rolname, selectDumpableObject(), CatalogId::tableoid, username_subquery, and write_msg().

Referenced by getSchemaData().

5314 {
5315  PGresult *res;
5316  int ntups;
5317  int i;
5318  PQExpBuffer query;
5319  OpfamilyInfo *opfinfo;
5320  int i_tableoid;
5321  int i_oid;
5322  int i_opfname;
5323  int i_opfnamespace;
5324  int i_rolname;
5325 
5326  /* Before 8.3, there is no separate concept of opfamilies */
5327  if (fout->remoteVersion < 80300)
5328  {
5329  *numOpfamilies = 0;
5330  return NULL;
5331  }
5332 
5333  query = createPQExpBuffer();
5334 
5335  /*
5336  * find all opfamilies, including builtin opfamilies; we filter out
5337  * system-defined opfamilies at dump-out time.
5338  */
5339 
5340  appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, "
5341  "opfnamespace, "
5342  "(%s opfowner) AS rolname "
5343  "FROM pg_opfamily",
5345 
5346  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5347 
5348  ntups = PQntuples(res);
5349  *numOpfamilies = ntups;
5350 
5351  opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
5352 
5353  i_tableoid = PQfnumber(res, "tableoid");
5354  i_oid = PQfnumber(res, "oid");
5355  i_opfname = PQfnumber(res, "opfname");
5356  i_opfnamespace = PQfnumber(res, "opfnamespace");
5357  i_rolname = PQfnumber(res, "rolname");
5358 
5359  for (i = 0; i < ntups; i++)
5360  {
5361  opfinfo[i].dobj.objType = DO_OPFAMILY;
5362  opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5363  opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5364  AssignDumpId(&opfinfo[i].dobj);
5365  opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
5366  opfinfo[i].dobj.namespace =
5367  findNamespace(fout,
5368  atooid(PQgetvalue(res, i, i_opfnamespace)));
5369  opfinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5370 
5371  /* Decide whether we want to dump it */
5372  selectDumpableObject(&(opfinfo[i].dobj), fout);
5373 
5374  /* Extensions do not currently have ACLs. */
5375  opfinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5376 
5377  if (strlen(opfinfo[i].rolname) == 0)
5378  write_msg(NULL, "WARNING: owner of operator family \"%s\" appears to be invalid\n",
5379  opfinfo[i].dobj.name);
5380  }
5381 
5382  PQclear(res);
5383 
5384  destroyPQExpBuffer(query);
5385 
5386  return opfinfo;
5387 }
char * name
Definition: pg_dump.h:134
DumpableObject dobj
Definition: pg_dump.h:241
DumpComponents dump
Definition: pg_dump.h:135
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1713
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4576
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113