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, NULL, pg_malloc(), and pg_realloc().

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

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
#define NULL
Definition: c.h:229
static bool catalogIdMapValid
Definition: common.c:38
#define DUMP_COMPONENT_ALL
Definition: pg_dump.h:99
DumpId createDumpId ( void  )
CollInfo* findCollationByOid ( Oid  oid)

Definition at line 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(), NULL, 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
#define NULL
Definition: c.h:229
static DumpableObject ** catalogIdMap
Definition: common.c:39
static bool catalogIdMapValid
Definition: common.c:38
#define qsort(a, b, c, d)
Definition: port.h:443
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition: common.c:690
DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 540 of file common.c.

References allocedDumpIds, and NULL.

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
#define NULL
Definition: c.h:229
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, NULL, 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
#define NULL
Definition: c.h:229
static int numextmembers
Definition: common.c:67
CatalogId catId
Definition: pg_dump.h:620
TableInfo* findTableByOid ( Oid  oid)

Definition at line 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 4899 of file pg_dump.c.

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

Referenced by getSchemaData().

4900 {
4901  PGresult *res;
4902  int ntups;
4903  int i;
4904  PQExpBuffer query;
4905  AccessMethodInfo *aminfo;
4906  int i_tableoid;
4907  int i_oid;
4908  int i_amname;
4909  int i_amhandler;
4910  int i_amtype;
4911 
4912  /* Before 9.6, there are no user-defined access methods */
4913  if (fout->remoteVersion < 90600)
4914  {
4915  *numAccessMethods = 0;
4916  return NULL;
4917  }
4918 
4919  query = createPQExpBuffer();
4920 
4921  /* Make sure we are in proper schema */
4922  selectSourceSchema(fout, "pg_catalog");
4923 
4924  /* Select all access methods from pg_am table */
4925  appendPQExpBuffer(query, "SELECT tableoid, oid, amname, amtype, "
4926  "amhandler::pg_catalog.regproc AS amhandler "
4927  "FROM pg_am");
4928 
4929  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4930 
4931  ntups = PQntuples(res);
4932  *numAccessMethods = ntups;
4933 
4934  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
4935 
4936  i_tableoid = PQfnumber(res, "tableoid");
4937  i_oid = PQfnumber(res, "oid");
4938  i_amname = PQfnumber(res, "amname");
4939  i_amhandler = PQfnumber(res, "amhandler");
4940  i_amtype = PQfnumber(res, "amtype");
4941 
4942  for (i = 0; i < ntups; i++)
4943  {
4944  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
4945  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4946  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4947  AssignDumpId(&aminfo[i].dobj);
4948  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
4949  aminfo[i].dobj.namespace = NULL;
4950  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
4951  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
4952 
4953  /* Decide whether we want to dump it */
4954  selectDumpableAccessMethod(&(aminfo[i]), fout);
4955 
4956  /* Access methods do not currently have ACLs. */
4957  aminfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4958  }
4959 
4960  PQclear(res);
4961 
4962  destroyPQExpBuffer(query);
4963 
4964  return aminfo;
4965 }
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpableObject dobj
Definition: pg_dump.h:227
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:1594
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:17824
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
char * amhandler
Definition: pg_dump.h:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
AggInfo* getAggregates ( Archive fout,
int *  numAggregates 
)

Definition at line 5141 of file pg_dump.c.

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

Referenced by getSchemaData().

5142 {
5143  DumpOptions *dopt = fout->dopt;
5144  PGresult *res;
5145  int ntups;
5146  int i;
5147  PQExpBuffer query = createPQExpBuffer();
5148  AggInfo *agginfo;
5149  int i_tableoid;
5150  int i_oid;
5151  int i_aggname;
5152  int i_aggnamespace;
5153  int i_pronargs;
5154  int i_proargtypes;
5155  int i_rolname;
5156  int i_aggacl;
5157  int i_raggacl;
5158  int i_initaggacl;
5159  int i_initraggacl;
5160 
5161  /* Make sure we are in proper schema */
5162  selectSourceSchema(fout, "pg_catalog");
5163 
5164  /*
5165  * Find all interesting aggregates. See comment in getFuncs() for the
5166  * rationale behind the filtering logic.
5167  */
5168  if (fout->remoteVersion >= 90600)
5169  {
5170  PQExpBuffer acl_subquery = createPQExpBuffer();
5171  PQExpBuffer racl_subquery = createPQExpBuffer();
5172  PQExpBuffer initacl_subquery = createPQExpBuffer();
5173  PQExpBuffer initracl_subquery = createPQExpBuffer();
5174 
5175  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5176  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5177  dopt->binary_upgrade);
5178 
5179  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5180  "p.proname AS aggname, "
5181  "p.pronamespace AS aggnamespace, "
5182  "p.pronargs, p.proargtypes, "
5183  "(%s p.proowner) AS rolname, "
5184  "%s AS aggacl, "
5185  "%s AS raggacl, "
5186  "%s AS initaggacl, "
5187  "%s AS initraggacl "
5188  "FROM pg_proc p "
5189  "LEFT JOIN pg_init_privs pip ON "
5190  "(p.oid = pip.objoid "
5191  "AND pip.classoid = 'pg_proc'::regclass "
5192  "AND pip.objsubid = 0) "
5193  "WHERE p.proisagg AND ("
5194  "p.pronamespace != "
5195  "(SELECT oid FROM pg_namespace "
5196  "WHERE nspname = 'pg_catalog') OR "
5197  "p.proacl IS DISTINCT FROM pip.initprivs",
5199  acl_subquery->data,
5200  racl_subquery->data,
5201  initacl_subquery->data,
5202  initracl_subquery->data);
5203  if (dopt->binary_upgrade)
5204  appendPQExpBufferStr(query,
5205  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5206  "classid = 'pg_proc'::regclass AND "
5207  "objid = p.oid AND "
5208  "refclassid = 'pg_extension'::regclass AND "
5209  "deptype = 'e')");
5210  appendPQExpBufferChar(query, ')');
5211 
5212  destroyPQExpBuffer(acl_subquery);
5213  destroyPQExpBuffer(racl_subquery);
5214  destroyPQExpBuffer(initacl_subquery);
5215  destroyPQExpBuffer(initracl_subquery);
5216  }
5217  else if (fout->remoteVersion >= 80200)
5218  {
5219  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5220  "pronamespace AS aggnamespace, "
5221  "pronargs, proargtypes, "
5222  "(%s proowner) AS rolname, "
5223  "proacl AS aggacl, "
5224  "NULL AS raggacl, "
5225  "NULL AS initaggacl, NULL AS initraggacl "
5226  "FROM pg_proc p "
5227  "WHERE proisagg AND ("
5228  "pronamespace != "
5229  "(SELECT oid FROM pg_namespace "
5230  "WHERE nspname = 'pg_catalog')",
5232  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5233  appendPQExpBufferStr(query,
5234  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5235  "classid = 'pg_proc'::regclass AND "
5236  "objid = p.oid AND "
5237  "refclassid = 'pg_extension'::regclass AND "
5238  "deptype = 'e')");
5239  appendPQExpBufferChar(query, ')');
5240  }
5241  else
5242  {
5243  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5244  "pronamespace AS aggnamespace, "
5245  "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
5246  "proargtypes, "
5247  "(%s proowner) AS rolname, "
5248  "proacl AS aggacl, "
5249  "NULL AS raggacl, "
5250  "NULL AS initaggacl, NULL AS initraggacl "
5251  "FROM pg_proc "
5252  "WHERE proisagg "
5253  "AND pronamespace != "
5254  "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
5256  }
5257 
5258  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5259 
5260  ntups = PQntuples(res);
5261  *numAggs = ntups;
5262 
5263  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5264 
5265  i_tableoid = PQfnumber(res, "tableoid");
5266  i_oid = PQfnumber(res, "oid");
5267  i_aggname = PQfnumber(res, "aggname");
5268  i_aggnamespace = PQfnumber(res, "aggnamespace");
5269  i_pronargs = PQfnumber(res, "pronargs");
5270  i_proargtypes = PQfnumber(res, "proargtypes");
5271  i_rolname = PQfnumber(res, "rolname");
5272  i_aggacl = PQfnumber(res, "aggacl");
5273  i_raggacl = PQfnumber(res, "raggacl");
5274  i_initaggacl = PQfnumber(res, "initaggacl");
5275  i_initraggacl = PQfnumber(res, "initraggacl");
5276 
5277  for (i = 0; i < ntups; i++)
5278  {
5279  agginfo[i].aggfn.dobj.objType = DO_AGG;
5280  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5281  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5282  AssignDumpId(&agginfo[i].aggfn.dobj);
5283  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5284  agginfo[i].aggfn.dobj.namespace =
5285  findNamespace(fout,
5286  atooid(PQgetvalue(res, i, i_aggnamespace)));
5287  agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5288  if (strlen(agginfo[i].aggfn.rolname) == 0)
5289  write_msg(NULL, "WARNING: owner of aggregate function \"%s\" appears to be invalid\n",
5290  agginfo[i].aggfn.dobj.name);
5291  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5292  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5293  agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5294  agginfo[i].aggfn.rproacl = pg_strdup(PQgetvalue(res, i, i_raggacl));
5295  agginfo[i].aggfn.initproacl = pg_strdup(PQgetvalue(res, i, i_initaggacl));
5296  agginfo[i].aggfn.initrproacl = pg_strdup(PQgetvalue(res, i, i_initraggacl));
5297  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5298  if (agginfo[i].aggfn.nargs == 0)
5299  agginfo[i].aggfn.argtypes = NULL;
5300  else
5301  {
5302  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5303  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5304  agginfo[i].aggfn.argtypes,
5305  agginfo[i].aggfn.nargs);
5306  }
5307 
5308  /* Decide whether we want to dump it */
5309  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5310 
5311  /* Do not try to dump ACL if no ACL exists. */
5312  if (PQgetisnull(res, i, i_aggacl) && PQgetisnull(res, i, i_raggacl) &&
5313  PQgetisnull(res, i, i_initaggacl) &&
5314  PQgetisnull(res, i, i_initraggacl))
5315  agginfo[i].aggfn.dobj.dump &= ~DUMP_COMPONENT_ACL;
5316  }
5317 
5318  PQclear(res);
5319 
5320  destroyPQExpBuffer(query);
5321 
5322  return agginfo;
5323 }
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:1660
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int nargs
Definition: pg_dump.h:201
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4296
char * initrproacl
Definition: pg_dump.h:207
Oid lang
Definition: pg_dump.h:200
DumpableObject dobj
Definition: pg_dump.h:198
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
FuncInfo aggfn
Definition: pg_dump.h:213
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
Definition: pg_dump.h:49
DumpOptions * dopt
Definition: pg_backup.h: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:17824
static const char * username_subquery
Definition: pg_dump.c:96
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:2781
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:650
void write_msg(const char *modulename, const char *fmt,...)
Oid prorettype
Definition: pg_dump.h:203
#define NULL
Definition: c.h:229
char * initproacl
Definition: pg_dump.h:206
char * rolname
Definition: pg_dump.h:199
char * proacl
Definition: pg_dump.h:204
char * rproacl
Definition: pg_dump.h:205
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
CastInfo* getCasts ( Archive fout,
int *  numCasts 
)

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

