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  _ruleInfo
 
struct  _triggerInfo
 
struct  _evttriggerInfo
 
struct  _constraintInfo
 
struct  _procLangInfo
 
struct  _castInfo
 
struct  _transformInfo
 
struct  _inhInfo
 
struct  _partInfo
 
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 _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 _partInfo PartInfo
 
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_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)
 
PartInfogetPartitions (Archive *fout, int *numPartitions)
 
void getIndexes (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 getTablePartitionKeyInfo (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 96 of file pg_dump.h.

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

#define DUMP_COMPONENT_USERMAP   (1 << 6)

Definition at line 97 of file pg_dump.h.

Referenced by dumpForeignServer().

#define DUMP_COMPONENTS_REQUIRING_LOCK
Value:
(\
#define DUMP_COMPONENT_DATA
Definition: pg_dump.h:92
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:91
#define DUMP_COMPONENT_POLICY
Definition: pg_dump.h:96

Definition at line 122 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 89 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_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,
59  DO_RULE,
60  DO_TRIGGER,
62  DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
64  DO_CAST,
69  DO_TSDICT,
72  DO_FDW,
76  DO_BLOB,
82  DO_POLICY,
DumpableObjectType
Definition: pg_dump.h:41
Definition: pg_dump.h:49
Definition: pg_dump.h:72

Function Documentation

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

Definition at line 745 of file common.c.

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

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

746 {
747  if (dobj->nDeps >= dobj->allocDeps)
748  {
749  if (dobj->allocDeps <= 0)
750  {
751  dobj->allocDeps = 16;
752  dobj->dependencies = (DumpId *)
753  pg_malloc(dobj->allocDeps * sizeof(DumpId));
754  }
755  else
756  {
757  dobj->allocDeps *= 2;
758  dobj->dependencies = (DumpId *)
759  pg_realloc(dobj->dependencies,
760  dobj->allocDeps * sizeof(DumpId));
761  }
762  }
763  dobj->dependencies[dobj->nDeps++] = refId;
764 }
int DumpId
Definition: pg_backup.h:228
DumpId * dependencies
Definition: pg_dump.h:137
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 509 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(), 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().

510 {
511  dobj->dumpId = ++lastDumpId;
512  dobj->name = NULL; /* must be set later */
513  dobj->namespace = NULL; /* may be set later */
514  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
515  dobj->ext_member = false; /* default assumption */
516  dobj->dependencies = NULL;
517  dobj->nDeps = 0;
518  dobj->allocDeps = 0;
519 
520  while (dobj->dumpId >= allocedDumpIds)
521  {
522  int newAlloc;
523 
524  if (allocedDumpIds <= 0)
525  {
526  newAlloc = 256;
528  pg_malloc(newAlloc * sizeof(DumpableObject *));
529  }
530  else
531  {
532  newAlloc = allocedDumpIds * 2;
534  pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
535  }
536  memset(dumpIdMap + allocedDumpIds, 0,
537  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
538  allocedDumpIds = newAlloc;
539  }
540  dumpIdMap[dobj->dumpId] = dobj;
541 
542  /* mark catalogIdMap invalid, but don't rebuild it yet */
543  catalogIdMapValid = false;
544 }
char * name
Definition: pg_dump.h:132
static int allocedDumpIds
Definition: common.c:32
DumpComponents dump
Definition: pg_dump.h:133
static DumpId lastDumpId
Definition: common.c:33
static DumpableObject ** dumpIdMap
Definition: common.c:31
DumpId * dependencies
Definition: pg_dump.h:137
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpId dumpId
Definition: pg_dump.h:131
bool ext_member
Definition: pg_dump.h:136
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
#define NULL
Definition: c.h:226
static bool catalogIdMapValid
Definition: common.c:38
#define DUMP_COMPONENT_ALL
Definition: pg_dump.h:98
DumpId createDumpId ( void  )
CollInfo* findCollationByOid ( Oid  oid)

Definition at line 836 of file common.c.

References findObjectByOid(), and numCollations.

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

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

Definition at line 858 of file common.c.

References findObjectByOid(), and numExtensions.

Referenced by getExtensionMembership().

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

Definition at line 814 of file common.c.

References findObjectByOid(), and numFuncs.

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

815 {
816  return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs);
817 }
static int numFuncs
Definition: common.c:59
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:642
static DumpableObject ** funinfoindex
Definition: common.c:52
NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 847 of file common.c.

References findObjectByOid(), and numNamespaces.

Referenced by findNamespace().

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

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

592 {
593  DumpableObject **low;
594  DumpableObject **high;
595 
596  if (!catalogIdMapValid)
597  {
598  if (catalogIdMap)
601  if (numCatalogIds > 1)
602  qsort((void *) catalogIdMap, numCatalogIds,
604  catalogIdMapValid = true;
605  }
606 
607  /*
608  * We could use bsearch() here, but the notational cruft of calling
609  * bsearch is nearly as bad as doing it ourselves; and the generalized
610  * bsearch function is noticeably slower as well.
611  */
612  if (numCatalogIds <= 0)
613  return NULL;
614  low = catalogIdMap;
615  high = catalogIdMap + (numCatalogIds - 1);
616  while (low <= high)
617  {
618  DumpableObject **middle;
619  int difference;
620 
621  middle = low + (high - low) / 2;
622  /* comparison must match DOCatalogIdCompare, below */
623  difference = oidcmp((*middle)->catId.oid, catalogId.oid);
624  if (difference == 0)
625  difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid);
626  if (difference == 0)
627  return *middle;
628  else if (difference < 0)
629  low = middle + 1;
630  else
631  high = middle - 1;
632  }
633  return NULL;
634 }
Oid tableoid
Definition: pg_backup.h:224
#define oidcmp(x, y)
Definition: pg_dump.h:20
static int DOCatalogIdCompare(const void *p1, const void *p2)
Definition: common.c:701
static int numCatalogIds
Definition: common.c:40
Datum difference(PG_FUNCTION_ARGS)
#define free(a)
Definition: header.h:60
#define NULL
Definition: c.h:226
static DumpableObject ** catalogIdMap
Definition: common.c:39
static bool catalogIdMapValid
Definition: common.c:38
#define qsort(a, b, c, d)
Definition: port.h:440
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition: common.c:723
DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 573 of file common.c.

References allocedDumpIds, and NULL.

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

574 {
575  if (dumpId <= 0 || dumpId >= allocedDumpIds)
576  return NULL; /* out of range? */
577  return dumpIdMap[dumpId];
578 }
static int allocedDumpIds
Definition: common.c:32
static DumpableObject ** dumpIdMap
Definition: common.c:31
#define NULL
Definition: c.h:226
OprInfo* findOprByOid ( Oid  oid)

Definition at line 825 of file common.c.

References findObjectByOid(), and numOperators.

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

Definition at line 885 of file common.c.

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

Referenced by checkExtensionMembership().

886 {
887  ExtensionMemberId *low;
888  ExtensionMemberId *high;
889 
890  /*
891  * We could use bsearch() here, but the notational cruft of calling
892  * bsearch is nearly as bad as doing it ourselves; and the generalized
893  * bsearch function is noticeably slower as well.
894  */
895  if (numextmembers <= 0)
896  return NULL;
897  low = extmembers;
898  high = extmembers + (numextmembers - 1);
899  while (low <= high)
900  {
901  ExtensionMemberId *middle;
902  int difference;
903 
904  middle = low + (high - low) / 2;
905  /* comparison must match ExtensionMemberIdCompare, below */
906  difference = oidcmp(middle->catId.oid, catalogId.oid);
907  if (difference == 0)
908  difference = oidcmp(middle->catId.tableoid, catalogId.tableoid);
909  if (difference == 0)
910  return middle->ext;
911  else if (difference < 0)
912  low = middle + 1;
913  else
914  high = middle - 1;
915  }
916  return NULL;
917 }
ExtensionInfo * ext
Definition: pg_dump.h:619
Oid tableoid
Definition: pg_backup.h:224
#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:226
static int numextmembers
Definition: common.c:67
CatalogId catId
Definition: pg_dump.h:618
TableInfo* findTableByOid ( Oid  oid)

Definition at line 792 of file common.c.

References findObjectByOid(), and numTables.

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

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

Definition at line 803 of file common.c.

References findObjectByOid(), and numTypes.

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

804 {
805  return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes);
806 }
static int numTypes
Definition: common.c:58
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:642
static DumpableObject ** typinfoindex
Definition: common.c:51
AccessMethodInfo* getAccessMethods ( Archive fout,
int *  numAccessMethods 
)

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

4671 {
4672  PGresult *res;
4673  int ntups;
4674  int i;
4675  PQExpBuffer query;
4676  AccessMethodInfo *aminfo;
4677  int i_tableoid;
4678  int i_oid;
4679  int i_amname;
4680  int i_amhandler;
4681  int i_amtype;
4682 
4683  /* Before 9.6, there are no user-defined access methods */
4684  if (fout->remoteVersion < 90600)
4685  {
4686  *numAccessMethods = 0;
4687  return NULL;
4688  }
4689 
4690  query = createPQExpBuffer();
4691 
4692  /* Make sure we are in proper schema */
4693  selectSourceSchema(fout, "pg_catalog");
4694 
4695  /* Select all access methods from pg_am table */
4696  appendPQExpBuffer(query, "SELECT tableoid, oid, amname, amtype, "
4697  "amhandler::pg_catalog.regproc AS amhandler "
4698  "FROM pg_am");
4699 
4700  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4701 
4702  ntups = PQntuples(res);
4703  *numAccessMethods = ntups;
4704 
4705  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
4706 
4707  i_tableoid = PQfnumber(res, "tableoid");
4708  i_oid = PQfnumber(res, "oid");
4709  i_amname = PQfnumber(res, "amname");
4710  i_amhandler = PQfnumber(res, "amhandler");
4711  i_amtype = PQfnumber(res, "amtype");
4712 
4713  for (i = 0; i < ntups; i++)
4714  {
4715  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
4716  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4717  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4718  AssignDumpId(&aminfo[i].dobj);
4719  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
4720  aminfo[i].dobj.namespace = NULL;
4721  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
4722  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
4723 
4724  /* Decide whether we want to dump it */
4725  selectDumpableAccessMethod(&(aminfo[i]), fout);
4726 
4727  /* Access methods do not currently have ACLs. */
4728  aminfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4729  }
4730 
4731  PQclear(res);
4732 
4733  destroyPQExpBuffer(query);
4734 
4735  return aminfo;
4736 }
char * name
Definition: pg_dump.h:132
DumpComponents dump
Definition: pg_dump.h:133
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:226
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:1573
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
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:226
char * amhandler
Definition: pg_dump.h:228
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:95
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
AggInfo* getAggregates ( Archive fout,
int *  numAggregates 
)

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

4913 {
4914  DumpOptions *dopt = fout->dopt;
4915  PGresult *res;
4916  int ntups;
4917  int i;
4918  PQExpBuffer query = createPQExpBuffer();
4919  AggInfo *agginfo;
4920  int i_tableoid;
4921  int i_oid;
4922  int i_aggname;
4923  int i_aggnamespace;
4924  int i_pronargs;
4925  int i_proargtypes;
4926  int i_rolname;
4927  int i_aggacl;
4928  int i_raggacl;
4929  int i_initaggacl;
4930  int i_initraggacl;
4931 
4932  /* Make sure we are in proper schema */
4933  selectSourceSchema(fout, "pg_catalog");
4934 
4935  /*
4936  * Find all interesting aggregates. See comment in getFuncs() for the
4937  * rationale behind the filtering logic.
4938  */
4939  if (fout->remoteVersion >= 90600)
4940  {
4941  PQExpBuffer acl_subquery = createPQExpBuffer();
4942  PQExpBuffer racl_subquery = createPQExpBuffer();
4943  PQExpBuffer initacl_subquery = createPQExpBuffer();
4944  PQExpBuffer initracl_subquery = createPQExpBuffer();
4945 
4946  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
4947  initracl_subquery, "p.proacl", "p.proowner", "'f'",
4948  dopt->binary_upgrade);
4949 
4950  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
4951  "p.proname AS aggname, "
4952  "p.pronamespace AS aggnamespace, "
4953  "p.pronargs, p.proargtypes, "
4954  "(%s p.proowner) AS rolname, "
4955  "%s AS aggacl, "
4956  "%s AS raggacl, "
4957  "%s AS initaggacl, "
4958  "%s AS initraggacl "
4959  "FROM pg_proc p "
4960  "LEFT JOIN pg_init_privs pip ON "
4961  "(p.oid = pip.objoid "
4962  "AND pip.classoid = 'pg_proc'::regclass "
4963  "AND pip.objsubid = 0) "
4964  "WHERE p.proisagg AND ("
4965  "p.pronamespace != "
4966  "(SELECT oid FROM pg_namespace "
4967  "WHERE nspname = 'pg_catalog') OR "
4968  "p.proacl IS DISTINCT FROM pip.initprivs",
4970  acl_subquery->data,
4971  racl_subquery->data,
4972  initacl_subquery->data,
4973  initracl_subquery->data);
4974  if (dopt->binary_upgrade)
4975  appendPQExpBufferStr(query,
4976  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
4977  "classid = 'pg_proc'::regclass AND "
4978  "objid = p.oid AND "
4979  "refclassid = 'pg_extension'::regclass AND "
4980  "deptype = 'e')");
4981  appendPQExpBufferChar(query, ')');
4982 
4983  destroyPQExpBuffer(acl_subquery);
4984  destroyPQExpBuffer(racl_subquery);
4985  destroyPQExpBuffer(initacl_subquery);
4986  destroyPQExpBuffer(initracl_subquery);
4987  }
4988  else if (fout->remoteVersion >= 80200)
4989  {
4990  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
4991  "pronamespace AS aggnamespace, "
4992  "pronargs, proargtypes, "
4993  "(%s proowner) AS rolname, "
4994  "proacl AS aggacl, "
4995  "NULL AS raggacl, "
4996  "NULL AS initaggacl, NULL AS initraggacl "
4997  "FROM pg_proc p "
4998  "WHERE proisagg AND ("
4999  "pronamespace != "
5000  "(SELECT oid FROM pg_namespace "
5001  "WHERE nspname = 'pg_catalog')",
5003  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5004  appendPQExpBufferStr(query,
5005  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5006  "classid = 'pg_proc'::regclass AND "
5007  "objid = p.oid AND "
5008  "refclassid = 'pg_extension'::regclass AND "
5009  "deptype = 'e')");
5010  appendPQExpBufferChar(query, ')');
5011  }
5012  else
5013  {
5014  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5015  "pronamespace AS aggnamespace, "
5016  "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
5017  "proargtypes, "
5018  "(%s proowner) AS rolname, "
5019  "proacl AS aggacl, "
5020  "NULL AS raggacl, "
5021  "NULL AS initaggacl, NULL AS initraggacl "
5022  "FROM pg_proc "
5023  "WHERE proisagg "
5024  "AND pronamespace != "
5025  "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
5027  }
5028 
5029  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5030 
5031  ntups = PQntuples(res);
5032  *numAggs = ntups;
5033 
5034  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5035 
5036  i_tableoid = PQfnumber(res, "tableoid");
5037  i_oid = PQfnumber(res, "oid");
5038  i_aggname = PQfnumber(res, "aggname");
5039  i_aggnamespace = PQfnumber(res, "aggnamespace");
5040  i_pronargs = PQfnumber(res, "pronargs");
5041  i_proargtypes = PQfnumber(res, "proargtypes");
5042  i_rolname = PQfnumber(res, "rolname");
5043  i_aggacl = PQfnumber(res, "aggacl");
5044  i_raggacl = PQfnumber(res, "raggacl");
5045  i_initaggacl = PQfnumber(res, "initaggacl");
5046  i_initraggacl = PQfnumber(res, "initraggacl");
5047 
5048  for (i = 0; i < ntups; i++)
5049  {
5050  agginfo[i].aggfn.dobj.objType = DO_AGG;
5051  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5052  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5053  AssignDumpId(&agginfo[i].aggfn.dobj);
5054  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5055  agginfo[i].aggfn.dobj.namespace =
5056  findNamespace(fout,
5057  atooid(PQgetvalue(res, i, i_aggnamespace)));
5058  agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5059  if (strlen(agginfo[i].aggfn.rolname) == 0)
5060  write_msg(NULL, "WARNING: owner of aggregate function \"%s\" appears to be invalid\n",
5061  agginfo[i].aggfn.dobj.name);
5062  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5063  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5064  agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5065  agginfo[i].aggfn.rproacl = pg_strdup(PQgetvalue(res, i, i_raggacl));
5066  agginfo[i].aggfn.initproacl = pg_strdup(PQgetvalue(res, i, i_initaggacl));
5067  agginfo[i].aggfn.initrproacl = pg_strdup(PQgetvalue(res, i, i_initraggacl));
5068  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5069  if (agginfo[i].aggfn.nargs == 0)
5070  agginfo[i].aggfn.argtypes = NULL;
5071  else
5072  {
5073  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5074  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5075  agginfo[i].aggfn.argtypes,
5076  agginfo[i].aggfn.nargs);
5077  }
5078 
5079  /* Decide whether we want to dump it */
5080  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5081 
5082  /* Do not try to dump ACL if no ACL exists. */
5083  if (PQgetisnull(res, i, i_aggacl) && PQgetisnull(res, i, i_raggacl) &&
5084  PQgetisnull(res, i, i_initaggacl) &&
5085  PQgetisnull(res, i, i_initraggacl))
5086  agginfo[i].aggfn.dobj.dump &= ~DUMP_COMPONENT_ACL;
5087  }
5088 
5089  PQclear(res);
5090 
5091  destroyPQExpBuffer(query);
5092 
5093  return agginfo;
5094 }
Oid * argtypes
Definition: pg_dump.h:201
char * name
Definition: pg_dump.h:132
DumpComponents dump
Definition: pg_dump.h:133
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1622
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:200
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4067
char * initrproacl
Definition: pg_dump.h:206
Oid lang
Definition: pg_dump.h:199
DumpableObject dobj
Definition: pg_dump.h:197
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
FuncInfo aggfn
Definition: pg_dump.h:212
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:133
Definition: pg_dump.h:49
DumpOptions * dopt
Definition: pg_backup.h:178
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:688
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static const char * username_subquery
Definition: pg_dump.c:94
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1034
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:202
#define NULL
Definition: c.h:226
char * initproacl
Definition: pg_dump.h:205
char * rolname
Definition: pg_dump.h:198
char * proacl
Definition: pg_dump.h:203
char * rproacl
Definition: pg_dump.h:204
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:95
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
CastInfo* getCasts ( Archive fout,
int *  numCasts 
)

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

