PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_dump.h File Reference
#include "pg_backup.h"
Include dependency graph for pg_dump.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _dumpableObject
 
struct  _namespaceInfo
 
struct  _extensionInfo
 
struct  _typeInfo
 
struct  _shellTypeInfo
 
struct  _funcInfo
 
struct  _aggInfo
 
struct  _oprInfo
 
struct  _accessMethodInfo
 
struct  _opclassInfo
 
struct  _opfamilyInfo
 
struct  _collInfo
 
struct  _convInfo
 
struct  _tableInfo
 
struct  _attrDefInfo
 
struct  _tableDataInfo
 
struct  _indxInfo
 
struct  _statsExtInfo
 
struct  _ruleInfo
 
struct  _triggerInfo
 
struct  _evttriggerInfo
 
struct  _constraintInfo
 
struct  _procLangInfo
 
struct  _castInfo
 
struct  _transformInfo
 
struct  _inhInfo
 
struct  _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 _statsExtInfo StatsExtInfo
 
typedef struct _ruleInfo RuleInfo
 
typedef struct _triggerInfo TriggerInfo
 
typedef struct _evttriggerInfo EventTriggerInfo
 
typedef struct _constraintInfo ConstraintInfo
 
typedef struct _procLangInfo ProcLangInfo
 
typedef struct _castInfo CastInfo
 
typedef struct _transformInfo TransformInfo
 
typedef struct _inhInfo InhInfo
 
typedef struct _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_STATSEXT,
  DO_RULE, DO_TRIGGER, DO_CONSTRAINT, DO_FK_CONSTRAINT,
  DO_PROCLANG, DO_CAST, DO_TABLE_DATA, DO_SEQUENCE_SET,
  DO_DUMMY_TYPE, DO_TSPARSER, DO_TSDICT, DO_TSTEMPLATE,
  DO_TSCONFIG, DO_FDW, DO_FOREIGN_SERVER, DO_DEFAULT_ACL,
  DO_TRANSFORM, DO_BLOB, DO_BLOB_DATA, DO_PRE_DATA_BOUNDARY,
  DO_POST_DATA_BOUNDARY, DO_EVENT_TRIGGER, DO_REFRESH_MATVIEW, DO_POLICY,
  DO_PUBLICATION, DO_PUBLICATION_REL, DO_SUBSCRIPTION
}
 

Functions

TableInfogetSchemaData (Archive *fout, int *numTablesPtr)
 
void AssignDumpId (DumpableObject *dobj)
 
DumpId createDumpId (void)
 
DumpId getMaxDumpId (void)
 
DumpableObjectfindObjectByDumpId (DumpId dumpId)
 
DumpableObjectfindObjectByCatalogId (CatalogId catalogId)
 
void getDumpableObjects (DumpableObject ***objs, int *numObjs)
 
void addObjectDependency (DumpableObject *dobj, DumpId refId)
 
void removeObjectDependency (DumpableObject *dobj, DumpId refId)
 
TableInfofindTableByOid (Oid oid)
 
TypeInfofindTypeByOid (Oid oid)
 
FuncInfofindFuncByOid (Oid oid)
 
OprInfofindOprByOid (Oid oid)
 
CollInfofindCollationByOid (Oid oid)
 
NamespaceInfofindNamespaceByOid (Oid oid)
 
ExtensionInfofindExtensionByOid (Oid oid)
 
void setExtensionMembership (ExtensionMemberId *extmems, int nextmems)
 
ExtensionInfofindOwningExtension (CatalogId catalogId)
 
void parseOidArray (const char *str, Oid *array, int arraysize)
 
void sortDumpableObjects (DumpableObject **objs, int numObjs, DumpId preBoundaryId, DumpId postBoundaryId)
 
void sortDumpableObjectsByTypeName (DumpableObject **objs, int numObjs)
 
void sortDataAndIndexObjectsBySize (DumpableObject **objs, int numObjs)
 
NamespaceInfogetNamespaces (Archive *fout, int *numNamespaces)
 
ExtensionInfogetExtensions (Archive *fout, int *numExtensions)
 
TypeInfogetTypes (Archive *fout, int *numTypes)
 
FuncInfogetFuncs (Archive *fout, int *numFuncs)
 
AggInfogetAggregates (Archive *fout, int *numAggregates)
 
OprInfogetOperators (Archive *fout, int *numOperators)
 
AccessMethodInfogetAccessMethods (Archive *fout, int *numAccessMethods)
 
OpclassInfogetOpclasses (Archive *fout, int *numOpclasses)
 
OpfamilyInfogetOpfamilies (Archive *fout, int *numOpfamilies)
 
CollInfogetCollations (Archive *fout, int *numCollations)
 
ConvInfogetConversions (Archive *fout, int *numConversions)
 
TableInfogetTables (Archive *fout, int *numTables)
 
void getOwnedSeqs (Archive *fout, TableInfo tblinfo[], int numTables)
 
InhInfogetInherits (Archive *fout, int *numInherits)
 
PartInfogetPartitions (Archive *fout, int *numPartitions)
 