7618 {
7619  PGresult *res;
7620  int ntups;
7621  int i;
7622  PQExpBuffer query = createPQExpBuffer();
7623  CastInfo *castinfo;
7624  int i_tableoid;
7625  int i_oid;
7626  int i_castsource;
7627  int i_casttarget;
7628  int i_castfunc;
7629  int i_castcontext;
7630  int i_castmethod;
7631 
7632  /* Make sure we are in proper schema */
7633  selectSourceSchema(fout, "pg_catalog");
7634 
7635  if (fout->remoteVersion >= 80400)
7636  {
7637  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7638  "castsource, casttarget, castfunc, castcontext, "
7639  "castmethod "
7640  "FROM pg_cast ORDER BY 3,4");
7641  }
7642  else
7643  {
7644  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7645  "castsource, casttarget, castfunc, castcontext, "
7646  "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
7647  "FROM pg_cast ORDER BY 3,4");
7648  }
7649 
7650  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7651 
7652  ntups = PQntuples(res);
7653 
7654  *numCasts = ntups;
7655 
7656  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
7657 
7658  i_tableoid = PQfnumber(res, "tableoid");
7659  i_oid = PQfnumber(res, "oid");
7660  i_castsource = PQfnumber(res, "castsource");
7661  i_casttarget = PQfnumber(res, "casttarget");
7662  i_castfunc = PQfnumber(res, "castfunc");
7663  i_castcontext = PQfnumber(res, "castcontext");
7664  i_castmethod = PQfnumber(res, "castmethod");
7665 
7666  for (i = 0; i < ntups; i++)
7667  {
7668  PQExpBufferData namebuf;
7669  TypeInfo *sTypeInfo;
7670  TypeInfo *tTypeInfo;
7671 
7672  castinfo[i].dobj.objType = DO_CAST;
7673  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7674  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7675  AssignDumpId(&castinfo[i].dobj);
7676  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
7677  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
7678  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
7679  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
7680  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
7681 
7682  /*
7683  * Try to name cast as concatenation of typnames. This is only used
7684  * for purposes of sorting. If we fail to find either type, the name
7685  * will be an empty string.
7686  */
7687  initPQExpBuffer(&namebuf);
7688  sTypeInfo = findTypeByOid(castinfo[i].castsource);
7689  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
7690  if (sTypeInfo && tTypeInfo)
7691  appendPQExpBuffer(&namebuf, "%s %s",
7692  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
7693  castinfo[i].dobj.name = namebuf.data;
7694 
7695  /* Decide whether we want to dump it */
7696  selectDumpableCast(&(castinfo[i]), fout);
7697 
7698  /* Casts do not currently have ACLs. */
7699  castinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7700  }
7701 
7702  PQclear(res);
7703 
7704  destroyPQExpBuffer(query);
7705 
7706  return castinfo;
7707 }
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:1536
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
Oid castfunc
Definition: pg_dump.h:458
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:455
Oid casttarget
Definition: pg_dump.h:457
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
DumpableObject dobj
Definition: pg_dump.h:165
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
char castmethod
Definition: pg_dump.h:460
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c: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 4740 of file pg_dump.c.

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

Referenced by getSchemaData().

4741 {
4742  PGresult *res;
4743  int ntups;
4744  int i;
4745  PQExpBuffer query;
4746  CollInfo *collinfo;
4747  int i_tableoid;
4748  int i_oid;
4749  int i_collname;
4750  int i_collnamespace;
4751  int i_rolname;
4752 
4753  /* Collations didn't exist pre-9.1 */
4754  if (fout->remoteVersion < 90100)
4755  {
4756  *numCollations = 0;
4757  return NULL;
4758  }
4759 
4760  query = createPQExpBuffer();
4761 
4762  /*
4763  * find all collations, including builtin collations; we filter out
4764  * system-defined collations at dump-out time.
4765  */
4766 
4767  /* Make sure we are in proper schema */
4768  selectSourceSchema(fout, "pg_catalog");
4769 
4770  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
4771  "collnamespace, "
4772  "(%s collowner) AS rolname "
4773  "FROM pg_collation",
4775 
4776  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4777 
4778  ntups = PQntuples(res);
4779  *numCollations = ntups;
4780 
4781  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
4782 
4783  i_tableoid = PQfnumber(res, "tableoid");
4784  i_oid = PQfnumber(res, "oid");
4785  i_collname = PQfnumber(res, "collname");
4786  i_collnamespace = PQfnumber(res, "collnamespace");
4787  i_rolname = PQfnumber(res, "rolname");
4788 
4789  for (i = 0; i < ntups; i++)
4790  {
4791  collinfo[i].dobj.objType = DO_COLLATION;
4792  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4793  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4794  AssignDumpId(&collinfo[i].dobj);
4795  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
4796  collinfo[i].dobj.namespace =
4797  findNamespace(fout,
4798  atooid(PQgetvalue(res, i, i_collnamespace)));
4799  collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4800 
4801  /* Decide whether we want to dump it */
4802  selectDumpableObject(&(collinfo[i].dobj), fout);
4803 
4804  /* Collations do not currently have ACLs. */
4805  collinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4806  }
4807 
4808  PQclear(res);
4809 
4810  destroyPQExpBuffer(query);
4811 
4812  return collinfo;
4813 }
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:1660
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4296
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
DumpableObject dobj
Definition: pg_dump.h:246
char * rolname
Definition: pg_dump.h:247
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
static const char * username_subquery
Definition: pg_dump.c:96
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
static int numCollations
Definition: common.c:61
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
void getConstraints ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 6842 of file pg_dump.c.

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