7295 {
7296  PGresult *res;
7297  int ntups;
7298  int i;
7299  PQExpBuffer query = createPQExpBuffer();
7300  CastInfo *castinfo;
7301  int i_tableoid;
7302  int i_oid;
7303  int i_castsource;
7304  int i_casttarget;
7305  int i_castfunc;
7306  int i_castcontext;
7307  int i_castmethod;
7308 
7309  /* Make sure we are in proper schema */
7310  selectSourceSchema(fout, "pg_catalog");
7311 
7312  if (fout->remoteVersion >= 80400)
7313  {
7314  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7315  "castsource, casttarget, castfunc, castcontext, "
7316  "castmethod "
7317  "FROM pg_cast ORDER BY 3,4");
7318  }
7319  else
7320  {
7321  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7322  "castsource, casttarget, castfunc, castcontext, "
7323  "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
7324  "FROM pg_cast ORDER BY 3,4");
7325  }
7326 
7327  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7328 
7329  ntups = PQntuples(res);
7330 
7331  *numCasts = ntups;
7332 
7333  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
7334 
7335  i_tableoid = PQfnumber(res, "tableoid");
7336  i_oid = PQfnumber(res, "oid");
7337  i_castsource = PQfnumber(res, "castsource");
7338  i_casttarget = PQfnumber(res, "casttarget");
7339  i_castfunc = PQfnumber(res, "castfunc");
7340  i_castcontext = PQfnumber(res, "castcontext");
7341  i_castmethod = PQfnumber(res, "castmethod");
7342 
7343  for (i = 0; i < ntups; i++)
7344  {
7345  PQExpBufferData namebuf;
7346  TypeInfo *sTypeInfo;
7347  TypeInfo *tTypeInfo;
7348 
7349  castinfo[i].dobj.objType = DO_CAST;
7350  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7351  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7352  AssignDumpId(&castinfo[i].dobj);
7353  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
7354  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
7355  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
7356  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
7357  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
7358 
7359  /*
7360  * Try to name cast as concatenation of typnames. This is only used
7361  * for purposes of sorting. If we fail to find either type, the name
7362  * will be an empty string.
7363  */
7364  initPQExpBuffer(&namebuf);
7365  sTypeInfo = findTypeByOid(castinfo[i].castsource);
7366  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
7367  if (sTypeInfo && tTypeInfo)
7368  appendPQExpBuffer(&namebuf, "%s %s",
7369  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
7370  castinfo[i].dobj.name = namebuf.data;
7371 
7372  /* Decide whether we want to dump it */
7373  selectDumpableCast(&(castinfo[i]), fout);
7374 
7375  /* Casts do not currently have ACLs. */
7376  castinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7377  }
7378 
7379  PQclear(res);
7380 
7381  destroyPQExpBuffer(query);
7382 
7383  return castinfo;
7384 }
char * name
Definition: pg_dump.h:132
Oid castsource
Definition: pg_dump.h:445
DumpComponents dump
Definition: pg_dump.h:133
Oid tableoid
Definition: pg_backup.h:224
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:1515
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:447
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:444
Oid casttarget
Definition: pg_dump.h:446
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
DumpableObject dobj
Definition: pg_dump.h:164
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:95
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
char castmethod
Definition: pg_dump.h:449
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:803
DumpableObjectType objType
Definition: pg_dump.h:129
char castcontext
Definition: pg_dump.h:448
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
CollInfo* getCollations ( Archive fout,
int *  numCollations 
)

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

4512 {
4513  PGresult *res;
4514  int ntups;
4515  int i;
4516  PQExpBuffer query;
4517  CollInfo *collinfo;
4518  int i_tableoid;
4519  int i_oid;
4520  int i_collname;
4521  int i_collnamespace;
4522  int i_rolname;
4523 
4524  /* Collations didn't exist pre-9.1 */
4525  if (fout->remoteVersion < 90100)
4526  {
4527  *numCollations = 0;
4528  return NULL;
4529  }
4530 
4531  query = createPQExpBuffer();
4532 
4533  /*
4534  * find all collations, including builtin collations; we filter out
4535  * system-defined collations at dump-out time.
4536  */
4537 
4538  /* Make sure we are in proper schema */
4539  selectSourceSchema(fout, "pg_catalog");
4540 
4541  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
4542  "collnamespace, "
4543  "(%s collowner) AS rolname "
4544  "FROM pg_collation",
4546 
4547  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4548 
4549  ntups = PQntuples(res);
4550  *numCollations = ntups;
4551 
4552  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
4553 
4554  i_tableoid = PQfnumber(res, "tableoid");
4555  i_oid = PQfnumber(res, "oid");
4556  i_collname = PQfnumber(res, "collname");
4557  i_collnamespace = PQfnumber(res, "collnamespace");
4558  i_rolname = PQfnumber(res, "rolname");
4559 
4560  for (i = 0; i < ntups; i++)
4561  {
4562  collinfo[i].dobj.objType = DO_COLLATION;
4563  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4564  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4565  AssignDumpId(&collinfo[i].dobj);
4566  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
4567  collinfo[i].dobj.namespace =
4568  findNamespace(fout,
4569  atooid(PQgetvalue(res, i, i_collnamespace)));
4570  collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4571 
4572  /* Decide whether we want to dump it */
4573  selectDumpableObject(&(collinfo[i].dobj), fout);
4574 
4575  /* Collations do not currently have ACLs. */
4576  collinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4577  }
4578 
4579  PQclear(res);
4580 
4581  destroyPQExpBuffer(query);
4582 
4583  return collinfo;
4584 }
char * name
Definition: pg_dump.h:132
DumpComponents dump
Definition: pg_dump.h:133
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1622
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:4067
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
DumpableObject dobj
Definition: pg_dump.h:245
char * rolname
Definition: pg_dump.h:246
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
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static const char * username_subquery
Definition: pg_dump.c:94
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:226
static int numCollations
Definition: common.c:61
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:95
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
void getConstraints ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

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

