PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

#define DUMP_COMPONENT_DATA   (1 << 1)
#define DUMP_COMPONENT_POLICY   (1 << 5)

Definition at line 97 of file pg_dump.h.

Referenced by checkExtensionMembership(), dumpPolicy(), and getPolicies().

#define DUMP_COMPONENT_USERMAP   (1 << 6)

Definition at line 98 of file pg_dump.h.

Referenced by dumpForeignServer().

#define DUMP_COMPONENTS_REQUIRING_LOCK
Value:
(\
#define DUMP_COMPONENT_DATA
Definition: pg_dump.h:93
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define DUMP_COMPONENT_POLICY
Definition: pg_dump.h:97

Definition at line 123 of file pg_dump.h.

Referenced by getTables().

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

Definition at line 21 of file pg_dump.h.

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

Definition at line 23 of file pg_dump.h.

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

Definition at line 22 of file pg_dump.h.

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

Definition at line 24 of file pg_dump.h.

Typedef Documentation

Definition at line 90 of file pg_dump.h.

Enumeration Type Documentation

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

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

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

694 {
695  if (dobj->nDeps >= dobj->allocDeps)
696  {
697  if (dobj->allocDeps <= 0)
698  {
699  dobj->allocDeps = 16;
700  dobj->dependencies = (DumpId *)
701  pg_malloc(dobj->allocDeps * sizeof(DumpId));
702  }
703  else
704  {
705  dobj->allocDeps *= 2;
706  dobj->dependencies = (DumpId *)
707  pg_realloc(dobj->dependencies,
708  dobj->allocDeps * sizeof(DumpId));
709  }
710  }
711  dobj->dependencies[dobj->nDeps++] = refId;
712 }
int DumpId
Definition: pg_backup.h:229
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
void AssignDumpId ( DumpableObject dobj)

Definition at line 457 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, NULL, 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().

458 {
459  dobj->dumpId = ++lastDumpId;
460  dobj->name = NULL; /* must be set later */
461  dobj->namespace = NULL; /* may be set later */
462  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
463  dobj->ext_member = false; /* default assumption */
464  dobj->dependencies = NULL;
465  dobj->nDeps = 0;
466  dobj->allocDeps = 0;
467 
468  while (dobj->dumpId >= allocedDumpIds)
469  {
470  int newAlloc;
471 
472  if (allocedDumpIds <= 0)
473  {
474  newAlloc = 256;
476  pg_malloc(newAlloc * sizeof(DumpableObject *));
477  }
478  else
479  {
480  newAlloc = allocedDumpIds * 2;
482  pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
483  }
484  memset(dumpIdMap + allocedDumpIds, 0,
485  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
486  allocedDumpIds = newAlloc;
487  }
488  dumpIdMap[dobj->dumpId] = dobj;
489 
490  /* mark catalogIdMap invalid, but don't rebuild it yet */
491  catalogIdMapValid = false;
492 }
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
#define NULL
Definition: c.h:229
static bool catalogIdMapValid
Definition: common.c:38
#define DUMP_COMPONENT_ALL
Definition: pg_dump.h:99
DumpId createDumpId ( void  )
CollInfo* findCollationByOid ( Oid  oid)

Definition at line 784 of file common.c.

References findObjectByOid(), and numCollations.

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

785 {
787 }
static DumpableObject ** collinfoindex
Definition: common.c:54
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:590
static int numCollations
Definition: common.c:61
ExtensionInfo* findExtensionByOid ( Oid  oid)

Definition at line 806 of file common.c.

References findObjectByOid(), and numExtensions.

Referenced by getExtensionMembership().

807 {
809 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:590
static int numExtensions
Definition: common.c:63
static DumpableObject ** extinfoindex
Definition: common.c:56
FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 762 of file common.c.

References findObjectByOid(), and numFuncs.

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

763 {
764  return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs);
765 }
static int numFuncs
Definition: common.c:59
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:590
static DumpableObject ** funinfoindex
Definition: common.c:52
NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 795 of file common.c.

References findObjectByOid(), and numNamespaces.

Referenced by findNamespace().

796 {
798 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:590
static int numNamespaces
Definition: common.c:62
static DumpableObject ** nspinfoindex
Definition: common.c:55
DumpableObject* findObjectByCatalogId ( CatalogId  catalogId)

Definition at line 539 of file common.c.

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

Referenced by buildMatViewRefreshDependencies(), and getDependencies().

540 {
541  DumpableObject **low;
542  DumpableObject **high;
543 
544  if (!catalogIdMapValid)
545  {
546  if (catalogIdMap)
549  if (numCatalogIds > 1)
550  qsort((void *) catalogIdMap, numCatalogIds,
552  catalogIdMapValid = true;
553  }
554 
555  /*
556  * We could use bsearch() here, but the notational cruft of calling
557  * bsearch is nearly as bad as doing it ourselves; and the generalized
558  * bsearch function is noticeably slower as well.
559  */
560  if (numCatalogIds <= 0)
561  return NULL;
562  low = catalogIdMap;
563  high = catalogIdMap + (numCatalogIds - 1);
564  while (low <= high)
565  {
566  DumpableObject **middle;
567  int difference;
568 
569  middle = low + (high - low) / 2;
570  /* comparison must match DOCatalogIdCompare, below */
571  difference = oidcmp((*middle)->catId.oid, catalogId.oid);
572  if (difference == 0)
573  difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid);
574  if (difference == 0)
575  return *middle;
576  else if (difference < 0)
577  low = middle + 1;
578  else
579  high = middle - 1;
580  }
581  return NULL;
582 }
Oid tableoid
Definition: pg_backup.h:225
#define oidcmp(x, y)
Definition: pg_dump.h:20
static int DOCatalogIdCompare(const void *p1, const void *p2)
Definition: common.c:649
static int numCatalogIds
Definition: common.c:40
Datum difference(PG_FUNCTION_ARGS)
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static DumpableObject ** catalogIdMap
Definition: common.c:39
static bool catalogIdMapValid
Definition: common.c:38
#define qsort(a, b, c, d)
Definition: port.h:440
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition: common.c:671
DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 521 of file common.c.

References allocedDumpIds, and NULL.

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

522 {
523  if (dumpId <= 0 || dumpId >= allocedDumpIds)
524  return NULL; /* out of range? */
525  return dumpIdMap[dumpId];
526 }
static int allocedDumpIds
Definition: common.c:32
static DumpableObject ** dumpIdMap
Definition: common.c:31
#define NULL
Definition: c.h:229
OprInfo* findOprByOid ( Oid  oid)

Definition at line 773 of file common.c.

References findObjectByOid(), and numOperators.

774 {
776 }
static DumpableObject ** oprinfoindex
Definition: common.c:53
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:590
static int numOperators
Definition: common.c:60
ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 833 of file common.c.

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

Referenced by checkExtensionMembership().

834 {
835  ExtensionMemberId *low;
836  ExtensionMemberId *high;
837 
838  /*
839  * We could use bsearch() here, but the notational cruft of calling
840  * bsearch is nearly as bad as doing it ourselves; and the generalized
841  * bsearch function is noticeably slower as well.
842  */
843  if (numextmembers <= 0)
844  return NULL;
845  low = extmembers;
846  high = extmembers + (numextmembers - 1);
847  while (low <= high)
848  {
849  ExtensionMemberId *middle;
850  int difference;
851 
852  middle = low + (high - low) / 2;
853  /* comparison must match ExtensionMemberIdCompare, below */
854  difference = oidcmp(middle->catId.oid, catalogId.oid);
855  if (difference == 0)
856  difference = oidcmp(middle->catId.tableoid, catalogId.tableoid);
857  if (difference == 0)
858  return middle->ext;
859  else if (difference < 0)
860  low = middle + 1;
861  else
862  high = middle - 1;
863  }
864  return NULL;
865 }
ExtensionInfo * ext
Definition: pg_dump.h:621
Oid tableoid
Definition: pg_backup.h:225
#define oidcmp(x, y)
Definition: pg_dump.h:20
Datum difference(PG_FUNCTION_ARGS)
static ExtensionMemberId * extmembers
Definition: common.c:66
#define NULL
Definition: c.h:229
static int numextmembers
Definition: common.c:67
CatalogId catId
Definition: pg_dump.h:620
TableInfo* findTableByOid ( Oid  oid)

Definition at line 740 of file common.c.

References findObjectByOid(), and numTables.

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

741 {
743 }
static int numTables
Definition: common.c:57
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:590
static DumpableObject ** tblinfoindex
Definition: common.c:50
TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 751 of file common.c.

References findObjectByOid(), and numTypes.

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

752 {
753  return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes);
754 }
static int numTypes
Definition: common.c:58
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:590
static DumpableObject ** typinfoindex
Definition: common.c:51
AccessMethodInfo* getAccessMethods ( Archive fout,
int *  numAccessMethods 
)

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

4823 {
4824  PGresult *res;
4825  int ntups;
4826  int i;
4827  PQExpBuffer query;
4828  AccessMethodInfo *aminfo;
4829  int i_tableoid;
4830  int i_oid;
4831  int i_amname;
4832  int i_amhandler;
4833  int i_amtype;
4834 
4835  /* Before 9.6, there are no user-defined access methods */
4836  if (fout->remoteVersion < 90600)
4837  {
4838  *numAccessMethods = 0;
4839  return NULL;
4840  }
4841 
4842  query = createPQExpBuffer();
4843 
4844  /* Make sure we are in proper schema */
4845  selectSourceSchema(fout, "pg_catalog");
4846 
4847  /* Select all access methods from pg_am table */
4848  appendPQExpBuffer(query, "SELECT tableoid, oid, amname, amtype, "
4849  "amhandler::pg_catalog.regproc AS amhandler "
4850  "FROM pg_am");
4851 
4852  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4853 
4854  ntups = PQntuples(res);
4855  *numAccessMethods = ntups;
4856 
4857  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
4858 
4859  i_tableoid = PQfnumber(res, "tableoid");
4860  i_oid = PQfnumber(res, "oid");
4861  i_amname = PQfnumber(res, "amname");
4862  i_amhandler = PQfnumber(res, "amhandler");
4863  i_amtype = PQfnumber(res, "amtype");
4864 
4865  for (i = 0; i < ntups; i++)
4866  {
4867  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
4868  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4869  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4870  AssignDumpId(&aminfo[i].dobj);
4871  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
4872  aminfo[i].dobj.namespace = NULL;
4873  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
4874  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
4875 
4876  /* Decide whether we want to dump it */
4877  selectDumpableAccessMethod(&(aminfo[i]), fout);
4878 
4879  /* Access methods do not currently have ACLs. */
4880  aminfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4881  }
4882 
4883  PQclear(res);
4884 
4885  destroyPQExpBuffer(query);
4886 
4887  return aminfo;
4888 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:1591
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:17728
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
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:185
AggInfo* getAggregates ( Archive fout,
int *  numAggregates 
)

Definition at line 5064 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, NULL, _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().

5065 {
5066  DumpOptions *dopt = fout->dopt;
5067  PGresult *res;
5068  int ntups;
5069  int i;
5070  PQExpBuffer query = createPQExpBuffer();
5071  AggInfo *agginfo;
5072  int i_tableoid;
5073  int i_oid;
5074  int i_aggname;
5075  int i_aggnamespace;
5076  int i_pronargs;
5077  int i_proargtypes;
5078  int i_rolname;
5079  int i_aggacl;
5080  int i_raggacl;
5081  int i_initaggacl;
5082  int i_initraggacl;
5083 
5084  /* Make sure we are in proper schema */
5085  selectSourceSchema(fout, "pg_catalog");
5086 
5087  /*
5088  * Find all interesting aggregates. See comment in getFuncs() for the
5089  * rationale behind the filtering logic.
5090  */
5091  if (fout->remoteVersion >= 90600)
5092  {
5093  PQExpBuffer acl_subquery = createPQExpBuffer();
5094  PQExpBuffer racl_subquery = createPQExpBuffer();
5095  PQExpBuffer initacl_subquery = createPQExpBuffer();
5096  PQExpBuffer initracl_subquery = createPQExpBuffer();
5097 
5098  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5099  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5100  dopt->binary_upgrade);
5101 
5102  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5103  "p.proname AS aggname, "
5104  "p.pronamespace AS aggnamespace, "
5105  "p.pronargs, p.proargtypes, "
5106  "(%s p.proowner) AS rolname, "
5107  "%s AS aggacl, "
5108  "%s AS raggacl, "
5109  "%s AS initaggacl, "
5110  "%s AS initraggacl "
5111  "FROM pg_proc p "
5112  "LEFT JOIN pg_init_privs pip ON "
5113  "(p.oid = pip.objoid "
5114  "AND pip.classoid = 'pg_proc'::regclass "
5115  "AND pip.objsubid = 0) "
5116  "WHERE p.proisagg AND ("
5117  "p.pronamespace != "
5118  "(SELECT oid FROM pg_namespace "
5119  "WHERE nspname = 'pg_catalog') OR "
5120  "p.proacl IS DISTINCT FROM pip.initprivs",
5122  acl_subquery->data,
5123  racl_subquery->data,
5124  initacl_subquery->data,
5125  initracl_subquery->data);
5126  if (dopt->binary_upgrade)
5127  appendPQExpBufferStr(query,
5128  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5129  "classid = 'pg_proc'::regclass AND "
5130  "objid = p.oid AND "
5131  "refclassid = 'pg_extension'::regclass AND "
5132  "deptype = 'e')");
5133  appendPQExpBufferChar(query, ')');
5134 
5135  destroyPQExpBuffer(acl_subquery);
5136  destroyPQExpBuffer(racl_subquery);
5137  destroyPQExpBuffer(initacl_subquery);
5138  destroyPQExpBuffer(initracl_subquery);
5139  }
5140  else if (fout->remoteVersion >= 80200)
5141  {
5142  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5143  "pronamespace AS aggnamespace, "
5144  "pronargs, proargtypes, "
5145  "(%s proowner) AS rolname, "
5146  "proacl AS aggacl, "
5147  "NULL AS raggacl, "
5148  "NULL AS initaggacl, NULL AS initraggacl "
5149  "FROM pg_proc p "
5150  "WHERE proisagg AND ("
5151  "pronamespace != "
5152  "(SELECT oid FROM pg_namespace "
5153  "WHERE nspname = 'pg_catalog')",
5155  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5156  appendPQExpBufferStr(query,
5157  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5158  "classid = 'pg_proc'::regclass AND "
5159  "objid = p.oid AND "
5160  "refclassid = 'pg_extension'::regclass AND "
5161  "deptype = 'e')");
5162  appendPQExpBufferChar(query, ')');
5163  }
5164  else
5165  {
5166  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5167  "pronamespace AS aggnamespace, "
5168  "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
5169  "proargtypes, "
5170  "(%s proowner) AS rolname, "
5171  "proacl AS aggacl, "
5172  "NULL AS raggacl, "
5173  "NULL AS initaggacl, NULL AS initraggacl "
5174  "FROM pg_proc "
5175  "WHERE proisagg "
5176  "AND pronamespace != "
5177  "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
5179  }
5180 
5181  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5182 
5183  ntups = PQntuples(res);
5184  *numAggs = ntups;
5185 
5186  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5187 
5188  i_tableoid = PQfnumber(res, "tableoid");
5189  i_oid = PQfnumber(res, "oid");
5190  i_aggname = PQfnumber(res, "aggname");
5191  i_aggnamespace = PQfnumber(res, "aggnamespace");
5192  i_pronargs = PQfnumber(res, "pronargs");
5193  i_proargtypes = PQfnumber(res, "proargtypes");
5194  i_rolname = PQfnumber(res, "rolname");
5195  i_aggacl = PQfnumber(res, "aggacl");
5196  i_raggacl = PQfnumber(res, "raggacl");
5197  i_initaggacl = PQfnumber(res, "initaggacl");
5198  i_initraggacl = PQfnumber(res, "initraggacl");
5199 
5200  for (i = 0; i < ntups; i++)
5201  {
5202  agginfo[i].aggfn.dobj.objType = DO_AGG;
5203  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5204  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5205  AssignDumpId(&agginfo[i].aggfn.dobj);
5206  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5207  agginfo[i].aggfn.dobj.namespace =
5208  findNamespace(fout,
5209  atooid(PQgetvalue(res, i, i_aggnamespace)));
5210  agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5211  if (strlen(agginfo[i].aggfn.rolname) == 0)
5212  write_msg(NULL, "WARNING: owner of aggregate function \"%s\" appears to be invalid\n",
5213  agginfo[i].aggfn.dobj.name);
5214  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5215  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5216  agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5217  agginfo[i].aggfn.rproacl = pg_strdup(PQgetvalue(res, i, i_raggacl));
5218  agginfo[i].aggfn.initproacl = pg_strdup(PQgetvalue(res, i, i_initaggacl));
5219  agginfo[i].aggfn.initrproacl = pg_strdup(PQgetvalue(res, i, i_initraggacl));
5220  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5221  if (agginfo[i].aggfn.nargs == 0)
5222  agginfo[i].aggfn.argtypes = NULL;
5223  else
5224  {
5225  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5226  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5227  agginfo[i].aggfn.argtypes,
5228  agginfo[i].aggfn.nargs);
5229  }
5230 
5231  /* Decide whether we want to dump it */
5232  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5233 
5234  /* Do not try to dump ACL if no ACL exists. */
5235  if (PQgetisnull(res, i, i_aggacl) && PQgetisnull(res, i, i_raggacl) &&
5236  PQgetisnull(res, i, i_initaggacl) &&
5237  PQgetisnull(res, i, i_initraggacl))
5238  agginfo[i].aggfn.dobj.dump &= ~DUMP_COMPONENT_ACL;
5239  }
5240 
5241  PQclear(res);
5242 
5243  destroyPQExpBuffer(query);
5244 
5245  return agginfo;
5246 }
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:1657
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:4219
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:2673
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:180
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:695
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:17728
static const char * username_subquery
Definition: pg_dump.c:96
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:948
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
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:650
void write_msg(const char *modulename, const char *fmt,...)
Oid prorettype
Definition: pg_dump.h:203
#define NULL
Definition: c.h:229
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:3092
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:185
CastInfo* getCasts ( Archive fout,
int *  numCasts 
)

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

