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

596 {
597  dobj->dumpId = ++lastDumpId;
598  dobj->name = NULL; /* must be set later */
599  dobj->namespace = NULL; /* may be set later */
600  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
601  dobj->dump_contains = DUMP_COMPONENT_ALL; /* default assumption */
602  /* All objects have definitions; we may set more components bits later */
604  dobj->ext_member = false; /* default assumption */
605  dobj->depends_on_ext = false; /* default assumption */
606  dobj->dependencies = NULL;
607  dobj->nDeps = 0;
608  dobj->allocDeps = 0;
609 
610  /* Add object to dumpIdMap[], enlarging that array if need be */
611  while (dobj->dumpId >= allocedDumpIds)
612  {
613  int newAlloc;
614 
615  if (allocedDumpIds <= 0)
616  {
617  newAlloc = 256;
619  }
620  else
621  {
622  newAlloc = allocedDumpIds * 2;
624  }
625  memset(dumpIdMap + allocedDumpIds, 0,
626  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
627  allocedDumpIds = newAlloc;
628  }
629  dumpIdMap[dobj->dumpId] = dobj;
630 
631  /* If it has a valid CatalogId, enter it into the hash table */
632  if (OidIsValid(dobj->catId.tableoid))
633  {
634  CatalogIdMapEntry *entry;
635  bool found;
636 
637  /* Initialize CatalogId hash table if not done yet */
638  if (catalogIdHash == NULL)
639  catalogIdHash = catalogid_create(CATALOGIDHASH_INITIAL_SIZE, NULL);
640 
641  entry = catalogid_insert(catalogIdHash, dobj->catId, &found);
642  if (!found)
643  {
644  entry->dobj = NULL;
645  entry->ext = NULL;
646  }
647  Assert(entry->dobj == NULL);
648  entry->dobj = dobj;
649  }
650 }
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 868 of file common.c.

869 {
870  CatalogId catId;
871  DumpableObject *dobj;
872 
873  catId.tableoid = CollationRelationId;
874  catId.oid = oid;
875  dobj = findObjectByCatalogId(catId);
876  Assert(dobj == NULL || dobj->objType == DO_COLLATION);
877  return (CollInfo *) dobj;
878 }
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition: common.c:692
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 904 of file common.c.

905 {
906  CatalogId catId;
907  DumpableObject *dobj;
908 
909  catId.tableoid = ExtensionRelationId;
910  catId.oid = oid;
911  dobj = findObjectByCatalogId(catId);
912  Assert(dobj == NULL || dobj->objType == DO_EXTENSION);
913  return (ExtensionInfo *) dobj;
914 }

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

Referenced by getExtensionMembership().

◆ findFuncByOid()

FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 832 of file common.c.

833 {
834  CatalogId catId;
835  DumpableObject *dobj;
836 
837  catId.tableoid = ProcedureRelationId;
838  catId.oid = oid;
839  dobj = findObjectByCatalogId(catId);
840  Assert(dobj == NULL || dobj->objType == DO_FUNC);
841  return (FuncInfo *) dobj;
842 }

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

887 {
888  CatalogId catId;
889  DumpableObject *dobj;
890 
891  catId.tableoid = NamespaceRelationId;
892  catId.oid = oid;
893  dobj = findObjectByCatalogId(catId);
894  Assert(dobj == NULL || dobj->objType == DO_NAMESPACE);
895  return (NamespaceInfo *) dobj;
896 }

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

693 {
694  CatalogIdMapEntry *entry;
695 
696  if (catalogIdHash == NULL)
697  return NULL; /* no objects exist yet */
698 
699  entry = catalogid_lookup(catalogIdHash, catalogId);
700  if (entry == NULL)
701  return NULL;
702  return entry->dobj;
703 }

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

680 {
681  if (dumpId <= 0 || dumpId >= allocedDumpIds)
682  return NULL; /* out of range? */
683  return dumpIdMap[dumpId];
684 }

References allocedDumpIds, and dumpIdMap.

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

◆ findOprByOid()

OprInfo* findOprByOid ( Oid  oid)

Definition at line 850 of file common.c.

851 {
852  CatalogId catId;
853  DumpableObject *dobj;
854 
855  catId.tableoid = OperatorRelationId;
856  catId.oid = oid;
857  dobj = findObjectByCatalogId(catId);
858  Assert(dobj == NULL || dobj->objType == DO_OPERATOR);
859  return (OprInfo *) dobj;
860 }

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

Referenced by getFormattedOperatorName().

◆ findOwningExtension()

ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 965 of file common.c.

966 {
967  CatalogIdMapEntry *entry;
968 
969  if (catalogIdHash == NULL)
970  return NULL; /* no objects exist yet */
971 
972  entry = catalogid_lookup(catalogIdHash, catalogId);
973  if (entry == NULL)
974  return NULL;
975  return entry->ext;
976 }

References catalogIdHash, and _catalogIdMapEntry::ext.

Referenced by checkExtensionMembership().

◆ findPublicationByOid()

PublicationInfo* findPublicationByOid ( Oid  oid)

Definition at line 922 of file common.c.

923 {
924  CatalogId catId;
925  DumpableObject *dobj;
926 
927  catId.tableoid = PublicationRelationId;
928  catId.oid = oid;
929  dobj = findObjectByCatalogId(catId);
930  Assert(dobj == NULL || dobj->objType == DO_PUBLICATION);
931  return (PublicationInfo *) dobj;
932 }

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

778 {
779  CatalogId catId;
780  DumpableObject *dobj;
781 
782  catId.tableoid = RelationRelationId;
783  catId.oid = oid;
784  dobj = findObjectByCatalogId(catId);
785  Assert(dobj == NULL || dobj->objType == DO_TABLE);
786  return (TableInfo *) dobj;
787 }

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

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

◆ findTypeByOid()

TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 813 of file common.c.

814 {
815  CatalogId catId;
816  DumpableObject *dobj;
817 
818  catId.tableoid = TypeRelationId;
819  catId.oid = oid;
820  dobj = findObjectByCatalogId(catId);
821  Assert(dobj == NULL ||
822  dobj->objType == DO_TYPE || dobj->objType == DO_DUMMY_TYPE);
823  return (TypeInfo *) dobj;
824 }

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 5651 of file pg_dump.c.

5652 {
5653  PGresult *res;
5654  int ntups;
5655  int i;
5656  PQExpBuffer query;
5657  AccessMethodInfo *aminfo;
5658  int i_tableoid;
5659  int i_oid;
5660  int i_amname;
5661  int i_amhandler;
5662  int i_amtype;
5663 
5664  /* Before 9.6, there are no user-defined access methods */
5665  if (fout->remoteVersion < 90600)
5666  {
5667  *numAccessMethods = 0;
5668  return NULL;
5669  }
5670 
5671  query = createPQExpBuffer();
5672 
5673  /* Select all access methods from pg_am table */
5674  appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, amtype, "
5675  "amhandler::pg_catalog.regproc AS amhandler "
5676  "FROM pg_am");
5677 
5678  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5679 
5680  ntups = PQntuples(res);
5681  *numAccessMethods = ntups;
5682 
5683  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
5684 
5685  i_tableoid = PQfnumber(res, "tableoid");
5686  i_oid = PQfnumber(res, "oid");
5687  i_amname = PQfnumber(res, "amname");
5688  i_amhandler = PQfnumber(res, "amhandler");
5689  i_amtype = PQfnumber(res, "amtype");
5690 
5691  for (i = 0; i < ntups; i++)
5692  {
5693  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
5694  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5695  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5696  AssignDumpId(&aminfo[i].dobj);
5697  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
5698  aminfo[i].dobj.namespace = NULL;
5699  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
5700  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
5701 
5702  /* Decide whether we want to dump it */
5703  selectDumpableAccessMethod(&(aminfo[i]), fout);
5704  }
5705 
5706  PQclear(res);
5707 
5708  destroyPQExpBuffer(query);
5709 
5710  return aminfo;
5711 }
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:595
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3310
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3705
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3418
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:1899
#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 5856 of file pg_dump.c.

5857 {
5858  DumpOptions *dopt = fout->dopt;
5859  PGresult *res;
5860  int ntups;
5861  int i;
5862  PQExpBuffer query = createPQExpBuffer();
5863  AggInfo *agginfo;
5864  int i_tableoid;
5865  int i_oid;
5866  int i_aggname;
5867  int i_aggnamespace;
5868  int i_pronargs;
5869  int i_proargtypes;
5870  int i_proowner;
5871  int i_aggacl;
5872  int i_acldefault;
5873 
5874  /*
5875  * Find all interesting aggregates. See comment in getFuncs() for the
5876  * rationale behind the filtering logic.
5877  */
5878  if (fout->remoteVersion >= 90600)
5879  {
5880  const char *agg_check;
5881 
5882  agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
5883  : "p.proisagg");
5884 
5885  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5886  "p.proname AS aggname, "
5887  "p.pronamespace AS aggnamespace, "
5888  "p.pronargs, p.proargtypes, "
5889  "p.proowner, "
5890  "p.proacl AS aggacl, "
5891  "acldefault('f', p.proowner) AS acldefault "
5892  "FROM pg_proc p "
5893  "LEFT JOIN pg_init_privs pip ON "
5894  "(p.oid = pip.objoid "
5895  "AND pip.classoid = 'pg_proc'::regclass "
5896  "AND pip.objsubid = 0) "
5897  "WHERE %s AND ("
5898  "p.pronamespace != "
5899  "(SELECT oid FROM pg_namespace "
5900  "WHERE nspname = 'pg_catalog') OR "
5901  "p.proacl IS DISTINCT FROM pip.initprivs",
5902  agg_check);
5903  if (dopt->binary_upgrade)
5904  appendPQExpBufferStr(query,
5905  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5906  "classid = 'pg_proc'::regclass AND "
5907  "objid = p.oid AND "
5908  "refclassid = 'pg_extension'::regclass AND "
5909  "deptype = 'e')");
5910  appendPQExpBufferChar(query, ')');
5911  }
5912  else
5913  {
5914  appendPQExpBufferStr(query, "SELECT tableoid, oid, proname AS aggname, "
5915  "pronamespace AS aggnamespace, "
5916  "pronargs, proargtypes, "
5917  "proowner, "
5918  "proacl AS aggacl, "
5919  "acldefault('f', proowner) AS acldefault "
5920  "FROM pg_proc p "
5921  "WHERE proisagg AND ("
5922  "pronamespace != "
5923  "(SELECT oid FROM pg_namespace "
5924  "WHERE nspname = 'pg_catalog')");
5925  if (dopt->binary_upgrade)
5926  appendPQExpBufferStr(query,
5927  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5928  "classid = 'pg_proc'::regclass AND "
5929  "objid = p.oid AND "
5930  "refclassid = 'pg_extension'::regclass AND "
5931  "deptype = 'e')");
5932  appendPQExpBufferChar(query, ')');
5933  }
5934 
5935  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5936 
5937  ntups = PQntuples(res);
5938  *numAggs = ntups;
5939 
5940  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5941 
5942  i_tableoid = PQfnumber(res, "tableoid");
5943  i_oid = PQfnumber(res, "oid");
5944  i_aggname = PQfnumber(res, "aggname");
5945  i_aggnamespace = PQfnumber(res, "aggnamespace");
5946  i_pronargs = PQfnumber(res, "pronargs");
5947  i_proargtypes = PQfnumber(res, "proargtypes");
5948  i_proowner = PQfnumber(res, "proowner");
5949  i_aggacl = PQfnumber(res, "aggacl");
5950  i_acldefault = PQfnumber(res, "acldefault");
5951 
5952  for (i = 0; i < ntups; i++)
5953  {
5954  agginfo[i].aggfn.dobj.objType = DO_AGG;
5955  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5956  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5957  AssignDumpId(&agginfo[i].aggfn.dobj);
5958  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5959  agginfo[i].aggfn.dobj.namespace =
5960  findNamespace(atooid(PQgetvalue(res, i, i_aggnamespace)));
5961  agginfo[i].aggfn.dacl.acl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5962  agginfo[i].aggfn.dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
5963  agginfo[i].aggfn.dacl.privtype = 0;
5964  agginfo[i].aggfn.dacl.initprivs = NULL;
5965  agginfo[i].aggfn.rolname = getRoleName(PQgetvalue(res, i, i_proowner));
5966  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5967  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5968  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5969  if (agginfo[i].aggfn.nargs == 0)
5970  agginfo[i].aggfn.argtypes = NULL;
5971  else
5972  {
5973  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5974  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5975  agginfo[i].aggfn.argtypes,
5976  agginfo[i].aggfn.nargs);
5977  }
5978 
5979  /* Decide whether we want to dump it */
5980  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5981 
5982  /* Mark whether aggregate has an ACL */
5983  if (!PQgetisnull(res, i, i_aggacl))
5984  agginfo[i].aggfn.dobj.components |= DUMP_COMPONENT_ACL;
5985  }
5986 
5987  PQclear(res);
5988 
5989  destroyPQExpBuffer(query);
5990 
5991  return agginfo;
5992 }
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1035
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3730
static const char * getRoleName(const char *roleoid_str)
Definition: pg_dump.c:9315
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1976
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:5178
#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 7965 of file pg_dump.c.

