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  _blobInfo
 
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 _blobInfo BlobInfo
 
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_BLOB ,
  DO_BLOB_DATA , DO_PRE_DATA_BOUNDARY , DO_POST_DATA_BOUNDARY , DO_EVENT_TRIGGER ,
  DO_REFRESH_MATVIEW , DO_POLICY , DO_PUBLICATION , DO_PUBLICATION_REL ,
  DO_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 *numAggregates)
 
OprInfogetOperators (Archive *fout, int *numOperators)
 
AccessMethodInfogetAccessMethods (Archive *fout, int *numAccessMethods)
 
OpclassInfogetOpclasses (Archive *fout, int *numOpclasses)
 
OpfamilyInfogetOpfamilies (Archive *fout, int *numOpfamilies)
 
CollInfogetCollations (Archive *fout, int *numCollations)
 
ConvInfogetConversions (Archive *fout, int *numConversions)
 
TableInfogetTables (Archive *fout, int *numTables)
 
void getOwnedSeqs (Archive *fout, TableInfo tblinfo[], int numTables)
 
InhInfogetInherits (Archive *fout, int *numInherits)
 
void getIndexes (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getExtendedStatistics (Archive *fout)
 
void getConstraints (Archive *fout, TableInfo tblinfo[], int numTables)
 
RuleInfogetRules (Archive *fout, int *numRules)
 
void getTriggers (Archive *fout, TableInfo tblinfo[], int numTables)
 
ProcLangInfogetProcLangs (Archive *fout, int *numProcLangs)
 
CastInfogetCasts (Archive *fout, int *numCasts)
 
TransformInfogetTransforms (Archive *fout, int *numTransforms)
 
void getTableAttrs (Archive *fout, TableInfo *tbinfo, int numTables)
 
bool shouldPrintColumn (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

◆ BlobInfo

typedef struct _blobInfo BlobInfo

◆ 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

◆ 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_BLOB 
DO_BLOB_DATA 
DO_PRE_DATA_BOUNDARY 
DO_POST_DATA_BOUNDARY 
DO_EVENT_TRIGGER 
DO_REFRESH_MATVIEW 
DO_POLICY 
DO_PUBLICATION 
DO_PUBLICATION_REL 
DO_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,
75  DO_BLOB,
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_BLOB
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_BLOB_DATA
Definition: pg_dump.h:76
@ 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_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 
)

Definition at line 720 of file common.c.

721 {
722  if (dobj->nDeps >= dobj->allocDeps)
723  {
724  if (dobj->allocDeps <= 0)
725  {
726  dobj->allocDeps = 16;
727  dobj->dependencies = (DumpId *)
728  pg_malloc(dobj->allocDeps * sizeof(DumpId));
729  }
730  else
731  {
732  dobj->allocDeps *= 2;
733  dobj->dependencies = (DumpId *)
734  pg_realloc(dobj->dependencies,
735  dobj->allocDeps * sizeof(DumpId));
736  }
737  }
738  dobj->dependencies[dobj->nDeps++] = refId;
739 }
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int DumpId
Definition: pg_backup.h:265
DumpId * dependencies
Definition: pg_dump.h:144

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

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

◆ AssignDumpId()

void AssignDumpId ( DumpableObject dobj)

Definition at line 580 of file common.c.

581 {
582  dobj->dumpId = ++lastDumpId;
583  dobj->name = NULL; /* must be set later */
584  dobj->namespace = NULL; /* may be set later */
585  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
586  dobj->dump_contains = DUMP_COMPONENT_ALL; /* default assumption */
587  /* All objects have definitions; we may set more components bits later */
589  dobj->ext_member = false; /* default assumption */
590  dobj->depends_on_ext = false; /* default assumption */
591  dobj->dependencies = NULL;
592  dobj->nDeps = 0;
593  dobj->allocDeps = 0;
594 
595  /* Add object to dumpIdMap[], enlarging that array if need be */
596  while (dobj->dumpId >= allocedDumpIds)
597  {
598  int newAlloc;
599 
600  if (allocedDumpIds <= 0)
601  {
602  newAlloc = 256;
604  pg_malloc(newAlloc * sizeof(DumpableObject *));
605  }
606  else
607  {
608  newAlloc = allocedDumpIds * 2;
610  pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
611  }
612  memset(dumpIdMap + allocedDumpIds, 0,
613  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
614  allocedDumpIds = newAlloc;
615  }
616  dumpIdMap[dobj->dumpId] = dobj;
617 
618  /* If it has a valid CatalogId, enter it into the hash table */
619  if (OidIsValid(dobj->catId.tableoid))
620  {
621  CatalogIdMapEntry *entry;
622  bool found;
623 
624  /* Initialize CatalogId hash table if not done yet */
625  if (catalogIdHash == NULL)
626  catalogIdHash = catalogid_create(CATALOGIDHASH_INITIAL_SIZE, NULL);
627 
628  entry = catalogid_insert(catalogIdHash, dobj->catId, &found);
629  if (!found)
630  {
631  entry->dobj = NULL;
632  entry->ext = NULL;
633  }
634  Assert(entry->dobj == NULL);
635  entry->dobj = dobj;
636  }
637 }
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:710
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:261
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(), pg_realloc(), and CatalogId::tableoid.

Referenced by createBoundaryObjects(), flagInhAttrs(), flagInhIndexes(), flagInhTables(), getAccessMethods(), getAggregates(), getBlobs(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDomainConstraints(), getEventTriggers(), getExtendedStatistics(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), 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 858 of file common.c.

859 {
860  CatalogId catId;
861  DumpableObject *dobj;
862 
863  catId.tableoid = CollationRelationId;
864  catId.oid = oid;
865  dobj = findObjectByCatalogId(catId);
866  Assert(dobj == NULL || dobj->objType == DO_COLLATION);
867  return (CollInfo *) dobj;
868 }
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition: common.c:679
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 894 of file common.c.

895 {
896  CatalogId catId;
897  DumpableObject *dobj;
898 
899  catId.tableoid = ExtensionRelationId;
900  catId.oid = oid;
901  dobj = findObjectByCatalogId(catId);
902  Assert(dobj == NULL || dobj->objType == DO_EXTENSION);
903  return (ExtensionInfo *) dobj;
904 }

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

Referenced by getExtensionMembership().

◆ findFuncByOid()

FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 822 of file common.c.

823 {
824  CatalogId catId;
825  DumpableObject *dobj;
826 
827  catId.tableoid = ProcedureRelationId;
828  catId.oid = oid;
829  dobj = findObjectByCatalogId(catId);
830  Assert(dobj == NULL || dobj->objType == DO_FUNC);
831  return (FuncInfo *) dobj;
832 }

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

877 {
878  CatalogId catId;
879  DumpableObject *dobj;
880 
881  catId.tableoid = NamespaceRelationId;
882  catId.oid = oid;
883  dobj = findObjectByCatalogId(catId);
884  Assert(dobj == NULL || dobj->objType == DO_NAMESPACE);
885  return (NamespaceInfo *) dobj;
886 }

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

680 {
681  CatalogIdMapEntry *entry;
682 
683  if (catalogIdHash == NULL)
684  return NULL; /* no objects exist yet */
685 
686  entry = catalogid_lookup(catalogIdHash, catalogId);
687  if (entry == NULL)
688  return NULL;
689  return entry->dobj;
690 }

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

667 {
668  if (dumpId <= 0 || dumpId >= allocedDumpIds)
669  return NULL; /* out of range? */
670  return dumpIdMap[dumpId];
671 }

References allocedDumpIds, and dumpIdMap.

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

◆ findOprByOid()

OprInfo* findOprByOid ( Oid  oid)

Definition at line 840 of file common.c.

841 {
842  CatalogId catId;
843  DumpableObject *dobj;
844 
845  catId.tableoid = OperatorRelationId;
846  catId.oid = oid;
847  dobj = findObjectByCatalogId(catId);
848  Assert(dobj == NULL || dobj->objType == DO_OPERATOR);
849  return (OprInfo *) dobj;
850 }

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

Referenced by getFormattedOperatorName().

◆ findOwningExtension()

ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 955 of file common.c.

956 {
957  CatalogIdMapEntry *entry;
958 
959  if (catalogIdHash == NULL)
960  return NULL; /* no objects exist yet */
961 
962  entry = catalogid_lookup(catalogIdHash, catalogId);
963  if (entry == NULL)
964  return NULL;
965  return entry->ext;
966 }

References catalogIdHash, and _catalogIdMapEntry::ext.

Referenced by checkExtensionMembership().

◆ findPublicationByOid()

PublicationInfo* findPublicationByOid ( Oid  oid)

Definition at line 912 of file common.c.

913 {
914  CatalogId catId;
915  DumpableObject *dobj;
916 
917  catId.tableoid = PublicationRelationId;
918  catId.oid = oid;
919  dobj = findObjectByCatalogId(catId);
920  Assert(dobj == NULL || dobj->objType == DO_PUBLICATION);
921  return (PublicationInfo *) dobj;
922 }

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

768 {
769  CatalogId catId;
770  DumpableObject *dobj;
771 
772  catId.tableoid = RelationRelationId;
773  catId.oid = oid;
774  dobj = findObjectByCatalogId(catId);
775  Assert(dobj == NULL || dobj->objType == DO_TABLE);
776  return (TableInfo *) dobj;
777 }

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

804 {
805  CatalogId catId;
806  DumpableObject *dobj;
807 
808  catId.tableoid = TypeRelationId;
809  catId.oid = oid;
810  dobj = findObjectByCatalogId(catId);
811  Assert(dobj == NULL ||
812  dobj->objType == DO_TYPE || dobj->objType == DO_DUMMY_TYPE);
813  return (TypeInfo *) dobj;
814 }

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

5558 {
5559  PGresult *res;
5560  int ntups;
5561  int i;
5562  PQExpBuffer query;
5563  AccessMethodInfo *aminfo;
5564  int i_tableoid;
5565  int i_oid;
5566  int i_amname;
5567  int i_amhandler;
5568  int i_amtype;
5569 
5570  /* Before 9.6, there are no user-defined access methods */
5571  if (fout->remoteVersion < 90600)
5572  {
5573  *numAccessMethods = 0;
5574  return NULL;
5575  }
5576 
5577  query = createPQExpBuffer();
5578 
5579  /* Select all access methods from pg_am table */
5580  appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, amtype, "
5581  "amhandler::pg_catalog.regproc AS amhandler "
5582  "FROM pg_am");
5583 
5584  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5585 
5586  ntups = PQntuples(res);
5587  *numAccessMethods = ntups;
5588 
5589  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
5590 
5591  i_tableoid = PQfnumber(res, "tableoid");
5592  i_oid = PQfnumber(res, "oid");
5593  i_amname = PQfnumber(res, "amname");
5594  i_amhandler = PQfnumber(res, "amhandler");
5595  i_amtype = PQfnumber(res, "amtype");
5596 
5597  for (i = 0; i < ntups; i++)
5598  {
5599  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
5600  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5601  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5602  AssignDumpId(&aminfo[i].dobj);
5603  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
5604  aminfo[i].dobj.namespace = NULL;
5605  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
5606  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
5607 
5608  /* Decide whether we want to dump it */
5609  selectDumpableAccessMethod(&(aminfo[i]), fout);
5610  }
5611 
5612  PQclear(res);
5613 
5614  destroyPQExpBuffer(query);
5615 
5616  return aminfo;
5617 }
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:580
void PQclear(PGresult *res)
Definition: fe-exec.c:718
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3340
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3735
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3448
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
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:291
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:1863
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
int remoteVersion
Definition: pg_backup.h:214
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 *  numAggregates 
)

Definition at line 5762 of file pg_dump.c.

5763 {
5764  DumpOptions *dopt = fout->dopt;
5765  PGresult *res;
5766  int ntups;
5767  int i;
5768  PQExpBuffer query = createPQExpBuffer();
5769  AggInfo *agginfo;
5770  int i_tableoid;
5771  int i_oid;
5772  int i_aggname;
5773  int i_aggnamespace;
5774  int i_pronargs;
5775  int i_proargtypes;
5776  int i_proowner;
5777  int i_aggacl;
5778  int i_acldefault;
5779 
5780  /*
5781  * Find all interesting aggregates. See comment in getFuncs() for the
5782  * rationale behind the filtering logic.
5783  */
5784  if (fout->remoteVersion >= 90600)
5785  {
5786  const char *agg_check;
5787 
5788  agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
5789  : "p.proisagg");
5790 
5791  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
5792  "p.proname AS aggname, "
5793  "p.pronamespace AS aggnamespace, "
5794  "p.pronargs, p.proargtypes, "
5795  "p.proowner, "
5796  "p.proacl AS aggacl, "
5797  "acldefault('f', p.proowner) AS acldefault "
5798  "FROM pg_proc p "
5799  "LEFT JOIN pg_init_privs pip ON "
5800  "(p.oid = pip.objoid "
5801  "AND pip.classoid = 'pg_proc'::regclass "
5802  "AND pip.objsubid = 0) "
5803  "WHERE %s AND ("
5804  "p.pronamespace != "
5805  "(SELECT oid FROM pg_namespace "
5806  "WHERE nspname = 'pg_catalog') OR "
5807  "p.proacl IS DISTINCT FROM pip.initprivs",
5808  agg_check);
5809  if (dopt->binary_upgrade)
5810  appendPQExpBufferStr(query,
5811  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5812  "classid = 'pg_proc'::regclass AND "
5813  "objid = p.oid AND "
5814  "refclassid = 'pg_extension'::regclass AND "
5815  "deptype = 'e')");
5816  appendPQExpBufferChar(query, ')');
5817  }
5818  else
5819  {
5820  appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
5821  "pronamespace AS aggnamespace, "
5822  "pronargs, proargtypes, "
5823  "proowner, "
5824  "proacl AS aggacl, "
5825  "acldefault('f', proowner) AS acldefault "
5826  "FROM pg_proc p "
5827  "WHERE proisagg AND ("
5828  "pronamespace != "
5829  "(SELECT oid FROM pg_namespace "
5830  "WHERE nspname = 'pg_catalog')");
5831  if (dopt->binary_upgrade)
5832  appendPQExpBufferStr(query,
5833  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5834  "classid = 'pg_proc'::regclass AND "
5835  "objid = p.oid AND "
5836  "refclassid = 'pg_extension'::regclass AND "
5837  "deptype = 'e')");
5838  appendPQExpBufferChar(query, ')');
5839  }
5840 
5841  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5842 
5843  ntups = PQntuples(res);
5844  *numAggs = ntups;
5845 
5846  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
5847 
5848  i_tableoid = PQfnumber(res, "tableoid");
5849  i_oid = PQfnumber(res, "oid");
5850  i_aggname = PQfnumber(res, "aggname");
5851  i_aggnamespace = PQfnumber(res, "aggnamespace");
5852  i_pronargs = PQfnumber(res, "pronargs");
5853  i_proargtypes = PQfnumber(res, "proargtypes");
5854  i_proowner = PQfnumber(res, "proowner");
5855  i_aggacl = PQfnumber(res, "aggacl");
5856  i_acldefault = PQfnumber(res, "acldefault");
5857 
5858  for (i = 0; i < ntups; i++)
5859  {
5860  agginfo[i].aggfn.dobj.objType = DO_AGG;
5861  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5862  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5863  AssignDumpId(&agginfo[i].aggfn.dobj);
5864  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
5865  agginfo[i].aggfn.dobj.namespace =
5866  findNamespace(atooid(PQgetvalue(res, i, i_aggnamespace)));
5867  agginfo[i].aggfn.dacl.acl = pg_strdup(PQgetvalue(res, i, i_aggacl));
5868  agginfo[i].aggfn.dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
5869  agginfo[i].aggfn.dacl.privtype = 0;
5870  agginfo[i].aggfn.dacl.initprivs = NULL;
5871  agginfo[i].aggfn.rolname = getRoleName(PQgetvalue(res, i, i_proowner));
5872  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
5873  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
5874  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
5875  if (agginfo[i].aggfn.nargs == 0)
5876  agginfo[i].aggfn.argtypes = NULL;
5877  else
5878  {
5879  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
5880  parseOidArray(PQgetvalue(res, i, i_proargtypes),
5881  agginfo[i].aggfn.argtypes,
5882  agginfo[i].aggfn.nargs);
5883  }
5884 
5885  /* Decide whether we want to dump it */
5886  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
5887 
5888  /* Mark whether aggregate has an ACL */
5889  if (!PQgetisnull(res, i, i_aggacl))
5890  agginfo[i].aggfn.dobj.components |= DUMP_COMPONENT_ACL;
5891  }
5892 
5893  PQclear(res);
5894 
5895  destroyPQExpBuffer(query);
5896 
5897  return agginfo;
5898 }
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1026
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3760
static const char * getRoleName(const char *roleoid_str)
Definition: pg_dump.c:9201
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1940
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:5084
#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:267
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
DumpOptions * dopt
Definition: pg_backup.h:209
int binary_upgrade
Definition: pg_backup.h:161

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