Referenced by getSchemaData().

6843 {
6844  int i,
6845  j;
6846  ConstraintInfo *constrinfo;
6847  PQExpBuffer query;
6848  PGresult *res;
6849  int i_contableoid,
6850  i_conoid,
6851  i_conname,
6852  i_confrelid,
6853  i_condef;
6854  int ntups;
6855 
6856  query = createPQExpBuffer();
6857 
6858  for (i = 0; i < numTables; i++)
6859  {
6860  TableInfo *tbinfo = &tblinfo[i];
6861 
6862  if (!tbinfo->hastriggers ||
6863  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6864  continue;
6865 
6866  if (g_verbose)
6867  write_msg(NULL, "reading foreign key constraints for table \"%s.%s\"\n",
6868  tbinfo->dobj.namespace->dobj.name,
6869  tbinfo->dobj.name);
6870 
6871  /*
6872  * select table schema to ensure constraint expr is qualified if
6873  * needed
6874  */
6875  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6876 
6877  resetPQExpBuffer(query);
6878  appendPQExpBuffer(query,
6879  "SELECT tableoid, oid, conname, confrelid, "
6880  "pg_catalog.pg_get_constraintdef(oid) AS condef "
6881  "FROM pg_catalog.pg_constraint "
6882  "WHERE conrelid = '%u'::pg_catalog.oid "
6883  "AND contype = 'f'",
6884  tbinfo->dobj.catId.oid);
6885  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6886 
6887  ntups = PQntuples(res);
6888 
6889  i_contableoid = PQfnumber(res, "tableoid");
6890  i_conoid = PQfnumber(res, "oid");
6891  i_conname = PQfnumber(res, "conname");
6892  i_confrelid = PQfnumber(res, "confrelid");
6893  i_condef = PQfnumber(res, "condef");
6894 
6895  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
6896 
6897  for (j = 0; j < ntups; j++)
6898  {
6899  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
6900  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
6901  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
6902  AssignDumpId(&constrinfo[j].dobj);
6903  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
6904  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6905  constrinfo[j].contable = tbinfo;
6906  constrinfo[j].condomain = NULL;
6907  constrinfo[j].contype = 'f';
6908  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
6909  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
6910  constrinfo[j].conindex = 0;
6911  constrinfo[j].condeferrable = false;
6912  constrinfo[j].condeferred = false;
6913  constrinfo[j].conislocal = true;
6914  constrinfo[j].separate = true;
6915  }
6916 
6917  PQclear(res);
6918  }
6919 
6920  destroyPQExpBuffer(query);
6921 }
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
bool hastriggers
Definition: pg_dump.h:277
static int numTables
Definition: common.c:57
DumpId conindex
Definition: pg_dump.h:432
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
DumpableObject dobj
Definition: pg_dump.h:261
char * condef
Definition: pg_dump.h:430
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:426
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
bool condeferrable
Definition: pg_dump.h:433
TypeInfo * condomain
Definition: pg_dump.h:428
bool conislocal
Definition: pg_dump.h:435
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
TableInfo * contable
Definition: pg_dump.h:427
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
void write_msg(const char *modulename, const char *fmt,...)
bool condeferred
Definition: pg_dump.h:434
#define NULL
Definition: c.h:229
CatalogId catId
Definition: pg_dump.h:131
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
DumpableObjectType objType
Definition: pg_dump.h:130
bool g_verbose
Definition: pg_dump.c:91
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
ConvInfo* getConversions ( Archive fout,
int *  numConversions 
)

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

4824 {
4825  PGresult *res;
4826  int ntups;
4827  int i;
4828  PQExpBuffer query;
4829  ConvInfo *convinfo;
4830  int i_tableoid;
4831  int i_oid;
4832  int i_conname;
4833  int i_connamespace;
4834  int i_rolname;
4835 
4836  query = createPQExpBuffer();
4837 
4838  /*
4839  * find all conversions, including builtin conversions; we filter out
4840  * system-defined conversions at dump-out time.
4841  */
4842 
4843  /* Make sure we are in proper schema */
4844  selectSourceSchema(fout, "pg_catalog");
4845 
4846  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
4847  "connamespace, "
4848  "(%s conowner) AS rolname "
4849  "FROM pg_conversion",
4851 
4852  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4853 
4854  ntups = PQntuples(res);
4855  *numConversions = ntups;
4856 
4857  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
4858 
4859  i_tableoid = PQfnumber(res, "tableoid");
4860  i_oid = PQfnumber(res, "oid");
4861  i_conname = PQfnumber(res, "conname");
4862  i_connamespace = PQfnumber(res, "connamespace");
4863  i_rolname = PQfnumber(res, "rolname");
4864 
4865  for (i = 0; i < ntups; i++)
4866  {
4867  convinfo[i].dobj.objType = DO_CONVERSION;
4868  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4869  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4870  AssignDumpId(&convinfo[i].dobj);
4871  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
4872  convinfo[i].dobj.namespace =
4873  findNamespace(fout,
4874  atooid(PQgetvalue(res, i, i_connamespace)));
4875  convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4876 
4877  /* Decide whether we want to dump it */
4878  selectDumpableObject(&(convinfo[i].dobj), fout);
4879 
4880  /* Conversions do not currently have ACLs. */
4881  convinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4882  }
4883 
4884  PQclear(res);
4885 
4886  destroyPQExpBuffer(query);
4887 
4888  return convinfo;
4889 }
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:1660
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4296
char * rolname
Definition: pg_dump.h:253
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
static const char * username_subquery
Definition: pg_dump.c:96
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
DumpableObject dobj
Definition: pg_dump.h:252
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
DefaultACLInfo* getDefaultACLs ( Archive fout,
int *  numDefaultACLs 
)

Definition at line 8983 of file pg_dump.c.

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

Referenced by getSchemaData().

8984 {
8985  DumpOptions *dopt = fout->dopt;
8986  DefaultACLInfo *daclinfo;
8987  PQExpBuffer query;
8988  PGresult *res;
8989  int i_oid;
8990  int i_tableoid;
8991  int i_defaclrole;
8992  int i_defaclnamespace;
8993  int i_defaclobjtype;
8994  int i_defaclacl;
8995  int i_rdefaclacl;
8996  int i_initdefaclacl;
8997  int i_initrdefaclacl;
8998  int i,
8999  ntups;
9000 
9001  if (fout->remoteVersion < 90000)
9002  {
9003  *numDefaultACLs = 0;
9004  return NULL;
9005  }
9006 
9007  query = createPQExpBuffer();
9008 
9009  /* Make sure we are in proper schema */
9010  selectSourceSchema(fout, "pg_catalog");
9011 
9012  if (fout->remoteVersion >= 90600)
9013  {
9014  PQExpBuffer acl_subquery = createPQExpBuffer();
9015  PQExpBuffer racl_subquery = createPQExpBuffer();
9016  PQExpBuffer initacl_subquery = createPQExpBuffer();
9017  PQExpBuffer initracl_subquery = createPQExpBuffer();
9018 
9019  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9020  initracl_subquery, "defaclacl", "defaclrole",
9021  "CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
9022  dopt->binary_upgrade);
9023 
9024  appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
9025  "(%s d.defaclrole) AS defaclrole, "
9026  "d.defaclnamespace, "
9027  "d.defaclobjtype, "
9028  "%s AS defaclacl, "
9029  "%s AS rdefaclacl, "
9030  "%s AS initdefaclacl, "
9031  "%s AS initrdefaclacl "
9032  "FROM pg_default_acl d "
9033  "LEFT JOIN pg_init_privs pip ON "
9034  "(d.oid = pip.objoid "
9035  "AND pip.classoid = 'pg_default_acl'::regclass "
9036  "AND pip.objsubid = 0) ",
9038  acl_subquery->data,
9039  racl_subquery->data,
9040  initacl_subquery->data,
9041  initracl_subquery->data);
9042  }
9043  else
9044  {
9045  appendPQExpBuffer(query, "SELECT oid, tableoid, "
9046  "(%s defaclrole) AS defaclrole, "
9047  "defaclnamespace, "
9048  "defaclobjtype, "
9049  "defaclacl, "
9050  "NULL AS rdefaclacl, "
9051  "NULL AS initdefaclacl, "
9052  "NULL AS initrdefaclacl "
9053  "FROM pg_default_acl",
9055  }
9056 
9057  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9058 
9059  ntups = PQntuples(res);
9060  *numDefaultACLs = ntups;
9061 
9062  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9063 
9064  i_oid = PQfnumber(res, "oid");
9065  i_tableoid = PQfnumber(res, "tableoid");
9066  i_defaclrole = PQfnumber(res, "defaclrole");
9067  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9068  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9069  i_defaclacl = PQfnumber(res, "defaclacl");
9070  i_rdefaclacl = PQfnumber(res, "rdefaclacl");
9071  i_initdefaclacl = PQfnumber(res, "initdefaclacl");
9072  i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
9073 
9074  for (i = 0; i < ntups; i++)
9075  {
9076  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9077 
9078  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9079  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9080  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9081  AssignDumpId(&daclinfo[i].dobj);
9082  /* cheesy ... is it worth coming up with a better object name? */
9083  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9084 
9085  if (nspid != InvalidOid)
9086  daclinfo[i].dobj.namespace = findNamespace(fout, nspid);
9087  else
9088  daclinfo[i].dobj.namespace = NULL;
9089 
9090  daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
9091  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9092  daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9093  daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
9094  daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
9095  daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
9096 
9097  /* Decide whether we want to dump it */
9098  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9099  }
9100 
9101  PQclear(res);
9102 
9103  destroyPQExpBuffer(query);
9104 
9105  return daclinfo;
9106 }
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4296
char * rdefaclacl
Definition: pg_dump.h:544
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition: pg_dump.c:1514
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:17824
static const char * username_subquery
Definition: pg_dump.c:96
char * defaclacl
Definition: pg_dump.h:543
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
char * initdefaclacl
Definition: pg_dump.h:545
CatalogId catId
Definition: pg_dump.h:131
char * initrdefaclacl
Definition: pg_dump.h:546
int i
char defaclobjtype
Definition: pg_dump.h:542
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h: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 7342 of file pg_dump.c.

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

