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 712 of file common.c.

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

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

713 {
714  if (dobj->nDeps >= dobj->allocDeps)
715  {
716  if (dobj->allocDeps <= 0)
717  {
718  dobj->allocDeps = 16;
719  dobj->dependencies = (DumpId *)
720  pg_malloc(dobj->allocDeps * sizeof(DumpId));
721  }
722  else
723  {
724  dobj->allocDeps *= 2;
725  dobj->dependencies = (DumpId *)
726  pg_realloc(dobj->dependencies,
727  dobj->allocDeps * sizeof(DumpId));
728  }
729  }
730  dobj->dependencies[dobj->nDeps++] = refId;
731 }
int DumpId
Definition: pg_backup.h:230
DumpId * dependencies
Definition: pg_dump.h:138
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
void AssignDumpId ( DumpableObject dobj)

Definition at line 476 of file common.c.

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

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

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

Definition at line 803 of file common.c.

References findObjectByOid(), and numCollations.

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

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

Definition at line 825 of file common.c.

References findObjectByOid(), and numExtensions.

Referenced by getExtensionMembership().

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

Definition at line 781 of file common.c.

References findObjectByOid(), and numFuncs.

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

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

Definition at line 814 of file common.c.

References findObjectByOid(), and numNamespaces.

Referenced by findNamespace().

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

Definition at line 558 of file common.c.

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

Referenced by buildMatViewRefreshDependencies(), and getDependencies().

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

Definition at line 540 of file common.c.

References allocedDumpIds.

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

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

Definition at line 792 of file common.c.

References findObjectByOid(), and numOperators.

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

Definition at line 852 of file common.c.

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

Referenced by checkExtensionMembership().

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

Definition at line 759 of file common.c.

References findObjectByOid(), and numTables.

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

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

Definition at line 770 of file common.c.

References findObjectByOid(), and numTypes.

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

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

Definition at line 4933 of file pg_dump.c.

References _accessMethodInfo::amhandler, _accessMethodInfo::amtype, appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_ACCESS_METHOD, _accessMethodInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, selectDumpableAccessMethod(), selectSourceSchema(), and CatalogId::tableoid.

Referenced by getSchemaData().