7846 {
7847  PGresult *res;
7848  int ntups;
7849  int i;
7850  PQExpBuffer query = createPQExpBuffer();
7851  CastInfo *castinfo;
7852  int i_tableoid;
7853  int i_oid;
7854  int i_castsource;
7855  int i_casttarget;
7856  int i_castfunc;
7857  int i_castcontext;
7858  int i_castmethod;
7859 
7860  if (fout->remoteVersion >= 140000)
7861  {
7862  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7863  "castsource, casttarget, castfunc, castcontext, "
7864  "castmethod "
7865  "FROM pg_cast c "
7866  "WHERE NOT EXISTS ( "
7867  "SELECT 1 FROM pg_range r "
7868  "WHERE c.castsource = r.rngtypid "
7869  "AND c.casttarget = r.rngmultitypid "
7870  ") "
7871  "ORDER BY 3,4");
7872  }
7873  else
7874  {
7875  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
7876  "castsource, casttarget, castfunc, castcontext, "
7877  "castmethod "
7878  "FROM pg_cast ORDER BY 3,4");
7879  }
7880 
7881  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7882 
7883  ntups = PQntuples(res);
7884 
7885  *numCasts = ntups;
7886 
7887  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
7888 
7889  i_tableoid = PQfnumber(res, "tableoid");
7890  i_oid = PQfnumber(res, "oid");
7891  i_castsource = PQfnumber(res, "castsource");
7892  i_casttarget = PQfnumber(res, "casttarget");
7893  i_castfunc = PQfnumber(res, "castfunc");
7894  i_castcontext = PQfnumber(res, "castcontext");
7895  i_castmethod = PQfnumber(res, "castmethod");
7896 
7897  for (i = 0; i < ntups; i++)
7898  {
7899  PQExpBufferData namebuf;
7900  TypeInfo *sTypeInfo;
7901  TypeInfo *tTypeInfo;
7902 
7903  castinfo[i].dobj.objType = DO_CAST;
7904  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7905  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7906  AssignDumpId(&castinfo[i].dobj);
7907  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
7908  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
7909  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
7910  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
7911  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
7912 
7913  /*
7914  * Try to name cast as concatenation of typnames. This is only used
7915  * for purposes of sorting. If we fail to find either type, the name
7916  * will be an empty string.
7917  */
7918  initPQExpBuffer(&namebuf);
7919  sTypeInfo = findTypeByOid(castinfo[i].castsource);
7920  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
7921  if (sTypeInfo && tTypeInfo)
7922  appendPQExpBuffer(&namebuf, "%s %s",
7923  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
7924  castinfo[i].dobj.name = namebuf.data;
7925 
7926  /* Decide whether we want to dump it */
7927  selectDumpableCast(&(castinfo[i]), fout);
7928  }
7929 
7930  PQclear(res);
7931 
7932  destroyPQExpBuffer(query);
7933 
7934  return castinfo;
7935 }
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:803
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:1805
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
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 5421 of file pg_dump.c.

5422 {
5423  PGresult *res;
5424  int ntups;
5425  int i;
5426  PQExpBuffer query;
5427  CollInfo *collinfo;
5428  int i_tableoid;
5429  int i_oid;
5430  int i_collname;
5431  int i_collnamespace;
5432  int i_collowner;
5433 
5434  query = createPQExpBuffer();
5435 
5436  /*
5437  * find all collations, including builtin collations; we filter out
5438  * system-defined collations at dump-out time.
5439  */
5440 
5441  appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
5442  "collnamespace, "
5443  "collowner "
5444  "FROM pg_collation");
5445 
5446  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5447 
5448  ntups = PQntuples(res);
5449  *numCollations = ntups;
5450 
5451  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
5452 
5453  i_tableoid = PQfnumber(res, "tableoid");
5454  i_oid = PQfnumber(res, "oid");
5455  i_collname = PQfnumber(res, "collname");
5456  i_collnamespace = PQfnumber(res, "collnamespace");
5457  i_collowner = PQfnumber(res, "collowner");
5458 
5459  for (i = 0; i < ntups; i++)
5460  {
5461  collinfo[i].dobj.objType = DO_COLLATION;
5462  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5463  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5464  AssignDumpId(&collinfo[i].dobj);
5465  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
5466  collinfo[i].dobj.namespace =
5467  findNamespace(atooid(PQgetvalue(res, i, i_collnamespace)));
5468  collinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_collowner));
5469 
5470  /* Decide whether we want to dump it */
5471  selectDumpableObject(&(collinfo[i].dobj), fout);
5472  }
5473 
5474  PQclear(res);
5475 
5476  destroyPQExpBuffer(query);
5477 
5478  return collinfo;
5479 }
const char * rolname
Definition: pg_dump.h:269
DumpableObject dobj
Definition: pg_dump.h:268

References appendPQExpBuffer(), 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 7017 of file pg_dump.c.