Referenced by getSchemaData().

7343 {
7344  int i;
7345  PQExpBuffer query;
7346  PGresult *res;
7347  EventTriggerInfo *evtinfo;
7348  int i_tableoid,
7349  i_oid,
7350  i_evtname,
7351  i_evtevent,
7352  i_evtowner,
7353  i_evttags,
7354  i_evtfname,
7355  i_evtenabled;
7356  int ntups;
7357 
7358  /* Before 9.3, there are no event triggers */
7359  if (fout->remoteVersion < 90300)
7360  {
7361  *numEventTriggers = 0;
7362  return NULL;
7363  }
7364 
7365  query = createPQExpBuffer();
7366 
7367  /* Make sure we are in proper schema */
7368  selectSourceSchema(fout, "pg_catalog");
7369 
7370  appendPQExpBuffer(query,
7371  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
7372  "evtevent, (%s evtowner) AS evtowner, "
7373  "array_to_string(array("
7374  "select quote_literal(x) "
7375  " from unnest(evttags) as t(x)), ', ') as evttags, "
7376  "e.evtfoid::regproc as evtfname "
7377  "FROM pg_event_trigger e "
7378  "ORDER BY e.oid",
7380 
7381  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7382 
7383  ntups = PQntuples(res);
7384 
7385  *numEventTriggers = ntups;
7386 
7387  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
7388 
7389  i_tableoid = PQfnumber(res, "tableoid");
7390  i_oid = PQfnumber(res, "oid");
7391  i_evtname = PQfnumber(res, "evtname");
7392  i_evtevent = PQfnumber(res, "evtevent");
7393  i_evtowner = PQfnumber(res, "evtowner");
7394  i_evttags = PQfnumber(res, "evttags");
7395  i_evtfname = PQfnumber(res, "evtfname");
7396  i_evtenabled = PQfnumber(res, "evtenabled");
7397 
7398  for (i = 0; i < ntups; i++)
7399  {
7400  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
7401  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7402  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7403  AssignDumpId(&evtinfo[i].dobj);
7404  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
7405  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
7406  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
7407  evtinfo[i].evtowner = pg_strdup(PQgetvalue(res, i, i_evtowner));
7408  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
7409  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
7410  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
7411 
7412  /* Decide whether we want to dump it */
7413  selectDumpableObject(&(evtinfo[i].dobj), fout);
7414 
7415  /* Event Triggers do not currently have ACLs. */
7416  evtinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7417  }
7418 
7419  PQclear(res);
7420 
7421  destroyPQExpBuffer(query);
7422 
7423  return evtinfo;
7424 }
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:1660
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * evtowner
Definition: pg_dump.h:410
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
static const char * username_subquery
Definition: pg_dump.c:96
char * evtfname
Definition: pg_dump.h:412
char * evttags
Definition: pg_dump.h:411
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
char * evtname
Definition: pg_dump.h:408
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
DumpableObject dobj
Definition: pg_dump.h:407
char evtenabled
Definition: pg_dump.h:413
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
void getExtendedStatistics ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 6743 of file pg_dump.c.

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

Referenced by getSchemaData().

6744 {
6745  int i,
6746  j;
6747  PQExpBuffer query;
6748  PGresult *res;
6749  StatsExtInfo *statsextinfo;
6750  int ntups;
6751  int i_tableoid;
6752  int i_oid;
6753  int i_stxname;
6754  int i_stxdef;
6755 
6756  /* Extended statistics were new in v10 */
6757  if (fout->remoteVersion < 100000)
6758  return;
6759 
6760  query = createPQExpBuffer();
6761 
6762  for (i = 0; i < numTables; i++)
6763  {
6764  TableInfo *tbinfo = &tblinfo[i];
6765 
6766  /*
6767  * Only plain tables, materialized views, foreign tables and
6768  * partitioned tables can have extended statistics.
6769  */
6770  if (tbinfo->relkind != RELKIND_RELATION &&
6771  tbinfo->relkind != RELKIND_MATVIEW &&
6772  tbinfo->relkind != RELKIND_FOREIGN_TABLE &&
6774  continue;
6775 
6776  /*
6777  * Ignore extended statistics of tables whose definitions are not to
6778  * be dumped.
6779  */
6780  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6781  continue;
6782 
6783  if (g_verbose)
6784  write_msg(NULL, "reading extended statistics for table \"%s.%s\"\n",
6785  tbinfo->dobj.namespace->dobj.name,
6786  tbinfo->dobj.name);
6787 
6788  /* Make sure we are in proper schema so stadef is right */
6789  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6790 
6791  resetPQExpBuffer(query);
6792 
6793  appendPQExpBuffer(query,
6794  "SELECT "
6795  "tableoid, "
6796  "oid, "
6797  "stxname, "
6798  "pg_catalog.pg_get_statisticsobjdef(oid) AS stxdef "
6799  "FROM pg_statistic_ext "
6800  "WHERE stxrelid = '%u' "
6801  "ORDER BY stxname", tbinfo->dobj.catId.oid);
6802 
6803  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6804 
6805  ntups = PQntuples(res);
6806 
6807  i_tableoid = PQfnumber(res, "tableoid");
6808  i_oid = PQfnumber(res, "oid");
6809  i_stxname = PQfnumber(res, "stxname");
6810  i_stxdef = PQfnumber(res, "stxdef");
6811 
6812  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
6813 
6814  for (j = 0; j < ntups; j++)
6815  {
6816  statsextinfo[j].dobj.objType = DO_STATSEXT;
6817  statsextinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
6818  statsextinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
6819  AssignDumpId(&statsextinfo[j].dobj);
6820  statsextinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_stxname));
6821  statsextinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6822  statsextinfo[j].statsexttable = tbinfo;
6823  statsextinfo[j].statsextdef = pg_strdup(PQgetvalue(res, j, i_stxdef));
6824  }
6825 
6826  PQclear(res);
6827  }
6828 
6829  destroyPQExpBuffer(query);
6830 }
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpableObject dobj
Definition: pg_dump.h:371
#define RELKIND_MATVIEW
Definition: pg_class.h:165
static int numTables
Definition: common.c:57
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
DumpableObject dobj
Definition: pg_dump.h:261
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
CatalogId catId
Definition: pg_dump.h:131
TableInfo * statsexttable
Definition: pg_dump.h:372
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
#define RELKIND_RELATION
Definition: pg_class.h:160
DumpableObjectType objType
Definition: pg_dump.h:130
bool g_verbose
Definition: pg_dump.c:91
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
void getExtensionMembership ( Archive fout,
ExtensionInfo  extinfo[],
int  numExtensions 
)

