PostgreSQL Source Code  git master
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  _dumpableAcl
 
struct  _dumpableObjectWithAcl
 
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  _tableAttachInfo
 
struct  _attrDefInfo
 
struct  _tableDataInfo
 
struct  _indxInfo
 
struct  _indexAttachInfo
 
struct  _statsExtInfo
 
struct  _ruleInfo
 
struct  _triggerInfo
 
struct  _evttriggerInfo
 
struct  _constraintInfo
 
struct  _procLangInfo
 
struct  _castInfo
 
struct  _transformInfo
 
struct  _inhInfo
 
struct  _prsInfo
 
struct  _dictInfo
 
struct  _tmplInfo
 
struct  _cfgInfo
 
struct  _fdwInfo
 
struct  _foreignServerInfo
 
struct  _defaultACLInfo
 
struct  _loInfo
 
struct  _policyInfo
 
struct  _PublicationInfo
 
struct  _PublicationRelInfo
 
struct  _PublicationSchemaInfo
 
struct  _SubscriptionInfo
 

Macros

#define oidcmp(x, y)   ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 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 _dumpableAcl DumpableAcl
 
typedef struct _dumpableObjectWithAcl DumpableObjectWithAcl
 
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 _tableAttachInfo TableAttachInfo
 
typedef struct _attrDefInfo AttrDefInfo
 
typedef struct _tableDataInfo TableDataInfo
 
typedef struct _indxInfo IndxInfo
 
typedef struct _indexAttachInfo IndexAttachInfo
 
typedef struct _statsExtInfo StatsExtInfo
 
typedef struct _ruleInfo RuleInfo
 
typedef struct _triggerInfo TriggerInfo
 
typedef struct _evttriggerInfo EventTriggerInfo
 
typedef struct _constraintInfo ConstraintInfo
 
typedef struct _procLangInfo ProcLangInfo
 
typedef struct _castInfo CastInfo
 
typedef struct _transformInfo TransformInfo
 
typedef struct _inhInfo InhInfo
 
typedef struct _prsInfo TSParserInfo
 
typedef struct _dictInfo TSDictInfo
 
typedef struct _tmplInfo TSTemplateInfo
 
typedef struct _cfgInfo TSConfigInfo
 
typedef struct _fdwInfo FdwInfo
 
typedef struct _foreignServerInfo ForeignServerInfo
 
typedef struct _defaultACLInfo DefaultACLInfo
 
typedef struct _loInfo LoInfo
 
typedef struct _policyInfo PolicyInfo
 
typedef struct _PublicationInfo PublicationInfo
 
typedef struct _PublicationRelInfo PublicationRelInfo
 
typedef struct _PublicationSchemaInfo PublicationSchemaInfo
 
typedef struct _SubscriptionInfo SubscriptionInfo
 

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_TABLE_ATTACH , DO_ATTRDEF , DO_INDEX ,
  DO_INDEX_ATTACH , 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_LARGE_OBJECT ,
  DO_LARGE_OBJECT_DATA , DO_PRE_DATA_BOUNDARY , DO_POST_DATA_BOUNDARY , DO_EVENT_TRIGGER ,
  DO_REFRESH_MATVIEW , DO_POLICY , DO_PUBLICATION , DO_PUBLICATION_REL ,
  DO_PUBLICATION_TABLE_IN_SCHEMA , 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)
 
PublicationInfofindPublicationByOid (Oid oid)
 
void recordExtensionMembership (CatalogId catId, ExtensionInfo *ext)
 
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)
 
NamespaceInfogetNamespaces (Archive *fout, int *numNamespaces)
 
ExtensionInfogetExtensions (Archive *fout, int *numExtensions)
 
TypeInfogetTypes (Archive *fout, int *numTypes)
 
FuncInfogetFuncs (Archive *fout, int *numFuncs)
 
AggInfogetAggregates (Archive *fout, int *numAggs)
 
OprInfogetOperators (Archive *fout, int *numOprs)
 
AccessMethodInfogetAccessMethods (Archive *fout, int *numAccessMethods)
 
OpclassInfogetOpclasses (Archive *fout, int *numOpclasses)
 
OpfamilyInfogetOpfamilies (Archive *fout, int *numOpfamilies)
 
CollInfogetCollations (Archive *fout, int *numCollations)
 
ConvInfogetConversions (Archive *fout, int *numConversions)
 
TableInfogetTables (Archive *fout, int *numTables)
 
void getOwnedSeqs (Archive *fout, TableInfo tblinfo[], int numTables)
 
InhInfogetInherits (Archive *fout, int *numInherits)
 
void getPartitioningInfo (Archive *fout)
 
void getIndexes (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getExtendedStatistics (Archive *fout)
 
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 *tblinfo, int numTables)
 
bool shouldPrintColumn (const DumpOptions *dopt, const 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)
 
PublicationInfogetPublications (Archive *fout, int *numPublications)
 
void getPublicationNamespaces (Archive *fout)
 