7018 {
7019  PQExpBuffer query = createPQExpBuffer();
7020  PQExpBuffer tbloids = createPQExpBuffer();
7021  PGresult *res;
7022  int ntups;
7023  int curtblindx;
7024  TableInfo *tbinfo = NULL;
7025  ConstraintInfo *constrinfo;
7026  int i_contableoid,
7027  i_conoid,
7028  i_conrelid,
7029  i_conname,
7030  i_confrelid,
7031  i_conindid,
7032  i_condef;
7033 
7034  /*
7035  * We want to perform just one query against pg_constraint. However, we
7036  * mustn't try to select every row of the catalog and then sort it out on
7037  * the client side, because some of the server-side functions we need
7038  * would be unsafe to apply to tables we don't have lock on. Hence, we
7039  * build an array of the OIDs of tables we care about (and now have lock
7040  * on!), and use a WHERE clause to constrain which rows are selected.
7041  */
7042  appendPQExpBufferChar(tbloids, '{');
7043  for (int i = 0; i < numTables; i++)
7044  {
7045  TableInfo *tbinfo = &tblinfo[i];
7046 
7047  /*
7048  * For partitioned tables, foreign keys have no triggers so they must
7049  * be included anyway in case some foreign keys are defined.
7050  */
7051  if ((!tbinfo->hastriggers &&
7052  tbinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7053  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
7054  continue;
7055 
7056  /* OK, we need info for this table */
7057  if (tbloids->len > 1) /* do we have more than the '{'? */
7058  appendPQExpBufferChar(tbloids, ',');
7059  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
7060  }
7061  appendPQExpBufferChar(tbloids, '}');
7062 
7063  appendPQExpBufferStr(query,
7064  "SELECT c.tableoid, c.oid, "
7065  "conrelid, conname, confrelid, ");
7066  if (fout->remoteVersion >= 110000)
7067  appendPQExpBufferStr(query, "conindid, ");
7068  else
7069  appendPQExpBufferStr(query, "0 AS conindid, ");
7070  appendPQExpBuffer(query,
7071  "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
7072  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7073  "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
7074  "WHERE contype = 'f' ",
7075  tbloids->data);
7076  if (fout->remoteVersion >= 110000)
7077  appendPQExpBufferStr(query,
7078  "AND conparentid = 0 ");
7079  appendPQExpBufferStr(query,
7080  "ORDER BY conrelid, conname");
7081 
7082  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7083 
7084  ntups = PQntuples(res);
7085 
7086  i_contableoid = PQfnumber(res, "tableoid");
7087  i_conoid = PQfnumber(res, "oid");
7088  i_conrelid = PQfnumber(res, "conrelid");
7089  i_conname = PQfnumber(res, "conname");
7090  i_confrelid = PQfnumber(res, "confrelid");
7091  i_conindid = PQfnumber(res, "conindid");
7092  i_condef = PQfnumber(res, "condef");
7093 
7094  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7095 
7096  curtblindx = -1;
7097  for (int j = 0; j < ntups; j++)
7098  {
7099  Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
7100  TableInfo *reftable;
7101 
7102  /*
7103  * Locate the associated TableInfo; we rely on tblinfo[] being in OID
7104  * order.
7105  */
7106  if (tbinfo == NULL || tbinfo->dobj.catId.oid != conrelid)
7107  {
7108  while (++curtblindx < numTables)
7109  {
7110  tbinfo = &tblinfo[curtblindx];
7111  if (tbinfo->dobj.catId.oid == conrelid)
7112  break;
7113  }
7114  if (curtblindx >= numTables)
7115  pg_fatal("unrecognized table OID %u", conrelid);
7116  }
7117 
7118  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
7119  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7120  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7121  AssignDumpId(&constrinfo[j].dobj);
7122  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7123  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7124  constrinfo[j].contable = tbinfo;
7125  constrinfo[j].condomain = NULL;
7126  constrinfo[j].contype = 'f';
7127  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7128  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
7129  constrinfo[j].conindex = 0;
7130  constrinfo[j].condeferrable = false;
7131  constrinfo[j].condeferred = false;
7132  constrinfo[j].conislocal = true;
7133  constrinfo[j].separate = true;
7134 
7135  /*
7136  * Restoring an FK that points to a partitioned table requires that
7137  * all partition indexes have been attached beforehand. Ensure that
7138  * happens by making the constraint depend on each index partition
7139  * attach object.
7140  */
7141  reftable = findTableByOid(constrinfo[j].confrelid);
7142  if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
7143  {
7144  Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
7145 
7146  if (indexOid != InvalidOid)
7147  {
7148  for (int k = 0; k < reftable->numIndexes; k++)
7149  {
7150  IndxInfo *refidx;
7151 
7152  /* not our index? */
7153  if (reftable->indexes[k].dobj.catId.oid != indexOid)
7154  continue;
7155 
7156  refidx = &reftable->indexes[k];
7157  addConstrChildIdxDeps(&constrinfo[j].dobj, refidx);
7158  break;
7159  }
7160  }
7161  }
7162  }
7163 
7164  PQclear(res);
7165 
7166  destroyPQExpBuffer(query);
7167  destroyPQExpBuffer(tbloids);
7168 }
TableInfo * findTableByOid(Oid oid)
Definition: common.c:767
int j
Definition: isn.c:74
#define pg_fatal(...)
static void addConstrChildIdxDeps(DumpableObject *dobj, const IndxInfo *refidx)
Definition: pg_dump.c:7182
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
bool hastriggers
Definition: pg_dump.h:296
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, _dumpableObject::dump, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), findTableByOid(), _tableInfo::hastriggers, 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, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getConversions()

ConvInfo* getConversions ( Archive fout,
int *  numConversions 
)

Definition at line 5489 of file pg_dump.c.

5490 {
5491  PGresult *res;
5492  int ntups;
5493  int i;
5494  PQExpBuffer query;
5495  ConvInfo *convinfo;
5496  int i_tableoid;
5497  int i_oid;
5498  int i_conname;
5499  int i_connamespace;
5500  int i_conowner;
5501 
5502  query = createPQExpBuffer();
5503 
5504  /*
5505  * find all conversions, including builtin conversions; we filter out
5506  * system-defined conversions at dump-out time.
5507  */
5508 
5509  appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
5510  "connamespace, "
5511  "conowner "
5512  "FROM pg_conversion");
5513 
5514  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5515 
5516  ntups = PQntuples(res);
5517  *numConversions = ntups;
5518 
5519  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
5520 
5521  i_tableoid = PQfnumber(res, "tableoid");
5522  i_oid = PQfnumber(res, "oid");
5523  i_conname = PQfnumber(res, "conname");
5524  i_connamespace = PQfnumber(res, "connamespace");
5525  i_conowner = PQfnumber(res, "conowner");
5526 
5527  for (i = 0; i < ntups; i++)
5528  {
5529  convinfo[i].dobj.objType = DO_CONVERSION;
5530  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5531  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5532  AssignDumpId(&convinfo[i].dobj);
5533  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
5534  convinfo[i].dobj.namespace =
5535  findNamespace(atooid(PQgetvalue(res, i, i_connamespace)));
5536  convinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_conowner));
5537 
5538  /* Decide whether we want to dump it */
5539  selectDumpableObject(&(convinfo[i].dobj), fout);
5540  }
5541 
5542  PQclear(res);
5543 
5544  destroyPQExpBuffer(query);
5545 
5546  return convinfo;
5547 }
DumpableObject dobj
Definition: pg_dump.h:274
const char * rolname
Definition: pg_dump.h:275

References appendPQExpBuffer(), 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 9101 of file pg_dump.c.

9102 {
9103  DumpOptions *dopt = fout->dopt;
9104  DefaultACLInfo *daclinfo;
9105  PQExpBuffer query;
9106  PGresult *res;
9107  int i_oid;
9108  int i_tableoid;
9109  int i_defaclrole;
9110  int i_defaclnamespace;
9111  int i_defaclobjtype;
9112  int i_defaclacl;
9113  int i_acldefault;
9114  int i,
9115  ntups;
9116 
9117  query = createPQExpBuffer();
9118 
9119  /*
9120  * Global entries (with defaclnamespace=0) replace the hard-wired default
9121  * ACL for their object type. We should dump them as deltas from the
9122  * default ACL, since that will be used as a starting point for
9123  * interpreting the ALTER DEFAULT PRIVILEGES commands. On the other hand,
9124  * non-global entries can only add privileges not revoke them. We must
9125  * dump those as-is (i.e., as deltas from an empty ACL).
9126  *
9127  * We can use defaclobjtype as the object type for acldefault(), except
9128  * for the case of 'S' (DEFACLOBJ_SEQUENCE) which must be converted to
9129  * 's'.
9130  */
9131  appendPQExpBuffer(query,
9132  "SELECT oid, tableoid, "
9133  "defaclrole, "
9134  "defaclnamespace, "
9135  "defaclobjtype, "
9136  "defaclacl, "
9137  "CASE WHEN defaclnamespace = 0 THEN "
9138  "acldefault(CASE WHEN defaclobjtype = 'S' "
9139  "THEN 's'::\"char\" ELSE defaclobjtype END, "
9140  "defaclrole) ELSE '{}' END AS acldefault "
9141  "FROM pg_default_acl");
9142 
9143  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9144 
9145  ntups = PQntuples(res);
9146  *numDefaultACLs = ntups;
9147 
9148  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9149 
9150  i_oid = PQfnumber(res, "oid");
9151  i_tableoid = PQfnumber(res, "tableoid");
9152  i_defaclrole = PQfnumber(res, "defaclrole");
9153  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9154  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9155  i_defaclacl = PQfnumber(res, "defaclacl");
9156  i_acldefault = PQfnumber(res, "acldefault");
9157 
9158  for (i = 0; i < ntups; i++)
9159  {
9160  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9161 
9162  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9163  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9164  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9165  AssignDumpId(&daclinfo[i].dobj);
9166  /* cheesy ... is it worth coming up with a better object name? */
9167  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9168 
9169  if (nspid != InvalidOid)
9170  daclinfo[i].dobj.namespace = findNamespace(nspid);
9171  else
9172  daclinfo[i].dobj.namespace = NULL;
9173 
9174  daclinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9175  daclinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9176  daclinfo[i].dacl.privtype = 0;
9177  daclinfo[i].dacl.initprivs = NULL;
9178  daclinfo[i].defaclrole = getRoleName(PQgetvalue(res, i, i_defaclrole));
9179  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9180 
9181  /* Default ACLs are ACLs, of course */
9182  daclinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9183 
9184  /* Decide whether we want to dump it */
9185  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9186  }
9187 
9188  PQclear(res);
9189 
9190  destroyPQExpBuffer(query);
9191 
9192  return daclinfo;
9193 }
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition: pg_dump.c:1783
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, appendPQExpBuffer(), 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, _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 698 of file common.c.

699 {
700  int i,
701  j;
702 
703  *objs = (DumpableObject **)
705  j = 0;
706  for (i = 1; i < allocedDumpIds; i++)
707  {
708  if (dumpIdMap[i])
709  (*objs)[j++] = dumpIdMap[i];
710  }
711  *numObjs = j;
712 }

References allocedDumpIds, dumpIdMap, i, j, and pg_malloc().

Referenced by getTableDataFKConstraints(), and main().

◆ getEventTriggers()

EventTriggerInfo* getEventTriggers ( Archive fout,
int *  numEventTriggers 
)

Definition at line 7668 of file pg_dump.c.

7669 {
7670  int i;
7671  PQExpBuffer query;
7672  PGresult *res;
7673  EventTriggerInfo *evtinfo;
7674  int i_tableoid,
7675  i_oid,
7676  i_evtname,
7677  i_evtevent,
7678  i_evtowner,
7679  i_evttags,
7680  i_evtfname,
7681  i_evtenabled;
7682  int ntups;
7683 
7684  /* Before 9.3, there are no event triggers */
7685  if (fout->remoteVersion < 90300)
7686  {
7687  *numEventTriggers = 0;
7688  return NULL;
7689  }
7690 
7691  query = createPQExpBuffer();
7692 
7693  appendPQExpBuffer(query,
7694  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
7695  "evtevent, evtowner, "
7696  "array_to_string(array("
7697  "select quote_literal(x) "
7698  " from unnest(evttags) as t(x)), ', ') as evttags, "
7699  "e.evtfoid::regproc as evtfname "
7700  "FROM pg_event_trigger e "
7701  "ORDER BY e.oid");
7702 
7703  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7704 
7705  ntups = PQntuples(res);
7706 
7707  *numEventTriggers = ntups;
7708 
7709  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
7710 
7711  i_tableoid = PQfnumber(res, "tableoid");
7712  i_oid = PQfnumber(res, "oid");
7713  i_evtname = PQfnumber(res, "evtname");
7714  i_evtevent = PQfnumber(res, "evtevent");
7715  i_evtowner = PQfnumber(res, "evtowner");
7716  i_evttags = PQfnumber(res, "evttags");
7717  i_evtfname = PQfnumber(res, "evtfname");
7718  i_evtenabled = PQfnumber(res, "evtenabled");
7719 
7720  for (i = 0; i < ntups; i++)
7721  {
7722  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
7723  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7724  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7725  AssignDumpId(&evtinfo[i].dobj);
7726  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
7727  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
7728  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
7729  evtinfo[i].evtowner = getRoleName(PQgetvalue(res, i, i_evtowner));
7730  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
7731  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
7732  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
7733 
7734  /* Decide whether we want to dump it */
7735  selectDumpableObject(&(evtinfo[i].dobj), fout);
7736  }
7737 
7738  PQclear(res);
7739 
7740  destroyPQExpBuffer(query);
7741 
7742  return evtinfo;
7743 }
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 appendPQExpBuffer(), 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 6945 of file pg_dump.c.

6946 {
6947  PQExpBuffer query;
6948  PGresult *res;
6949  StatsExtInfo *statsextinfo;
6950  int ntups;
6951  int i_tableoid;
6952  int i_oid;
6953  int i_stxname;
6954  int i_stxnamespace;
6955  int i_stxowner;
6956  int i_stattarget;
6957  int i;
6958 
6959  /* Extended statistics were new in v10 */
6960  if (fout->remoteVersion < 100000)
6961  return;
6962 
6963  query = createPQExpBuffer();
6964 
6965  if (fout->remoteVersion < 130000)
6966  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
6967  "stxnamespace, stxowner, (-1) AS stxstattarget "
6968  "FROM pg_catalog.pg_statistic_ext");
6969  else
6970  appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
6971  "stxnamespace, stxowner, stxstattarget "
6972  "FROM pg_catalog.pg_statistic_ext");
6973 
6974  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6975 
6976  ntups = PQntuples(res);
6977 
6978  i_tableoid = PQfnumber(res, "tableoid");
6979  i_oid = PQfnumber(res, "oid");
6980  i_stxname = PQfnumber(res, "stxname");
6981  i_stxnamespace = PQfnumber(res, "stxnamespace");
6982  i_stxowner = PQfnumber(res, "stxowner");
6983  i_stattarget = PQfnumber(res, "stxstattarget");
6984 
6985  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
6986 
6987  for (i = 0; i < ntups; i++)
6988  {
6989  statsextinfo[i].dobj.objType = DO_STATSEXT;
6990  statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6991  statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6992  AssignDumpId(&statsextinfo[i].dobj);
6993  statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
6994  statsextinfo[i].dobj.namespace =
6995  findNamespace(atooid(PQgetvalue(res, i, i_stxnamespace)));
6996  statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
6997  statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
6998 
6999  /* Decide whether we want to dump it */
7000  selectDumpableObject(&(statsextinfo[i].dobj), fout);
7001  }
7002 
7003  PQclear(res);
7004  destroyPQExpBuffer(query);
7005 }
int stattarget
Definition: pg_dump.h:420
const char * rolname
Definition: pg_dump.h:419
DumpableObject dobj
Definition: pg_dump.h:418

References appendPQExpBuffer(), 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 17368 of file pg_dump.c.