Definition at line 17188 of file pg_dump.c.

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

Referenced by getSchemaData().

17190 {
17191  PQExpBuffer query;
17192  PGresult *res;
17193  int ntups,
17194  nextmembers,
17195  i;
17196  int i_classid,
17197  i_objid,
17198  i_refobjid;
17200  ExtensionInfo *ext;
17201 
17202  /* Nothing to do if no extensions */
17203  if (numExtensions == 0)
17204  return;
17205 
17206  /* Make sure we are in proper schema */
17207  selectSourceSchema(fout, "pg_catalog");
17208 
17209  query = createPQExpBuffer();
17210 
17211  /* refclassid constraint is redundant but may speed the search */
17212  appendPQExpBufferStr(query, "SELECT "
17213  "classid, objid, refobjid "
17214  "FROM pg_depend "
17215  "WHERE refclassid = 'pg_extension'::regclass "
17216  "AND deptype = 'e' "
17217  "ORDER BY 3");
17218 
17219  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
17220 
17221  ntups = PQntuples(res);
17222 
17223  i_classid = PQfnumber(res, "classid");
17224  i_objid = PQfnumber(res, "objid");
17225  i_refobjid = PQfnumber(res, "refobjid");
17226 
17227  extmembers = (ExtensionMemberId *) pg_malloc(ntups * sizeof(ExtensionMemberId));
17228  nextmembers = 0;
17229 
17230  /*
17231  * Accumulate data into extmembers[].
17232  *
17233  * Since we ordered the SELECT by referenced ID, we can expect that
17234  * multiple entries for the same extension will appear together; this
17235  * saves on searches.
17236  */
17237  ext = NULL;
17238 
17239  for (i = 0; i < ntups; i++)
17240  {
17241  CatalogId objId;
17242  Oid extId;
17243 
17244  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
17245  objId.oid = atooid(PQgetvalue(res, i, i_objid));
17246  extId = atooid(PQgetvalue(res, i, i_refobjid));
17247 
17248  if (ext == NULL ||
17249  ext->dobj.catId.oid != extId)
17250  ext = findExtensionByOid(extId);
17251 
17252  if (ext == NULL)
17253  {
17254  /* shouldn't happen */
17255  fprintf(stderr, "could not find referenced extension %u\n", extId);
17256  continue;
17257  }
17258 
17259  extmembers[nextmembers].catId = objId;
17260  extmembers[nextmembers].ext = ext;
17261  nextmembers++;
17262  }
17263 
17264  PQclear(res);
17265 
17266  /* Remember the data for use later */
17267  setExtensionMembership(extmembers, nextmembers);
17268 
17269  destroyPQExpBuffer(query);
17270 }
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void setExtensionMembership(ExtensionMemberId *extmems, int nextmems)
Definition: common.c: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:17824
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
static ExtensionMemberId * extmembers
Definition: common.c:66
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:825
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
CatalogId catId
Definition: pg_dump.h:131
CatalogId catId
Definition: pg_dump.h:620
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
ExtensionInfo* getExtensions ( Archive fout,
int *  numExtensions 
)

Definition at line 4314 of file pg_dump.c.

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

Referenced by getSchemaData().

4315 {
4316  DumpOptions *dopt = fout->dopt;
4317  PGresult *res;
4318  int ntups;
4319  int i;
4320  PQExpBuffer query;
4321  ExtensionInfo *extinfo;
4322  int i_tableoid;
4323  int i_oid;
4324  int i_extname;
4325  int i_nspname;
4326  int i_extrelocatable;
4327  int i_extversion;
4328  int i_extconfig;
4329  int i_extcondition;
4330 
4331  /*
4332  * Before 9.1, there are no extensions.
4333  */
4334  if (fout->remoteVersion < 90100)
4335  {
4336  *numExtensions = 0;
4337  return NULL;
4338  }
4339 
4340  query = createPQExpBuffer();
4341 
4342  /* Make sure we are in proper schema */
4343  selectSourceSchema(fout, "pg_catalog");
4344 
4345  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
4346  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
4347  "FROM pg_extension x "
4348  "JOIN pg_namespace n ON n.oid = x.extnamespace");
4349 
4350  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4351 
4352  ntups = PQntuples(res);
4353 
4354  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
4355 
4356  i_tableoid = PQfnumber(res, "tableoid");
4357  i_oid = PQfnumber(res, "oid");
4358  i_extname = PQfnumber(res, "extname");
4359  i_nspname = PQfnumber(res, "nspname");
4360  i_extrelocatable = PQfnumber(res, "extrelocatable");
4361  i_extversion = PQfnumber(res, "extversion");
4362  i_extconfig = PQfnumber(res, "extconfig");
4363  i_extcondition = PQfnumber(res, "extcondition");
4364 
4365  for (i = 0; i < ntups; i++)
4366  {
4367  extinfo[i].dobj.objType = DO_EXTENSION;
4368  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4369  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4370  AssignDumpId(&extinfo[i].dobj);
4371  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
4372  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
4373  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
4374  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
4375  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
4376  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
4377 
4378  /* Decide whether we want to dump it */
4379  selectDumpableExtension(&(extinfo[i]), dopt);
4380  }
4381 
4382  PQclear(res);
4383  destroyPQExpBuffer(query);
4384 
4385  *numExtensions = ntups;
4386 
4387  return extinfo;
4388 }
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpOptions * dopt
Definition: pg_backup.h: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:17824
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:1621
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * extcondition
Definition: pg_dump.h:160
#define NULL
Definition: c.h:229
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
bool relocatable
Definition: pg_dump.h:156
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
char * extversion
Definition: pg_dump.h:158
FdwInfo* getForeignDataWrappers ( Archive fout,
int *  numForeignDataWrappers 
)

Definition at line 8661 of file pg_dump.c.

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

Referenced by getSchemaData().