7541 {
7542  PGresult *res;
7543  int ntups;
7544  int i;
7545  PQExpBuffer query = createPQExpBuffer();
7546  CastInfo *castinfo;
7547  int i_tableoid;
7548  int i_oid;
7549  int i_castsource;
7550  int i_casttarget;
7551  int i_castfunc;
7552  int i_castcontext;
7553  int i_castmethod;
7554 
7555  /* Make sure we are in proper schema */
7556  selectSourceSchema(fout, "pg_catalog");
7557 
7558  if (fout->remoteVersion >= 80400)
7559  {
7560  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7561  "castsource, casttarget, castfunc, castcontext, "
7562  "castmethod "
7563  "FROM pg_cast ORDER BY 3,4");
7564  }
7565  else
7566  {
7567  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7568  "castsource, casttarget, castfunc, castcontext, "
7569  "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
7570  "FROM pg_cast ORDER BY 3,4");
7571  }
7572 
7573  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7574 
7575  ntups = PQntuples(res);
7576 
7577  *numCasts = ntups;
7578 
7579  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
7580 
7581  i_tableoid = PQfnumber(res, "tableoid");
7582  i_oid = PQfnumber(res, "oid");
7583  i_castsource = PQfnumber(res, "castsource");
7584  i_casttarget = PQfnumber(res, "casttarget");
7585  i_castfunc = PQfnumber(res, "castfunc");
7586  i_castcontext = PQfnumber(res, "castcontext");
7587  i_castmethod = PQfnumber(res, "castmethod");
7588 
7589  for (i = 0; i < ntups; i++)
7590  {
7591  PQExpBufferData namebuf;
7592  TypeInfo *sTypeInfo;
7593  TypeInfo *tTypeInfo;
7594 
7595  castinfo[i].dobj.objType = DO_CAST;
7596  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7597  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7598  AssignDumpId(&castinfo[i].dobj);
7599  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
7600  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
7601  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
7602  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
7603  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
7604 
7605  /*
7606  * Try to name cast as concatenation of typnames. This is only used
7607  * for purposes of sorting. If we fail to find either type, the name
7608  * will be an empty string.
7609  */
7610  initPQExpBuffer(&namebuf);
7611  sTypeInfo = findTypeByOid(castinfo[i].castsource);
7612  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
7613  if (sTypeInfo && tTypeInfo)
7614  appendPQExpBuffer(&namebuf, "%s %s",
7615  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
7616  castinfo[i].dobj.name = namebuf.data;
7617 
7618  /* Decide whether we want to dump it */
7619  selectDumpableCast(&(castinfo[i]), fout);
7620 
7621  /* Casts do not currently have ACLs. */
7622  castinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7623  }
7624 
7625  PQclear(res);
7626 
7627  destroyPQExpBuffer(query);
7628 
7629  return castinfo;
7630 }
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:225
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:1533
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:2673
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:17728
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:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#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:751
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:185
CollInfo* getCollations ( Archive fout,
int *  numCollations 
)

Definition at line 4663 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, NULL, _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().

4664 {
4665  PGresult *res;
4666  int ntups;
4667  int i;
4668  PQExpBuffer query;
4669  CollInfo *collinfo;
4670  int i_tableoid;
4671  int i_oid;
4672  int i_collname;
4673  int i_collnamespace;
4674  int i_rolname;
4675 
4676  /* Collations didn't exist pre-9.1 */
4677  if (fout->remoteVersion < 90100)
4678  {
4679  *numCollations = 0;
4680  return NULL;
4681  }
4682 
4683  query = createPQExpBuffer();
4684 
4685  /*
4686  * find all collations, including builtin collations; we filter out
4687  * system-defined collations at dump-out time.
4688  */
4689 
4690  /* Make sure we are in proper schema */
4691  selectSourceSchema(fout, "pg_catalog");
4692 
4693  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
4694  "collnamespace, "
4695  "(%s collowner) AS rolname "
4696  "FROM pg_collation",
4698 
4699  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4700 
4701  ntups = PQntuples(res);
4702  *numCollations = ntups;
4703 
4704  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
4705 
4706  i_tableoid = PQfnumber(res, "tableoid");
4707  i_oid = PQfnumber(res, "oid");
4708  i_collname = PQfnumber(res, "collname");
4709  i_collnamespace = PQfnumber(res, "collnamespace");
4710  i_rolname = PQfnumber(res, "rolname");
4711 
4712  for (i = 0; i < ntups; i++)
4713  {
4714  collinfo[i].dobj.objType = DO_COLLATION;
4715  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4716  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4717  AssignDumpId(&collinfo[i].dobj);
4718  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
4719  collinfo[i].dobj.namespace =
4720  findNamespace(fout,
4721  atooid(PQgetvalue(res, i, i_collnamespace)));
4722  collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4723 
4724  /* Decide whether we want to dump it */
4725  selectDumpableObject(&(collinfo[i].dobj), fout);
4726 
4727  /* Collations do not currently have ACLs. */
4728  collinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4729  }
4730 
4731  PQclear(res);
4732 
4733  destroyPQExpBuffer(query);
4734 
4735  return collinfo;
4736 }
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:1657
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4219
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
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:17728
static const char * username_subquery
Definition: pg_dump.c:96
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
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:185
void getConstraints ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 6765 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, NULL, 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().