17370 {
17371  PQExpBuffer query;
17372  PGresult *res;
17373  int ntups,
17374  i;
17375  int i_classid,
17376  i_objid,
17377  i_refobjid;
17378  ExtensionInfo *ext;
17379 
17380  /* Nothing to do if no extensions */
17381  if (numExtensions == 0)
17382  return;
17383 
17384  query = createPQExpBuffer();
17385 
17386  /* refclassid constraint is redundant but may speed the search */
17387  appendPQExpBufferStr(query, "SELECT "
17388  "classid, objid, refobjid "
17389  "FROM pg_depend "
17390  "WHERE refclassid = 'pg_extension'::regclass "
17391  "AND deptype = 'e' "
17392  "ORDER BY 3");
17393 
17394  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
17395 
17396  ntups = PQntuples(res);
17397 
17398  i_classid = PQfnumber(res, "classid");
17399  i_objid = PQfnumber(res, "objid");
17400  i_refobjid = PQfnumber(res, "refobjid");
17401 
17402  /*
17403  * Since we ordered the SELECT by referenced ID, we can expect that
17404  * multiple entries for the same extension will appear together; this
17405  * saves on searches.
17406  */
17407  ext = NULL;
17408 
17409  for (i = 0; i < ntups; i++)
17410  {
17411  CatalogId objId;
17412  Oid extId;
17413 
17414  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
17415  objId.oid = atooid(PQgetvalue(res, i, i_objid));
17416  extId = atooid(PQgetvalue(res, i, i_refobjid));
17417 
17418  if (ext == NULL ||
17419  ext->dobj.catId.oid != extId)
17420  ext = findExtensionByOid(extId);
17421 
17422  if (ext == NULL)
17423  {
17424  /* shouldn't happen */
17425  pg_log_warning("could not find referenced extension %u", extId);
17426  continue;
17427  }
17428 
17429  recordExtensionMembership(objId, ext);
17430  }
17431 
17432  PQclear(res);
17433 
17434  destroyPQExpBuffer(query);
17435 }
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition: common.c:931
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:894
#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 5102 of file pg_dump.c.

5103 {
5104  DumpOptions *dopt = fout->dopt;
5105  PGresult *res;
5106  int ntups;
5107  int i;
5108  PQExpBuffer query;
5109  ExtensionInfo *extinfo;
5110  int i_tableoid;
5111  int i_oid;
5112  int i_extname;
5113  int i_nspname;
5114  int i_extrelocatable;
5115  int i_extversion;
5116  int i_extconfig;
5117  int i_extcondition;
5118 
5119  query = createPQExpBuffer();
5120 
5121  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
5122  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
5123  "FROM pg_extension x "
5124  "JOIN pg_namespace n ON n.oid = x.extnamespace");
5125 
5126  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5127 
5128  ntups = PQntuples(res);
5129 
5130  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
5131 
5132  i_tableoid = PQfnumber(res, "tableoid");
5133  i_oid = PQfnumber(res, "oid");
5134  i_extname = PQfnumber(res, "extname");
5135  i_nspname = PQfnumber(res, "nspname");
5136  i_extrelocatable = PQfnumber(res, "extrelocatable");
5137  i_extversion = PQfnumber(res, "extversion");
5138  i_extconfig = PQfnumber(res, "extconfig");
5139  i_extcondition = PQfnumber(res, "extcondition");
5140 
5141  for (i = 0; i < ntups; i++)
5142  {
5143  extinfo[i].dobj.objType = DO_EXTENSION;
5144  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5145  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5146  AssignDumpId(&extinfo[i].dobj);
5147  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
5148  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
5149  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
5150  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
5151  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
5152  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
5153 
5154  /* Decide whether we want to dump it */
5155  selectDumpableExtension(&(extinfo[i]), dopt);
5156  }
5157 
5158  PQclear(res);
5159  destroyPQExpBuffer(query);
5160 
5161  *numExtensions = ntups;
5162 
5163  return extinfo;
5164 }
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:1891
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 8917 of file pg_dump.c.

8918 {
8919  PGresult *res;
8920  int ntups;
8921  int i;
8922  PQExpBuffer query;
8923  FdwInfo *fdwinfo;
8924  int i_tableoid;
8925  int i_oid;
8926  int i_fdwname;
8927  int i_fdwowner;
8928  int i_fdwhandler;
8929  int i_fdwvalidator;
8930  int i_fdwacl;
8931  int i_acldefault;
8932  int i_fdwoptions;
8933 
8934  query = createPQExpBuffer();
8935 
8936  appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
8937  "fdwowner, "
8938  "fdwhandler::pg_catalog.regproc, "
8939  "fdwvalidator::pg_catalog.regproc, "
8940  "fdwacl, "
8941  "acldefault('F', fdwowner) AS acldefault, "
8942  "array_to_string(ARRAY("
8943  "SELECT quote_ident(option_name) || ' ' || "
8944  "quote_literal(option_value) "
8945  "FROM pg_options_to_table(fdwoptions) "
8946  "ORDER BY option_name"
8947  "), E',\n ') AS fdwoptions "
8948  "FROM pg_foreign_data_wrapper");
8949 
8950  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8951 
8952  ntups = PQntuples(res);
8953  *numForeignDataWrappers = ntups;
8954 
8955  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
8956 
8957  i_tableoid = PQfnumber(res, "tableoid");
8958  i_oid = PQfnumber(res, "oid");
8959  i_fdwname = PQfnumber(res, "fdwname");
8960  i_fdwowner = PQfnumber(res, "fdwowner");
8961  i_fdwhandler = PQfnumber(res, "fdwhandler");
8962  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
8963  i_fdwacl = PQfnumber(res, "fdwacl");
8964  i_acldefault = PQfnumber(res, "acldefault");
8965  i_fdwoptions = PQfnumber(res, "fdwoptions");
8966 
8967  for (i = 0; i < ntups; i++)
8968  {
8969  fdwinfo[i].dobj.objType = DO_FDW;
8970  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8971  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8972  AssignDumpId(&fdwinfo[i].dobj);
8973  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
8974  fdwinfo[i].dobj.namespace = NULL;
8975  fdwinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
8976  fdwinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
8977  fdwinfo[i].dacl.privtype = 0;
8978  fdwinfo[i].dacl.initprivs = NULL;
8979  fdwinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_fdwowner));
8980  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
8981  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
8982  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
8983 
8984  /* Decide whether we want to dump it */
8985  selectDumpableObject(&(fdwinfo[i].dobj), fout);
8986 
8987  /* Mark whether FDW has an ACL */
8988  if (!PQgetisnull(res, i, i_fdwacl))
8989  fdwinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
8990  }
8991 
8992  PQclear(res);
8993 
8994  destroyPQExpBuffer(query);
8995 
8996  return fdwinfo;
8997 }
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, appendPQExpBuffer(), 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 9007 of file pg_dump.c.

9008 {
9009  PGresult *res;
9010  int ntups;
9011  int i;
9012  PQExpBuffer query;
9013  ForeignServerInfo *srvinfo;
9014  int i_tableoid;
9015  int i_oid;
9016  int i_srvname;
9017  int i_srvowner;
9018  int i_srvfdw;
9019  int i_srvtype;
9020  int i_srvversion;
9021  int i_srvacl;
9022  int i_acldefault;
9023  int i_srvoptions;
9024 
9025  query = createPQExpBuffer();
9026 
9027  appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
9028  "srvowner, "
9029  "srvfdw, srvtype, srvversion, srvacl, "
9030  "acldefault('S', srvowner) AS acldefault, "
9031  "array_to_string(ARRAY("
9032  "SELECT quote_ident(option_name) || ' ' || "
9033  "quote_literal(option_value) "
9034  "FROM pg_options_to_table(srvoptions) "
9035  "ORDER BY option_name"
9036  "), E',\n ') AS srvoptions "
9037  "FROM pg_foreign_server");
9038 
9039  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9040 
9041  ntups = PQntuples(res);
9042  *numForeignServers = ntups;
9043 
9044  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
9045 
9046  i_tableoid = PQfnumber(res, "tableoid");
9047  i_oid = PQfnumber(res, "oid");
9048  i_srvname = PQfnumber(res, "srvname");
9049  i_srvowner = PQfnumber(res, "srvowner");
9050  i_srvfdw = PQfnumber(res, "srvfdw");
9051  i_srvtype = PQfnumber(res, "srvtype");
9052  i_srvversion = PQfnumber(res, "srvversion");
9053  i_srvacl = PQfnumber(res, "srvacl");
9054  i_acldefault = PQfnumber(res, "acldefault");
9055  i_srvoptions = PQfnumber(res, "srvoptions");
9056 
9057  for (i = 0; i < ntups; i++)
9058  {
9059  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
9060  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9061  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9062  AssignDumpId(&srvinfo[i].dobj);
9063  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
9064  srvinfo[i].dobj.namespace = NULL;
9065  srvinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_srvacl));
9066  srvinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9067  srvinfo[i].dacl.privtype = 0;
9068  srvinfo[i].dacl.initprivs = NULL;
9069  srvinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_srvowner));
9070  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
9071  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
9072  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
9073  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
9074 
9075  /* Decide whether we want to dump it */
9076  selectDumpableObject(&(srvinfo[i].dobj), fout);
9077 
9078  /* Servers have user mappings */
9080 
9081  /* Mark whether server has an ACL */
9082  if (!PQgetisnull(res, i, i_srvacl))
9083  srvinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9084  }
9085 
9086  PQclear(res);
9087 
9088  destroyPQExpBuffer(query);
9089 
9090  return srvinfo;
9091 }
#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, appendPQExpBuffer(), 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 5908 of file pg_dump.c.