void getIndexes (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getExtendedStatistics (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getConstraints (Archive *fout, TableInfo tblinfo[], int numTables)
 
RuleInfogetRules (Archive *fout, int *numRules)
 
void getTriggers (Archive *fout, TableInfo tblinfo[], int numTables)
 
ProcLangInfogetProcLangs (Archive *fout, int *numProcLangs)
 
CastInfogetCasts (Archive *fout, int *numCasts)
 
TransformInfogetTransforms (Archive *fout, int *numTransforms)
 
void getTableAttrs (Archive *fout, TableInfo *tbinfo, int numTables)
 
bool shouldPrintColumn (DumpOptions *dopt, TableInfo *tbinfo, int colno)
 
TSParserInfogetTSParsers (Archive *fout, int *numTSParsers)
 
TSDictInfogetTSDictionaries (Archive *fout, int *numTSDicts)
 
TSTemplateInfogetTSTemplates (Archive *fout, int *numTSTemplates)
 
TSConfigInfogetTSConfigurations (Archive *fout, int *numTSConfigs)
 
FdwInfogetForeignDataWrappers (Archive *fout, int *numForeignDataWrappers)
 
ForeignServerInfogetForeignServers (Archive *fout, int *numForeignServers)
 
DefaultACLInfogetDefaultACLs (Archive *fout, int *numDefaultACLs)
 
void getExtensionMembership (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
void processExtensionTables (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
EventTriggerInfogetEventTriggers (Archive *fout, int *numEventTriggers)
 
void getPolicies (Archive *fout, TableInfo tblinfo[], int numTables)
 
void 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 97 of file pg_dump.h.

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

#define DUMP_COMPONENT_USERMAP   (1 << 6)

Definition at line 98 of file pg_dump.h.

Referenced by dumpForeignServer().

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

Definition at line 123 of file pg_dump.h.

Referenced by getTables().

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

Definition at line 21 of file pg_dump.h.

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

Definition at line 23 of file pg_dump.h.

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

Definition at line 22 of file pg_dump.h.

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

Definition at line 24 of file pg_dump.h.

Typedef Documentation

Definition at line 90 of file pg_dump.h.

Enumeration Type Documentation

Enumerator
DO_NAMESPACE 
DO_EXTENSION 
DO_TYPE 
DO_SHELL_TYPE 
DO_FUNC 
DO_AGG 
DO_OPERATOR 
DO_ACCESS_METHOD 
DO_OPCLASS 
DO_OPFAMILY 
DO_COLLATION 
DO_CONVERSION 
DO_TABLE 
DO_ATTRDEF 
DO_INDEX 
DO_STATSEXT 
DO_RULE 
DO_TRIGGER 
DO_CONSTRAINT 
DO_FK_CONSTRAINT 
DO_PROCLANG 
DO_CAST 
DO_TABLE_DATA 
DO_SEQUENCE_SET 
DO_DUMMY_TYPE 
DO_TSPARSER 
DO_TSDICT 
DO_TSTEMPLATE 
DO_TSCONFIG 
DO_FDW 
DO_FOREIGN_SERVER 
DO_DEFAULT_ACL 
DO_TRANSFORM 
DO_BLOB 
DO_BLOB_DATA 
DO_PRE_DATA_BOUNDARY 
DO_POST_DATA_BOUNDARY 
DO_EVENT_TRIGGER 
DO_REFRESH_MATVIEW 
DO_POLICY 
DO_PUBLICATION 
DO_PUBLICATION_REL 
DO_SUBSCRIPTION 

Definition at line 41 of file pg_dump.h.

42 {
43  /* When modifying this enum, update priority tables in pg_dump_sort.c! */
46  DO_TYPE,
48  DO_FUNC,
49  DO_AGG,
52  DO_OPCLASS,
56  DO_TABLE,
57  DO_ATTRDEF,
58  DO_INDEX,
60  DO_RULE,
61  DO_TRIGGER,
63  DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
65  DO_CAST,
70  DO_TSDICT,
73  DO_FDW,
77  DO_BLOB,
83  DO_POLICY,
DumpableObjectType
Definition: pg_dump.h:41
Definition: pg_dump.h:49
Definition: pg_dump.h:73

Function Documentation

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

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

750 {
751  if (dobj->nDeps >= dobj->allocDeps)
752  {
753  if (dobj->allocDeps <= 0)
754  {
755  dobj->allocDeps = 16;
756  dobj->dependencies = (DumpId *)
757  pg_malloc(dobj->allocDeps * sizeof(DumpId));
758  }
759  else
760  {
761  dobj->allocDeps *= 2;
762  dobj->dependencies = (DumpId *)
763  pg_realloc(dobj->dependencies,
764  dobj->allocDeps * sizeof(DumpId));
765  }
766  }
767  dobj->dependencies[dobj->nDeps++] = refId;
768 }
int DumpId
Definition: pg_backup.h:229
DumpId * dependencies
Definition: pg_dump.h:138
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
void AssignDumpId ( DumpableObject dobj)

Definition at line 513 of file common.c.

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

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

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

Definition at line 840 of file common.c.

References findObjectByOid(), and numCollations.

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

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

Definition at line 862 of file common.c.

References findObjectByOid(), and numExtensions.

Referenced by getExtensionMembership().

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

Definition at line 818 of file common.c.

References findObjectByOid(), and numFuncs.

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

819 {
820  return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs);
821 }
static int numFuncs
Definition: common.c:59
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:646
static DumpableObject ** funinfoindex
Definition: common.c:52
NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 851 of file common.c.

References findObjectByOid(), and numNamespaces.

Referenced by findNamespace().

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

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

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

Definition at line 577 of file common.c.

References allocedDumpIds, and NULL.

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

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

Definition at line 829 of file common.c.

References findObjectByOid(), and numOperators.

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

Definition at line 889 of file common.c.

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

Referenced by checkExtensionMembership().

890 {
891  ExtensionMemberId *low;
892  ExtensionMemberId *high;
893 
894  /*
895  * We could use bsearch() here, but the notational cruft of calling
896  * bsearch is nearly as bad as doing it ourselves; and the generalized
897  * bsearch function is noticeably slower as well.
898  */
899  if (numextmembers <= 0)
900  return NULL;
901  low = extmembers;
902  high = extmembers + (numextmembers - 1);
903  while (low <= high)
904  {
905  ExtensionMemberId *middle;
906  int difference;
907 
908  middle = low + (high - low) / 2;
909  /* comparison must match ExtensionMemberIdCompare, below */
910  difference = oidcmp(middle->catId.oid, catalogId.oid);
911  if (difference == 0)
912  difference = oidcmp(middle->catId.tableoid, catalogId.tableoid);
913  if (difference == 0)
914  return middle->ext;
915  else if (difference < 0)
916  low = middle + 1;
917  else
918  high = middle - 1;
919  }
920  return NULL;
921 }
ExtensionInfo * ext
Definition: pg_dump.h:627
Oid tableoid
Definition: pg_backup.h:225
#define oidcmp(x, y)
Definition: pg_dump.h:20
Datum difference(PG_FUNCTION_ARGS)
static ExtensionMemberId * extmembers
Definition: common.c:66
#define NULL
Definition: c.h:229
static int numextmembers
Definition: common.c:67
CatalogId catId
Definition: pg_dump.h:626
TableInfo* findTableByOid ( Oid  oid)

Definition at line 796 of file common.c.

References findObjectByOid(), and numTables.

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

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

Definition at line 807 of file common.c.

References findObjectByOid(), and numTypes.

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

808 {
809  return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes);
810 }
static int numTypes
Definition: common.c:58
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:646
static DumpableObject ** typinfoindex
Definition: common.c:51
AccessMethodInfo* getAccessMethods ( Archive fout,
int *  numAccessMethods 
)

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

4746 {
4747  PGresult *res;
4748  int ntups;
4749  int i;
4750  PQExpBuffer query;
4751  AccessMethodInfo *aminfo;
4752  int i_tableoid;
4753  int i_oid;
4754  int i_amname;
4755  int i_amhandler;
4756  int i_amtype;
4757 
4758  /* Before 9.6, there are no user-defined access methods */
4759  if (fout->remoteVersion < 90600)
4760  {
4761  *numAccessMethods = 0;
4762  return NULL;
4763  }
4764 
4765  query = createPQExpBuffer();
4766 
4767  /* Make sure we are in proper schema */
4768  selectSourceSchema(fout, "pg_catalog");
4769 
4770  /* Select all access methods from pg_am table */
4771  appendPQExpBuffer(query, "SELECT tableoid, oid, amname, amtype, "
4772  "amhandler::pg_catalog.regproc AS amhandler "
4773  "FROM pg_am");
4774 
4775  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4776 
4777  ntups = PQntuples(res);
4778  *numAccessMethods = ntups;
4779 
4780  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
4781 
4782  i_tableoid = PQfnumber(res, "tableoid");
4783  i_oid = PQfnumber(res, "oid");
4784  i_amname = PQfnumber(res, "amname");
4785  i_amhandler = PQfnumber(res, "amhandler");
4786  i_amtype = PQfnumber(res, "amtype");
4787 
4788  for (i = 0; i < ntups; i++)
4789  {
4790  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
4791  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4792  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4793  AssignDumpId(&aminfo[i].dobj);
4794  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
4795  aminfo[i].dobj.namespace = NULL;
4796  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
4797  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
4798 
4799  /* Decide whether we want to dump it */
4800  selectDumpableAccessMethod(&(aminfo[i]), fout);
4801 
4802  /* Access methods do not currently have ACLs. */
4803  aminfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4804  }
4805 
4806  PQclear(res);
4807 
4808  destroyPQExpBuffer(query);
4809 
4810  return aminfo;
4811 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpableObject dobj
Definition: pg_dump.h:227
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:1590
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
char * amhandler
Definition: pg_dump.h:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:184
AggInfo* getAggregates ( Archive fout,
int *  numAggregates 
)

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

4988 {
4989  DumpOptions *dopt = fout->dopt;
4990  PGresult *res;
4991  int ntups;
4992  int i;
4993  PQExpBuffer query = createPQExpBuffer();
4994  AggInfo *agginfo;
4995  int i_tableoid;
4996  int i_oid;
4997  int i_aggname;
4998  int i_aggnamespace;
4999  int i_pronargs;
5000  int i_proargtypes;
5001  int i_rolname;
5002  int i_aggacl;
5003  int i_raggacl;
5004  int i_initaggacl;
5005  int i_initraggacl;
5006 
5007  /* Make sure we are in proper schema */
5008  selectSourceSchema(fout, "pg_catalog");
5009 
5010  /*
5011  * Find all interesting aggregates. See comment in getFuncs() for the
5012  * rationale behind the filtering logic.
5013  */
5014  if (fout->remoteVersion >= 90600)
5015  {
5016  PQExpBuffer acl_subquery = createPQExpBuffer();
5017  PQExpBuffer racl_subquery = createPQExpBuffer();
5018  PQExpBuffer initacl_subquery = createPQExpBuffer();
5019  PQExpBuffer initracl_subquery = createPQExpBuffer();
5020 
5021  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5022  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5023  dopt->binary_upgrade);
5024 
5025  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5026  "p.proname AS aggname, "
5027  "p.pronamespace AS aggnamespace, "
5028  "p.pronargs, p.proargtypes, "
5029  "(%s p.proowner) AS rolname, "
5030  "%s AS aggacl, "
5031  "%s AS raggacl, "
5032  "%s AS initaggacl, "
5033  "%s AS initraggacl "
5034  "FROM pg_proc p "
5035  "LEFT JOIN pg_init_privs pip ON "
5036  "(p.oid = pip.objoid "
5037  "AND pip.classoid = 'pg_proc'::regclass "
5038  "AND pip.objsubid = 0) "
5039  "WHERE p.proisagg AND ("
5040  "p.pronamespace != "
5041  "(SELECT oid FROM pg_namespace "
5042  "WHERE nspname = 'pg_catalog') OR "
5043  "p.proacl IS DISTINCT FROM pip.initprivs",
5045  acl_subquery->data,
5046  racl_subquery->data,
5047  initacl_subquery->data,
5048  initracl_subquery->data);
5049  if (dopt->binary_upgrade)
5050  appendPQExpBufferStr(query,
5051  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5052  "classid = 'pg_proc'::regclass AND "
5053  "objid = p.oid AND "
5054  "refclassid = 'pg_extension'::regclass AND "
5055  "deptype = 'e')");
5056  appendPQExpBufferChar(query, ')');
5057 
5058  destroyPQExpBuffer(acl_subquery);
5059  destroyPQExpBuffer(racl_subquery);
5060  destroyPQExpBuffer(initacl_subquery);
5061  destroyPQExpBuffer(initracl_subquery);
5062  }
5063  else if (fout->remoteVersion >= 80200)
5064  {
5065  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5066  "pronamespace AS aggnamespace, "
5067  "pronargs, proargtypes, "
5068  "(%s proowner) AS rolname, "
5069  "proacl AS aggacl, "
5070  "NULL AS raggacl, "
5071  "NULL AS initaggacl, NULL AS initraggacl "
5072  "FROM pg_proc p "
5073  "WHERE proisagg AND ("
5074  "pronamespace != "
5075  "(SELECT oid FROM pg_namespace "
5076  "WHERE nspname = 'pg_catalog')",
5078  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5079  appendPQExpBufferStr(query,
5080  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5081  "classid = 'pg_proc'::regclass AND "
5082  "objid = p.oid AND "
5083  "refclassid = 'pg_extension'::regclass AND "
5084  "deptype = 'e')");
5085  appendPQExpBufferChar(query, ')');
5086  }
5087  else
5088  {
5089  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5090  "pronamespace AS aggnamespace, "
5091  "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
5092  "proargtypes, "
5093  "(%s proowner) AS rolname, "
5094  "proacl AS aggacl, "
5095  "NULL AS raggacl, "
5096  "NULL AS initaggacl, NULL AS initraggacl "
5097  "FROM pg_proc "
5098  "WHERE proisagg "
5099  "AND pronamespace != "
5100  "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
5102  }
5103 
5104  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5105 
5106  ntups = PQntuples(res);
5107  *numAggs = ntups;
5108 
5109  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5110 
5111  i_tableoid = PQfnumber(res, "tableoid");
5112  i_oid = PQfnumber(res, "oid");
5113  i_aggname = PQfnumber(res, "aggname");
5114  i_aggnamespace = PQfnumber(res, "aggnamespace");
5115  i_pronargs = PQfnumber(res, "pronargs");
5116  i_proargtypes = PQfnumber(res, "proargtypes");
5117  i_rolname = PQfnumber(res, "rolname");
5118  i_aggacl = PQfnumber(res, "aggacl");
5119  i_raggacl = PQfnumber(res, "raggacl");
5120  i_initaggacl = PQfnumber(res, "initaggacl");
5121  i_initraggacl = PQfnumber(res, "initraggacl");
5122 
5123  for (i = 0; i < ntups; i++)
5124  {
5125  agginfo[i].aggfn.dobj.objType = DO_AGG;
5126  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5127  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5128  AssignDumpId(&agginfo[i].aggfn.dobj);
5129  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5130  agginfo[i].aggfn.dobj.namespace =
5131  findNamespace(fout,
5132  atooid(PQgetvalue(res, i, i_aggnamespace)));
5133  agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5134  if (strlen(agginfo[i].aggfn.rolname) == 0)
5135  write_msg(NULL, "WARNING: owner of aggregate function \"%s\" appears to be invalid\n",
5136  agginfo[i].aggfn.dobj.name);
5137  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5138  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5139  agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5140  agginfo[i].aggfn.rproacl = pg_strdup(PQgetvalue(res, i, i_raggacl));
5141  agginfo[i].aggfn.initproacl = pg_strdup(PQgetvalue(res, i, i_initaggacl));
5142  agginfo[i].aggfn.initrproacl = pg_strdup(PQgetvalue(res, i, i_initraggacl));
5143  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5144  if (agginfo[i].aggfn.nargs == 0)
5145  agginfo[i].aggfn.argtypes = NULL;
5146  else
5147  {
5148  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5149  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5150  agginfo[i].aggfn.argtypes,
5151  agginfo[i].aggfn.nargs);
5152  }
5153 
5154  /* Decide whether we want to dump it */
5155  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5156 
5157  /* Do not try to dump ACL if no ACL exists. */
5158  if (PQgetisnull(res, i, i_aggacl) && PQgetisnull(res, i, i_raggacl) &&
5159  PQgetisnull(res, i, i_initaggacl) &&
5160  PQgetisnull(res, i, i_initraggacl))
5161  agginfo[i].aggfn.dobj.dump &= ~DUMP_COMPONENT_ACL;
5162  }
5163 
5164  PQclear(res);
5165 
5166  destroyPQExpBuffer(query);
5167 
5168  return agginfo;
5169 }
Oid * argtypes
Definition: pg_dump.h:202
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1656
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int nargs
Definition: pg_dump.h:201
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4142
char * initrproacl
Definition: pg_dump.h:207
Oid lang
Definition: pg_dump.h:200
DumpableObject dobj
Definition: pg_dump.h:198
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
FuncInfo aggfn
Definition: pg_dump.h:213
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:134
Definition: pg_dump.h:49
DumpOptions * dopt
Definition: pg_backup.h:179
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
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
static const char * username_subquery
Definition: pg_dump.c:96
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1038
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:650
void write_msg(const char *modulename, const char *fmt,...)
Oid prorettype
Definition: pg_dump.h:203
#define NULL
Definition: c.h:229
char * initproacl
Definition: pg_dump.h:206
char * rolname
Definition: pg_dump.h:199
char * proacl
Definition: pg_dump.h:204
char * rproacl
Definition: pg_dump.h:205
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:184
CastInfo* getCasts ( Archive fout,
int *  numCasts 
)

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

7465 {
7466  PGresult *res;
7467  int ntups;
7468  int i;
7469  PQExpBuffer query = createPQExpBuffer();
7470  CastInfo *castinfo;
7471  int i_tableoid;
7472  int i_oid;
7473  int i_castsource;
7474  int i_casttarget;
7475  int i_castfunc;
7476  int i_castcontext;
7477  int i_castmethod;
7478 
7479  /* Make sure we are in proper schema */
7480  selectSourceSchema(fout, "pg_catalog");
7481 
7482  if (fout->remoteVersion >= 80400)
7483  {
7484  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7485  "castsource, casttarget, castfunc, castcontext, "
7486  "castmethod "
7487  "FROM pg_cast ORDER BY 3,4");
7488  }
7489  else
7490  {
7491  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7492  "castsource, casttarget, castfunc, castcontext, "
7493  "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
7494  "FROM pg_cast ORDER BY 3,4");
7495  }
7496 
7497  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7498 
7499  ntups = PQntuples(res);
7500 
7501  *numCasts = ntups;
7502 
7503  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
7504 
7505  i_tableoid = PQfnumber(res, "tableoid");
7506  i_oid = PQfnumber(res, "oid");
7507  i_castsource = PQfnumber(res, "castsource");
7508  i_casttarget = PQfnumber(res, "casttarget");
7509  i_castfunc = PQfnumber(res, "castfunc");
7510  i_castcontext = PQfnumber(res, "castcontext");
7511  i_castmethod = PQfnumber(res, "castmethod");
7512 
7513  for (i = 0; i < ntups; i++)
7514  {
7515  PQExpBufferData namebuf;
7516  TypeInfo *sTypeInfo;
7517  TypeInfo *tTypeInfo;
7518 
7519  castinfo[i].dobj.objType = DO_CAST;
7520  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7521  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7522  AssignDumpId(&castinfo[i].dobj);
7523  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
7524  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
7525  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
7526  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
7527  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
7528 
7529  /*
7530  * Try to name cast as concatenation of typnames. This is only used
7531  * for purposes of sorting. If we fail to find either type, the name
7532  * will be an empty string.
7533  */
7534  initPQExpBuffer(&namebuf);
7535  sTypeInfo = findTypeByOid(castinfo[i].castsource);
7536  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
7537  if (sTypeInfo && tTypeInfo)
7538  appendPQExpBuffer(&namebuf, "%s %s",
7539  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
7540  castinfo[i].dobj.name = namebuf.data;
7541 
7542  /* Decide whether we want to dump it */
7543  selectDumpableCast(&(castinfo[i]), fout);
7544 
7545  /* Casts do not currently have ACLs. */
7546  castinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7547  }
7548 
7549  PQclear(res);
7550 
7551  destroyPQExpBuffer(query);
7552 
7553  return castinfo;
7554 }
char * name
Definition: pg_dump.h:133
Oid castsource
Definition: pg_dump.h:453
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:225
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:1532
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
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:455
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:452
Oid casttarget
Definition: pg_dump.h:454
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
DumpableObject dobj
Definition: pg_dump.h:165
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
char castmethod
Definition: pg_dump.h:457
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:807
DumpableObjectType objType
Definition: pg_dump.h:130
char castcontext
Definition: pg_dump.h:456
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:184
CollInfo* getCollations ( Archive fout,
int *  numCollations 
)

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