void getPublicationTables (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getSubscriptions (Archive *fout)
 

Macro Definition Documentation

◆ DUMP_COMPONENT_ACL

#define DUMP_COMPONENT_ACL   (1 << 4)

Definition at line 100 of file pg_dump.h.

◆ DUMP_COMPONENT_ALL

#define DUMP_COMPONENT_ALL   (0xFFFF)

Definition at line 103 of file pg_dump.h.

◆ DUMP_COMPONENT_COMMENT

#define DUMP_COMPONENT_COMMENT   (1 << 2)

Definition at line 98 of file pg_dump.h.

◆ DUMP_COMPONENT_DATA

#define DUMP_COMPONENT_DATA   (1 << 1)

Definition at line 97 of file pg_dump.h.

◆ DUMP_COMPONENT_DEFINITION

#define DUMP_COMPONENT_DEFINITION   (1 << 0)

Definition at line 96 of file pg_dump.h.

◆ DUMP_COMPONENT_NONE

#define DUMP_COMPONENT_NONE   (0)

Definition at line 95 of file pg_dump.h.

◆ DUMP_COMPONENT_POLICY

#define DUMP_COMPONENT_POLICY   (1 << 5)

Definition at line 101 of file pg_dump.h.

◆ DUMP_COMPONENT_SECLABEL

#define DUMP_COMPONENT_SECLABEL   (1 << 3)

Definition at line 99 of file pg_dump.h.

◆ DUMP_COMPONENT_USERMAP

#define DUMP_COMPONENT_USERMAP   (1 << 6)

Definition at line 102 of file pg_dump.h.

◆ DUMP_COMPONENTS_REQUIRING_LOCK

#define DUMP_COMPONENTS_REQUIRING_LOCK
Value:
(\
DUMP_COMPONENT_DEFINITION |\
DUMP_COMPONENT_DATA |\
DUMP_COMPONENT_POLICY)

Definition at line 127 of file pg_dump.h.

◆ oidcmp

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

Definition at line 20 of file pg_dump.h.

Typedef Documentation

◆ AccessMethodInfo

◆ AggInfo

typedef struct _aggInfo AggInfo

◆ AttrDefInfo

typedef struct _attrDefInfo AttrDefInfo

◆ CastInfo

typedef struct _castInfo CastInfo

◆ CollInfo

typedef struct _collInfo CollInfo

◆ ConstraintInfo

◆ ConvInfo

typedef struct _convInfo ConvInfo

◆ DefaultACLInfo

◆ DumpableAcl

typedef struct _dumpableAcl DumpableAcl

◆ DumpableObject

◆ DumpableObjectWithAcl

◆ DumpComponents

Definition at line 94 of file pg_dump.h.

◆ EventTriggerInfo

◆ ExtensionInfo

typedef struct _extensionInfo ExtensionInfo

◆ FdwInfo

typedef struct _fdwInfo FdwInfo

◆ ForeignServerInfo

◆ FuncInfo

typedef struct _funcInfo FuncInfo

◆ IndexAttachInfo

◆ IndxInfo

typedef struct _indxInfo IndxInfo

◆ InhInfo

typedef struct _inhInfo InhInfo

◆ LoInfo

typedef struct _loInfo LoInfo

◆ NamespaceInfo

typedef struct _namespaceInfo NamespaceInfo

◆ OpclassInfo

typedef struct _opclassInfo OpclassInfo

◆ OpfamilyInfo

typedef struct _opfamilyInfo OpfamilyInfo

◆ OprInfo

typedef struct _oprInfo OprInfo

◆ PolicyInfo

typedef struct _policyInfo PolicyInfo

◆ ProcLangInfo

typedef struct _procLangInfo ProcLangInfo

◆ PublicationInfo

◆ PublicationRelInfo

◆ PublicationSchemaInfo

◆ RuleInfo

typedef struct _ruleInfo RuleInfo

◆ ShellTypeInfo

typedef struct _shellTypeInfo ShellTypeInfo

◆ StatsExtInfo

typedef struct _statsExtInfo StatsExtInfo

◆ SubscriptionInfo

◆ TableAttachInfo

◆ TableDataInfo

typedef struct _tableDataInfo TableDataInfo

◆ TableInfo

typedef struct _tableInfo TableInfo

◆ TransformInfo

typedef struct _transformInfo TransformInfo

◆ TriggerInfo

typedef struct _triggerInfo TriggerInfo

◆ TSConfigInfo

typedef struct _cfgInfo TSConfigInfo

◆ TSDictInfo

typedef struct _dictInfo TSDictInfo

◆ TSParserInfo

typedef struct _prsInfo TSParserInfo

◆ TSTemplateInfo

typedef struct _tmplInfo TSTemplateInfo

◆ TypeInfo

typedef struct _typeInfo TypeInfo

Enumeration Type Documentation

◆ DumpableObjectType

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_TABLE_ATTACH 
DO_ATTRDEF 
DO_INDEX 
DO_INDEX_ATTACH 
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_LARGE_OBJECT 
DO_LARGE_OBJECT_DATA 
DO_PRE_DATA_BOUNDARY 
DO_POST_DATA_BOUNDARY 
DO_EVENT_TRIGGER 
DO_REFRESH_MATVIEW 
DO_POLICY 
DO_PUBLICATION 
DO_PUBLICATION_REL 
DO_PUBLICATION_TABLE_IN_SCHEMA 
DO_SUBSCRIPTION 

Definition at line 37 of file pg_dump.h.

38 {
39  /* When modifying this enum, update priority tables in pg_dump_sort.c! */
42  DO_TYPE,
44  DO_FUNC,
45  DO_AGG,
48  DO_OPCLASS,
52  DO_TABLE,
54  DO_ATTRDEF,
55  DO_INDEX,
58  DO_RULE,
59  DO_TRIGGER,
61  DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
63  DO_CAST,
68  DO_TSDICT,
71  DO_FDW,
81  DO_POLICY,
DumpableObjectType
Definition: pg_dump.h:38
@ DO_EVENT_TRIGGER
Definition: pg_dump.h:79
@ DO_REFRESH_MATVIEW
Definition: pg_dump.h:80
@ DO_POLICY
Definition: pg_dump.h:81
@ DO_CAST
Definition: pg_dump.h:63
@ DO_FOREIGN_SERVER
Definition: pg_dump.h:72
@ DO_PRE_DATA_BOUNDARY
Definition: pg_dump.h:77
@ DO_PROCLANG
Definition: pg_dump.h:62
@ DO_TYPE
Definition: pg_dump.h:42
@ DO_INDEX
Definition: pg_dump.h:55
@ DO_COLLATION
Definition: pg_dump.h:50
@ DO_LARGE_OBJECT
Definition: pg_dump.h:75
@ DO_TSCONFIG
Definition: pg_dump.h:70
@ DO_OPERATOR
Definition: pg_dump.h:46
@ DO_FK_CONSTRAINT
Definition: pg_dump.h:61
@ DO_CONSTRAINT
Definition: pg_dump.h:60
@ DO_SUBSCRIPTION
Definition: pg_dump.h:85
@ DO_DEFAULT_ACL
Definition: pg_dump.h:73
@ DO_FDW
Definition: pg_dump.h:71
@ DO_SEQUENCE_SET
Definition: pg_dump.h:65
@ DO_ATTRDEF
Definition: pg_dump.h:54
@ DO_PUBLICATION_REL
Definition: pg_dump.h:83
@ DO_TABLE_ATTACH
Definition: pg_dump.h:53
@ DO_OPCLASS
Definition: pg_dump.h:48
@ DO_INDEX_ATTACH
Definition: pg_dump.h:56
@ DO_TSTEMPLATE
Definition: pg_dump.h:69
@ DO_STATSEXT
Definition: pg_dump.h:57
@ DO_FUNC
Definition: pg_dump.h:44
@ DO_POST_DATA_BOUNDARY
Definition: pg_dump.h:78
@ DO_LARGE_OBJECT_DATA
Definition: pg_dump.h:76
@ DO_OPFAMILY
Definition: pg_dump.h:49
@ DO_TRANSFORM
Definition: pg_dump.h:74
@ DO_ACCESS_METHOD
Definition: pg_dump.h:47
@ DO_PUBLICATION_TABLE_IN_SCHEMA
Definition: pg_dump.h:84
@ DO_CONVERSION
Definition: pg_dump.h:51
@ DO_TRIGGER
Definition: pg_dump.h:59
@ DO_RULE
Definition: pg_dump.h:58
@ DO_DUMMY_TYPE
Definition: pg_dump.h:66
@ DO_TSDICT
Definition: pg_dump.h:68
@ DO_TSPARSER
Definition: pg_dump.h:67
@ DO_EXTENSION
Definition: pg_dump.h:41
@ DO_TABLE_DATA
Definition: pg_dump.h:64
@ DO_PUBLICATION
Definition: pg_dump.h:82
@ DO_TABLE
Definition: pg_dump.h:52
@ DO_NAMESPACE
Definition: pg_dump.h:40
@ DO_AGG
Definition: pg_dump.h:45
@ DO_SHELL_TYPE
Definition: pg_dump.h:43

Function Documentation

◆ addObjectDependency()

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

◆ AssignDumpId()

void AssignDumpId ( DumpableObject dobj)

Definition at line 638 of file common.c.

639 {
640  dobj->dumpId = ++lastDumpId;
641  dobj->name = NULL; /* must be set later */
642  dobj->namespace = NULL; /* may be set later */
643  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
644  dobj->dump_contains = DUMP_COMPONENT_ALL; /* default assumption */
645  /* All objects have definitions; we may set more components bits later */
647  dobj->ext_member = false; /* default assumption */
648  dobj->depends_on_ext = false; /* default assumption */
649  dobj->dependencies = NULL;
650  dobj->nDeps = 0;
651  dobj->allocDeps = 0;
652 
653  /* Add object to dumpIdMap[], enlarging that array if need be */
654  while (dobj->dumpId >= allocedDumpIds)
655  {
656  int newAlloc;
657 
658  if (allocedDumpIds <= 0)
659  {
660  newAlloc = 256;
662  }
663  else
664  {
665  newAlloc = allocedDumpIds * 2;
667  }
668  memset(dumpIdMap + allocedDumpIds, 0,
669  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
670  allocedDumpIds = newAlloc;
671  }
672  dumpIdMap[dobj->dumpId] = dobj;
673 
674  /* If it has a valid CatalogId, enter it into the hash table */
675  if (OidIsValid(dobj->catId.tableoid))
676  {
677  CatalogIdMapEntry *entry;
678  bool found;
679 
680  /* Initialize CatalogId hash table if not done yet */
681  if (catalogIdHash == NULL)
682  catalogIdHash = catalogid_create(CATALOGIDHASH_INITIAL_SIZE, NULL);
683 
684  entry = catalogid_insert(catalogIdHash, dobj->catId, &found);
685  if (!found)
686  {
687  entry->dobj = NULL;
688  entry->ext = NULL;
689  }
690  Assert(entry->dobj == NULL);
691  entry->dobj = dobj;
692  }
693 }
static int allocedDumpIds
Definition: common.c:38
static DumpableObject ** dumpIdMap
Definition: common.c:37
#define CATALOGIDHASH_INITIAL_SIZE
Definition: common.c:78
static catalogid_hash * catalogIdHash
Definition: common.c:80
static DumpId lastDumpId
Definition: common.c:39
#define OidIsValid(objectId)
Definition: c.h:759
Assert(fmt[strlen(fmt) - 1] !='\n')
#define DUMP_COMPONENT_ALL
Definition: pg_dump.h:103
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:96
Oid tableoid
Definition: pg_backup.h:263
ExtensionInfo * ext
Definition: common.c:61
DumpableObject * dobj
Definition: common.c:60
DumpComponents dump
Definition: pg_dump.h:138
char * name
Definition: pg_dump.h:137
DumpId dumpId
Definition: pg_dump.h:136
bool ext_member
Definition: pg_dump.h:142
DumpComponents components
Definition: pg_dump.h:141
CatalogId catId
Definition: pg_dump.h:135
DumpComponents dump_contains
Definition: pg_dump.h:140
bool depends_on_ext
Definition: pg_dump.h:143

References _dumpableObject::allocDeps, allocedDumpIds, Assert(), catalogIdHash, CATALOGIDHASH_INITIAL_SIZE, _dumpableObject::catId, _dumpableObject::components, _dumpableObject::dependencies, _dumpableObject::depends_on_ext, _catalogIdMapEntry::dobj, _dumpableObject::dump, DUMP_COMPONENT_ALL, DUMP_COMPONENT_DEFINITION, _dumpableObject::dump_contains, _dumpableObject::dumpId, dumpIdMap, _catalogIdMapEntry::ext, _dumpableObject::ext_member, lastDumpId, _dumpableObject::name, _dumpableObject::nDeps, OidIsValid, pg_malloc_array, pg_realloc_array, and CatalogId::tableoid.

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

◆ createDumpId()

◆ findCollationByOid()

CollInfo* findCollationByOid ( Oid  oid)

Definition at line 911 of file common.c.

912 {
913  CatalogId catId;
914  DumpableObject *dobj;
915 
916  catId.tableoid = CollationRelationId;
917  catId.oid = oid;
918  dobj = findObjectByCatalogId(catId);
919  Assert(dobj == NULL || dobj->objType == DO_COLLATION);
920  return (CollInfo *) dobj;
921 }
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition: common.c:735
DumpableObjectType objType
Definition: pg_dump.h:134

References Assert(), DO_COLLATION, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

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

◆ findExtensionByOid()

ExtensionInfo* findExtensionByOid ( Oid  oid)

Definition at line 947 of file common.c.

948 {
949  CatalogId catId;
950  DumpableObject *dobj;
951 
952  catId.tableoid = ExtensionRelationId;
953  catId.oid = oid;
954  dobj = findObjectByCatalogId(catId);
955  Assert(dobj == NULL || dobj->objType == DO_EXTENSION);
956  return (ExtensionInfo *) dobj;
957 }

References Assert(), DO_EXTENSION, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getExtensionMembership().

◆ findFuncByOid()

FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 875 of file common.c.

876 {
877  CatalogId catId;
878  DumpableObject *dobj;
879 
880  catId.tableoid = ProcedureRelationId;
881  catId.oid = oid;
882  dobj = findObjectByCatalogId(catId);
883  Assert(dobj == NULL || dobj->objType == DO_FUNC);
884  return (FuncInfo *) dobj;
885 }

References Assert(), DO_FUNC, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

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

◆ findNamespaceByOid()

NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 929 of file common.c.

930 {
931  CatalogId catId;
932  DumpableObject *dobj;
933 
934  catId.tableoid = NamespaceRelationId;
935  catId.oid = oid;
936  dobj = findObjectByCatalogId(catId);
937  Assert(dobj == NULL || dobj->objType == DO_NAMESPACE);
938  return (NamespaceInfo *) dobj;
939 }

References Assert(), DO_NAMESPACE, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by findNamespace(), and getPublicationNamespaces().

◆ findObjectByCatalogId()

DumpableObject* findObjectByCatalogId ( CatalogId  catalogId)

Definition at line 735 of file common.c.

736 {
737  CatalogIdMapEntry *entry;
738 
739  if (catalogIdHash == NULL)
740  return NULL; /* no objects exist yet */
741 
742  entry = catalogid_lookup(catalogIdHash, catalogId);
743  if (entry == NULL)
744  return NULL;
745  return entry->dobj;
746 }

References catalogIdHash, and _catalogIdMapEntry::dobj.

Referenced by buildMatViewRefreshDependencies(), collectComments(), collectSecLabels(), findCollationByOid(), findExtensionByOid(), findFuncByOid(), findIndexByOid(), findNamespaceByOid(), findOprByOid(), findPublicationByOid(), findTableByOid(), findTypeByOid(), getAdditionalACLs(), and getDependencies().

◆ findObjectByDumpId()

DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 722 of file common.c.

723 {
724  if (dumpId <= 0 || dumpId >= allocedDumpIds)
725  return NULL; /* out of range? */
726  return dumpIdMap[dumpId];
727 }

References allocedDumpIds, and dumpIdMap.

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

◆ findOprByOid()

OprInfo* findOprByOid ( Oid  oid)

Definition at line 893 of file common.c.

894 {
895  CatalogId catId;
896  DumpableObject *dobj;
897 
898  catId.tableoid = OperatorRelationId;
899  catId.oid = oid;
900  dobj = findObjectByCatalogId(catId);
901  Assert(dobj == NULL || dobj->objType == DO_OPERATOR);
902  return (OprInfo *) dobj;
903 }

References Assert(), DO_OPERATOR, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getFormattedOperatorName().

◆ findOwningExtension()

ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 1008 of file common.c.

1009 {
1010  CatalogIdMapEntry *entry;
1011 
1012  if (catalogIdHash == NULL)
1013  return NULL; /* no objects exist yet */
1014 
1015  entry = catalogid_lookup(catalogIdHash, catalogId);
1016  if (entry == NULL)
1017  return NULL;
1018  return entry->ext;
1019 }

References catalogIdHash, and _catalogIdMapEntry::ext.

Referenced by checkExtensionMembership().

◆ findPublicationByOid()

PublicationInfo* findPublicationByOid ( Oid  oid)

Definition at line 965 of file common.c.

966 {
967  CatalogId catId;
968  DumpableObject *dobj;
969 
970  catId.tableoid = PublicationRelationId;
971  catId.oid = oid;
972  dobj = findObjectByCatalogId(catId);
973  Assert(dobj == NULL || dobj->objType == DO_PUBLICATION);
974  return (PublicationInfo *) dobj;
975 }

References Assert(), DO_PUBLICATION, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getPublicationNamespaces(), and getPublicationTables().

◆ findTableByOid()

TableInfo* findTableByOid ( Oid  oid)

Definition at line 820 of file common.c.

821 {
822  CatalogId catId;
823  DumpableObject *dobj;
824 
825  catId.tableoid = RelationRelationId;
826  catId.oid = oid;
827  dobj = findObjectByCatalogId(catId);
828  Assert(dobj == NULL || dobj->objType == DO_TABLE);
829  return (TableInfo *) dobj;
830 }

References Assert(), DO_TABLE, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by dumpSequence(), flagInhTables(), getAdditionalACLs(), getConstraints(), getOwnedSeqs(), getPartitioningInfo(), getPolicies(), getPublicationTables(), getRules(), getTableDataFKConstraints(), processExtensionTables(), and selectDumpableType().

◆ findTypeByOid()

TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 856 of file common.c.

857 {
858  CatalogId catId;
859  DumpableObject *dobj;
860 
861  catId.tableoid = TypeRelationId;
862  catId.oid = oid;
863  dobj = findObjectByCatalogId(catId);
864  Assert(dobj == NULL ||
865  dobj->objType == DO_TYPE || dobj->objType == DO_DUMMY_TYPE);
866  return (TypeInfo *) dobj;
867 }

References Assert(), DO_DUMMY_TYPE, DO_TYPE, findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by collectComments(), collectSecLabels(), DOTypeNameCompare(), getCasts(), getFormattedTypeName(), and getTransforms().

◆ getAccessMethods()

AccessMethodInfo* getAccessMethods ( Archive fout,
int *  numAccessMethods 
)

Definition at line 5761 of file pg_dump.c.

5762 {
5763  PGresult *res;
5764  int ntups;
5765  int i;
5766  PQExpBuffer query;
5767  AccessMethodInfo *aminfo;
5768  int i_tableoid;
5769  int i_oid;
5770  int i_amname;
5771  int i_amhandler;
5772  int i_amtype;
5773 
5774  /* Before 9.6, there are no user-defined access methods */
5775  if (fout->remoteVersion < 90600)
5776  {
5777  *numAccessMethods = 0;
5778  return NULL;
5779  }
5780 
5781  query = createPQExpBuffer();
5782 
5783  /* Select all access methods from pg_am table */
5784  appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, amtype, "
5785  "amhandler::pg_catalog.regproc AS amhandler "
5786  "FROM pg_am");
5787 
5788  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5789 
5790  ntups = PQntuples(res);
5791  *numAccessMethods = ntups;
5792 
5793  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
5794 
5795  i_tableoid = PQfnumber(res, "tableoid");
5796  i_oid = PQfnumber(res, "oid");
5797  i_amname = PQfnumber(res, "amname");
5798  i_amhandler = PQfnumber(res, "amhandler");
5799  i_amtype = PQfnumber(res, "amtype");
5800 
5801  for (i = 0; i < ntups; i++)
5802  {
5803  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
5804  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5805  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5806  AssignDumpId(&aminfo[i].dobj);
5807  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
5808  aminfo[i].dobj.namespace = NULL;
5809  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
5810  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
5811 
5812  /* Decide whether we want to dump it */
5813  selectDumpableAccessMethod(&(aminfo[i]), fout);
5814  }
5815 
5816  PQclear(res);
5817 
5818  destroyPQExpBuffer(query);
5819 
5820  return aminfo;
5821 }
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:638
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3314
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3709
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3422
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int i
Definition: isn.c:73
@ PGRES_TUPLES_OK
Definition: libpq-fe.h:100
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:290
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:1960
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:72
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:114
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:367
int remoteVersion
Definition: pg_backup.h:216
char * amhandler
Definition: pg_dump.h:251
DumpableObject dobj
Definition: pg_dump.h:249

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

Referenced by getSchemaData().

◆ getAggregates()

AggInfo* getAggregates ( Archive fout,
int *  numAggs 
)

Definition at line 5966 of file pg_dump.c.

5967 {
5968  DumpOptions *dopt = fout->dopt;
5969  PGresult *res;
5970  int ntups;
5971  int i;
5972  PQExpBuffer query = createPQExpBuffer();
5973  AggInfo *agginfo;
5974  int i_tableoid;
5975  int i_oid;
5976  int i_aggname;
5977  int i_aggnamespace;
5978  int i_pronargs;
5979  int i_proargtypes;
5980  int i_proowner;
5981  int i_aggacl;
5982  int i_acldefault;
5983 
5984  /*
5985  * Find all interesting aggregates. See comment in getFuncs() for the
5986  * rationale behind the filtering logic.
5987  */
5988  if (fout->remoteVersion >= 90600)
5989  {
5990  const char *agg_check;
5991 
5992  agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
5993  : "p.proisagg");
5994 
5995  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5996  "p.proname AS aggname, "
5997  "p.pronamespace AS aggnamespace, "
5998  "p.pronargs, p.proargtypes, "
5999  "p.proowner, "
6000  "p.proacl AS aggacl, "
6001  "acldefault('f', p.proowner) AS acldefault "
6002  "FROM pg_proc p "
6003  "LEFT JOIN pg_init_privs pip ON "
6004  "(p.oid = pip.objoid "
6005  "AND pip.classoid = 'pg_proc'::regclass "
6006  "AND pip.objsubid = 0) "
6007  "WHERE %s AND ("
6008  "p.pronamespace != "
6009  "(SELECT oid FROM pg_namespace "
6010  "WHERE nspname = 'pg_catalog') OR "
6011  "p.proacl IS DISTINCT FROM pip.initprivs",
6012  agg_check);
6013  if (dopt->binary_upgrade)
6014  appendPQExpBufferStr(query,
6015  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6016  "classid = 'pg_proc'::regclass AND "
6017  "objid = p.oid AND "
6018  "refclassid = 'pg_extension'::regclass AND "
6019  "deptype = 'e')");
6020  appendPQExpBufferChar(query, ')');
6021  }
6022  else
6023  {
6024  appendPQExpBufferStr(query, "SELECT tableoid, oid, proname AS aggname, "
6025  "pronamespace AS aggnamespace, "
6026  "pronargs, proargtypes, "
6027  "proowner, "
6028  "proacl AS aggacl, "
6029  "acldefault('f', proowner) AS acldefault "
6030  "FROM pg_proc p "
6031  "WHERE proisagg AND ("
6032  "pronamespace != "
6033  "(SELECT oid FROM pg_namespace "
6034  "WHERE nspname = 'pg_catalog')");
6035  if (dopt->binary_upgrade)
6036  appendPQExpBufferStr(query,
6037  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6038  "classid = 'pg_proc'::regclass AND "
6039  "objid = p.oid AND "
6040  "refclassid = 'pg_extension'::regclass AND "
6041  "deptype = 'e')");
6042  appendPQExpBufferChar(query, ')');
6043  }
6044 
6045  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6046 
6047  ntups = PQntuples(res);
6048  *numAggs = ntups;
6049 
6050  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
6051 
6052  i_tableoid = PQfnumber(res, "tableoid");
6053  i_oid = PQfnumber(res, "oid");
6054  i_aggname = PQfnumber(res, "aggname");
6055  i_aggnamespace = PQfnumber(res, "aggnamespace");
6056  i_pronargs = PQfnumber(res, "pronargs");
6057  i_proargtypes = PQfnumber(res, "proargtypes");
6058  i_proowner = PQfnumber(res, "proowner");
6059  i_aggacl = PQfnumber(res, "aggacl");
6060  i_acldefault = PQfnumber(res, "acldefault");
6061 
6062  for (i = 0; i < ntups; i++)
6063  {
6064  agginfo[i].aggfn.dobj.objType = DO_AGG;
6065  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6066  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6067  AssignDumpId(&agginfo[i].aggfn.dobj);
6068  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
6069  agginfo[i].aggfn.dobj.namespace =
6070  findNamespace(atooid(PQgetvalue(res, i, i_aggnamespace)));
6071  agginfo[i].aggfn.dacl.acl = pg_strdup(PQgetvalue(res, i, i_aggacl));
6072  agginfo[i].aggfn.dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6073  agginfo[i].aggfn.dacl.privtype = 0;
6074  agginfo[i].aggfn.dacl.initprivs = NULL;
6075  agginfo[i].aggfn.rolname = getRoleName(PQgetvalue(res, i, i_proowner));
6076  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
6077  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
6078  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
6079  if (agginfo[i].aggfn.nargs == 0)
6080  agginfo[i].aggfn.argtypes = NULL;
6081  else
6082  {
6083  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
6084  parseOidArray(PQgetvalue(res, i, i_proargtypes),
6085  agginfo[i].aggfn.argtypes,
6086  agginfo[i].aggfn.nargs);
6087  }
6088 
6089  /* Decide whether we want to dump it */
6090  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
6091 
6092  /* Mark whether aggregate has an ACL */
6093  if (!PQgetisnull(res, i, i_aggacl))
6094  agginfo[i].aggfn.dobj.components |= DUMP_COMPONENT_ACL;
6095  }
6096 
6097  PQclear(res);
6098 
6099  destroyPQExpBuffer(query);
6100 
6101  return agginfo;
6102 }
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1032
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3734
static const char * getRoleName(const char *roleoid_str)
Definition: pg_dump.c:9490
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:2037
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:5288
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:100
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:265
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:378
DumpOptions * dopt
Definition: pg_backup.h:211
int binary_upgrade
Definition: pg_backup.h:163

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_AGG, Archive::dopt, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, InvalidOid, parseOidArray(), pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, and selectDumpableObject().

Referenced by getSchemaData().

◆ getCasts()

CastInfo* getCasts ( Archive fout,
int *  numCasts 
)

Definition at line 8145 of file pg_dump.c.

8146 {
8147  PGresult *res;
8148  int ntups;
8149  int i;
8150  PQExpBuffer query = createPQExpBuffer();
8151  CastInfo *castinfo;
8152  int i_tableoid;
8153  int i_oid;
8154  int i_castsource;
8155  int i_casttarget;
8156  int i_castfunc;
8157  int i_castcontext;
8158  int i_castmethod;
8159 
8160  if (fout->remoteVersion >= 140000)
8161  {
8162  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8163  "castsource, casttarget, castfunc, castcontext, "
8164  "castmethod "
8165  "FROM pg_cast c "
8166  "WHERE NOT EXISTS ( "
8167  "SELECT 1 FROM pg_range r "
8168  "WHERE c.castsource = r.rngtypid "
8169  "AND c.casttarget = r.rngmultitypid "
8170  ") "
8171  "ORDER BY 3,4");
8172  }
8173  else
8174  {
8175  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8176  "castsource, casttarget, castfunc, castcontext, "
8177  "castmethod "
8178  "FROM pg_cast ORDER BY 3,4");
8179  }
8180 
8181  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8182 
8183  ntups = PQntuples(res);
8184 
8185  *numCasts = ntups;
8186 
8187  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
8188 
8189  i_tableoid = PQfnumber(res, "tableoid");
8190  i_oid = PQfnumber(res, "oid");
8191  i_castsource = PQfnumber(res, "castsource");
8192  i_casttarget = PQfnumber(res, "casttarget");
8193  i_castfunc = PQfnumber(res, "castfunc");
8194  i_castcontext = PQfnumber(res, "castcontext");
8195  i_castmethod = PQfnumber(res, "castmethod");
8196 
8197  for (i = 0; i < ntups; i++)
8198  {
8199  PQExpBufferData namebuf;
8200  TypeInfo *sTypeInfo;
8201  TypeInfo *tTypeInfo;
8202 
8203  castinfo[i].dobj.objType = DO_CAST;
8204  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8205  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8206  AssignDumpId(&castinfo[i].dobj);
8207  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
8208  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
8209  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
8210  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
8211  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
8212 
8213  /*
8214  * Try to name cast as concatenation of typnames. This is only used
8215  * for purposes of sorting. If we fail to find either type, the name
8216  * will be an empty string.
8217  */
8218  initPQExpBuffer(&namebuf);
8219  sTypeInfo = findTypeByOid(castinfo[i].castsource);
8220  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
8221  if (sTypeInfo && tTypeInfo)
8222  appendPQExpBuffer(&namebuf, "%s %s",
8223  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
8224  castinfo[i].dobj.name = namebuf.data;
8225 
8226  /* Decide whether we want to dump it */
8227  selectDumpableCast(&(castinfo[i]), fout);
8228  }
8229 
8230  PQclear(res);
8231 
8232  destroyPQExpBuffer(query);
8233 
8234  return castinfo;
8235 }
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:856
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:1902
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
char castmethod
Definition: pg_dump.h:506
Oid casttarget
Definition: pg_dump.h:503
char castcontext
Definition: pg_dump.h:505
DumpableObject dobj
Definition: pg_dump.h:501
Oid castsource
Definition: pg_dump.h:502
Oid castfunc
Definition: pg_dump.h:504
DumpableObject dobj
Definition: pg_dump.h:190

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, ExecuteSqlQuery(), findTypeByOid(), i, initPQExpBuffer(), _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, selectDumpableCast(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getCollations()

CollInfo* getCollations ( Archive fout,
int *  numCollations 
)

Definition at line 5625 of file pg_dump.c.

5626 {
5627  PGresult *res;
5628  int ntups;
5629  int i;
5630  PQExpBuffer query;
5631  CollInfo *collinfo;
5632  int i_tableoid;
5633  int i_oid;
5634  int i_collname;
5635  int i_collnamespace;
5636  int i_collowner;
5637 
5638  query = createPQExpBuffer();
5639 
5640  /*
5641  * find all collations, including builtin collations; we filter out
5642  * system-defined collations at dump-out time.
5643  */
5644 
5645  appendPQExpBufferStr(query, "SELECT tableoid, oid, collname, "
5646  "collnamespace, "
5647  "collowner "
5648  "FROM pg_collation");
5649 
5650  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5651 
5652  ntups = PQntuples(res);
5653  *numCollations = ntups;
5654 
5655  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
5656 
5657  i_tableoid = PQfnumber(res, "tableoid");
5658  i_oid = PQfnumber(res, "oid");
5659  i_collname = PQfnumber(res, "collname");
5660  i_collnamespace = PQfnumber(res, "collnamespace");
5661  i_collowner = PQfnumber(res, "collowner");
5662 
5663  for (i = 0; i < ntups; i++)
5664  {
5665  collinfo[i].dobj.objType = DO_COLLATION;
5666  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5667  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5668  AssignDumpId(&collinfo[i].dobj);
5669  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
5670  collinfo[i].dobj.namespace =
5671  findNamespace(atooid(PQgetvalue(res, i, i_collnamespace)));
5672  collinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_collowner));
5673 
5674  /* Decide whether we want to dump it */
5675  selectDumpableObject(&(collinfo[i].dobj), fout);
5676  }
5677 
5678  PQclear(res);
5679 
5680  destroyPQExpBuffer(query);
5681 
5682  return collinfo;
5683 }
const char * rolname
Definition: pg_dump.h:269
DumpableObject dobj
Definition: pg_dump.h:268

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_COLLATION, _collInfo::dobj, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), res, _collInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getConstraints()