5909 {
5910  DumpOptions *dopt = fout->dopt;
5911  PGresult *res;
5912  int ntups;
5913  int i;
5914  PQExpBuffer query = createPQExpBuffer();
5915  FuncInfo *finfo;
5916  int i_tableoid;
5917  int i_oid;
5918  int i_proname;
5919  int i_pronamespace;
5920  int i_proowner;
5921  int i_prolang;
5922  int i_pronargs;
5923  int i_proargtypes;
5924  int i_prorettype;
5925  int i_proacl;
5926  int i_acldefault;
5927 
5928  /*
5929  * Find all interesting functions. This is a bit complicated:
5930  *
5931  * 1. Always exclude aggregates; those are handled elsewhere.
5932  *
5933  * 2. Always exclude functions that are internally dependent on something
5934  * else, since presumably those will be created as a result of creating
5935  * the something else. This currently acts only to suppress constructor
5936  * functions for range types. Note this is OK only because the
5937  * constructors don't have any dependencies the range type doesn't have;
5938  * otherwise we might not get creation ordering correct.
5939  *
5940  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
5941  * they're members of extensions and we are in binary-upgrade mode then
5942  * include them, since we want to dump extension members individually in
5943  * that mode. Also, if they are used by casts or transforms then we need
5944  * to gather the information about them, though they won't be dumped if
5945  * they are built-in. Also, in 9.6 and up, include functions in
5946  * pg_catalog if they have an ACL different from what's shown in
5947  * pg_init_privs (so we have to join to pg_init_privs; annoying).
5948  */
5949  if (fout->remoteVersion >= 90600)
5950  {
5951  const char *not_agg_check;
5952 
5953  not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
5954  : "NOT p.proisagg");
5955 
5956  appendPQExpBuffer(query,
5957  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
5958  "p.pronargs, p.proargtypes, p.prorettype, "
5959  "p.proacl, "
5960  "acldefault('f', p.proowner) AS acldefault, "
5961  "p.pronamespace, "
5962  "p.proowner "
5963  "FROM pg_proc p "
5964  "LEFT JOIN pg_init_privs pip ON "
5965  "(p.oid = pip.objoid "
5966  "AND pip.classoid = 'pg_proc'::regclass "
5967  "AND pip.objsubid = 0) "
5968  "WHERE %s"
5969  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
5970  "WHERE classid = 'pg_proc'::regclass AND "
5971  "objid = p.oid AND deptype = 'i')"
5972  "\n AND ("
5973  "\n pronamespace != "
5974  "(SELECT oid FROM pg_namespace "
5975  "WHERE nspname = 'pg_catalog')"
5976  "\n OR EXISTS (SELECT 1 FROM pg_cast"
5977  "\n WHERE pg_cast.oid > %u "
5978  "\n AND p.oid = pg_cast.castfunc)"
5979  "\n OR EXISTS (SELECT 1 FROM pg_transform"
5980  "\n WHERE pg_transform.oid > %u AND "
5981  "\n (p.oid = pg_transform.trffromsql"
5982  "\n OR p.oid = pg_transform.trftosql))",
5983  not_agg_check,
5986  if (dopt->binary_upgrade)
5987  appendPQExpBufferStr(query,
5988  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
5989  "classid = 'pg_proc'::regclass AND "
5990  "objid = p.oid AND "
5991  "refclassid = 'pg_extension'::regclass AND "
5992  "deptype = 'e')");
5993  appendPQExpBufferStr(query,
5994  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
5995  appendPQExpBufferChar(query, ')');
5996  }
5997  else
5998  {
5999  appendPQExpBuffer(query,
6000  "SELECT tableoid, oid, proname, prolang, "
6001  "pronargs, proargtypes, prorettype, proacl, "
6002  "acldefault('f', proowner) AS acldefault, "
6003  "pronamespace, "
6004  "proowner "
6005  "FROM pg_proc p "
6006  "WHERE NOT proisagg"
6007  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6008  "WHERE classid = 'pg_proc'::regclass AND "
6009  "objid = p.oid AND deptype = 'i')"
6010  "\n AND ("
6011  "\n pronamespace != "
6012  "(SELECT oid FROM pg_namespace "
6013  "WHERE nspname = 'pg_catalog')"
6014  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6015  "\n WHERE pg_cast.oid > '%u'::oid"
6016  "\n AND p.oid = pg_cast.castfunc)",
6018 
6019  if (fout->remoteVersion >= 90500)
6020  appendPQExpBuffer(query,
6021  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6022  "\n WHERE pg_transform.oid > '%u'::oid"
6023  "\n AND (p.oid = pg_transform.trffromsql"
6024  "\n OR p.oid = pg_transform.trftosql))",
6026 
6027  if (dopt->binary_upgrade)
6028  appendPQExpBufferStr(query,
6029  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6030  "classid = 'pg_proc'::regclass AND "
6031  "objid = p.oid AND "
6032  "refclassid = 'pg_extension'::regclass AND "
6033  "deptype = 'e')");
6034  appendPQExpBufferChar(query, ')');
6035  }
6036 
6037  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6038 
6039  ntups = PQntuples(res);
6040 
6041  *numFuncs = ntups;
6042 
6043  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
6044 
6045  i_tableoid = PQfnumber(res, "tableoid");
6046  i_oid = PQfnumber(res, "oid");
6047  i_proname = PQfnumber(res, "proname");
6048  i_pronamespace = PQfnumber(res, "pronamespace");
6049  i_proowner = PQfnumber(res, "proowner");
6050  i_prolang = PQfnumber(res, "prolang");
6051  i_pronargs = PQfnumber(res, "pronargs");
6052  i_proargtypes = PQfnumber(res, "proargtypes");
6053  i_prorettype = PQfnumber(res, "prorettype");
6054  i_proacl = PQfnumber(res, "proacl");
6055  i_acldefault = PQfnumber(res, "acldefault");
6056 
6057  for (i = 0; i < ntups; i++)
6058  {
6059  finfo[i].dobj.objType = DO_FUNC;
6060  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6061  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6062  AssignDumpId(&finfo[i].dobj);
6063  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
6064  finfo[i].dobj.namespace =
6065  findNamespace(atooid(PQgetvalue(res, i, i_pronamespace)));
6066  finfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_proacl));
6067  finfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6068  finfo[i].dacl.privtype = 0;
6069  finfo[i].dacl.initprivs = NULL;
6070  finfo[i].rolname = getRoleName(PQgetvalue(res, i, i_proowner));
6071  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
6072  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
6073  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
6074  if (finfo[i].nargs == 0)
6075  finfo[i].argtypes = NULL;
6076  else
6077  {
6078  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
6079  parseOidArray(PQgetvalue(res, i, i_proargtypes),
6080  finfo[i].argtypes, finfo[i].nargs);
6081  }
6082 
6083  /* Decide whether we want to dump it */
6084  selectDumpableObject(&(finfo[i].dobj), fout);
6085 
6086  /* Mark whether function has an ACL */
6087  if (!PQgetisnull(res, i, i_proacl))
6088  finfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6089  }
6090 
6091  PQclear(res);
6092 
6093  destroyPQExpBuffer(query);
6094 
6095  return finfo;
6096 }
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
static Oid g_last_builtin_oid
Definition: pg_dump.c:102
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 6635 of file pg_dump.c.

6636 {
6637  PQExpBuffer query = createPQExpBuffer();
6638  PQExpBuffer tbloids = createPQExpBuffer();
6639  PGresult *res;
6640  int ntups;
6641  int curtblindx;
6642  IndxInfo *indxinfo;
6643  int i_tableoid,
6644  i_oid,
6645  i_indrelid,
6646  i_indexname,
6647  i_parentidx,
6648  i_indexdef,
6649  i_indnkeyatts,
6650  i_indnatts,
6651  i_indkey,
6652  i_indisclustered,
6653  i_indisreplident,
6654  i_indnullsnotdistinct,
6655  i_contype,
6656  i_conname,
6657  i_condeferrable,
6658  i_condeferred,
6659  i_contableoid,
6660  i_conoid,
6661  i_condef,
6662  i_tablespace,
6663  i_indreloptions,
6664  i_indstatcols,
6665  i_indstatvals;
6666 
6667  /*
6668  * We want to perform just one query against pg_index. However, we
6669  * mustn't try to select every row of the catalog and then sort it out on
6670  * the client side, because some of the server-side functions we need
6671  * would be unsafe to apply to tables we don't have lock on. Hence, we
6672  * build an array of the OIDs of tables we care about (and now have lock
6673  * on!), and use a WHERE clause to constrain which rows are selected.
6674  */
6675  appendPQExpBufferChar(tbloids, '{');
6676  for (int i = 0; i < numTables; i++)
6677  {
6678  TableInfo *tbinfo = &tblinfo[i];
6679 
6680  if (!tbinfo->hasindex)
6681  continue;
6682 
6683  /*
6684  * We can ignore indexes of uninteresting tables.
6685  */
6686  if (!tbinfo->interesting)
6687  continue;
6688 
6689  /* OK, we need info for this table */
6690  if (tbloids->len > 1) /* do we have more than the '{'? */
6691  appendPQExpBufferChar(tbloids, ',');
6692  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
6693  }
6694  appendPQExpBufferChar(tbloids, '}');
6695 
6696  appendPQExpBuffer(query,
6697  "SELECT t.tableoid, t.oid, i.indrelid, "
6698  "t.relname AS indexname, "
6699  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6700  "i.indkey, i.indisclustered, "
6701  "c.contype, c.conname, "
6702  "c.condeferrable, c.condeferred, "
6703  "c.tableoid AS contableoid, "
6704  "c.oid AS conoid, "
6705  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6706  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6707  "t.reloptions AS indreloptions, ");
6708 
6709 
6710  if (fout->remoteVersion >= 90400)
6711  appendPQExpBuffer(query,
6712  "i.indisreplident, ");
6713  else
6714  appendPQExpBuffer(query,
6715  "false AS indisreplident, ");
6716 
6717  if (fout->remoteVersion >= 110000)
6718  appendPQExpBuffer(query,
6719  "inh.inhparent AS parentidx, "
6720  "i.indnkeyatts AS indnkeyatts, "
6721  "i.indnatts AS indnatts, "
6722  "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
6723  " FROM pg_catalog.pg_attribute "
6724  " WHERE attrelid = i.indexrelid AND "
6725  " attstattarget >= 0) AS indstatcols, "
6726  "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
6727  " FROM pg_catalog.pg_attribute "
6728  " WHERE attrelid = i.indexrelid AND "
6729  " attstattarget >= 0) AS indstatvals, ");
6730  else
6731  appendPQExpBuffer(query,
6732  "0 AS parentidx, "
6733  "i.indnatts AS indnkeyatts, "
6734  "i.indnatts AS indnatts, "
6735  "'' AS indstatcols, "
6736  "'' AS indstatvals, ");
6737 
6738  if (fout->remoteVersion >= 150000)
6739  appendPQExpBuffer(query,
6740  "i.indnullsnotdistinct ");
6741  else
6742  appendPQExpBuffer(query,
6743  "false AS indnullsnotdistinct ");
6744 
6745  /*
6746  * The point of the messy-looking outer join is to find a constraint that
6747  * is related by an internal dependency link to the index. If we find one,
6748  * create a CONSTRAINT entry linked to the INDEX entry. We assume an
6749  * index won't have more than one internal dependency.
6750  *
6751  * Note: the check on conrelid is redundant, but useful because that
6752  * column is indexed while conindid is not.
6753  */
6754  if (fout->remoteVersion >= 110000)
6755  {
6756  appendPQExpBuffer(query,
6757  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
6758  "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
6759  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6760  "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
6761  "LEFT JOIN pg_catalog.pg_constraint c "
6762  "ON (i.indrelid = c.conrelid AND "
6763  "i.indexrelid = c.conindid AND "
6764  "c.contype IN ('p','u','x')) "
6765  "LEFT JOIN pg_catalog.pg_inherits inh "
6766  "ON (inh.inhrelid = indexrelid) "
6767  "WHERE (i.indisvalid OR t2.relkind = 'p') "
6768  "AND i.indisready "
6769  "ORDER BY i.indrelid, indexname",
6770  tbloids->data);
6771  }
6772  else
6773  {
6774  /*
6775  * the test on indisready is necessary in 9.2, and harmless in
6776  * earlier/later versions
6777  */
6778  appendPQExpBuffer(query,
6779  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
6780  "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
6781  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6782  "LEFT JOIN pg_catalog.pg_constraint c "
6783  "ON (i.indrelid = c.conrelid AND "
6784  "i.indexrelid = c.conindid AND "
6785  "c.contype IN ('p','u','x')) "
6786  "WHERE i.indisvalid AND i.indisready "
6787  "ORDER BY i.indrelid, indexname",
6788  tbloids->data);
6789  }
6790 
6791  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6792 
6793  ntups = PQntuples(res);
6794 
6795  i_tableoid = PQfnumber(res, "tableoid");
6796  i_oid = PQfnumber(res, "oid");
6797  i_indrelid = PQfnumber(res, "indrelid");
6798  i_indexname = PQfnumber(res, "indexname");
6799  i_parentidx = PQfnumber(res, "parentidx");
6800  i_indexdef = PQfnumber(res, "indexdef");
6801  i_indnkeyatts = PQfnumber(res, "indnkeyatts");
6802  i_indnatts = PQfnumber(res, "indnatts");
6803  i_indkey = PQfnumber(res, "indkey");
6804  i_indisclustered = PQfnumber(res, "indisclustered");
6805  i_indisreplident = PQfnumber(res, "indisreplident");
6806  i_indnullsnotdistinct = PQfnumber(res, "indnullsnotdistinct");
6807  i_contype = PQfnumber(res, "contype");
6808  i_conname = PQfnumber(res, "conname");
6809  i_condeferrable = PQfnumber(res, "condeferrable");
6810  i_condeferred = PQfnumber(res, "condeferred");
6811  i_contableoid = PQfnumber(res, "contableoid");
6812  i_conoid = PQfnumber(res, "conoid");
6813  i_condef = PQfnumber(res, "condef");
6814  i_tablespace = PQfnumber(res, "tablespace");
6815  i_indreloptions = PQfnumber(res, "indreloptions");
6816  i_indstatcols = PQfnumber(res, "indstatcols");
6817  i_indstatvals = PQfnumber(res, "indstatvals");
6818 
6819  indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
6820 
6821  /*
6822  * Outer loop iterates once per table, not once per row. Incrementing of
6823  * j is handled by the inner loop.
6824  */
6825  curtblindx = -1;
6826  for (int j = 0; j < ntups;)
6827  {
6828  Oid indrelid = atooid(PQgetvalue(res, j, i_indrelid));
6829  TableInfo *tbinfo = NULL;
6830  int numinds;
6831 
6832  /* Count rows for this table */
6833  for (numinds = 1; numinds < ntups - j; numinds++)
6834  if (atooid(PQgetvalue(res, j + numinds, i_indrelid)) != indrelid)
6835  break;
6836 
6837  /*
6838  * Locate the associated TableInfo; we rely on tblinfo[] being in OID
6839  * order.
6840  */
6841  while (++curtblindx < numTables)
6842  {
6843  tbinfo = &tblinfo[curtblindx];
6844  if (tbinfo->dobj.catId.oid == indrelid)
6845  break;
6846  }
6847  if (curtblindx >= numTables)
6848  pg_fatal("unrecognized table OID %u", indrelid);
6849  /* cross-check that we only got requested tables */
6850  if (!tbinfo->hasindex ||
6851  !tbinfo->interesting)
6852  pg_fatal("unexpected index data for table \"%s\"",
6853  tbinfo->dobj.name);
6854 
6855  /* Save data for this table */
6856  tbinfo->indexes = indxinfo + j;
6857  tbinfo->numIndexes = numinds;
6858 
6859  for (int c = 0; c < numinds; c++, j++)
6860  {
6861  char contype;
6862 
6863  indxinfo[j].dobj.objType = DO_INDEX;
6864  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
6865  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
6866  AssignDumpId(&indxinfo[j].dobj);
6867  indxinfo[j].dobj.dump = tbinfo->dobj.dump;
6868  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
6869  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
6870  indxinfo[j].indextable = tbinfo;
6871  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
6872  indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
6873  indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
6874  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
6875  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
6876  indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
6877  indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
6878  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
6879  parseOidArray(PQgetvalue(res, j, i_indkey),
6880  indxinfo[j].indkeys, indxinfo[j].indnattrs);
6881  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
6882  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
6883  indxinfo[j].indnullsnotdistinct = (PQgetvalue(res, j, i_indnullsnotdistinct)[0] == 't');
6884  indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
6885  indxinfo[j].partattaches = (SimplePtrList)
6886  {
6887  NULL, NULL
6888  };
6889  contype = *(PQgetvalue(res, j, i_contype));
6890 
6891  if (contype == 'p' || contype == 'u' || contype == 'x')
6892  {
6893  /*
6894  * If we found a constraint matching the index, create an
6895  * entry for it.
6896  */
6897  ConstraintInfo *constrinfo;
6898 
6899  constrinfo = (ConstraintInfo *) pg_malloc(sizeof(ConstraintInfo));
6900  constrinfo->dobj.objType = DO_CONSTRAINT;
6901  constrinfo->dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
6902  constrinfo->dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
6903  AssignDumpId(&constrinfo->dobj);
6904  constrinfo->dobj.dump = tbinfo->dobj.dump;
6905  constrinfo->dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
6906  constrinfo->dobj.namespace = tbinfo->dobj.namespace;
6907  constrinfo->contable = tbinfo;
6908  constrinfo->condomain = NULL;
6909  constrinfo->contype = contype;
6910  if (contype == 'x')
6911  constrinfo->condef = pg_strdup(PQgetvalue(res, j, i_condef));
6912  else
6913  constrinfo->condef = NULL;
6914  constrinfo->confrelid = InvalidOid;
6915  constrinfo->conindex = indxinfo[j].dobj.dumpId;
6916  constrinfo->condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
6917  constrinfo->condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
6918  constrinfo->conislocal = true;
6919  constrinfo->separate = true;
6920 
6921  indxinfo[j].indexconstraint = constrinfo->dobj.dumpId;
6922  }
6923  else
6924  {
6925  /* Plain secondary index */
6926  indxinfo[j].indexconstraint = 0;
6927  }
6928  }
6929  }
6930 
6931  PQclear(res);
6932 
6933  destroyPQExpBuffer(query);
6934  destroyPQExpBuffer(tbloids);
6935 }
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(), 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 6589 of file pg_dump.c.

6590 {
6591  PGresult *res;
6592  int ntups;
6593  int i;
6594  PQExpBuffer query = createPQExpBuffer();
6595  InhInfo *inhinfo;
6596 
6597  int i_inhrelid;
6598  int i_inhparent;
6599 
6600  /* find all the inheritance information */
6601  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
6602 
6603  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6604 
6605  ntups = PQntuples(res);
6606 
6607  *numInherits = ntups;
6608 
6609  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
6610 
6611  i_inhrelid = PQfnumber(res, "inhrelid");
6612  i_inhparent = PQfnumber(res, "inhparent");
6613 
6614  for (i = 0; i < ntups; i++)
6615  {
6616  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
6617  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
6618  }
6619 
6620  PQclear(res);
6621 
6622  destroyPQExpBuffer(query);
6623 
6624  return inhinfo;
6625 }
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 655 of file common.c.

656 {
657  return lastDumpId;
658 }

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

◆ getNamespaces()

NamespaceInfo* getNamespaces ( Archive fout,
int *  numNamespaces 
)

Definition at line 4966 of file pg_dump.c.

4967 {
4968  PGresult *res;
4969  int ntups;
4970  int i;
4971  PQExpBuffer query;
4972  NamespaceInfo *nsinfo;
4973  int i_tableoid;
4974  int i_oid;
4975  int i_nspname;
4976  int i_nspowner;
4977  int i_nspacl;
4978  int i_acldefault;
4979 
4980  query = createPQExpBuffer();
4981 
4982  /*
4983  * we fetch all namespaces including system ones, so that every object we
4984  * read in can be linked to a containing namespace.
4985  */
4986  appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, "
4987  "n.nspowner, "
4988  "n.nspacl, "
4989  "acldefault('n', n.nspowner) AS acldefault "
4990  "FROM pg_namespace n");
4991 
4992  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4993 
4994  ntups = PQntuples(res);
4995 
4996  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
4997 
4998  i_tableoid = PQfnumber(res, "tableoid");
4999  i_oid = PQfnumber(res, "oid");
5000  i_nspname = PQfnumber(res, "nspname");
5001  i_nspowner = PQfnumber(res, "nspowner");
5002  i_nspacl = PQfnumber(res, "nspacl");
5003  i_acldefault = PQfnumber(res, "acldefault");
5004 
5005  for (i = 0; i < ntups; i++)
5006  {
5007  const char *nspowner;
5008 
5009  nsinfo[i].dobj.objType = DO_NAMESPACE;
5010  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5011  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5012  AssignDumpId(&nsinfo[i].dobj);
5013  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
5014  nsinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_nspacl));
5015  nsinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
5016  nsinfo[i].dacl.privtype = 0;
5017  nsinfo[i].dacl.initprivs = NULL;
5018  nspowner = PQgetvalue(res, i, i_nspowner);
5019  nsinfo[i].nspowner = atooid(nspowner);
5020  nsinfo[i].rolname = getRoleName(nspowner);
5021 
5022  /* Decide whether to dump this namespace */
5023  selectDumpableNamespace(&nsinfo[i], fout);
5024 
5025  /* Mark whether namespace has an ACL */
5026  if (!PQgetisnull(res, i, i_nspacl))
5027  nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
5028 
5029  /*
5030  * We ignore any pg_init_privs.initprivs entry for the public schema
5031  * and assume a predetermined default, for several reasons. First,
5032  * dropping and recreating the schema removes its pg_init_privs entry,
5033  * but an empty destination database starts with this ACL nonetheless.
5034  * Second, we support dump/reload of public schema ownership changes.
5035  * ALTER SCHEMA OWNER filters nspacl through aclnewowner(), but
5036  * initprivs continues to reflect the initial owner. Hence,
5037  * synthesize the value that nspacl will have after the restore's
5038  * ALTER SCHEMA OWNER. Third, this makes the destination database
5039  * match the source's ACL, even if the latter was an initdb-default
5040  * ACL, which changed in v15. An upgrade pulls in changes to most
5041  * system object ACLs that the DBA had not customized. We've made the
5042  * public schema depart from that, because changing its ACL so easily
5043  * breaks applications.
5044  */
5045  if (strcmp(nsinfo[i].dobj.name, "public") == 0)
5046  {
5047  PQExpBuffer aclarray = createPQExpBuffer();
5048  PQExpBuffer aclitem = createPQExpBuffer();
5049 
5050  /* Standard ACL as of v15 is {owner=UC/owner,=U/owner} */
5051  appendPQExpBufferChar(aclarray, '{');
5052  quoteAclUserName(aclitem, nsinfo[i].rolname);
5053  appendPQExpBufferStr(aclitem, "=UC/");
5054  quoteAclUserName(aclitem, nsinfo[i].rolname);
5055  appendPGArray(aclarray, aclitem->data);
5056  resetPQExpBuffer(aclitem);
5057  appendPQExpBufferStr(aclitem, "=U/");
5058  quoteAclUserName(aclitem, nsinfo[i].rolname);
5059  appendPGArray(aclarray, aclitem->data);
5060  appendPQExpBufferChar(aclarray, '}');
5061 
5062  nsinfo[i].dacl.privtype = 'i';
5063  nsinfo[i].dacl.initprivs = pstrdup(aclarray->data);
5064  nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
5065 
5066  destroyPQExpBuffer(aclarray);
5067  destroyPQExpBuffer(aclitem);
5068  }
5069  }
5070 
5071  PQclear(res);
5072  destroyPQExpBuffer(query);
5073 
5074  *numNamespaces = ntups;
5075 
5076  return nsinfo;
5077 }
void quoteAclUserName(PQExpBuffer output, const char *input)
Definition: dumputils.c:544
char * pstrdup(const char *in)
Definition: mcxt.c:1305
NameData rolname
Definition: pg_authid.h:34
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1613
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148
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(), appendPQExpBuffer(), 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 5628 of file pg_dump.c.

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