6520 {
6521  int i,
6522  j;
6523  ConstraintInfo *constrinfo;
6524  PQExpBuffer query;
6525  PGresult *res;
6526  int i_contableoid,
6527  i_conoid,
6528  i_conname,
6529  i_confrelid,
6530  i_condef;
6531  int ntups;
6532 
6533  query = createPQExpBuffer();
6534 
6535  for (i = 0; i < numTables; i++)
6536  {
6537  TableInfo *tbinfo = &tblinfo[i];
6538 
6539  if (!tbinfo->hastriggers ||
6540  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6541  continue;
6542 
6543  if (g_verbose)
6544  write_msg(NULL, "reading foreign key constraints for table \"%s.%s\"\n",
6545  tbinfo->dobj.namespace->dobj.name,
6546  tbinfo->dobj.name);
6547 
6548  /*
6549  * select table schema to ensure constraint expr is qualified if
6550  * needed
6551  */
6552  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6553 
6554  resetPQExpBuffer(query);
6555  appendPQExpBuffer(query,
6556  "SELECT tableoid, oid, conname, confrelid, "
6557  "pg_catalog.pg_get_constraintdef(oid) AS condef "
6558  "FROM pg_catalog.pg_constraint "
6559  "WHERE conrelid = '%u'::pg_catalog.oid "
6560  "AND contype = 'f'",
6561  tbinfo->dobj.catId.oid);
6562  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6563 
6564  ntups = PQntuples(res);
6565 
6566  i_contableoid = PQfnumber(res, "tableoid");
6567  i_conoid = PQfnumber(res, "oid");
6568  i_conname = PQfnumber(res, "conname");
6569  i_confrelid = PQfnumber(res, "confrelid");
6570  i_condef = PQfnumber(res, "condef");
6571 
6572  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
6573 
6574  for (j = 0; j < ntups; j++)
6575  {
6576  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
6577  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
6578  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
6579  AssignDumpId(&constrinfo[j].dobj);
6580  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
6581  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6582  constrinfo[j].contable = tbinfo;
6583  constrinfo[j].condomain = NULL;
6584  constrinfo[j].contype = 'f';
6585  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
6586  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
6587  constrinfo[j].conindex = 0;
6588  constrinfo[j].condeferrable = false;
6589  constrinfo[j].condeferred = false;
6590  constrinfo[j].conislocal = true;
6591  constrinfo[j].separate = true;
6592  }
6593 
6594  PQclear(res);
6595  }
6596 
6597  destroyPQExpBuffer(query);
6598 }
char * name
Definition: pg_dump.h:132
DumpComponents dump
Definition: pg_dump.h:133
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:276
static int numTables
Definition: common.c:57
DumpId conindex
Definition: pg_dump.h:421
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
DumpableObject dobj
Definition: pg_dump.h:260
char * condef
Definition: pg_dump.h:419
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:415
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
bool condeferrable
Definition: pg_dump.h:422
TypeInfo * condomain
Definition: pg_dump.h:417
bool conislocal
Definition: pg_dump.h:424
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:416
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:91
void write_msg(const char *modulename, const char *fmt,...)
bool condeferred
Definition: pg_dump.h:423
#define NULL
Definition: c.h:226
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
DumpableObjectType objType
Definition: pg_dump.h:129
bool g_verbose
Definition: pg_dump.c:90
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
ConvInfo* getConversions ( Archive fout,
int *  numConversions 
)

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

4595 {
4596  PGresult *res;
4597  int ntups;
4598  int i;
4599  PQExpBuffer query;
4600  ConvInfo *convinfo;
4601  int i_tableoid;
4602  int i_oid;
4603  int i_conname;
4604  int i_connamespace;
4605  int i_rolname;
4606 
4607  query = createPQExpBuffer();
4608 
4609  /*
4610  * find all conversions, including builtin conversions; we filter out
4611  * system-defined conversions at dump-out time.
4612  */
4613 
4614  /* Make sure we are in proper schema */
4615  selectSourceSchema(fout, "pg_catalog");
4616 
4617  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
4618  "connamespace, "
4619  "(%s conowner) AS rolname "
4620  "FROM pg_conversion",
4622 
4623  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4624 
4625  ntups = PQntuples(res);
4626  *numConversions = ntups;
4627 
4628  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
4629 
4630  i_tableoid = PQfnumber(res, "tableoid");
4631  i_oid = PQfnumber(res, "oid");
4632  i_conname = PQfnumber(res, "conname");
4633  i_connamespace = PQfnumber(res, "connamespace");
4634  i_rolname = PQfnumber(res, "rolname");
4635 
4636  for (i = 0; i < ntups; i++)
4637  {
4638  convinfo[i].dobj.objType = DO_CONVERSION;
4639  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4640  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4641  AssignDumpId(&convinfo[i].dobj);
4642  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
4643  convinfo[i].dobj.namespace =
4644  findNamespace(fout,
4645  atooid(PQgetvalue(res, i, i_connamespace)));
4646  convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4647 
4648  /* Decide whether we want to dump it */
4649  selectDumpableObject(&(convinfo[i].dobj), fout);
4650 
4651  /* Conversions do not currently have ACLs. */
4652  convinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4653  }
4654 
4655  PQclear(res);
4656 
4657  destroyPQExpBuffer(query);
4658 
4659  return convinfo;
4660 }
char * name
Definition: pg_dump.h:132
DumpComponents dump
Definition: pg_dump.h:133
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1622
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:4067
char * rolname
Definition: pg_dump.h:252
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
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static const char * username_subquery
Definition: pg_dump.c:94
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:251
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:95
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
DefaultACLInfo* getDefaultACLs ( Archive fout,
int *  numDefaultACLs 
)

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

8672 {
8673  DumpOptions *dopt = fout->dopt;
8674  DefaultACLInfo *daclinfo;
8675  PQExpBuffer query;
8676  PGresult *res;
8677  int i_oid;
8678  int i_tableoid;
8679  int i_defaclrole;
8680  int i_defaclnamespace;
8681  int i_defaclobjtype;
8682  int i_defaclacl;
8683  int i_rdefaclacl;
8684  int i_initdefaclacl;
8685  int i_initrdefaclacl;
8686  int i,
8687  ntups;
8688 
8689  if (fout->remoteVersion < 90000)
8690  {
8691  *numDefaultACLs = 0;
8692  return NULL;
8693  }
8694 
8695  query = createPQExpBuffer();
8696 
8697  /* Make sure we are in proper schema */
8698  selectSourceSchema(fout, "pg_catalog");
8699 
8700  if (fout->remoteVersion >= 90600)
8701  {
8702  PQExpBuffer acl_subquery = createPQExpBuffer();
8703  PQExpBuffer racl_subquery = createPQExpBuffer();
8704  PQExpBuffer initacl_subquery = createPQExpBuffer();
8705  PQExpBuffer initracl_subquery = createPQExpBuffer();
8706 
8707  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8708  initracl_subquery, "defaclacl", "defaclrole",
8709  "CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
8710  dopt->binary_upgrade);
8711 
8712  appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
8713  "(%s d.defaclrole) AS defaclrole, "
8714  "d.defaclnamespace, "
8715  "d.defaclobjtype, "
8716  "%s AS defaclacl, "
8717  "%s AS rdefaclacl, "
8718  "%s AS initdefaclacl, "
8719  "%s AS initrdefaclacl "
8720  "FROM pg_default_acl d "
8721  "LEFT JOIN pg_init_privs pip ON "
8722  "(d.oid = pip.objoid "
8723  "AND pip.classoid = 'pg_default_acl'::regclass "
8724  "AND pip.objsubid = 0) ",
8726  acl_subquery->data,
8727  racl_subquery->data,
8728  initacl_subquery->data,
8729  initracl_subquery->data);
8730  }
8731  else
8732  {
8733  appendPQExpBuffer(query, "SELECT oid, tableoid, "
8734  "(%s defaclrole) AS defaclrole, "
8735  "defaclnamespace, "
8736  "defaclobjtype, "
8737  "defaclacl, "
8738  "NULL AS rdefaclacl, "
8739  "NULL AS initdefaclacl, "
8740  "NULL AS initrdefaclacl "
8741  "FROM pg_default_acl",
8743  }
8744 
8745  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8746 
8747  ntups = PQntuples(res);
8748  *numDefaultACLs = ntups;
8749 
8750  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
8751 
8752  i_oid = PQfnumber(res, "oid");
8753  i_tableoid = PQfnumber(res, "tableoid");
8754  i_defaclrole = PQfnumber(res, "defaclrole");
8755  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
8756  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
8757  i_defaclacl = PQfnumber(res, "defaclacl");
8758  i_rdefaclacl = PQfnumber(res, "rdefaclacl");
8759  i_initdefaclacl = PQfnumber(res, "initdefaclacl");
8760  i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
8761 
8762  for (i = 0; i < ntups; i++)
8763  {
8764  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
8765 
8766  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
8767  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8768  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8769  AssignDumpId(&daclinfo[i].dobj);
8770  /* cheesy ... is it worth coming up with a better object name? */
8771  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
8772 
8773  if (nspid != InvalidOid)
8774  daclinfo[i].dobj.namespace = findNamespace(fout, nspid);
8775  else
8776  daclinfo[i].dobj.namespace = NULL;
8777 
8778  daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
8779  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
8780  daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
8781  daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
8782  daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
8783  daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
8784 
8785  /* Decide whether we want to dump it */
8786  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
8787  }
8788 
8789  PQclear(res);
8790 
8791  destroyPQExpBuffer(query);
8792 
8793  return daclinfo;
8794 }
char * name
Definition: pg_dump.h:132
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:4067
char * rdefaclacl
Definition: pg_dump.h:542
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:1493
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:133
DumpOptions * dopt
Definition: pg_backup.h:178
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:688
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:538
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static const char * username_subquery
Definition: pg_dump.c:94
char * defaclacl
Definition: pg_dump.h:541
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:226
char * initdefaclacl
Definition: pg_dump.h:543
CatalogId catId
Definition: pg_dump.h:130
char * initrdefaclacl
Definition: pg_dump.h:544
#define atooid(x)
Definition: lo.c:17
int i
char defaclobjtype
Definition: pg_dump.h:540
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
char * defaclrole
Definition: pg_dump.h:539
void getDumpableObjects ( DumpableObject ***  objs,
int *  numObjs 
)

Definition at line 723 of file common.c.

References allocedDumpIds, i, and pg_malloc().

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

724 {
725  int i,
726  j;
727 
728  *objs = (DumpableObject **)
730  j = 0;
731  for (i = 1; i < allocedDumpIds; i++)
732  {
733  if (dumpIdMap[i])
734  (*objs)[j++] = dumpIdMap[i];
735  }
736  *numObjs = j;
737 }
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 7019 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().