void getConstraints ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 7317 of file pg_dump.c.

7318 {
7319  PQExpBuffer query = createPQExpBuffer();
7320  PQExpBuffer tbloids = createPQExpBuffer();
7321  PGresult *res;
7322  int ntups;
7323  int curtblindx;
7324  TableInfo *tbinfo = NULL;
7325  ConstraintInfo *constrinfo;
7326  int i_contableoid,
7327  i_conoid,
7328  i_conrelid,
7329  i_conname,
7330  i_confrelid,
7331  i_conindid,
7332  i_condef;
7333 
7334  /*
7335  * We want to perform just one query against pg_constraint. However, we
7336  * mustn't try to select every row of the catalog and then sort it out on
7337  * the client side, because some of the server-side functions we need
7338  * would be unsafe to apply to tables we don't have lock on. Hence, we
7339  * build an array of the OIDs of tables we care about (and now have lock
7340  * on!), and use a WHERE clause to constrain which rows are selected.
7341  */
7342  appendPQExpBufferChar(tbloids, '{');
7343  for (int i = 0; i < numTables; i++)
7344  {
7345  TableInfo *tinfo = &tblinfo[i];
7346 
7347  /*
7348  * For partitioned tables, foreign keys have no triggers so they must
7349  * be included anyway in case some foreign keys are defined.
7350  */
7351  if ((!tinfo->hastriggers &&
7352  tinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7353  !(tinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
7354  continue;
7355 
7356  /* OK, we need info for this table */
7357  if (tbloids->len > 1) /* do we have more than the '{'? */
7358  appendPQExpBufferChar(tbloids, ',');
7359  appendPQExpBuffer(tbloids, "%u", tinfo->dobj.catId.oid);
7360  }
7361  appendPQExpBufferChar(tbloids, '}');
7362 
7363  appendPQExpBufferStr(query,
7364  "SELECT c.tableoid, c.oid, "
7365  "conrelid, conname, confrelid, ");
7366  if (fout->remoteVersion >= 110000)
7367  appendPQExpBufferStr(query, "conindid, ");
7368  else
7369  appendPQExpBufferStr(query, "0 AS conindid, ");
7370  appendPQExpBuffer(query,
7371  "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
7372  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7373  "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
7374  "WHERE contype = 'f' ",
7375  tbloids->data);
7376  if (fout->remoteVersion >= 110000)
7377  appendPQExpBufferStr(query,
7378  "AND conparentid = 0 ");
7379  appendPQExpBufferStr(query,
7380  "ORDER BY conrelid, conname");
7381 
7382  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7383 
7384  ntups = PQntuples(res);
7385 
7386  i_contableoid = PQfnumber(res, "tableoid");
7387  i_conoid = PQfnumber(res, "oid");
7388  i_conrelid = PQfnumber(res, "conrelid");
7389  i_conname = PQfnumber(res, "conname");
7390  i_confrelid = PQfnumber(res, "confrelid");
7391  i_conindid = PQfnumber(res, "conindid");
7392  i_condef = PQfnumber(res, "condef");
7393 
7394  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7395 
7396  curtblindx = -1;
7397  for (int j = 0; j < ntups; j++)
7398  {
7399  Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
7400  TableInfo *reftable;
7401 
7402  /*
7403  * Locate the associated TableInfo; we rely on tblinfo[] being in OID
7404  * order.
7405  */
7406  if (tbinfo == NULL || tbinfo->dobj.catId.oid != conrelid)
7407  {
7408  while (++curtblindx < numTables)
7409  {
7410  tbinfo = &tblinfo[curtblindx];
7411  if (tbinfo->dobj.catId.oid == conrelid)
7412  break;
7413  }
7414  if (curtblindx >= numTables)
7415  pg_fatal("unrecognized table OID %u", conrelid);
7416  }
7417 
7418  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
7419  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7420  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7421  AssignDumpId(&constrinfo[j].dobj);
7422  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7423  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7424  constrinfo[j].contable = tbinfo;
7425  constrinfo[j].condomain = NULL;
7426  constrinfo[j].contype = 'f';
7427  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7428  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
7429  constrinfo[j].conindex = 0;
7430  constrinfo[j].condeferrable = false;
7431  constrinfo[j].condeferred = false;
7432  constrinfo[j].conislocal = true;
7433  constrinfo[j].separate = true;
7434 
7435  /*
7436  * Restoring an FK that points to a partitioned table requires that
7437  * all partition indexes have been attached beforehand. Ensure that
7438  * happens by making the constraint depend on each index partition
7439  * attach object.
7440  */
7441  reftable = findTableByOid(constrinfo[j].confrelid);
7442  if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
7443  {
7444  Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
7445 
7446  if (indexOid != InvalidOid)
7447  {
7448  for (int k = 0; k < reftable->numIndexes; k++)
7449  {
7450  IndxInfo *refidx;
7451 
7452  /* not our index? */
7453  if (reftable->indexes[k].dobj.catId.oid != indexOid)
7454  continue;
7455 
7456  refidx = &reftable->indexes[k];
7457  addConstrChildIdxDeps(&constrinfo[j].dobj, refidx);
7458  break;
7459  }
7460  }
7461  }
7462  }
7463 
7464  PQclear(res);
7465 
7466  destroyPQExpBuffer(query);
7467  destroyPQExpBuffer(tbloids);
7468 }
TableInfo * findTableByOid(Oid oid)
Definition: common.c:820
static const gbtree_vinfo tinfo
Definition: btree_bit.c:109
int j
Definition: isn.c:74
#define pg_fatal(...)
static void addConstrChildIdxDeps(DumpableObject *dobj, const IndxInfo *refidx)
Definition: pg_dump.c:7482
TypeInfo * condomain
Definition: pg_dump.h:477
TableInfo * contable
Definition: pg_dump.h:476
bool condeferred
Definition: pg_dump.h:483
bool conislocal
Definition: pg_dump.h:484
DumpableObject dobj
Definition: pg_dump.h:475
DumpId conindex
Definition: pg_dump.h:481
bool condeferrable
Definition: pg_dump.h:482
char * condef
Definition: pg_dump.h:479
DumpableObject dobj
Definition: pg_dump.h:389
struct _indxInfo * indexes
Definition: pg_dump.h:358
DumpableObject dobj
Definition: pg_dump.h:283
char relkind
Definition: pg_dump.h:286
int numIndexes
Definition: pg_dump.h:357

References addConstrChildIdxDeps(), appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), 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, _indxInfo::dobj, _constraintInfo::dobj, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), findTableByOid(), i, _tableInfo::indexes, InvalidOid, j, PQExpBufferData::len, _dumpableObject::name, _tableInfo::numIndexes, _dumpableObject::objType, CatalogId::oid, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relkind, Archive::remoteVersion, res, _constraintInfo::separate, CatalogId::tableoid, and tinfo.

Referenced by getSchemaData().

◆ getConversions()

ConvInfo* getConversions ( Archive fout,
int *  numConversions 
)

Definition at line 5693 of file pg_dump.c.

5694 {
5695  PGresult *res;
5696  int ntups;
5697  int i;
5698  PQExpBuffer query;
5699  ConvInfo *convinfo;
5700  int i_tableoid;
5701  int i_oid;
5702  int i_conname;
5703  int i_connamespace;
5704  int i_conowner;
5705 
5706  query = createPQExpBuffer();
5707 
5708  /*
5709  * find all conversions, including builtin conversions; we filter out
5710  * system-defined conversions at dump-out time.
5711  */
5712 
5713  appendPQExpBufferStr(query, "SELECT tableoid, oid, conname, "
5714  "connamespace, "
5715  "conowner "
5716  "FROM pg_conversion");
5717 
5718  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5719 
5720  ntups = PQntuples(res);
5721  *numConversions = ntups;
5722 
5723  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
5724 
5725  i_tableoid = PQfnumber(res, "tableoid");
5726  i_oid = PQfnumber(res, "oid");
5727  i_conname = PQfnumber(res, "conname");
5728  i_connamespace = PQfnumber(res, "connamespace");
5729  i_conowner = PQfnumber(res, "conowner");
5730 
5731  for (i = 0; i < ntups; i++)
5732  {
5733  convinfo[i].dobj.objType = DO_CONVERSION;
5734  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5735  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5736  AssignDumpId(&convinfo[i].dobj);
5737  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
5738  convinfo[i].dobj.namespace =
5739  findNamespace(atooid(PQgetvalue(res, i, i_connamespace)));
5740  convinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_conowner));
5741 
5742  /* Decide whether we want to dump it */
5743  selectDumpableObject(&(convinfo[i].dobj), fout);
5744  }
5745 
5746  PQclear(res);
5747 
5748  destroyPQExpBuffer(query);
5749 
5750  return convinfo;
5751 }
DumpableObject dobj
Definition: pg_dump.h:274
const char * rolname
Definition: pg_dump.h:275

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_CONVERSION, _convInfo::dobj, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), res, _convInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getDefaultACLs()

DefaultACLInfo* getDefaultACLs ( Archive fout,
int *  numDefaultACLs 
)

Definition at line 9390 of file pg_dump.c.

9391 {
9392  DumpOptions *dopt = fout->dopt;
9393  DefaultACLInfo *daclinfo;
9394  PQExpBuffer query;
9395  PGresult *res;
9396  int i_oid;
9397  int i_tableoid;
9398  int i_defaclrole;
9399  int i_defaclnamespace;
9400  int i_defaclobjtype;
9401  int i_defaclacl;
9402  int i_acldefault;
9403  int i,
9404  ntups;
9405 
9406  query = createPQExpBuffer();
9407 
9408  /*
9409  * Global entries (with defaclnamespace=0) replace the hard-wired default
9410  * ACL for their object type. We should dump them as deltas from the
9411  * default ACL, since that will be used as a starting point for
9412  * interpreting the ALTER DEFAULT PRIVILEGES commands. On the other hand,
9413  * non-global entries can only add privileges not revoke them. We must
9414  * dump those as-is (i.e., as deltas from an empty ACL).
9415  *
9416  * We can use defaclobjtype as the object type for acldefault(), except
9417  * for the case of 'S' (DEFACLOBJ_SEQUENCE) which must be converted to
9418  * 's'.
9419  */
9420  appendPQExpBufferStr(query,
9421  "SELECT oid, tableoid, "
9422  "defaclrole, "
9423  "defaclnamespace, "
9424  "defaclobjtype, "
9425  "defaclacl, "
9426  "CASE WHEN defaclnamespace = 0 THEN "
9427  "acldefault(CASE WHEN defaclobjtype = 'S' "
9428  "THEN 's'::\"char\" ELSE defaclobjtype END, "
9429  "defaclrole) ELSE '{}' END AS acldefault "
9430  "FROM pg_default_acl");
9431 
9432  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9433 
9434  ntups = PQntuples(res);
9435  *numDefaultACLs = ntups;
9436 
9437  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9438 
9439  i_oid = PQfnumber(res, "oid");
9440  i_tableoid = PQfnumber(res, "tableoid");
9441  i_defaclrole = PQfnumber(res, "defaclrole");
9442  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9443  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9444  i_defaclacl = PQfnumber(res, "defaclacl");
9445  i_acldefault = PQfnumber(res, "acldefault");
9446 
9447  for (i = 0; i < ntups; i++)
9448  {
9449  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9450 
9451  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9452  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9453  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9454  AssignDumpId(&daclinfo[i].dobj);
9455  /* cheesy ... is it worth coming up with a better object name? */
9456  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9457 
9458  if (nspid != InvalidOid)
9459  daclinfo[i].dobj.namespace = findNamespace(nspid);
9460  else
9461  daclinfo[i].dobj.namespace = NULL;
9462 
9463  daclinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9464  daclinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9465  daclinfo[i].dacl.privtype = 0;
9466  daclinfo[i].dacl.initprivs = NULL;
9467  daclinfo[i].defaclrole = getRoleName(PQgetvalue(res, i, i_defaclrole));
9468  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9469 
9470  /* Default ACLs are ACLs, of course */
9471  daclinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9472 
9473  /* Decide whether we want to dump it */
9474  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9475  }
9476 
9477  PQclear(res);
9478 
9479  destroyPQExpBuffer(query);
9480 
9481  return daclinfo;
9482 }
int nspid
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition: pg_dump.c:1880
DumpableObject dobj
Definition: pg_dump.h:580
DumpableAcl dacl
Definition: pg_dump.h:581
const char * defaclrole
Definition: pg_dump.h:582
char defaclobjtype
Definition: pg_dump.h:583
char privtype
Definition: pg_dump.h:158
char * acldefault
Definition: pg_dump.h:156
char * acl
Definition: pg_dump.h:155
char * initprivs
Definition: pg_dump.h:159

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _defaultACLInfo::dacl, PQExpBufferData::data, _defaultACLInfo::defaclobjtype, _defaultACLInfo::defaclrole, destroyPQExpBuffer(), DO_DEFAULT_ACL, _defaultACLInfo::dobj, Archive::dopt, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableAcl::initprivs, InvalidOid, _dumpableObject::name, nspid, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, res, selectDumpableDefaultACL(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getDumpableObjects()

void getDumpableObjects ( DumpableObject ***  objs,
int *  numObjs 
)

Definition at line 754 of file common.c.

755 {
756  int i,
757  j;
758 
760  j = 0;
761  for (i = 1; i < allocedDumpIds; i++)
762  {
763  if (dumpIdMap[i])
764  (*objs)[j++] = dumpIdMap[i];
765  }
766  *numObjs = j;
767 }

References allocedDumpIds, dumpIdMap, i, j, and pg_malloc_array.

Referenced by getTableDataFKConstraints(), and main().

◆ getEventTriggers()

EventTriggerInfo* getEventTriggers ( Archive fout,
int *  numEventTriggers 
)

Definition at line 7968 of file pg_dump.c.

7969 {
7970  int i;
7971  PQExpBuffer query;
7972  PGresult *res;
7973  EventTriggerInfo *evtinfo;
7974  int i_tableoid,
7975  i_oid,
7976  i_evtname,
7977  i_evtevent,
7978  i_evtowner,
7979  i_evttags,
7980  i_evtfname,
7981  i_evtenabled;
7982  int ntups;
7983 
7984  /* Before 9.3, there are no event triggers */
7985  if (fout->remoteVersion < 90300)
7986  {
7987  *numEventTriggers = 0;
7988  return NULL;
7989  }
7990 
7991  query = createPQExpBuffer();
7992 
7993  appendPQExpBufferStr(query,
7994  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
7995  "evtevent, evtowner, "
7996  "array_to_string(array("
7997  "select quote_literal(x) "
7998  " from unnest(evttags) as t(x)), ', ') as evttags, "
7999  "e.evtfoid::regproc as evtfname "
8000  "FROM pg_event_trigger e "
8001  "ORDER BY e.oid");
8002 
8003  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8004 
8005  ntups = PQntuples(res);
8006 
8007  *numEventTriggers = ntups;
8008 
8009  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
8010 
8011  i_tableoid = PQfnumber(res, "tableoid");
8012  i_oid = PQfnumber(res, "oid");
8013  i_evtname = PQfnumber(res, "evtname");
8014  i_evtevent = PQfnumber(res, "evtevent");
8015  i_evtowner = PQfnumber(res, "evtowner");
8016  i_evttags = PQfnumber(res, "evttags");
8017  i_evtfname = PQfnumber(res, "evtfname");
8018  i_evtenabled = PQfnumber(res, "evtenabled");
8019 
8020  for (i = 0; i < ntups; i++)
8021  {
8022  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
8023  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8024  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8025  AssignDumpId(&evtinfo[i].dobj);
8026  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
8027  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
8028  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
8029  evtinfo[i].evtowner = getRoleName(PQgetvalue(res, i, i_evtowner));
8030  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
8031  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
8032  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
8033 
8034  /* Decide whether we want to dump it */
8035  selectDumpableObject(&(evtinfo[i].dobj), fout);
8036  }
8037 
8038  PQclear(res);
8039 
8040  destroyPQExpBuffer(query);
8041 
8042  return evtinfo;
8043 }
char * evtevent
Definition: pg_dump.h:458
char * evtfname
Definition: pg_dump.h:461
char evtenabled
Definition: pg_dump.h:462
char * evtname
Definition: pg_dump.h:457
const char * evtowner
Definition: pg_dump.h:459
char * evttags
Definition: pg_dump.h:460
DumpableObject dobj
Definition: pg_dump.h:456

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

Referenced by getSchemaData().

◆ getExtendedStatistics()

void getExtendedStatistics ( Archive fout)

Definition at line 7245 of file pg_dump.c.

7246 {
7247  PQExpBuffer query;
7248  PGresult *res;
7249  StatsExtInfo *statsextinfo;
7250  int ntups;
7251  int i_tableoid;
7252  int i_oid;
7253  int i_stxname;
7254  int i_stxnamespace;
7255  int i_stxowner;
7256  int i_stattarget;
7257  int i;
7258 
7259  /* Extended statistics were new in v10 */
7260  if (fout->remoteVersion < 100000)
7261  return;
7262 
7263  query = createPQExpBuffer();
7264 
7265  if (fout->remoteVersion < 130000)
7266  appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
7267  "stxnamespace, stxowner, (-1) AS stxstattarget "
7268  "FROM pg_catalog.pg_statistic_ext");
7269  else
7270  appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
7271  "stxnamespace, stxowner, stxstattarget "
7272  "FROM pg_catalog.pg_statistic_ext");
7273 
7274  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7275 
7276  ntups = PQntuples(res);
7277 
7278  i_tableoid = PQfnumber(res, "tableoid");
7279  i_oid = PQfnumber(res, "oid");
7280  i_stxname = PQfnumber(res, "stxname");
7281  i_stxnamespace = PQfnumber(res, "stxnamespace");
7282  i_stxowner = PQfnumber(res, "stxowner");
7283  i_stattarget = PQfnumber(res, "stxstattarget");
7284 
7285  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
7286 
7287  for (i = 0; i < ntups; i++)
7288  {
7289  statsextinfo[i].dobj.objType = DO_STATSEXT;
7290  statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7291  statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7292  AssignDumpId(&statsextinfo[i].dobj);
7293  statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
7294  statsextinfo[i].dobj.namespace =
7295  findNamespace(atooid(PQgetvalue(res, i, i_stxnamespace)));
7296  statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
7297  statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
7298 
7299  /* Decide whether we want to dump it */
7300  selectDumpableObject(&(statsextinfo[i].dobj), fout);
7301  }
7302 
7303  PQclear(res);
7304  destroyPQExpBuffer(query);
7305 }
int stattarget
Definition: pg_dump.h:421
const char * rolname
Definition: pg_dump.h:420
DumpableObject dobj
Definition: pg_dump.h:419

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_STATSEXT, _statsExtInfo::dobj, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, _statsExtInfo::rolname, selectDumpableObject(), _statsExtInfo::stattarget, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getExtensionMembership()