4587 {
4588  PGresult *res;
4589  int ntups;
4590  int i;
4591  PQExpBuffer query;
4592  CollInfo *collinfo;
4593  int i_tableoid;
4594  int i_oid;
4595  int i_collname;
4596  int i_collnamespace;
4597  int i_rolname;
4598 
4599  /* Collations didn't exist pre-9.1 */
4600  if (fout->remoteVersion < 90100)
4601  {
4602  *numCollations = 0;
4603  return NULL;
4604  }
4605 
4606  query = createPQExpBuffer();
4607 
4608  /*
4609  * find all collations, including builtin collations; we filter out
4610  * system-defined collations at dump-out time.
4611  */
4612 
4613  /* Make sure we are in proper schema */
4614  selectSourceSchema(fout, "pg_catalog");
4615 
4616  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
4617  "collnamespace, "
4618  "(%s collowner) AS rolname "
4619  "FROM pg_collation",
4621 
4622  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4623 
4624  ntups = PQntuples(res);
4625  *numCollations = ntups;
4626 
4627  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
4628 
4629  i_tableoid = PQfnumber(res, "tableoid");
4630  i_oid = PQfnumber(res, "oid");
4631  i_collname = PQfnumber(res, "collname");
4632  i_collnamespace = PQfnumber(res, "collnamespace");
4633  i_rolname = PQfnumber(res, "rolname");
4634 
4635  for (i = 0; i < ntups; i++)
4636  {
4637  collinfo[i].dobj.objType = DO_COLLATION;
4638  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4639  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4640  AssignDumpId(&collinfo[i].dobj);
4641  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
4642  collinfo[i].dobj.namespace =
4643  findNamespace(fout,
4644  atooid(PQgetvalue(res, i, i_collnamespace)));
4645  collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4646 
4647  /* Decide whether we want to dump it */
4648  selectDumpableObject(&(collinfo[i].dobj), fout);
4649 
4650  /* Collations do not currently have ACLs. */
4651  collinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4652  }
4653 
4654  PQclear(res);
4655 
4656  destroyPQExpBuffer(query);
4657 
4658  return collinfo;
4659 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1656
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
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:4142
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
DumpableObject dobj
Definition: pg_dump.h:246
char * rolname
Definition: pg_dump.h:247
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
static const char * username_subquery
Definition: pg_dump.c:96
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
static int numCollations
Definition: common.c:61
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:184
void getConstraints ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

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

6690 {
6691  int i,
6692  j;
6693  ConstraintInfo *constrinfo;
6694  PQExpBuffer query;
6695  PGresult *res;
6696  int i_contableoid,
6697  i_conoid,
6698  i_conname,
6699  i_confrelid,
6700  i_condef;
6701  int ntups;
6702 
6703  query = createPQExpBuffer();
6704 
6705  for (i = 0; i < numTables; i++)
6706  {
6707  TableInfo *tbinfo = &tblinfo[i];
6708 
6709  if (!tbinfo->hastriggers ||
6710  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6711  continue;
6712 
6713  if (g_verbose)
6714  write_msg(NULL, "reading foreign key constraints for table \"%s.%s\"\n",
6715  tbinfo->dobj.namespace->dobj.name,
6716  tbinfo->dobj.name);
6717 
6718  /*
6719  * select table schema to ensure constraint expr is qualified if
6720  * needed
6721  */
6722  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6723 
6724  resetPQExpBuffer(query);
6725  appendPQExpBuffer(query,
6726  "SELECT tableoid, oid, conname, confrelid, "
6727  "pg_catalog.pg_get_constraintdef(oid) AS condef "
6728  "FROM pg_catalog.pg_constraint "
6729  "WHERE conrelid = '%u'::pg_catalog.oid "
6730  "AND contype = 'f'",
6731  tbinfo->dobj.catId.oid);
6732  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6733 
6734  ntups = PQntuples(res);
6735 
6736  i_contableoid = PQfnumber(res, "tableoid");
6737  i_conoid = PQfnumber(res, "oid");
6738  i_conname = PQfnumber(res, "conname");
6739  i_confrelid = PQfnumber(res, "confrelid");
6740  i_condef = PQfnumber(res, "condef");
6741 
6742  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
6743 
6744  for (j = 0; j < ntups; j++)
6745  {
6746  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
6747  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
6748  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
6749  AssignDumpId(&constrinfo[j].dobj);
6750  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
6751  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6752  constrinfo[j].contable = tbinfo;
6753  constrinfo[j].condomain = NULL;
6754  constrinfo[j].contype = 'f';
6755  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
6756  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
6757  constrinfo[j].conindex = 0;
6758  constrinfo[j].condeferrable = false;
6759  constrinfo[j].condeferred = false;
6760  constrinfo[j].conislocal = true;
6761  constrinfo[j].separate = true;
6762  }
6763 
6764  PQclear(res);
6765  }
6766 
6767  destroyPQExpBuffer(query);
6768 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
bool hastriggers
Definition: pg_dump.h:277
static int numTables
Definition: common.c:57
DumpId conindex
Definition: pg_dump.h:429
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
DumpableObject dobj
Definition: pg_dump.h:261
char * condef
Definition: pg_dump.h:427
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:423
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
bool condeferrable
Definition: pg_dump.h:430
TypeInfo * condomain
Definition: pg_dump.h:425
bool conislocal
Definition: pg_dump.h:432
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:424
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
void write_msg(const char *modulename, const char *fmt,...)
bool condeferred
Definition: pg_dump.h:431
#define NULL
Definition: c.h:229
CatalogId catId
Definition: pg_dump.h:131
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
DumpableObjectType objType
Definition: pg_dump.h:130
bool g_verbose
Definition: pg_dump.c: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 4669 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().

4670 {
4671  PGresult *res;
4672  int ntups;
4673  int i;
4674  PQExpBuffer query;
4675  ConvInfo *convinfo;
4676  int i_tableoid;
4677  int i_oid;
4678  int i_conname;
4679  int i_connamespace;
4680  int i_rolname;
4681 
4682  query = createPQExpBuffer();
4683 
4684  /*
4685  * find all conversions, including builtin conversions; we filter out
4686  * system-defined conversions at dump-out time.
4687  */
4688 
4689  /* Make sure we are in proper schema */
4690  selectSourceSchema(fout, "pg_catalog");
4691 
4692  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
4693  "connamespace, "
4694  "(%s conowner) AS rolname "
4695  "FROM pg_conversion",
4697 
4698  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4699 
4700  ntups = PQntuples(res);
4701  *numConversions = ntups;
4702 
4703  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
4704 
4705  i_tableoid = PQfnumber(res, "tableoid");
4706  i_oid = PQfnumber(res, "oid");
4707  i_conname = PQfnumber(res, "conname");
4708  i_connamespace = PQfnumber(res, "connamespace");
4709  i_rolname = PQfnumber(res, "rolname");
4710 
4711  for (i = 0; i < ntups; i++)
4712  {
4713  convinfo[i].dobj.objType = DO_CONVERSION;
4714  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4715  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4716  AssignDumpId(&convinfo[i].dobj);
4717  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
4718  convinfo[i].dobj.namespace =
4719  findNamespace(fout,
4720  atooid(PQgetvalue(res, i, i_connamespace)));
4721  convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4722 
4723  /* Decide whether we want to dump it */
4724  selectDumpableObject(&(convinfo[i].dobj), fout);
4725 
4726  /* Conversions do not currently have ACLs. */
4727  convinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4728  }
4729 
4730  PQclear(res);
4731 
4732  destroyPQExpBuffer(query);
4733 
4734  return convinfo;
4735 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1656
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
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:4142
char * rolname
Definition: pg_dump.h:253
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
static const char * username_subquery
Definition: pg_dump.c:96
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
DumpableObject dobj
Definition: pg_dump.h:252
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
DefaultACLInfo* getDefaultACLs ( Archive fout,
int *  numDefaultACLs 
)

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

8842 {
8843  DumpOptions *dopt = fout->dopt;
8844  DefaultACLInfo *daclinfo;
8845  PQExpBuffer query;
8846  PGresult *res;
8847  int i_oid;
8848  int i_tableoid;
8849  int i_defaclrole;
8850  int i_defaclnamespace;
8851  int i_defaclobjtype;
8852  int i_defaclacl;
8853  int i_rdefaclacl;
8854  int i_initdefaclacl;
8855  int i_initrdefaclacl;
8856  int i,
8857  ntups;
8858 
8859  if (fout->remoteVersion < 90000)
8860  {
8861  *numDefaultACLs = 0;
8862  return NULL;
8863  }
8864 
8865  query = createPQExpBuffer();
8866 
8867  /* Make sure we are in proper schema */
8868  selectSourceSchema(fout, "pg_catalog");
8869 
8870  if (fout->remoteVersion >= 90600)
8871  {
8872  PQExpBuffer acl_subquery = createPQExpBuffer();
8873  PQExpBuffer racl_subquery = createPQExpBuffer();
8874  PQExpBuffer initacl_subquery = createPQExpBuffer();
8875  PQExpBuffer initracl_subquery = createPQExpBuffer();
8876 
8877  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8878  initracl_subquery, "defaclacl", "defaclrole",
8879  "CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
8880  dopt->binary_upgrade);
8881 
8882  appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
8883  "(%s d.defaclrole) AS defaclrole, "
8884  "d.defaclnamespace, "
8885  "d.defaclobjtype, "
8886  "%s AS defaclacl, "
8887  "%s AS rdefaclacl, "
8888  "%s AS initdefaclacl, "
8889  "%s AS initrdefaclacl "
8890  "FROM pg_default_acl d "
8891  "LEFT JOIN pg_init_privs pip ON "
8892  "(d.oid = pip.objoid "
8893  "AND pip.classoid = 'pg_default_acl'::regclass "
8894  "AND pip.objsubid = 0) ",
8896  acl_subquery->data,
8897  racl_subquery->data,
8898  initacl_subquery->data,
8899  initracl_subquery->data);
8900  }
8901  else
8902  {
8903  appendPQExpBuffer(query, "SELECT oid, tableoid, "
8904  "(%s defaclrole) AS defaclrole, "
8905  "defaclnamespace, "
8906  "defaclobjtype, "
8907  "defaclacl, "
8908  "NULL AS rdefaclacl, "
8909  "NULL AS initdefaclacl, "
8910  "NULL AS initrdefaclacl "
8911  "FROM pg_default_acl",
8913  }
8914 
8915  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8916 
8917  ntups = PQntuples(res);
8918  *numDefaultACLs = ntups;
8919 
8920  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
8921 
8922  i_oid = PQfnumber(res, "oid");
8923  i_tableoid = PQfnumber(res, "tableoid");
8924  i_defaclrole = PQfnumber(res, "defaclrole");
8925  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
8926  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
8927  i_defaclacl = PQfnumber(res, "defaclacl");
8928  i_rdefaclacl = PQfnumber(res, "rdefaclacl");
8929  i_initdefaclacl = PQfnumber(res, "initdefaclacl");
8930  i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
8931 
8932  for (i = 0; i < ntups; i++)
8933  {
8934  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
8935 
8936  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
8937  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8938  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8939  AssignDumpId(&daclinfo[i].dobj);
8940  /* cheesy ... is it worth coming up with a better object name? */
8941  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
8942 
8943  if (nspid != InvalidOid)
8944  daclinfo[i].dobj.namespace = findNamespace(fout, nspid);
8945  else
8946  daclinfo[i].dobj.namespace = NULL;
8947 
8948  daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
8949  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
8950  daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
8951  daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
8952  daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
8953  daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
8954 
8955  /* Decide whether we want to dump it */
8956  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
8957  }
8958 
8959  PQclear(res);
8960 
8961  destroyPQExpBuffer(query);
8962 
8963  return daclinfo;
8964 }
char * name
Definition: pg_dump.h:133
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
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:4142
char * rdefaclacl
Definition: pg_dump.h:550
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:1510
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:134
DumpOptions * dopt
Definition: pg_backup.h:179
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:546
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
static const char * username_subquery
Definition: pg_dump.c:96
char * defaclacl
Definition: pg_dump.h:549
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
char * initdefaclacl
Definition: pg_dump.h:551
CatalogId catId
Definition: pg_dump.h:131
char * initrdefaclacl
Definition: pg_dump.h:552
int i
char defaclobjtype
Definition: pg_dump.h:548
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:184
char * defaclrole
Definition: pg_dump.h:547
void getDumpableObjects ( DumpableObject ***  objs,
int *  numObjs 
)

Definition at line 727 of file common.c.

References allocedDumpIds, i, and pg_malloc().

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

728 {
729  int i,
730  j;
731 
732  *objs = (DumpableObject **)
734  j = 0;
735  for (i = 1; i < allocedDumpIds; i++)
736  {
737  if (dumpIdMap[i])
738  (*objs)[j++] = dumpIdMap[i];
739  }
740  *numObjs = j;
741 }
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 7189 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().

7190 {
7191  int i;
7192  PQExpBuffer query;
7193  PGresult *res;
7194  EventTriggerInfo *evtinfo;
7195  int i_tableoid,
7196  i_oid,
7197  i_evtname,
7198  i_evtevent,
7199  i_evtowner,
7200  i_evttags,
7201  i_evtfname,
7202  i_evtenabled;
7203  int ntups;
7204 
7205  /* Before 9.3, there are no event triggers */
7206  if (fout->remoteVersion < 90300)
7207  {
7208  *numEventTriggers = 0;
7209  return NULL;
7210  }
7211 
7212  query = createPQExpBuffer();
7213 
7214  /* Make sure we are in proper schema */
7215  selectSourceSchema(fout, "pg_catalog");
7216 
7217  appendPQExpBuffer(query,
7218  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
7219  "evtevent, (%s evtowner) AS evtowner, "
7220  "array_to_string(array("
7221  "select quote_literal(x) "
7222  " from unnest(evttags) as t(x)), ', ') as evttags, "
7223  "e.evtfoid::regproc as evtfname "
7224  "FROM pg_event_trigger e "
7225  "ORDER BY e.oid",
7227 
7228  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7229 
7230  ntups = PQntuples(res);
7231 
7232  *numEventTriggers = ntups;
7233 
7234  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
7235 
7236  i_tableoid = PQfnumber(res, "tableoid");
7237  i_oid = PQfnumber(res, "oid");
7238  i_evtname = PQfnumber(res, "evtname");
7239  i_evtevent = PQfnumber(res, "evtevent");
7240  i_evtowner = PQfnumber(res, "evtowner");
7241  i_evttags = PQfnumber(res, "evttags");
7242  i_evtfname = PQfnumber(res, "evtfname");
7243  i_evtenabled = PQfnumber(res, "evtenabled");
7244 
7245  for (i = 0; i < ntups; i++)
7246  {
7247  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
7248  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7249  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7250  AssignDumpId(&evtinfo[i].dobj);
7251  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
7252  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
7253  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
7254  evtinfo[i].evtowner = pg_strdup(PQgetvalue(res, i, i_evtowner));
7255  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
7256  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
7257  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
7258 
7259  /* Decide whether we want to dump it */
7260  selectDumpableObject(&(evtinfo[i].dobj), fout);
7261 
7262  /* Event Triggers do not currently have ACLs. */
7263  evtinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
7264  }
7265 
7266  PQclear(res);
7267 
7268  destroyPQExpBuffer(query);
7269 
7270  return evtinfo;
7271 }
char * name
Definition: pg_dump.h:133
char * evtevent
Definition: pg_dump.h:406
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1656
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
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:407
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
static const char * username_subquery
Definition: pg_dump.c:96
char * evtfname
Definition: pg_dump.h:409
char * evttags
Definition: pg_dump.h:408
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
char * evtname
Definition: pg_dump.h:405
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
DumpableObject dobj
Definition: pg_dump.h:404
char evtenabled
Definition: pg_dump.h:410
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:184
void getExtendedStatistics ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 6595 of file pg_dump.c.

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

Referenced by getSchemaData().

6596 {
6597  int i,
6598  j;
6599  PQExpBuffer query;
6600  PGresult *res;
6601  StatsExtInfo *statsextinfo;
6602  int ntups;
6603  int i_tableoid;
6604  int i_oid;
6605  int i_staname;
6606  int i_stadef;
6607 
6608  /* Extended statistics were new in v10 */
6609  if (fout->remoteVersion < 100000)
6610  return;
6611 
6612  query = createPQExpBuffer();
6613 
6614  for (i = 0; i < numTables; i++)
6615  {
6616  TableInfo *tbinfo = &tblinfo[i];
6617 
6618  /* Only plain tables and materialized views can have extended statistics. */
6619  if (tbinfo->relkind != RELKIND_RELATION &&
6620  tbinfo->relkind != RELKIND_MATVIEW)
6621  continue;
6622 
6623  /*
6624  * Ignore extended statistics of tables whose definitions are not to
6625  * be dumped.
6626  */
6627  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6628  continue;
6629 
6630  if (g_verbose)
6631  write_msg(NULL, "reading extended statistics for table \"%s.%s\"\n",
6632  tbinfo->dobj.namespace->dobj.name,
6633  tbinfo->dobj.name);
6634 
6635  /* Make sure we are in proper schema so stadef is right */
6636  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6637 
6638  resetPQExpBuffer(query);
6639 
6640  appendPQExpBuffer(query,
6641  "SELECT "
6642  "tableoid, "
6643  "oid, "
6644  "staname, "
6645  "pg_catalog.pg_get_statisticsextdef(oid) AS stadef "
6646  "FROM pg_statistic_ext "
6647  "WHERE starelid = '%u' "
6648  "ORDER BY staname", tbinfo->dobj.catId.oid);
6649 
6650  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6651 
6652  ntups = PQntuples(res);
6653 
6654  i_tableoid = PQfnumber(res, "tableoid");
6655  i_oid = PQfnumber(res, "oid");
6656  i_staname = PQfnumber(res, "staname");
6657  i_stadef = PQfnumber(res, "stadef");
6658 
6659  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
6660 
6661  for (j = 0; j < ntups; j++)
6662  {
6663  statsextinfo[j].dobj.objType = DO_STATSEXT;
6664  statsextinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
6665  statsextinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
6666  AssignDumpId(&statsextinfo[j].dobj);
6667  statsextinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_staname));
6668  statsextinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6669  statsextinfo[j].statsexttable = tbinfo;
6670  statsextinfo[j].statsextdef = pg_strdup(PQgetvalue(res, j, i_stadef));
6671  }
6672 
6673  PQclear(res);
6674  }
6675 
6676  destroyPQExpBuffer(query);
6677 }
char * name
Definition: pg_dump.h:133
char relkind
Definition: pg_dump.h:267
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
char * statsextdef
Definition: pg_dump.h:370
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:368
#define RELKIND_MATVIEW
Definition: pg_class.h:165
static int numTables
Definition: common.c:57
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
DumpableObject dobj
Definition: pg_dump.h:261
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
CatalogId catId
Definition: pg_dump.h:131
TableInfo * statsexttable
Definition: pg_dump.h:369
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
#define RELKIND_RELATION
Definition: pg_class.h:160
DumpableObjectType objType
Definition: pg_dump.h:130
bool g_verbose
Definition: pg_dump.c:90
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:184
void getExtensionMembership ( Archive fout,
ExtensionInfo  extinfo[],
int  numExtensions 
)

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

16956 {
16957  PQExpBuffer query;
16958  PGresult *res;
16959  int ntups,
16960  nextmembers,
16961  i;
16962  int i_classid,
16963  i_objid,
16964  i_refobjid;
16966  ExtensionInfo *ext;
16967 
16968  /* Nothing to do if no extensions */
16969  if (numExtensions == 0)
16970  return;
16971 
16972  /* Make sure we are in proper schema */
16973  selectSourceSchema(fout, "pg_catalog");
16974 
16975  query = createPQExpBuffer();
16976 
16977  /* refclassid constraint is redundant but may speed the search */
16978  appendPQExpBufferStr(query, "SELECT "
16979  "classid, objid, refobjid "
16980  "FROM pg_depend "
16981  "WHERE refclassid = 'pg_extension'::regclass "
16982  "AND deptype = 'e' "
16983  "ORDER BY 3");
16984 
16985  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
16986 
16987  ntups = PQntuples(res);
16988 
16989  i_classid = PQfnumber(res, "classid");
16990  i_objid = PQfnumber(res, "objid");
16991  i_refobjid = PQfnumber(res, "refobjid");
16992 
16993  extmembers = (ExtensionMemberId *) pg_malloc(ntups * sizeof(ExtensionMemberId));
16994  nextmembers = 0;
16995 
16996  /*
16997  * Accumulate data into extmembers[].
16998  *
16999  * Since we ordered the SELECT by referenced ID, we can expect that
17000  * multiple entries for the same extension will appear together; this
17001  * saves on searches.
17002  */
17003  ext = NULL;
17004 
17005  for (i = 0; i < ntups; i++)
17006  {
17007  CatalogId objId;
17008  Oid extId;
17009 
17010  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
17011  objId.oid = atooid(PQgetvalue(res, i, i_objid));
17012  extId = atooid(PQgetvalue(res, i, i_refobjid));
17013 
17014  if (ext == NULL ||
17015  ext->dobj.catId.oid != extId)
17016  ext = findExtensionByOid(extId);
17017 
17018  if (ext == NULL)
17019  {
17020  /* shouldn't happen */
17021  fprintf(stderr, "could not find referenced extension %u\n", extId);
17022  continue;
17023  }
17024 
17025  extmembers[nextmembers].catId = objId;
17026  extmembers[nextmembers].ext = ext;
17027  nextmembers++;
17028  }
17029 
17030  PQclear(res);
17031 
17032  /* Remember the data for use later */
17033  setExtensionMembership(extmembers, nextmembers);
17034 
17035  destroyPQExpBuffer(query);
17036 }
ExtensionInfo * ext
Definition: pg_dump.h:627
DumpableObject dobj
Definition: pg_dump.h:155
Oid tableoid
Definition: pg_backup.h:225
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void setExtensionMembership(ExtensionMemberId *extmems, int nextmems)
Definition: common.c:873
static int numExtensions
Definition: common.c:63
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
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:862
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
CatalogId catId
Definition: pg_dump.h:131
CatalogId catId
Definition: pg_dump.h:626
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 4160 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().

4161 {
4162  DumpOptions *dopt = fout->dopt;
4163  PGresult *res;
4164  int ntups;
4165  int i;
4166  PQExpBuffer query;
4167  ExtensionInfo *extinfo;
4168  int i_tableoid;
4169  int i_oid;
4170  int i_extname;
4171  int i_nspname;
4172  int i_extrelocatable;
4173  int i_extversion;
4174  int i_extconfig;
4175  int i_extcondition;
4176 
4177  /*
4178  * Before 9.1, there are no extensions.
4179  */
4180  if (fout->remoteVersion < 90100)
4181  {
4182  *numExtensions = 0;
4183  return NULL;
4184  }
4185 
4186  query = createPQExpBuffer();
4187 
4188  /* Make sure we are in proper schema */
4189  selectSourceSchema(fout, "pg_catalog");
4190 
4191  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
4192  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
4193  "FROM pg_extension x "
4194  "JOIN pg_namespace n ON n.oid = x.extnamespace");
4195 
4196  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4197 
4198  ntups = PQntuples(res);
4199 
4200  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
4201 
4202  i_tableoid = PQfnumber(res, "tableoid");
4203  i_oid = PQfnumber(res, "oid");
4204  i_extname = PQfnumber(res, "extname");
4205  i_nspname = PQfnumber(res, "nspname");
4206  i_extrelocatable = PQfnumber(res, "extrelocatable");
4207  i_extversion = PQfnumber(res, "extversion");
4208  i_extconfig = PQfnumber(res, "extconfig");
4209  i_extcondition = PQfnumber(res, "extcondition");
4210 
4211  for (i = 0; i < ntups; i++)
4212  {
4213  extinfo[i].dobj.objType = DO_EXTENSION;
4214  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4215  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4216  AssignDumpId(&extinfo[i].dobj);
4217  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
4218  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
4219  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
4220  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
4221  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
4222  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
4223 
4224  /* Decide whether we want to dump it */
4225  selectDumpableExtension(&(extinfo[i]), dopt);
4226  }
4227 
4228  PQclear(res);
4229  destroyPQExpBuffer(query);
4230 
4231  *numExtensions = ntups;
4232 
4233  return extinfo;
4234 }
char * name
Definition: pg_dump.h:133
DumpableObject dobj
Definition: pg_dump.h:155
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
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:179
char * extconfig
Definition: pg_dump.h:159
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static int numExtensions
Definition: common.c:63
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:1617
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * extcondition
Definition: pg_dump.h:160
#define NULL
Definition: c.h:229
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
bool relocatable
Definition: pg_dump.h:156
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:184
char * extversion
Definition: pg_dump.h:158
FdwInfo* getForeignDataWrappers ( Archive fout,
int *  numForeignDataWrappers 
)

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

8520 {
8521  DumpOptions *dopt = fout->dopt;
8522  PGresult *res;
8523  int ntups;
8524  int i;
8525  PQExpBuffer query;
8526  FdwInfo *fdwinfo;
8527  int i_tableoid;
8528  int i_oid;
8529  int i_fdwname;
8530  int i_rolname;
8531  int i_fdwhandler;
8532  int i_fdwvalidator;
8533  int i_fdwacl;
8534  int i_rfdwacl;
8535  int i_initfdwacl;
8536  int i_initrfdwacl;
8537  int i_fdwoptions;
8538 
8539  /* Before 8.4, there are no foreign-data wrappers */
8540  if (fout->remoteVersion < 80400)
8541  {
8542  *numForeignDataWrappers = 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.fdwacl", "f.fdwowner", "'F'",
8560  dopt->binary_upgrade);
8561 
8562  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.fdwname, "
8563  "(%s f.fdwowner) AS rolname, "
8564  "f.fdwhandler::pg_catalog.regproc, "
8565  "f.fdwvalidator::pg_catalog.regproc, "
8566  "%s AS fdwacl, "
8567  "%s AS rfdwacl, "
8568  "%s AS initfdwacl, "
8569  "%s AS initrfdwacl, "
8570  "array_to_string(ARRAY("
8571  "SELECT quote_ident(option_name) || ' ' || "
8572  "quote_literal(option_value) "
8573  "FROM pg_options_to_table(f.fdwoptions) "
8574  "ORDER BY option_name"
8575  "), E',\n ') AS fdwoptions "
8576  "FROM pg_foreign_data_wrapper f "
8577  "LEFT JOIN pg_init_privs pip ON "
8578  "(f.oid = pip.objoid "
8579  "AND pip.classoid = 'pg_foreign_data_wrapper'::regclass "
8580  "AND pip.objsubid = 0) ",
8582  acl_subquery->data,
8583  racl_subquery->data,
8584  initacl_subquery->data,
8585  initracl_subquery->data);
8586 
8587  destroyPQExpBuffer(acl_subquery);
8588  destroyPQExpBuffer(racl_subquery);
8589  destroyPQExpBuffer(initacl_subquery);
8590  destroyPQExpBuffer(initracl_subquery);
8591  }
8592  else if (fout->remoteVersion >= 90100)
8593  {
8594  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8595  "(%s fdwowner) AS rolname, "
8596  "fdwhandler::pg_catalog.regproc, "
8597  "fdwvalidator::pg_catalog.regproc, fdwacl, "
8598  "NULL as rfdwacl, "
8599  "NULL as initfdwacl, NULL AS initrfdwacl, "
8600  "array_to_string(ARRAY("
8601  "SELECT quote_ident(option_name) || ' ' || "
8602  "quote_literal(option_value) "
8603  "FROM pg_options_to_table(fdwoptions) "
8604  "ORDER BY option_name"
8605  "), E',\n ') AS fdwoptions "
8606  "FROM pg_foreign_data_wrapper",
8608  }
8609  else
8610  {
8611  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8612  "(%s fdwowner) AS rolname, "
8613  "'-' AS fdwhandler, "
8614  "fdwvalidator::pg_catalog.regproc, fdwacl, "
8615  "NULL as rfdwacl, "
8616  "NULL as initfdwacl, NULL AS initrfdwacl, "
8617  "array_to_string(ARRAY("
8618  "SELECT quote_ident(option_name) || ' ' || "
8619  "quote_literal(option_value) "
8620  "FROM pg_options_to_table(fdwoptions) "
8621  "ORDER BY option_name"
8622  "), E',\n ') AS fdwoptions "
8623  "FROM pg_foreign_data_wrapper",
8625  }
8626 
8627  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8628 
8629  ntups = PQntuples(res);
8630  *numForeignDataWrappers = ntups;
8631 
8632  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
8633 
8634  i_tableoid = PQfnumber(res, "tableoid");
8635  i_oid = PQfnumber(res, "oid");
8636  i_fdwname = PQfnumber(res, "fdwname");
8637  i_rolname = PQfnumber(res, "rolname");
8638  i_fdwhandler = PQfnumber(res, "fdwhandler");
8639  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
8640  i_fdwacl = PQfnumber(res, "fdwacl");
8641  i_rfdwacl = PQfnumber(res, "rfdwacl");
8642  i_initfdwacl = PQfnumber(res, "initfdwacl");
8643  i_initrfdwacl = PQfnumber(res, "initrfdwacl");
8644  i_fdwoptions = PQfnumber(res, "fdwoptions");
8645 
8646  for (i = 0; i < ntups; i++)
8647  {
8648  fdwinfo[i].dobj.objType = DO_FDW;
8649  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8650  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8651  AssignDumpId(&fdwinfo[i].dobj);
8652  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
8653  fdwinfo[i].dobj.namespace = NULL;
8654  fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
8655  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
8656  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
8657  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
8658  fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
8659  fdwinfo[i].rfdwacl = pg_strdup(PQgetvalue(res, i, i_rfdwacl));
8660  fdwinfo[i].initfdwacl = pg_strdup(PQgetvalue(res, i, i_initfdwacl));
8661  fdwinfo[i].initrfdwacl = pg_strdup(PQgetvalue(res, i, i_initrfdwacl));
8662 
8663  /* Decide whether we want to dump it */
8664  selectDumpableObject(&(fdwinfo[i].dobj), fout);
8665 
8666  /* Do not try to dump ACL if no ACL exists. */
8667  if (PQgetisnull(res, i, i_fdwacl) && PQgetisnull(res, i, i_rfdwacl) &&
8668  PQgetisnull(res, i, i_initfdwacl) &&
8669  PQgetisnull(res, i, i_initrfdwacl))
8670  fdwinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8671  }
8672 
8673  PQclear(res);
8674 
8675  destroyPQExpBuffer(query);
8676 
8677  return fdwinfo;
8678 }
char * name
Definition: pg_dump.h:133
char * rfdwacl
Definition: pg_dump.h:525
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1656
Oid tableoid
Definition: pg_backup.h:225
char * fdwhandler
Definition: pg_dump.h:521
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
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:523
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:519
int binary_upgrade
Definition: pg_backup.h:134
DumpOptions * dopt
Definition: pg_backup.h:179
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:522
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
char * fdwacl
Definition: pg_dump.h:524
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
static const char * username_subquery
Definition: pg_dump.c:96
char * rolname
Definition: pg_dump.h:520
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:526
Definition: pg_dump.h:73
#define NULL
Definition: c.h:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
char * initrfdwacl
Definition: pg_dump.h:527
CatalogId catId
Definition: pg_dump.h:131
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:184
ForeignServerInfo* getForeignServers ( Archive fout,
int *  numForeignServers 
)

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