8662 {
8663  DumpOptions *dopt = fout->dopt;
8664  PGresult *res;
8665  int ntups;
8666  int i;
8667  PQExpBuffer query;
8668  FdwInfo *fdwinfo;
8669  int i_tableoid;
8670  int i_oid;
8671  int i_fdwname;
8672  int i_rolname;
8673  int i_fdwhandler;
8674  int i_fdwvalidator;
8675  int i_fdwacl;
8676  int i_rfdwacl;
8677  int i_initfdwacl;
8678  int i_initrfdwacl;
8679  int i_fdwoptions;
8680 
8681  /* Before 8.4, there are no foreign-data wrappers */
8682  if (fout->remoteVersion < 80400)
8683  {
8684  *numForeignDataWrappers = 0;
8685  return NULL;
8686  }
8687 
8688  query = createPQExpBuffer();
8689 
8690  /* Make sure we are in proper schema */
8691  selectSourceSchema(fout, "pg_catalog");
8692 
8693  if (fout->remoteVersion >= 90600)
8694  {
8695  PQExpBuffer acl_subquery = createPQExpBuffer();
8696  PQExpBuffer racl_subquery = createPQExpBuffer();
8697  PQExpBuffer initacl_subquery = createPQExpBuffer();
8698  PQExpBuffer initracl_subquery = createPQExpBuffer();
8699 
8700  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8701  initracl_subquery, "f.fdwacl", "f.fdwowner", "'F'",
8702  dopt->binary_upgrade);
8703 
8704  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.fdwname, "
8705  "(%s f.fdwowner) AS rolname, "
8706  "f.fdwhandler::pg_catalog.regproc, "
8707  "f.fdwvalidator::pg_catalog.regproc, "
8708  "%s AS fdwacl, "
8709  "%s AS rfdwacl, "
8710  "%s AS initfdwacl, "
8711  "%s AS initrfdwacl, "
8712  "array_to_string(ARRAY("
8713  "SELECT quote_ident(option_name) || ' ' || "
8714  "quote_literal(option_value) "
8715  "FROM pg_options_to_table(f.fdwoptions) "
8716  "ORDER BY option_name"
8717  "), E',\n ') AS fdwoptions "
8718  "FROM pg_foreign_data_wrapper f "
8719  "LEFT JOIN pg_init_privs pip ON "
8720  "(f.oid = pip.objoid "
8721  "AND pip.classoid = 'pg_foreign_data_wrapper'::regclass "
8722  "AND pip.objsubid = 0) ",
8724  acl_subquery->data,
8725  racl_subquery->data,
8726  initacl_subquery->data,
8727  initracl_subquery->data);
8728 
8729  destroyPQExpBuffer(acl_subquery);
8730  destroyPQExpBuffer(racl_subquery);
8731  destroyPQExpBuffer(initacl_subquery);
8732  destroyPQExpBuffer(initracl_subquery);
8733  }
8734  else if (fout->remoteVersion >= 90100)
8735  {
8736  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8737  "(%s fdwowner) AS rolname, "
8738  "fdwhandler::pg_catalog.regproc, "
8739  "fdwvalidator::pg_catalog.regproc, fdwacl, "
8740  "NULL as rfdwacl, "
8741  "NULL as initfdwacl, NULL AS initrfdwacl, "
8742  "array_to_string(ARRAY("
8743  "SELECT quote_ident(option_name) || ' ' || "
8744  "quote_literal(option_value) "
8745  "FROM pg_options_to_table(fdwoptions) "
8746  "ORDER BY option_name"
8747  "), E',\n ') AS fdwoptions "
8748  "FROM pg_foreign_data_wrapper",
8750  }
8751  else
8752  {
8753  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8754  "(%s fdwowner) AS rolname, "
8755  "'-' AS fdwhandler, "
8756  "fdwvalidator::pg_catalog.regproc, fdwacl, "
8757  "NULL as rfdwacl, "
8758  "NULL as initfdwacl, NULL AS initrfdwacl, "
8759  "array_to_string(ARRAY("
8760  "SELECT quote_ident(option_name) || ' ' || "
8761  "quote_literal(option_value) "
8762  "FROM pg_options_to_table(fdwoptions) "
8763  "ORDER BY option_name"
8764  "), E',\n ') AS fdwoptions "
8765  "FROM pg_foreign_data_wrapper",
8767  }
8768 
8769  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8770 
8771  ntups = PQntuples(res);
8772  *numForeignDataWrappers = ntups;
8773 
8774  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
8775 
8776  i_tableoid = PQfnumber(res, "tableoid");
8777  i_oid = PQfnumber(res, "oid");
8778  i_fdwname = PQfnumber(res, "fdwname");
8779  i_rolname = PQfnumber(res, "rolname");
8780  i_fdwhandler = PQfnumber(res, "fdwhandler");
8781  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
8782  i_fdwacl = PQfnumber(res, "fdwacl");
8783  i_rfdwacl = PQfnumber(res, "rfdwacl");
8784  i_initfdwacl = PQfnumber(res, "initfdwacl");
8785  i_initrfdwacl = PQfnumber(res, "initrfdwacl");
8786  i_fdwoptions = PQfnumber(res, "fdwoptions");
8787 
8788  for (i = 0; i < ntups; i++)
8789  {
8790  fdwinfo[i].dobj.objType = DO_FDW;
8791  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8792  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8793  AssignDumpId(&fdwinfo[i].dobj);
8794  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
8795  fdwinfo[i].dobj.namespace = NULL;
8796  fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
8797  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
8798  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
8799  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
8800  fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
8801  fdwinfo[i].rfdwacl = pg_strdup(PQgetvalue(res, i, i_rfdwacl));
8802  fdwinfo[i].initfdwacl = pg_strdup(PQgetvalue(res, i, i_initfdwacl));
8803  fdwinfo[i].initrfdwacl = pg_strdup(PQgetvalue(res, i, i_initrfdwacl));
8804 
8805  /* Decide whether we want to dump it */
8806  selectDumpableObject(&(fdwinfo[i].dobj), fout);
8807 
8808  /* Do not try to dump ACL if no ACL exists. */
8809  if (PQgetisnull(res, i, i_fdwacl) && PQgetisnull(res, i, i_rfdwacl) &&
8810  PQgetisnull(res, i, i_initfdwacl) &&
8811  PQgetisnull(res, i, i_initrfdwacl))
8812  fdwinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8813  }
8814 
8815  PQclear(res);
8816 
8817  destroyPQExpBuffer(query);
8818 
8819  return fdwinfo;
8820 }
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:1660
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * fdwoptions
Definition: pg_dump.h:517
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:513
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h: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:17824
static const char * username_subquery
Definition: pg_dump.c:96
char * rolname
Definition: pg_dump.h:514
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * initfdwacl
Definition: pg_dump.h:520
Definition: pg_dump.h:73
#define NULL
Definition: c.h:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
char * initrfdwacl
Definition: pg_dump.h:521
CatalogId catId
Definition: pg_dump.h:131
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
ForeignServerInfo* getForeignServers ( Archive fout,
int *  numForeignServers 
)

Definition at line 8830 of file pg_dump.c.

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

Referenced by getSchemaData().

8831 {
8832  DumpOptions *dopt = fout->dopt;
8833  PGresult *res;
8834  int ntups;
8835  int i;
8836  PQExpBuffer query;
8837  ForeignServerInfo *srvinfo;
8838  int i_tableoid;
8839  int i_oid;
8840  int i_srvname;
8841  int i_rolname;
8842  int i_srvfdw;
8843  int i_srvtype;
8844  int i_srvversion;
8845  int i_srvacl;
8846  int i_rsrvacl;
8847  int i_initsrvacl;
8848  int i_initrsrvacl;
8849  int i_srvoptions;
8850 
8851  /* Before 8.4, there are no foreign servers */
8852  if (fout->remoteVersion < 80400)
8853  {
8854  *numForeignServers = 0;
8855  return NULL;
8856  }
8857 
8858  query = createPQExpBuffer();
8859 
8860  /* Make sure we are in proper schema */
8861  selectSourceSchema(fout, "pg_catalog");
8862 
8863  if (fout->remoteVersion >= 90600)
8864  {
8865  PQExpBuffer acl_subquery = createPQExpBuffer();
8866  PQExpBuffer racl_subquery = createPQExpBuffer();
8867  PQExpBuffer initacl_subquery = createPQExpBuffer();
8868  PQExpBuffer initracl_subquery = createPQExpBuffer();
8869 
8870  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8871  initracl_subquery, "f.srvacl", "f.srvowner", "'S'",
8872  dopt->binary_upgrade);
8873 
8874  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.srvname, "
8875  "(%s f.srvowner) AS rolname, "
8876  "f.srvfdw, f.srvtype, f.srvversion, "
8877  "%s AS srvacl, "
8878  "%s AS rsrvacl, "
8879  "%s AS initsrvacl, "
8880  "%s AS initrsrvacl, "
8881  "array_to_string(ARRAY("
8882  "SELECT quote_ident(option_name) || ' ' || "
8883  "quote_literal(option_value) "
8884  "FROM pg_options_to_table(f.srvoptions) "
8885  "ORDER BY option_name"
8886  "), E',\n ') AS srvoptions "
8887  "FROM pg_foreign_server f "
8888  "LEFT JOIN pg_init_privs pip "
8889  "ON (f.oid = pip.objoid "
8890  "AND pip.classoid = 'pg_foreign_server'::regclass "
8891  "AND pip.objsubid = 0) ",
8893  acl_subquery->data,
8894  racl_subquery->data,
8895  initacl_subquery->data,
8896  initracl_subquery->data);
8897 
8898  destroyPQExpBuffer(acl_subquery);
8899  destroyPQExpBuffer(racl_subquery);
8900  destroyPQExpBuffer(initacl_subquery);
8901  destroyPQExpBuffer(initracl_subquery);
8902  }
8903  else
8904  {
8905  appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
8906  "(%s srvowner) AS rolname, "
8907  "srvfdw, srvtype, srvversion, srvacl, "
8908  "NULL AS rsrvacl, "
8909  "NULL AS initsrvacl, NULL AS initrsrvacl, "
8910  "array_to_string(ARRAY("
8911  "SELECT quote_ident(option_name) || ' ' || "
8912  "quote_literal(option_value) "
8913  "FROM pg_options_to_table(srvoptions) "
8914  "ORDER BY option_name"
8915  "), E',\n ') AS srvoptions "
8916  "FROM pg_foreign_server",
8918  }
8919 
8920  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8921 
8922  ntups = PQntuples(res);
8923  *numForeignServers = ntups;
8924 
8925  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
8926 
8927  i_tableoid = PQfnumber(res, "tableoid");
8928  i_oid = PQfnumber(res, "oid");
8929  i_srvname = PQfnumber(res, "srvname");
8930  i_rolname = PQfnumber(res, "rolname");
8931  i_srvfdw = PQfnumber(res, "srvfdw");
8932  i_srvtype = PQfnumber(res, "srvtype");
8933  i_srvversion = PQfnumber(res, "srvversion");
8934  i_srvacl = PQfnumber(res, "srvacl");
8935  i_rsrvacl = PQfnumber(res, "rsrvacl");
8936  i_initsrvacl = PQfnumber(res, "initsrvacl");
8937  i_initrsrvacl = PQfnumber(res, "initrsrvacl");
8938  i_srvoptions = PQfnumber(res, "srvoptions");
8939 
8940  for (i = 0; i < ntups; i++)
8941  {
8942  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
8943  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8944  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8945  AssignDumpId(&srvinfo[i].dobj);
8946  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
8947  srvinfo[i].dobj.namespace = NULL;
8948  srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
8949  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
8950  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
8951  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
8952  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
8953  srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl));
8954  srvinfo[i].rsrvacl = pg_strdup(PQgetvalue(res, i, i_rsrvacl));
8955  srvinfo[i].initsrvacl = pg_strdup(PQgetvalue(res, i, i_initsrvacl));
8956  srvinfo[i].initrsrvacl = pg_strdup(PQgetvalue(res, i, i_initrsrvacl));
8957 
8958  /* Decide whether we want to dump it */
8959  selectDumpableObject(&(srvinfo[i].dobj), fout);
8960 
8961  /* Do not try to dump ACL if no ACL exists. */
8962  if (PQgetisnull(res, i, i_srvacl) && PQgetisnull(res, i, i_rsrvacl) &&
8963  PQgetisnull(res, i, i_initsrvacl) &&
8964  PQgetisnull(res, i, i_initrsrvacl))
8965  srvinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8966  }
8967 
8968  PQclear(res);
8969 
8970  destroyPQExpBuffer(query);
8971 
8972  return srvinfo;
8973 }
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:1660
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
char * initrsrvacl
Definition: pg_dump.h:534
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h: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:17824
static const char * username_subquery
Definition: pg_dump.c:96
char * srvversion
Definition: pg_dump.h:530
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
DumpableObject dobj
Definition: pg_dump.h:526
int i
char * initsrvacl
Definition: pg_dump.h:533
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
FuncInfo* getFuncs ( Archive fout,
int *  numFuncs 
)