void getExtensionMembership ( Archive fout,
ExtensionInfo  extinfo[],
int  numExtensions 
)

Definition at line 17711 of file pg_dump.c.

17713 {
17714  PQExpBuffer query;
17715  PGresult *res;
17716  int ntups,
17717  i;
17718  int i_classid,
17719  i_objid,
17720  i_refobjid;
17721  ExtensionInfo *ext;
17722 
17723  /* Nothing to do if no extensions */
17724  if (numExtensions == 0)
17725  return;
17726 
17727  query = createPQExpBuffer();
17728 
17729  /* refclassid constraint is redundant but may speed the search */
17730  appendPQExpBufferStr(query, "SELECT "
17731  "classid, objid, refobjid "
17732  "FROM pg_depend "
17733  "WHERE refclassid = 'pg_extension'::regclass "
17734  "AND deptype = 'e' "
17735  "ORDER BY 3");
17736 
17737  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
17738 
17739  ntups = PQntuples(res);
17740 
17741  i_classid = PQfnumber(res, "classid");
17742  i_objid = PQfnumber(res, "objid");
17743  i_refobjid = PQfnumber(res, "refobjid");
17744 
17745  /*
17746  * Since we ordered the SELECT by referenced ID, we can expect that
17747  * multiple entries for the same extension will appear together; this
17748  * saves on searches.
17749  */
17750  ext = NULL;
17751 
17752  for (i = 0; i < ntups; i++)
17753  {
17754  CatalogId objId;
17755  Oid extId;
17756 
17757  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
17758  objId.oid = atooid(PQgetvalue(res, i, i_objid));
17759  extId = atooid(PQgetvalue(res, i, i_refobjid));
17760 
17761  if (ext == NULL ||
17762  ext->dobj.catId.oid != extId)
17763  ext = findExtensionByOid(extId);
17764 
17765  if (ext == NULL)
17766  {
17767  /* shouldn't happen */
17768  pg_log_warning("could not find referenced extension %u", extId);
17769  continue;
17770  }
17771 
17772  recordExtensionMembership(objId, ext);
17773  }
17774 
17775  PQclear(res);
17776 
17777  destroyPQExpBuffer(query);
17778 }
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition: common.c:984
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:947
#define pg_log_warning(...)
Definition: pgfnames.c:24
DumpableObject dobj
Definition: pg_dump.h:180

References appendPQExpBufferStr(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _extensionInfo::dobj, ExecuteSqlQuery(), findExtensionByOid(), i, CatalogId::oid, pg_log_warning, PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), recordExtensionMembership(), res, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getExtensions()

ExtensionInfo* getExtensions ( Archive fout,
int *  numExtensions 
)

Definition at line 5306 of file pg_dump.c.

5307 {
5308  DumpOptions *dopt = fout->dopt;
5309  PGresult *res;
5310  int ntups;
5311  int i;
5312  PQExpBuffer query;
5313  ExtensionInfo *extinfo;
5314  int i_tableoid;
5315  int i_oid;
5316  int i_extname;
5317  int i_nspname;
5318  int i_extrelocatable;
5319  int i_extversion;
5320  int i_extconfig;
5321  int i_extcondition;
5322 
5323  query = createPQExpBuffer();
5324 
5325  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
5326  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
5327  "FROM pg_extension x "
5328  "JOIN pg_namespace n ON n.oid = x.extnamespace");
5329 
5330  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5331 
5332  ntups = PQntuples(res);
5333 
5334  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
5335 
5336  i_tableoid = PQfnumber(res, "tableoid");
5337  i_oid = PQfnumber(res, "oid");
5338  i_extname = PQfnumber(res, "extname");
5339  i_nspname = PQfnumber(res, "nspname");
5340  i_extrelocatable = PQfnumber(res, "extrelocatable");
5341  i_extversion = PQfnumber(res, "extversion");
5342  i_extconfig = PQfnumber(res, "extconfig");
5343  i_extcondition = PQfnumber(res, "extcondition");
5344 
5345  for (i = 0; i < ntups; i++)
5346  {
5347  extinfo[i].dobj.objType = DO_EXTENSION;
5348  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5349  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5350  AssignDumpId(&extinfo[i].dobj);
5351  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
5352  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
5353  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
5354  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
5355  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
5356  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
5357 
5358  /* Decide whether we want to dump it */
5359  selectDumpableExtension(&(extinfo[i]), dopt);
5360  }
5361 
5362  PQclear(res);
5363  destroyPQExpBuffer(query);
5364 
5365  *numExtensions = ntups;
5366 
5367  return extinfo;
5368 }
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:1988
bool relocatable
Definition: pg_dump.h:181
char * extversion
Definition: pg_dump.h:183
char * extcondition
Definition: pg_dump.h:185
char * extconfig
Definition: pg_dump.h:184

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

Referenced by getSchemaData().

◆ getForeignDataWrappers()

FdwInfo* getForeignDataWrappers ( Archive fout,
int *  numForeignDataWrappers 
)

Definition at line 9206 of file pg_dump.c.

9207 {
9208  PGresult *res;
9209  int ntups;
9210  int i;
9211  PQExpBuffer query;
9212  FdwInfo *fdwinfo;
9213  int i_tableoid;
9214  int i_oid;
9215  int i_fdwname;
9216  int i_fdwowner;
9217  int i_fdwhandler;
9218  int i_fdwvalidator;
9219  int i_fdwacl;
9220  int i_acldefault;
9221  int i_fdwoptions;
9222 
9223  query = createPQExpBuffer();
9224 
9225  appendPQExpBufferStr(query, "SELECT tableoid, oid, fdwname, "
9226  "fdwowner, "
9227  "fdwhandler::pg_catalog.regproc, "
9228  "fdwvalidator::pg_catalog.regproc, "
9229  "fdwacl, "
9230  "acldefault('F', fdwowner) AS acldefault, "
9231  "array_to_string(ARRAY("
9232  "SELECT quote_ident(option_name) || ' ' || "
9233  "quote_literal(option_value) "
9234  "FROM pg_options_to_table(fdwoptions) "
9235  "ORDER BY option_name"
9236  "), E',\n ') AS fdwoptions "
9237  "FROM pg_foreign_data_wrapper");
9238 
9239  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9240 
9241  ntups = PQntuples(res);
9242  *numForeignDataWrappers = ntups;
9243 
9244  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
9245 
9246  i_tableoid = PQfnumber(res, "tableoid");
9247  i_oid = PQfnumber(res, "oid");
9248  i_fdwname = PQfnumber(res, "fdwname");
9249  i_fdwowner = PQfnumber(res, "fdwowner");
9250  i_fdwhandler = PQfnumber(res, "fdwhandler");
9251  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
9252  i_fdwacl = PQfnumber(res, "fdwacl");
9253  i_acldefault = PQfnumber(res, "acldefault");
9254  i_fdwoptions = PQfnumber(res, "fdwoptions");
9255 
9256  for (i = 0; i < ntups; i++)
9257  {
9258  fdwinfo[i].dobj.objType = DO_FDW;
9259  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9260  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9261  AssignDumpId(&fdwinfo[i].dobj);
9262  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
9263  fdwinfo[i].dobj.namespace = NULL;
9264  fdwinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
9265  fdwinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9266  fdwinfo[i].dacl.privtype = 0;
9267  fdwinfo[i].dacl.initprivs = NULL;
9268  fdwinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_fdwowner));
9269  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
9270  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
9271  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
9272 
9273  /* Decide whether we want to dump it */
9274  selectDumpableObject(&(fdwinfo[i].dobj), fout);
9275 
9276  /* Mark whether FDW has an ACL */
9277  if (!PQgetisnull(res, i, i_fdwacl))
9278  fdwinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9279  }
9280 
9281  PQclear(res);
9282 
9283  destroyPQExpBuffer(query);
9284 
9285  return fdwinfo;
9286 }
char * fdwhandler
Definition: pg_dump.h:562
const char * rolname
Definition: pg_dump.h:561
char * fdwvalidator
Definition: pg_dump.h:563
char * fdwoptions
Definition: pg_dump.h:564
DumpableAcl dacl
Definition: pg_dump.h:560
DumpableObject dobj
Definition: pg_dump.h:559

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _fdwInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_FDW, _fdwInfo::dobj, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), _fdwInfo::fdwhandler, _fdwInfo::fdwoptions, _fdwInfo::fdwvalidator, getRoleName(), i, _dumpableAcl::initprivs, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, res, _fdwInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getForeignServers()

ForeignServerInfo* getForeignServers ( Archive fout,
int *  numForeignServers 
)

Definition at line 9296 of file pg_dump.c.

9297 {
9298  PGresult *res;
9299  int ntups;
9300  int i;
9301  PQExpBuffer query;
9302  ForeignServerInfo *srvinfo;
9303  int i_tableoid;
9304  int i_oid;
9305  int i_srvname;
9306  int i_srvowner;
9307  int i_srvfdw;
9308  int i_srvtype;
9309  int i_srvversion;
9310  int i_srvacl;
9311  int i_acldefault;
9312  int i_srvoptions;
9313 
9314  query = createPQExpBuffer();
9315 
9316  appendPQExpBufferStr(query, "SELECT tableoid, oid, srvname, "
9317  "srvowner, "
9318  "srvfdw, srvtype, srvversion, srvacl, "
9319  "acldefault('S', srvowner) AS acldefault, "
9320  "array_to_string(ARRAY("
9321  "SELECT quote_ident(option_name) || ' ' || "
9322  "quote_literal(option_value) "
9323  "FROM pg_options_to_table(srvoptions) "
9324  "ORDER BY option_name"
9325  "), E',\n ') AS srvoptions "
9326  "FROM pg_foreign_server");
9327 
9328  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9329 
9330  ntups = PQntuples(res);
9331  *numForeignServers = ntups;
9332 
9333  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
9334 
9335  i_tableoid = PQfnumber(res, "tableoid");
9336  i_oid = PQfnumber(res, "oid");
9337  i_srvname = PQfnumber(res, "srvname");
9338  i_srvowner = PQfnumber(res, "srvowner");
9339  i_srvfdw = PQfnumber(res, "srvfdw");
9340  i_srvtype = PQfnumber(res, "srvtype");
9341  i_srvversion = PQfnumber(res, "srvversion");
9342  i_srvacl = PQfnumber(res, "srvacl");
9343  i_acldefault = PQfnumber(res, "acldefault");
9344  i_srvoptions = PQfnumber(res, "srvoptions");
9345 
9346  for (i = 0; i < ntups; i++)
9347  {
9348  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
9349  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9350  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9351  AssignDumpId(&srvinfo[i].dobj);
9352  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
9353  srvinfo[i].dobj.namespace = NULL;
9354  srvinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_srvacl));
9355  srvinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9356  srvinfo[i].dacl.privtype = 0;
9357  srvinfo[i].dacl.initprivs = NULL;
9358  srvinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_srvowner));
9359  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
9360  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
9361  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
9362  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
9363 
9364  /* Decide whether we want to dump it */
9365  selectDumpableObject(&(srvinfo[i].dobj), fout);
9366 
9367  /* Servers have user mappings */
9369 
9370  /* Mark whether server has an ACL */
9371  if (!PQgetisnull(res, i, i_srvacl))
9372  srvinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9373  }
9374 
9375  PQclear(res);
9376 
9377  destroyPQExpBuffer(query);
9378 
9379  return srvinfo;
9380 }
#define DUMP_COMPONENT_USERMAP
Definition: pg_dump.h:102
DumpableAcl dacl
Definition: pg_dump.h:570
char * srvoptions
Definition: pg_dump.h:575
DumpableObject dobj
Definition: pg_dump.h:569
const char * rolname
Definition: pg_dump.h:571
char * srvversion
Definition: pg_dump.h:574

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _foreignServerInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_FOREIGN_SERVER, _foreignServerInfo::dobj, DUMP_COMPONENT_ACL, DUMP_COMPONENT_USERMAP, ExecuteSqlQuery(), getRoleName(), i, _dumpableAcl::initprivs, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, res, _foreignServerInfo::rolname, selectDumpableObject(), _foreignServerInfo::srvfdw, _foreignServerInfo::srvoptions, _foreignServerInfo::srvtype, _foreignServerInfo::srvversion, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getFuncs()

FuncInfo* getFuncs ( Archive fout,
int *  numFuncs 
)

Definition at line 6112 of file pg_dump.c.

