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  _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 _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_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, TableInfo tblinfo[], int numTables)
 
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 97 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 98 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 123 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 90 of file pg_dump.h.

◆ EventTriggerInfo

◆ ExtensionInfo

◆ ExtensionMemberId

◆ FdwInfo

◆ ForeignServerInfo

◆ FuncInfo

◆ 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_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,
60  DO_RULE,
61  DO_TRIGGER,
63  DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
65  DO_CAST,
70  DO_TSDICT,
73  DO_FDW,
77  DO_BLOB,
83  DO_POLICY,
DumpableObjectType
Definition: pg_dump.h:41
Definition: pg_dump.h:49
Definition: pg_dump.h:73

Function Documentation

◆ addObjectDependency()

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

Definition at line 712 of file common.c.

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

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

713 {
714  if (dobj->nDeps >= dobj->allocDeps)
715  {
716  if (dobj->allocDeps <= 0)
717  {
718  dobj->allocDeps = 16;
719  dobj->dependencies = (DumpId *)
720  pg_malloc(dobj->allocDeps * sizeof(DumpId));
721  }
722  else
723  {
724  dobj->allocDeps *= 2;
725  dobj->dependencies = (DumpId *)
726  pg_realloc(dobj->dependencies,
727  dobj->allocDeps * sizeof(DumpId));
728  }
729  }
730  dobj->dependencies[dobj->nDeps++] = refId;
731 }
int DumpId
Definition: pg_backup.h:230
DumpId * dependencies
Definition: pg_dump.h:138
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 476 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(), 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().

477 {
478  dobj->dumpId = ++lastDumpId;
479  dobj->name = NULL; /* must be set later */
480  dobj->namespace = NULL; /* may be set later */
481  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
482  dobj->ext_member = false; /* default assumption */
483  dobj->dependencies = NULL;
484  dobj->nDeps = 0;
485  dobj->allocDeps = 0;
486 
487  while (dobj->dumpId >= allocedDumpIds)
488  {
489  int newAlloc;
490 
491  if (allocedDumpIds <= 0)
492  {
493  newAlloc = 256;
495  pg_malloc(newAlloc * sizeof(DumpableObject *));
496  }
497  else
498  {
499  newAlloc = allocedDumpIds * 2;
501  pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
502  }
503  memset(dumpIdMap + allocedDumpIds, 0,
504  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
505  allocedDumpIds = newAlloc;
506  }
507  dumpIdMap[dobj->dumpId] = dobj;
508 
509  /* mark catalogIdMap invalid, but don't rebuild it yet */
510  catalogIdMapValid = false;
511 }
char * name
Definition: pg_dump.h:133
static int allocedDumpIds
Definition: common.c:32
DumpComponents dump
Definition: pg_dump.h:134
static DumpId lastDumpId
Definition: common.c:33
static DumpableObject ** dumpIdMap
Definition: common.c:31
DumpId * dependencies
Definition: pg_dump.h:138
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpId dumpId
Definition: pg_dump.h:132
bool ext_member
Definition: pg_dump.h:137
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:99

◆ createDumpId()

DumpId createDumpId ( void  )

◆ findCollationByOid()

CollInfo* findCollationByOid ( Oid  oid)

Definition at line 803 of file common.c.

References findObjectByOid(), and numCollations.

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

804 {
806 }
static DumpableObject ** collinfoindex
Definition: common.c:54
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:609
static int numCollations
Definition: common.c:61

◆ findExtensionByOid()

ExtensionInfo* findExtensionByOid ( Oid  oid)

Definition at line 825 of file common.c.

References findObjectByOid(), and numExtensions.

Referenced by getExtensionMembership().

826 {
828 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:609
static int numExtensions
Definition: common.c:63
static DumpableObject ** extinfoindex
Definition: common.c:56

◆ findFuncByOid()

FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 781 of file common.c.

References findObjectByOid(), and numFuncs.

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

782 {
783  return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs);
784 }
static int numFuncs
Definition: common.c:59
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:609
static DumpableObject ** funinfoindex
Definition: common.c:52

◆ findNamespaceByOid()

NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 814 of file common.c.

References findObjectByOid(), and numNamespaces.

Referenced by findNamespace().

815 {
817 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:609
static int numNamespaces
Definition: common.c:62
static DumpableObject ** nspinfoindex
Definition: common.c:55

◆ findObjectByCatalogId()

DumpableObject* findObjectByCatalogId ( CatalogId  catalogId)

Definition at line 558 of file common.c.

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

Referenced by buildMatViewRefreshDependencies(), and getDependencies().

559 {
560  DumpableObject **low;
561  DumpableObject **high;
562 
563  if (!catalogIdMapValid)
564  {
565  if (catalogIdMap)
568  if (numCatalogIds > 1)
569  qsort((void *) catalogIdMap, numCatalogIds,
571  catalogIdMapValid = true;
572  }
573 
574  /*
575  * We could use bsearch() here, but the notational cruft of calling
576  * bsearch is nearly as bad as doing it ourselves; and the generalized
577  * bsearch function is noticeably slower as well.
578  */
579  if (numCatalogIds <= 0)
580  return NULL;
581  low = catalogIdMap;
582  high = catalogIdMap + (numCatalogIds - 1);
583  while (low <= high)
584  {
585  DumpableObject **middle;
586  int difference;
587 
588  middle = low + (high - low) / 2;
589  /* comparison must match DOCatalogIdCompare, below */
590  difference = oidcmp((*middle)->catId.oid, catalogId.oid);
591  if (difference == 0)
592  difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid);
593  if (difference == 0)
594  return *middle;
595  else if (difference < 0)
596  low = middle + 1;
597  else
598  high = middle - 1;
599  }
600  return NULL;
601 }
Oid tableoid
Definition: pg_backup.h:226
#define oidcmp(x, y)
Definition: pg_dump.h:20
static int DOCatalogIdCompare(const void *p1, const void *p2)
Definition: common.c:668
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:408
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition: common.c:690

◆ findObjectByDumpId()

DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 540 of file common.c.

References allocedDumpIds.

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

541 {
542  if (dumpId <= 0 || dumpId >= allocedDumpIds)
543  return NULL; /* out of range? */
544  return dumpIdMap[dumpId];
545 }
static int allocedDumpIds
Definition: common.c:32
static DumpableObject ** dumpIdMap
Definition: common.c:31

◆ findOprByOid()

OprInfo* findOprByOid ( Oid  oid)

Definition at line 792 of file common.c.

References findObjectByOid(), and numOperators.

793 {
795 }
static DumpableObject ** oprinfoindex
Definition: common.c:53
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:609
static int numOperators
Definition: common.c:60

◆ findOwningExtension()

ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 852 of file common.c.

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

Referenced by checkExtensionMembership().

853 {
854  ExtensionMemberId *low;
855  ExtensionMemberId *high;
856 
857  /*
858  * We could use bsearch() here, but the notational cruft of calling
859  * bsearch is nearly as bad as doing it ourselves; and the generalized
860  * bsearch function is noticeably slower as well.
861  */
862  if (numextmembers <= 0)
863  return NULL;
864  low = extmembers;
865  high = extmembers + (numextmembers - 1);
866  while (low <= high)
867  {
868  ExtensionMemberId *middle;
869  int difference;
870 
871  middle = low + (high - low) / 2;
872  /* comparison must match ExtensionMemberIdCompare, below */
873  difference = oidcmp(middle->catId.oid, catalogId.oid);
874  if (difference == 0)
875  difference = oidcmp(middle->catId.tableoid, catalogId.tableoid);
876  if (difference == 0)
877  return middle->ext;
878  else if (difference < 0)
879  low = middle + 1;
880  else
881  high = middle - 1;
882  }
883  return NULL;
884 }
ExtensionInfo * ext
Definition: pg_dump.h:621
Oid tableoid
Definition: pg_backup.h:226
#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:620

◆ findTableByOid()

TableInfo* findTableByOid ( Oid  oid)

Definition at line 759 of file common.c.

References findObjectByOid(), and numTables.

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

760 {
762 }
static int numTables
Definition: common.c:57
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:609
static DumpableObject ** tblinfoindex
Definition: common.c:50

◆ findTypeByOid()

TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 770 of file common.c.

References findObjectByOid(), and numTypes.

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

771 {
772  return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes);
773 }
static int numTypes
Definition: common.c:58
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:609
static DumpableObject ** typinfoindex
Definition: common.c:51

◆ getAccessMethods()

AccessMethodInfo* getAccessMethods ( Archive fout,
int *  numAccessMethods 
)

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

Referenced by getSchemaData().

4942 {
4943  PGresult *res;
4944  int ntups;
4945  int i;
4946  PQExpBuffer query;
4947  AccessMethodInfo *aminfo;
4948  int i_tableoid;
4949  int i_oid;
4950  int i_amname;
4951  int i_amhandler;
4952  int i_amtype;
4953 
4954  /* Before 9.6, there are no user-defined access methods */
4955  if (fout->remoteVersion < 90600)
4956  {
4957  *numAccessMethods = 0;
4958  return NULL;
4959  }
4960 
4961  query = createPQExpBuffer();
4962 
4963  /* Make sure we are in proper schema */
4964  selectSourceSchema(fout, "pg_catalog");
4965 
4966  /* Select all access methods from pg_am table */
4967  appendPQExpBuffer(query, "SELECT tableoid, oid, amname, amtype, "
4968  "amhandler::pg_catalog.regproc AS amhandler "
4969  "FROM pg_am");
4970 
4971  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4972 
4973  ntups = PQntuples(res);
4974  *numAccessMethods = ntups;
4975 
4976  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
4977 
4978  i_tableoid = PQfnumber(res, "tableoid");
4979  i_oid = PQfnumber(res, "oid");
4980  i_amname = PQfnumber(res, "amname");
4981  i_amhandler = PQfnumber(res, "amhandler");
4982  i_amtype = PQfnumber(res, "amtype");
4983 
4984  for (i = 0; i < ntups; i++)
4985  {
4986  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
4987  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4988  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4989  AssignDumpId(&aminfo[i].dobj);
4990  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
4991  aminfo[i].dobj.namespace = NULL;
4992  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
4993  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
4994 
4995  /* Decide whether we want to dump it */
4996  selectDumpableAccessMethod(&(aminfo[i]), fout);
4997 
4998  /* Access methods do not currently have ACLs. */
4999  aminfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5000  }
5001 
5002  PQclear(res);
5003 
5004  destroyPQExpBuffer(query);
5005 
5006  return aminfo;
5007 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:227
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:1597
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 void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
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:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186

◆ getAggregates()

AggInfo* getAggregates ( Archive fout,
int *  numAggregates 
)

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

Referenced by getSchemaData().

5184 {
5185  DumpOptions *dopt = fout->dopt;
5186  PGresult *res;
5187  int ntups;
5188  int i;
5189  PQExpBuffer query = createPQExpBuffer();
5190  AggInfo *agginfo;
5191  int i_tableoid;
5192  int i_oid;
5193  int i_aggname;
5194  int i_aggnamespace;
5195  int i_pronargs;
5196  int i_proargtypes;
5197  int i_rolname;
5198  int i_aggacl;
5199  int i_raggacl;
5200  int i_initaggacl;
5201  int i_initraggacl;
5202 
5203  /* Make sure we are in proper schema */
5204  selectSourceSchema(fout, "pg_catalog");
5205 
5206  /*
5207  * Find all interesting aggregates. See comment in getFuncs() for the
5208  * rationale behind the filtering logic.
5209  */
5210  if (fout->remoteVersion >= 90600)
5211  {
5212  PQExpBuffer acl_subquery = createPQExpBuffer();
5213  PQExpBuffer racl_subquery = createPQExpBuffer();
5214  PQExpBuffer initacl_subquery = createPQExpBuffer();
5215  PQExpBuffer initracl_subquery = createPQExpBuffer();
5216 
5217  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5218  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5219  dopt->binary_upgrade);
5220 
5221  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5222  "p.proname AS aggname, "
5223  "p.pronamespace AS aggnamespace, "
5224  "p.pronargs, p.proargtypes, "
5225  "(%s p.proowner) AS rolname, "
5226  "%s AS aggacl, "
5227  "%s AS raggacl, "
5228  "%s AS initaggacl, "
5229  "%s AS initraggacl "
5230  "FROM pg_proc p "
5231  "LEFT JOIN pg_init_privs pip ON "
5232  "(p.oid = pip.objoid "
5233  "AND pip.classoid = 'pg_proc'::regclass "
5234  "AND pip.objsubid = 0) "
5235  "WHERE p.proisagg AND ("
5236  "p.pronamespace != "
5237  "(SELECT oid FROM pg_namespace "
5238  "WHERE nspname = 'pg_catalog') OR "
5239  "p.proacl IS DISTINCT FROM pip.initprivs",
5241  acl_subquery->data,
5242  racl_subquery->data,
5243  initacl_subquery->data,
5244  initracl_subquery->data);
5245  if (dopt->binary_upgrade)
5246  appendPQExpBufferStr(query,
5247  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5248  "classid = 'pg_proc'::regclass AND "
5249  "objid = p.oid AND "
5250  "refclassid = 'pg_extension'::regclass AND "
5251  "deptype = 'e')");
5252  appendPQExpBufferChar(query, ')');
5253 
5254  destroyPQExpBuffer(acl_subquery);
5255  destroyPQExpBuffer(racl_subquery);
5256  destroyPQExpBuffer(initacl_subquery);
5257  destroyPQExpBuffer(initracl_subquery);
5258  }
5259  else if (fout->remoteVersion >= 80200)
5260  {
5261  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5262  "pronamespace AS aggnamespace, "
5263  "pronargs, proargtypes, "
5264  "(%s proowner) AS rolname, "
5265  "proacl AS aggacl, "
5266  "NULL AS raggacl, "
5267  "NULL AS initaggacl, NULL AS initraggacl "
5268  "FROM pg_proc p "
5269  "WHERE proisagg AND ("
5270  "pronamespace != "
5271  "(SELECT oid FROM pg_namespace "
5272  "WHERE nspname = 'pg_catalog')",
5274  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5275  appendPQExpBufferStr(query,
5276  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5277  "classid = 'pg_proc'::regclass AND "
5278  "objid = p.oid AND "
5279  "refclassid = 'pg_extension'::regclass AND "
5280  "deptype = 'e')");
5281  appendPQExpBufferChar(query, ')');
5282  }
5283  else
5284  {
5285  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5286  "pronamespace AS aggnamespace, "
5287  "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
5288  "proargtypes, "
5289  "(%s proowner) AS rolname, "
5290  "proacl AS aggacl, "
5291  "NULL AS raggacl, "
5292  "NULL AS initaggacl, NULL AS initraggacl "
5293  "FROM pg_proc "
5294  "WHERE proisagg "
5295  "AND pronamespace != "
5296  "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
5298  }
5299 
5300  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5301 
5302  ntups = PQntuples(res);
5303  *numAggs = ntups;
5304 
5305  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5306 
5307  i_tableoid = PQfnumber(res, "tableoid");
5308  i_oid = PQfnumber(res, "oid");
5309  i_aggname = PQfnumber(res, "aggname");
5310  i_aggnamespace = PQfnumber(res, "aggnamespace");
5311  i_pronargs = PQfnumber(res, "pronargs");
5312  i_proargtypes = PQfnumber(res, "proargtypes");
5313  i_rolname = PQfnumber(res, "rolname");
5314  i_aggacl = PQfnumber(res, "aggacl");
5315  i_raggacl = PQfnumber(res, "raggacl");
5316  i_initaggacl = PQfnumber(res, "initaggacl");
5317  i_initraggacl = PQfnumber(res, "initraggacl");
5318 
5319  for (i = 0; i < ntups; i++)
5320  {
5321  agginfo[i].aggfn.dobj.objType = DO_AGG;
5322  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5323  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5324  AssignDumpId(&agginfo[i].aggfn.dobj);
5325  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5326  agginfo[i].aggfn.dobj.namespace =
5327  findNamespace(fout,
5328  atooid(PQgetvalue(res, i, i_aggnamespace)));
5329  agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5330  if (strlen(agginfo[i].aggfn.rolname) == 0)
5331  write_msg(NULL, "WARNING: owner of aggregate function \"%s\" appears to be invalid\n",
5332  agginfo[i].aggfn.dobj.name);
5333  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5334  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5335  agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5336  agginfo[i].aggfn.rproacl = pg_strdup(PQgetvalue(res, i, i_raggacl));
5337  agginfo[i].aggfn.initproacl = pg_strdup(PQgetvalue(res, i, i_initaggacl));
5338  agginfo[i].aggfn.initrproacl = pg_strdup(PQgetvalue(res, i, i_initraggacl));
5339  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5340  if (agginfo[i].aggfn.nargs == 0)
5341  agginfo[i].aggfn.argtypes = NULL;
5342  else
5343  {
5344  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5345  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5346  agginfo[i].aggfn.argtypes,
5347  agginfo[i].aggfn.nargs);
5348  }
5349 
5350  /* Decide whether we want to dump it */
5351  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5352 
5353  /* Do not try to dump ACL if no ACL exists. */
5354  if (PQgetisnull(res, i, i_aggacl) && PQgetisnull(res, i, i_raggacl) &&
5355  PQgetisnull(res, i, i_initaggacl) &&
5356  PQgetisnull(res, i, i_initraggacl))
5357  agginfo[i].aggfn.dobj.dump &= ~DUMP_COMPONENT_ACL;
5358  }
5359 
5360  PQclear(res);
5361 
5362  destroyPQExpBuffer(query);
5363 
5364  return agginfo;
5365 }
Oid * argtypes
Definition: pg_dump.h:202
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1663
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:201
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4338
char * initrproacl
Definition: pg_dump.h:207
Oid lang
Definition: pg_dump.h:200
DumpableObject dobj
Definition: pg_dump.h:198
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
FuncInfo aggfn
Definition: pg_dump.h:213
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
Definition: pg_dump.h:49
DumpOptions * dopt
Definition: pg_backup.h:181
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:698
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 void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
static const char * username_subquery
Definition: pg_dump.c:97
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:967
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:203
char * initproacl
Definition: pg_dump.h:206
char * rolname
Definition: pg_dump.h:199
char * proacl
Definition: pg_dump.h:204
char * rproacl
Definition: pg_dump.h:205
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186

◆ getCasts()

CastInfo* getCasts ( Archive fout,
int *  numCasts 
)

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

Referenced by getSchemaData().

7660 {
7661  PGresult *res;
7662  int ntups;
7663  int i;
7664  PQExpBuffer query = createPQExpBuffer();
7665  CastInfo *castinfo;
7666  int i_tableoid;
7667  int i_oid;
7668  int i_castsource;
7669  int i_casttarget;
7670  int i_castfunc;
7671  int i_castcontext;
7672  int i_castmethod;
7673 
7674  /* Make sure we are in proper schema */
7675  selectSourceSchema(fout, "pg_catalog");
7676 
7677  if (fout->remoteVersion >= 80400)
7678  {
7679  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7680  "castsource, casttarget, castfunc, castcontext, "
7681  "castmethod "
7682  "FROM pg_cast ORDER BY 3,4");
7683  }
7684  else
7685  {
7686  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7687  "castsource, casttarget, castfunc, castcontext, "
7688  "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
7689  "FROM pg_cast ORDER BY 3,4");
7690  }
7691 
7692  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7693 
7694  ntups = PQntuples(res);
7695 
7696  *numCasts = ntups;
7697 
7698  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
7699 
7700  i_tableoid = PQfnumber(res, "tableoid");
7701  i_oid = PQfnumber(res, "oid");
7702  i_castsource = PQfnumber(res, "castsource");
7703  i_casttarget = PQfnumber(res, "casttarget");
7704  i_castfunc = PQfnumber(res, "castfunc");
7705  i_castcontext = PQfnumber(res, "castcontext");
7706  i_castmethod = PQfnumber(res, "castmethod");
7707 
7708  for (i = 0; i < ntups; i++)
7709  {
7710  PQExpBufferData namebuf;
7711  TypeInfo *sTypeInfo;
7712  TypeInfo *tTypeInfo;
7713 
7714  castinfo[i].dobj.objType = DO_CAST;
7715  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7716  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7717  AssignDumpId(&castinfo[i].dobj);
7718  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
7719  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
7720  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
7721  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
7722  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
7723 
7724  /*
7725  * Try to name cast as concatenation of typnames. This is only used
7726  * for purposes of sorting. If we fail to find either type, the name
7727  * will be an empty string.
7728  */
7729  initPQExpBuffer(&namebuf);
7730  sTypeInfo = findTypeByOid(castinfo[i].castsource);
7731  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
7732  if (sTypeInfo && tTypeInfo)
7733  appendPQExpBuffer(&namebuf, "%s %s",
7734  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
7735  castinfo[i].dobj.name = namebuf.data;
7736 
7737  /* Decide whether we want to dump it */
7738  selectDumpableCast(&(castinfo[i]), fout);
7739 
7740  /* Casts do not currently have ACLs. */
7741  castinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7742  }
7743 
7744  PQclear(res);
7745 
7746  destroyPQExpBuffer(query);
7747 
7748  return castinfo;
7749 }
char * name
Definition: pg_dump.h:133
Oid castsource
Definition: pg_dump.h:456
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:226
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:1539
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:458
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:455
Oid casttarget
Definition: pg_dump.h:457
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
DumpableObject dobj
Definition: pg_dump.h:165
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:96
CatalogId catId
Definition: pg_dump.h:131
int i
char castmethod
Definition: pg_dump.h:460
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:770
DumpableObjectType objType
Definition: pg_dump.h:130
char castcontext
Definition: pg_dump.h:459
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186

◆ getCollations()

CollInfo* getCollations ( Archive fout,
int *  numCollations 
)

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

Referenced by getSchemaData().

4783 {
4784  PGresult *res;
4785  int ntups;
4786  int i;
4787  PQExpBuffer query;
4788  CollInfo *collinfo;
4789  int i_tableoid;
4790  int i_oid;
4791  int i_collname;
4792  int i_collnamespace;
4793  int i_rolname;
4794 
4795  /* Collations didn't exist pre-9.1 */
4796  if (fout->remoteVersion < 90100)
4797  {
4798  *numCollations = 0;
4799  return NULL;
4800  }
4801 
4802  query = createPQExpBuffer();
4803 
4804  /*
4805  * find all collations, including builtin collations; we filter out
4806  * system-defined collations at dump-out time.
4807  */
4808 
4809  /* Make sure we are in proper schema */
4810  selectSourceSchema(fout, "pg_catalog");
4811 
4812  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
4813  "collnamespace, "
4814  "(%s collowner) AS rolname "
4815  "FROM pg_collation",
4817 
4818  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4819 
4820  ntups = PQntuples(res);
4821  *numCollations = ntups;
4822 
4823  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
4824 
4825  i_tableoid = PQfnumber(res, "tableoid");
4826  i_oid = PQfnumber(res, "oid");
4827  i_collname = PQfnumber(res, "collname");
4828  i_collnamespace = PQfnumber(res, "collnamespace");
4829  i_rolname = PQfnumber(res, "rolname");
4830 
4831  for (i = 0; i < ntups; i++)
4832  {
4833  collinfo[i].dobj.objType = DO_COLLATION;
4834  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4835  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4836  AssignDumpId(&collinfo[i].dobj);
4837  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
4838  collinfo[i].dobj.namespace =
4839  findNamespace(fout,
4840  atooid(PQgetvalue(res, i, i_collnamespace)));
4841  collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4842 
4843  /* Decide whether we want to dump it */
4844  selectDumpableObject(&(collinfo[i].dobj), fout);
4845 
4846  /* Collations do not currently have ACLs. */
4847  collinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4848  }
4849 
4850  PQclear(res);
4851 
4852  destroyPQExpBuffer(query);
4853 
4854  return collinfo;
4855 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1663
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:4338
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
DumpableObject dobj
Definition: pg_dump.h:246
char * rolname
Definition: pg_dump.h:247
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 void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
static const char * username_subquery
Definition: pg_dump.c:97
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:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186

◆ getConstraints()

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

Definition at line 6884 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(), resetPQExpBuffer(), selectSourceSchema(), _constraintInfo::separate, CatalogId::tableoid, and write_msg().

Referenced by getSchemaData().

6885 {
6886  int i,
6887  j;
6888  ConstraintInfo *constrinfo;
6889  PQExpBuffer query;
6890  PGresult *res;
6891  int i_contableoid,
6892  i_conoid,
6893  i_conname,
6894  i_confrelid,
6895  i_condef;
6896  int ntups;
6897 
6898  query = createPQExpBuffer();
6899 
6900  for (i = 0; i < numTables; i++)
6901  {
6902  TableInfo *tbinfo = &tblinfo[i];
6903 
6904  if (!tbinfo->hastriggers ||
6905  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6906  continue;
6907 
6908  if (g_verbose)
6909  write_msg(NULL, "reading foreign key constraints for table \"%s.%s\"\n",
6910  tbinfo->dobj.namespace->dobj.name,
6911  tbinfo->dobj.name);
6912 
6913  /*
6914  * select table schema to ensure constraint expr is qualified if
6915  * needed
6916  */
6917  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6918 
6919  resetPQExpBuffer(query);
6920  appendPQExpBuffer(query,
6921  "SELECT tableoid, oid, conname, confrelid, "
6922  "pg_catalog.pg_get_constraintdef(oid) AS condef "
6923  "FROM pg_catalog.pg_constraint "
6924  "WHERE conrelid = '%u'::pg_catalog.oid "
6925  "AND contype = 'f'",
6926  tbinfo->dobj.catId.oid);
6927  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6928 
6929  ntups = PQntuples(res);
6930 
6931  i_contableoid = PQfnumber(res, "tableoid");
6932  i_conoid = PQfnumber(res, "oid");
6933  i_conname = PQfnumber(res, "conname");
6934  i_confrelid = PQfnumber(res, "confrelid");
6935  i_condef = PQfnumber(res, "condef");
6936 
6937  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
6938 
6939  for (j = 0; j < ntups; j++)
6940  {
6941  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
6942  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
6943  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
6944  AssignDumpId(&constrinfo[j].dobj);
6945  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
6946  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6947  constrinfo[j].contable = tbinfo;
6948  constrinfo[j].condomain = NULL;
6949  constrinfo[j].contype = 'f';
6950  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
6951  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
6952  constrinfo[j].conindex = 0;
6953  constrinfo[j].condeferrable = false;
6954  constrinfo[j].condeferred = false;
6955  constrinfo[j].conislocal = true;
6956  constrinfo[j].separate = true;
6957  }
6958 
6959  PQclear(res);
6960  }
6961 
6962  destroyPQExpBuffer(query);
6963 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:277
static int numTables
Definition: common.c:57
DumpId conindex
Definition: pg_dump.h:432
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
DumpableObject dobj
Definition: pg_dump.h:261
char * condef
Definition: pg_dump.h:430
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:426
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 void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
bool condeferrable
Definition: pg_dump.h:433
TypeInfo * condomain
Definition: pg_dump.h:428
bool conislocal
Definition: pg_dump.h:435
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:427
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
void write_msg(const char *modulename, const char *fmt,...)
bool condeferred
Definition: pg_dump.h:434
CatalogId catId
Definition: pg_dump.h:131
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
DumpableObjectType objType
Definition: pg_dump.h:130
bool g_verbose
Definition: pg_dump.c:92
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407

◆ getConversions()

ConvInfo* getConversions ( Archive fout,
int *  numConversions 
)

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

Referenced by getSchemaData().

4866 {
4867  PGresult *res;
4868  int ntups;
4869  int i;
4870  PQExpBuffer query;
4871  ConvInfo *convinfo;
4872  int i_tableoid;
4873  int i_oid;
4874  int i_conname;
4875  int i_connamespace;
4876  int i_rolname;
4877 
4878  query = createPQExpBuffer();
4879 
4880  /*
4881  * find all conversions, including builtin conversions; we filter out
4882  * system-defined conversions at dump-out time.
4883  */
4884 
4885  /* Make sure we are in proper schema */
4886  selectSourceSchema(fout, "pg_catalog");
4887 
4888  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
4889  "connamespace, "
4890  "(%s conowner) AS rolname "
4891  "FROM pg_conversion",
4893 
4894  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4895 
4896  ntups = PQntuples(res);
4897  *numConversions = ntups;
4898 
4899  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
4900 
4901  i_tableoid = PQfnumber(res, "tableoid");
4902  i_oid = PQfnumber(res, "oid");
4903  i_conname = PQfnumber(res, "conname");
4904  i_connamespace = PQfnumber(res, "connamespace");
4905  i_rolname = PQfnumber(res, "rolname");
4906 
4907  for (i = 0; i < ntups; i++)
4908  {
4909  convinfo[i].dobj.objType = DO_CONVERSION;
4910  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4911  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4912  AssignDumpId(&convinfo[i].dobj);
4913  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
4914  convinfo[i].dobj.namespace =
4915  findNamespace(fout,
4916  atooid(PQgetvalue(res, i, i_connamespace)));
4917  convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4918 
4919  /* Decide whether we want to dump it */
4920  selectDumpableObject(&(convinfo[i].dobj), fout);
4921 
4922  /* Conversions do not currently have ACLs. */
4923  convinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4924  }
4925 
4926  PQclear(res);
4927 
4928  destroyPQExpBuffer(query);
4929 
4930  return convinfo;
4931 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1663
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:4338
char * rolname
Definition: pg_dump.h:253
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 void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
static const char * username_subquery
Definition: pg_dump.c:97
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:252
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407

◆ getDefaultACLs()

DefaultACLInfo* getDefaultACLs ( Archive fout,
int *  numDefaultACLs 
)

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

Referenced by getSchemaData().

9026 {
9027  DumpOptions *dopt = fout->dopt;
9028  DefaultACLInfo *daclinfo;
9029  PQExpBuffer query;
9030  PGresult *res;
9031  int i_oid;
9032  int i_tableoid;
9033  int i_defaclrole;
9034  int i_defaclnamespace;
9035  int i_defaclobjtype;
9036  int i_defaclacl;
9037  int i_rdefaclacl;
9038  int i_initdefaclacl;
9039  int i_initrdefaclacl;
9040  int i,
9041  ntups;
9042 
9043  if (fout->remoteVersion < 90000)
9044  {
9045  *numDefaultACLs = 0;
9046  return NULL;
9047  }
9048 
9049  query = createPQExpBuffer();
9050 
9051  /* Make sure we are in proper schema */
9052  selectSourceSchema(fout, "pg_catalog");
9053 
9054  if (fout->remoteVersion >= 90600)
9055  {
9056  PQExpBuffer acl_subquery = createPQExpBuffer();
9057  PQExpBuffer racl_subquery = createPQExpBuffer();
9058  PQExpBuffer initacl_subquery = createPQExpBuffer();
9059  PQExpBuffer initracl_subquery = createPQExpBuffer();
9060 
9061  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9062  initracl_subquery, "defaclacl", "defaclrole",
9063  "CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
9064  dopt->binary_upgrade);
9065 
9066  appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
9067  "(%s d.defaclrole) AS defaclrole, "
9068  "d.defaclnamespace, "
9069  "d.defaclobjtype, "
9070  "%s AS defaclacl, "
9071  "%s AS rdefaclacl, "
9072  "%s AS initdefaclacl, "
9073  "%s AS initrdefaclacl "
9074  "FROM pg_default_acl d "
9075  "LEFT JOIN pg_init_privs pip ON "
9076  "(d.oid = pip.objoid "
9077  "AND pip.classoid = 'pg_default_acl'::regclass "
9078  "AND pip.objsubid = 0) ",
9080  acl_subquery->data,
9081  racl_subquery->data,
9082  initacl_subquery->data,
9083  initracl_subquery->data);
9084  }
9085  else
9086  {
9087  appendPQExpBuffer(query, "SELECT oid, tableoid, "
9088  "(%s defaclrole) AS defaclrole, "
9089  "defaclnamespace, "
9090  "defaclobjtype, "
9091  "defaclacl, "
9092  "NULL AS rdefaclacl, "
9093  "NULL AS initdefaclacl, "
9094  "NULL AS initrdefaclacl "
9095  "FROM pg_default_acl",
9097  }
9098 
9099  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9100 
9101  ntups = PQntuples(res);
9102  *numDefaultACLs = ntups;
9103 
9104  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9105 
9106  i_oid = PQfnumber(res, "oid");
9107  i_tableoid = PQfnumber(res, "tableoid");
9108  i_defaclrole = PQfnumber(res, "defaclrole");
9109  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9110  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9111  i_defaclacl = PQfnumber(res, "defaclacl");
9112  i_rdefaclacl = PQfnumber(res, "rdefaclacl");
9113  i_initdefaclacl = PQfnumber(res, "initdefaclacl");
9114  i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
9115 
9116  for (i = 0; i < ntups; i++)
9117  {
9118  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9119 
9120  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9121  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9122  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9123  AssignDumpId(&daclinfo[i].dobj);
9124  /* cheesy ... is it worth coming up with a better object name? */
9125  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9126 
9127  if (nspid != InvalidOid)
9128  daclinfo[i].dobj.namespace = findNamespace(fout, nspid);
9129  else
9130  daclinfo[i].dobj.namespace = NULL;
9131 
9132  daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
9133  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9134  daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9135  daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
9136  daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
9137  daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
9138 
9139  /* Decide whether we want to dump it */
9140  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9141  }
9142 
9143  PQclear(res);
9144 
9145  destroyPQExpBuffer(query);
9146 
9147  return daclinfo;
9148 }
char * name
Definition: pg_dump.h:133
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:4338
char * rdefaclacl
Definition: pg_dump.h:544
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:1517
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:181
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:698
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:540
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
static const char * username_subquery
Definition: pg_dump.c:97
char * defaclacl
Definition: pg_dump.h:543
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:545
CatalogId catId
Definition: pg_dump.h:131
char * initrdefaclacl
Definition: pg_dump.h:546
int i
char defaclobjtype
Definition: pg_dump.h:542
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
char * defaclrole
Definition: pg_dump.h:541

◆ getDumpableObjects()

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

Definition at line 690 of file common.c.

References allocedDumpIds, i, and pg_malloc().

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

691 {
692  int i,
693  j;
694 
695  *objs = (DumpableObject **)
697  j = 0;
698  for (i = 1; i < allocedDumpIds; i++)
699  {
700  if (dumpIdMap[i])
701  (*objs)[j++] = dumpIdMap[i];
702  }
703  *numObjs = j;
704 }
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 7384 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(), selectSourceSchema(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

7385 {
7386  int i;
7387  PQExpBuffer query;
7388  PGresult *res;
7389  EventTriggerInfo *evtinfo;
7390  int i_tableoid,
7391  i_oid,
7392  i_evtname,
7393  i_evtevent,
7394  i_evtowner,
7395  i_evttags,
7396  i_evtfname,
7397  i_evtenabled;
7398  int ntups;
7399 
7400  /* Before 9.3, there are no event triggers */
7401  if (fout->remoteVersion < 90300)
7402  {
7403  *numEventTriggers = 0;
7404  return NULL;
7405  }
7406 
7407  query = createPQExpBuffer();
7408 
7409  /* Make sure we are in proper schema */
7410  selectSourceSchema(fout, "pg_catalog");
7411 
7412  appendPQExpBuffer(query,
7413  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
7414  "evtevent, (%s evtowner) AS evtowner, "
7415  "array_to_string(array("
7416  "select quote_literal(x) "
7417  " from unnest(evttags) as t(x)), ', ') as evttags, "
7418  "e.evtfoid::regproc as evtfname "
7419  "FROM pg_event_trigger e "
7420  "ORDER BY e.oid",
7422 
7423  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7424 
7425  ntups = PQntuples(res);
7426 
7427  *numEventTriggers = ntups;
7428 
7429  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
7430 
7431  i_tableoid = PQfnumber(res, "tableoid");
7432  i_oid = PQfnumber(res, "oid");
7433  i_evtname = PQfnumber(res, "evtname");
7434  i_evtevent = PQfnumber(res, "evtevent");
7435  i_evtowner = PQfnumber(res, "evtowner");
7436  i_evttags = PQfnumber(res, "evttags");
7437  i_evtfname = PQfnumber(res, "evtfname");
7438  i_evtenabled = PQfnumber(res, "evtenabled");
7439 
7440  for (i = 0; i < ntups; i++)
7441  {
7442  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
7443  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7444  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7445  AssignDumpId(&evtinfo[i].dobj);
7446  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
7447  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
7448  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
7449  evtinfo[i].evtowner = pg_strdup(PQgetvalue(res, i, i_evtowner));
7450  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
7451  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
7452  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
7453 
7454  /* Decide whether we want to dump it */
7455  selectDumpableObject(&(evtinfo[i].dobj), fout);
7456 
7457  /* Event Triggers do not currently have ACLs. */
7458  evtinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7459  }
7460 
7461  PQclear(res);
7462 
7463  destroyPQExpBuffer(query);
7464 
7465  return evtinfo;
7466 }
char * name
Definition: pg_dump.h:133
char * evtevent
Definition: pg_dump.h:409
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1663
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:410
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
static const char * username_subquery
Definition: pg_dump.c:97
char * evtfname
Definition: pg_dump.h:412
char * evttags
Definition: pg_dump.h:411
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
char * evtname
Definition: pg_dump.h:408
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:407
char evtenabled
Definition: pg_dump.h:413
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186

◆ getExtendedStatistics()

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

Definition at line 6785 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_STATSEXT, _tableInfo::dobj, _statsExtInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), g_verbose, i, _dumpableObject::name, numTables, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relkind, RELKIND_FOREIGN_TABLE, RELKIND_MATVIEW, RELKIND_PARTITIONED_TABLE, RELKIND_RELATION, Archive::remoteVersion, resetPQExpBuffer(), selectSourceSchema(), _statsExtInfo::statsextdef, _statsExtInfo::statsexttable, CatalogId::tableoid, and write_msg().

Referenced by getSchemaData().

6786 {
6787  int i,
6788  j;
6789  PQExpBuffer query;
6790  PGresult *res;
6791  StatsExtInfo *statsextinfo;
6792  int ntups;
6793  int i_tableoid;
6794  int i_oid;
6795  int i_stxname;
6796  int i_stxdef;
6797 
6798  /* Extended statistics were new in v10 */
6799  if (fout->remoteVersion < 100000)
6800  return;
6801 
6802  query = createPQExpBuffer();
6803 
6804  for (i = 0; i < numTables; i++)
6805  {
6806  TableInfo *tbinfo = &tblinfo[i];
6807 
6808  /*
6809  * Only plain tables, materialized views, foreign tables and
6810  * partitioned tables can have extended statistics.
6811  */
6812  if (tbinfo->relkind != RELKIND_RELATION &&
6813  tbinfo->relkind != RELKIND_MATVIEW &&
6814  tbinfo->relkind != RELKIND_FOREIGN_TABLE &&
6816  continue;
6817 
6818  /*
6819  * Ignore extended statistics of tables whose definitions are not to
6820  * be dumped.
6821  */
6822  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6823  continue;
6824 
6825  if (g_verbose)
6826  write_msg(NULL, "reading extended statistics for table \"%s.%s\"\n",
6827  tbinfo->dobj.namespace->dobj.name,
6828  tbinfo->dobj.name);
6829 
6830  /* Make sure we are in proper schema so stadef is right */
6831  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6832 
6833  resetPQExpBuffer(query);
6834 
6835  appendPQExpBuffer(query,
6836  "SELECT "
6837  "tableoid, "
6838  "oid, "
6839  "stxname, "
6840  "pg_catalog.pg_get_statisticsobjdef(oid) AS stxdef "
6841  "FROM pg_catalog.pg_statistic_ext "
6842  "WHERE stxrelid = '%u' "
6843  "ORDER BY stxname", tbinfo->dobj.catId.oid);
6844 
6845  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6846 
6847  ntups = PQntuples(res);
6848 
6849  i_tableoid = PQfnumber(res, "tableoid");
6850  i_oid = PQfnumber(res, "oid");
6851  i_stxname = PQfnumber(res, "stxname");
6852  i_stxdef = PQfnumber(res, "stxdef");
6853 
6854  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
6855 
6856  for (j = 0; j < ntups; j++)
6857  {
6858  statsextinfo[j].dobj.objType = DO_STATSEXT;
6859  statsextinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
6860  statsextinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
6861  AssignDumpId(&statsextinfo[j].dobj);
6862  statsextinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_stxname));
6863  statsextinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6864  statsextinfo[j].statsexttable = tbinfo;
6865  statsextinfo[j].statsextdef = pg_strdup(PQgetvalue(res, j, i_stxdef));
6866  }
6867 
6868  PQclear(res);
6869  }
6870 
6871  destroyPQExpBuffer(query);
6872 }
char * name
Definition: pg_dump.h:133
char relkind
Definition: pg_dump.h:267
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
char * statsextdef
Definition: pg_dump.h:373
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:371
#define RELKIND_MATVIEW
Definition: pg_class.h:165
static int numTables
Definition: common.c:57
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
DumpableObject dobj
Definition: pg_dump.h:261
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 RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
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_DEFINITION
Definition: pg_dump.h:92
void write_msg(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:131
TableInfo * statsexttable
Definition: pg_dump.h:372
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
#define RELKIND_RELATION
Definition: pg_class.h:160
DumpableObjectType objType
Definition: pg_dump.h:130
bool g_verbose
Definition: pg_dump.c:92
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186

◆ getExtensionMembership()

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

Definition at line 17339 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(), selectSourceSchema(), setExtensionMembership(), and CatalogId::tableoid.

Referenced by getSchemaData().

17341 {
17342  PQExpBuffer query;
17343  PGresult *res;
17344  int ntups,
17345  nextmembers,
17346  i;
17347  int i_classid,
17348  i_objid,
17349  i_refobjid;
17351  ExtensionInfo *ext;
17352 
17353  /* Nothing to do if no extensions */
17354  if (numExtensions == 0)
17355  return;
17356 
17357  /* Make sure we are in proper schema */
17358  selectSourceSchema(fout, "pg_catalog");
17359 
17360  query = createPQExpBuffer();
17361 
17362  /* refclassid constraint is redundant but may speed the search */
17363  appendPQExpBufferStr(query, "SELECT "
17364  "classid, objid, refobjid "
17365  "FROM pg_depend "
17366  "WHERE refclassid = 'pg_extension'::regclass "
17367  "AND deptype = 'e' "
17368  "ORDER BY 3");
17369 
17370  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
17371 
17372  ntups = PQntuples(res);
17373 
17374  i_classid = PQfnumber(res, "classid");
17375  i_objid = PQfnumber(res, "objid");
17376  i_refobjid = PQfnumber(res, "refobjid");
17377 
17378  extmembers = (ExtensionMemberId *) pg_malloc(ntups * sizeof(ExtensionMemberId));
17379  nextmembers = 0;
17380 
17381  /*
17382  * Accumulate data into extmembers[].
17383  *
17384  * Since we ordered the SELECT by referenced ID, we can expect that
17385  * multiple entries for the same extension will appear together; this
17386  * saves on searches.
17387  */
17388  ext = NULL;
17389 
17390  for (i = 0; i < ntups; i++)
17391  {
17392  CatalogId objId;
17393  Oid extId;
17394 
17395  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
17396  objId.oid = atooid(PQgetvalue(res, i, i_objid));
17397  extId = atooid(PQgetvalue(res, i, i_refobjid));
17398 
17399  if (ext == NULL ||
17400  ext->dobj.catId.oid != extId)
17401  ext = findExtensionByOid(extId);
17402 
17403  if (ext == NULL)
17404  {
17405  /* shouldn't happen */
17406  fprintf(stderr, "could not find referenced extension %u\n", extId);
17407  continue;
17408  }
17409 
17410  extmembers[nextmembers].catId = objId;
17411  extmembers[nextmembers].ext = ext;
17412  nextmembers++;
17413  }
17414 
17415  PQclear(res);
17416 
17417  /* Remember the data for use later */
17418  setExtensionMembership(extmembers, nextmembers);
17419 
17420  destroyPQExpBuffer(query);
17421 }
ExtensionInfo * ext
Definition: pg_dump.h:621
DumpableObject dobj
Definition: pg_dump.h:155
Oid tableoid
Definition: pg_backup.h:226
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:836
static int numExtensions
Definition: common.c:63
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
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:825
void PQclear(PGresult *res)
Definition: fe-exec.c:671
CatalogId catId
Definition: pg_dump.h:131
CatalogId catId
Definition: pg_dump.h:620
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407

◆ getExtensions()

ExtensionInfo* getExtensions ( Archive fout,
int *  numExtensions 
)

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

Referenced by getSchemaData().

4357 {
4358  DumpOptions *dopt = fout->dopt;
4359  PGresult *res;
4360  int ntups;
4361  int i;
4362  PQExpBuffer query;
4363  ExtensionInfo *extinfo;
4364  int i_tableoid;
4365  int i_oid;
4366  int i_extname;
4367  int i_nspname;
4368  int i_extrelocatable;
4369  int i_extversion;
4370  int i_extconfig;
4371  int i_extcondition;
4372 
4373  /*
4374  * Before 9.1, there are no extensions.
4375  */
4376  if (fout->remoteVersion < 90100)
4377  {
4378  *numExtensions = 0;
4379  return NULL;
4380  }
4381 
4382  query = createPQExpBuffer();
4383 
4384  /* Make sure we are in proper schema */
4385  selectSourceSchema(fout, "pg_catalog");
4386 
4387  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
4388  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
4389  "FROM pg_extension x "
4390  "JOIN pg_namespace n ON n.oid = x.extnamespace");
4391 
4392  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4393 
4394  ntups = PQntuples(res);
4395 
4396  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
4397 
4398  i_tableoid = PQfnumber(res, "tableoid");
4399  i_oid = PQfnumber(res, "oid");
4400  i_extname = PQfnumber(res, "extname");
4401  i_nspname = PQfnumber(res, "nspname");
4402  i_extrelocatable = PQfnumber(res, "extrelocatable");
4403  i_extversion = PQfnumber(res, "extversion");
4404  i_extconfig = PQfnumber(res, "extconfig");
4405  i_extcondition = PQfnumber(res, "extcondition");
4406 
4407  for (i = 0; i < ntups; i++)
4408  {
4409  extinfo[i].dobj.objType = DO_EXTENSION;
4410  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4411  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4412  AssignDumpId(&extinfo[i].dobj);
4413  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
4414  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
4415  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
4416  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
4417  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
4418  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
4419 
4420  /* Decide whether we want to dump it */
4421  selectDumpableExtension(&(extinfo[i]), dopt);
4422  }
4423 
4424  PQclear(res);
4425  destroyPQExpBuffer(query);
4426 
4427  *numExtensions = ntups;
4428 
4429  return extinfo;
4430 }
char * name
Definition: pg_dump.h:133
DumpableObject dobj
Definition: pg_dump.h:155
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:181
char * extconfig
Definition: pg_dump.h:159
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 selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:1624
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:160
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
bool relocatable
Definition: pg_dump.h:156
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
char * extversion
Definition: pg_dump.h:158

◆ getForeignDataWrappers()

FdwInfo* getForeignDataWrappers ( Archive fout,
int *  numForeignDataWrappers 
)

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

Referenced by getSchemaData().

8704 {
8705  DumpOptions *dopt = fout->dopt;
8706  PGresult *res;
8707  int ntups;
8708  int i;
8709  PQExpBuffer query;
8710  FdwInfo *fdwinfo;
8711  int i_tableoid;
8712  int i_oid;
8713  int i_fdwname;
8714  int i_rolname;
8715  int i_fdwhandler;
8716  int i_fdwvalidator;
8717  int i_fdwacl;
8718  int i_rfdwacl;
8719  int i_initfdwacl;
8720  int i_initrfdwacl;
8721  int i_fdwoptions;
8722 
8723  /* Before 8.4, there are no foreign-data wrappers */
8724  if (fout->remoteVersion < 80400)
8725  {
8726  *numForeignDataWrappers = 0;
8727  return NULL;
8728  }
8729 
8730  query = createPQExpBuffer();
8731 
8732  /* Make sure we are in proper schema */
8733  selectSourceSchema(fout, "pg_catalog");
8734 
8735  if (fout->remoteVersion >= 90600)
8736  {
8737  PQExpBuffer acl_subquery = createPQExpBuffer();
8738  PQExpBuffer racl_subquery = createPQExpBuffer();
8739  PQExpBuffer initacl_subquery = createPQExpBuffer();
8740  PQExpBuffer initracl_subquery = createPQExpBuffer();
8741 
8742  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8743  initracl_subquery, "f.fdwacl", "f.fdwowner", "'F'",
8744  dopt->binary_upgrade);
8745 
8746  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.fdwname, "
8747  "(%s f.fdwowner) AS rolname, "
8748  "f.fdwhandler::pg_catalog.regproc, "
8749  "f.fdwvalidator::pg_catalog.regproc, "
8750  "%s AS fdwacl, "
8751  "%s AS rfdwacl, "
8752  "%s AS initfdwacl, "
8753  "%s AS initrfdwacl, "
8754  "array_to_string(ARRAY("
8755  "SELECT quote_ident(option_name) || ' ' || "
8756  "quote_literal(option_value) "
8757  "FROM pg_options_to_table(f.fdwoptions) "
8758  "ORDER BY option_name"
8759  "), E',\n ') AS fdwoptions "
8760  "FROM pg_foreign_data_wrapper f "
8761  "LEFT JOIN pg_init_privs pip ON "
8762  "(f.oid = pip.objoid "
8763  "AND pip.classoid = 'pg_foreign_data_wrapper'::regclass "
8764  "AND pip.objsubid = 0) ",
8766  acl_subquery->data,
8767  racl_subquery->data,
8768  initacl_subquery->data,
8769  initracl_subquery->data);
8770 
8771  destroyPQExpBuffer(acl_subquery);
8772  destroyPQExpBuffer(racl_subquery);
8773  destroyPQExpBuffer(initacl_subquery);
8774  destroyPQExpBuffer(initracl_subquery);
8775  }
8776  else if (fout->remoteVersion >= 90100)
8777  {
8778  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8779  "(%s fdwowner) AS rolname, "
8780  "fdwhandler::pg_catalog.regproc, "
8781  "fdwvalidator::pg_catalog.regproc, fdwacl, "
8782  "NULL as rfdwacl, "
8783  "NULL as initfdwacl, NULL AS initrfdwacl, "
8784  "array_to_string(ARRAY("
8785  "SELECT quote_ident(option_name) || ' ' || "
8786  "quote_literal(option_value) "
8787  "FROM pg_options_to_table(fdwoptions) "
8788  "ORDER BY option_name"
8789  "), E',\n ') AS fdwoptions "
8790  "FROM pg_foreign_data_wrapper",
8792  }
8793  else
8794  {
8795  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8796  "(%s fdwowner) AS rolname, "
8797  "'-' AS fdwhandler, "
8798  "fdwvalidator::pg_catalog.regproc, fdwacl, "
8799  "NULL as rfdwacl, "
8800  "NULL as initfdwacl, NULL AS initrfdwacl, "
8801  "array_to_string(ARRAY("
8802  "SELECT quote_ident(option_name) || ' ' || "
8803  "quote_literal(option_value) "
8804  "FROM pg_options_to_table(fdwoptions) "
8805  "ORDER BY option_name"
8806  "), E',\n ') AS fdwoptions "
8807  "FROM pg_foreign_data_wrapper",
8809  }
8810 
8811  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8812 
8813  ntups = PQntuples(res);
8814  *numForeignDataWrappers = ntups;
8815 
8816  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
8817 
8818  i_tableoid = PQfnumber(res, "tableoid");
8819  i_oid = PQfnumber(res, "oid");
8820  i_fdwname = PQfnumber(res, "fdwname");
8821  i_rolname = PQfnumber(res, "rolname");
8822  i_fdwhandler = PQfnumber(res, "fdwhandler");
8823  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
8824  i_fdwacl = PQfnumber(res, "fdwacl");
8825  i_rfdwacl = PQfnumber(res, "rfdwacl");
8826  i_initfdwacl = PQfnumber(res, "initfdwacl");
8827  i_initrfdwacl = PQfnumber(res, "initrfdwacl");
8828  i_fdwoptions = PQfnumber(res, "fdwoptions");
8829 
8830  for (i = 0; i < ntups; i++)
8831  {
8832  fdwinfo[i].dobj.objType = DO_FDW;
8833  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8834  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8835  AssignDumpId(&fdwinfo[i].dobj);
8836  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
8837  fdwinfo[i].dobj.namespace = NULL;
8838  fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
8839  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
8840  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
8841  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
8842  fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
8843  fdwinfo[i].rfdwacl = pg_strdup(PQgetvalue(res, i, i_rfdwacl));
8844  fdwinfo[i].initfdwacl = pg_strdup(PQgetvalue(res, i, i_initfdwacl));
8845  fdwinfo[i].initrfdwacl = pg_strdup(PQgetvalue(res, i, i_initrfdwacl));
8846 
8847  /* Decide whether we want to dump it */
8848  selectDumpableObject(&(fdwinfo[i].dobj), fout);
8849 
8850  /* Do not try to dump ACL if no ACL exists. */
8851  if (PQgetisnull(res, i, i_fdwacl) && PQgetisnull(res, i, i_rfdwacl) &&
8852  PQgetisnull(res, i, i_initfdwacl) &&
8853  PQgetisnull(res, i, i_initrfdwacl))
8854  fdwinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8855  }
8856 
8857  PQclear(res);
8858 
8859  destroyPQExpBuffer(query);
8860 
8861  return fdwinfo;
8862 }
char * name
Definition: pg_dump.h:133
char * rfdwacl
Definition: pg_dump.h:519
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1663
Oid tableoid
Definition: pg_backup.h:226
char * fdwhandler
Definition: pg_dump.h:515
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:517
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:513
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:181
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:698
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * fdwvalidator
Definition: pg_dump.h:516
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:518
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
static const char * username_subquery
Definition: pg_dump.c:97
char * rolname
Definition: pg_dump.h:514
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:520
Definition: pg_dump.h:73
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
char * initrfdwacl
Definition: pg_dump.h:521
CatalogId catId
Definition: pg_dump.h:131
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186

◆ getForeignServers()

ForeignServerInfo* getForeignServers ( Archive fout,
int *  numForeignServers 
)

Definition at line 8872 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(), selectSourceSchema(), _foreignServerInfo::srvacl, _foreignServerInfo::srvfdw, _foreignServerInfo::srvoptions, _foreignServerInfo::srvtype, _foreignServerInfo::srvversion, CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

8873 {
8874  DumpOptions *dopt = fout->dopt;
8875  PGresult *res;
8876  int ntups;
8877  int i;
8878  PQExpBuffer query;
8879  ForeignServerInfo *srvinfo;
8880  int i_tableoid;
8881  int i_oid;
8882  int i_srvname;
8883  int i_rolname;
8884  int i_srvfdw;
8885  int i_srvtype;
8886  int i_srvversion;
8887  int i_srvacl;
8888  int i_rsrvacl;
8889  int i_initsrvacl;
8890  int i_initrsrvacl;
8891  int i_srvoptions;
8892 
8893  /* Before 8.4, there are no foreign servers */
8894  if (fout->remoteVersion < 80400)
8895  {
8896  *numForeignServers = 0;
8897  return NULL;
8898  }
8899 
8900  query = createPQExpBuffer();
8901 
8902  /* Make sure we are in proper schema */
8903  selectSourceSchema(fout, "pg_catalog");
8904 
8905  if (fout->remoteVersion >= 90600)
8906  {
8907  PQExpBuffer acl_subquery = createPQExpBuffer();
8908  PQExpBuffer racl_subquery = createPQExpBuffer();
8909  PQExpBuffer initacl_subquery = createPQExpBuffer();
8910  PQExpBuffer initracl_subquery = createPQExpBuffer();
8911 
8912  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8913  initracl_subquery, "f.srvacl", "f.srvowner", "'S'",
8914  dopt->binary_upgrade);
8915 
8916  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.srvname, "
8917  "(%s f.srvowner) AS rolname, "
8918  "f.srvfdw, f.srvtype, f.srvversion, "
8919  "%s AS srvacl, "
8920  "%s AS rsrvacl, "
8921  "%s AS initsrvacl, "
8922  "%s AS initrsrvacl, "
8923  "array_to_string(ARRAY("
8924  "SELECT quote_ident(option_name) || ' ' || "
8925  "quote_literal(option_value) "
8926  "FROM pg_options_to_table(f.srvoptions) "
8927  "ORDER BY option_name"
8928  "), E',\n ') AS srvoptions "
8929  "FROM pg_foreign_server f "
8930  "LEFT JOIN pg_init_privs pip "
8931  "ON (f.oid = pip.objoid "
8932  "AND pip.classoid = 'pg_foreign_server'::regclass "
8933  "AND pip.objsubid = 0) ",
8935  acl_subquery->data,
8936  racl_subquery->data,
8937  initacl_subquery->data,
8938  initracl_subquery->data);
8939 
8940  destroyPQExpBuffer(acl_subquery);
8941  destroyPQExpBuffer(racl_subquery);
8942  destroyPQExpBuffer(initacl_subquery);
8943  destroyPQExpBuffer(initracl_subquery);
8944  }
8945  else
8946  {
8947  appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
8948  "(%s srvowner) AS rolname, "
8949  "srvfdw, srvtype, srvversion, srvacl, "
8950  "NULL AS rsrvacl, "
8951  "NULL AS initsrvacl, NULL AS initrsrvacl, "
8952  "array_to_string(ARRAY("
8953  "SELECT quote_ident(option_name) || ' ' || "
8954  "quote_literal(option_value) "
8955  "FROM pg_options_to_table(srvoptions) "
8956  "ORDER BY option_name"
8957  "), E',\n ') AS srvoptions "
8958  "FROM pg_foreign_server",
8960  }
8961 
8962  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8963 
8964  ntups = PQntuples(res);
8965  *numForeignServers = ntups;
8966 
8967  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
8968 
8969  i_tableoid = PQfnumber(res, "tableoid");
8970  i_oid = PQfnumber(res, "oid");
8971  i_srvname = PQfnumber(res, "srvname");
8972  i_rolname = PQfnumber(res, "rolname");
8973  i_srvfdw = PQfnumber(res, "srvfdw");
8974  i_srvtype = PQfnumber(res, "srvtype");
8975  i_srvversion = PQfnumber(res, "srvversion");
8976  i_srvacl = PQfnumber(res, "srvacl");
8977  i_rsrvacl = PQfnumber(res, "rsrvacl");
8978  i_initsrvacl = PQfnumber(res, "initsrvacl");
8979  i_initrsrvacl = PQfnumber(res, "initrsrvacl");
8980  i_srvoptions = PQfnumber(res, "srvoptions");
8981 
8982  for (i = 0; i < ntups; i++)
8983  {
8984  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
8985  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8986  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8987  AssignDumpId(&srvinfo[i].dobj);
8988  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
8989  srvinfo[i].dobj.namespace = NULL;
8990  srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
8991  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
8992  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
8993  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
8994  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
8995  srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl));
8996  srvinfo[i].rsrvacl = pg_strdup(PQgetvalue(res, i, i_rsrvacl));
8997  srvinfo[i].initsrvacl = pg_strdup(PQgetvalue(res, i, i_initsrvacl));
8998  srvinfo[i].initrsrvacl = pg_strdup(PQgetvalue(res, i, i_initrsrvacl));
8999 
9000  /* Decide whether we want to dump it */
9001  selectDumpableObject(&(srvinfo[i].dobj), fout);
9002 
9003  /* Do not try to dump ACL if no ACL exists. */
9004  if (PQgetisnull(res, i, i_srvacl) && PQgetisnull(res, i, i_rsrvacl) &&
9005  PQgetisnull(res, i, i_initsrvacl) &&
9006  PQgetisnull(res, i, i_initrsrvacl))
9007  srvinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
9008  }
9009 
9010  PQclear(res);
9011 
9012  destroyPQExpBuffer(query);
9013 
9014  return srvinfo;
9015 }
char * srvoptions
Definition: pg_dump.h:535
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1663
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:534
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:181
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:698
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 void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
static const char * username_subquery
Definition: pg_dump.c:97
char * srvversion
Definition: pg_dump.h:530
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:96
CatalogId catId
Definition: pg_dump.h:131
DumpableObject dobj
Definition: pg_dump.h:526
int i
char * initsrvacl
Definition: pg_dump.h:533
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186

◆ getFuncs()

FuncInfo* getFuncs ( Archive fout,
int *  numFuncs 
)

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

Referenced by getSchemaData().

5376 {
5377  DumpOptions *dopt = fout->dopt;
5378  PGresult *res;
5379  int ntups;
5380  int i;
5381  PQExpBuffer query = createPQExpBuffer();
5382  FuncInfo *finfo;
5383  int i_tableoid;
5384  int i_oid;
5385  int i_proname;
5386  int i_pronamespace;
5387  int i_rolname;
5388  int i_prolang;
5389  int i_pronargs;
5390  int i_proargtypes;
5391  int i_prorettype;
5392  int i_proacl;
5393  int i_rproacl;
5394  int i_initproacl;
5395  int i_initrproacl;
5396 
5397  /* Make sure we are in proper schema */
5398  selectSourceSchema(fout, "pg_catalog");
5399 
5400  /*
5401  * Find all interesting functions. This is a bit complicated:
5402  *
5403  * 1. Always exclude aggregates; those are handled elsewhere.
5404  *
5405  * 2. Always exclude functions that are internally dependent on something
5406  * else, since presumably those will be created as a result of creating
5407  * the something else. This currently acts only to suppress constructor
5408  * functions for range types (so we only need it in 9.2 and up). Note
5409  * this is OK only because the constructors don't have any dependencies
5410  * the range type doesn't have; otherwise we might not get creation
5411  * ordering correct.
5412  *
5413  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
5414  * they're members of extensions and we are in binary-upgrade mode then
5415  * include them, since we want to dump extension members individually in
5416  * that mode. Also, if they are used by casts or transforms then we need
5417  * to gather the information about them, though they won't be dumped if
5418  * they are built-in. Also, in 9.6 and up, include functions in
5419  * pg_catalog if they have an ACL different from what's shown in
5420  * pg_init_privs.
5421  */
5422  if (fout->remoteVersion >= 90600)
5423  {
5424  PQExpBuffer acl_subquery = createPQExpBuffer();
5425  PQExpBuffer racl_subquery = createPQExpBuffer();
5426  PQExpBuffer initacl_subquery = createPQExpBuffer();
5427  PQExpBuffer initracl_subquery = createPQExpBuffer();
5428 
5429  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5430  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5431  dopt->binary_upgrade);
5432 
5433  appendPQExpBuffer(query,
5434  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
5435  "p.pronargs, p.proargtypes, p.prorettype, "
5436  "%s AS proacl, "
5437  "%s AS rproacl, "
5438  "%s AS initproacl, "
5439  "%s AS initrproacl, "
5440  "p.pronamespace, "
5441  "(%s p.proowner) AS rolname "
5442  "FROM pg_proc p "
5443  "LEFT JOIN pg_init_privs pip ON "
5444  "(p.oid = pip.objoid "
5445  "AND pip.classoid = 'pg_proc'::regclass "
5446  "AND pip.objsubid = 0) "
5447  "WHERE NOT proisagg"
5448  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5449  "WHERE classid = 'pg_proc'::regclass AND "
5450  "objid = p.oid AND deptype = 'i')"
5451  "\n AND ("
5452  "\n pronamespace != "
5453  "(SELECT oid FROM pg_namespace "
5454  "WHERE nspname = 'pg_catalog')"
5455  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5456  "\n WHERE pg_cast.oid > %u "
5457  "\n AND p.oid = pg_cast.castfunc)"
5458  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5459  "\n WHERE pg_transform.oid > %u AND "
5460  "\n (p.oid = pg_transform.trffromsql"
5461  "\n OR p.oid = pg_transform.trftosql))",
5462  acl_subquery->data,
5463  racl_subquery->data,
5464  initacl_subquery->data,
5465  initracl_subquery->data,
5469  if (dopt->binary_upgrade)
5470  appendPQExpBufferStr(query,
5471  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5472  "classid = 'pg_proc'::regclass AND "
5473  "objid = p.oid AND "
5474  "refclassid = 'pg_extension'::regclass AND "
5475  "deptype = 'e')");
5476  appendPQExpBufferStr(query,
5477  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
5478  appendPQExpBufferChar(query, ')');
5479 
5480  destroyPQExpBuffer(acl_subquery);
5481  destroyPQExpBuffer(racl_subquery);
5482  destroyPQExpBuffer(initacl_subquery);
5483  destroyPQExpBuffer(initracl_subquery);
5484  }
5485  else
5486  {
5487  appendPQExpBuffer(query,
5488  "SELECT tableoid, oid, proname, prolang, "
5489  "pronargs, proargtypes, prorettype, proacl, "
5490  "NULL as rproacl, "
5491  "NULL as initproacl, NULL AS initrproacl, "
5492  "pronamespace, "
5493  "(%s proowner) AS rolname "
5494  "FROM pg_proc p "
5495  "WHERE NOT proisagg",
5497  if (fout->remoteVersion >= 90200)
5498  appendPQExpBufferStr(query,
5499  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5500  "WHERE classid = 'pg_proc'::regclass AND "
5501  "objid = p.oid AND deptype = 'i')");
5502  appendPQExpBuffer(query,
5503  "\n AND ("
5504  "\n pronamespace != "
5505  "(SELECT oid FROM pg_namespace "
5506  "WHERE nspname = 'pg_catalog')"
5507  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5508  "\n WHERE pg_cast.oid > '%u'::oid"
5509  "\n AND p.oid = pg_cast.castfunc)",
5511 
5512  if (fout->remoteVersion >= 90500)
5513  appendPQExpBuffer(query,
5514  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5515  "\n WHERE pg_transform.oid > '%u'::oid"
5516  "\n AND (p.oid = pg_transform.trffromsql"
5517  "\n OR p.oid = pg_transform.trftosql))",
5519 
5520  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5521  appendPQExpBufferStr(query,
5522  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5523  "classid = 'pg_proc'::regclass AND "
5524  "objid = p.oid AND "
5525  "refclassid = 'pg_extension'::regclass AND "
5526  "deptype = 'e')");
5527  appendPQExpBufferChar(query, ')');
5528  }
5529 
5530  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5531 
5532  ntups = PQntuples(res);
5533 
5534  *numFuncs = ntups;
5535 
5536  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
5537 
5538  i_tableoid = PQfnumber(res, "tableoid");
5539  i_oid = PQfnumber(res, "oid");
5540  i_proname = PQfnumber(res, "proname");
5541  i_pronamespace = PQfnumber(res, "pronamespace");
5542  i_rolname = PQfnumber(res, "rolname");
5543  i_prolang = PQfnumber(res, "prolang");
5544  i_pronargs = PQfnumber(res, "pronargs");
5545  i_proargtypes = PQfnumber(res, "proargtypes");
5546  i_prorettype = PQfnumber(res, "prorettype");
5547  i_proacl = PQfnumber(res, "proacl");
5548  i_rproacl = PQfnumber(res, "rproacl");
5549  i_initproacl = PQfnumber(res, "initproacl");
5550  i_initrproacl = PQfnumber(res, "initrproacl");
5551 
5552  for (i = 0; i < ntups; i++)
5553  {
5554  finfo[i].dobj.objType = DO_FUNC;
5555  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5556  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5557  AssignDumpId(&finfo[i].dobj);
5558  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
5559  finfo[i].dobj.namespace =
5560  findNamespace(fout,
5561  atooid(PQgetvalue(res, i, i_pronamespace)));
5562  finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5563  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
5564  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
5565  finfo[i].proacl = pg_strdup(PQgetvalue(res, i, i_proacl));
5566  finfo[i].rproacl = pg_strdup(PQgetvalue(res, i, i_rproacl));
5567  finfo[i].initproacl = pg_strdup(PQgetvalue(res, i, i_initproacl));
5568  finfo[i].initrproacl = pg_strdup(PQgetvalue(res, i, i_initrproacl));
5569  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
5570  if (finfo[i].nargs == 0)
5571  finfo[i].argtypes = NULL;
5572  else
5573  {
5574  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
5575  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5576  finfo[i].argtypes, finfo[i].nargs);
5577  }
5578 
5579  /* Decide whether we want to dump it */
5580  selectDumpableObject(&(finfo[i].dobj), fout);
5581 
5582  /* Do not try to dump ACL if no ACL exists. */
5583  if (PQgetisnull(res, i, i_proacl) && PQgetisnull(res, i, i_rproacl) &&
5584  PQgetisnull(res, i, i_initproacl) &&
5585  PQgetisnull(res, i, i_initrproacl))
5586  finfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5587 
5588  if (strlen(finfo[i].rolname) == 0)
5589  write_msg(NULL,
5590  "WARNING: owner of function \"%s\" appears to be invalid\n",
5591  finfo[i].dobj.name);
5592  }
5593 
5594  PQclear(res);
5595 
5596  destroyPQExpBuffer(query);
5597 
5598  return finfo;
5599 }
Oid * argtypes
Definition: pg_dump.h:202
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1663
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:201
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4338
static int numFuncs
Definition: common.c:59
char * initrproacl
Definition: pg_dump.h:207
Oid lang
Definition: pg_dump.h:200
DumpableObject dobj
Definition: pg_dump.h:198
unsigned int Oid
Definition: postgres_ext.h:31
static Oid g_last_builtin_oid
Definition: pg_dump.c:103
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:135
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
DumpOptions * dopt
Definition: pg_backup.h:181
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:698
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 void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
static const char * username_subquery
Definition: pg_dump.c:97
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:967
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:203
char * initproacl
Definition: pg_dump.h:206
char * rolname
Definition: pg_dump.h:199
char * proacl
Definition: pg_dump.h:204
char * rproacl
Definition: pg_dump.h:205
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186

◆ getIndexes()

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

Definition at line 6501 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, _indxInfo::indextable, _indxInfo::indisclustered, _indxInfo::indisreplident, _indxInfo::indkeys, _indxInfo::indnkeys, _indxInfo::indreloptions, InvalidOid, _dumpableObject::name, numTables, _dumpableObject::objType, CatalogId::oid, parseOidArray(), pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relkind, RELKIND_MATVIEW, RELKIND_RELATION, _indxInfo::relpages, Archive::remoteVersion, resetPQExpBuffer(), selectSourceSchema(), _constraintInfo::separate, CatalogId::tableoid, _indxInfo::tablespace, and write_msg().

Referenced by getSchemaData().

6502 {
6503  int i,
6504  j;
6505  PQExpBuffer query = createPQExpBuffer();
6506  PGresult *res;
6507  IndxInfo *indxinfo;
6508  ConstraintInfo *constrinfo;
6509  int i_tableoid,
6510  i_oid,
6511  i_indexname,
6512  i_indexdef,
6513  i_indnkeys,
6514  i_indkey,
6515  i_indisclustered,
6516  i_indisreplident,
6517  i_contype,
6518  i_conname,
6519  i_condeferrable,
6520  i_condeferred,
6521  i_contableoid,
6522  i_conoid,
6523  i_condef,
6524  i_tablespace,
6525  i_indreloptions,
6526  i_relpages;
6527  int ntups;
6528 
6529  for (i = 0; i < numTables; i++)
6530  {
6531  TableInfo *tbinfo = &tblinfo[i];
6532 
6533  /* Only plain tables and materialized views have indexes. */
6534  if (tbinfo->relkind != RELKIND_RELATION &&
6535  tbinfo->relkind != RELKIND_MATVIEW)
6536  continue;
6537  if (!tbinfo->hasindex)
6538  continue;
6539 
6540  /* Ignore indexes of tables whose definitions are not to be dumped */
6541  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6542  continue;
6543 
6544  if (g_verbose)
6545  write_msg(NULL, "reading indexes for table \"%s.%s\"\n",
6546  tbinfo->dobj.namespace->dobj.name,
6547  tbinfo->dobj.name);
6548 
6549  /* Make sure we are in proper schema so indexdef is right */
6550  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6551 
6552  /*
6553  * The point of the messy-looking outer join is to find a constraint
6554  * that is related by an internal dependency link to the index. If we
6555  * find one, create a CONSTRAINT entry linked to the INDEX entry. We
6556  * assume an index won't have more than one internal dependency.
6557  *
6558  * As of 9.0 we don't need to look at pg_depend but can check for a
6559  * match to pg_constraint.conindid. The check on conrelid is
6560  * redundant but useful because that column is indexed while conindid
6561  * is not.
6562  */
6563  resetPQExpBuffer(query);
6564  if (fout->remoteVersion >= 90400)
6565  {
6566  /*
6567  * the test on indisready is necessary in 9.2, and harmless in
6568  * earlier/later versions
6569  */
6570  appendPQExpBuffer(query,
6571  "SELECT t.tableoid, t.oid, "
6572  "t.relname AS indexname, "
6573  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6574  "t.relnatts AS indnkeys, "
6575  "i.indkey, i.indisclustered, "
6576  "i.indisreplident, t.relpages, "
6577  "c.contype, c.conname, "
6578  "c.condeferrable, c.condeferred, "
6579  "c.tableoid AS contableoid, "
6580  "c.oid AS conoid, "
6581  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6582  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6583  "t.reloptions AS indreloptions "
6584  "FROM pg_catalog.pg_index i "
6585  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6586  "LEFT JOIN pg_catalog.pg_constraint c "
6587  "ON (i.indrelid = c.conrelid AND "
6588  "i.indexrelid = c.conindid AND "
6589  "c.contype IN ('p','u','x')) "
6590  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6591  "AND i.indisvalid AND i.indisready "
6592  "ORDER BY indexname",
6593  tbinfo->dobj.catId.oid);
6594  }
6595  else if (fout->remoteVersion >= 90000)
6596  {
6597  /*
6598  * the test on indisready is necessary in 9.2, and harmless in
6599  * earlier/later versions
6600  */
6601  appendPQExpBuffer(query,
6602  "SELECT t.tableoid, t.oid, "
6603  "t.relname AS indexname, "
6604  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6605  "t.relnatts AS indnkeys, "
6606  "i.indkey, i.indisclustered, "
6607  "false AS indisreplident, t.relpages, "
6608  "c.contype, c.conname, "
6609  "c.condeferrable, c.condeferred, "
6610  "c.tableoid AS contableoid, "
6611  "c.oid AS conoid, "
6612  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6613  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6614  "t.reloptions AS indreloptions "
6615  "FROM pg_catalog.pg_index i "
6616  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6617  "LEFT JOIN pg_catalog.pg_constraint c "
6618  "ON (i.indrelid = c.conrelid AND "
6619  "i.indexrelid = c.conindid AND "
6620  "c.contype IN ('p','u','x')) "
6621  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6622  "AND i.indisvalid AND i.indisready "
6623  "ORDER BY indexname",
6624  tbinfo->dobj.catId.oid);
6625  }
6626  else if (fout->remoteVersion >= 80200)
6627  {
6628  appendPQExpBuffer(query,
6629  "SELECT t.tableoid, t.oid, "
6630  "t.relname AS indexname, "
6631  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6632  "t.relnatts AS indnkeys, "
6633  "i.indkey, i.indisclustered, "
6634  "false AS indisreplident, t.relpages, "
6635  "c.contype, c.conname, "
6636  "c.condeferrable, c.condeferred, "
6637  "c.tableoid AS contableoid, "
6638  "c.oid AS conoid, "
6639  "null AS condef, "
6640  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6641  "t.reloptions AS indreloptions "
6642  "FROM pg_catalog.pg_index i "
6643  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6644  "LEFT JOIN pg_catalog.pg_depend d "
6645  "ON (d.classid = t.tableoid "
6646  "AND d.objid = t.oid "
6647  "AND d.deptype = 'i') "
6648  "LEFT JOIN pg_catalog.pg_constraint c "
6649  "ON (d.refclassid = c.tableoid "
6650  "AND d.refobjid = c.oid) "
6651  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6652  "AND i.indisvalid "
6653  "ORDER BY indexname",
6654  tbinfo->dobj.catId.oid);
6655  }
6656  else
6657  {
6658  appendPQExpBuffer(query,
6659  "SELECT t.tableoid, t.oid, "
6660  "t.relname AS indexname, "
6661  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6662  "t.relnatts AS indnkeys, "
6663  "i.indkey, i.indisclustered, "
6664  "false AS indisreplident, t.relpages, "
6665  "c.contype, c.conname, "
6666  "c.condeferrable, c.condeferred, "
6667  "c.tableoid AS contableoid, "
6668  "c.oid AS conoid, "
6669  "null AS condef, "
6670  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6671  "null AS indreloptions "
6672  "FROM pg_catalog.pg_index i "
6673  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6674  "LEFT JOIN pg_catalog.pg_depend d "
6675  "ON (d.classid = t.tableoid "
6676  "AND d.objid = t.oid "
6677  "AND d.deptype = 'i') "
6678  "LEFT JOIN pg_catalog.pg_constraint c "
6679  "ON (d.refclassid = c.tableoid "
6680  "AND d.refobjid = c.oid) "
6681  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6682  "ORDER BY indexname",
6683  tbinfo->dobj.catId.oid);
6684  }
6685 
6686  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6687 
6688  ntups = PQntuples(res);
6689 
6690  i_tableoid = PQfnumber(res, "tableoid");
6691  i_oid = PQfnumber(res, "oid");
6692  i_indexname = PQfnumber(res, "indexname");
6693  i_indexdef = PQfnumber(res, "indexdef");
6694  i_indnkeys = PQfnumber(res, "indnkeys");
6695  i_indkey = PQfnumber(res, "indkey");
6696  i_indisclustered = PQfnumber(res, "indisclustered");
6697  i_indisreplident = PQfnumber(res, "indisreplident");
6698  i_relpages = PQfnumber(res, "relpages");
6699  i_contype = PQfnumber(res, "contype");
6700  i_conname = PQfnumber(res, "conname");
6701  i_condeferrable = PQfnumber(res, "condeferrable");
6702  i_condeferred = PQfnumber(res, "condeferred");
6703  i_contableoid = PQfnumber(res, "contableoid");
6704  i_conoid = PQfnumber(res, "conoid");
6705  i_condef = PQfnumber(res, "condef");
6706  i_tablespace = PQfnumber(res, "tablespace");
6707  i_indreloptions = PQfnumber(res, "indreloptions");
6708 
6709  indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
6710  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
6711 
6712  for (j = 0; j < ntups; j++)
6713  {
6714  char contype;
6715 
6716  indxinfo[j].dobj.objType = DO_INDEX;
6717  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
6718  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
6719  AssignDumpId(&indxinfo[j].dobj);
6720  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
6721  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6722  indxinfo[j].indextable = tbinfo;
6723  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
6724  indxinfo[j].indnkeys = atoi(PQgetvalue(res, j, i_indnkeys));
6725  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
6726  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
6727  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnkeys * sizeof(Oid));
6728  parseOidArray(PQgetvalue(res, j, i_indkey),
6729  indxinfo[j].indkeys, indxinfo[j].indnkeys);
6730  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
6731  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
6732  indxinfo[j].relpages = atoi(PQgetvalue(res, j, i_relpages));
6733  contype = *(PQgetvalue(res, j, i_contype));
6734 
6735  if (contype == 'p' || contype == 'u' || contype == 'x')
6736  {
6737  /*
6738  * If we found a constraint matching the index, create an
6739  * entry for it.
6740  */
6741  constrinfo[j].dobj.objType = DO_CONSTRAINT;
6742  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
6743  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
6744  AssignDumpId(&constrinfo[j].dobj);
6745  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
6746  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6747  constrinfo[j].contable = tbinfo;
6748  constrinfo[j].condomain = NULL;
6749  constrinfo[j].contype = contype;
6750  if (contype == 'x')
6751  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
6752  else
6753  constrinfo[j].condef = NULL;
6754  constrinfo[j].confrelid = InvalidOid;
6755  constrinfo[j].conindex = indxinfo[j].dobj.dumpId;
6756  constrinfo[j].condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
6757  constrinfo[j].condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
6758  constrinfo[j].conislocal = true;
6759  constrinfo[j].separate = true;
6760 
6761  indxinfo[j].indexconstraint = constrinfo[j].dobj.dumpId;
6762  }
6763  else
6764  {
6765  /* Plain secondary index */
6766  indxinfo[j].indexconstraint = 0;
6767  }
6768  }
6769 
6770  PQclear(res);
6771  }
6772 
6773  destroyPQExpBuffer(query);
6774 }
char * tablespace
Definition: pg_dump.h:358
char * name
Definition: pg_dump.h:133
char relkind
Definition: pg_dump.h:267
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
int relpages
Definition: pg_dump.h:366
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
#define RELKIND_MATVIEW
Definition: pg_class.h:165
bool hasindex
Definition: pg_dump.h:275
DumpId dumpId
Definition: pg_dump.h:132
static int numTables
Definition: common.c:57
unsigned int Oid
Definition: postgres_ext.h:31
DumpId conindex
Definition: pg_dump.h:432
DumpId indexconstraint
Definition: pg_dump.h:365
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
char * indexdef
Definition: pg_dump.h:357
DumpableObject dobj
Definition: pg_dump.h:261
char * condef
Definition: pg_dump.h:430
bool indisreplident
Definition: pg_dump.h:363
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:426
TableInfo * indextable
Definition: pg_dump.h:356
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
Oid * indkeys
Definition: pg_dump.h:361
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
bool condeferrable
Definition: pg_dump.h:433
int indnkeys
Definition: pg_dump.h:360
char * indreloptions
Definition: pg_dump.h:359
TypeInfo * condomain
Definition: pg_dump.h:428
bool conislocal
Definition: pg_dump.h:435
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:967
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:427
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
void write_msg(const char *modulename, const char *fmt,...)
bool condeferred
Definition: pg_dump.h:434
CatalogId catId
Definition: pg_dump.h:131
DumpableObject dobj
Definition: pg_dump.h:355
int i
bool indisclustered
Definition: pg_dump.h:362
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
#define RELKIND_RELATION
Definition: pg_class.h:160
DumpableObjectType objType
Definition: pg_dump.h:130
bool g_verbose
Definition: pg_dump.c:92
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186

◆ getInherits()

InhInfo* getInherits ( Archive fout,
int *  numInherits 
)

Definition at line 6447 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(), PQntuples(), and selectSourceSchema().

Referenced by getSchemaData().

6448 {
6449  PGresult *res;
6450  int ntups;
6451  int i;
6452  PQExpBuffer query = createPQExpBuffer();
6453  InhInfo *inhinfo;
6454 
6455  int i_inhrelid;
6456  int i_inhparent;
6457 
6458  /* Make sure we are in proper schema */
6459  selectSourceSchema(fout, "pg_catalog");
6460 
6461  /*
6462  * Find all the inheritance information, excluding implicit inheritance
6463  * via partitioning. We handle that case using getPartitions(), because
6464  * we want more information about partitions than just the parent-child
6465  * relationship.
6466  */
6467  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
6468 
6469  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6470 
6471  ntups = PQntuples(res);
6472 
6473  *numInherits = ntups;
6474 
6475  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6476 
6477  i_inhrelid = PQfnumber(res, "inhrelid");
6478  i_inhparent = PQfnumber(res, "inhparent");
6479 
6480  for (i = 0; i < ntups; i++)
6481  {
6482  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6483  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6484  }
6485 
6486  PQclear(res);
6487 
6488  destroyPQExpBuffer(query);
6489 
6490  return inhinfo;
6491 }
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:475
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
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:476
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )

Definition at line 529 of file common.c.

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

530 {
531  return lastDumpId;
532 }
static DumpId lastDumpId
Definition: common.c:33

◆ getNamespaces()

NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

Definition at line 4184 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, _dumpOptions::outputClean, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _namespaceInfo::rnspacl, _namespaceInfo::rolname, selectDumpableNamespace(), selectSourceSchema(), CatalogId::tableoid, username_subquery, and write_msg().

Referenced by getSchemaData().

4185 {
4186  DumpOptions *dopt = fout->dopt;
4187  PGresult *res;
4188  int ntups;
4189  int i;
4190  PQExpBuffer query;
4191  NamespaceInfo *nsinfo;
4192  int i_tableoid;
4193  int i_oid;
4194  int i_nspname;
4195  int i_rolname;
4196  int i_nspacl;
4197  int i_rnspacl;
4198  int i_initnspacl;
4199  int i_initrnspacl;
4200 
4201  query = createPQExpBuffer();
4202 
4203  /* Make sure we are in proper schema */
4204  selectSourceSchema(fout, "pg_catalog");
4205 
4206  /*
4207  * we fetch all namespaces including system ones, so that every object we
4208  * read in can be linked to a containing namespace.
4209  */
4210  if (fout->remoteVersion >= 90600)
4211  {
4212  PQExpBuffer acl_subquery = createPQExpBuffer();
4213  PQExpBuffer racl_subquery = createPQExpBuffer();
4214  PQExpBuffer init_acl_subquery = createPQExpBuffer();
4215  PQExpBuffer init_racl_subquery = createPQExpBuffer();
4216 
4217  buildACLQueries(acl_subquery, racl_subquery, init_acl_subquery,
4218  init_racl_subquery, "n.nspacl", "n.nspowner", "'n'",
4219  dopt->binary_upgrade);
4220 
4221  appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, "
4222  "(%s nspowner) AS rolname, "
4223  "%s as nspacl, "
4224  "%s as rnspacl, "
4225  "%s as initnspacl, "
4226  "%s as initrnspacl "
4227  "FROM pg_namespace n "
4228  "LEFT JOIN pg_init_privs pip "
4229  "ON (n.oid = pip.objoid "
4230  "AND pip.classoid = 'pg_namespace'::regclass "
4231  "AND pip.objsubid = 0",
4233  acl_subquery->data,
4234  racl_subquery->data,
4235  init_acl_subquery->data,
4236  init_racl_subquery->data);
4237 
4238  /*
4239  * When we are doing a 'clean' run, we will be dropping and recreating
4240  * the 'public' schema (the only object which has that kind of
4241  * treatment in the backend and which has an entry in pg_init_privs)
4242  * and therefore we should not consider any initial privileges in
4243  * pg_init_privs in that case.
4244  *
4245  * See pg_backup_archiver.c:_printTocEntry() for the details on why
4246  * the public schema is special in this regard.
4247  *
4248  * Note that if the public schema is dropped and re-created, this is
4249  * essentially a no-op because the new public schema won't have an
4250  * entry in pg_init_privs anyway, as the entry will be removed when
4251  * the public schema is dropped.
4252  *
4253  * Further, we have to handle the case where the public schema does
4254  * not exist at all.
4255  */
4256  if (dopt->outputClean)
4257  appendPQExpBuffer(query, " AND pip.objoid <> "
4258  "coalesce((select oid from pg_namespace "
4259  "where nspname = 'public'),0)");
4260 
4261  appendPQExpBuffer(query, ") ");
4262 
4263  destroyPQExpBuffer(acl_subquery);
4264  destroyPQExpBuffer(racl_subquery);
4265  destroyPQExpBuffer(init_acl_subquery);
4266  destroyPQExpBuffer(init_racl_subquery);
4267  }
4268  else
4269  appendPQExpBuffer(query, "SELECT tableoid, oid, nspname, "
4270  "(%s nspowner) AS rolname, "
4271  "nspacl, NULL as rnspacl, "
4272  "NULL AS initnspacl, NULL as initrnspacl "
4273  "FROM pg_namespace",
4275 
4276  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4277 
4278  ntups = PQntuples(res);
4279 
4280  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
4281 
4282  i_tableoid = PQfnumber(res, "tableoid");
4283  i_oid = PQfnumber(res, "oid");
4284  i_nspname = PQfnumber(res, "nspname");
4285  i_rolname = PQfnumber(res, "rolname");
4286  i_nspacl = PQfnumber(res, "nspacl");
4287  i_rnspacl = PQfnumber(res, "rnspacl");
4288  i_initnspacl = PQfnumber(res, "initnspacl");
4289  i_initrnspacl = PQfnumber(res, "initrnspacl");
4290 
4291  for (i = 0; i < ntups; i++)
4292  {
4293  nsinfo[i].dobj.objType = DO_NAMESPACE;
4294  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4295  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4296  AssignDumpId(&nsinfo[i].dobj);
4297  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
4298  nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4299  nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl));
4300  nsinfo[i].rnspacl = pg_strdup(PQgetvalue(res, i, i_rnspacl));
4301  nsinfo[i].initnspacl = pg_strdup(PQgetvalue(res, i, i_initnspacl));
4302  nsinfo[i].initrnspacl = pg_strdup(PQgetvalue(res, i, i_initrnspacl));
4303 
4304  /* Decide whether to dump this namespace */
4305  selectDumpableNamespace(&nsinfo[i], fout);
4306 
4307  /*
4308  * Do not try to dump ACL if the ACL is empty or the default.
4309  *
4310  * This is useful because, for some schemas/objects, the only
4311  * component we are going to try and dump is the ACL and if we can
4312  * remove that then 'dump' goes to zero/false and we don't consider
4313  * this object for dumping at all later on.
4314  */
4315  if (PQgetisnull(res, i, i_nspacl) && PQgetisnull(res, i, i_rnspacl) &&
4316  PQgetisnull(res, i, i_initnspacl) &&
4317  PQgetisnull(res, i, i_initrnspacl))
4318  nsinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4319 
4320  if (strlen(nsinfo[i].rolname) == 0)
4321  write_msg(NULL, "WARNING: owner of schema \"%s\" appears to be invalid\n",
4322  nsinfo[i].dobj.name);
4323  }
4324 
4325  PQclear(res);
4326  destroyPQExpBuffer(query);
4327 
4328  *numNamespaces = ntups;
4329 
4330  return nsinfo;
4331 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:148
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:181
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:698
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * rolname
Definition: pg_dump.h:146
char * initnspacl
Definition: pg_dump.h:149
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 void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
static const char * username_subquery
Definition: pg_dump.c:97
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:1377
void PQclear(PGresult *res)
Definition: fe-exec.c:671
void write_msg(const char *modulename, const char *fmt,...)
int outputClean
Definition: pg_backup.h:165
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
char * initrnspacl
Definition: pg_dump.h:150
CatalogId catId
Definition: pg_dump.h:131
int i
char * nspacl
Definition: pg_dump.h:147
DumpableObject dobj
Definition: pg_dump.h:145
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186

◆ getOpclasses()

OpclassInfo* getOpclasses ( Archive fout,
int *  numOpclasses 
)

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

Referenced by getSchemaData().

5019 {
5020  PGresult *res;
5021  int ntups;
5022  int i;
5023  PQExpBuffer query = createPQExpBuffer();
5024  OpclassInfo *opcinfo;
5025  int i_tableoid;
5026  int i_oid;
5027  int i_opcname;
5028  int i_opcnamespace;
5029  int i_rolname;
5030 
5031  /*
5032  * find all opclasses, including builtin opclasses; we filter out
5033  * system-defined opclasses at dump-out time.
5034  */
5035 
5036  /* Make sure we are in proper schema */
5037  selectSourceSchema(fout, "pg_catalog");
5038 
5039  appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
5040  "opcnamespace, "
5041  "(%s opcowner) AS rolname "
5042  "FROM pg_opclass",
5044 
5045  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5046 
5047  ntups = PQntuples(res);
5048  *numOpclasses = ntups;
5049 
5050  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
5051 
5052  i_tableoid = PQfnumber(res, "tableoid");
5053  i_oid = PQfnumber(res, "oid");
5054  i_opcname = PQfnumber(res, "opcname");
5055  i_opcnamespace = PQfnumber(res, "opcnamespace");
5056  i_rolname = PQfnumber(res, "rolname");
5057 
5058  for (i = 0; i < ntups; i++)
5059  {
5060  opcinfo[i].dobj.objType = DO_OPCLASS;
5061  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5062  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5063  AssignDumpId(&opcinfo[i].dobj);
5064  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
5065  opcinfo[i].dobj.namespace =
5066  findNamespace(fout,
5067  atooid(PQgetvalue(res, i, i_opcnamespace)));
5068  opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5069 
5070  /* Decide whether we want to dump it */
5071  selectDumpableObject(&(opcinfo[i].dobj), fout);
5072 
5073  /* Op Classes do not currently have ACLs. */
5074  opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5075 
5076  if (strlen(opcinfo[i].rolname) == 0)
5077  write_msg(NULL, "WARNING: owner of operator class \"%s\" appears to be invalid\n",
5078  opcinfo[i].dobj.name);
5079  }
5080 
5081  PQclear(res);
5082 
5083  destroyPQExpBuffer(query);
5084 
5085  return opcinfo;
5086 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1663
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:4338
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
char * rolname
Definition: pg_dump.h:235
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 void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
static const char * username_subquery
Definition: pg_dump.c:97
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
DumpableObject dobj
Definition: pg_dump.h:234
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:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407

◆ getOperators()

OprInfo* getOperators ( Archive fout,
int *  numOperators 
)

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

Referenced by getSchemaData().

4697 {
4698  PGresult *res;
4699  int ntups;
4700  int i;
4701  PQExpBuffer query = createPQExpBuffer();
4702  OprInfo *oprinfo;
4703  int i_tableoid;
4704  int i_oid;
4705  int i_oprname;
4706  int i_oprnamespace;
4707  int i_rolname;
4708  int i_oprkind;
4709  int i_oprcode;
4710 
4711  /*
4712  * find all operators, including builtin operators; we filter out
4713  * system-defined operators at dump-out time.
4714  */
4715 
4716  /* Make sure we are in proper schema */
4717  selectSourceSchema(fout, "pg_catalog");
4718 
4719  appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
4720  "oprnamespace, "
4721  "(%s oprowner) AS rolname, "
4722  "oprkind, "
4723  "oprcode::oid AS oprcode "
4724  "FROM pg_operator",
4726 
4727  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4728 
4729  ntups = PQntuples(res);
4730  *numOprs = ntups;
4731 
4732  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
4733 
4734  i_tableoid = PQfnumber(res, "tableoid");
4735  i_oid = PQfnumber(res, "oid");
4736  i_oprname = PQfnumber(res, "oprname");
4737  i_oprnamespace = PQfnumber(res, "oprnamespace");
4738  i_rolname = PQfnumber(res, "rolname");
4739  i_oprkind = PQfnumber(res, "oprkind");
4740  i_oprcode = PQfnumber(res, "oprcode");
4741 
4742  for (i = 0; i < ntups; i++)
4743  {
4744  oprinfo[i].dobj.objType = DO_OPERATOR;
4745  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4746  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4747  AssignDumpId(&oprinfo[i].dobj);
4748  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
4749  oprinfo[i].dobj.namespace =
4750  findNamespace(fout,
4751  atooid(PQgetvalue(res, i, i_oprnamespace)));
4752  oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4753  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
4754  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
4755 
4756  /* Decide whether we want to dump it */
4757  selectDumpableObject(&(oprinfo[i].dobj), fout);
4758 
4759  /* Operators do not currently have ACLs. */
4760  oprinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4761 
4762  if (strlen(oprinfo[i].rolname) == 0)
4763  write_msg(NULL, "WARNING: owner of operator \"%s\" appears to be invalid\n",
4764  oprinfo[i].dobj.name);
4765  }
4766 
4767  PQclear(res);
4768 
4769  destroyPQExpBuffer(query);
4770 
4771  return oprinfo;
4772 }
char * name
Definition: pg_dump.h:133
DumpableObject dobj
Definition: pg_dump.h:219
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1663
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
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:4338
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 void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17975
static const char * username_subquery
Definition: pg_dump.c:97
char * rolname
Definition: pg_dump.h:220
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:221
void write_msg(const char *modulename, const char *fmt,...)
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
Oid oprcode
Definition: pg_dump.h:222

◆ getOpfamilies()

OpfamilyInfo* getOpfamilies ( Archive fout,
int *  numOpfamilies 
)

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

Referenced by getSchemaData().

5097 {
5098  PGresult *res;
5099  int ntups;
5100  int i;
5101  PQExpBuffer query;
5102  OpfamilyInfo *opfinfo;
5103  int i_tableoid;
5104  int i_oid;
5105  int i_opfname;
5106  int i_opfnamespace;
5107  int i_rolname;
5108 
5109  /* Before 8.3, there is no separate concept of opfamilies */
5110  if (fout->remoteVersion < 80300)
5111  {
5112  *numOpfamilies = 0;
5113  return NULL;
5114  }
5115 
5116  query = createPQExpBuffer();
5117 
5118  /*
5119  * find all opfamilies, including builtin opfamilies; we filter out
5120  * system-defined opfamilies at dump-out time.
5121  */
5122 
5123  /* Make sure we are in proper schema */
5124  selectSourceSchema(fout, "pg_catalog");
5125 
5126  appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, "
5127  "opfnamespace, "
5128  "(%s opfowner) AS rolname "
5129  "FROM pg_opfamily",
5131 
5132  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5133 
5134  ntups = PQntuples(res);
5135  *numOpfamilies = ntups;
5136 
5137  opfinfo = (