References appendPQExpBuffer(), 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 *  numOperators 
)

Definition at line 5347 of file pg_dump.c.

5348 {
5349  PGresult *res;
5350  int ntups;
5351  int i;
5352  PQExpBuffer query = createPQExpBuffer();
5353  OprInfo *oprinfo;
5354  int i_tableoid;
5355  int i_oid;
5356  int i_oprname;
5357  int i_oprnamespace;
5358  int i_oprowner;
5359  int i_oprkind;
5360  int i_oprcode;
5361 
5362  /*
5363  * find all operators, including builtin operators; we filter out
5364  * system-defined operators at dump-out time.
5365  */
5366 
5367  appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
5368  "oprnamespace, "
5369  "oprowner, "
5370  "oprkind, "
5371  "oprcode::oid AS oprcode "
5372  "FROM pg_operator");
5373 
5374  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5375 
5376  ntups = PQntuples(res);
5377  *numOprs = ntups;
5378 
5379  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
5380 
5381  i_tableoid = PQfnumber(res, "tableoid");
5382  i_oid = PQfnumber(res, "oid");
5383  i_oprname = PQfnumber(res, "oprname");
5384  i_oprnamespace = PQfnumber(res, "oprnamespace");
5385  i_oprowner = PQfnumber(res, "oprowner");
5386  i_oprkind = PQfnumber(res, "oprkind");
5387  i_oprcode = PQfnumber(res, "oprcode");
5388 
5389  for (i = 0; i < ntups; i++)
5390  {
5391  oprinfo[i].dobj.objType = DO_OPERATOR;
5392  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5393  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5394  AssignDumpId(&oprinfo[i].dobj);
5395  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
5396  oprinfo[i].dobj.namespace =
5397  findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)));
5398  oprinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_oprowner));
5399  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
5400  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
5401 
5402  /* Decide whether we want to dump it */
5403  selectDumpableObject(&(oprinfo[i].dobj), fout);
5404  }
5405 
5406  PQclear(res);
5407 
5408  destroyPQExpBuffer(query);
5409 
5410  return oprinfo;
5411 }
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 appendPQExpBuffer(), 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 5694 of file pg_dump.c.

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

References appendPQExpBuffer(), 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 6526 of file pg_dump.c.

6527 {
6528  int i;
6529 
6530  /*
6531  * Force sequences that are "owned" by table columns to be dumped whenever
6532  * their owning table is being dumped.
6533  */
6534  for (i = 0; i < numTables; i++)
6535  {
6536  TableInfo *seqinfo = &tblinfo[i];
6537  TableInfo *owning_tab;
6538 
6539  if (!OidIsValid(seqinfo->owning_tab))
6540  continue; /* not an owned sequence */
6541 
6542  owning_tab = findTableByOid(seqinfo->owning_tab);
6543  if (owning_tab == NULL)
6544  pg_fatal("failed sanity check, parent table with OID %u of sequence with OID %u not found",
6545  seqinfo->owning_tab, seqinfo->dobj.catId.oid);
6546 
6547  /*
6548  * Only dump identity sequences if we're going to dump the table that
6549  * it belongs to.
6550  */
6551  if (owning_tab->dobj.dump == DUMP_COMPONENT_NONE &&
6552  seqinfo->is_identity_sequence)
6553  {
6554  seqinfo->dobj.dump = DUMP_COMPONENT_NONE;
6555  continue;
6556  }
6557 
6558  /*
6559  * Otherwise we need to dump the components that are being dumped for
6560  * the table and any components which the sequence is explicitly
6561  * marked with.
6562  *
6563  * We can't simply use the set of components which are being dumped
6564  * for the table as the table might be in an extension (and only the
6565  * non-extension components, eg: ACLs if changed, security labels, and
6566  * policies, are being dumped) while the sequence is not (and
6567  * therefore the definition and other components should also be
6568  * dumped).
6569  *
6570  * If the sequence is part of the extension then it should be properly
6571  * marked by checkExtensionMembership() and this will be a no-op as
6572  * the table will be equivalently marked.
6573  */
6574  seqinfo->dobj.dump = seqinfo->dobj.dump | owning_tab->dobj.dump;
6575 
6576  if (seqinfo->dobj.dump != DUMP_COMPONENT_NONE)
6577  seqinfo->interesting = true;
6578  }
6579 }
#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 3570 of file pg_dump.c.