6113 {
6114  DumpOptions *dopt = fout->dopt;
6115  PGresult *res;
6116  int ntups;
6117  int i;
6118  PQExpBuffer query = createPQExpBuffer();
6119  FuncInfo *finfo;
6120  int i_tableoid;
6121  int i_oid;
6122  int i_proname;
6123  int i_pronamespace;
6124  int i_proowner;
6125  int i_prolang;
6126  int i_pronargs;
6127  int i_proargtypes;
6128  int i_prorettype;
6129  int i_proacl;
6130  int i_acldefault;
6131 
6132  /*
6133  * Find all interesting functions. This is a bit complicated:
6134  *
6135  * 1. Always exclude aggregates; those are handled elsewhere.
6136  *
6137  * 2. Always exclude functions that are internally dependent on something
6138  * else, since presumably those will be created as a result of creating
6139  * the something else. This currently acts only to suppress constructor
6140  * functions for range types. Note this is OK only because the
6141  * constructors don't have any dependencies the range type doesn't have;
6142  * otherwise we might not get creation ordering correct.
6143  *
6144  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
6145  * they're members of extensions and we are in binary-upgrade mode then
6146  * include them, since we want to dump extension members individually in
6147  * that mode. Also, if they are used by casts or transforms then we need
6148  * to gather the information about them, though they won't be dumped if
6149  * they are built-in. Also, in 9.6 and up, include functions in
6150  * pg_catalog if they have an ACL different from what's shown in
6151  * pg_init_privs (so we have to join to pg_init_privs; annoying).
6152  */
6153  if (fout->remoteVersion >= 90600)
6154  {
6155  const char *not_agg_check;
6156 
6157  not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
6158  : "NOT p.proisagg");
6159 
6160  appendPQExpBuffer(query,
6161  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6162  "p.pronargs, p.proargtypes, p.prorettype, "
6163  "p.proacl, "
6164  "acldefault('f', p.proowner) AS acldefault, "
6165  "p.pronamespace, "
6166  "p.proowner "
6167  "FROM pg_proc p "
6168  "LEFT JOIN pg_init_privs pip ON "
6169  "(p.oid = pip.objoid "
6170  "AND pip.classoid = 'pg_proc'::regclass "
6171  "AND pip.objsubid = 0) "
6172  "WHERE %s"
6173  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6174  "WHERE classid = 'pg_proc'::regclass AND "
6175  "objid = p.oid AND deptype = 'i')"
6176  "\n AND ("
6177  "\n pronamespace != "
6178  "(SELECT oid FROM pg_namespace "
6179  "WHERE nspname = 'pg_catalog')"
6180  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6181  "\n WHERE pg_cast.oid > %u "
6182  "\n AND p.oid = pg_cast.castfunc)"
6183  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6184  "\n WHERE pg_transform.oid > %u AND "
6185  "\n (p.oid = pg_transform.trffromsql"
6186  "\n OR p.oid = pg_transform.trftosql))",
6187  not_agg_check,
6190  if (dopt->binary_upgrade)
6191  appendPQExpBufferStr(query,
6192  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6193  "classid = 'pg_proc'::regclass AND "
6194  "objid = p.oid AND "
6195  "refclassid = 'pg_extension'::regclass AND "
6196  "deptype = 'e')");
6197  appendPQExpBufferStr(query,
6198  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
6199  appendPQExpBufferChar(query, ')');
6200  }
6201  else
6202  {
6203  appendPQExpBuffer(query,
6204  "SELECT tableoid, oid, proname, prolang, "
6205  "pronargs, proargtypes, prorettype, proacl, "
6206  "acldefault('f', proowner) AS acldefault, "
6207  "pronamespace, "
6208  "proowner "
6209  "FROM pg_proc p "
6210  "WHERE NOT proisagg"
6211  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6212  "WHERE classid = 'pg_proc'::regclass AND "
6213  "objid = p.oid AND deptype = 'i')"
6214  "\n AND ("
6215  "\n pronamespace != "
6216  "(SELECT oid FROM pg_namespace "
6217  "WHERE nspname = 'pg_catalog')"
6218  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6219  "\n WHERE pg_cast.oid > '%u'::oid"
6220  "\n AND p.oid = pg_cast.castfunc)",
6222 
6223  if (fout->remoteVersion >= 90500)
6224  appendPQExpBuffer(query,
6225  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6226  "\n WHERE pg_transform.oid > '%u'::oid"
6227  "\n AND (p.oid = pg_transform.trffromsql"
6228  "\n OR p.oid = pg_transform.trftosql))",
6230 
6231  if (dopt->binary_upgrade)
6232  appendPQExpBufferStr(query,
6233  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6234  "classid = 'pg_proc'::regclass AND "
6235  "objid = p.oid AND "
6236  "refclassid = 'pg_extension'::regclass AND "
6237  "deptype = 'e')");
6238  appendPQExpBufferChar(query, ')');
6239  }
6240 
6241  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6242 
6243  ntups = PQntuples(res);
6244 
6245  *numFuncs = ntups;
6246 
6247  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
6248 
6249  i_tableoid = PQfnumber(res, "tableoid");
6250  i_oid = PQfnumber(res, "oid");
6251  i_proname = PQfnumber(res, "proname");
6252  i_pronamespace = PQfnumber(res, "pronamespace");
6253  i_proowner = PQfnumber(res, "proowner");
6254  i_prolang = PQfnumber(res, "prolang");
6255  i_pronargs = PQfnumber(res, "pronargs");
6256  i_proargtypes = PQfnumber(res, "proargtypes");
6257  i_prorettype = PQfnumber(res, "prorettype");
6258  i_proacl = PQfnumber(res, "proacl");
6259  i_acldefault = PQfnumber(res, "acldefault");
6260 
6261  for (i = 0; i < ntups; i++)
6262  {
6263  finfo[i].dobj.objType = DO_FUNC;
6264  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6265  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6266  AssignDumpId(&finfo[i].dobj);
6267  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
6268  finfo[i].dobj.namespace =
6269  findNamespace(atooid(PQgetvalue(res, i, i_pronamespace)));
6270  finfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_proacl));
6271  finfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6272  finfo[i].dacl.privtype = 0;
6273  finfo[i].dacl.initprivs = NULL;
6274  finfo[i].rolname = getRoleName(PQgetvalue(res, i, i_proowner));
6275  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
6276  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
6277  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
6278  if (finfo[i].nargs == 0)
6279  finfo[i].argtypes = NULL;
6280  else
6281  {
6282  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
6283  parseOidArray(PQgetvalue(res, i, i_proargtypes),
6284  finfo[i].argtypes, finfo[i].nargs);
6285  }
6286 
6287  /* Decide whether we want to dump it */
6288  selectDumpableObject(&(finfo[i].dobj), fout);
6289 
6290  /* Mark whether function has an ACL */
6291  if (!PQgetisnull(res, i, i_proacl))
6292  finfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6293  }
6294 
6295  PQclear(res);
6296 
6297  destroyPQExpBuffer(query);
6298 
6299  return finfo;
6300 }
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
static Oid g_last_builtin_oid
Definition: pg_dump.c:104
Oid lang
Definition: pg_dump.h:226
const char * rolname
Definition: pg_dump.h:225
Oid * argtypes
Definition: pg_dump.h:228
Oid prorettype
Definition: pg_dump.h:229
DumpableObject dobj
Definition: pg_dump.h:223
int nargs
Definition: pg_dump.h:227
DumpableAcl dacl
Definition: pg_dump.h:224

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), _funcInfo::argtypes, AssignDumpId(), atooid, _dumpOptions::binary_upgrade, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _funcInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_FUNC, _funcInfo::dobj, Archive::dopt, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), findNamespace(), g_last_builtin_oid, getRoleName(), i, _dumpableAcl::initprivs, _funcInfo::lang, _dumpableObject::name, _funcInfo::nargs, _dumpableObject::objType, CatalogId::oid, parseOidArray(), pg_malloc(), pg_malloc0(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, _funcInfo::prorettype, Archive::remoteVersion, res, _funcInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getIndexes()

void getIndexes ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 6935 of file pg_dump.c.

6936 {
6937  PQExpBuffer query = createPQExpBuffer();
6938  PQExpBuffer tbloids = createPQExpBuffer();
6939  PGresult *res;
6940  int ntups;
6941  int curtblindx;
6942  IndxInfo *indxinfo;
6943  int i_tableoid,
6944  i_oid,
6945  i_indrelid,
6946  i_indexname,
6947  i_parentidx,
6948  i_indexdef,
6949  i_indnkeyatts,
6950  i_indnatts,
6951  i_indkey,
6952  i_indisclustered,
6953  i_indisreplident,
6954  i_indnullsnotdistinct,
6955  i_contype,
6956  i_conname,
6957  i_condeferrable,
6958  i_condeferred,
6959  i_contableoid,
6960  i_conoid,
6961  i_condef,
6962  i_tablespace,
6963  i_indreloptions,
6964  i_indstatcols,
6965  i_indstatvals;
6966 
6967  /*
6968  * We want to perform just one query against pg_index. However, we
6969  * mustn't try to select every row of the catalog and then sort it out on
6970  * the client side, because some of the server-side functions we need
6971  * would be unsafe to apply to tables we don't have lock on. Hence, we
6972  * build an array of the OIDs of tables we care about (and now have lock
6973  * on!), and use a WHERE clause to constrain which rows are selected.
6974  */
6975  appendPQExpBufferChar(tbloids, '{');
6976  for (int i = 0; i < numTables; i++)
6977  {
6978  TableInfo *tbinfo = &tblinfo[i];
6979 
6980  if (!tbinfo->hasindex)
6981  continue;
6982 
6983  /*
6984  * We can ignore indexes of uninteresting tables.
6985  */
6986  if (!tbinfo->interesting)
6987  continue;
6988 
6989  /* OK, we need info for this table */
6990  if (tbloids->len > 1) /* do we have more than the '{'? */
6991  appendPQExpBufferChar(tbloids, ',');
6992  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
6993  }
6994  appendPQExpBufferChar(tbloids, '}');
6995 
6996  appendPQExpBufferStr(query,
6997  "SELECT t.tableoid, t.oid, i.indrelid, "
6998  "t.relname AS indexname, "
6999  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7000  "i.indkey, i.indisclustered, "
7001  "c.contype, c.conname, "
7002  "c.condeferrable, c.condeferred, "
7003  "c.tableoid AS contableoid, "
7004  "c.oid AS conoid, "
7005  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7006  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7007  "t.reloptions AS indreloptions, ");
7008 
7009 
7010  if (fout->remoteVersion >= 90400)
7011  appendPQExpBufferStr(query,
7012  "i.indisreplident, ");
7013  else
7014  appendPQExpBufferStr(query,
7015  "false AS indisreplident, ");
7016 
7017  if (fout->remoteVersion >= 110000)
7018  appendPQExpBufferStr(query,
7019  "inh.inhparent AS parentidx, "
7020  "i.indnkeyatts AS indnkeyatts, "
7021  "i.indnatts AS indnatts, "
7022  "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
7023  " FROM pg_catalog.pg_attribute "
7024  " WHERE attrelid = i.indexrelid AND "
7025  " attstattarget >= 0) AS indstatcols, "
7026  "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
7027  " FROM pg_catalog.pg_attribute "
7028  " WHERE attrelid = i.indexrelid AND "
7029  " attstattarget >= 0) AS indstatvals, ");
7030  else
7031  appendPQExpBufferStr(query,
7032  "0 AS parentidx, "
7033  "i.indnatts AS indnkeyatts, "
7034  "i.indnatts AS indnatts, "
7035  "'' AS indstatcols, "
7036  "'' AS indstatvals, ");
7037 
7038  if (fout->remoteVersion >= 150000)
7039  appendPQExpBufferStr(query,
7040  "i.indnullsnotdistinct ");
7041  else
7042  appendPQExpBufferStr(query,
7043  "false AS indnullsnotdistinct ");
7044 
7045  /*
7046  * The point of the messy-looking outer join is to find a constraint that
7047  * is related by an internal dependency link to the index. If we find one,
7048  * create a CONSTRAINT entry linked to the INDEX entry. We assume an
7049  * index won't have more than one internal dependency.
7050  *
7051  * Note: the check on conrelid is redundant, but useful because that
7052  * column is indexed while conindid is not.
7053  */
7054  if (fout->remoteVersion >= 110000)
7055  {
7056  appendPQExpBuffer(query,
7057  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7058  "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7059  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7060  "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
7061  "LEFT JOIN pg_catalog.pg_constraint c "
7062  "ON (i.indrelid = c.conrelid AND "
7063  "i.indexrelid = c.conindid AND "
7064  "c.contype IN ('p','u','x')) "
7065  "LEFT JOIN pg_catalog.pg_inherits inh "
7066  "ON (inh.inhrelid = indexrelid) "
7067  "WHERE (i.indisvalid OR t2.relkind = 'p') "
7068  "AND i.indisready "
7069  "ORDER BY i.indrelid, indexname",
7070  tbloids->data);
7071  }
7072  else
7073  {
7074  /*
7075  * the test on indisready is necessary in 9.2, and harmless in
7076  * earlier/later versions
7077  */
7078  appendPQExpBuffer(query,
7079  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7080  "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7081  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7082  "LEFT JOIN pg_catalog.pg_constraint c "
7083  "ON (i.indrelid = c.conrelid AND "
7084  "i.indexrelid = c.conindid AND "
7085  "c.contype IN ('p','u','x')) "
7086  "WHERE i.indisvalid AND i.indisready "
7087  "ORDER BY i.indrelid, indexname",
7088  tbloids->data);
7089  }
7090 
7091  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7092 
7093  ntups = PQntuples(res);
7094 
7095  i_tableoid = PQfnumber(res, "tableoid");
7096  i_oid = PQfnumber(res, "oid");
7097  i_indrelid = PQfnumber(res, "indrelid");
7098  i_indexname = PQfnumber(res, "indexname");
7099  i_parentidx = PQfnumber(res, "parentidx");
7100  i_indexdef = PQfnumber(res, "indexdef");
7101  i_indnkeyatts = PQfnumber(res, "indnkeyatts");
7102  i_indnatts = PQfnumber(res, "indnatts");
7103  i_indkey = PQfnumber(res, "indkey");
7104  i_indisclustered = PQfnumber(res, "indisclustered");
7105  i_indisreplident = PQfnumber(res, "indisreplident");
7106  i_indnullsnotdistinct = PQfnumber(res, "indnullsnotdistinct");
7107  i_contype = PQfnumber(res, "contype");
7108  i_conname = PQfnumber(res, "conname");
7109  i_condeferrable = PQfnumber(res, "condeferrable");
7110  i_condeferred = PQfnumber(res, "condeferred");
7111  i_contableoid = PQfnumber(res, "contableoid");
7112  i_conoid = PQfnumber(res, "conoid");
7113  i_condef = PQfnumber(res, "condef");
7114  i_tablespace = PQfnumber(res, "tablespace");
7115  i_indreloptions = PQfnumber(res, "indreloptions");
7116  i_indstatcols = PQfnumber(res, "indstatcols");
7117  i_indstatvals = PQfnumber(res, "indstatvals");
7118 
7119  indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
7120 
7121  /*
7122  * Outer loop iterates once per table, not once per row. Incrementing of
7123  * j is handled by the inner loop.
7124  */
7125  curtblindx = -1;
7126  for (int j = 0; j < ntups;)
7127  {
7128  Oid indrelid = atooid(PQgetvalue(res, j, i_indrelid));
7129  TableInfo *tbinfo = NULL;
7130  int numinds;
7131 
7132  /* Count rows for this table */
7133  for (numinds = 1; numinds < ntups - j; numinds++)
7134  if (atooid(PQgetvalue(res, j + numinds, i_indrelid)) != indrelid)
7135  break;
7136 
7137  /*
7138  * Locate the associated TableInfo; we rely on tblinfo[] being in OID
7139  * order.
7140  */
7141  while (++curtblindx < numTables)
7142  {
7143  tbinfo = &tblinfo[curtblindx];
7144  if (tbinfo->dobj.catId.oid == indrelid)
7145  break;
7146  }
7147  if (curtblindx >= numTables)
7148  pg_fatal("unrecognized table OID %u", indrelid);
7149  /* cross-check that we only got requested tables */
7150  if (!tbinfo->hasindex ||
7151  !tbinfo->interesting)
7152  pg_fatal("unexpected index data for table \"%s\"",
7153  tbinfo->dobj.name);
7154 
7155  /* Save data for this table */
7156  tbinfo->indexes = indxinfo + j;
7157  tbinfo->numIndexes = numinds;
7158 
7159  for (int c = 0; c < numinds; c++, j++)
7160  {
7161  char contype;
7162 
7163  indxinfo[j].dobj.objType = DO_INDEX;
7164  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
7165  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
7166  AssignDumpId(&indxinfo[j].dobj);
7167  indxinfo[j].dobj.dump = tbinfo->dobj.dump;
7168  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
7169  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7170  indxinfo[j].indextable = tbinfo;
7171  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
7172  indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
7173  indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
7174  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
7175  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
7176  indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
7177  indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
7178  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
7179  parseOidArray(PQgetvalue(res, j, i_indkey),
7180  indxinfo[j].indkeys, indxinfo[j].indnattrs);
7181  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
7182  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
7183  indxinfo[j].indnullsnotdistinct = (PQgetvalue(res, j, i_indnullsnotdistinct)[0] == 't');
7184  indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
7185  indxinfo[j].partattaches = (SimplePtrList)
7186  {
7187  NULL, NULL
7188  };
7189  contype = *(PQgetvalue(res, j, i_contype));
7190 
7191  if (contype == 'p' || contype == 'u' || contype == 'x')
7192  {
7193  /*
7194  * If we found a constraint matching the index, create an
7195  * entry for it.
7196  */
7197  ConstraintInfo *constrinfo;
7198 
7199  constrinfo = (ConstraintInfo *) pg_malloc(sizeof(ConstraintInfo));
7200  constrinfo->dobj.objType = DO_CONSTRAINT;
7201  constrinfo->dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7202  constrinfo->dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7203  AssignDumpId(&constrinfo->dobj);
7204  constrinfo->dobj.dump = tbinfo->dobj.dump;
7205  constrinfo->dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7206  constrinfo->dobj.namespace = tbinfo->dobj.namespace;
7207  constrinfo->contable = tbinfo;
7208  constrinfo->condomain = NULL;
7209  constrinfo->contype = contype;
7210  if (contype == 'x')
7211  constrinfo->condef = pg_strdup(PQgetvalue(res, j, i_condef));
7212  else
7213  constrinfo->condef = NULL;
7214  constrinfo->confrelid = InvalidOid;
7215  constrinfo->conindex = indxinfo[j].dobj.dumpId;
7216  constrinfo->condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
7217  constrinfo->condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
7218  constrinfo->conislocal = true;
7219  constrinfo->separate = true;
7220 
7221  indxinfo[j].indexconstraint = constrinfo->dobj.dumpId;
7222  }
7223  else
7224  {
7225  /* Plain secondary index */
7226  indxinfo[j].indexconstraint = 0;
7227  }
7228  }
7229  }
7230 
7231  PQclear(res);
7232 
7233  destroyPQExpBuffer(query);
7234  destroyPQExpBuffer(tbloids);
7235 }
char * c
struct SimplePtrList SimplePtrList
bool indisreplident
Definition: pg_dump.h:401
int indnkeyattrs
Definition: pg_dump.h:396
char * indstatvals
Definition: pg_dump.h:395
char * indstatcols
Definition: pg_dump.h:394
int indnattrs
Definition: pg_dump.h:397
TableInfo * indextable
Definition: pg_dump.h:390
Oid parentidx
Definition: pg_dump.h:403
Oid * indkeys
Definition: pg_dump.h:398
char * indreloptions
Definition: pg_dump.h:393
DumpId indexconstraint
Definition: pg_dump.h:407
bool indisclustered
Definition: pg_dump.h:400
SimplePtrList partattaches
Definition: pg_dump.h:404
char * tablespace
Definition: pg_dump.h:392
bool indnullsnotdistinct
Definition: pg_dump.h:402
char * indexdef
Definition: pg_dump.h:391
bool interesting
Definition: pg_dump.h:317
bool hasindex
Definition: pg_dump.h:294

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), 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, _dumpableObject::dumpId, ExecuteSqlQuery(), _tableInfo::hasindex, i, _indxInfo::indexconstraint, _indxInfo::indexdef, _tableInfo::indexes, _indxInfo::indextable, _indxInfo::indisclustered, _indxInfo::indisreplident, _indxInfo::indkeys, _indxInfo::indnattrs, _indxInfo::indnkeyattrs, _indxInfo::indnullsnotdistinct, _indxInfo::indreloptions, _indxInfo::indstatcols, _indxInfo::indstatvals, _tableInfo::interesting, InvalidOid, j, PQExpBufferData::len, _dumpableObject::name, _tableInfo::numIndexes, _dumpableObject::objType, CatalogId::oid, _indxInfo::parentidx, parseOidArray(), _indxInfo::partattaches, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, _constraintInfo::separate, CatalogId::tableoid, and _indxInfo::tablespace.

Referenced by getSchemaData().

◆ getInherits()

InhInfo* getInherits ( Archive fout,
int *  numInherits 
)

Definition at line 6819 of file pg_dump.c.

6820 {
6821  PGresult *res;
6822  int ntups;
6823  int i;
6824  PQExpBuffer query = createPQExpBuffer();
6825  InhInfo *inhinfo;
6826 
6827  int i_inhrelid;
6828  int i_inhparent;
6829 
6830  /* find all the inheritance information */
6831  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
6832 
6833  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6834 
6835  ntups = PQntuples(res);
6836 
6837  *numInherits = ntups;
6838 
6839  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6840 
6841  i_inhrelid = PQfnumber(res, "inhrelid");
6842  i_inhparent = PQfnumber(res, "inhparent");
6843 
6844  for (i = 0; i < ntups; i++)
6845  {
6846  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6847  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6848  }
6849 
6850  PQclear(res);
6851 
6852  destroyPQExpBuffer(query);
6853 
6854  return inhinfo;
6855 }
Oid inhparent
Definition: pg_dump.h:522
Oid inhrelid
Definition: pg_dump.h:521

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

Referenced by getSchemaData().

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )

Definition at line 711 of file common.c.

712 {
713  return lastDumpId;
714 }

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

◆ getNamespaces()

NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

Definition at line 5170 of file pg_dump.c.

5171 {
5172  PGresult *res;
5173  int ntups;
5174  int i;
5175  PQExpBuffer query;
5176  NamespaceInfo *nsinfo;
5177  int i_tableoid;
5178  int i_oid;
5179  int i_nspname;
5180  int i_nspowner;
5181  int i_nspacl;
5182  int i_acldefault;
5183 
5184  query = createPQExpBuffer();
5185 
5186  /*
5187  * we fetch all namespaces including system ones, so that every object we
5188  * read in can be linked to a containing namespace.
5189  */
5190  appendPQExpBufferStr(query, "SELECT n.tableoid, n.oid, n.nspname, "
5191  "n.nspowner, "
5192  "n.nspacl, "
5193  "acldefault('n', n.nspowner) AS acldefault "
5194  "FROM pg_namespace n");
5195 
5196  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5197 
5198  ntups = PQntuples(res);
5199 
5200  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
5201 
5202  i_tableoid = PQfnumber(res, "tableoid");
5203  i_oid = PQfnumber(res, "oid");
5204  i_nspname = PQfnumber(res, "nspname");
5205  i_nspowner = PQfnumber(res, "nspowner");
5206  i_nspacl = PQfnumber(res, "nspacl");
5207  i_acldefault = PQfnumber(res, "acldefault");
5208 
5209  for (i = 0; i < ntups; i++)
5210  {
5211  const char *nspowner;
5212 
5213  nsinfo[i].dobj.objType = DO_NAMESPACE;
5214  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5215  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5216  AssignDumpId(&nsinfo[i].dobj);
5217  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
5218  nsinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_nspacl));
5219  nsinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
5220  nsinfo[i].dacl.privtype = 0;
5221  nsinfo[i].dacl.initprivs = NULL;
5222  nspowner = PQgetvalue(res, i, i_nspowner);
5223  nsinfo[i].nspowner = atooid(nspowner);
5224  nsinfo[i].rolname = getRoleName(nspowner);
5225 
5226  /* Decide whether to dump this namespace */
5227  selectDumpableNamespace(&nsinfo[i], fout);
5228 
5229  /* Mark whether namespace has an ACL */
5230  if (!PQgetisnull(res, i, i_nspacl))
5231  nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
5232 
5233  /*
5234  * We ignore any pg_init_privs.initprivs entry for the public schema
5235  * and assume a predetermined default, for several reasons. First,
5236  * dropping and recreating the schema removes its pg_init_privs entry,
5237  * but an empty destination database starts with this ACL nonetheless.
5238  * Second, we support dump/reload of public schema ownership changes.
5239  * ALTER SCHEMA OWNER filters nspacl through aclnewowner(), but
5240  * initprivs continues to reflect the initial owner. Hence,
5241  * synthesize the value that nspacl will have after the restore's
5242  * ALTER SCHEMA OWNER. Third, this makes the destination database
5243  * match the source's ACL, even if the latter was an initdb-default
5244  * ACL, which changed in v15. An upgrade pulls in changes to most
5245  * system object ACLs that the DBA had not customized. We've made the
5246  * public schema depart from that, because changing its ACL so easily
5247  * breaks applications.
5248  */
5249  if (strcmp(nsinfo[i].dobj.name, "public") == 0)
5250  {
5251  PQExpBuffer aclarray = createPQExpBuffer();
5252  PQExpBuffer aclitem = createPQExpBuffer();
5253 
5254  /* Standard ACL as of v15 is {owner=UC/owner,=U/owner} */
5255  appendPQExpBufferChar(aclarray, '{');
5256  quoteAclUserName(aclitem, nsinfo[i].rolname);
5257  appendPQExpBufferStr(aclitem, "=UC/");
5258  quoteAclUserName(aclitem, nsinfo[i].rolname);
5259  appendPGArray(aclarray, aclitem->data);
5260  resetPQExpBuffer(aclitem);
5261  appendPQExpBufferStr(aclitem, "=U/");
5262  quoteAclUserName(aclitem, nsinfo[i].rolname);
5263  appendPGArray(aclarray, aclitem->data);
5264  appendPQExpBufferChar(aclarray, '}');
5265 
5266  nsinfo[i].dacl.privtype = 'i';
5267  nsinfo[i].dacl.initprivs = pstrdup(aclarray->data);
5268  nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
5269 
5270  destroyPQExpBuffer(aclarray);
5271  destroyPQExpBuffer(aclitem);
5272  }
5273  }
5274 
5275  PQclear(res);
5276  destroyPQExpBuffer(query);
5277 
5278  *numNamespaces = ntups;
5279 
5280  return nsinfo;
5281 }
void quoteAclUserName(PQExpBuffer output, const char *input)
Definition: dumputils.c:544
char * pstrdup(const char *in)
Definition: mcxt.c:1644
NameData rolname
Definition: pg_authid.h:34
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1710
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:146
void appendPGArray(PQExpBuffer buffer, const char *value)
Definition: string_utils.c:740
DumpableObject dobj
Definition: pg_dump.h:171
DumpableAcl dacl
Definition: pg_dump.h:172
const char * rolname
Definition: pg_dump.h:175

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPGArray(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _namespaceInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_NAMESPACE, _namespaceInfo::dobj, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), getRoleName(), i, _dumpableAcl::initprivs, _dumpableObject::name, _namespaceInfo::nspowner, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, pstrdup(), quoteAclUserName(), res, resetPQExpBuffer(), _namespaceInfo::rolname, rolname, selectDumpableNamespace(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getOpclasses()

OpclassInfo* getOpclasses ( Archive fout,
int *  numOpclasses 
)

Definition at line 5832 of file pg_dump.c.

5833 {
5834  PGresult *res;
5835  int ntups;
5836  int i;
5837  PQExpBuffer query = createPQExpBuffer();
5838  OpclassInfo *opcinfo;
5839  int i_tableoid;
5840  int i_oid;
5841  int i_opcname;
5842  int i_opcnamespace;
5843  int i_opcowner;
5844 
5845  /*
5846  * find all opclasses, including builtin opclasses; we filter out
5847  * system-defined opclasses at dump-out time.
5848  */
5849 
5850  appendPQExpBufferStr(query, "SELECT tableoid, oid, opcname, "
5851  "opcnamespace, "
5852  "opcowner "
5853  "FROM pg_opclass");
5854 
5855  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5856 
5857  ntups = PQntuples(res);
5858  *numOpclasses = ntups;
5859 
5860  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
5861 
5862  i_tableoid = PQfnumber(res, "tableoid");
5863  i_oid = PQfnumber(res, "oid");
5864  i_opcname = PQfnumber(res, "opcname");
5865  i_opcnamespace = PQfnumber(res, "opcnamespace");
5866  i_opcowner = PQfnumber(res, "opcowner");
5867 
5868  for (i = 0; i < ntups; i++)
5869  {
5870  opcinfo[i].dobj.objType = DO_OPCLASS;
5871  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5872  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5873  AssignDumpId(&opcinfo[i].dobj);
5874  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
5875  opcinfo[i].dobj.namespace =
5876  findNamespace(atooid(PQgetvalue(res, i, i_opcnamespace)));
5877  opcinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opcowner));
5878 
5879  /* Decide whether we want to dump it */
5880  selectDumpableObject(&(opcinfo[i].dobj), fout);
5881  }
5882 
5883  PQclear(res);
5884 
5885  destroyPQExpBuffer(query);
5886 
5887  return opcinfo;
5888 }
DumpableObject dobj
Definition: pg_dump.h:256
const char * rolname
Definition: pg_dump.h:257

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPCLASS, _opclassInfo::dobj, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), res, _opclassInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getOperators()

OprInfo* getOperators ( Archive fout,
int *  numOprs 
)

Definition at line 5551 of file pg_dump.c.

5552 {
5553  PGresult *res;
5554  int ntups;
5555  int i;
5556  PQExpBuffer query = createPQExpBuffer();
5557  OprInfo *oprinfo;
5558  int i_tableoid;
5559  int i_oid;
5560  int i_oprname;
5561  int i_oprnamespace;
5562  int i_oprowner;
5563  int i_oprkind;
5564  int i_oprcode;
5565 
5566  /*
5567  * find all operators, including builtin operators; we filter out
5568  * system-defined operators at dump-out time.
5569  */
5570 
5571  appendPQExpBufferStr(query, "SELECT tableoid, oid, oprname, "
5572  "oprnamespace, "
5573  "oprowner, "
5574  "oprkind, "
5575  "oprcode::oid AS oprcode "
5576  "FROM pg_operator");
5577 
5578  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5579 
5580  ntups = PQntuples(res);
5581  *numOprs = ntups;
5582 
5583  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
5584 
5585  i_tableoid = PQfnumber(res, "tableoid");
5586  i_oid = PQfnumber(res, "oid");
5587  i_oprname = PQfnumber(res, "oprname");
5588  i_oprnamespace = PQfnumber(res, "oprnamespace");
5589  i_oprowner = PQfnumber(res, "oprowner");
5590  i_oprkind = PQfnumber(res, "oprkind");
5591  i_oprcode = PQfnumber(res, "oprcode");
5592 
5593  for (i = 0; i < ntups; i++)
5594  {
5595  oprinfo[i].dobj.objType = DO_OPERATOR;
5596  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5597  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5598  AssignDumpId(&oprinfo[i].dobj);
5599  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
5600  oprinfo[i].dobj.namespace =
5601  findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)));
5602  oprinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_oprowner));
5603  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
5604  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
5605 
5606  /* Decide whether we want to dump it */
5607  selectDumpableObject(&(oprinfo[i].dobj), fout);
5608  }
5609 
5610  PQclear(res);
5611 
5612  destroyPQExpBuffer(query);
5613 
5614  return oprinfo;
5615 }
DumpableObject dobj
Definition: pg_dump.h:241
char oprkind
Definition: pg_dump.h:243
Oid oprcode
Definition: pg_dump.h:244
const char * rolname
Definition: pg_dump.h:242

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

Referenced by getSchemaData().

◆ getOpfamilies()

OpfamilyInfo* getOpfamilies ( Archive fout,
int *  numOpfamilies 
)

Definition at line 5898 of file pg_dump.c.

5899 {
5900  PGresult *res;
5901  int ntups;
5902  int i;
5903  PQExpBuffer query;
5904  OpfamilyInfo *opfinfo;
5905  int i_tableoid;
5906  int i_oid;
5907  int i_opfname;
5908  int i_opfnamespace;
5909  int i_opfowner;
5910 
5911  query = createPQExpBuffer();
5912 
5913  /*
5914  * find all opfamilies, including builtin opfamilies; we filter out
5915  * system-defined opfamilies at dump-out time.
5916  */
5917 
5918  appendPQExpBufferStr(query, "SELECT tableoid, oid, opfname, "
5919  "opfnamespace, "
5920  "opfowner "
5921  "FROM pg_opfamily");
5922 
5923  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5924 
5925  ntups = PQntuples(res);
5926  *numOpfamilies = ntups;
5927 
5928  opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
5929 
5930  i_tableoid = PQfnumber(res, "tableoid");
5931  i_oid = PQfnumber(res, "oid");
5932  i_opfname = PQfnumber(res, "opfname");
5933  i_opfnamespace = PQfnumber(res, "opfnamespace");
5934  i_opfowner = PQfnumber(res, "opfowner");
5935 
5936  for (i = 0; i < ntups; i++)
5937  {
5938  opfinfo[i].dobj.objType = DO_OPFAMILY;
5939  opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5940  opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5941  AssignDumpId(&opfinfo[i].dobj);
5942  opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
5943  opfinfo[i].dobj.namespace =
5944  findNamespace(atooid(PQgetvalue(res, i, i_opfnamespace)));
5945  opfinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opfowner));
5946 
5947  /* Decide whether we want to dump it */
5948  selectDumpableObject(&(opfinfo[i].dobj), fout);
5949  }
5950 
5951  PQclear(res);
5952 
5953  destroyPQExpBuffer(query);
5954 
5955  return opfinfo;
5956 }
const char * rolname
Definition: pg_dump.h:263
DumpableObject dobj
Definition: pg_dump.h:262

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPFAMILY, _opfamilyInfo::dobj, ExecuteSqlQuery(), findNamespace(), getRoleName(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), res, _opfamilyInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getOwnedSeqs()

void getOwnedSeqs ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 6756 of file pg_dump.c.

6757 {
6758  int i;
6759 
6760  /*
6761  * Force sequences that are "owned" by table columns to be dumped whenever
6762  * their owning table is being dumped.
6763  */
6764  for (i = 0; i < numTables; i++)
6765  {
6766  TableInfo *seqinfo = &tblinfo[i];
6767  TableInfo *owning_tab;
6768 
6769  if (!OidIsValid(seqinfo->owning_tab))
6770  continue; /* not an owned sequence */
6771 
6772  owning_tab = findTableByOid(seqinfo->owning_tab);
6773  if (owning_tab == NULL)
6774  pg_fatal("failed sanity check, parent table with OID %u of sequence with OID %u not found",
6775  seqinfo->owning_tab, seqinfo->dobj.catId.oid);
6776 
6777  /*
6778  * Only dump identity sequences if we're going to dump the table that
6779  * it belongs to.
6780  */
6781  if (owning_tab->dobj.dump == DUMP_COMPONENT_NONE &&
6782  seqinfo->is_identity_sequence)
6783  {
6784  seqinfo->dobj.dump = DUMP_COMPONENT_NONE;
6785  continue;
6786  }
6787 
6788  /*
6789  * Otherwise we need to dump the components that are being dumped for
6790  * the table and any components which the sequence is explicitly
6791  * marked with.
6792  *
6793  * We can't simply use the set of components which are being dumped
6794  * for the table as the table might be in an extension (and only the
6795  * non-extension components, eg: ACLs if changed, security labels, and
6796  * policies, are being dumped) while the sequence is not (and
6797  * therefore the definition and other components should also be
6798  * dumped).
6799  *
6800  * If the sequence is part of the extension then it should be properly
6801  * marked by checkExtensionMembership() and this will be a no-op as
6802  * the table will be equivalently marked.
6803  */
6804  seqinfo->dobj.dump = seqinfo->dobj.dump | owning_tab->dobj.dump;
6805 
6806  if (seqinfo->dobj.dump != DUMP_COMPONENT_NONE)
6807  seqinfo->interesting = true;
6808  }
6809 }
#define DUMP_COMPONENT_NONE
Definition: pg_dump.h:95
bool is_identity_sequence
Definition: pg_dump.h:313
Oid owning_tab
Definition: pg_dump.h:311

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

Referenced by getSchemaData().

◆ getPartitioningInfo()

void getPartitioningInfo ( Archive fout)

Definition at line 6875 of file pg_dump.c.

6876 {
6877  PQExpBuffer query;
6878  PGresult *res;
6879  int ntups;
6880 
6881  /* hash partitioning didn't exist before v11 */
6882  if (fout->remoteVersion < 110000)
6883  return;
6884  /* needn't bother if schema-only dump */
6885  if (fout->dopt->schemaOnly)
6886  return;
6887 
6888  query = createPQExpBuffer();
6889 
6890  /*
6891  * Unsafe partitioning schemes are exactly those for which hash enum_ops
6892  * appears among the partition opclasses. We needn't check partstrat.
6893  *
6894  * Note that this query may well retrieve info about tables we aren't
6895  * going to dump and hence have no lock on. That's okay since we need not
6896  * invoke any unsafe server-side functions.
6897  */
6898  appendPQExpBufferStr(query,
6899  "SELECT partrelid FROM pg_partitioned_table WHERE\n"
6900  "(SELECT c.oid FROM pg_opclass c JOIN pg_am a "
6901  "ON c.opcmethod = a.oid\n"
6902  "WHERE opcname = 'enum_ops' "
6903  "AND opcnamespace = 'pg_catalog'::regnamespace "
6904  "AND amname = 'hash') = ANY(partclass)");
6905 
6906  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6907 
6908  ntups = PQntuples(res);
6909 
6910  for (int i = 0; i < ntups; i++)
6911  {
6912  Oid tabrelid = atooid(PQgetvalue(res, i, 0));
6913  TableInfo *tbinfo;
6914 
6915  tbinfo = findTableByOid(tabrelid);
6916  if (tbinfo == NULL)
6917  pg_fatal("failed sanity check, table OID %u appearing in pg_partitioned_table not found",
6918  tabrelid);
6919  tbinfo->unsafe_partitions = true;
6920  }
6921 
6922  PQclear(res);
6923 
6924  destroyPQExpBuffer(query);
6925 }
bool schemaOnly
Definition: pg_backup.h:166
bool unsafe_partitions
Definition: pg_dump.h:321

References appendPQExpBufferStr(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), Archive::dopt, ExecuteSqlQuery(), findTableByOid(), i, pg_fatal, PGRES_TUPLES_OK, PQclear(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, _dumpOptions::schemaOnly, and _tableInfo::unsafe_partitions.

Referenced by getSchemaData().

◆ getPolicies()

void getPolicies ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 3750 of file pg_dump.c.

3751 {
3752  PQExpBuffer query;
3753  PQExpBuffer tbloids;
3754  PGresult *res;
3755  PolicyInfo *polinfo;
3756  int i_oid;
3757  int i_tableoid;
3758  int i_polrelid;
3759  int i_polname;
3760  int i_polcmd;
3761  int i_polpermissive;
3762  int i_polroles;
3763  int i_polqual;
3764  int i_polwithcheck;
3765  int i,
3766  j,
3767  ntups;
3768 
3769  /* No policies before 9.5 */
3770  if (fout->remoteVersion < 90500)
3771  return;
3772 
3773  query = createPQExpBuffer();
3774  tbloids = createPQExpBuffer();
3775 
3776  /*
3777  * Identify tables of interest, and check which ones have RLS enabled.
3778  */
3779  appendPQExpBufferChar(tbloids, '{');
3780  for (i = 0; i < numTables; i++)
3781  {
3782  TableInfo *tbinfo = &tblinfo[i];
3783 
3784  /* Ignore row security on tables not to be dumped */
3785  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_POLICY))
3786  continue;
3787 
3788  /* It can't have RLS or policies if it's not a table */
3789  if (tbinfo->relkind != RELKIND_RELATION &&
3790  tbinfo->relkind != RELKIND_PARTITIONED_TABLE)
3791  continue;
3792 
3793  /* Add it to the list of table OIDs to be probed below */
3794  if (tbloids->len > 1) /* do we have more than the '{'? */
3795  appendPQExpBufferChar(tbloids, ',');
3796  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
3797 
3798  /* Is RLS enabled? (That's separate from whether it has policies) */
3799  if (tbinfo->rowsec)
3800  {
3802 
3803  /*
3804  * We represent RLS being enabled on a table by creating a
3805  * PolicyInfo object with null polname.
3806  *
3807  * Note: use tableoid 0 so that this object won't be mistaken for
3808  * something that pg_depend entries apply to.
3809  */
3810  polinfo = pg_malloc(sizeof(PolicyInfo));
3811  polinfo->dobj.objType = DO_POLICY;
3812  polinfo->dobj.catId.tableoid = 0;
3813  polinfo->dobj.catId.oid = tbinfo->dobj.catId.oid;
3814  AssignDumpId(&polinfo->dobj);
3815  polinfo->dobj.namespace = tbinfo->dobj.namespace;
3816  polinfo->dobj.name = pg_strdup(tbinfo->dobj.name);
3817  polinfo->poltable = tbinfo;
3818  polinfo->polname = NULL;
3819  polinfo->polcmd = '\0';
3820  polinfo->polpermissive = 0;
3821  polinfo->polroles = NULL;
3822  polinfo->polqual = NULL;
3823  polinfo->polwithcheck = NULL;
3824  }
3825  }
3826  appendPQExpBufferChar(tbloids, '}');
3827 
3828  /*
3829  * Now, read all RLS policies belonging to the tables of interest, and
3830  * create PolicyInfo objects for them. (Note that we must filter the
3831  * results server-side not locally, because we dare not apply pg_get_expr
3832  * to tables we don't have lock on.)
3833  */
3834  pg_log_info("reading row-level security policies");
3835 
3836  printfPQExpBuffer(query,
3837  "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
3838  if (fout->remoteVersion >= 100000)
3839  appendPQExpBufferStr(query, "pol.polpermissive, ");
3840  else
3841  appendPQExpBufferStr(query, "'t' as polpermissive, ");
3842  appendPQExpBuffer(query,
3843  "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
3844  " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, "
3845  "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
3846  "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
3847  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
3848  "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
3849  tbloids->data);
3850 
3851  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
3852 
3853  ntups = PQntuples(res);
3854  if (ntups > 0)
3855  {
3856  i_oid = PQfnumber(res, "oid");
3857  i_tableoid = PQfnumber(res, "tableoid");
3858  i_polrelid = PQfnumber(res, "polrelid");
3859  i_polname = PQfnumber(res, "polname");
3860  i_polcmd = PQfnumber(res, "polcmd");
3861  i_polpermissive = PQfnumber(res, "polpermissive");
3862  i_polroles = PQfnumber(res, "polroles");
3863  i_polqual = PQfnumber(res, "polqual");
3864  i_polwithcheck = PQfnumber(res, "polwithcheck");
3865 
3866  polinfo = pg_malloc(ntups * sizeof(PolicyInfo));
3867 
3868  for (j = 0; j < ntups; j++)
3869  {
3870  Oid polrelid = atooid(PQgetvalue(res, j, i_polrelid));
3871  TableInfo *tbinfo = findTableByOid(polrelid);
3872 
3874 
3875  polinfo[j].dobj.objType = DO_POLICY;
3876  polinfo[j].dobj.catId.tableoid =
3877  atooid(PQgetvalue(res, j, i_tableoid));
3878  polinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
3879  AssignDumpId(&polinfo[j].dobj);
3880  polinfo[j].dobj.namespace = tbinfo->dobj.namespace;
3881  polinfo[j].poltable = tbinfo;
3882  polinfo[j].polname = pg_strdup(PQgetvalue(res, j, i_polname));
3883  polinfo[j].dobj.name = pg_strdup(polinfo[j].polname);
3884 
3885  polinfo[j].polcmd = *(PQgetvalue(res, j, i_polcmd));
3886  polinfo[j].polpermissive = *(PQgetvalue(res, j, i_polpermissive)) == 't';
3887 
3888  if (PQgetisnull(res, j, i_polroles))
3889  polinfo[j].polroles = NULL;
3890  else
3891  polinfo[j].polroles = pg_strdup(PQgetvalue(res, j, i_polroles));
3892 
3893  if (PQgetisnull(res, j, i_polqual))
3894  polinfo[j].polqual = NULL;
3895  else
3896  polinfo[j].polqual = pg_strdup(PQgetvalue(res, j, i_polqual));
3897 
3898  if (PQgetisnull(res, j, i_polwithcheck))
3899  polinfo[j].polwithcheck = NULL;
3900  else
3901  polinfo[j].polwithcheck
3902  = pg_strdup(PQgetvalue(res, j, i_polwithcheck));
3903  }
3904  }
3905 
3906  PQclear(res);
3907 
3908  destroyPQExpBuffer(query);
3909  destroyPQExpBuffer(tbloids);
3910 }
#define pg_log_info(...)
Definition: logging.h:124
#define DUMP_COMPONENT_POLICY
Definition: pg_dump.h:101
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:235
TableInfo * poltable
Definition: pg_dump.h:602
char * polqual
Definition: pg_dump.h:607
char polcmd
Definition: pg_dump.h:604
char * polroles
Definition: pg_dump.h:606
char * polwithcheck
Definition: pg_dump.h:608
DumpableObject dobj
Definition: pg_dump.h:601
bool polpermissive
Definition: pg_dump.h:605
char * polname
Definition: pg_dump.h:603
bool rowsec
Definition: pg_dump.h:298

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_POLICY, _tableInfo::dobj, _policyInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_POLICY, ExecuteSqlQuery(), findTableByOid(), i, j, PQExpBufferData::len, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_log_info, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, _policyInfo::polcmd, _policyInfo::polname, _policyInfo::polpermissive, _policyInfo::polqual, _policyInfo::polroles, _policyInfo::poltable, _policyInfo::polwithcheck, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), _tableInfo::relkind, Archive::remoteVersion, res, _tableInfo::rowsec, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getProcLangs()

ProcLangInfo* getProcLangs ( Archive fout,
int *  numProcLangs 
)

Definition at line 8055 of file pg_dump.c.

8056 {
8057  PGresult *res;
8058  int ntups;
8059  int i;
8060  PQExpBuffer query = createPQExpBuffer();
8061  ProcLangInfo *planginfo;
8062  int i_tableoid;
8063  int i_oid;
8064  int i_lanname;
8065  int i_lanpltrusted;
8066  int i_lanplcallfoid;
8067  int i_laninline;
8068  int i_lanvalidator;
8069  int i_lanacl;
8070  int i_acldefault;
8071  int i_lanowner;
8072 
8073  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8074  "lanname, lanpltrusted, lanplcallfoid, "
8075  "laninline, lanvalidator, "
8076  "lanacl, "
8077  "acldefault('l', lanowner) AS acldefault, "
8078  "lanowner "
8079  "FROM pg_language "
8080  "WHERE lanispl "
8081  "ORDER BY oid");
8082 
8083  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8084 
8085  ntups = PQntuples(res);
8086 
8087  *numProcLangs = ntups;
8088 
8089  planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo));
8090 
8091  i_tableoid = PQfnumber(res, "tableoid");
8092  i_oid = PQfnumber(res, "oid");
8093  i_lanname = PQfnumber(res, "lanname");
8094  i_lanpltrusted = PQfnumber(res, "lanpltrusted");
8095  i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
8096  i_laninline = PQfnumber(res, "laninline");
8097  i_lanvalidator = PQfnumber(res, "lanvalidator");
8098  i_lanacl = PQfnumber(res, "lanacl");
8099  i_acldefault = PQfnumber(res, "acldefault");
8100  i_lanowner = PQfnumber(res, "lanowner");
8101 
8102  for (i = 0; i < ntups; i++)
8103  {
8104  planginfo[i].dobj.objType = DO_PROCLANG;
8105  planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8106  planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8107  AssignDumpId(&planginfo[i].dobj);
8108 
8109  planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
8110  planginfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_lanacl));
8111  planginfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
8112  planginfo[i].dacl.privtype = 0;
8113  planginfo[i].dacl.initprivs = NULL;
8114  planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
8115  planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
8116  planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
8117  planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
8118  planginfo[i].lanowner = getRoleName(PQgetvalue(res, i, i_lanowner));
8119 
8120  /* Decide whether we want to dump it */
8121  selectDumpableProcLang(&(planginfo[i]), fout);
8122 
8123  /* Mark whether language has an ACL */
8124  if (!PQgetisnull(res, i, i_lanacl))
8125  planginfo[i].dobj.components |= DUMP_COMPONENT_ACL;
8126  }
8127 
8128  PQclear(res);
8129 
8130  destroyPQExpBuffer(query);
8131 
8132  return planginfo;
8133 }
static void selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
Definition: pg_dump.c:1927
Oid lanvalidator
Definition: pg_dump.h:495
DumpableAcl dacl
Definition: pg_dump.h:491
DumpableObject dobj
Definition: pg_dump.h:490
Oid laninline
Definition: pg_dump.h:494
const char * lanowner
Definition: pg_dump.h:496
Oid lanplcallfoid
Definition: pg_dump.h:493
bool lanpltrusted
Definition: pg_dump.h:492

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _procLangInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_PROCLANG, _procLangInfo::dobj, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), getRoleName(), i, _dumpableAcl::initprivs, _procLangInfo::laninline, _procLangInfo::lanowner, _procLangInfo::lanplcallfoid, _procLangInfo::lanpltrusted, _procLangInfo::lanvalidator, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, res, selectDumpableProcLang(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getPublicationNamespaces()

void getPublicationNamespaces ( Archive fout)

Definition at line 4235 of file pg_dump.c.

4236 {
4237  PQExpBuffer query;
4238  PGresult *res;
4239  PublicationSchemaInfo *pubsinfo;
4240  DumpOptions *dopt = fout->dopt;
4241  int i_tableoid;
4242  int i_oid;
4243  int i_pnpubid;
4244  int i_pnnspid;
4245  int i,
4246  j,
4247  ntups;
4248 
4249  if (dopt->no_publications || fout->remoteVersion < 150000)
4250  return;
4251 
4252  query = createPQExpBuffer();
4253 
4254  /* Collect all publication membership info. */
4255  appendPQExpBufferStr(query,
4256  "SELECT tableoid, oid, pnpubid, pnnspid "
4257  "FROM pg_catalog.pg_publication_namespace");
4258  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4259 
4260  ntups = PQntuples(res);
4261 
4262  i_tableoid = PQfnumber(res, "tableoid");
4263  i_oid = PQfnumber(res, "oid");
4264  i_pnpubid = PQfnumber(res, "pnpubid");
4265  i_pnnspid = PQfnumber(res, "pnnspid");
4266 
4267  /* this allocation may be more than we need */
4268  pubsinfo = pg_malloc(ntups * sizeof(PublicationSchemaInfo));
4269  j = 0;
4270 
4271  for (i = 0; i < ntups; i++)
4272  {
4273  Oid pnpubid = atooid(PQgetvalue(res, i, i_pnpubid));
4274  Oid pnnspid = atooid(PQgetvalue(res, i, i_pnnspid));
4275  PublicationInfo *pubinfo;
4276  NamespaceInfo *nspinfo;
4277 
4278  /*
4279  * Ignore any entries for which we aren't interested in either the
4280  * publication or the rel.
4281  */
4282  pubinfo = findPublicationByOid(pnpubid);
4283  if (pubinfo == NULL)
4284  continue;
4285  nspinfo = findNamespaceByOid(pnnspid);
4286  if (nspinfo == NULL)
4287  continue;
4288 
4289  /*
4290  * We always dump publication namespaces unless the corresponding
4291  * namespace is excluded from the dump.
4292  */
4293  if (nspinfo->dobj.dump == DUMP_COMPONENT_NONE)
4294  continue;
4295 
4296  /* OK, make a DumpableObject for this relationship */
4298  pubsinfo[j].dobj.catId.tableoid =
4299  atooid(PQgetvalue(res, i, i_tableoid));
4300  pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4301  AssignDumpId(&pubsinfo[j].dobj);
4302  pubsinfo[j].dobj.namespace = nspinfo->dobj.namespace;
4303  pubsinfo[j].dobj.name = nspinfo->dobj.name;
4304  pubsinfo[j].publication = pubinfo;
4305  pubsinfo[j].pubschema = nspinfo;
4306 
4307  /* Decide whether we want to dump it */
4308  selectDumpablePublicationObject(&(pubsinfo[j].dobj), fout);
4309 
4310  j++;
4311  }
4312 
4313  PQclear(res);
4314  destroyPQExpBuffer(query);
4315 }
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition: common.c:929
PublicationInfo * findPublicationByOid(Oid oid)
Definition: common.c:965
static void selectDumpablePublicationObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:2021
NamespaceInfo * pubschema
Definition: pg_dump.h:647
DumpableObject dobj
Definition: pg_dump.h:645
PublicationInfo * publication
Definition: pg_dump.h:646
int no_publications
Definition: pg_backup.h:179

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PUBLICATION_TABLE_IN_SCHEMA, _namespaceInfo::dobj, _PublicationSchemaInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_NONE, ExecuteSqlQuery(), findNamespaceByOid(), findPublicationByOid(), i, j, _dumpableObject::name, _dumpOptions::no_publications, _dumpableObject::objType, CatalogId::oid, pg_malloc(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _PublicationSchemaInfo::publication, _PublicationSchemaInfo::pubschema, Archive::remoteVersion, res, selectDumpablePublicationObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getPublications()

PublicationInfo* getPublications ( Archive fout,
int *  numPublications 
)

Definition at line 4035 of file pg_dump.c.

4036 {
4037  DumpOptions *dopt = fout->dopt;
4038  PQExpBuffer query;
4039  PGresult *res;
4040  PublicationInfo *pubinfo;
4041  int i_tableoid;
4042  int i_oid;
4043  int i_pubname;
4044  int i_pubowner;
4045  int i_puballtables;
4046  int i_pubinsert;
4047  int i_pubupdate;
4048  int i_pubdelete;
4049  int i_pubtruncate;
4050  int i_pubviaroot;
4051  int i,
4052  ntups;
4053 
4054  if (dopt->no_publications || fout->remoteVersion < 100000)
4055  {
4056  *numPublications = 0;
4057  return NULL;
4058  }
4059 
4060  query = createPQExpBuffer();
4061 
4062  resetPQExpBuffer(query);
4063 
4064  /* Get the publications. */
4065  if (fout->remoteVersion >= 130000)
4066  appendPQExpBufferStr(query,
4067  "SELECT p.tableoid, p.oid, p.pubname, "
4068  "p.pubowner, "
4069  "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, p.pubviaroot "
4070  "FROM pg_publication p");
4071  else if (fout->remoteVersion >= 110000)
4072  appendPQExpBufferStr(query,
4073  "SELECT p.tableoid, p.oid, p.pubname, "
4074  "p.pubowner, "
4075  "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, false AS pubviaroot "
4076  "FROM pg_publication p");
4077  else
4078  appendPQExpBufferStr(query,
4079  "SELECT p.tableoid, p.oid, p.pubname, "
4080  "p.pubowner, "
4081  "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, false AS pubtruncate, false AS pubviaroot "
4082  "FROM pg_publication p");
4083 
4084  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4085 
4086  ntups = PQntuples(res);
4087 
4088  i_tableoid = PQfnumber(res, "tableoid");
4089  i_oid = PQfnumber(res, "oid");
4090  i_pubname = PQfnumber(res, "pubname");
4091  i_pubowner = PQfnumber(res, "pubowner");
4092  i_puballtables = PQfnumber(res, "puballtables");
4093  i_pubinsert = PQfnumber(res, "pubinsert");
4094  i_pubupdate = PQfnumber(res, "pubupdate");
4095  i_pubdelete = PQfnumber(res, "pubdelete");
4096  i_pubtruncate = PQfnumber(res, "pubtruncate");
4097  i_pubviaroot = PQfnumber(res, "pubviaroot");
4098 
4099  pubinfo = pg_malloc(ntups * sizeof(PublicationInfo));
4100 
4101  for (i = 0; i < ntups; i++)
4102  {
4103  pubinfo[i].dobj.objType = DO_PUBLICATION;
4104  pubinfo[i].dobj.catId.tableoid =
4105  atooid(PQgetvalue(res, i, i_tableoid));
4106  pubinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4107  AssignDumpId(&pubinfo[i].dobj);
4108  pubinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_pubname));
4109  pubinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_pubowner));
4110  pubinfo[i].puballtables =
4111  (strcmp(PQgetvalue(res, i, i_puballtables), "t") == 0);
4112  pubinfo[i].pubinsert =
4113  (strcmp(PQgetvalue(res, i, i_pubinsert), "t") == 0);
4114  pubinfo[i].pubupdate =
4115  (strcmp(PQgetvalue(res, i, i_pubupdate), "t") == 0);
4116  pubinfo[i].pubdelete =
4117  (strcmp(PQgetvalue(res, i, i_pubdelete), "t") == 0);
4118  pubinfo[i].pubtruncate =
4119  (strcmp(PQgetvalue(res, i, i_pubtruncate), "t") == 0);
4120  pubinfo[i].pubviaroot =
4121  (strcmp(PQgetvalue(res, i, i_pubviaroot), "t") == 0);
4122 
4123  /* Decide whether we want to dump it */
4124  selectDumpableObject(&(pubinfo[i].dobj), fout);
4125  }
4126  PQclear(res);
4127 
4128  destroyPQExpBuffer(query);
4129 
4130  *numPublications = ntups;
4131  return pubinfo;
4132 }
const char * rolname
Definition: pg_dump.h:617
bool puballtables
Definition: pg_dump.h:618
bool pubtruncate
Definition: pg_dump.h:622
DumpableObject dobj
Definition: pg_dump.h:616

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PUBLICATION, _PublicationInfo::dobj, Archive::dopt, ExecuteSqlQuery(), getRoleName(), i, _dumpableObject::name, _dumpOptions::no_publications, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _PublicationInfo::puballtables, _PublicationInfo::pubdelete, _PublicationInfo::pubinsert, _PublicationInfo::pubtruncate, _PublicationInfo::pubupdate, _PublicationInfo::pubviaroot, Archive::remoteVersion, res, resetPQExpBuffer(), _PublicationInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getPublicationTables()