Definition at line 5333 of file pg_dump.c.

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

Referenced by getSchemaData().

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

Definition at line 6459 of file pg_dump.c.

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

Referenced by getSchemaData().

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

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

6406 {
6407  PGresult *res;
6408  int ntups;
6409  int i;
6410  PQExpBuffer query = createPQExpBuffer();
6411  InhInfo *inhinfo;
6412 
6413  int i_inhrelid;
6414  int i_inhparent;
6415 
6416  /* Make sure we are in proper schema */
6417  selectSourceSchema(fout, "pg_catalog");
6418 
6419  /*
6420  * Find all the inheritance information, excluding implicit inheritance
6421  * via partitioning. We handle that case using getPartitions(), because
6422  * we want more information about partitions than just the parent-child
6423  * relationship.
6424  */
6425  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
6426 
6427  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6428 
6429  ntups = PQntuples(res);
6430 
6431  *numInherits = ntups;
6432 
6433  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6434 
6435  i_inhrelid = PQfnumber(res, "inhrelid");
6436  i_inhparent = PQfnumber(res, "inhparent");
6437 
6438  for (i = 0; i < ntups; i++)
6439  {
6440  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6441  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6442  }
6443 
6444  PQclear(res);
6445 
6446  destroyPQExpBuffer(query);
6447 
6448  return inhinfo;
6449 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
Oid inhrelid
Definition: pg_dump.h:475
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
Oid inhparent
Definition: pg_dump.h:476
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
DumpId getMaxDumpId ( void  )

Definition at line 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 4142 of file pg_dump.c.

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

Referenced by getSchemaData().

4143 {
4144  DumpOptions *dopt = fout->dopt;
4145  PGresult *res;
4146  int ntups;
4147  int i;
4148  PQExpBuffer query;
4149  NamespaceInfo *nsinfo;
4150  int i_tableoid;
4151  int i_oid;
4152  int i_nspname;
4153  int i_rolname;
4154  int i_nspacl;
4155  int i_rnspacl;
4156  int i_initnspacl;
4157  int i_initrnspacl;
4158 
4159  query = createPQExpBuffer();
4160 
4161  /* Make sure we are in proper schema */
4162  selectSourceSchema(fout, "pg_catalog");
4163 
4164  /*
4165  * we fetch all namespaces including system ones, so that every object we
4166  * read in can be linked to a containing namespace.
4167  */
4168  if (fout->remoteVersion >= 90600)
4169  {
4170  PQExpBuffer acl_subquery = createPQExpBuffer();
4171  PQExpBuffer racl_subquery = createPQExpBuffer();
4172  PQExpBuffer init_acl_subquery = createPQExpBuffer();
4173  PQExpBuffer init_racl_subquery = createPQExpBuffer();
4174 
4175  buildACLQueries(acl_subquery, racl_subquery, init_acl_subquery,
4176  init_racl_subquery, "n.nspacl", "n.nspowner", "'n'",
4177  dopt->binary_upgrade);
4178 
4179  appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, "
4180  "(%s nspowner) AS rolname, "
4181  "%s as nspacl, "
4182  "%s as rnspacl, "
4183  "%s as initnspacl, "
4184  "%s as initrnspacl "
4185  "FROM pg_namespace n "
4186  "LEFT JOIN pg_init_privs pip "
4187  "ON (n.oid = pip.objoid "
4188  "AND pip.classoid = 'pg_namespace'::regclass "
4189  "AND pip.objsubid = 0",
4191  acl_subquery->data,
4192  racl_subquery->data,
4193  init_acl_subquery->data,
4194  init_racl_subquery->data);
4195 
4196  /*
4197  * When we are doing a 'clean' run, we will be dropping and recreating
4198  * the 'public' schema (the only object which has that kind of
4199  * treatment in the backend and which has an entry in pg_init_privs)
4200  * and therefore we should not consider any initial privileges in
4201  * pg_init_privs in that case.
4202  *
4203  * See pg_backup_archiver.c:_printTocEntry() for the details on why
4204  * the public schema is special in this regard.
4205  *
4206  * Note that if the public schema is dropped and re-created, this is
4207  * essentially a no-op because the new public schema won't have an
4208  * entry in pg_init_privs anyway, as the entry will be removed when
4209  * the public schema is dropped.
4210  *
4211  * Further, we have to handle the case where the public schema does
4212  * not exist at all.
4213  */
4214  if (dopt->outputClean)
4215  appendPQExpBuffer(query, " AND pip.objoid <> "
4216  "coalesce((select oid from pg_namespace "
4217  "where nspname = 'public'),0)");
4218 
4219  appendPQExpBuffer(query, ") ");
4220 
4221  destroyPQExpBuffer(acl_subquery);
4222  destroyPQExpBuffer(racl_subquery);
4223  destroyPQExpBuffer(init_acl_subquery);
4224  destroyPQExpBuffer(init_racl_subquery);
4225  }
4226  else
4227  appendPQExpBuffer(query, "SELECT tableoid, oid, nspname, "
4228  "(%s nspowner) AS rolname, "
4229  "nspacl, NULL as rnspacl, "
4230  "NULL AS initnspacl, NULL as initrnspacl "
4231  "FROM pg_namespace",
4233 
4234  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4235 
4236  ntups = PQntuples(res);
4237 
4238  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
4239 
4240  i_tableoid = PQfnumber(res, "tableoid");
4241  i_oid = PQfnumber(res, "oid");
4242  i_nspname = PQfnumber(res, "nspname");
4243  i_rolname = PQfnumber(res, "rolname");
4244  i_nspacl = PQfnumber(res, "nspacl");
4245  i_rnspacl = PQfnumber(res, "rnspacl");
4246  i_initnspacl = PQfnumber(res, "initnspacl");
4247  i_initrnspacl = PQfnumber(res, "initrnspacl");
4248 
4249  for (i = 0; i < ntups; i++)
4250  {
4251  nsinfo[i].dobj.objType = DO_NAMESPACE;
4252  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4253  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4254  AssignDumpId(&nsinfo[i].dobj);
4255  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
4256  nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4257  nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl));
4258  nsinfo[i].rnspacl = pg_strdup(PQgetvalue(res, i, i_rnspacl));
4259  nsinfo[i].initnspacl = pg_strdup(PQgetvalue(res, i, i_initnspacl));
4260  nsinfo[i].initrnspacl = pg_strdup(PQgetvalue(res, i, i_initrnspacl));
4261 
4262  /* Decide whether to dump this namespace */
4263  selectDumpableNamespace(&nsinfo[i], fout);
4264 
4265  /*
4266  * Do not try to dump ACL if the ACL is empty or the default.
4267  *
4268  * This is useful because, for some schemas/objects, the only
4269  * component we are going to try and dump is the ACL and if we can
4270  * remove that then 'dump' goes to zero/false and we don't consider
4271  * this object for dumping at all later on.
4272  */
4273  if (PQgetisnull(res, i, i_nspacl) && PQgetisnull(res, i, i_rnspacl) &&
4274  PQgetisnull(res, i, i_initnspacl) &&
4275  PQgetisnull(res, i, i_initrnspacl))
4276  nsinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4277 
4278  if (strlen(nsinfo[i].rolname) == 0)
4279  write_msg(NULL, "WARNING: owner of schema \"%s\" appears to be invalid\n",
4280  nsinfo[i].dobj.name);
4281  }
4282 
4283  PQclear(res);
4284  destroyPQExpBuffer(query);
4285 
4286  *numNamespaces = ntups;
4287 
4288  return nsinfo;
4289 }
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
char * rnspacl
Definition: pg_dump.h:148
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h: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:17824
static const char * username_subquery
Definition: pg_dump.c:96
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1374
void PQclear(PGresult *res)
Definition: fe-exec.c:650
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
int outputClean
Definition: pg_backup.h: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:3092
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
OpclassInfo* getOpclasses ( Archive fout,
int *  numOpclasses 
)