4934 {
4935  PGresult *res;
4936  int ntups;
4937  int i;
4938  PQExpBuffer query;
4939  AccessMethodInfo *aminfo;
4940  int i_tableoid;
4941  int i_oid;
4942  int i_amname;
4943  int i_amhandler;
4944  int i_amtype;
4945 
4946  /* Before 9.6, there are no user-defined access methods */
4947  if (fout->remoteVersion < 90600)
4948  {
4949  *numAccessMethods = 0;
4950  return NULL;
4951  }
4952 
4953  query = createPQExpBuffer();
4954 
4955  /* Make sure we are in proper schema */
4956  selectSourceSchema(fout, "pg_catalog");
4957 
4958  /* Select all access methods from pg_am table */
4959  appendPQExpBuffer(query, "SELECT tableoid, oid, amname, amtype, "
4960  "amhandler::pg_catalog.regproc AS amhandler "
4961  "FROM pg_am");
4962 
4963  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4964 
4965  ntups = PQntuples(res);
4966  *numAccessMethods = ntups;
4967 
4968  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
4969 
4970  i_tableoid = PQfnumber(res, "tableoid");
4971  i_oid = PQfnumber(res, "oid");
4972  i_amname = PQfnumber(res, "amname");
4973  i_amhandler = PQfnumber(res, "amhandler");
4974  i_amtype = PQfnumber(res, "amtype");
4975 
4976  for (i = 0; i < ntups; i++)
4977  {
4978  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
4979  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4980  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4981  AssignDumpId(&aminfo[i].dobj);
4982  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
4983  aminfo[i].dobj.namespace = NULL;
4984  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
4985  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
4986 
4987  /* Decide whether we want to dump it */
4988  selectDumpableAccessMethod(&(aminfo[i]), fout);
4989 
4990  /* Access methods do not currently have ACLs. */
4991  aminfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4992  }
4993 
4994  PQclear(res);
4995 
4996  destroyPQExpBuffer(query);
4997 
4998  return aminfo;
4999 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpableObject dobj
Definition: pg_dump.h:227
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:1597
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * amhandler
Definition: pg_dump.h:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
AggInfo* getAggregates ( Archive fout,
int *  numAggregates 
)

Definition at line 5175 of file pg_dump.c.

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

Referenced by getSchemaData().

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

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

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

Definition at line 4774 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_COLLATION, _collInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _collInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

4775 {
4776  PGresult *res;
4777  int ntups;
4778  int i;
4779  PQExpBuffer query;
4780  CollInfo *collinfo;
4781  int i_tableoid;
4782  int i_oid;
4783  int i_collname;
4784  int i_collnamespace;
4785  int i_rolname;
4786 
4787  /* Collations didn't exist pre-9.1 */
4788  if (fout->remoteVersion < 90100)
4789  {
4790  *numCollations = 0;
4791  return NULL;
4792  }
4793 
4794  query = createPQExpBuffer();
4795 
4796  /*
4797  * find all collations, including builtin collations; we filter out
4798  * system-defined collations at dump-out time.
4799  */
4800 
4801  /* Make sure we are in proper schema */
4802  selectSourceSchema(fout, "pg_catalog");
4803 
4804  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
4805  "collnamespace, "
4806  "(%s collowner) AS rolname "
4807  "FROM pg_collation",
4809 
4810  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4811 
4812  ntups = PQntuples(res);
4813  *numCollations = ntups;
4814 
4815  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
4816 
4817  i_tableoid = PQfnumber(res, "tableoid");
4818  i_oid = PQfnumber(res, "oid");
4819  i_collname = PQfnumber(res, "collname");
4820  i_collnamespace = PQfnumber(res, "collnamespace");
4821  i_rolname = PQfnumber(res, "rolname");
4822 
4823  for (i = 0; i < ntups; i++)
4824  {
4825  collinfo[i].dobj.objType = DO_COLLATION;
4826  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4827  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4828  AssignDumpId(&collinfo[i].dobj);
4829  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
4830  collinfo[i].dobj.namespace =
4831  findNamespace(fout,
4832  atooid(PQgetvalue(res, i, i_collnamespace)));
4833  collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4834 
4835  /* Decide whether we want to dump it */
4836  selectDumpableObject(&(collinfo[i].dobj), fout);
4837 
4838  /* Collations do not currently have ACLs. */
4839  collinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4840  }
4841 
4842  PQclear(res);
4843 
4844  destroyPQExpBuffer(query);
4845 
4846  return collinfo;
4847 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1663
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4330
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
DumpableObject dobj
Definition: pg_dump.h:246
char * rolname
Definition: pg_dump.h:247
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
static const char * username_subquery
Definition: pg_dump.c:97
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
static int numCollations
Definition: common.c:61
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
void getConstraints ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 6876 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, _constraintInfo::condef, _constraintInfo::condeferrable, _constraintInfo::condeferred, _constraintInfo::condomain, _constraintInfo::confrelid, _constraintInfo::conindex, _constraintInfo::conislocal, _constraintInfo::contable, _constraintInfo::contype, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FK_CONSTRAINT, _tableInfo::dobj, _constraintInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), g_verbose, _tableInfo::hastriggers, i, _dumpableObject::name, numTables, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), resetPQExpBuffer(), selectSourceSchema(), _constraintInfo::separate, CatalogId::tableoid, and write_msg().

Referenced by getSchemaData().

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

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