void getPublicationTables ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)

Definition at line 4322 of file pg_dump.c.

4323 {
4324  PQExpBuffer query;
4325  PGresult *res;
4326  PublicationRelInfo *pubrinfo;
4327  DumpOptions *dopt = fout->dopt;
4328  int i_tableoid;
4329  int i_oid;
4330  int i_prpubid;
4331  int i_prrelid;
4332  int i_prrelqual;
4333  int i_prattrs;
4334  int i,
4335  j,
4336  ntups;
4337 
4338  if (dopt->no_publications || fout->remoteVersion < 100000)
4339  return;
4340 
4341  query = createPQExpBuffer();
4342 
4343  /* Collect all publication membership info. */
4344  if (fout->remoteVersion >= 150000)
4345  appendPQExpBufferStr(query,
4346  "SELECT tableoid, oid, prpubid, prrelid, "
4347  "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4348  "(CASE\n"
4349  " WHEN pr.prattrs IS NOT NULL THEN\n"
4350  " (SELECT array_agg(attname)\n"
4351  " FROM\n"
4352  " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4353  " pg_catalog.pg_attribute\n"
4354  " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4355  " ELSE NULL END) prattrs "
4356  "FROM pg_catalog.pg_publication_rel pr");
4357  else
4358  appendPQExpBufferStr(query,
4359  "SELECT tableoid, oid, prpubid, prrelid, "
4360  "NULL AS prrelqual, NULL AS prattrs "
4361  "FROM pg_catalog.pg_publication_rel");
4362  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4363 
4364  ntups = PQntuples(res);
4365 
4366  i_tableoid = PQfnumber(res, "tableoid");
4367  i_oid = PQfnumber(res, "oid");
4368  i_prpubid = PQfnumber(res, "prpubid");
4369  i_prrelid = PQfnumber(res, "prrelid");
4370  i_prrelqual = PQfnumber(res, "prrelqual");
4371  i_prattrs = PQfnumber(res, "prattrs");
4372 
4373  /* this allocation may be more than we need */
4374  pubrinfo = pg_malloc(ntups * sizeof(PublicationRelInfo));
4375  j = 0;
4376 
4377  for (i = 0; i < ntups; i++)
4378  {
4379  Oid prpubid = atooid(PQgetvalue(res, i, i_prpubid));
4380  Oid prrelid = atooid(PQgetvalue(res, i, i_prrelid));
4381  PublicationInfo *pubinfo;
4382  TableInfo *tbinfo;
4383 
4384  /*
4385  * Ignore any entries for which we aren't interested in either the
4386  * publication or the rel.
4387  */
4388  pubinfo = findPublicationByOid(prpubid);
4389  if (pubinfo == NULL)
4390  continue;
4391  tbinfo = findTableByOid(prrelid);
4392  if (tbinfo == NULL)
4393  continue;
4394 
4395  /*
4396  * Ignore publication membership of tables whose definitions are not
4397  * to be dumped.
4398  */
4399  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
4400  continue;
4401 
4402  /* OK, make a DumpableObject for this relationship */
4403  pubrinfo[j].dobj.objType = DO_PUBLICATION_REL;
4404  pubrinfo[j].dobj.catId.tableoid =
4405  atooid(PQgetvalue(res, i, i_tableoid));
4406  pubrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4407  AssignDumpId(&pubrinfo[j].dobj);
4408  pubrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4409  pubrinfo[j].dobj.name = tbinfo->dobj.name;
4410  pubrinfo[j].publication = pubinfo;
4411  pubrinfo[j].pubtable = tbinfo;
4412  if (PQgetisnull(res, i, i_prrelqual))
4413  pubrinfo[j].pubrelqual = NULL;
4414  else
4415  pubrinfo[j].pubrelqual = pg_strdup(PQgetvalue(res, i, i_prrelqual));
4416 
4417  if (!PQgetisnull(res, i, i_prattrs))
4418  {
4419  char **attnames;
4420  int nattnames;
4421  PQExpBuffer attribs;
4422 
4423  if (!parsePGArray(PQgetvalue(res, i, i_prattrs),
4424  &attnames, &nattnames))
4425  pg_fatal("could not parse %s array", "prattrs");
4426  attribs = createPQExpBuffer();
4427  for (int k = 0; k < nattnames; k++)
4428  {
4429  if (k > 0)
4430  appendPQExpBufferStr(attribs, ", ");
4431 
4432  appendPQExpBufferStr(attribs, fmtId(attnames[k]));
4433  }
4434  pubrinfo[j].pubrattrs = attribs->data;
4435  }
4436  else
4437  pubrinfo[j].pubrattrs = NULL;
4438 
4439  /* Decide whether we want to dump it */
4440  selectDumpablePublicationObject(&(pubrinfo[j].dobj), fout);
4441 
4442  j++;
4443  }
4444 
4445  PQclear(res);
4446  destroyPQExpBuffer(query);
4447 }
const char * fmtId(const char *rawid)
Definition: string_utils.c:64
bool parsePGArray(const char *atext, char ***itemarray, int *nitems)
Definition: string_utils.c:657

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PUBLICATION_REL, _tableInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), findPublicationByOid(), findTableByOid(), fmtId(), i, j, _dumpableObject::name, _dumpOptions::no_publications, parsePGArray(), pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, and selectDumpablePublicationObject().

Referenced by getSchemaData().

◆ getRules()

RuleInfo* getRules ( Archive fout,
int *  numRules 
)

Definition at line 7597 of file pg_dump.c.

7598 {
7599  PGresult *res;
7600  int ntups;
7601  int i;
7602  PQExpBuffer query = createPQExpBuffer();
7603  RuleInfo *ruleinfo;
7604  int i_tableoid;
7605  int i_oid;
7606  int i_rulename;
7607  int i_ruletable;
7608  int i_ev_type;
7609  int i_is_instead;
7610  int i_ev_enabled;
7611 
7612  appendPQExpBufferStr(query, "SELECT "
7613  "tableoid, oid, rulename, "
7614  "ev_class AS ruletable, ev_type, is_instead, "
7615  "ev_enabled "
7616  "FROM pg_rewrite "
7617  "ORDER BY oid");
7618 
7619  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7620 
7621  ntups = PQntuples(res);
7622 
7623  *numRules = ntups;
7624 
7625  ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo));
7626 
7627  i_tableoid = PQfnumber(res, "tableoid");
7628  i_oid = PQfnumber(res, "oid");
7629  i_rulename = PQfnumber(res, "rulename");
7630  i_ruletable = PQfnumber(res, "ruletable");
7631  i_ev_type = PQfnumber(res, "ev_type");
7632  i_is_instead = PQfnumber(res, "is_instead");
7633  i_ev_enabled = PQfnumber(res, "ev_enabled");
7634 
7635  for (i = 0; i < ntups; i++)
7636  {
7637  Oid ruletableoid;
7638 
7639  ruleinfo[i].dobj.objType = DO_RULE;
7640  ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7641  ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7642  AssignDumpId(&ruleinfo[i].dobj);
7643  ruleinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_rulename));
7644  ruletableoid = atooid(PQgetvalue(res, i, i_ruletable));
7645  ruleinfo[i].ruletable = findTableByOid(ruletableoid);
7646  if (ruleinfo[i].ruletable == NULL)
7647  pg_fatal("failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
7648  ruletableoid, ruleinfo[i].dobj.catId.oid);
7649  ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace;
7650  ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump;
7651  ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type));
7652  ruleinfo[i].is_instead = *(PQgetvalue(res, i, i_is_instead)) == 't';
7653  ruleinfo[i].ev_enabled = *(PQgetvalue(res, i, i_ev_enabled));
7654  if (ruleinfo[i].ruletable)
7655  {
7656  /*
7657  * If the table is a view or materialized view, force its ON
7658  * SELECT rule to be sorted before the view itself --- this
7659  * ensures that any dependencies for the rule affect the table's
7660  * positioning. Other rules are forced to appear after their
7661  * table.
7662  */
7663  if ((ruleinfo[i].ruletable->relkind == RELKIND_VIEW ||
7664  ruleinfo[i].ruletable->relkind == RELKIND_MATVIEW) &&
7665  ruleinfo[i].ev_type == '1' && ruleinfo[i].is_instead)
7666  {
7667  addObjectDependency(&ruleinfo[i].ruletable->dobj,
7668  ruleinfo[i].dobj.dumpId);
7669  /* We'll merge the rule into CREATE VIEW, if possible */
7670  ruleinfo[i].separate = false;
7671  }
7672  else
7673  {
7674  addObjectDependency(&ruleinfo[i].dobj,
7675  ruleinfo[i].ruletable->dobj.dumpId);
7676  ruleinfo[i].separate = true;
7677  }
7678  }
7679  else
7680  ruleinfo[i].separate = true;
7681  }
7682 
7683  PQclear(res);
7684 
7685  destroyPQExpBuffer(query);
7686 
7687  return ruleinfo;
7688 }
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:775
DumpableObject dobj
Definition: pg_dump.h:426
bool separate
Definition: pg_dump.h:431
char ev_enabled
Definition: pg_dump.h:430
bool is_instead
Definition: pg_dump.h:429
TableInfo * ruletable
Definition: pg_dump.h:427
char ev_type
Definition: pg_dump.h:428

References addObjectDependency(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_RULE, _tableInfo::dobj, _ruleInfo::dobj, _dumpableObject::dump, _dumpableObject::dumpId, _ruleInfo::ev_enabled, _ruleInfo::ev_type, ExecuteSqlQuery(), findTableByOid(), i, _ruleInfo::is_instead, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relkind, res, _ruleInfo::ruletable, _ruleInfo::separate, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getSchemaData()

TableInfo* getSchemaData ( Archive fout,
int *  numTablesPtr 
)

Definition at line 95 of file common.c.

96 {
97  TableInfo *tblinfo;
98  ExtensionInfo *extinfo;
99  InhInfo *inhinfo;
100  int numTables;
101  int numTypes;
102  int numFuncs;
103  int numOperators;
104  int numCollations;
105  int numNamespaces;
106  int numExtensions;
107  int numPublications;
108  int numAggregates;
109  int numInherits;
110  int numRules;
111  int numProcLangs;
112  int numCasts;
113  int numTransforms;
114  int numAccessMethods;
115  int numOpclasses;
116  int numOpfamilies;
117  int numConversions;
118  int numTSParsers;
119  int numTSTemplates;
120  int numTSDicts;
121  int numTSConfigs;
122  int numForeignDataWrappers;
123  int numForeignServers;
124  int numDefaultACLs;
125  int numEventTriggers;
126 
127  /*
128  * We must read extensions and extension membership info first, because
129  * extension membership needs to be consultable during decisions about
130  * whether other objects are to be dumped.
131  */
132  pg_log_info("reading extensions");
133  extinfo = getExtensions(fout, &numExtensions);
134 
135  pg_log_info("identifying extension members");
136  getExtensionMembership(fout, extinfo, numExtensions);
137 
138  pg_log_info("reading schemas");
139  (void) getNamespaces(fout, &numNamespaces);
140 
141  /*
142  * getTables should be done as soon as possible, so as to minimize the
143  * window between starting our transaction and acquiring per-table locks.
144  * However, we have to do getNamespaces first because the tables get
145  * linked to their containing namespaces during getTables.
146  */
147  pg_log_info("reading user-defined tables");
148  tblinfo = getTables(fout, &numTables);
149 
150  getOwnedSeqs(fout, tblinfo, numTables);
151 
152  pg_log_info("reading user-defined functions");
153  (void) getFuncs(fout, &numFuncs);
154 
155  /* this must be after getTables and getFuncs */
156  pg_log_info("reading user-defined types");
157  (void) getTypes(fout, &numTypes);
158 
159  /* this must be after getFuncs, too */
160  pg_log_info("reading procedural languages");
161  getProcLangs(fout, &numProcLangs);
162 
163  pg_log_info("reading user-defined aggregate functions");
164  getAggregates(fout, &numAggregates);
165 
166  pg_log_info("reading user-defined operators");
167  (void) getOperators(fout, &numOperators);
168 
169  pg_log_info("reading user-defined access methods");
170  getAccessMethods(fout, &numAccessMethods);
171 
172  pg_log_info("reading user-defined operator classes");
173  getOpclasses(fout, &numOpclasses);
174 
175  pg_log_info("reading user-defined operator families");
176  getOpfamilies(fout, &numOpfamilies);
177 
178  pg_log_info("reading user-defined text search parsers");
179  getTSParsers(fout, &numTSParsers);
180 
181  pg_log_info("reading user-defined text search templates");
182  getTSTemplates(fout, &numTSTemplates);
183 
184  pg_log_info("reading user-defined text search dictionaries");
185  getTSDictionaries(fout, &numTSDicts);
186 
187  pg_log_info("reading user-defined text search configurations");
188  getTSConfigurations(fout, &numTSConfigs);
189 
190  pg_log_info("reading user-defined foreign-data wrappers");
191  getForeignDataWrappers(fout, &numForeignDataWrappers);
192 
193  pg_log_info("reading user-defined foreign servers");
194  getForeignServers(fout, &numForeignServers);
195 
196  pg_log_info("reading default privileges");
197  getDefaultACLs(fout, &numDefaultACLs);
198 
199  pg_log_info("reading user-defined collations");
200  (void) getCollations(fout, &numCollations);
201 
202  pg_log_info("reading user-defined conversions");
203  getConversions(fout, &numConversions);
204 
205  pg_log_info("reading type casts");
206