3571 {
3572  PQExpBuffer query;
3573  PQExpBuffer tbloids;
3574  PGresult *res;
3575  PolicyInfo *polinfo;
3576  int i_oid;
3577  int i_tableoid;
3578  int i_polrelid;
3579  int i_polname;
3580  int i_polcmd;
3581  int i_polpermissive;
3582  int i_polroles;
3583  int i_polqual;
3584  int i_polwithcheck;
3585  int i,
3586  j,
3587  ntups;
3588 
3589  /* No policies before 9.5 */
3590  if (fout->remoteVersion < 90500)
3591  return;
3592 
3593  query = createPQExpBuffer();
3594  tbloids = createPQExpBuffer();
3595 
3596  /*
3597  * Identify tables of interest, and check which ones have RLS enabled.
3598  */
3599  appendPQExpBufferChar(tbloids, '{');
3600  for (i = 0; i < numTables; i++)
3601  {
3602  TableInfo *tbinfo = &tblinfo[i];
3603 
3604  /* Ignore row security on tables not to be dumped */
3605  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_POLICY))
3606  continue;
3607 
3608  /* It can't have RLS or policies if it's not a table */
3609  if (tbinfo->relkind != RELKIND_RELATION &&
3610  tbinfo->relkind != RELKIND_PARTITIONED_TABLE)
3611  continue;
3612 
3613  /* Add it to the list of table OIDs to be probed below */
3614  if (tbloids->len > 1) /* do we have more than the '{'? */
3615  appendPQExpBufferChar(tbloids, ',');
3616  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
3617 
3618  /* Is RLS enabled? (That's separate from whether it has policies) */
3619  if (tbinfo->rowsec)
3620  {
3622 
3623  /*
3624  * We represent RLS being enabled on a table by creating a
3625  * PolicyInfo object with null polname.
3626  *
3627  * Note: use tableoid 0 so that this object won't be mistaken for
3628  * something that pg_depend entries apply to.
3629  */
3630  polinfo = pg_malloc(sizeof(PolicyInfo));
3631  polinfo->dobj.objType = DO_POLICY;
3632  polinfo->dobj.catId.tableoid = 0;
3633  polinfo->dobj.catId.oid = tbinfo->dobj.catId.oid;
3634  AssignDumpId(&polinfo->dobj);
3635  polinfo->dobj.namespace = tbinfo->dobj.namespace;
3636  polinfo->dobj.name = pg_strdup(tbinfo->dobj.name);
3637  polinfo->poltable = tbinfo;
3638  polinfo->polname = NULL;
3639  polinfo->polcmd = '\0';
3640  polinfo->polpermissive = 0;
3641  polinfo->polroles = NULL;
3642  polinfo->polqual = NULL;
3643  polinfo->polwithcheck = NULL;
3644  }
3645  }
3646  appendPQExpBufferChar(tbloids, '}');
3647 
3648  /*
3649  * Now, read all RLS policies belonging to the tables of interest, and
3650  * create PolicyInfo objects for them. (Note that we must filter the
3651  * results server-side not locally, because we dare not apply pg_get_expr
3652  * to tables we don't have lock on.)
3653  */
3654  pg_log_info("reading row-level security policies");
3655 
3656  printfPQExpBuffer(query,
3657  "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
3658  if (fout->remoteVersion >= 100000)
3659  appendPQExpBuffer(query, "pol.polpermissive, ");
3660  else
3661  appendPQExpBuffer(query, "'t' as polpermissive, ");
3662  appendPQExpBuffer(query,
3663  "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
3664  " 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, "
3665  "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
3666  "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
3667  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
3668  "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
3669  tbloids->data);
3670 
3671  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
3672 
3673  ntups = PQntuples(res);
3674  if (ntups > 0)
3675  {
3676  i_oid = PQfnumber(res, "oid");
3677  i_tableoid = PQfnumber(res, "tableoid");
3678  i_polrelid = PQfnumber(res, "polrelid");
3679  i_polname = PQfnumber(res, "polname");
3680  i_polcmd = PQfnumber(res, "polcmd");
3681  i_polpermissive = PQfnumber(res, "polpermissive");
3682  i_polroles = PQfnumber(res, "polroles");
3683  i_polqual = PQfnumber(res, "polqual");
3684  i_polwithcheck = PQfnumber(res, "polwithcheck");
3685 
3686  polinfo = pg_malloc(ntups * sizeof(PolicyInfo));
3687 
3688  for (j = 0; j < ntups; j++)
3689  {
3690  Oid polrelid = atooid(PQgetvalue(res, j, i_polrelid));
3691  TableInfo *tbinfo = findTableByOid(polrelid);
3692 
3694 
3695  polinfo[j].dobj.objType = DO_POLICY;
3696  polinfo[j].dobj.catId.tableoid =
3697  atooid(PQgetvalue(res, j, i_tableoid));
3698  polinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
3699  AssignDumpId(&polinfo[j].dobj);
3700  polinfo[j].dobj.namespace = tbinfo->dobj.namespace;
3701  polinfo[j].poltable = tbinfo;
3702  polinfo[j].polname = pg_strdup(PQgetvalue(res, j, i_polname));
3703  polinfo[j].dobj.name = pg_strdup(polinfo[j].polname);
3704 
3705  polinfo[j].polcmd = *(PQgetvalue(res, j, i_polcmd));
3706  polinfo[j].polpermissive = *(PQgetvalue(res, j, i_polpermissive)) == 't';
3707 
3708  if (PQgetisnull(res, j, i_polroles))
3709  polinfo[j].polroles = NULL;
3710  else
3711  polinfo[j].polroles = pg_strdup(PQgetvalue(res, j, i_polroles));
3712 
3713  if (PQgetisnull(res, j, i_polqual))
3714  polinfo[j].polqual = NULL;
3715  else
3716  polinfo[j].polqual = pg_strdup(PQgetvalue(res, j, i_polqual));
3717 
3718  if (PQgetisnull(res, j, i_polwithcheck))
3719  polinfo[j].polwithcheck = NULL;
3720  else
3721  polinfo[j].polwithcheck
3722  = pg_strdup(PQgetvalue(res, j, i_polwithcheck));
3723  }
3724  }
3725 
3726  PQclear(res);
3727 
3728  destroyPQExpBuffer(query);
3729  destroyPQExpBuffer(tbloids);
3730 }
#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:237
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(), 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 7755 of file pg_dump.c.

7756 {
7757  PGresult *res;
7758  int ntups;
7759  int i;
7760  PQExpBuffer query = createPQExpBuffer();
7761  ProcLangInfo *planginfo;
7762  int i_tableoid;
7763  int i_oid;
7764  int i_lanname;
7765  int i_lanpltrusted;
7766  int i_lanplcallfoid;
7767  int i_laninline;
7768  int i_lanvalidator;
7769  int i_lanacl;
7770  int i_acldefault;
7771  int i_lanowner;
7772 
7773  appendPQExpBuffer(query, "SELECT tableoid, oid, "
7774  "lanname, lanpltrusted, lanplcallfoid, "
7775  "laninline, lanvalidator, "
7776  "lanacl, "
7777  "acldefault('l', lanowner) AS acldefault, "
7778  "lanowner "
7779  "FROM pg_language "
7780  "WHERE lanispl "
7781  "ORDER BY oid");
7782 
7783  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7784 
7785  ntups = PQntuples(res);
7786 
7787  *numProcLangs = ntups;
7788 
7789  planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo));
7790 
7791  i_tableoid = PQfnumber(res, "tableoid");
7792  i_oid = PQfnumber(res, "oid");
7793  i_lanname = PQfnumber(res, "lanname");
7794  i_lanpltrusted = PQfnumber(res, "lanpltrusted");
7795  i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
7796  i_laninline = PQfnumber(res, "laninline");
7797  i_lanvalidator = PQfnumber(res, "lanvalidator");
7798  i_lanacl = PQfnumber(res, "lanacl");
7799  i_acldefault = PQfnumber(res, "acldefault");
7800  i_lanowner = PQfnumber(res, "lanowner");
7801 
7802  for (i = 0; i < ntups; i++)
7803  {
7804  planginfo[i].dobj.objType = DO_PROCLANG;
7805  planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7806  planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7807  AssignDumpId(&planginfo[i].dobj);
7808 
7809  planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
7810  planginfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_lanacl));
7811  planginfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
7812  planginfo[i].dacl.privtype = 0;
7813  planginfo[i].dacl.initprivs = NULL;
7814  planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
7815  planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
7816  planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
7817  planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
7818  planginfo[i].lanowner = getRoleName(PQgetvalue(res, i, i_lanowner));
7819 
7820  /* Decide whether we want to dump it */
7821  selectDumpableProcLang(&(planginfo[i]), fout);
7822 
7823  /* Mark whether language has an ACL */
7824  if (!PQgetisnull(res, i, i_lanacl))
7825  planginfo[i].dobj.components |= DUMP_COMPONENT_ACL;
7826  }
7827 
7828  PQclear(res);
7829 
7830  destroyPQExpBuffer(query);
7831 
7832  return planginfo;
7833 }
static void selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
Definition: pg_dump.c:1830
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, appendPQExpBuffer(), 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 4055 of file pg_dump.c.

4056 {
4057  PQExpBuffer query;
4058  PGresult *res;
4059  PublicationSchemaInfo *pubsinfo;
4060  DumpOptions *dopt = fout->dopt;
4061  int i_tableoid;
4062  int i_oid;
4063  int i_pnpubid;
4064  int i_pnnspid;
4065  int i,
4066  j,
4067  ntups;
4068 
4069  if (dopt->no_publications || fout->remoteVersion < 150000)
4070  return;
4071 
4072  query = createPQExpBuffer();
4073 
4074  /* Collect all publication membership info. */
4075  appendPQExpBufferStr(query,
4076  "SELECT tableoid, oid, pnpubid, pnnspid "
4077  "FROM pg_catalog.pg_publication_namespace");
4078  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4079 
4080  ntups = PQntuples(res);
4081 
4082  i_tableoid = PQfnumber(res, "tableoid");
4083  i_oid = PQfnumber(res, "oid");
4084  i_pnpubid = PQfnumber(res, "pnpubid");
4085  i_pnnspid = PQfnumber(res, "pnnspid");
4086 
4087  /* this allocation may be more than we need */
4088  pubsinfo = pg_malloc(ntups * sizeof(PublicationSchemaInfo));
4089  j = 0;
4090 
4091  for (i = 0; i < ntups; i++)
4092  {
4093  Oid pnpubid = atooid(PQgetvalue(res, i, i_pnpubid));
4094  Oid pnnspid = atooid(PQgetvalue(res, i, i_pnnspid));
4095  PublicationInfo *pubinfo;
4096  NamespaceInfo *nspinfo;
4097 
4098  /*
4099  * Ignore any entries for which we aren't interested in either the
4100  * publication or the rel.
4101  */
4102  pubinfo = findPublicationByOid(pnpubid);
4103  if (pubinfo == NULL)
4104  continue;
4105  nspinfo = findNamespaceByOid(pnnspid);
4106  if (nspinfo == NULL)
4107  continue;
4108 
4109  /*
4110  * We always dump publication namespaces unless the corresponding
4111  * namespace is excluded from the dump.
4112  */
4113  if (nspinfo->dobj.dump == DUMP_COMPONENT_NONE)
4114  continue;
4115 
4116  /* OK, make a DumpableObject for this relationship */
4118  pubsinfo[j].dobj.catId.tableoid =
4119  atooid(PQgetvalue(res, i, i_tableoid));
4120  pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4121  AssignDumpId(&pubsinfo[j].dobj);
4122  pubsinfo[j].dobj.namespace = nspinfo->dobj.namespace;
4123  pubsinfo[j].dobj.name = nspinfo->dobj.name;
4124  pubsinfo[j].publication = pubinfo;
4125  pubsinfo[j].pubschema = nspinfo;
4126 
4127  /* Decide whether we want to dump it */
4128  selectDumpablePublicationObject(&(pubsinfo[j].dobj), fout);
4129 
4130  j++;
4131  }
4132 
4133  PQclear(res);
4134  destroyPQExpBuffer(query);
4135 }
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition: common.c:876
PublicationInfo * findPublicationByOid(Oid oid)
Definition: common.c:912
static void selectDumpablePublicationObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:1924
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:177

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