Definition at line 4976 of file pg_dump.c.

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

Referenced by getSchemaData().

4977 {
4978  PGresult *res;
4979  int ntups;
4980  int i;
4981  PQExpBuffer query = createPQExpBuffer();
4982  OpclassInfo *opcinfo;
4983  int i_tableoid;
4984  int i_oid;
4985  int i_opcname;
4986  int i_opcnamespace;
4987  int i_rolname;
4988 
4989  /*
4990  * find all opclasses, including builtin opclasses; we filter out
4991  * system-defined opclasses at dump-out time.
4992  */
4993 
4994  /* Make sure we are in proper schema */
4995  selectSourceSchema(fout, "pg_catalog");
4996 
4997  appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
4998  "opcnamespace, "
4999  "(%s opcowner) AS rolname "
5000  "FROM pg_opclass",
5002 
5003  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5004 
5005  ntups = PQntuples(res);
5006  *numOpclasses = ntups;
5007 
5008  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
5009 
5010  i_tableoid = PQfnumber(res, "tableoid");
5011  i_oid = PQfnumber(res, "oid");
5012  i_opcname = PQfnumber(res, "opcname");
5013  i_opcnamespace = PQfnumber(res, "opcnamespace");
5014  i_rolname = PQfnumber(res, "rolname");
5015 
5016  for (i = 0; i < ntups; i++)
5017  {
5018  opcinfo[i].dobj.objType = DO_OPCLASS;
5019  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5020  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5021  AssignDumpId(&opcinfo[i].dobj);
5022  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
5023  opcinfo[i].dobj.namespace =
5024  findNamespace(fout,
5025  atooid(PQgetvalue(res, i, i_opcnamespace)));
5026  opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5027 
5028  /* Decide whether we want to dump it */
5029  selectDumpableObject(&(opcinfo[i].dobj), fout);
5030 
5031  /* Op Classes do not currently have ACLs. */
5032  opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5033 
5034  if (strlen(opcinfo[i].rolname) == 0)
5035  write_msg(NULL, "WARNING: owner of operator class \"%s\" appears to be invalid\n",
5036  opcinfo[i].dobj.name);
5037  }
5038 
5039  PQclear(res);
5040 
5041  destroyPQExpBuffer(query);
5042 
5043  return opcinfo;
5044 }
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:1660
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4296
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
char * rolname
Definition: pg_dump.h:235
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
static const char * username_subquery
Definition: pg_dump.c:96
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
DumpableObject dobj
Definition: pg_dump.h:234
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
OprInfo* getOperators ( Archive fout,
int *  numOperators 
)

Definition at line 4654 of file pg_dump.c.

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

Referenced by getSchemaData().

4655 {
4656  PGresult *res;
4657  int ntups;
4658  int i;
4659  PQExpBuffer query = createPQExpBuffer();
4660  OprInfo *oprinfo;
4661  int i_tableoid;
4662  int i_oid;
4663  int i_oprname;
4664  int i_oprnamespace;
4665  int i_rolname;
4666  int i_oprkind;
4667  int i_oprcode;
4668 
4669  /*
4670  * find all operators, including builtin operators; we filter out
4671  * system-defined operators at dump-out time.
4672  */
4673 
4674  /* Make sure we are in proper schema */
4675  selectSourceSchema(fout, "pg_catalog");
4676 
4677  appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
4678  "oprnamespace, "
4679  "(%s oprowner) AS rolname, "
4680  "oprkind, "
4681  "oprcode::oid AS oprcode "
4682  "FROM pg_operator",
4684 
4685  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4686 
4687  ntups = PQntuples(res);
4688  *numOprs = ntups;
4689 
4690  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
4691 
4692  i_tableoid = PQfnumber(res, "tableoid");
4693  i_oid = PQfnumber(res, "oid");
4694  i_oprname = PQfnumber(res, "oprname");
4695  i_oprnamespace = PQfnumber(res, "oprnamespace");
4696  i_rolname = PQfnumber(res, "rolname");
4697  i_oprkind = PQfnumber(res, "oprkind");
4698  i_oprcode = PQfnumber(res, "oprcode");
4699 
4700  for (i = 0; i < ntups; i++)
4701  {
4702  oprinfo[i].dobj.objType = DO_OPERATOR;
4703  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4704  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4705  AssignDumpId(&oprinfo[i].dobj);
4706  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
4707  oprinfo[i].dobj.namespace =
4708  findNamespace(fout,
4709  atooid(PQgetvalue(res, i, i_oprnamespace)));
4710  oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4711  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
4712  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
4713 
4714  /* Decide whether we want to dump it */
4715  selectDumpableObject(&(oprinfo[i].dobj), fout);
4716 
4717  /* Operators do not currently have ACLs. */
4718  oprinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4719 
4720  if (strlen(oprinfo[i].rolname) == 0)
4721  write_msg(NULL, "WARNING: owner of operator \"%s\" appears to be invalid\n",
4722  oprinfo[i].dobj.name);
4723  }
4724 
4725  PQclear(res);
4726 
4727  destroyPQExpBuffer(query);
4728 
4729  return oprinfo;
4730 }
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:1660
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:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4296
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
static const char * username_subquery
Definition: pg_dump.c:96
char * rolname
Definition: pg_dump.h:220
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char oprkind
Definition: pg_dump.h:221
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
Oid oprcode
Definition: pg_dump.h:222
OpfamilyInfo* getOpfamilies ( Archive fout,
int *  numOpfamilies 
)

Definition at line 5054 of file pg_dump.c.

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

Referenced by getSchemaData().

5055 {
5056  PGresult *res;
5057  int ntups;
5058  int i;
5059  PQExpBuffer query;
5060  OpfamilyInfo *opfinfo;
5061  int i_tableoid;
5062  int i_oid;
5063  int i_opfname;
5064  int i_opfnamespace;
5065  int i_rolname;
5066 
5067  /* Before 8.3, there is no separate concept of opfamilies */
5068  if (fout->remoteVersion < 80300)
5069  {
5070  *numOpfamilies = 0;
5071  return NULL;
5072  }
5073 
5074  query = createPQExpBuffer();
5075 
5076  /*
5077