4858 {
4859  PGresult *res;
4860  int ntups;
4861  int i;
4862  PQExpBuffer query;
4863  ConvInfo *convinfo;
4864  int i_tableoid;
4865  int i_oid;
4866  int i_conname;
4867  int i_connamespace;
4868  int i_rolname;
4869 
4870  query = createPQExpBuffer();
4871 
4872  /*
4873  * find all conversions, including builtin conversions; we filter out
4874  * system-defined conversions at dump-out time.
4875  */
4876 
4877  /* Make sure we are in proper schema */
4878  selectSourceSchema(fout, "pg_catalog");
4879 
4880  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
4881  "connamespace, "
4882  "(%s conowner) AS rolname "
4883  "FROM pg_conversion",
4885 
4886  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4887 
4888  ntups = PQntuples(res);
4889  *numConversions = ntups;
4890 
4891  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
4892 
4893  i_tableoid = PQfnumber(res, "tableoid");
4894  i_oid = PQfnumber(res, "oid");
4895  i_conname = PQfnumber(res, "conname");
4896  i_connamespace = PQfnumber(res, "connamespace");
4897  i_rolname = PQfnumber(res, "rolname");
4898 
4899  for (i = 0; i < ntups; i++)
4900  {
4901  convinfo[i].dobj.objType = DO_CONVERSION;
4902  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4903  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4904  AssignDumpId(&convinfo[i].dobj);
4905  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
4906  convinfo[i].dobj.namespace =
4907  findNamespace(fout,
4908  atooid(PQgetvalue(res, i, i_connamespace)));
4909  convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4910 
4911  /* Decide whether we want to dump it */
4912  selectDumpableObject(&(convinfo[i].dobj), fout);
4913 
4914  /* Conversions do not currently have ACLs. */
4915  convinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4916  }
4917 
4918  PQclear(res);
4919 
4920  destroyPQExpBuffer(query);
4921 
4922  return convinfo;
4923 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1663
Oid tableoid
Definition: pg_backup.h:226
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4330
char * rolname
Definition: pg_dump.h:253
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
static const char * username_subquery
Definition: pg_dump.c:97
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
DumpableObject dobj
Definition: pg_dump.h:252
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
DefaultACLInfo* getDefaultACLs ( Archive fout,
int *  numDefaultACLs 
)

Definition at line 9017 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, buildACLQueries(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, _defaultACLInfo::defaclacl, _defaultACLInfo::defaclobjtype, _defaultACLInfo::defaclrole, destroyPQExpBuffer(), DO_DEFAULT_ACL, _defaultACLInfo::dobj, Archive::dopt, ExecuteSqlQuery(), findNamespace(), i, _defaultACLInfo::initdefaclacl, _defaultACLInfo::initrdefaclacl, InvalidOid, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _defaultACLInfo::rdefaclacl, Archive::remoteVersion, selectDumpableDefaultACL(), selectSourceSchema(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

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

Definition at line 690 of file common.c.

References allocedDumpIds, i, and pg_malloc().

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

691 {
692  int i,
693  j;
694 
695  *objs = (DumpableObject **)
697  j = 0;
698  for (i = 1; i < allocedDumpIds; i++)
699  {
700  if (dumpIdMap[i])
701  (*objs)[j++] = dumpIdMap[i];
702  }
703  *numObjs = j;
704 }
static int allocedDumpIds
Definition: common.c:32
static DumpableObject ** dumpIdMap
Definition: common.c:31
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int i
EventTriggerInfo* getEventTriggers ( Archive fout,
int *  numEventTriggers 
)

Definition at line 7376 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_EVENT_TRIGGER, _evttriggerInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_ACL, _evttriggerInfo::evtenabled, _evttriggerInfo::evtevent, _evttriggerInfo::evtfname, _evttriggerInfo::evtname, _evttriggerInfo::evtowner, _evttriggerInfo::evttags, ExecuteSqlQuery(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

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

Definition at line 6777 of file pg_dump.c.

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

Referenced by getSchemaData().

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

Definition at line 17314 of file pg_dump.c.

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

Referenced by getSchemaData().

17316 {
17317  PQExpBuffer query;
17318  PGresult *res;
17319  int ntups,
17320  nextmembers,
17321  i;
17322  int i_classid,
17323  i_objid,
17324  i_refobjid;
17326  ExtensionInfo *ext;
17327 
17328  /* Nothing to do if no extensions */
17329  if (numExtensions == 0)
17330  return;
17331 
17332  /* Make sure we are in proper schema */
17333  selectSourceSchema(fout, "pg_catalog");
17334 
17335  query = createPQExpBuffer();
17336 
17337  /* refclassid constraint is redundant but may speed the search */
17338  appendPQExpBufferStr(query, "SELECT "
17339  "classid, objid, refobjid "
17340  "FROM pg_depend "
17341  "WHERE refclassid = 'pg_extension'::regclass "
17342  "AND deptype = 'e' "
17343  "ORDER BY 3");
17344 
17345  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
17346 
17347  ntups = PQntuples(res);
17348 
17349  i_classid = PQfnumber(res, "classid");
17350  i_objid = PQfnumber(res, "objid");
17351  i_refobjid = PQfnumber(res, "refobjid");
17352 
17353  extmembers = (ExtensionMemberId *) pg_malloc(ntups * sizeof(ExtensionMemberId));
17354  nextmembers = 0;
17355 
17356  /*
17357  * Accumulate data into extmembers[].
17358  *
17359  * Since we ordered the SELECT by referenced ID, we can expect that
17360  * multiple entries for the same extension will appear together; this
17361  * saves on searches.
17362  */
17363  ext = NULL;
17364 
17365  for (i = 0; i < ntups; i++)
17366  {
17367  CatalogId objId;
17368  Oid extId;
17369 
17370  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
17371  objId.oid = atooid(PQgetvalue(res, i, i_objid));
17372  extId = atooid(PQgetvalue(res, i, i_refobjid));
17373 
17374  if (ext == NULL ||
17375  ext->dobj.catId.oid != extId)
17376  ext = findExtensionByOid(extId);
17377 
17378  if (ext == NULL)
17379  {
17380  /* shouldn't happen */
17381  fprintf(stderr, "could not find referenced extension %u\n", extId);
17382  continue;
17383  }
17384 
17385  extmembers[nextmembers].catId = objId;
17386  extmembers[nextmembers].ext = ext;
17387  nextmembers++;
17388  }
17389 
17390  PQclear(res);
17391 
17392  /* Remember the data for use later */
17393  setExtensionMembership(extmembers, nextmembers);
17394 
17395  destroyPQExpBuffer(query);
17396 }
ExtensionInfo * ext
Definition: pg_dump.h:621
DumpableObject dobj
Definition: pg_dump.h:155
Oid tableoid
Definition: pg_backup.h:226
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void setExtensionMembership(ExtensionMemberId *extmems, int nextmems)
Definition: common.c:836
static int numExtensions
Definition: common.c:63
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
static ExtensionMemberId * extmembers
Definition: common.c:66
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:825
void PQclear(PGresult *res)
Definition: fe-exec.c:671
CatalogId catId
Definition: pg_dump.h:131
CatalogId catId
Definition: pg_dump.h:620
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
ExtensionInfo* getExtensions ( Archive fout,
int *  numExtensions 
)

Definition at line 4348 of file pg_dump.c.

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_EXTENSION, _extensionInfo::dobj, Archive::dopt, ExecuteSqlQuery(), _extensionInfo::extcondition, _extensionInfo::extconfig, _extensionInfo::extversion, i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _extensionInfo::relocatable, Archive::remoteVersion, selectDumpableExtension(), selectSourceSchema(), and CatalogId::tableoid.

Referenced by getSchemaData().

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

Definition at line 8695 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, buildACLQueries(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FDW, _fdwInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), _fdwInfo::fdwacl, _fdwInfo::fdwhandler, _fdwInfo::fdwoptions, _fdwInfo::fdwvalidator, i, _fdwInfo::initfdwacl, _fdwInfo::initrfdwacl, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _fdwInfo::rfdwacl, _fdwInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

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

Definition at line 8864 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, buildACLQueries(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FOREIGN_SERVER, _foreignServerInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), i, _foreignServerInfo::initrsrvacl, _foreignServerInfo::initsrvacl, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _foreignServerInfo::rolname, _foreignServerInfo::rsrvacl, selectDumpableObject(), selectSourceSchema(), _foreignServerInfo::srvacl, _foreignServerInfo::srvfdw, _foreignServerInfo::srvoptions, _foreignServerInfo::srvtype, _foreignServerInfo::srvversion, CatalogId::tableoid, and username_subquery.

Referenced by getSchemaData().

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

Definition at line 5367 of file pg_dump.c.

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

Referenced by getSchemaData().

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

Definition at line 6493 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, _constraintInfo::condef, _constraintInfo::condeferrable, _constraintInfo::condeferred, _constraintInfo::condomain, _constraintInfo::confrelid, _constraintInfo::conindex, _constraintInfo::conislocal, _constraintInfo::contable, _constraintInfo::contype, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_CONSTRAINT, DO_INDEX, _tableInfo::dobj, _indxInfo::dobj, _constraintInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_DEFINITION, _dumpableObject::dumpId, ExecuteSqlQuery(), g_verbose, _tableInfo::hasindex, i, _indxInfo::indexconstraint, _indxInfo::indexdef, _indxInfo::indextable, _indxInfo::indisclustered, _indxInfo::indisreplident, _indxInfo::indkeys, _indxInfo::indnkeys, _indxInfo::indreloptions, InvalidOid, _dumpableObject::name, numTables, _dumpableObject::objType, CatalogId::oid, parseOidArray(), pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relkind, RELKIND_MATVIEW, RELKIND_RELATION, _indxInfo::relpages, Archive::remoteVersion, resetPQExpBuffer(), selectSourceSchema(), _constraintInfo::separate, CatalogId::tableoid, _indxInfo::tablespace, and write_msg().

Referenced by getSchemaData().

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

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

6440 {
6441  PGresult *res;
6442  int ntups;
6443  int i;
6444  PQExpBuffer query = createPQExpBuffer();
6445  InhInfo *inhinfo;
6446 
6447  int i_inhrelid;
6448  int i_inhparent;
6449 
6450  /* Make sure we are in proper schema */
6451  selectSourceSchema(fout, "pg_catalog");
6452 
6453  /*
6454  * Find all the inheritance information, excluding implicit inheritance
6455  * via partitioning. We handle that case using getPartitions(), because
6456  * we want more information about partitions than just the parent-child
6457  * relationship.
6458  */
6459  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
6460 
6461  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6462 
6463  ntups = PQntuples(res);
6464 
6465  *numInherits = ntups;
6466 
6467  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6468 
6469  i_inhrelid = PQfnumber(res, "inhrelid");
6470  i_inhparent = PQfnumber(res, "inhparent");
6471 
6472  for (i = 0; i < ntups; i++)
6473  {
6474  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6475  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6476  }
6477 
6478  PQclear(res);
6479 
6480  destroyPQExpBuffer(query);
6481 
6482  return inhinfo;
6483 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
Oid inhrelid
Definition: pg_dump.h:475
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
Oid inhparent
Definition: pg_dump.h:476
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
DumpId getMaxDumpId ( void  )

Definition at line 529 of file common.c.

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

530 {
531  return lastDumpId;
532 }
static DumpId lastDumpId
Definition: common.c:33
NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

Definition at line 4176 of file pg_dump.c.

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

Referenced by getSchemaData().

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

Definition at line 5010 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPCLASS, _opclassInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _opclassInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, username_subquery, and write_msg().

Referenced by getSchemaData().

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

Definition at line 4688 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPERATOR, _oprInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, _oprInfo::oprcode, _oprInfo::oprkind, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _oprInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, username_subquery, and write_msg().

Referenced by getSchemaData().

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

Definition at line 5088 of file pg_dump.c.

References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPFAMILY, _opfamilyInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _opfamilyInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, username_subquery, and write_msg().

Referenced by getSchemaData().

5089 {
5090  PGresult *res;
5091  int ntups;
5092  int i;
5093  PQExpBuffer query;
5094  OpfamilyInfo *opfinfo;
5095  int i_tableoid;
5096  int i_oid;
5097  int i_opfname;
5098  int i_opfnamespace;
5099  int i_rolname;
5100 
5101  /* Before 8.3, there is no separate concept of opfamilies */
5102  if (fout->remoteVersion < 80300)
5103  {
5104  *numOpfamilies = 0;
5105  return NULL;
5106  }
5107 
5108  query = createPQExpBuffer();
5109 
5110  /*
5111  * find all opfamilies, including builtin opfamilies; we filter out
5112  * system-defined opfamilies at dump-out time.
5113  */
5114 
5115  /* Make sure we are in proper schema */
5116  selectSourceSchema(fout, "pg_catalog");
5117 
5118  appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, "
5119  "opfnamespace, "
5120  "(%s opfowner) AS rolname "
5121  "FROM pg_opfamily",
5123 
5124  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5125 
5126  ntups = PQntuples(res);
5127  *numOpfamilies = ntups;
5128 
5129  opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
5130 
5131  i_tableoid = PQfnumber(res, "tableoid");
5132  i_oid = PQfnumber(res, "oid");
5133  i_opfname = PQfnumber(res, "opfname");
5134  i_opfnamespace = PQfnumber(res, "opfnamespace");
5135  i_rolname = PQfnumber(res, "rolname");
5136 
5137  for (i = 0; i < ntups; i++)
5138  {
5139  opfinfo[i].dobj.objType = DO_OPFAMILY;
5140  opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5141  opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5142  AssignDumpId(&opfinfo[i].dobj);
5143  opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
5144  opfinfo[i].dobj.namespace =
5145  findNamespace(fout,
5146  atooid(PQgetvalue(res, i, i_opfnamespace)));
5147  opfinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5148 
5149  /* Decide whether we want to dump it */
5150  selectDumpableObject(&(opfinfo[i].dobj), fout);
5151