7020 {
7021  int i;
7022  PQExpBuffer query;
7023  PGresult *res;
7024  EventTriggerInfo *evtinfo;
7025  int i_tableoid,
7026  i_oid,
7027  i_evtname,
7028  i_evtevent,
7029  i_evtowner,
7030  i_evttags,
7031  i_evtfname,
7032  i_evtenabled;
7033  int ntups;
7034 
7035  /* Before 9.3, there are no event triggers */
7036  if (fout->remoteVersion < 90300)
7037  {
7038  *numEventTriggers = 0;
7039  return NULL;
7040  }
7041 
7042  query = createPQExpBuffer();
7043 
7044  /* Make sure we are in proper schema */
7045  selectSourceSchema(fout, "pg_catalog");
7046 
7047  appendPQExpBuffer(query,
7048  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
7049  "evtevent, (%s evtowner) AS evtowner, "
7050  "array_to_string(array("
7051  "select quote_literal(x) "
7052  " from unnest(evttags) as t(x)), ', ') as evttags, "
7053  "e.evtfoid::regproc as evtfname "
7054  "FROM pg_event_trigger e "
7055  "ORDER BY e.oid",
7057 
7058  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7059 
7060  ntups = PQntuples(res);
7061 
7062  *numEventTriggers = ntups;
7063 
7064  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
7065 
7066  i_tableoid = PQfnumber(res, "tableoid");
7067  i_oid = PQfnumber(res, "oid");
7068  i_evtname = PQfnumber(res, "evtname");
7069  i_evtevent = PQfnumber(res, "evtevent");
7070  i_evtowner = PQfnumber(res, "evtowner");
7071  i_evttags = PQfnumber(res, "evttags");
7072  i_evtfname = PQfnumber(res, "evtfname");
7073  i_evtenabled = PQfnumber(res, "evtenabled");
7074 
7075  for (i = 0; i < ntups; i++)
7076  {
7077  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
7078  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7079  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7080  AssignDumpId(&evtinfo[i].dobj);
7081  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
7082  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
7083  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
7084  evtinfo[i].evtowner = pg_strdup(PQgetvalue(res, i, i_evtowner));
7085  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
7086  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
7087  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
7088 
7089  /* Decide whether we want to dump it */
7090  selectDumpableObject(&(evtinfo[i].dobj), fout);
7091 
7092  /* Event Triggers do not currently have ACLs. */
7093  evtinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7094  }
7095 
7096  PQclear(res);
7097 
7098  destroyPQExpBuffer(query);
7099 
7100  return evtinfo;
7101 }
char * name
Definition: pg_dump.h:132
char * evtevent
Definition: pg_dump.h:398
DumpComponents dump
Definition: pg_dump.h:133
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1622
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:399
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static const char * username_subquery
Definition: pg_dump.c:94
char * evtfname
Definition: pg_dump.h:401
char * evttags
Definition: pg_dump.h:400
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
char * evtname
Definition: pg_dump.h:397
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:226
DumpableObject dobj
Definition: pg_dump.h:396
char evtenabled
Definition: pg_dump.h:402
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:95
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
void getExtensionMembership ( Archive fout,
ExtensionInfo  extinfo[],
int  numExtensions 
)

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

16671 {
16672  PQExpBuffer query;
16673  PGresult *res;
16674  int ntups,
16675  nextmembers,
16676  i;
16677  int i_classid,
16678  i_objid,
16679  i_refobjid;
16681  ExtensionInfo *ext;
16682 
16683  /* Nothing to do if no extensions */
16684  if (numExtensions == 0)
16685  return;
16686 
16687  /* Make sure we are in proper schema */
16688  selectSourceSchema(fout, "pg_catalog");
16689 
16690  query = createPQExpBuffer();
16691 
16692  /* refclassid constraint is redundant but may speed the search */
16693  appendPQExpBufferStr(query, "SELECT "
16694  "classid, objid, refobjid "
16695  "FROM pg_depend "
16696  "WHERE refclassid = 'pg_extension'::regclass "
16697  "AND deptype = 'e' "
16698  "ORDER BY 3");
16699 
16700  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
16701 
16702  ntups = PQntuples(res);
16703 
16704  i_classid = PQfnumber(res, "classid");
16705  i_objid = PQfnumber(res, "objid");
16706  i_refobjid = PQfnumber(res, "refobjid");
16707 
16708  extmembers = (ExtensionMemberId *) pg_malloc(ntups * sizeof(ExtensionMemberId));
16709  nextmembers = 0;
16710 
16711  /*
16712  * Accumulate data into extmembers[].
16713  *
16714  * Since we ordered the SELECT by referenced ID, we can expect that
16715  * multiple entries for the same extension will appear together; this
16716  * saves on searches.
16717  */
16718  ext = NULL;
16719 
16720  for (i = 0; i < ntups; i++)
16721  {
16722  CatalogId objId;
16723  Oid extId;
16724 
16725  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
16726  objId.oid = atooid(PQgetvalue(res, i, i_objid));
16727  extId = atooid(PQgetvalue(res, i, i_refobjid));
16728 
16729  if (ext == NULL ||
16730  ext->dobj.catId.oid != extId)
16731  ext = findExtensionByOid(extId);
16732 
16733  if (ext == NULL)
16734  {
16735  /* shouldn't happen */
16736  fprintf(stderr, "could not find referenced extension %u\n", extId);
16737  continue;
16738  }
16739 
16740  extmembers[nextmembers].catId = objId;
16741  extmembers[nextmembers].ext = ext;
16742  nextmembers++;
16743  }
16744 
16745  PQclear(res);
16746 
16747  /* Remember the data for use later */
16748  setExtensionMembership(extmembers, nextmembers);
16749 
16750  destroyPQExpBuffer(query);
16751 }
ExtensionInfo * ext
Definition: pg_dump.h:619
DumpableObject dobj
Definition: pg_dump.h:154
Oid tableoid
Definition: pg_backup.h:224
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:869
static int numExtensions
Definition: common.c:63
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
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:858
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:226
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
CatalogId catId
Definition: pg_dump.h:618
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
ExtensionInfo* getExtensions ( Archive fout,
int *  numExtensions 
)

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

4086 {
4087  DumpOptions *dopt = fout->dopt;
4088  PGresult *res;
4089  int ntups;
4090  int i;
4091  PQExpBuffer query;
4092  ExtensionInfo *extinfo;
4093  int i_tableoid;
4094  int i_oid;
4095  int i_extname;
4096  int i_nspname;
4097  int i_extrelocatable;
4098  int i_extversion;
4099  int i_extconfig;
4100  int i_extcondition;
4101 
4102  /*
4103  * Before 9.1, there are no extensions.
4104  */
4105  if (fout->remoteVersion < 90100)
4106  {
4107  *numExtensions = 0;
4108  return NULL;
4109  }
4110 
4111  query = createPQExpBuffer();
4112 
4113  /* Make sure we are in proper schema */
4114  selectSourceSchema(fout, "pg_catalog");
4115 
4116  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
4117  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
4118  "FROM pg_extension x "
4119  "JOIN pg_namespace n ON n.oid = x.extnamespace");
4120 
4121  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4122 
4123  ntups = PQntuples(res);
4124 
4125  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
4126 
4127  i_tableoid = PQfnumber(res, "tableoid");
4128  i_oid = PQfnumber(res, "oid");
4129  i_extname = PQfnumber(res, "extname");
4130  i_nspname = PQfnumber(res, "nspname");
4131  i_extrelocatable = PQfnumber(res, "extrelocatable");
4132  i_extversion = PQfnumber(res, "extversion");
4133  i_extconfig = PQfnumber(res, "extconfig");
4134  i_extcondition = PQfnumber(res, "extcondition");
4135 
4136  for (i = 0; i < ntups; i++)
4137  {
4138  extinfo[i].dobj.objType = DO_EXTENSION;
4139  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4140  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4141  AssignDumpId(&extinfo[i].dobj);
4142  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
4143  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
4144  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
4145  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
4146  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
4147  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
4148 
4149  /* Decide whether we want to dump it */
4150  selectDumpableExtension(&(extinfo[i]), dopt);
4151  }
4152 
4153  PQclear(res);
4154  destroyPQExpBuffer(query);
4155 
4156  *numExtensions = ntups;
4157 
4158  return extinfo;
4159 }
char * name
Definition: pg_dump.h:132
DumpableObject dobj
Definition: pg_dump.h:154
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:178
char * extconfig
Definition: pg_dump.h:158
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static int numExtensions
Definition: common.c:63
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:1600
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:159
#define NULL
Definition: c.h:226
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
DumpableObjectType objType
Definition: pg_dump.h:129
bool relocatable
Definition: pg_dump.h:155
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
char * extversion
Definition: pg_dump.h:157
FdwInfo* getForeignDataWrappers ( Archive fout,
int *  numForeignDataWrappers 
)

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

8350 {
8351  DumpOptions *dopt = fout->dopt;
8352  PGresult *res;
8353  int ntups;
8354  int i;
8355  PQExpBuffer query;
8356  FdwInfo *fdwinfo;
8357  int i_tableoid;
8358  int i_oid;
8359  int i_fdwname;
8360  int i_rolname;
8361  int i_fdwhandler;
8362  int i_fdwvalidator;
8363  int i_fdwacl;
8364  int i_rfdwacl;
8365  int i_initfdwacl;
8366  int i_initrfdwacl;
8367  int i_fdwoptions;
8368 
8369  /* Before 8.4, there are no foreign-data wrappers */
8370  if (fout->remoteVersion < 80400)
8371  {
8372  *numForeignDataWrappers = 0;
8373  return NULL;
8374  }
8375 
8376  query = createPQExpBuffer();
8377 
8378  /* Make sure we are in proper schema */
8379  selectSourceSchema(fout, "pg_catalog");
8380 
8381  if (fout->remoteVersion >= 90600)
8382  {
8383  PQExpBuffer acl_subquery = createPQExpBuffer();
8384  PQExpBuffer racl_subquery = createPQExpBuffer();
8385  PQExpBuffer initacl_subquery = createPQExpBuffer();
8386  PQExpBuffer initracl_subquery = createPQExpBuffer();
8387 
8388  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8389  initracl_subquery, "f.fdwacl", "f.fdwowner", "'F'",
8390  dopt->binary_upgrade);
8391 
8392  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.fdwname, "
8393  "(%s f.fdwowner) AS rolname, "
8394  "f.fdwhandler::pg_catalog.regproc, "
8395  "f.fdwvalidator::pg_catalog.regproc, "
8396  "%s AS fdwacl, "
8397  "%s AS rfdwacl, "
8398  "%s AS initfdwacl, "
8399  "%s AS initrfdwacl, "
8400  "array_to_string(ARRAY("
8401  "SELECT quote_ident(option_name) || ' ' || "
8402  "quote_literal(option_value) "
8403  "FROM pg_options_to_table(f.fdwoptions) "
8404  "ORDER BY option_name"
8405  "), E',\n ') AS fdwoptions "
8406  "FROM pg_foreign_data_wrapper f "
8407  "LEFT JOIN pg_init_privs pip ON "
8408  "(f.oid = pip.objoid "
8409  "AND pip.classoid = 'pg_foreign_data_wrapper'::regclass "
8410  "AND pip.objsubid = 0) ",
8412  acl_subquery->data,
8413  racl_subquery->data,
8414  initacl_subquery->data,
8415  initracl_subquery->data);
8416 
8417  destroyPQExpBuffer(acl_subquery);
8418  destroyPQExpBuffer(racl_subquery);
8419  destroyPQExpBuffer(initacl_subquery);
8420  destroyPQExpBuffer(initracl_subquery);
8421  }
8422  else if (fout->remoteVersion >= 90100)
8423  {
8424  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8425  "(%s fdwowner) AS rolname, "
8426  "fdwhandler::pg_catalog.regproc, "
8427  "fdwvalidator::pg_catalog.regproc, fdwacl, "
8428  "NULL as rfdwacl, "
8429  "NULL as initfdwacl, NULL AS initrfdwacl, "
8430  "array_to_string(ARRAY("
8431  "SELECT quote_ident(option_name) || ' ' || "
8432  "quote_literal(option_value) "
8433  "FROM pg_options_to_table(fdwoptions) "
8434  "ORDER BY option_name"
8435  "), E',\n ') AS fdwoptions "
8436  "FROM pg_foreign_data_wrapper",
8438  }
8439  else
8440  {
8441  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8442  "(%s fdwowner) AS rolname, "
8443  "'-' AS fdwhandler, "
8444  "fdwvalidator::pg_catalog.regproc, fdwacl, "
8445  "NULL as rfdwacl, "
8446  "NULL as initfdwacl, NULL AS initrfdwacl, "
8447  "array_to_string(ARRAY("
8448  "SELECT quote_ident(option_name) || ' ' || "
8449  "quote_literal(option_value) "
8450  "FROM pg_options_to_table(fdwoptions) "
8451  "ORDER BY option_name"
8452  "), E',\n ') AS fdwoptions "
8453  "FROM pg_foreign_data_wrapper",
8455  }
8456 
8457  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8458 
8459  ntups = PQntuples(res);
8460  *numForeignDataWrappers = ntups;
8461 
8462  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
8463 
8464  i_tableoid = PQfnumber(res, "tableoid");
8465  i_oid = PQfnumber(res, "oid");
8466  i_fdwname = PQfnumber(res, "fdwname");
8467  i_rolname = PQfnumber(res, "rolname");
8468  i_fdwhandler = PQfnumber(res, "fdwhandler");
8469  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
8470  i_fdwacl = PQfnumber(res, "fdwacl");
8471  i_rfdwacl = PQfnumber(res, "rfdwacl");
8472  i_initfdwacl = PQfnumber(res, "initfdwacl");
8473  i_initrfdwacl = PQfnumber(res, "initrfdwacl");
8474  i_fdwoptions = PQfnumber(res, "fdwoptions");
8475 
8476  for (i = 0; i < ntups; i++)
8477  {
8478  fdwinfo[i].dobj.objType = DO_FDW;
8479  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8480  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8481  AssignDumpId(&fdwinfo[i].dobj);
8482  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
8483  fdwinfo[i].dobj.namespace = NULL;
8484  fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
8485  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
8486  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
8487  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
8488  fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
8489  fdwinfo[i].rfdwacl = pg_strdup(PQgetvalue(res, i, i_rfdwacl));
8490  fdwinfo[i].initfdwacl = pg_strdup(PQgetvalue(res, i, i_initfdwacl));
8491  fdwinfo[i].initrfdwacl = pg_strdup(PQgetvalue(res, i, i_initrfdwacl));
8492 
8493  /* Decide whether we want to dump it */
8494  selectDumpableObject(&(fdwinfo[i].dobj), fout);
8495 
8496  /* Do not try to dump ACL if no ACL exists. */
8497  if (PQgetisnull(res, i, i_fdwacl) && PQgetisnull(res, i, i_rfdwacl) &&
8498  PQgetisnull(res, i, i_initfdwacl) &&
8499  PQgetisnull(res, i, i_initrfdwacl))
8500  fdwinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8501  }
8502 
8503  PQclear(res);
8504 
8505  destroyPQExpBuffer(query);
8506 
8507  return fdwinfo;
8508 }
char * name
Definition: pg_dump.h:132
char * rfdwacl
Definition: pg_dump.h:517
DumpComponents dump
Definition: pg_dump.h:133
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1622
Oid tableoid
Definition: pg_backup.h:224
char * fdwhandler
Definition: pg_dump.h:513
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:515
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:511
int binary_upgrade
Definition: pg_backup.h:133
DumpOptions * dopt
Definition: pg_backup.h:178
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:688
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * fdwvalidator
Definition: pg_dump.h:514
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
char * fdwacl
Definition: pg_dump.h:516
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static const char * username_subquery
Definition: pg_dump.c:94
char * rolname
Definition: pg_dump.h:512
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:518
Definition: pg_dump.h:72
#define NULL
Definition: c.h:226
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:95
char * initrfdwacl
Definition: pg_dump.h:519
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
ForeignServerInfo* getForeignServers ( Archive fout,
int *  numForeignServers 
)

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