6766 {
6767  int i,
6768  j;
6769  ConstraintInfo *constrinfo;
6770  PQExpBuffer query;
6771  PGresult *res;
6772  int i_contableoid,
6773  i_conoid,
6774  i_conname,
6775  i_confrelid,
6776  i_condef;
6777  int ntups;
6778 
6779  query = createPQExpBuffer();
6780 
6781  for (i = 0; i < numTables; i++)
6782  {
6783  TableInfo *tbinfo = &tblinfo[i];
6784 
6785  if (!tbinfo->hastriggers ||
6786  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6787  continue;
6788 
6789  if (g_verbose)
6790  write_msg(NULL, "reading foreign key constraints for table \"%s.%s\"\n",
6791  tbinfo->dobj.namespace->dobj.name,
6792  tbinfo->dobj.name);
6793 
6794  /*
6795  * select table schema to ensure constraint expr is qualified if
6796  * needed
6797  */
6798  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6799 
6800  resetPQExpBuffer(query);
6801  appendPQExpBuffer(query,
6802  "SELECT tableoid, oid, conname, confrelid, "
6803  "pg_catalog.pg_get_constraintdef(oid) AS condef "
6804  "FROM pg_catalog.pg_constraint "
6805  "WHERE conrelid = '%u'::pg_catalog.oid "
6806  "AND contype = 'f'",
6807  tbinfo->dobj.catId.oid);
6808  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6809 
6810  ntups = PQntuples(res);
6811 
6812  i_contableoid = PQfnumber(res, "tableoid");
6813  i_conoid = PQfnumber(res, "oid");
6814  i_conname = PQfnumber(res, "conname");
6815  i_confrelid = PQfnumber(res, "confrelid");
6816  i_condef = PQfnumber(res, "condef");
6817 
6818  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
6819 
6820  for (j = 0; j < ntups; j++)
6821  {
6822  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
6823  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
6824  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
6825  AssignDumpId(&constrinfo[j].dobj);
6826  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
6827  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6828  constrinfo[j].contable = tbinfo;
6829  constrinfo[j].condomain = NULL;
6830  constrinfo[j].contype = 'f';
6831  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
6832  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
6833  constrinfo[j].conindex = 0;
6834  constrinfo[j].condeferrable = false;
6835  constrinfo[j].condeferred = false;
6836  constrinfo[j].conislocal = true;
6837  constrinfo[j].separate = true;
6838  }
6839 
6840  PQclear(res);
6841  }
6842 
6843  destroyPQExpBuffer(query);
6844 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:2673
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:17728
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:2781
TableInfo * contable
Definition: pg_dump.h:427
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#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
#define NULL
Definition: c.h:229
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:91
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
ConvInfo* getConversions ( Archive fout,
int *  numConversions 
)

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

4747 {
4748  PGresult *res;
4749  int ntups;
4750  int i;
4751  PQExpBuffer query;
4752  ConvInfo *convinfo;
4753  int i_tableoid;
4754  int i_oid;
4755  int i_conname;
4756  int i_connamespace;
4757  int i_rolname;
4758 
4759  query = createPQExpBuffer();
4760 
4761  /*
4762  * find all conversions, including builtin conversions; we filter out
4763  * system-defined conversions at dump-out time.
4764  */
4765 
4766  /* Make sure we are in proper schema */
4767  selectSourceSchema(fout, "pg_catalog");
4768 
4769  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
4770  "connamespace, "
4771  "(%s conowner) AS rolname "
4772  "FROM pg_conversion",
4774 
4775  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4776 
4777  ntups = PQntuples(res);
4778  *numConversions = ntups;
4779 
4780  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
4781 
4782  i_tableoid = PQfnumber(res, "tableoid");
4783  i_oid = PQfnumber(res, "oid");
4784  i_conname = PQfnumber(res, "conname");
4785  i_connamespace = PQfnumber(res, "connamespace");
4786  i_rolname = PQfnumber(res, "rolname");
4787 
4788  for (i = 0; i < ntups; i++)
4789  {
4790  convinfo[i].dobj.objType = DO_CONVERSION;
4791  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4792  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4793  AssignDumpId(&convinfo[i].dobj);
4794  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
4795  convinfo[i].dobj.namespace =
4796  findNamespace(fout,
4797  atooid(PQgetvalue(res, i, i_connamespace)));
4798  convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4799 
4800  /* Decide whether we want to dump it */
4801  selectDumpableObject(&(convinfo[i].dobj), fout);
4802 
4803  /* Conversions do not currently have ACLs. */
4804  convinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4805  }
4806 
4807  PQclear(res);
4808 
4809  destroyPQExpBuffer(query);
4810 
4811  return convinfo;
4812 }
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:1657
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4219
char * rolname
Definition: pg_dump.h:253
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
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:17728
static const char * username_subquery
Definition: pg_dump.c:96
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
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
DefaultACLInfo* getDefaultACLs ( Archive fout,
int *  numDefaultACLs 
)

Definition at line 8906 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, NULL, _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().

8907 {
8908  DumpOptions *dopt = fout->dopt;
8909  DefaultACLInfo *daclinfo;
8910  PQExpBuffer query;
8911  PGresult *res;
8912  int i_oid;
8913  int i_tableoid;
8914  int i_defaclrole;
8915  int i_defaclnamespace;
8916  int i_defaclobjtype;
8917  int i_defaclacl;
8918  int i_rdefaclacl;
8919  int i_initdefaclacl;
8920  int i_initrdefaclacl;
8921  int i,
8922  ntups;
8923 
8924  if (fout->remoteVersion < 90000)
8925  {
8926  *numDefaultACLs = 0;
8927  return NULL;
8928  }
8929 
8930  query = createPQExpBuffer();
8931 
8932  /* Make sure we are in proper schema */
8933  selectSourceSchema(fout, "pg_catalog");
8934 
8935  if (fout->remoteVersion >= 90600)
8936  {
8937  PQExpBuffer acl_subquery = createPQExpBuffer();
8938  PQExpBuffer racl_subquery = createPQExpBuffer();
8939  PQExpBuffer initacl_subquery = createPQExpBuffer();
8940  PQExpBuffer initracl_subquery = createPQExpBuffer();
8941 
8942  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8943  initracl_subquery, "defaclacl", "defaclrole",
8944  "CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
8945  dopt->binary_upgrade);
8946 
8947  appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
8948  "(%s d.defaclrole) AS defaclrole, "
8949  "d.defaclnamespace, "
8950  "d.defaclobjtype, "
8951  "%s AS defaclacl, "
8952  "%s AS rdefaclacl, "
8953  "%s AS initdefaclacl, "
8954  "%s AS initrdefaclacl "
8955  "FROM pg_default_acl d "
8956  "LEFT JOIN pg_init_privs pip ON "
8957  "(d.oid = pip.objoid "
8958  "AND pip.classoid = 'pg_default_acl'::regclass "
8959  "AND pip.objsubid = 0) ",
8961  acl_subquery->data,
8962  racl_subquery->data,
8963  initacl_subquery->data,
8964  initracl_subquery->data);
8965  }
8966  else
8967  {
8968  appendPQExpBuffer(query, "SELECT oid, tableoid, "
8969  "(%s defaclrole) AS defaclrole, "
8970  "defaclnamespace, "
8971  "defaclobjtype, "
8972  "defaclacl, "
8973  "NULL AS rdefaclacl, "
8974  "NULL AS initdefaclacl, "
8975  "NULL AS initrdefaclacl "
8976  "FROM pg_default_acl",
8978  }
8979 
8980  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8981 
8982  ntups = PQntuples(res);
8983  *numDefaultACLs = ntups;
8984 
8985  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
8986 
8987  i_oid = PQfnumber(res, "oid");
8988  i_tableoid = PQfnumber(res, "tableoid");
8989  i_defaclrole = PQfnumber(res, "defaclrole");
8990  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
8991  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
8992  i_defaclacl = PQfnumber(res, "defaclacl");
8993  i_rdefaclacl = PQfnumber(res, "rdefaclacl");
8994  i_initdefaclacl = PQfnumber(res, "initdefaclacl");
8995  i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
8996 
8997  for (i = 0; i < ntups; i++)
8998  {
8999  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9000 
9001  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9002  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9003  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9004  AssignDumpId(&daclinfo[i].dobj);
9005  /* cheesy ... is it worth coming up with a better object name? */
9006  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9007 
9008  if (nspid != InvalidOid)
9009  daclinfo[i].dobj.namespace = findNamespace(fout, nspid);
9010  else
9011  daclinfo[i].dobj.namespace = NULL;
9012 
9013  daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
9014  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9015  daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9016  daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
9017  daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
9018  daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
9019 
9020  /* Decide whether we want to dump it */
9021  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9022  }
9023 
9024  PQclear(res);
9025 
9026  destroyPQExpBuffer(query);
9027 
9028  return daclinfo;
9029 }
char * name
Definition: pg_dump.h:133
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4219
char * rdefaclacl
Definition: pg_dump.h:544
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition: pg_dump.c:1511
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:180
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:695
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:17728
static const char * username_subquery
Definition: pg_dump.c:96
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:2781
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
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:185
char * defaclrole
Definition: pg_dump.h:541
void getDumpableObjects ( DumpableObject ***  objs,
int *  numObjs 
)

Definition at line 671 of file common.c.

References allocedDumpIds, i, and pg_malloc().

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

672 {
673  int i,
674  j;
675 
676  *objs = (DumpableObject **)
678  j = 0;
679  for (i = 1; i < allocedDumpIds; i++)
680  {
681  if (dumpIdMap[i])
682  (*objs)[j++] = dumpIdMap[i];
683  }
684  *numObjs = j;
685 }
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
EventTriggerInfo* getEventTriggers ( Archive fout,
int *  numEventTriggers 
)

Definition at line 7265 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, NULL, _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().

7266 {
7267  int i;
7268  PQExpBuffer query;
7269  PGresult *res;
7270  EventTriggerInfo *evtinfo;
7271  int i_tableoid,
7272  i_oid,
7273  i_evtname,
7274  i_evtevent,
7275  i_evtowner,
7276  i_evttags,
7277  i_evtfname,
7278  i_evtenabled;
7279  int ntups;
7280 
7281  /* Before 9.3, there are no event triggers */
7282  if (fout->remoteVersion < 90300)
7283  {
7284  *numEventTriggers = 0;
7285  return NULL;
7286  }
7287 
7288  query = createPQExpBuffer();
7289 
7290  /* Make sure we are in proper schema */
7291  selectSourceSchema(fout, "pg_catalog");
7292 
7293  appendPQExpBuffer(query,
7294  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
7295  "evtevent, (%s evtowner) AS evtowner, "
7296  "array_to_string(array("
7297  "select quote_literal(x) "
7298  " from unnest(evttags) as t(x)), ', ') as evttags, "
7299  "e.evtfoid::regproc as evtfname "
7300  "FROM pg_event_trigger e "
7301  "ORDER BY e.oid",
7303 
7304  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7305 
7306  ntups = PQntuples(res);
7307 
7308  *numEventTriggers = ntups;
7309 
7310  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
7311 
7312  i_tableoid = PQfnumber(res, "tableoid");
7313  i_oid = PQfnumber(res, "oid");
7314  i_evtname = PQfnumber(res, "evtname");
7315  i_evtevent = PQfnumber(res, "evtevent");
7316  i_evtowner = PQfnumber(res, "evtowner");
7317  i_evttags = PQfnumber(res, "evttags");
7318  i_evtfname = PQfnumber(res, "evtfname");
7319  i_evtenabled = PQfnumber(res, "evtenabled");
7320 
7321  for (i = 0; i < ntups; i++)
7322  {
7323  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
7324  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7325  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7326  AssignDumpId(&evtinfo[i].dobj);
7327  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
7328  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
7329  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
7330  evtinfo[i].evtowner = pg_strdup(PQgetvalue(res, i, i_evtowner));
7331  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
7332  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
7333  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
7334 
7335  /* Decide whether we want to dump it */
7336  selectDumpableObject(&(evtinfo[i].dobj), fout);
7337 
7338  /* Event Triggers do not currently have ACLs. */
7339  evtinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7340  }
7341 
7342  PQclear(res);
7343 
7344  destroyPQExpBuffer(query);
7345 
7346  return evtinfo;
7347 }
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:1657
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
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:17728
static const char * username_subquery
Definition: pg_dump.c:96
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:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
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:185
void getExtendedStatistics ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 6666 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, NULL, 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().

6667 {
6668  int i,
6669  j;
6670  PQExpBuffer query;
6671  PGresult *res;
6672  StatsExtInfo *statsextinfo;
6673  int ntups;
6674  int i_tableoid;
6675  int i_oid;
6676  int i_stxname;
6677  int i_stxdef;
6678 
6679  /* Extended statistics were new in v10 */
6680  if (fout->remoteVersion < 100000)
6681  return;
6682 
6683  query = createPQExpBuffer();
6684 
6685  for (i = 0; i < numTables; i++)
6686  {
6687  TableInfo *tbinfo = &tblinfo[i];
6688 
6689  /*
6690  * Only plain tables, materialized views, foreign tables and
6691  * partitioned tables can have extended statistics.
6692  */
6693  if (tbinfo->relkind != RELKIND_RELATION &&
6694  tbinfo->relkind != RELKIND_MATVIEW &&
6695  tbinfo->relkind != RELKIND_FOREIGN_TABLE &&
6697  continue;
6698 
6699  /*
6700  * Ignore extended statistics of tables whose definitions are not to
6701  * be dumped.
6702  */
6703  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6704  continue;
6705 
6706  if (g_verbose)
6707  write_msg(NULL, "reading extended statistics for table \"%s.%s\"\n",
6708  tbinfo->dobj.namespace->dobj.name,
6709  tbinfo->dobj.name);
6710 
6711  /* Make sure we are in proper schema so stadef is right */
6712  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6713 
6714  resetPQExpBuffer(query);
6715 
6716  appendPQExpBuffer(query,
6717  "SELECT "
6718  "tableoid, "
6719  "oid, "
6720  "stxname, "
6721  "pg_catalog.pg_get_statisticsobjdef(oid) AS stxdef "
6722  "FROM pg_statistic_ext "
6723  "WHERE stxrelid = '%u' "
6724  "ORDER BY stxname", tbinfo->dobj.catId.oid);
6725 
6726  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6727 
6728  ntups = PQntuples(res);
6729 
6730  i_tableoid = PQfnumber(res, "tableoid");
6731  i_oid = PQfnumber(res, "oid");
6732  i_stxname = PQfnumber(res, "stxname");
6733  i_stxdef = PQfnumber(res, "stxdef");
6734 
6735  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
6736 
6737  for (j = 0; j < ntups; j++)
6738  {
6739  statsextinfo[j].dobj.objType = DO_STATSEXT;
6740  statsextinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
6741  statsextinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
6742  AssignDumpId(&statsextinfo[j].dobj);
6743  statsextinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_stxname));
6744  statsextinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6745  statsextinfo[j].statsexttable = tbinfo;
6746  statsextinfo[j].statsextdef = pg_strdup(PQgetvalue(res, j, i_stxdef));
6747  }
6748 
6749  PQclear(res);
6750  }
6751 
6752  destroyPQExpBuffer(query);
6753 }
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:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * statsextdef
Definition: pg_dump.h:373
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:2673
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:17728
#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:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
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:91
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:185
void getExtensionMembership ( Archive fout,
ExtensionInfo  extinfo[],
int  numExtensions 
)

Definition at line 17092 of file pg_dump.c.

References appendPQExpBufferStr(), atooid, _dumpableObject::catId, _extensionMemberId::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _extensionInfo::dobj, ExecuteSqlQuery(), _extensionMemberId::ext, extmembers, findExtensionByOid(), i, NULL, CatalogId::oid, pg_malloc(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), selectSourceSchema(), setExtensionMembership(), and CatalogId::tableoid.

Referenced by getSchemaData().

17094 {
17095  PQExpBuffer query;
17096  PGresult *res;
17097  int ntups,
17098  nextmembers,
17099  i;
17100  int i_classid,
17101  i_objid,
17102  i_refobjid;
17104  ExtensionInfo *ext;
17105 
17106  /* Nothing to do if no extensions */
17107  if (numExtensions == 0)
17108  return;
17109 
17110  /* Make sure we are in proper schema */
17111  selectSourceSchema(fout, "pg_catalog");
17112 
17113  query = createPQExpBuffer();
17114 
17115  /* refclassid constraint is redundant but may speed the search */
17116  appendPQExpBufferStr(query, "SELECT "
17117  "classid, objid, refobjid "
17118  "FROM pg_depend "
17119  "WHERE refclassid = 'pg_extension'::regclass "
17120  "AND deptype = 'e' "
17121  "ORDER BY 3");
17122 
17123  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
17124 
17125  ntups = PQntuples(res);
17126 
17127  i_classid = PQfnumber(res, "classid");
17128  i_objid = PQfnumber(res, "objid");
17129  i_refobjid = PQfnumber(res, "refobjid");
17130 
17131  extmembers = (ExtensionMemberId *) pg_malloc(ntups * sizeof(ExtensionMemberId));
17132  nextmembers = 0;
17133 
17134  /*
17135  * Accumulate data into extmembers[].
17136  *
17137  * Since we ordered the SELECT by referenced ID, we can expect that
17138  * multiple entries for the same extension will appear together; this
17139  * saves on searches.
17140  */
17141  ext = NULL;
17142 
17143  for (i = 0; i < ntups; i++)
17144  {
17145  CatalogId objId;
17146  Oid extId;
17147 
17148  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
17149  objId.oid = atooid(PQgetvalue(res, i, i_objid));
17150  extId = atooid(PQgetvalue(res, i, i_refobjid));
17151 
17152  if (ext == NULL ||
17153  ext->dobj.catId.oid != extId)
17154  ext = findExtensionByOid(extId);
17155 
17156  if (ext == NULL)
17157  {
17158  /* shouldn't happen */
17159  fprintf(stderr, "could not find referenced extension %u\n", extId);
17160  continue;
17161  }
17162 
17163  extmembers[nextmembers].catId = objId;
17164  extmembers[nextmembers].ext = ext;
17165  nextmembers++;
17166  }
17167 
17168  PQclear(res);
17169 
17170  /* Remember the data for use later */
17171  setExtensionMembership(extmembers, nextmembers);
17172 
17173  destroyPQExpBuffer(query);
17174 }
ExtensionInfo * ext
Definition: pg_dump.h:621
DumpableObject dobj
Definition: pg_dump.h:155
Oid tableoid
Definition: pg_backup.h:225
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void setExtensionMembership(ExtensionMemberId *extmems, int nextmems)
Definition: common.c:817
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:17728
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:2781
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:806
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
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
ExtensionInfo* getExtensions ( Archive fout,
int *  numExtensions 
)

Definition at line 4237 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, NULL, _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().

4238 {
4239  DumpOptions *dopt = fout->dopt;
4240  PGresult *res;
4241  int ntups;
4242  int i;
4243  PQExpBuffer query;
4244  ExtensionInfo *extinfo;
4245  int i_tableoid;
4246  int i_oid;
4247  int i_extname;
4248  int i_nspname;
4249  int i_extrelocatable;
4250  int i_extversion;
4251  int i_extconfig;
4252  int i_extcondition;
4253 
4254  /*
4255  * Before 9.1, there are no extensions.
4256  */
4257  if (fout->remoteVersion < 90100)
4258  {
4259  *numExtensions = 0;
4260  return NULL;
4261  }
4262 
4263  query = createPQExpBuffer();
4264 
4265  /* Make sure we are in proper schema */
4266  selectSourceSchema(fout, "pg_catalog");
4267 
4268  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
4269  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
4270  "FROM pg_extension x "
4271  "JOIN pg_namespace n ON n.oid = x.extnamespace");
4272 
4273  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4274 
4275  ntups = PQntuples(res);
4276 
4277  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
4278 
4279  i_tableoid = PQfnumber(res, "tableoid");
4280  i_oid = PQfnumber(res, "oid");
4281  i_extname = PQfnumber(res, "extname");
4282  i_nspname = PQfnumber(res, "nspname");
4283  i_extrelocatable = PQfnumber(res, "extrelocatable");
4284  i_extversion = PQfnumber(res, "extversion");
4285  i_extconfig = PQfnumber(res, "extconfig");
4286  i_extcondition = PQfnumber(res, "extcondition");
4287 
4288  for (i = 0; i < ntups; i++)
4289  {
4290  extinfo[i].dobj.objType = DO_EXTENSION;
4291  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4292  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4293  AssignDumpId(&extinfo[i].dobj);
4294  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
4295  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
4296  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
4297  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
4298  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
4299  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
4300 
4301  /* Decide whether we want to dump it */
4302  selectDumpableExtension(&(extinfo[i]), dopt);
4303  }
4304 
4305  PQclear(res);
4306  destroyPQExpBuffer(query);
4307 
4308  *numExtensions = ntups;
4309 
4310  return extinfo;
4311 }
char * name
Definition: pg_dump.h:133
DumpableObject dobj
Definition: pg_dump.h:155
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpOptions * dopt
Definition: pg_backup.h:180
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:17728
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:1618
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * extcondition
Definition: pg_dump.h:160
#define NULL
Definition: c.h:229
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:185
char * extversion
Definition: pg_dump.h:158
FdwInfo* getForeignDataWrappers ( Archive fout,
int *  numForeignDataWrappers 
)