8689 {
8690  DumpOptions *dopt = fout->dopt;
8691  PGresult *res;
8692  int ntups;
8693  int i;
8694  PQExpBuffer query;
8695  ForeignServerInfo *srvinfo;
8696  int i_tableoid;
8697  int i_oid;
8698  int i_srvname;
8699  int i_rolname;
8700  int i_srvfdw;
8701  int i_srvtype;
8702  int i_srvversion;
8703  int i_srvacl;
8704  int i_rsrvacl;
8705  int i_initsrvacl;
8706  int i_initrsrvacl;
8707  int i_srvoptions;
8708 
8709  /* Before 8.4, there are no foreign servers */
8710  if (fout->remoteVersion < 80400)
8711  {
8712  *numForeignServers = 0;
8713  return NULL;
8714  }
8715 
8716  query = createPQExpBuffer();
8717 
8718  /* Make sure we are in proper schema */
8719  selectSourceSchema(fout, "pg_catalog");
8720 
8721  if (fout->remoteVersion >= 90600)
8722  {
8723  PQExpBuffer acl_subquery = createPQExpBuffer();
8724  PQExpBuffer racl_subquery = createPQExpBuffer();
8725  PQExpBuffer initacl_subquery = createPQExpBuffer();
8726  PQExpBuffer initracl_subquery = createPQExpBuffer();
8727 
8728  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
8729  initracl_subquery, "f.srvacl", "f.srvowner", "'S'",
8730  dopt->binary_upgrade);
8731 
8732  appendPQExpBuffer(query, "SELECT f.tableoid, f.oid, f.srvname, "
8733  "(%s f.srvowner) AS rolname, "
8734  "f.srvfdw, f.srvtype, f.srvversion, "
8735  "%s AS srvacl, "
8736  "%s AS rsrvacl, "
8737  "%s AS initsrvacl, "
8738  "%s AS initrsrvacl, "
8739  "array_to_string(ARRAY("
8740  "SELECT quote_ident(option_name) || ' ' || "
8741  "quote_literal(option_value) "
8742  "FROM pg_options_to_table(f.srvoptions) "
8743  "ORDER BY option_name"
8744  "), E',\n ') AS srvoptions "
8745  "FROM pg_foreign_server f "
8746  "LEFT JOIN pg_init_privs pip "
8747  "ON (f.oid = pip.objoid "
8748  "AND pip.classoid = 'pg_foreign_server'::regclass "
8749  "AND pip.objsubid = 0) ",
8751  acl_subquery->data,
8752  racl_subquery->data,
8753  initacl_subquery->data,
8754  initracl_subquery->data);
8755 
8756  destroyPQExpBuffer(acl_subquery);
8757  destroyPQExpBuffer(racl_subquery);
8758  destroyPQExpBuffer(initacl_subquery);
8759  destroyPQExpBuffer(initracl_subquery);
8760  }
8761  else
8762  {
8763  appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
8764  "(%s srvowner) AS rolname, "
8765  "srvfdw, srvtype, srvversion, srvacl, "
8766  "NULL AS rsrvacl, "
8767  "NULL AS initsrvacl, NULL AS initrsrvacl, "
8768  "array_to_string(ARRAY("
8769  "SELECT quote_ident(option_name) || ' ' || "
8770  "quote_literal(option_value) "
8771  "FROM pg_options_to_table(srvoptions) "
8772  "ORDER BY option_name"
8773  "), E',\n ') AS srvoptions "
8774  "FROM pg_foreign_server",
8776  }
8777 
8778  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8779 
8780  ntups = PQntuples(res);
8781  *numForeignServers = ntups;
8782 
8783  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
8784 
8785  i_tableoid = PQfnumber(res, "tableoid");
8786  i_oid = PQfnumber(res, "oid");
8787  i_srvname = PQfnumber(res, "srvname");
8788  i_rolname = PQfnumber(res, "rolname");
8789  i_srvfdw = PQfnumber(res, "srvfdw");
8790  i_srvtype = PQfnumber(res, "srvtype");
8791  i_srvversion = PQfnumber(res, "srvversion");
8792  i_srvacl = PQfnumber(res, "srvacl");
8793  i_rsrvacl = PQfnumber(res, "rsrvacl");
8794  i_initsrvacl = PQfnumber(res, "initsrvacl");
8795  i_initrsrvacl = PQfnumber(res, "initrsrvacl");
8796  i_srvoptions = PQfnumber(res, "srvoptions");
8797 
8798  for (i = 0; i < ntups; i++)
8799  {
8800  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
8801  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8802  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8803  AssignDumpId(&srvinfo[i].dobj);
8804  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
8805  srvinfo[i].dobj.namespace = NULL;
8806  srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
8807  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
8808  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
8809  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
8810  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
8811  srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl));
8812  srvinfo[i].rsrvacl = pg_strdup(PQgetvalue(res, i, i_rsrvacl));
8813  srvinfo[i].initsrvacl = pg_strdup(PQgetvalue(res, i, i_initsrvacl));
8814  srvinfo[i].initrsrvacl = pg_strdup(PQgetvalue(res, i, i_initrsrvacl));
8815 
8816  /* Decide whether we want to dump it */
8817  selectDumpableObject(&(srvinfo[i].dobj), fout);
8818 
8819  /* Do not try to dump ACL if no ACL exists. */
8820  if (PQgetisnull(res, i, i_srvacl) && PQgetisnull(res, i, i_rsrvacl) &&
8821  PQgetisnull(res, i, i_initsrvacl) &&
8822  PQgetisnull(res, i, i_initrsrvacl))
8823  srvinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
8824  }
8825 
8826  PQclear(res);
8827 
8828  destroyPQExpBuffer(query);
8829 
8830  return srvinfo;
8831 }
char * srvoptions
Definition: pg_dump.h:541
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1656
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
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:540
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:134
DumpOptions * dopt
Definition: pg_backup.h:179
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
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
static const char * username_subquery
Definition: pg_dump.c:96
char * srvversion
Definition: pg_dump.h:536
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
DumpableObject dobj
Definition: pg_dump.h:532
int i
char * initsrvacl
Definition: pg_dump.h:539
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:184
FuncInfo* getFuncs ( Archive fout,
int *  numFuncs 
)

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