8519 {
8520  DumpOptions *dopt = fout->dopt;
8521  PGresult *res;
8522  int ntups;
8523  int i;
8524  PQExpBuffer query;
8525  ForeignServerInfo *srvinfo;
8526  int i_tableoid;
8527  int i_oid;
8528  int i_srvname;
8529  int i_rolname;
8530  int i_srvfdw;
8531  int i_srvtype;
8532  int i_srvversion;
8533  int i_srvacl;
8534  int i_rsrvacl;
8535  int i_initsrvacl;
8536  int i_initrsrvacl;
8537  int i_srvoptions;
8538 
8539  /* Before 8.4, there are no foreign servers */
8540  if (fout->remoteVersion < 80400)
8541  {
8542  *numForeignServers = 0;
8543  return NULL;
8544  }
8545 
8546  query = createPQExpBuffer();
8547 
8548  /* Make sure we are in proper schema */
8549  selectSourceSchema(fout, "pg_catalog");
8550 
8551  if (fout->remoteVersion >= 90600)
8552  {
8553  PQExpBuffer acl_subquery = createPQExpBuffer();
8554  PQExpBuffer racl_subquery = createPQExpBuffer();
8555  PQExpBuffer initacl_subquery = createPQExpBuffer();
8556  PQExpBuffer initracl_subquery = createPQExpBuffer();
8557 
8558  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8559  initracl_subquery, "f.srvacl", "f.srvowner", "'S'",
8560  dopt->binary_upgrade);
8561 
8562  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.srvname, "
8563  "(%s f.srvowner) AS rolname, "
8564  "f.srvfdw, f.srvtype, f.srvversion, "
8565  "%s AS srvacl, "
8566  "%s AS rsrvacl, "
8567  "%s AS initsrvacl, "
8568  "%s AS initrsrvacl, "
8569  "array_to_string(ARRAY("
8570  "SELECT quote_ident(option_name) || ' ' || "
8571  "quote_literal(option_value) "
8572  "FROM pg_options_to_table(f.srvoptions) "
8573  "ORDER BY option_name"
8574  "), E',\n ') AS srvoptions "
8575  "FROM pg_foreign_server f "
8576  "LEFT JOIN pg_init_privs pip "
8577  "ON (f.oid = pip.objoid "
8578  "AND pip.classoid = 'pg_foreign_server'::regclass "
8579  "AND pip.objsubid = 0) ",
8581  acl_subquery->data,
8582  racl_subquery->data,
8583  initacl_subquery->data,
8584  initracl_subquery->data);
8585 
8586  destroyPQExpBuffer(acl_subquery);
8587  destroyPQExpBuffer(racl_subquery);
8588  destroyPQExpBuffer(initacl_subquery);
8589  destroyPQExpBuffer(initracl_subquery);
8590  }
8591  else
8592  {
8593  appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
8594  "(%s srvowner) AS rolname, "
8595  "srvfdw, srvtype, srvversion, srvacl, "
8596  "NULL AS rsrvacl, "
8597  "NULL AS initsrvacl, NULL AS initrsrvacl, "
8598  "array_to_string(ARRAY("
8599  "SELECT quote_ident(option_name) || ' ' || "
8600  "quote_literal(option_value) "
8601  "FROM pg_options_to_table(srvoptions) "
8602  "ORDER BY option_name"
8603  "), E',\n ') AS srvoptions "
8604  "FROM pg_foreign_server",
8606  }
8607 
8608  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8609 
8610  ntups = PQntuples(res);
8611  *numForeignServers = ntups;
8612 
8613  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
8614 
8615  i_tableoid = PQfnumber(res, "tableoid");
8616  i_oid = PQfnumber(res, "oid");
8617  i_srvname = PQfnumber(res, "srvname");
8618  i_rolname = PQfnumber(res, "rolname");
8619  i_srvfdw = PQfnumber(res, "srvfdw");
8620  i_srvtype = PQfnumber(res, "srvtype");
8621  i_srvversion = PQfnumber(res, "srvversion");
8622  i_srvacl = PQfnumber(res, "srvacl");
8623  i_rsrvacl = PQfnumber(res, "rsrvacl");
8624  i_initsrvacl = PQfnumber(res, "initsrvacl");
8625  i_initrsrvacl = PQfnumber(res, "initrsrvacl");
8626  i_srvoptions = PQfnumber(res, "srvoptions");
8627 
8628  for (i = 0; i < ntups; i++)
8629  {
8630  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
8631  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8632  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8633  AssignDumpId(&srvinfo[i].dobj);
8634  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
8635  srvinfo[i].dobj.namespace = NULL;
8636  srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
8637  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
8638  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
8639  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
8640  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
8641  srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl));
8642  srvinfo[i].rsrvacl = pg_strdup(PQgetvalue(res, i, i_rsrvacl));
8643  srvinfo[i].initsrvacl = pg_strdup(PQgetvalue(res, i, i_initsrvacl));
8644  srvinfo[i].initrsrvacl = pg_strdup(PQgetvalue(res, i, i_initrsrvacl));
8645 
8646  /* Decide whether we want to dump it */
8647  selectDumpableObject(&(srvinfo[i].dobj), fout);
8648 
8649  /* Do not try to dump ACL if no ACL exists. */
8650  if (PQgetisnull(res, i, i_srvacl) && PQgetisnull(res, i, i_rsrvacl) &&
8651  PQgetisnull(res, i, i_initsrvacl) &&
8652  PQgetisnull(res, i, i_initrsrvacl))
8653  srvinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8654  }
8655 
8656  PQclear(res);
8657 
8658  destroyPQExpBuffer(query);
8659 
8660  return srvinfo;
8661 }
char * srvoptions
Definition: pg_dump.h:533
char * name
Definition: pg_dump.h:132
DumpComponents dump
Definition: pg_dump.h:133
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1622
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:532
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:133
DumpOptions * dopt
Definition: pg_backup.h:178
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:688
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static const char * username_subquery
Definition: pg_dump.c:94
char * srvversion
Definition: pg_dump.h:528
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:226
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:95
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
DumpableObject dobj
Definition: pg_dump.h:524
int i
char * initsrvacl
Definition: pg_dump.h:531
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
FuncInfo* getFuncs ( Archive fout,
int *  numFuncs 
)

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