Definition at line 8584 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, NULL, _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().

8585 {
8586  DumpOptions *dopt = fout->dopt;
8587  PGresult *res;
8588  int ntups;
8589  int i;
8590  PQExpBuffer query;
8591  FdwInfo *fdwinfo;
8592  int i_tableoid;
8593  int i_oid;
8594  int i_fdwname;
8595  int i_rolname;
8596  int i_fdwhandler;
8597  int i_fdwvalidator;
8598  int i_fdwacl;
8599  int i_rfdwacl;
8600  int i_initfdwacl;
8601  int i_initrfdwacl;
8602  int i_fdwoptions;
8603 
8604  /* Before 8.4, there are no foreign-data wrappers */
8605  if (fout->remoteVersion < 80400)
8606  {
8607  *numForeignDataWrappers = 0;
8608  return NULL;
8609  }
8610 
8611  query = createPQExpBuffer();
8612 
8613  /* Make sure we are in proper schema */
8614  selectSourceSchema(fout, "pg_catalog");
8615 
8616  if (fout->remoteVersion >= 90600)
8617  {
8618  PQExpBuffer acl_subquery = createPQExpBuffer();
8619  PQExpBuffer racl_subquery = createPQExpBuffer();
8620  PQExpBuffer initacl_subquery = createPQExpBuffer();
8621  PQExpBuffer initracl_subquery = createPQExpBuffer();
8622 
8623  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8624  initracl_subquery, "f.fdwacl", "f.fdwowner", "'F'",
8625  dopt->binary_upgrade);
8626 
8627  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.fdwname, "
8628  "(%s f.fdwowner) AS rolname, "
8629  "f.fdwhandler::pg_catalog.regproc, "
8630  "f.fdwvalidator::pg_catalog.regproc, "
8631  "%s AS fdwacl, "
8632  "%s AS rfdwacl, "
8633  "%s AS initfdwacl, "
8634  "%s AS initrfdwacl, "
8635  "array_to_string(ARRAY("
8636  "SELECT quote_ident(option_name) || ' ' || "
8637  "quote_literal(option_value) "
8638  "FROM pg_options_to_table(f.fdwoptions) "
8639  "ORDER BY option_name"
8640  "), E',\n ') AS fdwoptions "
8641  "FROM pg_foreign_data_wrapper f "
8642  "LEFT JOIN pg_init_privs pip ON "
8643  "(f.oid = pip.objoid "
8644  "AND pip.classoid = 'pg_foreign_data_wrapper'::regclass "
8645  "AND pip.objsubid = 0) ",
8647  acl_subquery->data,
8648  racl_subquery->data,
8649  initacl_subquery->data,
8650  initracl_subquery->data);
8651 
8652  destroyPQExpBuffer(acl_subquery);
8653  destroyPQExpBuffer(racl_subquery);
8654  destroyPQExpBuffer(initacl_subquery);
8655  destroyPQExpBuffer(initracl_subquery);
8656  }
8657  else if (fout->remoteVersion >= 90100)
8658  {
8659  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8660  "(%s fdwowner) AS rolname, "
8661  "fdwhandler::pg_catalog.regproc, "
8662  "fdwvalidator::pg_catalog.regproc, fdwacl, "
8663  "NULL as rfdwacl, "
8664  "NULL as initfdwacl, NULL AS initrfdwacl, "
8665  "array_to_string(ARRAY("
8666  "SELECT quote_ident(option_name) || ' ' || "
8667  "quote_literal(option_value) "
8668  "FROM pg_options_to_table(fdwoptions) "
8669  "ORDER BY option_name"
8670  "), E',\n ') AS fdwoptions "
8671  "FROM pg_foreign_data_wrapper",
8673  }
8674  else
8675  {
8676  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8677  "(%s fdwowner) AS rolname, "
8678  "'-' AS fdwhandler, "
8679  "fdwvalidator::pg_catalog.regproc, fdwacl, "
8680  "NULL as rfdwacl, "
8681  "NULL as initfdwacl, NULL AS initrfdwacl, "
8682  "array_to_string(ARRAY("
8683  "SELECT quote_ident(option_name) || ' ' || "
8684  "quote_literal(option_value) "
8685  "FROM pg_options_to_table(fdwoptions) "
8686  "ORDER BY option_name"
8687  "), E',\n ') AS fdwoptions "
8688  "FROM pg_foreign_data_wrapper",
8690  }
8691 
8692  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8693 
8694  ntups = PQntuples(res);
8695  *numForeignDataWrappers = ntups;
8696 
8697  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
8698 
8699  i_tableoid = PQfnumber(res, "tableoid");
8700  i_oid = PQfnumber(res, "oid");
8701  i_fdwname = PQfnumber(res, "fdwname");
8702  i_rolname = PQfnumber(res, "rolname");
8703  i_fdwhandler = PQfnumber(res, "fdwhandler");
8704  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
8705  i_fdwacl = PQfnumber(res, "fdwacl");
8706  i_rfdwacl = PQfnumber(res, "rfdwacl");
8707  i_initfdwacl = PQfnumber(res, "initfdwacl");
8708  i_initrfdwacl = PQfnumber(res, "initrfdwacl");
8709  i_fdwoptions = PQfnumber(res, "fdwoptions");
8710 
8711  for (i = 0; i < ntups; i++)
8712  {
8713  fdwinfo[i].dobj.objType = DO_FDW;
8714  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8715  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8716  AssignDumpId(&fdwinfo[i].dobj);
8717  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
8718  fdwinfo[i].dobj.namespace = NULL;
8719  fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
8720  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
8721  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
8722  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
8723  fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
8724  fdwinfo[i].rfdwacl = pg_strdup(PQgetvalue(res, i, i_rfdwacl));
8725  fdwinfo[i].initfdwacl = pg_strdup(PQgetvalue(res, i, i_initfdwacl));
8726  fdwinfo[i].initrfdwacl = pg_strdup(PQgetvalue(res, i, i_initrfdwacl));
8727 
8728  /* Decide whether we want to dump it */
8729  selectDumpableObject(&(fdwinfo[i].dobj), fout);
8730 
8731  /* Do not try to dump ACL if no ACL exists. */
8732  if (PQgetisnull(res, i, i_fdwacl) && PQgetisnull(res, i, i_rfdwacl) &&
8733  PQgetisnull(res, i, i_initfdwacl) &&
8734  PQgetisnull(res, i, i_initrfdwacl))
8735  fdwinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8736  }
8737 
8738  PQclear(res);
8739 
8740  destroyPQExpBuffer(query);
8741 
8742  return fdwinfo;
8743 }
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:1657
Oid tableoid
Definition: pg_backup.h:225
char * fdwhandler
Definition: pg_dump.h:515
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:2673
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:180
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:695
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:17728
static const char * username_subquery
Definition: pg_dump.c:96
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:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * initfdwacl
Definition: pg_dump.h:520
Definition: pg_dump.h:73
#define NULL
Definition: c.h:229
#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:3092
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:185
ForeignServerInfo* getForeignServers ( Archive fout,
int *  numForeignServers 
)