5180 {
5181  DumpOptions *dopt = fout->dopt;
5182  PGresult *res;
5183  int ntups;
5184  int i;
5185  PQExpBuffer query = createPQExpBuffer();
5186  FuncInfo *finfo;
5187  int i_tableoid;
5188  int i_oid;
5189  int i_proname;
5190  int i_pronamespace;
5191  int i_rolname;
5192  int i_prolang;
5193  int i_pronargs;
5194  int i_proargtypes;
5195  int i_prorettype;
5196  int i_proacl;
5197  int i_rproacl;
5198  int i_initproacl;
5199  int i_initrproacl;
5200 
5201  /* Make sure we are in proper schema */
5202  selectSourceSchema(fout, "pg_catalog");
5203 
5204  /*
5205  * Find all interesting functions. This is a bit complicated:
5206  *
5207  * 1. Always exclude aggregates; those are handled elsewhere.
5208  *
5209  * 2. Always exclude functions that are internally dependent on something
5210  * else, since presumably those will be created as a result of creating
5211  * the something else. This currently acts only to suppress constructor
5212  * functions for range types (so we only need it in 9.2 and up). Note
5213  * this is OK only because the constructors don't have any dependencies
5214  * the range type doesn't have; otherwise we might not get creation
5215  * ordering correct.
5216  *
5217  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
5218  * they're members of extensions and we are in binary-upgrade mode then
5219  * include them, since we want to dump extension members individually in
5220  * that mode. Also, if they are used by casts or transforms then we need
5221  * to gather the information about them, though they won't be dumped if
5222  * they are built-in. Also, in 9.6 and up, include functions in
5223  * pg_catalog if they have an ACL different from what's shown in
5224  * pg_init_privs.
5225  */
5226  if (fout->remoteVersion >= 90600)
5227  {
5228  PQExpBuffer acl_subquery = createPQExpBuffer();
5229  PQExpBuffer racl_subquery = createPQExpBuffer();
5230  PQExpBuffer initacl_subquery = createPQExpBuffer();
5231  PQExpBuffer initracl_subquery = createPQExpBuffer();
5232 
5233  buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
5234  initracl_subquery, "p.proacl", "p.proowner", "'f'",
5235  dopt->binary_upgrade);
5236 
5237  appendPQExpBuffer(query,
5238  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
5239  "p.pronargs, p.proargtypes, p.prorettype, "
5240  "%s AS proacl, "
5241  "%s AS rproacl, "
5242  "%s AS initproacl, "
5243  "%s AS initrproacl, "
5244  "p.pronamespace, "
5245  "(%s p.proowner) AS rolname "
5246  "FROM pg_proc p "
5247  "LEFT JOIN pg_init_privs pip ON "
5248  "(p.oid = pip.objoid "
5249  "AND pip.classoid = 'pg_proc'::regclass "
5250  "AND pip.objsubid = 0) "
5251  "WHERE NOT proisagg"
5252  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5253  "WHERE classid = 'pg_proc'::regclass AND "
5254  "objid = p.oid AND deptype = 'i')"
5255  "\n AND ("
5256  "\n pronamespace != "
5257  "(SELECT oid FROM pg_namespace "
5258  "WHERE nspname = 'pg_catalog')"
5259  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5260  "\n WHERE pg_cast.oid > %u "
5261  "\n AND p.oid = pg_cast.castfunc)"
5262  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5263  "\n WHERE pg_transform.oid > %u AND "
5264  "\n (p.oid = pg_transform.trffromsql"
5265  "\n OR p.oid = pg_transform.trftosql))",
5266  acl_subquery->data,
5267  racl_subquery->data,
5268  initacl_subquery->data,
5269  initracl_subquery->data,
5273  if (dopt->binary_upgrade)
5274  appendPQExpBufferStr(query,
5275  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5276  "classid = 'pg_proc'::regclass AND "
5277  "objid = p.oid AND "
5278  "refclassid = 'pg_extension'::regclass AND "
5279  "deptype = 'e')");
5280  appendPQExpBufferStr(query,
5281  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
5282  appendPQExpBufferChar(query, ')');
5283 
5284  destroyPQExpBuffer(acl_subquery);
5285  destroyPQExpBuffer(racl_subquery);
5286  destroyPQExpBuffer(initacl_subquery);
5287  destroyPQExpBuffer(initracl_subquery);
5288  }
5289  else
5290  {
5291  appendPQExpBuffer(query,
5292  "SELECT tableoid, oid, proname, prolang, "
5293  "pronargs, proargtypes, prorettype, proacl, "
5294  "NULL as rproacl, "
5295  "NULL as initproacl, NULL AS initrproacl, "
5296  "pronamespace, "
5297  "(%s proowner) AS rolname "
5298  "FROM pg_proc p "
5299  "WHERE NOT proisagg",
5301  if (fout->remoteVersion >= 90200)
5302  appendPQExpBufferStr(query,
5303  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5304  "WHERE classid = 'pg_proc'::regclass AND "
5305  "objid = p.oid AND deptype = 'i')");
5306  appendPQExpBuffer(query,
5307  "\n AND ("
5308  "\n pronamespace != "
5309  "(SELECT oid FROM pg_namespace "
5310  "WHERE nspname = 'pg_catalog')"
5311  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5312  "\n WHERE pg_cast.oid > '%u'::oid"
5313  "\n AND p.oid = pg_cast.castfunc)",
5315 
5316  if (fout->remoteVersion >= 90500)
5317  appendPQExpBuffer(query,
5318  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5319  "\n WHERE pg_transform.oid > '%u'::oid"
5320  "\n AND (p.oid = pg_transform.trffromsql"
5321  "\n OR p.oid = pg_transform.trftosql))",
5323 
5324  if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
5325  appendPQExpBufferStr(query,
5326  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5327  "classid = 'pg_proc'::regclass AND "
5328  "objid = p.oid AND "
5329  "refclassid = 'pg_extension'::regclass AND "
5330  "deptype = 'e')");
5331  appendPQExpBufferChar(query, ')');
5332  }
5333 
5334  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5335 
5336  ntups = PQntuples(res);
5337 
5338  *numFuncs = ntups;
5339 
5340  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
5341 
5342  i_tableoid = PQfnumber(res, "tableoid");
5343  i_oid = PQfnumber(res, "oid");
5344  i_proname = PQfnumber(res, "proname");
5345  i_pronamespace = PQfnumber(res, "pronamespace");
5346  i_rolname = PQfnumber(res, "rolname");
5347  i_prolang = PQfnumber(res, "prolang");
5348  i_pronargs = PQfnumber(res, "pronargs");
5349  i_proargtypes = PQfnumber(res, "proargtypes");
5350  i_prorettype = PQfnumber(res, "prorettype");
5351  i_proacl = PQfnumber(res, "proacl");
5352  i_rproacl = PQfnumber(res, "rproacl");
5353  i_initproacl = PQfnumber(res, "initproacl");
5354  i_initrproacl = PQfnumber(res, "initrproacl");
5355 
5356  for (i = 0; i < ntups; i++)
5357  {
5358  finfo[i].dobj.objType = DO_FUNC;
5359  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5360  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5361  AssignDumpId(&finfo[i].dobj);
5362  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
5363  finfo[i].dobj.namespace =
5364  findNamespace(fout,
5365  atooid(PQgetvalue(res, i, i_pronamespace)));
5366  finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5367  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
5368  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
5369  finfo[i].proacl = pg_strdup(PQgetvalue(res, i, i_proacl));
5370  finfo[i].rproacl = pg_strdup(PQgetvalue(res, i, i_rproacl));
5371  finfo[i].initproacl = pg_strdup(PQgetvalue(res, i, i_initproacl));
5372  finfo[i].initrproacl = pg_strdup(PQgetvalue(res, i, i_initrproacl));
5373  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
5374  if (finfo[i].nargs == 0)
5375  finfo[i].argtypes = NULL;
5376  else
5377  {
5378  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
5379  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5380  finfo[i].argtypes, finfo[i].nargs);
5381  }
5382 
5383  /* Decide whether we want to dump it */
5384  selectDumpableObject(&(finfo[i].dobj), fout);
5385 
5386  /* Do not try to dump ACL if no ACL exists. */
5387  if (PQgetisnull(res, i, i_proacl) && PQgetisnull(res, i, i_rproacl) &&
5388  PQgetisnull(res, i, i_initproacl) &&
5389  PQgetisnull(res, i, i_initrproacl))
5390  finfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
5391 
5392  if (strlen(finfo[i].rolname) == 0)
5393  write_msg(NULL,
5394  "WARNING: owner of function \"%s\" appears to be invalid\n",
5395  finfo[i].dobj.name);
5396  }
5397 
5398  PQclear(res);
5399 
5400  destroyPQExpBuffer(query);
5401 
5402  return finfo;
5403 }
Oid * argtypes
Definition: pg_dump.h:202
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1656
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int nargs
Definition: pg_dump.h:201
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
static NamespaceInfo * findNamespace(Archive *fout, Oid nsoid)
Definition: pg_dump.c:4142
static int numFuncs
Definition: common.c:59
char * initrproacl
Definition: pg_dump.h:207
Oid lang
Definition: pg_dump.h:200
DumpableObject dobj
Definition: pg_dump.h:198
unsigned int Oid
Definition: postgres_ext.h:31
static Oid g_last_builtin_oid
Definition: pg_dump.c:102
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:134
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
DumpOptions * dopt
Definition: pg_backup.h:179
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
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
static const char * username_subquery
Definition: pg_dump.c:96
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1038
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
void PQclear(PGresult *res)
Definition: fe-exec.c:650
void write_msg(const char *modulename, const char *fmt,...)
Oid prorettype
Definition: pg_dump.h:203
#define NULL
Definition: c.h:229
char * initproacl
Definition: pg_dump.h:206
char * rolname
Definition: pg_dump.h:199
char * proacl
Definition: pg_dump.h:204
char * rproacl
Definition: pg_dump.h:205
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:184
void getIndexes ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

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

6312 {
6313  int i,
6314  j;
6315  PQExpBuffer query = createPQExpBuffer();
6316  PGresult *res;
6317  IndxInfo *indxinfo;
6318  ConstraintInfo *constrinfo;
6319  int i_tableoid,
6320  i_oid,
6321  i_indexname,
6322  i_indexdef,
6323  i_indnkeys,
6324  i_indkey,
6325  i_indisclustered,
6326  i_indisreplident,
6327  i_contype,
6328  i_conname,
6329  i_condeferrable,
6330  i_condeferred,
6331  i_contableoid,
6332  i_conoid,
6333  i_condef,
6334  i_tablespace,
6335  i_indreloptions,
6336  i_relpages;
6337  int ntups;
6338 
6339  for (i = 0; i < numTables; i++)
6340  {
6341  TableInfo *tbinfo = &tblinfo[i];
6342 
6343  /* Only plain tables and materialized views have indexes. */
6344  if (tbinfo->relkind != RELKIND_RELATION &&
6345  tbinfo->relkind != RELKIND_MATVIEW)
6346  continue;
6347  if (!tbinfo->hasindex)
6348  continue;
6349 
6350  /* Ignore indexes of tables whose definitions are not to be dumped */
6351  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
6352  continue;
6353 
6354  if (g_verbose)
6355  write_msg(NULL, "reading indexes for table \"%s.%s\"\n",
6356  tbinfo->dobj.namespace->dobj.name,
6357  tbinfo->dobj.name);
6358 
6359  /* Make sure we are in proper schema so indexdef is right */
6360  selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
6361 
6362  /*
6363  * The point of the messy-looking outer join is to find a constraint
6364  * that is related by an internal dependency link to the index. If we
6365  * find one, create a CONSTRAINT entry linked to the INDEX entry. We
6366  * assume an index won't have more than one internal dependency.
6367  *
6368  * As of 9.0 we don't need to look at pg_depend but can check for a
6369  * match to pg_constraint.conindid. The check on conrelid is
6370  * redundant but useful because that column is indexed while conindid
6371  * is not.
6372  */
6373  resetPQExpBuffer(query);
6374  if (fout->remoteVersion >= 90400)
6375  {
6376  /*
6377  * the test on indisready is necessary in 9.2, and harmless in
6378  * earlier/later versions
6379  */
6380  appendPQExpBuffer(query,
6381  "SELECT t.tableoid, t.oid, "
6382  "t.relname AS indexname, "
6383  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6384  "t.relnatts AS indnkeys, "
6385  "i.indkey, i.indisclustered, "
6386  "i.indisreplident, t.relpages, "
6387  "c.contype, c.conname, "
6388  "c.condeferrable, c.condeferred, "
6389  "c.tableoid AS contableoid, "
6390  "c.oid AS conoid, "
6391  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6392  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6393  "t.reloptions AS indreloptions "
6394  "FROM pg_catalog.pg_index i "
6395  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6396  "LEFT JOIN pg_catalog.pg_constraint c "
6397  "ON (i.indrelid = c.conrelid AND "
6398  "i.indexrelid = c.conindid AND "
6399  "c.contype IN ('p','u','x')) "
6400  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6401  "AND i.indisvalid AND i.indisready "
6402  "ORDER BY indexname",
6403  tbinfo->dobj.catId.oid);
6404  }
6405  else if (fout->remoteVersion >= 90000)
6406  {
6407  /*
6408  * the test on indisready is necessary in 9.2, and harmless in
6409  * earlier/later versions
6410  */
6411  appendPQExpBuffer(query,
6412  "SELECT t.tableoid, t.oid, "
6413  "t.relname AS indexname, "
6414  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6415  "t.relnatts AS indnkeys, "
6416  "i.indkey, i.indisclustered, "
6417  "false AS indisreplident, t.relpages, "
6418  "c.contype, c.conname, "
6419  "c.condeferrable, c.condeferred, "
6420  "c.tableoid AS contableoid, "
6421  "c.oid AS conoid, "
6422  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6423  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6424  "t.reloptions AS indreloptions "
6425  "FROM pg_catalog.pg_index i "
6426  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6427  "LEFT JOIN pg_catalog.pg_constraint c "
6428  "ON (i.indrelid = c.conrelid AND "
6429  "i.indexrelid = c.conindid AND "
6430  "c.contype IN ('p','u','x')) "
6431  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6432  "AND i.indisvalid AND i.indisready "
6433  "ORDER BY indexname",
6434  tbinfo->dobj.catId.oid);
6435  }
6436  else if (fout->remoteVersion >= 80200)
6437  {
6438  appendPQExpBuffer(query,
6439  "SELECT t.tableoid, t.oid, "
6440  "t.relname AS indexname, "
6441  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6442  "t.relnatts AS indnkeys, "
6443  "i.indkey, i.indisclustered, "
6444  "false AS indisreplident, t.relpages, "
6445  "c.contype, c.conname, "
6446  "c.condeferrable, c.condeferred, "
6447  "c.tableoid AS contableoid, "
6448  "c.oid AS conoid, "
6449  "null AS condef, "
6450  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6451  "t.reloptions AS indreloptions "
6452  "FROM pg_catalog.pg_index i "
6453  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6454  "LEFT JOIN pg_catalog.pg_depend d "
6455  "ON (d.classid = t.tableoid "
6456  "AND d.objid = t.oid "
6457  "AND d.deptype = 'i') "
6458  "LEFT JOIN pg_catalog.pg_constraint c "
6459  "ON (d.refclassid = c.tableoid "
6460  "AND d.refobjid = c.oid) "
6461  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6462  "AND i.indisvalid "
6463  "ORDER BY indexname",
6464  tbinfo->dobj.catId.oid);
6465  }
6466  else
6467  {
6468  appendPQExpBuffer(query,
6469  "SELECT t.tableoid, t.oid, "
6470  "t.relname AS indexname, "
6471  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6472  "t.relnatts AS indnkeys, "
6473  "i.indkey, i.indisclustered, "
6474  "false AS indisreplident, t.relpages, "
6475  "c.contype, c.conname, "
6476  "c.condeferrable, c.condeferred, "
6477  "c.tableoid AS contableoid, "
6478  "c.oid AS conoid, "
6479  "null AS condef, "
6480  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6481  "null AS indreloptions "
6482  "FROM pg_catalog.pg_index i "
6483  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6484  "LEFT JOIN pg_catalog.pg_depend d "
6485  "ON (d.classid = t.tableoid "
6486  "AND d.objid = t.oid "
6487  "AND d.deptype = 'i') "
6488  "LEFT JOIN pg_catalog.pg_constraint c "
6489  "ON (d.refclassid = c.tableoid "
6490  "AND d.refobjid = c.oid) "
6491  "WHERE i.indrelid = '%u'::pg_catalog.oid "
6492  "ORDER BY indexname",
6493  tbinfo->dobj.catId.oid);
6494  }
6495 
6496  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6497 
6498  ntups = PQntuples(res);
6499 
6500  i_tableoid = PQfnumber(res, "tableoid");
6501  i_oid = PQfnumber(res, "oid");
6502  i_indexname = PQfnumber(res, "indexname");
6503  i_indexdef = PQfnumber(res, "indexdef");
6504  i_indnkeys = PQfnumber(res, "indnkeys");
6505  i_indkey = PQfnumber(res, "indkey");
6506  i_indisclustered = PQfnumber(res, "indisclustered");
6507  i_indisreplident = PQfnumber(res, "indisreplident");
6508  i_relpages = PQfnumber(res, "relpages");
6509  i_contype = PQfnumber(res, "contype");
6510  i_conname = PQfnumber(res, "conname");
6511  i_condeferrable = PQfnumber(res, "condeferrable");
6512  i_condeferred = PQfnumber(res, "condeferred");
6513  i_contableoid = PQfnumber(res, "contableoid");
6514  i_conoid = PQfnumber(res, "conoid");
6515  i_condef = PQfnumber(res, "condef");
6516  i_tablespace = PQfnumber(res, "tablespace");
6517  i_indreloptions = PQfnumber(res, "indreloptions");
6518 
6519  indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
6520  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
6521 
6522  for (j = 0; j < ntups; j++)
6523  {
6524  char contype;
6525 
6526  indxinfo[j].dobj.objType = DO_INDEX;
6527  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
6528  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
6529  AssignDumpId(&indxinfo[j].dobj);
6530  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
6531  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6532  indxinfo[j].indextable = tbinfo;
6533  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
6534  indxinfo[j].indnkeys = atoi(PQgetvalue(res, j, i_indnkeys));
6535  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
6536  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
6537  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnkeys * sizeof(Oid));
6538  parseOidArray(PQgetvalue(res, j, i_indkey),
6539  indxinfo[j].indkeys, indxinfo[j].indnkeys);
6540  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
6541  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
6542  indxinfo[j].relpages = atoi(PQgetvalue(res, j, i_relpages));
6543  contype = *(PQgetvalue(res, j, i_contype));
6544 
6545  if (contype == 'p' || contype == 'u' || contype == 'x')
6546  {
6547  /*
6548  * If we found a constraint matching the index, create an
6549  * entry for it.
6550  */
6551  constrinfo[j].dobj.objType = DO_CONSTRAINT;
6552  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
6553  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
6554  AssignDumpId(&constrinfo[j].dobj);
6555  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
6556  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6557  constrinfo[j].contable = tbinfo;
6558  constrinfo[j].condomain = NULL;
6559  constrinfo[j].contype = contype;
6560  if (contype == 'x')
6561  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
6562  else
6563  constrinfo[j].condef = NULL;
6564  constrinfo[j].confrelid = InvalidOid;
6565  constrinfo[j].conindex = indxinfo[j].dobj.dumpId;
6566  constrinfo[j].condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
6567  constrinfo[j].condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
6568  constrinfo[j].conislocal = true;
6569  constrinfo[j].separate = true;
6570 
6571  indxinfo[j].indexconstraint = constrinfo[j].dobj.dumpId;
6572  }
6573  else
6574  {
6575  /* Plain secondary index */
6576  indxinfo[j].indexconstraint = 0;
6577  }
6578  }
6579 
6580  PQclear(res);
6581  }
6582 
6583  destroyPQExpBuffer(query);
6584 }
char * tablespace
Definition: pg_dump.h:355
char * name
Definition: pg_dump.h:133
char relkind
Definition: pg_dump.h:267
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
int relpages
Definition: pg_dump.h:363
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
#define RELKIND_MATVIEW
Definition: pg_class.h:165
bool hasindex
Definition: pg_dump.h:275
DumpId dumpId
Definition: pg_dump.h:132
static int numTables
Definition: common.c:57
unsigned int Oid
Definition: postgres_ext.h:31
DumpId conindex
Definition: pg_dump.h:429
DumpId indexconstraint
Definition: pg_dump.h:362
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
char * indexdef
Definition: pg_dump.h:354
DumpableObject dobj
Definition: pg_dump.h:261
char * condef
Definition: pg_dump.h:427
bool indisreplident
Definition: pg_dump.h:360
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:423
TableInfo * indextable
Definition: pg_dump.h:353
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
Oid * indkeys
Definition: pg_dump.h:358
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
bool condeferrable
Definition: pg_dump.h:430
int indnkeys
Definition: pg_dump.h:357
char * indreloptions
Definition: pg_dump.h:356
TypeInfo * condomain
Definition: pg_dump.h:425
bool conislocal
Definition: pg_dump.h:432
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1038
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:424
#define InvalidOid
Definition: postgres_ext.h:36
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
void write_msg(const char *modulename, const char *fmt,...)
bool condeferred
Definition: pg_dump.h:431
#define NULL
Definition: c.h:229
CatalogId catId
Definition: pg_dump.h:131
DumpableObject dobj
Definition: pg_dump.h:352
int i
bool indisclustered
Definition: pg_dump.h:359
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
#define RELKIND_RELATION
Definition: pg_class.h:160
DumpableObjectType objType
Definition: pg_dump.h:130
bool g_verbose
Definition: pg_dump.c:90
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:184
InhInfo* getInherits ( Archive fout,
int *  numInherits 
)

Definition at line 6187 of file pg_dump.c.

References appendPQExpBufferStr(), atooid, CppAsString2, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), ExecuteSqlQuery(), i, _inhInfo::inhparent, _inhInfo::inhrelid, pg_malloc(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), RELKIND_PARTITIONED_TABLE, and selectSourceSchema().

Referenced by getSchemaData().

6188 {
6189  PGresult *res;
6190  int ntups;
6191  int i;
6192  PQExpBuffer query = createPQExpBuffer();
6193  InhInfo *inhinfo;
6194 
6195  int i_inhrelid;
6196  int i_inhparent;
6197 
6198  /* Make sure we are in proper schema */
6199  selectSourceSchema(fout, "pg_catalog");
6200 
6201  /*
6202  * Find all the inheritance information, excluding implicit inheritance
6203  * via partitioning. We handle that case using getPartitions(), because
6204  * we want more information about partitions than just the parent-child
6205  * relationship.
6206  */
6207  appendPQExpBufferStr(query,
6208  "SELECT inhrelid, inhparent "
6209  "FROM pg_inherits "
6210  "WHERE inhparent NOT IN (SELECT oid FROM pg_class "
6211  "WHERE relkind = " CppAsString2(RELKIND_PARTITIONED_TABLE) ")");
6212 
6213  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6214 
6215  ntups = PQntuples(res);
6216 
6217  *numInherits = ntups;
6218 
6219  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6220 
6221  i_inhrelid = PQfnumber(res, "inhrelid");
6222  i_inhparent = PQfnumber(res, "inhparent");
6223 
6224  for (i = 0; i < ntups; i++)
6225  {
6226  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6227  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6228  }
6229 
6230  PQclear(res);
6231 
6232  destroyPQExpBuffer(query);
6233 
6234  return inhinfo;
6235 }
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:472
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
#define CppAsString2(x)
Definition: c.h:162
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
Oid inhparent
Definition: pg_dump.h:473
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
DumpId getMaxDumpId ( void  )

Definition at line 566 of file common.c.

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

567 {
568  return lastDumpId;
569 }
static DumpId lastDumpId
Definition: common.c:33
NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

Definition at line 3993 of file pg_dump.c.

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

Referenced by getSchemaData().

3994 {
3995  DumpOptions *dopt = fout->dopt;
3996  PGresult *res;
3997  int ntups;
3998  int i;
3999  PQExpBuffer query;
4000  NamespaceInfo *nsinfo;
4001  int i_tableoid;
4002  int i_oid;
4003  int i_nspname;
4004  int i_rolname;
4005  int i_nspacl;
4006  int i_rnspacl;
4007  int i_initnspacl;
4008  int i_initrnspacl;
4009 
4010  query = createPQExpBuffer();
4011 
4012  /* Make sure we are in proper schema */
4013  selectSourceSchema(fout, "pg_catalog");
4014 
4015  /*
4016  * we fetch all namespaces including system ones, so that every object we
4017  * read in can be linked to a containing namespace.
4018  */
4019  if (fout->remoteVersion >= 90600)
4020  {
4021  PQExpBuffer acl_subquery = createPQExpBuffer();
4022  PQExpBuffer racl_subquery = createPQExpBuffer();
4023  PQExpBuffer init_acl_subquery = createPQExpBuffer();
4024  PQExpBuffer init_racl_subquery = createPQExpBuffer();
4025 
4026  buildACLQueries(acl_subquery, racl_subquery, init_acl_subquery,
4027  init_racl_subquery, "n.nspacl", "n.nspowner", "'n'",
4028  dopt->binary_upgrade);
4029 
4030  appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, "
4031  "(%s nspowner) AS rolname, "
4032  "%s as nspacl, "
4033  "%s as rnspacl, "
4034  "%s as initnspacl, "
4035  "%s as initrnspacl "
4036  "FROM pg_namespace n "
4037  "LEFT JOIN pg_init_privs pip "
4038  "ON (n.oid = pip.objoid "
4039  "AND pip.classoid = 'pg_namespace'::regclass "
4040  "AND pip.objsubid = 0",
4042  acl_subquery->data,
4043  racl_subquery->data,
4044  init_acl_subquery->data,
4045  init_racl_subquery->data);
4046 
4047  /*
4048  * When we are doing a 'clean' run, we will be dropping and recreating
4049  * the 'public' schema (the only object which has that kind of
4050  * treatment in the backend and which has an entry in pg_init_privs)
4051  * and therefore we should not consider any initial privileges in
4052  * pg_init_privs in that case.
4053  *
4054  * See pg_backup_archiver.c:_printTocEntry() for the details on why
4055  * the public schema is special in this regard.
4056  *
4057  * Note that if the public schema is dropped and re-created, this is
4058  * essentially a no-op because the new public schema won't have an
4059  * entry in pg_init_privs anyway, as the entry will be removed when
4060  * the public schema is dropped.
4061  */
4062  if (dopt->outputClean)
4063  appendPQExpBuffer(query," AND pip.objoid <> 'public'::regnamespace");
4064 
4065  appendPQExpBuffer(query,") ");
4066 
4067  destroyPQExpBuffer(acl_subquery);
4068  destroyPQExpBuffer(racl_subquery);
4069  destroyPQExpBuffer(init_acl_subquery);
4070  destroyPQExpBuffer(init_racl_subquery);
4071  }
4072  else
4073  appendPQExpBuffer(query, "SELECT tableoid, oid, nspname, "
4074  "(%s nspowner) AS rolname, "
4075  "nspacl, NULL as rnspacl, "
4076  "NULL AS initnspacl, NULL as initrnspacl "
4077  "FROM pg_namespace",
4079 
4080  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4081 
4082  ntups = PQntuples(res);
4083 
4084  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
4085 
4086  i_tableoid = PQfnumber(res, "tableoid");
4087  i_oid = PQfnumber(res, "oid");
4088  i_nspname = PQfnumber(res, "nspname");
4089  i_rolname = PQfnumber(res, "rolname");
4090  i_nspacl = PQfnumber(res, "nspacl");
4091  i_rnspacl = PQfnumber(res, "rnspacl");
4092  i_initnspacl = PQfnumber(res, "initnspacl");
4093  i_initrnspacl = PQfnumber(res, "initrnspacl");
4094 
4095  for (i = 0; i < ntups; i++)
4096  {
4097  nsinfo[i].dobj.objType = DO_NAMESPACE;
4098  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4099  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4100  AssignDumpId(&nsinfo[i].dobj);
4101  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
4102  nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4103  nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl));
4104  nsinfo[i].rnspacl = pg_strdup(PQgetvalue(res, i, i_rnspacl));
4105  nsinfo[i].initnspacl = pg_strdup(PQgetvalue(res, i, i_initnspacl));
4106  nsinfo[i].initrnspacl = pg_strdup(PQgetvalue(res, i, i_initrnspacl));
4107 
4108  /* Decide whether to dump this namespace */
4109  selectDumpableNamespace(&nsinfo[i], fout);
4110 
4111  /*
4112  * Do not try to dump ACL if the ACL is empty or the default.
4113  *
4114  * This is useful because, for some schemas/objects, the only
4115  * component we are going to try and dump is the ACL and if we can
4116  * remove that then 'dump' goes to zero/false and we don't consider
4117  * this object for dumping at all later on.
4118  */
4119  if (PQgetisnull(res, i, i_nspacl) && PQgetisnull(res, i, i_rnspacl) &&
4120  PQgetisnull(res, i, i_initnspacl) &&
4121  PQgetisnull(res, i, i_initrnspacl))
4122  nsinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4123 
4124  if (strlen(nsinfo[i].rolname) == 0)
4125  write_msg(NULL, "WARNING: owner of schema \"%s\" appears to be invalid\n",
4126  nsinfo[i].dobj.name);
4127  }
4128 
4129  PQclear(res);
4130  destroyPQExpBuffer(query);
4131 
4132  *numNamespaces = ntups;
4133 
4134  return nsinfo;
4135 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
char * rnspacl
Definition: pg_dump.h:148
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:134
DumpOptions * dopt
Definition: pg_backup.h:179
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:146
char * initnspacl
Definition: pg_dump.h:149
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static int numNamespaces
Definition: common.c:62
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
static const char * username_subquery
Definition: pg_dump.c:96
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1370
void PQclear(PGresult *res)
Definition: fe-exec.c:650
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
int outputClean
Definition: pg_backup.h:163
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
char * initrnspacl
Definition: pg_dump.h:150
CatalogId catId
Definition: pg_dump.h:131
int i
char * nspacl
Definition: pg_dump.h:147
DumpableObject dobj
Definition: pg_dump.h:145
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:184
OpclassInfo* getOpclasses ( Archive fout,
int *  numOpclasses 
)

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