5105 {
5106  DumpOptions *dopt = fout->dopt;
5107  PGresult *res;
5108  int ntups;
5109  int i;
5110  PQExpBuffer query = createPQExpBuffer();
5111  FuncInfo *finfo;
5112  int i_tableoid;
5113  int i_oid;
5114  int i_proname;
5115  int i_pronamespace;
5116  int i_rolname;
5117  int i_prolang;
5118  int i_pronargs;
5119  int i_proargtypes;
5120  int i_prorettype;
5121  int i_proacl;
5122  int i_rproacl;
5123  int i_initproacl;
5124  int i_initrproacl;
5125 
5126  /* Make sure we are in proper schema */
5127  selectSourceSchema(fout, "pg_catalog");
5128 
5129  /*
5130  * Find all interesting functions. This is a bit complicated:
5131  *
5132  * 1. Always exclude aggregates; those are handled elsewhere.
5133  *
5134  * 2. Always exclude functions that are internally dependent on something
5135  * else, since presumably those will be created as a result of creating
5136  * the something else. This currently acts only to suppress constructor
5137  * functions for range types (so we only need it in 9.2 and up). Note
5138  * this is OK only because the constructors don't have any dependencies
5139  * the range type doesn't have; otherwise we might not get creation
5140  * ordering correct.
5141  *
5142  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
5143  * they're members of extensions and we are in binary-upgrade mode then
5144  * include them, since we want to dump extension members individually in
5145  * that mode. Also, if they are used by casts or transforms then we need
5146  * to gather the information about them, though they won't be dumped if
5147  * they are built-in. Also, in 9.6 and up, include functions in
5148  * pg_catalog if they have an ACL different from what's shown in
5149  * pg_init_privs.
5150  */
5151  if (fout->remoteVersion >= 90600)
5152  {
5153  PQExpBuffer acl_subquery = createPQExpBuffer();
5154  PQExpBuffer racl_subquery = createPQExpBuffer();
5155  PQExpBuffer initacl_subquery = createPQExpBuffer();
5156  PQExpBuffer initracl_subquery = createPQExpBuffer();
5157 
5158  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5159  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5160  dopt->binary_upgrade);
5161 
5162  appendPQExpBuffer(query,
5163  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
5164  "p.pronargs, p.proargtypes, p.prorettype, "
5165  "%s AS proacl, "
5166  "%s AS rproacl, "
5167  "%s AS initproacl, "
5168  "%s AS initrproacl, "
5169  "p.pronamespace, "
5170  "(%s p.proowner) AS rolname "
5171  "FROM pg_proc p "
5172  "LEFT JOIN pg_init_privs pip ON "
5173  "(p.oid = pip.objoid "
5174  "AND pip.classoid = 'pg_proc'::regclass "
5175  "AND pip.objsubid = 0) "
5176  "WHERE NOT proisagg"
5177  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5178  "WHERE classid = 'pg_proc'::regclass AND "
5179  "objid = p.oid AND deptype = 'i')"
5180  "\n AND ("
5181  "\n pronamespace != "
5182  "(SELECT oid FROM pg_namespace "
5183  "WHERE nspname = 'pg_catalog')"
5184  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5185  "\n WHERE pg_cast.oid > %u "
5186  "\n AND p.oid = pg_cast.castfunc)"
5187  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5188  "\n WHERE pg_transform.oid > %u AND "
5189  "\n (p.oid = pg_transform.trffromsql"
5190  "\n OR p.oid = pg_transform.trftosql))",
5191  acl_subquery->data,
5192  racl_subquery->data,
5193  initacl_subquery->data,
5194  initracl_subquery->data,
5198  if (dopt->binary_upgrade)
5199  appendPQExpBufferStr(query,
5200  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5201  "classid = 'pg_proc'::regclass AND "
5202  "objid = p.oid AND "
5203  "refclassid = 'pg_extension'::regclass AND "
5204  "deptype = 'e')");
5205  appendPQExpBufferStr(query,
5206  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
5207  appendPQExpBufferChar(query, ')');
5208 
5209  destroyPQExpBuffer(acl_subquery);
5210  destroyPQExpBuffer(racl_subquery);
5211  destroyPQExpBuffer(initacl_subquery);
5212  destroyPQExpBuffer(initracl_subquery);
5213  }
5214  else
5215  {
5216  appendPQExpBuffer(query,
5217  "SELECT tableoid, oid, proname, prolang, "
5218  "pronargs, proargtypes, prorettype, proacl, "
5219  "NULL as rproacl, "
5220  "NULL as initproacl, NULL AS initrproacl, "
5221  "pronamespace, "
5222  "(%s proowner) AS rolname "
5223  "FROM pg_proc p "
5224  "WHERE NOT proisagg",
5226  if (fout->remoteVersion >= 90200)
5227  appendPQExpBufferStr(query,
5228  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5229  "WHERE classid = 'pg_proc'::regclass AND "
5230  "objid = p.oid AND deptype = 'i')");
5231  appendPQExpBuffer(query,
5232  "\n AND ("
5233  "\n pronamespace != "
5234  "(SELECT oid FROM pg_namespace "
5235  "WHERE nspname = 'pg_catalog')"
5236  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5237  "\n WHERE pg_cast.oid > '%u'::oid"
5238  "\n AND p.oid = pg_cast.castfunc)",
5240 
5241  if (fout->remoteVersion >= 90500)
5242  appendPQExpBuffer(query,
5243  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5244  "\n WHERE pg_transform.oid > '%u'::oid"
5245  "\n AND (p.oid = pg_transform.trffromsql"
5246  "\n OR p.oid = pg_transform.trftosql))",
5248 
5249  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5250  appendPQExpBufferStr(query,
5251  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5252  "classid = 'pg_proc'::regclass AND "
5253  "objid = p.oid AND "
5254  "refclassid = 'pg_extension'::regclass AND "
5255  "deptype = 'e')");
5256  appendPQExpBufferChar(query, ')');
5257  }
5258 
5259  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5260 
5261  ntups = PQntuples(res);
5262 
5263  *numFuncs = ntups;
5264 
5265  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
5266 
5267  i_tableoid = PQfnumber(res, "tableoid");
5268  i_oid = PQfnumber(res, "oid");
5269  i_proname = PQfnumber(res, "proname");
5270  i_pronamespace = PQfnumber(res, "pronamespace");
5271  i_rolname = PQfnumber(res, "rolname");
5272  i_prolang = PQfnumber(res, "prolang");
5273  i_pronargs = PQfnumber(res, "pronargs");
5274  i_proargtypes = PQfnumber(res, "proargtypes");
5275  i_prorettype = PQfnumber(res, "prorettype");
5276  i_proacl = PQfnumber(res, "proacl");
5277  i_rproacl = PQfnumber(res, "rproacl");
5278  i_initproacl = PQfnumber(res, "initproacl");
5279  i_initrproacl = PQfnumber(res, "initrproacl");
5280 
5281  for (i = 0; i < ntups; i++)
5282  {
5283  finfo[i].dobj.objType = DO_FUNC;
5284  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5285  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5286  AssignDumpId(&finfo[i].dobj);
5287  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
5288  finfo[i].dobj.namespace =
5289  findNamespace(fout,
5290  atooid(PQgetvalue(res, i, i_pronamespace)));
5291  finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5292  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
5293  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
5294  finfo[i].proacl = pg_strdup(PQgetvalue(res, i, i_proacl));
5295  finfo[i].rproacl = pg_strdup(PQgetvalue(res, i, i_rproacl));
5296  finfo[i].initproacl = pg_strdup(PQgetvalue(res, i, i_initproacl));
5297  finfo[i].initrproacl = pg_strdup(PQgetvalue(res, i, i_initrproacl));
5298  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
5299  if (finfo[i].nargs == 0)
5300  finfo[i].argtypes = NULL;
5301  else
5302  {
5303  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
5304  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5305  finfo[i].argtypes, finfo[i].nargs);
5306  }
5307 
5308  /* Decide whether we want to dump it */
5309  selectDumpableObject(&(finfo[i].dobj), fout);
5310 
5311  /* Do not try to dump ACL if no ACL exists. */
5312  if (PQgetisnull(res, i, i_proacl) && PQgetisnull(res, i, i_rproacl) &&
5313  PQgetisnull(res, i, i_initproacl) &&
5314  PQgetisnull(res, i, i_initrproacl))
5315  finfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5316 
5317  if (strlen(finfo[i].rolname) == 0)
5318  write_msg(NULL,
5319  "WARNING: owner of function \"%s\" appears to be invalid\n",
5320  finfo[i].dobj.name);
5321  }
5322 
5323  PQclear(res);
5324 
5325  destroyPQExpBuffer(query);
5326 
5327  return finfo;
5328 }
Oid * argtypes
Definition: pg_dump.h:201
char * name
Definition: pg_dump.h:132
DumpComponents dump
Definition: pg_dump.h:133
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1622
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:200
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4067
static int numFuncs
Definition: common.c:59
char * initrproacl
Definition: pg_dump.h:206
Oid lang
Definition: pg_dump.h:199
DumpableObject dobj
Definition: pg_dump.h:197
unsigned int Oid
Definition: postgres_ext.h:31
static Oid g_last_builtin_oid
Definition: pg_dump.c:100
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:133
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
DumpOptions * dopt
Definition: pg_backup.h:178
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:688
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static const char * username_subquery
Definition: pg_dump.c:94
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1034
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:202
#define NULL
Definition: c.h:226
char * initproacl
Definition: pg_dump.h:205
char * rolname
Definition: pg_dump.h:198
char * proacl
Definition: pg_dump.h:203
char * rproacl
Definition: pg_dump.h:204
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:95
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
void getIndexes ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

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

6235 {
6236  int i,
6237  j;
6238  PQExpBuffer query = createPQExpBuffer();
6239  PGresult *res;
6240  IndxInfo *indxinfo;
6241  ConstraintInfo *constrinfo;
6242  int i_tableoid,
6243  i_oid,
6244  i_indexname,
6245  i_indexdef,
6246  i_indnkeys,
6247  i_indkey,
6248  i_indisclustered,
6249  i_indisreplident,
6250  i_contype,
6251  i_conname,
6252  i_condeferrable,
6253  i_condeferred,
6254  i_contableoid,
6255  i_conoid,
6256  i_condef,
6257  i_tablespace,
6258  i_indreloptions,
6259  i_relpages;
6260  int ntups;
6261 
6262  for (i = 0; i < numTables; i++)
6263  {
6264  TableInfo *tbinfo = &tblinfo[i];
6265 
6266  /* Only plain tables and materialized views have indexes. */
6267  if (tbinfo->relkind != RELKIND_RELATION &&
6268  tbinfo->relkind != RELKIND_MATVIEW)
6269  continue;
6270  if (!tbinfo->hasindex)
6271  continue;
6272 
6273  /* Ignore indexes of tables whose definitions are not to be dumped */
6274  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6275  continue;
6276 
6277  if (g_verbose)
6278  write_msg(NULL, "reading indexes for table \"%s.%s\"\n",
6279  tbinfo->dobj.namespace->dobj.name,
6280  tbinfo->dobj.name);
6281 
6282  /* Make sure we are in proper schema so indexdef is right */
6283  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6284 
6285  /*
6286  * The point of the messy-looking outer join is to find a constraint
6287  * that is related by an internal dependency link to the index. If we
6288  * find one, create a CONSTRAINT entry linked to the INDEX entry. We
6289  * assume an index won't have more than one internal dependency.
6290  *
6291  * As of 9.0 we don't need to look at pg_depend but can check for a
6292  * match to pg_constraint.conindid. The check on conrelid is
6293  * redundant but useful because that column is indexed while conindid
6294  * is not.
6295  */
6296  resetPQExpBuffer(query);
6297  if (fout->remoteVersion >= 90400)
6298  {
6299  /*
6300  * the test on indisready is necessary in 9.2, and harmless in
6301  * earlier/later versions
6302  */
6303  appendPQExpBuffer(query,
6304  "SELECT t.tableoid, t.oid, "
6305  "t.relname AS indexname, "
6306  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6307  "t.relnatts AS indnkeys, "
6308  "i.indkey, i.indisclustered, "
6309  "i.indisreplident, t.relpages, "
6310  "c.contype, c.conname, "
6311  "c.condeferrable, c.condeferred, "
6312  "c.tableoid AS contableoid, "
6313  "c.oid AS conoid, "
6314  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6315  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6316  "t.reloptions AS indreloptions "
6317  "FROM pg_catalog.pg_index i "
6318  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6319  "LEFT JOIN pg_catalog.pg_constraint c "
6320  "ON (i.indrelid = c.conrelid AND "
6321  "i.indexrelid = c.conindid AND "
6322  "c.contype IN ('p','u','x')) "
6323  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6324  "AND i.indisvalid AND i.indisready "
6325  "ORDER BY indexname",
6326  tbinfo->dobj.catId.oid);
6327  }
6328  else if (fout->remoteVersion >= 90000)
6329  {
6330  /*
6331  * the test on indisready is necessary in 9.2, and harmless in
6332  * earlier/later versions
6333  */
6334  appendPQExpBuffer(query,
6335  "SELECT t.tableoid, t.oid, "
6336  "t.relname AS indexname, "
6337  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6338  "t.relnatts AS indnkeys, "
6339  "i.indkey, i.indisclustered, "
6340  "false AS indisreplident, t.relpages, "
6341  "c.contype, c.conname, "
6342  "c.condeferrable, c.condeferred, "
6343  "c.tableoid AS contableoid, "
6344  "c.oid AS conoid, "
6345  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6346  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6347  "t.reloptions AS indreloptions "
6348  "FROM pg_catalog.pg_index i "
6349  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6350  "LEFT JOIN pg_catalog.pg_constraint c "
6351  "ON (i.indrelid = c.conrelid AND "
6352  "i.indexrelid = c.conindid AND "
6353  "c.contype IN ('p','u','x')) "
6354  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6355  "AND i.indisvalid AND i.indisready "
6356  "ORDER BY indexname",
6357  tbinfo->dobj.catId.oid);
6358  }
6359  else if (fout->remoteVersion >= 80200)
6360  {
6361  appendPQExpBuffer(query,
6362  "SELECT t.tableoid, t.oid, "
6363  "t.relname AS indexname, "
6364  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6365  "t.relnatts AS indnkeys, "
6366  "i.indkey, i.indisclustered, "
6367  "false AS indisreplident, t.relpages, "
6368  "c.contype, c.conname, "
6369  "c.condeferrable, c.condeferred, "
6370  "c.tableoid AS contableoid, "
6371  "c.oid AS conoid, "
6372  "null AS condef, "
6373  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6374  "t.reloptions AS indreloptions "
6375  "FROM pg_catalog.pg_index i "
6376  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6377  "LEFT JOIN pg_catalog.pg_depend d "
6378  "ON (d.classid = t.tableoid "
6379  "AND d.objid = t.oid "
6380  "AND d.deptype = 'i') "
6381  "LEFT JOIN pg_catalog.pg_constraint c "
6382  "ON (d.refclassid = c.tableoid "
6383  "AND d.refobjid = c.oid) "
6384  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6385  "AND i.indisvalid "
6386  "ORDER BY indexname",
6387  tbinfo->dobj.catId.oid);
6388  }
6389  else
6390  {
6391  appendPQExpBuffer(query,
6392  "SELECT t.tableoid, t.oid, "
6393  "t.relname AS indexname, "
6394  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6395  "t.relnatts AS indnkeys, "
6396  "i.indkey, i.indisclustered, "
6397  "false AS indisreplident, t.relpages, "
6398  "c.contype, c.conname, "
6399  "c.condeferrable, c.condeferred, "
6400  "c.tableoid AS contableoid, "
6401  "c.oid AS conoid, "
6402  "null AS condef, "
6403  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6404  "null AS indreloptions "
6405  "FROM pg_catalog.pg_index i "
6406  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6407  "LEFT JOIN pg_catalog.pg_depend d "
6408  "ON (d.classid = t.tableoid "
6409  "AND d.objid = t.oid "
6410  "AND d.deptype = 'i') "
6411  "LEFT JOIN pg_catalog.pg_constraint c "
6412  "ON (d.refclassid = c.tableoid "
6413  "AND d.refobjid = c.oid) "
6414  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6415  "ORDER BY indexname",
6416  tbinfo->dobj.catId.oid);
6417  }
6418 
6419  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6420 
6421  ntups = PQntuples(res);
6422 
6423  i_tableoid = PQfnumber(res, "tableoid");
6424  i_oid = PQfnumber(res, "oid");
6425  i_indexname = PQfnumber(res, "indexname");
6426  i_indexdef = PQfnumber(res, "indexdef");
6427  i_indnkeys = PQfnumber(res, "indnkeys");
6428  i_indkey = PQfnumber(res, "indkey");
6429  i_indisclustered = PQfnumber(res, "indisclustered");
6430  i_indisreplident = PQfnumber(res, "indisreplident");
6431  i_relpages = PQfnumber(res, "relpages");
6432  i_contype = PQfnumber(res, "contype");
6433  i_conname = PQfnumber(res, "conname");
6434  i_condeferrable = PQfnumber(res, "condeferrable");
6435  i_condeferred = PQfnumber(res, "condeferred");
6436  i_contableoid = PQfnumber(res, "contableoid");
6437  i_conoid = PQfnumber(res, "conoid");
6438  i_condef = PQfnumber(res, "condef");
6439  i_tablespace = PQfnumber(res, "tablespace");
6440  i_indreloptions = PQfnumber(res, "indreloptions");
6441 
6442  indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
6443  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
6444 
6445  for (j = 0; j < ntups; j++)
6446  {
6447  char contype;
6448 
6449  indxinfo[j].dobj.objType = DO_INDEX;
6450  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
6451  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
6452  AssignDumpId(&indxinfo[j].dobj);
6453  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
6454  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6455  indxinfo[j].indextable = tbinfo;
6456  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
6457  indxinfo[j].indnkeys = atoi(PQgetvalue(res, j, i_indnkeys));
6458  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
6459  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
6460  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnkeys * sizeof(Oid));
6461  parseOidArray(PQgetvalue(res, j, i_indkey),
6462  indxinfo[j].indkeys, indxinfo[j].indnkeys);
6463  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
6464  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
6465  indxinfo[j].relpages = atoi(PQgetvalue(res, j, i_relpages));
6466  contype = *(PQgetvalue(res, j, i_contype));
6467 
6468  if (contype == 'p' || contype == 'u' || contype == 'x')
6469  {
6470  /*
6471  * If we found a constraint matching the index, create an
6472  * entry for it.
6473  */
6474  constrinfo[j].dobj.objType = DO_CONSTRAINT;
6475  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
6476  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
6477  AssignDumpId(&constrinfo[j].dobj);
6478  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
6479  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6480  constrinfo[j].contable = tbinfo;
6481  constrinfo[j].condomain = NULL;
6482  constrinfo[j].contype = contype;
6483  if (contype == 'x')
6484  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
6485  else
6486  constrinfo[j].condef = NULL;
6487  constrinfo[j].confrelid = InvalidOid;
6488  constrinfo[j].conindex = indxinfo[j].dobj.dumpId;
6489  constrinfo[j].condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
6490  constrinfo[j].condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
6491  constrinfo[j].conislocal = true;
6492  constrinfo[j].separate = true;
6493 
6494  indxinfo[j].indexconstraint = constrinfo[j].dobj.dumpId;
6495  }
6496  else
6497  {
6498  /* Plain secondary index */
6499  indxinfo[j].indexconstraint = 0;
6500  }
6501  }
6502 
6503  PQclear(res);
6504  }
6505 
6506  destroyPQExpBuffer(query);
6507 }
char * tablespace
Definition: pg_dump.h:354
char * name
Definition: pg_dump.h:132
char relkind
Definition: pg_dump.h:266
DumpComponents dump
Definition: pg_dump.h:133
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
int relpages
Definition: pg_dump.h:362
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
#define RELKIND_MATVIEW
Definition: pg_class.h:167
bool hasindex
Definition: pg_dump.h:274
DumpId dumpId
Definition: pg_dump.h:131
static int numTables
Definition: common.c:57
unsigned int Oid
Definition: postgres_ext.h:31
DumpId conindex
Definition: pg_dump.h:421
DumpId indexconstraint
Definition: pg_dump.h:361
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
char * indexdef
Definition: pg_dump.h:353
DumpableObject dobj
Definition: pg_dump.h:260
char * condef
Definition: pg_dump.h:419
bool indisreplident
Definition: pg_dump.h:359
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:415
TableInfo * indextable
Definition: pg_dump.h:352
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
Oid * indkeys
Definition: pg_dump.h:357
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
bool condeferrable
Definition: pg_dump.h:422
int indnkeys
Definition: pg_dump.h:356
char * indreloptions
Definition: pg_dump.h:355
TypeInfo * condomain
Definition: pg_dump.h:417
bool conislocal
Definition: pg_dump.h:424
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1034
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:416
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:91
void write_msg(const char *modulename, const char *fmt,...)
bool condeferred
Definition: pg_dump.h:423
#define NULL
Definition: c.h:226
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
DumpableObject dobj
Definition: pg_dump.h:351
int i
bool indisclustered
Definition: pg_dump.h:358
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
#define RELKIND_RELATION
Definition: pg_class.h:160
DumpableObjectType objType
Definition: pg_dump.h:129
bool g_verbose
Definition: pg_dump.c:90
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
InhInfo* getInherits ( Archive fout,
int *  numInherits 
)

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

6112 {
6113  PGresult *res;
6114  int ntups;
6115  int i;
6116  PQExpBuffer query = createPQExpBuffer();
6117  InhInfo *inhinfo;
6118 
6119  int i_inhrelid;
6120  int i_inhparent;
6121 
6122  /* Make sure we are in proper schema */
6123  selectSourceSchema(fout, "pg_catalog");
6124 
6125  /*
6126  * Find all the inheritance information, excluding implicit inheritance
6127  * via partitioning. We handle that case using getPartitions(), because
6128  * we want more information about partitions than just the parent-child
6129  * relationship.
6130  */
6131  appendPQExpBufferStr(query,
6132  "SELECT inhrelid, inhparent "
6133  "FROM pg_inherits "
6134  "WHERE inhparent NOT IN (SELECT oid FROM pg_class WHERE relkind = 'P')");
6135 
6136  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6137 
6138  ntups = PQntuples(res);
6139 
6140  *numInherits = ntups;
6141 
6142  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6143 
6144  i_inhrelid = PQfnumber(res, "inhrelid");
6145  i_inhparent = PQfnumber(res, "inhparent");
6146 
6147  for (i = 0; i < ntups; i++)
6148  {
6149  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6150  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6151  }
6152 
6153  PQclear(res);
6154 
6155  destroyPQExpBuffer(query);
6156 
6157  return inhinfo;
6158 }
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:464
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
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:465
#define atooid(x)
Definition: lo.c:17
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
DumpId getMaxDumpId ( void  )

Definition at line 562 of file common.c.

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

563 {
564  return lastDumpId;
565 }
static DumpId lastDumpId
Definition: common.c:33
NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

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

3939 {
3940  DumpOptions *dopt = fout->dopt;
3941  PGresult *res;
3942  int ntups;
3943  int i;
3944  PQExpBuffer query;
3945  NamespaceInfo *nsinfo;
3946  int i_tableoid;
3947  int i_oid;
3948  int i_nspname;
3949  int i_rolname;
3950  int i_nspacl;
3951  int i_rnspacl;
3952  int i_initnspacl;
3953  int i_initrnspacl;
3954 
3955  query = createPQExpBuffer();
3956 
3957  /* Make sure we are in proper schema */
3958  selectSourceSchema(fout, "pg_catalog");
3959 
3960  /*
3961  * we fetch all namespaces including system ones, so that every object we
3962  * read in can be linked to a containing namespace.
3963  */
3964  if (fout->remoteVersion >= 90600)
3965  {
3966  PQExpBuffer acl_subquery = createPQExpBuffer();
3967  PQExpBuffer racl_subquery = createPQExpBuffer();
3968  PQExpBuffer init_acl_subquery = createPQExpBuffer();
3969  PQExpBuffer init_racl_subquery = createPQExpBuffer();
3970 
3971  buildACLQueries(acl_subquery, racl_subquery, init_acl_subquery,
3972  init_racl_subquery, "n.nspacl", "n.nspowner", "'n'",
3973  dopt->binary_upgrade);
3974 
3975  appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, "
3976  "(%s nspowner) AS rolname, "
3977  "%s as nspacl, "
3978  "%s as rnspacl, "
3979  "%s as initnspacl, "
3980  "%s as initrnspacl "
3981  "FROM pg_namespace n "
3982  "LEFT JOIN pg_init_privs pip "
3983  "ON (n.oid = pip.objoid "
3984  "AND pip.classoid = 'pg_namespace'::regclass "
3985  "AND pip.objsubid = 0) ",
3987  acl_subquery->data,
3988  racl_subquery->data,
3989  init_acl_subquery->data,
3990  init_racl_subquery->data);
3991 
3992  destroyPQExpBuffer(acl_subquery);
3993  destroyPQExpBuffer(racl_subquery);
3994  destroyPQExpBuffer(init_acl_subquery);
3995  destroyPQExpBuffer(init_racl_subquery);
3996  }
3997  else
3998  appendPQExpBuffer(query, "SELECT tableoid, oid, nspname, "
3999  "(%s nspowner) AS rolname, "
4000  "nspacl, NULL as rnspacl, "
4001  "NULL AS initnspacl, NULL as initrnspacl "
4002  "FROM pg_namespace",
4004 
4005  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4006 
4007  ntups = PQntuples(res);
4008 
4009  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
4010 
4011  i_tableoid = PQfnumber(res, "tableoid");
4012  i_oid = PQfnumber(res, "oid");
4013  i_nspname = PQfnumber(res, "nspname");
4014  i_rolname = PQfnumber(res, "rolname");
4015  i_nspacl = PQfnumber(res, "nspacl");
4016  i_rnspacl = PQfnumber(res, "rnspacl");
4017  i_initnspacl = PQfnumber(res, "initnspacl");
4018  i_initrnspacl = PQfnumber(res, "initrnspacl");
4019 
4020  for (i = 0; i < ntups; i++)
4021  {
4022  nsinfo[i].dobj.objType = DO_NAMESPACE;
4023  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4024  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4025  AssignDumpId(&nsinfo[i].dobj);
4026  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
4027  nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4028  nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl));
4029  nsinfo[i].rnspacl = pg_strdup(PQgetvalue(res, i, i_rnspacl));
4030  nsinfo[i].initnspacl = pg_strdup(PQgetvalue(res, i, i_initnspacl));
4031  nsinfo[i].initrnspacl = pg_strdup(PQgetvalue(res, i, i_initrnspacl));
4032 
4033  /* Decide whether to dump this namespace */
4034  selectDumpableNamespace(&nsinfo[i], fout);
4035 
4036  /*
4037  * Do not try to dump ACL if the ACL is empty or the default.
4038  *
4039  * This is useful because, for some schemas/objects, the only
4040  * component we are going to try and dump is the ACL and if we can
4041  * remove that then 'dump' goes to zero/false and we don't consider
4042  * this object for dumping at all later on.
4043  */
4044  if (PQgetisnull(res, i, i_nspacl) && PQgetisnull(res, i, i_rnspacl) &&
4045  PQgetisnull(res, i, i_initnspacl) &&
4046  PQgetisnull(res, i, i_initrnspacl))
4047  nsinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4048 
4049  if (strlen(nsinfo[i].rolname) == 0)
4050  write_msg(NULL, "WARNING: owner of schema \"%s\" appears to be invalid\n",
4051  nsinfo[i].dobj.name);
4052  }
4053 
4054  PQclear(res);
4055  destroyPQExpBuffer(query);
4056 
4057  *numNamespaces = ntups;
4058 
4059  return nsinfo;
4060 }
char * name
Definition: pg_dump.h:132
DumpComponents dump
Definition: pg_dump.h:133
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:147
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:133
DumpOptions * dopt
Definition: pg_backup.h:178
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:688
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * rolname
Definition: pg_dump.h:145
char * initnspacl
Definition: pg_dump.h:148
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static int numNamespaces
Definition: common.c:62
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static const char * username_subquery
Definition: pg_dump.c:94
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:1353
void PQclear(PGresult *res)
Definition: fe-exec.c:650
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:226
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:95
char * initrnspacl
Definition: pg_dump.h:149
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
char * nspacl
Definition: pg_dump.h:146
DumpableObject dobj
Definition: pg_dump.h:144
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
OpclassInfo* getOpclasses ( Archive fout,
int *  numOpclasses 
)

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

4748 {
4749  PGresult *res;
4750  int ntups;
4751  int i;
4752  PQExpBuffer query = createPQExpBuffer();
4753  OpclassInfo *opcinfo;
4754  int i_tableoid;
4755  int i_oid;
4756  int i_opcname;
4757  int i_opcnamespace;
4758  int i_rolname;
4759 
4760  /*
4761  * find all opclasses, including builtin opclasses; we filter out
4762  * system-defined opclasses at dump-out time.
4763  */
4764 
4765  /* Make sure we are in proper schema */
4766  selectSourceSchema(fout, "pg_catalog");
4767 
4768  appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
4769  "opcnamespace, "
4770  "(%s opcowner) AS rolname "
4771  "FROM pg_opclass",
4773 
4774  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4775 
4776  ntups = PQntuples(res);
4777  *numOpclasses = ntups;
4778 
4779  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
4780 
4781  i_tableoid = PQfnumber(res, "tableoid");
4782  i_oid = PQfnumber(res, "oid");
4783  i_opcname = PQfnumber(res, "opcname");
4784  i_opcnamespace = PQfnumber(res, "opcnamespace");
4785  i_rolname = PQfnumber(res, "rolname");
4786 
4787  for (i = 0; i < ntups; i++)
4788  {
4789  opcinfo[i].dobj.objType = DO_OPCLASS;
4790  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4791  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4792  AssignDumpId(&opcinfo[i].dobj);
4793  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
4794  opcinfo[i].dobj.namespace =
4795  findNamespace(fout,
4796  atooid(PQgetvalue(res, i, i_opcnamespace)));
4797  opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4798 
4799  /* Decide whether we want to dump it */
4800  selectDumpableObject(&(opcinfo[i].dobj), fout);
4801 
4802  /* Op Classes do not currently have ACLs. */
4803  opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4804 
4805  if (strlen(opcinfo[i].rolname) == 0)
4806  write_msg(NULL, "WARNING: owner of operator class \"%s\" appears to be invalid\n",
4807  opcinfo[i].dobj.name);
4808  }
4809 
4810  PQclear(res);
4811 
4812  destroyPQExpBuffer(query);
4813 
4814  return opcinfo;
4815 }
char * name
Definition: pg_dump.h:132
DumpComponents dump
Definition: pg_dump.h:133
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1622
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:4067
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
char * rolname
Definition: pg_dump.h:234
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
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static const char * username_subquery
Definition: pg_dump.c:94
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
DumpableObject dobj
Definition: pg_dump.h:233
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:226
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:95
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
OprInfo* getOperators ( Archive fout,
int *  numOperators 
)

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

