Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

PostgreSQL Source Code git master
pg_dump.h File Reference
#include "pg_backup.h"
#include "catalog/pg_publication_d.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  _relStatsInfo
 
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 NUM_DUMPABLE_OBJECT_TYPES   (DO_SUBSCRIPTION_REL + 1)
 
#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_STATISTICS   (1 << 7)
 
#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 _relStatsInfo RelStatsInfo
 
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_REL_STATS , 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)
 
AccessMethodInfofindAccessMethodByOid (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 113 of file pg_dump.h.

◆ DUMP_COMPONENT_ALL

#define DUMP_COMPONENT_ALL   (0xFFFF)

Definition at line 117 of file pg_dump.h.

◆ DUMP_COMPONENT_COMMENT

#define DUMP_COMPONENT_COMMENT   (1 << 2)

Definition at line 111 of file pg_dump.h.

◆ DUMP_COMPONENT_DATA

#define DUMP_COMPONENT_DATA   (1 << 1)

Definition at line 110 of file pg_dump.h.

◆ DUMP_COMPONENT_DEFINITION

#define DUMP_COMPONENT_DEFINITION   (1 << 0)

Definition at line 109 of file pg_dump.h.

◆ DUMP_COMPONENT_NONE

#define DUMP_COMPONENT_NONE   (0)

Definition at line 108 of file pg_dump.h.

◆ DUMP_COMPONENT_POLICY

#define DUMP_COMPONENT_POLICY   (1 << 5)

Definition at line 114 of file pg_dump.h.

◆ DUMP_COMPONENT_SECLABEL

#define DUMP_COMPONENT_SECLABEL   (1 << 3)

Definition at line 112 of file pg_dump.h.

◆ DUMP_COMPONENT_STATISTICS

#define DUMP_COMPONENT_STATISTICS   (1 << 7)

Definition at line 116 of file pg_dump.h.

◆ DUMP_COMPONENT_USERMAP

#define DUMP_COMPONENT_USERMAP   (1 << 6)

Definition at line 115 of file pg_dump.h.

◆ DUMP_COMPONENTS_REQUIRING_LOCK

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

Definition at line 141 of file pg_dump.h.

◆ NUM_DUMPABLE_OBJECT_TYPES

#define NUM_DUMPABLE_OBJECT_TYPES   (DO_SUBSCRIPTION_REL + 1)

Definition at line 91 of file pg_dump.h.

◆ oidcmp

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

Definition at line 21 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 107 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

◆ RelStatsInfo

typedef struct _relStatsInfo RelStatsInfo

◆ 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_REL_STATS 
DO_SUBSCRIPTION 
DO_SUBSCRIPTION_REL 

Definition at line 38 of file pg_dump.h.

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

Function Documentation

◆ addObjectDependency()

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

◆ AssignDumpId()

void AssignDumpId ( DumpableObject dobj)

Definition at line 657 of file common.c.

658{
659 dobj->dumpId = ++lastDumpId;
660 dobj->name = NULL; /* must be set later */
661 dobj->namespace = NULL; /* may be set later */
662 dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
663 dobj->dump_contains = DUMP_COMPONENT_ALL; /* default assumption */
664 /* All objects have definitions; we may set more components bits later */
666 dobj->ext_member = false; /* default assumption */
667 dobj->depends_on_ext = false; /* default assumption */
668 dobj->dependencies = NULL;
669 dobj->nDeps = 0;
670 dobj->allocDeps = 0;
671
672 /* Add object to dumpIdMap[], enlarging that array if need be */
673 while (dobj->dumpId >= allocedDumpIds)
674 {
675 int newAlloc;
676
677 if (allocedDumpIds <= 0)
678 {
679 newAlloc = 256;
681 }
682 else
683 {
684 newAlloc = allocedDumpIds * 2;
686 }
687 memset(dumpIdMap + allocedDumpIds, 0,
688 (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
689 allocedDumpIds = newAlloc;
690 }
691 dumpIdMap[dobj->dumpId] = dobj;
692
693 /* If it has a valid CatalogId, enter it into the hash table */
694 if (OidIsValid(dobj->catId.tableoid))
695 {
696 CatalogIdMapEntry *entry;
697 bool found;
698
699 /* Initialize CatalogId hash table if not done yet */
700 if (catalogIdHash == NULL)
701 catalogIdHash = catalogid_create(CATALOGIDHASH_INITIAL_SIZE, NULL);
702
703 entry = catalogid_insert(catalogIdHash, dobj->catId, &found);
704 if (!found)
705 {
706 entry->dobj = NULL;
707 entry->ext = NULL;
708 }
709 Assert(entry->dobj == NULL);
710 entry->dobj = dobj;
711 }
712}
static int allocedDumpIds
Definition: common.c:38
static DumpableObject ** dumpIdMap
Definition: common.c:37
#define CATALOGIDHASH_INITIAL_SIZE
Definition: common.c:80
static catalogid_hash * catalogIdHash
Definition: common.c:82
static DumpId lastDumpId
Definition: common.c:39
#define OidIsValid(objectId)
Definition: c.h:775
Assert(PointerIsAligned(start, uint64))
#define DUMP_COMPONENT_ALL
Definition: pg_dump.h:117
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:109
Oid tableoid
Definition: pg_backup.h:280
ExtensionInfo * ext
Definition: common.c:63
DumpableObject * dobj
Definition: common.c:62
DumpComponents dump
Definition: pg_dump.h:153
char * name
Definition: pg_dump.h:152
DumpId dumpId
Definition: pg_dump.h:151
bool ext_member
Definition: pg_dump.h:157
DumpComponents components
Definition: pg_dump.h:156
CatalogId catId
Definition: pg_dump.h:150
DumpComponents dump_contains
Definition: pg_dump.h:155
bool depends_on_ext
Definition: pg_dump.h:158

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(), getRelationStatistics(), getRules(), getSubscriptions(), getSubscriptionTables(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), and makeTableDataInfo().

◆ createDumpId()

◆ findAccessMethodByOid()

AccessMethodInfo * findAccessMethodByOid ( Oid  oid)

Definition at line 954 of file common.c.

955{
956 CatalogId catId;
957 DumpableObject *dobj;
958
959 catId.tableoid = AccessMethodRelationId;
960 catId.oid = oid;
961 dobj = findObjectByCatalogId(catId);
962 Assert(dobj == NULL || dobj->objType == DO_ACCESS_METHOD);
963 return (AccessMethodInfo *) dobj;
964}
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition: common.c:778
DumpableObjectType objType
Definition: pg_dump.h:149

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

Referenced by accessMethodNameCompare().

◆ findCollationByOid()

CollInfo * findCollationByOid ( Oid  oid)

Definition at line 972 of file common.c.

973{
974 CatalogId catId;
975 DumpableObject *dobj;
976
977 catId.tableoid = CollationRelationId;
978 catId.oid = oid;
979 dobj = findObjectByCatalogId(catId);
980 Assert(dobj == NULL || dobj->objType == DO_COLLATION);
981 return (CollInfo *) dobj;
982}

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

1009{
1010 CatalogId catId;
1011 DumpableObject *dobj;
1012
1013 catId.tableoid = ExtensionRelationId;
1014 catId.oid = oid;
1015 dobj = findObjectByCatalogId(catId);
1016 Assert(dobj == NULL || dobj->objType == DO_EXTENSION);
1017 return (ExtensionInfo *) dobj;
1018}

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

Referenced by getExtensionMembership().

◆ findFuncByOid()

FuncInfo * findFuncByOid ( Oid  oid)

Definition at line 918 of file common.c.

919{
920 CatalogId catId;
921 DumpableObject *dobj;
922
923 catId.tableoid = ProcedureRelationId;
924 catId.oid = oid;
925 dobj = findObjectByCatalogId(catId);
926 Assert(dobj == NULL || dobj->objType == DO_FUNC);
927 return (FuncInfo *) dobj;
928}

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

991{
992 CatalogId catId;
993 DumpableObject *dobj;
994
995 catId.tableoid = NamespaceRelationId;
996 catId.oid = oid;
997 dobj = findObjectByCatalogId(catId);
998 Assert(dobj == NULL || dobj->objType == DO_NAMESPACE);
999 return (NamespaceInfo *) dobj;
1000}

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

779{
780 CatalogIdMapEntry *entry;
781
782 if (catalogIdHash == NULL)
783 return NULL; /* no objects exist yet */
784
785 entry = catalogid_lookup(catalogIdHash, catalogId);
786 if (entry == NULL)
787 return NULL;
788 return entry->dobj;
789}

References catalogIdHash, and _catalogIdMapEntry::dobj.

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

◆ findObjectByDumpId()

DumpableObject * findObjectByDumpId ( DumpId  dumpId)

Definition at line 765 of file common.c.

766{
767 if (dumpId <= 0 || dumpId >= allocedDumpIds)
768 return NULL; /* out of range? */
769 return dumpIdMap[dumpId];
770}

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

937{
938 CatalogId catId;
939 DumpableObject *dobj;
940
941 catId.tableoid = OperatorRelationId;
942 catId.oid = oid;
943 dobj = findObjectByCatalogId(catId);
944 Assert(dobj == NULL || dobj->objType == DO_OPERATOR);
945 return (OprInfo *) dobj;
946}

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

Referenced by getFormattedOperatorName().

◆ findOwningExtension()

ExtensionInfo * findOwningExtension ( CatalogId  catalogId)

Definition at line 1087 of file common.c.

1088{
1089 CatalogIdMapEntry *entry;
1090
1091 if (catalogIdHash == NULL)
1092 return NULL; /* no objects exist yet */
1093
1094 entry = catalogid_lookup(catalogIdHash, catalogId);
1095 if (entry == NULL)
1096 return NULL;
1097 return entry->ext;
1098}

References catalogIdHash, and _catalogIdMapEntry::ext.

Referenced by checkExtensionMembership().

◆ findPublicationByOid()

PublicationInfo * findPublicationByOid ( Oid  oid)

Definition at line 1026 of file common.c.

1027{
1028 CatalogId catId;
1029 DumpableObject *dobj;
1030
1031 catId.tableoid = PublicationRelationId;
1032 catId.oid = oid;
1033 dobj = findObjectByCatalogId(catId);
1034 Assert(dobj == NULL || dobj->objType == DO_PUBLICATION);
1035 return (PublicationInfo *) dobj;
1036}

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

1045{
1046 CatalogId catId;
1047 DumpableObject *dobj;
1048
1049 catId.tableoid = SubscriptionRelationId;
1050 catId.oid = oid;
1051 dobj = findObjectByCatalogId(catId);
1052 Assert(dobj == NULL || dobj->objType == DO_SUBSCRIPTION);
1053 return (SubscriptionInfo *) dobj;
1054}

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

Referenced by getSubscriptionTables().

◆ findTableByOid()

◆ findTypeByOid()

TypeInfo * findTypeByOid ( Oid  oid)

Definition at line 899 of file common.c.

900{
901 CatalogId catId;
902 DumpableObject *dobj;
903
904 catId.tableoid = TypeRelationId;
905 catId.oid = oid;
906 dobj = findObjectByCatalogId(catId);
907 Assert(dobj == NULL ||
908 dobj->objType == DO_TYPE || dobj->objType == DO_DUMMY_TYPE);
909 return (TypeInfo *) dobj;
910}

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(), getCasts(), getFormattedTypeName(), getTransforms(), and pgTypeNameCompare().

◆ getAccessMethods()

void getAccessMethods ( Archive fout)

Definition at line 6543 of file pg_dump.c.

6544{
6545 PGresult *res;
6546 int ntups;
6547 int i;
6548 PQExpBuffer query;
6549 AccessMethodInfo *aminfo;
6550 int i_tableoid;
6551 int i_oid;
6552 int i_amname;
6553 int i_amhandler;
6554 int i_amtype;
6555
6556 query = createPQExpBuffer();
6557
6558 /*
6559 * Select all access methods from pg_am table. v9.6 introduced CREATE
6560 * ACCESS METHOD, so earlier versions usually have only built-in access
6561 * methods. v9.6 also changed the access method API, replacing dozens of
6562 * pg_am columns with amhandler. Even if a user created an access method
6563 * by "INSERT INTO pg_am", we have no way to translate pre-v9.6 pg_am
6564 * columns to a v9.6+ CREATE ACCESS METHOD. Hence, before v9.6, read
6565 * pg_am just to facilitate findAccessMethodByOid() providing the
6566 * OID-to-name mapping.
6567 */
6568 appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, ");
6569 if (fout->remoteVersion >= 90600)
6571 "amtype, "
6572 "amhandler::pg_catalog.regproc AS amhandler ");
6573 else
6575 "'i'::pg_catalog.\"char\" AS amtype, "
6576 "'-'::pg_catalog.regproc AS amhandler ");
6577 appendPQExpBufferStr(query, "FROM pg_am");
6578
6579 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6580
6581 ntups = PQntuples(res);
6582
6583 aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
6584
6585 i_tableoid = PQfnumber(res, "tableoid");
6586 i_oid = PQfnumber(res, "oid");
6587 i_amname = PQfnumber(res, "amname");
6588 i_amhandler = PQfnumber(res, "amhandler");
6589 i_amtype = PQfnumber(res, "amtype");
6590
6591 for (i = 0; i < ntups; i++)
6592 {
6593 aminfo[i].dobj.objType = DO_ACCESS_METHOD;
6594 aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6595 aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6596 AssignDumpId(&aminfo[i].dobj);
6597 aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
6598 aminfo[i].dobj.namespace = NULL;
6599 aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
6600 aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
6601
6602 /* Decide whether we want to dump it */
6603 selectDumpableAccessMethod(&(aminfo[i]), fout);
6604 }
6605
6606 PQclear(res);
6607
6608 destroyPQExpBuffer(query);
6609}
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:657
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3600
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
int i
Definition: isn.c:77
#define PQgetvalue
Definition: libpq-be-fe.h:253
#define PQclear
Definition: libpq-be-fe.h:245
#define PQntuples
Definition: libpq-be-fe.h:251
@ PGRES_TUPLES_OK
Definition: libpq-fe.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:229
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition: pg_dump.c:2234
#define atooid(x)
Definition: postgres_ext.h:43
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:233
char * amhandler
Definition: pg_dump.h:272
DumpableObject dobj
Definition: pg_dump.h:270

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, selectDumpableAccessMethod(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getAggregates()

void getAggregates ( Archive fout)

Definition at line 6745 of file pg_dump.c.

6746{
6747 DumpOptions *dopt = fout->dopt;
6748 PGresult *res;
6749 int ntups;
6750 int i;
6752 AggInfo *agginfo;
6753 int i_tableoid;
6754 int i_oid;
6755 int i_aggname;
6756 int i_aggnamespace;
6757 int i_pronargs;
6758 int i_proargtypes;
6759 int i_proowner;
6760 int i_aggacl;
6761 int i_acldefault;
6762
6763 /*
6764 * Find all interesting aggregates. See comment in getFuncs() for the
6765 * rationale behind the filtering logic.
6766 */
6767 if (fout->remoteVersion >= 90600)
6768 {
6769 const char *agg_check;
6770
6771 agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
6772 : "p.proisagg");
6773
6774 appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
6775 "p.proname AS aggname, "
6776 "p.pronamespace AS aggnamespace, "
6777 "p.pronargs, p.proargtypes, "
6778 "p.proowner, "
6779 "p.proacl AS aggacl, "
6780 "acldefault('f', p.proowner) AS acldefault "
6781 "FROM pg_proc p "
6782 "LEFT JOIN pg_init_privs pip ON "
6783 "(p.oid = pip.objoid "
6784 "AND pip.classoid = 'pg_proc'::regclass "
6785 "AND pip.objsubid = 0) "
6786 "WHERE %s AND ("
6787 "p.pronamespace != "
6788 "(SELECT oid FROM pg_namespace "
6789 "WHERE nspname = 'pg_catalog') OR "
6790 "p.proacl IS DISTINCT FROM pip.initprivs",
6791 agg_check);
6792 if (dopt->binary_upgrade)
6794 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6795 "classid = 'pg_proc'::regclass AND "
6796 "objid = p.oid AND "
6797 "refclassid = 'pg_extension'::regclass AND "
6798 "deptype = 'e')");
6799 appendPQExpBufferChar(query, ')');
6800 }
6801 else
6802 {
6803 appendPQExpBufferStr(query, "SELECT tableoid, oid, proname AS aggname, "
6804 "pronamespace AS aggnamespace, "
6805 "pronargs, proargtypes, "
6806 "proowner, "
6807 "proacl AS aggacl, "
6808 "acldefault('f', proowner) AS acldefault "
6809 "FROM pg_proc p "
6810 "WHERE proisagg AND ("
6811 "pronamespace != "
6812 "(SELECT oid FROM pg_namespace "
6813 "WHERE nspname = 'pg_catalog')");
6814 if (dopt->binary_upgrade)
6816 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6817 "classid = 'pg_proc'::regclass AND "
6818 "objid = p.oid AND "
6819 "refclassid = 'pg_extension'::regclass AND "
6820 "deptype = 'e')");
6821 appendPQExpBufferChar(query, ')');
6822 }
6823
6824 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6825
6826 ntups = PQntuples(res);
6827
6828 agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
6829
6830 i_tableoid = PQfnumber(res, "tableoid");
6831 i_oid = PQfnumber(res, "oid");
6832 i_aggname = PQfnumber(res, "aggname");
6833 i_aggnamespace = PQfnumber(res, "aggnamespace");
6834 i_pronargs = PQfnumber(res, "pronargs");
6835 i_proargtypes = PQfnumber(res, "proargtypes");
6836 i_proowner = PQfnumber(res, "proowner");
6837 i_aggacl = PQfnumber(res, "aggacl");
6838 i_acldefault = PQfnumber(res, "acldefault");
6839
6840 for (i = 0; i < ntups; i++)
6841 {
6842 agginfo[i].aggfn.dobj.objType = DO_AGG;
6843 agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6844 agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6845 AssignDumpId(&agginfo[i].aggfn.dobj);
6846 agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
6847 agginfo[i].aggfn.dobj.namespace =
6848 findNamespace(atooid(PQgetvalue(res, i, i_aggnamespace)));
6849 agginfo[i].aggfn.dacl.acl = pg_strdup(PQgetvalue(res, i, i_aggacl));
6850 agginfo[i].aggfn.dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6851 agginfo[i].aggfn.dacl.privtype = 0;
6852 agginfo[i].aggfn.dacl.initprivs = NULL;
6853 agginfo[i].aggfn.rolname = getRoleName(PQgetvalue(res, i, i_proowner));
6854 agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
6855 agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
6856 agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
6857 if (agginfo[i].aggfn.nargs == 0)
6858 agginfo[i].aggfn.argtypes = NULL;
6859 else
6860 {
6861 agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
6862 parseOidArray(PQgetvalue(res, i, i_proargtypes),
6863 agginfo[i].aggfn.argtypes,
6864 agginfo[i].aggfn.nargs);
6865 }
6866 agginfo[i].aggfn.postponed_def = false; /* might get set during sort */
6867
6868 /* Decide whether we want to dump it */
6869 selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
6870
6871 /* Mark whether aggregate has an ACL */
6872 if (!PQgetisnull(res, i, i_aggacl))
6873 agginfo[i].aggfn.dobj.components |= DUMP_COMPONENT_ACL;
6874 }
6875
6876 PQclear(res);
6877
6878 destroyPQExpBuffer(query);
6879}
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition: common.c:1111
#define PQgetisnull
Definition: libpq-be-fe.h:255
static const char * getRoleName(const char *roleoid_str)
Definition: pg_dump.c:10651
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:2344
static NamespaceInfo * findNamespace(Oid nsoid)
Definition: pg_dump.c:6078
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:113
#define InvalidOid
Definition: postgres_ext.h:37
unsigned int Oid
Definition: postgres_ext.h:32
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:228
int binary_upgrade
Definition: pg_backup.h:174

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, and selectDumpableObject().

Referenced by getSchemaData().

◆ getCasts()

void getCasts ( Archive fout)

Definition at line 9013 of file pg_dump.c.

9014{
9015 PGresult *res;
9016 int ntups;
9017 int i;
9019 CastInfo *castinfo;
9020 int i_tableoid;
9021 int i_oid;
9022 int i_castsource;
9023 int i_casttarget;
9024 int i_castfunc;
9025 int i_castcontext;
9026 int i_castmethod;
9027
9028 if (fout->remoteVersion >= 140000)
9029 {
9030 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9031 "castsource, casttarget, castfunc, castcontext, "
9032 "castmethod "
9033 "FROM pg_cast c "
9034 "WHERE NOT EXISTS ( "
9035 "SELECT 1 FROM pg_range r "
9036 "WHERE c.castsource = r.rngtypid "
9037 "AND c.casttarget = r.rngmultitypid "
9038 ") "
9039 "ORDER BY 3,4");
9040 }
9041 else
9042 {
9043 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9044 "castsource, casttarget, castfunc, castcontext, "
9045 "castmethod "
9046 "FROM pg_cast ORDER BY 3,4");
9047 }
9048
9049 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9050
9051 ntups = PQntuples(res);
9052
9053 castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
9054
9055 i_tableoid = PQfnumber(res, "tableoid");
9056 i_oid = PQfnumber(res, "oid");
9057 i_castsource = PQfnumber(res, "castsource");
9058 i_casttarget = PQfnumber(res, "casttarget");
9059 i_castfunc = PQfnumber(res, "castfunc");
9060 i_castcontext = PQfnumber(res, "castcontext");
9061 i_castmethod = PQfnumber(res, "castmethod");
9062
9063 for (i = 0; i < ntups; i++)
9064 {
9065 PQExpBufferData namebuf;
9066 TypeInfo *sTypeInfo;
9067 TypeInfo *tTypeInfo;
9068
9069 castinfo[i].dobj.objType = DO_CAST;
9070 castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9071 castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9072 AssignDumpId(&castinfo[i].dobj);
9073 castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
9074 castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
9075 castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
9076 castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
9077 castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
9078
9079 /*
9080 * Try to name cast as concatenation of typnames. This is only used
9081 * for purposes of sorting. If we fail to find either type, the name
9082 * will be an empty string.
9083 */
9084 initPQExpBuffer(&namebuf);
9085 sTypeInfo = findTypeByOid(castinfo[i].castsource);
9086 tTypeInfo = findTypeByOid(castinfo[i].casttarget);
9087 if (sTypeInfo && tTypeInfo)
9088 appendPQExpBuffer(&namebuf, "%s %s",
9089 sTypeInfo->dobj.name, tTypeInfo->dobj.name);
9090 castinfo[i].dobj.name = namebuf.data;
9091
9092 /* Decide whether we want to dump it */
9093 selectDumpableCast(&(castinfo[i]), fout);
9094 }
9095
9096 PQclear(res);
9097
9098 destroyPQExpBuffer(query);
9099}
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:899
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition: pg_dump.c:2176
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
char castmethod
Definition: pg_dump.h:549
Oid casttarget
Definition: pg_dump.h:546
char castcontext
Definition: pg_dump.h:548
DumpableObject dobj
Definition: pg_dump.h:544
Oid castsource
Definition: pg_dump.h:545
Oid castfunc
Definition: pg_dump.h:547
DumpableObject dobj
Definition: pg_dump.h:205

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, selectDumpableCast(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getCollations()

void getCollations ( Archive fout)

Definition at line 6415 of file pg_dump.c.

6416{
6417 PGresult *res;
6418 int ntups;
6419 int i;
6420 PQExpBuffer query;
6421 CollInfo *collinfo;
6422 int i_tableoid;
6423 int i_oid;
6424 int i_collname;
6425 int i_collnamespace;
6426 int i_collowner;
6427 int i_collencoding;
6428
6429 query = createPQExpBuffer();
6430
6431 /*
6432 * find all collations, including builtin collations; we filter out
6433 * system-defined collations at dump-out time.
6434 */
6435
6436 appendPQExpBufferStr(query, "SELECT tableoid, oid, collname, "
6437 "collnamespace, "
6438 "collowner, "
6439 "collencoding "
6440 "FROM pg_collation");
6441
6442 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6443
6444 ntups = PQntuples(res);
6445
6446 collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
6447
6448 i_tableoid = PQfnumber(res, "tableoid");
6449 i_oid = PQfnumber(res, "oid");
6450 i_collname = PQfnumber(res, "collname");
6451 i_collnamespace = PQfnumber(res, "collnamespace");
6452 i_collowner = PQfnumber(res, "collowner");
6453 i_collencoding = PQfnumber(res, "collencoding");
6454
6455 for (i = 0; i < ntups; i++)
6456 {
6457 collinfo[i].dobj.objType = DO_COLLATION;
6458 collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6459 collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6460 AssignDumpId(&collinfo[i].dobj);
6461 collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
6462 collinfo[i].dobj.namespace =
6463 findNamespace(atooid(PQgetvalue(res, i, i_collnamespace)));
6464 collinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_collowner));
6465 collinfo[i].collencoding = atoi(PQgetvalue(res, i, i_collencoding));
6466
6467 /* Decide whether we want to dump it */
6468 selectDumpableObject(&(collinfo[i].dobj), fout);
6469 }
6470
6471 PQclear(res);
6472
6473 destroyPQExpBuffer(query);
6474}
int collencoding
Definition: pg_dump.h:293
const char * rolname
Definition: pg_dump.h:292
DumpableObject dobj
Definition: pg_dump.h:291

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _collInfo::collencoding, 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, _collInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getConstraints()

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

Definition at line 8264 of file pg_dump.c.

8265{
8267 PQExpBuffer tbloids = createPQExpBuffer();
8268 PGresult *res;
8269 int ntups;
8270 int curtblindx;
8271 TableInfo *tbinfo = NULL;
8272 ConstraintInfo *constrinfo;
8273 int i_contableoid,
8274 i_conoid,
8275 i_conrelid,
8276 i_conname,
8277 i_confrelid,
8278 i_conindid,
8279 i_condef;
8280
8281 /*
8282 * We want to perform just one query against pg_constraint. However, we
8283 * mustn't try to select every row of the catalog and then sort it out on
8284 * the client side, because some of the server-side functions we need
8285 * would be unsafe to apply to tables we don't have lock on. Hence, we
8286 * build an array of the OIDs of tables we care about (and now have lock
8287 * on!), and use a WHERE clause to constrain which rows are selected.
8288 */
8289 appendPQExpBufferChar(tbloids, '{');
8290 for (int i = 0; i < numTables; i++)
8291 {
8292 TableInfo *tinfo = &tblinfo[i];
8293
8294 if (!(tinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
8295 continue;
8296
8297 /* OK, we need info for this table */
8298 if (tbloids->len > 1) /* do we have more than the '{'? */
8299 appendPQExpBufferChar(tbloids, ',');
8300 appendPQExpBuffer(tbloids, "%u", tinfo->dobj.catId.oid);
8301 }
8302 appendPQExpBufferChar(tbloids, '}');
8303
8305 "SELECT c.tableoid, c.oid, "
8306 "conrelid, conname, confrelid, ");
8307 if (fout->remoteVersion >= 110000)
8308 appendPQExpBufferStr(query, "conindid, ");
8309 else
8310 appendPQExpBufferStr(query, "0 AS conindid, ");
8311 appendPQExpBuffer(query,
8312 "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
8313 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8314 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
8315 "WHERE contype = 'f' ",
8316 tbloids->data);
8317 if (fout->remoteVersion >= 110000)
8319 "AND conparentid = 0 ");
8321 "ORDER BY conrelid, conname");
8322
8323 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8324
8325 ntups = PQntuples(res);
8326
8327 i_contableoid = PQfnumber(res, "tableoid");
8328 i_conoid = PQfnumber(res, "oid");
8329 i_conrelid = PQfnumber(res, "conrelid");
8330 i_conname = PQfnumber(res, "conname");
8331 i_confrelid = PQfnumber(res, "confrelid");
8332 i_conindid = PQfnumber(res, "conindid");
8333 i_condef = PQfnumber(res, "condef");
8334
8335 constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
8336
8337 curtblindx = -1;
8338 for (int j = 0; j < ntups; j++)
8339 {
8340 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
8341 TableInfo *reftable;
8342
8343 /*
8344 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8345 * order.
8346 */
8347 if (tbinfo == NULL || tbinfo->dobj.catId.oid != conrelid)
8348 {
8349 while (++curtblindx < numTables)
8350 {
8351 tbinfo = &tblinfo[curtblindx];
8352 if (tbinfo->dobj.catId.oid == conrelid)
8353 break;
8354 }
8355 if (curtblindx >= numTables)
8356 pg_fatal("unrecognized table OID %u", conrelid);
8357 }
8358
8359 constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
8360 constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
8361 constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
8362 AssignDumpId(&constrinfo[j].dobj);
8363 constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
8364 constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
8365 constrinfo[j].contable = tbinfo;
8366 constrinfo[j].condomain = NULL;
8367 constrinfo[j].contype = 'f';
8368 constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
8369 constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
8370 constrinfo[j].conindex = 0;
8371 constrinfo[j].condeferrable = false;
8372 constrinfo[j].condeferred = false;
8373 constrinfo[j].conislocal = true;
8374 constrinfo[j].separate = true;
8375
8376 /*
8377 * Restoring an FK that points to a partitioned table requires that
8378 * all partition indexes have been attached beforehand. Ensure that
8379 * happens by making the constraint depend on each index partition
8380 * attach object.
8381 */
8382 reftable = findTableByOid(constrinfo[j].confrelid);
8383 if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
8384 {
8385 Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
8386
8387 if (indexOid != InvalidOid)
8388 {
8389 for (int k = 0; k < reftable->numIndexes; k++)
8390 {
8391 IndxInfo *refidx;
8392
8393 /* not our index? */
8394 if (reftable->indexes[k].dobj.catId.oid != indexOid)
8395 continue;
8396
8397 refidx = &reftable->indexes[k];
8398 addConstrChildIdxDeps(&constrinfo[j].dobj, refidx);
8399 break;
8400 }
8401 }
8402 }
8403 }
8404
8405 PQclear(res);
8406
8407 destroyPQExpBuffer(query);
8408 destroyPQExpBuffer(tbloids);
8409}
TableInfo * findTableByOid(Oid oid)
Definition: common.c:863
static const gbtree_vinfo tinfo
Definition: btree_bit.c:108
int j
Definition: isn.c:78
#define pg_fatal(...)
static void addConstrChildIdxDeps(DumpableObject *dobj, const IndxInfo *refidx)
Definition: pg_dump.c:8423
TypeInfo * condomain
Definition: pg_dump.h:519
TableInfo * contable
Definition: pg_dump.h:518
bool condeferred
Definition: pg_dump.h:525
bool conislocal
Definition: pg_dump.h:527
DumpableObject dobj
Definition: pg_dump.h:517
DumpId conindex
Definition: pg_dump.h:523
bool condeferrable
Definition: pg_dump.h:524
char * condef
Definition: pg_dump.h:521
DumpableObject dobj
Definition: pg_dump.h:420
struct _indxInfo * indexes
Definition: pg_dump.h:389
DumpableObject dobj
Definition: pg_dump.h:307
char relkind
Definition: pg_dump.h:310
int numIndexes
Definition: pg_dump.h:388

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, _constraintInfo::separate, CatalogId::tableoid, and tinfo.

Referenced by getSchemaData().

◆ getConversions()

void getConversions ( Archive fout)

Definition at line 6481 of file pg_dump.c.

6482{
6483 PGresult *res;
6484 int ntups;
6485 int i;
6486 PQExpBuffer query;
6487 ConvInfo *convinfo;
6488 int i_tableoid;
6489 int i_oid;
6490 int i_conname;
6491 int i_connamespace;
6492 int i_conowner;
6493
6494 query = createPQExpBuffer();
6495
6496 /*
6497 * find all conversions, including builtin conversions; we filter out
6498 * system-defined conversions at dump-out time.
6499 */
6500
6501 appendPQExpBufferStr(query, "SELECT tableoid, oid, conname, "
6502 "connamespace, "
6503 "conowner "
6504 "FROM pg_conversion");
6505
6506 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6507
6508 ntups = PQntuples(res);
6509
6510 convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
6511
6512 i_tableoid = PQfnumber(res, "tableoid");
6513 i_oid = PQfnumber(res, "oid");
6514 i_conname = PQfnumber(res, "conname");
6515 i_connamespace = PQfnumber(res, "connamespace");
6516 i_conowner = PQfnumber(res, "conowner");
6517
6518 for (i = 0; i < ntups; i++)
6519 {
6520 convinfo[i].dobj.objType = DO_CONVERSION;
6521 convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6522 convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6523 AssignDumpId(&convinfo[i].dobj);
6524 convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
6525 convinfo[i].dobj.namespace =
6526 findNamespace(atooid(PQgetvalue(res, i, i_connamespace)));
6527 convinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_conowner));
6528
6529 /* Decide whether we want to dump it */
6530 selectDumpableObject(&(convinfo[i].dobj), fout);
6531 }
6532
6533 PQclear(res);
6534
6535 destroyPQExpBuffer(query);
6536}
DumpableObject dobj
Definition: pg_dump.h:298
const char * rolname
Definition: pg_dump.h:299

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, _convInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getDefaultACLs()

void getDefaultACLs ( Archive fout)

Definition at line 10554 of file pg_dump.c.

10555{
10556 DumpOptions *dopt = fout->dopt;
10557 DefaultACLInfo *daclinfo;
10558 PQExpBuffer query;
10559 PGresult *res;
10560 int i_oid;
10561 int i_tableoid;
10562 int i_defaclrole;
10563 int i_defaclnamespace;
10564 int i_defaclobjtype;
10565 int i_defaclacl;
10566 int i_acldefault;
10567 int i,
10568 ntups;
10569
10570 query = createPQExpBuffer();
10571
10572 /*
10573 * Global entries (with defaclnamespace=0) replace the hard-wired default
10574 * ACL for their object type. We should dump them as deltas from the
10575 * default ACL, since that will be used as a starting point for
10576 * interpreting the ALTER DEFAULT PRIVILEGES commands. On the other hand,
10577 * non-global entries can only add privileges not revoke them. We must
10578 * dump those as-is (i.e., as deltas from an empty ACL).
10579 *
10580 * We can use defaclobjtype as the object type for acldefault(), except
10581 * for the case of 'S' (DEFACLOBJ_SEQUENCE) which must be converted to
10582 * 's'.
10583 */
10585 "SELECT oid, tableoid, "
10586 "defaclrole, "
10587 "defaclnamespace, "
10588 "defaclobjtype, "
10589 "defaclacl, "
10590 "CASE WHEN defaclnamespace = 0 THEN "
10591 "acldefault(CASE WHEN defaclobjtype = 'S' "
10592 "THEN 's'::\"char\" ELSE defaclobjtype END, "
10593 "defaclrole) ELSE '{}' END AS acldefault "
10594 "FROM pg_default_acl");
10595
10596 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10597
10598 ntups = PQntuples(res);
10599
10600 daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
10601
10602 i_oid = PQfnumber(res, "oid");
10603 i_tableoid = PQfnumber(res, "tableoid");
10604 i_defaclrole = PQfnumber(res, "defaclrole");
10605 i_defaclnamespace = PQfnumber(res, "defaclnamespace");
10606 i_defaclobjtype = PQfnumber(res, "defaclobjtype");
10607 i_defaclacl = PQfnumber(res, "defaclacl");
10608 i_acldefault = PQfnumber(res, "acldefault");
10609
10610 for (i = 0; i < ntups; i++)
10611 {
10612 Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace));
10613
10614 daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
10615 daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10616 daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10617 AssignDumpId(&daclinfo[i].dobj);
10618 /* cheesy ... is it worth coming up with a better object name? */
10619 daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
10620
10621 if (nspid != InvalidOid)
10622 daclinfo[i].dobj.namespace = findNamespace(nspid);
10623 else
10624 daclinfo[i].dobj.namespace = NULL;
10625
10626 daclinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
10627 daclinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10628 daclinfo[i].dacl.privtype = 0;
10629 daclinfo[i].dacl.initprivs = NULL;
10630 daclinfo[i].defaclrole = getRoleName(PQgetvalue(res, i, i_defaclrole));
10631 daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
10632
10633 /* Default ACLs are ACLs, of course */
10634 daclinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10635
10636 /* Decide whether we want to dump it */
10637 selectDumpableDefaultACL(&(daclinfo[i]), dopt);
10638 }
10639
10640 PQclear(res);
10641
10642 destroyPQExpBuffer(query);
10643}
int nspid
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition: pg_dump.c:2154
DumpableObject dobj
Definition: pg_dump.h:623
DumpableAcl dacl
Definition: pg_dump.h:624
const char * defaclrole
Definition: pg_dump.h:625
char defaclobjtype
Definition: pg_dump.h:626
char privtype
Definition: pg_dump.h:173
char * acldefault
Definition: pg_dump.h:171
char * acl
Definition: pg_dump.h:170
char * initprivs
Definition: pg_dump.h:174

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, selectDumpableDefaultACL(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getDumpableObjects()

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

Definition at line 797 of file common.c.

798{
799 int i,
800 j;
801
803 j = 0;
804 for (i = 1; i < allocedDumpIds; i++)
805 {
806 if (dumpIdMap[i])
807 (*objs)[j++] = dumpIdMap[i];
808 }
809 *numObjs = j;
810}

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

Referenced by getTableDataFKConstraints(), and main().

◆ getEventTriggers()

void getEventTriggers ( Archive fout)

Definition at line 8851 of file pg_dump.c.

8852{
8853 int i;
8854 PQExpBuffer query;
8855 PGresult *res;
8856 EventTriggerInfo *evtinfo;
8857 int i_tableoid,
8858 i_oid,
8859 i_evtname,
8860 i_evtevent,
8861 i_evtowner,
8862 i_evttags,
8863 i_evtfname,
8864 i_evtenabled;
8865 int ntups;
8866
8867 /* Before 9.3, there are no event triggers */
8868 if (fout->remoteVersion < 90300)
8869 return;
8870
8871 query = createPQExpBuffer();
8872
8874 "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8875 "evtevent, evtowner, "
8876 "array_to_string(array("
8877 "select quote_literal(x) "
8878 " from unnest(evttags) as t(x)), ', ') as evttags, "
8879 "e.evtfoid::regproc as evtfname "
8880 "FROM pg_event_trigger e "
8881 "ORDER BY e.oid");
8882
8883 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8884
8885 ntups = PQntuples(res);
8886
8887 evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
8888
8889 i_tableoid = PQfnumber(res, "tableoid");
8890 i_oid = PQfnumber(res, "oid");
8891 i_evtname = PQfnumber(res, "evtname");
8892 i_evtevent = PQfnumber(res, "evtevent");
8893 i_evtowner = PQfnumber(res, "evtowner");
8894 i_evttags = PQfnumber(res, "evttags");
8895 i_evtfname = PQfnumber(res, "evtfname");
8896 i_evtenabled = PQfnumber(res, "evtenabled");
8897
8898 for (i = 0; i < ntups; i++)
8899 {
8900 evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
8901 evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8902 evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8903 AssignDumpId(&evtinfo[i].dobj);
8904 evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
8905 evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
8906 evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
8907 evtinfo[i].evtowner = getRoleName(PQgetvalue(res, i, i_evtowner));
8908 evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
8909 evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
8910 evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
8911
8912 /* Decide whether we want to dump it */
8913 selectDumpableObject(&(evtinfo[i].dobj), fout);
8914 }
8915
8916 PQclear(res);
8917
8918 destroyPQExpBuffer(query);
8919}
char * evtevent
Definition: pg_dump.h:498
char * evtfname
Definition: pg_dump.h:501
char evtenabled
Definition: pg_dump.h:502
char * evtname
Definition: pg_dump.h:497
const char * evtowner
Definition: pg_dump.h:499
char * evttags
Definition: pg_dump.h:500
DumpableObject dobj
Definition: pg_dump.h:496

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, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getExtendedStatistics()

void getExtendedStatistics ( Archive fout)

Definition at line 8185 of file pg_dump.c.

8186{
8187 PQExpBuffer query;
8188 PGresult *res;
8189 StatsExtInfo *statsextinfo;
8190 int ntups;
8191 int i_tableoid;
8192 int i_oid;
8193 int i_stxname;
8194 int i_stxnamespace;
8195 int i_stxowner;
8196 int i_stxrelid;
8197 int i_stattarget;
8198 int i;
8199
8200 /* Extended statistics were new in v10 */
8201 if (fout->remoteVersion < 100000)
8202 return;
8203
8204 query = createPQExpBuffer();
8205
8206 if (fout->remoteVersion < 130000)
8207 appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
8208 "stxnamespace, stxowner, stxrelid, NULL AS stxstattarget "
8209 "FROM pg_catalog.pg_statistic_ext");
8210 else
8211 appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
8212 "stxnamespace, stxowner, stxrelid, stxstattarget "
8213 "FROM pg_catalog.pg_statistic_ext");
8214
8215 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8216
8217 ntups = PQntuples(res);
8218
8219 i_tableoid = PQfnumber(res, "tableoid");
8220 i_oid = PQfnumber(res, "oid");
8221 i_stxname = PQfnumber(res, "stxname");
8222 i_stxnamespace = PQfnumber(res, "stxnamespace");
8223 i_stxowner = PQfnumber(res, "stxowner");
8224 i_stxrelid = PQfnumber(res, "stxrelid");
8225 i_stattarget = PQfnumber(res, "stxstattarget");
8226
8227 statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
8228
8229 for (i = 0; i < ntups; i++)
8230 {
8231 statsextinfo[i].dobj.objType = DO_STATSEXT;
8232 statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8233 statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8234 AssignDumpId(&statsextinfo[i].dobj);
8235 statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
8236 statsextinfo[i].dobj.namespace =
8237 findNamespace(atooid(PQgetvalue(res, i, i_stxnamespace)));
8238 statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
8239 statsextinfo[i].stattable =
8240 findTableByOid(atooid(PQgetvalue(res, i, i_stxrelid)));
8241 if (PQgetisnull(res, i, i_stattarget))
8242 statsextinfo[i].stattarget = -1;
8243 else
8244 statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
8245
8246 /* Decide whether we want to dump it */
8247 selectDumpableStatisticsObject(&(statsextinfo[i]), fout);
8248 }
8249
8250 PQclear(res);
8251 destroyPQExpBuffer(query);
8252}
static void selectDumpableStatisticsObject(StatsExtInfo *sobj, Archive *fout)
Definition: pg_dump.c:2326
TableInfo * stattable
Definition: pg_dump.h:470
int stattarget
Definition: pg_dump.h:471
const char * rolname
Definition: pg_dump.h:469
DumpableObject dobj
Definition: pg_dump.h:468

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, _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 19658 of file pg_dump.c.

19660{
19661 PQExpBuffer query;
19662 PGresult *res;
19663 int ntups,
19664 i;
19665 int i_classid,
19666 i_objid,
19667 i_refobjid;
19668 ExtensionInfo *ext;
19669
19670 /* Nothing to do if no extensions */
19671 if (numExtensions == 0)
19672 return;
19673
19674 query = createPQExpBuffer();
19675
19676 /* refclassid constraint is redundant but may speed the search */
19677 appendPQExpBufferStr(query, "SELECT "
19678 "classid, objid, refobjid "
19679 "FROM pg_depend "
19680 "WHERE refclassid = 'pg_extension'::regclass "
19681 "AND deptype = 'e' "
19682 "ORDER BY 3");
19683
19684 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
19685
19686 ntups = PQntuples(res);
19687
19688 i_classid = PQfnumber(res, "classid");
19689 i_objid = PQfnumber(res, "objid");
19690 i_refobjid = PQfnumber(res, "refobjid");
19691
19692 /*
19693 * Since we ordered the SELECT by referenced ID, we can expect that
19694 * multiple entries for the same extension will appear together; this
19695 * saves on searches.
19696 */
19697 ext = NULL;
19698
19699 for (i = 0; i < ntups; i++)
19700 {
19701 CatalogId objId;
19702 Oid extId;
19703
19704 objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
19705 objId.oid = atooid(PQgetvalue(res, i, i_objid));
19706 extId = atooid(PQgetvalue(res, i, i_refobjid));
19707
19708 if (ext == NULL ||
19709 ext->dobj.catId.oid != extId)
19710 ext = findExtensionByOid(extId);
19711
19712 if (ext == NULL)
19713 {
19714 /* shouldn't happen */
19715 pg_log_warning("could not find referenced extension %u", extId);
19716 continue;
19717 }
19718
19719 recordExtensionMembership(objId, ext);
19720 }
19721
19722 PQclear(res);
19723
19724 destroyPQExpBuffer(query);
19725}
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition: common.c:1063
ExtensionInfo * findExtensionByOid(Oid oid)
Definition: common.c:1008
#define pg_log_warning(...)
Definition: pgfnames.c:24
DumpableObject dobj
Definition: pg_dump.h:195

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(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getExtensions()

ExtensionInfo * getExtensions ( Archive fout,
int *  numExtensions 
)

Definition at line 6096 of file pg_dump.c.

6097{
6098 DumpOptions *dopt = fout->dopt;
6099 PGresult *res;
6100 int ntups;
6101 int i;
6102 PQExpBuffer query;
6103 ExtensionInfo *extinfo = NULL;
6104 int i_tableoid;
6105 int i_oid;
6106 int i_extname;
6107 int i_nspname;
6108 int i_extrelocatable;
6109 int i_extversion;
6110 int i_extconfig;
6111 int i_extcondition;
6112
6113 query = createPQExpBuffer();
6114
6115 appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
6116 "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
6117 "FROM pg_extension x "
6118 "JOIN pg_namespace n ON n.oid = x.extnamespace");
6119
6120 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6121
6122 ntups = PQntuples(res);
6123 if (ntups == 0)
6124 goto cleanup;
6125
6126 extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
6127
6128 i_tableoid = PQfnumber(res, "tableoid");
6129 i_oid = PQfnumber(res, "oid");
6130 i_extname = PQfnumber(res, "extname");
6131 i_nspname = PQfnumber(res, "nspname");
6132 i_extrelocatable = PQfnumber(res, "extrelocatable");
6133 i_extversion = PQfnumber(res, "extversion");
6134 i_extconfig = PQfnumber(res, "extconfig");
6135 i_extcondition = PQfnumber(res, "extcondition");
6136
6137 for (i = 0; i < ntups; i++)
6138 {
6139 extinfo[i].dobj.objType = DO_EXTENSION;
6140 extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6141 extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6142 AssignDumpId(&extinfo[i].dobj);
6143 extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
6144 extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
6145 extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
6146 extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
6147 extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
6148 extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
6149
6150 /* Decide whether we want to dump it */
6151 selectDumpableExtension(&(extinfo[i]), dopt);
6152 }
6153
6154cleanup:
6155 PQclear(res);
6156 destroyPQExpBuffer(query);
6157
6158 *numExtensions = ntups;
6159
6160 return extinfo;
6161}
static void cleanup(void)
Definition: bootstrap.c:715
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition: pg_dump.c:2269
bool relocatable
Definition: pg_dump.h:196
char * extversion
Definition: pg_dump.h:198
char * extcondition
Definition: pg_dump.h:200
char * extconfig
Definition: pg_dump.h:199

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, selectDumpableExtension(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getForeignDataWrappers()

void getForeignDataWrappers ( Archive fout)

Definition at line 10382 of file pg_dump.c.

10383{
10384 PGresult *res;
10385 int ntups;
10386 int i;
10387 PQExpBuffer query;
10388 FdwInfo *fdwinfo;
10389 int i_tableoid;
10390 int i_oid;
10391 int i_fdwname;
10392 int i_fdwowner;
10393 int i_fdwhandler;
10394 int i_fdwvalidator;
10395 int i_fdwacl;
10396 int i_acldefault;
10397 int i_fdwoptions;
10398
10399 query = createPQExpBuffer();
10400
10401 appendPQExpBufferStr(query, "SELECT tableoid, oid, fdwname, "
10402 "fdwowner, "
10403 "fdwhandler::pg_catalog.regproc, "
10404 "fdwvalidator::pg_catalog.regproc, "
10405 "fdwacl, "
10406 "acldefault('F', fdwowner) AS acldefault, "
10407 "array_to_string(ARRAY("
10408 "SELECT quote_ident(option_name) || ' ' || "
10409 "quote_literal(option_value) "
10410 "FROM pg_options_to_table(fdwoptions) "
10411 "ORDER BY option_name"
10412 "), E',\n ') AS fdwoptions "
10413 "FROM pg_foreign_data_wrapper");
10414
10415 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10416
10417 ntups = PQntuples(res);
10418
10419 fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
10420
10421 i_tableoid = PQfnumber(res, "tableoid");
10422 i_oid = PQfnumber(res, "oid");
10423 i_fdwname = PQfnumber(res, "fdwname");
10424 i_fdwowner = PQfnumber(res, "fdwowner");
10425 i_fdwhandler = PQfnumber(res, "fdwhandler");
10426 i_fdwvalidator = PQfnumber(res, "fdwvalidator");
10427 i_fdwacl = PQfnumber(res, "fdwacl");
10428 i_acldefault = PQfnumber(res, "acldefault");
10429 i_fdwoptions = PQfnumber(res, "fdwoptions");
10430
10431 for (i = 0; i < ntups; i++)
10432 {
10433 fdwinfo[i].dobj.objType = DO_FDW;
10434 fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10435 fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10436 AssignDumpId(&fdwinfo[i].dobj);
10437 fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
10438 fdwinfo[i].dobj.namespace = NULL;
10439 fdwinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
10440 fdwinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10441 fdwinfo[i].dacl.privtype = 0;
10442 fdwinfo[i].dacl.initprivs = NULL;
10443 fdwinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_fdwowner));
10444 fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
10445 fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
10446 fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
10447
10448 /* Decide whether we want to dump it */
10449 selectDumpableObject(&(fdwinfo[i].dobj), fout);
10450
10451 /* Mark whether FDW has an ACL */
10452 if (!PQgetisnull(res, i, i_fdwacl))
10453 fdwinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10454 }
10455
10456 PQclear(res);
10457
10458 destroyPQExpBuffer(query);
10459}
char * fdwhandler
Definition: pg_dump.h:605
const char * rolname
Definition: pg_dump.h:604
char * fdwvalidator
Definition: pg_dump.h:606
char * fdwoptions
Definition: pg_dump.h:607
DumpableAcl dacl
Definition: pg_dump.h:603
DumpableObject dobj
Definition: pg_dump.h:602

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, _fdwInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getForeignServers()

void getForeignServers ( Archive fout)

Definition at line 10466 of file pg_dump.c.

10467{
10468 PGresult *res;
10469 int ntups;
10470 int i;
10471 PQExpBuffer query;
10472 ForeignServerInfo *srvinfo;
10473 int i_tableoid;
10474 int i_oid;
10475 int i_srvname;
10476 int i_srvowner;
10477 int i_srvfdw;
10478 int i_srvtype;
10479 int i_srvversion;
10480 int i_srvacl;
10481 int i_acldefault;
10482 int i_srvoptions;
10483
10484 query = createPQExpBuffer();
10485
10486 appendPQExpBufferStr(query, "SELECT tableoid, oid, srvname, "
10487 "srvowner, "
10488 "srvfdw, srvtype, srvversion, srvacl, "
10489 "acldefault('S', srvowner) AS acldefault, "
10490 "array_to_string(ARRAY("
10491 "SELECT quote_ident(option_name) || ' ' || "
10492 "quote_literal(option_value) "
10493 "FROM pg_options_to_table(srvoptions) "
10494 "ORDER BY option_name"
10495 "), E',\n ') AS srvoptions "
10496 "FROM pg_foreign_server");
10497
10498 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10499
10500 ntups = PQntuples(res);
10501
10502 srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
10503
10504 i_tableoid = PQfnumber(res, "tableoid");
10505 i_oid = PQfnumber(res, "oid");
10506 i_srvname = PQfnumber(res, "srvname");
10507 i_srvowner = PQfnumber(res, "srvowner");
10508 i_srvfdw = PQfnumber(res, "srvfdw");
10509 i_srvtype = PQfnumber(res, "srvtype");
10510 i_srvversion = PQfnumber(res, "srvversion");
10511 i_srvacl = PQfnumber(res, "srvacl");
10512 i_acldefault = PQfnumber(res, "acldefault");
10513 i_srvoptions = PQfnumber(res, "srvoptions");
10514
10515 for (i = 0; i < ntups; i++)
10516 {
10517 srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
10518 srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10519 srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10520 AssignDumpId(&srvinfo[i].dobj);
10521 srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
10522 srvinfo[i].dobj.namespace = NULL;
10523 srvinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_srvacl));
10524 srvinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10525 srvinfo[i].dacl.privtype = 0;
10526 srvinfo[i].dacl.initprivs = NULL;
10527 srvinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_srvowner));
10528 srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
10529 srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
10530 srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
10531 srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
10532
10533 /* Decide whether we want to dump it */
10534 selectDumpableObject(&(srvinfo[i].dobj), fout);
10535
10536 /* Servers have user mappings */
10538
10539 /* Mark whether server has an ACL */
10540 if (!PQgetisnull(res, i, i_srvacl))
10541 srvinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10542 }
10543
10544 PQclear(res);
10545
10546 destroyPQExpBuffer(query);
10547}
#define DUMP_COMPONENT_USERMAP
Definition: pg_dump.h:115
DumpableAcl dacl
Definition: pg_dump.h:613
char * srvoptions
Definition: pg_dump.h:618
DumpableObject dobj
Definition: pg_dump.h:612
const char * rolname
Definition: pg_dump.h:614
char * srvversion
Definition: pg_dump.h:617

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, _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 6886 of file pg_dump.c.

6887{
6888 DumpOptions *dopt = fout->dopt;
6889 PGresult *res;
6890 int ntups;
6891 int i;
6893 FuncInfo *finfo;
6894 int i_tableoid;
6895 int i_oid;
6896 int i_proname;
6897 int i_pronamespace;
6898 int i_proowner;
6899 int i_prolang;
6900 int i_pronargs;
6901 int i_proargtypes;
6902 int i_prorettype;
6903 int i_proacl;
6904 int i_acldefault;
6905
6906 /*
6907 * Find all interesting functions. This is a bit complicated:
6908 *
6909 * 1. Always exclude aggregates; those are handled elsewhere.
6910 *
6911 * 2. Always exclude functions that are internally dependent on something
6912 * else, since presumably those will be created as a result of creating
6913 * the something else. This currently acts only to suppress constructor
6914 * functions for range types. Note this is OK only because the
6915 * constructors don't have any dependencies the range type doesn't have;
6916 * otherwise we might not get creation ordering correct.
6917 *
6918 * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
6919 * they're members of extensions and we are in binary-upgrade mode then
6920 * include them, since we want to dump extension members individually in
6921 * that mode. Also, if they are used by casts or transforms then we need
6922 * to gather the information about them, though they won't be dumped if
6923 * they are built-in. Also, in 9.6 and up, include functions in
6924 * pg_catalog if they have an ACL different from what's shown in
6925 * pg_init_privs (so we have to join to pg_init_privs; annoying).
6926 */
6927 if (fout->remoteVersion >= 90600)
6928 {
6929 const char *not_agg_check;
6930
6931 not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
6932 : "NOT p.proisagg");
6933
6934 appendPQExpBuffer(query,
6935 "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6936 "p.pronargs, p.proargtypes, p.prorettype, "
6937 "p.proacl, "
6938 "acldefault('f', p.proowner) AS acldefault, "
6939 "p.pronamespace, "
6940 "p.proowner "
6941 "FROM pg_proc p "
6942 "LEFT JOIN pg_init_privs pip ON "
6943 "(p.oid = pip.objoid "
6944 "AND pip.classoid = 'pg_proc'::regclass "
6945 "AND pip.objsubid = 0) "
6946 "WHERE %s"
6947 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6948 "WHERE classid = 'pg_proc'::regclass AND "
6949 "objid = p.oid AND deptype = 'i')"
6950 "\n AND ("
6951 "\n pronamespace != "
6952 "(SELECT oid FROM pg_namespace "
6953 "WHERE nspname = 'pg_catalog')"
6954 "\n OR EXISTS (SELECT 1 FROM pg_cast"
6955 "\n WHERE pg_cast.oid > %u "
6956 "\n AND p.oid = pg_cast.castfunc)"
6957 "\n OR EXISTS (SELECT 1 FROM pg_transform"
6958 "\n WHERE pg_transform.oid > %u AND "
6959 "\n (p.oid = pg_transform.trffromsql"
6960 "\n OR p.oid = pg_transform.trftosql))",
6961 not_agg_check,
6964 if (dopt->binary_upgrade)
6966 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6967 "classid = 'pg_proc'::regclass AND "
6968 "objid = p.oid AND "
6969 "refclassid = 'pg_extension'::regclass AND "
6970 "deptype = 'e')");
6972 "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
6973 appendPQExpBufferChar(query, ')');
6974 }
6975 else
6976 {
6977 appendPQExpBuffer(query,
6978 "SELECT tableoid, oid, proname, prolang, "
6979 "pronargs, proargtypes, prorettype, proacl, "
6980 "acldefault('f', proowner) AS acldefault, "
6981 "pronamespace, "
6982 "proowner "
6983 "FROM pg_proc p "
6984 "WHERE NOT proisagg"
6985 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6986 "WHERE classid = 'pg_proc'::regclass AND "
6987 "objid = p.oid AND deptype = 'i')"
6988 "\n AND ("
6989 "\n pronamespace != "
6990 "(SELECT oid FROM pg_namespace "
6991 "WHERE nspname = 'pg_catalog')"
6992 "\n OR EXISTS (SELECT 1 FROM pg_cast"
6993 "\n WHERE pg_cast.oid > '%u'::oid"
6994 "\n AND p.oid = pg_cast.castfunc)",
6996
6997 if (fout->remoteVersion >= 90500)
6998 appendPQExpBuffer(query,
6999 "\n OR EXISTS (SELECT 1 FROM pg_transform"
7000 "\n WHERE pg_transform.oid > '%u'::oid"
7001 "\n AND (p.oid = pg_transform.trffromsql"
7002 "\n OR p.oid = pg_transform.trftosql))",
7004
7005 if (dopt->binary_upgrade)
7007 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
7008 "classid = 'pg_proc'::regclass AND "
7009 "objid = p.oid AND "
7010 "refclassid = 'pg_extension'::regclass AND "
7011 "deptype = 'e')");
7012 appendPQExpBufferChar(query, ')');
7013 }
7014
7015 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7016
7017 ntups = PQntuples(res);
7018
7019 finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
7020
7021 i_tableoid = PQfnumber(res, "tableoid");
7022 i_oid = PQfnumber(res, "oid");
7023 i_proname = PQfnumber(res, "proname");
7024 i_pronamespace = PQfnumber(res, "pronamespace");
7025 i_proowner = PQfnumber(res, "proowner");
7026 i_prolang = PQfnumber(res, "prolang");
7027 i_pronargs = PQfnumber(res, "pronargs");
7028 i_proargtypes = PQfnumber(res, "proargtypes");
7029 i_prorettype = PQfnumber(res, "prorettype");
7030 i_proacl = PQfnumber(res, "proacl");
7031 i_acldefault = PQfnumber(res, "acldefault");
7032
7033 for (i = 0; i < ntups; i++)
7034 {
7035 finfo[i].dobj.objType = DO_FUNC;
7036 finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7037 finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7038 AssignDumpId(&finfo[i].dobj);
7039 finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
7040 finfo[i].dobj.namespace =
7041 findNamespace(atooid(PQgetvalue(res, i, i_pronamespace)));
7042 finfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_proacl));
7043 finfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
7044 finfo[i].dacl.privtype = 0;
7045 finfo[i].dacl.initprivs = NULL;
7046 finfo[i].rolname = getRoleName(PQgetvalue(res, i, i_proowner));
7047 finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
7048 finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
7049 finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
7050 if (finfo[i].nargs == 0)
7051 finfo[i].argtypes = NULL;
7052 else
7053 {
7054 finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
7055 parseOidArray(PQgetvalue(res, i, i_proargtypes),
7056 finfo[i].argtypes, finfo[i].nargs);
7057 }
7058 finfo[i].postponed_def = false; /* might get set during sort */
7059
7060 /* Decide whether we want to dump it */
7061 selectDumpableObject(&(finfo[i].dobj), fout);
7062
7063 /* Mark whether function has an ACL */
7064 if (!PQgetisnull(res, i, i_proacl))
7066 }
7067
7068 PQclear(res);
7069
7070 destroyPQExpBuffer(query);
7071}
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
static Oid g_last_builtin_oid
Definition: pg_dump.c:152
bool postponed_def
Definition: pg_dump.h:248
Oid lang
Definition: pg_dump.h:244
const char * rolname
Definition: pg_dump.h:243
Oid * argtypes
Definition: pg_dump.h:246
Oid prorettype
Definition: pg_dump.h:247
DumpableObject dobj
Definition: pg_dump.h:241
int nargs
Definition: pg_dump.h:245
DumpableAcl dacl
Definition: pg_dump.h:242

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, _funcInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getIndexes()

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

Definition at line 7816 of file pg_dump.c.

7817{
7819 PQExpBuffer tbloids = createPQExpBuffer();
7820 PGresult *res;
7821 int ntups;
7822 int curtblindx;
7823 IndxInfo *indxinfo;
7824 int i_tableoid,
7825 i_oid,
7826 i_indrelid,
7827 i_indexname,
7828 i_relpages,
7829 i_reltuples,
7830 i_relallvisible,
7831 i_relallfrozen,
7832 i_parentidx,
7833 i_indexdef,
7834 i_indnkeyatts,
7835 i_indnatts,
7836 i_indkey,
7837 i_indisclustered,
7838 i_indisreplident,
7839 i_indnullsnotdistinct,
7840 i_contype,
7841 i_conname,
7842 i_condeferrable,
7843 i_condeferred,
7844 i_conperiod,
7845 i_contableoid,
7846 i_conoid,
7847 i_condef,
7848 i_indattnames,
7849 i_tablespace,
7850 i_indreloptions,
7851 i_indstatcols,
7852 i_indstatvals;
7853
7854 /*
7855 * We want to perform just one query against pg_index. However, we
7856 * mustn't try to select every row of the catalog and then sort it out on
7857 * the client side, because some of the server-side functions we need
7858 * would be unsafe to apply to tables we don't have lock on. Hence, we
7859 * build an array of the OIDs of tables we care about (and now have lock
7860 * on!), and use a WHERE clause to constrain which rows are selected.
7861 */
7862 appendPQExpBufferChar(tbloids, '{');
7863 for (int i = 0; i < numTables; i++)
7864 {
7865 TableInfo *tbinfo = &tblinfo[i];
7866
7867 if (!tbinfo->hasindex)
7868 continue;
7869
7870 /*
7871 * We can ignore indexes of uninteresting tables.
7872 */
7873 if (!tbinfo->interesting)
7874 continue;
7875
7876 /* OK, we need info for this table */
7877 if (tbloids->len > 1) /* do we have more than the '{'? */
7878 appendPQExpBufferChar(tbloids, ',');
7879 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
7880 }
7881 appendPQExpBufferChar(tbloids, '}');
7882
7884 "SELECT t.tableoid, t.oid, i.indrelid, "
7885 "t.relname AS indexname, "
7886 "t.relpages, t.reltuples, t.relallvisible, ");
7887
7888 if (fout->remoteVersion >= 180000)
7889 appendPQExpBufferStr(query, "t.relallfrozen, ");
7890 else
7891 appendPQExpBufferStr(query, "0 AS relallfrozen, ");
7892
7894 "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7895 "i.indkey, i.indisclustered, "
7896 "c.contype, c.conname, "
7897 "c.condeferrable, c.condeferred, "
7898 "c.tableoid AS contableoid, "
7899 "c.oid AS conoid, "
7900 "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7901 "CASE WHEN i.indexprs IS NOT NULL THEN "
7902 "(SELECT pg_catalog.array_agg(attname ORDER BY attnum)"
7903 " FROM pg_catalog.pg_attribute "
7904 " WHERE attrelid = i.indexrelid) "
7905 "ELSE NULL END AS indattnames, "
7906 "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7907 "t.reloptions AS indreloptions, ");
7908
7909
7910 if (fout->remoteVersion >= 90400)
7912 "i.indisreplident, ");
7913 else
7915 "false AS indisreplident, ");
7916
7917 if (fout->remoteVersion >= 110000)
7919 "inh.inhparent AS parentidx, "
7920 "i.indnkeyatts AS indnkeyatts, "
7921 "i.indnatts AS indnatts, "
7922 "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
7923 " FROM pg_catalog.pg_attribute "
7924 " WHERE attrelid = i.indexrelid AND "
7925 " attstattarget >= 0) AS indstatcols, "
7926 "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
7927 " FROM pg_catalog.pg_attribute "
7928 " WHERE attrelid = i.indexrelid AND "
7929 " attstattarget >= 0) AS indstatvals, ");
7930 else
7932 "0 AS parentidx, "
7933 "i.indnatts AS indnkeyatts, "
7934 "i.indnatts AS indnatts, "
7935 "'' AS indstatcols, "
7936 "'' AS indstatvals, ");
7937
7938 if (fout->remoteVersion >= 150000)
7940 "i.indnullsnotdistinct, ");
7941 else
7943 "false AS indnullsnotdistinct, ");
7944
7945 if (fout->remoteVersion >= 180000)
7947 "c.conperiod ");
7948 else
7950 "NULL AS conperiod ");
7951
7952 /*
7953 * The point of the messy-looking outer join is to find a constraint that
7954 * is related by an internal dependency link to the index. If we find one,
7955 * create a CONSTRAINT entry linked to the INDEX entry. We assume an
7956 * index won't have more than one internal dependency.
7957 *
7958 * Note: the check on conrelid is redundant, but useful because that
7959 * column is indexed while conindid is not.
7960 */
7961 if (fout->remoteVersion >= 110000)
7962 {
7963 appendPQExpBuffer(query,
7964 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7965 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7966 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7967 "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
7968 "LEFT JOIN pg_catalog.pg_constraint c "
7969 "ON (i.indrelid = c.conrelid AND "
7970 "i.indexrelid = c.conindid AND "
7971 "c.contype IN ('p','u','x')) "
7972 "LEFT JOIN pg_catalog.pg_inherits inh "
7973 "ON (inh.inhrelid = indexrelid) "
7974 "WHERE (i.indisvalid OR t2.relkind = 'p') "
7975 "AND i.indisready "
7976 "ORDER BY i.indrelid, indexname",
7977 tbloids->data);
7978 }
7979 else
7980 {
7981 /*
7982 * the test on indisready is necessary in 9.2, and harmless in
7983 * earlier/later versions
7984 */
7985 appendPQExpBuffer(query,
7986 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7987 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7988 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7989 "LEFT JOIN pg_catalog.pg_constraint c "
7990 "ON (i.indrelid = c.conrelid AND "
7991 "i.indexrelid = c.conindid AND "
7992 "c.contype IN ('p','u','x')) "
7993 "WHERE i.indisvalid AND i.indisready "
7994 "ORDER BY i.indrelid, indexname",
7995 tbloids->data);
7996 }
7997
7998 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7999
8000 ntups = PQntuples(res);
8001
8002 i_tableoid = PQfnumber(res, "tableoid");
8003 i_oid = PQfnumber(res, "oid");
8004 i_indrelid = PQfnumber(res, "indrelid");
8005 i_indexname = PQfnumber(res, "indexname");
8006 i_relpages = PQfnumber(res, "relpages");
8007 i_reltuples = PQfnumber(res, "reltuples");
8008 i_relallvisible = PQfnumber(res, "relallvisible");
8009 i_relallfrozen = PQfnumber(res, "relallfrozen");
8010 i_parentidx = PQfnumber(res, "parentidx");
8011 i_indexdef = PQfnumber(res, "indexdef");
8012 i_indnkeyatts = PQfnumber(res, "indnkeyatts");
8013 i_indnatts = PQfnumber(res, "indnatts");
8014 i_indkey = PQfnumber(res, "indkey");
8015 i_indisclustered = PQfnumber(res, "indisclustered");
8016 i_indisreplident = PQfnumber(res, "indisreplident");
8017 i_indnullsnotdistinct = PQfnumber(res, "indnullsnotdistinct");
8018 i_contype = PQfnumber(res, "contype");
8019 i_conname = PQfnumber(res, "conname");
8020 i_condeferrable = PQfnumber(res, "condeferrable");
8021 i_condeferred = PQfnumber(res, "condeferred");
8022 i_conperiod = PQfnumber(res, "conperiod");
8023 i_contableoid = PQfnumber(res, "contableoid");
8024 i_conoid = PQfnumber(res, "conoid");
8025 i_condef = PQfnumber(res, "condef");
8026 i_indattnames = PQfnumber(res, "indattnames");
8027 i_tablespace = PQfnumber(res, "tablespace");
8028 i_indreloptions = PQfnumber(res, "indreloptions");
8029 i_indstatcols = PQfnumber(res, "indstatcols");
8030 i_indstatvals = PQfnumber(res, "indstatvals");
8031
8032 indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
8033
8034 /*
8035 * Outer loop iterates once per table, not once per row. Incrementing of
8036 * j is handled by the inner loop.
8037 */
8038 curtblindx = -1;
8039 for (int j = 0; j < ntups;)
8040 {
8041 Oid indrelid = atooid(PQgetvalue(res, j, i_indrelid));
8042 TableInfo *tbinfo = NULL;
8043 char **indAttNames = NULL;
8044 int nindAttNames = 0;
8045 int numinds;
8046
8047 /* Count rows for this table */
8048 for (numinds = 1; numinds < ntups - j; numinds++)
8049 if (atooid(PQgetvalue(res, j + numinds, i_indrelid)) != indrelid)
8050 break;
8051
8052 /*
8053 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8054 * order.
8055 */
8056 while (++curtblindx < numTables)
8057 {
8058 tbinfo = &tblinfo[curtblindx];
8059 if (tbinfo->dobj.catId.oid == indrelid)
8060 break;
8061 }
8062 if (curtblindx >= numTables)
8063 pg_fatal("unrecognized table OID %u", indrelid);
8064 /* cross-check that we only got requested tables */
8065 if (!tbinfo->hasindex ||
8066 !tbinfo->interesting)
8067 pg_fatal("unexpected index data for table \"%s\"",
8068 tbinfo->dobj.name);
8069
8070 /* Save data for this table */
8071 tbinfo->indexes = indxinfo + j;
8072 tbinfo->numIndexes = numinds;
8073
8074 for (int c = 0; c < numinds; c++, j++)
8075 {
8076 char contype;
8077 char indexkind;
8078 RelStatsInfo *relstats;
8079 int32 relpages = atoi(PQgetvalue(res, j, i_relpages));
8080 int32 relallvisible = atoi(PQgetvalue(res, j, i_relallvisible));
8081 int32 relallfrozen = atoi(PQgetvalue(res, j, i_relallfrozen));
8082
8083 indxinfo[j].dobj.objType = DO_INDEX;
8084 indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
8085 indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
8086 AssignDumpId(&indxinfo[j].dobj);
8087 indxinfo[j].dobj.dump = tbinfo->dobj.dump;
8088 indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
8089 indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
8090 indxinfo[j].indextable = tbinfo;
8091 indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
8092 indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
8093 indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
8094 indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
8095 indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
8096 indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
8097 indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
8098 indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
8099 parseOidArray(PQgetvalue(res, j, i_indkey),
8100 indxinfo[j].indkeys, indxinfo[j].indnattrs);
8101 indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
8102 indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
8103 indxinfo[j].indnullsnotdistinct = (PQgetvalue(res, j, i_indnullsnotdistinct)[0] == 't');
8104 indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
8105 indxinfo[j].partattaches = (SimplePtrList)
8106 {
8107 NULL, NULL
8108 };
8109
8110 if (indxinfo[j].parentidx == 0)
8111 indexkind = RELKIND_INDEX;
8112 else
8113 indexkind = RELKIND_PARTITIONED_INDEX;
8114
8115 if (!PQgetisnull(res, j, i_indattnames))
8116 {
8117 if (!parsePGArray(PQgetvalue(res, j, i_indattnames),
8118 &indAttNames, &nindAttNames))
8119 pg_fatal("could not parse %s array", "indattnames");
8120 }
8121
8122 relstats = getRelationStatistics(fout, &indxinfo[j].dobj, relpages,
8123 PQgetvalue(res, j, i_reltuples),
8124 relallvisible, relallfrozen, indexkind,
8125 indAttNames, nindAttNames);
8126
8127 contype = *(PQgetvalue(res, j, i_contype));
8128 if (contype == 'p' || contype == 'u' || contype == 'x')
8129 {
8130 /*
8131 * If we found a constraint matching the index, create an
8132 * entry for it.
8133 */
8134 ConstraintInfo *constrinfo;
8135
8136 constrinfo = (ConstraintInfo *) pg_malloc(sizeof(ConstraintInfo));
8137 constrinfo->dobj.objType = DO_CONSTRAINT;
8138 constrinfo->dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
8139 constrinfo->dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
8140 AssignDumpId(&constrinfo->dobj);
8141 constrinfo->dobj.dump = tbinfo->dobj.dump;
8142 constrinfo->dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
8143 constrinfo->dobj.namespace = tbinfo->dobj.namespace;
8144 constrinfo->contable = tbinfo;
8145 constrinfo->condomain = NULL;
8146 constrinfo->contype = contype;
8147 if (contype == 'x')
8148 constrinfo->condef = pg_strdup(PQgetvalue(res, j, i_condef));
8149 else
8150 constrinfo->condef = NULL;
8151 constrinfo->confrelid = InvalidOid;
8152 constrinfo->conindex = indxinfo[j].dobj.dumpId;
8153 constrinfo->condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
8154 constrinfo->condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
8155 constrinfo->conperiod = *(PQgetvalue(res, j, i_conperiod)) == 't';
8156 constrinfo->conislocal = true;
8157 constrinfo->separate = true;
8158
8159 indxinfo[j].indexconstraint = constrinfo->dobj.dumpId;
8160 if (relstats != NULL)
8161 addObjectDependency(&relstats->dobj, constrinfo->dobj.dumpId);
8162 }
8163 else
8164 {
8165 /* Plain secondary index */
8166 indxinfo[j].indexconstraint = 0;
8167 }
8168 }
8169 }
8170
8171 PQclear(res);
8172
8173 destroyPQExpBuffer(query);
8174 destroyPQExpBuffer(tbloids);
8175}
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:818
int32_t int32
Definition: c.h:535
static RelStatsInfo * getRelationStatistics(Archive *fout, DumpableObject *rel, int32 relpages, char *reltuples, int32 relallvisible, int32 relallfrozen, char relkind, char **indAttNames, int nindAttNames)
Definition: pg_dump.c:7081
char * c
struct SimplePtrList SimplePtrList
bool parsePGArray(const char *atext, char ***itemarray, int *nitems)
Definition: string_utils.c:819
bool conperiod
Definition: pg_dump.h:526
bool indisreplident
Definition: pg_dump.h:432
int indnkeyattrs
Definition: pg_dump.h:427
char * indstatvals
Definition: pg_dump.h:426
char * indstatcols
Definition: pg_dump.h:425
int indnattrs
Definition: pg_dump.h:428
TableInfo * indextable
Definition: pg_dump.h:421
Oid parentidx
Definition: pg_dump.h:434
Oid * indkeys
Definition: pg_dump.h:429
char * indreloptions
Definition: pg_dump.h:424
DumpId indexconstraint
Definition: pg_dump.h:438
bool indisclustered
Definition: pg_dump.h:431
SimplePtrList partattaches
Definition: pg_dump.h:435
char * tablespace
Definition: pg_dump.h:423
bool indnullsnotdistinct
Definition: pg_dump.h:433
char * indexdef
Definition: pg_dump.h:422
DumpableObject dobj
Definition: pg_dump.h:450
bool interesting
Definition: pg_dump.h:341
bool hasindex
Definition: pg_dump.h:318

References addObjectDependency(), 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, _relStatsInfo::dobj, _constraintInfo::dobj, _dumpableObject::dump, _dumpableObject::dumpId, ExecuteSqlQuery(), getRelationStatistics(), _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(), parsePGArray(), _indxInfo::partattaches, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, Archive::remoteVersion, _constraintInfo::separate, CatalogId::tableoid, and _indxInfo::tablespace.

Referenced by getSchemaData().

◆ getInherits()

InhInfo * getInherits ( Archive fout,
int *  numInherits 
)

Definition at line 7700 of file pg_dump.c.

7701{
7702 PGresult *res;
7703 int ntups;
7704 int i;
7706 InhInfo *inhinfo;
7707
7708 int i_inhrelid;
7709 int i_inhparent;
7710
7711 /* find all the inheritance information */
7712 appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
7713
7714 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7715
7716 ntups = PQntuples(res);
7717
7718 *numInherits = ntups;
7719
7720 inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
7721
7722 i_inhrelid = PQfnumber(res, "inhrelid");
7723 i_inhparent = PQfnumber(res, "inhparent");
7724
7725 for (i = 0; i < ntups; i++)
7726 {
7727 inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
7728 inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
7729 }
7730
7731 PQclear(res);
7732
7733 destroyPQExpBuffer(query);
7734
7735 return inhinfo;
7736}
Oid inhparent
Definition: pg_dump.h:565
Oid inhrelid
Definition: pg_dump.h:564

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

Referenced by getSchemaData().

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )

Definition at line 754 of file common.c.

755{
756 return lastDumpId;
757}

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

◆ getNamespaces()

void getNamespaces ( Archive fout)

Definition at line 5964 of file pg_dump.c.

5965{
5966 PGresult *res;
5967 int ntups;
5968 int i;
5969 PQExpBuffer query;
5970 NamespaceInfo *nsinfo;
5971 int i_tableoid;
5972 int i_oid;
5973 int i_nspname;
5974 int i_nspowner;
5975 int i_nspacl;
5976 int i_acldefault;
5977
5978 query = createPQExpBuffer();
5979
5980 /*
5981 * we fetch all namespaces including system ones, so that every object we
5982 * read in can be linked to a containing namespace.
5983 */
5984 appendPQExpBufferStr(query, "SELECT n.tableoid, n.oid, n.nspname, "
5985 "n.nspowner, "
5986 "n.nspacl, "
5987 "acldefault('n', n.nspowner) AS acldefault "
5988 "FROM pg_namespace n");
5989
5990 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5991
5992 ntups = PQntuples(res);
5993
5994 nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
5995
5996 i_tableoid = PQfnumber(res, "tableoid");
5997 i_oid = PQfnumber(res, "oid");
5998 i_nspname = PQfnumber(res, "nspname");
5999 i_nspowner = PQfnumber(res, "nspowner");
6000 i_nspacl = PQfnumber(res, "nspacl");
6001 i_acldefault = PQfnumber(res, "acldefault");
6002
6003 for (i = 0; i < ntups; i++)
6004 {
6005 const char *nspowner;
6006
6007 nsinfo[i].dobj.objType = DO_NAMESPACE;
6008 nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6009 nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6010 AssignDumpId(&nsinfo[i].dobj);
6011 nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
6012 nsinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_nspacl));
6013 nsinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6014 nsinfo[i].dacl.privtype = 0;
6015 nsinfo[i].dacl.initprivs = NULL;
6016 nspowner = PQgetvalue(res, i, i_nspowner);
6017 nsinfo[i].nspowner = atooid(nspowner);
6018 nsinfo[i].rolname = getRoleName(nspowner);
6019
6020 /* Decide whether to dump this namespace */
6021 selectDumpableNamespace(&nsinfo[i], fout);
6022
6023 /* Mark whether namespace has an ACL */
6024 if (!PQgetisnull(res, i, i_nspacl))
6026
6027 /*
6028 * We ignore any pg_init_privs.initprivs entry for the public schema
6029 * and assume a predetermined default, for several reasons. First,
6030 * dropping and recreating the schema removes its pg_init_privs entry,
6031 * but an empty destination database starts with this ACL nonetheless.
6032 * Second, we support dump/reload of public schema ownership changes.
6033 * ALTER SCHEMA OWNER filters nspacl through aclnewowner(), but
6034 * initprivs continues to reflect the initial owner. Hence,
6035 * synthesize the value that nspacl will have after the restore's
6036 * ALTER SCHEMA OWNER. Third, this makes the destination database
6037 * match the source's ACL, even if the latter was an initdb-default
6038 * ACL, which changed in v15. An upgrade pulls in changes to most
6039 * system object ACLs that the DBA had not customized. We've made the
6040 * public schema depart from that, because changing its ACL so easily
6041 * breaks applications.
6042 */
6043 if (strcmp(nsinfo[i].dobj.name, "public") == 0)
6044 {
6045 PQExpBuffer aclarray = createPQExpBuffer();
6046 PQExpBuffer aclitem = createPQExpBuffer();
6047
6048 /* Standard ACL as of v15 is {owner=UC/owner,=U/owner} */
6049 appendPQExpBufferChar(aclarray, '{');
6050 quoteAclUserName(aclitem, nsinfo[i].rolname);
6051 appendPQExpBufferStr(aclitem, "=UC/");
6052 quoteAclUserName(aclitem, nsinfo[i].rolname);
6053 appendPGArray(aclarray, aclitem->data);
6054 resetPQExpBuffer(aclitem);
6055 appendPQExpBufferStr(aclitem, "=U/");
6056 quoteAclUserName(aclitem, nsinfo[i].rolname);
6057 appendPGArray(aclarray, aclitem->data);
6058 appendPQExpBufferChar(aclarray, '}');
6059
6060 nsinfo[i].dacl.privtype = 'i';
6061 nsinfo[i].dacl.initprivs = pstrdup(aclarray->data);
6063
6064 destroyPQExpBuffer(aclarray);
6065 destroyPQExpBuffer(aclitem);
6066 }
6067 }
6068
6069 PQclear(res);
6070 destroyPQExpBuffer(query);
6071}
void quoteAclUserName(PQExpBuffer output, const char *input)
Definition: dumputils.c:585
char * pstrdup(const char *in)
Definition: mcxt.c:1759
NameData rolname
Definition: pg_authid.h:34
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition: pg_dump.c:1984
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:146
void appendPGArray(PQExpBuffer buffer, const char *value)
Definition: string_utils.c:902
DumpableObject dobj
Definition: pg_dump.h:186
DumpableAcl dacl
Definition: pg_dump.h:187
const char * rolname
Definition: pg_dump.h:190

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(), resetPQExpBuffer(), _namespaceInfo::rolname, rolname, selectDumpableNamespace(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getOpclasses()

void getOpclasses ( Archive fout)

Definition at line 6617 of file pg_dump.c.

6618{
6619 PGresult *res;
6620 int ntups;
6621 int i;
6623 OpclassInfo *opcinfo;
6624 int i_tableoid;
6625 int i_oid;
6626 int i_opcmethod;
6627 int i_opcname;
6628 int i_opcnamespace;
6629 int i_opcowner;
6630
6631 /*
6632 * find all opclasses, including builtin opclasses; we filter out
6633 * system-defined opclasses at dump-out time.
6634 */
6635
6636 appendPQExpBufferStr(query, "SELECT tableoid, oid, opcmethod, opcname, "
6637 "opcnamespace, "
6638 "opcowner "
6639 "FROM pg_opclass");
6640
6641 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6642
6643 ntups = PQntuples(res);
6644
6645 opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
6646
6647 i_tableoid = PQfnumber(res, "tableoid");
6648 i_oid = PQfnumber(res, "oid");
6649 i_opcmethod = PQfnumber(res, "opcmethod");
6650 i_opcname = PQfnumber(res, "opcname");
6651 i_opcnamespace = PQfnumber(res, "opcnamespace");
6652 i_opcowner = PQfnumber(res, "opcowner");
6653
6654 for (i = 0; i < ntups; i++)
6655 {
6656 opcinfo[i].dobj.objType = DO_OPCLASS;
6657 opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6658 opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6659 AssignDumpId(&opcinfo[i].dobj);
6660 opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
6661 opcinfo[i].dobj.namespace =
6662 findNamespace(atooid(PQgetvalue(res, i, i_opcnamespace)));
6663 opcinfo[i].opcmethod = atooid(PQgetvalue(res, i, i_opcmethod));
6664 opcinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opcowner));
6665
6666 /* Decide whether we want to dump it */
6667 selectDumpableObject(&(opcinfo[i].dobj), fout);
6668 }
6669
6670 PQclear(res);
6671
6672 destroyPQExpBuffer(query);
6673}
Oid opcmethod
Definition: pg_dump.h:278
DumpableObject dobj
Definition: pg_dump.h:277
const char * rolname
Definition: pg_dump.h:279

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

Referenced by getSchemaData().

◆ getOperators()

void getOperators ( Archive fout)

Definition at line 6339 of file pg_dump.c.

6340{
6341 PGresult *res;
6342 int ntups;
6343 int i;
6345 OprInfo *oprinfo;
6346 int i_tableoid;
6347 int i_oid;
6348 int i_oprname;
6349 int i_oprnamespace;
6350 int i_oprowner;
6351 int i_oprkind;
6352 int i_oprleft;
6353 int i_oprright;
6354 int i_oprcode;
6355
6356 /*
6357 * find all operators, including builtin operators; we filter out
6358 * system-defined operators at dump-out time.
6359 */
6360
6361 appendPQExpBufferStr(query, "SELECT tableoid, oid, oprname, "
6362 "oprnamespace, "
6363 "oprowner, "
6364 "oprkind, "
6365 "oprleft, "
6366 "oprright, "
6367 "oprcode::oid AS oprcode "
6368 "FROM pg_operator");
6369
6370 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6371
6372 ntups = PQntuples(res);
6373
6374 oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
6375
6376 i_tableoid = PQfnumber(res, "tableoid");
6377 i_oid = PQfnumber(res, "oid");
6378 i_oprname = PQfnumber(res, "oprname");
6379 i_oprnamespace = PQfnumber(res, "oprnamespace");
6380 i_oprowner = PQfnumber(res, "oprowner");
6381 i_oprkind = PQfnumber(res, "oprkind");
6382 i_oprleft = PQfnumber(res, "oprleft");
6383 i_oprright = PQfnumber(res, "oprright");
6384 i_oprcode = PQfnumber(res, "oprcode");
6385
6386 for (i = 0; i < ntups; i++)
6387 {
6388 oprinfo[i].dobj.objType = DO_OPERATOR;
6389 oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6390 oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6391 AssignDumpId(&oprinfo[i].dobj);
6392 oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
6393 oprinfo[i].dobj.namespace =
6394 findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)));
6395 oprinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_oprowner));
6396 oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
6397 oprinfo[i].oprleft = atooid(PQgetvalue(res, i, i_oprleft));
6398 oprinfo[i].oprright = atooid(PQgetvalue(res, i, i_oprright));
6399 oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
6400
6401 /* Decide whether we want to dump it */
6402 selectDumpableObject(&(oprinfo[i].dobj), fout);
6403 }
6404
6405 PQclear(res);
6406
6407 destroyPQExpBuffer(query);
6408}
DumpableObject dobj
Definition: pg_dump.h:260
Oid oprleft
Definition: pg_dump.h:263
char oprkind
Definition: pg_dump.h:262
Oid oprcode
Definition: pg_dump.h:265
Oid oprright
Definition: pg_dump.h:264
const char * rolname
Definition: pg_dump.h:261

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, _oprInfo::oprleft, _oprInfo::oprright, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, _oprInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getOpfamilies()

void getOpfamilies ( Archive fout)

Definition at line 6680 of file pg_dump.c.

6681{
6682 PGresult *res;
6683 int ntups;
6684 int i;
6685 PQExpBuffer query;
6686 OpfamilyInfo *opfinfo;
6687 int i_tableoid;
6688 int i_oid;
6689 int i_opfmethod;
6690 int i_opfname;
6691 int i_opfnamespace;
6692 int i_opfowner;
6693
6694 query = createPQExpBuffer();
6695
6696 /*
6697 * find all opfamilies, including builtin opfamilies; we filter out
6698 * system-defined opfamilies at dump-out time.
6699 */
6700
6701 appendPQExpBufferStr(query, "SELECT tableoid, oid, opfmethod, opfname, "
6702 "opfnamespace, "
6703 "opfowner "
6704 "FROM pg_opfamily");
6705
6706 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6707
6708 ntups = PQntuples(res);
6709
6710 opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
6711
6712 i_tableoid = PQfnumber(res, "tableoid");
6713 i_oid = PQfnumber(res, "oid");
6714 i_opfname = PQfnumber(res, "opfname");
6715 i_opfmethod = PQfnumber(res, "opfmethod");
6716 i_opfnamespace = PQfnumber(res, "opfnamespace");
6717 i_opfowner = PQfnumber(res, "opfowner");
6718
6719 for (i = 0; i < ntups; i++)
6720 {
6721 opfinfo[i].dobj.objType = DO_OPFAMILY;
6722 opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6723 opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6724 AssignDumpId(&opfinfo[i].dobj);
6725 opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
6726 opfinfo[i].dobj.namespace =
6727 findNamespace(atooid(PQgetvalue(res, i, i_opfnamespace)));
6728 opfinfo[i].opfmethod = atooid(PQgetvalue(res, i, i_opfmethod));
6729 opfinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opfowner));
6730
6731 /* Decide whether we want to dump it */
6732 selectDumpableObject(&(opfinfo[i].dobj), fout);
6733 }
6734
6735 PQclear(res);
6736
6737 destroyPQExpBuffer(query);
6738}
const char * rolname
Definition: pg_dump.h:286
Oid opfmethod
Definition: pg_dump.h:285
DumpableObject dobj
Definition: pg_dump.h:284

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

Referenced by getSchemaData().

◆ getOwnedSeqs()

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

Definition at line 7635 of file pg_dump.c.

7636{
7637 int i;
7638
7639 /*
7640 * Force sequences that are "owned" by table columns to be dumped whenever
7641 * their owning table is being dumped.
7642 */
7643 for (i = 0; i < numTables; i++)
7644 {
7645 TableInfo *seqinfo = &tblinfo[i];
7646 TableInfo *owning_tab;
7647
7648 if (!OidIsValid(seqinfo->owning_tab))
7649 continue; /* not an owned sequence */
7650
7651 owning_tab = findTableByOid(seqinfo->owning_tab);
7652 if (owning_tab == NULL)
7653 pg_fatal("failed sanity check, parent table with OID %u of sequence with OID %u not found",
7654 seqinfo->owning_tab, seqinfo->dobj.catId.oid);
7655
7656 /*
7657 * For an identity sequence, dump exactly the same components for the
7658 * sequence as for the owning table. This is important because we
7659 * treat the identity sequence as an integral part of the table. For
7660 * example, there is not any DDL command that allows creation of such
7661 * a sequence independently of the table.
7662 *
7663 * For other owned sequences such as serial sequences, we need to dump
7664 * the components that are being dumped for the table and any
7665 * components that the sequence is explicitly marked with.
7666 *
7667 * We can't simply use the set of components which are being dumped
7668 * for the table as the table might be in an extension (and only the
7669 * non-extension components, eg: ACLs if changed, security labels, and
7670 * policies, are being dumped) while the sequence is not (and
7671 * therefore the definition and other components should also be
7672 * dumped).
7673 *
7674 * If the sequence is part of the extension then it should be properly
7675 * marked by checkExtensionMembership() and this will be a no-op as
7676 * the table will be equivalently marked.
7677 */
7678 if (seqinfo->is_identity_sequence)
7679 seqinfo->dobj.dump = owning_tab->dobj.dump;
7680 else
7681 seqinfo->dobj.dump |= owning_tab->dobj.dump;
7682
7683 /* Make sure that necessary data is available if we're dumping it */
7684 if (seqinfo->dobj.dump != DUMP_COMPONENT_NONE)
7685 {
7686 seqinfo->interesting = true;
7687 owning_tab->interesting = true;
7688 }
7689 }
7690}
#define DUMP_COMPONENT_NONE
Definition: pg_dump.h:108
bool is_identity_sequence
Definition: pg_dump.h:337
Oid owning_tab
Definition: pg_dump.h:335

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

7757{
7758 PQExpBuffer query;
7759 PGresult *res;
7760 int ntups;
7761
7762 /* hash partitioning didn't exist before v11 */
7763 if (fout->remoteVersion < 110000)
7764 return;
7765 /* needn't bother if not dumping data */
7766 if (!fout->dopt->dumpData)
7767 return;
7768
7769 query = createPQExpBuffer();
7770
7771 /*
7772 * Unsafe partitioning schemes are exactly those for which hash enum_ops
7773 * appears among the partition opclasses. We needn't check partstrat.
7774 *
7775 * Note that this query may well retrieve info about tables we aren't
7776 * going to dump and hence have no lock on. That's okay since we need not
7777 * invoke any unsafe server-side functions.
7778 */
7780 "SELECT partrelid FROM pg_partitioned_table WHERE\n"
7781 "(SELECT c.oid FROM pg_opclass c JOIN pg_am a "
7782 "ON c.opcmethod = a.oid\n"
7783 "WHERE opcname = 'enum_ops' "
7784 "AND opcnamespace = 'pg_catalog'::regnamespace "
7785 "AND amname = 'hash') = ANY(partclass)");
7786
7787 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7788
7789 ntups = PQntuples(res);
7790
7791 for (int i = 0; i < ntups; i++)
7792 {
7793 Oid tabrelid = atooid(PQgetvalue(res, i, 0));
7794 TableInfo *tbinfo;
7795
7796 tbinfo = findTableByOid(tabrelid);
7797 if (tbinfo == NULL)
7798 pg_fatal("failed sanity check, table OID %u appearing in pg_partitioned_table not found",
7799 tabrelid);
7800 tbinfo->unsafe_partitions = true;
7801 }
7802
7803 PQclear(res);
7804
7805 destroyPQExpBuffer(query);
7806}
bool dumpData
Definition: pg_backup.h:216
bool unsafe_partitions
Definition: pg_dump.h:345

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

Referenced by getSchemaData().

◆ getPolicies()

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

Definition at line 4233 of file pg_dump.c.

4234{
4235 DumpOptions *dopt = fout->dopt;
4236 PQExpBuffer query;
4237 PQExpBuffer tbloids;
4238 PGresult *res;
4239 PolicyInfo *polinfo;
4240 int i_oid;
4241 int i_tableoid;
4242 int i_polrelid;
4243 int i_polname;
4244 int i_polcmd;
4245 int i_polpermissive;
4246 int i_polroles;
4247 int i_polqual;
4248 int i_polwithcheck;
4249 int i,
4250 j,
4251 ntups;
4252
4253 /* No policies before 9.5 */
4254 if (fout->remoteVersion < 90500)
4255 return;
4256
4257 /* Skip if --no-policies was specified */
4258 if (dopt->no_policies)
4259 return;
4260
4261 query = createPQExpBuffer();
4262 tbloids = createPQExpBuffer();
4263
4264 /*
4265 * Identify tables of interest, and check which ones have RLS enabled.
4266 */
4267 appendPQExpBufferChar(tbloids, '{');
4268 for (i = 0; i < numTables; i++)
4269 {
4270 TableInfo *tbinfo = &tblinfo[i];
4271
4272 /* Ignore row security on tables not to be dumped */
4273 if (!(tbinfo->dobj.dump & DUMP_COMPONENT_POLICY))
4274 continue;
4275
4276 /* It can't have RLS or policies if it's not a table */
4277 if (tbinfo->relkind != RELKIND_RELATION &&
4278 tbinfo->relkind != RELKIND_PARTITIONED_TABLE)
4279 continue;
4280
4281 /* Add it to the list of table OIDs to be probed below */
4282 if (tbloids->len > 1) /* do we have more than the '{'? */
4283 appendPQExpBufferChar(tbloids, ',');
4284 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
4285
4286 /* Is RLS enabled? (That's separate from whether it has policies) */
4287 if (tbinfo->rowsec)
4288 {
4290
4291 /*
4292 * We represent RLS being enabled on a table by creating a
4293 * PolicyInfo object with null polname.
4294 *
4295 * Note: use tableoid 0 so that this object won't be mistaken for
4296 * something that pg_depend entries apply to.
4297 */
4298 polinfo = pg_malloc(sizeof(PolicyInfo));
4299 polinfo->dobj.objType = DO_POLICY;
4300 polinfo->dobj.catId.tableoid = 0;
4301 polinfo->dobj.catId.oid = tbinfo->dobj.catId.oid;
4302 AssignDumpId(&polinfo->dobj);
4303 polinfo->dobj.namespace = tbinfo->dobj.namespace;
4304 polinfo->dobj.name = pg_strdup(tbinfo->dobj.name);
4305 polinfo->poltable = tbinfo;
4306 polinfo->polname = NULL;
4307 polinfo->polcmd = '\0';
4308 polinfo->polpermissive = 0;
4309 polinfo->polroles = NULL;
4310 polinfo->polqual = NULL;
4311 polinfo->polwithcheck = NULL;
4312 }
4313 }
4314 appendPQExpBufferChar(tbloids, '}');
4315
4316 /*
4317 * Now, read all RLS policies belonging to the tables of interest, and
4318 * create PolicyInfo objects for them. (Note that we must filter the
4319 * results server-side not locally, because we dare not apply pg_get_expr
4320 * to tables we don't have lock on.)
4321 */
4322 pg_log_info("reading row-level security policies");
4323
4324 printfPQExpBuffer(query,
4325 "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
4326 if (fout->remoteVersion >= 100000)
4327 appendPQExpBufferStr(query, "pol.polpermissive, ");
4328 else
4329 appendPQExpBufferStr(query, "'t' as polpermissive, ");
4330 appendPQExpBuffer(query,
4331 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
4332 " 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, "
4333 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
4334 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
4335 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
4336 "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
4337 tbloids->data);
4338
4339 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4340
4341 ntups = PQntuples(res);
4342 if (ntups > 0)
4343 {
4344 i_oid = PQfnumber(res, "oid");
4345 i_tableoid = PQfnumber(res, "tableoid");
4346 i_polrelid = PQfnumber(res, "polrelid");
4347 i_polname = PQfnumber(res, "polname");
4348 i_polcmd = PQfnumber(res, "polcmd");
4349 i_polpermissive = PQfnumber(res, "polpermissive");
4350 i_polroles = PQfnumber(res, "polroles");
4351 i_polqual = PQfnumber(res, "polqual");
4352 i_polwithcheck = PQfnumber(res, "polwithcheck");
4353
4354 polinfo = pg_malloc(ntups * sizeof(PolicyInfo));
4355
4356 for (j = 0; j < ntups; j++)
4357 {
4358 Oid polrelid = atooid(PQgetvalue(res, j, i_polrelid));
4359 TableInfo *tbinfo = findTableByOid(polrelid);
4360
4362
4363 polinfo[j].dobj.objType = DO_POLICY;
4364 polinfo[j].dobj.catId.tableoid =
4365 atooid(PQgetvalue(res, j, i_tableoid));
4366 polinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
4367 AssignDumpId(&polinfo[j].dobj);
4368 polinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4369 polinfo[j].poltable = tbinfo;
4370 polinfo[j].polname = pg_strdup(PQgetvalue(res, j, i_polname));
4371 polinfo[j].dobj.name = pg_strdup(polinfo[j].polname);
4372
4373 polinfo[j].polcmd = *(PQgetvalue(res, j, i_polcmd));
4374 polinfo[j].polpermissive = *(PQgetvalue(res, j, i_polpermissive)) == 't';
4375
4376 if (PQgetisnull(res, j, i_polroles))
4377 polinfo[j].polroles = NULL;
4378 else
4379 polinfo[j].polroles = pg_strdup(PQgetvalue(res, j, i_polroles));
4380
4381 if (PQgetisnull(res, j, i_polqual))
4382 polinfo[j].polqual = NULL;
4383 else
4384 polinfo[j].polqual = pg_strdup(PQgetvalue(res, j, i_polqual));
4385
4386 if (PQgetisnull(res, j, i_polwithcheck))
4387 polinfo[j].polwithcheck = NULL;
4388 else
4389 polinfo[j].polwithcheck
4390 = pg_strdup(PQgetvalue(res, j, i_polwithcheck));
4391 }
4392 }
4393
4394 PQclear(res);
4395
4396 destroyPQExpBuffer(query);
4397 destroyPQExpBuffer(tbloids);
4398}
#define pg_log_info(...)
Definition: logging.h:124
#define DUMP_COMPONENT_POLICY
Definition: pg_dump.h:114
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:235
int no_policies
Definition: pg_backup.h:187
TableInfo * poltable
Definition: pg_dump.h:655
char * polqual
Definition: pg_dump.h:660
char polcmd
Definition: pg_dump.h:657
char * polroles
Definition: pg_dump.h:659
char * polwithcheck
Definition: pg_dump.h:661
DumpableObject dobj
Definition: pg_dump.h:654
bool polpermissive
Definition: pg_dump.h:658
char * polname
Definition: pg_dump.h:656
bool rowsec
Definition: pg_dump.h:322

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_POLICY, _tableInfo::dobj, _policyInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_POLICY, ExecuteSqlQuery(), findTableByOid(), i, j, PQExpBufferData::len, _dumpableObject::name, _dumpOptions::no_policies, _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, _tableInfo::rowsec, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getProcLangs()

void getProcLangs ( Archive fout)

Definition at line 8929 of file pg_dump.c.

8930{
8931 PGresult *res;
8932 int ntups;
8933 int i;
8935 ProcLangInfo *planginfo;
8936 int i_tableoid;
8937 int i_oid;
8938 int i_lanname;
8939 int i_lanpltrusted;
8940 int i_lanplcallfoid;
8941 int i_laninline;
8942 int i_lanvalidator;
8943 int i_lanacl;
8944 int i_acldefault;
8945 int i_lanowner;
8946
8947 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8948 "lanname, lanpltrusted, lanplcallfoid, "
8949 "laninline, lanvalidator, "
8950 "lanacl, "
8951 "acldefault('l', lanowner) AS acldefault, "
8952 "lanowner "
8953 "FROM pg_language "
8954 "WHERE lanispl "
8955 "ORDER BY oid");
8956
8957 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8958
8959 ntups = PQntuples(res);
8960
8961 planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo));
8962
8963 i_tableoid = PQfnumber(res, "tableoid");
8964 i_oid = PQfnumber(res, "oid");
8965 i_lanname = PQfnumber(res, "lanname");
8966 i_lanpltrusted = PQfnumber(res, "lanpltrusted");
8967 i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
8968 i_laninline = PQfnumber(res, "laninline");
8969 i_lanvalidator = PQfnumber(res, "lanvalidator");
8970 i_lanacl = PQfnumber(res, "lanacl");
8971 i_acldefault = PQfnumber(res, "acldefault");
8972 i_lanowner = PQfnumber(res, "lanowner");
8973
8974 for (i = 0; i < ntups; i++)
8975 {
8976 planginfo[i].dobj.objType = DO_PROCLANG;
8977 planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8978 planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8979 AssignDumpId(&planginfo[i].dobj);
8980
8981 planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
8982 planginfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_lanacl));
8983 planginfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
8984 planginfo[i].dacl.privtype = 0;
8985 planginfo[i].dacl.initprivs = NULL;
8986 planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
8987 planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
8988 planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
8989 planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
8990 planginfo[i].lanowner = getRoleName(PQgetvalue(res, i, i_lanowner));
8991
8992 /* Decide whether we want to dump it */
8993 selectDumpableProcLang(&(planginfo[i]), fout);
8994
8995 /* Mark whether language has an ACL */
8996 if (!PQgetisnull(res, i, i_lanacl))
8997 planginfo[i].dobj.components |= DUMP_COMPONENT_ACL;
8998 }
8999
9000 PQclear(res);
9001
9002 destroyPQExpBuffer(query);
9003}
static void selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
Definition: pg_dump.c:2201
Oid lanvalidator
Definition: pg_dump.h:538
DumpableAcl dacl
Definition: pg_dump.h:534
DumpableObject dobj
Definition: pg_dump.h:533
Oid laninline
Definition: pg_dump.h:537
const char * lanowner
Definition: pg_dump.h:539
Oid lanplcallfoid
Definition: pg_dump.h:536
bool lanpltrusted
Definition: pg_dump.h:535

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, selectDumpableProcLang(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getPublicationNamespaces()

void getPublicationNamespaces ( Archive fout)

Definition at line 4729 of file pg_dump.c.

4730{
4731 PQExpBuffer query;
4732 PGresult *res;
4733 PublicationSchemaInfo *pubsinfo;
4734 DumpOptions *dopt = fout->dopt;
4735 int i_tableoid;
4736 int i_oid;
4737 int i_pnpubid;
4738 int i_pnnspid;
4739 int i,
4740 j,
4741 ntups;
4742
4743 if (dopt->no_publications || fout->remoteVersion < 150000)
4744 return;
4745
4746 query = createPQExpBuffer();
4747
4748 /* Collect all publication membership info. */
4750 "SELECT tableoid, oid, pnpubid, pnnspid "
4751 "FROM pg_catalog.pg_publication_namespace");
4752 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4753
4754 ntups = PQntuples(res);
4755
4756 i_tableoid = PQfnumber(res, "tableoid");
4757 i_oid = PQfnumber(res, "oid");
4758 i_pnpubid = PQfnumber(res, "pnpubid");
4759 i_pnnspid = PQfnumber(res, "pnnspid");
4760
4761 /* this allocation may be more than we need */
4762 pubsinfo = pg_malloc(ntups * sizeof(PublicationSchemaInfo));
4763 j = 0;
4764
4765 for (i = 0; i < ntups; i++)
4766 {
4767 Oid pnpubid = atooid(PQgetvalue(res, i, i_pnpubid));
4768 Oid pnnspid = atooid(PQgetvalue(res, i, i_pnnspid));
4769 PublicationInfo *pubinfo;
4770 NamespaceInfo *nspinfo;
4771
4772 /*
4773 * Ignore any entries for which we aren't interested in either the
4774 * publication or the rel.
4775 */
4776 pubinfo = findPublicationByOid(pnpubid);
4777 if (pubinfo == NULL)
4778 continue;
4779 nspinfo = findNamespaceByOid(pnnspid);
4780 if (nspinfo == NULL)
4781 continue;
4782
4783 /* OK, make a DumpableObject for this relationship */
4785 pubsinfo[j].dobj.catId.tableoid =
4786 atooid(PQgetvalue(res, i, i_tableoid));
4787 pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4788 AssignDumpId(&pubsinfo[j].dobj);
4789 pubsinfo[j].dobj.namespace = nspinfo->dobj.namespace;
4790 pubsinfo[j].dobj.name = nspinfo->dobj.name;
4791 pubsinfo[j].publication = pubinfo;
4792 pubsinfo[j].pubschema = nspinfo;
4793
4794 /* Decide whether we want to dump it */
4795 selectDumpablePublicationObject(&(pubsinfo[j].dobj), fout);
4796
4797 j++;
4798 }
4799
4800 PQclear(res);
4801 destroyPQExpBuffer(query);
4802}
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition: common.c:990
PublicationInfo * findPublicationByOid(Oid oid)
Definition: common.c:1026
static void selectDumpablePublicationObject(DumpableObject *dobj, Archive *fout)
Definition: pg_dump.c:2308
NamespaceInfo * pubschema
Definition: pg_dump.h:701
DumpableObject dobj
Definition: pg_dump.h:699
PublicationInfo * publication
Definition: pg_dump.h:700
int no_publications
Definition: pg_backup.h:188

References appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PUBLICATION_TABLE_IN_SCHEMA, _namespaceInfo::dobj, _PublicationSchemaInfo::dobj, Archive::dopt, 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, selectDumpablePublicationObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getPublications()

void getPublications ( Archive fout)

Definition at line 4523 of file pg_dump.c.

4524{
4525 DumpOptions *dopt = fout->dopt;
4526 PQExpBuffer query;
4527 PGresult *res;
4528 PublicationInfo *pubinfo;
4529 int i_tableoid;
4530 int i_oid;
4531 int i_pubname;
4532 int i_pubowner;
4533 int i_puballtables;
4534 int i_pubinsert;
4535 int i_pubupdate;
4536 int i_pubdelete;
4537 int i_pubtruncate;
4538 int i_pubviaroot;
4539 int i_pubgencols;
4540 int i,
4541 ntups;
4542
4543 if (dopt->no_publications || fout->remoteVersion < 100000)
4544 return;
4545
4546 query = createPQExpBuffer();
4547
4548 /* Get the publications. */
4549 appendPQExpBufferStr(query, "SELECT p.tableoid, p.oid, p.pubname, "
4550 "p.pubowner, p.puballtables, p.pubinsert, "
4551 "p.pubupdate, p.pubdelete, ");
4552
4553 if (fout->remoteVersion >= 110000)
4554 appendPQExpBufferStr(query, "p.pubtruncate, ");
4555 else
4556 appendPQExpBufferStr(query, "false AS pubtruncate, ");
4557
4558 if (fout->remoteVersion >= 130000)
4559 appendPQExpBufferStr(query, "p.pubviaroot, ");
4560 else
4561 appendPQExpBufferStr(query, "false AS pubviaroot, ");
4562
4563 if (fout->remoteVersion >= 180000)
4564 appendPQExpBufferStr(query, "p.pubgencols ");
4565 else
4566 appendPQExpBuffer(query, "'%c' AS pubgencols ", PUBLISH_GENCOLS_NONE);
4567
4568 appendPQExpBufferStr(query, "FROM pg_publication p");
4569
4570 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4571
4572 ntups = PQntuples(res);
4573
4574 if (ntups == 0)
4575 goto cleanup;
4576
4577 i_tableoid = PQfnumber(res, "tableoid");
4578 i_oid = PQfnumber(res, "oid");
4579 i_pubname = PQfnumber(res, "pubname");
4580 i_pubowner = PQfnumber(res, "pubowner");
4581 i_puballtables = PQfnumber(res, "puballtables");
4582 i_pubinsert = PQfnumber(res, "pubinsert");
4583 i_pubupdate = PQfnumber(res, "pubupdate");
4584 i_pubdelete = PQfnumber(res, "pubdelete");
4585 i_pubtruncate = PQfnumber(res, "pubtruncate");
4586 i_pubviaroot = PQfnumber(res, "pubviaroot");
4587 i_pubgencols = PQfnumber(res, "pubgencols");
4588
4589 pubinfo = pg_malloc(ntups * sizeof(PublicationInfo));
4590
4591 for (i = 0; i < ntups; i++)
4592 {
4593 pubinfo[i].dobj.objType = DO_PUBLICATION;
4594 pubinfo[i].dobj.catId.tableoid =
4595 atooid(PQgetvalue(res, i, i_tableoid));
4596 pubinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4597 AssignDumpId(&pubinfo[i].dobj);
4598 pubinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_pubname));
4599 pubinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_pubowner));
4600 pubinfo[i].puballtables =
4601 (strcmp(PQgetvalue(res, i, i_puballtables), "t") == 0);
4602 pubinfo[i].pubinsert =
4603 (strcmp(PQgetvalue(res, i, i_pubinsert), "t") == 0);
4604 pubinfo[i].pubupdate =
4605 (strcmp(PQgetvalue(res, i, i_pubupdate), "t") == 0);
4606 pubinfo[i].pubdelete =
4607 (strcmp(PQgetvalue(res, i, i_pubdelete), "t") == 0);
4608 pubinfo[i].pubtruncate =
4609 (strcmp(PQgetvalue(res, i, i_pubtruncate), "t") == 0);
4610 pubinfo[i].pubviaroot =
4611 (strcmp(PQgetvalue(res, i, i_pubviaroot), "t") == 0);
4612 pubinfo[i].pubgencols_type =
4613 *(PQgetvalue(res, i, i_pubgencols));
4614
4615 /* Decide whether we want to dump it */
4616 selectDumpableObject(&(pubinfo[i].dobj), fout);
4617 }
4618
4619cleanup:
4620 PQclear(res);
4621
4622 destroyPQExpBuffer(query);
4623}
const char * rolname
Definition: pg_dump.h:670
bool puballtables
Definition: pg_dump.h:671
bool pubtruncate
Definition: pg_dump.h:675
PublishGencolsType pubgencols_type
Definition: pg_dump.h:677
DumpableObject dobj
Definition: pg_dump.h:669

References appendPQExpBuffer(), 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_type, _PublicationInfo::pubinsert, _PublicationInfo::pubtruncate, _PublicationInfo::pubupdate, _PublicationInfo::pubviaroot, Archive::remoteVersion, _PublicationInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getPublicationTables()

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

Definition at line 4809 of file pg_dump.c.

4810{
4811 PQExpBuffer query;
4812 PGresult *res;
4813 PublicationRelInfo *pubrinfo;
4814 DumpOptions *dopt = fout->dopt;
4815 int i_tableoid;
4816 int i_oid;
4817 int i_prpubid;
4818 int i_prrelid;
4819 int i_prrelqual;
4820 int i_prattrs;
4821 int i,
4822 j,
4823 ntups;
4824
4825 if (dopt->no_publications || fout->remoteVersion < 100000)
4826 return;
4827
4828 query = createPQExpBuffer();
4829
4830 /* Collect all publication membership info. */
4831 if (fout->remoteVersion >= 150000)
4833 "SELECT tableoid, oid, prpubid, prrelid, "
4834 "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4835 "(CASE\n"
4836 " WHEN pr.prattrs IS NOT NULL THEN\n"
4837 " (SELECT array_agg(attname)\n"
4838 " FROM\n"
4839 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4840 " pg_catalog.pg_attribute\n"
4841 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4842 " ELSE NULL END) prattrs "
4843 "FROM pg_catalog.pg_publication_rel pr");
4844 else
4846 "SELECT tableoid, oid, prpubid, prrelid, "
4847 "NULL AS prrelqual, NULL AS prattrs "
4848 "FROM pg_catalog.pg_publication_rel");
4849 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4850
4851 ntups = PQntuples(res);
4852
4853 i_tableoid = PQfnumber(res, "tableoid");
4854 i_oid = PQfnumber(res, "oid");
4855 i_prpubid = PQfnumber(res, "prpubid");
4856 i_prrelid = PQfnumber(res, "prrelid");
4857 i_prrelqual = PQfnumber(res, "prrelqual");
4858 i_prattrs = PQfnumber(res, "prattrs");
4859
4860 /* this allocation may be more than we need */
4861 pubrinfo = pg_malloc(ntups * sizeof(PublicationRelInfo));
4862 j = 0;
4863
4864 for (i = 0; i < ntups; i++)
4865 {
4866 Oid prpubid = atooid(PQgetvalue(res, i, i_prpubid));
4867 Oid prrelid = atooid(PQgetvalue(res, i, i_prrelid));
4868 PublicationInfo *pubinfo;
4869 TableInfo *tbinfo;
4870
4871 /*
4872 * Ignore any entries for which we aren't interested in either the
4873 * publication or the rel.
4874 */
4875 pubinfo = findPublicationByOid(prpubid);
4876 if (pubinfo == NULL)
4877 continue;
4878 tbinfo = findTableByOid(prrelid);
4879 if (tbinfo == NULL)
4880 continue;
4881
4882 /* OK, make a DumpableObject for this relationship */
4883 pubrinfo[j].dobj.objType = DO_PUBLICATION_REL;
4884 pubrinfo[j].dobj.catId.tableoid =
4885 atooid(PQgetvalue(res, i, i_tableoid));
4886 pubrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4887 AssignDumpId(&pubrinfo[j].dobj);
4888 pubrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4889 pubrinfo[j].dobj.name = tbinfo->dobj.name;
4890 pubrinfo[j].publication = pubinfo;
4891 pubrinfo[j].pubtable = tbinfo;
4892 if (PQgetisnull(res, i, i_prrelqual))
4893 pubrinfo[j].pubrelqual = NULL;
4894 else
4895 pubrinfo[j].pubrelqual = pg_strdup(PQgetvalue(res, i, i_prrelqual));
4896
4897 if (!PQgetisnull(res, i, i_prattrs))
4898 {
4899 char **attnames;
4900 int nattnames;
4901 PQExpBuffer attribs;
4902
4903 if (!parsePGArray(PQgetvalue(res, i, i_prattrs),
4904 &attnames, &nattnames))
4905 pg_fatal("could not parse %s array", "prattrs");
4906 attribs = createPQExpBuffer();
4907 for (int k = 0; k < nattnames; k++)
4908 {
4909 if (k > 0)
4910 appendPQExpBufferStr(attribs, ", ");
4911
4912 appendPQExpBufferStr(attribs, fmtId(attnames[k]));
4913 }
4914 pubrinfo[j].pubrattrs = attribs->data;
4915 free(attribs); /* but not attribs->data */
4916 free(attnames);
4917 }
4918 else
4919 pubrinfo[j].pubrattrs = NULL;
4920
4921 /* Decide whether we want to dump it */
4922 selectDumpablePublicationObject(&(pubrinfo[j].dobj), fout);
4923
4924 j++;
4925 }
4926
4927 PQclear(res);
4928 destroyPQExpBuffer(query);
4929}
#define free(a)
Definition: header.h:65
const char * fmtId(const char *rawid)
Definition: string_utils.c:248

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

Referenced by getSchemaData().

◆ getRules()

void getRules ( Archive fout)

Definition at line 8558 of file pg_dump.c.

8559{
8560 PGresult *res;
8561 int ntups;
8562 int i;
8564 RuleInfo *ruleinfo;
8565 int i_tableoid;
8566 int i_oid;
8567 int i_rulename;
8568 int i_ruletable;
8569 int i_ev_type;
8570 int i_is_instead;
8571 int i_ev_enabled;
8572
8573 appendPQExpBufferStr(query, "SELECT "
8574 "tableoid, oid, rulename, "
8575 "ev_class AS ruletable, ev_type, is_instead, "
8576 "ev_enabled "
8577 "FROM pg_rewrite "
8578 "ORDER BY oid");
8579
8580 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8581
8582 ntups = PQntuples(res);
8583
8584 ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo));
8585
8586 i_tableoid = PQfnumber(res, "tableoid");
8587 i_oid = PQfnumber(res, "oid");
8588 i_rulename = PQfnumber(res, "rulename");
8589 i_ruletable = PQfnumber(res, "ruletable");
8590 i_ev_type = PQfnumber(res, "ev_type");
8591 i_is_instead = PQfnumber(res, "is_instead");
8592 i_ev_enabled = PQfnumber(res, "ev_enabled");
8593
8594 for (i = 0; i < ntups; i++)
8595 {
8596 Oid ruletableoid;
8597
8598 ruleinfo[i].dobj.objType = DO_RULE;
8599 ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8600 ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8601 AssignDumpId(&ruleinfo[i].dobj);
8602 ruleinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_rulename));
8603 ruletableoid = atooid(PQgetvalue(res, i, i_ruletable));
8604 ruleinfo[i].ruletable = findTableByOid(ruletableoid);
8605 if (ruleinfo[i].ruletable == NULL)
8606 pg_fatal("failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
8607 ruletableoid, ruleinfo[i].dobj.catId.oid);
8608 ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace;
8609 ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump;
8610 ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type));
8611 ruleinfo[i].is_instead = *(PQgetvalue(res, i, i_is_instead)) == 't';
8612 ruleinfo[i].ev_enabled = *(PQgetvalue(res, i, i_ev_enabled));
8613 if (ruleinfo[i].ruletable)
8614 {
8615 /*
8616 * If the table is a view or materialized view, force its ON
8617 * SELECT rule to be sorted before the view itself --- this
8618 * ensures that any dependencies for the rule affect the table's
8619 * positioning. Other rules are forced to appear after their
8620 * table.
8621 */
8622 if ((ruleinfo[i].ruletable->relkind == RELKIND_VIEW ||
8623 ruleinfo[i].ruletable->relkind == RELKIND_MATVIEW) &&
8624 ruleinfo[i].ev_type == '1' && ruleinfo[i].is_instead)
8625 {
8626 addObjectDependency(&ruleinfo[i].ruletable->dobj,
8627 ruleinfo[i].dobj.dumpId);
8628 /* We'll merge the rule into CREATE VIEW, if possible */
8629 ruleinfo[i].separate = false;
8630 }
8631 else
8632 {
8633 addObjectDependency(&ruleinfo[i].dobj,
8634 ruleinfo[i].ruletable->dobj.dumpId);
8635 ruleinfo[i].separate = true;
8636 }
8637 }
8638 else
8639 ruleinfo[i].separate = true;
8640 }
8641
8642 PQclear(res);
8643
8644 destroyPQExpBuffer(query);
8645}
DumpableObject dobj
Definition: pg_dump.h:476
bool separate
Definition: pg_dump.h:481
char ev_enabled
Definition: pg_dump.h:480
bool is_instead
Definition: pg_dump.h:479
TableInfo * ruletable
Definition: pg_dump.h:477
char ev_type
Definition: pg_dump.h:478

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, _ruleInfo::ruletable, _ruleInfo::separate, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getSchemaData()

TableInfo * getSchemaData ( Archive fout,
int *  numTablesPtr 
)

Definition at line 98 of file common.c.

99{
100 TableInfo *tblinfo;
101 ExtensionInfo *extinfo;
102 InhInfo *inhinfo;
103 int numTables;
104 int numExtensions;
105 int numInherits;
106
107 /*
108 * We must read extensions and extension membership info first, because
109 * extension membership needs to be consultable during decisions about
110 * whether other objects are to be dumped.
111 */
112 pg_log_info("reading extensions");
113 extinfo = getExtensions(fout, &numExtensions);
114
115 pg_log_info("identifying extension members");
116 getExtensionMembership(fout, extinfo, numExtensions);
117
118 pg_log_info("reading schemas");
119 getNamespaces(fout);
120
121 /*
122 * getTables should be done as soon as possible, so as to minimize the
123 * window between starting our transaction and acquiring per-table locks.
124 * However, we have to do getNamespaces first because the tables get
125 * linked to their containing namespaces during getTables.
126 */
127 pg_log_info("reading user-defined tables");
128 tblinfo = getTables(fout, &numTables);
129
130 getOwnedSeqs(fout, tblinfo, numTables);
131
132 pg_log_info("reading user-defined functions");
133 getFuncs(fout);
134
135 /* this must be after getTables and getFuncs */
136 pg_log_info("reading user-defined types");
137 getTypes(fout);
138
139 /* this must be after getFuncs, too */
140 pg_log_info("reading procedural languages");
141 getProcLangs(fout);
142
143 pg_log_info("reading user-defined aggregate functions");
144 getAggregates(fout);
145
146 pg_log_info("reading user-defined operators");
147 getOperators(fout);
148
149 pg_log_info("reading user-defined access methods");
150 getAccessMethods(fout);
151
152 pg_log_info("reading user-defined operator classes");
153 getOpclasses(fout);
154
155 pg_log_info("reading user-defined operator families");
156 getOpfamilies(fout);
157
158 pg_log_info("reading user-defined text search parsers");
159 getTSParsers(fout);
160
161 pg_log_info("reading user-defined text search templates");
162 getTSTemplates(fout);
163
164 pg_log_info("reading user-defined text search dictionaries");
165 getTSDictionaries(fout);
166
167 pg_log_info("reading user-defined text search configurations");
169
170 pg_log_info("reading user-defined foreign-data wrappers");
172
173 pg_log_info("reading user-defined foreign servers");
174 getForeignServers(fout);
175
176 pg_log_info("reading default privileges");
177 getDefaultACLs(fout);
178
179 pg_log_info("reading user-defined collations");
180 getCollations(fout);
181
182 pg_log_info("reading user-defined conversions");
183 getConversions(fout);
184
185 pg_log_info("reading type casts");
186 getCasts(fout);
187
188 pg_log_info("reading transforms");
189 getTransforms(fout);
190
191 pg_log_info("reading table inheritance information");
192 inhinfo = getInherits(fout, &numInherits);
193
194 pg_log_info("reading event triggers");
195 getEventTriggers(fout);
196
197 /* Identify extension configuration tables that should be dumped */
198 pg_log_info("finding extension tables");
199 processExtensionTables(fout, extinfo, numExtensions);
200
201 /* Link tables to parents, mark parents of target tables interesting */
202 pg_log_info("finding inheritance relationships");
203 flagInhTables(fout, tblinfo, numTables, inhinfo, numInherits);
204
205 pg_log_info("reading column info for interesting tables");
206 getTableAttrs(fout, tblinfo, numTables);
207
208 pg_log_info("flagging inherited columns in subtables");
209 flagInhAttrs(fout, fout->dopt, tblinfo, numTables);
210
211 pg_log_info("reading partitioning data");
213
214 pg_log_info("reading indexes");
215 getIndexes(fout, tblinfo, numTables);
216
217 pg_log_info("flagging indexes in partitioned tables");
218 flagInhIndexes(fout, tblinfo, numTables);
219
220 pg_log_info("reading extended statistics");
222
223 pg_log_info("reading constraints");
224 getConstraints(fout, tblinfo, numTables);
225
226 pg_log_info("reading triggers");
227 getTriggers(fout, tblinfo, numTables);
228
229 pg_log_info("reading rewrite rules");
230 getRules(fout);
231
232 pg_log_info("reading policies");
233 getPolicies(fout, tblinfo, numTables);
234
235 pg_log_info("reading publications");
236 getPublications(fout);
237
238 pg_log_info("reading publication membership of tables");
239 getPublicationTables(fout, tblinfo, numTables);
240
241 pg_log_info("reading publication membership of schemas");
243
244 pg_log_info("reading subscriptions");
245 getSubscriptions(fout);
246
247 pg_log_info("reading subscription membership of tables");
249
250 free(inhinfo); /* not needed any longer */
251
252 *numTablesPtr = numTables;
253 return tblinfo;
254}
static void flagInhAttrs(Archive *fout, DumpOptions *dopt, TableInfo *tblinfo, int numTables)
Definition: common.c:478
static void flagInhTables(Archive *fout, TableInfo *tblinfo, int numTables, InhInfo *inhinfo, int numInherits)
Definition: common.c:269
static void flagInhIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:8264
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition: pg_dump.c:6096
void getPublicationNamespaces(Archive *fout)
Definition: pg_dump.c:4729
void getPartitioningInfo(Archive *fout)
Definition: pg_dump.c:7756
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition: pg_dump.c:7700
void getForeignDataWrappers(Archive *fout)
Definition: pg_dump.c:10382
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:4233
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition: pg_dump.c:19658
void getTypes(Archive *fout)
Definition: pg_dump.c:6171
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:7635
void getOpclasses(Archive *fout)
Definition: pg_dump.c:6617
void getForeignServers(Archive *fout)
Definition: pg_dump.c:10466
void getFuncs(Archive *fout)
Definition: pg_dump.c:6886
void getTSDictionaries(Archive *fout)
Definition: pg_dump.c:10198
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:4809
void getCasts(Archive *fout)
Definition: pg_dump.c:9013
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:7816
void getTSConfigurations(Archive *fout)
Definition: pg_dump.c:10323
void getAccessMethods(Archive *fout)
Definition: pg_dump.c:6543
void getConversions(Archive *fout)
Definition: pg_dump.c:6481
void getRules(Archive *fout)
Definition: pg_dump.c:8558
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition: pg_dump.c:9207
void getSubscriptionTables(Archive *fout)
Definition: pg_dump.c:5300
void getCollations(Archive *fout)
Definition: pg_dump.c:6415
void getAggregates(Archive *fout)
Definition: pg_dump.c:6745
void getNamespaces(Archive *fout)
Definition: pg_dump.c:5964
void getPublications(Archive *fout)
Definition: pg_dump.c:4523
void getTSParsers(Archive *fout)
Definition: pg_dump.c:10124
TableInfo * getTables(Archive *fout, int *numTables)
Definition: pg_dump.c:7158
void getExtendedStatistics(Archive *fout)
Definition: pg_dump.c:8185
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition: pg_dump.c:19751
void getDefaultACLs(Archive *fout)
Definition: pg_dump.c:10554
void getSubscriptions(Archive *fout)
Definition: pg_dump.c:5080
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:8655
void getTransforms(Archive *fout)
Definition: pg_dump.c:9123
void getEventTriggers(Archive *fout)
Definition: pg_dump.c:8851
void getTSTemplates(Archive *fout)
Definition: pg_dump.c:10264
void getProcLangs(Archive *fout)
Definition: pg_dump.c:8929
void getOperators(Archive *fout)
Definition: pg_dump.c:6339
void getOpfamilies(Archive *fout)
Definition: pg_dump.c:6680

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

5081{
5082 DumpOptions *dopt = fout->dopt;
5083 PQExpBuffer query;
5084 PGresult *res;
5085 SubscriptionInfo *subinfo;
5086 int i_tableoid;
5087 int i_oid;
5088 int i_subname;
5089 int i_subowner;
5090 int i_subbinary;
5091 int i_substream;
5092 int i_subtwophasestate;
5093 int i_subdisableonerr;
5094 int i_subpasswordrequired;
5095 int i_subrunasowner;
5096 int i_subconninfo;
5097 int i_subslotname;
5098 int i_subsynccommit;
5099 int i_subpublications;
5100 int i_suborigin;
5101 int i_suboriginremotelsn;
5102 int i_subenabled;
5103 int i_subfailover;
5104 int i_subretaindeadtuples;
5105 int i_submaxretention;
5106 int i,
5107 ntups;
5108
5109 if (dopt->no_subscriptions || fout->remoteVersion < 100000)
5110 return;
5111
5112 if (!is_superuser(fout))
5113 {
5114 int n;
5115
5116 res = ExecuteSqlQuery(fout,
5117 "SELECT count(*) FROM pg_subscription "
5118 "WHERE subdbid = (SELECT oid FROM pg_database"
5119 " WHERE datname = current_database())",
5121 n = atoi(PQgetvalue(res, 0, 0));
5122 if (n > 0)
5123 pg_log_warning("subscriptions not dumped because current user is not a superuser");
5124 PQclear(res);
5125 return;
5126 }
5127
5128 query = createPQExpBuffer();
5129
5130 /* Get the subscriptions in current database. */
5132 "SELECT s.tableoid, s.oid, s.subname,\n"
5133 " s.subowner,\n"
5134 " s.subconninfo, s.subslotname, s.subsynccommit,\n"
5135 " s.subpublications,\n");
5136
5137 if (fout->remoteVersion >= 140000)
5138 appendPQExpBufferStr(query, " s.subbinary,\n");
5139 else
5140 appendPQExpBufferStr(query, " false AS subbinary,\n");
5141
5142 if (fout->remoteVersion >= 140000)
5143 appendPQExpBufferStr(query, " s.substream,\n");
5144 else
5145 appendPQExpBufferStr(query, " 'f' AS substream,\n");
5146
5147 if (fout->remoteVersion >= 150000)
5149 " s.subtwophasestate,\n"
5150 " s.subdisableonerr,\n");
5151 else
5152 appendPQExpBuffer(query,
5153 " '%c' AS subtwophasestate,\n"
5154 " false AS subdisableonerr,\n",
5155 LOGICALREP_TWOPHASE_STATE_DISABLED);
5156
5157 if (fout->remoteVersion >= 160000)
5159 " s.subpasswordrequired,\n"
5160 " s.subrunasowner,\n"
5161 " s.suborigin,\n");
5162 else
5163 appendPQExpBuffer(query,
5164 " 't' AS subpasswordrequired,\n"
5165 " 't' AS subrunasowner,\n"
5166 " '%s' AS suborigin,\n",
5167 LOGICALREP_ORIGIN_ANY);
5168
5169 if (dopt->binary_upgrade && fout->remoteVersion >= 170000)
5170 appendPQExpBufferStr(query, " o.remote_lsn AS suboriginremotelsn,\n"
5171 " s.subenabled,\n");
5172 else
5173 appendPQExpBufferStr(query, " NULL AS suboriginremotelsn,\n"
5174 " false AS subenabled,\n");
5175
5176 if (fout->remoteVersion >= 170000)
5178 " s.subfailover,\n");
5179 else
5181 " false AS subfailover,\n");
5182
5183 if (fout->remoteVersion >= 190000)
5185 " s.subretaindeadtuples,\n");
5186 else
5188 " false AS subretaindeadtuples,\n");
5189
5190 if (fout->remoteVersion >= 190000)
5192 " s.submaxretention\n");
5193 else
5194 appendPQExpBuffer(query,
5195 " 0 AS submaxretention\n");
5196
5198 "FROM pg_subscription s\n");
5199
5200 if (dopt->binary_upgrade && fout->remoteVersion >= 170000)
5202 "LEFT JOIN pg_catalog.pg_replication_origin_status o \n"
5203 " ON o.external_id = 'pg_' || s.oid::text \n");
5204
5206 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
5207 " WHERE datname = current_database())");
5208
5209 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5210
5211 ntups = PQntuples(res);
5212
5213 /*
5214 * Get subscription fields. We don't include subskiplsn in the dump as
5215 * after restoring the dump this value may no longer be relevant.
5216 */
5217 i_tableoid = PQfnumber(res, "tableoid");
5218 i_oid = PQfnumber(res, "oid");
5219 i_subname = PQfnumber(res, "subname");
5220 i_subowner = PQfnumber(res, "subowner");
5221 i_subenabled = PQfnumber(res, "subenabled");
5222 i_subbinary = PQfnumber(res, "subbinary");
5223 i_substream = PQfnumber(res, "substream");
5224 i_subtwophasestate = PQfnumber(res, "subtwophasestate");
5225 i_subdisableonerr = PQfnumber(res, "subdisableonerr");
5226 i_subpasswordrequired = PQfnumber(res, "subpasswordrequired");
5227 i_subrunasowner = PQfnumber(res, "subrunasowner");
5228 i_subfailover = PQfnumber(res, "subfailover");
5229 i_subretaindeadtuples = PQfnumber(res, "subretaindeadtuples");
5230 i_submaxretention = PQfnumber(res, "submaxretention");
5231 i_subconninfo = PQfnumber(res, "subconninfo");
5232 i_subslotname = PQfnumber(res, "subslotname");
5233 i_subsynccommit = PQfnumber(res, "subsynccommit");
5234 i_subpublications = PQfnumber(res, "subpublications");
5235 i_suborigin = PQfnumber(res, "suborigin");
5236 i_suboriginremotelsn = PQfnumber(res, "suboriginremotelsn");
5237
5238 subinfo = pg_malloc(ntups * sizeof(SubscriptionInfo));
5239
5240 for (i = 0; i < ntups; i++)
5241 {
5242 subinfo[i].dobj.objType = DO_SUBSCRIPTION;
5243 subinfo[i].dobj.catId.tableoid =
5244 atooid(PQgetvalue(res, i, i_tableoid));
5245 subinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5246 AssignDumpId(&subinfo[i].dobj);
5247 subinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_subname));
5248 subinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_subowner));
5249
5250 subinfo[i].subenabled =
5251 (strcmp(PQgetvalue(res, i, i_subenabled), "t") == 0);
5252 subinfo[i].subbinary =
5253 (strcmp(PQgetvalue(res, i, i_subbinary), "t") == 0);
5254 subinfo[i].substream = *(PQgetvalue(res, i, i_substream));
5255 subinfo[i].subtwophasestate = *(PQgetvalue(res, i, i_subtwophasestate));
5256 subinfo[i].subdisableonerr =
5257 (strcmp(PQgetvalue(res, i, i_subdisableonerr), "t") == 0);
5258 subinfo[i].subpasswordrequired =
5259 (strcmp(PQgetvalue(res, i, i_subpasswordrequired), "t") == 0);
5260 subinfo[i].subrunasowner =
5261 (strcmp(PQgetvalue(res, i, i_subrunasowner), "t") == 0);
5262 subinfo[i].subfailover =
5263 (strcmp(PQgetvalue(res, i, i_subfailover), "t") == 0);
5264 subinfo[i].subretaindeadtuples =
5265 (strcmp(PQgetvalue(res, i, i_subretaindeadtuples), "t") == 0);
5266 subinfo[i].submaxretention =
5267 atoi(PQgetvalue(res, i, i_submaxretention));
5268 subinfo[i].subconninfo =
5269 pg_strdup(PQgetvalue(res, i, i_subconninfo));
5270 if (PQgetisnull(res, i, i_subslotname))
5271 subinfo[i].subslotname = NULL;
5272 else
5273 subinfo[i].subslotname =
5274 pg_strdup(PQgetvalue(res, i, i_subslotname));
5275 subinfo[i].subsynccommit =
5276 pg_strdup(PQgetvalue(res, i, i_subsynccommit));
5277 subinfo[i].subpublications =
5278 pg_strdup(PQgetvalue(res, i, i_subpublications));
5279 subinfo[i].suborigin = pg_strdup(PQgetvalue(res, i, i_suborigin));
5280 if (PQgetisnull(res, i, i_suboriginremotelsn))
5281 subinfo[i].suboriginremotelsn = NULL;
5282 else
5283 subinfo[i].suboriginremotelsn =
5284 pg_strdup(PQgetvalue(res, i, i_suboriginremotelsn));
5285
5286 /* Decide whether we want to dump it */
5287 selectDumpableObject(&(subinfo[i].dobj), fout);
5288 }
5289 PQclear(res);
5290
5291 destroyPQExpBuffer(query);
5292}
static bool is_superuser(Archive *fout)
Definition: pg_dump.c:5040
char * suboriginremotelsn
Definition: pg_dump.h:726
bool subpasswordrequired
Definition: pg_dump.h:716
char * suborigin
Definition: pg_dump.h:725
const char * rolname
Definition: pg_dump.h:710
char * subsynccommit
Definition: pg_dump.h:723
char * subpublications
Definition: pg_dump.h:724
bool subdisableonerr
Definition: pg_dump.h:715
bool subrunasowner
Definition: pg_dump.h:717
char * subslotname
Definition: pg_dump.h:722
char subtwophasestate
Definition: pg_dump.h:714
bool subretaindeadtuples
Definition: pg_dump.h:719
char * subconninfo
Definition: pg_dump.h:721
DumpableObject dobj
Definition: pg_dump.h:709
int no_subscriptions
Definition: pg_backup.h:190

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(), _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, _SubscriptionInfo::rolname, selectDumpableObject(), _SubscriptionInfo::subbinary, _SubscriptionInfo::subconninfo, _SubscriptionInfo::subdisableonerr, _SubscriptionInfo::subenabled, _SubscriptionInfo::subfailover, _SubscriptionInfo::submaxretention, _SubscriptionInfo::suborigin, _SubscriptionInfo::suboriginremotelsn, _SubscriptionInfo::subpasswordrequired, _SubscriptionInfo::subpublications, _SubscriptionInfo::subretaindeadtuples, _SubscriptionInfo::subrunasowner, _SubscriptionInfo::subslotname, _SubscriptionInfo::substream, _SubscriptionInfo::subsynccommit, _SubscriptionInfo::subtwophasestate, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getSubscriptionTables()

void getSubscriptionTables ( Archive fout)

Definition at line 5300 of file pg_dump.c.

5301{
5302 DumpOptions *dopt = fout->dopt;
5303 SubscriptionInfo *subinfo = NULL;
5304 SubRelInfo *subrinfo;
5305 PGresult *res;
5306 int i_srsubid;
5307 int i_srrelid;
5308 int i_srsubstate;
5309 int i_srsublsn;
5310 int ntups;
5311 Oid last_srsubid = InvalidOid;
5312
5313 if (dopt->no_subscriptions || !dopt->binary_upgrade ||
5314 fout->remoteVersion < 170000)
5315 return;
5316
5317 res = ExecuteSqlQuery(fout,
5318 "SELECT srsubid, srrelid, srsubstate, srsublsn "
5319 "FROM pg_catalog.pg_subscription_rel "
5320 "ORDER BY srsubid",
5322 ntups = PQntuples(res);
5323 if (ntups == 0)
5324 goto cleanup;
5325
5326 /* Get pg_subscription_rel attributes */
5327 i_srsubid = PQfnumber(res, "srsubid");
5328 i_srrelid = PQfnumber(res, "srrelid");
5329 i_srsubstate = PQfnumber(res, "srsubstate");
5330 i_srsublsn = PQfnumber(res, "srsublsn");
5331
5332 subrinfo = pg_malloc(ntups * sizeof(SubRelInfo));
5333 for (int i = 0; i < ntups; i++)
5334 {
5335 Oid cur_srsubid = atooid(PQgetvalue(res, i, i_srsubid));
5336 Oid relid = atooid(PQgetvalue(res, i, i_srrelid));
5337 TableInfo *tblinfo;
5338
5339 /*
5340 * If we switched to a new subscription, check if the subscription
5341 * exists.
5342 */
5343 if (cur_srsubid != last_srsubid)
5344 {
5345 subinfo = findSubscriptionByOid(cur_srsubid);
5346 if (subinfo == NULL)
5347 pg_fatal("subscription with OID %u does not exist", cur_srsubid);
5348
5349 last_srsubid = cur_srsubid;
5350 }
5351
5352 tblinfo = findTableByOid(relid);
5353 if (tblinfo == NULL)
5354 pg_fatal("failed sanity check, table with OID %u not found",
5355 relid);
5356
5357 /* OK, make a DumpableObject for this relationship */
5358 subrinfo[i].dobj.objType = DO_SUBSCRIPTION_REL;
5359 subrinfo[i].dobj.catId.tableoid = relid;
5360 subrinfo[i].dobj.catId.oid = cur_srsubid;
5361 AssignDumpId(&subrinfo[i].dobj);
5362 subrinfo[i].dobj.name = pg_strdup(subinfo->dobj.name);
5363 subrinfo[i].tblinfo = tblinfo;
5364 subrinfo[i].srsubstate = PQgetvalue(res, i, i_srsubstate)[0];
5365 if (PQgetisnull(res, i, i_srsublsn))
5366 subrinfo[i].srsublsn = NULL;
5367 else
5368 subrinfo[i].srsublsn = pg_strdup(PQgetvalue(res, i, i_srsublsn));
5369
5370 subrinfo[i].subinfo = subinfo;
5371
5372 /* Decide whether we want to dump it */
5373 selectDumpableObject(&(subrinfo[i].dobj), fout);
5374 }
5375
5376cleanup:
5377 PQclear(res);
5378}
SubscriptionInfo * findSubscriptionByOid(Oid oid)
Definition: common.c:1044
DumpableObject dobj
Definition: pg_dump.h:741
char * srsublsn
Definition: pg_dump.h:745
SubscriptionInfo * subinfo
Definition: pg_dump.h:742
TableInfo * tblinfo
Definition: pg_dump.h:743
char srsubstate
Definition: pg_dump.h:744

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

9208{
9209 DumpOptions *dopt = fout->dopt;
9211 PQExpBuffer tbloids = createPQExpBuffer();
9212 PQExpBuffer checkoids = createPQExpBuffer();
9213 PQExpBuffer invalidnotnulloids = NULL;
9214 PGresult *res;
9215 int ntups;
9216 int curtblindx;
9217 int i_attrelid;
9218 int i_attnum;
9219 int i_attname;
9220 int i_atttypname;
9221 int i_attstattarget;
9222 int i_attstorage;
9223 int i_typstorage;
9224 int i_attidentity;
9225 int i_attgenerated;
9226 int i_attisdropped;
9227 int i_attlen;
9228 int i_attalign;
9229 int i_attislocal;
9230 int i_notnull_name;
9231 int i_notnull_comment;
9232 int i_notnull_noinherit;
9233 int i_notnull_islocal;
9234 int i_notnull_invalidoid;
9235 int i_attoptions;
9236 int i_attcollation;
9237 int i_attcompression;
9238 int i_attfdwoptions;
9239 int i_attmissingval;
9240 int i_atthasdef;
9241
9242 /*
9243 * We want to perform just one query against pg_attribute, and then just
9244 * one against pg_attrdef (for DEFAULTs) and two against pg_constraint
9245 * (for CHECK constraints and for NOT NULL constraints). However, we
9246 * mustn't try to select every row of those catalogs and then sort it out
9247 * on the client side, because some of the server-side functions we need
9248 * would be unsafe to apply to tables we don't have lock on. Hence, we
9249 * build an array of the OIDs of tables we care about (and now have lock
9250 * on!), and use a WHERE clause to constrain which rows are selected.
9251 */
9252 appendPQExpBufferChar(tbloids, '{');
9253 appendPQExpBufferChar(checkoids, '{');
9254 for (int i = 0; i < numTables; i++)
9255 {
9256 TableInfo *tbinfo = &tblinfo[i];
9257
9258 /* Don't bother to collect info for sequences */
9259 if (tbinfo->relkind == RELKIND_SEQUENCE)
9260 continue;
9261
9262 /*
9263 * Don't bother with uninteresting tables, either. For binary
9264 * upgrades, this is bypassed for pg_largeobject_metadata and
9265 * pg_shdepend so that the columns names are collected for the
9266 * corresponding COPY commands. Restoring the data for those catalogs
9267 * is faster than restoring the equivalent set of large object
9268 * commands. We can only do this for upgrades from v12 and newer; in
9269 * older versions, pg_largeobject_metadata was created WITH OIDS, so
9270 * the OID column is hidden and won't be dumped.
9271 */
9272 if (!tbinfo->interesting &&
9273 !(fout->dopt->binary_upgrade && fout->remoteVersion >= 120000 &&
9274 (tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId ||
9275 tbinfo->dobj.catId.oid == SharedDependRelationId)))
9276 continue;
9277
9278 /* OK, we need info for this table */
9279 if (tbloids->len > 1) /* do we have more than the '{'? */
9280 appendPQExpBufferChar(tbloids, ',');
9281 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
9282
9283 if (tbinfo->ncheck > 0)
9284 {
9285 /* Also make a list of the ones with check constraints */
9286 if (checkoids->len > 1) /* do we have more than the '{'? */
9287 appendPQExpBufferChar(checkoids, ',');
9288 appendPQExpBuffer(checkoids, "%u", tbinfo->dobj.catId.oid);
9289 }
9290 }
9291 appendPQExpBufferChar(tbloids, '}');
9292 appendPQExpBufferChar(checkoids, '}');
9293
9294 /*
9295 * Find all the user attributes and their types.
9296 *
9297 * Since we only want to dump COLLATE clauses for attributes whose
9298 * collation is different from their type's default, we use a CASE here to
9299 * suppress uninteresting attcollations cheaply.
9300 */
9302 "SELECT\n"
9303 "a.attrelid,\n"
9304 "a.attnum,\n"
9305 "a.attname,\n"
9306 "a.attstattarget,\n"
9307 "a.attstorage,\n"
9308 "t.typstorage,\n"
9309 "a.atthasdef,\n"
9310 "a.attisdropped,\n"
9311 "a.attlen,\n"
9312 "a.attalign,\n"
9313 "a.attislocal,\n"
9314 "pg_catalog.format_type(t.oid, a.atttypmod) AS atttypname,\n"
9315 "array_to_string(a.attoptions, ', ') AS attoptions,\n"
9316 "CASE WHEN a.attcollation <> t.typcollation "
9317 "THEN a.attcollation ELSE 0 END AS attcollation,\n"
9318 "pg_catalog.array_to_string(ARRAY("
9319 "SELECT pg_catalog.quote_ident(option_name) || "
9320 "' ' || pg_catalog.quote_literal(option_value) "
9321 "FROM pg_catalog.pg_options_to_table(attfdwoptions) "
9322 "ORDER BY option_name"
9323 "), E',\n ') AS attfdwoptions,\n");
9324
9325 /*
9326 * Find out any NOT NULL markings for each column. In 18 and up we read
9327 * pg_constraint to obtain the constraint name, and for valid constraints
9328 * also pg_description to obtain its comment. notnull_noinherit is set
9329 * according to the NO INHERIT property. For versions prior to 18, we
9330 * store an empty string as the name when a constraint is marked as
9331 * attnotnull (this cues dumpTableSchema to print the NOT NULL clause
9332 * without a name); also, such cases are never NO INHERIT.
9333 *
9334 * For invalid constraints, we need to store their OIDs for processing
9335 * elsewhere, so we bring the pg_constraint.oid value when the constraint
9336 * is invalid, and NULL otherwise. Their comments are handled not here
9337 * but by collectComments, because they're their own dumpable object.
9338 *
9339 * We track in notnull_islocal whether the constraint was defined directly
9340 * in this table or via an ancestor, for binary upgrade. flagInhAttrs
9341 * might modify this later; that routine is also in charge of determining
9342 * the correct inhcount.
9343 */
9344 if (fout->remoteVersion >= 180000)
9346 "co.conname AS notnull_name,\n"
9347 "CASE WHEN co.convalidated THEN pt.description"
9348 " ELSE NULL END AS notnull_comment,\n"
9349 "CASE WHEN NOT co.convalidated THEN co.oid "
9350 "ELSE NULL END AS notnull_invalidoid,\n"
9351 "co.connoinherit AS notnull_noinherit,\n"
9352 "co.conislocal AS notnull_islocal,\n");
9353 else
9355 "CASE WHEN a.attnotnull THEN '' ELSE NULL END AS notnull_name,\n"
9356 "NULL AS notnull_comment,\n"
9357 "NULL AS notnull_invalidoid,\n"
9358 "false AS notnull_noinherit,\n"
9359 "a.attislocal AS notnull_islocal,\n");
9360
9361 if (fout->remoteVersion >= 140000)
9363 "a.attcompression AS attcompression,\n");
9364 else
9366 "'' AS attcompression,\n");
9367
9368 if (fout->remoteVersion >= 100000)
9370 "a.attidentity,\n");
9371 else
9373 "'' AS attidentity,\n");
9374
9375 if (fout->remoteVersion >= 110000)
9377 "CASE WHEN a.atthasmissing AND NOT a.attisdropped "
9378 "THEN a.attmissingval ELSE null END AS attmissingval,\n");
9379 else
9381 "NULL AS attmissingval,\n");
9382
9383 if (fout->remoteVersion >= 120000)
9385 "a.attgenerated\n");
9386 else
9388 "'' AS attgenerated\n");
9389
9390 /* need left join to pg_type to not fail on dropped columns ... */
9392 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9393 "JOIN pg_catalog.pg_attribute a ON (src.tbloid = a.attrelid) "
9394 "LEFT JOIN pg_catalog.pg_type t "
9395 "ON (a.atttypid = t.oid)\n",
9396 tbloids->data);
9397
9398 /*
9399 * In versions 18 and up, we need pg_constraint for explicit NOT NULL
9400 * entries and pg_description to get their comments.
9401 */
9402 if (fout->remoteVersion >= 180000)
9404 " LEFT JOIN pg_catalog.pg_constraint co ON "
9405 "(a.attrelid = co.conrelid\n"
9406 " AND co.contype = 'n' AND "
9407 "co.conkey = array[a.attnum])\n"
9408 " LEFT JOIN pg_catalog.pg_description pt ON "
9409 "(pt.classoid = co.tableoid AND pt.objoid = co.oid)\n");
9410
9412 "WHERE a.attnum > 0::pg_catalog.int2\n"
9413 "ORDER BY a.attrelid, a.attnum");
9414
9415 res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
9416
9417 ntups = PQntuples(res);
9418
9419 i_attrelid = PQfnumber(res, "attrelid");
9420 i_attnum = PQfnumber(res, "attnum");
9421 i_attname = PQfnumber(res, "attname");
9422 i_atttypname = PQfnumber(res, "atttypname");
9423 i_attstattarget = PQfnumber(res, "attstattarget");
9424 i_attstorage = PQfnumber(res, "attstorage");
9425 i_typstorage = PQfnumber(res, "typstorage");
9426 i_attidentity = PQfnumber(res, "attidentity");
9427 i_attgenerated = PQfnumber(res, "attgenerated");
9428 i_attisdropped = PQfnumber(res, "attisdropped");
9429 i_attlen = PQfnumber(res, "attlen");
9430 i_attalign = PQfnumber(res, "attalign");
9431 i_attislocal = PQfnumber(res, "attislocal");
9432 i_notnull_name = PQfnumber(res, "notnull_name");
9433 i_notnull_comment = PQfnumber(res, "notnull_comment");
9434 i_notnull_invalidoid = PQfnumber(res, "notnull_invalidoid");
9435 i_notnull_noinherit = PQfnumber(res, "notnull_noinherit");
9436 i_notnull_islocal = PQfnumber(res, "notnull_islocal");
9437 i_attoptions = PQfnumber(res, "attoptions");
9438 i_attcollation = PQfnumber(res, "attcollation");
9439 i_attcompression = PQfnumber(res, "attcompression");
9440 i_attfdwoptions = PQfnumber(res, "attfdwoptions");
9441 i_attmissingval = PQfnumber(res, "attmissingval");
9442 i_atthasdef = PQfnumber(res, "atthasdef");
9443
9444 /* Within the next loop, we'll accumulate OIDs of tables with defaults */
9445 resetPQExpBuffer(tbloids);
9446 appendPQExpBufferChar(tbloids, '{');
9447
9448 /*
9449 * Outer loop iterates once per table, not once per row. Incrementing of
9450 * r is handled by the inner loop.
9451 */
9452 curtblindx = -1;
9453 for (int r = 0; r < ntups;)
9454 {
9455 Oid attrelid = atooid(PQgetvalue(res, r, i_attrelid));
9456 TableInfo *tbinfo = NULL;
9457 int numatts;
9458 bool hasdefaults;
9459
9460 /* Count rows for this table */
9461 for (numatts = 1; numatts < ntups - r; numatts++)
9462 if (atooid(PQgetvalue(res, r + numatts, i_attrelid)) != attrelid)
9463 break;
9464
9465 /*
9466 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
9467 * order.
9468 */
9469 while (++curtblindx < numTables)
9470 {
9471 tbinfo = &tblinfo[curtblindx];
9472 if (tbinfo->dobj.catId.oid == attrelid)
9473 break;
9474 }
9475 if (curtblindx >= numTables)
9476 pg_fatal("unrecognized table OID %u", attrelid);
9477 /* cross-check that we only got requested tables */
9478 if (tbinfo->relkind == RELKIND_SEQUENCE ||
9479 (!tbinfo->interesting &&
9480 !(fout->dopt->binary_upgrade && fout->remoteVersion >= 120000 &&
9481 (tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId ||
9482 tbinfo->dobj.catId.oid == SharedDependRelationId))))
9483 pg_fatal("unexpected column data for table \"%s\"",
9484 tbinfo->dobj.name);
9485
9486 /* Save data for this table */
9487 tbinfo->numatts = numatts;
9488 tbinfo->attnames = (char **) pg_malloc(numatts * sizeof(char *));
9489 tbinfo->atttypnames = (char **) pg_malloc(numatts * sizeof(char *));
9490 tbinfo->attstattarget = (int *) pg_malloc(numatts * sizeof(int));
9491 tbinfo->attstorage = (char *) pg_malloc(numatts * sizeof(char));
9492 tbinfo->typstorage = (char *) pg_malloc(numatts * sizeof(char));
9493 tbinfo->attidentity = (char *) pg_malloc(numatts * sizeof(char));
9494 tbinfo->attgenerated = (char *) pg_malloc(numatts * sizeof(char));
9495 tbinfo->attisdropped = (bool *) pg_malloc(numatts * sizeof(bool));
9496 tbinfo->attlen = (int *) pg_malloc(numatts * sizeof(int));
9497 tbinfo->attalign = (char *) pg_malloc(numatts * sizeof(char));
9498 tbinfo->attislocal = (bool *) pg_malloc(numatts * sizeof(bool));
9499 tbinfo->attoptions = (char **) pg_malloc(numatts * sizeof(char *));
9500 tbinfo->attcollation = (Oid *) pg_malloc(numatts * sizeof(Oid));
9501 tbinfo->attcompression = (char *) pg_malloc(numatts * sizeof(char));
9502 tbinfo->attfdwoptions = (char **) pg_malloc(numatts * sizeof(char *));
9503 tbinfo->attmissingval = (char **) pg_malloc(numatts * sizeof(char *));
9504 tbinfo->notnull_constrs = (char **) pg_malloc(numatts * sizeof(char *));
9505 tbinfo->notnull_comment = (char **) pg_malloc(numatts * sizeof(char *));
9506 tbinfo->notnull_invalid = (bool *) pg_malloc(numatts * sizeof(bool));
9507 tbinfo->notnull_noinh = (bool *) pg_malloc(numatts * sizeof(bool));
9508 tbinfo->notnull_islocal = (bool *) pg_malloc(numatts * sizeof(bool));
9509 tbinfo->attrdefs = (AttrDefInfo **) pg_malloc(numatts * sizeof(AttrDefInfo *));
9510 hasdefaults = false;
9511
9512 for (int j = 0; j < numatts; j++, r++)
9513 {
9514 if (j + 1 != atoi(PQgetvalue(res, r, i_attnum)))
9515 pg_fatal("invalid column numbering in table \"%s\"",
9516 tbinfo->dobj.name);
9517 tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, r, i_attname));
9518 tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, r, i_atttypname));
9519 if (PQgetisnull(res, r, i_attstattarget))
9520 tbinfo->attstattarget[j] = -1;
9521 else
9522 tbinfo->attstattarget[j] = atoi(PQgetvalue(res, r, i_attstattarget));
9523 tbinfo->attstorage[j] = *(PQgetvalue(res, r, i_attstorage));
9524 tbinfo->typstorage[j] = *(PQgetvalue(res, r, i_typstorage));
9525 tbinfo->attidentity[j] = *(PQgetvalue(res, r, i_attidentity));
9526 tbinfo->attgenerated[j] = *(PQgetvalue(res, r, i_attgenerated));
9527 tbinfo->needs_override = tbinfo->needs_override || (tbinfo->attidentity[j] == ATTRIBUTE_IDENTITY_ALWAYS);
9528 tbinfo->attisdropped[j] = (PQgetvalue(res, r, i_attisdropped)[0] == 't');
9529 tbinfo->attlen[j] = atoi(PQgetvalue(res, r, i_attlen));
9530 tbinfo->attalign[j] = *(PQgetvalue(res, r, i_attalign));
9531 tbinfo->attislocal[j] = (PQgetvalue(res, r, i_attislocal)[0] == 't');
9532
9533 /* Handle not-null constraint name and flags */
9534 determineNotNullFlags(fout, res, r,
9535 tbinfo, j,
9536 i_notnull_name,
9537 i_notnull_comment,
9538 i_notnull_invalidoid,
9539 i_notnull_noinherit,
9540 i_notnull_islocal,
9541 &invalidnotnulloids);
9542
9543 tbinfo->notnull_comment[j] = PQgetisnull(res, r, i_notnull_comment) ?
9544 NULL : pg_strdup(PQgetvalue(res, r, i_notnull_comment));
9545 tbinfo->attoptions[j] = pg_strdup(PQgetvalue(res, r, i_attoptions));
9546 tbinfo->attcollation[j] = atooid(PQgetvalue(res, r, i_attcollation));
9547 tbinfo->attcompression[j] = *(PQgetvalue(res, r, i_attcompression));
9548 tbinfo->attfdwoptions[j] = pg_strdup(PQgetvalue(res, r, i_attfdwoptions));
9549 tbinfo->attmissingval[j] = pg_strdup(PQgetvalue(res, r, i_attmissingval));
9550 tbinfo->attrdefs[j] = NULL; /* fix below */
9551 if (PQgetvalue(res, r, i_atthasdef)[0] == 't')
9552 hasdefaults = true;
9553 }
9554
9555 if (hasdefaults)
9556 {
9557 /* Collect OIDs of interesting tables that have defaults */
9558 if (tbloids->len > 1) /* do we have more than the '{'? */
9559 appendPQExpBufferChar(tbloids, ',');
9560 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
9561 }
9562 }
9563
9564 /* If invalidnotnulloids has any data, finalize it */
9565 if (invalidnotnulloids != NULL)
9566 appendPQExpBufferChar(invalidnotnulloids, '}');
9567
9568 PQclear(res);
9569
9570 /*
9571 * Now get info about column defaults. This is skipped for a data-only
9572 * dump, as it is only needed for table schemas.
9573 */
9574 if (dopt->dumpSchema && tbloids->len > 1)
9575 {
9576 AttrDefInfo *attrdefs;
9577 int numDefaults;
9578 TableInfo *tbinfo = NULL;
9579
9580 pg_log_info("finding table default expressions");
9581
9582 appendPQExpBufferChar(tbloids, '}');
9583
9584 printfPQExpBuffer(q, "SELECT a.tableoid, a.oid, adrelid, adnum, "
9585 "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc\n"
9586 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9587 "JOIN pg_catalog.pg_attrdef a ON (src.tbloid = a.adrelid)\n"
9588 "ORDER BY a.adrelid, a.adnum",
9589 tbloids->data);
9590
9591 res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
9592
9593 numDefaults = PQntuples(res);
9594 attrdefs = (AttrDefInfo *) pg_malloc(numDefaults * sizeof(AttrDefInfo));
9595
9596 curtblindx = -1;
9597 for (int j = 0; j < numDefaults; j++)
9598 {
9599 Oid adtableoid = atooid(PQgetvalue(res, j, 0));
9600 Oid adoid = atooid(PQgetvalue(res, j, 1));
9601 Oid adrelid = atooid(PQgetvalue(res, j, 2));
9602 int adnum = atoi(PQgetvalue(res, j, 3));
9603 char *adsrc = PQgetvalue(res, j, 4);
9604
9605 /*
9606 * Locate the associated TableInfo; we rely on tblinfo[] being in
9607 * OID order.
9608 */
9609 if (tbinfo == NULL || tbinfo->dobj.catId.oid != adrelid)
9610 {
9611 while (++curtblindx < numTables)
9612 {
9613 tbinfo = &tblinfo[curtblindx];
9614 if (tbinfo->dobj.catId.oid == adrelid)
9615 break;
9616 }
9617 if (curtblindx >= numTables)
9618 pg_fatal("unrecognized table OID %u", adrelid);
9619 }
9620
9621 if (adnum <= 0 || adnum > tbinfo->numatts)
9622 pg_fatal("invalid adnum value %d for table \"%s\"",
9623 adnum, tbinfo->dobj.name);
9624
9625 /*
9626 * dropped columns shouldn't have defaults, but just in case,
9627 * ignore 'em
9628 */
9629 if (tbinfo->attisdropped[adnum - 1])
9630 continue;
9631
9632 attrdefs[j].dobj.objType = DO_ATTRDEF;
9633 attrdefs[j].dobj.catId.tableoid = adtableoid;
9634 attrdefs[j].dobj.catId.oid = adoid;
9635 AssignDumpId(&attrdefs[j].dobj);
9636 attrdefs[j].adtable = tbinfo;
9637 attrdefs[j].adnum = adnum;
9638 attrdefs[j].adef_expr = pg_strdup(adsrc);
9639
9640 attrdefs[j].dobj.name = pg_strdup(tbinfo->dobj.name);
9641 attrdefs[j].dobj.namespace = tbinfo->dobj.namespace;
9642
9643 attrdefs[j].dobj.dump = tbinfo->dobj.dump;
9644
9645 /*
9646 * Figure out whether the default/generation expression should be
9647 * dumped as part of the main CREATE TABLE (or similar) command or
9648 * as a separate ALTER TABLE (or similar) command. The preference
9649 * is to put it into the CREATE command, but in some cases that's
9650 * not possible.
9651 */
9652 if (tbinfo->attgenerated[adnum - 1])
9653 {
9654 /*
9655 * Column generation expressions cannot be dumped separately,
9656 * because there is no syntax for it. By setting separate to
9657 * false here we prevent the "default" from being processed as
9658 * its own dumpable object. Later, flagInhAttrs() will mark
9659 * it as not to be dumped at all, if possible (that is, if it
9660 * can be inherited from a parent).
9661 */
9662 attrdefs[j].separate = false;
9663 }
9664 else if (tbinfo->relkind == RELKIND_VIEW)
9665 {
9666 /*
9667 * Defaults on a VIEW must always be dumped as separate ALTER
9668 * TABLE commands.
9669 */
9670 attrdefs[j].separate = true;
9671 }
9672 else if (!shouldPrintColumn(dopt, tbinfo, adnum - 1))
9673 {
9674 /* column will be suppressed, print default separately */
9675 attrdefs[j].separate = true;
9676 }
9677 else
9678 {
9679 attrdefs[j].separate = false;
9680 }
9681
9682 if (!attrdefs[j].separate)
9683 {
9684 /*
9685 * Mark the default as needing to appear before the table, so
9686 * that any dependencies it has must be emitted before the
9687 * CREATE TABLE. If this is not possible, we'll change to
9688 * "separate" mode while sorting dependencies.
9689 */
9690 addObjectDependency(&tbinfo->dobj,
9691 attrdefs[j].dobj.dumpId);
9692 }
9693
9694 tbinfo->attrdefs[adnum - 1] = &attrdefs[j];
9695 }
9696
9697 PQclear(res);
9698 }
9699
9700 /*
9701 * Get info about NOT NULL NOT VALID constraints. This is skipped for a
9702 * data-only dump, as it is only needed for table schemas.
9703 */
9704 if (dopt->dumpSchema && invalidnotnulloids)
9705 {
9706 ConstraintInfo *constrs;
9707 int numConstrs;
9708 int i_tableoid;
9709 int i_oid;
9710 int i_conrelid;
9711 int i_conname;
9712 int i_consrc;
9713 int i_conislocal;
9714
9715 pg_log_info("finding invalid not-null constraints");
9716
9719 "SELECT c.tableoid, c.oid, conrelid, conname, "
9720 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9721 "conislocal, convalidated "
9722 "FROM unnest('%s'::pg_catalog.oid[]) AS src(conoid)\n"
9723 "JOIN pg_catalog.pg_constraint c ON (src.conoid = c.oid)\n"
9724 "ORDER BY c.conrelid, c.conname",
9725 invalidnotnulloids->data);
9726
9727 res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
9728
9729 numConstrs = PQntuples(res);
9730 constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(ConstraintInfo));
9731
9732 i_tableoid = PQfnumber(res, "tableoid");
9733 i_oid = PQfnumber(res, "oid");
9734 i_conrelid = PQfnumber(res, "conrelid");
9735 i_conname = PQfnumber(res, "conname");
9736 i_consrc = PQfnumber(res, "consrc");
9737 i_conislocal = PQfnumber(res, "conislocal");
9738
9739 /* As above, this loop iterates once per table, not once per row */
9740 curtblindx = -1;
9741 for (int j = 0; j < numConstrs;)
9742 {
9743 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
9744 TableInfo *tbinfo = NULL;
9745 int numcons;
9746
9747 /* Count rows for this table */
9748 for (numcons = 1; numcons < numConstrs - j; numcons++)
9749 if (atooid(PQgetvalue(res, j + numcons, i_conrelid)) != conrelid)
9750 break;
9751
9752 /*
9753 * Locate the associated TableInfo; we rely on tblinfo[] being in
9754 * OID order.
9755 */
9756 while (++curtblindx < numTables)
9757 {
9758 tbinfo = &tblinfo[curtblindx];
9759 if (tbinfo->dobj.catId.oid == conrelid)
9760 break;
9761 }
9762 if (curtblindx >= numTables)
9763 pg_fatal("unrecognized table OID %u", conrelid);
9764
9765 for (int c = 0; c < numcons; c++, j++)
9766 {
9767 constrs[j].dobj.objType = DO_CONSTRAINT;
9768 constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
9769 constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
9770 AssignDumpId(&constrs[j].dobj);
9771 constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
9772 constrs[j].dobj.namespace = tbinfo->dobj.namespace;
9773 constrs[j].contable = tbinfo;
9774 constrs[j].condomain = NULL;
9775 constrs[j].contype = 'n';
9776 constrs[j].condef = pg_strdup(PQgetvalue(res, j, i_consrc));
9777 constrs[j].confrelid = InvalidOid;
9778 constrs[j].conindex = 0;
9779 constrs[j].condeferrable = false;
9780 constrs[j].condeferred = false;
9781 constrs[j].conislocal = (PQgetvalue(res, j, i_conislocal)[0] == 't');
9782
9783 /*
9784 * All invalid not-null constraints must be dumped separately,
9785 * because CREATE TABLE would not create them as invalid, and
9786 * also because they must be created after potentially
9787 * violating data has been loaded.
9788 */
9789 constrs[j].separate = true;
9790
9791 constrs[j].dobj.dump = tbinfo->dobj.dump;
9792 }
9793 }
9794 PQclear(res);
9795 }
9796
9797 /*
9798 * Get info about table CHECK constraints. This is skipped for a
9799 * data-only dump, as it is only needed for table schemas.
9800 */
9801 if (dopt->dumpSchema && checkoids->len > 2)
9802 {
9803 ConstraintInfo *constrs;
9804 int numConstrs;
9805 int i_tableoid;
9806 int i_oid;
9807 int i_conrelid;
9808 int i_conname;
9809 int i_consrc;
9810 int i_conislocal;
9811 int i_convalidated;
9812
9813 pg_log_info("finding table check constraints");
9814
9817 "SELECT c.tableoid, c.oid, conrelid, conname, "
9818 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9819 "conislocal, convalidated "
9820 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9821 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
9822 "WHERE contype = 'c' "
9823 "ORDER BY c.conrelid, c.conname",
9824 checkoids->data);
9825
9826 res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
9827
9828 numConstrs = PQntuples(res);
9829 constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(ConstraintInfo));
9830
9831 i_tableoid = PQfnumber(res, "tableoid");
9832 i_oid = PQfnumber(res, "oid");
9833 i_conrelid = PQfnumber(res, "conrelid");
9834 i_conname = PQfnumber(res, "conname");
9835 i_consrc = PQfnumber(res, "consrc");
9836 i_conislocal = PQfnumber(res, "conislocal");
9837 i_convalidated = PQfnumber(res, "convalidated");
9838
9839 /* As above, this loop iterates once per table, not once per row */
9840 curtblindx = -1;
9841 for (int j = 0; j < numConstrs;)
9842 {
9843 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
9844 TableInfo *tbinfo = NULL;
9845 int numcons;
9846
9847 /* Count rows for this table */
9848 for (numcons = 1; numcons < numConstrs - j; numcons++)
9849 if (atooid(PQgetvalue(res, j + numcons, i_conrelid)) != conrelid)
9850 break;
9851
9852 /*
9853 * Locate the associated TableInfo; we rely on tblinfo[] being in
9854 * OID order.
9855 */
9856 while (++curtblindx < numTables)
9857 {
9858 tbinfo = &tblinfo[curtblindx];
9859 if (tbinfo->dobj.catId.oid == conrelid)
9860 break;
9861 }
9862 if (curtblindx >= numTables)
9863 pg_fatal("unrecognized table OID %u", conrelid);
9864
9865 if (numcons != tbinfo->ncheck)
9866 {
9867 pg_log_error(ngettext("expected %d check constraint on table \"%s\" but found %d",
9868 "expected %d check constraints on table \"%s\" but found %d",
9869 tbinfo->ncheck),
9870 tbinfo->ncheck, tbinfo->dobj.name, numcons);
9871 pg_log_error_hint("The system catalogs might be corrupted.");
9872 exit_nicely(1);
9873 }
9874
9875 tbinfo->checkexprs = constrs + j;
9876
9877 for (int c = 0; c < numcons; c++, j++)
9878 {
9879 bool validated = PQgetvalue(res, j, i_convalidated)[0] == 't';
9880
9881 constrs[j].dobj.objType = DO_CONSTRAINT;
9882 constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
9883 constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
9884 AssignDumpId(&constrs[j].dobj);
9885 constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
9886 constrs[j].dobj.namespace = tbinfo->dobj.namespace;
9887 constrs[j].contable = tbinfo;
9888 constrs[j].condomain = NULL;
9889 constrs[j].contype = 'c';
9890 constrs[j].condef = pg_strdup(PQgetvalue(res, j, i_consrc));
9891 constrs[j].confrelid = InvalidOid;
9892 constrs[j].conindex = 0;
9893 constrs[j].condeferrable = false;
9894 constrs[j].condeferred = false;
9895 constrs[j].conislocal = (PQgetvalue(res, j, i_conislocal)[0] == 't');
9896
9897 /*
9898 * An unvalidated constraint needs to be dumped separately, so
9899 * that potentially-violating existing data is loaded before
9900 * the constraint.
9901 */
9902 constrs[j].separate = !validated;
9903
9904 constrs[j].dobj.dump = tbinfo->dobj.dump;
9905
9906 /*
9907 * Mark the constraint as needing to appear before the table
9908 * --- this is so that any other dependencies of the
9909 * constraint will be emitted before we try to create the
9910 * table. If the constraint is to be dumped separately, it
9911 * will be dumped after data is loaded anyway, so don't do it.
9912 * (There's an automatic dependency in the opposite direction
9913 * anyway, so don't need to add one manually here.)
9914 */
9915 if (!constrs[j].separate)
9916 addObjectDependency(&tbinfo->dobj,
9917 constrs[j].dobj.dumpId);
9918
9919 /*
9920 * We will detect later whether the constraint must be split
9921 * out from the table definition.
9922 */
9923 }
9924 }
9925
9926 PQclear(res);
9927 }
9928
9930 destroyPQExpBuffer(tbloids);
9931 destroyPQExpBuffer(checkoids);
9932}
#define ngettext(s, p, n)
Definition: c.h:1181
#define pg_log_error(...)
Definition: logging.h:106
#define pg_log_error_hint(...)
Definition: logging.h:112
void exit_nicely(int code)
static void determineNotNullFlags(Archive *fout, PGresult *res, int r, TableInfo *tbinfo, int j, int i_notnull_name, int i_notnull_comment, int i_notnull_invalidoid, int i_notnull_noinherit, int i_notnull_islocal, PQExpBuffer *invalidnotnulloids)
Definition: pg_dump.c:9982
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition: pg_dump.c:10109
DumpableObject dobj
Definition: pg_dump.h:404
char * adef_expr
Definition: pg_dump.h:407
TableInfo * adtable
Definition: pg_dump.h:405
bool separate
Definition: pg_dump.h:408
bool dumpSchema
Definition: pg_backup.h:215
bool * notnull_invalid
Definition: pg_dump.h:376
char * attidentity
Definition: pg_dump.h:361
char ** notnull_constrs
Definition: pg_dump.h:371
int ncheck
Definition: pg_dump.h:330
bool * attislocal
Definition: pg_dump.h:365
char * attgenerated
Definition: pg_dump.h:362
int * attlen
Definition: pg_dump.h:363
char ** attfdwoptions
Definition: pg_dump.h:369
char ** notnull_comment
Definition: pg_dump.h:375
bool * attisdropped
Definition: pg_dump.h:360
bool needs_override
Definition: pg_dump.h:382
struct _constraintInfo * checkexprs
Definition: pg_dump.h:380
int * attstattarget
Definition: pg_dump.h:357
bool * notnull_islocal
Definition: pg_dump.h:378
char * typstorage
Definition: pg_dump.h:359
int numatts
Definition: pg_dump.h:354
struct _attrDefInfo ** attrdefs
Definition: pg_dump.h:379
char ** attoptions
Definition: pg_dump.h:366
Oid * attcollation
Definition: pg_dump.h:367
bool * notnull_noinh
Definition: pg_dump.h:377
char * attstorage
Definition: pg_dump.h:358
char ** atttypnames
Definition: pg_dump.h:356
char ** attmissingval
Definition: pg_dump.h:370
char ** attnames
Definition: pg_dump.h:355
char * attalign
Definition: pg_dump.h:364
char * attcompression
Definition: pg_dump.h:368

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, _dumpOptions::binary_upgrade, _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, destroyPQExpBuffer(), determineNotNullFlags(), DO_ATTRDEF, DO_CONSTRAINT, _tableInfo::dobj, _attrDefInfo::dobj, _constraintInfo::dobj, Archive::dopt, _dumpableObject::dump, _dumpableObject::dumpId, _dumpOptions::dumpSchema, ExecuteSqlQuery(), exit_nicely(), i, _tableInfo::interesting, InvalidOid, j, PQExpBufferData::len, _dumpableObject::name, _tableInfo::ncheck, _tableInfo::needs_override, ngettext, _tableInfo::notnull_comment, _tableInfo::notnull_constrs, _tableInfo::notnull_invalid, _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, resetPQExpBuffer(), _attrDefInfo::separate, _constraintInfo::separate, shouldPrintColumn(), CatalogId::tableoid, and _tableInfo::typstorage.

Referenced by getSchemaData().

◆ getTables()

TableInfo * getTables ( Archive fout,
int *  numTables 
)

Definition at line 7158 of file pg_dump.c.

7159{
7160 DumpOptions *dopt = fout->dopt;
7161 PGresult *res;
7162 int ntups;
7163 int i;
7165 TableInfo *tblinfo;
7166 int i_reltableoid;
7167 int i_reloid;
7168 int i_relname;
7169 int i_relnamespace;
7170 int i_relkind;
7171 int i_reltype;
7172 int i_relowner;
7173 int i_relchecks;
7174 int i_relhasindex;
7175 int i_relhasrules;
7176 int i_relpages;
7177 int i_reltuples;
7178 int i_relallvisible;
7179 int i_relallfrozen;
7180 int i_toastpages;
7181 int i_owning_tab;
7182 int i_owning_col;
7183 int i_reltablespace;
7184 int i_relhasoids;
7185 int i_relhastriggers;
7186 int i_relpersistence;
7187 int i_relispopulated;
7188 int i_relreplident;
7189 int i_relrowsec;
7190 int i_relforcerowsec;
7191 int i_relfrozenxid;
7192 int i_toastfrozenxid;
7193 int i_toastoid;
7194 int i_relminmxid;
7195 int i_toastminmxid;
7196 int i_reloptions;
7197 int i_checkoption;
7198 int i_toastreloptions;
7199 int i_reloftype;
7200 int i_foreignserver;
7201 int i_amname;
7202 int i_is_identity_sequence;
7203 int i_relacl;
7204 int i_acldefault;
7205 int i_ispartition;
7206
7207 /*
7208 * Find all the tables and table-like objects.
7209 *
7210 * We must fetch all tables in this phase because otherwise we cannot
7211 * correctly identify inherited columns, owned sequences, etc.
7212 *
7213 * We include system catalogs, so that we can work if a user table is
7214 * defined to inherit from a system catalog (pretty weird, but...)
7215 *
7216 * Note: in this phase we should collect only a minimal amount of
7217 * information about each table, basically just enough to decide if it is
7218 * interesting. In particular, since we do not yet have lock on any user
7219 * table, we MUST NOT invoke any server-side data collection functions
7220 * (for instance, pg_get_partkeydef()). Those are likely to fail or give
7221 * wrong answers if any concurrent DDL is happening.
7222 */
7223
7225 "SELECT c.tableoid, c.oid, c.relname, "
7226 "c.relnamespace, c.relkind, c.reltype, "
7227 "c.relowner, "
7228 "c.relchecks, "
7229 "c.relhasindex, c.relhasrules, c.relpages, "
7230 "c.reltuples, c.relallvisible, ");
7231
7232 if (fout->remoteVersion >= 180000)
7233 appendPQExpBufferStr(query, "c.relallfrozen, ");
7234 else
7235 appendPQExpBufferStr(query, "0 AS relallfrozen, ");
7236
7238 "c.relhastriggers, c.relpersistence, "
7239 "c.reloftype, "
7240 "c.relacl, "
7241 "acldefault(CASE WHEN c.relkind = " CppAsString2(RELKIND_SEQUENCE)
7242 " THEN 's'::\"char\" ELSE 'r'::\"char\" END, c.relowner) AS acldefault, "
7243 "CASE WHEN c.relkind = " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN "
7244 "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) "
7245 "ELSE 0 END AS foreignserver, "
7246 "c.relfrozenxid, tc.relfrozenxid AS tfrozenxid, "
7247 "tc.oid AS toid, "
7248 "tc.relpages AS toastpages, "
7249 "tc.reloptions AS toast_reloptions, "
7250 "d.refobjid AS owning_tab, "
7251 "d.refobjsubid AS owning_col, "
7252 "tsp.spcname AS reltablespace, ");
7253
7254 if (fout->remoteVersion >= 120000)
7256 "false AS relhasoids, ");
7257 else
7259 "c.relhasoids, ");
7260
7261 if (fout->remoteVersion >= 90300)
7263 "c.relispopulated, ");
7264 else
7266 "'t' as relispopulated, ");
7267
7268 if (fout->remoteVersion >= 90400)
7270 "c.relreplident, ");
7271 else
7273 "'d' AS relreplident, ");
7274
7275 if (fout->remoteVersion >= 90500)
7277 "c.relrowsecurity, c.relforcerowsecurity, ");
7278 else
7280 "false AS relrowsecurity, "
7281 "false AS relforcerowsecurity, ");
7282
7283 if (fout->remoteVersion >= 90300)
7285 "c.relminmxid, tc.relminmxid AS tminmxid, ");
7286 else
7288 "0 AS relminmxid, 0 AS tminmxid, ");
7289
7290 if (fout->remoteVersion >= 90300)
7292 "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, "
7293 "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text "
7294 "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, ");
7295 else
7297 "c.reloptions, NULL AS checkoption, ");
7298
7299 if (fout->remoteVersion >= 90600)
7301 "am.amname, ");
7302 else
7304 "NULL AS amname, ");
7305
7306 if (fout->remoteVersion >= 90600)
7308 "(d.deptype = 'i') IS TRUE AS is_identity_sequence, ");
7309 else
7311 "false AS is_identity_sequence, ");
7312
7313 if (fout->remoteVersion >= 100000)
7315 "c.relispartition AS ispartition ");
7316 else
7318 "false AS ispartition ");
7319
7320 /*
7321 * Left join to pg_depend to pick up dependency info linking sequences to
7322 * their owning column, if any (note this dependency is AUTO except for
7323 * identity sequences, where it's INTERNAL). Also join to pg_tablespace to
7324 * collect the spcname.
7325 */
7327 "\nFROM pg_class c\n"
7328 "LEFT JOIN pg_depend d ON "
7329 "(c.relkind = " CppAsString2(RELKIND_SEQUENCE) " AND "
7330 "d.classid = 'pg_class'::regclass AND d.objid = c.oid AND "
7331 "d.objsubid = 0 AND "
7332 "d.refclassid = 'pg_class'::regclass AND d.deptype IN ('a', 'i'))\n"
7333 "LEFT JOIN pg_tablespace tsp ON (tsp.oid = c.reltablespace)\n");
7334
7335 /*
7336 * In 9.6 and up, left join to pg_am to pick up the amname.
7337 */
7338 if (fout->remoteVersion >= 90600)
7340 "LEFT JOIN pg_am am ON (c.relam = am.oid)\n");
7341
7342 /*
7343 * We purposefully ignore toast OIDs for partitioned tables; the reason is
7344 * that versions 10 and 11 have them, but later versions do not, so
7345 * emitting them causes the upgrade to fail.
7346 */
7348 "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid"
7349 " AND tc.relkind = " CppAsString2(RELKIND_TOASTVALUE)
7350 " AND c.relkind <> " CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n");
7351
7352 /*
7353 * Restrict to interesting relkinds (in particular, not indexes). Not all
7354 * relkinds are possible in older servers, but it's not worth the trouble
7355 * to emit a version-dependent list.
7356 *
7357 * Composite-type table entries won't be dumped as such, but we have to
7358 * make a DumpableObject for them so that we can track dependencies of the
7359 * composite type (pg_depend entries for columns of the composite type
7360 * link to the pg_class entry not the pg_type entry).
7361 */
7363 "WHERE c.relkind IN ("
7364 CppAsString2(RELKIND_RELATION) ", "
7365 CppAsString2(RELKIND_SEQUENCE) ", "
7366 CppAsString2(RELKIND_VIEW) ", "
7367 CppAsString2(RELKIND_COMPOSITE_TYPE) ", "
7368 CppAsString2(RELKIND_MATVIEW) ", "
7369 CppAsString2(RELKIND_FOREIGN_TABLE) ", "
7370 CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n"
7371 "ORDER BY c.oid");
7372
7373 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7374
7375 ntups = PQntuples(res);
7376
7377 *numTables = ntups;
7378
7379 /*
7380 * Extract data from result and lock dumpable tables. We do the locking
7381 * before anything else, to minimize the window wherein a table could
7382 * disappear under us.
7383 *
7384 * Note that we have to save info about all tables here, even when dumping
7385 * only one, because we don't yet know which tables might be inheritance
7386 * ancestors of the target table.
7387 */
7388 tblinfo = (TableInfo *) pg_malloc0(ntups * sizeof(TableInfo));
7389
7390 i_reltableoid = PQfnumber(res, "tableoid");
7391 i_reloid = PQfnumber(res, "oid");
7392 i_relname = PQfnumber(res, "relname");
7393 i_relnamespace = PQfnumber(res, "relnamespace");
7394 i_relkind = PQfnumber(res, "relkind");
7395 i_reltype = PQfnumber(res, "reltype");
7396 i_relowner = PQfnumber(res, "relowner");
7397 i_relchecks = PQfnumber(res, "relchecks");
7398 i_relhasindex = PQfnumber(res, "relhasindex");
7399 i_relhasrules = PQfnumber(res, "relhasrules");
7400 i_relpages = PQfnumber(res, "relpages");
7401 i_reltuples = PQfnumber(res, "reltuples");
7402 i_relallvisible = PQfnumber(res, "relallvisible");
7403 i_relallfrozen = PQfnumber(res, "relallfrozen");
7404 i_toastpages = PQfnumber(res, "toastpages");
7405 i_owning_tab = PQfnumber(res, "owning_tab");
7406 i_owning_col = PQfnumber(res, "owning_col");
7407 i_reltablespace = PQfnumber(res, "reltablespace");
7408 i_relhasoids = PQfnumber(res, "relhasoids");
7409 i_relhastriggers = PQfnumber(res, "relhastriggers");
7410 i_relpersistence = PQfnumber(res, "relpersistence");
7411 i_relispopulated = PQfnumber(res, "relispopulated");
7412 i_relreplident = PQfnumber(res, "relreplident");
7413 i_relrowsec = PQfnumber(res, "relrowsecurity");
7414 i_relforcerowsec = PQfnumber(res, "relforcerowsecurity");
7415 i_relfrozenxid = PQfnumber(res, "relfrozenxid");
7416 i_toastfrozenxid = PQfnumber(res, "tfrozenxid");
7417 i_toastoid = PQfnumber(res, "toid");
7418 i_relminmxid = PQfnumber(res, "relminmxid");
7419 i_toastminmxid = PQfnumber(res, "tminmxid");
7420 i_reloptions = PQfnumber(res, "reloptions");
7421 i_checkoption = PQfnumber(res, "checkoption");
7422 i_toastreloptions = PQfnumber(res, "toast_reloptions");
7423 i_reloftype = PQfnumber(res, "reloftype");
7424 i_foreignserver = PQfnumber(res, "foreignserver");
7425 i_amname = PQfnumber(res, "amname");
7426 i_is_identity_sequence = PQfnumber(res, "is_identity_sequence");
7427 i_relacl = PQfnumber(res, "relacl");
7428 i_acldefault = PQfnumber(res, "acldefault");
7429 i_ispartition = PQfnumber(res, "ispartition");
7430
7431 if (dopt->lockWaitTimeout)
7432 {
7433 /*
7434 * Arrange to fail instead of waiting forever for a table lock.
7435 *
7436 * NB: this coding assumes that the only queries issued within the
7437 * following loop are LOCK TABLEs; else the timeout may be undesirably
7438 * applied to other things too.
7439 */
7440 resetPQExpBuffer(query);
7441 appendPQExpBufferStr(query, "SET statement_timeout = ");
7443 ExecuteSqlStatement(fout, query->data);
7444 }
7445
7446 resetPQExpBuffer(query);
7447
7448 for (i = 0; i < ntups; i++)
7449 {
7450 int32 relallvisible = atoi(PQgetvalue(res, i, i_relallvisible));
7451 int32 relallfrozen = atoi(PQgetvalue(res, i, i_relallfrozen));
7452
7453 tblinfo[i].dobj.objType = DO_TABLE;
7454 tblinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_reltableoid));
7455 tblinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_reloid));
7456 AssignDumpId(&tblinfo[i].dobj);
7457 tblinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_relname));
7458 tblinfo[i].dobj.namespace =
7459 findNamespace(atooid(PQgetvalue(res, i, i_relnamespace)));
7460 tblinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_relacl));
7461 tblinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
7462 tblinfo[i].dacl.privtype = 0;
7463 tblinfo[i].dacl.initprivs = NULL;
7464 tblinfo[i].relkind = *(PQgetvalue(res, i, i_relkind));
7465 tblinfo[i].reltype = atooid(PQgetvalue(res, i, i_reltype));
7466 tblinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_relowner));
7467 tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
7468 tblinfo[i].hasindex = (strcmp(PQgetvalue(res, i, i_relhasindex), "t") == 0);
7469 tblinfo[i].hasrules = (strcmp(PQgetvalue(res, i, i_relhasrules), "t") == 0);
7470 tblinfo[i].relpages = atoi(PQgetvalue(res, i, i_relpages));
7471 if (PQgetisnull(res, i, i_toastpages))
7472 tblinfo[i].toastpages = 0;
7473 else
7474 tblinfo[i].toastpages = atoi(PQgetvalue(res, i, i_toastpages));
7475 if (PQgetisnull(res, i, i_owning_tab))
7476 {
7477 tblinfo[i].owning_tab = InvalidOid;
7478 tblinfo[i].owning_col = 0;
7479 }
7480 else
7481 {
7482 tblinfo[i].owning_tab = atooid(PQgetvalue(res, i, i_owning_tab));
7483 tblinfo[i].owning_col = atoi(PQgetvalue(res, i, i_owning_col));
7484 }
7485 tblinfo[i].reltablespace = pg_strdup(PQgetvalue(res, i, i_reltablespace));
7486 tblinfo[i].hasoids = (strcmp(PQgetvalue(res, i, i_relhasoids), "t") == 0);
7487 tblinfo[i].hastriggers = (strcmp(PQgetvalue(res, i, i_relhastriggers), "t") == 0);
7488 tblinfo[i].relpersistence = *(PQgetvalue(res, i, i_relpersistence));
7489 tblinfo[i].relispopulated = (strcmp(PQgetvalue(res, i, i_relispopulated), "t") == 0);
7490 tblinfo[i].relreplident = *(PQgetvalue(res, i, i_relreplident));
7491 tblinfo[i].rowsec = (strcmp(PQgetvalue(res, i, i_relrowsec), "t") == 0);
7492 tblinfo[i].forcerowsec = (strcmp(PQgetvalue(res, i, i_relforcerowsec), "t") == 0);
7493 tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid));
7494 tblinfo[i].toast_frozenxid = atooid(PQgetvalue(res, i, i_toastfrozenxid));
7495 tblinfo[i].toast_oid = atooid(PQgetvalue(res, i, i_toastoid));
7496 tblinfo[i].minmxid = atooid(PQgetvalue(res, i, i_relminmxid));
7497 tblinfo[i].toast_minmxid = atooid(PQgetvalue(res, i, i_toastminmxid));
7498 tblinfo[i].reloptions = pg_strdup(PQgetvalue(res, i, i_reloptions));
7499 if (PQgetisnull(res, i, i_checkoption))
7500 tblinfo[i].checkoption = NULL;
7501 else
7502 tblinfo[i].checkoption = pg_strdup(PQgetvalue(res, i, i_checkoption));
7503 tblinfo[i].toast_reloptions = pg_strdup(PQgetvalue(res, i, i_toastreloptions));
7504 tblinfo[i].reloftype = atooid(PQgetvalue(res, i, i_reloftype));
7505 tblinfo[i].foreign_server = atooid(PQgetvalue(res, i, i_foreignserver));
7506 if (PQgetisnull(res, i, i_amname))
7507 tblinfo[i].amname = NULL;
7508 else
7509 tblinfo[i].amname = pg_strdup(PQgetvalue(res, i, i_amname));
7510 tblinfo[i].is_identity_sequence = (strcmp(PQgetvalue(res, i, i_is_identity_sequence), "t") == 0);
7511 tblinfo[i].ispartition = (strcmp(PQgetvalue(res, i, i_ispartition), "t") == 0);
7512
7513 /* other fields were zeroed above */
7514
7515 /*
7516 * Decide whether we want to dump this table.
7517 */
7518 if (tblinfo[i].relkind == RELKIND_COMPOSITE_TYPE)
7519 tblinfo[i].dobj.dump = DUMP_COMPONENT_NONE;
7520 else
7521 selectDumpableTable(&tblinfo[i], fout);
7522
7523 /*
7524 * Now, consider the table "interesting" if we need to dump its
7525 * definition, data or its statistics. Later on, we'll skip a lot of
7526 * data collection for uninteresting tables.
7527 *
7528 * Note: the "interesting" flag will also be set by flagInhTables for
7529 * parents of interesting tables, so that we collect necessary
7530 * inheritance info even when the parents are not themselves being
7531 * dumped. This is the main reason why we need an "interesting" flag
7532 * that's separate from the components-to-dump bitmask.
7533 */
7534 tblinfo[i].interesting = (tblinfo[i].dobj.dump &
7538
7539 tblinfo[i].dummy_view = false; /* might get set during sort */
7540 tblinfo[i].postponed_def = false; /* might get set during sort */
7541
7542 /* Tables have data */
7544
7545 /* Mark whether table has an ACL */
7546 if (!PQgetisnull(res, i, i_relacl))
7547 tblinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
7548 tblinfo[i].hascolumnACLs = false; /* may get set later */
7549
7550 /* Add statistics */
7551 if (tblinfo[i].interesting)
7552 {
7553 RelStatsInfo *stats;
7554
7555 stats = getRelationStatistics(fout, &tblinfo[i].dobj,
7556 tblinfo[i].relpages,
7557 PQgetvalue(res, i, i_reltuples),
7558 relallvisible, relallfrozen,
7559 tblinfo[i].relkind, NULL, 0);
7560 if (tblinfo[i].relkind == RELKIND_MATVIEW)
7561 tblinfo[i].stats = stats;
7562 }
7563
7564 /*
7565 * Read-lock target tables to make sure they aren't DROPPED or altered
7566 * in schema before we get around to dumping them.
7567 *
7568 * Note that we don't explicitly lock parents of the target tables; we
7569 * assume our lock on the child is enough to prevent schema
7570 * alterations to parent tables.
7571 *
7572 * NOTE: it'd be kinda nice to lock other relations too, not only
7573 * plain or partitioned tables, but the backend doesn't presently
7574 * allow that.
7575 *
7576 * We only need to lock the table for certain components; see
7577 * pg_dump.h
7578 */
7579 if ((tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK) &&
7580 (tblinfo[i].relkind == RELKIND_RELATION ||
7581 tblinfo[i].relkind == RELKIND_PARTITIONED_TABLE))
7582 {
7583 /*
7584 * Tables are locked in batches. When dumping from a remote
7585 * server this can save a significant amount of time by reducing
7586 * the number of round trips.
7587 */
7588 if (query->len == 0)
7589 appendPQExpBuffer(query, "LOCK TABLE %s",
7590 fmtQualifiedDumpable(&tblinfo[i]));
7591 else
7592 {
7593 appendPQExpBuffer(query, ", %s",
7594 fmtQualifiedDumpable(&tblinfo[i]));
7595
7596 /* Arbitrarily end a batch when query length reaches 100K. */
7597 if (query->len >= 100000)
7598 {
7599 /* Lock another batch of tables. */
7600 appendPQExpBufferStr(query, " IN ACCESS SHARE MODE");
7601 ExecuteSqlStatement(fout, query->data);
7602 resetPQExpBuffer(query);
7603 }
7604 }
7605 }
7606 }
7607
7608 if (query->len != 0)
7609 {
7610 /* Lock the tables in the last batch. */
7611 appendPQExpBufferStr(query, " IN ACCESS SHARE MODE");
7612 ExecuteSqlStatement(fout, query->data);
7613 }
7614
7615 if (dopt->lockWaitTimeout)
7616 {
7617 ExecuteSqlStatement(fout, "SET statement_timeout = 0");
7618 }
7619
7620 PQclear(res);
7621
7622 destroyPQExpBuffer(query);
7623
7624 return tblinfo;
7625}
#define CppAsString2(x)
Definition: c.h:419
PGconn * GetConnection(UserMapping *user, bool will_prep_stmt, PgFdwConnState **state)
Definition: connection.c:205
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
void ExecuteSqlStatement(Archive *AHX, const char *query)
Definition: pg_backup_db.c:217
static void selectDumpableTable(TableInfo *tbinfo, Archive *fout)
Definition: pg_dump.c:2070
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:240
#define DUMP_COMPONENT_DATA
Definition: pg_dump.h:110
#define DUMP_COMPONENTS_REQUIRING_LOCK
Definition: pg_dump.h:141
#define DUMP_COMPONENT_STATISTICS
Definition: pg_dump.h:116
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
Definition: string_utils.c:446
const char * lockWaitTimeout
Definition: pg_backup.h:179
char * reltablespace
Definition: pg_dump.h:314
struct _relStatsInfo * stats
Definition: pg_dump.h:381
bool ispartition
Definition: pg_dump.h:344
Oid reloftype
Definition: pg_dump.h:332
char * toast_reloptions
Definition: pg_dump.h:317
DumpableAcl dacl
Definition: pg_dump.h:308
bool relispopulated
Definition: pg_dump.h:312
Oid reltype
Definition: pg_dump.h:331
bool hasoids
Definition: pg_dump.h:324
Oid toast_oid
Definition: pg_dump.h:327
Oid foreign_server
Definition: pg_dump.h:333
bool hasrules
Definition: pg_dump.h:319
uint32 frozenxid
Definition: pg_dump.h:325
int owning_col
Definition: pg_dump.h:336
char * checkoption
Definition: pg_dump.h:316
bool hastriggers
Definition: pg_dump.h:320
const char * rolname
Definition: pg_dump.h:309
char relreplident
Definition: pg_dump.h:313
uint32 minmxid
Definition: pg_dump.h:326
int toastpages
Definition: pg_dump.h:339
char * amname
Definition: pg_dump.h:383
bool dummy_view
Definition: pg_dump.h:342
int32 relpages
Definition: pg_dump.h:338
bool forcerowsec
Definition: pg_dump.h:323
char relpersistence
Definition: pg_dump.h:311
char * reloptions
Definition: pg_dump.h:315
uint32 toast_frozenxid
Definition: pg_dump.h:328
uint32 toast_minmxid
Definition: pg_dump.h:329
bool postponed_def
Definition: pg_dump.h:343

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_COMPONENT_STATISTICS, DUMP_COMPONENTS_REQUIRING_LOCK, ExecuteSqlQuery(), ExecuteSqlStatement(), findNamespace(), fmtQualifiedDumpable, _tableInfo::forcerowsec, _tableInfo::foreign_server, _tableInfo::frozenxid, GetConnection(), getRelationStatistics(), 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, resetPQExpBuffer(), _tableInfo::rolname, _tableInfo::rowsec, selectDumpableTable(), _tableInfo::stats, 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 9123 of file pg_dump.c.

9124{
9125 PGresult *res;
9126 int ntups;
9127 int i;
9128 PQExpBuffer query;
9129 TransformInfo *transforminfo;
9130 int i_tableoid;
9131 int i_oid;
9132 int i_trftype;
9133 int i_trflang;
9134 int i_trffromsql;
9135 int i_trftosql;
9136
9137 /* Transforms didn't exist pre-9.5 */
9138 if (fout->remoteVersion < 90500)
9139 return;
9140
9141 query = createPQExpBuffer();
9142
9143 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9144 "trftype, trflang, trffromsql::oid, trftosql::oid "
9145 "FROM pg_transform "
9146 "ORDER BY 3,4");
9147
9148 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9149
9150 ntups = PQntuples(res);
9151
9152 transforminfo = (TransformInfo *) pg_malloc(ntups * sizeof(TransformInfo));
9153
9154 i_tableoid = PQfnumber(res, "tableoid");
9155 i_oid = PQfnumber(res, "oid");
9156 i_trftype = PQfnumber(res, "trftype");
9157 i_trflang = PQfnumber(res, "trflang");
9158 i_trffromsql = PQfnumber(res, "trffromsql");
9159 i_trftosql = PQfnumber(res, "trftosql");
9160
9161 for (i = 0; i < ntups; i++)
9162 {
9163 PQExpBufferData namebuf;
9164 TypeInfo *typeInfo;
9165 char *lanname;
9166
9167 transforminfo[i].dobj.objType = DO_TRANSFORM;
9168 transforminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9169 transforminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9170 AssignDumpId(&transforminfo[i].dobj);
9171 transforminfo[i].trftype = atooid(PQgetvalue(res, i, i_trftype));
9172 transforminfo[i].trflang = atooid(PQgetvalue(res, i, i_trflang));
9173 transforminfo[i].trffromsql = atooid(PQgetvalue(res, i, i_trffromsql));
9174 transforminfo[i].trftosql = atooid(PQgetvalue(res, i, i_trftosql));
9175
9176 /*
9177 * Try to name transform as concatenation of type and language name.
9178 * This is only used for purposes of sorting. If we fail to find
9179 * either, the name will be an empty string.
9180 */
9181 initPQExpBuffer(&namebuf);
9182 typeInfo = findTypeByOid(transforminfo[i].trftype);
9183 lanname = get_language_name(fout, transforminfo[i].trflang);
9184 if (typeInfo && lanname)
9185 appendPQExpBuffer(&namebuf, "%s %s",
9186 typeInfo->dobj.name, lanname);
9187 transforminfo[i].dobj.name = namebuf.data;
9188 free(lanname);
9189
9190 /* Decide whether we want to dump it */
9191 selectDumpableObject(&(transforminfo[i].dobj), fout);
9192 }
9193
9194 PQclear(res);
9195
9196 destroyPQExpBuffer(query);
9197}
static char * get_language_name(Archive *fout, Oid langid)
Definition: pg_dump.c:9102
DumpableObject dobj
Definition: pg_dump.h:554
Oid trffromsql
Definition: pg_dump.h:557

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

8656{
8658 PQExpBuffer tbloids = createPQExpBuffer();
8659 PGresult *res;
8660 int ntups;
8661 int curtblindx;
8662 TriggerInfo *tginfo;
8663 int i_tableoid,
8664 i_oid,
8665 i_tgrelid,
8666 i_tgname,
8667 i_tgenabled,
8668 i_tgispartition,
8669 i_tgdef;
8670
8671 /*
8672 * We want to perform just one query against pg_trigger. However, we
8673 * mustn't try to select every row of the catalog and then sort it out on
8674 * the client side, because some of the server-side functions we need
8675 * would be unsafe to apply to tables we don't have lock on. Hence, we
8676 * build an array of the OIDs of tables we care about (and now have lock
8677 * on!), and use a WHERE clause to constrain which rows are selected.
8678 */
8679 appendPQExpBufferChar(tbloids, '{');
8680 for (int i = 0; i < numTables; i++)
8681 {
8682 TableInfo *tbinfo = &tblinfo[i];
8683
8684 if (!tbinfo->hastriggers ||
8685 !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
8686 continue;
8687
8688 /* OK, we need info for this table */
8689 if (tbloids->len > 1) /* do we have more than the '{'? */
8690 appendPQExpBufferChar(tbloids, ',');
8691 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
8692 }
8693 appendPQExpBufferChar(tbloids, '}');
8694
8695 if (fout->remoteVersion >= 150000)
8696 {
8697 /*
8698 * NB: think not to use pretty=true in pg_get_triggerdef. It could
8699 * result in non-forward-compatible dumps of WHEN clauses due to
8700 * under-parenthesization.
8701 *
8702 * NB: We need to see partition triggers in case the tgenabled flag
8703 * has been changed from the parent.
8704 */
8705 appendPQExpBuffer(query,
8706 "SELECT t.tgrelid, t.tgname, "
8707 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8708 "t.tgenabled, t.tableoid, t.oid, "
8709 "t.tgparentid <> 0 AS tgispartition\n"
8710 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8711 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8712 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8713 "WHERE ((NOT t.tgisinternal AND t.tgparentid = 0) "
8714 "OR t.tgenabled != u.tgenabled) "
8715 "ORDER BY t.tgrelid, t.tgname",
8716 tbloids->data);
8717 }
8718 else if (fout->remoteVersion >= 130000)
8719 {
8720 /*
8721 * NB: think not to use pretty=true in pg_get_triggerdef. It could
8722 * result in non-forward-compatible dumps of WHEN clauses due to
8723 * under-parenthesization.
8724 *
8725 * NB: We need to see tgisinternal triggers in partitions, in case the
8726 * tgenabled flag has been changed from the parent.
8727 */
8728 appendPQExpBuffer(query,
8729 "SELECT t.tgrelid, t.tgname, "
8730 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8731 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
8732 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8733 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8734 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8735 "WHERE (NOT t.tgisinternal OR t.tgenabled != u.tgenabled) "
8736 "ORDER BY t.tgrelid, t.tgname",
8737 tbloids->data);
8738 }
8739 else if (fout->remoteVersion >= 110000)
8740 {
8741 /*
8742 * NB: We need to see tgisinternal triggers in partitions, in case the
8743 * tgenabled flag has been changed from the parent. No tgparentid in
8744 * version 11-12, so we have to match them via pg_depend.
8745 *
8746 * See above about pretty=true in pg_get_triggerdef.
8747 */
8748 appendPQExpBuffer(query,
8749 "SELECT t.tgrelid, t.tgname, "
8750 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8751 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
8752 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8753 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8754 "LEFT JOIN pg_catalog.pg_depend AS d ON "
8755 " d.classid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8756 " d.refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8757 " d.objid = t.oid "
8758 "LEFT JOIN pg_catalog.pg_trigger AS pt ON pt.oid = refobjid "
8759 "WHERE (NOT t.tgisinternal OR t.tgenabled != pt.tgenabled) "
8760 "ORDER BY t.tgrelid, t.tgname",
8761 tbloids->data);
8762 }
8763 else
8764 {
8765 /* See above about pretty=true in pg_get_triggerdef */
8766 appendPQExpBuffer(query,
8767 "SELECT t.tgrelid, t.tgname, "
8768 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8769 "t.tgenabled, false as tgispartition, "
8770 "t.tableoid, t.oid "
8771 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8772 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8773 "WHERE NOT tgisinternal "
8774 "ORDER BY t.tgrelid, t.tgname",
8775 tbloids->data);
8776 }
8777
8778 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8779
8780 ntups = PQntuples(res);
8781
8782 i_tableoid = PQfnumber(res, "tableoid");
8783 i_oid = PQfnumber(res, "oid");
8784 i_tgrelid = PQfnumber(res, "tgrelid");
8785 i_tgname = PQfnumber(res, "tgname");
8786 i_tgenabled = PQfnumber(res, "tgenabled");
8787 i_tgispartition = PQfnumber(res, "tgispartition");
8788 i_tgdef = PQfnumber(res, "tgdef");
8789
8790 tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(TriggerInfo));
8791
8792 /*
8793 * Outer loop iterates once per table, not once per row. Incrementing of
8794 * j is handled by the inner loop.
8795 */
8796 curtblindx = -1;
8797 for (int j = 0; j < ntups;)
8798 {
8799 Oid tgrelid = atooid(PQgetvalue(res, j, i_tgrelid));
8800 TableInfo *tbinfo = NULL;
8801 int numtrigs;
8802
8803 /* Count rows for this table */
8804 for (numtrigs = 1; numtrigs < ntups - j; numtrigs++)
8805 if (atooid(PQgetvalue(res, j + numtrigs, i_tgrelid)) != tgrelid)
8806 break;
8807
8808 /*
8809 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8810 * order.
8811 */
8812 while (++curtblindx < numTables)
8813 {
8814 tbinfo = &tblinfo[curtblindx];
8815 if (tbinfo->dobj.catId.oid == tgrelid)
8816 break;
8817 }
8818 if (curtblindx >= numTables)
8819 pg_fatal("unrecognized table OID %u", tgrelid);
8820
8821 /* Save data for this table */
8822 tbinfo->triggers = tginfo + j;
8823 tbinfo->numTriggers = numtrigs;
8824
8825 for (int c = 0; c < numtrigs; c++, j++)
8826 {
8827 tginfo[j].dobj.objType = DO_TRIGGER;
8828 tginfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
8829 tginfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
8830 AssignDumpId(&tginfo[j].dobj);
8831 tginfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_tgname));
8832 tginfo[j].dobj.namespace = tbinfo->dobj.namespace;
8833 tginfo[j].tgtable = tbinfo;
8834 tginfo[j].tgenabled = *(PQgetvalue(res, j, i_tgenabled));
8835 tginfo[j].tgispartition = *(PQgetvalue(res, j, i_tgispartition)) == 't';
8836 tginfo[j].tgdef = pg_strdup(PQgetvalue(res, j, i_tgdef));
8837 }
8838 }
8839
8840 PQclear(res);
8841
8842 destroyPQExpBuffer(query);
8843 destroyPQExpBuffer(tbloids);
8844}
struct _triggerInfo * triggers
Definition: pg_dump.h:392
int numTriggers
Definition: pg_dump.h:391
TableInfo * tgtable
Definition: pg_dump.h:488
DumpableObject dobj
Definition: pg_dump.h:487
char tgenabled
Definition: pg_dump.h:489
char * tgdef
Definition: pg_dump.h:491
bool tgispartition
Definition: pg_dump.h:490

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, CatalogId::tableoid, _triggerInfo::tgdef, _triggerInfo::tgenabled, _triggerInfo::tgispartition, _triggerInfo::tgtable, and _tableInfo::triggers.

Referenced by getSchemaData().

◆ getTSConfigurations()

void getTSConfigurations ( Archive fout)

Definition at line 10323 of file pg_dump.c.

10324{
10325 PGresult *res;
10326 int ntups;
10327 int i;
10328 PQExpBuffer query;
10329 TSConfigInfo *cfginfo;
10330 int i_tableoid;
10331 int i_oid;
10332 int i_cfgname;
10333 int i_cfgnamespace;
10334 int i_cfgowner;
10335 int i_cfgparser;
10336
10337 query = createPQExpBuffer();
10338
10339 appendPQExpBufferStr(query, "SELECT tableoid, oid, cfgname, "
10340 "cfgnamespace, cfgowner, cfgparser "
10341 "FROM pg_ts_config");
10342
10343 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10344
10345 ntups = PQntuples(res);
10346
10347 cfginfo = (TSConfigInfo *) pg_malloc(ntups * sizeof(TSConfigInfo));
10348
10349 i_tableoid = PQfnumber(res, "tableoid");
10350 i_oid = PQfnumber(res, "oid");
10351 i_cfgname = PQfnumber(res, "cfgname");
10352 i_cfgnamespace = PQfnumber(res, "cfgnamespace");
10353 i_cfgowner = PQfnumber(res, "cfgowner");
10354 i_cfgparser = PQfnumber(res, "cfgparser");
10355
10356 for (i = 0; i < ntups; i++)
10357 {
10358 cfginfo[i].dobj.objType = DO_TSCONFIG;
10359 cfginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10360 cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10361 AssignDumpId(&cfginfo[i].dobj);
10362 cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname));
10363 cfginfo[i].dobj.namespace =
10364 findNamespace(atooid(PQgetvalue(res, i, i_cfgnamespace)));
10365 cfginfo[i].rolname = getRoleName(PQgetvalue(res, i, i_cfgowner));
10366 cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser));
10367
10368 /* Decide whether we want to dump it */
10369 selectDumpableObject(&(cfginfo[i].dobj), fout);
10370 }
10371
10372 PQclear(res);
10373
10374 destroyPQExpBuffer(query);
10375}
Oid cfgparser
Definition: pg_dump.h:597
DumpableObject dobj
Definition: pg_dump.h:595
const char * rolname
Definition: pg_dump.h:596

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, _cfgInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getTSDictionaries()

void getTSDictionaries ( Archive fout)

Definition at line 10198 of file pg_dump.c.

10199{
10200 PGresult *res;
10201 int ntups;
10202 int i;
10203 PQExpBuffer query;
10204 TSDictInfo *dictinfo;
10205 int i_tableoid;
10206 int i_oid;
10207 int i_dictname;
10208 int i_dictnamespace;
10209 int i_dictowner;
10210 int i_dicttemplate;
10211 int i_dictinitoption;
10212
10213 query = createPQExpBuffer();
10214
10215 appendPQExpBufferStr(query, "SELECT tableoid, oid, dictname, "
10216 "dictnamespace, dictowner, "
10217 "dicttemplate, dictinitoption "
10218 "FROM pg_ts_dict");
10219
10220 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10221
10222 ntups = PQntuples(res);
10223
10224 dictinfo = (TSDictInfo *) pg_malloc(ntups * sizeof(TSDictInfo));
10225
10226 i_tableoid = PQfnumber(res, "tableoid");
10227 i_oid = PQfnumber(res, "oid");
10228 i_dictname = PQfnumber(res, "dictname");
10229 i_dictnamespace = PQfnumber(res, "dictnamespace");
10230 i_dictowner = PQfnumber(res, "dictowner");
10231 i_dictinitoption = PQfnumber(res, "dictinitoption");
10232 i_dicttemplate = PQfnumber(res, "dicttemplate");
10233
10234 for (i = 0; i < ntups; i++)
10235 {
10236 dictinfo[i].dobj.objType = DO_TSDICT;
10237 dictinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10238 dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10239 AssignDumpId(&dictinfo[i].dobj);
10240 dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname));
10241 dictinfo[i].dobj.namespace =
10242 findNamespace(atooid(PQgetvalue(res, i, i_dictnamespace)));
10243 dictinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_dictowner));
10244 dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate));
10245 if (PQgetisnull(res, i, i_dictinitoption))
10246 dictinfo[i].dictinitoption = NULL;
10247 else
10248 dictinfo[i].dictinitoption = pg_strdup(PQgetvalue(res, i, i_dictinitoption));
10249
10250 /* Decide whether we want to dump it */
10251 selectDumpableObject(&(dictinfo[i].dobj), fout);
10252 }
10253
10254 PQclear(res);
10255
10256 destroyPQExpBuffer(query);
10257}
char * dictinitoption
Definition: pg_dump.h:583
DumpableObject dobj
Definition: pg_dump.h:580
const char * rolname
Definition: pg_dump.h:581
Oid dicttemplate
Definition: pg_dump.h:582

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, _dictInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getTSParsers()

void getTSParsers ( Archive fout)

Definition at line 10124 of file pg_dump.c.

10125{
10126 PGresult *res;
10127 int ntups;
10128 int i;
10129 PQExpBuffer query;
10130 TSParserInfo *prsinfo;
10131 int i_tableoid;
10132 int i_oid;
10133 int i_prsname;
10134 int i_prsnamespace;
10135 int i_prsstart;
10136 int i_prstoken;
10137 int i_prsend;
10138 int i_prsheadline;
10139 int i_prslextype;
10140
10141 query = createPQExpBuffer();
10142
10143 /*
10144 * find all text search objects, including builtin ones; we filter out
10145 * system-defined objects at dump-out time.
10146 */
10147
10148 appendPQExpBufferStr(query, "SELECT tableoid, oid, prsname, prsnamespace, "
10149 "prsstart::oid, prstoken::oid, "
10150 "prsend::oid, prsheadline::oid, prslextype::oid "
10151 "FROM pg_ts_parser");
10152
10153 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10154
10155 ntups = PQntuples(res);
10156
10157 prsinfo = (TSParserInfo *) pg_malloc(ntups * sizeof(TSParserInfo));
10158
10159 i_tableoid = PQfnumber(res, "tableoid");
10160 i_oid = PQfnumber(res, "oid");
10161 i_prsname = PQfnumber(res, "prsname");
10162 i_prsnamespace = PQfnumber(res, "prsnamespace");
10163 i_prsstart = PQfnumber(res, "prsstart");
10164 i_prstoken = PQfnumber(res, "prstoken");
10165 i_prsend = PQfnumber(res, "prsend");
10166 i_prsheadline = PQfnumber(res, "prsheadline");
10167 i_prslextype = PQfnumber(res, "prslextype");
10168
10169 for (i = 0; i < ntups; i++)
10170 {
10171 prsinfo[i].dobj.objType = DO_TSPARSER;
10172 prsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10173 prsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10174 AssignDumpId(&prsinfo[i].dobj);
10175 prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname));
10176 prsinfo[i].dobj.namespace =
10177 findNamespace(atooid(PQgetvalue(res, i, i_prsnamespace)));
10178 prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart));
10179 prsinfo[i].prstoken = atooid(PQgetvalue(res, i, i_prstoken));
10180 prsinfo[i].prsend = atooid(PQgetvalue(res, i, i_prsend));
10181 prsinfo[i].prsheadline = atooid(PQgetvalue(res, i, i_prsheadline));
10182 prsinfo[i].prslextype = atooid(PQgetvalue(res, i, i_prslextype));
10183
10184 /* Decide whether we want to dump it */
10185 selectDumpableObject(&(prsinfo[i].dobj), fout);
10186 }
10187
10188 PQclear(res);
10189
10190 destroyPQExpBuffer(query);
10191}
DumpableObject dobj
Definition: pg_dump.h:570
Oid prstoken
Definition: pg_dump.h:572
Oid prslextype
Definition: pg_dump.h:575
Oid prsheadline
Definition: pg_dump.h:574
Oid prsstart
Definition: pg_dump.h:571
Oid prsend
Definition: pg_dump.h:573

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, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getTSTemplates()

void getTSTemplates ( Archive fout)

Definition at line 10264 of file pg_dump.c.

10265{
10266 PGresult *res;
10267 int ntups;
10268 int i;
10269 PQExpBuffer query;
10270 TSTemplateInfo *tmplinfo;
10271 int i_tableoid;
10272 int i_oid;
10273 int i_tmplname;
10274 int i_tmplnamespace;
10275 int i_tmplinit;
10276 int i_tmpllexize;
10277
10278 query = createPQExpBuffer();
10279
10280 appendPQExpBufferStr(query, "SELECT tableoid, oid, tmplname, "
10281 "tmplnamespace, tmplinit::oid, tmpllexize::oid "
10282 "FROM pg_ts_template");
10283
10284 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10285
10286 ntups = PQntuples(res);
10287
10288 tmplinfo = (TSTemplateInfo *) pg_malloc(ntups * sizeof(TSTemplateInfo));
10289
10290 i_tableoid = PQfnumber(res, "tableoid");
10291 i_oid = PQfnumber(res, "oid");
10292 i_tmplname = PQfnumber(res, "tmplname");
10293 i_tmplnamespace = PQfnumber(res, "tmplnamespace");
10294 i_tmplinit = PQfnumber(res, "tmplinit");
10295 i_tmpllexize = PQfnumber(res, "tmpllexize");
10296
10297 for (i = 0; i < ntups; i++)
10298 {
10299 tmplinfo[i].dobj.objType = DO_TSTEMPLATE;
10300 tmplinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10301 tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10302 AssignDumpId(&tmplinfo[i].dobj);
10303 tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname));
10304 tmplinfo[i].dobj.namespace =
10305 findNamespace(atooid(PQgetvalue(res, i, i_tmplnamespace)));
10306 tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit));
10307 tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize));
10308
10309 /* Decide whether we want to dump it */
10310 selectDumpableObject(&(tmplinfo[i].dobj), fout);
10311 }
10312
10313 PQclear(res);
10314
10315 destroyPQExpBuffer(query);
10316}
Oid tmpllexize
Definition: pg_dump.h:590
Oid tmplinit
Definition: pg_dump.h:589
DumpableObject dobj
Definition: pg_dump.h:588

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, selectDumpableObject(), CatalogId::tableoid, _tmplInfo::tmplinit, and _tmplInfo::tmpllexize.

Referenced by getSchemaData().

◆ getTypes()

void getTypes ( Archive fout)

Definition at line 6171 of file pg_dump.c.

6172{
6173 PGresult *res;
6174 int ntups;
6175 int i;
6177 TypeInfo *tyinfo;
6178 ShellTypeInfo *stinfo;
6179 int i_tableoid;
6180 int i_oid;
6181 int i_typname;
6182 int i_typnamespace;
6183 int i_typacl;
6184 int i_acldefault;
6185 int i_typowner;
6186 int i_typelem;
6187 int i_typrelid;
6188 int i_typrelkind;
6189 int i_typtype;
6190 int i_typisdefined;
6191 int i_isarray;
6192 int i_typarray;
6193
6194 /*
6195 * we include even the built-in types because those may be used as array
6196 * elements by user-defined types
6197 *
6198 * we filter out the built-in types when we dump out the types
6199 *
6200 * same approach for undefined (shell) types and array types
6201 *
6202 * Note: as of 8.3 we can reliably detect whether a type is an
6203 * auto-generated array type by checking the element type's typarray.
6204 * (Before that the test is capable of generating false positives.) We
6205 * still check for name beginning with '_', though, so as to avoid the
6206 * cost of the subselect probe for all standard types. This would have to
6207 * be revisited if the backend ever allows renaming of array types.
6208 */
6209 appendPQExpBufferStr(query, "SELECT tableoid, oid, typname, "
6210 "typnamespace, typacl, "
6211 "acldefault('T', typowner) AS acldefault, "
6212 "typowner, "
6213 "typelem, typrelid, typarray, "
6214 "CASE WHEN typrelid = 0 THEN ' '::\"char\" "
6215 "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, "
6216 "typtype, typisdefined, "
6217 "typname[0] = '_' AND typelem != 0 AND "
6218 "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray "
6219 "FROM pg_type");
6220
6221 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6222
6223 ntups = PQntuples(res);
6224
6225 tyinfo = (TypeInfo *) pg_malloc(ntups * sizeof(TypeInfo));
6226
6227 i_tableoid = PQfnumber(res, "tableoid");
6228 i_oid = PQfnumber(res, "oid");
6229 i_typname = PQfnumber(res, "typname");
6230 i_typnamespace = PQfnumber(res, "typnamespace");
6231 i_typacl = PQfnumber(res, "typacl");
6232 i_acldefault = PQfnumber(res, "acldefault");
6233 i_typowner = PQfnumber(res, "typowner");
6234 i_typelem = PQfnumber(res, "typelem");
6235 i_typrelid = PQfnumber(res, "typrelid");
6236 i_typrelkind = PQfnumber(res, "typrelkind");
6237 i_typtype = PQfnumber(res, "typtype");
6238 i_typisdefined = PQfnumber(res, "typisdefined");
6239 i_isarray = PQfnumber(res, "isarray");
6240 i_typarray = PQfnumber(res, "typarray");
6241
6242 for (i = 0; i < ntups; i++)
6243 {
6244 tyinfo[i].dobj.objType = DO_TYPE;
6245 tyinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6246 tyinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6247 AssignDumpId(&tyinfo[i].dobj);
6248 tyinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_typname));
6249 tyinfo[i].dobj.namespace =
6250 findNamespace(atooid(PQgetvalue(res, i, i_typnamespace)));
6251 tyinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_typacl));
6252 tyinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6253 tyinfo[i].dacl.privtype = 0;
6254 tyinfo[i].dacl.initprivs = NULL;
6255 tyinfo[i].ftypname = NULL; /* may get filled later */
6256 tyinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_typowner));
6257 tyinfo[i].typelem = atooid(PQgetvalue(res, i, i_typelem));
6258 tyinfo[i].typrelid = atooid(PQgetvalue(res, i, i_typrelid));
6259 tyinfo[i].typrelkind = *PQgetvalue(res, i, i_typrelkind);
6260 tyinfo[i].typtype = *PQgetvalue(res, i, i_typtype);
6261 tyinfo[i].shellType = NULL;
6262
6263 if (strcmp(PQgetvalue(res, i, i_typisdefined), "t") == 0)
6264 tyinfo[i].isDefined = true;
6265 else
6266 tyinfo[i].isDefined = false;
6267
6268 if (strcmp(PQgetvalue(res, i, i_isarray), "t") == 0)
6269 tyinfo[i].isArray = true;
6270 else
6271 tyinfo[i].isArray = false;
6272
6273 tyinfo[i].typarray = atooid(PQgetvalue(res, i, i_typarray));
6274
6275 if (tyinfo[i].typtype == TYPTYPE_MULTIRANGE)
6276 tyinfo[i].isMultirange = true;
6277 else
6278 tyinfo[i].isMultirange = false;
6279
6280 /* Decide whether we want to dump it */
6281 selectDumpableType(&tyinfo[i], fout);
6282
6283 /* Mark whether type has an ACL */
6284 if (!PQgetisnull(res, i, i_typacl))
6286
6287 /*
6288 * If it's a domain, fetch info about its constraints, if any
6289 */
6290 tyinfo[i].nDomChecks = 0;
6291 tyinfo[i].domChecks = NULL;
6292 tyinfo[i].notnull = NULL;
6293 if ((tyinfo[i].dobj.dump & DUMP_COMPONENT_DEFINITION) &&
6294 tyinfo[i].typtype == TYPTYPE_DOMAIN)
6295 getDomainConstraints(fout, &(tyinfo[i]));
6296
6297 /*
6298 * If it's a base type, make a DumpableObject representing a shell
6299 * definition of the type. We will need to dump that ahead of the I/O
6300 * functions for the type. Similarly, range types need a shell
6301 * definition in case they have a canonicalize function.
6302 *
6303 * Note: the shell type doesn't have a catId. You might think it
6304 * should copy the base type's catId, but then it might capture the
6305 * pg_depend entries for the type, which we don't want.
6306 */
6307 if ((tyinfo[i].dobj.dump & DUMP_COMPONENT_DEFINITION) &&
6308 (tyinfo[i].typtype == TYPTYPE_BASE ||
6309 tyinfo[i].typtype == TYPTYPE_RANGE))
6310 {
6311 stinfo = (ShellTypeInfo *) pg_malloc(sizeof(ShellTypeInfo));
6312 stinfo->dobj.objType = DO_SHELL_TYPE;
6313 stinfo->dobj.catId = nilCatalogId;
6314 AssignDumpId(&stinfo->dobj);
6315 stinfo->dobj.name = pg_strdup(tyinfo[i].dobj.name);
6316 stinfo->dobj.namespace = tyinfo[i].dobj.namespace;
6317 stinfo->baseType = &(tyinfo[i]);
6318 tyinfo[i].shellType = stinfo;
6319
6320 /*
6321 * Initially mark the shell type as not to be dumped. We'll only
6322 * dump it if the I/O or canonicalize functions need to be dumped;
6323 * this is taken care of while sorting dependencies.
6324 */
6325 stinfo->dobj.dump = DUMP_COMPONENT_NONE;
6326 }
6327 }
6328
6329 PQclear(res);
6330
6331 destroyPQExpBuffer(query);
6332}
static const CatalogId nilCatalogId
Definition: pg_dump.c:189
static void getDomainConstraints(Archive *fout, TypeInfo *tyinfo)
Definition: pg_dump.c:8446
static void selectDumpableType(TypeInfo *tyinfo, Archive *fout)
Definition: pg_dump.c:2109
TypeInfo * baseType
Definition: pg_dump.h:236
DumpableObject dobj
Definition: pg_dump.h:234
bool isMultirange
Definition: pg_dump.h:221
struct _constraintInfo * domChecks
Definition: pg_dump.h:229
DumpableAcl dacl
Definition: pg_dump.h:206
bool isDefined
Definition: pg_dump.h:222
char * ftypname
Definition: pg_dump.h:213
char typrelkind
Definition: pg_dump.h:218
Oid typarray
Definition: pg_dump.h:217
Oid typelem
Definition: pg_dump.h:215
struct _shellTypeInfo * shellType
Definition: pg_dump.h:224
int nDomChecks
Definition: pg_dump.h:228
struct _constraintInfo * notnull
Definition: pg_dump.h:226
char typtype
Definition: pg_dump.h:219
const char * rolname
Definition: pg_dump.h:214
Oid typrelid
Definition: pg_dump.h:216
bool isArray
Definition: pg_dump.h:220

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, _typeInfo::notnull, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, _dumpableAcl::privtype, _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 1111 of file common.c.

1112{
1113 int j,
1114 argNum;
1115 char temp[100];
1116 char s;
1117
1118 argNum = 0;
1119 j = 0;
1120 for (;;)
1121 {
1122 s = *str++;
1123 if (s == ' ' || s == '\0')
1124 {
1125 if (j > 0)
1126 {
1127 if (argNum >= arraysize)
1128 pg_fatal("could not parse numeric array \"%s\": too many numbers", str);
1129 temp[j] = '\0';
1130 array[argNum++] = atooid(temp);
1131 j = 0;
1132 }
1133 if (s == '\0')
1134 break;
1135 }
1136 else
1137 {
1138 if (!(isdigit((unsigned char) s) || s == '-') ||
1139 j >= sizeof(temp) - 1)
1140 pg_fatal("could not parse numeric array \"%s\": invalid character in number", str);
1141 temp[j++] = s;
1142 }
1143 }
1144
1145 while (argNum < arraysize)
1146 array[argNum++] = InvalidOid;
1147}
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 19751 of file pg_dump.c.

19753{
19754 DumpOptions *dopt = fout->dopt;
19755 PQExpBuffer query;
19756 PGresult *res;
19757 int ntups,
19758 i;
19759 int i_conrelid,
19760 i_confrelid;
19761
19762 /* Nothing to do if no extensions */
19763 if (numExtensions == 0)
19764 return;
19765
19766 /*
19767 * Identify extension configuration tables and create TableDataInfo
19768 * objects for them, ensuring their data will be dumped even though the
19769 * tables themselves won't be.
19770 *
19771 * Note that we create TableDataInfo objects even in schema-only mode, ie,
19772 * user data in a configuration table is treated like schema data. This
19773 * seems appropriate since system data in a config table would get
19774 * reloaded by CREATE EXTENSION. If the extension is not listed in the
19775 * list of extensions to be included, none of its data is dumped.
19776 */
19777 for (i = 0; i < numExtensions; i++)
19778 {
19779 ExtensionInfo *curext = &(extinfo[i]);
19780 char *extconfig = curext->extconfig;
19781 char *extcondition = curext->extcondition;
19782 char **extconfigarray = NULL;
19783 char **extconditionarray = NULL;
19784 int nconfigitems = 0;
19785 int nconditionitems = 0;
19786
19787 /*
19788 * Check if this extension is listed as to include in the dump. If
19789 * not, any table data associated with it is discarded.
19790 */
19791 if (extension_include_oids.head != NULL &&
19793 curext->dobj.catId.oid))
19794 continue;
19795
19796 /*
19797 * Check if this extension is listed as to exclude in the dump. If
19798 * yes, any table data associated with it is discarded.
19799 */
19800 if (extension_exclude_oids.head != NULL &&
19802 curext->dobj.catId.oid))
19803 continue;
19804
19805 if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
19806 {
19807 int j;
19808
19809 if (!parsePGArray(extconfig, &extconfigarray, &nconfigitems))
19810 pg_fatal("could not parse %s array", "extconfig");
19811 if (!parsePGArray(extcondition, &extconditionarray, &nconditionitems))
19812 pg_fatal("could not parse %s array", "extcondition");
19813 if (nconfigitems != nconditionitems)
19814 pg_fatal("mismatched number of configurations and conditions for extension");
19815
19816 for (j = 0; j < nconfigitems; j++)
19817 {
19818 TableInfo *configtbl;
19819 Oid configtbloid = atooid(extconfigarray[j]);
19820 bool dumpobj =
19822
19823 configtbl = findTableByOid(configtbloid);
19824 if (configtbl == NULL)
19825 continue;
19826
19827 /*
19828 * Tables of not-to-be-dumped extensions shouldn't be dumped
19829 * unless the table or its schema is explicitly included
19830 */
19831 if (!(curext->dobj.dump & DUMP_COMPONENT_DEFINITION))
19832 {
19833 /* check table explicitly requested */
19834 if (table_include_oids.head != NULL &&
19836 configtbloid))
19837 dumpobj = true;
19838
19839 /* check table's schema explicitly requested */
19840 if (configtbl->dobj.namespace->dobj.dump &
19842 dumpobj = true;
19843 }
19844
19845 /* check table excluded by an exclusion switch */
19846 if (table_exclude_oids.head != NULL &&
19848 configtbloid))
19849 dumpobj = false;
19850
19851 /* check schema excluded by an exclusion switch */
19853 configtbl->dobj.namespace->dobj.catId.oid))
19854 dumpobj = false;
19855
19856 if (dumpobj)
19857 {
19858 makeTableDataInfo(dopt, configtbl);
19859 if (configtbl->dataObj != NULL)
19860 {
19861 if (strlen(extconditionarray[j]) > 0)
19862 configtbl->dataObj->filtercond = pg_strdup(extconditionarray[j]);
19863 }
19864 }
19865 }
19866 }
19867 if (extconfigarray)
19868 free(extconfigarray);
19869 if (extconditionarray)
19870 free(extconditionarray);
19871 }
19872
19873 /*
19874 * Now that all the TableDataInfo objects have been created for all the
19875 * extensions, check their FK dependencies and register them to try and
19876 * dump the data out in an order that they can be restored in.
19877 *
19878 * Note that this is not a problem for user tables as their FKs are
19879 * recreated after the data has been loaded.
19880 */
19881
19882 query = createPQExpBuffer();
19883
19884 printfPQExpBuffer(query,
19885 "SELECT conrelid, confrelid "
19886 "FROM pg_constraint "
19887 "JOIN pg_depend ON (objid = confrelid) "
19888 "WHERE contype = 'f' "
19889 "AND refclassid = 'pg_extension'::regclass "
19890 "AND classid = 'pg_class'::regclass;");
19891
19892 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
19893 ntups = PQntuples(res);
19894
19895 i_conrelid = PQfnumber(res, "conrelid");
19896 i_confrelid = PQfnumber(res, "confrelid");
19897
19898 /* Now get the dependencies and register them */
19899 for (i = 0; i < ntups; i++)
19900 {
19901 Oid conrelid,
19902 confrelid;
19903 TableInfo *reftable,
19904 *contable;
19905
19906 conrelid = atooid(PQgetvalue(res, i, i_conrelid));
19907 confrelid = atooid(PQgetvalue(res, i, i_confrelid));
19908 contable = findTableByOid(conrelid);
19909 reftable = findTableByOid(confrelid);
19910
19911 if (reftable == NULL ||
19912 reftable->dataObj == NULL ||
19913 contable == NULL ||
19914 contable->dataObj == NULL)
19915 continue;
19916
19917 /*
19918 * Make referencing TABLE_DATA object depend on the referenced table's
19919 * TABLE_DATA object.
19920 */
19921 addObjectDependency(&contable->dataObj->dobj,
19922 reftable->dataObj->dobj.dumpId);
19923 }
19924 PQclear(res);
19925 destroyPQExpBuffer(query);
19926}
static SimpleOidList schema_exclude_oids
Definition: pg_dump.c:168
static SimpleOidList extension_include_oids
Definition: pg_dump.c:184
static SimpleOidList extension_exclude_oids
Definition: pg_dump.c:187
static void makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo)
Definition: pg_dump.c:3025
static SimpleOidList table_exclude_oids
Definition: pg_dump.c:175
static SimpleOidList table_include_oids
Definition: pg_dump.c:172
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:413
char * filtercond
Definition: pg_dump.h:415
struct _tableDataInfo * dataObj
Definition: pg_dump.h:390

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(), 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 719 of file common.c.

720{
721 CatalogIdMapEntry *entry;
722 bool found;
723
724 /* CatalogId hash table must exist, if we have a DumpableObject */
725 Assert(catalogIdHash != NULL);
726
727 /* Add reference to CatalogId hash */
728 entry = catalogid_insert(catalogIdHash, catId, &found);
729 if (!found)
730 {
731 entry->dobj = NULL;
732 entry->ext = NULL;
733 }
734 Assert(entry->dobj == NULL);
735 entry->dobj = dobj;
736}

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

Referenced by getLOs().

◆ recordExtensionMembership()

void recordExtensionMembership ( CatalogId  catId,
ExtensionInfo ext 
)

Definition at line 1063 of file common.c.

1064{
1065 CatalogIdMapEntry *entry;
1066 bool found;
1067
1068 /* CatalogId hash table must exist, if we have an ExtensionInfo */
1069 Assert(catalogIdHash != NULL);
1070
1071 /* Add reference to CatalogId hash */
1072 entry = catalogid_insert(catalogIdHash, catId, &found);
1073 if (!found)
1074 {
1075 entry->dobj = NULL;
1076 entry->ext = NULL;
1077 }
1078 Assert(entry->ext == NULL);
1079 entry->ext = ext;
1080}

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

Referenced by getExtensionMembership().

◆ removeObjectDependency()

◆ shouldPrintColumn()

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

Definition at line 10109 of file pg_dump.c.

10110{
10111 if (dopt->binary_upgrade)
10112 return true;
10113 if (tbinfo->attisdropped[colno])
10114 return false;
10115 return (tbinfo->attislocal[colno] || tbinfo->ispartition);
10116}

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 547 of file pg_dump_sort.c.

549{
550 DumpableObject **ordering;
551 int nOrdering;
552
553 if (numObjs <= 0) /* can't happen anymore ... */
554 return;
555
556 /*
557 * Saving the boundary IDs in static variables is a bit grotty, but seems
558 * better than adding them to parameter lists of subsidiary functions.
559 */
560 preDataBoundId = preBoundaryId;
561 postDataBoundId = postBoundaryId;
562
563 ordering = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *));
564 while (!TopoSort(objs, numObjs, ordering, &nOrdering))
565 findDependencyLoops(ordering, nOrdering, numObjs);
566
567 memcpy(objs, ordering, numObjs * sizeof(DumpableObject *));
568
569 free(ordering);
570}
static void findDependencyLoops(DumpableObject **objs, int nObjs, int totObjs)
Definition: pg_dump_sort.c:748
static DumpId preDataBoundId
Definition: pg_dump_sort.c:160
static bool TopoSort(DumpableObject **objs, int numObjs, DumpableObject **ordering, int *nOrdering)
Definition: pg_dump_sort.c:599
static DumpId postDataBoundId
Definition: pg_dump_sort.c:161

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

Referenced by main().

◆ sortDumpableObjectsByTypeName()

void sortDumpableObjectsByTypeName ( DumpableObject **  objs,
int  numObjs 
)

Definition at line 192 of file pg_dump_sort.c.

193{
194 if (numObjs > 1)
195 qsort(objs, numObjs, sizeof(DumpableObject *),
197}
static int DOTypeNameCompare(const void *p1, const void *p2)
Definition: pg_dump_sort.c:200
#define qsort(a, b, c, d)
Definition: port.h:479

References DOTypeNameCompare(), and qsort.

Referenced by main().