4823 {
4824  PGresult *res;
4825  int ntups;
4826  int i;
4827  PQExpBuffer query = createPQExpBuffer();
4828  OpclassInfo *opcinfo;
4829  int i_tableoid;
4830  int i_oid;
4831  int i_opcname;
4832  int i_opcnamespace;
4833  int i_rolname;
4834 
4835  /*
4836  * find all opclasses, including builtin opclasses; we filter out
4837  * system-defined opclasses at dump-out time.
4838  */
4839 
4840  /* Make sure we are in proper schema */
4841  selectSourceSchema(fout, "pg_catalog");
4842 
4843  appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
4844  "opcnamespace, "
4845  "(%s opcowner) AS rolname "
4846  "FROM pg_opclass",
4848 
4849  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4850 
4851  ntups = PQntuples(res);
4852  *numOpclasses = ntups;
4853 
4854  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
4855 
4856  i_tableoid = PQfnumber(res, "tableoid");
4857  i_oid = PQfnumber(res, "oid");
4858  i_opcname = PQfnumber(res, "opcname");
4859  i_opcnamespace = PQfnumber(res, "opcnamespace");
4860  i_rolname = PQfnumber(res, "rolname");
4861 
4862  for (i = 0; i < ntups; i++)
4863  {
4864  opcinfo[i].dobj.objType = DO_OPCLASS;
4865  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4866  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4867  AssignDumpId(&opcinfo[i].dobj);
4868  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
4869  opcinfo[i].dobj.namespace =
4870  findNamespace(fout,
4871  atooid(PQgetvalue(res, i, i_opcnamespace)));
4872  opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4873 
4874  /* Decide whether we want to dump it */
4875  selectDumpableObject(&(opcinfo[i].dobj), fout);
4876 
4877  /* Op Classes do not currently have ACLs. */
4878  opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4879 
4880  if (strlen(opcinfo[i].rolname) == 0)
4881  write_msg(NULL, "WARNING: owner of operator class \"%s\" appears to be invalid\n",
4882  opcinfo[i].dobj.name);
4883  }
4884 
4885  PQclear(res);
4886 
4887  destroyPQExpBuffer(query);
4888 
4889  return opcinfo;
4890 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1656
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
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:4142
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
char * rolname
Definition: pg_dump.h:235
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
static const char * username_subquery
Definition: pg_dump.c:96
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
DumpableObject dobj
Definition: pg_dump.h:234
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
OprInfo* getOperators ( Archive fout,
int *  numOperators 
)

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

4501 {
4502  PGresult *res;
4503  int ntups;
4504  int i;
4505  PQExpBuffer query = createPQExpBuffer();
4506  OprInfo *oprinfo;
4507  int i_tableoid;
4508  int i_oid;
4509  int i_oprname;
4510  int i_oprnamespace;
4511  int i_rolname;
4512  int i_oprkind;
4513  int i_oprcode;
4514 
4515  /*
4516  * find all operators, including builtin operators; we filter out
4517  * system-defined operators at dump-out time.
4518  */
4519 
4520  /* Make sure we are in proper schema */
4521  selectSourceSchema(fout, "pg_catalog");
4522 
4523  appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
4524  "oprnamespace, "
4525  "(%s oprowner) AS rolname, "
4526  "oprkind, "
4527  "oprcode::oid AS oprcode "
4528  "FROM pg_operator",
4530 
4531  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4532 
4533  ntups = PQntuples(res);
4534  *numOprs = ntups;
4535 
4536  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
4537 
4538  i_tableoid = PQfnumber(res, "tableoid");
4539  i_oid = PQfnumber(res, "oid");
4540  i_oprname = PQfnumber(res, "oprname");
4541  i_oprnamespace = PQfnumber(res, "oprnamespace");
4542  i_rolname = PQfnumber(res, "rolname");
4543  i_oprkind = PQfnumber(res, "oprkind");
4544  i_oprcode = PQfnumber(res, "oprcode");
4545 
4546  for (i = 0; i < ntups; i++)
4547  {
4548  oprinfo[i].dobj.objType = DO_OPERATOR;
4549  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
4550  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4551  AssignDumpId(&oprinfo[i].dobj);
4552  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
4553  oprinfo[i].dobj.namespace =
4554  findNamespace(fout,
4555  atooid(PQgetvalue(res, i, i_oprnamespace)));
4556  oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
4557  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
4558  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
4559 
4560  /* Decide whether we want to dump it */
4561  selectDumpableObject(&(oprinfo[i].dobj), fout);
4562 
4563  /* Operators do not currently have ACLs. */
4564  oprinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
4565 
4566  if (strlen(oprinfo[i].rolname) == 0)
4567  write_msg(NULL, "WARNING: owner of operator \"%s\" appears to be invalid\n",
4568  oprinfo[i].dobj.name);
4569  }
4570 
4571  PQclear(res);
4572 
4573  destroyPQExpBuffer(query);
4574 
4575  return oprinfo;
4576 }
char * name
Definition: pg_dump.h:133
DumpableObject dobj
Definition: pg_dump.h:219
DumpComponents dump
Definition: pg_dump.h:134
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1656
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
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:4142
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17590
static const char * username_subquery
Definition: pg_dump.c:96
char * rolname
Definition: pg_dump.h:220
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char oprkind
Definition: pg_dump.h:221
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
Oid oprcode
Definition: pg_dump.h:222
OpfamilyInfo* getOpfamilies ( Archive fout,
int *  numOpfamilies 
)

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

4901 {
4902  PGresult *res;
4903  int ntups;
4904  int i;
4905  PQExpBuffer query;
4906  OpfamilyInfo *opfinfo;
4907  int i_tableoid;
4908  int i_oid;
4909  int i_opfname;
4910  int i_opfnamespace;
4911  int i_rolname;
4912 
4913  /* Before 8.3, there is no separate concept of opfamilies */
4914  if (fout->