4426 {
4427  PGresult *res;
4428  int ntups;
4429  int i;
4430  PQExpBuffer query = createPQExpBuffer();
4431  OprInfo *oprinfo;
4432  int i_tableoid;
4433  int i_oid;
4434  int i_oprname;
4435  int i_oprnamespace;
4436  int i_rolname;
4437  int i_oprkind;
4438  int i_oprcode;
4439 
4440  /*
4441  * find all operators, including builtin operators; we filter out
4442  * system-defined operators at dump-out time.
4443  */
4444 
4445  /* Make sure we are in proper schema */
4446  selectSourceSchema(fout, "pg_catalog");
4447 
4448  appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
4449  "oprnamespace, "
4450  "(%s oprowner) AS rolname, "
4451  "oprkind, "
4452  "oprcode::oid AS oprcode "
4453  "FROM pg_operator",
4455 
4456  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4457 
4458  ntups = PQntuples(res);
4459  *numOprs = ntups;
4460 
4461  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
4462 
4463  i_tableoid = PQfnumber(res, "tableoid");
4464  i_oid = PQfnumber(res, "oid");
4465  i_oprname = PQfnumber(res, "oprname");
4466  i_oprnamespace = PQfnumber(res, "oprnamespace");
4467  i_rolname = PQfnumber(res, "rolname");
4468  i_oprkind = PQfnumber(res, "oprkind");
4469  i_oprcode = PQfnumber(res, "oprcode");
4470 
4471  for (i = 0; i < ntups; i++)
4472  {
4473  oprinfo[i].dobj.objType = DO_OPERATOR;
4474  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4475  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4476  AssignDumpId(&oprinfo[i].dobj);
4477  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
4478  oprinfo[i].dobj.namespace =
4479  findNamespace(fout,
4480  atooid(PQgetvalue(res, i, i_oprnamespace)));
4481  oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4482  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
4483  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
4484 
4485  /* Decide whether we want to dump it */
4486  selectDumpableObject(&(oprinfo[i].dobj), fout);
4487 
4488  /* Operators do not currently have ACLs. */
4489  oprinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4490 
4491  if (strlen(oprinfo[i].rolname) == 0)
4492  write_msg(NULL, "WARNING: owner of operator \"%s\" appears to be invalid\n",
4493  oprinfo[i].dobj.name);
4494  }
4495 
4496  PQclear(res);
4497 
4498  destroyPQExpBuffer(query);
4499 
4500  return oprinfo;
4501 }
char * name
Definition: pg_dump.h:132
DumpableObject dobj
Definition: pg_dump.h:218
DumpComponents dump
Definition: pg_dump.h:133
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1622
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:4067
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
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static const char * username_subquery
Definition: pg_dump.c:94
char * rolname
Definition: pg_dump.h:219
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:220
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:226
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:95
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
Oid oprcode
Definition: pg_dump.h:221
OpfamilyInfo* getOpfamilies ( Archive fout,
int *  numOpfamilies 
)

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

4826 {
4827  PGresult *res;
4828  int ntups;
4829  int i;
4830  PQExpBuffer query;
4831  OpfamilyInfo *opfinfo;
4832  int i_tableoid;
4833  int i_oid;
4834  int i_opfname;
4835  int i_opfnamespace;
4836  int i_rolname;
4837 
4838  /* Before 8.3, there is no separate concept of opfamilies */
4839  if (fout->remoteVersion < 80300)
4840  {
4841  *numOpfamilies = 0;
4842  return NULL;
4843  }
4844 
4845  query = createPQExpBuffer();
4846 
4847  /*
4848  * find all opfamilies, including builtin opfamilies; we filter out
4849  * system-defined opfamilies at dump-out time.
4850  */
4851 
4852  /* Make sure we are in proper schema */
4853  selectSourceSchema(fout, "pg_catalog");
4854 
4855  appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, "
4856  "opfnamespace, "
4857  "(%s opfowner) AS rolname "
4858  "FROM pg_opfamily",
4860 
4861  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4862 
4863  ntups = PQntuples(res);
4864  *numOpfamilies = ntups;
4865 
4866  opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
4867 
4868  i_tableoid = PQfnumber(res, "tableoid");
4869  i_oid = PQfnumber(res, "oid");
4870  i_opfname = PQfnumber(res, "opfname");
4871  i_opfnamespace = PQfnumber(res, "opfnamespace");
4872  i_rolname = PQfnumber(res, "rolname");
4873 
4874  for (i = 0; i < ntups; i++)
4875  {
4876  opfinfo[i].dobj.objType = DO_OPFAMILY;
4877  opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4878  opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4879  AssignDumpId(&opfinfo[i].dobj);
4880  opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
4881  opfinfo[i].dobj.namespace =
4882  findNamespace(fout,
4883  atooid(PQgetvalue(res, i, i_opfnamespace)));
4884  opfinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4885 
4886  /* Decide whether we want to dump it */
4887  selectDumpableObject(&(opfinfo[i].dobj), fout);
4888 
4889  /* Extensions do not currently have ACLs. */
4890  opfinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4891 
4892  if (strlen(opfinfo[i].rolname) == 0)
4893  write_msg(NULL, "WARNING: owner of operator family \"%s\" appears to be invalid\n",
4894  opfinfo[i].dobj.name);
4895  }
4896 
4897  PQclear(res);
4898 
4899  destroyPQExpBuffer(query);
4900 
4901  return opfinfo;
4902 }
char * name
Definition: pg_dump.h:132
DumpableObject dobj
Definition: pg_dump.h:239
DumpComponents dump
Definition: pg_dump.h:133
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1622
Oid tableoid
Definition: pg_backup.h:224
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:509
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:4067
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
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17304
static const char * username_subquery
Definition: pg_dump.c:94
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
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:226
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:95
CatalogId catId
Definition: pg_dump.h:130
#define atooid(x)
Definition: lo.c:17
int i
char * rolname
Definition: pg_dump.h:240
DumpableObjectType objType
Definition: pg_dump.h:129
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
void getOwnedSeqs ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 6060 of file pg_dump.c.

References _dumpableObject::catId, _tableInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_NONE, exit_horribly(), findTableByOid(), i, _tableInfo::interesting, NULL, numTables, CatalogId::oid, OidIsValid, and _tableInfo::owning_tab.

Referenced by getSchemaData().

6061 {
6062  int i;
6063 
6064  /*
6065  * Force sequences that are "owned" by table columns to be dumped whenever
6066  * their owning table is being dumped.
6067  */
6068  for (i = 0; i < numTables; i++)
6069  {
6070  TableInfo *seqinfo = &tblinfo[i];
6071  TableInfo *owning_tab;
6072 
6073  if (!OidIsValid(seqinfo->owning_tab))
6074  continue; /* not an owned sequence */
6075 
6076  owning_tab = findTableByOid(seqinfo->owning_tab);
6077  if (owning_tab == NULL)
6078  exit_horribly(NULL, "failed sanity check, parent table with OID %u of sequence with OID %u not found\n",
6079  seqinfo->owning_tab, seqinfo->dobj.catId.oid);
6080 
6081  /*
6082  * We need to dump the components that are being dumped for the table
6083  * and any components which the sequence is explicitly marked with.
6084  *
6085  * We can't simply use the set of components which are being dumped
6086  * for the table as the table might be in an extension (and only the
6087  * non-extension components, eg: ACLs if changed, security labels, and
6088  * policies, are being dumped) while the sequence is not (and
6089  * therefore the definition and other components should also be
6090  * dumped).
6091  *
6092  * If the sequence is part of the extension then it should be properly
6093  * marked by checkExtensionMembership() and this will be a no-op as
6094  * the table will be equivalently marked.
6095  */
6096  seqinfo->dobj.dump = seqinfo->dobj.dump | owning_tab->dobj.dump;
6097 
6098  if (seqinfo->dobj.dump != DUMP_COMPONENT_NONE)
6099  seqinfo->interesting = true;
6100  }
6101 }
TableInfo * findTableByOid(Oid oid)
Definition: common.c:792
DumpComponents dump
Definition: pg_dump.h:133
static int numTables
Definition: common.c:57
#define OidIsValid(objectId)
Definition: c.h:534
DumpableObject dobj
Definition: pg_dump.h:260
#define DUMP_COMPONENT_NONE
Definition: pg_dump.h:90
Oid owning_tab
Definition: pg_dump.h:288
#define NULL
Definition: c.h:226
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:130
bool interesting
Definition: pg_dump.h:292
int i
PartInfo* getPartitions ( Archive fout,
int *  numPartitions 
)

Definition at line 6168 of file pg_dump.c.

References appendPQExpBufferStr(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), ExecuteSqlQuery(), i, NULL, _partInfo::partdef, _partInfo::partparent, _partInfo::partrelid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, and selectSourceSchema().

Referenced by getSchemaData().

6169 {
6170  PGresult *res;
6171  int ntups;
6172  int i;
6173  PQExpBuffer query;
6174  PartInfo *partinfo;
6175 
6176  int i_partrelid;
6177  int i_partparent;
6178  int i_partbound;
6179 
6180  /* Before version 10, there are no partitions */
6181  if (fout->remoteVersion < 100000)
6182  {
6183  *numPartitions = 0;