3856 {
3857  DumpOptions *dopt = fout->dopt;
3858  PQExpBuffer query;
3859  PGresult *res;
3860  PublicationInfo *pubinfo;
3861  int i_tableoid;
3862  int i_oid;
3863  int i_pubname;
3864  int i_pubowner;
3865  int i_puballtables;
3866  int i_pubinsert;
3867  int i_pubupdate;
3868  int i_pubdelete;
3869  int i_pubtruncate;
3870  int i_pubviaroot;
3871  int i,
3872  ntups;
3873 
3874  if (dopt->no_publications || fout->remoteVersion < 100000)
3875  {
3876  *numPublications = 0;
3877  return NULL;
3878  }
3879 
3880  query = createPQExpBuffer();
3881 
3882  resetPQExpBuffer(query);
3883 
3884  /* Get the publications. */
3885  if (fout->remoteVersion >= 130000)
3886  appendPQExpBuffer(query,
3887  "SELECT p.tableoid, p.oid, p.pubname, "
3888  "p.pubowner, "
3889  "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, p.pubviaroot "
3890  "FROM pg_publication p");
3891  else if (fout->remoteVersion >= 110000)
3892  appendPQExpBuffer(query,
3893  "SELECT p.tableoid, p.oid, p.pubname, "
3894  "p.pubowner, "
3895  "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, false AS pubviaroot "
3896  "FROM pg_publication p");
3897  else
3898  appendPQExpBuffer(query,
3899  "SELECT p.tableoid, p.oid, p.pubname, "
3900  "p.pubowner, "
3901  "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, false AS pubtruncate, false AS pubviaroot "
3902  "FROM pg_publication p");
3903 
3904  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
3905 
3906  ntups = PQntuples(res);
3907 
3908  i_tableoid = PQfnumber(res, "tableoid");
3909  i_oid = PQfnumber(res, "oid");
3910  i_pubname = PQfnumber(res, "pubname");
3911  i_pubowner = PQfnumber(res, "pubowner");
3912  i_puballtables = PQfnumber(res, "puballtables");
3913  i_pubinsert = PQfnumber(res, "pubinsert");
3914  i_pubupdate = PQfnumber(res, "pubupdate");
3915  i_pubdelete = PQfnumber(res, "pubdelete");
3916  i_pubtruncate = PQfnumber(res, "pubtruncate");
3917  i_pubviaroot = PQfnumber(res, "pubviaroot");
3918 
3919  pubinfo = pg_malloc(ntups * sizeof(PublicationInfo));
3920 
3921  for (i = 0; i < ntups; i++)
3922  {
3923  pubinfo[i].dobj.objType = DO_PUBLICATION;
3924  pubinfo[i].dobj.catId.tableoid =
3925  atooid(PQgetvalue(res, i, i_tableoid));
3926  pubinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
3927  AssignDumpId(&pubinfo[i].dobj);
3928  pubinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_pubname));
3929  pubinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_pubowner));
3930  pubinfo[i].puballtables =
3931  (strcmp(PQgetvalue(res, i, i_puballtables), "t") == 0);
3932  pubinfo[i].pubinsert =
3933  (strcmp(PQgetvalue(res, i, i_pubinsert), "t") == 0);
3934  pubinfo[i].pubupdate =
3935  (strcmp(PQgetvalue(res, i, i_pubupdate), "t") == 0);
3936  pubinfo[i].pubdelete =
3937  (strcmp(PQgetvalue(res, i, i_pubdelete), "t") == 0);
3938  pubinfo[i].pubtruncate =
3939  (strcmp(PQgetvalue(res, i, i_pubtruncate), "t") == 0);
3940  pubinfo[i].pubviaroot =
3941  (strcmp(PQgetvalue(res, i, i_pubviaroot), "t") == 0);
3942 
3943  /* Decide whether we want to dump it */
3944  selectDumpableObject(&(pubinfo[i].dobj), fout);
3945  }
3946  PQclear(res);
3947 
3948  destroyPQExpBuffer(query);
3949 
3950  *numPublications = ntups;
3951  return pubinfo;
3952 }
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 appendPQExpBuffer(), 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 4142 of file pg_dump.c.

4143 {
4144  PQExpBuffer query;
4145  PGresult *res;
4146  PublicationRelInfo *pubrinfo;
4147  DumpOptions *dopt = fout->dopt;
4148  int i_tableoid;
4149  int i_oid;
4150  int i_prpubid;
4151  int i_prrelid;
4152  int i_prrelqual;
4153  int i_prattrs;
4154  int i,
4155  j,
4156  ntups;
4157 
4158  if (dopt->no_publications || fout->remoteVersion < 100000)
4159  return;
4160 
4161  query = createPQExpBuffer();
4162 
4163  /* Collect all publication membership info. */
4164  if (fout->remoteVersion >= 150000)
4165  appendPQExpBufferStr(query,
4166  "SELECT tableoid, oid, prpubid, prrelid, "
4167  "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4168  "(CASE\n"
4169  " WHEN pr.prattrs IS NOT NULL THEN\n"
4170  " (SELECT array_agg(attname)\n"
4171  " FROM\n"
4172  " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4173  " pg_catalog.pg_attribute\n"
4174  " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4175  " ELSE NULL END) prattrs "
4176  "FROM pg_catalog.pg_publication_rel pr");
4177  else
4178  appendPQExpBufferStr(query,
4179  "SELECT tableoid, oid, prpubid, prrelid, "
4180  "NULL AS prrelqual, NULL AS prattrs "
4181  "FROM pg_catalog.pg_publication_rel");
4182  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4183 
4184  ntups = PQntuples(res);
4185 
4186  i_tableoid = PQfnumber(res, "tableoid");
4187  i_oid = PQfnumber(res, "oid");
4188  i_prpubid = PQfnumber(res, "prpubid");
4189  i_prrelid = PQfnumber(res, "prrelid");
4190  i_prrelqual = PQfnumber(res, "prrelqual");
4191  i_prattrs = PQfnumber(res, "prattrs");
4192 
4193  /* this allocation may be more than we need */
4194  pubrinfo = pg_malloc(ntups * sizeof(PublicationRelInfo));
4195  j = 0;
4196 
4197  for (i = 0; i < ntups; i++)
4198  {
4199  Oid prpubid = atooid(PQgetvalue(res, i, i_prpubid));
4200  Oid prrelid = atooid(PQgetvalue(res, i, i_prrelid));
4201  PublicationInfo *pubinfo;
4202  TableInfo *tbinfo;
4203 
4204  /*
4205  * Ignore any entries for which we aren't interested in either the
4206  * publication or the rel.
4207  */
4208  pubinfo = findPublicationByOid(prpubid);
4209  if (pubinfo == NULL)
4210  continue;
4211  tbinfo = findTableByOid(prrelid);
4212  if (tbinfo == NULL)
4213  continue;
4214 
4215  /*
4216  * Ignore publication membership of tables whose definitions are not
4217  * to be dumped.
4218  */
4219  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
4220  continue;
4221 
4222  /* OK, make a DumpableObject for this relationship */
4223  pubrinfo[j].dobj.objType = DO_PUBLICATION_REL;
4224  pubrinfo[j].dobj.catId.tableoid =
4225  atooid(PQgetvalue(res, i, i_tableoid));
4226  pubrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4227  AssignDumpId(&pubrinfo[j].dobj);
4228  pubrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4229  pubrinfo[j].dobj.name = tbinfo->dobj.name;
4230  pubrinfo[j].publication = pubinfo;
4231  pubrinfo[j].pubtable = tbinfo;
4232  if (PQgetisnull(res, i, i_prrelqual))
4233  pubrinfo[j].pubrelqual = NULL;
4234  else
4235  pubrinfo[j].pubrelqual = pg_strdup(PQgetvalue(res, i, i_prrelqual));
4236 
4237  if (!PQgetisnull(res, i, i_prattrs))
4238  {
4239  char **attnames;
4240  int nattnames;
4241  PQExpBuffer attribs;
4242 
4243  if (!parsePGArray(PQgetvalue(res, i, i_prattrs),
4244  &attnames, &nattnames))
4245  pg_fatal("could not parse %s array", "prattrs");
4246  attribs = createPQExpBuffer();
4247  for (int k = 0; k < nattnames; k++)
4248  {
4249  if (k > 0)
4250  appendPQExpBufferStr(attribs, ", ");
4251 
4252  appendPQExpBufferStr(attribs, fmtId(attnames[k]));
4253  }
4254  pubrinfo[j].pubrattrs = attribs->data;
4255  }
4256  else
4257  pubrinfo[j].pubrattrs = NULL;
4258 
4259  /* Decide whether we want to dump it */
4260  selectDumpablePublicationObject(&(pubrinfo[j].dobj), fout);
4261 
4262  j++;
4263  }
4264 
4265  PQclear(res);
4266  destroyPQExpBuffer(query);
4267 }
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 7297 of file pg_dump.c.

7298 {
7299  PGresult *res;
7300  int ntups;
7301  int i;
7302  PQExpBuffer query = createPQExpBuffer();
7303  RuleInfo *ruleinfo;
7304  int i_tableoid;
7305  int i_oid;
7306  int i_rulename;
7307  int i_ruletable;
7308  int i_ev_type;
7309  int i_is_instead;
7310  int i_ev_enabled;
7311 
7312  appendPQExpBufferStr(query, "SELECT "
7313  "tableoid, oid, rulename, "
7314  "ev_class AS ruletable, ev_type, is_instead, "
7315  "ev_enabled "
7316  "FROM pg_rewrite "
7317  "ORDER BY oid");
7318 
7319  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7320 
7321  ntups = PQntuples(res);
7322 
7323  *numRules = ntups;
7324 
7325  ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo));
7326 
7327  i_tableoid = PQfnumber(res, "tableoid");
7328  i_oid = PQfnumber(res, "oid");
7329  i_rulename = PQfnumber(res, "rulename");
7330  i_ruletable = PQfnumber(res, "ruletable");
7331  i_ev_type = PQfnumber(res, "ev_type");
7332  i_is_instead = PQfnumber(res, "is_instead");
7333  i_ev_enabled = PQfnumber(res, "ev_enabled");
7334 
7335  for (i = 0; i < ntups; i++)
7336  {
7337  Oid ruletableoid;
7338 
7339  ruleinfo[i].dobj.objType = DO_RULE;
7340  ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7341  ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7342  AssignDumpId(&ruleinfo[i].dobj);
7343  ruleinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_rulename));
7344  ruletableoid = atooid(PQgetvalue(res, i, i_ruletable));
7345  ruleinfo[i].ruletable = findTableByOid(ruletableoid);
7346  if (ruleinfo[i].ruletable == NULL)
7347  pg_fatal("failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
7348  ruletableoid, ruleinfo[i].dobj.catId.oid);
7349  ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace;
7350  ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump;
7351  ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type));
7352  ruleinfo[i].is_instead = *(PQgetvalue(res, i, i_is_instead)) == 't';
7353  ruleinfo[i].ev_enabled = *(PQgetvalue(res, i, i_ev_enabled));
7354  if (ruleinfo[i].ruletable)
7355  {
7356  /*
7357  * If the table is a view or materialized view, force its ON
7358  * SELECT rule to be sorted before the view itself --- this
7359  * ensures that any dependencies for the rule affect the table's
7360  * positioning. Other rules are forced to appear after their
7361  * table.
7362  */
7363  if ((ruleinfo[i].ruletable->relkind == RELKIND_VIEW ||
7364  ruleinfo[i].ruletable->relkind == RELKIND_MATVIEW) &&
7365  ruleinfo[i].ev_type == '1' && ruleinfo[i].is_instead)
7366  {
7367  addObjectDependency(&ruleinfo[i].ruletable->dobj,
7368  ruleinfo[i].dobj.dumpId);
7369  /* We'll merge the rule into CREATE VIEW, if possible */
7370  ruleinfo[i].separate = false;
7371  }
7372  else
7373  {
7374  addObjectDependency(&ruleinfo[i].dobj,
7375  ruleinfo[i].ruletable->dobj.dumpId);
7376  ruleinfo[i].separate = true;
7377  }
7378  }
7379  else
7380  ruleinfo[i].separate = true;
7381  }
7382 
7383  PQclear(res);
7384 
7385  destroyPQExpBuffer(query);
7386 
7387  return ruleinfo;
7388 }
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:720
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 *tbinfo, 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:467
#define free(a)
Definition: header.h:65
NamespaceInfo * getNamespaces(Archive *fout, int *numNamespaces)
Definition: pg_dump.c:4966
void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: