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

Go to the source code of this file.

Data Structures

struct  _dumpableObject
 
struct  _dumpableAcl
 
struct  _dumpableObjectWithAcl
 
struct  _namespaceInfo
 
struct  _extensionInfo
 
struct  _typeInfo
 
struct  _shellTypeInfo
 
struct  _funcInfo
 
struct  _aggInfo
 
struct  _oprInfo
 
struct  _accessMethodInfo
 
struct  _opclassInfo
 
struct  _opfamilyInfo
 
struct  _collInfo
 
struct  _convInfo
 
struct  _tableInfo
 
struct  _tableAttachInfo
 
struct  _attrDefInfo
 
struct  _tableDataInfo
 
struct  _indxInfo
 
struct  _indexAttachInfo
 
struct  _statsExtInfo
 
struct  _ruleInfo
 
struct  _triggerInfo
 
struct  _evttriggerInfo
 
struct  _constraintInfo
 
struct  _procLangInfo
 
struct  _castInfo
 
struct  _transformInfo
 
struct  _inhInfo
 
struct  _prsInfo
 
struct  _dictInfo
 
struct  _tmplInfo
 
struct  _cfgInfo
 
struct  _fdwInfo
 
struct  _foreignServerInfo
 
struct  _defaultACLInfo
 
struct  _loInfo
 
struct  _policyInfo
 
struct  _PublicationInfo
 
struct  _PublicationRelInfo
 
struct  _PublicationSchemaInfo
 
struct  _SubscriptionInfo
 
struct  _SubRelInfo
 

Macros

#define oidcmp(x, y)   ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) )
 
#define DUMP_COMPONENT_NONE   (0)
 
#define DUMP_COMPONENT_DEFINITION   (1 << 0)
 
#define DUMP_COMPONENT_DATA   (1 << 1)
 
#define DUMP_COMPONENT_COMMENT   (1 << 2)
 
#define DUMP_COMPONENT_SECLABEL   (1 << 3)
 
#define DUMP_COMPONENT_ACL   (1 << 4)
 
#define DUMP_COMPONENT_POLICY   (1 << 5)
 
#define DUMP_COMPONENT_USERMAP   (1 << 6)
 
#define DUMP_COMPONENT_ALL   (0xFFFF)
 
#define DUMP_COMPONENTS_REQUIRING_LOCK
 

Typedefs

typedef uint32 DumpComponents
 
typedef struct _dumpableObject DumpableObject
 
typedef struct _dumpableAcl DumpableAcl
 
typedef struct _dumpableObjectWithAcl DumpableObjectWithAcl
 
typedef struct _namespaceInfo NamespaceInfo
 
typedef struct _extensionInfo ExtensionInfo
 
typedef struct _typeInfo TypeInfo
 
typedef struct _shellTypeInfo ShellTypeInfo
 
typedef struct _funcInfo FuncInfo
 
typedef struct _aggInfo AggInfo
 
typedef struct _oprInfo OprInfo
 
typedef struct _accessMethodInfo AccessMethodInfo
 
typedef struct _opclassInfo OpclassInfo
 
typedef struct _opfamilyInfo OpfamilyInfo
 
typedef struct _collInfo CollInfo
 
typedef struct _convInfo ConvInfo
 
typedef struct _tableInfo TableInfo
 
typedef struct _tableAttachInfo TableAttachInfo
 
typedef struct _attrDefInfo AttrDefInfo
 
typedef struct _tableDataInfo TableDataInfo
 
typedef struct _indxInfo IndxInfo
 
typedef struct _indexAttachInfo IndexAttachInfo
 
typedef struct _statsExtInfo StatsExtInfo
 
typedef struct _ruleInfo RuleInfo
 
typedef struct _triggerInfo TriggerInfo
 
typedef struct _evttriggerInfo EventTriggerInfo
 
typedef struct _constraintInfo ConstraintInfo
 
typedef struct _procLangInfo ProcLangInfo
 
typedef struct _castInfo CastInfo
 
typedef struct _transformInfo TransformInfo
 
typedef struct _inhInfo InhInfo
 
typedef struct _prsInfo TSParserInfo
 
typedef struct _dictInfo TSDictInfo
 
typedef struct _tmplInfo TSTemplateInfo
 
typedef struct _cfgInfo TSConfigInfo
 
typedef struct _fdwInfo FdwInfo
 
typedef struct _foreignServerInfo ForeignServerInfo
 
typedef struct _defaultACLInfo DefaultACLInfo
 
typedef struct _loInfo LoInfo
 
typedef struct _policyInfo PolicyInfo
 
typedef struct _PublicationInfo PublicationInfo
 
typedef struct _PublicationRelInfo PublicationRelInfo
 
typedef struct _PublicationSchemaInfo PublicationSchemaInfo
 
typedef struct _SubscriptionInfo SubscriptionInfo
 
typedef struct _SubRelInfo SubRelInfo
 

Enumerations

enum  DumpableObjectType {
  DO_NAMESPACE , DO_EXTENSION , DO_TYPE , DO_SHELL_TYPE ,
  DO_FUNC , DO_AGG , DO_OPERATOR , DO_ACCESS_METHOD ,
  DO_OPCLASS , DO_OPFAMILY , DO_COLLATION , DO_CONVERSION ,
  DO_TABLE , DO_TABLE_ATTACH , DO_ATTRDEF , DO_INDEX ,
  DO_INDEX_ATTACH , DO_STATSEXT , DO_RULE , DO_TRIGGER ,
  DO_CONSTRAINT , DO_FK_CONSTRAINT , DO_PROCLANG , DO_CAST ,
  DO_TABLE_DATA , DO_SEQUENCE_SET , DO_DUMMY_TYPE , DO_TSPARSER ,
  DO_TSDICT , DO_TSTEMPLATE , DO_TSCONFIG , DO_FDW ,
  DO_FOREIGN_SERVER , DO_DEFAULT_ACL , DO_TRANSFORM , DO_LARGE_OBJECT ,
  DO_LARGE_OBJECT_DATA , DO_PRE_DATA_BOUNDARY , DO_POST_DATA_BOUNDARY , DO_EVENT_TRIGGER ,
  DO_REFRESH_MATVIEW , DO_POLICY , DO_PUBLICATION , DO_PUBLICATION_REL ,
  DO_PUBLICATION_TABLE_IN_SCHEMA , DO_SUBSCRIPTION , DO_SUBSCRIPTION_REL
}
 

Functions

TableInfogetSchemaData (Archive *fout, int *numTablesPtr)
 
void AssignDumpId (DumpableObject *dobj)
 
void recordAdditionalCatalogID (CatalogId catId, 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)
 
SubscriptionInfofindSubscriptionByOid (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)
 
void getNamespaces (Archive *fout)
 
ExtensionInfogetExtensions (Archive *fout, int *numExtensions)
 
void getTypes (Archive *fout)
 
void getFuncs (Archive *fout)
 
void getAggregates (Archive *fout)
 
void getOperators (Archive *fout)
 
void getAccessMethods (Archive *fout)
 
void getOpclasses (Archive *fout)
 
void getOpfamilies (Archive *fout)
 
void getCollations (Archive *fout)
 
void getConversions (Archive *fout)
 
TableInfogetTables (Archive *fout, int *numTables)
 
void getOwnedSeqs (Archive *fout, TableInfo tblinfo[], int numTables)
 
InhInfogetInherits (Archive *fout, int *numInherits)
 
void getPartitioningInfo (Archive *fout)
 
void getIndexes (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getExtendedStatistics (Archive *fout)
 
void getConstraints (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getRules (Archive *fout)
 
void getTriggers (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getProcLangs (Archive *fout)
 
void getCasts (Archive *fout)
 
void getTransforms (Archive *fout)
 
void getTableAttrs (Archive *fout, TableInfo *tblinfo, int numTables)
 
bool shouldPrintColumn (const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
 
void getTSParsers (Archive *fout)
 
void getTSDictionaries (Archive *fout)
 
void getTSTemplates (Archive *fout)
 
void getTSConfigurations (Archive *fout)
 
void getForeignDataWrappers (Archive *fout)
 
void getForeignServers (Archive *fout)
 
void getDefaultACLs (Archive *fout)
 
void getExtensionMembership (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
void processExtensionTables (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
void getEventTriggers (Archive *fout)
 
void getPolicies (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getPublications (Archive *fout)
 
void getPublicationNamespaces (Archive *fout)
 
void getPublicationTables (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getSubscriptions (Archive *fout)
 
void getSubscriptionTables (Archive *fout)
 

Macro Definition Documentation

◆ DUMP_COMPONENT_ACL

#define DUMP_COMPONENT_ACL   (1 << 4)

Definition at line 101 of file pg_dump.h.

◆ DUMP_COMPONENT_ALL

#define DUMP_COMPONENT_ALL   (0xFFFF)

Definition at line 104 of file pg_dump.h.

◆ DUMP_COMPONENT_COMMENT

#define DUMP_COMPONENT_COMMENT   (1 << 2)

Definition at line 99 of file pg_dump.h.

◆ DUMP_COMPONENT_DATA

#define DUMP_COMPONENT_DATA   (1 << 1)

Definition at line 98 of file pg_dump.h.

◆ DUMP_COMPONENT_DEFINITION

#define DUMP_COMPONENT_DEFINITION   (1 << 0)

Definition at line 97 of file pg_dump.h.

◆ DUMP_COMPONENT_NONE

#define DUMP_COMPONENT_NONE   (0)

Definition at line 96 of file pg_dump.h.

◆ DUMP_COMPONENT_POLICY

#define DUMP_COMPONENT_POLICY   (1 << 5)

Definition at line 102 of file pg_dump.h.

◆ DUMP_COMPONENT_SECLABEL

#define DUMP_COMPONENT_SECLABEL   (1 << 3)

Definition at line 100 of file pg_dump.h.

◆ DUMP_COMPONENT_USERMAP

#define DUMP_COMPONENT_USERMAP   (1 << 6)

Definition at line 103 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 128 of file pg_dump.h.

◆ oidcmp

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

Definition at line 20 of file pg_dump.h.

Typedef Documentation

◆ AccessMethodInfo

◆ AggInfo

typedef struct _aggInfo AggInfo

◆ AttrDefInfo

typedef struct _attrDefInfo AttrDefInfo

◆ CastInfo

typedef struct _castInfo CastInfo

◆ CollInfo

typedef struct _collInfo CollInfo

◆ ConstraintInfo

◆ ConvInfo

typedef struct _convInfo ConvInfo

◆ DefaultACLInfo

◆ DumpableAcl

typedef struct _dumpableAcl DumpableAcl

◆ DumpableObject

◆ DumpableObjectWithAcl

◆ DumpComponents

Definition at line 95 of file pg_dump.h.

◆ EventTriggerInfo

◆ ExtensionInfo

typedef struct _extensionInfo ExtensionInfo

◆ FdwInfo

typedef struct _fdwInfo FdwInfo

◆ ForeignServerInfo

◆ FuncInfo

typedef struct _funcInfo FuncInfo

◆ IndexAttachInfo

◆ IndxInfo

typedef struct _indxInfo IndxInfo

◆ InhInfo

typedef struct _inhInfo InhInfo

◆ LoInfo

typedef struct _loInfo LoInfo

◆ NamespaceInfo

typedef struct _namespaceInfo NamespaceInfo

◆ OpclassInfo

typedef struct _opclassInfo OpclassInfo

◆ OpfamilyInfo

typedef struct _opfamilyInfo OpfamilyInfo

◆ OprInfo

typedef struct _oprInfo OprInfo

◆ PolicyInfo

typedef struct _policyInfo PolicyInfo

◆ ProcLangInfo

typedef struct _procLangInfo ProcLangInfo

◆ PublicationInfo

◆ PublicationRelInfo

◆ PublicationSchemaInfo

◆ RuleInfo

typedef struct _ruleInfo RuleInfo

◆ ShellTypeInfo

typedef struct _shellTypeInfo ShellTypeInfo

◆ StatsExtInfo

typedef struct _statsExtInfo StatsExtInfo

◆ SubRelInfo

typedef struct _SubRelInfo SubRelInfo

◆ SubscriptionInfo

◆ TableAttachInfo

◆ TableDataInfo

typedef struct _tableDataInfo TableDataInfo

◆ TableInfo

typedef struct _tableInfo TableInfo

◆ TransformInfo

typedef struct _transformInfo TransformInfo

◆ TriggerInfo

typedef struct _triggerInfo TriggerInfo

◆ TSConfigInfo

typedef struct _cfgInfo TSConfigInfo

◆ TSDictInfo

typedef struct _dictInfo TSDictInfo

◆ TSParserInfo

typedef struct _prsInfo TSParserInfo

◆ TSTemplateInfo

typedef struct _tmplInfo TSTemplateInfo

◆ TypeInfo

typedef struct _typeInfo TypeInfo

Enumeration Type Documentation

◆ DumpableObjectType

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

Definition at line 37 of file pg_dump.h.

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

Function Documentation

◆ addObjectDependency()

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

◆ AssignDumpId()

void AssignDumpId ( DumpableObject dobj)

Definition at line 634 of file common.c.

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

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

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

◆ createDumpId()

◆ findCollationByOid()

CollInfo* findCollationByOid ( Oid  oid)

Definition at line 931 of file common.c.

932 {
933  CatalogId catId;
934  DumpableObject *dobj;
935 
936  catId.tableoid = CollationRelationId;
937  catId.oid = oid;
938  dobj = findObjectByCatalogId(catId);
939  Assert(dobj == NULL || dobj->objType == DO_COLLATION);
940  return (CollInfo *) dobj;
941 }
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition: common.c:755
DumpableObjectType objType
Definition: pg_dump.h:135

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

968 {
969  CatalogId catId;
970  DumpableObject *dobj;
971 
972  catId.tableoid = ExtensionRelationId;
973  catId.oid = oid;
974  dobj = findObjectByCatalogId(catId);
975  Assert(dobj == NULL || dobj->objType == DO_EXTENSION);
976  return (ExtensionInfo *) dobj;
977 }

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

Referenced by getExtensionMembership().

◆ findFuncByOid()

FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 895 of file common.c.

896 {
897  CatalogId catId;
898  DumpableObject *dobj;
899 
900  catId.tableoid = ProcedureRelationId;
901  catId.oid = oid;
902  dobj = findObjectByCatalogId(catId);
903  Assert(dobj == NULL || dobj->objType == DO_FUNC);
904  return (FuncInfo *) dobj;
905 }

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

950 {
951  CatalogId catId;
952  DumpableObject *dobj;
953 
954  catId.tableoid = NamespaceRelationId;
955  catId.oid = oid;
956  dobj = findObjectByCatalogId(catId);
957  Assert(dobj == NULL || dobj->objType == DO_NAMESPACE);
958  return (NamespaceInfo *) dobj;
959 }

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

756 {
757  CatalogIdMapEntry *entry;
758 
759  if (catalogIdHash == NULL)
760  return NULL; /* no objects exist yet */
761 
762  entry = catalogid_lookup(catalogIdHash, catalogId);
763  if (entry == NULL)
764  return NULL;
765  return entry->dobj;
766 }

References catalogIdHash, and _catalogIdMapEntry::dobj.

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

◆ findObjectByDumpId()

DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 742 of file common.c.

743 {
744  if (dumpId <= 0 || dumpId >= allocedDumpIds)
745  return NULL; /* out of range? */
746  return dumpIdMap[dumpId];
747 }

References allocedDumpIds, and dumpIdMap.

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

◆ findOprByOid()

OprInfo* findOprByOid ( Oid  oid)

Definition at line 913 of file common.c.

914 {
915  CatalogId catId;
916  DumpableObject *dobj;
917 
918  catId.tableoid = OperatorRelationId;
919  catId.oid = oid;
920  dobj = findObjectByCatalogId(catId);
921  Assert(dobj == NULL || dobj->objType == DO_OPERATOR);
922  return (OprInfo *) dobj;
923 }

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

Referenced by getFormattedOperatorName().

◆ findOwningExtension()

ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 1046 of file common.c.

1047 {
1048  CatalogIdMapEntry *entry;
1049 
1050  if (catalogIdHash == NULL)
1051  return NULL; /* no objects exist yet */
1052 
1053  entry = catalogid_lookup(catalogIdHash, catalogId);
1054  if (entry == NULL)
1055  return NULL;
1056  return entry->ext;
1057 }

References catalogIdHash, and _catalogIdMapEntry::ext.

Referenced by checkExtensionMembership().

◆ findPublicationByOid()

PublicationInfo* findPublicationByOid ( Oid  oid)

Definition at line 985 of file common.c.

986 {
987  CatalogId catId;
988  DumpableObject *dobj;
989 
990  catId.tableoid = PublicationRelationId;
991  catId.oid = oid;
992  dobj = findObjectByCatalogId(catId);
993  Assert(dobj == NULL || dobj->objType == DO_PUBLICATION);
994  return (PublicationInfo *) dobj;
995 }

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

Referenced by getPublicationNamespaces(), and getPublicationTables().

◆ findSubscriptionByOid()

SubscriptionInfo* findSubscriptionByOid ( Oid  oid)

Definition at line 1003 of file common.c.

1004 {
1005  CatalogId catId;
1006  DumpableObject *dobj;
1007 
1008  catId.tableoid = SubscriptionRelationId;
1009  catId.oid = oid;
1010  dobj = findObjectByCatalogId(catId);
1011  Assert(dobj == NULL || dobj->objType == DO_SUBSCRIPTION);
1012  return (SubscriptionInfo *) dobj;
1013 }

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

Referenced by getSubscriptionTables().

◆ findTableByOid()

TableInfo* findTableByOid ( Oid  oid)

◆ findTypeByOid()

TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 876 of file common.c.

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

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

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

◆ getAccessMethods()

void getAccessMethods ( Archive fout)

Definition at line 6265 of file pg_dump.c.

6266 {
6267  PGresult *res;
6268  int ntups;
6269  int i;
6270  PQExpBuffer query;
6271  AccessMethodInfo *aminfo;
6272  int i_tableoid;
6273  int i_oid;
6274  int i_amname;
6275  int i_amhandler;
6276  int i_amtype;
6277 
6278  /* Before 9.6, there are no user-defined access methods */
6279  if (fout->remoteVersion < 90600)
6280  return;
6281 
6282  query = createPQExpBuffer();
6283 
6284  /* Select all access methods from pg_am table */
6285  appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, amtype, "
6286  "amhandler::pg_catalog.regproc AS amhandler "
6287  "FROM pg_am");
6288 
6289  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6290 
6291  ntups = PQntuples(res);
6292 
6293  aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
6294 
6295  i_tableoid = PQfnumber(res, "tableoid");
6296  i_oid = PQfnumber(res, "oid");
6297  i_amname = PQfnumber(res, "amname");
6298  i_amhandler = PQfnumber(res, "amhandler");
6299  i_amtype = PQfnumber(res, "amtype");
6300 
6301  for (i = 0; i < ntups; i++)
6302  {
6303  aminfo[i].dobj.objType = DO_ACCESS_METHOD;
6304  aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6305  aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6306  AssignDumpId(&aminfo[i].dobj);
6307  aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
6308  aminfo[i].dobj.namespace = NULL;
6309  aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
6310  aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
6311 
6312  /* Decide whether we want to dump it */
6313  selectDumpableAccessMethod(&(aminfo[i]), fout);
6314  }
6315 
6316  PQclear(res);
6317 
6318  destroyPQExpBuffer(query);
6319 }
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:634
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3481
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3876
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3589
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int i
Definition: isn.c:72
@ PGRES_TUPLES_OK
Definition: libpq-fe.h:123
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:288
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:2074
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:72
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:114
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:367
int remoteVersion
Definition: pg_backup.h:220
char * amhandler
Definition: pg_dump.h:254
DumpableObject dobj
Definition: pg_dump.h:252

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()

void getAggregates ( Archive fout)

Definition at line 6449 of file pg_dump.c.

6450 {
6451  DumpOptions *dopt = fout->dopt;
6452  PGresult *res;
6453  int ntups;
6454  int i;
6455  PQExpBuffer query = createPQExpBuffer();
6456  AggInfo *agginfo;
6457  int i_tableoid;
6458  int i_oid;
6459  int i_aggname;
6460  int i_aggnamespace;
6461  int i_pronargs;
6462  int i_proargtypes;
6463  int i_proowner;
6464  int i_aggacl;
6465  int i_acldefault;
6466 
6467  /*
6468  * Find all interesting aggregates. See comment in getFuncs() for the
6469  * rationale behind the filtering logic.
6470  */
6471  if (fout->remoteVersion >= 90600)
6472  {
6473  const char *agg_check;
6474 
6475  agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
6476  : "p.proisagg");
6477 
6478  appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
6479  "p.proname AS aggname, "
6480  "p.pronamespace AS aggnamespace, "
6481  "p.pronargs, p.proargtypes, "
6482  "p.proowner, "
6483  "p.proacl AS aggacl, "
6484  "acldefault('f', p.proowner) AS acldefault "
6485  "FROM pg_proc p "
6486  "LEFT JOIN pg_init_privs pip ON "
6487  "(p.oid = pip.objoid "
6488  "AND pip.classoid = 'pg_proc'::regclass "
6489  "AND pip.objsubid = 0) "
6490  "WHERE %s AND ("
6491  "p.pronamespace != "
6492  "(SELECT oid FROM pg_namespace "
6493  "WHERE nspname = 'pg_catalog') OR "
6494  "p.proacl IS DISTINCT FROM pip.initprivs",
6495  agg_check);
6496  if (dopt->binary_upgrade)
6497  appendPQExpBufferStr(query,
6498  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6499  "classid = 'pg_proc'::regclass AND "
6500  "objid = p.oid AND "
6501  "refclassid = 'pg_extension'::regclass AND "
6502  "deptype = 'e')");
6503  appendPQExpBufferChar(query, ')');
6504  }
6505  else
6506  {
6507  appendPQExpBufferStr(query, "SELECT tableoid, oid, proname AS aggname, "
6508  "pronamespace AS aggnamespace, "
6509  "pronargs, proargtypes, "
6510  "proowner, "
6511  "proacl AS aggacl, "
6512  "acldefault('f', proowner) AS acldefault "
6513  "FROM pg_proc p "
6514  "WHERE proisagg AND ("
6515  "pronamespace != "
6516  "(SELECT oid FROM pg_namespace "
6517  "WHERE nspname = 'pg_catalog')");
6518  if (dopt->binary_upgrade)
6519  appendPQExpBufferStr(query,
6520  " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6521  "classid = 'pg_proc'::regclass AND "
6522  "objid = p.oid AND "
6523  "refclassid = 'pg_extension'::regclass AND "
6524  "deptype = 'e')");
6525  appendPQExpBufferChar(query, ')');
6526  }
6527 
6528  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6529 
6530  ntups = PQntuples(res);
6531 
6532  agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
6533 
6534  i_tableoid = PQfnumber(res, "tableoid");
6535  i_oid = PQfnumber(res, "oid");
6536  i_aggname = PQfnumber(res, "aggname");
6537  i_aggnamespace = PQfnumber(res, "aggnamespace");
6538  i_pronargs = PQfnumber(res, "pronargs");
6539  i_proargtypes = PQfnumber(res, "proargtypes");
6540  i_proowner = PQfnumber(res, "proowner");
6541  i_aggacl = PQfnumber(res, "aggacl");
6542  i_acldefault = PQfnumber(res, "acldefault");
6543 
6544  for (i = 0; i < ntups; i++)
6545  {
6546  agginfo[i].aggfn.dobj.objType = DO_AGG;
6547  agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6548  agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6549  AssignDumpId(&agginfo[i].aggfn.dobj);
6550  agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
6551  agginfo[i].aggfn.dobj.namespace =
6552  findNamespace(atooid(PQgetvalue(res, i, i_aggnamespace)));
6553  agginfo[i].aggfn.dacl.acl = pg_strdup(PQgetvalue(res, i, i_aggacl));
6554  agginfo[i].aggfn.dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6555  agginfo[i].aggfn.dacl.privtype = 0;
6556  agginfo[i].aggfn.dacl.initprivs = NULL;
6557  agginfo[i].aggfn.rolname = getRoleName(PQgetvalue(res, i, i_proowner));
6558  agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
6559  agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
6560  agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
6561  if (agginfo[i].aggfn.nargs == 0)
6562  agginfo[i].aggfn.argtypes = NULL;
6563  else
6564  {
6565  agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
6566  parseOidArray(PQgetvalue(res, i, i_proargtypes),
6567  agginfo[i].aggfn.argtypes,
6568  agginfo[i].aggfn.nargs);
6569  }
6570  agginfo[i].aggfn.postponed_def = false; /* might get set during sort */
6571 
6572  /* Decide whether we want to dump it */
6573  selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
6574 
6575  /* Mark whether aggregate has an ACL */
6576  if (!PQgetisnull(res, i, i_aggacl))
6577  agginfo[i].aggfn.dobj.components |= DUMP_COMPONENT_ACL;
6578  }
6579 
6580  PQclear(res);
6581 
6582  destroyPQExpBuffer(query);
6583 }
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1070
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3901
static const char * getRoleName(const char *roleoid_str)
Definition: pg_dump.c:9985
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:2177
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:5813
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:101
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:265
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:378
DumpOptions * dopt
Definition: pg_backup.h:215
int binary_upgrade
Definition: pg_backup.h:167

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()

void getCasts ( Archive fout)

Definition at line 8542 of file pg_dump.c.

8543 {
8544  PGresult *res;
8545  int ntups;
8546  int i;
8547  PQExpBuffer query = createPQExpBuffer();
8548  CastInfo *castinfo;
8549  int i_tableoid;
8550  int i_oid;
8551  int i_castsource;
8552  int i_casttarget;
8553  int i_castfunc;
8554  int i_castcontext;
8555  int i_castmethod;
8556 
8557  if (fout->remoteVersion >= 140000)
8558  {
8559  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8560  "castsource, casttarget, castfunc, castcontext, "
8561  "castmethod "
8562  "FROM pg_cast c "
8563  "WHERE NOT EXISTS ( "
8564  "SELECT 1 FROM pg_range r "
8565  "WHERE c.castsource = r.rngtypid "
8566  "AND c.casttarget = r.rngmultitypid "
8567  ") "
8568  "ORDER BY 3,4");
8569  }
8570  else
8571  {
8572  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8573  "castsource, casttarget, castfunc, castcontext, "
8574  "castmethod "
8575  "FROM pg_cast ORDER BY 3,4");
8576  }
8577 
8578  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8579 
8580  ntups = PQntuples(res);
8581 
8582  castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
8583 
8584  i_tableoid = PQfnumber(res, "tableoid");
8585  i_oid = PQfnumber(res, "oid");
8586  i_castsource = PQfnumber(res, "castsource");
8587  i_casttarget = PQfnumber(res, "casttarget");
8588  i_castfunc = PQfnumber(res, "castfunc");
8589  i_castcontext = PQfnumber(res, "castcontext");
8590  i_castmethod = PQfnumber(res, "castmethod");
8591 
8592  for (i = 0; i < ntups; i++)
8593  {
8594  PQExpBufferData namebuf;
8595  TypeInfo *sTypeInfo;
8596  TypeInfo *tTypeInfo;
8597 
8598  castinfo[i].dobj.objType = DO_CAST;
8599  castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8600  castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8601  AssignDumpId(&castinfo[i].dobj);
8602  castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
8603  castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
8604  castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
8605  castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
8606  castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
8607 
8608  /*
8609  * Try to name cast as concatenation of typnames. This is only used
8610  * for purposes of sorting. If we fail to find either type, the name
8611  * will be an empty string.
8612  */
8613  initPQExpBuffer(&namebuf);
8614  sTypeInfo = findTypeByOid(castinfo[i].castsource);
8615  tTypeInfo = findTypeByOid(castinfo[i].casttarget);
8616  if (sTypeInfo && tTypeInfo)
8617  appendPQExpBuffer(&namebuf, "%s %s",
8618  sTypeInfo->dobj.name, tTypeInfo->dobj.name);
8619  castinfo[i].dobj.name = namebuf.data;
8620 
8621  /* Decide whether we want to dump it */
8622  selectDumpableCast(&(castinfo[i]), fout);
8623  }
8624 
8625  PQclear(res);
8626 
8627  destroyPQExpBuffer(query);
8628 }
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:876
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:2016
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
char castmethod
Definition: pg_dump.h:505
Oid casttarget
Definition: pg_dump.h:502
char castcontext
Definition: pg_dump.h:504
DumpableObject dobj
Definition: pg_dump.h:500
Oid castsource
Definition: pg_dump.h:501
Oid castfunc
Definition: pg_dump.h:503
DumpableObject dobj
Definition: pg_dump.h:191

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()

void getCollations ( Archive fout)

Definition at line 6141 of file pg_dump.c.

6142 {
6143  PGresult *res;
6144  int ntups;
6145  int i;
6146  PQExpBuffer query;
6147  CollInfo *collinfo;
6148  int i_tableoid;
6149  int i_oid;
6150  int i_collname;
6151  int i_collnamespace;
6152  int i_collowner;
6153 
6154  query = createPQExpBuffer();
6155 
6156  /*
6157  * find all collations, including builtin collations; we filter out
6158  * system-defined collations at dump-out time.
6159  */
6160 
6161  appendPQExpBufferStr(query, "SELECT tableoid, oid, collname, "
6162  "collnamespace, "
6163  "collowner "
6164  "FROM pg_collation");
6165 
6166  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6167 
6168  ntups = PQntuples(res);
6169 
6170  collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
6171 
6172  i_tableoid = PQfnumber(res, "tableoid");
6173  i_oid = PQfnumber(res, "oid");
6174  i_collname = PQfnumber(res, "collname");
6175  i_collnamespace = PQfnumber(res, "collnamespace");
6176  i_collowner = PQfnumber(res, "collowner");
6177 
6178  for (i = 0; i < ntups; i++)
6179  {
6180  collinfo[i].dobj.objType = DO_COLLATION;
6181  collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6182  collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6183  AssignDumpId(&collinfo[i].dobj);
6184  collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
6185  collinfo[i].dobj.namespace =
6186  findNamespace(atooid(PQgetvalue(res, i, i_collnamespace)));
6187  collinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_collowner));
6188 
6189  /* Decide whether we want to dump it */
6190  selectDumpableObject(&(collinfo[i].dobj), fout);
6191  }
6192 
6193  PQclear(res);
6194 
6195  destroyPQExpBuffer(query);
6196 }
const char * rolname
Definition: pg_dump.h:272
DumpableObject dobj
Definition: pg_dump.h:271

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

Referenced by getSchemaData().

◆ getConstraints()

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

Definition at line 7809 of file pg_dump.c.

7810 {
7811  PQExpBuffer query = createPQExpBuffer();
7812  PQExpBuffer tbloids = createPQExpBuffer();
7813  PGresult *res;
7814  int ntups;
7815  int curtblindx;
7816  TableInfo *tbinfo = NULL;
7817  ConstraintInfo *constrinfo;
7818  int i_contableoid,
7819  i_conoid,
7820  i_conrelid,
7821  i_conname,
7822  i_confrelid,
7823  i_conindid,
7824  i_condef;
7825 
7826  /*
7827  * We want to perform just one query against pg_constraint. However, we
7828  * mustn't try to select every row of the catalog and then sort it out on
7829  * the client side, because some of the server-side functions we need
7830  * would be unsafe to apply to tables we don't have lock on. Hence, we
7831  * build an array of the OIDs of tables we care about (and now have lock
7832  * on!), and use a WHERE clause to constrain which rows are selected.
7833  */
7834  appendPQExpBufferChar(tbloids, '{');
7835  for (int i = 0; i < numTables; i++)
7836  {
7837  TableInfo *tinfo = &tblinfo[i];
7838 
7839  /*
7840  * For partitioned tables, foreign keys have no triggers so they must
7841  * be included anyway in case some foreign keys are defined.
7842  */
7843  if ((!tinfo->hastriggers &&
7844  tinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7845  !(tinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
7846  continue;
7847 
7848  /* OK, we need info for this table */
7849  if (tbloids->len > 1) /* do we have more than the '{'? */
7850  appendPQExpBufferChar(tbloids, ',');
7851  appendPQExpBuffer(tbloids, "%u", tinfo->dobj.catId.oid);
7852  }
7853  appendPQExpBufferChar(tbloids, '}');
7854 
7855  appendPQExpBufferStr(query,
7856  "SELECT c.tableoid, c.oid, "
7857  "conrelid, conname, confrelid, ");
7858  if (fout->remoteVersion >= 110000)
7859  appendPQExpBufferStr(query, "conindid, ");
7860  else
7861  appendPQExpBufferStr(query, "0 AS conindid, ");
7862  appendPQExpBuffer(query,
7863  "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
7864  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7865  "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
7866  "WHERE contype = 'f' ",
7867  tbloids->data);
7868  if (fout->remoteVersion >= 110000)
7869  appendPQExpBufferStr(query,
7870  "AND conparentid = 0 ");
7871  appendPQExpBufferStr(query,
7872  "ORDER BY conrelid, conname");
7873 
7874  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7875 
7876  ntups = PQntuples(res);
7877 
7878  i_contableoid = PQfnumber(res, "tableoid");
7879  i_conoid = PQfnumber(res, "oid");
7880  i_conrelid = PQfnumber(res, "conrelid");
7881  i_conname = PQfnumber(res, "conname");
7882  i_confrelid = PQfnumber(res, "confrelid");
7883  i_conindid = PQfnumber(res, "conindid");
7884  i_condef = PQfnumber(res, "condef");
7885 
7886  constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
7887 
7888  curtblindx = -1;
7889  for (int j = 0; j < ntups; j++)
7890  {
7891  Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
7892  TableInfo *reftable;
7893 
7894  /*
7895  * Locate the associated TableInfo; we rely on tblinfo[] being in OID
7896  * order.
7897  */
7898  if (tbinfo == NULL || tbinfo->dobj.catId.oid != conrelid)
7899  {
7900  while (++curtblindx < numTables)
7901  {
7902  tbinfo = &tblinfo[curtblindx];
7903  if (tbinfo->dobj.catId.oid == conrelid)
7904  break;
7905  }
7906  if (curtblindx >= numTables)
7907  pg_fatal("unrecognized table OID %u", conrelid);
7908  }
7909 
7910  constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
7911  constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7912  constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7913  AssignDumpId(&constrinfo[j].dobj);
7914  constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7915  constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7916  constrinfo[j].contable = tbinfo;
7917  constrinfo[j].condomain = NULL;
7918  constrinfo[j].contype = 'f';
7919  constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
7920  constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
7921  constrinfo[j].conindex = 0;
7922  constrinfo[j].condeferrable = false;
7923  constrinfo[j].condeferred = false;
7924  constrinfo[j].conislocal = true;
7925  constrinfo[j].separate = true;
7926 
7927  /*
7928  * Restoring an FK that points to a partitioned table requires that
7929  * all partition indexes have been attached beforehand. Ensure that
7930  * happens by making the constraint depend on each index partition
7931  * attach object.
7932  */
7933  reftable = findTableByOid(constrinfo[j].confrelid);
7934  if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
7935  {
7936  Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
7937 
7938  if (indexOid != InvalidOid)
7939  {
7940  for (int k = 0; k < reftable->numIndexes; k++)
7941  {
7942  IndxInfo *refidx;
7943 
7944  /* not our index? */
7945  if (reftable->indexes[k].dobj.catId.oid != indexOid)
7946  continue;
7947 
7948  refidx = &reftable->indexes[k];
7949  addConstrChildIdxDeps(&constrinfo[j].dobj, refidx);
7950  break;
7951  }
7952  }
7953  }
7954  }
7955 
7956  PQclear(res);
7957 
7958  destroyPQExpBuffer(query);
7959  destroyPQExpBuffer(tbloids);
7960 }
TableInfo * findTableByOid(Oid oid)
Definition: common.c:840
static const gbtree_vinfo tinfo
Definition: btree_bit.c:108
int j
Definition: isn.c:73
#define pg_fatal(...)
static void addConstrChildIdxDeps(DumpableObject *dobj, const IndxInfo *refidx)
Definition: pg_dump.c:7974
TypeInfo * condomain
Definition: pg_dump.h:475
TableInfo * contable
Definition: pg_dump.h:474
bool condeferred
Definition: pg_dump.h:481
bool conislocal
Definition: pg_dump.h:483
DumpableObject dobj
Definition: pg_dump.h:473
DumpId conindex
Definition: pg_dump.h:479
bool condeferrable
Definition: pg_dump.h:480
char * condef
Definition: pg_dump.h:477
DumpableObject dobj
Definition: pg_dump.h:396
struct _indxInfo * indexes
Definition: pg_dump.h:365
DumpableObject dobj
Definition: pg_dump.h:286
char relkind
Definition: pg_dump.h:289
int numIndexes
Definition: pg_dump.h:364

References addConstrChildIdxDeps(), appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _constraintInfo::condef, _constraintInfo::condeferrable, _constraintInfo::condeferred, _constraintInfo::condomain, _constraintInfo::confrelid, _constraintInfo::conindex, _constraintInfo::conislocal, _constraintInfo::contable, _constraintInfo::contype, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FK_CONSTRAINT, _tableInfo::dobj, _indxInfo::dobj, _constraintInfo::dobj, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), findTableByOid(), i, _tableInfo::indexes, InvalidOid, j, PQExpBufferData::len, _dumpableObject::name, _tableInfo::numIndexes, _dumpableObject::objType, CatalogId::oid, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relkind, Archive::remoteVersion, res, _constraintInfo::separate, CatalogId::tableoid, and tinfo.

Referenced by getSchemaData().

◆ getConversions()

void getConversions ( Archive fout)

Definition at line 6203 of file pg_dump.c.

6204 {
6205  PGresult *res;
6206  int ntups;
6207  int i;
6208  PQExpBuffer query;
6209  ConvInfo *convinfo;
6210  int i_tableoid;
6211  int i_oid;
6212  int i_conname;
6213  int i_connamespace;
6214  int i_conowner;
6215 
6216  query = createPQExpBuffer();
6217 
6218  /*
6219  * find all conversions, including builtin conversions; we filter out
6220  * system-defined conversions at dump-out time.
6221  */
6222 
6223  appendPQExpBufferStr(query, "SELECT tableoid, oid, conname, "
6224  "connamespace, "
6225  "conowner "
6226  "FROM pg_conversion");
6227 
6228  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6229 
6230  ntups = PQntuples(res);
6231 
6232  convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
6233 
6234  i_tableoid = PQfnumber(res, "tableoid");
6235  i_oid = PQfnumber(res, "oid");
6236  i_conname = PQfnumber(res, "conname");
6237  i_connamespace = PQfnumber(res, "connamespace");
6238  i_conowner = PQfnumber(res, "conowner");
6239 
6240  for (i = 0; i < ntups; i++)
6241  {
6242  convinfo[i].dobj.objType = DO_CONVERSION;
6243  convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6244  convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6245  AssignDumpId(&convinfo[i].dobj);
6246  convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
6247  convinfo[i].dobj.namespace =
6248  findNamespace(atooid(PQgetvalue(res, i, i_connamespace)));
6249  convinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_conowner));
6250 
6251  /* Decide whether we want to dump it */
6252  selectDumpableObject(&(convinfo[i].dobj), fout);
6253  }
6254 
6255  PQclear(res);
6256 
6257  destroyPQExpBuffer(query);
6258 }
DumpableObject dobj
Definition: pg_dump.h:277
const char * rolname
Definition: pg_dump.h:278

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

Referenced by getSchemaData().

◆ getDefaultACLs()

void getDefaultACLs ( Archive fout)

Definition at line 9888 of file pg_dump.c.

9889 {
9890  DumpOptions *dopt = fout->dopt;
9891  DefaultACLInfo *daclinfo;
9892  PQExpBuffer query;
9893  PGresult *res;
9894  int i_oid;
9895  int i_tableoid;
9896  int i_defaclrole;
9897  int i_defaclnamespace;
9898  int i_defaclobjtype;
9899  int i_defaclacl;
9900  int i_acldefault;
9901  int i,
9902  ntups;
9903 
9904  query = createPQExpBuffer();
9905 
9906  /*
9907  * Global entries (with defaclnamespace=0) replace the hard-wired default
9908  * ACL for their object type. We should dump them as deltas from the
9909  * default ACL, since that will be used as a starting point for
9910  * interpreting the ALTER DEFAULT PRIVILEGES commands. On the other hand,
9911  * non-global entries can only add privileges not revoke them. We must
9912  * dump those as-is (i.e., as deltas from an empty ACL).
9913  *
9914  * We can use defaclobjtype as the object type for acldefault(), except
9915  * for the case of 'S' (DEFACLOBJ_SEQUENCE) which must be converted to
9916  * 's'.
9917  */
9918  appendPQExpBufferStr(query,
9919  "SELECT oid, tableoid, "
9920  "defaclrole, "
9921  "defaclnamespace, "
9922  "defaclobjtype, "
9923  "defaclacl, "
9924  "CASE WHEN defaclnamespace = 0 THEN "
9925  "acldefault(CASE WHEN defaclobjtype = 'S' "
9926  "THEN 's'::\"char\" ELSE defaclobjtype END, "
9927  "defaclrole) ELSE '{}' END AS acldefault "
9928  "FROM pg_default_acl");
9929 
9930  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9931 
9932  ntups = PQntuples(res);
9933 
9934  daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
9935 
9936  i_oid = PQfnumber(res, "oid");
9937  i_tableoid = PQfnumber(res, "tableoid");
9938  i_defaclrole = PQfnumber(res, "defaclrole");
9939  i_defaclnamespace = PQfnumber(res, "defaclnamespace");
9940  i_defaclobjtype = PQfnumber(res, "defaclobjtype");
9941  i_defaclacl = PQfnumber(res, "defaclacl");
9942  i_acldefault = PQfnumber(res, "acldefault");
9943 
9944  for (i = 0; i < ntups; i++)
9945  {
9946  Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
9947 
9948  daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
9949  daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9950  daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9951  AssignDumpId(&daclinfo[i].dobj);
9952  /* cheesy ... is it worth coming up with a better object name? */
9953  daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
9954 
9955  if (nspid != InvalidOid)
9956  daclinfo[i].dobj.namespace = findNamespace(nspid);
9957  else
9958  daclinfo[i].dobj.namespace = NULL;
9959 
9960  daclinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9961  daclinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9962  daclinfo[i].dacl.privtype = 0;
9963  daclinfo[i].dacl.initprivs = NULL;
9964  daclinfo[i].defaclrole = getRoleName(PQgetvalue(res, i, i_defaclrole));
9965  daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
9966 
9967  /* Default ACLs are ACLs, of course */
9968  daclinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9969 
9970  /* Decide whether we want to dump it */
9971  selectDumpableDefaultACL(&(daclinfo[i]), dopt);
9972  }
9973 
9974  PQclear(res);
9975 
9976  destroyPQExpBuffer(query);
9977 }
int nspid
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition: pg_dump.c:1994
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:159
char * acldefault
Definition: pg_dump.h:157
char * acl
Definition: pg_dump.h:156
char * initprivs
Definition: pg_dump.h:160

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

Referenced by getSchemaData().

◆ getDumpableObjects()

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

Definition at line 774 of file common.c.

775 {
776  int i,
777  j;
778 
780  j = 0;
781  for (i = 1; i < allocedDumpIds; i++)
782  {
783  if (dumpIdMap[i])
784  (*objs)[j++] = dumpIdMap[i];
785  }
786  *numObjs = j;
787 }

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

Referenced by getTableDataFKConstraints(), and main().

◆ getEventTriggers()

void getEventTriggers ( Archive fout)

Definition at line 8380 of file pg_dump.c.

8381 {
8382  int i;
8383  PQExpBuffer query;
8384  PGresult *res;
8385  EventTriggerInfo *evtinfo;
8386  int i_tableoid,
8387  i_oid,
8388  i_evtname,
8389  i_evtevent,
8390  i_evtowner,
8391  i_evttags,
8392  i_evtfname,
8393  i_evtenabled;
8394  int ntups;
8395 
8396  /* Before 9.3, there are no event triggers */
8397  if (fout->remoteVersion < 90300)
8398  return;
8399 
8400  query = createPQExpBuffer();
8401 
8402  appendPQExpBufferStr(query,
8403  "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8404  "evtevent, evtowner, "
8405  "array_to_string(array("
8406  "select quote_literal(x) "
8407  " from unnest(evttags) as t(x)), ', ') as evttags, "
8408  "e.evtfoid::regproc as evtfname "
8409  "FROM pg_event_trigger e "
8410  "ORDER BY e.oid");
8411 
8412  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8413 
8414  ntups = PQntuples(res);
8415 
8416  evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
8417 
8418  i_tableoid = PQfnumber(res, "tableoid");
8419  i_oid = PQfnumber(res, "oid");
8420  i_evtname = PQfnumber(res, "evtname");
8421  i_evtevent = PQfnumber(res, "evtevent");
8422  i_evtowner = PQfnumber(res, "evtowner");
8423  i_evttags = PQfnumber(res, "evttags");
8424  i_evtfname = PQfnumber(res, "evtfname");
8425  i_evtenabled = PQfnumber(res, "evtenabled");
8426 
8427  for (i = 0; i < ntups; i++)
8428  {
8429  evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
8430  evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8431  evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8432  AssignDumpId(&evtinfo[i].dobj);
8433  evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
8434  evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
8435  evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
8436  evtinfo[i].evtowner = getRoleName(PQgetvalue(res, i, i_evtowner));
8437  evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
8438  evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
8439  evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
8440 
8441  /* Decide whether we want to dump it */
8442  selectDumpableObject(&(evtinfo[i].dobj), fout);
8443  }
8444 
8445  PQclear(res);
8446 
8447  destroyPQExpBuffer(query);
8448 }
char * evtevent
Definition: pg_dump.h:456
char * evtfname
Definition: pg_dump.h:459
char evtenabled
Definition: pg_dump.h:460
char * evtname
Definition: pg_dump.h:455
const char * evtowner
Definition: pg_dump.h:457
char * evttags
Definition: pg_dump.h:458
DumpableObject dobj
Definition: pg_dump.h:454

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

Referenced by getSchemaData().

◆ getExtendedStatistics()

void getExtendedStatistics ( Archive fout)

Definition at line 7730 of file pg_dump.c.

7731 {
7732  PQExpBuffer query;
7733  PGresult *res;
7734  StatsExtInfo *statsextinfo;
7735  int ntups;
7736  int i_tableoid;
7737  int i_oid;
7738  int i_stxname;
7739  int i_stxnamespace;
7740  int i_stxowner;
7741  int i_stxrelid;
7742  int i_stattarget;
7743  int i;
7744 
7745  /* Extended statistics were new in v10 */
7746  if (fout->remoteVersion < 100000)
7747  return;
7748 
7749  query = createPQExpBuffer();
7750 
7751  if (fout->remoteVersion < 130000)
7752  appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
7753  "stxnamespace, stxowner, stxrelid, NULL AS stxstattarget "
7754  "FROM pg_catalog.pg_statistic_ext");
7755  else
7756  appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
7757  "stxnamespace, stxowner, stxrelid, stxstattarget "
7758  "FROM pg_catalog.pg_statistic_ext");
7759 
7760  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7761 
7762  ntups = PQntuples(res);
7763 
7764  i_tableoid = PQfnumber(res, "tableoid");
7765  i_oid = PQfnumber(res, "oid");
7766  i_stxname = PQfnumber(res, "stxname");
7767  i_stxnamespace = PQfnumber(res, "stxnamespace");
7768  i_stxowner = PQfnumber(res, "stxowner");
7769  i_stxrelid = PQfnumber(res, "stxrelid");
7770  i_stattarget = PQfnumber(res, "stxstattarget");
7771 
7772  statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
7773 
7774  for (i = 0; i < ntups; i++)
7775  {
7776  statsextinfo[i].dobj.objType = DO_STATSEXT;
7777  statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7778  statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7779  AssignDumpId(&statsextinfo[i].dobj);
7780  statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
7781  statsextinfo[i].dobj.namespace =
7782  findNamespace(atooid(PQgetvalue(res, i, i_stxnamespace)));
7783  statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
7784  statsextinfo[i].stattable =
7785  findTableByOid(atooid(PQgetvalue(res, i, i_stxrelid)));
7786  if (PQgetisnull(res, i, i_stattarget))
7787  statsextinfo[i].stattarget = -1;
7788  else
7789  statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
7790 
7791  /* Decide whether we want to dump it */
7792  selectDumpableStatisticsObject(&(statsextinfo[i]), fout);
7793  }
7794 
7795  PQclear(res);
7796  destroyPQExpBuffer(query);
7797 }
static void selectDumpableStatisticsObject(StatsExtInfo *sobj, Archive *fout)
Definition: pg_dump.c:2159
TableInfo * stattable
Definition: pg_dump.h:428
int stattarget
Definition: pg_dump.h:429
const char * rolname
Definition: pg_dump.h:427
DumpableObject dobj
Definition: pg_dump.h:426

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

Referenced by getSchemaData().

◆ getExtensionMembership()

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

Definition at line 18419 of file pg_dump.c.

18421 {
18422  PQExpBuffer query;
18423  PGresult *res;
18424  int ntups,
18425  i;
18426  int i_classid,
18427  i_objid,
18428  i_refobjid;
18429  ExtensionInfo *ext;
18430 
18431  /* Nothing to do if no extensions */
18432  if (numExtensions == 0)
18433  return;
18434 
18435  query = createPQExpBuffer();
18436 
18437  /* refclassid constraint is redundant but may speed the search */
18438  appendPQExpBufferStr(query, "SELECT "
18439  "classid, objid, refobjid "
18440  "FROM pg_depend "
18441  "WHERE refclassid = 'pg_extension'::regclass "
18442  "AND deptype = 'e' "
18443  "ORDER BY 3");
18444 
18445  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
18446 
18447  ntups = PQntuples(res);
18448 
18449  i_classid = PQfnumber(res, "classid");
18450  i_objid = PQfnumber(res, "objid");
18451  i_refobjid = PQfnumber(res, "refobjid");
18452 
18453  /*
18454  * Since we ordered the SELECT by referenced ID, we can expect that
18455  * multiple entries for the same extension will appear together; this
18456  * saves on searches.
18457  */
18458  ext = NULL;
18459 
18460  for (i = 0; i < ntups; i++)
18461  {
18462  CatalogId objId;
18463  Oid extId;
18464 
18465  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
18466  objId.oid = atooid(PQgetvalue(res, i, i_objid));
18467  extId = atooid(PQgetvalue(res, i, i_refobjid));
18468 
18469  if (ext == NULL ||
18470  ext->dobj.catId.oid != extId)
18471  ext = findExtensionByOid(extId);
18472 
18473  if (ext == NULL)
18474  {
18475  /* shouldn't happen */
18476  pg_log_warning("could not find referenced extension %u", extId);
18477  continue;
18478  }
18479 
18480  recordExtensionMembership(objId, ext);
18481  }
18482 
18483  PQclear(res);
18484 
18485  destroyPQExpBuffer(query);
18486 }
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition: common.c:1022
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:967
#define pg_log_warning(...)
Definition: pgfnames.c:24
DumpableObject dobj
Definition: pg_dump.h:181

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

5832 {
5833  DumpOptions *dopt = fout->dopt;
5834  PGresult *res;
5835  int ntups;
5836  int i;
5837  PQExpBuffer query;
5838  ExtensionInfo *extinfo = NULL;
5839  int i_tableoid;
5840  int i_oid;
5841  int i_extname;
5842  int i_nspname;
5843  int i_extrelocatable;
5844  int i_extversion;
5845  int i_extconfig;
5846  int i_extcondition;
5847 
5848  query = createPQExpBuffer();
5849 
5850  appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
5851  "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
5852  "FROM pg_extension x "
5853  "JOIN pg_namespace n ON n.oid = x.extnamespace");
5854 
5855  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5856 
5857  ntups = PQntuples(res);
5858  if (ntups == 0)
5859  goto cleanup;
5860 
5861  extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
5862 
5863  i_tableoid = PQfnumber(res, "tableoid");
5864  i_oid = PQfnumber(res, "oid");
5865  i_extname = PQfnumber(res, "extname");
5866  i_nspname = PQfnumber(res, "nspname");
5867  i_extrelocatable = PQfnumber(res, "extrelocatable");
5868  i_extversion = PQfnumber(res, "extversion");
5869  i_extconfig = PQfnumber(res, "extconfig");
5870  i_extcondition = PQfnumber(res, "extcondition");
5871 
5872  for (i = 0; i < ntups; i++)
5873  {
5874  extinfo[i].dobj.objType = DO_EXTENSION;
5875  extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5876  extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5877  AssignDumpId(&extinfo[i].dobj);
5878  extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
5879  extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
5880  extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
5881  extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
5882  extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
5883  extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
5884 
5885  /* Decide whether we want to dump it */
5886  selectDumpableExtension(&(extinfo[i]), dopt);
5887  }
5888 
5889 cleanup:
5890  PQclear(res);
5891  destroyPQExpBuffer(query);
5892 
5893  *numExtensions = ntups;
5894 
5895  return extinfo;
5896 }
static void cleanup(void)
Definition: bootstrap.c:691
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:2102
bool relocatable
Definition: pg_dump.h:182
char * extversion
Definition: pg_dump.h:184
char * extcondition
Definition: pg_dump.h:186
char * extconfig
Definition: pg_dump.h:185

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, cleanup(), 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()

void getForeignDataWrappers ( Archive fout)

Definition at line 9716 of file pg_dump.c.

9717 {
9718  PGresult *res;
9719  int ntups;
9720  int i;
9721  PQExpBuffer query;
9722  FdwInfo *fdwinfo;
9723  int i_tableoid;
9724  int i_oid;
9725  int i_fdwname;
9726  int i_fdwowner;
9727  int i_fdwhandler;
9728  int i_fdwvalidator;
9729  int i_fdwacl;
9730  int i_acldefault;
9731  int i_fdwoptions;
9732 
9733  query = createPQExpBuffer();
9734 
9735  appendPQExpBufferStr(query, "SELECT tableoid, oid, fdwname, "
9736  "fdwowner, "
9737  "fdwhandler::pg_catalog.regproc, "
9738  "fdwvalidator::pg_catalog.regproc, "
9739  "fdwacl, "
9740  "acldefault('F', fdwowner) AS acldefault, "
9741  "array_to_string(ARRAY("
9742  "SELECT quote_ident(option_name) || ' ' || "
9743  "quote_literal(option_value) "
9744  "FROM pg_options_to_table(fdwoptions) "
9745  "ORDER BY option_name"
9746  "), E',\n ') AS fdwoptions "
9747  "FROM pg_foreign_data_wrapper");
9748 
9749  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9750 
9751  ntups = PQntuples(res);
9752 
9753  fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
9754 
9755  i_tableoid = PQfnumber(res, "tableoid");
9756  i_oid = PQfnumber(res, "oid");
9757  i_fdwname = PQfnumber(res, "fdwname");
9758  i_fdwowner = PQfnumber(res, "fdwowner");
9759  i_fdwhandler = PQfnumber(res, "fdwhandler");
9760  i_fdwvalidator = PQfnumber(res, "fdwvalidator");
9761  i_fdwacl = PQfnumber(res, "fdwacl");
9762  i_acldefault = PQfnumber(res, "acldefault");
9763  i_fdwoptions = PQfnumber(res, "fdwoptions");
9764 
9765  for (i = 0; i < ntups; i++)
9766  {
9767  fdwinfo[i].dobj.objType = DO_FDW;
9768  fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9769  fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9770  AssignDumpId(&fdwinfo[i].dobj);
9771  fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
9772  fdwinfo[i].dobj.namespace = NULL;
9773  fdwinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
9774  fdwinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9775  fdwinfo[i].dacl.privtype = 0;
9776  fdwinfo[i].dacl.initprivs = NULL;
9777  fdwinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_fdwowner));
9778  fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
9779  fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
9780  fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
9781 
9782  /* Decide whether we want to dump it */
9783  selectDumpableObject(&(fdwinfo[i].dobj), fout);
9784 
9785  /* Mark whether FDW has an ACL */
9786  if (!PQgetisnull(res, i, i_fdwacl))
9787  fdwinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9788  }
9789 
9790  PQclear(res);
9791 
9792  destroyPQExpBuffer(query);
9793 }
char * fdwhandler
Definition: pg_dump.h:561
const char * rolname
Definition: pg_dump.h:560
char * fdwvalidator
Definition: pg_dump.h:562
char * fdwoptions
Definition: pg_dump.h:563
DumpableAcl dacl
Definition: pg_dump.h:559
DumpableObject dobj
Definition: pg_dump.h:558

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

Referenced by getSchemaData().

◆ getForeignServers()

void getForeignServers ( Archive fout)

Definition at line 9800 of file pg_dump.c.

9801 {
9802  PGresult *res;
9803  int ntups;
9804  int i;
9805  PQExpBuffer query;
9806  ForeignServerInfo *srvinfo;
9807  int i_tableoid;
9808  int i_oid;
9809  int i_srvname;
9810  int i_srvowner;
9811  int i_srvfdw;
9812  int i_srvtype;
9813  int i_srvversion;
9814  int i_srvacl;
9815  int i_acldefault;
9816  int i_srvoptions;
9817 
9818  query = createPQExpBuffer();
9819 
9820  appendPQExpBufferStr(query, "SELECT tableoid, oid, srvname, "
9821  "srvowner, "
9822  "srvfdw, srvtype, srvversion, srvacl, "
9823  "acldefault('S', srvowner) AS acldefault, "
9824  "array_to_string(ARRAY("
9825  "SELECT quote_ident(option_name) || ' ' || "
9826  "quote_literal(option_value) "
9827  "FROM pg_options_to_table(srvoptions) "
9828  "ORDER BY option_name"
9829  "), E',\n ') AS srvoptions "
9830  "FROM pg_foreign_server");
9831 
9832  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9833 
9834  ntups = PQntuples(res);
9835 
9836  srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
9837 
9838  i_tableoid = PQfnumber(res, "tableoid");
9839  i_oid = PQfnumber(res, "oid");
9840  i_srvname = PQfnumber(res, "srvname");
9841  i_srvowner = PQfnumber(res, "srvowner");
9842  i_srvfdw = PQfnumber(res, "srvfdw");
9843  i_srvtype = PQfnumber(res, "srvtype");
9844  i_srvversion = PQfnumber(res, "srvversion");
9845  i_srvacl = PQfnumber(res, "srvacl");
9846  i_acldefault = PQfnumber(res, "acldefault");
9847  i_srvoptions = PQfnumber(res, "srvoptions");
9848 
9849  for (i = 0; i < ntups; i++)
9850  {
9851  srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
9852  srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9853  srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9854  AssignDumpId(&srvinfo[i].dobj);
9855  srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
9856  srvinfo[i].dobj.namespace = NULL;
9857  srvinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_srvacl));
9858  srvinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9859  srvinfo[i].dacl.privtype = 0;
9860  srvinfo[i].dacl.initprivs = NULL;
9861  srvinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_srvowner));
9862  srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
9863  srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
9864  srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
9865  srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
9866 
9867  /* Decide whether we want to dump it */
9868  selectDumpableObject(&(srvinfo[i].dobj), fout);
9869 
9870  /* Servers have user mappings */
9872 
9873  /* Mark whether server has an ACL */
9874  if (!PQgetisnull(res, i, i_srvacl))
9875  srvinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9876  }
9877 
9878  PQclear(res);
9879 
9880  destroyPQExpBuffer(query);
9881 }
#define DUMP_COMPONENT_USERMAP
Definition: pg_dump.h:103
DumpableAcl dacl
Definition: pg_dump.h:569
char * srvoptions
Definition: pg_dump.h:574
DumpableObject dobj
Definition: pg_dump.h:568
const char * rolname
Definition: pg_dump.h:570
char * srvversion
Definition: pg_dump.h:573

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

Referenced by getSchemaData().

◆ getFuncs()

void getFuncs ( Archive fout)

Definition at line 6590 of file pg_dump.c.

6591 {
6592  DumpOptions *dopt = fout->dopt;
6593  PGresult *res;
6594  int ntups;
6595  int i;
6596  PQExpBuffer query = createPQExpBuffer();
6597  FuncInfo *finfo;
6598  int i_tableoid;
6599  int i_oid;
6600  int i_proname;
6601  int i_pronamespace;
6602  int i_proowner;
6603  int i_prolang;
6604  int i_pronargs;
6605  int i_proargtypes;
6606  int i_prorettype;
6607  int i_proacl;
6608  int i_acldefault;
6609 
6610  /*
6611  * Find all interesting functions. This is a bit complicated:
6612  *
6613  * 1. Always exclude aggregates; those are handled elsewhere.
6614  *
6615  * 2. Always exclude functions that are internally dependent on something
6616  * else, since presumably those will be created as a result of creating
6617  * the something else. This currently acts only to suppress constructor
6618  * functions for range types. Note this is OK only because the
6619  * constructors don't have any dependencies the range type doesn't have;
6620  * otherwise we might not get creation ordering correct.
6621  *
6622  * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
6623  * they're members of extensions and we are in binary-upgrade mode then
6624  * include them, since we want to dump extension members individually in
6625  * that mode. Also, if they are used by casts or transforms then we need
6626  * to gather the information about them, though they won't be dumped if
6627  * they are built-in. Also, in 9.6 and up, include functions in
6628  * pg_catalog if they have an ACL different from what's shown in
6629  * pg_init_privs (so we have to join to pg_init_privs; annoying).
6630  */
6631  if (fout->remoteVersion >= 90600)
6632  {
6633  const char *not_agg_check;
6634 
6635  not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
6636  : "NOT p.proisagg");
6637 
6638  appendPQExpBuffer(query,
6639  "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6640  "p.pronargs, p.proargtypes, p.prorettype, "
6641  "p.proacl, "
6642  "acldefault('f', p.proowner) AS acldefault, "
6643  "p.pronamespace, "
6644  "p.proowner "
6645  "FROM pg_proc p "
6646  "LEFT JOIN pg_init_privs pip ON "
6647  "(p.oid = pip.objoid "
6648  "AND pip.classoid = 'pg_proc'::regclass "
6649  "AND pip.objsubid = 0) "
6650  "WHERE %s"
6651  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6652  "WHERE classid = 'pg_proc'::regclass AND "
6653  "objid = p.oid AND deptype = 'i')"
6654  "\n AND ("
6655  "\n pronamespace != "
6656  "(SELECT oid FROM pg_namespace "
6657  "WHERE nspname = 'pg_catalog')"
6658  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6659  "\n WHERE pg_cast.oid > %u "
6660  "\n AND p.oid = pg_cast.castfunc)"
6661  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6662  "\n WHERE pg_transform.oid > %u AND "
6663  "\n (p.oid = pg_transform.trffromsql"
6664  "\n OR p.oid = pg_transform.trftosql))",
6665  not_agg_check,
6668  if (dopt->binary_upgrade)
6669  appendPQExpBufferStr(query,
6670  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6671  "classid = 'pg_proc'::regclass AND "
6672  "objid = p.oid AND "
6673  "refclassid = 'pg_extension'::regclass AND "
6674  "deptype = 'e')");
6675  appendPQExpBufferStr(query,
6676  "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
6677  appendPQExpBufferChar(query, ')');
6678  }
6679  else
6680  {
6681  appendPQExpBuffer(query,
6682  "SELECT tableoid, oid, proname, prolang, "
6683  "pronargs, proargtypes, prorettype, proacl, "
6684  "acldefault('f', proowner) AS acldefault, "
6685  "pronamespace, "
6686  "proowner "
6687  "FROM pg_proc p "
6688  "WHERE NOT proisagg"
6689  "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6690  "WHERE classid = 'pg_proc'::regclass AND "
6691  "objid = p.oid AND deptype = 'i')"
6692  "\n AND ("
6693  "\n pronamespace != "
6694  "(SELECT oid FROM pg_namespace "
6695  "WHERE nspname = 'pg_catalog')"
6696  "\n OR EXISTS (SELECT 1 FROM pg_cast"
6697  "\n WHERE pg_cast.oid > '%u'::oid"
6698  "\n AND p.oid = pg_cast.castfunc)",
6700 
6701  if (fout->remoteVersion >= 90500)
6702  appendPQExpBuffer(query,
6703  "\n OR EXISTS (SELECT 1 FROM pg_transform"
6704  "\n WHERE pg_transform.oid > '%u'::oid"
6705  "\n AND (p.oid = pg_transform.trffromsql"
6706  "\n OR p.oid = pg_transform.trftosql))",
6708 
6709  if (dopt->binary_upgrade)
6710  appendPQExpBufferStr(query,
6711  "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6712  "classid = 'pg_proc'::regclass AND "
6713  "objid = p.oid AND "
6714  "refclassid = 'pg_extension'::regclass AND "
6715  "deptype = 'e')");
6716  appendPQExpBufferChar(query, ')');
6717  }
6718 
6719  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6720 
6721  ntups = PQntuples(res);
6722 
6723  finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
6724 
6725  i_tableoid = PQfnumber(res, "tableoid");
6726  i_oid = PQfnumber(res, "oid");
6727  i_proname = PQfnumber(res, "proname");
6728  i_pronamespace = PQfnumber(res, "pronamespace");
6729  i_proowner = PQfnumber(res, "proowner");
6730  i_prolang = PQfnumber(res, "prolang");
6731  i_pronargs = PQfnumber(res, "pronargs");
6732  i_proargtypes = PQfnumber(res, "proargtypes");
6733  i_prorettype = PQfnumber(res, "prorettype");
6734  i_proacl = PQfnumber(res, "proacl");
6735  i_acldefault = PQfnumber(res, "acldefault");
6736 
6737  for (i = 0; i < ntups; i++)
6738  {
6739  finfo[i].dobj.objType = DO_FUNC;
6740  finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6741  finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6742  AssignDumpId(&finfo[i].dobj);
6743  finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
6744  finfo[i].dobj.namespace =
6745  findNamespace(atooid(PQgetvalue(res, i, i_pronamespace)));
6746  finfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_proacl));
6747  finfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6748  finfo[i].dacl.privtype = 0;
6749  finfo[i].dacl.initprivs = NULL;
6750  finfo[i].rolname = getRoleName(PQgetvalue(res, i, i_proowner));
6751  finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
6752  finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
6753  finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
6754  if (finfo[i].nargs == 0)
6755  finfo[i].argtypes = NULL;
6756  else
6757  {
6758  finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
6759  parseOidArray(PQgetvalue(res, i, i_proargtypes),
6760  finfo[i].argtypes, finfo[i].nargs);
6761  }
6762  finfo[i].postponed_def = false; /* might get set during sort */
6763 
6764  /* Decide whether we want to dump it */
6765  selectDumpableObject(&(finfo[i].dobj), fout);
6766 
6767  /* Mark whether function has an ACL */
6768  if (!PQgetisnull(res, i, i_proacl))
6769  finfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6770  }
6771 
6772  PQclear(res);
6773 
6774  destroyPQExpBuffer(query);
6775 }
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
static Oid g_last_builtin_oid
Definition: pg_dump.c:147
bool postponed_def
Definition: pg_dump.h:232
Oid lang
Definition: pg_dump.h:228
const char * rolname
Definition: pg_dump.h:227
Oid * argtypes
Definition: pg_dump.h:230
Oid prorettype
Definition: pg_dump.h:231
DumpableObject dobj
Definition: pg_dump.h:225
int nargs
Definition: pg_dump.h:229
DumpableAcl dacl
Definition: pg_dump.h:226

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, _funcInfo::postponed_def, 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 7410 of file pg_dump.c.

7411 {
7412  PQExpBuffer query = createPQExpBuffer();
7413  PQExpBuffer tbloids = createPQExpBuffer();
7414  PGresult *res;
7415  int ntups;
7416  int curtblindx;
7417  IndxInfo *indxinfo;
7418  int i_tableoid,
7419  i_oid,
7420  i_indrelid,
7421  i_indexname,
7422  i_parentidx,
7423  i_indexdef,
7424  i_indnkeyatts,
7425  i_indnatts,
7426  i_indkey,
7427  i_indisclustered,
7428  i_indisreplident,
7429  i_indnullsnotdistinct,
7430  i_contype,
7431  i_conname,
7432  i_condeferrable,
7433  i_condeferred,
7434  i_conperiod,
7435  i_contableoid,
7436  i_conoid,
7437  i_condef,
7438  i_tablespace,
7439  i_indreloptions,
7440  i_indstatcols,
7441  i_indstatvals;
7442 
7443  /*
7444  * We want to perform just one query against pg_index. However, we
7445  * mustn't try to select every row of the catalog and then sort it out on
7446  * the client side, because some of the server-side functions we need
7447  * would be unsafe to apply to tables we don't have lock on. Hence, we
7448  * build an array of the OIDs of tables we care about (and now have lock
7449  * on!), and use a WHERE clause to constrain which rows are selected.
7450  */
7451  appendPQExpBufferChar(tbloids, '{');
7452  for (int i = 0; i < numTables; i++)
7453  {
7454  TableInfo *tbinfo = &tblinfo[i];
7455 
7456  if (!tbinfo->hasindex)
7457  continue;
7458 
7459  /*
7460  * We can ignore indexes of uninteresting tables.
7461  */
7462  if (!tbinfo->interesting)
7463  continue;
7464 
7465  /* OK, we need info for this table */
7466  if (tbloids->len > 1) /* do we have more than the '{'? */
7467  appendPQExpBufferChar(tbloids, ',');
7468  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
7469  }
7470  appendPQExpBufferChar(tbloids, '}');
7471 
7472  appendPQExpBufferStr(query,
7473  "SELECT t.tableoid, t.oid, i.indrelid, "
7474  "t.relname AS indexname, "
7475  "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7476  "i.indkey, i.indisclustered, "
7477  "c.contype, c.conname, "
7478  "c.condeferrable, c.condeferred, "
7479  "c.tableoid AS contableoid, "
7480  "c.oid AS conoid, "
7481  "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7482  "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7483  "t.reloptions AS indreloptions, ");
7484 
7485 
7486  if (fout->remoteVersion >= 90400)
7487  appendPQExpBufferStr(query,
7488  "i.indisreplident, ");
7489  else
7490  appendPQExpBufferStr(query,
7491  "false AS indisreplident, ");
7492 
7493  if (fout->remoteVersion >= 110000)
7494  appendPQExpBufferStr(query,
7495  "inh.inhparent AS parentidx, "
7496  "i.indnkeyatts AS indnkeyatts, "
7497  "i.indnatts AS indnatts, "
7498  "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
7499  " FROM pg_catalog.pg_attribute "
7500  " WHERE attrelid = i.indexrelid AND "
7501  " attstattarget >= 0) AS indstatcols, "
7502  "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
7503  " FROM pg_catalog.pg_attribute "
7504  " WHERE attrelid = i.indexrelid AND "
7505  " attstattarget >= 0) AS indstatvals, ");
7506  else
7507  appendPQExpBufferStr(query,
7508  "0 AS parentidx, "
7509  "i.indnatts AS indnkeyatts, "
7510  "i.indnatts AS indnatts, "
7511  "'' AS indstatcols, "
7512  "'' AS indstatvals, ");
7513 
7514  if (fout->remoteVersion >= 150000)
7515  appendPQExpBufferStr(query,
7516  "i.indnullsnotdistinct, ");
7517  else
7518  appendPQExpBufferStr(query,
7519  "false AS indnullsnotdistinct, ");
7520 
7521  if (fout->remoteVersion >= 180000)
7522  appendPQExpBufferStr(query,
7523  "c.conperiod ");
7524  else
7525  appendPQExpBufferStr(query,
7526  "NULL AS conperiod ");
7527 
7528  /*
7529  * The point of the messy-looking outer join is to find a constraint that
7530  * is related by an internal dependency link to the index. If we find one,
7531  * create a CONSTRAINT entry linked to the INDEX entry. We assume an
7532  * index won't have more than one internal dependency.
7533  *
7534  * Note: the check on conrelid is redundant, but useful because that
7535  * column is indexed while conindid is not.
7536  */
7537  if (fout->remoteVersion >= 110000)
7538  {
7539  appendPQExpBuffer(query,
7540  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7541  "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7542  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7543  "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
7544  "LEFT JOIN pg_catalog.pg_constraint c "
7545  "ON (i.indrelid = c.conrelid AND "
7546  "i.indexrelid = c.conindid AND "
7547  "c.contype IN ('p','u','x')) "
7548  "LEFT JOIN pg_catalog.pg_inherits inh "
7549  "ON (inh.inhrelid = indexrelid) "
7550  "WHERE (i.indisvalid OR t2.relkind = 'p') "
7551  "AND i.indisready "
7552  "ORDER BY i.indrelid, indexname",
7553  tbloids->data);
7554  }
7555  else
7556  {
7557  /*
7558  * the test on indisready is necessary in 9.2, and harmless in
7559  * earlier/later versions
7560  */
7561  appendPQExpBuffer(query,
7562  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7563  "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7564  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7565  "LEFT JOIN pg_catalog.pg_constraint c "
7566  "ON (i.indrelid = c.conrelid AND "
7567  "i.indexrelid = c.conindid AND "
7568  "c.contype IN ('p','u','x')) "
7569  "WHERE i.indisvalid AND i.indisready "
7570  "ORDER BY i.indrelid, indexname",
7571  tbloids->data);
7572  }
7573 
7574  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7575 
7576  ntups = PQntuples(res);
7577 
7578  i_tableoid = PQfnumber(res, "tableoid");
7579  i_oid = PQfnumber(res, "oid");
7580  i_indrelid = PQfnumber(res, "indrelid");
7581  i_indexname = PQfnumber(res, "indexname");
7582  i_parentidx = PQfnumber(res, "parentidx");
7583  i_indexdef = PQfnumber(res, "indexdef");
7584  i_indnkeyatts = PQfnumber(res, "indnkeyatts");
7585  i_indnatts = PQfnumber(res, "indnatts");
7586  i_indkey = PQfnumber(res, "indkey");
7587  i_indisclustered = PQfnumber(res, "indisclustered");
7588  i_indisreplident = PQfnumber(res, "indisreplident");
7589  i_indnullsnotdistinct = PQfnumber(res, "indnullsnotdistinct");
7590  i_contype = PQfnumber(res, "contype");
7591  i_conname = PQfnumber(res, "conname");
7592  i_condeferrable = PQfnumber(res, "condeferrable");
7593  i_condeferred = PQfnumber(res, "condeferred");
7594  i_conperiod = PQfnumber(res, "conperiod");
7595  i_contableoid = PQfnumber(res, "contableoid");
7596  i_conoid = PQfnumber(res, "conoid");
7597  i_condef = PQfnumber(res, "condef");
7598  i_tablespace = PQfnumber(res, "tablespace");
7599  i_indreloptions = PQfnumber(res, "indreloptions");
7600  i_indstatcols = PQfnumber(res, "indstatcols");
7601  i_indstatvals = PQfnumber(res, "indstatvals");
7602 
7603  indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
7604 
7605  /*
7606  * Outer loop iterates once per table, not once per row. Incrementing of
7607  * j is handled by the inner loop.
7608  */
7609  curtblindx = -1;
7610  for (int j = 0; j < ntups;)
7611  {
7612  Oid indrelid = atooid(PQgetvalue(res, j, i_indrelid));
7613  TableInfo *tbinfo = NULL;
7614  int numinds;
7615 
7616  /* Count rows for this table */
7617  for (numinds = 1; numinds < ntups - j; numinds++)
7618  if (atooid(PQgetvalue(res, j + numinds, i_indrelid)) != indrelid)
7619  break;
7620 
7621  /*
7622  * Locate the associated TableInfo; we rely on tblinfo[] being in OID
7623  * order.
7624  */
7625  while (++curtblindx < numTables)
7626  {
7627  tbinfo = &tblinfo[curtblindx];
7628  if (tbinfo->dobj.catId.oid == indrelid)
7629  break;
7630  }
7631  if (curtblindx >= numTables)
7632  pg_fatal("unrecognized table OID %u", indrelid);
7633  /* cross-check that we only got requested tables */
7634  if (!tbinfo->hasindex ||
7635  !tbinfo->interesting)
7636  pg_fatal("unexpected index data for table \"%s\"",
7637  tbinfo->dobj.name);
7638 
7639  /* Save data for this table */
7640  tbinfo->indexes = indxinfo + j;
7641  tbinfo->numIndexes = numinds;
7642 
7643  for (int c = 0; c < numinds; c++, j++)
7644  {
7645  char contype;
7646 
7647  indxinfo[j].dobj.objType = DO_INDEX;
7648  indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
7649  indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
7650  AssignDumpId(&indxinfo[j].dobj);
7651  indxinfo[j].dobj.dump = tbinfo->dobj.dump;
7652  indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
7653  indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
7654  indxinfo[j].indextable = tbinfo;
7655  indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
7656  indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
7657  indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
7658  indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
7659  indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
7660  indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
7661  indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
7662  indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
7663  parseOidArray(PQgetvalue(res, j, i_indkey),
7664  indxinfo[j].indkeys, indxinfo[j].indnattrs);
7665  indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
7666  indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
7667  indxinfo[j].indnullsnotdistinct = (PQgetvalue(res, j, i_indnullsnotdistinct)[0] == 't');
7668  indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
7669  indxinfo[j].partattaches = (SimplePtrList)
7670  {
7671  NULL, NULL
7672  };
7673  contype = *(PQgetvalue(res, j, i_contype));
7674 
7675  if (contype == 'p' || contype == 'u' || contype == 'x')
7676  {
7677  /*
7678  * If we found a constraint matching the index, create an
7679  * entry for it.
7680  */
7681  ConstraintInfo *constrinfo;
7682 
7683  constrinfo = (ConstraintInfo *) pg_malloc(sizeof(ConstraintInfo));
7684  constrinfo->dobj.objType = DO_CONSTRAINT;
7685  constrinfo->dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
7686  constrinfo->dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
7687  AssignDumpId(&constrinfo->dobj);
7688  constrinfo->dobj.dump = tbinfo->dobj.dump;
7689  constrinfo->dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
7690  constrinfo->dobj.namespace = tbinfo->dobj.namespace;
7691  constrinfo->contable = tbinfo;
7692  constrinfo->condomain = NULL;
7693  constrinfo->contype = contype;
7694  if (contype == 'x')
7695  constrinfo->condef = pg_strdup(PQgetvalue(res, j, i_condef));
7696  else
7697  constrinfo->condef = NULL;
7698  constrinfo->confrelid = InvalidOid;
7699  constrinfo->conindex = indxinfo[j].dobj.dumpId;
7700  constrinfo->condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
7701  constrinfo->condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
7702  constrinfo->conperiod = *(PQgetvalue(res, j, i_conperiod)) == 't';
7703  constrinfo->conislocal = true;
7704  constrinfo->separate = true;
7705 
7706  indxinfo[j].indexconstraint = constrinfo->dobj.dumpId;
7707  }
7708  else
7709  {
7710  /* Plain secondary index */
7711  indxinfo[j].indexconstraint = 0;
7712  }
7713  }
7714  }
7715 
7716  PQclear(res);
7717 
7718  destroyPQExpBuffer(query);
7719  destroyPQExpBuffer(tbloids);
7720 }
char * c
struct SimplePtrList SimplePtrList
bool conperiod
Definition: pg_dump.h:482
bool indisreplident
Definition: pg_dump.h:408
int indnkeyattrs
Definition: pg_dump.h:403
char * indstatvals
Definition: pg_dump.h:402
char * indstatcols
Definition: pg_dump.h:401
int indnattrs
Definition: pg_dump.h:404
TableInfo * indextable
Definition: pg_dump.h:397
Oid parentidx
Definition: pg_dump.h:410
Oid * indkeys
Definition: pg_dump.h:405
char * indreloptions
Definition: pg_dump.h:400
DumpId indexconstraint
Definition: pg_dump.h:414
bool indisclustered
Definition: pg_dump.h:407
SimplePtrList partattaches
Definition: pg_dump.h:411
char * tablespace
Definition: pg_dump.h:399
bool indnullsnotdistinct
Definition: pg_dump.h:409
char * indexdef
Definition: pg_dump.h:398
bool interesting
Definition: pg_dump.h:320
bool hasindex
Definition: pg_dump.h:297

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _constraintInfo::condef, _constraintInfo::condeferrable, _constraintInfo::condeferred, _constraintInfo::condomain, _constraintInfo::confrelid, _constraintInfo::conindex, _constraintInfo::conislocal, _constraintInfo::conperiod, _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 7294 of file pg_dump.c.

7295 {
7296  PGresult *res;
7297  int ntups;
7298  int i;
7299  PQExpBuffer query = createPQExpBuffer();
7300  InhInfo *inhinfo;
7301 
7302  int i_inhrelid;
7303  int i_inhparent;
7304 
7305  /* find all the inheritance information */
7306  appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
7307 
7308  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7309 
7310  ntups = PQntuples(res);
7311 
7312  *numInherits = ntups;
7313 
7314  inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
7315 
7316  i_inhrelid = PQfnumber(res, "inhrelid");
7317  i_inhparent = PQfnumber(res, "inhparent");
7318 
7319  for (i = 0; i < ntups; i++)
7320  {
7321  inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
7322  inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
7323  }
7324 
7325  PQclear(res);
7326 
7327  destroyPQExpBuffer(query);
7328 
7329  return inhinfo;
7330 }
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 731 of file common.c.

732 {
733  return lastDumpId;
734 }

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

◆ getNamespaces()

void getNamespaces ( Archive fout)

Definition at line 5699 of file pg_dump.c.

5700 {
5701  PGresult *res;
5702  int ntups;
5703  int i;
5704  PQExpBuffer query;
5705  NamespaceInfo *nsinfo;
5706  int i_tableoid;
5707  int i_oid;
5708  int i_nspname;
5709  int i_nspowner;
5710  int i_nspacl;
5711  int i_acldefault;
5712 
5713  query = createPQExpBuffer();
5714 
5715  /*
5716  * we fetch all namespaces including system ones, so that every object we
5717  * read in can be linked to a containing namespace.
5718  */
5719  appendPQExpBufferStr(query, "SELECT n.tableoid, n.oid, n.nspname, "
5720  "n.nspowner, "
5721  "n.nspacl, "
5722  "acldefault('n', n.nspowner) AS acldefault "
5723  "FROM pg_namespace n");
5724 
5725  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5726 
5727  ntups = PQntuples(res);
5728 
5729  nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
5730 
5731  i_tableoid = PQfnumber(res, "tableoid");
5732  i_oid = PQfnumber(res, "oid");
5733  i_nspname = PQfnumber(res, "nspname");
5734  i_nspowner = PQfnumber(res, "nspowner");
5735  i_nspacl = PQfnumber(res, "nspacl");
5736  i_acldefault = PQfnumber(res, "acldefault");
5737 
5738  for (i = 0; i < ntups; i++)
5739  {
5740  const char *nspowner;
5741 
5742  nsinfo[i].dobj.objType = DO_NAMESPACE;
5743  nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5744  nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5745  AssignDumpId(&nsinfo[i].dobj);
5746  nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
5747  nsinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_nspacl));
5748  nsinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
5749  nsinfo[i].dacl.privtype = 0;
5750  nsinfo[i].dacl.initprivs = NULL;
5751  nspowner = PQgetvalue(res, i, i_nspowner);
5752  nsinfo[i].nspowner = atooid(nspowner);
5753  nsinfo[i].rolname = getRoleName(nspowner);
5754 
5755  /* Decide whether to dump this namespace */
5756  selectDumpableNamespace(&nsinfo[i], fout);
5757 
5758  /* Mark whether namespace has an ACL */
5759  if (!PQgetisnull(res, i, i_nspacl))
5760  nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
5761 
5762  /*
5763  * We ignore any pg_init_privs.initprivs entry for the public schema
5764  * and assume a predetermined default, for several reasons. First,
5765  * dropping and recreating the schema removes its pg_init_privs entry,
5766  * but an empty destination database starts with this ACL nonetheless.
5767  * Second, we support dump/reload of public schema ownership changes.
5768  * ALTER SCHEMA OWNER filters nspacl through aclnewowner(), but
5769  * initprivs continues to reflect the initial owner. Hence,
5770  * synthesize the value that nspacl will have after the restore's
5771  * ALTER SCHEMA OWNER. Third, this makes the destination database
5772  * match the source's ACL, even if the latter was an initdb-default
5773  * ACL, which changed in v15. An upgrade pulls in changes to most
5774  * system object ACLs that the DBA had not customized. We've made the
5775  * public schema depart from that, because changing its ACL so easily
5776  * breaks applications.
5777  */
5778  if (strcmp(nsinfo[i].dobj.name, "public") == 0)
5779  {
5780  PQExpBuffer aclarray = createPQExpBuffer();
5781  PQExpBuffer aclitem = createPQExpBuffer();
5782 
5783  /* Standard ACL as of v15 is {owner=UC/owner,=U/owner} */
5784  appendPQExpBufferChar(aclarray, '{');
5785  quoteAclUserName(aclitem, nsinfo[i].rolname);
5786  appendPQExpBufferStr(aclitem, "=UC/");
5787  quoteAclUserName(aclitem, nsinfo[i].rolname);
5788  appendPGArray(aclarray, aclitem->data);
5789  resetPQExpBuffer(aclitem);
5790  appendPQExpBufferStr(aclitem, "=U/");
5791  quoteAclUserName(aclitem, nsinfo[i].rolname);
5792  appendPGArray(aclarray, aclitem->data);
5793  appendPQExpBufferChar(aclarray, '}');
5794 
5795  nsinfo[i].dacl.privtype = 'i';
5796  nsinfo[i].dacl.initprivs = pstrdup(aclarray->data);
5797  nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
5798 
5799  destroyPQExpBuffer(aclarray);
5800  destroyPQExpBuffer(aclitem);
5801  }
5802  }
5803 
5804  PQclear(res);
5805  destroyPQExpBuffer(query);
5806 }
void quoteAclUserName(PQExpBuffer output, const char *input)
Definition: dumputils.c:544
char * pstrdup(const char *in)
Definition: mcxt.c:1696
NameData rolname
Definition: pg_authid.h:34
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1824
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:146
void appendPGArray(PQExpBuffer buffer, const char *value)
Definition: string_utils.c:740
DumpableObject dobj
Definition: pg_dump.h:172
DumpableAcl dacl
Definition: pg_dump.h:173
const char * rolname
Definition: pg_dump.h:176

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

Referenced by getSchemaData().

◆ getOpclasses()

void getOpclasses ( Archive fout)

Definition at line 6327 of file pg_dump.c.

6328 {
6329  PGresult *res;
6330  int ntups;
6331  int i;
6332  PQExpBuffer query = createPQExpBuffer();
6333  OpclassInfo *opcinfo;
6334  int i_tableoid;
6335  int i_oid;
6336  int i_opcname;
6337  int i_opcnamespace;
6338  int i_opcowner;
6339 
6340  /*
6341  * find all opclasses, including builtin opclasses; we filter out
6342  * system-defined opclasses at dump-out time.
6343  */
6344 
6345  appendPQExpBufferStr(query, "SELECT tableoid, oid, opcname, "
6346  "opcnamespace, "
6347  "opcowner "
6348  "FROM pg_opclass");
6349 
6350  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6351 
6352  ntups = PQntuples(res);
6353 
6354  opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
6355 
6356  i_tableoid = PQfnumber(res, "tableoid");
6357  i_oid = PQfnumber(res, "oid");
6358  i_opcname = PQfnumber(res, "opcname");
6359  i_opcnamespace = PQfnumber(res, "opcnamespace");
6360  i_opcowner = PQfnumber(res, "opcowner");
6361 
6362  for (i = 0; i < ntups; i++)
6363  {
6364  opcinfo[i].dobj.objType = DO_OPCLASS;
6365  opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6366  opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6367  AssignDumpId(&opcinfo[i].dobj);
6368  opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
6369  opcinfo[i].dobj.namespace =
6370  findNamespace(atooid(PQgetvalue(res, i, i_opcnamespace)));
6371  opcinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opcowner));
6372 
6373  /* Decide whether we want to dump it */
6374  selectDumpableObject(&(opcinfo[i].dobj), fout);
6375  }
6376 
6377  PQclear(res);
6378 
6379  destroyPQExpBuffer(query);
6380 }
DumpableObject dobj
Definition: pg_dump.h:259
const char * rolname
Definition: pg_dump.h:260

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

Referenced by getSchemaData().

◆ getOperators()

void getOperators ( Archive fout)

Definition at line 6073 of file pg_dump.c.

6074 {
6075  PGresult *res;
6076  int ntups;
6077  int i;
6078  PQExpBuffer query = createPQExpBuffer();
6079  OprInfo *oprinfo;
6080  int i_tableoid;
6081  int i_oid;
6082  int i_oprname;
6083  int i_oprnamespace;
6084  int i_oprowner;
6085  int i_oprkind;
6086  int i_oprcode;
6087 
6088  /*
6089  * find all operators, including builtin operators; we filter out
6090  * system-defined operators at dump-out time.
6091  */
6092 
6093  appendPQExpBufferStr(query, "SELECT tableoid, oid, oprname, "
6094  "oprnamespace, "
6095  "oprowner, "
6096  "oprkind, "
6097  "oprcode::oid AS oprcode "
6098  "FROM pg_operator");
6099 
6100  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6101 
6102  ntups = PQntuples(res);
6103 
6104  oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
6105 
6106  i_tableoid = PQfnumber(res, "tableoid");
6107  i_oid = PQfnumber(res, "oid");
6108  i_oprname = PQfnumber(res, "oprname");
6109  i_oprnamespace = PQfnumber(res, "oprnamespace");
6110  i_oprowner = PQfnumber(res, "oprowner");
6111  i_oprkind = PQfnumber(res, "oprkind");
6112  i_oprcode = PQfnumber(res, "oprcode");
6113 
6114  for (i = 0; i < ntups; i++)
6115  {
6116  oprinfo[i].dobj.objType = DO_OPERATOR;
6117  oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6118  oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6119  AssignDumpId(&oprinfo[i].dobj);
6120  oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
6121  oprinfo[i].dobj.namespace =
6122  findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)));
6123  oprinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_oprowner));
6124  oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
6125  oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
6126 
6127  /* Decide whether we want to dump it */
6128  selectDumpableObject(&(oprinfo[i].dobj), fout);
6129  }
6130 
6131  PQclear(res);
6132 
6133  destroyPQExpBuffer(query);
6134 }
DumpableObject dobj
Definition: pg_dump.h:244
char oprkind
Definition: pg_dump.h:246
Oid oprcode
Definition: pg_dump.h:247
const char * rolname
Definition: pg_dump.h:245

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

Referenced by getSchemaData().

◆ getOpfamilies()

void getOpfamilies ( Archive fout)

Definition at line 6387 of file pg_dump.c.

6388 {
6389  PGresult *res;
6390  int ntups;
6391  int i;
6392  PQExpBuffer query;
6393  OpfamilyInfo *opfinfo;
6394  int i_tableoid;
6395  int i_oid;
6396  int i_opfname;
6397  int i_opfnamespace;
6398  int i_opfowner;
6399 
6400  query = createPQExpBuffer();
6401 
6402  /*
6403  * find all opfamilies, including builtin opfamilies; we filter out
6404  * system-defined opfamilies at dump-out time.
6405  */
6406 
6407  appendPQExpBufferStr(query, "SELECT tableoid, oid, opfname, "
6408  "opfnamespace, "
6409  "opfowner "
6410  "FROM pg_opfamily");
6411 
6412  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6413 
6414  ntups = PQntuples(res);
6415 
6416  opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
6417 
6418  i_tableoid = PQfnumber(res, "tableoid");
6419  i_oid = PQfnumber(res, "oid");
6420  i_opfname = PQfnumber(res, "opfname");
6421  i_opfnamespace = PQfnumber(res, "opfnamespace");
6422  i_opfowner = PQfnumber(res, "opfowner");
6423 
6424  for (i = 0; i < ntups; i++)
6425  {
6426  opfinfo[i].dobj.objType = DO_OPFAMILY;
6427  opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6428  opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6429  AssignDumpId(&opfinfo[i].dobj);
6430  opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
6431  opfinfo[i].dobj.namespace =
6432  findNamespace(atooid(PQgetvalue(res, i, i_opfnamespace)));
6433  opfinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opfowner));
6434 
6435  /* Decide whether we want to dump it */
6436  selectDumpableObject(&(opfinfo[i].dobj), fout);
6437  }
6438 
6439  PQclear(res);
6440 
6441  destroyPQExpBuffer(query);
6442 }
const char * rolname
Definition: pg_dump.h:266
DumpableObject dobj
Definition: pg_dump.h:265

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

Referenced by getSchemaData().

◆ getOwnedSeqs()

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

Definition at line 7231 of file pg_dump.c.

7232 {
7233  int i;
7234 
7235  /*
7236  * Force sequences that are "owned" by table columns to be dumped whenever
7237  * their owning table is being dumped.
7238  */
7239  for (i = 0; i < numTables; i++)
7240  {
7241  TableInfo *seqinfo = &tblinfo[i];
7242  TableInfo *owning_tab;
7243 
7244  if (!OidIsValid(seqinfo->owning_tab))
7245  continue; /* not an owned sequence */
7246 
7247  owning_tab = findTableByOid(seqinfo->owning_tab);
7248  if (owning_tab == NULL)
7249  pg_fatal("failed sanity check, parent table with OID %u of sequence with OID %u not found",
7250  seqinfo->owning_tab, seqinfo->dobj.catId.oid);
7251 
7252  /*
7253  * Only dump identity sequences if we're going to dump the table that
7254  * it belongs to.
7255  */
7256  if (owning_tab->dobj.dump == DUMP_COMPONENT_NONE &&
7257  seqinfo->is_identity_sequence)
7258  {
7259  seqinfo->dobj.dump = DUMP_COMPONENT_NONE;
7260  continue;
7261  }
7262 
7263  /*
7264  * Otherwise we need to dump the components that are being dumped for
7265  * the table and any components which the sequence is explicitly
7266  * marked with.
7267  *
7268  * We can't simply use the set of components which are being dumped
7269  * for the table as the table might be in an extension (and only the
7270  * non-extension components, eg: ACLs if changed, security labels, and
7271  * policies, are being dumped) while the sequence is not (and
7272  * therefore the definition and other components should also be
7273  * dumped).
7274  *
7275  * If the sequence is part of the extension then it should be properly
7276  * marked by checkExtensionMembership() and this will be a no-op as
7277  * the table will be equivalently marked.
7278  */
7279  seqinfo->dobj.dump = seqinfo->dobj.dump | owning_tab->dobj.dump;
7280 
7281  if (seqinfo->dobj.dump != DUMP_COMPONENT_NONE)
7282  seqinfo->interesting = true;
7283  }
7284 }
#define DUMP_COMPONENT_NONE
Definition: pg_dump.h:96
bool is_identity_sequence
Definition: pg_dump.h:316
Oid owning_tab
Definition: pg_dump.h:314

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

Referenced by getSchemaData().

◆ getPartitioningInfo()

void getPartitioningInfo ( Archive fout)

Definition at line 7350 of file pg_dump.c.

7351 {
7352  PQExpBuffer query;
7353  PGresult *res;
7354  int ntups;
7355 
7356  /* hash partitioning didn't exist before v11 */
7357  if (fout->remoteVersion < 110000)
7358  return;
7359  /* needn't bother if schema-only dump */
7360  if (fout->dopt->schemaOnly)
7361  return;
7362 
7363  query = createPQExpBuffer();
7364 
7365  /*
7366  * Unsafe partitioning schemes are exactly those for which hash enum_ops
7367  * appears among the partition opclasses. We needn't check partstrat.
7368  *
7369  * Note that this query may well retrieve info about tables we aren't
7370  * going to dump and hence have no lock on. That's okay since we need not
7371  * invoke any unsafe server-side functions.
7372  */
7373  appendPQExpBufferStr(query,
7374  "SELECT partrelid FROM pg_partitioned_table WHERE\n"
7375  "(SELECT c.oid FROM pg_opclass c JOIN pg_am a "
7376  "ON c.opcmethod = a.oid\n"
7377  "WHERE opcname = 'enum_ops' "
7378  "AND opcnamespace = 'pg_catalog'::regnamespace "
7379  "AND amname = 'hash') = ANY(partclass)");
7380 
7381  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7382 
7383  ntups = PQntuples(res);
7384 
7385  for (int i = 0; i < ntups; i++)
7386  {
7387  Oid tabrelid = atooid(PQgetvalue(res, i, 0));
7388  TableInfo *tbinfo;
7389 
7390  tbinfo = findTableByOid(tabrelid);
7391  if (tbinfo == NULL)
7392  pg_fatal("failed sanity check, table OID %u appearing in pg_partitioned_table not found",
7393  tabrelid);
7394  tbinfo->unsafe_partitions = true;
7395  }
7396 
7397  PQclear(res);
7398 
7399  destroyPQExpBuffer(query);
7400 }
bool schemaOnly
Definition: pg_backup.h:170
bool unsafe_partitions
Definition: pg_dump.h:324

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

Referenced by getSchemaData().

◆ getPolicies()

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

Definition at line 3986 of file pg_dump.c.

3987 {
3988  PQExpBuffer query;
3989  PQExpBuffer tbloids;
3990  PGresult *res;
3991  PolicyInfo *polinfo;
3992  int i_oid;
3993  int i_tableoid;
3994  int i_polrelid;
3995  int i_polname;
3996  int i_polcmd;
3997  int i_polpermissive;
3998  int i_polroles;
3999  int i_polqual;
4000  int i_polwithcheck;
4001  int i,
4002  j,
4003  ntups;
4004 
4005  /* No policies before 9.5 */
4006  if (fout->remoteVersion < 90500)
4007  return;
4008 
4009  query = createPQExpBuffer();
4010  tbloids = createPQExpBuffer();
4011 
4012  /*
4013  * Identify tables of interest, and check which ones have RLS enabled.
4014  */
4015  appendPQExpBufferChar(tbloids, '{');
4016  for (i = 0; i < numTables; i++)
4017  {
4018  TableInfo *tbinfo = &tblinfo[i];
4019 
4020  /* Ignore row security on tables not to be dumped */
4021  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_POLICY))
4022  continue;
4023 
4024  /* It can't have RLS or policies if it's not a table */
4025  if (tbinfo->relkind != RELKIND_RELATION &&
4026  tbinfo->relkind != RELKIND_PARTITIONED_TABLE)
4027  continue;
4028 
4029  /* Add it to the list of table OIDs to be probed below */
4030  if (tbloids->len > 1) /* do we have more than the '{'? */
4031  appendPQExpBufferChar(tbloids, ',');
4032  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
4033 
4034  /* Is RLS enabled? (That's separate from whether it has policies) */
4035  if (tbinfo->rowsec)
4036  {
4038 
4039  /*
4040  * We represent RLS being enabled on a table by creating a
4041  * PolicyInfo object with null polname.
4042  *
4043  * Note: use tableoid 0 so that this object won't be mistaken for
4044  * something that pg_depend entries apply to.
4045  */
4046  polinfo = pg_malloc(sizeof(PolicyInfo));
4047  polinfo->dobj.objType = DO_POLICY;
4048  polinfo->dobj.catId.tableoid = 0;
4049  polinfo->dobj.catId.oid = tbinfo->dobj.catId.oid;
4050  AssignDumpId(&polinfo->dobj);
4051  polinfo->dobj.namespace = tbinfo->dobj.namespace;
4052  polinfo->dobj.name = pg_strdup(tbinfo->dobj.name);
4053  polinfo->poltable = tbinfo;
4054  polinfo->polname = NULL;
4055  polinfo->polcmd = '\0';
4056  polinfo->polpermissive = 0;
4057  polinfo->polroles = NULL;
4058  polinfo->polqual = NULL;
4059  polinfo->polwithcheck = NULL;
4060  }
4061  }
4062  appendPQExpBufferChar(tbloids, '}');
4063 
4064  /*
4065  * Now, read all RLS policies belonging to the tables of interest, and
4066  * create PolicyInfo objects for them. (Note that we must filter the
4067  * results server-side not locally, because we dare not apply pg_get_expr
4068  * to tables we don't have lock on.)
4069  */
4070  pg_log_info("reading row-level security policies");
4071 
4072  printfPQExpBuffer(query,
4073  "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
4074  if (fout->remoteVersion >= 100000)
4075  appendPQExpBufferStr(query, "pol.polpermissive, ");
4076  else
4077  appendPQExpBufferStr(query, "'t' as polpermissive, ");
4078  appendPQExpBuffer(query,
4079  "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
4080  " 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, "
4081  "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
4082  "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
4083  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
4084  "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
4085  tbloids->data);
4086 
4087  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4088 
4089  ntups = PQntuples(res);
4090  if (ntups > 0)
4091  {
4092  i_oid = PQfnumber(res, "oid");
4093  i_tableoid = PQfnumber(res, "tableoid");
4094  i_polrelid = PQfnumber(res, "polrelid");
4095  i_polname = PQfnumber(res, "polname");
4096  i_polcmd = PQfnumber(res, "polcmd");
4097  i_polpermissive = PQfnumber(res, "polpermissive");
4098  i_polroles = PQfnumber(res, "polroles");
4099  i_polqual = PQfnumber(res, "polqual");
4100  i_polwithcheck = PQfnumber(res, "polwithcheck");
4101 
4102  polinfo = pg_malloc(ntups * sizeof(PolicyInfo));
4103 
4104  for (j = 0; j < ntups; j++)
4105  {
4106  Oid polrelid = atooid(PQgetvalue(res, j, i_polrelid));
4107  TableInfo *tbinfo = findTableByOid(polrelid);
4108 
4110 
4111  polinfo[j].dobj.objType = DO_POLICY;
4112  polinfo[j].dobj.catId.tableoid =
4113  atooid(PQgetvalue(res, j, i_tableoid));
4114  polinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
4115  AssignDumpId(&polinfo[j].dobj);
4116  polinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4117  polinfo[j].poltable = tbinfo;
4118  polinfo[j].polname = pg_strdup(PQgetvalue(res, j, i_polname));
4119  polinfo[j].dobj.name = pg_strdup(polinfo[j].polname);
4120 
4121  polinfo[j].polcmd = *(PQgetvalue(res, j, i_polcmd));
4122  polinfo[j].polpermissive = *(PQgetvalue(res, j, i_polpermissive)) == 't';
4123 
4124  if (PQgetisnull(res, j, i_polroles))
4125  polinfo[j].polroles = NULL;
4126  else
4127  polinfo[j].polroles = pg_strdup(PQgetvalue(res, j, i_polroles));
4128 
4129  if (PQgetisnull(res, j, i_polqual))
4130  polinfo[j].polqual = NULL;
4131  else
4132  polinfo[j].polqual = pg_strdup(PQgetvalue(res, j, i_polqual));
4133 
4134  if (PQgetisnull(res, j, i_polwithcheck))
4135  polinfo[j].polwithcheck = NULL;
4136  else
4137  polinfo[j].polwithcheck
4138  = pg_strdup(PQgetvalue(res, j, i_polwithcheck));
4139  }
4140  }
4141 
4142  PQclear(res);
4143 
4144  destroyPQExpBuffer(query);
4145  destroyPQExpBuffer(tbloids);
4146 }
#define pg_log_info(...)
Definition: logging.h:124
#define DUMP_COMPONENT_POLICY
Definition: pg_dump.h:102
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:235
TableInfo * poltable
Definition: pg_dump.h:611
char * polqual
Definition: pg_dump.h:616
char polcmd
Definition: pg_dump.h:613
char * polroles
Definition: pg_dump.h:615
char * polwithcheck
Definition: pg_dump.h:617
DumpableObject dobj
Definition: pg_dump.h:610
bool polpermissive
Definition: pg_dump.h:614
char * polname
Definition: pg_dump.h:612
bool rowsec
Definition: pg_dump.h:301

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

Referenced by getSchemaData().

◆ getProcLangs()

void getProcLangs ( Archive fout)

Definition at line 8458 of file pg_dump.c.

8459 {
8460  PGresult *res;
8461  int ntups;
8462  int i;
8463  PQExpBuffer query = createPQExpBuffer();
8464  ProcLangInfo *planginfo;
8465  int i_tableoid;
8466  int i_oid;
8467  int i_lanname;
8468  int i_lanpltrusted;
8469  int i_lanplcallfoid;
8470  int i_laninline;
8471  int i_lanvalidator;
8472  int i_lanacl;
8473  int i_acldefault;
8474  int i_lanowner;
8475 
8476  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8477  "lanname, lanpltrusted, lanplcallfoid, "
8478  "laninline, lanvalidator, "
8479  "lanacl, "
8480  "acldefault('l', lanowner) AS acldefault, "
8481  "lanowner "
8482  "FROM pg_language "
8483  "WHERE lanispl "
8484  "ORDER BY oid");
8485 
8486  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8487 
8488  ntups = PQntuples(res);
8489 
8490  planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo));
8491 
8492  i_tableoid = PQfnumber(res, "tableoid");
8493  i_oid = PQfnumber(res, "oid");
8494  i_lanname = PQfnumber(res, "lanname");
8495  i_lanpltrusted = PQfnumber(res, "lanpltrusted");
8496  i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
8497  i_laninline = PQfnumber(res, "laninline");
8498  i_lanvalidator = PQfnumber(res, "lanvalidator");
8499  i_lanacl = PQfnumber(res, "lanacl");
8500  i_acldefault = PQfnumber(res, "acldefault");
8501  i_lanowner = PQfnumber(res, "lanowner");
8502 
8503  for (i = 0; i < ntups; i++)
8504  {
8505  planginfo[i].dobj.objType = DO_PROCLANG;
8506  planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8507  planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8508  AssignDumpId(&planginfo[i].dobj);
8509 
8510  planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
8511  planginfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_lanacl));
8512  planginfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
8513  planginfo[i].dacl.privtype = 0;
8514  planginfo[i].dacl.initprivs = NULL;
8515  planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
8516  planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
8517  planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
8518  planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
8519  planginfo[i].lanowner = getRoleName(PQgetvalue(res, i, i_lanowner));
8520 
8521  /* Decide whether we want to dump it */
8522  selectDumpableProcLang(&(planginfo[i]), fout);
8523 
8524  /* Mark whether language has an ACL */
8525  if (!PQgetisnull(res, i, i_lanacl))
8526  planginfo[i].dobj.components |= DUMP_COMPONENT_ACL;
8527  }
8528 
8529  PQclear(res);
8530 
8531  destroyPQExpBuffer(query);
8532 }
static void selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
Definition: pg_dump.c:2041
Oid lanvalidator
Definition: pg_dump.h:494
DumpableAcl dacl
Definition: pg_dump.h:490
DumpableObject dobj
Definition: pg_dump.h:489
Oid laninline
Definition: pg_dump.h:493
const char * lanowner
Definition: pg_dump.h:495
Oid lanplcallfoid
Definition: pg_dump.h:492
bool lanpltrusted
Definition: pg_dump.h:491

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

Referenced by getSchemaData().

◆ getPublicationNamespaces()

void getPublicationNamespaces ( Archive fout)

Definition at line 4477 of file pg_dump.c.

4478 {
4479  PQExpBuffer query;
4480  PGresult *res;
4481  PublicationSchemaInfo *pubsinfo;
4482  DumpOptions *dopt = fout->dopt;
4483  int i_tableoid;
4484  int i_oid;
4485  int i_pnpubid;
4486  int i_pnnspid;
4487  int i,
4488  j,
4489  ntups;
4490 
4491  if (dopt->no_publications || fout->remoteVersion < 150000)
4492  return;
4493 
4494  query = createPQExpBuffer();
4495 
4496  /* Collect all publication membership info. */
4497  appendPQExpBufferStr(query,
4498  "SELECT tableoid, oid, pnpubid, pnnspid "
4499  "FROM pg_catalog.pg_publication_namespace");
4500  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4501 
4502  ntups = PQntuples(res);
4503 
4504  i_tableoid = PQfnumber(res, "tableoid");
4505  i_oid = PQfnumber(res, "oid");
4506  i_pnpubid = PQfnumber(res, "pnpubid");
4507  i_pnnspid = PQfnumber(res, "pnnspid");
4508 
4509  /* this allocation may be more than we need */
4510  pubsinfo = pg_malloc(ntups * sizeof(PublicationSchemaInfo));
4511  j = 0;
4512 
4513  for (i = 0; i < ntups; i++)
4514  {
4515  Oid pnpubid = atooid(PQgetvalue(res, i, i_pnpubid));
4516  Oid pnnspid = atooid(PQgetvalue(res, i, i_pnnspid));
4517  PublicationInfo *pubinfo;
4518  NamespaceInfo *nspinfo;
4519 
4520  /*
4521  * Ignore any entries for which we aren't interested in either the
4522  * publication or the rel.
4523  */
4524  pubinfo = findPublicationByOid(pnpubid);
4525  if (pubinfo == NULL)
4526  continue;
4527  nspinfo = findNamespaceByOid(pnnspid);
4528  if (nspinfo == NULL)
4529  continue;
4530 
4531  /*
4532  * We always dump publication namespaces unless the corresponding
4533  * namespace is excluded from the dump.
4534  */
4535  if (nspinfo->dobj.dump == DUMP_COMPONENT_NONE)
4536  continue;
4537 
4538  /* OK, make a DumpableObject for this relationship */
4540  pubsinfo[j].dobj.catId.tableoid =
4541  atooid(PQgetvalue(res, i, i_tableoid));
4542  pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4543  AssignDumpId(&pubsinfo[j].dobj);
4544  pubsinfo[j].dobj.namespace = nspinfo->dobj.namespace;
4545  pubsinfo[j].dobj.name = nspinfo->dobj.name;
4546  pubsinfo[j].publication = pubinfo;
4547  pubsinfo[j].pubschema = nspinfo;
4548 
4549  /* Decide whether we want to dump it */
4550  selectDumpablePublicationObject(&(pubsinfo[j].dobj), fout);
4551 
4552  j++;
4553  }
4554 
4555  PQclear(res);
4556  destroyPQExpBuffer(query);
4557 }
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition: common.c:949
PublicationInfo * findPublicationByOid(Oid oid)
Definition: common.c:985
static void selectDumpablePublicationObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:2141
NamespaceInfo * pubschema
Definition: pg_dump.h:657
DumpableObject dobj
Definition: pg_dump.h:655
PublicationInfo * publication
Definition: pg_dump.h:656
int no_publications
Definition: pg_backup.h:183

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()

void getPublications ( Archive fout)

Definition at line 4271 of file pg_dump.c.

4272 {
4273  DumpOptions *dopt = fout->dopt;
4274  PQExpBuffer query;
4275  PGresult *res;
4276  PublicationInfo *pubinfo;
4277  int i_tableoid;
4278  int i_oid;
4279  int i_pubname;
4280  int i_pubowner;
4281  int i_puballtables;
4282  int i_pubinsert;
4283  int i_pubupdate;
4284  int i_pubdelete;
4285  int i_pubtruncate;
4286  int i_pubviaroot;
4287  int i_pubgencols;
4288  int i,
4289  ntups;
4290 
4291  if (dopt->no_publications || fout->remoteVersion < 100000)
4292  return;
4293 
4294  query = createPQExpBuffer();
4295 
4296  /* Get the publications. */
4297  appendPQExpBufferStr(query, "SELECT p.tableoid, p.oid, p.pubname, "
4298  "p.pubowner, p.puballtables, p.pubinsert, "
4299  "p.pubupdate, p.pubdelete, ");
4300 
4301  if (fout->remoteVersion >= 110000)
4302  appendPQExpBufferStr(query, "p.pubtruncate, ");
4303  else
4304  appendPQExpBufferStr(query, "false AS pubtruncate, ");
4305 
4306  if (fout->remoteVersion >= 130000)
4307  appendPQExpBufferStr(query, "p.pubviaroot, ");
4308  else
4309  appendPQExpBufferStr(query, "false AS pubviaroot, ");
4310 
4311  if (fout->remoteVersion >= 180000)
4312  appendPQExpBufferStr(query, "p.pubgencols ");
4313  else
4314  appendPQExpBufferStr(query, "false AS pubgencols ");
4315 
4316  appendPQExpBufferStr(query, "FROM pg_publication p");
4317 
4318  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4319 
4320  ntups = PQntuples(res);
4321 
4322  if (ntups == 0)
4323  goto cleanup;
4324 
4325  i_tableoid = PQfnumber(res, "tableoid");
4326  i_oid = PQfnumber(res, "oid");
4327  i_pubname = PQfnumber(res, "pubname");
4328  i_pubowner = PQfnumber(res, "pubowner");
4329  i_puballtables = PQfnumber(res, "puballtables");
4330  i_pubinsert = PQfnumber(res, "pubinsert");
4331  i_pubupdate = PQfnumber(res, "pubupdate");
4332  i_pubdelete = PQfnumber(res, "pubdelete");
4333  i_pubtruncate = PQfnumber(res, "pubtruncate");
4334  i_pubviaroot = PQfnumber(res, "pubviaroot");
4335  i_pubgencols = PQfnumber(res, "pubgencols");
4336 
4337  pubinfo = pg_malloc(ntups * sizeof(PublicationInfo));
4338 
4339  for (i = 0; i < ntups; i++)
4340  {
4341  pubinfo[i].dobj.objType = DO_PUBLICATION;
4342  pubinfo[i].dobj.catId.tableoid =
4343  atooid(PQgetvalue(res, i, i_tableoid));
4344  pubinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4345  AssignDumpId(&pubinfo[i].dobj);
4346  pubinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_pubname));
4347  pubinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_pubowner));
4348  pubinfo[i].puballtables =
4349  (strcmp(PQgetvalue(res, i, i_puballtables), "t") == 0);
4350  pubinfo[i].pubinsert =
4351  (strcmp(PQgetvalue(res, i, i_pubinsert), "t") == 0);
4352  pubinfo[i].pubupdate =
4353  (strcmp(PQgetvalue(res, i, i_pubupdate), "t") == 0);
4354  pubinfo[i].pubdelete =
4355  (strcmp(PQgetvalue(res, i, i_pubdelete), "t") == 0);
4356  pubinfo[i].pubtruncate =
4357  (strcmp(PQgetvalue(res, i, i_pubtruncate), "t") == 0);
4358  pubinfo[i].pubviaroot =
4359  (strcmp(PQgetvalue(res, i, i_pubviaroot), "t") == 0);
4360  pubinfo[i].pubgencols =
4361  (strcmp(PQgetvalue(res, i, i_pubgencols), "t") == 0);
4362 
4363  /* Decide whether we want to dump it */
4364  selectDumpableObject(&(pubinfo[i].dobj), fout);
4365  }
4366 
4367 cleanup:
4368  PQclear(res);
4369 
4370  destroyPQExpBuffer(query);
4371 }
const char * rolname
Definition: pg_dump.h:626
bool puballtables
Definition: pg_dump.h:627
bool pubtruncate
Definition: pg_dump.h:631
DumpableObject dobj
Definition: pg_dump.h:625

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, cleanup(), 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::pubgencols, _PublicationInfo::pubinsert, _PublicationInfo::pubtruncate, _PublicationInfo::pubupdate, _PublicationInfo::pubviaroot, Archive::remoteVersion, res, _PublicationInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getPublicationTables()

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

Definition at line 4564 of file pg_dump.c.

4565 {
4566  PQExpBuffer query;
4567  PGresult *res;
4568  PublicationRelInfo *pubrinfo;
4569  DumpOptions *dopt = fout->dopt;
4570  int i_tableoid;
4571  int i_oid;
4572  int i_prpubid;
4573  int i_prrelid;
4574  int i_prrelqual;
4575  int i_prattrs;
4576  int i,
4577  j,
4578  ntups;
4579 
4580  if (dopt->no_publications || fout->remoteVersion < 100000)
4581  return;
4582 
4583  query = createPQExpBuffer();
4584 
4585  /* Collect all publication membership info. */
4586  if (fout->remoteVersion >= 150000)
4587  appendPQExpBufferStr(query,
4588  "SELECT tableoid, oid, prpubid, prrelid, "
4589  "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4590  "(CASE\n"
4591  " WHEN pr.prattrs IS NOT NULL THEN\n"
4592  " (SELECT array_agg(attname)\n"
4593  " FROM\n"
4594  " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4595  " pg_catalog.pg_attribute\n"
4596  " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4597  " ELSE NULL END) prattrs "
4598  "FROM pg_catalog.pg_publication_rel pr");
4599  else
4600  appendPQExpBufferStr(query,
4601  "SELECT tableoid, oid, prpubid, prrelid, "
4602  "NULL AS prrelqual, NULL AS prattrs "
4603  "FROM pg_catalog.pg_publication_rel");
4604  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4605 
4606  ntups = PQntuples(res);
4607 
4608  i_tableoid = PQfnumber(res, "tableoid");
4609  i_oid = PQfnumber(res, "oid");
4610  i_prpubid = PQfnumber(res, "prpubid");
4611  i_prrelid = PQfnumber(res, "prrelid");
4612  i_prrelqual = PQfnumber(res, "prrelqual");
4613  i_prattrs = PQfnumber(res, "prattrs");
4614 
4615  /* this allocation may be more than we need */
4616  pubrinfo = pg_malloc(ntups * sizeof(PublicationRelInfo));
4617  j = 0;
4618 
4619  for (i = 0; i < ntups; i++)
4620  {
4621  Oid prpubid = atooid(PQgetvalue(res, i, i_prpubid));
4622  Oid prrelid = atooid(PQgetvalue(res, i, i_prrelid));
4623  PublicationInfo *pubinfo;
4624  TableInfo *tbinfo;
4625 
4626  /*
4627  * Ignore any entries for which we aren't interested in either the
4628  * publication or the rel.
4629  */
4630  pubinfo = findPublicationByOid(prpubid);
4631  if (pubinfo == NULL)
4632  continue;
4633  tbinfo = findTableByOid(prrelid);
4634  if (tbinfo == NULL)
4635  continue;
4636 
4637  /*
4638  * Ignore publication membership of tables whose definitions are not
4639  * to be dumped.
4640  */
4641  if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
4642  continue;
4643 
4644  /* OK, make a DumpableObject for this relationship */
4645  pubrinfo[j].dobj.objType = DO_PUBLICATION_REL;
4646  pubrinfo[j].dobj.catId.tableoid =
4647  atooid(PQgetvalue(res, i, i_tableoid));
4648  pubrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4649  AssignDumpId(&pubrinfo[j].dobj);
4650  pubrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4651  pubrinfo[j].dobj.name = tbinfo->dobj.name;
4652  pubrinfo[j].publication = pubinfo;
4653  pubrinfo[j].pubtable = tbinfo;
4654  if (PQgetisnull(res, i, i_prrelqual))
4655  pubrinfo[j].pubrelqual = NULL;
4656  else
4657  pubrinfo[j].pubrelqual = pg_strdup(PQgetvalue(res, i, i_prrelqual));
4658 
4659  if (!PQgetisnull(res, i, i_prattrs))
4660  {
4661  char **attnames;
4662  int nattnames;
4663  PQExpBuffer attribs;
4664 
4665  if (!parsePGArray(PQgetvalue(res, i, i_prattrs),
4666  &attnames, &nattnames))
4667  pg_fatal("could not parse %s array", "prattrs");
4668  attribs = createPQExpBuffer();
4669  for (int k = 0; k < nattnames; k++)
4670  {
4671  if (k > 0)
4672  appendPQExpBufferStr(attribs, ", ");
4673 
4674  appendPQExpBufferStr(attribs, fmtId(attnames[k]));
4675  }
4676  pubrinfo[j].pubrattrs = attribs->data;
4677  }
4678  else
4679  pubrinfo[j].pubrattrs = NULL;
4680 
4681  /* Decide whether we want to dump it */
4682  selectDumpablePublicationObject(&(pubrinfo[j].dobj), fout);
4683 
4684  j++;
4685  }
4686 
4687  PQclear(res);
4688  destroyPQExpBuffer(query);
4689 }
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()

void getRules ( Archive fout)

Definition at line 8087 of file pg_dump.c.

8088 {
8089  PGresult *res;
8090  int ntups;
8091  int i;
8092  PQExpBuffer query = createPQExpBuffer();
8093  RuleInfo *ruleinfo;
8094  int i_tableoid;
8095  int i_oid;
8096  int i_rulename;
8097  int i_ruletable;
8098  int i_ev_type;
8099  int i_is_instead;
8100  int i_ev_enabled;
8101 
8102  appendPQExpBufferStr(query, "SELECT "
8103  "tableoid, oid, rulename, "
8104  "ev_class AS ruletable, ev_type, is_instead, "
8105  "ev_enabled "
8106  "FROM pg_rewrite "
8107  "ORDER BY oid");
8108 
8109  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8110 
8111  ntups = PQntuples(res);
8112 
8113  ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo));
8114 
8115  i_tableoid = PQfnumber(res, "tableoid");
8116  i_oid = PQfnumber(res, "oid");
8117  i_rulename = PQfnumber(res, "rulename");
8118  i_ruletable = PQfnumber(res, "ruletable");
8119  i_ev_type = PQfnumber(res, "ev_type");
8120  i_is_instead = PQfnumber(res, "is_instead");
8121  i_ev_enabled = PQfnumber(res, "ev_enabled");
8122 
8123  for (i = 0; i < ntups; i++)
8124  {
8125  Oid ruletableoid;
8126 
8127  ruleinfo[i].dobj.objType = DO_RULE;
8128  ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8129  ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8130  AssignDumpId(&ruleinfo[i].dobj);
8131  ruleinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_rulename));
8132  ruletableoid = atooid(PQgetvalue(res, i, i_ruletable));
8133  ruleinfo[i].ruletable = findTableByOid(ruletableoid);
8134  if (ruleinfo[i].ruletable == NULL)
8135  pg_fatal("failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
8136  ruletableoid, ruleinfo[i].dobj.catId.oid);
8137  ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace;
8138  ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump;
8139  ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type));
8140  ruleinfo[i].is_instead = *(PQgetvalue(res, i, i_is_instead)) == 't';
8141  ruleinfo[i].ev_enabled = *(PQgetvalue(res, i, i_ev_enabled));
8142  if (ruleinfo[i].ruletable)
8143  {
8144  /*
8145  * If the table is a view or materialized view, force its ON
8146  * SELECT rule to be sorted before the view itself --- this
8147  * ensures that any dependencies for the rule affect the table's
8148  * positioning. Other rules are forced to appear after their
8149  * table.
8150  */
8151  if ((ruleinfo[i].ruletable->relkind == RELKIND_VIEW ||
8152  ruleinfo[i].ruletable->relkind == RELKIND_MATVIEW) &&
8153  ruleinfo[i].ev_type == '1' && ruleinfo[i].is_instead)
8154  {
8155  addObjectDependency(&ruleinfo[i].ruletable->dobj,
8156  ruleinfo[i].dobj.dumpId);
8157  /* We'll merge the rule into CREATE VIEW, if possible */
8158  ruleinfo[i].separate = false;
8159  }
8160  else
8161  {
8162  addObjectDependency(&ruleinfo[i].dobj,
8163  ruleinfo[i].ruletable->dobj.dumpId);
8164  ruleinfo[i].separate = true;
8165  }
8166  }
8167  else
8168  ruleinfo[i].separate = true;
8169  }
8170 
8171  PQclear(res);
8172 
8173  destroyPQExpBuffer(query);
8174 }
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:795
DumpableObject dobj
Definition: pg_dump.h:434
bool separate
Definition: pg_dump.h:439
char ev_enabled
Definition: pg_dump.h:438
bool is_instead
Definition: pg_dump.h:437
TableInfo * ruletable
Definition: pg_dump.h:435
char ev_type
Definition: pg_dump.h:436

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 numExtensions;
104  int numInherits;
105 
106  /*
107  * We must read extensions and extension membership info first, because
108  * extension membership needs to be consultable during decisions about
109  * whether other objects are to be dumped.
110  */
111  pg_log_info("reading extensions");
112  extinfo = getExtensions(fout, &numExtensions);
113 
114  pg_log_info("identifying extension members");
115  getExtensionMembership(fout, extinfo, numExtensions);
116 
117  pg_log_info("reading schemas");
118  getNamespaces(fout);
119 
120  /*
121  * getTables should be done as soon as possible, so as to minimize the
122  * window between starting our transaction and acquiring per-table locks.
123  * However, we have to do getNamespaces first because the tables get
124  * linked to their containing namespaces during getTables.
125  */
126  pg_log_info("reading user-defined tables");
127  tblinfo = getTables(fout, &numTables);
128 
129  getOwnedSeqs(fout, tblinfo, numTables);
130 
131  pg_log_info("reading user-defined functions");
132  getFuncs(fout);
133 
134  /* this must be after getTables and getFuncs */
135  pg_log_info("reading user-defined types");
136  getTypes(fout);
137 
138  /* this must be after getFuncs, too */
139  pg_log_info("reading procedural languages");
140  getProcLangs(fout);
141 
142  pg_log_info("reading user-defined aggregate functions");
143  getAggregates(fout);
144 
145  pg_log_info("reading user-defined operators");
146  getOperators(fout);
147 
148  pg_log_info("reading user-defined access methods");
149  getAccessMethods(fout);
150 
151  pg_log_info("reading user-defined operator classes");
152  getOpclasses(fout);
153 
154  pg_log_info("reading user-defined operator families");
155  getOpfamilies(fout);
156 
157  pg_log_info("reading user-defined text search parsers");
158  getTSParsers(fout);
159 
160  pg_log_info("reading user-defined text search templates");
161  getTSTemplates(fout);
162 
163  pg_log_info("reading user-defined text search dictionaries");
164  getTSDictionaries(fout);
165 
166  pg_log_info("reading user-defined text search configurations");
167  getTSConfigurations(fout);
168 
169  pg_log_info("reading user-defined foreign-data wrappers");
171 
172  pg_log_info("reading user-defined foreign servers");
173  getForeignServers(fout);
174 
175  pg_log_info("reading default privileges");
176  getDefaultACLs(fout);
177 
178  pg_log_info("reading user-defined collations");
179  getCollations(fout);
180 
181  pg_log_info("reading user-defined conversions");
182  getConversions(fout);
183 
184  pg_log_info("reading type casts");
185  getCasts(fout);
186 
187  pg_log_info("reading transforms");
188  getTransforms(fout);
189 
190  pg_log_info("reading table inheritance information");
191  inhinfo = getInherits(fout, &numInherits);
192 
193  pg_log_info("reading event triggers");
194  getEventTriggers(fout);
195 
196  /* Identify extension configuration tables that should be dumped */
197  pg_log_info("finding extension tables");
198  processExtensionTables(fout, extinfo, numExtensions);
199 
200  /* Link tables to parents, mark parents of target tables interesting */
201  pg_log_info("finding inheritance relationships");
202  flagInhTables(fout, tblinfo, numTables, inhinfo, numInherits);
203 
204  pg_log_info("reading column info for interesting tables");
205  getTableAttrs(fout, tblinfo, numTables);
206 
207  pg_log_info("flagging inherited columns in subtables");
208  flagInhAttrs(fout, fout->dopt, tblinfo, numTables);
209 
210  pg_log_info("reading partitioning data");
211  getPartitioningInfo(fout);
212 
213  pg_log_info("reading indexes");
214  getIndexes(fout, tblinfo, numTables);
215 
216  pg_log_info("flagging indexes in partitioned tables");
217  flagInhIndexes(fout, tblinfo, numTables);
218 
219  pg_log_info("reading extended statistics");
220  getExtendedStatistics(fout);
221 
222  pg_log_info("reading constraints");
223  getConstraints(fout, tblinfo, numTables);
224 
225  pg_log_info("reading triggers");
226  getTriggers(fout, tblinfo, numTables);
227 
228  pg_log_info("reading rewrite rules");
229  getRules(fout);
230 
231  pg_log_info("reading policies");
232  getPolicies(fout, tblinfo, numTables);
233 
234  pg_log_info("reading publications");
235  getPublications(fout);
236 
237  pg_log_info("reading publication membership of tables");
238  getPublicationTables(fout, tblinfo, numTables);
239 
240  pg_log_info("reading publication membership of schemas");
242 
243  pg_log_info("reading subscriptions");
244  getSubscriptions(fout);
245 
246  pg_log_info("reading subscription membership of tables");
247  getSubscriptionTables(fout);
248 
249  free(inhinfo); /* not needed any longer */
250 
251  *numTablesPtr = numTables;
252  return tblinfo;
253 }
static void flagInhAttrs(Archive *fout, DumpOptions *dopt, TableInfo *tblinfo, int numTables)
Definition: common.c:477
static void flagInhTables(Archive *fout, TableInfo *tblinfo, int numTables, InhInfo *inhinfo, int numInherits)
Definition: common.c:268
static void flagInhIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
#define free(a)
Definition: header.h:65
void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:7809
void getPublicationNamespaces(Archive *fout)
Definition: pg_dump.c:4477
void getPartitioningInfo(Archive *fout)
Definition: pg_dump.c:7350
void getForeignDataWrappers(Archive *fout)
Definition: pg_dump.c:9716
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:3986
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition: pg_dump.c:18419
void getTypes(Archive *fout)
Definition: pg_dump.c:5906
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:7231
void getOpclasses(Archive *fout)
Definition: pg_dump.c:6327
void getForeignServers(Archive *fout)
Definition: pg_dump.c:9800
void getFuncs(Archive *fout)
Definition: pg_dump.c:6590
void getTSDictionaries(Archive *fout)
Definition: pg_dump.c:9532
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:4564
void getCasts(Archive *fout)
Definition: pg_dump.c:8542
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:7410
void getTSConfigurations(Archive *fout)
Definition: pg_dump.c:9657
void getAccessMethods(Archive *fout)
Definition: pg_dump.c:6265
void getConversions(Archive *fout)
Definition: pg_dump.c:6203
void getRules(Archive *fout)
Definition: pg_dump.c:8087
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition: pg_dump.c:7294
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition: pg_dump.c:8736
void getSubscriptionTables(Archive *fout)
Definition: pg_dump.c:5040
void getCollations(Archive *fout)
Definition: pg_dump.c:6141
void getAggregates(Archive *fout)
Definition: pg_dump.c:6449
void getNamespaces(Archive *fout)
Definition: pg_dump.c:5699
void getPublications(Archive *fout)
Definition: pg_dump.c:4271
void getTSParsers(Archive *fout)
Definition: pg_dump.c:9458
void getExtendedStatistics(Archive *fout)
Definition: pg_dump.c:7730
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition: pg_dump.c:18512
void getDefaultACLs(Archive *fout)
Definition: pg_dump.c:9888
void getSubscriptions(Archive *fout)
Definition: pg_dump.c:4840
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition: pg_dump.c:5831
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:8184
void getTransforms(Archive *fout)
Definition: pg_dump.c:8652
void getEventTriggers(Archive *fout)
Definition: pg_dump.c:8380
TableInfo * getTables(Archive *fout, int *numTables)
Definition: pg_dump.c:6785
void getTSTemplates(Archive *fout)
Definition: pg_dump.c:9598
void getProcLangs(Archive *fout)
Definition: pg_dump.c:8458
void getOperators(Archive *fout)
Definition: pg_dump.c:6073
void getOpfamilies(Archive *fout)
Definition: pg_dump.c:6387

References Archive::dopt, flagInhAttrs(), flagInhIndexes(), flagInhTables(), free, getAccessMethods(), getAggregates(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getEventTriggers(), getExtendedStatistics(), getExtensionMembership(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), getInherits(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getOwnedSeqs(), getPartitioningInfo(), getPolicies(), getProcLangs(), getPublicationNamespaces(), getPublications(), getPublicationTables(), getRules(), getSubscriptions(), getSubscriptionTables(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), pg_log_info, and processExtensionTables().

Referenced by main().

◆ getSubscriptions()

void getSubscriptions ( Archive fout)

Definition at line 4840 of file pg_dump.c.

4841 {
4842  DumpOptions *dopt = fout->dopt;
4843  PQExpBuffer query;
4844  PGresult *res;
4845  SubscriptionInfo *subinfo;
4846  int i_tableoid;
4847  int i_oid;
4848  int i_subname;
4849  int i_subowner;
4850  int i_subbinary;
4851  int i_substream;
4852  int i_subtwophasestate;
4853  int i_subdisableonerr;
4854  int i_subpasswordrequired;
4855  int i_subrunasowner;
4856  int i_subconninfo;
4857  int i_subslotname;
4858  int i_subsynccommit;
4859  int i_subpublications;
4860  int i_suborigin;
4861  int i_suboriginremotelsn;
4862  int i_subenabled;
4863  int i_subfailover;
4864  int i,
4865  ntups;
4866 
4867  if (dopt->no_subscriptions || fout->remoteVersion < 100000)
4868  return;
4869 
4870  if (!is_superuser(fout))
4871  {
4872  int n;
4873 
4874  res = ExecuteSqlQuery(fout,
4875  "SELECT count(*) FROM pg_subscription "
4876  "WHERE subdbid = (SELECT oid FROM pg_database"
4877  " WHERE datname = current_database())",
4878  PGRES_TUPLES_OK);
4879  n = atoi(PQgetvalue(res, 0, 0));
4880  if (n > 0)
4881  pg_log_warning("subscriptions not dumped because current user is not a superuser");
4882  PQclear(res);
4883  return;
4884  }
4885 
4886  query = createPQExpBuffer();
4887 
4888  /* Get the subscriptions in current database. */
4889  appendPQExpBufferStr(query,
4890  "SELECT s.tableoid, s.oid, s.subname,\n"
4891  " s.subowner,\n"
4892  " s.subconninfo, s.subslotname, s.subsynccommit,\n"
4893  " s.subpublications,\n");
4894 
4895  if (fout->remoteVersion >= 140000)
4896  appendPQExpBufferStr(query, " s.subbinary,\n");
4897  else
4898  appendPQExpBufferStr(query, " false AS subbinary,\n");
4899 
4900  if (fout->remoteVersion >= 140000)
4901  appendPQExpBufferStr(query, " s.substream,\n");
4902  else
4903  appendPQExpBufferStr(query, " 'f' AS substream,\n");
4904 
4905  if (fout->remoteVersion >= 150000)
4906  appendPQExpBufferStr(query,
4907  " s.subtwophasestate,\n"
4908  " s.subdisableonerr,\n");
4909  else
4910  appendPQExpBuffer(query,
4911  " '%c' AS subtwophasestate,\n"
4912  " false AS subdisableonerr,\n",
4914 
4915  if (fout->remoteVersion >= 160000)
4916  appendPQExpBufferStr(query,
4917  " s.subpasswordrequired,\n"
4918  " s.subrunasowner,\n"
4919  " s.suborigin,\n");
4920  else
4921  appendPQExpBuffer(query,
4922  " 't' AS subpasswordrequired,\n"
4923  " 't' AS subrunasowner,\n"
4924  " '%s' AS suborigin,\n",
4926 
4927  if (dopt->binary_upgrade && fout->remoteVersion >= 170000)
4928  appendPQExpBufferStr(query, " o.remote_lsn AS suboriginremotelsn,\n"
4929  " s.subenabled,\n");
4930  else
4931  appendPQExpBufferStr(query, " NULL AS suboriginremotelsn,\n"
4932  " false AS subenabled,\n");
4933 
4934  if (fout->remoteVersion >= 170000)
4935  appendPQExpBufferStr(query,
4936  " s.subfailover\n");
4937  else
4938  appendPQExpBuffer(query,
4939  " false AS subfailover\n");
4940 
4941  appendPQExpBufferStr(query,
4942  "FROM pg_subscription s\n");
4943 
4944  if (dopt->binary_upgrade && fout->remoteVersion >= 170000)
4945  appendPQExpBufferStr(query,
4946  "LEFT JOIN pg_catalog.pg_replication_origin_status o \n"
4947  " ON o.external_id = 'pg_' || s.oid::text \n");
4948 
4949  appendPQExpBufferStr(query,
4950  "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
4951  " WHERE datname = current_database())");
4952 
4953  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4954 
4955  ntups = PQntuples(res);
4956 
4957  /*
4958  * Get subscription fields. We don't include subskiplsn in the dump as
4959  * after restoring the dump this value may no longer be relevant.
4960  */
4961  i_tableoid = PQfnumber(res, "tableoid");
4962  i_oid = PQfnumber(res, "oid");
4963  i_subname = PQfnumber(res, "subname");
4964  i_subowner = PQfnumber(res, "subowner");
4965  i_subbinary = PQfnumber(res, "subbinary");
4966  i_substream = PQfnumber(res, "substream");
4967  i_subtwophasestate = PQfnumber(res, "subtwophasestate");
4968  i_subdisableonerr = PQfnumber(res, "subdisableonerr");
4969  i_subpasswordrequired = PQfnumber(res, "subpasswordrequired");
4970  i_subrunasowner = PQfnumber(res, "subrunasowner");
4971  i_subconninfo = PQfnumber(res, "subconninfo");
4972  i_subslotname = PQfnumber(res, "subslotname");
4973  i_subsynccommit = PQfnumber(res, "subsynccommit");
4974  i_subpublications = PQfnumber(res, "subpublications");
4975  i_suborigin = PQfnumber(res, "suborigin");
4976  i_suboriginremotelsn = PQfnumber(res, "suboriginremotelsn");
4977  i_subenabled = PQfnumber(res, "subenabled");
4978  i_subfailover = PQfnumber(res, "subfailover");
4979 
4980  subinfo = pg_malloc(ntups * sizeof(SubscriptionInfo));
4981 
4982  for (i = 0; i < ntups; i++)
4983  {
4984  subinfo[i].dobj.objType = DO_SUBSCRIPTION;
4985  subinfo[i].dobj.catId.tableoid =
4986  atooid(PQgetvalue(res, i, i_tableoid));
4987  subinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4988  AssignDumpId(&subinfo[i].dobj);
4989  subinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_subname));
4990  subinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_subowner));
4991 
4992  subinfo[i].subbinary =
4993  pg_strdup(PQgetvalue(res, i, i_subbinary));
4994  subinfo[i].substream =
4995  pg_strdup(PQgetvalue(res, i, i_substream));
4996  subinfo[i].subtwophasestate =
4997  pg_strdup(PQgetvalue(res, i, i_subtwophasestate));
4998  subinfo[i].subdisableonerr =
4999  pg_strdup(PQgetvalue(res, i, i_subdisableonerr));
5000  subinfo[i].subpasswordrequired =
5001  pg_strdup(PQgetvalue(res, i, i_subpasswordrequired));
5002  subinfo[i].subrunasowner =
5003  pg_strdup(PQgetvalue(res, i, i_subrunasowner));
5004  subinfo[i].subconninfo =
5005  pg_strdup(PQgetvalue(res, i, i_subconninfo));
5006  if (PQgetisnull(res, i, i_subslotname))
5007  subinfo[i].subslotname = NULL;
5008  else
5009  subinfo[i].subslotname =
5010  pg_strdup(PQgetvalue(res, i, i_subslotname));
5011  subinfo[i].subsynccommit =
5012  pg_strdup(PQgetvalue(res, i, i_subsynccommit));
5013  subinfo[i].subpublications =
5014  pg_strdup(PQgetvalue(res, i, i_subpublications));
5015  subinfo[i].suborigin = pg_strdup(PQgetvalue(res, i, i_suborigin));
5016  if (PQgetisnull(res, i, i_suboriginremotelsn))
5017  subinfo[i].suboriginremotelsn = NULL;
5018  else
5019  subinfo[i].suboriginremotelsn =
5020  pg_strdup(PQgetvalue(res, i, i_suboriginremotelsn));
5021  subinfo[i].subenabled =
5022  pg_strdup(PQgetvalue(res, i, i_subenabled));
5023  subinfo[i].subfailover =
5024  pg_strdup(PQgetvalue(res, i, i_subfailover));
5025 
5026  /* Decide whether we want to dump it */
5027  selectDumpableObject(&(subinfo[i].dobj), fout);
5028  }
5029  PQclear(res);
5030 
5031  destroyPQExpBuffer(query);
5032 }
static bool is_superuser(Archive *fout)
Definition: pg_dump.c:4800
#define LOGICALREP_ORIGIN_ANY
#define LOGICALREP_TWOPHASE_STATE_DISABLED
char * suboriginremotelsn
Definition: pg_dump.h:679
char * suborigin
Definition: pg_dump.h:678
char * subbinary
Definition: pg_dump.h:668
const char * rolname
Definition: pg_dump.h:666
char * subrunasowner
Definition: pg_dump.h:673
char * subsynccommit
Definition: pg_dump.h:676
char * subpublications
Definition: pg_dump.h:677
char * subtwophasestate
Definition: pg_dump.h:670
char * subfailover
Definition: pg_dump.h:680
char * subenabled
Definition: pg_dump.h:667
char * substream
Definition: pg_dump.h:669
char * subpasswordrequired
Definition: pg_dump.h:672
char * subslotname
Definition: pg_dump.h:675
char * subdisableonerr
Definition: pg_dump.h:671
char * subconninfo
Definition: pg_dump.h:674
DumpableObject dobj
Definition: pg_dump.h:665
int no_subscriptions
Definition: pg_backup.h:184

References appendPQExpBuffer(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_SUBSCRIPTION, _SubscriptionInfo::dobj, Archive::dopt, ExecuteSqlQuery(), getRoleName(), i, is_superuser(), LOGICALREP_ORIGIN_ANY, LOGICALREP_TWOPHASE_STATE_DISABLED, _dumpableObject::name, _dumpOptions::no_subscriptions, _dumpableObject::objType, CatalogId::oid, pg_log_warning, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, _SubscriptionInfo::rolname, selectDumpableObject(), _SubscriptionInfo::subbinary, _SubscriptionInfo::subconninfo, _SubscriptionInfo::subdisableonerr, _SubscriptionInfo::subenabled, _SubscriptionInfo::subfailover, _SubscriptionInfo::suborigin, _SubscriptionInfo::suboriginremotelsn, _SubscriptionInfo::subpasswordrequired, _SubscriptionInfo::subpublications, _SubscriptionInfo::subrunasowner, _SubscriptionInfo::subslotname, _SubscriptionInfo::substream, _SubscriptionInfo::subsynccommit, _SubscriptionInfo::subtwophasestate, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getSubscriptionTables()

void getSubscriptionTables ( Archive fout)

Definition at line 5040 of file pg_dump.c.

5041 {
5042  DumpOptions *dopt = fout->dopt;
5043  SubscriptionInfo *subinfo = NULL;
5044  SubRelInfo *subrinfo;
5045  PGresult *res;
5046  int i_srsubid;
5047  int i_srrelid;
5048  int i_srsubstate;
5049  int i_srsublsn;
5050  int ntups;
5051  Oid last_srsubid = InvalidOid;
5052 
5053  if (dopt->no_subscriptions || !dopt->binary_upgrade ||
5054  fout->remoteVersion < 170000)
5055  return;
5056 
5057  res = ExecuteSqlQuery(fout,
5058  "SELECT srsubid, srrelid, srsubstate, srsublsn "
5059  "FROM pg_catalog.pg_subscription_rel "
5060  "ORDER BY srsubid",
5061  PGRES_TUPLES_OK);
5062  ntups = PQntuples(res);
5063  if (ntups == 0)
5064  goto cleanup;
5065 
5066  /* Get pg_subscription_rel attributes */
5067  i_srsubid = PQfnumber(res, "srsubid");
5068  i_srrelid = PQfnumber(res, "srrelid");
5069  i_srsubstate = PQfnumber(res, "srsubstate");
5070  i_srsublsn = PQfnumber(res, "srsublsn");
5071 
5072  subrinfo = pg_malloc(ntups * sizeof(SubRelInfo));
5073  for (int i = 0; i < ntups; i++)
5074  {
5075  Oid cur_srsubid = atooid(PQgetvalue(res, i, i_srsubid));
5076  Oid relid = atooid(PQgetvalue(res, i, i_srrelid));
5077  TableInfo *tblinfo;
5078 
5079  /*
5080  * If we switched to a new subscription, check if the subscription
5081  * exists.
5082  */
5083  if (cur_srsubid != last_srsubid)
5084  {
5085  subinfo = findSubscriptionByOid(cur_srsubid);
5086  if (subinfo == NULL)
5087  pg_fatal("subscription with OID %u does not exist", cur_srsubid);
5088 
5089  last_srsubid = cur_srsubid;
5090  }
5091 
5092  tblinfo = findTableByOid(relid);
5093  if (tblinfo == NULL)
5094  pg_fatal("failed sanity check, table with OID %u not found",
5095  relid);
5096 
5097  /* OK, make a DumpableObject for this relationship */
5098  subrinfo[i].dobj.objType = DO_SUBSCRIPTION_REL;
5099  subrinfo[i].dobj.catId.tableoid = relid;
5100  subrinfo[i].dobj.catId.oid = cur_srsubid;
5101  AssignDumpId(&subrinfo[i].dobj);
5102  subrinfo[i].dobj.name = pg_strdup(subinfo->dobj.name);
5103  subrinfo[i].tblinfo = tblinfo;
5104  subrinfo[i].srsubstate = PQgetvalue(res, i, i_srsubstate)[0];
5105  if (PQgetisnull(res, i, i_srsublsn))
5106  subrinfo[i].srsublsn = NULL;
5107  else
5108  subrinfo[i].srsublsn = pg_strdup(PQgetvalue(res, i, i_srsublsn));
5109 
5110  subrinfo[i].subinfo = subinfo;
5111 
5112  /* Decide whether we want to dump it */
5113  selectDumpableObject(&(subrinfo[i].dobj), fout);
5114  }
5115 
5116 cleanup:
5117  PQclear(res);
5118 }
SubscriptionInfo * findSubscriptionByOid(Oid oid)
Definition: common.c:1003
DumpableObject dobj
Definition: pg_dump.h:695
char * srsublsn
Definition: pg_dump.h:699
SubscriptionInfo * subinfo
Definition: pg_dump.h:696
TableInfo * tblinfo
Definition: pg_dump.h:697
char srsubstate
Definition: pg_dump.h:698

References AssignDumpId(), atooid, _dumpOptions::binary_upgrade, _dumpableObject::catId, cleanup(), DO_SUBSCRIPTION_REL, _SubscriptionInfo::dobj, _SubRelInfo::dobj, Archive::dopt, ExecuteSqlQuery(), findSubscriptionByOid(), findTableByOid(), i, InvalidOid, _dumpableObject::name, _dumpOptions::no_subscriptions, _dumpableObject::objType, CatalogId::oid, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, selectDumpableObject(), _SubRelInfo::srsublsn, _SubRelInfo::srsubstate, _SubRelInfo::subinfo, CatalogId::tableoid, and _SubRelInfo::tblinfo.

Referenced by getSchemaData().

◆ getTableAttrs()

void getTableAttrs ( Archive fout,
TableInfo tblinfo,
int  numTables 
)

Definition at line 8736 of file pg_dump.c.

8737 {
8738  DumpOptions *dopt = fout->dopt;
8740  PQExpBuffer tbloids = createPQExpBuffer();
8741  PQExpBuffer checkoids = createPQExpBuffer();
8742  PGresult *res;
8743  int ntups;
8744  int curtblindx;
8745  int i_attrelid;
8746  int i_attnum;
8747  int i_attname;
8748  int i_atttypname;
8749  int i_attstattarget;
8750  int i_attstorage;
8751  int i_typstorage;
8752  int i_attidentity;
8753  int i_attgenerated;
8754  int i_attisdropped;
8755  int i_attlen;
8756  int i_attalign;
8757  int i_attislocal;
8758  int i_notnull_name;
8759  int i_notnull_noinherit;
8760  int i_notnull_islocal;
8761  int i_attoptions;
8762  int i_attcollation;
8763  int i_attcompression;
8764  int i_attfdwoptions;
8765  int i_attmissingval;
8766  int i_atthasdef;
8767 
8768  /*
8769  * We want to perform just one query against pg_attribute, and then just
8770  * one against pg_attrdef (for DEFAULTs) and two against pg_constraint
8771  * (for CHECK constraints and for NOT NULL constraints). However, we
8772  * mustn't try to select every row of those catalogs and then sort it out
8773  * on the client side, because some of the server-side functions we need
8774  * would be unsafe to apply to tables we don't have lock on. Hence, we
8775  * build an array of the OIDs of tables we care about (and now have lock
8776  * on!), and use a WHERE clause to constrain which rows are selected.
8777  */
8778  appendPQExpBufferChar(tbloids, '{');
8779  appendPQExpBufferChar(checkoids, '{');
8780  for (int i = 0; i < numTables; i++)
8781  {
8782  TableInfo *tbinfo = &tblinfo[i];
8783 
8784  /* Don't bother to collect info for sequences */
8785  if (tbinfo->relkind == RELKIND_SEQUENCE)
8786  continue;
8787 
8788  /* Don't bother with uninteresting tables, either */
8789  if (!tbinfo->interesting)
8790  continue;
8791 
8792  /* OK, we need info for this table */
8793  if (tbloids->len > 1) /* do we have more than the '{'? */
8794  appendPQExpBufferChar(tbloids, ',');
8795  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
8796 
8797  if (tbinfo->ncheck > 0)
8798  {
8799  /* Also make a list of the ones with check constraints */
8800  if (checkoids->len > 1) /* do we have more than the '{'? */
8801  appendPQExpBufferChar(checkoids, ',');
8802  appendPQExpBuffer(checkoids, "%u", tbinfo->dobj.catId.oid);
8803  }
8804  }
8805  appendPQExpBufferChar(tbloids, '}');
8806  appendPQExpBufferChar(checkoids, '}');
8807 
8808  /*
8809  * Find all the user attributes and their types.
8810  *
8811  * Since we only want to dump COLLATE clauses for attributes whose
8812  * collation is different from their type's default, we use a CASE here to
8813  * suppress uninteresting attcollations cheaply.
8814  */
8816  "SELECT\n"
8817  "a.attrelid,\n"
8818  "a.attnum,\n"
8819  "a.attname,\n"
8820  "a.attstattarget,\n"
8821  "a.attstorage,\n"
8822  "t.typstorage,\n"
8823  "a.atthasdef,\n"
8824  "a.attisdropped,\n"
8825  "a.attlen,\n"
8826  "a.attalign,\n"
8827  "a.attislocal,\n"
8828  "pg_catalog.format_type(t.oid, a.atttypmod) AS atttypname,\n"
8829  "array_to_string(a.attoptions, ', ') AS attoptions,\n"
8830  "CASE WHEN a.attcollation <> t.typcollation "
8831  "THEN a.attcollation ELSE 0 END AS attcollation,\n"
8832  "pg_catalog.array_to_string(ARRAY("
8833  "SELECT pg_catalog.quote_ident(option_name) || "
8834  "' ' || pg_catalog.quote_literal(option_value) "
8835  "FROM pg_catalog.pg_options_to_table(attfdwoptions) "
8836  "ORDER BY option_name"
8837  "), E',\n ') AS attfdwoptions,\n");
8838 
8839  /*
8840  * Find out any NOT NULL markings for each column. In 18 and up we read
8841  * pg_constraint to obtain the constraint name. notnull_noinherit is set
8842  * according to the NO INHERIT property. For versions prior to 18, we
8843  * store an empty string as the name when a constraint is marked as
8844  * attnotnull (this cues dumpTableSchema to print the NOT NULL clause
8845  * without a name); also, such cases are never NO INHERIT.
8846  *
8847  * We track in notnull_islocal whether the constraint was defined directly
8848  * in this table or via an ancestor, for binary upgrade. flagInhAttrs
8849  * might modify this later for servers older than 18; it's also in charge
8850  * of determining the correct inhcount.
8851  */
8852  if (fout->remoteVersion >= 180000)
8854  "co.conname AS notnull_name,\n"
8855  "co.connoinherit AS notnull_noinherit,\n"
8856  "co.conislocal AS notnull_islocal,\n");
8857  else
8859  "CASE WHEN a.attnotnull THEN '' ELSE NULL END AS notnull_name,\n"
8860  "false AS notnull_noinherit,\n"
8861  "a.attislocal AS notnull_islocal,\n");
8862 
8863  if (fout->remoteVersion >= 140000)
8865  "a.attcompression AS attcompression,\n");
8866  else
8868  "'' AS attcompression,\n");
8869 
8870  if (fout->remoteVersion >= 100000)
8872  "a.attidentity,\n");
8873  else
8875  "'' AS attidentity,\n");
8876 
8877  if (fout->remoteVersion >= 110000)
8879  "CASE WHEN a.atthasmissing AND NOT a.attisdropped "
8880  "THEN a.attmissingval ELSE null END AS attmissingval,\n");
8881  else
8883  "NULL AS attmissingval,\n");
8884 
8885  if (fout->remoteVersion >= 120000)
8887  "a.attgenerated\n");
8888  else
8890  "'' AS attgenerated\n");
8891 
8892  /* need left join to pg_type to not fail on dropped columns ... */
8894  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8895  "JOIN pg_catalog.pg_attribute a ON (src.tbloid = a.attrelid) "
8896  "LEFT JOIN pg_catalog.pg_type t "
8897  "ON (a.atttypid = t.oid)\n",
8898  tbloids->data);
8899 
8900  /*
8901  * In versions 18 and up, we need pg_constraint for explicit NOT NULL
8902  * entries. Also, we need to know if the NOT NULL for each column is
8903  * backing a primary key.
8904  */
8905  if (fout->remoteVersion >= 180000)
8907  " LEFT JOIN pg_catalog.pg_constraint co ON "
8908  "(a.attrelid = co.conrelid\n"
8909  " AND co.contype = 'n' AND "
8910  "co.conkey = array[a.attnum])\n");
8911 
8913  "WHERE a.attnum > 0::pg_catalog.int2\n"
8914  "ORDER BY a.attrelid, a.attnum");
8915 
8916  res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
8917 
8918  ntups = PQntuples(res);
8919 
8920  i_attrelid = PQfnumber(res, "attrelid");
8921  i_attnum = PQfnumber(res, "attnum");
8922  i_attname = PQfnumber(res, "attname");
8923  i_atttypname = PQfnumber(res, "atttypname");
8924  i_attstattarget = PQfnumber(res, "attstattarget");
8925  i_attstorage = PQfnumber(res, "attstorage");
8926  i_typstorage = PQfnumber(res, "typstorage");
8927  i_attidentity = PQfnumber(res, "attidentity");
8928  i_attgenerated = PQfnumber(res, "attgenerated");
8929  i_attisdropped = PQfnumber(res, "attisdropped");
8930  i_attlen = PQfnumber(res, "attlen");
8931  i_attalign = PQfnumber(res, "attalign");
8932  i_attislocal = PQfnumber(res, "attislocal");
8933  i_notnull_name = PQfnumber(res, "notnull_name");
8934  i_notnull_noinherit = PQfnumber(res, "notnull_noinherit");
8935  i_notnull_islocal = PQfnumber(res, "notnull_islocal");
8936  i_attoptions = PQfnumber(res, "attoptions");
8937  i_attcollation = PQfnumber(res, "attcollation");
8938  i_attcompression = PQfnumber(res, "attcompression");
8939  i_attfdwoptions = PQfnumber(res, "attfdwoptions");
8940  i_attmissingval = PQfnumber(res, "attmissingval");
8941  i_atthasdef = PQfnumber(res, "atthasdef");
8942 
8943  /* Within the next loop, we'll accumulate OIDs of tables with defaults */
8944  resetPQExpBuffer(tbloids);
8945  appendPQExpBufferChar(tbloids, '{');
8946 
8947  /*
8948  * Outer loop iterates once per table, not once per row. Incrementing of
8949  * r is handled by the inner loop.
8950  */
8951  curtblindx = -1;
8952  for (int r = 0; r < ntups;)
8953  {
8954  Oid attrelid = atooid(PQgetvalue(res, r, i_attrelid));
8955  TableInfo *tbinfo = NULL;
8956  int numatts;
8957  bool hasdefaults;
8958 
8959  /* Count rows for this table */
8960  for (numatts = 1; numatts < ntups - r; numatts++)
8961  if (atooid(PQgetvalue(res, r + numatts, i_attrelid)) != attrelid)
8962  break;
8963 
8964  /*
8965  * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8966  * order.
8967  */
8968  while (++curtblindx < numTables)
8969  {
8970  tbinfo = &tblinfo[curtblindx];
8971  if (tbinfo->dobj.catId.oid == attrelid)
8972  break;
8973  }
8974  if (curtblindx >= numTables)
8975  pg_fatal("unrecognized table OID %u", attrelid);
8976  /* cross-check that we only got requested tables */
8977  if (tbinfo->relkind == RELKIND_SEQUENCE ||
8978  !tbinfo->interesting)
8979  pg_fatal("unexpected column data for table \"%s\"",
8980  tbinfo->dobj.name);
8981 
8982  /* Save data for this table */
8983  tbinfo->numatts = numatts;
8984  tbinfo->attnames = (char **) pg_malloc(numatts * sizeof(char *));
8985  tbinfo->atttypnames = (char **) pg_malloc(numatts * sizeof(char *));
8986  tbinfo->attstattarget = (int *) pg_malloc(numatts * sizeof(int));
8987  tbinfo->attstorage = (char *) pg_malloc(numatts * sizeof(char));
8988  tbinfo->typstorage = (char *) pg_malloc(numatts * sizeof(char));
8989  tbinfo->attidentity = (char *) pg_malloc(numatts * sizeof(char));
8990  tbinfo->attgenerated = (char *) pg_malloc(numatts * sizeof(char));
8991  tbinfo->attisdropped = (bool *) pg_malloc(numatts * sizeof(bool));
8992  tbinfo->attlen = (int *) pg_malloc(numatts * sizeof(int));
8993  tbinfo->attalign = (char *) pg_malloc(numatts * sizeof(char));
8994  tbinfo->attislocal = (bool *) pg_malloc(numatts * sizeof(bool));
8995  tbinfo->attoptions = (char **) pg_malloc(numatts * sizeof(char *));
8996  tbinfo->attcollation = (Oid *) pg_malloc(numatts * sizeof(Oid));
8997  tbinfo->attcompression = (char *) pg_malloc(numatts * sizeof(char));
8998  tbinfo->attfdwoptions = (char **) pg_malloc(numatts * sizeof(char *));
8999  tbinfo->attmissingval = (char **) pg_malloc(numatts * sizeof(char *));
9000  tbinfo->notnull_constrs = (char **) pg_malloc(numatts * sizeof(char *));
9001  tbinfo->notnull_noinh = (bool *) pg_malloc(numatts * sizeof(bool));
9002  tbinfo->notnull_islocal = (bool *) pg_malloc(numatts * sizeof(bool));
9003  tbinfo->attrdefs = (AttrDefInfo **) pg_malloc(numatts * sizeof(AttrDefInfo *));
9004  hasdefaults = false;
9005 
9006  for (int j = 0; j < numatts; j++, r++)
9007  {
9008  if (j + 1 != atoi(PQgetvalue(res, r, i_attnum)))
9009  pg_fatal("invalid column numbering in table \"%s\"",
9010  tbinfo->dobj.name);
9011  tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, r, i_attname));
9012  tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, r, i_atttypname));
9013  if (PQgetisnull(res, r, i_attstattarget))
9014  tbinfo->attstattarget[j] = -1;
9015  else
9016  tbinfo->attstattarget[j] = atoi(PQgetvalue(res, r, i_attstattarget));
9017  tbinfo->attstorage[j] = *(PQgetvalue(res, r, i_attstorage));
9018  tbinfo->typstorage[j] = *(PQgetvalue(res, r, i_typstorage));
9019  tbinfo->attidentity[j] = *(PQgetvalue(res, r, i_attidentity));
9020  tbinfo->attgenerated[j] = *(PQgetvalue(res, r, i_attgenerated));
9021  tbinfo->needs_override = tbinfo->needs_override || (tbinfo->attidentity[j] == ATTRIBUTE_IDENTITY_ALWAYS);
9022  tbinfo->attisdropped[j] = (PQgetvalue(res, r, i_attisdropped)[0] == 't');
9023  tbinfo->attlen[j] = atoi(PQgetvalue(res, r, i_attlen));
9024  tbinfo->attalign[j] = *(PQgetvalue(res, r, i_attalign));
9025  tbinfo->attislocal[j] = (PQgetvalue(res, r, i_attislocal)[0] == 't');
9026 
9027  /* Handle not-null constraint name and flags */
9028  determineNotNullFlags(fout, res, r,
9029  tbinfo, j,
9030  i_notnull_name, i_notnull_noinherit,
9031  i_notnull_islocal);
9032 
9033  tbinfo->attoptions[j] = pg_strdup(PQgetvalue(res, r, i_attoptions));
9034  tbinfo->attcollation[j] = atooid(PQgetvalue(res, r, i_attcollation));
9035  tbinfo->attcompression[j] = *(PQgetvalue(res, r, i_attcompression));
9036  tbinfo->attfdwoptions[j] = pg_strdup(PQgetvalue(res, r, i_attfdwoptions));
9037  tbinfo->attmissingval[j] = pg_strdup(PQgetvalue(res, r, i_attmissingval));
9038  tbinfo->attrdefs[j] = NULL; /* fix below */
9039  if (PQgetvalue(res, r, i_atthasdef)[0] == 't')
9040  hasdefaults = true;
9041  }
9042 
9043  if (hasdefaults)
9044  {
9045  /* Collect OIDs of interesting tables that have defaults */
9046  if (tbloids->len > 1) /* do we have more than the '{'? */
9047  appendPQExpBufferChar(tbloids, ',');
9048  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
9049  }
9050  }
9051 
9052  PQclear(res);
9053 
9054  /*
9055  * Now get info about column defaults. This is skipped for a data-only
9056  * dump, as it is only needed for table schemas.
9057  */
9058  if (!dopt->dataOnly && tbloids->len > 1)
9059  {
9060  AttrDefInfo *attrdefs;
9061  int numDefaults;
9062  TableInfo *tbinfo = NULL;
9063 
9064  pg_log_info("finding table default expressions");
9065 
9066  appendPQExpBufferChar(tbloids, '}');
9067 
9068  printfPQExpBuffer(q, "SELECT a.tableoid, a.oid, adrelid, adnum, "
9069  "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc\n"
9070  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9071  "JOIN pg_catalog.pg_attrdef a ON (src.tbloid = a.adrelid)\n"
9072  "ORDER BY a.adrelid, a.adnum",
9073  tbloids->data);
9074 
9075  res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
9076 
9077  numDefaults = PQntuples(res);
9078  attrdefs = (AttrDefInfo *) pg_malloc(numDefaults * sizeof(AttrDefInfo));
9079 
9080  curtblindx = -1;
9081  for (int j = 0; j < numDefaults; j++)
9082  {
9083  Oid adtableoid = atooid(PQgetvalue(res, j, 0));
9084  Oid adoid = atooid(PQgetvalue(res, j, 1));
9085  Oid adrelid = atooid(PQgetvalue(res, j, 2));
9086  int adnum = atoi(PQgetvalue(res, j, 3));
9087  char *adsrc = PQgetvalue(res, j, 4);
9088 
9089  /*
9090  * Locate the associated TableInfo; we rely on tblinfo[] being in
9091  * OID order.
9092  */
9093  if (tbinfo == NULL || tbinfo->dobj.catId.oid != adrelid)
9094  {
9095  while (++curtblindx < numTables)
9096  {
9097  tbinfo = &tblinfo[curtblindx];
9098  if (tbinfo->dobj.catId.oid == adrelid)
9099  break;
9100  }
9101  if (curtblindx >= numTables)
9102  pg_fatal("unrecognized table OID %u", adrelid);
9103  }
9104 
9105  if (adnum <= 0 || adnum > tbinfo->numatts)
9106  pg_fatal("invalid adnum value %d for table \"%s\"",
9107  adnum, tbinfo->dobj.name);
9108 
9109  /*
9110  * dropped columns shouldn't have defaults, but just in case,
9111  * ignore 'em
9112  */
9113  if (tbinfo->attisdropped[adnum - 1])
9114  continue;
9115 
9116  attrdefs[j].dobj.objType = DO_ATTRDEF;
9117  attrdefs[j].dobj.catId.tableoid = adtableoid;
9118  attrdefs[j].dobj.catId.oid = adoid;
9119  AssignDumpId(&attrdefs[j].dobj);
9120  attrdefs[j].adtable = tbinfo;
9121  attrdefs[j].adnum = adnum;
9122  attrdefs[j].adef_expr = pg_strdup(adsrc);
9123 
9124  attrdefs[j].dobj.name = pg_strdup(tbinfo->dobj.name);
9125  attrdefs[j].dobj.namespace = tbinfo->dobj.namespace;
9126 
9127  attrdefs[j].dobj.dump = tbinfo->dobj.dump;
9128 
9129  /*
9130  * Figure out whether the default/generation expression should be
9131  * dumped as part of the main CREATE TABLE (or similar) command or
9132  * as a separate ALTER TABLE (or similar) command. The preference
9133  * is to put it into the CREATE command, but in some cases that's
9134  * not possible.
9135  */
9136  if (tbinfo->attgenerated[adnum - 1])
9137  {
9138  /*
9139  * Column generation expressions cannot be dumped separately,
9140  * because there is no syntax for it. By setting separate to
9141  * false here we prevent the "default" from being processed as
9142  * its own dumpable object. Later, flagInhAttrs() will mark
9143  * it as not to be dumped at all, if possible (that is, if it
9144  * can be inherited from a parent).
9145  */
9146  attrdefs[j].separate = false;
9147  }
9148  else if (tbinfo->relkind == RELKIND_VIEW)
9149  {
9150  /*
9151  * Defaults on a VIEW must always be dumped as separate ALTER
9152  * TABLE commands.
9153  */
9154  attrdefs[j].separate = true;
9155  }
9156  else if (!shouldPrintColumn(dopt, tbinfo, adnum - 1))
9157  {
9158  /* column will be suppressed, print default separately */
9159  attrdefs[j].separate = true;
9160  }
9161  else
9162  {
9163  attrdefs[j].separate = false;
9164  }
9165 
9166  if (!attrdefs[j].separate)
9167  {
9168  /*
9169  * Mark the default as needing to appear before the table, so
9170  * that any dependencies it has must be emitted before the
9171  * CREATE TABLE. If this is not possible, we'll change to
9172  * "separate" mode while sorting dependencies.
9173  */
9174  addObjectDependency(&tbinfo->dobj,
9175  attrdefs[j].dobj.dumpId);
9176  }
9177 
9178  tbinfo->attrdefs[adnum - 1] = &attrdefs[j];
9179  }
9180 
9181  PQclear(res);
9182  }
9183 
9184  /*
9185  * Get info about table CHECK constraints. This is skipped for a
9186  * data-only dump, as it is only needed for table schemas.
9187  */
9188  if (!dopt->dataOnly && checkoids->len > 2)
9189  {
9190  ConstraintInfo *constrs;
9191  int numConstrs;
9192  int i_tableoid;
9193  int i_oid;
9194  int i_conrelid;
9195  int i_conname;
9196  int i_consrc;
9197  int i_conislocal;
9198  int i_convalidated;
9199 
9200  pg_log_info("finding table check constraints");
9201 
9202  resetPQExpBuffer(q);
9204  "SELECT c.tableoid, c.oid, conrelid, conname, "
9205  "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9206  "conislocal, convalidated "
9207  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9208  "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
9209  "WHERE contype = 'c' "
9210  "ORDER BY c.conrelid, c.conname",
9211  checkoids->data);
9212 
9213  res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
9214 
9215  numConstrs = PQntuples(res);
9216  constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(ConstraintInfo));
9217 
9218  i_tableoid = PQfnumber(res, "tableoid");
9219  i_oid = PQfnumber(res, "oid");
9220  i_conrelid = PQfnumber(res, "conrelid");
9221  i_conname = PQfnumber(res, "conname");
9222  i_consrc = PQfnumber(res, "consrc");
9223  i_conislocal = PQfnumber(res, "conislocal");
9224  i_convalidated = PQfnumber(res, "convalidated");
9225 
9226  /* As above, this loop iterates once per table, not once per row */
9227  curtblindx = -1;
9228  for (int j = 0; j < numConstrs;)
9229  {
9230  Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
9231  TableInfo *tbinfo = NULL;
9232  int numcons;
9233 
9234  /* Count rows for this table */
9235  for (numcons = 1; numcons < numConstrs - j; numcons++)
9236  if (atooid(PQgetvalue(res, j + numcons, i_conrelid)) != conrelid)
9237  break;
9238 
9239  /*
9240  * Locate the associated TableInfo; we rely on tblinfo[] being in
9241  * OID order.
9242  */
9243  while (++curtblindx < numTables)
9244  {
9245  tbinfo = &tblinfo[curtblindx];
9246  if (tbinfo->dobj.catId.oid == conrelid)
9247  break;
9248  }
9249  if (curtblindx >= numTables)
9250  pg_fatal("unrecognized table OID %u", conrelid);
9251 
9252  if (numcons != tbinfo->ncheck)
9253  {
9254  pg_log_error(ngettext("expected %d check constraint on table \"%s\" but found %d",
9255  "expected %d check constraints on table \"%s\" but found %d",
9256  tbinfo->ncheck),
9257  tbinfo->ncheck, tbinfo->dobj.name, numcons);
9258  pg_log_error_hint("The system catalogs might be corrupted.");
9259  exit_nicely(1);
9260  }
9261 
9262  tbinfo->checkexprs = constrs + j;
9263 
9264  for (int c = 0; c < numcons; c++, j++)
9265  {
9266  bool validated = PQgetvalue(res, j, i_convalidated)[0] == 't';
9267 
9268  constrs[j].dobj.objType = DO_CONSTRAINT;
9269  constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
9270  constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
9271  AssignDumpId(&constrs[j].dobj);
9272  constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
9273  constrs[j].dobj.namespace = tbinfo->dobj.namespace;
9274  constrs[j].contable = tbinfo;
9275  constrs[j].condomain = NULL;
9276  constrs[j].contype = 'c';
9277  constrs[j].condef = pg_strdup(PQgetvalue(res, j, i_consrc));
9278  constrs[j].confrelid = InvalidOid;
9279  constrs[j].conindex = 0;
9280  constrs[j].condeferrable = false;
9281  constrs[j].condeferred = false;
9282  constrs[j].conislocal = (PQgetvalue(res, j, i_conislocal)[0] == 't');
9283 
9284  /*
9285  * An unvalidated constraint needs to be dumped separately, so
9286  * that potentially-violating existing data is loaded before
9287  * the constraint.
9288  */
9289  constrs[j].separate = !validated;
9290 
9291  constrs[j].dobj.dump = tbinfo->dobj.dump;
9292 
9293  /*
9294  * Mark the constraint as needing to appear before the table
9295  * --- this is so that any other dependencies of the
9296  * constraint will be emitted before we try to create the
9297  * table. If the constraint is to be dumped separately, it
9298  * will be dumped after data is loaded anyway, so don't do it.
9299  * (There's an automatic dependency in the opposite direction
9300  * anyway, so don't need to add one manually here.)
9301  */
9302  if (!constrs[j].separate)
9303  addObjectDependency(&tbinfo->dobj,
9304  constrs[j].dobj.dumpId);
9305 
9306  /*
9307  * We will detect later whether the constraint must be split
9308  * out from the table definition.
9309  */
9310  }
9311  }
9312 
9313  PQclear(res);
9314  }
9315 
9316  destroyPQExpBuffer(q);
9317  destroyPQExpBuffer(tbloids);
9318  destroyPQExpBuffer(checkoids);
9319 }
#define ngettext(s, p, n)
Definition: c.h:1186
#define pg_log_error(...)
Definition: logging.h:106
#define pg_log_error_hint(...)
Definition: logging.h:112
static void determineNotNullFlags(Archive *fout, PGresult *res, int r, TableInfo *tbinfo, int j, int i_notnull_name, int i_notnull_noinherit, int i_notnull_islocal)
Definition: pg_dump.c:9357
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition: pg_dump.c:9443
#define exit_nicely(code)
Definition: pg_dumpall.c:124
DumpableObject dobj
Definition: pg_dump.h:380
char * adef_expr
Definition: pg_dump.h:383
TableInfo * adtable
Definition: pg_dump.h:381
bool separate
Definition: pg_dump.h:384
bool dataOnly
Definition: pg_backup.h:171
char * attidentity
Definition: pg_dump.h:340
char ** notnull_constrs
Definition: pg_dump.h:350
int ncheck
Definition: pg_dump.h:309
bool * attislocal
Definition: pg_dump.h:344
char * attgenerated
Definition: pg_dump.h:341
int * attlen
Definition: pg_dump.h:342
char ** attfdwoptions
Definition: pg_dump.h:348
bool * attisdropped
Definition: pg_dump.h:339
bool needs_override
Definition: pg_dump.h:358
struct _constraintInfo * checkexprs
Definition: pg_dump.h:357
int * attstattarget
Definition: pg_dump.h:336
bool * notnull_islocal
Definition: pg_dump.h:355
char * typstorage
Definition: pg_dump.h:338
int numatts
Definition: pg_dump.h:333
struct _attrDefInfo ** attrdefs
Definition: pg_dump.h:356
char ** attoptions
Definition: pg_dump.h:345
Oid * attcollation
Definition: pg_dump.h:346
bool * notnull_noinh
Definition: pg_dump.h:354
char * attstorage
Definition: pg_dump.h:337
char ** atttypnames
Definition: pg_dump.h:335
char ** attmissingval
Definition: pg_dump.h:349
char ** attnames
Definition: pg_dump.h:334
char * attalign
Definition: pg_dump.h:343
char * attcompression
Definition: pg_dump.h:347

References addObjectDependency(), _attrDefInfo::adef_expr, _attrDefInfo::adnum, _attrDefInfo::adtable, appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _tableInfo::attalign, _tableInfo::attcollation, _tableInfo::attcompression, _tableInfo::attfdwoptions, _tableInfo::attgenerated, _tableInfo::attidentity, _tableInfo::attisdropped, _tableInfo::attislocal, _tableInfo::attlen, _tableInfo::attmissingval, _tableInfo::attnames, _tableInfo::attoptions, _tableInfo::attrdefs, _tableInfo::attstattarget, _tableInfo::attstorage, _tableInfo::atttypnames, _dumpableObject::catId, _tableInfo::checkexprs, _constraintInfo::condef, _constraintInfo::condeferrable, _constraintInfo::condeferred, _constraintInfo::condomain, _constraintInfo::confrelid, _constraintInfo::conindex, _constraintInfo::conislocal, _constraintInfo::contable, _constraintInfo::contype, createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, destroyPQExpBuffer(), determineNotNullFlags(), DO_ATTRDEF, DO_CONSTRAINT, _tableInfo::dobj, _attrDefInfo::dobj, _constraintInfo::dobj, Archive::dopt, _dumpableObject::dump, _dumpableObject::dumpId, ExecuteSqlQuery(), exit_nicely, i, _tableInfo::interesting, InvalidOid, j, PQExpBufferData::len, _dumpableObject::name, _tableInfo::ncheck, _tableInfo::needs_override, ngettext, _tableInfo::notnull_constrs, _tableInfo::notnull_islocal, _tableInfo::notnull_noinh, _tableInfo::numatts, _dumpableObject::objType, CatalogId::oid, pg_fatal, pg_log_error, pg_log_error_hint, pg_log_info, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), _tableInfo::relkind, Archive::remoteVersion, res, resetPQExpBuffer(), _attrDefInfo::separate, _constraintInfo::separate, shouldPrintColumn(), CatalogId::tableoid, and _tableInfo::typstorage.

Referenced by getSchemaData().

◆ getTables()

TableInfo* getTables ( Archive fout,
int *  numTables 
)

Definition at line 6785 of file pg_dump.c.

6786 {
6787  DumpOptions *dopt = fout->dopt;
6788  PGresult *res;
6789  int ntups;
6790  int i;
6791  PQExpBuffer query = createPQExpBuffer();
6792  TableInfo *tblinfo;
6793  int i_reltableoid;
6794  int i_reloid;
6795  int i_relname;
6796  int i_relnamespace;
6797  int i_relkind;
6798  int i_reltype;
6799  int i_relowner;
6800  int i_relchecks;
6801  int i_relhasindex;
6802  int i_relhasrules;
6803  int i_relpages;
6804  int i_toastpages;
6805  int i_owning_tab;
6806  int i_owning_col;
6807  int i_reltablespace;
6808  int i_relhasoids;
6809  int i_relhastriggers;
6810  int i_relpersistence;
6811  int i_relispopulated;
6812  int i_relreplident;
6813  int i_relrowsec;
6814  int i_relforcerowsec;
6815  int i_relfrozenxid;
6816  int i_toastfrozenxid;
6817  int i_toastoid;
6818  int i_relminmxid;
6819  int i_toastminmxid;
6820  int i_reloptions;
6821  int i_checkoption;
6822  int i_toastreloptions;
6823  int i_reloftype;
6824  int i_foreignserver;
6825  int i_amname;
6826  int i_is_identity_sequence;
6827  int i_relacl;
6828  int i_acldefault;
6829  int i_ispartition;
6830 
6831  /*
6832  * Find all the tables and table-like objects.
6833  *
6834  * We must fetch all tables in this phase because otherwise we cannot
6835  * correctly identify inherited columns, owned sequences, etc.
6836  *
6837  * We include system catalogs, so that we can work if a user table is
6838  * defined to inherit from a system catalog (pretty weird, but...)
6839  *
6840  * Note: in this phase we should collect only a minimal amount of
6841  * information about each table, basically just enough to decide if it is
6842  * interesting. In particular, since we do not yet have lock on any user
6843  * table, we MUST NOT invoke any server-side data collection functions
6844  * (for instance, pg_get_partkeydef()). Those are likely to fail or give
6845  * wrong answers if any concurrent DDL is happening.
6846  */
6847 
6848  appendPQExpBufferStr(query,
6849  "SELECT c.tableoid, c.oid, c.relname, "
6850  "c.relnamespace, c.relkind, c.reltype, "
6851  "c.relowner, "
6852  "c.relchecks, "
6853  "c.relhasindex, c.relhasrules, c.relpages, "
6854  "c.relhastriggers, "
6855  "c.relpersistence, "
6856  "c.reloftype, "
6857  "c.relacl, "
6858  "acldefault(CASE WHEN c.relkind = " CppAsString2(RELKIND_SEQUENCE)
6859  " THEN 's'::\"char\" ELSE 'r'::\"char\" END, c.relowner) AS acldefault, "
6860  "CASE WHEN c.relkind = " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN "
6861  "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) "
6862  "ELSE 0 END AS foreignserver, "
6863  "c.relfrozenxid, tc.relfrozenxid AS tfrozenxid, "
6864  "tc.oid AS toid, "
6865  "tc.relpages AS toastpages, "
6866  "tc.reloptions AS toast_reloptions, "
6867  "d.refobjid AS owning_tab, "
6868  "d.refobjsubid AS owning_col, "
6869  "tsp.spcname AS reltablespace, ");
6870 
6871  if (fout->remoteVersion >= 120000)
6872  appendPQExpBufferStr(query,
6873  "false AS relhasoids, ");
6874  else
6875  appendPQExpBufferStr(query,
6876  "c.relhasoids, ");
6877 
6878  if (fout->remoteVersion >= 90300)
6879  appendPQExpBufferStr(query,
6880  "c.relispopulated, ");
6881  else
6882  appendPQExpBufferStr(query,
6883  "'t' as relispopulated, ");
6884 
6885  if (fout->remoteVersion >= 90400)
6886  appendPQExpBufferStr(query,
6887  "c.relreplident, ");
6888  else
6889  appendPQExpBufferStr(query,
6890  "'d' AS relreplident, ");
6891 
6892  if (fout->remoteVersion >= 90500)
6893  appendPQExpBufferStr(query,
6894  "c.relrowsecurity, c.relforcerowsecurity, ");
6895  else
6896  appendPQExpBufferStr(query,
6897  "false AS relrowsecurity, "
6898  "false AS relforcerowsecurity, ");
6899 
6900  if (fout->remoteVersion >= 90300)
6901  appendPQExpBufferStr(query,
6902  "c.relminmxid, tc.relminmxid AS tminmxid, ");
6903  else
6904  appendPQExpBufferStr(query,
6905  "0 AS relminmxid, 0 AS tminmxid, ");
6906 
6907  if (fout->remoteVersion >= 90300)
6908  appendPQExpBufferStr(query,
6909  "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, "
6910  "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text "
6911  "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, ");
6912  else
6913  appendPQExpBufferStr(query,
6914  "c.reloptions, NULL AS checkoption, ");
6915 
6916  if (fout->remoteVersion >= 90600)
6917  appendPQExpBufferStr(query,
6918  "am.amname, ");
6919  else
6920  appendPQExpBufferStr(query,
6921  "NULL AS amname, ");
6922 
6923  if (fout->remoteVersion >= 90600)
6924  appendPQExpBufferStr(query,
6925  "(d.deptype = 'i') IS TRUE AS is_identity_sequence, ");
6926  else
6927  appendPQExpBufferStr(query,
6928  "false AS is_identity_sequence, ");
6929 
6930  if (fout->remoteVersion >= 100000)
6931  appendPQExpBufferStr(query,
6932  "c.relispartition AS ispartition ");
6933  else
6934  appendPQExpBufferStr(query,
6935  "false AS ispartition ");
6936 
6937  /*
6938  * Left join to pg_depend to pick up dependency info linking sequences to
6939  * their owning column, if any (note this dependency is AUTO except for
6940  * identity sequences, where it's INTERNAL). Also join to pg_tablespace to
6941  * collect the spcname.
6942  */
6943  appendPQExpBufferStr(query,
6944  "\nFROM pg_class c\n"
6945  "LEFT JOIN pg_depend d ON "
6946  "(c.relkind = " CppAsString2(RELKIND_SEQUENCE) " AND "
6947  "d.classid = 'pg_class'::regclass AND d.objid = c.oid AND "
6948  "d.objsubid = 0 AND "
6949  "d.refclassid = 'pg_class'::regclass AND d.deptype IN ('a', 'i'))\n"
6950  "LEFT JOIN pg_tablespace tsp ON (tsp.oid = c.reltablespace)\n");
6951 
6952  /*
6953  * In 9.6 and up, left join to pg_am to pick up the amname.
6954  */
6955  if (fout->remoteVersion >= 90600)
6956  appendPQExpBufferStr(query,
6957  "LEFT JOIN pg_am am ON (c.relam = am.oid)\n");
6958 
6959  /*
6960  * We purposefully ignore toast OIDs for partitioned tables; the reason is
6961  * that versions 10 and 11 have them, but later versions do not, so
6962  * emitting them causes the upgrade to fail.
6963  */
6964  appendPQExpBufferStr(query,
6965  "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid"
6966  " AND tc.relkind = " CppAsString2(RELKIND_TOASTVALUE)
6967  " AND c.relkind <> " CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n");
6968 
6969  /*
6970  * Restrict to interesting relkinds (in particular, not indexes). Not all
6971  * relkinds are possible in older servers, but it's not worth the trouble
6972  * to emit a version-dependent list.
6973  *
6974  * Composite-type table entries won't be dumped as such, but we have to
6975  * make a DumpableObject for them so that we can track dependencies of the
6976  * composite type (pg_depend entries for columns of the composite type
6977  * link to the pg_class entry not the pg_type entry).
6978  */
6979  appendPQExpBufferStr(query,
6980  "WHERE c.relkind IN ("
6981  CppAsString2(RELKIND_RELATION) ", "
6982  CppAsString2(RELKIND_SEQUENCE) ", "
6983  CppAsString2(RELKIND_VIEW) ", "
6984  CppAsString2(RELKIND_COMPOSITE_TYPE) ", "
6985  CppAsString2(RELKIND_MATVIEW) ", "
6986  CppAsString2(RELKIND_FOREIGN_TABLE) ", "
6987  CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n"
6988  "ORDER BY c.oid");
6989 
6990  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6991 
6992  ntups = PQntuples(res);
6993 
6994  *numTables = ntups;
6995 
6996  /*
6997  * Extract data from result and lock dumpable tables. We do the locking
6998  * before anything else, to minimize the window wherein a table could
6999  * disappear under us.
7000  *
7001  * Note that we have to save info about all tables here, even when dumping
7002  * only one, because we don't yet know which tables might be inheritance
7003  * ancestors of the target table.
7004  */
7005  tblinfo = (TableInfo *) pg_malloc0(ntups * sizeof(TableInfo));
7006 
7007  i_reltableoid = PQfnumber(res, "tableoid");
7008  i_reloid = PQfnumber(res, "oid");
7009  i_relname = PQfnumber(res, "relname");
7010  i_relnamespace = PQfnumber(res, "relnamespace");
7011  i_relkind = PQfnumber(res, "relkind");
7012  i_reltype = PQfnumber(res, "reltype");
7013  i_relowner = PQfnumber(res, "relowner");
7014  i_relchecks = PQfnumber(res, "relchecks");
7015  i_relhasindex = PQfnumber(res, "relhasindex");
7016  i_relhasrules = PQfnumber(res, "relhasrules");
7017  i_relpages = PQfnumber(res, "relpages");
7018  i_toastpages = PQfnumber(res, "toastpages");
7019  i_owning_tab = PQfnumber(res, "owning_tab");
7020  i_owning_col = PQfnumber(res, "owning_col");
7021  i_reltablespace = PQfnumber(res, "reltablespace");
7022  i_relhasoids = PQfnumber(res, "relhasoids");
7023  i_relhastriggers = PQfnumber(res, "relhastriggers");
7024  i_relpersistence = PQfnumber(res, "relpersistence");
7025  i_relispopulated = PQfnumber(res, "relispopulated");
7026  i_relreplident = PQfnumber(res, "relreplident");
7027  i_relrowsec = PQfnumber(res, "relrowsecurity");
7028  i_relforcerowsec = PQfnumber(res, "relforcerowsecurity");
7029  i_relfrozenxid = PQfnumber(res, "relfrozenxid");
7030  i_toastfrozenxid = PQfnumber(res, "tfrozenxid");
7031  i_toastoid = PQfnumber(res, "toid");
7032  i_relminmxid = PQfnumber(res, "relminmxid");
7033  i_toastminmxid = PQfnumber(res, "tminmxid");
7034  i_reloptions = PQfnumber(res, "reloptions");
7035  i_checkoption = PQfnumber(res, "checkoption");
7036  i_toastreloptions = PQfnumber(res, "toast_reloptions");
7037  i_reloftype = PQfnumber(res, "reloftype");
7038  i_foreignserver = PQfnumber(res, "foreignserver");
7039  i_amname = PQfnumber(res, "amname");
7040  i_is_identity_sequence = PQfnumber(res, "is_identity_sequence");
7041  i_relacl = PQfnumber(res, "relacl");
7042  i_acldefault = PQfnumber(res, "acldefault");
7043  i_ispartition = PQfnumber(res, "ispartition");
7044 
7045  if (dopt->lockWaitTimeout)
7046  {
7047  /*
7048  * Arrange to fail instead of waiting forever for a table lock.
7049  *
7050  * NB: this coding assumes that the only queries issued within the
7051  * following loop are LOCK TABLEs; else the timeout may be undesirably
7052  * applied to other things too.
7053  */
7054  resetPQExpBuffer(query);
7055  appendPQExpBufferStr(query, "SET statement_timeout = ");
7057  ExecuteSqlStatement(fout, query->data);
7058  }
7059 
7060  resetPQExpBuffer(query);
7061 
7062  for (i = 0; i < ntups; i++)
7063  {
7064  tblinfo[i].dobj.objType = DO_TABLE;
7065  tblinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_reltableoid));
7066  tblinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_reloid));
7067  AssignDumpId(&tblinfo[i].dobj);
7068  tblinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_relname));
7069  tblinfo[i].dobj.namespace =
7070  findNamespace(atooid(PQgetvalue(res, i, i_relnamespace)));
7071  tblinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_relacl));
7072  tblinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
7073  tblinfo[i].dacl.privtype = 0;
7074  tblinfo[i].dacl.initprivs = NULL;
7075  tblinfo[i].relkind = *(PQgetvalue(res, i, i_relkind));
7076  tblinfo[i].reltype = atooid(PQgetvalue(res, i, i_reltype));
7077  tblinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_relowner));
7078  tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
7079  tblinfo[i].hasindex = (strcmp(PQgetvalue(res, i, i_relhasindex), "t") == 0);
7080  tblinfo[i].hasrules = (strcmp(PQgetvalue(res, i, i_relhasrules), "t") == 0);
7081  tblinfo[i].relpages = atoi(PQgetvalue(res, i, i_relpages));
7082  if (PQgetisnull(res, i, i_toastpages))
7083  tblinfo[i].toastpages = 0;
7084  else
7085  tblinfo[i].toastpages = atoi(PQgetvalue(res, i, i_toastpages));
7086  if (PQgetisnull(res, i, i_owning_tab))
7087  {
7088  tblinfo[i].owning_tab = InvalidOid;
7089  tblinfo[i].owning_col = 0;
7090  }
7091  else
7092  {
7093  tblinfo[i].owning_tab = atooid(PQgetvalue(res, i, i_owning_tab));
7094  tblinfo[i].owning_col = atoi(PQgetvalue(res, i, i_owning_col));
7095  }
7096  tblinfo[i].reltablespace = pg_strdup(PQgetvalue(res, i, i_reltablespace));
7097  tblinfo[i].hasoids = (strcmp(PQgetvalue(res, i, i_relhasoids), "t") == 0);
7098  tblinfo[i].hastriggers = (strcmp(PQgetvalue(res, i, i_relhastriggers), "t") == 0);
7099  tblinfo[i].relpersistence = *(PQgetvalue(res, i, i_relpersistence));
7100  tblinfo[i].relispopulated = (strcmp(PQgetvalue(res, i, i_relispopulated), "t") == 0);
7101  tblinfo[i].relreplident = *(PQgetvalue(res, i, i_relreplident));
7102  tblinfo[i].rowsec = (strcmp(PQgetvalue(res, i, i_relrowsec), "t") == 0);
7103  tblinfo[i].forcerowsec = (strcmp(PQgetvalue(res, i, i_relforcerowsec), "t") == 0);
7104  tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid));
7105  tblinfo[i].toast_frozenxid = atooid(PQgetvalue(res, i, i_toastfrozenxid));
7106  tblinfo[i].toast_oid = atooid(PQgetvalue(res, i, i_toastoid));
7107  tblinfo[i].minmxid = atooid(PQgetvalue(res, i, i_relminmxid));
7108  tblinfo[i].toast_minmxid = atooid(PQgetvalue(res, i, i_toastminmxid));
7109  tblinfo[i].reloptions = pg_strdup(PQgetvalue(res, i, i_reloptions));
7110  if (PQgetisnull(res, i, i_checkoption))
7111  tblinfo[i].checkoption = NULL;
7112  else
7113  tblinfo[i].checkoption = pg_strdup(PQgetvalue(res, i, i_checkoption));
7114  tblinfo[i].toast_reloptions = pg_strdup(PQgetvalue(res, i, i_toastreloptions));
7115  tblinfo[i].reloftype = atooid(PQgetvalue(res, i, i_reloftype));
7116  tblinfo[i].foreign_server = atooid(PQgetvalue(res, i, i_foreignserver));
7117  if (PQgetisnull(res, i, i_amname))
7118  tblinfo[i].amname = NULL;
7119  else
7120  tblinfo[i].amname = pg_strdup(PQgetvalue(res, i, i_amname));
7121  tblinfo[i].is_identity_sequence = (strcmp(PQgetvalue(res, i, i_is_identity_sequence), "t") == 0);
7122  tblinfo[i].ispartition = (strcmp(PQgetvalue(res, i, i_ispartition), "t") == 0);
7123 
7124  /* other fields were zeroed above */
7125 
7126  /*
7127  * Decide whether we want to dump this table.
7128  */
7129  if (tblinfo[i].relkind == RELKIND_COMPOSITE_TYPE)
7130  tblinfo[i].dobj.dump = DUMP_COMPONENT_NONE;
7131  else
7132  selectDumpableTable(&tblinfo[i], fout);
7133 
7134  /*
7135  * Now, consider the table "interesting" if we need to dump its
7136  * definition or its data. Later on, we'll skip a lot of data
7137  * collection for uninteresting tables.
7138  *
7139  * Note: the "interesting" flag will also be set by flagInhTables for
7140  * parents of interesting tables, so that we collect necessary
7141  * inheritance info even when the parents are not themselves being
7142  * dumped. This is the main reason why we need an "interesting" flag
7143  * that's separate from the components-to-dump bitmask.
7144  */
7145  tblinfo[i].interesting = (tblinfo[i].dobj.dump &
7147  DUMP_COMPONENT_DATA)) != 0;
7148 
7149  tblinfo[i].dummy_view = false; /* might get set during sort */
7150  tblinfo[i].postponed_def = false; /* might get set during sort */
7151 
7152  /* Tables have data */
7153  tblinfo[i].dobj.components |= DUMP_COMPONENT_DATA;
7154 
7155  /* Mark whether table has an ACL */
7156  if (!PQgetisnull(res, i, i_relacl))
7157  tblinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
7158  tblinfo[i].hascolumnACLs = false; /* may get set later */
7159 
7160  /*
7161  * Read-lock target tables to make sure they aren't DROPPED or altered
7162  * in schema before we get around to dumping them.
7163  *
7164  * Note that we don't explicitly lock parents of the target tables; we
7165  * assume our lock on the child is enough to prevent schema
7166  * alterations to parent tables.
7167  *
7168  * NOTE: it'd be kinda nice to lock other relations too, not only
7169  * plain or partitioned tables, but the backend doesn't presently
7170  * allow that.
7171  *
7172  * We only need to lock the table for certain components; see
7173  * pg_dump.h
7174  */
7175  if ((tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK) &&
7176  (tblinfo[i].relkind == RELKIND_RELATION ||
7177  tblinfo[i].relkind == RELKIND_PARTITIONED_TABLE))
7178  {
7179  /*
7180  * Tables are locked in batches. When dumping from a remote
7181  * server this can save a significant amount of time by reducing
7182  * the number of round trips.
7183  */
7184  if (query->len == 0)
7185  appendPQExpBuffer(query, "LOCK TABLE %s",
7186  fmtQualifiedDumpable(&tblinfo[i]));
7187  else
7188  {
7189  appendPQExpBuffer(query, ", %s",
7190  fmtQualifiedDumpable(&tblinfo[i]));
7191 
7192  /* Arbitrarily end a batch when query length reaches 100K. */
7193  if (query->len >= 100000)
7194  {
7195  /* Lock another batch of tables. */
7196  appendPQExpBufferStr(query, " IN ACCESS SHARE MODE");
7197  ExecuteSqlStatement(fout, query->data);
7198  resetPQExpBuffer(query);
7199  }
7200  }
7201  }
7202  }
7203 
7204  if (query->len != 0)
7205  {
7206  /* Lock the tables in the last batch. */
7207  appendPQExpBufferStr(query, " IN ACCESS SHARE MODE");
7208  ExecuteSqlStatement(fout, query->data);
7209  }
7210 
7211  if (dopt->lockWaitTimeout)
7212  {
7213  ExecuteSqlStatement(fout, "SET statement_timeout = 0");
7214  }
7215 
7216  PQclear(res);
7217 
7218  destroyPQExpBuffer(query);
7219 
7220  return tblinfo;
7221 }
#define CppAsString2(x)
Definition: c.h:342
PGconn * GetConnection(UserMapping *user, bool will_prep_stmt, PgFdwConnState **state)
Definition: connection.c:191
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:76
void ExecuteSqlStatement(Archive *AHX, const char *query)
Definition: pg_backup_db.c:276
static void selectDumpableTable(TableInfo *tbinfo, Archive *fout)
Definition: pg_dump.c:1910
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:226
#define DUMP_COMPONENT_DATA
Definition: pg_dump.h:98
#define DUMP_COMPONENTS_REQUIRING_LOCK
Definition: pg_dump.h:128
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
Definition: string_utils.c:293
const char * lockWaitTimeout
Definition: pg_backup.h:174
char * reltablespace
Definition: pg_dump.h:293
bool ispartition
Definition: pg_dump.h:323
Oid reloftype
Definition: pg_dump.h:311
char * toast_reloptions
Definition: pg_dump.h:296
DumpableAcl dacl
Definition: pg_dump.h:287
bool relispopulated
Definition: pg_dump.h:291
Oid reltype
Definition: pg_dump.h:310
bool hasoids
Definition: pg_dump.h:303
Oid toast_oid
Definition: pg_dump.h:306
Oid foreign_server
Definition: pg_dump.h:312
bool hasrules
Definition: pg_dump.h:298
uint32 frozenxid
Definition: pg_dump.h:304
int owning_col
Definition: pg_dump.h:315
char * checkoption
Definition: pg_dump.h:295
bool hastriggers
Definition: pg_dump.h:299
const char * rolname
Definition: pg_dump.h:288
char relreplident
Definition: pg_dump.h:292
uint32 minmxid
Definition: pg_dump.h:305
int toastpages
Definition: pg_dump.h:318
char * amname
Definition: pg_dump.h:359
bool dummy_view
Definition: pg_dump.h:321
bool forcerowsec
Definition: pg_dump.h:302
char relpersistence
Definition: pg_dump.h:290
char * reloptions
Definition: pg_dump.h:294
int relpages
Definition: pg_dump.h:317
uint32 toast_frozenxid
Definition: pg_dump.h:307
uint32 toast_minmxid
Definition: pg_dump.h:308
bool postponed_def
Definition: pg_dump.h:322

References _dumpableAcl::acl, _dumpableAcl::acldefault, _tableInfo::amname, appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralConn(), AssignDumpId(), atooid, _dumpableObject::catId, _tableInfo::checkoption, _dumpableObject::components, CppAsString2, createPQExpBuffer(), _tableInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_TABLE, _tableInfo::dobj, Archive::dopt, _tableInfo::dummy_view, _dumpableObject::dump, DUMP_COMPONENT_ACL, DUMP_COMPONENT_DATA, DUMP_COMPONENT_DEFINITION, DUMP_COMPONENT_NONE, DUMP_COMPONENTS_REQUIRING_LOCK, ExecuteSqlQuery(), ExecuteSqlStatement(), findNamespace(), fmtQualifiedDumpable, _tableInfo::forcerowsec, _tableInfo::foreign_server, _tableInfo::frozenxid, GetConnection(), getRoleName(), _tableInfo::hascolumnACLs, _tableInfo::hasindex, _tableInfo::hasoids, _tableInfo::hasrules, _tableInfo::hastriggers, i, if(), _dumpableAcl::initprivs, _tableInfo::interesting, InvalidOid, _tableInfo::is_identity_sequence, _tableInfo::ispartition, PQExpBufferData::len, _dumpOptions::lockWaitTimeout, _tableInfo::minmxid, _dumpableObject::name, _tableInfo::ncheck, _dumpableObject::objType, CatalogId::oid, _tableInfo::owning_col, _tableInfo::owning_tab, pg_malloc0(), pg_strdup(), PGRES_TUPLES_OK, _tableInfo::postponed_def, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, _tableInfo::relispopulated, _tableInfo::relkind, _tableInfo::reloftype, _tableInfo::reloptions, _tableInfo::relpages, _tableInfo::relpersistence, _tableInfo::relreplident, _tableInfo::reltablespace, _tableInfo::reltype, Archive::remoteVersion, res, resetPQExpBuffer(), _tableInfo::rolname, _tableInfo::rowsec, selectDumpableTable(), CatalogId::tableoid, _tableInfo::toast_frozenxid, _tableInfo::toast_minmxid, _tableInfo::toast_oid, _tableInfo::toast_reloptions, and _tableInfo::toastpages.

Referenced by getSchemaData().

◆ getTransforms()

void getTransforms ( Archive fout)

Definition at line 8652 of file pg_dump.c.

8653 {
8654  PGresult *res;
8655  int ntups;
8656  int i;
8657  PQExpBuffer query;
8658  TransformInfo *transforminfo;
8659  int i_tableoid;
8660  int i_oid;
8661  int i_trftype;
8662  int i_trflang;
8663  int i_trffromsql;
8664  int i_trftosql;
8665 
8666  /* Transforms didn't exist pre-9.5 */
8667  if (fout->remoteVersion < 90500)
8668  return;
8669 
8670  query = createPQExpBuffer();
8671 
8672  appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8673  "trftype, trflang, trffromsql::oid, trftosql::oid "
8674  "FROM pg_transform "
8675  "ORDER BY 3,4");
8676 
8677  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8678 
8679  ntups = PQntuples(res);
8680 
8681  transforminfo = (TransformInfo *) pg_malloc(ntups * sizeof(TransformInfo));
8682 
8683  i_tableoid = PQfnumber(res, "tableoid");
8684  i_oid = PQfnumber(res, "oid");
8685  i_trftype = PQfnumber(res, "trftype");
8686  i_trflang = PQfnumber(res, "trflang");
8687  i_trffromsql = PQfnumber(res, "trffromsql");
8688  i_trftosql = PQfnumber(res, "trftosql");
8689 
8690  for (i = 0; i < ntups; i++)
8691  {
8692  PQExpBufferData namebuf;
8693  TypeInfo *typeInfo;
8694  char *lanname;
8695 
8696  transforminfo[i].dobj.objType = DO_TRANSFORM;
8697  transforminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8698  transforminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8699  AssignDumpId(&transforminfo[i].dobj);
8700  transforminfo[i].trftype = atooid(PQgetvalue(res, i, i_trftype));
8701  transforminfo[i].trflang = atooid(PQgetvalue(res, i, i_trflang));
8702  transforminfo[i].trffromsql = atooid(PQgetvalue(res, i, i_trffromsql));
8703  transforminfo[i].trftosql = atooid(PQgetvalue(res, i, i_trftosql));
8704 
8705  /*
8706  * Try to name transform as concatenation of type and language name.
8707  * This is only used for purposes of sorting. If we fail to find
8708  * either, the name will be an empty string.
8709  */
8710  initPQExpBuffer(&namebuf);
8711  typeInfo = findTypeByOid(transforminfo[i].trftype);
8712  lanname = get_language_name(fout, transforminfo[i].trflang);
8713  if (typeInfo && lanname)
8714  appendPQExpBuffer(&namebuf, "%s %s",
8715  typeInfo->dobj.name, lanname);
8716  transforminfo[i].dobj.name = namebuf.data;
8717  free(lanname);
8718 
8719  /* Decide whether we want to dump it */
8720  selectDumpableObject(&(transforminfo[i].dobj), fout);
8721  }
8722 
8723  PQclear(res);
8724 
8725  destroyPQExpBuffer(query);
8726 }
static char * get_language_name(Archive *fout, Oid langid)
Definition: pg_dump.c:8631
DumpableObject dobj
Definition: pg_dump.h:510
Oid trffromsql
Definition: pg_dump.h:513

References appendPQExpBuffer(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TRANSFORM, _typeInfo::dobj, _transformInfo::dobj, ExecuteSqlQuery(), findTypeByOid(), free, get_language_name(), i, initPQExpBuffer(), _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, selectDumpableObject(), CatalogId::tableoid, _transformInfo::trffromsql, _transformInfo::trflang, _transformInfo::trftosql, and _transformInfo::trftype.

Referenced by getSchemaData().

◆ getTriggers()

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

Definition at line 8184 of file pg_dump.c.

8185 {
8186  PQExpBuffer query = createPQExpBuffer();
8187  PQExpBuffer tbloids = createPQExpBuffer();
8188  PGresult *res;
8189  int ntups;
8190  int curtblindx;
8191  TriggerInfo *tginfo;
8192  int i_tableoid,
8193  i_oid,
8194  i_tgrelid,
8195  i_tgname,
8196  i_tgenabled,
8197  i_tgispartition,
8198  i_tgdef;
8199 
8200  /*
8201  * We want to perform just one query against pg_trigger. However, we
8202  * mustn't try to select every row of the catalog and then sort it out on
8203  * the client side, because some of the server-side functions we need
8204  * would be unsafe to apply to tables we don't have lock on. Hence, we
8205  * build an array of the OIDs of tables we care about (and now have lock
8206  * on!), and use a WHERE clause to constrain which rows are selected.
8207  */
8208  appendPQExpBufferChar(tbloids, '{');
8209  for (int i = 0; i < numTables; i++)
8210  {
8211  TableInfo *tbinfo = &tblinfo[i];
8212 
8213  if (!tbinfo->hastriggers ||
8214  !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
8215  continue;
8216 
8217  /* OK, we need info for this table */
8218  if (tbloids->len > 1) /* do we have more than the '{'? */
8219  appendPQExpBufferChar(tbloids, ',');
8220  appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
8221  }
8222  appendPQExpBufferChar(tbloids, '}');
8223 
8224  if (fout->remoteVersion >= 150000)
8225  {
8226  /*
8227  * NB: think not to use pretty=true in pg_get_triggerdef. It could
8228  * result in non-forward-compatible dumps of WHEN clauses due to
8229  * under-parenthesization.
8230  *
8231  * NB: We need to see partition triggers in case the tgenabled flag
8232  * has been changed from the parent.
8233  */
8234  appendPQExpBuffer(query,
8235  "SELECT t.tgrelid, t.tgname, "
8236  "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8237  "t.tgenabled, t.tableoid, t.oid, "
8238  "t.tgparentid <> 0 AS tgispartition\n"
8239  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8240  "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8241  "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8242  "WHERE ((NOT t.tgisinternal AND t.tgparentid = 0) "
8243  "OR t.tgenabled != u.tgenabled) "
8244  "ORDER BY t.tgrelid, t.tgname",
8245  tbloids->data);
8246  }
8247  else if (fout->remoteVersion >= 130000)
8248  {
8249  /*
8250  * NB: think not to use pretty=true in pg_get_triggerdef. It could
8251  * result in non-forward-compatible dumps of WHEN clauses due to
8252  * under-parenthesization.
8253  *
8254  * NB: We need to see tgisinternal triggers in partitions, in case the
8255  * tgenabled flag has been changed from the parent.
8256  */
8257  appendPQExpBuffer(query,
8258  "SELECT t.tgrelid, t.tgname, "
8259  "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8260  "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
8261  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8262  "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8263  "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8264  "WHERE (NOT t.tgisinternal OR t.tgenabled != u.tgenabled) "
8265  "ORDER BY t.tgrelid, t.tgname",
8266  tbloids->data);
8267  }
8268  else if (fout->remoteVersion >= 110000)
8269  {
8270  /*
8271  * NB: We need to see tgisinternal triggers in partitions, in case the
8272  * tgenabled flag has been changed from the parent. No tgparentid in
8273  * version 11-12, so we have to match them via pg_depend.
8274  *
8275  * See above about pretty=true in pg_get_triggerdef.
8276  */
8277  appendPQExpBuffer(query,
8278  "SELECT t.tgrelid, t.tgname, "
8279  "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8280  "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
8281  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8282  "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8283  "LEFT JOIN pg_catalog.pg_depend AS d ON "
8284  " d.classid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8285  " d.refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8286  " d.objid = t.oid "
8287  "LEFT JOIN pg_catalog.pg_trigger AS pt ON pt.oid = refobjid "
8288  "WHERE (NOT t.tgisinternal OR t.tgenabled != pt.tgenabled) "
8289  "ORDER BY t.tgrelid, t.tgname",
8290  tbloids->data);
8291  }
8292  else
8293  {
8294  /* See above about pretty=true in pg_get_triggerdef */
8295  appendPQExpBuffer(query,
8296  "SELECT t.tgrelid, t.tgname, "
8297  "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8298  "t.tgenabled, false as tgispartition, "
8299  "t.tableoid, t.oid "
8300  "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8301  "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8302  "WHERE NOT tgisinternal "
8303  "ORDER BY t.tgrelid, t.tgname",
8304  tbloids->data);
8305  }
8306 
8307  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8308 
8309  ntups = PQntuples(res);
8310 
8311  i_tableoid = PQfnumber(res, "tableoid");
8312  i_oid = PQfnumber(res, "oid");
8313  i_tgrelid = PQfnumber(res, "tgrelid");
8314  i_tgname = PQfnumber(res, "tgname");
8315  i_tgenabled = PQfnumber(res, "tgenabled");
8316  i_tgispartition = PQfnumber(res, "tgispartition");
8317  i_tgdef = PQfnumber(res, "tgdef");
8318 
8319  tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(TriggerInfo));
8320 
8321  /*
8322  * Outer loop iterates once per table, not once per row. Incrementing of
8323  * j is handled by the inner loop.
8324  */
8325  curtblindx = -1;
8326  for (int j = 0; j < ntups;)
8327  {
8328  Oid tgrelid = atooid(PQgetvalue(res, j, i_tgrelid));
8329  TableInfo *tbinfo = NULL;
8330  int numtrigs;
8331 
8332  /* Count rows for this table */
8333  for (numtrigs = 1; numtrigs < ntups - j; numtrigs++)
8334  if (atooid(PQgetvalue(res, j + numtrigs, i_tgrelid)) != tgrelid)
8335  break;
8336 
8337  /*
8338  * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8339  * order.
8340  */
8341  while (++curtblindx < numTables)
8342  {
8343  tbinfo = &tblinfo[curtblindx];
8344  if (tbinfo->dobj.catId.oid == tgrelid)
8345  break;
8346  }
8347  if (curtblindx >= numTables)
8348  pg_fatal("unrecognized table OID %u", tgrelid);
8349 
8350  /* Save data for this table */
8351  tbinfo->triggers = tginfo + j;
8352  tbinfo->numTriggers = numtrigs;
8353 
8354  for (int c = 0; c < numtrigs; c++, j++)
8355  {
8356  tginfo[j].dobj.objType = DO_TRIGGER;
8357  tginfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
8358  tginfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
8359  AssignDumpId(&tginfo[j].dobj);
8360  tginfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_tgname));
8361  tginfo[j].dobj.namespace = tbinfo->dobj.namespace;
8362  tginfo[j].tgtable = tbinfo;
8363  tginfo[j].tgenabled = *(PQgetvalue(res, j, i_tgenabled));
8364  tginfo[j].tgispartition = *(PQgetvalue(res, j, i_tgispartition)) == 't';
8365  tginfo[j].tgdef = pg_strdup(PQgetvalue(res, j, i_tgdef));
8366  }
8367  }
8368 
8369  PQclear(res);
8370 
8371  destroyPQExpBuffer(query);
8372  destroyPQExpBuffer(tbloids);
8373 }
struct _triggerInfo * triggers
Definition: pg_dump.h:368
int numTriggers
Definition: pg_dump.h:367
TableInfo * tgtable
Definition: pg_dump.h:446
DumpableObject dobj
Definition: pg_dump.h:445
char tgenabled
Definition: pg_dump.h:447
char * tgdef
Definition: pg_dump.h:449
bool tgispartition
Definition: pg_dump.h:448

References appendPQExpBuffer(), appendPQExpBufferChar(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TRIGGER, _tableInfo::dobj, _triggerInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), _tableInfo::hastriggers, i, j, PQExpBufferData::len, _dumpableObject::name, _tableInfo::numTriggers, _dumpableObject::objType, CatalogId::oid, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, res, CatalogId::tableoid, _triggerInfo::tgdef, _triggerInfo::tgenabled, _triggerInfo::tgispartition, _triggerInfo::tgtable, and _tableInfo::triggers.

Referenced by getSchemaData().

◆ getTSConfigurations()

void getTSConfigurations ( Archive fout)

Definition at line 9657 of file pg_dump.c.

9658 {
9659  PGresult *res;
9660  int ntups;
9661  int i;
9662  PQExpBuffer query;
9663  TSConfigInfo *cfginfo;
9664  int i_tableoid;
9665  int i_oid;
9666  int i_cfgname;
9667  int i_cfgnamespace;
9668  int i_cfgowner;
9669  int i_cfgparser;
9670 
9671  query = createPQExpBuffer();
9672 
9673  appendPQExpBufferStr(query, "SELECT tableoid, oid, cfgname, "
9674  "cfgnamespace, cfgowner, cfgparser "
9675  "FROM pg_ts_config");
9676 
9677  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9678 
9679  ntups = PQntuples(res);
9680 
9681  cfginfo = (TSConfigInfo *) pg_malloc(ntups * sizeof(TSConfigInfo));
9682 
9683  i_tableoid = PQfnumber(res, "tableoid");
9684  i_oid = PQfnumber(res, "oid");
9685  i_cfgname = PQfnumber(res, "cfgname");
9686  i_cfgnamespace = PQfnumber(res, "cfgnamespace");
9687  i_cfgowner = PQfnumber(res, "cfgowner");
9688  i_cfgparser = PQfnumber(res, "cfgparser");
9689 
9690  for (i = 0; i < ntups; i++)
9691  {
9692  cfginfo[i].dobj.objType = DO_TSCONFIG;
9693  cfginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9694  cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9695  AssignDumpId(&cfginfo[i].dobj);
9696  cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname));
9697  cfginfo[i].dobj.namespace =
9698  findNamespace(atooid(PQgetvalue(res, i, i_cfgnamespace)));
9699  cfginfo[i].rolname = getRoleName(PQgetvalue(res, i, i_cfgowner));
9700  cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser));
9701 
9702  /* Decide whether we want to dump it */
9703  selectDumpableObject(&(cfginfo[i].dobj), fout);
9704  }
9705 
9706  PQclear(res);
9707 
9708  destroyPQExpBuffer(query);
9709 }
Oid cfgparser
Definition: pg_dump.h:553
DumpableObject dobj
Definition: pg_dump.h:551
const char * rolname
Definition: pg_dump.h:552

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

Referenced by getSchemaData().

◆ getTSDictionaries()

void getTSDictionaries ( Archive fout)

Definition at line 9532 of file pg_dump.c.

9533 {
9534  PGresult *res;
9535  int ntups;
9536  int i;
9537  PQExpBuffer query;
9538  TSDictInfo *dictinfo;
9539  int i_tableoid;
9540  int i_oid;
9541  int i_dictname;
9542  int i_dictnamespace;
9543  int i_dictowner;
9544  int i_dicttemplate;
9545  int i_dictinitoption;
9546 
9547  query = createPQExpBuffer();
9548 
9549  appendPQExpBufferStr(query, "SELECT tableoid, oid, dictname, "
9550  "dictnamespace, dictowner, "
9551  "dicttemplate, dictinitoption "
9552  "FROM pg_ts_dict");
9553 
9554  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9555 
9556  ntups = PQntuples(res);
9557 
9558  dictinfo = (TSDictInfo *) pg_malloc(ntups * sizeof(TSDictInfo));
9559 
9560  i_tableoid = PQfnumber(res, "tableoid");
9561  i_oid = PQfnumber(res, "oid");
9562  i_dictname = PQfnumber(res, "dictname");
9563  i_dictnamespace = PQfnumber(res, "dictnamespace");
9564  i_dictowner = PQfnumber(res, "dictowner");
9565  i_dictinitoption = PQfnumber(res, "dictinitoption");
9566  i_dicttemplate = PQfnumber(res, "dicttemplate");
9567 
9568  for (i = 0; i < ntups; i++)
9569  {
9570  dictinfo[i].dobj.objType = DO_TSDICT;
9571  dictinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9572  dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9573  AssignDumpId(&dictinfo[i].dobj);
9574  dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname));
9575  dictinfo[i].dobj.namespace =
9576  findNamespace(atooid(PQgetvalue(res, i, i_dictnamespace)));
9577  dictinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_dictowner));
9578  dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate));
9579  if (PQgetisnull(res, i, i_dictinitoption))
9580  dictinfo[i].dictinitoption = NULL;
9581  else
9582  dictinfo[i].dictinitoption = pg_strdup(PQgetvalue(res, i, i_dictinitoption));
9583 
9584  /* Decide whether we want to dump it */
9585  selectDumpableObject(&(dictinfo[i].dobj), fout);
9586  }
9587 
9588  PQclear(res);
9589 
9590  destroyPQExpBuffer(query);
9591 }
char * dictinitoption
Definition: pg_dump.h:539
DumpableObject dobj
Definition: pg_dump.h:536
const char * rolname
Definition: pg_dump.h:537
Oid dicttemplate
Definition: pg_dump.h:538

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

Referenced by getSchemaData().

◆ getTSParsers()

void getTSParsers ( Archive fout)

Definition at line 9458 of file pg_dump.c.

9459 {
9460  PGresult *res;
9461  int ntups;
9462  int i;
9463  PQExpBuffer query;
9464  TSParserInfo *prsinfo;
9465  int i_tableoid;
9466  int i_oid;
9467  int i_prsname;
9468  int i_prsnamespace;
9469  int i_prsstart;
9470  int i_prstoken;
9471  int i_prsend;
9472  int i_prsheadline;
9473  int i_prslextype;
9474 
9475  query = createPQExpBuffer();
9476 
9477  /*
9478  * find all text search objects, including builtin ones; we filter out
9479  * system-defined objects at dump-out time.
9480  */
9481 
9482  appendPQExpBufferStr(query, "SELECT tableoid, oid, prsname, prsnamespace, "
9483  "prsstart::oid, prstoken::oid, "
9484  "prsend::oid, prsheadline::oid, prslextype::oid "
9485  "FROM pg_ts_parser");
9486 
9487  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9488 
9489  ntups = PQntuples(res);
9490 
9491  prsinfo = (TSParserInfo *) pg_malloc(ntups * sizeof(TSParserInfo));
9492 
9493  i_tableoid = PQfnumber(res, "tableoid");
9494  i_oid = PQfnumber(res, "oid");
9495  i_prsname = PQfnumber(res, "prsname");
9496  i_prsnamespace = PQfnumber(res, "prsnamespace");
9497  i_prsstart = PQfnumber(res, "prsstart");
9498  i_prstoken = PQfnumber(res, "prstoken");
9499  i_prsend = PQfnumber(res, "prsend");
9500  i_prsheadline = PQfnumber(res, "prsheadline");
9501  i_prslextype = PQfnumber(res, "prslextype");
9502 
9503  for (i = 0; i < ntups; i++)
9504  {
9505  prsinfo[i].dobj.objType = DO_TSPARSER;
9506  prsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9507  prsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9508  AssignDumpId(&prsinfo[i].dobj);
9509  prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname));
9510  prsinfo[i].dobj.namespace =
9511  findNamespace(atooid(PQgetvalue(res, i, i_prsnamespace)));
9512  prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart));
9513  prsinfo[i].prstoken = atooid(PQgetvalue(res, i, i_prstoken));
9514  prsinfo[i].prsend = atooid(PQgetvalue(res, i, i_prsend));
9515  prsinfo[i].prsheadline = atooid(PQgetvalue(res, i, i_prsheadline));
9516  prsinfo[i].prslextype = atooid(PQgetvalue(res, i, i_prslextype));
9517 
9518  /* Decide whether we want to dump it */
9519  selectDumpableObject(&(prsinfo[i].dobj), fout);
9520  }
9521 
9522  PQclear(res);
9523 
9524  destroyPQExpBuffer(query);
9525 }
DumpableObject dobj
Definition: pg_dump.h:526
Oid prstoken
Definition: pg_dump.h:528
Oid prslextype
Definition: pg_dump.h:531
Oid prsheadline
Definition: pg_dump.h:530
Oid prsstart
Definition: pg_dump.h:527
Oid prsend
Definition: pg_dump.h:529

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TSPARSER, _prsInfo::dobj, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _prsInfo::prsend, _prsInfo::prsheadline, _prsInfo::prslextype, _prsInfo::prsstart, _prsInfo::prstoken, res, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getTSTemplates()

void getTSTemplates ( Archive fout)

Definition at line 9598 of file pg_dump.c.

9599 {
9600  PGresult *res;
9601  int ntups;
9602  int i;
9603  PQExpBuffer query;
9604  TSTemplateInfo *tmplinfo;
9605  int i_tableoid;
9606  int i_oid;
9607  int i_tmplname;
9608  int i_tmplnamespace;
9609  int i_tmplinit;
9610  int i_tmpllexize;
9611 
9612  query = createPQExpBuffer();
9613 
9614  appendPQExpBufferStr(query, "SELECT tableoid, oid, tmplname, "
9615  "tmplnamespace, tmplinit::oid, tmpllexize::oid "
9616  "FROM pg_ts_template");
9617 
9618  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9619 
9620  ntups = PQntuples(res);
9621 
9622  tmplinfo = (TSTemplateInfo *) pg_malloc(ntups * sizeof(TSTemplateInfo));
9623 
9624  i_tableoid = PQfnumber(res, "tableoid");
9625  i_oid = PQfnumber(res, "oid");
9626  i_tmplname = PQfnumber(res, "tmplname");
9627  i_tmplnamespace = PQfnumber(res, "tmplnamespace");
9628  i_tmplinit = PQfnumber(res, "tmplinit");
9629  i_tmpllexize = PQfnumber(res, "tmpllexize");
9630 
9631  for (i = 0; i < ntups; i++)
9632  {
9633  tmplinfo[i].dobj.objType = DO_TSTEMPLATE;
9634  tmplinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9635  tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9636  AssignDumpId(&tmplinfo[i].dobj);
9637  tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname));
9638  tmplinfo[i].dobj.namespace =
9639  findNamespace(atooid(PQgetvalue(res, i, i_tmplnamespace)));
9640  tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit));
9641  tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize));
9642 
9643  /* Decide whether we want to dump it */
9644  selectDumpableObject(&(tmplinfo[i].dobj), fout);
9645  }
9646 
9647  PQclear(res);
9648 
9649  destroyPQExpBuffer(query);
9650 }
Oid tmpllexize
Definition: pg_dump.h:546
Oid tmplinit
Definition: pg_dump.h:545
DumpableObject dobj
Definition: pg_dump.h:544

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

Referenced by getSchemaData().

◆ getTypes()

void getTypes ( Archive fout)

Definition at line 5906 of file pg_dump.c.

5907 {
5908  PGresult *res;
5909  int ntups;
5910  int i;
5911  PQExpBuffer query = createPQExpBuffer();
5912  TypeInfo *tyinfo;
5913  ShellTypeInfo *stinfo;
5914  int i_tableoid;
5915  int i_oid;
5916  int i_typname;
5917  int i_typnamespace;
5918  int i_typacl;
5919  int i_acldefault;
5920  int i_typowner;
5921  int i_typelem;
5922  int i_typrelid;
5923  int i_typrelkind;
5924  int i_typtype;
5925  int i_typisdefined;
5926  int i_isarray;
5927  int i_typarray;
5928 
5929  /*
5930  * we include even the built-in types because those may be used as array
5931  * elements by user-defined types
5932  *
5933  * we filter out the built-in types when we dump out the types
5934  *
5935  * same approach for undefined (shell) types and array types
5936  *
5937  * Note: as of 8.3 we can reliably detect whether a type is an
5938  * auto-generated array type by checking the element type's typarray.
5939  * (Before that the test is capable of generating false positives.) We
5940  * still check for name beginning with '_', though, so as to avoid the
5941  * cost of the subselect probe for all standard types. This would have to
5942  * be revisited if the backend ever allows renaming of array types.
5943  */
5944  appendPQExpBufferStr(query, "SELECT tableoid, oid, typname, "
5945  "typnamespace, typacl, "
5946  "acldefault('T', typowner) AS acldefault, "
5947  "typowner, "
5948  "typelem, typrelid, typarray, "
5949  "CASE WHEN typrelid = 0 THEN ' '::\"char\" "
5950  "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, "
5951  "typtype, typisdefined, "
5952  "typname[0] = '_' AND typelem != 0 AND "
5953  "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray "
5954  "FROM pg_type");
5955 
5956  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5957 
5958  ntups = PQntuples(res);
5959 
5960  tyinfo = (TypeInfo *) pg_malloc(ntups * sizeof(TypeInfo));
5961 
5962  i_tableoid = PQfnumber(res, "tableoid");
5963  i_oid = PQfnumber(res, "oid");
5964  i_typname = PQfnumber(res, "typname");
5965  i_typnamespace = PQfnumber(res, "typnamespace");
5966  i_typacl = PQfnumber(res, "typacl");
5967  i_acldefault = PQfnumber(res, "acldefault");
5968  i_typowner = PQfnumber(res, "typowner");
5969  i_typelem = PQfnumber(res, "typelem");
5970  i_typrelid = PQfnumber(res, "typrelid");
5971  i_typrelkind = PQfnumber(res, "typrelkind");
5972  i_typtype = PQfnumber(res, "typtype");
5973  i_typisdefined = PQfnumber(res, "typisdefined");
5974  i_isarray = PQfnumber(res, "isarray");
5975  i_typarray = PQfnumber(res, "typarray");
5976 
5977  for (i = 0; i < ntups; i++)
5978  {
5979  tyinfo[i].dobj.objType = DO_TYPE;
5980  tyinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5981  tyinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5982  AssignDumpId(&tyinfo[i].dobj);
5983  tyinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_typname));
5984  tyinfo[i].dobj.namespace =
5985  findNamespace(atooid(PQgetvalue(res, i, i_typnamespace)));
5986  tyinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_typacl));
5987  tyinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
5988  tyinfo[i].dacl.privtype = 0;
5989  tyinfo[i].dacl.initprivs = NULL;
5990  tyinfo[i].ftypname = NULL; /* may get filled later */
5991  tyinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_typowner));
5992  tyinfo[i].typelem = atooid(PQgetvalue(res, i, i_typelem));
5993  tyinfo[i].typrelid = atooid(PQgetvalue(res, i, i_typrelid));
5994  tyinfo[i].typrelkind = *PQgetvalue(res, i, i_typrelkind);
5995  tyinfo[i].typtype = *PQgetvalue(res, i, i_typtype);
5996  tyinfo[i].shellType = NULL;
5997 
5998  if (strcmp(PQgetvalue(res, i, i_typisdefined), "t") == 0)
5999  tyinfo[i].isDefined = true;
6000  else
6001  tyinfo[i].isDefined = false;
6002 
6003  if (strcmp(PQgetvalue(res, i, i_isarray), "t") == 0)
6004  tyinfo[i].isArray = true;
6005  else
6006  tyinfo[i].isArray = false;
6007 
6008  tyinfo[i].typarray = atooid(PQgetvalue(res, i, i_typarray));
6009 
6010  if (tyinfo[i].typtype == TYPTYPE_MULTIRANGE)
6011  tyinfo[i].isMultirange = true;
6012  else
6013  tyinfo[i].isMultirange = false;
6014 
6015  /* Decide whether we want to dump it */
6016  selectDumpableType(&tyinfo[i], fout);
6017 
6018  /* Mark whether type has an ACL */
6019  if (!PQgetisnull(res, i, i_typacl))
6020  tyinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6021 
6022  /*
6023  * If it's a domain, fetch info about its constraints, if any
6024  */
6025  tyinfo[i].nDomChecks = 0;
6026  tyinfo[i].domChecks = NULL;
6027  if ((tyinfo[i].dobj.dump & DUMP_COMPONENT_DEFINITION) &&
6028  tyinfo[i].typtype == TYPTYPE_DOMAIN)
6029  getDomainConstraints(fout, &(tyinfo[i]));
6030 
6031  /*
6032  * If it's a base type, make a DumpableObject representing a shell
6033  * definition of the type. We will need to dump that ahead of the I/O
6034  * functions for the type. Similarly, range types need a shell
6035  * definition in case they have a canonicalize function.
6036  *
6037  * Note: the shell type doesn't have a catId. You might think it
6038  * should copy the base type's catId, but then it might capture the
6039  * pg_depend entries for the type, which we don't want.
6040  */
6041  if ((tyinfo[i].dobj.dump & DUMP_COMPONENT_DEFINITION) &&
6042  (tyinfo[i].typtype == TYPTYPE_BASE ||
6043  tyinfo[i].typtype == TYPTYPE_RANGE))
6044  {
6045  stinfo = (ShellTypeInfo *) pg_malloc(sizeof(ShellTypeInfo));
6046  stinfo->dobj.objType = DO_SHELL_TYPE;
6047  stinfo->dobj.catId = nilCatalogId;
6048  AssignDumpId(&stinfo->dobj);
6049  stinfo->dobj.name = pg_strdup(tyinfo[i].dobj.name);
6050  stinfo->dobj.namespace = tyinfo[i].dobj.namespace;
6051  stinfo->baseType = &(tyinfo[i]);
6052  tyinfo[i].shellType = stinfo;
6053 
6054  /*
6055  * Initially mark the shell type as not to be dumped. We'll only
6056  * dump it if the I/O or canonicalize functions need to be dumped;
6057  * this is taken care of while sorting dependencies.
6058  */
6059  stinfo->dobj.dump = DUMP_COMPONENT_NONE;
6060  }
6061  }
6062 
6063  PQclear(res);
6064 
6065  destroyPQExpBuffer(query);
6066 }
static const CatalogId nilCatalogId
Definition: pg_dump.c:184
static void getDomainConstraints(Archive *fout, TypeInfo *tyinfo)
Definition: pg_dump.c:7997
static void selectDumpableType(TypeInfo *tyinfo, Archive *fout)
Definition: pg_dump.c:1949
TypeInfo * baseType
Definition: pg_dump.h:220
DumpableObject dobj
Definition: pg_dump.h:218
bool isMultirange
Definition: pg_dump.h:207
struct _constraintInfo * domChecks
Definition: pg_dump.h:213
DumpableAcl dacl
Definition: pg_dump.h:192
bool isDefined
Definition: pg_dump.h:208
char * ftypname
Definition: pg_dump.h:199
char typrelkind
Definition: pg_dump.h:204
Oid typarray
Definition: pg_dump.h:203
Oid typelem
Definition: pg_dump.h:201
struct _shellTypeInfo * shellType
Definition: pg_dump.h:210
int nDomChecks
Definition: pg_dump.h:212
char typtype
Definition: pg_dump.h:205
const char * rolname
Definition: pg_dump.h:200
Oid typrelid
Definition: pg_dump.h:202
bool isArray
Definition: pg_dump.h:206

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBufferStr(), AssignDumpId(), atooid, _shellTypeInfo::baseType, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _typeInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_SHELL_TYPE, DO_TYPE, _typeInfo::dobj, _shellTypeInfo::dobj, _typeInfo::domChecks, _dumpableObject::dump, DUMP_COMPONENT_ACL, DUMP_COMPONENT_DEFINITION, DUMP_COMPONENT_NONE, ExecuteSqlQuery(), findNamespace(), _typeInfo::ftypname, getDomainConstraints(), getRoleName(), i, _dumpableAcl::initprivs, _typeInfo::isArray, _typeInfo::isDefined, _typeInfo::isMultirange, _dumpableObject::name, _typeInfo::nDomChecks, nilCatalogId, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _dumpableAcl::privtype, res, _typeInfo::rolname, selectDumpableType(), _typeInfo::shellType, CatalogId::tableoid, _typeInfo::typarray, _typeInfo::typelem, _typeInfo::typrelid, _typeInfo::typrelkind, and _typeInfo::typtype.

Referenced by getSchemaData().

◆ parseOidArray()

void parseOidArray ( const char *  str,
Oid array,
int  arraysize 
)

Definition at line 1070 of file common.c.

1071 {
1072  int j,
1073  argNum;
1074  char temp[100];
1075  char s;
1076 
1077  argNum = 0;
1078  j = 0;
1079  for (;;)
1080  {
1081  s = *str++;
1082  if (s == ' ' || s == '\0')
1083  {
1084  if (j > 0)
1085  {
1086  if (argNum >= arraysize)
1087  pg_fatal("could not parse numeric array \"%s\": too many numbers", str);
1088  temp[j] = '\0';
1089  array[argNum++] = atooid(temp);
1090  j = 0;
1091  }
1092  if (s == '\0')
1093  break;
1094  }
1095  else
1096  {
1097  if (!(isdigit((unsigned char) s) || s == '-') ||
1098  j >= sizeof(temp) - 1)
1099  pg_fatal("could not parse numeric array \"%s\": invalid character in number", str);
1100  temp[j++] = s;
1101  }
1102  }
1103 
1104  while (argNum < arraysize)
1105  array[argNum++] = InvalidOid;
1106 }
const char * str

References atooid, InvalidOid, j, pg_fatal, and str.

Referenced by dumpFunc(), getAggregates(), getFuncs(), and getIndexes().

◆ processExtensionTables()

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

Definition at line 18512 of file pg_dump.c.

18514 {
18515  DumpOptions *dopt = fout->dopt;
18516  PQExpBuffer query;
18517  PGresult *res;
18518  int ntups,
18519  i;
18520  int i_conrelid,
18521  i_confrelid;
18522 
18523  /* Nothing to do if no extensions */
18524  if (numExtensions == 0)
18525  return;
18526 
18527  /*
18528  * Identify extension configuration tables and create TableDataInfo
18529  * objects for them, ensuring their data will be dumped even though the
18530  * tables themselves won't be.
18531  *
18532  * Note that we create TableDataInfo objects even in schemaOnly mode, ie,
18533  * user data in a configuration table is treated like schema data. This
18534  * seems appropriate since system data in a config table would get
18535  * reloaded by CREATE EXTENSION. If the extension is not listed in the
18536  * list of extensions to be included, none of its data is dumped.
18537  */
18538  for (i = 0; i < numExtensions; i++)
18539  {
18540  ExtensionInfo *curext = &(extinfo[i]);
18541  char *extconfig = curext->extconfig;
18542  char *extcondition = curext->extcondition;
18543  char **extconfigarray = NULL;
18544  char **extconditionarray = NULL;
18545  int nconfigitems = 0;
18546  int nconditionitems = 0;
18547 
18548  /*
18549  * Check if this extension is listed as to include in the dump. If
18550  * not, any table data associated with it is discarded.
18551  */
18552  if (extension_include_oids.head != NULL &&
18554  curext->dobj.catId.oid))
18555  continue;
18556 
18557  /*
18558  * Check if this extension is listed as to exclude in the dump. If
18559  * yes, any table data associated with it is discarded.
18560  */
18561  if (extension_exclude_oids.head != NULL &&
18563  curext->dobj.catId.oid))
18564  continue;
18565 
18566  if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
18567  {
18568  int j;
18569 
18570  if (!parsePGArray(extconfig, &extconfigarray, &nconfigitems))
18571  pg_fatal("could not parse %s array", "extconfig");
18572  if (!parsePGArray(extcondition, &extconditionarray, &nconditionitems))
18573  pg_fatal("could not parse %s array", "extcondition");
18574  if (nconfigitems != nconditionitems)
18575  pg_fatal("mismatched number of configurations and conditions for extension");
18576 
18577  for (j = 0; j < nconfigitems; j++)
18578  {
18579  TableInfo *configtbl;
18580  Oid configtbloid = atooid(extconfigarray[j]);
18581  bool dumpobj =
18583 
18584  configtbl = findTableByOid(configtbloid);
18585  if (configtbl == NULL)
18586  continue;
18587 
18588  /*
18589  * Tables of not-to-be-dumped extensions shouldn't be dumped
18590  * unless the table or its schema is explicitly included
18591  */
18592  if (!(curext->dobj.dump & DUMP_COMPONENT_DEFINITION))
18593  {
18594  /* check table explicitly requested */
18595  if (table_include_oids.head != NULL &&
18597  configtbloid))
18598  dumpobj = true;
18599 
18600  /* check table's schema explicitly requested */
18601  if (configtbl->dobj.namespace->dobj.dump &
18603  dumpobj = true;
18604  }
18605 
18606  /* check table excluded by an exclusion switch */
18607  if (table_exclude_oids.head != NULL &&
18609  configtbloid))
18610  dumpobj = false;
18611 
18612  /* check schema excluded by an exclusion switch */
18614  configtbl->dobj.namespace->dobj.catId.oid))
18615  dumpobj = false;
18616 
18617  if (dumpobj)
18618  {
18619  makeTableDataInfo(dopt, configtbl);
18620  if (configtbl->dataObj != NULL)
18621  {
18622  if (strlen(extconditionarray[j]) > 0)
18623  configtbl->dataObj->filtercond = pg_strdup(extconditionarray[j]);
18624  }
18625  }
18626  }
18627  }
18628  if (extconfigarray)
18629  free(extconfigarray);
18630  if (extconditionarray)
18631  free(extconditionarray);
18632  }
18633 
18634  /*
18635  * Now that all the TableDataInfo objects have been created for all the
18636  * extensions, check their FK dependencies and register them to try and
18637  * dump the data out in an order that they can be restored in.
18638  *
18639  * Note that this is not a problem for user tables as their FKs are
18640  * recreated after the data has been loaded.
18641  */
18642 
18643  query = createPQExpBuffer();
18644 
18645  printfPQExpBuffer(query,
18646  "SELECT conrelid, confrelid "
18647  "FROM pg_constraint "
18648  "JOIN pg_depend ON (objid = confrelid) "
18649  "WHERE contype = 'f' "
18650  "AND refclassid = 'pg_extension'::regclass "
18651  "AND classid = 'pg_class'::regclass;");
18652 
18653  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
18654  ntups = PQntuples(res);
18655 
18656  i_conrelid = PQfnumber(res, "conrelid");
18657  i_confrelid = PQfnumber(res, "confrelid");
18658 
18659  /* Now get the dependencies and register them */
18660  for (i = 0; i < ntups; i++)
18661  {
18662  Oid conrelid,
18663  confrelid;
18664  TableInfo *reftable,
18665  *contable;
18666 
18667  conrelid = atooid(PQgetvalue(res, i, i_conrelid));
18668  confrelid = atooid(PQgetvalue(res, i, i_confrelid));
18669  contable = findTableByOid(conrelid);
18670  reftable = findTableByOid(confrelid);
18671 
18672  if (reftable == NULL ||
18673  reftable->dataObj == NULL ||
18674  contable == NULL ||
18675  contable->dataObj == NULL)
18676  continue;
18677 
18678  /*
18679  * Make referencing TABLE_DATA object depend on the referenced table's
18680  * TABLE_DATA object.
18681  */
18682  addObjectDependency(&contable->dataObj->dobj,
18683  reftable->dataObj->dobj.dumpId);
18684  }
18685  PQclear(res);
18686  destroyPQExpBuffer(query);
18687 }
static SimpleOidList schema_exclude_oids
Definition: pg_dump.c:163
static SimpleOidList extension_include_oids
Definition: pg_dump.c:179
static SimpleOidList extension_exclude_oids
Definition: pg_dump.c:182
static void makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo)
Definition: pg_dump.c:2855
static SimpleOidList table_exclude_oids
Definition: pg_dump.c:170
static SimpleOidList table_include_oids
Definition: pg_dump.c:167
bool simple_oid_list_member(SimpleOidList *list, Oid val)
Definition: simple_list.c:45
SimpleOidListCell * head
Definition: simple_list.h:28
DumpableObject dobj
Definition: pg_dump.h:389
char * filtercond
Definition: pg_dump.h:391
struct _tableDataInfo * dataObj
Definition: pg_dump.h:366

References addObjectDependency(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, _tableInfo::dataObj, destroyPQExpBuffer(), _extensionInfo::dobj, _tableInfo::dobj, _tableDataInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_DATA, DUMP_COMPONENT_DEFINITION, _dumpableObject::dumpId, ExecuteSqlQuery(), _extensionInfo::extcondition, _extensionInfo::extconfig, extension_exclude_oids, extension_include_oids, _tableDataInfo::filtercond, findTableByOid(), free, SimpleOidList::head, i, j, makeTableDataInfo(), CatalogId::oid, parsePGArray(), pg_fatal, pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), res, schema_exclude_oids, simple_oid_list_member(), table_exclude_oids, and table_include_oids.

Referenced by getSchemaData().

◆ recordAdditionalCatalogID()

void recordAdditionalCatalogID ( CatalogId  catId,
DumpableObject dobj 
)

Definition at line 696 of file common.c.

697 {
698  CatalogIdMapEntry *entry;
699  bool found;
700 
701  /* CatalogId hash table must exist, if we have a DumpableObject */
702  Assert(catalogIdHash != NULL);
703 
704  /* Add reference to CatalogId hash */
705  entry = catalogid_insert(catalogIdHash, catId, &found);
706  if (!found)
707  {
708  entry->dobj = NULL;
709  entry->ext = NULL;
710  }
711  Assert(entry->dobj == NULL);
712  entry->dobj = dobj;
713 }

References Assert, catalogIdHash, _catalogIdMapEntry::dobj, and _catalogIdMapEntry::ext.

Referenced by getLOs().

◆ recordExtensionMembership()

void recordExtensionMembership ( CatalogId  catId,
ExtensionInfo ext 
)

Definition at line 1022 of file common.c.

1023 {
1024  CatalogIdMapEntry *entry;
1025  bool found;
1026 
1027  /* CatalogId hash table must exist, if we have an ExtensionInfo */
1028  Assert(catalogIdHash != NULL);
1029 
1030  /* Add reference to CatalogId hash */
1031  entry = catalogid_insert(catalogIdHash, catId, &found);
1032  if (!found)
1033  {
1034  entry->dobj = NULL;
1035  entry->ext = NULL;
1036  }
1037  Assert(entry->ext == NULL);
1038  entry->ext = ext;
1039 }

References Assert, catalogIdHash, _catalogIdMapEntry::dobj, and _catalogIdMapEntry::ext.

Referenced by getExtensionMembership().

◆ removeObjectDependency()

void removeObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

◆ shouldPrintColumn()

bool shouldPrintColumn ( const DumpOptions dopt,
const TableInfo tbinfo,
int  colno 
)

Definition at line 9443 of file pg_dump.c.

9444 {
9445  if (dopt->binary_upgrade)
9446  return true;
9447  if (tbinfo->attisdropped[colno])
9448  return false;
9449  return (tbinfo->attislocal[colno] || tbinfo->ispartition);
9450 }

References _tableInfo::attisdropped, _tableInfo::attislocal, _dumpOptions::binary_upgrade, and _tableInfo::ispartition.

Referenced by dumpTableSchema(), flagInhAttrs(), and getTableAttrs().

◆ sortDumpableObjects()

void sortDumpableObjects ( DumpableObject **  objs,
int  numObjs,
DumpId  preBoundaryId,
DumpId  postBoundaryId 
)

Definition at line 332 of file pg_dump_sort.c.

334 {
335  DumpableObject **ordering;
336  int nOrdering;
337 
338  if (numObjs <= 0) /* can't happen anymore ... */
339  return;
340 
341  /*
342  * Saving the boundary IDs in static variables is a bit grotty, but seems
343  * better than adding them to parameter lists of subsidiary functions.
344  */
345  preDataBoundId = preBoundaryId;
346  postDataBoundId = postBoundaryId;
347 
348  ordering = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *));
349  while (!TopoSort(objs, numObjs, ordering, &nOrdering))
350  findDependencyLoops(ordering, nOrdering, numObjs);
351 
352  memcpy(objs, ordering, numObjs * sizeof(DumpableObject *));
353 
354  free(ordering);
355 }
static void findDependencyLoops(DumpableObject **objs, int nObjs, int totObjs)
Definition: pg_dump_sort.c:533
static DumpId preDataBoundId
Definition: pg_dump_sort.c:158
static bool TopoSort(DumpableObject **objs, int numObjs, DumpableObject **ordering, int *nOrdering)
Definition: pg_dump_sort.c:384
static DumpId postDataBoundId
Definition: pg_dump_sort.c:159

References findDependencyLoops(), free, pg_malloc(), postDataBoundId, preDataBoundId, and TopoSort().

Referenced by main().

◆ sortDumpableObjectsByTypeName()

void sortDumpableObjectsByTypeName ( DumpableObject **  objs,
int  numObjs 
)

Definition at line 188 of file pg_dump_sort.c.

189 {
190  if (numObjs > 1)
191  qsort(objs, numObjs, sizeof(DumpableObject *),
193 }
static int DOTypeNameCompare(const void *p1, const void *p2)
Definition: pg_dump_sort.c:196
#define qsort(a, b, c, d)
Definition: port.h:447

References DOTypeNameCompare(), and qsort.

Referenced by main().