Definition at line 8753 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, NULL, _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().

8754 {
8755  DumpOptions *dopt = fout->dopt;
8756  PGresult *res;
8757  int ntups;
8758  int i;
8759  PQExpBuffer query;
8760  ForeignServerInfo *srvinfo;
8761  int i_tableoid;
8762  int i_oid;
8763  int i_srvname;
8764  int i_rolname;
8765  int i_srvfdw;
8766  int i_srvtype;
8767  int i_srvversion;
8768  int i_srvacl;
8769  int i_rsrvacl;
8770  int i_initsrvacl;
8771  int i_initrsrvacl;
8772  int i_srvoptions;
8773 
8774  /* Before 8.4, there are no foreign servers */
8775  if (fout->remoteVersion < 80400)
8776  {
8777  *numForeignServers = 0;
8778  return NULL;
8779  }
8780 
8781  query = createPQExpBuffer();
8782 
8783  /* Make sure we are in proper schema */
8784  selectSourceSchema(fout, "pg_catalog");
8785 
8786  if (fout->remoteVersion >= 90600)
8787  {
8788  PQExpBuffer acl_subquery = createPQExpBuffer();
8789  PQExpBuffer racl_subquery = createPQExpBuffer();
8790  PQExpBuffer initacl_subquery = createPQExpBuffer();
8791  PQExpBuffer initracl_subquery = createPQExpBuffer();
8792 
8793  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8794  initracl_subquery, "f.srvacl", "f.srvowner", "'S'",
8795  dopt->binary_upgrade);
8796 
8797  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.srvname, "
8798  "(%s f.srvowner) AS rolname, "
8799  "f.srvfdw, f.srvtype, f.srvversion, "
8800  "%s AS srvacl, "
8801  "%s AS rsrvacl, "
8802  "%s AS initsrvacl, "
8803  "%s AS initrsrvacl, "
8804  "array_to_string(ARRAY("
8805  "SELECT quote_ident(option_name) || ' ' || "
8806  "quote_literal(option_value) "
8807  "FROM pg_options_to_table(f.srvoptions) "
8808  "ORDER BY option_name"
8809  "), E',\n ') AS srvoptions "
8810  "FROM pg_foreign_server f "
8811  "LEFT JOIN pg_init_privs pip "
8812  "ON (f.oid = pip.objoid "
8813  "AND pip.classoid = 'pg_foreign_server'::regclass "
8814  "AND pip.objsubid = 0) ",
8816  acl_subquery->data,
8817  racl_subquery->data,
8818  initacl_subquery->data,
8819  initracl_subquery->data);
8820 
8821  destroyPQExpBuffer(acl_subquery);
8822  destroyPQExpBuffer(racl_subquery);
8823  destroyPQExpBuffer(initacl_subquery);
8824  destroyPQExpBuffer(initracl_subquery);
8825  }
8826  else
8827  {
8828  appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
8829  "(%s srvowner) AS rolname, "
8830  "srvfdw, srvtype, srvversion, srvacl, "
8831  "NULL AS rsrvacl, "
8832  "NULL AS initsrvacl, NULL AS initrsrvacl, "
8833  "array_to_string(ARRAY("
8834  "SELECT quote_ident(option_name) || ' ' || "
8835  "quote_literal(option_value) "
8836  "FROM pg_options_to_table(srvoptions) "
8837  "ORDER BY option_name"
8838  "), E',\n ') AS srvoptions "
8839  "FROM pg_foreign_server",
8841  }
8842 
8843  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8844 
8845  ntups = PQntuples(res);
8846  *numForeignServers = ntups;
8847 
8848  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
8849 
8850  i_tableoid = PQfnumber(res, "tableoid");
8851  i_oid = PQfnumber(res, "oid");
8852  i_srvname = PQfnumber(res, "srvname");
8853  i_rolname = PQfnumber(res, "rolname");
8854  i_srvfdw = PQfnumber(res, "srvfdw");
8855  i_srvtype = PQfnumber(res, "srvtype");
8856  i_srvversion = PQfnumber(res, "srvversion");
8857  i_srvacl = PQfnumber(res, "srvacl");
8858  i_rsrvacl = PQfnumber(res, "rsrvacl");
8859  i_initsrvacl = PQfnumber(res, "initsrvacl");
8860  i_initrsrvacl = PQfnumber(res, "initrsrvacl");
8861  i_srvoptions = PQfnumber(res, "srvoptions");
8862 
8863  for (i = 0; i < ntups; i++)
8864  {
8865  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
8866  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8867  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8868  AssignDumpId(&srvinfo[i].dobj);
8869  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
8870  srvinfo[i].dobj.namespace = NULL;
8871  srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
8872  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
8873  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
8874  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
8875  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
8876  srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl));
8877  srvinfo[i].rsrvacl = pg_strdup(PQgetvalue(res, i, i_rsrvacl));
8878  srvinfo[i].initsrvacl = pg_strdup(PQgetvalue(res, i, i_initsrvacl));
8879  srvinfo[i].initrsrvacl = pg_strdup(PQgetvalue(res, i, i_initrsrvacl));
8880 
8881  /* Decide whether we want to dump it */
8882  selectDumpableObject(&(srvinfo[i].dobj), fout);
8883 
8884  /* Do not try to dump ACL if no ACL exists. */
8885  if (PQgetisnull(res, i, i_srvacl) && PQgetisnull(res, i, i_rsrvacl) &&
8886  PQgetisnull(res, i, i_initsrvacl) &&
8887  PQgetisnull(res, i, i_initrsrvacl))
8888  srvinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8889  }
8890 
8891  PQclear(res);
8892 
8893  destroyPQExpBuffer(query);
8894 
8895  return srvinfo;
8896 }
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:1657
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
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:180
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:695
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:17728
static const char * username_subquery
Definition: pg_dump.c:96
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:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
#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:3092
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:185
FuncInfo* getFuncs ( Archive fout,
int *  numFuncs 
)