7966 {
7967  PGresult *res;
7968  int ntups;
7969  int i;
7970  PQExpBuffer query = createPQExpBuffer();
7971  CastInfo *castinfo;
7972  int i_tableoid;
7973  int i_oid;
7974  int i_castsource;
7975  int i_casttarget;
7976  int i_castfunc;
7977  int i_castcontext;
7978  int i_castmethod;
7979 
7980  if (fout->remoteVersion >= 140000)
7981  {
7982  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7983  "castsource, casttarget, castfunc, castcontext, "
7984  "castmethod "
7985  "FROM pg_cast c "
7986  "WHERE NOT EXISTS ( "
7987  "SELECT 1 FROM pg_range r "
7988  "WHERE c.castsource = r.rngtypid "
7989  "AND c.casttarget = r.rngmultitypid "
7990  ") "
7991  "ORDER BY 3,4");
7992  }
7993  else
7994  {
7995  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7996  "castsource, casttarget, castfunc, castcontext, "
7997  "castmethod "
7998  "FROM pg_cast ORDER BY 3,4");
7999  }
8000 
8001  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8002 
8003  ntups = PQntuples(res);
8004 
8005  *numCasts = ntups;
8006 
8007  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
8008 
8009  i_tableoid = PQfnumber(res, "tableoid");
8010  i_oid = PQfnumber(res, "oid");
8011  i_castsource = PQfnumber(res, "castsource");
8012  i_casttarget = PQfnumber(res, "casttarget");
8013  i_castfunc = PQfnumber(res, "castfunc");
8014  i_castcontext = PQfnumber(res, "castcontext");
8015  i_castmethod = PQfnumber(res, "castmethod");
8016 
8017  for (i = 0; i < ntups; i++)
8018  {
8019  PQExpBufferData namebuf;
8020  TypeInfo *sTypeInfo;
8021  TypeInfo *tTypeInfo;
8022 
8023  castinfo[i].dobj.objType = DO_CAST;
8024  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8025  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8026  AssignDumpId(&castinfo[i].dobj);
8027  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
8028  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
8029  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
8030  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
8031  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
8032 
8033  /*
8034  * Try to name cast as concatenation of typnames. This is only used
8035  * for purposes of sorting. If we fail to find either type, the name
8036  * will be an empty string.
8037  */
8038  initPQExpBuffer(&namebuf);
8039  sTypeInfo = findTypeByOid(castinfo[i].castsource);
8040  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
8041  if (sTypeInfo && tTypeInfo)
8042  appendPQExpBuffer(&namebuf, "%s %s",
8043  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
8044  castinfo[i].dobj.name = namebuf.data;
8045 
8046  /* Decide whether we want to dump it */
8047  selectDumpableCast(&(castinfo[i]), fout);
8048  }
8049 
8050  PQclear(res);
8051 
8052  destroyPQExpBuffer(query);
8053 
8054  return castinfo;
8055 }
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:813
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:1841
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
char castmethod
Definition: pg_dump.h:505
Oid casttarget
Definition: pg_dump.h:502
char castcontext
Definition: pg_dump.h:504
DumpableObject dobj
Definition: pg_dump.h:500
Oid castsource
Definition: pg_dump.h:501
Oid castfunc
Definition: pg_dump.h:503
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 5515 of file pg_dump.c.

5516 {
5517  PGresult *res;
5518  int ntups;
5519  int i;
5520  PQExpBuffer query;
5521  CollInfo *collinfo;
5522  int i_tableoid;
5523  int i_oid;
5524  int i_collname;
5525  int i_collnamespace;
5526  int i_collowner;
5527 
5528  query = createPQExpBuffer();
5529 
5530  /*
5531  * find all collations, including builtin collations; we filter out
5532  * system-defined collations at dump-out time.
5533  */
5534 
5535  appendPQExpBufferStr(query, "SELECT tableoid, oid, collname, "
5536  "collnamespace, "
5537  "collowner "
5538  "FROM pg_collation");
5539 
5540  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5541 
5542  ntups = PQntuples(res);
5543  *numCollations = ntups;
5544 
5545  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
5546 
5547  i_tableoid = PQfnumber(res, "tableoid");
5548  i_oid = PQfnumber(res, "oid");
5549  i_collname = PQfnumber(res, "collname");
5550  i_collnamespace = PQfnumber(res, "collnamespace");
5551  i_collowner = PQfnumber(res, "collowner");
5552 
5553  for (i = 0; i < ntups; i++)
5554  {
5555  collinfo[i].dobj.objType = DO_COLLATION;
5556  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5557  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5558  AssignDumpId(&collinfo[i].dobj);
5559  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
5560  collinfo[i].dobj.namespace =
5561  findNamespace(atooid(PQgetvalue(res, i, i_collnamespace)));
5562  collinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_collowner));
5563 
5564  /* Decide whether we want to dump it */
5565  selectDumpableObject(&(collinfo[i].dobj), fout);
5566  }
5567 
5568  PQclear(res);
5569 
5570  destroyPQExpBuffer(query);
5571 
5572  return collinfo;
5573 }
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 7137 of file pg_dump.c.

7138 {
7139  PQExpBuffer query = createPQExpBuffer();
7140  PQExpBuffer tbloids = createPQExpBuffer();
7141  PGresult *res;
7142  int ntups;
7143  int curtblindx;
7144  TableInfo *tbinfo = NULL;
7145  ConstraintInfo *constrinfo;
7146  int i_contableoid,
7147  i_conoid,
7148  i_conrelid,
7149  i_conname,
7150  i_confrelid,
7151  i_conindid,
7152  i_condef;
7153 
7154  /*
7155  * We want to perform just one query against pg_constraint. However, we
7156  * mustn't try to select every row of the catalog and then sort it out on
7157  * the client side, because some of the server-side functions we need
7158  * would be unsafe to apply to tables we don't have lock on. Hence, we
7159  * build an array of the OIDs of tables we care about (and now have lock
7160  * on!), and use a WHERE clause to constrain which rows are selected.
7161  */
7162  appendPQExpBufferChar(tbloids, '{');
7163  for (int i = 0; i < numTables; i++)
7164  {
7165  TableInfo *tinfo = &tblinfo[i];
7166 
7167  /*
7168  * For partitioned tables, foreign keys have no triggers so they must
7169  * be included anyway in case some foreign keys are defined.
7170  */
7171  if ((!tinfo->hastriggers &&
7172  tinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7173  !(tinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
7174  continue;
7175 
7176  /* OK, we need info for this table */
7177  if (tbloids->len > 1) /* do we have more than the '{'? */
7178  appendPQExpBufferChar(tbloids, ',');
7179  appendPQExpBuffer(tbloids, "%u", tinfo->dobj.catId.oid);
7180  }
7181  appendPQExpBufferChar(tbloids, '}');
7182 
7183  appendPQExpBufferStr(query,
7184  "SELECT c.tableoid, c.oid, "
7185  "conrelid, conname, confrelid, ");
7186  if (fout->remoteVersion >= 110000)
7187  appendPQExpBufferStr(query, "conindid, ");
7188  else
7189  appendPQExpBufferStr(query, "0 AS conindid, ");
7190  appendPQExpBuffer(query,
7191  "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
7192  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7193  "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
7194  "WHERE contype = 'f' ",
7195  tbloids->data);
7196  if (fout->remoteVersion >= 110000)
7197  appendPQExpBufferStr(query,
7198  "AND conparentid = 0 ");
7199  appendPQExpBufferStr(query,
7200  "ORDER BY conrelid, conname");
7201 
7202  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7203 
7204  ntups = PQntuples(res);
7205 
7206  i_contableoid = PQfnumber(res, "tableoid");
7207  i_conoid = PQfnumber(res, "oid");
7208  i_conrelid = PQfnumber(res, "conrelid");
7209  i_conname = PQfnumber(res, "conname");
7210  i_confrelid = PQfnumber(res, "confrelid");
7211  i_conindid = PQfnumber(res, "conindid");
7212  i_condef = PQfnumber(res, "condef");
7213 
7214  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7215 
7216  curtblindx = -1;
7217  for (int j = 0; j < ntups; j++)
7218  {
7219  Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
7220  TableInfo *reftable;
7221 
7222  /*
7223  * Locate the associated TableInfo; we rely on tblinfo[] being in OID
7224  * order.
7225  */
7226  if (tbinfo == NULL || tbinfo->dobj.catId.oid != conrelid)
7227  {
7228  while (++curtblindx < numTables)
7229  {
7230  tbinfo = &tblinfo[curtblindx];
7231  if (tbinfo->dobj.catId.oid == conrelid)
7232  break;
7233  }
7234  if (curtblindx >= numTables)
7235  pg_fatal("unrecognized table OID %u", conrelid);
7236  }
7237 
7238  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
7239  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7240  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7241  AssignDumpId(&constrinfo[j].dobj);
7242  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7243  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7244  constrinfo[j].contable = tbinfo;
7245  constrinfo[j].condomain = NULL;
7246  constrinfo[j].contype = 'f';
7247  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7248  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
7249  constrinfo[j].conindex = 0;
7250  constrinfo[j].condeferrable = false;
7251  constrinfo[j].condeferred = false;
7252  constrinfo[j].conislocal = true;
7253  constrinfo[j].separate = true;
7254 
7255  /*
7256  * Restoring an FK that points to a partitioned table requires that
7257  * all partition indexes have been attached beforehand. Ensure that
7258  * happens by making the constraint depend on each index partition
7259  * attach object.
7260  */
7261  reftable = findTableByOid(constrinfo[j].confrelid);
7262  if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
7263  {
7264  Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
7265 
7266  if (indexOid != InvalidOid)
7267  {
7268  for (int k = 0; k < reftable->numIndexes; k++)
7269  {
7270  IndxInfo *refidx;
7271 
7272  /* not our index? */
7273  if (reftable->indexes[k].dobj.catId.oid != indexOid)
7274  continue;
7275 
7276  refidx = &reftable->indexes[k];
7277  addConstrChildIdxDeps(&constrinfo[j].dobj, refidx);
7278  break;
7279  }
7280  }
7281  }
7282  }
7283 
7284  PQclear(res);
7285 
7286  destroyPQExpBuffer(query);
7287  destroyPQExpBuffer(tbloids);
7288 }
TableInfo * findTableByOid(Oid oid)
Definition: common.c:777
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:7302
TypeInfo * condomain
Definition: pg_dump.h:476
TableInfo * contable
Definition: pg_dump.h:475
bool condeferred
Definition: pg_dump.h:482
bool conislocal
Definition: pg_dump.h:483
DumpableObject dobj
Definition: pg_dump.h:474
DumpId conindex
Definition: pg_dump.h:480
bool condeferrable
Definition: pg_dump.h:481
char * condef
Definition: pg_dump.h:478
DumpableObject dobj
Definition: pg_dump.h:388
struct _indxInfo * indexes
Definition: pg_dump.h:357
DumpableObject dobj
Definition: pg_dump.h:283
char relkind
Definition: pg_dump.h:286
int numIndexes
Definition: pg_dump.h:356

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 5583 of file pg_dump.c.

5584 {
5585  PGresult *res;
5586  int ntups;
5587  int i;
5588  PQExpBuffer query;
5589  ConvInfo *convinfo;
5590  int i_tableoid;
5591  int i_oid;
5592  int i_conname;
5593  int i_connamespace;
5594  int i_conowner;
5595 
5596  query = createPQExpBuffer();
5597 
5598  /*
5599  * find all conversions, including builtin conversions; we filter out
5600  * system-defined conversions at dump-out time.
5601  */
5602 
5603  appendPQExpBufferStr(query, "SELECT tableoid, oid, conname, "
5604  "connamespace, "
5605  "conowner "
5606  "FROM pg_conversion");
5607 
5608  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5609 
5610  ntups = PQntuples(res);
5611  *numConversions = ntups;
5612 
5613  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
5614 
5615  i_tableoid = PQfnumber(res, "tableoid");
5616  i_oid = PQfnumber(res, "oid");
5617  i_conname = PQfnumber(res, "conname");
5618  i_connamespace = PQfnumber(res, "connamespace");
5619  i_conowner = PQfnumber(res, "conowner");
5620 
5621  for (i = 0; i < ntups; i++)
5622  {
5623  convinfo[i].dobj.objType = DO_CONVERSION;
5624  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5625  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5626  AssignDumpId(&convinfo[i].dobj);
5627  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
5628  convinfo[i].dobj.namespace =
5629  findNamespace(atooid(PQgetvalue(res, i, i_connamespace)));
5630  convinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_conowner));
5631 
5632  /* Decide whether we want to dump it */
5633  selectDumpableObject(&(convinfo[i].dobj), fout);
5634  }
5635 
5636  PQclear(res);
5637 
5638  destroyPQExpBuffer(query);
5639 
5640  return convinfo;
5641 }
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 9215 of file pg_dump.c.

9216 {
9217  DumpOptions *dopt = fout->dopt;
9218  DefaultACLInfo *daclinfo;
9219  PQExpBuffer query;
9220  PGresult *res;
9221  int i_oid;
9222  int i_tableoid;
9223  int i_defaclrole;
9224  int i_defaclnamespace;
9225  int i_defaclobjtype;
9226  int i_defaclacl;
9227  int i_acldefault;
9228  int i,
9229  ntups;
9230 
9231  query = createPQExpBuffer();
9232 
9233  /*
9234  * Global entries (with defaclnamespace=0) replace the hard-wired default
9235  * ACL for their object type. We should dump them as deltas from the
9236  * default ACL, since that will be used as a starting point for
9237  * interpreting the ALTER DEFAULT PRIVILEGES commands. On the other hand,
9238  * non-global entries can only add privileges not revoke them. We must
9239  * dump those as-is (i.e., as deltas from an empty ACL).
9240  *
9241  * We can use defaclobjtype as the object type for acldefault(), except
9242  * for the case of 'S' (DEFACLOBJ_SEQUENCE) which must be converted to
9243  * 's'.
9244  */
9245  appendPQExpBufferStr(query,
9246  "SELECT oid, tableoid, "
9247  "defaclrole, "
9248  "defaclnamespace, "
9249  "defaclobjtype, "
9250  "defaclacl, "
9251  "CASE WHEN defaclnamespace = 0 THEN "
9252  "acldefault(CASE WHEN defaclobjtype = 'S' "
9253  "THEN 's'::\"char\" ELSE defaclobjtype END, "
9254  "defaclrole) ELSE '{}' END AS acldefault "
9255  "FROM pg_default_acl");
9256 
9257  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9258 
9259  ntups = PQntuples(res);
9260  *numDefaultACLs = ntups;
9261 
9262  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9263 
9264  i_oid = PQfnumber(res, "oid");
9265  i_tableoid = PQfnumber(res, "tableoid");
9266  i_defaclrole = PQfnumber(res, "defaclrole");
9267  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9268  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9269  i_defaclacl = PQfnumber(res, "defaclacl");
9270  i_acldefault = PQfnumber(res, "acldefault");
9271 
9272  for (i = 0; i < ntups; i++)
9273  {
9274  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9275 
9276  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9277  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9278  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9279  AssignDumpId(&daclinfo[i].dobj);
9280  /* cheesy ... is it worth coming up with a better object name? */
9281  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9282 
9283  if (nspid != InvalidOid)
9284  daclinfo[i].dobj.namespace = findNamespace(nspid);
9285  else
9286  daclinfo[i].dobj.namespace = NULL;
9287 
9288  daclinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9289  daclinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9290  daclinfo[i].dacl.privtype = 0;
9291  daclinfo[i].dacl.initprivs = NULL;
9292  daclinfo[i].defaclrole = getRoleName(PQgetvalue(res, i, i_defaclrole));
9293  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9294 
9295  /* Default ACLs are ACLs, of course */
9296  daclinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9297 
9298  /* Decide whether we want to dump it */
9299  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9300  }
9301 
9302  PQclear(res);
9303 
9304  destroyPQExpBuffer(query);
9305 
9306  return daclinfo;
9307 }
int nspid
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition: pg_dump.c:1819
DumpableObject dobj
Definition: pg_dump.h:579
DumpableAcl dacl
Definition: pg_dump.h:580
const char * defaclrole
Definition: pg_dump.h:581
char defaclobjtype
Definition: pg_dump.h:582
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 711 of file common.c.

712 {
713  int i,
714  j;
715 
717  j = 0;
718  for (i = 1; i < allocedDumpIds; i++)
719  {
720  if (dumpIdMap[i])
721  (*objs)[j++] = dumpIdMap[i];
722  }
723  *numObjs = j;
724 }

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

Referenced by getTableDataFKConstraints(), and main().

◆ getEventTriggers()

EventTriggerInfo* getEventTriggers ( Archive fout,
int *  numEventTriggers 
)

Definition at line 7788 of file pg_dump.c.

7789 {
7790  int i;
7791  PQExpBuffer query;
7792  PGresult *res;
7793  EventTriggerInfo *evtinfo;
7794  int i_tableoid,
7795  i_oid,
7796  i_evtname,
7797  i_evtevent,
7798  i_evtowner,
7799  i_evttags,
7800  i_evtfname,
7801  i_evtenabled;
7802  int ntups;
7803 
7804  /* Before 9.3, there are no event triggers */
7805  if (fout->remoteVersion < 90300)
7806  {
7807  *numEventTriggers = 0;
7808  return NULL;
7809  }
7810 
7811  query = createPQExpBuffer();
7812 
7813  appendPQExpBufferStr(query,
7814  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
7815  "evtevent, evtowner, "
7816  "array_to_string(array("
7817  "select quote_literal(x) "
7818  " from unnest(evttags) as t(x)), ', ') as evttags, "
7819  "e.evtfoid::regproc as evtfname "
7820  "FROM pg_event_trigger e "
7821  "ORDER BY e.oid");
7822 
7823  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7824 
7825  ntups = PQntuples(res);
7826 
7827  *numEventTriggers = ntups;
7828 
7829  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
7830 
7831  i_tableoid = PQfnumber(res, "tableoid");
7832  i_oid = PQfnumber(res, "oid");
7833  i_evtname = PQfnumber(res, "evtname");
7834  i_evtevent = PQfnumber(res, "evtevent");
7835  i_evtowner = PQfnumber(res, "evtowner");
7836  i_evttags = PQfnumber(res, "evttags");
7837  i_evtfname = PQfnumber(res, "evtfname");
7838  i_evtenabled = PQfnumber(res, "evtenabled");
7839 
7840  for (i = 0; i < ntups; i++)
7841  {
7842  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
7843  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7844  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7845  AssignDumpId(&evtinfo[i].dobj);
7846  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
7847  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
7848  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
7849  evtinfo[i].evtowner = getRoleName(PQgetvalue(res, i, i_evtowner));
7850  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
7851  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
7852  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
7853 
7854  /* Decide whether we want to dump it */
7855  selectDumpableObject(&(evtinfo[i].dobj), fout);
7856  }
7857 
7858  PQclear(res);
7859 
7860  destroyPQExpBuffer(query);
7861 
7862  return evtinfo;
7863 }
char * evtevent
Definition: pg_dump.h:457
char * evtfname
Definition: pg_dump.h:460
char evtenabled
Definition: pg_dump.h:461
char * evtname
Definition: pg_dump.h:456
const char * evtowner
Definition: pg_dump.h:458
char * evttags
Definition: pg_dump.h:459
DumpableObject dobj
Definition: pg_dump.h:455

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 7065 of file pg_dump.c.

7066 {
7067  PQExpBuffer query;
7068  PGresult *res;
7069  StatsExtInfo *statsextinfo;
7070  int ntups;
7071  int i_tableoid;
7072  int i_oid;
7073  int i_stxname;
7074  int i_stxnamespace;
7075  int i_stxowner;
7076  int i_stattarget;
7077  int i;
7078 
7079  /* Extended statistics were new in v10 */
7080  if (fout->remoteVersion < 100000)
7081  return;
7082 
7083  query = createPQExpBuffer();
7084 
7085  if (fout->remoteVersion < 130000)
7086  appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
7087  "stxnamespace, stxowner, (-1) AS stxstattarget "
7088  "FROM pg_catalog.pg_statistic_ext");
7089  else
7090  appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
7091  "stxnamespace, stxowner, stxstattarget "
7092  "FROM pg_catalog.pg_statistic_ext");
7093 
7094  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7095 
7096  ntups = PQntuples(res);
7097 
7098  i_tableoid = PQfnumber(res, "tableoid");
7099  i_oid = PQfnumber(res, "oid");
7100  i_stxname = PQfnumber(res, "stxname");
7101  i_stxnamespace = PQfnumber(res, "stxnamespace");
7102  i_stxowner = PQfnumber(res, "stxowner");
7103  i_stattarget = PQfnumber(res, "stxstattarget");
7104 
7105  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
7106 
7107  for (i = 0; i < ntups; i++)
7108  {
7109  statsextinfo[i].dobj.objType = DO_STATSEXT;
7110  statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7111  statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7112  AssignDumpId(&statsextinfo[i].dobj);
7113  statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
7114  statsextinfo[i].dobj.namespace =
7115  findNamespace(atooid(PQgetvalue(res, i, i_stxnamespace)));
7116  statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
7117  statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
7118 
7119  /* Decide whether we want to dump it */
7120  selectDumpableObject(&(statsextinfo[i].dobj), fout);
7121  }
7122 
7123  PQclear(res);
7124  destroyPQExpBuffer(query);
7125 }
int stattarget
Definition: pg_dump.h:420
const char * rolname
Definition: pg_dump.h:419
DumpableObject dobj
Definition: pg_dump.h:418

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 17506 of file pg_dump.c.

17508 {
17509  PQExpBuffer query;
17510  PGresult *res;
17511  int ntups,
17512  i;
17513  int i_classid,
17514  i_objid,
17515  i_refobjid;
17516  ExtensionInfo *ext;
17517 
17518  /* Nothing to do if no extensions */
17519  if (numExtensions == 0)
17520  return;
17521 
17522  query = createPQExpBuffer();
17523 
17524  /* refclassid constraint is redundant but may speed the search */
17525  appendPQExpBufferStr(query, "SELECT "
17526  "classid, objid, refobjid "
17527  "FROM pg_depend "
17528  "WHERE refclassid = 'pg_extension'::regclass "
17529  "AND deptype = 'e' "
17530  "ORDER BY 3");
17531 
17532  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
17533 
17534  ntups = PQntuples(res);
17535 
17536  i_classid = PQfnumber(res, "classid");
17537  i_objid = PQfnumber(res, "objid");
17538  i_refobjid = PQfnumber(res, "refobjid");
17539 
17540  /*
17541  * Since we ordered the SELECT by referenced ID, we can expect that
17542  * multiple entries for the same extension will appear together; this
17543  * saves on searches.
17544  */
17545  ext = NULL;
17546 
17547  for (i = 0; i < ntups; i++)
17548  {
17549  CatalogId objId;
17550  Oid extId;
17551 
17552  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
17553  objId.oid = atooid(PQgetvalue(res, i, i_objid));
17554  extId = atooid(PQgetvalue(res, i, i_refobjid));
17555 
17556  if (ext == NULL ||
17557  ext->dobj.catId.oid != extId)
17558  ext = findExtensionByOid(extId);
17559 
17560  if (ext == NULL)
17561  {
17562  /* shouldn't happen */
17563  pg_log_warning("could not find referenced extension %u", extId);
17564  continue;
17565  }
17566 
17567  recordExtensionMembership(objId, ext);
17568  }
17569 
17570  PQclear(res);
17571 
17572  destroyPQExpBuffer(query);
17573 }
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition: common.c:941
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:904
#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 5196 of file pg_dump.c.

5197 {
5198  DumpOptions *dopt = fout->dopt;
5199  PGresult *res;
5200  int ntups;
5201  int i;
5202  PQExpBuffer query;
5203  ExtensionInfo *extinfo;
5204  int i_tableoid;
5205  int i_oid;
5206  int i_extname;
5207  int i_nspname;
5208  int i_extrelocatable;
5209  int i_extversion;
5210  int i_extconfig;
5211  int i_extcondition;
5212 
5213  query = createPQExpBuffer();
5214 
5215  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
5216  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
5217  "FROM pg_extension x "
5218  "JOIN pg_namespace n ON n.oid = x.extnamespace");
5219 
5220  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5221 
5222  ntups = PQntuples(res);
5223 
5224  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
5225 
5226  i_tableoid = PQfnumber(res, "tableoid");
5227  i_oid = PQfnumber(res, "oid");
5228  i_extname = PQfnumber(res, "extname");
5229  i_nspname = PQfnumber(res, "nspname");
5230  i_extrelocatable = PQfnumber(res, "extrelocatable");
5231  i_extversion = PQfnumber(res, "extversion");
5232  i_extconfig = PQfnumber(res, "extconfig");
5233  i_extcondition = PQfnumber(res, "extcondition");
5234 
5235  for (i = 0; i < ntups; i++)
5236  {
5237  extinfo[i].dobj.objType = DO_EXTENSION;
5238  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5239  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5240  AssignDumpId(&extinfo[i].dobj);
5241  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
5242  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
5243  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
5244  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
5245  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
5246  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
5247 
5248  /* Decide whether we want to dump it */
5249  selectDumpableExtension(&(extinfo[i]), dopt);
5250  }
5251 
5252  PQclear(res);
5253  destroyPQExpBuffer(query);
5254 
5255  *numExtensions = ntups;
5256 
5257  return extinfo;
5258 }
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:1927
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 9031 of file pg_dump.c.

9032 {
9033  PGresult *res;
9034  int ntups;
9035  int i;
9036  PQExpBuffer query;
9037  FdwInfo *fdwinfo;
9038  int i_tableoid;
9039  int i_oid;
9040  int i_fdwname;
9041  int i_fdwowner;
9042  int i_fdwhandler;
9043  int i_fdwvalidator;
9044  int i_fdwacl;
9045  int i_acldefault;
9046  int i_fdwoptions;
9047 
9048  query = createPQExpBuffer();
9049 
9050  appendPQExpBufferStr(query, "SELECT tableoid, oid, fdwname, "
9051  "fdwowner, "
9052  "fdwhandler::pg_catalog.regproc, "
9053  "fdwvalidator::pg_catalog.regproc, "
9054  "fdwacl, "
9055  "acldefault('F', fdwowner) AS acldefault, "
9056  "array_to_string(ARRAY("
9057  "SELECT quote_ident(option_name) || ' ' || "
9058  "quote_literal(option_value) "
9059  "FROM pg_options_to_table(fdwoptions) "
9060  "ORDER BY option_name"
9061  "), E',\n ') AS fdwoptions "
9062  "FROM pg_foreign_data_wrapper");
9063 
9064  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9065 
9066  ntups = PQntuples(res);
9067  *numForeignDataWrappers = ntups;
9068 
9069  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
9070 
9071  i_tableoid = PQfnumber(res, "tableoid");
9072  i_oid = PQfnumber(res, "oid");
9073  i_fdwname = PQfnumber(res, "fdwname");
9074  i_fdwowner = PQfnumber(res, "fdwowner");
9075  i_fdwhandler = PQfnumber(res, "fdwhandler");
9076  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
9077  i_fdwacl = PQfnumber(res, "fdwacl");
9078  i_acldefault = PQfnumber(res, "acldefault");
9079  i_fdwoptions = PQfnumber(res, "fdwoptions");
9080 
9081  for (i = 0; i < ntups; i++)
9082  {
9083  fdwinfo[i].dobj.objType = DO_FDW;
9084  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9085  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9086  AssignDumpId(&fdwinfo[i].dobj);
9087  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
9088  fdwinfo[i].dobj.namespace = NULL;
9089  fdwinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
9090  fdwinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9091  fdwinfo[i].dacl.privtype = 0;
9092  fdwinfo[i].dacl.initprivs = NULL;
9093  fdwinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_fdwowner));
9094  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
9095  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
9096  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
9097 
9098  /* Decide whether we want to dump it */
9099  selectDumpableObject(&(fdwinfo[i].dobj), fout);
9100 
9101  /* Mark whether FDW has an ACL */
9102  if (!PQgetisnull(res, i, i_fdwacl))
9103  fdwinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9104  }
9105 
9106  PQclear(res);
9107 
9108  destroyPQExpBuffer(query);
9109 
9110  return fdwinfo;
9111 }
char * fdwhandler
Definition: pg_dump.h:561
const char * rolname
Definition: pg_dump.h:560
char * fdwvalidator
Definition: pg_dump.h:562
char * fdwoptions
Definition: pg_dump.h:563
DumpableAcl dacl
Definition: pg_dump.h:559
DumpableObject dobj
Definition: pg_dump.h:558

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 9121 of file pg_dump.c.

9122 {
9123  PGresult *res;
9124  int ntups;
9125  int i;
9126  PQExpBuffer query;
9127  ForeignServerInfo *srvinfo;
9128  int i_tableoid;
9129  int i_oid;
9130  int i_srvname;
9131  int i_srvowner;
9132  int i_srvfdw;
9133  int i_srvtype;
9134  int i_srvversion;
9135  int i_srvacl;
9136  int i_acldefault;
9137  int i_srvoptions;
9138 
9139  query = createPQExpBuffer();
9140 
9141  appendPQExpBufferStr(query, "SELECT tableoid, oid, srvname, "
9142  "srvowner, "
9143  "srvfdw, srvtype, srvversion, srvacl, "
9144  "acldefault('S', srvowner) AS acldefault, "
9145  "array_to_string(ARRAY("
9146  "SELECT quote_ident(option_name) || ' ' || "
9147  "quote_literal(option_value) "
9148  "FROM pg_options_to_table(srvoptions) "
9149  "ORDER BY option_name"
9150  "), E',\n ') AS srvoptions "
9151  "FROM pg_foreign_server");
9152 
9153  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9154 
9155  ntups = PQntuples(res);
9156  *numForeignServers = ntups;
9157 
9158  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
9159 
9160  i_tableoid = PQfnumber(res, "tableoid");
9161  i_oid = PQfnumber(res, "oid");
9162  i_srvname = PQfnumber(res, "srvname");
9163  i_srvowner = PQfnumber(res, "srvowner");
9164  i_srvfdw = PQfnumber(res, "srvfdw");
9165  i_srvtype = PQfnumber(res, "srvtype");
9166  i_srvversion = PQfnumber(res, "srvversion");
9167  i_srvacl = PQfnumber(res, "srvacl");
9168  i_acldefault = PQfnumber(res, "acldefault");
9169  i_srvoptions = PQfnumber(res, "srvoptions");
9170 
9171  for (i = 0; i < ntups; i++)
9172  {
9173  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
9174  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9175  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9176  AssignDumpId(&srvinfo[i].dobj);
9177  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
9178  srvinfo[i].dobj.namespace = NULL;
9179  srvinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_srvacl));
9180  srvinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9181  srvinfo[i].dacl.privtype = 0;
9182  srvinfo[i].dacl.initprivs = NULL;
9183  srvinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_srvowner));
9184  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
9185  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
9186  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
9187  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
9188 
9189  /* Decide whether we want to dump it */
9190  selectDumpableObject(&(srvinfo[i].dobj), fout);
9191 
9192  /* Servers have user mappings */
9194 
9195  /* Mark whether server has an ACL */
9196  if (!PQgetisnull(res, i, i_srvacl))
9197  srvinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9198  }
9199 
9200  PQclear(res);
9201 
9202  destroyPQExpBuffer(query);
9203 
9204  return srvinfo;
9205 }
#define DUMP_COMPONENT_USERMAP
Definition: pg_dump.h:102
DumpableAcl dacl
Definition: pg_dump.h:569
char * srvoptions
Definition: pg_dump.h:574
DumpableObject dobj
Definition: pg_dump.h:568
const char * rolname
Definition: pg_dump.h:570
char * srvversion
Definition: pg_dump.h:573

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 6002 of file pg_dump.c.

6003 {
6004  DumpOptions *dopt = fout->dopt;
6005  PGresult *res;
6006  int ntups;
6007  int i;
6008  PQExpBuffer query = createPQExpBuffer();
6009  FuncInfo *finfo;
6010  int i_tableoid;
6011  int i_oid;
6012  int i_proname;
6013  int i_pronamespace;
6014  int i_proowner;
6015  int i_prolang;
6016  int i_pronargs;
6017  int i_proargtypes;
6018  int i_prorettype;
6019  int i_proacl;
6020  int i_acldefault;
6021 
6022  /*
6023  * Find all interesting functions. This is a bit complicated:
6024  *
6025  * 1. Always exclude aggregates; those are handled elsewhere.
6026  *
6027  * 2. Always exclude functions that are internally dependent on something
6028  * else, since presumably those will be created as a result of creating
6029  * the something else. This currently acts only to suppress constructor
6030  * functions for range types. Note this is OK only because the
6031  * constructors don't have any dependencies the range type doesn't have;
6032  * otherwise we might not get creation ordering correct.
6033  *
6034  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
6035  * they're members of extensions and we are in binary-upgrade mode then
6036  * include them, since we want to dump extension members individually in
6037  * that mode. Also, if they are used by casts or transforms then we need
6038  * to gather the information about them, though they won't be dumped if
6039  * they are built-in. Also, in 9.6 and up, include functions in
6040  * pg_catalog if they have an ACL different from what's shown in
6041  * pg_init_privs (so we have to join to pg_init_privs; annoying).
6042  */
6043  if (fout->remoteVersion >= 90600)
6044  {
6045  const char *not_agg_check;
6046 
6047  not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
6048  : "NOT p.proisagg");
6049 
6050  appendPQExpBuffer(query,
6051  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6052  "p.pronargs, p.proargtypes, p.prorettype, "
6053  "p.proacl, "
6054  "acldefault('f', p.proowner) AS acldefault, "
6055  "p.pronamespace, "
6056  "p.proowner "
6057  "FROM pg_proc p "
6058  "LEFT JOIN pg_init_privs pip ON "
6059  "(p.oid = pip.objoid "
6060  "AND pip.classoid = 'pg_proc'::regclass "
6061  "AND pip.objsubid = 0) "
6062  "WHERE %s"
6063  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6064  "WHERE classid = 'pg_proc'::regclass AND "
6065  "objid = p.oid AND deptype = 'i')"
6066  "\n AND ("
6067  "\n pronamespace != "
6068  "(SELECT oid FROM pg_namespace "
6069  "WHERE nspname = 'pg_catalog')"
6070  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6071  "\n WHERE pg_cast.oid > %u "
6072  "\n AND p.oid = pg_cast.castfunc)"
6073  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6074  "\n WHERE pg_transform.oid > %u AND "
6075  "\n (p.oid = pg_transform.trffromsql"
6076  "\n OR p.oid = pg_transform.trftosql))",
6077  not_agg_check,
6080  if (dopt->binary_upgrade)
6081  appendPQExpBufferStr(query,
6082  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6083  "classid = 'pg_proc'::regclass AND "
6084  "objid = p.oid AND "
6085  "refclassid = 'pg_extension'::regclass AND "
6086  "deptype = 'e')");
6087  appendPQExpBufferStr(query,
6088  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
6089  appendPQExpBufferChar(query, ')');
6090  }
6091  else
6092  {
6093  appendPQExpBuffer(query,
6094  "SELECT tableoid, oid, proname, prolang, "
6095  "pronargs, proargtypes, prorettype, proacl, "
6096  "acldefault('f', proowner) AS acldefault, "
6097  "pronamespace, "
6098  "proowner "
6099  "FROM pg_proc p "
6100  "WHERE NOT proisagg"
6101  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6102  "WHERE classid = 'pg_proc'::regclass AND "
6103  "objid = p.oid AND deptype = 'i')"
6104  "\n AND ("
6105  "\n pronamespace != "
6106  "(SELECT oid FROM pg_namespace "
6107  "WHERE nspname = 'pg_catalog')"
6108  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6109  "\n WHERE pg_cast.oid > '%u'::oid"
6110  "\n AND p.oid = pg_cast.castfunc)",
6112 
6113  if (fout->remoteVersion >= 90500)
6114  appendPQExpBuffer(query,
6115  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6116  "\n WHERE pg_transform.oid > '%u'::oid"
6117  "\n AND (p.oid = pg_transform.trffromsql"
6118  "\n OR p.oid = pg_transform.trftosql))",
6120 
6121  if (dopt->binary_upgrade)
6122  appendPQExpBufferStr(query,
6123  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6124  "classid = 'pg_proc'::regclass AND "
6125  "objid = p.oid AND "
6126  "refclassid = 'pg_extension'::regclass AND "
6127  "deptype = 'e')");
6128  appendPQExpBufferChar(query, ')');
6129  }
6130 
6131  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6132 
6133  ntups = PQntuples(res);
6134 
6135  *numFuncs = ntups;
6136 
6137  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
6138 
6139  i_tableoid = PQfnumber(res, "tableoid");
6140  i_oid = PQfnumber(res, "oid");
6141  i_proname = PQfnumber(res, "proname");
6142  i_pronamespace = PQfnumber(res, "pronamespace");
6143  i_proowner = PQfnumber(res, "proowner");
6144  i_prolang = PQfnumber(res, "prolang");
6145  i_pronargs = PQfnumber(res, "pronargs");
6146  i_proargtypes = PQfnumber(res, "proargtypes");
6147  i_prorettype = PQfnumber(res, "prorettype");
6148  i_proacl = PQfnumber(res, "proacl");
6149  i_acldefault = PQfnumber(res, "acldefault");
6150 
6151  for (i = 0; i < ntups; i++)
6152  {
6153  finfo[i].dobj.objType = DO_FUNC;
6154  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6155  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6156  AssignDumpId(&finfo[i].dobj);
6157  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
6158  finfo[i].dobj.namespace =
6159  findNamespace(atooid(PQgetvalue(res, i, i_pronamespace)));
6160  finfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_proacl));
6161  finfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6162  finfo[i].dacl.privtype = 0;
6163  finfo[i].dacl.initprivs = NULL;
6164  finfo[i].rolname = getRoleName(PQgetvalue(res, i, i_proowner));
6165  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
6166  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
6167  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
6168  if (finfo[i].nargs == 0)
6169  finfo[i].argtypes = NULL;
6170  else
6171  {
6172  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
6173  parseOidArray(PQgetvalue(res, i, i_proargtypes),
6174  finfo[i].argtypes, finfo[i].nargs);
6175  }
6176 
6177  /* Decide whether we want to dump it */
6178  selectDumpableObject(&(finfo[i].dobj), fout);
6179 
6180  /* Mark whether function has an ACL */
6181  if (!PQgetisnull(res, i, i_proacl))
6182  finfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6183  }
6184 
6185  PQclear(res);
6186 
6187  destroyPQExpBuffer(query);
6188 
6189  return finfo;
6190 }
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
static Oid g_last_builtin_oid
Definition: pg_dump.c:103
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 6755 of file pg_dump.c.

6756 {
6757  PQExpBuffer query = createPQExpBuffer();
6758  PQExpBuffer tbloids = createPQExpBuffer();
6759  PGresult *res;
6760  int ntups;
6761  int curtblindx;
6762  IndxInfo *indxinfo;
6763  int i_tableoid,
6764  i_oid,
6765  i_indrelid,
6766  i_indexname,
6767  i_parentidx,
6768  i_indexdef,
6769  i_indnkeyatts,
6770  i_indnatts,
6771  i_indkey,
6772  i_indisclustered,
6773  i_indisreplident,
6774  i_indnullsnotdistinct,
6775  i_contype,
6776  i_conname,
6777  i_condeferrable,
6778  i_condeferred,
6779  i_contableoid,
6780  i_conoid,
6781  i_condef,
6782  i_tablespace,
6783  i_indreloptions,
6784  i_indstatcols,
6785  i_indstatvals;
6786 
6787  /*
6788  * We want to perform just one query against pg_index. However, we
6789  * mustn't try to select every row of the catalog and then sort it out on
6790  * the client side, because some of the server-side functions we need
6791  * would be unsafe to apply to tables we don't have lock on. Hence, we
6792  * build an array of the OIDs of tables we care about (and now have lock
6793  * on!), and use a WHERE clause to constrain which rows are selected.
6794  */
6795  appendPQExpBufferChar(tbloids, '{');
6796  for (int i = 0; i < numTables; i++)
6797  {
6798  TableInfo *tbinfo = &tblinfo[i];
6799 
6800  if (!tbinfo->hasindex)
6801  continue;
6802 
6803  /*
6804  * We can ignore indexes of uninteresting tables.
6805  */
6806  if (!tbinfo->interesting)
6807  continue;
6808 
6809  /* OK, we need info for this table */
6810  if (tbloids->len > 1) /* do we have more than the '{'? */
6811  appendPQExpBufferChar(tbloids, ',');
6812  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
6813  }
6814  appendPQExpBufferChar(tbloids, '}');
6815 
6816  appendPQExpBufferStr(query,
6817  "SELECT t.tableoid, t.oid, i.indrelid, "
6818  "t.relname AS indexname, "
6819  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6820  "i.indkey, i.indisclustered, "
6821  "c.contype, c.conname, "
6822  "c.condeferrable, c.condeferred, "
6823  "c.tableoid AS contableoid, "
6824  "c.oid AS conoid, "
6825  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6826  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6827  "t.reloptions AS indreloptions, ");
6828 
6829 
6830  if (fout->remoteVersion >= 90400)
6831  appendPQExpBufferStr(query,
6832  "i.indisreplident, ");
6833  else
6834  appendPQExpBufferStr(query,
6835  "false AS indisreplident, ");
6836 
6837  if (fout->remoteVersion >= 110000)
6838  appendPQExpBufferStr(query,
6839  "inh.inhparent AS parentidx, "
6840  "i.indnkeyatts AS indnkeyatts, "
6841  "i.indnatts AS indnatts, "
6842  "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
6843  " FROM pg_catalog.pg_attribute "
6844  " WHERE attrelid = i.indexrelid AND "
6845  " attstattarget >= 0) AS indstatcols, "
6846  "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
6847  " FROM pg_catalog.pg_attribute "
6848  " WHERE attrelid = i.indexrelid AND "
6849  " attstattarget >= 0) AS indstatvals, ");
6850  else
6851  appendPQExpBufferStr(query,
6852  "0 AS parentidx, "
6853  "i.indnatts AS indnkeyatts, "
6854  "i.indnatts AS indnatts, "
6855  "'' AS indstatcols, "
6856  "'' AS indstatvals, ");
6857 
6858  if (fout->remoteVersion >= 150000)
6859  appendPQExpBufferStr(query,
6860  "i.indnullsnotdistinct ");
6861  else
6862  appendPQExpBufferStr(query,
6863  "false AS indnullsnotdistinct ");
6864 
6865  /*
6866  * The point of the messy-looking outer join is to find a constraint that
6867  * is related by an internal dependency link to the index. If we find one,
6868  * create a CONSTRAINT entry linked to the INDEX entry. We assume an
6869  * index won't have more than one internal dependency.
6870  *
6871  * Note: the check on conrelid is redundant, but useful because that
6872  * column is indexed while conindid is not.
6873  */
6874  if (fout->remoteVersion >= 110000)
6875  {
6876  appendPQExpBuffer(query,
6877  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
6878  "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
6879  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6880  "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
6881  "LEFT JOIN pg_catalog.pg_constraint c "
6882  "ON (i.indrelid = c.conrelid AND "
6883  "i.indexrelid = c.conindid AND "
6884  "c.contype IN ('p','u','x')) "
6885  "LEFT JOIN pg_catalog.pg_inherits inh "
6886  "ON (inh.inhrelid = indexrelid) "
6887  "WHERE (i.indisvalid OR t2.relkind = 'p') "
6888  "AND i.indisready "
6889  "ORDER BY i.indrelid, indexname",
6890  tbloids->data);
6891  }
6892  else
6893  {
6894  /*
6895  * the test on indisready is necessary in 9.2, and harmless in
6896  * earlier/later versions
6897  */
6898  appendPQExpBuffer(query,
6899  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
6900  "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
6901  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6902  "LEFT JOIN pg_catalog.pg_constraint c "
6903  "ON (i.indrelid = c.conrelid AND "
6904  "i.indexrelid = c.conindid AND "
6905  "c.contype IN ('p','u','x')) "
6906  "WHERE i.indisvalid AND i.indisready "
6907  "ORDER BY i.indrelid, indexname",
6908  tbloids->data);
6909  }
6910 
6911  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6912 
6913  ntups = PQntuples(res);
6914 
6915  i_tableoid = PQfnumber(res, "tableoid");
6916  i_oid = PQfnumber(res, "oid");
6917  i_indrelid = PQfnumber(res, "indrelid");
6918  i_indexname = PQfnumber(res, "indexname");
6919  i_parentidx = PQfnumber(res, "parentidx");
6920  i_indexdef = PQfnumber(res, "indexdef");
6921  i_indnkeyatts = PQfnumber(res, "indnkeyatts");
6922  i_indnatts = PQfnumber(res, "indnatts");
6923  i_indkey = PQfnumber(res, "indkey");
6924  i_indisclustered = PQfnumber(res, "indisclustered");
6925  i_indisreplident = PQfnumber(res, "indisreplident");
6926  i_indnullsnotdistinct = PQfnumber(res, "indnullsnotdistinct");
6927  i_contype = PQfnumber(res, "contype");
6928  i_conname = PQfnumber(res, "conname");
6929  i_condeferrable = PQfnumber(res, "condeferrable");
6930  i_condeferred = PQfnumber(res, "condeferred");
6931  i_contableoid = PQfnumber(res, "contableoid");
6932  i_conoid = PQfnumber(res, "conoid");
6933  i_condef = PQfnumber(res, "condef");
6934  i_tablespace = PQfnumber(res, "tablespace");
6935  i_indreloptions = PQfnumber(res, "indreloptions");
6936  i_indstatcols = PQfnumber(res, "indstatcols");
6937  i_indstatvals = PQfnumber(res, "indstatvals");
6938 
6939  indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
6940 
6941  /*
6942  * Outer loop iterates once per table, not once per row. Incrementing of
6943  * j is handled by the inner loop.
6944  */
6945  curtblindx = -1;
6946  for (int j = 0; j < ntups;)
6947  {
6948  Oid indrelid = atooid(PQgetvalue(res, j, i_indrelid));
6949  TableInfo *tbinfo = NULL;
6950  int numinds;
6951 
6952  /* Count rows for this table */
6953  for (numinds = 1; numinds < ntups - j; numinds++)
6954  if (atooid(PQgetvalue(res, j + numinds, i_indrelid)) != indrelid)
6955  break;
6956 
6957  /*
6958  * Locate the associated TableInfo; we rely on tblinfo[] being in OID
6959  * order.
6960  */
6961  while (++curtblindx < numTables)
6962  {
6963  tbinfo = &tblinfo[curtblindx];
6964  if (tbinfo->dobj.catId.oid == indrelid)
6965  break;
6966  }
6967  if (curtblindx >= numTables)
6968  pg_fatal("unrecognized table OID %u", indrelid);
6969  /* cross-check that we only got requested tables */
6970  if (!tbinfo->hasindex ||
6971  !tbinfo->interesting)
6972  pg_fatal("unexpected index data for table \"%s\"",
6973  tbinfo->dobj.name);
6974 
6975  /* Save data for this table */
6976  tbinfo->indexes = indxinfo + j;
6977  tbinfo->numIndexes = numinds;
6978 
6979  for (int c = 0; c < numinds; c++, j++)
6980  {
6981  char contype;
6982 
6983  indxinfo[j].dobj.objType = DO_INDEX;
6984  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
6985  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
6986  AssignDumpId(&indxinfo[j].dobj);
6987  indxinfo[j].dobj.dump = tbinfo->dobj.dump;
6988  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
6989  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6990  indxinfo[j].indextable = tbinfo;
6991  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
6992  indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
6993  indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
6994  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
6995  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
6996  indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
6997  indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
6998  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
6999  parseOidArray(PQgetvalue(res, j, i_indkey),
7000  indxinfo[j].indkeys, indxinfo[j].indnattrs);
7001  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
7002  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
7003  indxinfo[j].indnullsnotdistinct = (PQgetvalue(res, j, i_indnullsnotdistinct)[0] == 't');
7004  indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
7005  indxinfo[j].partattaches = (SimplePtrList)
7006  {
7007  NULL, NULL
7008  };
7009  contype = *(PQgetvalue(res, j, i_contype));
7010 
7011  if (contype == 'p' || contype == 'u' || contype == 'x')
7012  {
7013  /*
7014  * If we found a constraint matching the index, create an
7015  * entry for it.
7016  */
7017  ConstraintInfo *constrinfo;
7018 
7019  constrinfo = (ConstraintInfo *) pg_malloc(sizeof(ConstraintInfo));
7020  constrinfo->dobj.objType = DO_CONSTRAINT;
7021  constrinfo->dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7022  constrinfo->dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7023  AssignDumpId(&constrinfo->dobj);
7024  constrinfo->dobj.dump = tbinfo->dobj.dump;
7025  constrinfo->dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7026  constrinfo->dobj.namespace = tbinfo->dobj.namespace;
7027  constrinfo->contable = tbinfo;
7028  constrinfo->condomain = NULL;
7029  constrinfo->contype = contype;
7030  if (contype == 'x')
7031  constrinfo->condef = pg_strdup(PQgetvalue(res, j, i_condef));
7032  else
7033  constrinfo->condef = NULL;
7034  constrinfo->confrelid = InvalidOid;
7035  constrinfo->conindex = indxinfo[j].dobj.dumpId;
7036  constrinfo->condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
7037  constrinfo->condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
7038  constrinfo->conislocal = true;
7039  constrinfo->separate = true;
7040 
7041  indxinfo[j].indexconstraint = constrinfo->dobj.dumpId;
7042  }
7043  else
7044  {
7045  /* Plain secondary index */
7046  indxinfo[j].indexconstraint = 0;
7047  }
7048  }
7049  }
7050 
7051  PQclear(res);
7052 
7053  destroyPQExpBuffer(query);
7054  destroyPQExpBuffer(tbloids);
7055 }
char * c
struct SimplePtrList SimplePtrList
bool indisreplident
Definition: pg_dump.h:400
int indnkeyattrs
Definition: pg_dump.h:395
char * indstatvals
Definition: pg_dump.h:394
char * indstatcols
Definition: pg_dump.h:393
int indnattrs
Definition: pg_dump.h:396
TableInfo * indextable
Definition: pg_dump.h:389
Oid parentidx
Definition: pg_dump.h:402
Oid * indkeys
Definition: pg_dump.h:397
char * indreloptions
Definition: pg_dump.h:392
DumpId indexconstraint
Definition: pg_dump.h:406
bool indisclustered
Definition: pg_dump.h:399
SimplePtrList partattaches
Definition: pg_dump.h:403
char * tablespace
Definition: pg_dump.h:391
bool indnullsnotdistinct
Definition: pg_dump.h:401
char * indexdef
Definition: pg_dump.h:390
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 6709 of file pg_dump.c.

6710 {
6711  PGresult *res;
6712  int ntups;
6713  int i;
6714  PQExpBuffer query = createPQExpBuffer();
6715  InhInfo *inhinfo;
6716 
6717  int i_inhrelid;
6718  int i_inhparent;
6719 
6720  /* find all the inheritance information */
6721  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
6722 
6723  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6724 
6725  ntups = PQntuples(res);
6726 
6727  *numInherits = ntups;
6728 
6729  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6730 
6731  i_inhrelid = PQfnumber(res, "inhrelid");
6732  i_inhparent = PQfnumber(res, "inhparent");
6733 
6734  for (i = 0; i < ntups; i++)
6735  {
6736  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6737  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6738  }
6739 
6740  PQclear(res);
6741 
6742  destroyPQExpBuffer(query);
6743 
6744  return inhinfo;
6745 }
Oid inhparent
Definition: pg_dump.h:521
Oid inhrelid
Definition: pg_dump.h:520

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

669 {
670  return lastDumpId;
671 }

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

◆ getNamespaces()

NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

Definition at line 5060 of file pg_dump.c.

5061 {
5062  PGresult *res;
5063  int ntups;
5064  int i;
5065  PQExpBuffer query;
5066  NamespaceInfo *nsinfo;
5067  int i_tableoid;
5068  int i_oid;
5069  int i_nspname;
5070  int i_nspowner;
5071  int i_nspacl;
5072  int i_acldefault;
5073 
5074  query = createPQExpBuffer();
5075 
5076  /*
5077  * we fetch all namespaces including system ones, so that every object we
5078  * read in can be linked to a containing namespace.
5079  */
5080  appendPQExpBufferStr(query, "SELECT n.tableoid, n.oid, n.nspname, "
5081  "n.nspowner, "
5082  "n.nspacl, "
5083  "acldefault('n', n.nspowner) AS acldefault "
5084  "FROM pg_namespace n");
5085 
5086  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5087 
5088  ntups = PQntuples(res);
5089 
5090  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
5091 
5092  i_tableoid = PQfnumber(res, "tableoid");
5093  i_oid = PQfnumber(res, "oid");
5094  i_nspname = PQfnumber(res, "nspname");
5095  i_nspowner = PQfnumber(res, "nspowner");
5096  i_nspacl = PQfnumber(res, "nspacl");
5097  i_acldefault = PQfnumber(res, "acldefault");
5098 
5099  for (i = 0; i < ntups; i++)
5100  {
5101  const char *nspowner;
5102 
5103  nsinfo[i].dobj.objType = DO_NAMESPACE;
5104  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5105  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5106  AssignDumpId(&nsinfo[i].dobj);
5107  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
5108  nsinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_nspacl));
5109  nsinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
5110  nsinfo[i].dacl.privtype = 0;
5111  nsinfo[i].dacl.initprivs = NULL;
5112  nspowner = PQgetvalue(res, i, i_nspowner);
5113  nsinfo[i].nspowner = atooid(nspowner);
5114  nsinfo[i].rolname = getRoleName(nspowner);
5115 
5116  /* Decide whether to dump this namespace */
5117  selectDumpableNamespace(&nsinfo[i], fout);
5118 
5119  /* Mark whether namespace has an ACL */
5120  if (!PQgetisnull(res, i, i_nspacl))
5121  nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
5122 
5123  /*
5124  * We ignore any pg_init_privs.initprivs entry for the public schema
5125  * and assume a predetermined default, for several reasons. First,
5126  * dropping and recreating the schema removes its pg_init_privs entry,
5127  * but an empty destination database starts with this ACL nonetheless.
5128  * Second, we support dump/reload of public schema ownership changes.
5129  * ALTER SCHEMA OWNER filters nspacl through aclnewowner(), but
5130  * initprivs continues to reflect the initial owner. Hence,
5131  * synthesize the value that nspacl will have after the restore's
5132  * ALTER SCHEMA OWNER. Third, this makes the destination database
5133  * match the source's ACL, even if the latter was an initdb-default
5134  * ACL, which changed in v15. An upgrade pulls in changes to most
5135  * system object ACLs that the DBA had not customized. We've made the
5136  * public schema depart from that, because changing its ACL so easily
5137  * breaks applications.
5138  */
5139  if (strcmp(nsinfo[i].dobj.name, "public") == 0)
5140  {
5141  PQExpBuffer aclarray = createPQExpBuffer();
5142  PQExpBuffer aclitem = createPQExpBuffer();
5143 
5144  /* Standard ACL as of v15 is {owner=UC/owner,=U/owner} */
5145  appendPQExpBufferChar(aclarray, '{');
5146  quoteAclUserName(aclitem, nsinfo[i].rolname);
5147  appendPQExpBufferStr(aclitem, "=UC/");
5148  quoteAclUserName(aclitem, nsinfo[i].rolname);
5149  appendPGArray(aclarray, aclitem->data);
5150  resetPQExpBuffer(aclitem);
5151  appendPQExpBufferStr(aclitem, "=U/");
5152  quoteAclUserName(aclitem, nsinfo[i].rolname);
5153  appendPGArray(aclarray, aclitem->data);
5154  appendPQExpBufferChar(aclarray, '}');
5155 
5156  nsinfo[i].dacl.privtype = 'i';
5157  nsinfo[i].dacl.initprivs = pstrdup(aclarray->data);
5158  nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
5159 
5160  destroyPQExpBuffer(aclarray);
5161  destroyPQExpBuffer(aclitem);
5162  }
5163  }
5164 
5165  PQclear(res);
5166  destroyPQExpBuffer(query);
5167 
5168  *numNamespaces = ntups;
5169 
5170  return nsinfo;
5171 }
void quoteAclUserName(PQExpBuffer output, const char *input)
Definition: dumputils.c:544
char * pstrdup(const char *in)
Definition: mcxt.c:1624
NameData rolname
Definition: pg_authid.h:34
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1649
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 5722 of file pg_dump.c.

5723 {
5724  PGresult *res;
5725  int ntups;
5726  int i;
5727  PQExpBuffer query = createPQExpBuffer();
5728  OpclassInfo *opcinfo;
5729  int i_tableoid;
5730  int i_oid;
5731  int i_opcname;
5732  int i_opcnamespace;
5733  int i_opcowner;
5734 
5735  /*
5736  * find all opclasses, including builtin opclasses; we filter out
5737  * system-defined opclasses at dump-out time.
5738  */
5739 
5740  appendPQExpBufferStr(query, "SELECT tableoid, oid, opcname, "
5741  "opcnamespace, "
5742  "opcowner "
5743  "FROM pg_opclass");
5744 
5745  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5746 
5747  ntups = PQntuples(res);
5748  *numOpclasses = ntups;
5749 
5750  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
5751 
5752  i_tableoid = PQfnumber(res, "tableoid");
5753  i_oid = PQfnumber(res, "oid");
5754  i_opcname = PQfnumber(res, "opcname");
5755  i_opcnamespace = PQfnumber(res, "opcnamespace");
5756  i_opcowner = PQfnumber(res, "opcowner");
5757 
5758  for (i = 0; i < ntups; i++)
5759  {
5760  opcinfo[i].dobj.objType = DO_OPCLASS;
5761  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5762  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5763  AssignDumpId(&opcinfo[i].dobj);
5764  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
5765  opcinfo[i].dobj.namespace =
5766  findNamespace(atooid(PQgetvalue(res, i, i_opcnamespace)));
5767  opcinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opcowner));
5768 
5769  /* Decide whether we want to dump it */
5770  selectDumpableObject(&(opcinfo[i].dobj), fout);
5771  }
5772 
5773  PQclear(res);
5774 
5775  destroyPQExpBuffer(query);
5776 
5777  return opcinfo;
5778 }
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 5441 of file pg_dump.c.

5442 {
5443  PGresult *res;
5444  int ntups;
5445  int i;
5446  PQExpBuffer query = createPQExpBuffer();
5447  OprInfo *oprinfo;
5448  int i_tableoid;
5449  int i_oid;
5450  int i_oprname;
5451  int i_oprnamespace;
5452  int i_oprowner;
5453  int i_oprkind;
5454  int i_oprcode;
5455 
5456  /*
5457  * find all operators, including builtin operators; we filter out
5458  * system-defined operators at dump-out time.
5459  */
5460 
5461  appendPQExpBufferStr(query, "SELECT tableoid, oid, oprname, "
5462  "oprnamespace, "
5463  "oprowner, "
5464  "oprkind, "
5465  "oprcode::oid AS oprcode "
5466  "FROM pg_operator");
5467 
5468  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5469 
5470  ntups = PQntuples(res);
5471  *numOprs = ntups;
5472 
5473  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
5474 
5475  i_tableoid = PQfnumber(res, "tableoid");
5476  i_oid = PQfnumber(res, "oid");
5477  i_oprname = PQfnumber(res, "oprname");
5478  i_oprnamespace = PQfnumber(res, "oprnamespace");
5479  i_oprowner = PQfnumber(res, "oprowner");
5480  i_oprkind = PQfnumber(res, "oprkind");
5481  i_oprcode = PQfnumber(res, "oprcode");
5482 
5483  for (i = 0; i < ntups; i++)
5484  {
5485  oprinfo[i].dobj.objType = DO_OPERATOR;
5486  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5487  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5488  AssignDumpId(&oprinfo[i].dobj);
5489  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
5490  oprinfo[i].dobj.namespace =
5491  findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)));
5492  oprinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_oprowner));
5493  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
5494  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
5495 
5496  /* Decide whether we want to dump it */
5497  selectDumpableObject(&(oprinfo[i].dobj), fout);
5498  }
5499 
5500  PQclear(res);
5501 
5502  destroyPQExpBuffer(query);
5503 
5504  return oprinfo;
5505 }
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 5788 of file pg_dump.c.

5789 {
5790  PGresult *res;
5791  int ntups;
5792  int i;
5793  PQExpBuffer query;
5794  OpfamilyInfo *opfinfo;
5795  int i_tableoid;
5796  int i_oid;
5797  int i_opfname;
5798  int i_opfnamespace;
5799  int i_opfowner;
5800 
5801  query = createPQExpBuffer();
5802 
5803  /*
5804  * find all opfamilies, including builtin opfamilies; we filter out
5805  * system-defined opfamilies at dump-out time.
5806  */
5807 
5808  appendPQExpBufferStr(query, "SELECT tableoid, oid, opfname, "
5809  "opfnamespace, "
5810  "opfowner "
5811  "FROM pg_opfamily");
5812 
5813  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5814 
5815  ntups = PQntuples(res);
5816  *numOpfamilies = ntups;
5817 
5818  opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
5819 
5820  i_tableoid = PQfnumber(res, "tableoid");
5821  i_oid = PQfnumber(res, "oid");
5822  i_opfname = PQfnumber(res, "opfname");
5823  i_opfnamespace = PQfnumber(res, "opfnamespace");
5824  i_opfowner = PQfnumber(res, "opfowner");
5825 
5826  for (i = 0; i < ntups; i++)
5827  {
5828  opfinfo[i].dobj.objType = DO_OPFAMILY;
5829  opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5830  opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5831  AssignDumpId(&opfinfo[i].dobj);
5832  opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
5833  opfinfo[i].dobj.namespace =
5834  findNamespace(atooid(PQgetvalue(res, i, i_opfnamespace)));
5835  opfinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opfowner));
5836 
5837  /* Decide whether we want to dump it */
5838  selectDumpableObject(&(opfinfo[i].dobj), fout);
5839  }
5840 
5841  PQclear(res);
5842 
5843  destroyPQExpBuffer(query);
5844 
5845  return opfinfo;
5846 }
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 6646 of file pg_dump.c.

6647 {
6648  int i;
6649 
6650  /*
6651  * Force sequences that are "owned" by table columns to be dumped whenever
6652  * their owning table is being dumped.
6653  */
6654  for (i = 0; i < numTables; i++)
6655  {
6656  TableInfo *seqinfo = &tblinfo[i];
6657  TableInfo *owning_tab;
6658 
6659  if (!OidIsValid(seqinfo->owning_tab))
6660  continue; /* not an owned sequence */
6661 
6662  owning_tab = findTableByOid(seqinfo->owning_tab);
6663  if (owning_tab == NULL)
6664  pg_fatal("failed sanity check, parent table with OID %u of sequence with OID %u not found",
6665  seqinfo->owning_tab, seqinfo->dobj.catId.oid);
6666 
6667  /*
6668  * Only dump identity sequences if we're going to dump the table that
6669  * it belongs to.
6670  */
6671  if (owning_tab->dobj.dump == DUMP_COMPONENT_NONE &&
6672  seqinfo->is_identity_sequence)
6673  {
6674  seqinfo->dobj.dump = DUMP_COMPONENT_NONE;
6675  continue;
6676  }
6677 
6678  /*
6679  * Otherwise we need to dump the components that are being dumped for
6680  * the table and any components which the sequence is explicitly
6681  * marked with.
6682  *
6683  * We can't simply use the set of components which are being dumped
6684  * for the table as the table might be in an extension (and only the
6685  * non-extension components, eg: ACLs if changed, security labels, and
6686  * policies, are being dumped) while the sequence is not (and
6687  * therefore the definition and other components should also be
6688  * dumped).
6689  *
6690  * If the sequence is part of the extension then it should be properly
6691  * marked by checkExtensionMembership() and this will be a no-op as
6692  * the table will be equivalently marked.
6693  */
6694  seqinfo->dobj.dump = seqinfo->dobj.dump | owning_tab->dobj.dump;
6695 
6696  if (seqinfo->dobj.dump != DUMP_COMPONENT_NONE)
6697  seqinfo->interesting = true;
6698  }
6699 }
#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().

◆ getPolicies()

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

Definition at line 3652 of file pg_dump.c.

3653 {
3654  PQExpBuffer query;
3655  PQExpBuffer tbloids;
3656  PGresult *res;
3657  PolicyInfo *polinfo;
3658  int i_oid;
3659  int i_tableoid;
3660  int i_polrelid;
3661  int i_polname;
3662  int i_polcmd;
3663  int i_polpermissive;
3664  int i_polroles;
3665  int i_polqual;
3666  int i_polwithcheck;
3667  int i,
3668  j,
3669  ntups;
3670 
3671  /* No policies before 9.5 */
3672  if (fout->remoteVersion < 90500)
3673  return;
3674 
3675  query = createPQExpBuffer();
3676  tbloids = createPQExpBuffer();
3677 
3678  /*
3679  * Identify tables of interest, and check which ones have RLS enabled.
3680  */
3681  appendPQExpBufferChar(tbloids, '{');
3682  for (i = 0; i < numTables; i++)
3683  {
3684  TableInfo *tbinfo = &tblinfo[i];
3685 
3686  /* Ignore row security on tables not to be dumped */
3687  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_POLICY))
3688  continue;
3689 
3690  /* It can't have RLS or policies if it's not a table */
3691  if (tbinfo->relkind != RELKIND_RELATION &&
3692  tbinfo->relkind != RELKIND_PARTITIONED_TABLE)
3693  continue;
3694 
3695  /* Add it to the list of table OIDs to be probed below */
3696  if (tbloids->len > 1) /* do we have more than the '{'? */
3697  appendPQExpBufferChar(tbloids, ',');
3698  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
3699 
3700  /* Is RLS enabled? (That's separate from whether it has policies) */
3701  if (tbinfo->rowsec)
3702  {
3704 
3705  /*
3706  * We represent RLS being enabled on a table by creating a
3707  * PolicyInfo object with null polname.
3708  *
3709  * Note: use tableoid 0 so that this object won't be mistaken for
3710  * something that pg_depend entries apply to.
3711  */
3712  polinfo = pg_malloc(sizeof(PolicyInfo));
3713  polinfo->dobj.objType = DO_POLICY;
3714  polinfo->dobj.catId.tableoid = 0;
3715  polinfo->dobj.catId.oid = tbinfo->dobj.catId.oid;
3716  AssignDumpId(&polinfo->dobj);
3717  polinfo->dobj.namespace = tbinfo->dobj.namespace;
3718  polinfo->dobj.name = pg_strdup(tbinfo->dobj.name);
3719  polinfo->poltable = tbinfo;
3720  polinfo->polname = NULL;
3721  polinfo->polcmd = '\0';
3722  polinfo->polpermissive = 0;
3723  polinfo->polroles = NULL;
3724  polinfo->polqual = NULL;
3725  polinfo->polwithcheck = NULL;
3726  }
3727  }
3728  appendPQExpBufferChar(tbloids, '}');
3729 
3730  /*
3731  * Now, read all RLS policies belonging to the tables of interest, and
3732  * create PolicyInfo objects for them. (Note that we must filter the
3733  * results server-side not locally, because we dare not apply pg_get_expr
3734  * to tables we don't have lock on.)
3735  */
3736  pg_log_info("reading row-level security policies");
3737 
3738  printfPQExpBuffer(query,
3739  "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
3740  if (fout->remoteVersion >= 100000)
3741  appendPQExpBufferStr(query, "pol.polpermissive, ");
3742  else
3743  appendPQExpBufferStr(query, "'t' as polpermissive, ");
3744  appendPQExpBuffer(query,
3745  "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
3746  " 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, "
3747  "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
3748  "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
3749  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
3750  "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
3751  tbloids->data);
3752 
3753  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
3754 
3755  ntups = PQntuples(res);
3756  if (ntups > 0)
3757  {
3758  i_oid = PQfnumber(res, "oid");
3759  i_tableoid = PQfnumber(res, "tableoid");
3760  i_polrelid = PQfnumber(res, "polrelid");
3761  i_polname = PQfnumber(res, "polname");
3762  i_polcmd = PQfnumber(res, "polcmd");
3763  i_polpermissive = PQfnumber(res, "polpermissive");
3764  i_polroles = PQfnumber(res, "polroles");
3765  i_polqual = PQfnumber(res, "polqual");
3766  i_polwithcheck = PQfnumber(res, "polwithcheck");
3767 
3768  polinfo = pg_malloc(ntups * sizeof(PolicyInfo));
3769 
3770  for (j = 0; j < ntups; j++)
3771  {
3772  Oid polrelid = atooid(PQgetvalue(res, j, i_polrelid));
3773  TableInfo *tbinfo = findTableByOid(polrelid);
3774 
3776 
3777  polinfo[j].dobj.objType = DO_POLICY;
3778  polinfo[j].dobj.catId.tableoid =
3779  atooid(PQgetvalue(res, j, i_tableoid));
3780  polinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
3781  AssignDumpId(&polinfo[j].dobj);
3782  polinfo[j].dobj.namespace = tbinfo->dobj.namespace;
3783  polinfo[j].poltable = tbinfo;
3784  polinfo[j].polname = pg_strdup(PQgetvalue(res, j, i_polname));
3785  polinfo[j].dobj.name = pg_strdup(polinfo[j].polname);
3786 
3787  polinfo[j].polcmd = *(PQgetvalue(res, j, i_polcmd));
3788  polinfo[j].polpermissive = *(PQgetvalue(res, j, i_polpermissive)) == 't';
3789 
3790  if (PQgetisnull(res, j, i_polroles))
3791  polinfo[j].polroles = NULL;
3792  else
3793  polinfo[j].polroles = pg_strdup(PQgetvalue(res, j, i_polroles));
3794 
3795  if (PQgetisnull(res, j, i_polqual))
3796  polinfo[j].polqual = NULL;
3797  else
3798  polinfo[j].polqual = pg_strdup(PQgetvalue(res, j, i_polqual));
3799 
3800  if (PQgetisnull(res, j, i_polwithcheck))
3801  polinfo[j].polwithcheck = NULL;
3802  else
3803  polinfo[j].polwithcheck
3804  = pg_strdup(PQgetvalue(res, j, i_polwithcheck));
3805  }
3806  }
3807 
3808  PQclear(res);
3809 
3810  destroyPQExpBuffer(query);
3811  destroyPQExpBuffer(tbloids);
3812 }
#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:601
char * polqual
Definition: pg_dump.h:606
char polcmd
Definition: pg_dump.h:603
char * polroles
Definition: pg_dump.h:605
char * polwithcheck
Definition: pg_dump.h:607
DumpableObject dobj
Definition: pg_dump.h:600
bool polpermissive
Definition: pg_dump.h:604
char * polname
Definition: pg_dump.h:602
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 7875 of file pg_dump.c.