Definition at line 5256 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, NULL, _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().

5257 {
5258  DumpOptions *dopt = fout->dopt;
5259  PGresult *res;
5260  int ntups;
5261  int i;
5262  PQExpBuffer query = createPQExpBuffer();
5263  FuncInfo *finfo;
5264  int i_tableoid;
5265  int i_oid;
5266  int i_proname;
5267  int i_pronamespace;
5268  int i_rolname;
5269  int i_prolang;
5270  int i_pronargs;
5271  int i_proargtypes;
5272  int i_prorettype;
5273  int i_proacl;
5274  int i_rproacl;
5275  int i_initproacl;
5276  int i_initrproacl;
5277 
5278  /* Make sure we are in proper schema */
5279  selectSourceSchema(fout, "pg_catalog");
5280 
5281  /*
5282  * Find all interesting functions. This is a bit complicated:
5283  *
5284  * 1. Always exclude aggregates; those are handled elsewhere.
5285  *
5286  * 2. Always exclude functions that are internally dependent on something
5287  * else, since presumably those will be created as a result of creating
5288  * the something else. This currently acts only to suppress constructor
5289  * functions for range types (so we only need it in 9.2 and up). Note
5290  * this is OK only because the constructors don't have any dependencies
5291  * the range type doesn't have; otherwise we might not get creation
5292  * ordering correct.
5293  *
5294  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
5295  * they're members of extensions and we are in binary-upgrade mode then
5296  * include them, since we want to dump extension members individually in
5297  * that mode. Also, if they are used by casts or transforms then we need
5298  * to gather the information about them, though they won't be dumped if
5299  * they are built-in. Also, in 9.6 and up, include functions in
5300  * pg_catalog if they have an ACL different from what's shown in
5301  * pg_init_privs.
5302  */
5303  if (fout->remoteVersion >= 90600)
5304  {
5305  PQExpBuffer acl_subquery = createPQExpBuffer();
5306  PQExpBuffer racl_subquery = createPQExpBuffer();
5307  PQExpBuffer initacl_subquery = createPQExpBuffer();
5308  PQExpBuffer initracl_subquery = createPQExpBuffer();
5309 
5310  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5311  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5312  dopt->binary_upgrade);
5313 
5314  appendPQExpBuffer(query,
5315  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
5316  "p.pronargs, p.proargtypes, p.prorettype, "
5317  "%s AS proacl, "
5318  "%s AS rproacl, "
5319  "%s AS initproacl, "
5320  "%s AS initrproacl, "
5321  "p.pronamespace, "
5322  "(%s p.proowner) AS rolname "
5323  "FROM pg_proc p "
5324  "LEFT JOIN pg_init_privs pip ON "
5325  "(p.oid = pip.objoid "
5326  "AND pip.classoid = 'pg_proc'::regclass "
5327  "AND pip.objsubid = 0) "
5328  "WHERE NOT proisagg"
5329  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5330  "WHERE classid = 'pg_proc'::regclass AND "
5331  "objid = p.oid AND deptype = 'i')"
5332  "\n AND ("
5333  "\n pronamespace != "
5334  "(SELECT oid FROM pg_namespace "
5335  "WHERE nspname = 'pg_catalog')"
5336  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5337  "\n WHERE pg_cast.oid > %u "
5338  "\n AND p.oid = pg_cast.castfunc)"
5339  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5340  "\n WHERE pg_transform.oid > %u AND "
5341  "\n (p.oid = pg_transform.trffromsql"
5342  "\n OR p.oid = pg_transform.trftosql))",
5343  acl_subquery->data,
5344  racl_subquery->data,
5345  initacl_subquery->data,
5346  initracl_subquery->data,
5350  if (dopt->binary_upgrade)
5351  appendPQExpBufferStr(query,
5352  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5353  "classid = 'pg_proc'::regclass AND "
5354  "objid = p.oid AND "
5355  "refclassid = 'pg_extension'::regclass AND "
5356  "deptype = 'e')");
5357  appendPQExpBufferStr(query,
5358  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
5359  appendPQExpBufferChar(query, ')');
5360 
5361  destroyPQExpBuffer(acl_subquery);
5362  destroyPQExpBuffer(racl_subquery);
5363  destroyPQExpBuffer(initacl_subquery);
5364  destroyPQExpBuffer(initracl_subquery);
5365  }
5366  else
5367  {
5368  appendPQExpBuffer(query,
5369  "SELECT tableoid, oid, proname, prolang, "
5370  "pronargs, proargtypes, prorettype, proacl, "
5371  "NULL as rproacl, "
5372  "NULL as initproacl, NULL AS initrproacl, "
5373  "pronamespace, "
5374  "(%s proowner) AS rolname "
5375  "FROM pg_proc p "
5376  "WHERE NOT proisagg",
5378  if (fout->remoteVersion >= 90200)
5379  appendPQExpBufferStr(query,
5380  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5381  "WHERE classid = 'pg_proc'::regclass AND "
5382  "objid = p.oid AND deptype = 'i')");
5383  appendPQExpBuffer(query,
5384  "\n AND ("
5385  "\n pronamespace != "
5386  "(SELECT oid FROM pg_namespace "
5387  "WHERE nspname = 'pg_catalog')"
5388  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5389  "\n WHERE pg_cast.oid > '%u'::oid"
5390  "\n AND p.oid = pg_cast.castfunc)",
5392 
5393  if (fout->remoteVersion >= 90500)
5394  appendPQExpBuffer(query,
5395  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5396  "\n WHERE pg_transform.oid > '%u'::oid"
5397  "\n AND (p.oid = pg_transform.trffromsql"
5398  "\n OR p.oid = pg_transform.trftosql))",
5400 
5401  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5402  appendPQExpBufferStr(query,
5403  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5404  "classid = 'pg_proc'::regclass AND "
5405  "objid = p.oid AND "
5406  "refclassid = 'pg_extension'::regclass AND "
5407  "deptype = 'e')");
5408  appendPQExpBufferChar(query, ')');
5409  }
5410 
5411  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5412 
5413  ntups = PQntuples(res);
5414 
5415  *numFuncs = ntups;
5416 
5417  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
5418 
5419  i_tableoid = PQfnumber(res, "tableoid");
5420  i_oid = PQfnumber(res, "oid");
5421  i_proname = PQfnumber(res, "proname");
5422  i_pronamespace = PQfnumber(res, "pronamespace");
5423  i_rolname = PQfnumber(res, "rolname");
5424  i_prolang = PQfnumber(res, "prolang");
5425  i_pronargs = PQfnumber(res, "pronargs");
5426  i_proargtypes = PQfnumber(res, "proargtypes");
5427  i_prorettype = PQfnumber(res, "prorettype");
5428  i_proacl = PQfnumber(res, "proacl");
5429  i_rproacl = PQfnumber(res, "rproacl");
5430  i_initproacl = PQfnumber(res, "initproacl");
5431  i_initrproacl = PQfnumber(res, "initrproacl");
5432 
5433  for (i = 0; i < ntups; i++)
5434  {
5435  finfo[i].dobj.objType = DO_FUNC;
5436  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5437  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5438  AssignDumpId(&finfo[i].dobj);
5439  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
5440  finfo[i].dobj.namespace =
5441  findNamespace(fout,
5442  atooid(PQgetvalue(res, i, i_pronamespace)));
5443  finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5444  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
5445  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
5446  finfo[i].proacl = pg_strdup(PQgetvalue(res, i, i_proacl));
5447  finfo[i].rproacl = pg_strdup(PQgetvalue(res, i, i_rproacl));
5448  finfo[i].initproacl = pg_strdup(PQgetvalue(res, i, i_initproacl));
5449  finfo[i].initrproacl = pg_strdup(PQgetvalue(res, i, i_initrproacl));
5450  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
5451  if (finfo[i].nargs == 0)
5452  finfo[i].argtypes = NULL;
5453  else
5454  {
5455  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
5456  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5457  finfo[i].argtypes, finfo[i].nargs);
5458  }
5459 
5460  /* Decide whether we want to dump it */
5461  selectDumpableObject(&(finfo[i].dobj), fout);
5462 
5463  /* Do not try to dump ACL if no ACL exists. */
5464  if (PQgetisnull(res, i, i_proacl) && PQgetisnull(res, i, i_rproacl) &&
5465  PQgetisnull(res, i, i_initproacl) &&
5466  PQgetisnull(res, i, i_initrproacl))
5467  finfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5468 
5469  if (strlen(finfo[i].rolname) == 0)
5470  write_msg(NULL,
5471  "WARNING: owner of function \"%s\" appears to be invalid\n",
5472  finfo[i].dobj.name);
5473  }
5474 
5475  PQclear(res);
5476 
5477  destroyPQExpBuffer(query);
5478 
5479  return finfo;
5480 }
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:1657
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:4219
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:102
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
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:180
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:695
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:17728
static const char * username_subquery
Definition: pg_dump.c:96
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:948
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
void PQclear(PGresult *res)
Definition: fe-exec.c:650
void write_msg(const char *modulename, const char *fmt,...)
Oid prorettype
Definition: pg_dump.h:203
#define NULL
Definition: c.h:229
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:3092
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:185
void getIndexes ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 6382 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, NULL, 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().

6383 {
6384  int i,
6385  j;
6386  PQExpBuffer query = createPQExpBuffer();
6387  PGresult *res;
6388  IndxInfo *indxinfo;
6389  ConstraintInfo *constrinfo;
6390  int i_tableoid,
6391  i_oid,
6392  i_indexname,
6393  i_indexdef,
6394  i_indnkeys,
6395  i_indkey,
6396  i_indisclustered,
6397  i_indisreplident,
6398  i_contype,
6399  i_conname,
6400  i_condeferrable,
6401  i_condeferred,
6402  i_contableoid,
6403  i_conoid,
6404  i_condef,
6405  i_tablespace,
6406  i_indreloptions,
6407  i_relpages;
6408  int ntups;
6409 
6410  for (i = 0; i < numTables; i++)
6411  {
6412  TableInfo *tbinfo = &tblinfo[i];
6413 
6414  /* Only plain tables and materialized views have indexes. */
6415  if (tbinfo->relkind != RELKIND_RELATION &&
6416  tbinfo->relkind != RELKIND_MATVIEW)
6417  continue;
6418  if (!tbinfo->hasindex)
6419  continue;
6420 
6421  /* Ignore indexes of tables whose definitions are not to be dumped */
6422  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6423  continue;
6424 
6425  if (g_verbose)
6426  write_msg(NULL, "reading indexes for table \"%s.%s\"\n",
6427  tbinfo->dobj.namespace->dobj.name,
6428  tbinfo->dobj.name);
6429 
6430  /* Make sure we are in proper schema so indexdef is right */
6431  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6432 
6433  /*
6434  * The point of the messy-looking outer join is to find a constraint
6435  * that is related by an internal dependency link to the index. If we
6436  * find one, create a CONSTRAINT entry linked to the INDEX entry. We
6437  * assume an index won't have more than one internal dependency.
6438  *
6439  * As of 9.0 we don't need to look at pg_depend but can check for a
6440  * match to pg_constraint.conindid. The check on conrelid is
6441  * redundant but useful because that column is indexed while conindid
6442  * is not.
6443  */
6444  resetPQExpBuffer(query);
6445  if (fout->remoteVersion >= 90400)
6446  {
6447  /*
6448  * the test on indisready is necessary in 9.2, and harmless in
6449  * earlier/later versions
6450  */
6451  appendPQExpBuffer(query,
6452  "SELECT t.tableoid, t.oid, "
6453  "t.relname AS indexname, "
6454  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6455  "t.relnatts AS indnkeys, "
6456  "i.indkey, i.indisclustered, "
6457  "i.indisreplident, t.relpages, "
6458  "c.contype, c.conname, "
6459  "c.condeferrable, c.condeferred, "
6460  "c.tableoid AS contableoid, "
6461  "c.oid AS conoid, "
6462  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6463  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6464  "t.reloptions AS indreloptions "
6465  "FROM pg_catalog.pg_index i "
6466  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6467  "LEFT JOIN pg_catalog.pg_constraint c "
6468  "ON (i.indrelid = c.conrelid AND "
6469  "i.indexrelid = c.conindid AND "
6470  "c.contype IN ('p','u','x')) "
6471  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6472  "AND i.indisvalid AND i.indisready "
6473  "ORDER BY indexname",
6474  tbinfo->dobj.catId.oid);
6475  }
6476  else if (fout->remoteVersion >= 90000)
6477  {
6478  /*
6479  * the test on indisready is necessary in 9.2, and harmless in
6480  * earlier/later versions
6481  */
6482  appendPQExpBuffer(query,
6483  "SELECT t.tableoid, t.oid, "
6484  "t.relname AS indexname, "
6485  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6486  "t.relnatts AS indnkeys, "
6487  "i.indkey, i.indisclustered, "
6488  "false AS indisreplident, t.relpages, "
6489  "c.contype, c.conname, "
6490  "c.condeferrable, c.condeferred, "
6491  "c.tableoid AS contableoid, "
6492  "c.oid AS conoid, "
6493  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6494  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6495  "t.reloptions AS indreloptions "
6496  "FROM pg_catalog.pg_index i "
6497  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6498  "LEFT JOIN pg_catalog.pg_constraint c "
6499  "ON (i.indrelid = c.conrelid AND "
6500  "i.indexrelid = c.conindid AND "
6501  "c.contype IN ('p','u','x')) "
6502  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6503  "AND i.indisvalid AND i.indisready "
6504  "ORDER BY indexname",
6505  tbinfo->dobj.catId.oid);
6506  }
6507  else if (fout->remoteVersion >= 80200)
6508  {
6509  appendPQExpBuffer(query,
6510  "SELECT t.tableoid, t.oid, "
6511  "t.relname AS indexname, "
6512  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6513  "t.relnatts AS indnkeys, "
6514  "i.indkey, i.indisclustered, "
6515  "false AS indisreplident, t.relpages, "
6516  "c.contype, c.conname, "
6517  "c.condeferrable, c.condeferred, "
6518  "c.tableoid AS contableoid, "
6519  "c.oid AS conoid, "
6520  "null AS condef, "
6521  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6522  "t.reloptions AS indreloptions "
6523  "FROM pg_catalog.pg_index i "
6524  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6525  "LEFT JOIN pg_catalog.pg_depend d "
6526  "ON (d.classid = t.tableoid "
6527  "AND d.objid = t.oid "
6528  "AND d.deptype = 'i') "
6529  "LEFT JOIN pg_catalog.pg_constraint c "
6530  "ON (d.refclassid = c.tableoid "
6531  "AND d.refobjid = c.oid) "
6532  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6533  "AND i.indisvalid "
6534  "ORDER BY indexname",
6535  tbinfo->dobj.catId.oid);
6536  }
6537  else
6538  {
6539  appendPQExpBuffer(query,
6540  "SELECT t.tableoid, t.oid, "
6541  "t.relname AS indexname, "
6542  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6543  "t.relnatts AS indnkeys, "
6544  "i.indkey, i.indisclustered, "
6545  "false AS indisreplident, t.relpages, "
6546  "c.contype, c.conname, "
6547  "c.condeferrable, c.condeferred, "
6548  "c.tableoid AS contableoid, "
6549  "c.oid AS conoid, "
6550  "null AS condef, "
6551  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6552  "null AS indreloptions "
6553  "FROM pg_catalog.pg_index i "
6554  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6555  "LEFT JOIN pg_catalog.pg_depend d "
6556  "ON (d.classid = t.tableoid "
6557  "AND d.objid = t.oid "
6558  "AND d.deptype = 'i') "
6559  "LEFT JOIN pg_catalog.pg_constraint c "
6560  "ON (d.refclassid = c.tableoid "
6561  "AND d.refobjid = c.oid) "
6562  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6563  "ORDER BY indexname",
6564  tbinfo->dobj.catId.oid);
6565  }
6566 
6567  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6568 
6569  ntups = PQntuples(res);
6570 
6571  i_tableoid = PQfnumber(res, "tableoid");
6572  i_oid = PQfnumber(res, "oid");
6573  i_indexname = PQfnumber(res, "indexname");
6574  i_indexdef = PQfnumber(res, "indexdef");
6575  i_indnkeys = PQfnumber(res, "indnkeys");
6576  i_indkey = PQfnumber(res, "indkey");
6577  i_indisclustered = PQfnumber(res, "indisclustered");
6578  i_indisreplident = PQfnumber(res, "indisreplident");
6579  i_relpages = PQfnumber(res, "relpages");
6580  i_contype = PQfnumber(res, "contype");
6581  i_conname = PQfnumber(res, "conname");
6582  i_condeferrable = PQfnumber(res, "condeferrable");
6583  i_condeferred = PQfnumber(res, "condeferred");
6584  i_contableoid = PQfnumber(res, "contableoid");
6585  i_conoid = PQfnumber(res, "conoid");
6586  i_condef = PQfnumber(res, "condef");
6587  i_tablespace = PQfnumber(res, "tablespace");
6588  i_indreloptions = PQfnumber(res, "indreloptions");
6589 
6590  indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
6591  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
6592 
6593  for (j = 0; j < ntups; j++)
6594  {
6595  char contype;
6596 
6597  indxinfo[j].dobj.objType = DO_INDEX;
6598  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
6599  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
6600  AssignDumpId(&indxinfo[j].dobj);
6601  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
6602  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6603  indxinfo[j].indextable = tbinfo;
6604  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
6605  indxinfo[j].indnkeys = atoi(PQgetvalue(res, j, i_indnkeys));
6606  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
6607  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
6608  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnkeys * sizeof(Oid));
6609  parseOidArray(PQgetvalue(res, j, i_indkey),
6610  indxinfo[j].indkeys, indxinfo[j].indnkeys);
6611  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
6612  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
6613  indxinfo[j].relpages = atoi(PQgetvalue(res, j, i_relpages));
6614  contype = *(PQgetvalue(res, j, i_contype));
6615 
6616  if (contype == 'p' || contype == 'u' || contype == 'x')
6617  {
6618  /*
6619  * If we found a constraint matching the index, create an
6620  * entry for it.
6621  */
6622  constrinfo[j].dobj.objType = DO_CONSTRAINT;
6623  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
6624  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
6625  AssignDumpId(&constrinfo[j].dobj);
6626  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
6627  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6628  constrinfo[j].contable = tbinfo;
6629  constrinfo[j].condomain = NULL;
6630  constrinfo[j].contype = contype;
6631  if (contype == 'x')
6632  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
6633  else
6634  constrinfo[j].condef = NULL;
6635  constrinfo[j].confrelid = InvalidOid;
6636  constrinfo[j].conindex = indxinfo[j].dobj.dumpId;
6637  constrinfo[j].condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
6638  constrinfo[j].condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
6639  constrinfo[j].conislocal = true;
6640  constrinfo[j].separate = true;
6641 
6642  indxinfo[j].indexconstraint = constrinfo[j].dobj.dumpId;
6643  }
6644  else
6645  {
6646  /* Plain secondary index */
6647  indxinfo[j].indexconstraint = 0;
6648  }
6649  }
6650 
6651  PQclear(res);
6652  }
6653 
6654  destroyPQExpBuffer(query);
6655 }
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:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:2673
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:17728
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:948
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
TableInfo * contable
Definition: pg_dump.h:427
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#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
#define NULL
Definition: c.h:229
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:91
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:185
InhInfo* getInherits ( Archive fout,
int *  numInherits 
)

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

6329 {
6330  PGresult *res;
6331  int ntups;
6332  int i;
6333  PQExpBuffer query = createPQExpBuffer();
6334  InhInfo *inhinfo;
6335 
6336  int i_inhrelid;
6337  int i_inhparent;
6338 
6339  /* Make sure we are in proper schema */
6340  selectSourceSchema(fout, "pg_catalog");
6341 
6342  /*
6343  * Find all the inheritance information, excluding implicit inheritance
6344  * via partitioning. We handle that case using getPartitions(), because
6345  * we want more information about partitions than just the parent-child
6346  * relationship.
6347  */
6348  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
6349 
6350  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6351 
6352  ntups = PQntuples(res);
6353 
6354  *numInherits = ntups;
6355 
6356  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6357 
6358  i_inhrelid = PQfnumber(res, "inhrelid");
6359  i_inhparent = PQfnumber(res, "inhparent");
6360 
6361  for (i = 0; i < ntups; i++)
6362  {
6363  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6364  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6365  }
6366 
6367  PQclear(res);
6368 
6369  destroyPQExpBuffer(query);
6370 
6371  return inhinfo;
6372 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:2673
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:17728
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
Oid inhparent
Definition: pg_dump.h:476
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
DumpId getMaxDumpId ( void  )

Definition at line 510 of file common.c.

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

511 {
512  return lastDumpId;
513 }
static DumpId lastDumpId
Definition: common.c:33
NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

Definition at line 4070 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, NULL, _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().

4071 {
4072  DumpOptions *dopt = fout->dopt;
4073  PGresult *res;
4074  int ntups;
4075  int i;
4076  PQExpBuffer query;
4077  NamespaceInfo *nsinfo;
4078  int i_tableoid;
4079  int i_oid;
4080  int i_nspname;
4081  int i_rolname;
4082  int i_nspacl;
4083  int i_rnspacl;
4084  int i_initnspacl;
4085  int i_initrnspacl;
4086 
4087  query = createPQExpBuffer();
4088 
4089  /* Make sure we are in proper schema */
4090  selectSourceSchema(fout, "pg_catalog");
4091 
4092  /*
4093  * we fetch all namespaces including system ones, so that every object we
4094  * read in can be linked to a containing namespace.
4095  */
4096  if (fout->remoteVersion >= 90600)
4097  {
4098  PQExpBuffer acl_subquery = createPQExpBuffer();
4099  PQExpBuffer racl_subquery = createPQExpBuffer();
4100  PQExpBuffer init_acl_subquery = createPQExpBuffer();
4101  PQExpBuffer init_racl_subquery = createPQExpBuffer();
4102 
4103  buildACLQueries(acl_subquery, racl_subquery, init_acl_subquery,
4104  init_racl_subquery, "n.nspacl", "n.nspowner", "'n'",
4105  dopt->binary_upgrade);
4106 
4107  appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, "
4108  "(%s nspowner) AS rolname, "
4109  "%s as nspacl, "
4110  "%s as rnspacl, "
4111  "%s as initnspacl, "
4112  "%s as initrnspacl "
4113  "FROM pg_namespace n "
4114  "LEFT JOIN pg_init_privs pip "
4115  "ON (n.oid = pip.objoid "
4116  "AND pip.classoid = 'pg_namespace'::regclass "
4117  "AND pip.objsubid = 0",
4119  acl_subquery->data,
4120  racl_subquery->data,
4121  init_acl_subquery->data,
4122  init_racl_subquery->data);
4123 
4124  /*
4125  * When we are doing a 'clean' run, we will be dropping and recreating
4126  * the 'public' schema (the only object which has that kind of
4127  * treatment in the backend and which has an entry in pg_init_privs)
4128  * and therefore we should not consider any initial privileges in
4129  * pg_init_privs in that case.
4130  *
4131  * See pg_backup_archiver.c:_printTocEntry() for the details on why
4132  * the public schema is special in this regard.
4133  *
4134  * Note that if the public schema is dropped and re-created, this is
4135  * essentially a no-op because the new public schema won't have an
4136  * entry in pg_init_privs anyway, as the entry will be removed when
4137  * the public schema is dropped.
4138  */
4139  if (dopt->outputClean)
4140  appendPQExpBuffer(query, " AND pip.objoid <> 'public'::regnamespace");
4141 
4142  appendPQExpBuffer(query, ") ");
4143 
4144  destroyPQExpBuffer(acl_subquery);
4145  destroyPQExpBuffer(racl_subquery);
4146  destroyPQExpBuffer(init_acl_subquery);
4147  destroyPQExpBuffer(init_racl_subquery);
4148  }
4149  else
4150  appendPQExpBuffer(query, "SELECT tableoid, oid, nspname, "
4151  "(%s nspowner) AS rolname, "
4152  "nspacl, NULL as rnspacl, "
4153  "NULL AS initnspacl, NULL as initrnspacl "
4154  "FROM pg_namespace",
4156 
4157  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4158 
4159  ntups = PQntuples(res);
4160 
4161  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
4162 
4163  i_tableoid = PQfnumber(res, "tableoid");
4164  i_oid = PQfnumber(res, "oid");
4165  i_nspname = PQfnumber(res, "nspname");
4166  i_rolname = PQfnumber(res, "rolname");
4167  i_nspacl = PQfnumber(res, "nspacl");
4168  i_rnspacl = PQfnumber(res, "rnspacl");
4169  i_initnspacl = PQfnumber(res, "initnspacl");
4170  i_initrnspacl = PQfnumber(res, "initrnspacl");
4171 
4172  for (i = 0; i < ntups; i++)
4173  {
4174  nsinfo[i].dobj.objType = DO_NAMESPACE;
4175  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4176  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4177  AssignDumpId(&nsinfo[i].dobj);
4178  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
4179  nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4180  nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl));
4181  nsinfo[i].rnspacl = pg_strdup(PQgetvalue(res, i, i_rnspacl));
4182  nsinfo[i].initnspacl = pg_strdup(PQgetvalue(res, i, i_initnspacl));
4183  nsinfo[i].initrnspacl = pg_strdup(PQgetvalue(res, i, i_initrnspacl));
4184 
4185  /* Decide whether to dump this namespace */
4186  selectDumpableNamespace(&nsinfo[i], fout);
4187 
4188  /*
4189  * Do not try to dump ACL if the ACL is empty or the default.
4190  *
4191  * This is useful because, for some schemas/objects, the only
4192  * component we are going to try and dump is the ACL and if we can
4193  * remove that then 'dump' goes to zero/false and we don't consider
4194  * this object for dumping at all later on.
4195  */
4196  if (PQgetisnull(res, i, i_nspacl) && PQgetisnull(res, i, i_rnspacl) &&
4197  PQgetisnull(res, i, i_initnspacl) &&
4198  PQgetisnull(res, i, i_initrnspacl))
4199  nsinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4200 
4201  if (strlen(nsinfo[i].rolname) == 0)
4202  write_msg(NULL, "WARNING: owner of schema \"%s\" appears to be invalid\n",
4203  nsinfo[i].dobj.name);
4204  }
4205 
4206  PQclear(res);
4207  destroyPQExpBuffer(query);
4208 
4209  *numNamespaces = ntups;
4210 
4211  return nsinfo;
4212 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
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:180
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:695
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:17728
static const char * username_subquery
Definition: pg_dump.c:96
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1371
void PQclear(PGresult *res)
Definition: fe-exec.c:650
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
int outputClean
Definition: pg_backup.h:164
#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:3092
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:185
OpclassInfo* getOpclasses ( Archive fout,
int *  numOpclasses 
)

Definition at line 4899 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, NULL, _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().

4900 {
4901  PGresult *res;
4902  int ntups;
4903  int i;
4904  PQExpBuffer query = createPQExpBuffer();
4905  OpclassInfo *opcinfo;
4906  int i_tableoid;
4907  int i_oid;
4908  int i_opcname;
4909  int i_opcnamespace;
4910  int i_rolname;
4911 
4912  /*
4913  * find all opclasses, including builtin opclasses; we filter out
4914  * system-defined opclasses at dump-out time.
4915  */
4916 
4917  /* Make sure we are in proper schema */
4918  selectSourceSchema(fout, "pg_catalog");
4919 
4920  appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
4921  "opcnamespace, "
4922  "(%s opcowner) AS rolname "
4923  "FROM pg_opclass",
4925 
4926  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4927 
4928  ntups = PQntuples(res);
4929  *numOpclasses = ntups;
4930 
4931  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
4932 
4933  i_tableoid = PQfnumber(res, "tableoid");
4934  i_oid = PQfnumber(res, "oid");
4935  i_opcname = PQfnumber(res, "opcname");
4936  i_opcnamespace = PQfnumber(res, "opcnamespace");
4937  i_rolname = PQfnumber(res, "rolname");
4938 
4939  for (i = 0; i < ntups; i++)
4940  {
4941  opcinfo[i].dobj.objType = DO_OPCLASS;
4942  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4943  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4944  AssignDumpId(&opcinfo[i].dobj);
4945  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
4946  opcinfo[i].dobj.namespace =
4947  findNamespace(fout,
4948  atooid(PQgetvalue(res, i, i_opcnamespace)));
4949  opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4950 
4951  /* Decide whether we want to dump it */
4952  selectDumpableObject(&(opcinfo[i].dobj), fout);
4953 
4954  /* Op Classes do not currently have ACLs. */
4955  opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4956 
4957  if (strlen(opcinfo[i].rolname) == 0)
4958  write_msg(NULL, "WARNING: owner of operator class \"%s\" appears to be invalid\n",
4959  opcinfo[i].dobj.name);
4960  }
4961 
4962  PQclear(res);
4963 
4964  destroyPQExpBuffer(query);
4965 
4966  return opcinfo;
4967 }
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:1657
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4219
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
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:17728
static const char * username_subquery
Definition: pg_dump.c:96
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:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.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
OprInfo* getOperators ( Archive fout,
int *  numOperators 
)

Definition at line 4577 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, NULL, _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().

4578 {
4579  PGresult *res;
4580  int ntups;
4581  int i;
4582  PQExpBuffer query = createPQExpBuffer();
4583  OprInfo *oprinfo;
4584  int i_tableoid;
4585  int i_oid;
4586  int i_oprname;
4587  int i_oprnamespace;
4588  int i_rolname;
4589  int i_oprkind;
4590  int i_oprcode;
4591 
4592  /*
4593  * find all operators, including builtin operators; we filter out
4594  * system-defined operators at dump-out time.
4595  */
4596 
4597  /* Make sure we are in proper schema */
4598  selectSourceSchema(fout, "pg_catalog");
4599 
4600  appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
4601  "oprnamespace, "
4602  "(%s oprowner) AS rolname, "
4603  "oprkind, "
4604  "oprcode::oid AS oprcode "
4605  "FROM pg_operator",
4607 
4608  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4609 
4610  ntups = PQntuples(res);
4611  *numOprs = ntups;
4612 
4613  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
4614 
4615  i_tableoid = PQfnumber(res, "tableoid");
4616  i_oid = PQfnumber(res, "oid");
4617  i_oprname = PQfnumber(res, "oprname");
4618  i_oprnamespace = PQfnumber(res, "oprnamespace");
4619  i_rolname = PQfnumber(res, "rolname");
4620  i_oprkind = PQfnumber(res, "oprkind");
4621  i_oprcode = PQfnumber(res, "oprcode");
4622 
4623  for (i = 0; i < ntups; i++)
4624  {
4625  oprinfo[i].dobj.objType = DO_OPERATOR;
4626  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4627  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4628  AssignDumpId(&oprinfo[i].dobj);
4629  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
4630  oprinfo[i].dobj.namespace =
4631  findNamespace(fout,
4632  atooid(PQgetvalue(res, i, i_oprnamespace)));
4633  oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4634  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
4635  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
4636 
4637  /* Decide whether we want to dump it */
4638  selectDumpableObject(&(oprinfo[i].dobj), fout);
4639 
4640  /* Operators do not currently have ACLs. */
4641  oprinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4642 
4643  if (strlen(oprinfo[i].rolname) == 0)
4644  write_msg(NULL, "WARNING: owner of operator \"%s\" appears to be invalid\n",
4645  oprinfo[i].dobj.name);
4646  }
4647 
4648  PQclear(res);
4649 
4650  destroyPQExpBuffer(query);
4651 
4652  return oprinfo;
4653 }
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:1657
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4219
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
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:17728
static const char * username_subquery
Definition: pg_dump.c:96
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:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char oprkind
Definition: pg_dump.h:221
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.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
Oid oprcode
Definition: pg_dump.h:222
OpfamilyInfo* getOpfamilies ( Archive fout,
int *  numOpfamilies 
)

Definition at line 4977 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, NULL, _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().

4978 {
4979  PGresult *res;
4980  int ntups;
4981  int i;
4982  PQExpBuffer query;
4983  OpfamilyInfo *opfinfo;
4984  int i_tableoid;
4985  int i_oid;
4986  int i_opfname;
4987  int i_opfnamespace;
4988  int i_rolname;
4989 
4990  /* Before 8.3, there is no separate concept of opfamilies */
4991  if (fout->remoteVersion < 80300)
4992  {
4993  *numOpfamilies = 0;
4994  return NULL;
4995  }
4996 
4997  query = createPQExpBuffer();
4998 
4999  /*
5000  * find all opfamilies, including builtin opfamilies; we filter out
5001  * system-defined opfamilies at dump-out time.
5002  */
5003 
5004  /* Make sure we are in proper schema */
5005  selectSourceSchema(fout, &quo