7876 {
7877  PGresult *res;
7878  int ntups;
7879  int i;
7880  PQExpBuffer query = createPQExpBuffer();
7881  ProcLangInfo *planginfo;
7882  int i_tableoid;
7883  int i_oid;
7884  int i_lanname;
7885  int i_lanpltrusted;
7886  int i_lanplcallfoid;
7887  int i_laninline;
7888  int i_lanvalidator;
7889  int i_lanacl;
7890  int i_acldefault;
7891  int i_lanowner;
7892 
7893  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7894  "lanname, lanpltrusted, lanplcallfoid, "
7895  "laninline, lanvalidator, "
7896  "lanacl, "
7897  "acldefault('l', lanowner) AS acldefault, "
7898  "lanowner "
7899  "FROM pg_language "
7900  "WHERE lanispl "
7901  "ORDER BY oid");
7902 
7903  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7904 
7905  ntups = PQntuples(res);
7906 
7907  *numProcLangs = ntups;
7908 
7909  planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo));
7910 
7911  i_tableoid = PQfnumber(res, "tableoid");
7912  i_oid = PQfnumber(res, "oid");
7913  i_lanname = PQfnumber(res, "lanname");
7914  i_lanpltrusted = PQfnumber(res, "lanpltrusted");
7915  i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
7916  i_laninline = PQfnumber(res, "laninline");
7917  i_lanvalidator = PQfnumber(res, "lanvalidator");
7918  i_lanacl = PQfnumber(res, "lanacl");
7919  i_acldefault = PQfnumber(res, "acldefault");
7920  i_lanowner = PQfnumber(res, "lanowner");
7921 
7922  for (i = 0; i < ntups; i++)
7923  {
7924  planginfo[i].dobj.objType = DO_PROCLANG;
7925  planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7926  planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7927  AssignDumpId(&planginfo[i].dobj);
7928 
7929  planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
7930  planginfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_lanacl));
7931  planginfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
7932  planginfo[i].dacl.privtype = 0;
7933  planginfo[i].dacl.initprivs = NULL;
7934  planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
7935  planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
7936  planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
7937  planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
7938  planginfo[i].lanowner = getRoleName(PQgetvalue(res, i, i_lanowner));
7939 
7940  /* Decide whether we want to dump it */
7941  selectDumpableProcLang(&(planginfo[i]), fout);
7942 
7943  /* Mark whether language has an ACL */
7944  if (!PQgetisnull(res, i, i_lanacl))
7945  planginfo[i].dobj.components |= DUMP_COMPONENT_ACL;
7946  }
7947 
7948  PQclear(res);
7949 
7950  destroyPQExpBuffer(query);
7951 
7952  return planginfo;
7953 }
static void selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
Definition: pg_dump.c:1866
Oid lanvalidator
Definition: pg_dump.h:494
DumpableAcl dacl
Definition: pg_dump.h:490
DumpableObject dobj
Definition: pg_dump.h:489
Oid laninline
Definition: pg_dump.h:493
const char * lanowner
Definition: pg_dump.h:495
Oid lanplcallfoid
Definition: pg_dump.h:492
bool lanpltrusted
Definition: pg_dump.h:491

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 4137 of file pg_dump.c.

4138 {
4139  PQExpBuffer query;
4140  PGresult *res;
4141  PublicationSchemaInfo *pubsinfo;
4142  DumpOptions *dopt = fout->dopt;
4143  int i_tableoid;
4144  int i_oid;
4145  int i_pnpubid;
4146  int i_pnnspid;
4147  int i,
4148  j,
4149  ntups;
4150 
4151  if (dopt->no_publications || fout->remoteVersion < 150000)
4152  return;
4153 
4154  query = createPQExpBuffer();
4155 
4156  /* Collect all publication membership info. */
4157  appendPQExpBufferStr(query,
4158  "SELECT tableoid, oid, pnpubid, pnnspid "
4159  "FROM pg_catalog.pg_publication_namespace");
4160  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4161 
4162  ntups = PQntuples(res);
4163 
4164  i_tableoid = PQfnumber(res, "tableoid");
4165  i_oid = PQfnumber(res, "oid");
4166  i_pnpubid = PQfnumber(res, "pnpubid");
4167  i_pnnspid = PQfnumber(res, "pnnspid");
4168 
4169  /* this allocation may be more than we need */
4170  pubsinfo = pg_malloc(ntups * sizeof(PublicationSchemaInfo));
4171  j = 0;
4172 
4173  for (i = 0; i < ntups; i++)
4174  {
4175  Oid pnpubid = atooid(PQgetvalue(res, i, i_pnpubid));
4176  Oid pnnspid = atooid(PQgetvalue(res, i, i_pnnspid));
4177  PublicationInfo *pubinfo;
4178  NamespaceInfo *nspinfo;
4179 
4180  /*
4181  * Ignore any entries for which we aren't interested in either the
4182  * publication or the rel.
4183  */
4184  pubinfo = findPublicationByOid(pnpubid);
4185  if (pubinfo == NULL)
4186  continue;
4187  nspinfo = findNamespaceByOid(pnnspid);
4188  if (nspinfo == NULL)
4189  continue;
4190 
4191  /*
4192  * We always dump publication namespaces unless the corresponding
4193  * namespace is excluded from the dump.
4194  */
4195  if (nspinfo->dobj.dump == DUMP_COMPONENT_NONE)
4196  continue;
4197 
4198  /* OK, make a DumpableObject for this relationship */
4200  pubsinfo[j].dobj.catId.tableoid =
4201  atooid(PQgetvalue(res, i, i_tableoid));
4202  pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4203  AssignDumpId(&pubsinfo[j].dobj);
4204  pubsinfo[j].dobj.namespace = nspinfo->dobj.namespace;
4205  pubsinfo[j].dobj.name = nspinfo->dobj.name;
4206  pubsinfo[j].publication = pubinfo;
4207  pubsinfo[j].pubschema = nspinfo;
4208 
4209  /* Decide whether we want to dump it */
4210  selectDumpablePublicationObject(&(pubsinfo[j].dobj), fout);
4211 
4212  j++;
4213  }
4214 
4215  PQclear(res);
4216  destroyPQExpBuffer(query);
4217 }
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition: common.c:886
PublicationInfo * findPublicationByOid(Oid oid)
Definition: common.c:922
static void selectDumpablePublicationObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1960
NamespaceInfo * pubschema
Definition: pg_dump.h:646
DumpableObject dobj
Definition: pg_dump.h:644
PublicationInfo * publication
Definition: pg_dump.h:645
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 3937 of file pg_dump.c.

3938 {
3939  DumpOptions *dopt = fout->dopt;
3940  PQExpBuffer query;
3941  PGresult *res;
3942  PublicationInfo *pubinfo;
3943  int i_tableoid;
3944  int i_oid;
3945  int i_pubname;
3946  int i_pubowner;
3947  int i_puballtables;
3948  int i_pubinsert;
3949  int i_pubupdate;
3950  int i_pubdelete;
3951  int i_pubtruncate;
3952  int i_pubviaroot;
3953  int i,
3954  ntups;
3955 
3956  if (dopt->no_publications || fout->remoteVersion < 100000)
3957  {
3958  *numPublications = 0;
3959  return NULL;
3960  }
3961 
3962  query = createPQExpBuffer();
3963 
3964  resetPQExpBuffer(query);
3965 
3966  /* Get the publications. */
3967  if (fout->remoteVersion >= 130000)
3968  appendPQExpBufferStr(query,
3969  "SELECT p.tableoid, p.oid, p.pubname, "
3970  "p.pubowner, "
3971  "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, p.pubviaroot "
3972  "FROM pg_publication p");
3973  else if (fout->remoteVersion >= 110000)
3974  appendPQExpBufferStr(query,
3975  "SELECT p.tableoid, p.oid, p.pubname, "
3976  "p.pubowner, "
3977  "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, false AS pubviaroot "
3978  "FROM pg_publication p");
3979  else
3980  appendPQExpBufferStr(query,
3981  "SELECT p.tableoid, p.oid, p.pubname, "
3982  "p.pubowner, "
3983  "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, false AS pubtruncate, false AS pubviaroot "
3984  "FROM pg_publication p");
3985 
3986  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
3987 
3988  ntups = PQntuples(res);
3989 
3990  i_tableoid = PQfnumber(res, "tableoid");
3991  i_oid = PQfnumber(res, "oid");
3992  i_pubname = PQfnumber(res, "pubname");
3993  i_pubowner = PQfnumber(res, "pubowner");
3994  i_puballtables = PQfnumber(res, "puballtables");
3995  i_pubinsert = PQfnumber(res, "pubinsert");
3996  i_pubupdate = PQfnumber(res, "pubupdate");
3997  i_pubdelete = PQfnumber(res, "pubdelete");
3998  i_pubtruncate = PQfnumber(res, "pubtruncate");
3999  i_pubviaroot = PQfnumber(res, "pubviaroot");
4000 
4001  pubinfo = pg_malloc(ntups * sizeof(PublicationInfo));
4002 
4003  for (i = 0; i < ntups; i++)
4004  {
4005  pubinfo[i].dobj.objType = DO_PUBLICATION;
4006  pubinfo[i].dobj.catId.tableoid =
4007  atooid(PQgetvalue(res, i, i_tableoid));
4008  pubinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4009  AssignDumpId(&pubinfo[i].dobj);
4010  pubinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_pubname));
4011  pubinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_pubowner));
4012  pubinfo[i].puballtables =
4013  (strcmp(PQgetvalue(res, i, i_puballtables), "t") == 0);
4014  pubinfo[i].pubinsert =
4015  (strcmp(PQgetvalue(res, i, i_pubinsert), "t") == 0);
4016  pubinfo[i].pubupdate =
4017  (strcmp(PQgetvalue(res, i, i_pubupdate), "t") == 0);
4018  pubinfo[i].pubdelete =
4019  (strcmp(PQgetvalue(res, i, i_pubdelete), "t") == 0);
4020  pubinfo[i].pubtruncate =
4021  (strcmp(PQgetvalue(res, i, i_pubtruncate), "t") == 0);
4022  pubinfo[i].pubviaroot =
4023  (strcmp(PQgetvalue(res, i, i_pubviaroot), "t") == 0);
4024 
4025  /* Decide whether we want to dump it */
4026  selectDumpableObject(&(pubinfo[i].dobj), fout);
4027  }
4028  PQclear(res);
4029 
4030  destroyPQExpBuffer(query);
4031 
4032  *numPublications = ntups;
4033  return pubinfo;
4034 }
const char * rolname
Definition: pg_dump.h:616
bool puballtables
Definition: pg_dump.h:617
bool pubtruncate
Definition: pg_dump.h:621
DumpableObject dobj
Definition: pg_dump.h:615

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 4224 of file pg_dump.c.

4225 {
4226  PQExpBuffer query;
4227  PGresult *res;
4228  PublicationRelInfo *pubrinfo;
4229  DumpOptions *dopt = fout->dopt;
4230  int i_tableoid;
4231  int i_oid;
4232  int i_prpubid;
4233  int i_prrelid;
4234  int i_prrelqual;
4235  int i_prattrs;
4236  int i,
4237  j,
4238  ntups;
4239 
4240  if (dopt->no_publications || fout->remoteVersion < 100000)
4241  return;
4242 
4243  query = createPQExpBuffer();
4244 
4245  /* Collect all publication membership info. */
4246  if (fout->remoteVersion >= 150000)
4247  appendPQExpBufferStr(query,
4248  "SELECT tableoid, oid, prpubid, prrelid, "
4249  "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4250  "(CASE\n"
4251  " WHEN pr.prattrs IS NOT NULL THEN\n"
4252  " (SELECT array_agg(attname)\n"
4253  " FROM\n"
4254  " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4255  " pg_catalog.pg_attribute\n"
4256  " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4257  " ELSE NULL END) prattrs "
4258  "FROM pg_catalog.pg_publication_rel pr");
4259  else
4260  appendPQExpBufferStr(query,
4261  "SELECT tableoid, oid, prpubid, prrelid, "
4262  "NULL AS prrelqual, NULL AS prattrs "
4263  "FROM pg_catalog.pg_publication_rel");
4264  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4265 
4266  ntups = PQntuples(res);
4267 
4268  i_tableoid = PQfnumber(res, "tableoid");
4269  i_oid = PQfnumber(res, "oid");
4270  i_prpubid = PQfnumber(res, "prpubid");
4271  i_prrelid = PQfnumber(res, "prrelid");
4272  i_prrelqual = PQfnumber(res, "prrelqual");
4273  i_prattrs = PQfnumber(res, "prattrs");
4274 
4275  /* this allocation may be more than we need */
4276  pubrinfo = pg_malloc(ntups * sizeof(PublicationRelInfo));
4277  j = 0;
4278 
4279  for (i = 0; i < ntups; i++)
4280  {
4281  Oid prpubid = atooid(PQgetvalue(res, i, i_prpubid));
4282  Oid prrelid = atooid(PQgetvalue(res, i, i_prrelid));
4283  PublicationInfo *pubinfo;
4284  TableInfo *tbinfo;
4285 
4286  /*
4287  * Ignore any entries for which we aren't interested in either the
4288  * publication or the rel.
4289  */
4290  pubinfo = findPublicationByOid(prpubid);
4291  if (pubinfo == NULL)
4292  continue;
4293  tbinfo = findTableByOid(prrelid);
4294  if (tbinfo == NULL)
4295  continue;
4296 
4297  /*
4298  * Ignore publication membership of tables whose definitions are not
4299  * to be dumped.
4300  */
4301  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
4302  continue;
4303 
4304  /* OK, make a DumpableObject for this relationship */
4305  pubrinfo[j].dobj.objType = DO_PUBLICATION_REL;
4306  pubrinfo[j].dobj.catId.tableoid =
4307  atooid(PQgetvalue(res, i, i_tableoid));
4308  pubrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4309  AssignDumpId(&pubrinfo[j].dobj);
4310  pubrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4311  pubrinfo[j].dobj.name = tbinfo->dobj.name;
4312  pubrinfo[j].publication = pubinfo;
4313  pubrinfo[j].pubtable = tbinfo;
4314  if (PQgetisnull(res, i, i_prrelqual))
4315  pubrinfo[j].pubrelqual = NULL;
4316  else
4317  pubrinfo[j].pubrelqual = pg_strdup(PQgetvalue(res, i, i_prrelqual));
4318 
4319  if (!PQgetisnull(res, i, i_prattrs))
4320  {
4321  char **attnames;
4322  int nattnames;
4323  PQExpBuffer attribs;
4324 
4325  if (!parsePGArray(PQgetvalue(res, i, i_prattrs),
4326  &attnames, &nattnames))
4327  pg_fatal("could not parse %s array", "prattrs");
4328  attribs = createPQExpBuffer();
4329  for (int k = 0; k < nattnames; k++)
4330  {
4331  if (k > 0)
4332  appendPQExpBufferStr(attribs, ", ");
4333 
4334  appendPQExpBufferStr(attribs, fmtId(attnames[k]));
4335  }
4336  pubrinfo[j].pubrattrs = attribs->data;
4337  }
4338  else
4339  pubrinfo[j].pubrattrs = NULL;
4340 
4341  /* Decide whether we want to dump it */
4342  selectDumpablePublicationObject(&(pubrinfo[j].dobj), fout);
4343 
4344  j++;
4345  }
4346 
4347  PQclear(res);
4348  destroyPQExpBuffer(query);
4349 }
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 7417 of file pg_dump.c.

7418 {
7419  PGresult *res;
7420  int ntups;
7421  int i;
7422  PQExpBuffer query = createPQExpBuffer();
7423  RuleInfo *ruleinfo;
7424  int i_tableoid;
7425  int i_oid;
7426  int i_rulename;
7427  int i_ruletable;
7428  int i_ev_type;
7429  int i_is_instead;
7430  int i_ev_enabled;
7431 
7432  appendPQExpBufferStr(query, "SELECT "
7433  "tableoid, oid, rulename, "
7434  "ev_class AS ruletable, ev_type, is_instead, "
7435  "ev_enabled "
7436  "FROM pg_rewrite "
7437  "ORDER BY oid");
7438 
7439  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7440 
7441  ntups = PQntuples(res);
7442 
7443  *numRules = ntups;
7444 
7445  ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo));
7446 
7447  i_tableoid = PQfnumber(res, "tableoid");
7448  i_oid = PQfnumber(res, "oid");
7449  i_rulename = PQfnumber(res, "rulename");
7450  i_ruletable = PQfnumber(res, "ruletable");
7451  i_ev_type = PQfnumber(res, "ev_type");
7452  i_is_instead = PQfnumber(res, "is_instead");
7453  i_ev_enabled = PQfnumber(res, "ev_enabled");
7454 
7455  for (i = 0; i < ntups; i++)
7456  {
7457  Oid ruletableoid;
7458 
7459  ruleinfo[i].dobj.objType = DO_RULE;
7460  ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7461  ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7462  AssignDumpId(&ruleinfo[i].dobj);
7463  ruleinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_rulename));
7464  ruletableoid = atooid(PQgetvalue(res, i, i_ruletable));
7465  ruleinfo[i].ruletable = findTableByOid(ruletableoid);
7466  if (ruleinfo[i].ruletable == NULL)
7467  pg_fatal("failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
7468  ruletableoid, ruleinfo[i].dobj.catId.oid);
7469  ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace;
7470  ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump;
7471  ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type));
7472  ruleinfo[i].is_instead = *(PQgetvalue(res, i, i_is_instead)) == 't';
7473  ruleinfo[i].ev_enabled = *(PQgetvalue(res, i, i_ev_enabled));
7474  if (ruleinfo[i].ruletable)
7475  {
7476  /*
7477  * If the table is a view or materialized view, force its ON
7478  * SELECT rule to be sorted before the view itself --- this
7479  * ensures that any dependencies for the rule affect the table's
7480  * positioning. Other rules are forced to appear after their
7481  * table.
7482  */
7483  if ((ruleinfo[i].ruletable->relkind == RELKIND_VIEW ||
7484  ruleinfo[i].ruletable->relkind == RELKIND_MATVIEW) &&
7485  ruleinfo[i].ev_type == '1' && ruleinfo[i].is_instead)
7486  {
7487  addObjectDependency(&ruleinfo[i].ruletable->dobj,
7488  ruleinfo[i].dobj.dumpId);
7489  /* We'll merge the rule into CREATE VIEW, if possible */
7490  ruleinfo[i].separate = false;
7491  }
7492  else
7493  {
7494  addObjectDependency(&ruleinfo[i].dobj,
7495  ruleinfo[i].ruletable->dobj.dumpId);
7496  ruleinfo[i].separate = true;
7497  }
7498  }
7499  else
7500  ruleinfo[i].separate = true;
7501  }
7502 
7503  PQclear(res);
7504 
7505  destroyPQExpBuffer(query);
7506 
7507  return ruleinfo;
7508 }
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:732
DumpableObject dobj
Definition: pg_dump.h:425
bool separate
Definition: pg_dump.h:430
char ev_enabled
Definition: pg_dump.h:429
bool is_instead
Definition: pg_dump.h:428
TableInfo * ruletable
Definition: pg_dump.h:426
char ev_type
Definition: pg_dump.h:427

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

98 {
99  TableInfo *tblinfo;
100  ExtensionInfo *extinfo;
101  InhInfo *inhinfo;
102  int numTables;
103  int numTypes;
104  int numFuncs;
105  int numOperators;
106  int numCollations;
107  int numNamespaces;
108  int numExtensions;
109  int numPublications;
110  int numAggregates;
111  int numInherits;
112  int numRules;
113  int numProcLangs;
114  int numCasts;
115  int numTransforms;
116  int numAccessMethods;
117  int numOpclasses;
118  int numOpfamilies;
119  int numConversions;
120  int numTSParsers;
121  int numTSTemplates;
122  int numTSDicts;
123  int numTSConfigs;
124  int numForeignDataWrappers;
125  int numForeignServers;
126  int numDefaultACLs;
127  int numEventTriggers;
128 
129  /*
130  * We must read extensions and extension membership info first, because
131  * extension membership needs to be consultable during decisions about
132  * whether other objects are to be dumped.
133  */
134  pg_log_info("reading extensions");
135  extinfo = getExtensions(fout, &numExtensions);
136 
137  pg_log_info("identifying extension members");
138  getExtensionMembership(fout, extinfo, numExtensions);
139 
140  pg_log_info("reading schemas");
141  (void) getNamespaces(fout, &numNamespaces);
142 
143  /*
144  * getTables should be done as soon as possible, so as to minimize the
145  * window between starting our transaction and acquiring per-table locks.
146  * However, we have to do getNamespaces first because the tables get
147  * linked to their containing namespaces during getTables.
148  */
149  pg_log_info("reading user-defined tables");
150  tblinfo = getTables(fout, &numTables);
151 
152  getOwnedSeqs(fout, tblinfo, numTables);
153 
154  pg_log_info("reading user-defined functions");
155  (void) getFuncs(fout, &numFuncs);
156 
157  /* this must be after getTables and getFuncs */
158  pg_log_info("reading user-defined types");
159  (void) getTypes(fout, &numTypes);
160 
161  /* this must be after getFuncs, too */
162  pg_log_info("reading procedural languages");
163  getProcLangs(fout, &numProcLangs);
164 
165  pg_log_info("reading user-defined aggregate functions");
166  getAggregates(fout, &numAggregates);
167 
168  pg_log_info("reading user-defined operators");
169  (void) getOperators(fout, &numOperators);
170 
171  pg_log_info("reading user-defined access methods");
172  getAccessMethods(fout, &numAccessMethods);
173 
174  pg_log_info("reading user-defined operator classes");
175  getOpclasses(fout, &numOpclasses);
176 
177  pg_log_info("reading user-defined operator families");
178  getOpfamilies(fout, &numOpfamilies);
179 
180  pg_log_info("reading user-defined text search parsers");
181  getTSParsers(fout, &numTSParsers);
182 
183  pg_log_info("reading user-defined text search templates");
184  getTSTemplates(fout, &numTSTemplates);
185 
186  pg_log_info("reading user-defined text search dictionaries");
187  getTSDictionaries(fout, &numTSDicts);
188 
189  pg_log_info("reading user-defined text search configurations");
190  getTSConfigurations(fout, &numTSConfigs);
191 
192  pg_log_info("reading user-defined foreign-data wrappers");
193  getForeignDataWrappers(fout, &numForeignDataWrappers);
194 
195  pg_log_info("reading user-defined foreign servers");
196  getForeignServers(fout, &numForeignServers);
197 
198  pg_log_info("reading default privileges");
199  getDefaultACLs(fout, &numDefaultACLs);
200 
201  pg_log_info("reading user-defined collations");
202  (void) getCollations(fout, &numCollations);
203 
204  pg_log_info("reading user-defined conversions");
205  getConversions(fout, &numConversions);
206 
207  pg_log_info("reading type casts");
208  getCasts(fout, &numCasts);
209 
210  pg_log_info("reading transforms");
211  getTransforms(fout, &numTransforms);
212 
213  pg_log_info("reading table inheritance information");
214  inhinfo = getInherits(fout, &numInherits);
215 
216  pg_log_info("reading event triggers");
217  getEventTriggers(fout, &numEventTriggers);
218 
219  /* Identify extension configuration tables that should be dumped */
220  pg_log_info("finding extension tables");
221  processExtensionTables(fout, extinfo, numExtensions);
222 
223  /* Link tables to parents, mark parents of target tables interesting */
224  pg_log_info("finding inheritance relationships");
225  flagInhTables(fout, tblinfo, numTables, inhinfo, numInherits);
226 
227  pg_log_info("reading column info for interesting tables");
228  getTableAttrs(fout, tblinfo, numTables);
229 
230  pg_log_info("flagging inherited columns in subtables");
231  flagInhAttrs(fout->dopt, tblinfo, numTables);
232 
233  pg_log_info("reading indexes");
234  getIndexes(fout, tblinfo, numTables);
235 
236  pg_log_info("flagging indexes in partitioned tables");
237  flagInhIndexes(fout, tblinfo, numTables);
238 
239  pg_log_info("reading extended statistics");
240  getExtendedStatistics(fout);
241 
242  pg_log_info("reading constraints");
243  getConstraints(fout, tblinfo, numTables);
244 
245  pg_log_info("reading triggers");
246  getTriggers(fout, tblinfo, numTables);
247 
248  pg_log_info("reading rewrite rules");
249  getRules(fout, &numRules);
250 
251  pg_log_info("reading policies");
252  getPolicies(fout, tblinfo, numTables);
253 
254  pg_log_info("reading publications");
255  (void) getPublications(fout, &numPublications);
256 
257  pg_log_info("reading publication membership of tables");
258  getPublicationTables(fout, tblinfo, numTables);
259 
260  pg_log_info("reading publication membership of schemas");
262 
263  pg_log_info("reading subscriptions");
264  getSubscriptions(fout);
265 
266  free(inhinfo); /* not needed any longer */
267 
268  *numTablesPtr = numTables;
269  return tblinfo;
270 }
static void flagInhTables(Archive *fout, TableInfo *tblinfo, int numTables, InhInfo *inhinfo, int numInherits)
Definition: common.c:285
static void flagInhIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
static void flagInhAttrs(DumpOptions *dopt, TableInfo *tblinfo, int numTables)
Definition: common.c:468
#define free(a)
Definition:</