PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 getSubscriptionRelations (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:
(\
#define DUMP_COMPONENT_DATA
Definition pg_dump.h:110
#define DUMP_COMPONENT_POLICY
Definition pg_dump.h:114
#define DUMP_COMPONENT_DEFINITION
Definition pg_dump.h:109
#define DUMP_COMPONENT_STATISTICS
Definition pg_dump.h:116

Definition at line 141 of file pg_dump.h.

147{
148 DumpableObjectType objType;
149 CatalogId catId; /* zero if not a cataloged object */
150 DumpId dumpId; /* assigned by AssignDumpId() */
151 char *name; /* object name (should never be NULL) */
152 struct _namespaceInfo *namespace; /* containing namespace, or NULL */
153 DumpComponents dump; /* bitmask of components requested to dump */
154 DumpComponents dump_contains; /* as above, but for contained objects */
155 DumpComponents components; /* bitmask of components available to dump */
156 bool ext_member; /* true if object is member of extension */
157 bool depends_on_ext; /* true if object depends on an extension */
158 DumpId *dependencies; /* dumpIds of objects this one depends on */
159 int nDeps; /* number of valid dependencies */
160 int allocDeps; /* allocated size of dependencies[] */
162
163/*
164 * Object types that have ACLs must store them in a DumpableAcl sub-struct,
165 * which must immediately follow the DumpableObject base struct.
166 */
167typedef struct _dumpableAcl
168{
169 char *acl; /* the object's actual ACL string */
170 char *acldefault; /* default ACL for the object's type & owner */
171 /* these fields come from the object's pg_init_privs entry, if any: */
172 char privtype; /* entry type, 'i' or 'e'; 0 if no entry */
173 char *initprivs; /* the object's initial ACL string, or NULL */
175
176/* Generic struct that can be used to access any object type having an ACL */
177typedef struct _dumpableObjectWithAcl
178{
182
183typedef struct _namespaceInfo
184{
187 bool create; /* CREATE SCHEMA, or just set owner? */
188 Oid nspowner; /* OID of owner */
189 const char *rolname; /* name of owner */
191
192typedef struct _extensionInfo
193{
195 char *namespace; /* schema containing extension's objects */
196 bool relocatable;
197 char *extversion;
198 char *extconfig; /* info about configuration tables */
199 char *extcondition;
201
202typedef struct _typeInfo
203{
206
207 /*
208 * Note: dobj.name is the raw pg_type.typname entry. ftypname is the
209 * result of format_type(), which will be quoted if needed, and might be
210 * schema-qualified too.
211 */
212 char *ftypname;
213 const char *rolname;
214 Oid typelem;
217 char typrelkind; /* 'r', 'v', 'c', etc */
218 char typtype; /* 'b', 'c', etc */
219 bool isArray; /* true if auto-generated array type */
220 bool isMultirange; /* true if auto-generated multirange type */
221 bool isDefined; /* true if typisdefined */
222 /* If needed, we'll create a "shell type" entry for it; link that here: */
223 struct _shellTypeInfo *shellType; /* shell-type entry, or NULL */
224 /* If it's a domain, its not-null constraint is here: */
225 struct _constraintInfo *notnull;
226 /* If it's a domain, we store links to its CHECK constraints here: */
227 int nDomChecks;
229} TypeInfo;
230
231typedef struct _shellTypeInfo
232{
234
235 TypeInfo *baseType; /* back link to associated base type */
237
238typedef struct _funcInfo
239{
242 const char *rolname;
243 Oid lang;
244 int nargs;
245 Oid *argtypes;
247 bool postponed_def; /* function must be postponed into post-data */
248} FuncInfo;
249
250/* AggInfo is a superset of FuncInfo */
251typedef struct _aggInfo
252{
254 /* we don't require any other fields at the moment */
255} AggInfo;
256
257typedef struct _oprInfo
258{
260 const char *rolname;
261 char oprkind;
262 Oid oprleft;
264 Oid oprcode;
265} OprInfo;
266
267typedef struct _accessMethodInfo
268{
270 char amtype;
271 char *amhandler;
273
274typedef struct _opclassInfo
275{
278 const char *rolname;
280
281typedef struct _opfamilyInfo
282{
285 const char *rolname;
287
288typedef struct _collInfo
289{
291 const char *rolname;
292 int collencoding;
293} CollInfo;
294
295typedef struct _convInfo
296{
298 const char *rolname;
299} ConvInfo;
300
301typedef struct _tableInfo
302{
303 /*
304 * These fields are collected for every table in the database.
305 */
308 const char *rolname;
309 char relkind;
310 char relpersistence; /* relation persistence */
311 bool relispopulated; /* relation is populated */
312 char relreplident; /* replica identifier */
313 char *reltablespace; /* relation tablespace */
314 char *reloptions; /* options specified by WITH (...) */
315 char *checkoption; /* WITH CHECK OPTION, if any */
316 char *toast_reloptions; /* WITH options for the TOAST table */
317 bool hasindex; /* does it have any indexes? */
318 bool hasrules; /* does it have any rules? */
319 bool hastriggers; /* does it have any triggers? */
320 bool hascolumnACLs; /* do any columns have non-default ACLs? */
321 bool rowsec; /* is row security enabled? */
322 bool forcerowsec; /* is row security forced? */
323 bool hasoids; /* does it have OIDs? */
324 uint32 frozenxid; /* table's relfrozenxid */
325 uint32 minmxid; /* table's relminmxid */
326 Oid toast_oid; /* toast table's OID, or 0 if none */
327 uint32 toast_frozenxid; /* toast table's relfrozenxid, if any */
328 uint32 toast_minmxid; /* toast table's relminmxid */
329 int ncheck; /* # of CHECK expressions */
330 Oid reltype; /* OID of table's composite type, if any */
331 Oid reloftype; /* underlying type for typed table */
332 Oid foreign_server; /* foreign server oid, if applicable */
333 /* these two are set only if table is a sequence owned by a column: */
334 Oid owning_tab; /* OID of table owning sequence */
335 int owning_col; /* attr # of column owning sequence */
337 int32 relpages; /* table's size in pages (from pg_class) */
338 int toastpages; /* toast table's size in pages, if any */
339
340 bool interesting; /* true if need to collect more data */
341 bool dummy_view; /* view's real definition must be postponed */
342 bool postponed_def; /* matview must be postponed into post-data */
343 bool ispartition; /* is table a partition? */
344 bool unsafe_partitions; /* is it an unsafe partitioned table? */
345
346 int numParents; /* number of (immediate) parent tables */
347 struct _tableInfo **parents; /* TableInfos of immediate parents */
348
349 /*
350 * These fields are computed only if we decide the table is interesting
351 * (it's either a table to dump, or a direct parent of a dumpable table).
352 */
353 int numatts; /* number of attributes */
354 char **attnames; /* the attribute names */
355 char **atttypnames; /* attribute type names */
356 int *attstattarget; /* attribute statistics targets */
357 char *attstorage; /* attribute storage scheme */
358 char *typstorage; /* type storage scheme */
359 bool *attisdropped; /* true if attr is dropped; don't dump it */
360 char *attidentity;
361 char *attgenerated;
362 int *attlen; /* attribute length, used by binary_upgrade */
363 char *attalign; /* attribute align, used by binary_upgrade */
364 bool *attislocal; /* true if attr has local definition */
365 char **attoptions; /* per-attribute options */
366 Oid *attcollation; /* per-attribute collation selection */
367 char *attcompression; /* per-attribute compression method */
368 char **attfdwoptions; /* per-attribute fdw options */
369 char **attmissingval; /* per attribute missing value */
370 char **notnull_constrs; /* NOT NULL constraint names. If null,
371 * there isn't one on this column. If
372 * empty string, unnamed constraint
373 * (pre-v17) */
374 char **notnull_comment; /* comment thereof */
375 bool *notnull_invalid; /* true for NOT NULL NOT VALID */
376 bool *notnull_noinh; /* NOT NULL is NO INHERIT */
377 bool *notnull_islocal; /* true if NOT NULL has local definition */
378 struct _attrDefInfo **attrdefs; /* DEFAULT expressions */
379 struct _constraintInfo *checkexprs; /* CHECK constraints */
380 struct _relStatsInfo *stats; /* only set for matviews */
381 bool needs_override; /* has GENERATED ALWAYS AS IDENTITY */
382 char *amname; /* relation access method */
383
384 /*
385 * Stuff computed only for dumpable tables.
386 */
387 int numIndexes; /* number of indexes */
388 struct _indxInfo *indexes; /* indexes */
389 struct _tableDataInfo *dataObj; /* TableDataInfo, if dumping its data */
390 int numTriggers; /* number of triggers for table */
391 struct _triggerInfo *triggers; /* array of TriggerInfo structs */
392} TableInfo;
393
394typedef struct _tableAttachInfo
395{
397 TableInfo *parentTbl; /* link to partitioned table */
398 TableInfo *partitionTbl; /* link to partition */
400
401typedef struct _attrDefInfo
402{
403 DumpableObject dobj; /* note: dobj.name is name of table */
404 TableInfo *adtable; /* link to table of attribute */
405 int adnum;
406 char *adef_expr; /* decompiled DEFAULT expression */
407 bool separate; /* true if must dump as separate item */
409
410typedef struct _tableDataInfo
411{
413 TableInfo *tdtable; /* link to table to dump */
414 char *filtercond; /* WHERE condition to limit rows dumped */
416
417typedef struct _indxInfo
418{
420 TableInfo *indextable; /* link to table the index is for */
421 char *indexdef;
422 char *tablespace; /* tablespace in which index is stored */
423 char *indreloptions; /* options specified by WITH (...) */
424 char *indstatcols; /* column numbers with statistics */
425 char *indstatvals; /* statistic values for columns */
426 int indnkeyattrs; /* number of index key attributes */
427 int indnattrs; /* total number of index attributes */
428 Oid *indkeys; /* In spite of the name 'indkeys' this field
429 * contains both key and nonkey attributes */
430 bool indisclustered;
431 bool indisreplident;
433 Oid parentidx; /* if a partition, parent index OID */
434 SimplePtrList partattaches; /* if partitioned, partition attach objects */
435
436 /* if there is an associated constraint object, its dumpId: */
438} IndxInfo;
439
440typedef struct _indexAttachInfo
441{
443 IndxInfo *parentIdx; /* link to index on partitioned table */
444 IndxInfo *partitionIdx; /* link to index on partition */
446
447typedef struct _relStatsInfo
448{
451 char *reltuples;
454 char relkind; /* 'r', 'm', 'i', etc */
455
456 /*
457 * indAttNames/nindAttNames are populated only if the relation is an index
458 * with at least one expression column; we don't need them otherwise.
459 */
460 char **indAttNames; /* attnames of the index, in order */
461 int32 nindAttNames; /* number of attnames stored (can be 0) */
462 teSection section; /* stats may appear in data or post-data */
464
465typedef struct _statsExtInfo
466{
468 const char *rolname; /* owner */
469 TableInfo *stattable; /* link to table the stats are for */
470 int stattarget; /* statistics target */
472
473typedef struct _ruleInfo
474{
476 TableInfo *ruletable; /* link to table the rule is for */
477 char ev_type;
478 bool is_instead;
479 char ev_enabled;
480 bool separate; /* true if must dump as separate item */
481 /* separate is always true for non-ON SELECT rules */
482} RuleInfo;
483
484typedef struct _triggerInfo
485{
487 TableInfo *tgtable; /* link to table the trigger is for */
488 char tgenabled;
489 bool tgispartition;
490 char *tgdef;
492
493typedef struct _evttriggerInfo
494{
496 char *evtname;
497 char *evtevent;
498 const char *evtowner;
499 char *evttags;
500 char *evtfname;
501 char evtenabled;
503
504/*
505 * struct ConstraintInfo is used for all constraint types. However we
506 * use a different objType for foreign key constraints, to make it easier
507 * to sort them the way we want.
508 *
509 * Not-null constraints don't need this, unless they are NOT VALID.
510 *
511 * Note: condeferrable and condeferred are currently only valid for
512 * unique/primary-key constraints. Otherwise that info is in condef.
513 */
514typedef struct _constraintInfo
515{
517 TableInfo *contable; /* NULL if domain constraint */
518 TypeInfo *condomain; /* NULL if table constraint */
519 char contype;
520 char *condef; /* definition, if CHECK or FOREIGN KEY */
521 Oid confrelid; /* referenced table, if FOREIGN KEY */
522 DumpId conindex; /* identifies associated index if any */
523 bool condeferrable; /* true if constraint is DEFERRABLE */
524 bool condeferred; /* true if constraint is INITIALLY DEFERRED */
525 bool conperiod; /* true if the constraint is WITHOUT OVERLAPS */
526 bool conislocal; /* true if constraint has local definition */
527 bool separate; /* true if must dump as separate item */
529
530typedef struct _procLangInfo
531{
534 bool lanpltrusted;
538 const char *lanowner;
540
541typedef struct _castInfo
542{
547 char castcontext;
548 char castmethod;
549} CastInfo;
550
551typedef struct _transformInfo
552{
554 Oid trftype;
555 Oid trflang;
559
560/* InhInfo isn't a DumpableObject, just temporary state */
561typedef struct _inhInfo
562{
563 Oid inhrelid; /* OID of a child table */
564 Oid inhparent; /* OID of its parent */
565} InhInfo;
566
567typedef struct _prsInfo
568{
572 Oid prsend;
576
577typedef struct _dictInfo
578{
580 const char *rolname;
582 char *dictinitoption;
583} TSDictInfo;
584
585typedef struct _tmplInfo
586{
591
592typedef struct _cfgInfo
593{
595 const char *rolname;
598
599typedef struct _fdwInfo
600{
603 const char *rolname;
604 char *fdwhandler;
605 char *fdwvalidator;
606 char *fdwoptions;
607} FdwInfo;
608
609typedef struct _foreignServerInfo
610{
613 const char *rolname;
614 Oid srvfdw;
615 char *srvtype;
616 char *srvversion;
617 char *srvoptions;
619
620typedef struct _defaultACLInfo
621{
624 const char *defaclrole;
625 char defaclobjtype;
627
628/*
629 * LoInfo represents a group of large objects (blobs) that share the same
630 * owner and ACL setting. dobj.components has the DUMP_COMPONENT_COMMENT bit
631 * set if any blob in the group has a comment; similarly for sec labels.
632 * If there are many blobs with the same owner/ACL, we can divide them into
633 * multiple LoInfo groups, which will each spawn a BLOB METADATA and a BLOBS
634 * (data) TOC entry. This allows more parallelism during restore.
635 */
636typedef struct _loInfo
637{
640 const char *rolname;
641 int numlos;
643} LoInfo;
644
645/*
646 * The PolicyInfo struct is used to represent policies on a table and
647 * to indicate if a table has RLS enabled (ENABLE ROW SECURITY). If
648 * polname is NULL, then the record indicates ENABLE ROW SECURITY, while if
649 * it's non-NULL then this is a regular policy definition.
650 */
651typedef struct _policyInfo
652{
655 char *polname; /* null indicates RLS is enabled on rel */
656 char polcmd;
657 bool polpermissive;
658 char *polroles;
659 char *polqual;
660 char *polwithcheck;
661} PolicyInfo;
662
663/*
664 * The PublicationInfo struct is used to represent publications.
665 */
666typedef struct _PublicationInfo
667{
669 const char *rolname;
670 bool puballtables;
671 bool puballsequences;
672 bool pubinsert;
673 bool pubupdate;
674 bool pubdelete;
675 bool pubtruncate;
676 bool pubviaroot;
679
680/*
681 * The PublicationRelInfo struct is used to represent publication table
682 * mapping.
683 */
684typedef struct _PublicationRelInfo
685{
689 char *pubrelqual;
690 char *pubrattrs;
692
693/*
694 * The PublicationSchemaInfo struct is used to represent publication schema
695 * mapping.
696 */
697typedef struct _PublicationSchemaInfo
698{
703
704/*
705 * The SubscriptionInfo struct is used to represent subscription.
706 */
707typedef struct _SubscriptionInfo
708{
710 const char *rolname;
711 bool subenabled;
712 bool subbinary;
713 char substream;
714 char subtwophasestate;
715 bool subdisableonerr;
717 bool subrunasowner;
718 bool subfailover;
720 int submaxretention;
721 char *subconninfo;
722 char *subslotname;
723 char *subsynccommit;
724 char *subpublications;
725 char *suborigin;
726 char *suboriginremotelsn;
728
729/*
730 * The SubRelInfo struct is used to represent a subscription relation.
731 *
732 * XXX Currently, the subscription tables are added to the subscription after
733 * enabling the subscription in binary-upgrade mode. As the apply workers will
734 * not be started in binary_upgrade mode the ordering of enable subscription
735 * does not matter. The order of adding the subscription tables to the
736 * subscription and enabling the subscription should be taken care of if this
737 * feature will be supported in a non-binary-upgrade mode in the future.
738 */
739typedef struct _SubRelInfo
740{
744 char srsubstate;
745 char *srsublsn;
746} SubRelInfo;
747
748/*
749 * common utility functions
750 */
751
753
754extern void AssignDumpId(DumpableObject *dobj);
755extern void recordAdditionalCatalogID(CatalogId catId, DumpableObject *dobj);
756extern DumpId createDumpId(void);
757extern DumpId getMaxDumpId(void);
760extern void getDumpableObjects(DumpableObject ***objs, int *numObjs);
761
764
765extern TableInfo *findTableByOid(Oid oid);
766extern TypeInfo *findTypeByOid(Oid oid);
767extern FuncInfo *findFuncByOid(Oid oid);
768extern OprInfo *findOprByOid(Oid oid);
770extern CollInfo *findCollationByOid(Oid oid);
775
776extern void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext);
778
779extern void parseOidArray(const char *str, Oid *array, int arraysize);
780
784
785/*
786 * version specific routines
787 */
788extern void getNamespaces(Archive *fout);
790extern void getTypes(Archive *fout);
791extern void getFuncs(Archive *fout);
792extern void getAggregates(Archive *fout);
793extern void getOperators(Archive *fout);
794extern void getAccessMethods(Archive *fout);
795extern void getOpclasses(Archive *fout);
796extern void getOpfamilies(Archive *fout);
797extern void getCollations(Archive *fout);
798extern void getConversions(Archive *fout);
800extern void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables);
802extern void getPartitioningInfo(Archive *fout);
803extern void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables);
805extern void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables);
806extern void getRules(Archive *fout);
807extern void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables);
808extern void getProcLangs(Archive *fout);
809extern void getCasts(Archive *fout);
810extern void getTransforms(Archive *fout);
811extern void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables);
812extern bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno);
813extern void getTSParsers(Archive *fout);
814extern void getTSDictionaries(Archive *fout);
815extern void getTSTemplates(Archive *fout);
816extern void getTSConfigurations(Archive *fout);
818extern void getForeignServers(Archive *fout);
819extern void getDefaultACLs(Archive *fout);
821 int numExtensions);
823 int numExtensions);
824extern void getEventTriggers(Archive *fout);
825extern void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables);
826extern void getPublications(Archive *fout);
828extern void getPublicationTables(Archive *fout, TableInfo tblinfo[],
829 int numTables);
830extern void getSubscriptions(Archive *fout);
832
833#endif /* PG_DUMP_H */
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:480
int32_t int32
Definition c.h:542
uint32_t uint32
Definition c.h:546
const char * str
int DumpId
Definition pg_backup.h:285
enum _teSection teSection
void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8308
struct _collInfo CollInfo
void recordAdditionalCatalogID(CatalogId catId, DumpableObject *dobj)
Definition common.c:719
struct _transformInfo TransformInfo
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition pg_dump.c:6137
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition common.c:1063
void getPublicationNamespaces(Archive *fout)
Definition pg_dump.c:4770
struct _opfamilyInfo OpfamilyInfo
void getPartitioningInfo(Archive *fout)
Definition pg_dump.c:7797
struct _indxInfo IndxInfo
struct _fdwInfo FdwInfo
struct _triggerInfo TriggerInfo
struct _tmplInfo TSTemplateInfo
struct _tableInfo TableInfo
FuncInfo * findFuncByOid(Oid oid)
Definition common.c:918
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition pg_dump.c:7741
TableInfo * findTableByOid(Oid oid)
Definition common.c:863
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10428
struct _aggInfo AggInfo
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4261
ExtensionInfo * findExtensionByOid(Oid oid)
Definition common.c:1008
struct _castInfo CastInfo
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:19945
CollInfo * findCollationByOid(Oid oid)
Definition common.c:972
struct _tableDataInfo TableDataInfo
struct _cfgInfo TSConfigInfo
SubscriptionInfo * findSubscriptionByOid(Oid oid)
Definition common.c:1044
void getTypes(Archive *fout)
Definition pg_dump.c:6212
struct _dumpableObject DumpableObject
struct _accessMethodInfo AccessMethodInfo
struct _attrDefInfo AttrDefInfo
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7676
void getOpclasses(Archive *fout)
Definition pg_dump.c:6658
void getForeignServers(Archive *fout)
Definition pg_dump.c:10512
void getFuncs(Archive *fout)
Definition pg_dump.c:6927
OprInfo * findOprByOid(Oid oid)
Definition common.c:936
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10244
struct _ruleInfo RuleInfo
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4850
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition common.c:990
struct _relStatsInfo RelStatsInfo
void getCasts(Archive *fout)
Definition pg_dump.c:9057
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7857
AccessMethodInfo * findAccessMethodByOid(Oid oid)
Definition common.c:954
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:818
void getTSConfigurations(Archive *fout)
Definition pg_dump.c:10369
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition common.c:765
struct _foreignServerInfo ForeignServerInfo
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition common.c:1111
struct _inhInfo InhInfo
struct _indexAttachInfo IndexAttachInfo
struct _SubRelInfo SubRelInfo
struct _procLangInfo ProcLangInfo
void getAccessMethods(Archive *fout)
Definition pg_dump.c:6584
void getConversions(Archive *fout)
Definition pg_dump.c:6522
void getRules(Archive *fout)
Definition pg_dump.c:8602
ExtensionInfo * findOwningExtension(CatalogId catalogId)
Definition common.c:1087
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9251
struct _prsInfo TSParserInfo
struct _policyInfo PolicyInfo
TableInfo * getSchemaData(Archive *fout, int *numTablesPtr)
Definition common.c:98
struct _PublicationInfo PublicationInfo
void getCollations(Archive *fout)
Definition pg_dump.c:6456
struct _namespaceInfo NamespaceInfo
void getAggregates(Archive *fout)
Definition pg_dump.c:6786
struct _shellTypeInfo ShellTypeInfo
void getNamespaces(Archive *fout)
Definition pg_dump.c:6005
void getPublications(Archive *fout)
Definition pg_dump.c:4551
void getTSParsers(Archive *fout)
Definition pg_dump.c:10170
TypeInfo * findTypeByOid(Oid oid)
Definition common.c:899
struct _dumpableObjectWithAcl DumpableObjectWithAcl
struct _defaultACLInfo DefaultACLInfo
DumpId createDumpId(void)
Definition common.c:745
TableInfo * getTables(Archive *fout, int *numTables)
Definition pg_dump.c:7199
struct _loInfo LoInfo
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition common.c:778
void AssignDumpId(DumpableObject *dobj)
Definition common.c:657
struct _evttriggerInfo EventTriggerInfo
void getExtendedStatistics(Archive *fout)
Definition pg_dump.c:8226
struct _dumpableAcl DumpableAcl
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20038
DumpId getMaxDumpId(void)
Definition common.c:754
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10600
uint32 DumpComponents
Definition pg_dump.h:107
struct _typeInfo TypeInfo
void getSubscriptions(Archive *fout)
Definition pg_dump.c:5121
void sortDumpableObjects(DumpableObject **objs, int numObjs, DumpId preBoundaryId, DumpId postBoundaryId)
struct _SubscriptionInfo SubscriptionInfo
struct _extensionInfo ExtensionInfo
struct _dictInfo TSDictInfo
struct _funcInfo FuncInfo
struct _opclassInfo OpclassInfo
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition common.c:797
struct _statsExtInfo StatsExtInfo
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8699
void getTransforms(Archive *fout)
Definition pg_dump.c:9167
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8895
DumpableObjectType
Definition pg_dump.h:39
struct _PublicationRelInfo PublicationRelInfo
PublicationInfo * findPublicationByOid(Oid oid)
Definition common.c:1026
void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs)
struct _convInfo ConvInfo
struct _constraintInfo ConstraintInfo
void getTSTemplates(Archive *fout)
Definition pg_dump.c:10310
void getProcLangs(Archive *fout)
Definition pg_dump.c:8973
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition pg_dump.c:10155
void getSubscriptionRelations(Archive *fout)
Definition pg_dump.c:5341
struct _tableAttachInfo TableAttachInfo
void removeObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:843
void getOperators(Archive *fout)
Definition pg_dump.c:6380
void getOpfamilies(Archive *fout)
Definition pg_dump.c:6721
struct _oprInfo OprInfo
struct _PublicationSchemaInfo PublicationSchemaInfo
unsigned int Oid
static int fb(int x)
const char * rolname
Definition pg_dump.h:670
bool puballsequences
Definition pg_dump.h:672
PublishGencolsType pubgencols_type
Definition pg_dump.h:678
DumpableObject dobj
Definition pg_dump.h:669
TableInfo * pubtable
Definition pg_dump.h:689
PublicationInfo * publication
Definition pg_dump.h:688
DumpableObject dobj
Definition pg_dump.h:687
NamespaceInfo * pubschema
Definition pg_dump.h:702
DumpableObject dobj
Definition pg_dump.h:700
PublicationInfo * publication
Definition pg_dump.h:701
DumpableObject dobj
Definition pg_dump.h:742
char * srsublsn
Definition pg_dump.h:746
SubscriptionInfo * subinfo
Definition pg_dump.h:743
TableInfo * tblinfo
Definition pg_dump.h:744
char srsubstate
Definition pg_dump.h:745
char * suboriginremotelsn
Definition pg_dump.h:727
bool subpasswordrequired
Definition pg_dump.h:717
const char * rolname
Definition pg_dump.h:711
char * subsynccommit
Definition pg_dump.h:724
char * subpublications
Definition pg_dump.h:725
char * subslotname
Definition pg_dump.h:723
char subtwophasestate
Definition pg_dump.h:715
bool subretaindeadtuples
Definition pg_dump.h:720
char * subconninfo
Definition pg_dump.h:722
DumpableObject dobj
Definition pg_dump.h:710
DumpableObject dobj
Definition pg_dump.h:270
FuncInfo aggfn
Definition pg_dump.h:254
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
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
Oid cfgparser
Definition pg_dump.h:597
DumpableObject dobj
Definition pg_dump.h:595
const char * rolname
Definition pg_dump.h:596
int collencoding
Definition pg_dump.h:293
const char * rolname
Definition pg_dump.h:292
DumpableObject dobj
Definition pg_dump.h:291
TypeInfo * condomain
Definition pg_dump.h:519
TableInfo * contable
Definition pg_dump.h:518
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:298
const char * rolname
Definition pg_dump.h:299
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 * 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
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
DumpableObject dobj
Definition pg_dump.h:180
char * evtevent
Definition pg_dump.h:498
char * evtfname
Definition pg_dump.h:501
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
bool relocatable
Definition pg_dump.h:196
char * extversion
Definition pg_dump.h:198
DumpableObject dobj
Definition pg_dump.h:195
char * extcondition
Definition pg_dump.h:200
char * extconfig
Definition pg_dump.h:199
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
DumpableAcl dacl
Definition pg_dump.h:613
DumpableObject dobj
Definition pg_dump.h:612
const char * rolname
Definition pg_dump.h:614
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
IndxInfo * partitionIdx
Definition pg_dump.h:445
DumpableObject dobj
Definition pg_dump.h:443
IndxInfo * parentIdx
Definition pg_dump.h:444
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:420
Oid inhparent
Definition pg_dump.h:565
Oid inhrelid
Definition pg_dump.h:564
const char * rolname
Definition pg_dump.h:641
DumpableObject dobj
Definition pg_dump.h:639
DumpableAcl dacl
Definition pg_dump.h:640
Oid looids[FLEXIBLE_ARRAY_MEMBER]
Definition pg_dump.h:643
int numlos
Definition pg_dump.h:642
DumpableObject dobj
Definition pg_dump.h:186
DumpableAcl dacl
Definition pg_dump.h:187
const char * rolname
Definition pg_dump.h:190
Oid opcmethod
Definition pg_dump.h:278
DumpableObject dobj
Definition pg_dump.h:277
const char * rolname
Definition pg_dump.h:279
const char * rolname
Definition pg_dump.h:286
DumpableObject dobj
Definition pg_dump.h:284
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
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
Oid lanvalidator
Definition pg_dump.h:538
DumpableAcl dacl
Definition pg_dump.h:534
DumpableObject dobj
Definition pg_dump.h:533
const char * lanowner
Definition pg_dump.h:539
Oid lanplcallfoid
Definition pg_dump.h:536
bool lanpltrusted
Definition pg_dump.h:535
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
int32 nindAttNames
Definition pg_dump.h:462
char ** indAttNames
Definition pg_dump.h:461
int32 relpages
Definition pg_dump.h:451
int32 relallfrozen
Definition pg_dump.h:454
char * reltuples
Definition pg_dump.h:452
teSection section
Definition pg_dump.h:463
int32 relallvisible
Definition pg_dump.h:453
DumpableObject dobj
Definition pg_dump.h:450
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
TypeInfo * baseType
Definition pg_dump.h:236
DumpableObject dobj
Definition pg_dump.h:234
TableInfo * stattable
Definition pg_dump.h:470
const char * rolname
Definition pg_dump.h:469
DumpableObject dobj
Definition pg_dump.h:468
TableInfo * partitionTbl
Definition pg_dump.h:399
DumpableObject dobj
Definition pg_dump.h:397
TableInfo * parentTbl
Definition pg_dump.h:398
TableInfo * tdtable
Definition pg_dump.h:414
DumpableObject dobj
Definition pg_dump.h:413
char * filtercond
Definition pg_dump.h:415
bool * notnull_invalid
Definition pg_dump.h:376
char * attidentity
Definition pg_dump.h:361
char * reltablespace
Definition pg_dump.h:314
char ** notnull_constrs
Definition pg_dump.h:371
struct _relStatsInfo * stats
Definition pg_dump.h:381
int ncheck
Definition pg_dump.h:330
bool ispartition
Definition pg_dump.h:344
struct _indxInfo * indexes
Definition pg_dump.h:389
bool * attislocal
Definition pg_dump.h:365
DumpableObject dobj
Definition pg_dump.h:307
bool is_identity_sequence
Definition pg_dump.h:337
Oid reloftype
Definition pg_dump.h:332
int numParents
Definition pg_dump.h:347
bool interesting
Definition pg_dump.h:341
char * toast_reloptions
Definition pg_dump.h:317
struct _tableInfo ** parents
Definition pg_dump.h:348
DumpableAcl dacl
Definition pg_dump.h:308
bool relispopulated
Definition pg_dump.h:312
char * attgenerated
Definition pg_dump.h:362
int * attlen
Definition pg_dump.h:363
Oid reltype
Definition pg_dump.h:331
char ** attfdwoptions
Definition pg_dump.h:369
bool hasoids
Definition pg_dump.h:324
Oid toast_oid
Definition pg_dump.h:327
Oid foreign_server
Definition pg_dump.h:333
char ** notnull_comment
Definition pg_dump.h:375
bool hasrules
Definition pg_dump.h:319
struct _triggerInfo * triggers
Definition pg_dump.h:392
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
uint32 frozenxid
Definition pg_dump.h:325
char * typstorage
Definition pg_dump.h:359
int owning_col
Definition pg_dump.h:336
char * checkoption
Definition pg_dump.h:316
int numatts
Definition pg_dump.h:354
bool hastriggers
Definition pg_dump.h:320
const char * rolname
Definition pg_dump.h:309
struct _attrDefInfo ** attrdefs
Definition pg_dump.h:379
char ** attoptions
Definition pg_dump.h:366
char relreplident
Definition pg_dump.h:313
int numTriggers
Definition pg_dump.h:391
uint32 minmxid
Definition pg_dump.h:326
Oid * attcollation
Definition pg_dump.h:367
bool * notnull_noinh
Definition pg_dump.h:377
char * attstorage
Definition pg_dump.h:358
int toastpages
Definition pg_dump.h:339
Oid owning_tab
Definition pg_dump.h:335
struct _tableDataInfo * dataObj
Definition pg_dump.h:390
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
bool hascolumnACLs
Definition pg_dump.h:321
char ** atttypnames
Definition pg_dump.h:356
char ** attmissingval
Definition pg_dump.h:370
char relpersistence
Definition pg_dump.h:311
char ** attnames
Definition pg_dump.h:355
char relkind
Definition pg_dump.h:310
bool hasindex
Definition pg_dump.h:318
bool unsafe_partitions
Definition pg_dump.h:345
char * reloptions
Definition pg_dump.h:315
int numIndexes
Definition pg_dump.h:388
uint32 toast_frozenxid
Definition pg_dump.h:328
uint32 toast_minmxid
Definition pg_dump.h:329
char * attalign
Definition pg_dump.h:364
char * attcompression
Definition pg_dump.h:368
bool postponed_def
Definition pg_dump.h:343
bool rowsec
Definition pg_dump.h:322
Oid tmpllexize
Definition pg_dump.h:590
Oid tmplinit
Definition pg_dump.h:589
DumpableObject dobj
Definition pg_dump.h:588
DumpableObject dobj
Definition pg_dump.h:554
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
bool isMultirange
Definition pg_dump.h:221
struct _constraintInfo * domChecks
Definition pg_dump.h:229
DumpableAcl dacl
Definition pg_dump.h:206
DumpableObject dobj
Definition pg_dump.h:205
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
const char * name

◆ 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

◆ AttrDefInfo

◆ CastInfo

◆ CollInfo

◆ ConstraintInfo

◆ ConvInfo

◆ DefaultACLInfo

◆ DumpableAcl

◆ DumpableObject

◆ DumpableObjectWithAcl

◆ DumpComponents

Definition at line 107 of file pg_dump.h.

◆ EventTriggerInfo

◆ ExtensionInfo

◆ FdwInfo

◆ ForeignServerInfo

◆ FuncInfo

◆ IndexAttachInfo

◆ IndxInfo

◆ InhInfo

◆ LoInfo

◆ NamespaceInfo

◆ OpclassInfo

◆ OpfamilyInfo

◆ OprInfo

◆ PolicyInfo

◆ ProcLangInfo

◆ PublicationInfo

◆ PublicationRelInfo

◆ PublicationSchemaInfo

◆ RelStatsInfo

◆ RuleInfo

◆ ShellTypeInfo

◆ StatsExtInfo

◆ SubRelInfo

◆ SubscriptionInfo

◆ TableAttachInfo

◆ TableDataInfo

◆ TableInfo

◆ TransformInfo

◆ TriggerInfo

◆ TSConfigInfo

◆ TSDictInfo

◆ TSParserInfo

◆ TSTemplateInfo

◆ 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 */
@ 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 
)
extern

◆ AssignDumpId()

void AssignDumpId ( DumpableObject dobj)
extern

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 {
686 }
688 (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
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)
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 Assert(condition)
Definition c.h:873
#define OidIsValid(objectId)
Definition c.h:788
#define DUMP_COMPONENT_ALL
Definition pg_dump.h:117
Oid tableoid
Definition pg_backup.h:281
ExtensionInfo * ext
Definition common.c:63
DumpableObject * dobj
Definition common.c:62
DumpComponents dump
Definition pg_dump.h:153
DumpId dumpId
Definition pg_dump.h:151
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, fb(), 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(), getSubscriptionRelations(), getSubscriptions(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), and makeTableDataInfo().

◆ createDumpId()

◆ findAccessMethodByOid()

AccessMethodInfo * findAccessMethodByOid ( Oid  oid)
extern

Definition at line 954 of file common.c.

955{
956 CatalogId catId;
957 DumpableObject *dobj;
958
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, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by accessMethodNameCompare().

◆ findCollationByOid()

CollInfo * findCollationByOid ( Oid  oid)
extern

Definition at line 972 of file common.c.

973{
974 CatalogId catId;
975 DumpableObject *dobj;
976
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, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

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

◆ findExtensionByOid()

ExtensionInfo * findExtensionByOid ( Oid  oid)
extern

Definition at line 1008 of file common.c.

1009{
1010 CatalogId catId;
1011 DumpableObject *dobj;
1012
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, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getExtensionMembership().

◆ findFuncByOid()

FuncInfo * findFuncByOid ( Oid  oid)
extern

Definition at line 918 of file common.c.

919{
920 CatalogId catId;
921 DumpableObject *dobj;
922
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, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

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

◆ findNamespaceByOid()

NamespaceInfo * findNamespaceByOid ( Oid  oid)
extern

Definition at line 990 of file common.c.

991{
992 CatalogId catId;
993 DumpableObject *dobj;
994
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, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by findNamespace(), and getPublicationNamespaces().

◆ findObjectByCatalogId()

DumpableObject * findObjectByCatalogId ( CatalogId  catalogId)
extern

◆ findObjectByDumpId()

DumpableObject * findObjectByDumpId ( DumpId  dumpId)
extern

Definition at line 765 of file common.c.

766{
768 return NULL; /* out of range? */
769 return dumpIdMap[dumpId];
770}

References allocedDumpIds, dumpIdMap, and fb().

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

◆ findOprByOid()

OprInfo * findOprByOid ( Oid  oid)
extern

Definition at line 936 of file common.c.

937{
938 CatalogId catId;
939 DumpableObject *dobj;
940
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, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getFormattedOperatorName().

◆ findOwningExtension()

ExtensionInfo * findOwningExtension ( CatalogId  catalogId)
extern

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, _catalogIdMapEntry::ext, and fb().

Referenced by checkExtensionMembership().

◆ findPublicationByOid()

PublicationInfo * findPublicationByOid ( Oid  oid)
extern

Definition at line 1026 of file common.c.

1027{
1028 CatalogId catId;
1029 DumpableObject *dobj;
1030
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, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getPublicationNamespaces(), and getPublicationTables().

◆ findSubscriptionByOid()

SubscriptionInfo * findSubscriptionByOid ( Oid  oid)
extern

Definition at line 1044 of file common.c.

1045{
1046 CatalogId catId;
1047 DumpableObject *dobj;
1048
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, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getSubscriptionRelations().

◆ findTableByOid()

◆ findTypeByOid()

TypeInfo * findTypeByOid ( Oid  oid)
extern

◆ getAccessMethods()

void getAccessMethods ( Archive fout)
extern

Definition at line 6584 of file pg_dump.c.

6585{
6586 PGresult *res;
6587 int ntups;
6588 int i;
6589 PQExpBuffer query;
6591 int i_tableoid;
6592 int i_oid;
6593 int i_amname;
6594 int i_amhandler;
6595 int i_amtype;
6596
6597 query = createPQExpBuffer();
6598
6599 /*
6600 * Select all access methods from pg_am table. v9.6 introduced CREATE
6601 * ACCESS METHOD, so earlier versions usually have only built-in access
6602 * methods. v9.6 also changed the access method API, replacing dozens of
6603 * pg_am columns with amhandler. Even if a user created an access method
6604 * by "INSERT INTO pg_am", we have no way to translate pre-v9.6 pg_am
6605 * columns to a v9.6+ CREATE ACCESS METHOD. Hence, before v9.6, read
6606 * pg_am just to facilitate findAccessMethodByOid() providing the
6607 * OID-to-name mapping.
6608 */
6609 appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, ");
6610 if (fout->remoteVersion >= 90600)
6612 "amtype, "
6613 "amhandler::pg_catalog.regproc AS amhandler ");
6614 else
6616 "'i'::pg_catalog.\"char\" AS amtype, "
6617 "'-'::pg_catalog.regproc AS amhandler ");
6618 appendPQExpBufferStr(query, "FROM pg_am");
6619
6620 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6621
6622 ntups = PQntuples(res);
6623
6624 aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
6625
6626 i_tableoid = PQfnumber(res, "tableoid");
6627 i_oid = PQfnumber(res, "oid");
6628 i_amname = PQfnumber(res, "amname");
6629 i_amhandler = PQfnumber(res, "amhandler");
6630 i_amtype = PQfnumber(res, "amtype");
6631
6632 for (i = 0; i < ntups; i++)
6633 {
6634 aminfo[i].dobj.objType = DO_ACCESS_METHOD;
6635 aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6636 aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6637 AssignDumpId(&aminfo[i].dobj);
6638 aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
6639 aminfo[i].dobj.namespace = NULL;
6640 aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
6641 aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
6642
6643 /* Decide whether we want to dump it */
6645 }
6646
6647 PQclear(res);
6648
6649 destroyPQExpBuffer(query);
6650}
void AssignDumpId(DumpableObject *dobj)
Definition common.c:657
int PQfnumber(const PGresult *res, const char *field_name)
Definition fe-exec.c:3606
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
#define PQclear
#define PQntuples
@ PGRES_TUPLES_OK
Definition libpq-fe.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition pg_dump.c:2262
#define atooid(x)
PQExpBuffer createPQExpBuffer(void)
Definition pqexpbuffer.c:72
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_ACCESS_METHOD, ExecuteSqlQuery(), fb(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableAccessMethod().

Referenced by getSchemaData().

◆ getAggregates()

void getAggregates ( Archive fout)
extern

Definition at line 6786 of file pg_dump.c.

6787{
6788 DumpOptions *dopt = fout->dopt;
6789 PGresult *res;
6790 int ntups;
6791 int i;
6794 int i_tableoid;
6795 int i_oid;
6796 int i_aggname;
6797 int i_aggnamespace;
6798 int i_pronargs;
6799 int i_proargtypes;
6800 int i_proowner;
6801 int i_aggacl;
6802 int i_acldefault;
6803
6804 /*
6805 * Find all interesting aggregates. See comment in getFuncs() for the
6806 * rationale behind the filtering logic.
6807 */
6808 if (fout->remoteVersion >= 90600)
6809 {
6810 const char *agg_check;
6811
6812 agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
6813 : "p.proisagg");
6814
6815 appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
6816 "p.proname AS aggname, "
6817 "p.pronamespace AS aggnamespace, "
6818 "p.pronargs, p.proargtypes, "
6819 "p.proowner, "
6820 "p.proacl AS aggacl, "
6821 "acldefault('f', p.proowner) AS acldefault "
6822 "FROM pg_proc p "
6823 "LEFT JOIN pg_init_privs pip ON "
6824 "(p.oid = pip.objoid "
6825 "AND pip.classoid = 'pg_proc'::regclass "
6826 "AND pip.objsubid = 0) "
6827 "WHERE %s AND ("
6828 "p.pronamespace != "
6829 "(SELECT oid FROM pg_namespace "
6830 "WHERE nspname = 'pg_catalog') OR "
6831 "p.proacl IS DISTINCT FROM pip.initprivs",
6832 agg_check);
6833 if (dopt->binary_upgrade)
6835 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6836 "classid = 'pg_proc'::regclass AND "
6837 "objid = p.oid AND "
6838 "refclassid = 'pg_extension'::regclass AND "
6839 "deptype = 'e')");
6840 appendPQExpBufferChar(query, ')');
6841 }
6842 else
6843 {
6844 appendPQExpBufferStr(query, "SELECT tableoid, oid, proname AS aggname, "
6845 "pronamespace AS aggnamespace, "
6846 "pronargs, proargtypes, "
6847 "proowner, "
6848 "proacl AS aggacl, "
6849 "acldefault('f', proowner) AS acldefault "
6850 "FROM pg_proc p "
6851 "WHERE proisagg AND ("
6852 "pronamespace != "
6853 "(SELECT oid FROM pg_namespace "
6854 "WHERE nspname = 'pg_catalog')");
6855 if (dopt->binary_upgrade)
6857 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6858 "classid = 'pg_proc'::regclass AND "
6859 "objid = p.oid AND "
6860 "refclassid = 'pg_extension'::regclass AND "
6861 "deptype = 'e')");
6862 appendPQExpBufferChar(query, ')');
6863 }
6864
6865 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6866
6867 ntups = PQntuples(res);
6868
6869 agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
6870
6871 i_tableoid = PQfnumber(res, "tableoid");
6872 i_oid = PQfnumber(res, "oid");
6873 i_aggname = PQfnumber(res, "aggname");
6874 i_aggnamespace = PQfnumber(res, "aggnamespace");
6875 i_pronargs = PQfnumber(res, "pronargs");
6876 i_proargtypes = PQfnumber(res, "proargtypes");
6877 i_proowner = PQfnumber(res, "proowner");
6878 i_aggacl = PQfnumber(res, "aggacl");
6879 i_acldefault = PQfnumber(res, "acldefault");
6880
6881 for (i = 0; i < ntups; i++)
6882 {
6883 agginfo[i].aggfn.dobj.objType = DO_AGG;
6884 agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6885 agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6886 AssignDumpId(&agginfo[i].aggfn.dobj);
6887 agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
6888 agginfo[i].aggfn.dobj.namespace =
6890 agginfo[i].aggfn.dacl.acl = pg_strdup(PQgetvalue(res, i, i_aggacl));
6891 agginfo[i].aggfn.dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6892 agginfo[i].aggfn.dacl.privtype = 0;
6893 agginfo[i].aggfn.dacl.initprivs = NULL;
6894 agginfo[i].aggfn.rolname = getRoleName(PQgetvalue(res, i, i_proowner));
6895 agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
6896 agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
6897 agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
6898 if (agginfo[i].aggfn.nargs == 0)
6899 agginfo[i].aggfn.argtypes = NULL;
6900 else
6901 {
6902 agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
6904 agginfo[i].aggfn.argtypes,
6905 agginfo[i].aggfn.nargs);
6906 }
6907 agginfo[i].aggfn.postponed_def = false; /* might get set during sort */
6908
6909 /* Decide whether we want to dump it */
6910 selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
6911
6912 /* Mark whether aggregate has an ACL */
6913 if (!PQgetisnull(res, i, i_aggacl))
6914 agginfo[i].aggfn.dobj.components |= DUMP_COMPONENT_ACL;
6915 }
6916
6917 PQclear(res);
6918
6919 destroyPQExpBuffer(query);
6920}
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition common.c:1111
#define PQgetisnull
static const char * getRoleName(const char *roleoid_str)
Definition pg_dump.c:10697
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition pg_dump.c:2372
static NamespaceInfo * findNamespace(Oid nsoid)
Definition pg_dump.c:6119
#define DUMP_COMPONENT_ACL
Definition pg_dump.h:113
#define InvalidOid
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
int binary_upgrade
Definition pg_backup.h:175

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

Referenced by getSchemaData().

◆ getCasts()

void getCasts ( Archive fout)
extern

Definition at line 9057 of file pg_dump.c.

9058{
9059 PGresult *res;
9060 int ntups;
9061 int i;
9064 int i_tableoid;
9065 int i_oid;
9066 int i_castsource;
9067 int i_casttarget;
9068 int i_castfunc;
9069 int i_castcontext;
9070 int i_castmethod;
9071
9072 if (fout->remoteVersion >= 140000)
9073 {
9074 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9075 "castsource, casttarget, castfunc, castcontext, "
9076 "castmethod "
9077 "FROM pg_cast c "
9078 "WHERE NOT EXISTS ( "
9079 "SELECT 1 FROM pg_range r "
9080 "WHERE c.castsource = r.rngtypid "
9081 "AND c.casttarget = r.rngmultitypid "
9082 ") "
9083 "ORDER BY 3,4");
9084 }
9085 else
9086 {
9087 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9088 "castsource, casttarget, castfunc, castcontext, "
9089 "castmethod "
9090 "FROM pg_cast ORDER BY 3,4");
9091 }
9092
9093 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9094
9095 ntups = PQntuples(res);
9096
9097 castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
9098
9099 i_tableoid = PQfnumber(res, "tableoid");
9100 i_oid = PQfnumber(res, "oid");
9101 i_castsource = PQfnumber(res, "castsource");
9102 i_casttarget = PQfnumber(res, "casttarget");
9103 i_castfunc = PQfnumber(res, "castfunc");
9104 i_castcontext = PQfnumber(res, "castcontext");
9105 i_castmethod = PQfnumber(res, "castmethod");
9106
9107 for (i = 0; i < ntups; i++)
9108 {
9112
9114 castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9115 castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9116 AssignDumpId(&castinfo[i].dobj);
9117 castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
9118 castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
9119 castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
9120 castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
9121 castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
9122
9123 /*
9124 * Try to name cast as concatenation of typnames. This is only used
9125 * for purposes of sorting. If we fail to find either type, the name
9126 * will be an empty string.
9127 */
9129 sTypeInfo = findTypeByOid(castinfo[i].castsource);
9130 tTypeInfo = findTypeByOid(castinfo[i].casttarget);
9131 if (sTypeInfo && tTypeInfo)
9132 appendPQExpBuffer(&namebuf, "%s %s",
9133 sTypeInfo->dobj.name, tTypeInfo->dobj.name);
9134 castinfo[i].dobj.name = namebuf.data;
9135
9136 /* Decide whether we want to dump it */
9138 }
9139
9140 PQclear(res);
9141
9142 destroyPQExpBuffer(query);
9143}
TypeInfo * findTypeByOid(Oid oid)
Definition common.c:899
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition pg_dump.c:2204
void initPQExpBuffer(PQExpBuffer str)
Definition pqexpbuffer.c:90

References appendPQExpBuffer(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_CAST, _typeInfo::dobj, ExecuteSqlQuery(), fb(), findTypeByOid(), i, initPQExpBuffer(), _dumpableObject::objType, pg_malloc(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableCast().

Referenced by getSchemaData().

◆ getCollations()

void getCollations ( Archive fout)
extern

Definition at line 6456 of file pg_dump.c.

6457{
6458 PGresult *res;
6459 int ntups;
6460 int i;
6461 PQExpBuffer query;
6463 int i_tableoid;
6464 int i_oid;
6465 int i_collname;
6466 int i_collnamespace;
6467 int i_collowner;
6468 int i_collencoding;
6469
6470 query = createPQExpBuffer();
6471
6472 /*
6473 * find all collations, including builtin collations; we filter out
6474 * system-defined collations at dump-out time.
6475 */
6476
6477 appendPQExpBufferStr(query, "SELECT tableoid, oid, collname, "
6478 "collnamespace, "
6479 "collowner, "
6480 "collencoding "
6481 "FROM pg_collation");
6482
6483 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6484
6485 ntups = PQntuples(res);
6486
6487 collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
6488
6489 i_tableoid = PQfnumber(res, "tableoid");
6490 i_oid = PQfnumber(res, "oid");
6491 i_collname = PQfnumber(res, "collname");
6492 i_collnamespace = PQfnumber(res, "collnamespace");
6493 i_collowner = PQfnumber(res, "collowner");
6494 i_collencoding = PQfnumber(res, "collencoding");
6495
6496 for (i = 0; i < ntups; i++)
6497 {
6498 collinfo[i].dobj.objType = DO_COLLATION;
6499 collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6500 collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6501 AssignDumpId(&collinfo[i].dobj);
6502 collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
6503 collinfo[i].dobj.namespace =
6505 collinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_collowner));
6506 collinfo[i].collencoding = atoi(PQgetvalue(res, i, i_collencoding));
6507
6508 /* Decide whether we want to dump it */
6510 }
6511
6512 PQclear(res);
6513
6514 destroyPQExpBuffer(query);
6515}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_COLLATION, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getConstraints()

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

Definition at line 8308 of file pg_dump.c.

8309{
8312 PGresult *res;
8313 int ntups;
8314 int curtblindx;
8317 int i_contableoid,
8318 i_conoid,
8319 i_conrelid,
8320 i_conname,
8322 i_conindid,
8323 i_condef;
8324
8325 /*
8326 * We want to perform just one query against pg_constraint. However, we
8327 * mustn't try to select every row of the catalog and then sort it out on
8328 * the client side, because some of the server-side functions we need
8329 * would be unsafe to apply to tables we don't have lock on. Hence, we
8330 * build an array of the OIDs of tables we care about (and now have lock
8331 * on!), and use a WHERE clause to constrain which rows are selected.
8332 */
8334 for (int i = 0; i < numTables; i++)
8335 {
8336 TableInfo *tinfo = &tblinfo[i];
8337
8338 if (!(tinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
8339 continue;
8340
8341 /* OK, we need info for this table */
8342 if (tbloids->len > 1) /* do we have more than the '{'? */
8344 appendPQExpBuffer(tbloids, "%u", tinfo->dobj.catId.oid);
8345 }
8347
8349 "SELECT c.tableoid, c.oid, "
8350 "conrelid, conname, confrelid, ");
8351 if (fout->remoteVersion >= 110000)
8352 appendPQExpBufferStr(query, "conindid, ");
8353 else
8354 appendPQExpBufferStr(query, "0 AS conindid, ");
8355 appendPQExpBuffer(query,
8356 "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
8357 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8358 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
8359 "WHERE contype = 'f' ",
8360 tbloids->data);
8361 if (fout->remoteVersion >= 110000)
8363 "AND conparentid = 0 ");
8365 "ORDER BY conrelid, conname");
8366
8367 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8368
8369 ntups = PQntuples(res);
8370
8371 i_contableoid = PQfnumber(res, "tableoid");
8372 i_conoid = PQfnumber(res, "oid");
8373 i_conrelid = PQfnumber(res, "conrelid");
8374 i_conname = PQfnumber(res, "conname");
8375 i_confrelid = PQfnumber(res, "confrelid");
8376 i_conindid = PQfnumber(res, "conindid");
8377 i_condef = PQfnumber(res, "condef");
8378
8379 constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
8380
8381 curtblindx = -1;
8382 for (int j = 0; j < ntups; j++)
8383 {
8384 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
8386
8387 /*
8388 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8389 * order.
8390 */
8391 if (tbinfo == NULL || tbinfo->dobj.catId.oid != conrelid)
8392 {
8393 while (++curtblindx < numTables)
8394 {
8395 tbinfo = &tblinfo[curtblindx];
8396 if (tbinfo->dobj.catId.oid == conrelid)
8397 break;
8398 }
8399 if (curtblindx >= numTables)
8400 pg_fatal("unrecognized table OID %u", conrelid);
8401 }
8402
8403 constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
8404 constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
8405 constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
8406 AssignDumpId(&constrinfo[j].dobj);
8407 constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
8408 constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
8409 constrinfo[j].contable = tbinfo;
8410 constrinfo[j].condomain = NULL;
8411 constrinfo[j].contype = 'f';
8412 constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
8413 constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
8414 constrinfo[j].conindex = 0;
8415 constrinfo[j].condeferrable = false;
8416 constrinfo[j].condeferred = false;
8417 constrinfo[j].conislocal = true;
8418 constrinfo[j].separate = true;
8419
8420 /*
8421 * Restoring an FK that points to a partitioned table requires that
8422 * all partition indexes have been attached beforehand. Ensure that
8423 * happens by making the constraint depend on each index partition
8424 * attach object.
8425 */
8426 reftable = findTableByOid(constrinfo[j].confrelid);
8427 if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
8428 {
8429 Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
8430
8431 if (indexOid != InvalidOid)
8432 {
8433 for (int k = 0; k < reftable->numIndexes; k++)
8434 {
8436
8437 /* not our index? */
8438 if (reftable->indexes[k].dobj.catId.oid != indexOid)
8439 continue;
8440
8441 refidx = &reftable->indexes[k];
8443 break;
8444 }
8445 }
8446 }
8447 }
8448
8449 PQclear(res);
8450
8451 destroyPQExpBuffer(query);
8453}
TableInfo * findTableByOid(Oid oid)
Definition common.c:863
static const gbtree_vinfo tinfo
Definition btree_bit.c:109
int j
Definition isn.c:78
#define pg_fatal(...)
static void addConstrChildIdxDeps(DumpableObject *dobj, const IndxInfo *refidx)
Definition pg_dump.c:8467

References addConstrChildIdxDeps(), appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FK_CONSTRAINT, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), fb(), findTableByOid(), i, InvalidOid, j, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and tinfo.

Referenced by getSchemaData().

◆ getConversions()

void getConversions ( Archive fout)
extern

Definition at line 6522 of file pg_dump.c.

6523{
6524 PGresult *res;
6525 int ntups;
6526 int i;
6527 PQExpBuffer query;
6529 int i_tableoid;
6530 int i_oid;
6531 int i_conname;
6532 int i_connamespace;
6533 int i_conowner;
6534
6535 query = createPQExpBuffer();
6536
6537 /*
6538 * find all conversions, including builtin conversions; we filter out
6539 * system-defined conversions at dump-out time.
6540 */
6541
6542 appendPQExpBufferStr(query, "SELECT tableoid, oid, conname, "
6543 "connamespace, "
6544 "conowner "
6545 "FROM pg_conversion");
6546
6547 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6548
6549 ntups = PQntuples(res);
6550
6551 convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
6552
6553 i_tableoid = PQfnumber(res, "tableoid");
6554 i_oid = PQfnumber(res, "oid");
6555 i_conname = PQfnumber(res, "conname");
6556 i_connamespace = PQfnumber(res, "connamespace");
6557 i_conowner = PQfnumber(res, "conowner");
6558
6559 for (i = 0; i < ntups; i++)
6560 {
6561 convinfo[i].dobj.objType = DO_CONVERSION;
6562 convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6563 convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6564 AssignDumpId(&convinfo[i].dobj);
6565 convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
6566 convinfo[i].dobj.namespace =
6568 convinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_conowner));
6569
6570 /* Decide whether we want to dump it */
6572 }
6573
6574 PQclear(res);
6575
6576 destroyPQExpBuffer(query);
6577}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_CONVERSION, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getDefaultACLs()

void getDefaultACLs ( Archive fout)
extern

Definition at line 10600 of file pg_dump.c.

10601{
10602 DumpOptions *dopt = fout->dopt;
10604 PQExpBuffer query;
10605 PGresult *res;
10606 int i_oid;
10607 int i_tableoid;
10608 int i_defaclrole;
10610 int i_defaclobjtype;
10611 int i_defaclacl;
10612 int i_acldefault;
10613 int i,
10614 ntups;
10615
10616 query = createPQExpBuffer();
10617
10618 /*
10619 * Global entries (with defaclnamespace=0) replace the hard-wired default
10620 * ACL for their object type. We should dump them as deltas from the
10621 * default ACL, since that will be used as a starting point for
10622 * interpreting the ALTER DEFAULT PRIVILEGES commands. On the other hand,
10623 * non-global entries can only add privileges not revoke them. We must
10624 * dump those as-is (i.e., as deltas from an empty ACL).
10625 *
10626 * We can use defaclobjtype as the object type for acldefault(), except
10627 * for the case of 'S' (DEFACLOBJ_SEQUENCE) which must be converted to
10628 * 's'.
10629 */
10631 "SELECT oid, tableoid, "
10632 "defaclrole, "
10633 "defaclnamespace, "
10634 "defaclobjtype, "
10635 "defaclacl, "
10636 "CASE WHEN defaclnamespace = 0 THEN "
10637 "acldefault(CASE WHEN defaclobjtype = 'S' "
10638 "THEN 's'::\"char\" ELSE defaclobjtype END, "
10639 "defaclrole) ELSE '{}' END AS acldefault "
10640 "FROM pg_default_acl");
10641
10642 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10643
10644 ntups = PQntuples(res);
10645
10646 daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
10647
10648 i_oid = PQfnumber(res, "oid");
10649 i_tableoid = PQfnumber(res, "tableoid");
10650 i_defaclrole = PQfnumber(res, "defaclrole");
10651 i_defaclnamespace = PQfnumber(res, "defaclnamespace");
10652 i_defaclobjtype = PQfnumber(res, "defaclobjtype");
10653 i_defaclacl = PQfnumber(res, "defaclacl");
10654 i_acldefault = PQfnumber(res, "acldefault");
10655
10656 for (i = 0; i < ntups; i++)
10657 {
10659
10660 daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
10661 daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10662 daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10663 AssignDumpId(&daclinfo[i].dobj);
10664 /* cheesy ... is it worth coming up with a better object name? */
10665 daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
10666
10667 if (nspid != InvalidOid)
10668 daclinfo[i].dobj.namespace = findNamespace(nspid);
10669 else
10670 daclinfo[i].dobj.namespace = NULL;
10671
10672 daclinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
10673 daclinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10674 daclinfo[i].dacl.privtype = 0;
10675 daclinfo[i].dacl.initprivs = NULL;
10676 daclinfo[i].defaclrole = getRoleName(PQgetvalue(res, i, i_defaclrole));
10677 daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
10678
10679 /* Default ACLs are ACLs, of course */
10680 daclinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10681
10682 /* Decide whether we want to dump it */
10684 }
10685
10686 PQclear(res);
10687
10688 destroyPQExpBuffer(query);
10689}
int nspid
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition pg_dump.c:2182

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_DEFAULT_ACL, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, InvalidOid, nspid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableDefaultACL().

Referenced by getSchemaData().

◆ getDumpableObjects()

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

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, fb(), i, j, and pg_malloc_array.

Referenced by getTableDataFKConstraints(), and main().

◆ getEventTriggers()

void getEventTriggers ( Archive fout)
extern

Definition at line 8895 of file pg_dump.c.

8896{
8897 int i;
8898 PQExpBuffer query;
8899 PGresult *res;
8901 int i_tableoid,
8902 i_oid,
8903 i_evtname,
8904 i_evtevent,
8905 i_evtowner,
8906 i_evttags,
8907 i_evtfname,
8909 int ntups;
8910
8911 /* Before 9.3, there are no event triggers */
8912 if (fout->remoteVersion < 90300)
8913 return;
8914
8915 query = createPQExpBuffer();
8916
8918 "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8919 "evtevent, evtowner, "
8920 "array_to_string(array("
8921 "select quote_literal(x) "
8922 " from unnest(evttags) as t(x)), ', ') as evttags, "
8923 "e.evtfoid::regproc as evtfname "
8924 "FROM pg_event_trigger e "
8925 "ORDER BY e.oid");
8926
8927 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8928
8929 ntups = PQntuples(res);
8930
8931 evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
8932
8933 i_tableoid = PQfnumber(res, "tableoid");
8934 i_oid = PQfnumber(res, "oid");
8935 i_evtname = PQfnumber(res, "evtname");
8936 i_evtevent = PQfnumber(res, "evtevent");
8937 i_evtowner = PQfnumber(res, "evtowner");
8938 i_evttags = PQfnumber(res, "evttags");
8939 i_evtfname = PQfnumber(res, "evtfname");
8940 i_evtenabled = PQfnumber(res, "evtenabled");
8941
8942 for (i = 0; i < ntups; i++)
8943 {
8944 evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
8945 evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8946 evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8947 AssignDumpId(&evtinfo[i].dobj);
8948 evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
8949 evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
8950 evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
8951 evtinfo[i].evtowner = getRoleName(PQgetvalue(res, i, i_evtowner));
8952 evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
8953 evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
8954 evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
8955
8956 /* Decide whether we want to dump it */
8958 }
8959
8960 PQclear(res);
8961
8962 destroyPQExpBuffer(query);
8963}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_EVENT_TRIGGER, ExecuteSqlQuery(), fb(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getExtendedStatistics()

void getExtendedStatistics ( Archive fout)
extern

Definition at line 8226 of file pg_dump.c.

8227{
8228 PQExpBuffer query;
8229 PGresult *res;
8231 int ntups;
8232 int i_tableoid;
8233 int i_oid;
8234 int i_stxname;
8235 int i_stxnamespace;
8236 int i_stxowner;
8237 int i_stxrelid;
8238 int i_stattarget;
8239 int i;
8240
8241 /* Extended statistics were new in v10 */
8242 if (fout->remoteVersion < 100000)
8243 return;
8244
8245 query = createPQExpBuffer();
8246
8247 if (fout->remoteVersion < 130000)
8248 appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
8249 "stxnamespace, stxowner, stxrelid, NULL AS stxstattarget "
8250 "FROM pg_catalog.pg_statistic_ext");
8251 else
8252 appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
8253 "stxnamespace, stxowner, stxrelid, stxstattarget "
8254 "FROM pg_catalog.pg_statistic_ext");
8255
8256 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8257
8258 ntups = PQntuples(res);
8259
8260 i_tableoid = PQfnumber(res, "tableoid");
8261 i_oid = PQfnumber(res, "oid");
8262 i_stxname = PQfnumber(res, "stxname");
8263 i_stxnamespace = PQfnumber(res, "stxnamespace");
8264 i_stxowner = PQfnumber(res, "stxowner");
8265 i_stxrelid = PQfnumber(res, "stxrelid");
8266 i_stattarget = PQfnumber(res, "stxstattarget");
8267
8268 statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
8269
8270 for (i = 0; i < ntups; i++)
8271 {
8272 statsextinfo[i].dobj.objType = DO_STATSEXT;
8273 statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8274 statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8275 AssignDumpId(&statsextinfo[i].dobj);
8276 statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
8277 statsextinfo[i].dobj.namespace =
8279 statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
8280 statsextinfo[i].stattable =
8282 if (PQgetisnull(res, i, i_stattarget))
8283 statsextinfo[i].stattarget = -1;
8284 else
8285 statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
8286
8287 /* Decide whether we want to dump it */
8289
8290 if (fout->dopt->dumpStatistics)
8291 statsextinfo[i].dobj.components |= DUMP_COMPONENT_STATISTICS;
8292 }
8293
8294 PQclear(res);
8295 destroyPQExpBuffer(query);
8296}
static void selectDumpableStatisticsObject(StatsExtInfo *sobj, Archive *fout)
Definition pg_dump.c:2354

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_STATSEXT, DUMP_COMPONENT_STATISTICS, ExecuteSqlQuery(), fb(), findNamespace(), findTableByOid(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableStatisticsObject().

Referenced by getSchemaData().

◆ getExtensionMembership()

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

Definition at line 19945 of file pg_dump.c.

19947{
19948 PQExpBuffer query;
19949 PGresult *res;
19950 int ntups,
19951 i;
19952 int i_classid,
19953 i_objid,
19954 i_refobjid;
19955 ExtensionInfo *ext;
19956
19957 /* Nothing to do if no extensions */
19958 if (numExtensions == 0)
19959 return;
19960
19961 query = createPQExpBuffer();
19962
19963 /* refclassid constraint is redundant but may speed the search */
19964 appendPQExpBufferStr(query, "SELECT "
19965 "classid, objid, refobjid "
19966 "FROM pg_depend "
19967 "WHERE refclassid = 'pg_extension'::regclass "
19968 "AND deptype = 'e' "
19969 "ORDER BY 3");
19970
19971 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
19972
19973 ntups = PQntuples(res);
19974
19975 i_classid = PQfnumber(res, "classid");
19976 i_objid = PQfnumber(res, "objid");
19977 i_refobjid = PQfnumber(res, "refobjid");
19978
19979 /*
19980 * Since we ordered the SELECT by referenced ID, we can expect that
19981 * multiple entries for the same extension will appear together; this
19982 * saves on searches.
19983 */
19984 ext = NULL;
19985
19986 for (i = 0; i < ntups; i++)
19987 {
19988 CatalogId objId;
19989 Oid extId;
19990
19991 objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
19992 objId.oid = atooid(PQgetvalue(res, i, i_objid));
19994
19995 if (ext == NULL ||
19996 ext->dobj.catId.oid != extId)
19998
19999 if (ext == NULL)
20000 {
20001 /* shouldn't happen */
20002 pg_log_warning("could not find referenced extension %u", extId);
20003 continue;
20004 }
20005
20006 recordExtensionMembership(objId, ext);
20007 }
20008
20009 PQclear(res);
20010
20011 destroyPQExpBuffer(query);
20012}
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

References appendPQExpBufferStr(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _extensionInfo::dobj, ExecuteSqlQuery(), fb(), 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 
)
extern

Definition at line 6137 of file pg_dump.c.

6138{
6139 DumpOptions *dopt = fout->dopt;
6140 PGresult *res;
6141 int ntups;
6142 int i;
6143 PQExpBuffer query;
6145 int i_tableoid;
6146 int i_oid;
6147 int i_extname;
6148 int i_nspname;
6149 int i_extrelocatable;
6150 int i_extversion;
6151 int i_extconfig;
6152 int i_extcondition;
6153
6154 query = createPQExpBuffer();
6155
6156 appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
6157 "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
6158 "FROM pg_extension x "
6159 "JOIN pg_namespace n ON n.oid = x.extnamespace");
6160
6161 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6162
6163 ntups = PQntuples(res);
6164 if (ntups == 0)
6165 goto cleanup;
6166
6167 extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
6168
6169 i_tableoid = PQfnumber(res, "tableoid");
6170 i_oid = PQfnumber(res, "oid");
6171 i_extname = PQfnumber(res, "extname");
6172 i_nspname = PQfnumber(res, "nspname");
6173 i_extrelocatable = PQfnumber(res, "extrelocatable");
6174 i_extversion = PQfnumber(res, "extversion");
6175 i_extconfig = PQfnumber(res, "extconfig");
6176 i_extcondition = PQfnumber(res, "extcondition");
6177
6178 for (i = 0; i < ntups; i++)
6179 {
6180 extinfo[i].dobj.objType = DO_EXTENSION;
6181 extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6182 extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6183 AssignDumpId(&extinfo[i].dobj);
6184 extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
6185 extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
6186 extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
6187 extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
6188 extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
6189 extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
6190
6191 /* Decide whether we want to dump it */
6193 }
6194
6195cleanup:
6196 PQclear(res);
6197 destroyPQExpBuffer(query);
6198
6199 *numExtensions = ntups;
6200
6201 return extinfo;
6202}
static void cleanup(void)
Definition bootstrap.c:717
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition pg_dump.c:2297

References appendPQExpBufferStr(), AssignDumpId(), atooid, cleanup(), createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_EXTENSION, ExecuteSqlQuery(), fb(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableExtension().

Referenced by getSchemaData().

◆ getForeignDataWrappers()

void getForeignDataWrappers ( Archive fout)
extern

Definition at line 10428 of file pg_dump.c.

10429{
10430 PGresult *res;
10431 int ntups;
10432 int i;
10433 PQExpBuffer query;
10435 int i_tableoid;
10436 int i_oid;
10437 int i_fdwname;
10438 int i_fdwowner;
10439 int i_fdwhandler;
10440 int i_fdwvalidator;
10441 int i_fdwacl;
10442 int i_acldefault;
10443 int i_fdwoptions;
10444
10445 query = createPQExpBuffer();
10446
10447 appendPQExpBufferStr(query, "SELECT tableoid, oid, fdwname, "
10448 "fdwowner, "
10449 "fdwhandler::pg_catalog.regproc, "
10450 "fdwvalidator::pg_catalog.regproc, "
10451 "fdwacl, "
10452 "acldefault('F', fdwowner) AS acldefault, "
10453 "array_to_string(ARRAY("
10454 "SELECT quote_ident(option_name) || ' ' || "
10455 "quote_literal(option_value) "
10456 "FROM pg_options_to_table(fdwoptions) "
10457 "ORDER BY option_name"
10458 "), E',\n ') AS fdwoptions "
10459 "FROM pg_foreign_data_wrapper");
10460
10461 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10462
10463 ntups = PQntuples(res);
10464
10465 fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
10466
10467 i_tableoid = PQfnumber(res, "tableoid");
10468 i_oid = PQfnumber(res, "oid");
10469 i_fdwname = PQfnumber(res, "fdwname");
10470 i_fdwowner = PQfnumber(res, "fdwowner");
10471 i_fdwhandler = PQfnumber(res, "fdwhandler");
10472 i_fdwvalidator = PQfnumber(res, "fdwvalidator");
10473 i_fdwacl = PQfnumber(res, "fdwacl");
10474 i_acldefault = PQfnumber(res, "acldefault");
10475 i_fdwoptions = PQfnumber(res, "fdwoptions");
10476
10477 for (i = 0; i < ntups; i++)
10478 {
10479 fdwinfo[i].dobj.objType = DO_FDW;
10480 fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10481 fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10482 AssignDumpId(&fdwinfo[i].dobj);
10483 fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
10484 fdwinfo[i].dobj.namespace = NULL;
10485 fdwinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
10486 fdwinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10487 fdwinfo[i].dacl.privtype = 0;
10488 fdwinfo[i].dacl.initprivs = NULL;
10489 fdwinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_fdwowner));
10490 fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
10491 fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
10492 fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
10493
10494 /* Decide whether we want to dump it */
10496
10497 /* Mark whether FDW has an ACL */
10498 if (!PQgetisnull(res, i, i_fdwacl))
10499 fdwinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10500 }
10501
10502 PQclear(res);
10503
10504 destroyPQExpBuffer(query);
10505}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FDW, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), fb(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getForeignServers()

void getForeignServers ( Archive fout)
extern

Definition at line 10512 of file pg_dump.c.

10513{
10514 PGresult *res;
10515 int ntups;
10516 int i;
10517 PQExpBuffer query;
10519 int i_tableoid;
10520 int i_oid;
10521 int i_srvname;
10522 int i_srvowner;
10523 int i_srvfdw;
10524 int i_srvtype;
10525 int i_srvversion;
10526 int i_srvacl;
10527 int i_acldefault;
10528 int i_srvoptions;
10529
10530 query = createPQExpBuffer();
10531
10532 appendPQExpBufferStr(query, "SELECT tableoid, oid, srvname, "
10533 "srvowner, "
10534 "srvfdw, srvtype, srvversion, srvacl, "
10535 "acldefault('S', srvowner) AS acldefault, "
10536 "array_to_string(ARRAY("
10537 "SELECT quote_ident(option_name) || ' ' || "
10538 "quote_literal(option_value) "
10539 "FROM pg_options_to_table(srvoptions) "
10540 "ORDER BY option_name"
10541 "), E',\n ') AS srvoptions "
10542 "FROM pg_foreign_server");
10543
10544 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10545
10546 ntups = PQntuples(res);
10547
10549
10550 i_tableoid = PQfnumber(res, "tableoid");
10551 i_oid = PQfnumber(res, "oid");
10552 i_srvname = PQfnumber(res, "srvname");
10553 i_srvowner = PQfnumber(res, "srvowner");
10554 i_srvfdw = PQfnumber(res, "srvfdw");
10555 i_srvtype = PQfnumber(res, "srvtype");
10556 i_srvversion = PQfnumber(res, "srvversion");
10557 i_srvacl = PQfnumber(res, "srvacl");
10558 i_acldefault = PQfnumber(res, "acldefault");
10559 i_srvoptions = PQfnumber(res, "srvoptions");
10560
10561 for (i = 0; i < ntups; i++)
10562 {
10563 srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
10564 srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10565 srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10566 AssignDumpId(&srvinfo[i].dobj);
10567 srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
10568 srvinfo[i].dobj.namespace = NULL;
10569 srvinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_srvacl));
10570 srvinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10571 srvinfo[i].dacl.privtype = 0;
10572 srvinfo[i].dacl.initprivs = NULL;
10573 srvinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_srvowner));
10574 srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
10575 srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
10576 srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
10577 srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
10578
10579 /* Decide whether we want to dump it */
10581
10582 /* Servers have user mappings */
10583 srvinfo[i].dobj.components |= DUMP_COMPONENT_USERMAP;
10584
10585 /* Mark whether server has an ACL */
10586 if (!PQgetisnull(res, i, i_srvacl))
10587 srvinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10588 }
10589
10590 PQclear(res);
10591
10592 destroyPQExpBuffer(query);
10593}
#define DUMP_COMPONENT_USERMAP
Definition pg_dump.h:115

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FOREIGN_SERVER, DUMP_COMPONENT_ACL, DUMP_COMPONENT_USERMAP, ExecuteSqlQuery(), fb(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getFuncs()

void getFuncs ( Archive fout)
extern

Definition at line 6927 of file pg_dump.c.

6928{
6929 DumpOptions *dopt = fout->dopt;
6930 PGresult *res;
6931 int ntups;
6932 int i;
6934 FuncInfo *finfo;
6935 int i_tableoid;
6936 int i_oid;
6937 int i_proname;
6938 int i_pronamespace;
6939 int i_proowner;
6940 int i_prolang;
6941 int i_pronargs;
6942 int i_proargtypes;
6943 int i_prorettype;
6944 int i_proacl;
6945 int i_acldefault;
6946
6947 /*
6948 * Find all interesting functions. This is a bit complicated:
6949 *
6950 * 1. Always exclude aggregates; those are handled elsewhere.
6951 *
6952 * 2. Always exclude functions that are internally dependent on something
6953 * else, since presumably those will be created as a result of creating
6954 * the something else. This currently acts only to suppress constructor
6955 * functions for range types. Note this is OK only because the
6956 * constructors don't have any dependencies the range type doesn't have;
6957 * otherwise we might not get creation ordering correct.
6958 *
6959 * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
6960 * they're members of extensions and we are in binary-upgrade mode then
6961 * include them, since we want to dump extension members individually in
6962 * that mode. Also, if they are used by casts or transforms then we need
6963 * to gather the information about them, though they won't be dumped if
6964 * they are built-in. Also, in 9.6 and up, include functions in
6965 * pg_catalog if they have an ACL different from what's shown in
6966 * pg_init_privs (so we have to join to pg_init_privs; annoying).
6967 */
6968 if (fout->remoteVersion >= 90600)
6969 {
6970 const char *not_agg_check;
6971
6972 not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
6973 : "NOT p.proisagg");
6974
6975 appendPQExpBuffer(query,
6976 "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6977 "p.pronargs, p.proargtypes, p.prorettype, "
6978 "p.proacl, "
6979 "acldefault('f', p.proowner) AS acldefault, "
6980 "p.pronamespace, "
6981 "p.proowner "
6982 "FROM pg_proc p "
6983 "LEFT JOIN pg_init_privs pip ON "
6984 "(p.oid = pip.objoid "
6985 "AND pip.classoid = 'pg_proc'::regclass "
6986 "AND pip.objsubid = 0) "
6987 "WHERE %s"
6988 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6989 "WHERE classid = 'pg_proc'::regclass AND "
6990 "objid = p.oid AND deptype = 'i')"
6991 "\n AND ("
6992 "\n pronamespace != "
6993 "(SELECT oid FROM pg_namespace "
6994 "WHERE nspname = 'pg_catalog')"
6995 "\n OR EXISTS (SELECT 1 FROM pg_cast"
6996 "\n WHERE pg_cast.oid > %u "
6997 "\n AND p.oid = pg_cast.castfunc)"
6998 "\n OR EXISTS (SELECT 1 FROM pg_transform"
6999 "\n WHERE pg_transform.oid > %u AND "
7000 "\n (p.oid = pg_transform.trffromsql"
7001 "\n OR p.oid = pg_transform.trftosql))",
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')");
7013 "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
7014 appendPQExpBufferChar(query, ')');
7015 }
7016 else
7017 {
7018 appendPQExpBuffer(query,
7019 "SELECT tableoid, oid, proname, prolang, "
7020 "pronargs, proargtypes, prorettype, proacl, "
7021 "acldefault('f', proowner) AS acldefault, "
7022 "pronamespace, "
7023 "proowner "
7024 "FROM pg_proc p "
7025 "WHERE NOT proisagg"
7026 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
7027 "WHERE classid = 'pg_proc'::regclass AND "
7028 "objid = p.oid AND deptype = 'i')"
7029 "\n AND ("
7030 "\n pronamespace != "
7031 "(SELECT oid FROM pg_namespace "
7032 "WHERE nspname = 'pg_catalog')"
7033 "\n OR EXISTS (SELECT 1 FROM pg_cast"
7034 "\n WHERE pg_cast.oid > '%u'::oid"
7035 "\n AND p.oid = pg_cast.castfunc)",
7037
7038 if (fout->remoteVersion >= 90500)
7039 appendPQExpBuffer(query,
7040 "\n OR EXISTS (SELECT 1 FROM pg_transform"
7041 "\n WHERE pg_transform.oid > '%u'::oid"
7042 "\n AND (p.oid = pg_transform.trffromsql"
7043 "\n OR p.oid = pg_transform.trftosql))",
7045
7046 if (dopt->binary_upgrade)
7048 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
7049 "classid = 'pg_proc'::regclass AND "
7050 "objid = p.oid AND "
7051 "refclassid = 'pg_extension'::regclass AND "
7052 "deptype = 'e')");
7053 appendPQExpBufferChar(query, ')');
7054 }
7055
7056 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7057
7058 ntups = PQntuples(res);
7059
7060 finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
7061
7062 i_tableoid = PQfnumber(res, "tableoid");
7063 i_oid = PQfnumber(res, "oid");
7064 i_proname = PQfnumber(res, "proname");
7065 i_pronamespace = PQfnumber(res, "pronamespace");
7066 i_proowner = PQfnumber(res, "proowner");
7067 i_prolang = PQfnumber(res, "prolang");
7068 i_pronargs = PQfnumber(res, "pronargs");
7069 i_proargtypes = PQfnumber(res, "proargtypes");
7070 i_prorettype = PQfnumber(res, "prorettype");
7071 i_proacl = PQfnumber(res, "proacl");
7072 i_acldefault = PQfnumber(res, "acldefault");
7073
7074 for (i = 0; i < ntups; i++)
7075 {
7076 finfo[i].dobj.objType = DO_FUNC;
7077 finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7078 finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7079 AssignDumpId(&finfo[i].dobj);
7080 finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
7081 finfo[i].dobj.namespace =
7083 finfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_proacl));
7085 finfo[i].dacl.privtype = 0;
7086 finfo[i].dacl.initprivs = NULL;
7087 finfo[i].rolname = getRoleName(PQgetvalue(res, i, i_proowner));
7088 finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
7089 finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
7090 finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
7091 if (finfo[i].nargs == 0)
7092 finfo[i].argtypes = NULL;
7093 else
7094 {
7095 finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
7097 finfo[i].argtypes, finfo[i].nargs);
7098 }
7099 finfo[i].postponed_def = false; /* might get set during sort */
7100
7101 /* Decide whether we want to dump it */
7102 selectDumpableObject(&(finfo[i].dobj), fout);
7103
7104 /* Mark whether function has an ACL */
7105 if (!PQgetisnull(res, i, i_proacl))
7107 }
7108
7109 PQclear(res);
7110
7111 destroyPQExpBuffer(query);
7112}
void * pg_malloc0(size_t size)
Definition fe_memutils.c:53
static Oid g_last_builtin_oid
Definition pg_dump.c:154

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

Referenced by getSchemaData().

◆ getIndexes()

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

Definition at line 7857 of file pg_dump.c.

7858{
7861 PGresult *res;
7862 int ntups;
7863 int curtblindx;
7865 int i_tableoid,
7866 i_oid,
7867 i_indrelid,
7869 i_relpages,
7874 i_indexdef,
7876 i_indnatts,
7877 i_indkey,
7881 i_contype,
7882 i_conname,
7887 i_conoid,
7888 i_condef,
7894
7895 /*
7896 * We want to perform just one query against pg_index. However, we
7897 * mustn't try to select every row of the catalog and then sort it out on
7898 * the client side, because some of the server-side functions we need
7899 * would be unsafe to apply to tables we don't have lock on. Hence, we
7900 * build an array of the OIDs of tables we care about (and now have lock
7901 * on!), and use a WHERE clause to constrain which rows are selected.
7902 */
7904 for (int i = 0; i < numTables; i++)
7905 {
7906 TableInfo *tbinfo = &tblinfo[i];
7907
7908 if (!tbinfo->hasindex)
7909 continue;
7910
7911 /*
7912 * We can ignore indexes of uninteresting tables.
7913 */
7914 if (!tbinfo->interesting)
7915 continue;
7916
7917 /* OK, we need info for this table */
7918 if (tbloids->len > 1) /* do we have more than the '{'? */
7920 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
7921 }
7923
7925 "SELECT t.tableoid, t.oid, i.indrelid, "
7926 "t.relname AS indexname, "
7927 "t.relpages, t.reltuples, t.relallvisible, ");
7928
7929 if (fout->remoteVersion >= 180000)
7930 appendPQExpBufferStr(query, "t.relallfrozen, ");
7931 else
7932 appendPQExpBufferStr(query, "0 AS relallfrozen, ");
7933
7935 "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7936 "i.indkey, i.indisclustered, "
7937 "c.contype, c.conname, "
7938 "c.condeferrable, c.condeferred, "
7939 "c.tableoid AS contableoid, "
7940 "c.oid AS conoid, "
7941 "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7942 "CASE WHEN i.indexprs IS NOT NULL THEN "
7943 "(SELECT pg_catalog.array_agg(attname ORDER BY attnum)"
7944 " FROM pg_catalog.pg_attribute "
7945 " WHERE attrelid = i.indexrelid) "
7946 "ELSE NULL END AS indattnames, "
7947 "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7948 "t.reloptions AS indreloptions, ");
7949
7950
7951 if (fout->remoteVersion >= 90400)
7953 "i.indisreplident, ");
7954 else
7956 "false AS indisreplident, ");
7957
7958 if (fout->remoteVersion >= 110000)
7960 "inh.inhparent AS parentidx, "
7961 "i.indnkeyatts AS indnkeyatts, "
7962 "i.indnatts AS indnatts, "
7963 "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
7964 " FROM pg_catalog.pg_attribute "
7965 " WHERE attrelid = i.indexrelid AND "
7966 " attstattarget >= 0) AS indstatcols, "
7967 "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
7968 " FROM pg_catalog.pg_attribute "
7969 " WHERE attrelid = i.indexrelid AND "
7970 " attstattarget >= 0) AS indstatvals, ");
7971 else
7973 "0 AS parentidx, "
7974 "i.indnatts AS indnkeyatts, "
7975 "i.indnatts AS indnatts, "
7976 "'' AS indstatcols, "
7977 "'' AS indstatvals, ");
7978
7979 if (fout->remoteVersion >= 150000)
7981 "i.indnullsnotdistinct, ");
7982 else
7984 "false AS indnullsnotdistinct, ");
7985
7986 if (fout->remoteVersion >= 180000)
7988 "c.conperiod ");
7989 else
7991 "NULL AS conperiod ");
7992
7993 /*
7994 * The point of the messy-looking outer join is to find a constraint that
7995 * is related by an internal dependency link to the index. If we find one,
7996 * create a CONSTRAINT entry linked to the INDEX entry. We assume an
7997 * index won't have more than one internal dependency.
7998 *
7999 * Note: the check on conrelid is redundant, but useful because that
8000 * column is indexed while conindid is not.
8001 */
8002 if (fout->remoteVersion >= 110000)
8003 {
8004 appendPQExpBuffer(query,
8005 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8006 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
8007 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
8008 "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
8009 "LEFT JOIN pg_catalog.pg_constraint c "
8010 "ON (i.indrelid = c.conrelid AND "
8011 "i.indexrelid = c.conindid AND "
8012 "c.contype IN ('p','u','x')) "
8013 "LEFT JOIN pg_catalog.pg_inherits inh "
8014 "ON (inh.inhrelid = indexrelid) "
8015 "WHERE (i.indisvalid OR t2.relkind = 'p') "
8016 "AND i.indisready "
8017 "ORDER BY i.indrelid, indexname",
8018 tbloids->data);
8019 }
8020 else
8021 {
8022 /*
8023 * the test on indisready is necessary in 9.2, and harmless in
8024 * earlier/later versions
8025 */
8026 appendPQExpBuffer(query,
8027 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8028 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
8029 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
8030 "LEFT JOIN pg_catalog.pg_constraint c "
8031 "ON (i.indrelid = c.conrelid AND "
8032 "i.indexrelid = c.conindid AND "
8033 "c.contype IN ('p','u','x')) "
8034 "WHERE i.indisvalid AND i.indisready "
8035 "ORDER BY i.indrelid, indexname",
8036 tbloids->data);
8037 }
8038
8039 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8040
8041 ntups = PQntuples(res);
8042
8043 i_tableoid = PQfnumber(res, "tableoid");
8044 i_oid = PQfnumber(res, "oid");
8045 i_indrelid = PQfnumber(res, "indrelid");
8046 i_indexname = PQfnumber(res, "indexname");
8047 i_relpages = PQfnumber(res, "relpages");
8048 i_reltuples = PQfnumber(res, "reltuples");
8049 i_relallvisible = PQfnumber(res, "relallvisible");
8050 i_relallfrozen = PQfnumber(res, "relallfrozen");
8051 i_parentidx = PQfnumber(res, "parentidx");
8052 i_indexdef = PQfnumber(res, "indexdef");
8053 i_indnkeyatts = PQfnumber(res, "indnkeyatts");
8054 i_indnatts = PQfnumber(res, "indnatts");
8055 i_indkey = PQfnumber(res, "indkey");
8056 i_indisclustered = PQfnumber(res, "indisclustered");
8057 i_indisreplident = PQfnumber(res, "indisreplident");
8058 i_indnullsnotdistinct = PQfnumber(res, "indnullsnotdistinct");
8059 i_contype = PQfnumber(res, "contype");
8060 i_conname = PQfnumber(res, "conname");
8061 i_condeferrable = PQfnumber(res, "condeferrable");
8062 i_condeferred = PQfnumber(res, "condeferred");
8063 i_conperiod = PQfnumber(res, "conperiod");
8064 i_contableoid = PQfnumber(res, "contableoid");
8065 i_conoid = PQfnumber(res, "conoid");
8066 i_condef = PQfnumber(res, "condef");
8067 i_indattnames = PQfnumber(res, "indattnames");
8068 i_tablespace = PQfnumber(res, "tablespace");
8069 i_indreloptions = PQfnumber(res, "indreloptions");
8070 i_indstatcols = PQfnumber(res, "indstatcols");
8071 i_indstatvals = PQfnumber(res, "indstatvals");
8072
8073 indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
8074
8075 /*
8076 * Outer loop iterates once per table, not once per row. Incrementing of
8077 * j is handled by the inner loop.
8078 */
8079 curtblindx = -1;
8080 for (int j = 0; j < ntups;)
8081 {
8084 char **indAttNames = NULL;
8085 int nindAttNames = 0;
8086 int numinds;
8087
8088 /* Count rows for this table */
8089 for (numinds = 1; numinds < ntups - j; numinds++)
8090 if (atooid(PQgetvalue(res, j + numinds, i_indrelid)) != indrelid)
8091 break;
8092
8093 /*
8094 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8095 * order.
8096 */
8097 while (++curtblindx < numTables)
8098 {
8099 tbinfo = &tblinfo[curtblindx];
8100 if (tbinfo->dobj.catId.oid == indrelid)
8101 break;
8102 }
8103 if (curtblindx >= numTables)
8104 pg_fatal("unrecognized table OID %u", indrelid);
8105 /* cross-check that we only got requested tables */
8106 if (!tbinfo->hasindex ||
8107 !tbinfo->interesting)
8108 pg_fatal("unexpected index data for table \"%s\"",
8109 tbinfo->dobj.name);
8110
8111 /* Save data for this table */
8112 tbinfo->indexes = indxinfo + j;
8113 tbinfo->numIndexes = numinds;
8114
8115 for (int c = 0; c < numinds; c++, j++)
8116 {
8117 char contype;
8118 char indexkind;
8120 int32 relpages = atoi(PQgetvalue(res, j, i_relpages));
8121 int32 relallvisible = atoi(PQgetvalue(res, j, i_relallvisible));
8122 int32 relallfrozen = atoi(PQgetvalue(res, j, i_relallfrozen));
8123
8124 indxinfo[j].dobj.objType = DO_INDEX;
8125 indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
8126 indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
8127 AssignDumpId(&indxinfo[j].dobj);
8128 indxinfo[j].dobj.dump = tbinfo->dobj.dump;
8129 indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
8130 indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
8131 indxinfo[j].indextable = tbinfo;
8132 indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
8133 indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
8134 indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
8135 indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
8136 indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
8137 indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
8138 indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
8139 indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
8141 indxinfo[j].indkeys, indxinfo[j].indnattrs);
8142 indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
8143 indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
8144 indxinfo[j].indnullsnotdistinct = (PQgetvalue(res, j, i_indnullsnotdistinct)[0] == 't');
8145 indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
8146 indxinfo[j].partattaches = (SimplePtrList)
8147 {
8148 NULL, NULL
8149 };
8150
8151 if (indxinfo[j].parentidx == 0)
8153 else
8155
8156 if (!PQgetisnull(res, j, i_indattnames))
8157 {
8159 &indAttNames, &nindAttNames))
8160 pg_fatal("could not parse %s array", "indattnames");
8161 }
8162
8163 relstats = getRelationStatistics(fout, &indxinfo[j].dobj, relpages,
8164 PQgetvalue(res, j, i_reltuples),
8165 relallvisible, relallfrozen, indexkind,
8166 indAttNames, nindAttNames);
8167
8168 contype = *(PQgetvalue(res, j, i_contype));
8169 if (contype == 'p' || contype == 'u' || contype == 'x')
8170 {
8171 /*
8172 * If we found a constraint matching the index, create an
8173 * entry for it.
8174 */
8176
8179 constrinfo->dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
8180 constrinfo->dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
8181 AssignDumpId(&constrinfo->dobj);
8182 constrinfo->dobj.dump = tbinfo->dobj.dump;
8183 constrinfo->dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
8184 constrinfo->dobj.namespace = tbinfo->dobj.namespace;
8185 constrinfo->contable = tbinfo;
8186 constrinfo->condomain = NULL;
8187 constrinfo->contype = contype;
8188 if (contype == 'x')
8189 constrinfo->condef = pg_strdup(PQgetvalue(res, j, i_condef));
8190 else
8191 constrinfo->condef = NULL;
8192 constrinfo->confrelid = InvalidOid;
8193 constrinfo->conindex = indxinfo[j].dobj.dumpId;
8194 constrinfo->condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
8195 constrinfo->condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
8196 constrinfo->conperiod = *(PQgetvalue(res, j, i_conperiod)) == 't';
8197 constrinfo->conislocal = true;
8198 constrinfo->separate = true;
8199
8200 indxinfo[j].indexconstraint = constrinfo->dobj.dumpId;
8201 if (relstats != NULL)
8202 addObjectDependency(&relstats->dobj, constrinfo->dobj.dumpId);
8203 }
8204 else
8205 {
8206 /* Plain secondary index */
8207 indxinfo[j].indexconstraint = 0;
8208 }
8209 }
8210 }
8211
8212 PQclear(res);
8213
8214 destroyPQExpBuffer(query);
8216}
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:818
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:7122
char * c
bool parsePGArray(const char *atext, char ***itemarray, int *nitems)

References addObjectDependency(), appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_CONSTRAINT, DO_INDEX, _constraintInfo::dobj, ExecuteSqlQuery(), fb(), getRelationStatistics(), i, InvalidOid, j, _dumpableObject::objType, parseOidArray(), parsePGArray(), pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, and PQntuples.

Referenced by getSchemaData().

◆ getInherits()

InhInfo * getInherits ( Archive fout,
int numInherits 
)
extern

Definition at line 7741 of file pg_dump.c.

7742{
7743 PGresult *res;
7744 int ntups;
7745 int i;
7748
7749 int i_inhrelid;
7750 int i_inhparent;
7751
7752 /* find all the inheritance information */
7753 appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
7754
7755 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7756
7757 ntups = PQntuples(res);
7758
7759 *numInherits = ntups;
7760
7761 inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
7762
7763 i_inhrelid = PQfnumber(res, "inhrelid");
7764 i_inhparent = PQfnumber(res, "inhparent");
7765
7766 for (i = 0; i < ntups; i++)
7767 {
7768 inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
7769 inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
7770 }
7771
7772 PQclear(res);
7773
7774 destroyPQExpBuffer(query);
7775
7776 return inhinfo;
7777}

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

Referenced by getSchemaData().

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )
extern

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

Definition at line 6005 of file pg_dump.c.

6006{
6007 PGresult *res;
6008 int ntups;
6009 int i;
6010 PQExpBuffer query;
6012 int i_tableoid;
6013 int i_oid;
6014 int i_nspname;
6015 int i_nspowner;
6016 int i_nspacl;
6017 int i_acldefault;
6018
6019 query = createPQExpBuffer();
6020
6021 /*
6022 * we fetch all namespaces including system ones, so that every object we
6023 * read in can be linked to a containing namespace.
6024 */
6025 appendPQExpBufferStr(query, "SELECT n.tableoid, n.oid, n.nspname, "
6026 "n.nspowner, "
6027 "n.nspacl, "
6028 "acldefault('n', n.nspowner) AS acldefault "
6029 "FROM pg_namespace n");
6030
6031 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6032
6033 ntups = PQntuples(res);
6034
6035 nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
6036
6037 i_tableoid = PQfnumber(res, "tableoid");
6038 i_oid = PQfnumber(res, "oid");
6039 i_nspname = PQfnumber(res, "nspname");
6040 i_nspowner = PQfnumber(res, "nspowner");
6041 i_nspacl = PQfnumber(res, "nspacl");
6042 i_acldefault = PQfnumber(res, "acldefault");
6043
6044 for (i = 0; i < ntups; i++)
6045 {
6046 const char *nspowner;
6047
6048 nsinfo[i].dobj.objType = DO_NAMESPACE;
6049 nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6050 nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6051 AssignDumpId(&nsinfo[i].dobj);
6052 nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
6053 nsinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_nspacl));
6054 nsinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6055 nsinfo[i].dacl.privtype = 0;
6056 nsinfo[i].dacl.initprivs = NULL;
6057 nspowner = PQgetvalue(res, i, i_nspowner);
6058 nsinfo[i].nspowner = atooid(nspowner);
6059 nsinfo[i].rolname = getRoleName(nspowner);
6060
6061 /* Decide whether to dump this namespace */
6063
6064 /* Mark whether namespace has an ACL */
6065 if (!PQgetisnull(res, i, i_nspacl))
6066 nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6067
6068 /*
6069 * We ignore any pg_init_privs.initprivs entry for the public schema
6070 * and assume a predetermined default, for several reasons. First,
6071 * dropping and recreating the schema removes its pg_init_privs entry,
6072 * but an empty destination database starts with this ACL nonetheless.
6073 * Second, we support dump/reload of public schema ownership changes.
6074 * ALTER SCHEMA OWNER filters nspacl through aclnewowner(), but
6075 * initprivs continues to reflect the initial owner. Hence,
6076 * synthesize the value that nspacl will have after the restore's
6077 * ALTER SCHEMA OWNER. Third, this makes the destination database
6078 * match the source's ACL, even if the latter was an initdb-default
6079 * ACL, which changed in v15. An upgrade pulls in changes to most
6080 * system object ACLs that the DBA had not customized. We've made the
6081 * public schema depart from that, because changing its ACL so easily
6082 * breaks applications.
6083 */
6084 if (strcmp(nsinfo[i].dobj.name, "public") == 0)
6085 {
6088
6089 /* Standard ACL as of v15 is {owner=UC/owner,=U/owner} */
6100
6101 nsinfo[i].dacl.privtype = 'i';
6102 nsinfo[i].dacl.initprivs = pstrdup(aclarray->data);
6103 nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6104
6107 }
6108 }
6109
6110 PQclear(res);
6111 destroyPQExpBuffer(query);
6112}
void quoteAclUserName(PQExpBuffer output, const char *input)
Definition dumputils.c:585
char * pstrdup(const char *in)
Definition mcxt.c:1781
NameData rolname
Definition pg_authid.h:34
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition pg_dump.c:2012
void resetPQExpBuffer(PQExpBuffer str)
void appendPGArray(PQExpBuffer buffer, const char *value)

References appendPGArray(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_NAMESPACE, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), fb(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, pstrdup(), quoteAclUserName(), resetPQExpBuffer(), rolname, and selectDumpableNamespace().

Referenced by getSchemaData().

◆ getOpclasses()

void getOpclasses ( Archive fout)
extern

Definition at line 6658 of file pg_dump.c.

6659{
6660 PGresult *res;
6661 int ntups;
6662 int i;
6665 int i_tableoid;
6666 int i_oid;
6667 int i_opcmethod;
6668 int i_opcname;
6669 int i_opcnamespace;
6670 int i_opcowner;
6671
6672 /*
6673 * find all opclasses, including builtin opclasses; we filter out
6674 * system-defined opclasses at dump-out time.
6675 */
6676
6677 appendPQExpBufferStr(query, "SELECT tableoid, oid, opcmethod, opcname, "
6678 "opcnamespace, "
6679 "opcowner "
6680 "FROM pg_opclass");
6681
6682 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6683
6684 ntups = PQntuples(res);
6685
6686 opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
6687
6688 i_tableoid = PQfnumber(res, "tableoid");
6689 i_oid = PQfnumber(res, "oid");
6690 i_opcmethod = PQfnumber(res, "opcmethod");
6691 i_opcname = PQfnumber(res, "opcname");
6692 i_opcnamespace = PQfnumber(res, "opcnamespace");
6693 i_opcowner = PQfnumber(res, "opcowner");
6694
6695 for (i = 0; i < ntups; i++)
6696 {
6697 opcinfo[i].dobj.objType = DO_OPCLASS;
6698 opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6699 opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6700 AssignDumpId(&opcinfo[i].dobj);
6701 opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
6702 opcinfo[i].dobj.namespace =
6704 opcinfo[i].opcmethod = atooid(PQgetvalue(res, i, i_opcmethod));
6705 opcinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opcowner));
6706
6707 /* Decide whether we want to dump it */
6709 }
6710
6711 PQclear(res);
6712
6713 destroyPQExpBuffer(query);
6714}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPCLASS, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getOperators()

void getOperators ( Archive fout)
extern

Definition at line 6380 of file pg_dump.c.

6381{
6382 PGresult *res;
6383 int ntups;
6384 int i;
6387 int i_tableoid;
6388 int i_oid;
6389 int i_oprname;
6390 int i_oprnamespace;
6391 int i_oprowner;
6392 int i_oprkind;
6393 int i_oprleft;
6394 int i_oprright;
6395 int i_oprcode;
6396
6397 /*
6398 * find all operators, including builtin operators; we filter out
6399 * system-defined operators at dump-out time.
6400 */
6401
6402 appendPQExpBufferStr(query, "SELECT tableoid, oid, oprname, "
6403 "oprnamespace, "
6404 "oprowner, "
6405 "oprkind, "
6406 "oprleft, "
6407 "oprright, "
6408 "oprcode::oid AS oprcode "
6409 "FROM pg_operator");
6410
6411 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6412
6413 ntups = PQntuples(res);
6414
6415 oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
6416
6417 i_tableoid = PQfnumber(res, "tableoid");
6418 i_oid = PQfnumber(res, "oid");
6419 i_oprname = PQfnumber(res, "oprname");
6420 i_oprnamespace = PQfnumber(res, "oprnamespace");
6421 i_oprowner = PQfnumber(res, "oprowner");
6422 i_oprkind = PQfnumber(res, "oprkind");
6423 i_oprleft = PQfnumber(res, "oprleft");
6424 i_oprright = PQfnumber(res, "oprright");
6425 i_oprcode = PQfnumber(res, "oprcode");
6426
6427 for (i = 0; i < ntups; i++)
6428 {
6429 oprinfo[i].dobj.objType = DO_OPERATOR;
6430 oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6431 oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6432 AssignDumpId(&oprinfo[i].dobj);
6433 oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
6434 oprinfo[i].dobj.namespace =
6436 oprinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_oprowner));
6437 oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
6438 oprinfo[i].oprleft = atooid(PQgetvalue(res, i, i_oprleft));
6439 oprinfo[i].oprright = atooid(PQgetvalue(res, i, i_oprright));
6440 oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
6441
6442 /* Decide whether we want to dump it */
6444 }
6445
6446 PQclear(res);
6447
6448 destroyPQExpBuffer(query);
6449}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPERATOR, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getOpfamilies()

void getOpfamilies ( Archive fout)
extern

Definition at line 6721 of file pg_dump.c.

6722{
6723 PGresult *res;
6724 int ntups;
6725 int i;
6726 PQExpBuffer query;
6728 int i_tableoid;
6729 int i_oid;
6730 int i_opfmethod;
6731 int i_opfname;
6732 int i_opfnamespace;
6733 int i_opfowner;
6734
6735 query = createPQExpBuffer();
6736
6737 /*
6738 * find all opfamilies, including builtin opfamilies; we filter out
6739 * system-defined opfamilies at dump-out time.
6740 */
6741
6742 appendPQExpBufferStr(query, "SELECT tableoid, oid, opfmethod, opfname, "
6743 "opfnamespace, "
6744 "opfowner "
6745 "FROM pg_opfamily");
6746
6747 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6748
6749 ntups = PQntuples(res);
6750
6751 opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
6752
6753 i_tableoid = PQfnumber(res, "tableoid");
6754 i_oid = PQfnumber(res, "oid");
6755 i_opfname = PQfnumber(res, "opfname");
6756 i_opfmethod = PQfnumber(res, "opfmethod");
6757 i_opfnamespace = PQfnumber(res, "opfnamespace");
6758 i_opfowner = PQfnumber(res, "opfowner");
6759
6760 for (i = 0; i < ntups; i++)
6761 {
6762 opfinfo[i].dobj.objType = DO_OPFAMILY;
6763 opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6764 opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6765 AssignDumpId(&opfinfo[i].dobj);
6766 opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
6767 opfinfo[i].dobj.namespace =
6769 opfinfo[i].opfmethod = atooid(PQgetvalue(res, i, i_opfmethod));
6770 opfinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opfowner));
6771
6772 /* Decide whether we want to dump it */
6774 }
6775
6776 PQclear(res);
6777
6778 destroyPQExpBuffer(query);
6779}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPFAMILY, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getOwnedSeqs()

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

Definition at line 7676 of file pg_dump.c.

7677{
7678 int i;
7679
7680 /*
7681 * Force sequences that are "owned" by table columns to be dumped whenever
7682 * their owning table is being dumped.
7683 */
7684 for (i = 0; i < numTables; i++)
7685 {
7686 TableInfo *seqinfo = &tblinfo[i];
7687 TableInfo *owning_tab;
7688
7689 if (!OidIsValid(seqinfo->owning_tab))
7690 continue; /* not an owned sequence */
7691
7692 owning_tab = findTableByOid(seqinfo->owning_tab);
7693 if (owning_tab == NULL)
7694 pg_fatal("failed sanity check, parent table with OID %u of sequence with OID %u not found",
7695 seqinfo->owning_tab, seqinfo->dobj.catId.oid);
7696
7697 /*
7698 * For an identity sequence, dump exactly the same components for the
7699 * sequence as for the owning table. This is important because we
7700 * treat the identity sequence as an integral part of the table. For
7701 * example, there is not any DDL command that allows creation of such
7702 * a sequence independently of the table.
7703 *
7704 * For other owned sequences such as serial sequences, we need to dump
7705 * the components that are being dumped for the table and any
7706 * components that the sequence is explicitly marked with.
7707 *
7708 * We can't simply use the set of components which are being dumped
7709 * for the table as the table might be in an extension (and only the
7710 * non-extension components, eg: ACLs if changed, security labels, and
7711 * policies, are being dumped) while the sequence is not (and
7712 * therefore the definition and other components should also be
7713 * dumped).
7714 *
7715 * If the sequence is part of the extension then it should be properly
7716 * marked by checkExtensionMembership() and this will be a no-op as
7717 * the table will be equivalently marked.
7718 */
7719 if (seqinfo->is_identity_sequence)
7720 seqinfo->dobj.dump = owning_tab->dobj.dump;
7721 else
7722 seqinfo->dobj.dump |= owning_tab->dobj.dump;
7723
7724 /* Make sure that necessary data is available if we're dumping it */
7725 if (seqinfo->dobj.dump != DUMP_COMPONENT_NONE)
7726 {
7727 seqinfo->interesting = true;
7728 owning_tab->interesting = true;
7729 }
7730 }
7731}
#define DUMP_COMPONENT_NONE
Definition pg_dump.h:108

References _tableInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_NONE, fb(), findTableByOid(), i, _tableInfo::interesting, OidIsValid, and pg_fatal.

Referenced by getSchemaData().

◆ getPartitioningInfo()

void getPartitioningInfo ( Archive fout)
extern

Definition at line 7797 of file pg_dump.c.

7798{
7799 PQExpBuffer query;
7800 PGresult *res;
7801 int ntups;
7802
7803 /* hash partitioning didn't exist before v11 */
7804 if (fout->remoteVersion < 110000)
7805 return;
7806 /* needn't bother if not dumping data */
7807 if (!fout->dopt->dumpData)
7808 return;
7809
7810 query = createPQExpBuffer();
7811
7812 /*
7813 * Unsafe partitioning schemes are exactly those for which hash enum_ops
7814 * appears among the partition opclasses. We needn't check partstrat.
7815 *
7816 * Note that this query may well retrieve info about tables we aren't
7817 * going to dump and hence have no lock on. That's okay since we need not
7818 * invoke any unsafe server-side functions.
7819 */
7821 "SELECT partrelid FROM pg_partitioned_table WHERE\n"
7822 "(SELECT c.oid FROM pg_opclass c JOIN pg_am a "
7823 "ON c.opcmethod = a.oid\n"
7824 "WHERE opcname = 'enum_ops' "
7825 "AND opcnamespace = 'pg_catalog'::regnamespace "
7826 "AND amname = 'hash') = ANY(partclass)");
7827
7828 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7829
7830 ntups = PQntuples(res);
7831
7832 for (int i = 0; i < ntups; i++)
7833 {
7834 Oid tabrelid = atooid(PQgetvalue(res, i, 0));
7836
7838 if (tbinfo == NULL)
7839 pg_fatal("failed sanity check, table OID %u appearing in pg_partitioned_table not found",
7840 tabrelid);
7841 tbinfo->unsafe_partitions = true;
7842 }
7843
7844 PQclear(res);
7845
7846 destroyPQExpBuffer(query);
7847}

References appendPQExpBufferStr(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), ExecuteSqlQuery(), fb(), findTableByOid(), i, pg_fatal, PGRES_TUPLES_OK, PQclear, PQgetvalue, and PQntuples.

Referenced by getSchemaData().

◆ getPolicies()

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

Definition at line 4261 of file pg_dump.c.

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

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_POLICY, DUMP_COMPONENT_POLICY, ExecuteSqlQuery(), fb(), findTableByOid(), i, j, _dumpOptions::no_policies, pg_log_info, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and printfPQExpBuffer().

Referenced by getSchemaData().

◆ getProcLangs()

void getProcLangs ( Archive fout)
extern

Definition at line 8973 of file pg_dump.c.

8974{
8975 PGresult *res;
8976 int ntups;
8977 int i;
8980 int i_tableoid;
8981 int i_oid;
8982 int i_lanname;
8983 int i_lanpltrusted;
8984 int i_lanplcallfoid;
8985 int i_laninline;
8986 int i_lanvalidator;
8987 int i_lanacl;
8988 int i_acldefault;
8989 int i_lanowner;
8990
8991 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8992 "lanname, lanpltrusted, lanplcallfoid, "
8993 "laninline, lanvalidator, "
8994 "lanacl, "
8995 "acldefault('l', lanowner) AS acldefault, "
8996 "lanowner "
8997 "FROM pg_language "
8998 "WHERE lanispl "
8999 "ORDER BY oid");
9000
9001 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9002
9003 ntups = PQntuples(res);
9004
9005 planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo));
9006
9007 i_tableoid = PQfnumber(res, "tableoid");
9008 i_oid = PQfnumber(res, "oid");
9009 i_lanname = PQfnumber(res, "lanname");
9010 i_lanpltrusted = PQfnumber(res, "lanpltrusted");
9011 i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
9012 i_laninline = PQfnumber(res, "laninline");
9013 i_lanvalidator = PQfnumber(res, "lanvalidator");
9014 i_lanacl = PQfnumber(res, "lanacl");
9015 i_acldefault = PQfnumber(res, "acldefault");
9016 i_lanowner = PQfnumber(res, "lanowner");
9017
9018 for (i = 0; i < ntups; i++)
9019 {
9020 planginfo[i].dobj.objType = DO_PROCLANG;
9021 planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9022 planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9023 AssignDumpId(&planginfo[i].dobj);
9024
9025 planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
9026 planginfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_lanacl));
9027 planginfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9028 planginfo[i].dacl.privtype = 0;
9029 planginfo[i].dacl.initprivs = NULL;
9030 planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
9031 planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
9032 planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
9033 planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
9034 planginfo[i].lanowner = getRoleName(PQgetvalue(res, i, i_lanowner));
9035
9036 /* Decide whether we want to dump it */
9038
9039 /* Mark whether language has an ACL */
9040 if (!PQgetisnull(res, i, i_lanacl))
9041 planginfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9042 }
9043
9044 PQclear(res);
9045
9046 destroyPQExpBuffer(query);
9047}
static void selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
Definition pg_dump.c:2229

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PROCLANG, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), fb(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableProcLang().

Referenced by getSchemaData().

◆ getPublicationNamespaces()

void getPublicationNamespaces ( Archive fout)
extern

Definition at line 4770 of file pg_dump.c.

4771{
4772 PQExpBuffer query;
4773 PGresult *res;
4775 DumpOptions *dopt = fout->dopt;
4776 int i_tableoid;
4777 int i_oid;
4778 int i_pnpubid;
4779 int i_pnnspid;
4780 int i,
4781 j,
4782 ntups;
4783
4784 if (dopt->no_publications || fout->remoteVersion < 150000)
4785 return;
4786
4787 query = createPQExpBuffer();
4788
4789 /* Collect all publication membership info. */
4791 "SELECT tableoid, oid, pnpubid, pnnspid "
4792 "FROM pg_catalog.pg_publication_namespace");
4793 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4794
4795 ntups = PQntuples(res);
4796
4797 i_tableoid = PQfnumber(res, "tableoid");
4798 i_oid = PQfnumber(res, "oid");
4799 i_pnpubid = PQfnumber(res, "pnpubid");
4800 i_pnnspid = PQfnumber(res, "pnnspid");
4801
4802 /* this allocation may be more than we need */
4803 pubsinfo = pg_malloc(ntups * sizeof(PublicationSchemaInfo));
4804 j = 0;
4805
4806 for (i = 0; i < ntups; i++)
4807 {
4812
4813 /*
4814 * Ignore any entries for which we aren't interested in either the
4815 * publication or the rel.
4816 */
4818 if (pubinfo == NULL)
4819 continue;
4821 if (nspinfo == NULL)
4822 continue;
4823
4824 /* OK, make a DumpableObject for this relationship */
4826 pubsinfo[j].dobj.catId.tableoid =
4827 atooid(PQgetvalue(res, i, i_tableoid));
4828 pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4829 AssignDumpId(&pubsinfo[j].dobj);
4830 pubsinfo[j].dobj.namespace = nspinfo->dobj.namespace;
4831 pubsinfo[j].dobj.name = nspinfo->dobj.name;
4832 pubsinfo[j].publication = pubinfo;
4833 pubsinfo[j].pubschema = nspinfo;
4834
4835 /* Decide whether we want to dump it */
4837
4838 j++;
4839 }
4840
4841 PQclear(res);
4842 destroyPQExpBuffer(query);
4843}
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:2336
int no_publications
Definition pg_backup.h:189

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PUBLICATION_TABLE_IN_SCHEMA, ExecuteSqlQuery(), fb(), findNamespaceByOid(), findPublicationByOid(), i, j, _dumpOptions::no_publications, pg_malloc(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpablePublicationObject().

Referenced by getSchemaData().

◆ getPublications()

void getPublications ( Archive fout)
extern

Definition at line 4551 of file pg_dump.c.

4552{
4553 DumpOptions *dopt = fout->dopt;
4554 PQExpBuffer query;
4555 PGresult *res;
4557 int i_tableoid;
4558 int i_oid;
4559 int i_pubname;
4560 int i_pubowner;
4561 int i_puballtables;
4563 int i_pubinsert;
4564 int i_pubupdate;
4565 int i_pubdelete;
4566 int i_pubtruncate;
4567 int i_pubviaroot;
4568 int i_pubgencols;
4569 int i,
4570 ntups;
4571
4572 if (dopt->no_publications || fout->remoteVersion < 100000)
4573 return;
4574
4575 query = createPQExpBuffer();
4576
4577 /* Get the publications. */
4578 appendPQExpBufferStr(query, "SELECT p.tableoid, p.oid, p.pubname, "
4579 "p.pubowner, p.puballtables, p.pubinsert, "
4580 "p.pubupdate, p.pubdelete, ");
4581
4582 if (fout->remoteVersion >= 110000)
4583 appendPQExpBufferStr(query, "p.pubtruncate, ");
4584 else
4585 appendPQExpBufferStr(query, "false AS pubtruncate, ");
4586
4587 if (fout->remoteVersion >= 130000)
4588 appendPQExpBufferStr(query, "p.pubviaroot, ");
4589 else
4590 appendPQExpBufferStr(query, "false AS pubviaroot, ");
4591
4592 if (fout->remoteVersion >= 180000)
4593 appendPQExpBufferStr(query, "p.pubgencols, ");
4594 else
4595 appendPQExpBuffer(query, "'%c' AS pubgencols, ", PUBLISH_GENCOLS_NONE);
4596
4597 if (fout->remoteVersion >= 190000)
4598 appendPQExpBufferStr(query, "p.puballsequences ");
4599 else
4600 appendPQExpBufferStr(query, "false AS puballsequences ");
4601
4602 appendPQExpBufferStr(query, "FROM pg_publication p");
4603
4604 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4605
4606 ntups = PQntuples(res);
4607
4608 if (ntups == 0)
4609 goto cleanup;
4610
4611 i_tableoid = PQfnumber(res, "tableoid");
4612 i_oid = PQfnumber(res, "oid");
4613 i_pubname = PQfnumber(res, "pubname");
4614 i_pubowner = PQfnumber(res, "pubowner");
4615 i_puballtables = PQfnumber(res, "puballtables");
4616 i_puballsequences = PQfnumber(res, "puballsequences");
4617 i_pubinsert = PQfnumber(res, "pubinsert");
4618 i_pubupdate = PQfnumber(res, "pubupdate");
4619 i_pubdelete = PQfnumber(res, "pubdelete");
4620 i_pubtruncate = PQfnumber(res, "pubtruncate");
4621 i_pubviaroot = PQfnumber(res, "pubviaroot");
4622 i_pubgencols = PQfnumber(res, "pubgencols");
4623
4624 pubinfo = pg_malloc(ntups * sizeof(PublicationInfo));
4625
4626 for (i = 0; i < ntups; i++)
4627 {
4628 pubinfo[i].dobj.objType = DO_PUBLICATION;
4629 pubinfo[i].dobj.catId.tableoid =
4630 atooid(PQgetvalue(res, i, i_tableoid));
4631 pubinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4632 AssignDumpId(&pubinfo[i].dobj);
4633 pubinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_pubname));
4634 pubinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_pubowner));
4635 pubinfo[i].puballtables =
4636 (strcmp(PQgetvalue(res, i, i_puballtables), "t") == 0);
4637 pubinfo[i].puballsequences =
4638 (strcmp(PQgetvalue(res, i, i_puballsequences), "t") == 0);
4639 pubinfo[i].pubinsert =
4640 (strcmp(PQgetvalue(res, i, i_pubinsert), "t") == 0);
4641 pubinfo[i].pubupdate =
4642 (strcmp(PQgetvalue(res, i, i_pubupdate), "t") == 0);
4643 pubinfo[i].pubdelete =
4644 (strcmp(PQgetvalue(res, i, i_pubdelete), "t") == 0);
4645 pubinfo[i].pubtruncate =
4646 (strcmp(PQgetvalue(res, i, i_pubtruncate), "t") == 0);
4647 pubinfo[i].pubviaroot =
4648 (strcmp(PQgetvalue(res, i, i_pubviaroot), "t") == 0);
4649 pubinfo[i].pubgencols_type =
4650 *(PQgetvalue(res, i, i_pubgencols));
4651
4652 /* Decide whether we want to dump it */
4654 }
4655
4656cleanup:
4657 PQclear(res);
4658
4659 destroyPQExpBuffer(query);
4660}

References appendPQExpBuffer(), appendPQExpBufferStr(), AssignDumpId(), atooid, cleanup(), createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PUBLICATION, ExecuteSqlQuery(), fb(), getRoleName(), i, _dumpOptions::no_publications, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getPublicationTables()

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

Definition at line 4850 of file pg_dump.c.

4851{
4852 PQExpBuffer query;
4853 PGresult *res;
4855 DumpOptions *dopt = fout->dopt;
4856 int i_tableoid;
4857 int i_oid;
4858 int i_prpubid;
4859 int i_prrelid;
4860 int i_prrelqual;
4861 int i_prattrs;
4862 int i,
4863 j,
4864 ntups;
4865
4866 if (dopt->no_publications || fout->remoteVersion < 100000)
4867 return;
4868
4869 query = createPQExpBuffer();
4870
4871 /* Collect all publication membership info. */
4872 if (fout->remoteVersion >= 150000)
4874 "SELECT tableoid, oid, prpubid, prrelid, "
4875 "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4876 "(CASE\n"
4877 " WHEN pr.prattrs IS NOT NULL THEN\n"
4878 " (SELECT array_agg(attname)\n"
4879 " FROM\n"
4880 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4881 " pg_catalog.pg_attribute\n"
4882 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4883 " ELSE NULL END) prattrs "
4884 "FROM pg_catalog.pg_publication_rel pr");
4885 else
4887 "SELECT tableoid, oid, prpubid, prrelid, "
4888 "NULL AS prrelqual, NULL AS prattrs "
4889 "FROM pg_catalog.pg_publication_rel");
4890 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4891
4892 ntups = PQntuples(res);
4893
4894 i_tableoid = PQfnumber(res, "tableoid");
4895 i_oid = PQfnumber(res, "oid");
4896 i_prpubid = PQfnumber(res, "prpubid");
4897 i_prrelid = PQfnumber(res, "prrelid");
4898 i_prrelqual = PQfnumber(res, "prrelqual");
4899 i_prattrs = PQfnumber(res, "prattrs");
4900
4901 /* this allocation may be more than we need */
4902 pubrinfo = pg_malloc(ntups * sizeof(PublicationRelInfo));
4903 j = 0;
4904
4905 for (i = 0; i < ntups; i++)
4906 {
4911
4912 /*
4913 * Ignore any entries for which we aren't interested in either the
4914 * publication or the rel.
4915 */
4917 if (pubinfo == NULL)
4918 continue;
4920 if (tbinfo == NULL)
4921 continue;
4922
4923 /* OK, make a DumpableObject for this relationship */
4924 pubrinfo[j].dobj.objType = DO_PUBLICATION_REL;
4925 pubrinfo[j].dobj.catId.tableoid =
4926 atooid(PQgetvalue(res, i, i_tableoid));
4927 pubrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4928 AssignDumpId(&pubrinfo[j].dobj);
4929 pubrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4930 pubrinfo[j].dobj.name = tbinfo->dobj.name;
4931 pubrinfo[j].publication = pubinfo;
4932 pubrinfo[j].pubtable = tbinfo;
4933 if (PQgetisnull(res, i, i_prrelqual))
4934 pubrinfo[j].pubrelqual = NULL;
4935 else
4936 pubrinfo[j].pubrelqual = pg_strdup(PQgetvalue(res, i, i_prrelqual));
4937
4938 if (!PQgetisnull(res, i, i_prattrs))
4939 {
4940 char **attnames;
4941 int nattnames;
4943
4944 if (!parsePGArray(PQgetvalue(res, i, i_prattrs),
4945 &attnames, &nattnames))
4946 pg_fatal("could not parse %s array", "prattrs");
4948 for (int k = 0; k < nattnames; k++)
4949 {
4950 if (k > 0)
4952
4953 appendPQExpBufferStr(attribs, fmtId(attnames[k]));
4954 }
4955 pubrinfo[j].pubrattrs = attribs->data;
4956 free(attribs); /* but not attribs->data */
4957 free(attnames);
4958 }
4959 else
4960 pubrinfo[j].pubrattrs = NULL;
4961
4962 /* Decide whether we want to dump it */
4964
4965 j++;
4966 }
4967
4968 PQclear(res);
4969 destroyPQExpBuffer(query);
4970}
#define free(a)
const char * fmtId(const char *rawid)

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

Referenced by getSchemaData().

◆ getRules()

void getRules ( Archive fout)
extern

Definition at line 8602 of file pg_dump.c.

8603{
8604 PGresult *res;
8605 int ntups;
8606 int i;
8609 int i_tableoid;
8610 int i_oid;
8611 int i_rulename;
8612 int i_ruletable;
8613 int i_ev_type;
8614 int i_is_instead;
8615 int i_ev_enabled;
8616
8617 appendPQExpBufferStr(query, "SELECT "
8618 "tableoid, oid, rulename, "
8619 "ev_class AS ruletable, ev_type, is_instead, "
8620 "ev_enabled "
8621 "FROM pg_rewrite "
8622 "ORDER BY oid");
8623
8624 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8625
8626 ntups = PQntuples(res);
8627
8628 ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo));
8629
8630 i_tableoid = PQfnumber(res, "tableoid");
8631 i_oid = PQfnumber(res, "oid");
8632 i_rulename = PQfnumber(res, "rulename");
8633 i_ruletable = PQfnumber(res, "ruletable");
8634 i_ev_type = PQfnumber(res, "ev_type");
8635 i_is_instead = PQfnumber(res, "is_instead");
8636 i_ev_enabled = PQfnumber(res, "ev_enabled");
8637
8638 for (i = 0; i < ntups; i++)
8639 {
8641
8642 ruleinfo[i].dobj.objType = DO_RULE;
8643 ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8644 ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8645 AssignDumpId(&ruleinfo[i].dobj);
8646 ruleinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_rulename));
8648 ruleinfo[i].ruletable = findTableByOid(ruletableoid);
8649 if (ruleinfo[i].ruletable == NULL)
8650 pg_fatal("failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
8651 ruletableoid, ruleinfo[i].dobj.catId.oid);
8652 ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace;
8653 ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump;
8654 ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type));
8655 ruleinfo[i].is_instead = *(PQgetvalue(res, i, i_is_instead)) == 't';
8656 ruleinfo[i].ev_enabled = *(PQgetvalue(res, i, i_ev_enabled));
8657 if (ruleinfo[i].ruletable)
8658 {
8659 /*
8660 * If the table is a view or materialized view, force its ON
8661 * SELECT rule to be sorted before the view itself --- this
8662 * ensures that any dependencies for the rule affect the table's
8663 * positioning. Other rules are forced to appear after their
8664 * table.
8665 */
8666 if ((ruleinfo[i].ruletable->relkind == RELKIND_VIEW ||
8667 ruleinfo[i].ruletable->relkind == RELKIND_MATVIEW) &&
8668 ruleinfo[i].ev_type == '1' && ruleinfo[i].is_instead)
8669 {
8670 addObjectDependency(&ruleinfo[i].ruletable->dobj,
8671 ruleinfo[i].dobj.dumpId);
8672 /* We'll merge the rule into CREATE VIEW, if possible */
8673 ruleinfo[i].separate = false;
8674 }
8675 else
8676 {
8678 ruleinfo[i].ruletable->dobj.dumpId);
8679 ruleinfo[i].separate = true;
8680 }
8681 }
8682 else
8683 ruleinfo[i].separate = true;
8684 }
8685
8686 PQclear(res);
8687
8688 destroyPQExpBuffer(query);
8689}

References addObjectDependency(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_RULE, ExecuteSqlQuery(), fb(), findTableByOid(), i, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, and PQntuples.

Referenced by getSchemaData().

◆ getSchemaData()

TableInfo * getSchemaData ( Archive fout,
int numTablesPtr 
)
extern

Definition at line 98 of file common.c.

99{
100 TableInfo *tblinfo;
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");
114
115 pg_log_info("identifying extension members");
117
118 pg_log_info("reading schemas");
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");
142
143 pg_log_info("reading user-defined aggregate functions");
145
146 pg_log_info("reading user-defined operators");
148
149 pg_log_info("reading user-defined access methods");
151
152 pg_log_info("reading user-defined operator classes");
154
155 pg_log_info("reading user-defined operator families");
157
158 pg_log_info("reading user-defined text search parsers");
160
161 pg_log_info("reading user-defined text search templates");
163
164 pg_log_info("reading user-defined text search dictionaries");
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");
175
176 pg_log_info("reading default privileges");
178
179 pg_log_info("reading user-defined collations");
181
182 pg_log_info("reading user-defined conversions");
184
185 pg_log_info("reading type casts");
186 getCasts(fout);
187
188 pg_log_info("reading transforms");
190
191 pg_log_info("reading table inheritance information");
193
194 pg_log_info("reading event triggers");
196
197 /* Identify extension configuration tables that should be dumped */
198 pg_log_info("finding extension tables");
200
201 /* Link tables to parents, mark parents of target tables interesting */
202 pg_log_info("finding inheritance relationships");
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");
237
238 pg_log_info("reading publication membership of tables");
240
241 pg_log_info("reading publication membership of schemas");
243
244 pg_log_info("reading subscriptions");
246
247 pg_log_info("reading subscription membership of relations");
249
250 free(inhinfo); /* not needed any longer */
251
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:8308
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition pg_dump.c:6137
void getPublicationNamespaces(Archive *fout)
Definition pg_dump.c:4770
void getPartitioningInfo(Archive *fout)
Definition pg_dump.c:7797
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition pg_dump.c:7741
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10428
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4261
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:19945
void getTypes(Archive *fout)
Definition pg_dump.c:6212
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7676
void getOpclasses(Archive *fout)
Definition pg_dump.c:6658
void getForeignServers(Archive *fout)
Definition pg_dump.c:10512
void getFuncs(Archive *fout)
Definition pg_dump.c:6927
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10244
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4850
void getCasts(Archive *fout)
Definition pg_dump.c:9057
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7857
void getTSConfigurations(Archive *fout)
Definition pg_dump.c:10369
void getAccessMethods(Archive *fout)
Definition pg_dump.c:6584
void getConversions(Archive *fout)
Definition pg_dump.c:6522
void getRules(Archive *fout)
Definition pg_dump.c:8602
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9251
void getCollations(Archive *fout)
Definition pg_dump.c:6456
void getAggregates(Archive *fout)
Definition pg_dump.c:6786
void getNamespaces(Archive *fout)
Definition pg_dump.c:6005
void getPublications(Archive *fout)
Definition pg_dump.c:4551
void getTSParsers(Archive *fout)
Definition pg_dump.c:10170
TableInfo * getTables(Archive *fout, int *numTables)
Definition pg_dump.c:7199
void getExtendedStatistics(Archive *fout)
Definition pg_dump.c:8226
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20038
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10600
void getSubscriptions(Archive *fout)
Definition pg_dump.c:5121
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8699
void getTransforms(Archive *fout)
Definition pg_dump.c:9167
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8895
void getTSTemplates(Archive *fout)
Definition pg_dump.c:10310
void getProcLangs(Archive *fout)
Definition pg_dump.c:8973
void getSubscriptionRelations(Archive *fout)
Definition pg_dump.c:5341
void getOperators(Archive *fout)
Definition pg_dump.c:6380
void getOpfamilies(Archive *fout)
Definition pg_dump.c:6721

References fb(), 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(), getSubscriptionRelations(), getSubscriptions(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), pg_log_info, and processExtensionTables().

Referenced by main().

◆ getSubscriptionRelations()

void getSubscriptionRelations ( Archive fout)
extern

Definition at line 5341 of file pg_dump.c.

5342{
5343 DumpOptions *dopt = fout->dopt;
5344 SubscriptionInfo *subinfo = NULL;
5346 PGresult *res;
5347 int i_srsubid;
5348 int i_srrelid;
5349 int i_srsubstate;
5350 int i_srsublsn;
5351 int ntups;
5353
5354 if (dopt->no_subscriptions || !dopt->binary_upgrade ||
5355 fout->remoteVersion < 170000)
5356 return;
5357
5358 res = ExecuteSqlQuery(fout,
5359 "SELECT srsubid, srrelid, srsubstate, srsublsn "
5360 "FROM pg_catalog.pg_subscription_rel "
5361 "ORDER BY srsubid",
5363 ntups = PQntuples(res);
5364 if (ntups == 0)
5365 goto cleanup;
5366
5367 /* Get pg_subscription_rel attributes */
5368 i_srsubid = PQfnumber(res, "srsubid");
5369 i_srrelid = PQfnumber(res, "srrelid");
5370 i_srsubstate = PQfnumber(res, "srsubstate");
5371 i_srsublsn = PQfnumber(res, "srsublsn");
5372
5373 subrinfo = pg_malloc(ntups * sizeof(SubRelInfo));
5374 for (int i = 0; i < ntups; i++)
5375 {
5377 Oid relid = atooid(PQgetvalue(res, i, i_srrelid));
5378 TableInfo *tblinfo;
5379
5380 /*
5381 * If we switched to a new subscription, check if the subscription
5382 * exists.
5383 */
5385 {
5387 if (subinfo == NULL)
5388 pg_fatal("subscription with OID %u does not exist", cur_srsubid);
5389
5391 }
5392
5393 tblinfo = findTableByOid(relid);
5394 if (tblinfo == NULL)
5395 pg_fatal("failed sanity check, relation with OID %u not found",
5396 relid);
5397
5398 /* OK, make a DumpableObject for this relationship */
5399 subrinfo[i].dobj.objType = DO_SUBSCRIPTION_REL;
5400 subrinfo[i].dobj.catId.tableoid = relid;
5401 subrinfo[i].dobj.catId.oid = cur_srsubid;
5402 AssignDumpId(&subrinfo[i].dobj);
5403 subrinfo[i].dobj.namespace = tblinfo->dobj.namespace;
5404 subrinfo[i].dobj.name = tblinfo->dobj.name;
5405 subrinfo[i].subinfo = subinfo;
5406 subrinfo[i].tblinfo = tblinfo;
5407 subrinfo[i].srsubstate = PQgetvalue(res, i, i_srsubstate)[0];
5408 if (PQgetisnull(res, i, i_srsublsn))
5409 subrinfo[i].srsublsn = NULL;
5410 else
5411 subrinfo[i].srsublsn = pg_strdup(PQgetvalue(res, i, i_srsublsn));
5412
5413 /* Decide whether we want to dump it */
5415 }
5416
5417cleanup:
5418 PQclear(res);
5419}
SubscriptionInfo * findSubscriptionByOid(Oid oid)
Definition common.c:1044
int no_subscriptions
Definition pg_backup.h:191

References AssignDumpId(), atooid, _dumpOptions::binary_upgrade, cleanup(), DO_SUBSCRIPTION_REL, _tableInfo::dobj, ExecuteSqlQuery(), fb(), findSubscriptionByOid(), findTableByOid(), i, InvalidOid, _dumpableObject::name, _dumpOptions::no_subscriptions, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getSubscriptions()

void getSubscriptions ( Archive fout)
extern

Definition at line 5121 of file pg_dump.c.

5122{
5123 DumpOptions *dopt = fout->dopt;
5124 PQExpBuffer query;
5125 PGresult *res;
5126 SubscriptionInfo *subinfo;
5127 int i_tableoid;
5128 int i_oid;
5129 int i_subname;
5130 int i_subowner;
5131 int i_subbinary;
5132 int i_substream;
5136 int i_subrunasowner;
5137 int i_subconninfo;
5138 int i_subslotname;
5139 int i_subsynccommit;
5141 int i_suborigin;
5143 int i_subenabled;
5144 int i_subfailover;
5147 int i,
5148 ntups;
5149
5150 if (dopt->no_subscriptions || fout->remoteVersion < 100000)
5151 return;
5152
5153 if (!is_superuser(fout))
5154 {
5155 int n;
5156
5157 res = ExecuteSqlQuery(fout,
5158 "SELECT count(*) FROM pg_subscription "
5159 "WHERE subdbid = (SELECT oid FROM pg_database"
5160 " WHERE datname = current_database())",
5162 n = atoi(PQgetvalue(res, 0, 0));
5163 if (n > 0)
5164 pg_log_warning("subscriptions not dumped because current user is not a superuser");
5165 PQclear(res);
5166 return;
5167 }
5168
5169 query = createPQExpBuffer();
5170
5171 /* Get the subscriptions in current database. */
5173 "SELECT s.tableoid, s.oid, s.subname,\n"
5174 " s.subowner,\n"
5175 " s.subconninfo, s.subslotname, s.subsynccommit,\n"
5176 " s.subpublications,\n");
5177
5178 if (fout->remoteVersion >= 140000)
5179 appendPQExpBufferStr(query, " s.subbinary,\n");
5180 else
5181 appendPQExpBufferStr(query, " false AS subbinary,\n");
5182
5183 if (fout->remoteVersion >= 140000)
5184 appendPQExpBufferStr(query, " s.substream,\n");
5185 else
5186 appendPQExpBufferStr(query, " 'f' AS substream,\n");
5187
5188 if (fout->remoteVersion >= 150000)
5190 " s.subtwophasestate,\n"
5191 " s.subdisableonerr,\n");
5192 else
5193 appendPQExpBuffer(query,
5194 " '%c' AS subtwophasestate,\n"
5195 " false AS subdisableonerr,\n",
5197
5198 if (fout->remoteVersion >= 160000)
5200 " s.subpasswordrequired,\n"
5201 " s.subrunasowner,\n"
5202 " s.suborigin,\n");
5203 else
5204 appendPQExpBuffer(query,
5205 " 't' AS subpasswordrequired,\n"
5206 " 't' AS subrunasowner,\n"
5207 " '%s' AS suborigin,\n",
5209
5210 if (dopt->binary_upgrade && fout->remoteVersion >= 170000)
5211 appendPQExpBufferStr(query, " o.remote_lsn AS suboriginremotelsn,\n"
5212 " s.subenabled,\n");
5213 else
5214 appendPQExpBufferStr(query, " NULL AS suboriginremotelsn,\n"
5215 " false AS subenabled,\n");
5216
5217 if (fout->remoteVersion >= 170000)
5219 " s.subfailover,\n");
5220 else
5222 " false AS subfailover,\n");
5223
5224 if (fout->remoteVersion >= 190000)
5226 " s.subretaindeadtuples,\n");
5227 else
5229 " false AS subretaindeadtuples,\n");
5230
5231 if (fout->remoteVersion >= 190000)
5233 " s.submaxretention\n");
5234 else
5235 appendPQExpBuffer(query,
5236 " 0 AS submaxretention\n");
5237
5239 "FROM pg_subscription s\n");
5240
5241 if (dopt->binary_upgrade && fout->remoteVersion >= 170000)
5243 "LEFT JOIN pg_catalog.pg_replication_origin_status o \n"
5244 " ON o.external_id = 'pg_' || s.oid::text \n");
5245
5247 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
5248 " WHERE datname = current_database())");
5249
5250 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5251
5252 ntups = PQntuples(res);
5253
5254 /*
5255 * Get subscription fields. We don't include subskiplsn in the dump as
5256 * after restoring the dump this value may no longer be relevant.
5257 */
5258 i_tableoid = PQfnumber(res, "tableoid");
5259 i_oid = PQfnumber(res, "oid");
5260 i_subname = PQfnumber(res, "subname");
5261 i_subowner = PQfnumber(res, "subowner");
5262 i_subenabled = PQfnumber(res, "subenabled");
5263 i_subbinary = PQfnumber(res, "subbinary");
5264 i_substream = PQfnumber(res, "substream");
5265 i_subtwophasestate = PQfnumber(res, "subtwophasestate");
5266 i_subdisableonerr = PQfnumber(res, "subdisableonerr");
5267 i_subpasswordrequired = PQfnumber(res, "subpasswordrequired");
5268 i_subrunasowner = PQfnumber(res, "subrunasowner");
5269 i_subfailover = PQfnumber(res, "subfailover");
5270 i_subretaindeadtuples = PQfnumber(res, "subretaindeadtuples");
5271 i_submaxretention = PQfnumber(res, "submaxretention");
5272 i_subconninfo = PQfnumber(res, "subconninfo");
5273 i_subslotname = PQfnumber(res, "subslotname");
5274 i_subsynccommit = PQfnumber(res, "subsynccommit");
5275 i_subpublications = PQfnumber(res, "subpublications");
5276 i_suborigin = PQfnumber(res, "suborigin");
5277 i_suboriginremotelsn = PQfnumber(res, "suboriginremotelsn");
5278
5279 subinfo = pg_malloc(ntups * sizeof(SubscriptionInfo));
5280
5281 for (i = 0; i < ntups; i++)
5282 {
5283 subinfo[i].dobj.objType = DO_SUBSCRIPTION;
5284 subinfo[i].dobj.catId.tableoid =
5285 atooid(PQgetvalue(res, i, i_tableoid));
5286 subinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5287 AssignDumpId(&subinfo[i].dobj);
5288 subinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_subname));
5289 subinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_subowner));
5290
5291 subinfo[i].subenabled =
5292 (strcmp(PQgetvalue(res, i, i_subenabled), "t") == 0);
5293 subinfo[i].subbinary =
5294 (strcmp(PQgetvalue(res, i, i_subbinary), "t") == 0);
5295 subinfo[i].substream = *(PQgetvalue(res, i, i_substream));
5296 subinfo[i].subtwophasestate = *(PQgetvalue(res, i, i_subtwophasestate));
5297 subinfo[i].subdisableonerr =
5298 (strcmp(PQgetvalue(res, i, i_subdisableonerr), "t") == 0);
5299 subinfo[i].subpasswordrequired =
5300 (strcmp(PQgetvalue(res, i, i_subpasswordrequired), "t") == 0);
5301 subinfo[i].subrunasowner =
5302 (strcmp(PQgetvalue(res, i, i_subrunasowner), "t") == 0);
5303 subinfo[i].subfailover =
5304 (strcmp(PQgetvalue(res, i, i_subfailover), "t") == 0);
5305 subinfo[i].subretaindeadtuples =
5306 (strcmp(PQgetvalue(res, i, i_subretaindeadtuples), "t") == 0);
5307 subinfo[i].submaxretention =
5309 subinfo[i].subconninfo =
5311 if (PQgetisnull(res, i, i_subslotname))
5312 subinfo[i].subslotname = NULL;
5313 else
5314 subinfo[i].subslotname =
5316 subinfo[i].subsynccommit =
5318 subinfo[i].subpublications =
5320 subinfo[i].suborigin = pg_strdup(PQgetvalue(res, i, i_suborigin));
5322 subinfo[i].suboriginremotelsn = NULL;
5323 else
5324 subinfo[i].suboriginremotelsn =
5326
5327 /* Decide whether we want to dump it */
5328 selectDumpableObject(&(subinfo[i].dobj), fout);
5329 }
5330 PQclear(res);
5331
5332 destroyPQExpBuffer(query);
5333}
bool is_superuser(void)
Definition common.c:2480

References appendPQExpBuffer(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_SUBSCRIPTION, _SubscriptionInfo::dobj, ExecuteSqlQuery(), fb(), 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, _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().

◆ getTableAttrs()

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

Definition at line 9251 of file pg_dump.c.

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

References addObjectDependency(), _attrDefInfo::adef_expr, _attrDefInfo::adnum, _attrDefInfo::adtable, appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), determineNotNullFlags(), DO_ATTRDEF, DO_CONSTRAINT, _attrDefInfo::dobj, _dumpableObject::dump, _dumpableObject::dumpId, _dumpOptions::dumpSchema, ExecuteSqlQuery(), exit_nicely(), fb(), i, InvalidOid, j, _dumpableObject::name, ngettext, _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(), resetPQExpBuffer(), _attrDefInfo::separate, shouldPrintColumn(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getTables()

TableInfo * getTables ( Archive fout,
int numTables 
)
extern

Definition at line 7199 of file pg_dump.c.

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

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, _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(), fb(), findNamespace(), fmtQualifiedDumpable, _tableInfo::forcerowsec, _tableInfo::foreign_server, _tableInfo::frozenxid, GetConnection(), getRelationStatistics(), getRoleName(), _tableInfo::hascolumnACLs, _tableInfo::hasindex, _tableInfo::hasoids, _tableInfo::hasrules, _tableInfo::hastriggers, i, _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, 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)
extern

Definition at line 9167 of file pg_dump.c.

9168{
9169 PGresult *res;
9170 int ntups;
9171 int i;
9172 PQExpBuffer query;
9174 int i_tableoid;
9175 int i_oid;
9176 int i_trftype;
9177 int i_trflang;
9178 int i_trffromsql;
9179 int i_trftosql;
9180
9181 /* Transforms didn't exist pre-9.5 */
9182 if (fout->remoteVersion < 90500)
9183 return;
9184
9185 query = createPQExpBuffer();
9186
9187 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9188 "trftype, trflang, trffromsql::oid, trftosql::oid "
9189 "FROM pg_transform "
9190 "ORDER BY 3,4");
9191
9192 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9193
9194 ntups = PQntuples(res);
9195
9196 transforminfo = (TransformInfo *) pg_malloc(ntups * sizeof(TransformInfo));
9197
9198 i_tableoid = PQfnumber(res, "tableoid");
9199 i_oid = PQfnumber(res, "oid");
9200 i_trftype = PQfnumber(res, "trftype");
9201 i_trflang = PQfnumber(res, "trflang");
9202 i_trffromsql = PQfnumber(res, "trffromsql");
9203 i_trftosql = PQfnumber(res, "trftosql");
9204
9205 for (i = 0; i < ntups; i++)
9206 {
9209 char *lanname;
9210
9212 transforminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9213 transforminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9215 transforminfo[i].trftype = atooid(PQgetvalue(res, i, i_trftype));
9216 transforminfo[i].trflang = atooid(PQgetvalue(res, i, i_trflang));
9217 transforminfo[i].trffromsql = atooid(PQgetvalue(res, i, i_trffromsql));
9218 transforminfo[i].trftosql = atooid(PQgetvalue(res, i, i_trftosql));
9219
9220 /*
9221 * Try to name transform as concatenation of type and language name.
9222 * This is only used for purposes of sorting. If we fail to find
9223 * either, the name will be an empty string.
9224 */
9228 if (typeInfo && lanname)
9229 appendPQExpBuffer(&namebuf, "%s %s",
9230 typeInfo->dobj.name, lanname);
9231 transforminfo[i].dobj.name = namebuf.data;
9232 free(lanname);
9233
9234 /* Decide whether we want to dump it */
9236 }
9237
9238 PQclear(res);
9239
9240 destroyPQExpBuffer(query);
9241}
static char * get_language_name(Archive *fout, Oid langid)
Definition pg_dump.c:9146

References appendPQExpBuffer(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TRANSFORM, _typeInfo::dobj, ExecuteSqlQuery(), fb(), findTypeByOid(), free, get_language_name(), i, initPQExpBuffer(), _dumpableObject::objType, pg_malloc(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getTriggers()

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

Definition at line 8699 of file pg_dump.c.

8700{
8703 PGresult *res;
8704 int ntups;
8705 int curtblindx;
8707 int i_tableoid,
8708 i_oid,
8709 i_tgrelid,
8710 i_tgname,
8713 i_tgdef;
8714
8715 /*
8716 * We want to perform just one query against pg_trigger. However, we
8717 * mustn't try to select every row of the catalog and then sort it out on
8718 * the client side, because some of the server-side functions we need
8719 * would be unsafe to apply to tables we don't have lock on. Hence, we
8720 * build an array of the OIDs of tables we care about (and now have lock
8721 * on!), and use a WHERE clause to constrain which rows are selected.
8722 */
8724 for (int i = 0; i < numTables; i++)
8725 {
8726 TableInfo *tbinfo = &tblinfo[i];
8727
8728 if (!tbinfo->hastriggers ||
8729 !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
8730 continue;
8731
8732 /* OK, we need info for this table */
8733 if (tbloids->len > 1) /* do we have more than the '{'? */
8735 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
8736 }
8738
8739 if (fout->remoteVersion >= 150000)
8740 {
8741 /*
8742 * NB: think not to use pretty=true in pg_get_triggerdef. It could
8743 * result in non-forward-compatible dumps of WHEN clauses due to
8744 * under-parenthesization.
8745 *
8746 * NB: We need to see partition triggers in case the tgenabled flag
8747 * has been changed from the parent.
8748 */
8749 appendPQExpBuffer(query,
8750 "SELECT t.tgrelid, t.tgname, "
8751 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8752 "t.tgenabled, t.tableoid, t.oid, "
8753 "t.tgparentid <> 0 AS tgispartition\n"
8754 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8755 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8756 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8757 "WHERE ((NOT t.tgisinternal AND t.tgparentid = 0) "
8758 "OR t.tgenabled != u.tgenabled) "
8759 "ORDER BY t.tgrelid, t.tgname",
8760 tbloids->data);
8761 }
8762 else if (fout->remoteVersion >= 130000)
8763 {
8764 /*
8765 * NB: think not to use pretty=true in pg_get_triggerdef. It could
8766 * result in non-forward-compatible dumps of WHEN clauses due to
8767 * under-parenthesization.
8768 *
8769 * NB: We need to see tgisinternal triggers in partitions, in case the
8770 * tgenabled flag has been changed from the parent.
8771 */
8772 appendPQExpBuffer(query,
8773 "SELECT t.tgrelid, t.tgname, "
8774 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8775 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
8776 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8777 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8778 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8779 "WHERE (NOT t.tgisinternal OR t.tgenabled != u.tgenabled) "
8780 "ORDER BY t.tgrelid, t.tgname",
8781 tbloids->data);
8782 }
8783 else if (fout->remoteVersion >= 110000)
8784 {
8785 /*
8786 * NB: We need to see tgisinternal triggers in partitions, in case the
8787 * tgenabled flag has been changed from the parent. No tgparentid in
8788 * version 11-12, so we have to match them via pg_depend.
8789 *
8790 * See above about pretty=true in pg_get_triggerdef.
8791 */
8792 appendPQExpBuffer(query,
8793 "SELECT t.tgrelid, t.tgname, "
8794 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8795 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
8796 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8797 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8798 "LEFT JOIN pg_catalog.pg_depend AS d ON "
8799 " d.classid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8800 " d.refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8801 " d.objid = t.oid "
8802 "LEFT JOIN pg_catalog.pg_trigger AS pt ON pt.oid = refobjid "
8803 "WHERE (NOT t.tgisinternal OR t.tgenabled != pt.tgenabled) "
8804 "ORDER BY t.tgrelid, t.tgname",
8805 tbloids->data);
8806 }
8807 else
8808 {
8809 /* See above about pretty=true in pg_get_triggerdef */
8810 appendPQExpBuffer(query,
8811 "SELECT t.tgrelid, t.tgname, "
8812 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8813 "t.tgenabled, false as tgispartition, "
8814 "t.tableoid, t.oid "
8815 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8816 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8817 "WHERE NOT tgisinternal "
8818 "ORDER BY t.tgrelid, t.tgname",
8819 tbloids->data);
8820 }
8821
8822 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8823
8824 ntups = PQntuples(res);
8825
8826 i_tableoid = PQfnumber(res, "tableoid");
8827 i_oid = PQfnumber(res, "oid");
8828 i_tgrelid = PQfnumber(res, "tgrelid");
8829 i_tgname = PQfnumber(res, "tgname");
8830 i_tgenabled = PQfnumber(res, "tgenabled");
8831 i_tgispartition = PQfnumber(res, "tgispartition");
8832 i_tgdef = PQfnumber(res, "tgdef");
8833
8834 tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(TriggerInfo));
8835
8836 /*
8837 * Outer loop iterates once per table, not once per row. Incrementing of
8838 * j is handled by the inner loop.
8839 */
8840 curtblindx = -1;
8841 for (int j = 0; j < ntups;)
8842 {
8845 int numtrigs;
8846
8847 /* Count rows for this table */
8848 for (numtrigs = 1; numtrigs < ntups - j; numtrigs++)
8849 if (atooid(PQgetvalue(res, j + numtrigs, i_tgrelid)) != tgrelid)
8850 break;
8851
8852 /*
8853 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8854 * order.
8855 */
8856 while (++curtblindx < numTables)
8857 {
8858 tbinfo = &tblinfo[curtblindx];
8859 if (tbinfo->dobj.catId.oid == tgrelid)
8860 break;
8861 }
8862 if (curtblindx >= numTables)
8863 pg_fatal("unrecognized table OID %u", tgrelid);
8864
8865 /* Save data for this table */
8866 tbinfo->triggers = tginfo + j;
8867 tbinfo->numTriggers = numtrigs;
8868
8869 for (int c = 0; c < numtrigs; c++, j++)
8870 {
8871 tginfo[j].dobj.objType = DO_TRIGGER;
8872 tginfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
8873 tginfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
8874 AssignDumpId(&tginfo[j].dobj);
8875 tginfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_tgname));
8876 tginfo[j].dobj.namespace = tbinfo->dobj.namespace;
8877 tginfo[j].tgtable = tbinfo;
8878 tginfo[j].tgenabled = *(PQgetvalue(res, j, i_tgenabled));
8879 tginfo[j].tgispartition = *(PQgetvalue(res, j, i_tgispartition)) == 't';
8880 tginfo[j].tgdef = pg_strdup(PQgetvalue(res, j, i_tgdef));
8881 }
8882 }
8883
8884 PQclear(res);
8885
8886 destroyPQExpBuffer(query);
8888}

References appendPQExpBuffer(), appendPQExpBufferChar(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TRIGGER, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), fb(), i, j, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, and PQntuples.

Referenced by getSchemaData().

◆ getTSConfigurations()

void getTSConfigurations ( Archive fout)
extern

Definition at line 10369 of file pg_dump.c.

10370{
10371 PGresult *res;
10372 int ntups;
10373 int i;
10374 PQExpBuffer query;
10376 int i_tableoid;
10377 int i_oid;
10378 int i_cfgname;
10379 int i_cfgnamespace;
10380 int i_cfgowner;
10381 int i_cfgparser;
10382
10383 query = createPQExpBuffer();
10384
10385 appendPQExpBufferStr(query, "SELECT tableoid, oid, cfgname, "
10386 "cfgnamespace, cfgowner, cfgparser "
10387 "FROM pg_ts_config");
10388
10389 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10390
10391 ntups = PQntuples(res);
10392
10393 cfginfo = (TSConfigInfo *) pg_malloc(ntups * sizeof(TSConfigInfo));
10394
10395 i_tableoid = PQfnumber(res, "tableoid");
10396 i_oid = PQfnumber(res, "oid");
10397 i_cfgname = PQfnumber(res, "cfgname");
10398 i_cfgnamespace = PQfnumber(res, "cfgnamespace");
10399 i_cfgowner = PQfnumber(res, "cfgowner");
10400 i_cfgparser = PQfnumber(res, "cfgparser");
10401
10402 for (i = 0; i < ntups; i++)
10403 {
10404 cfginfo[i].dobj.objType = DO_TSCONFIG;
10405 cfginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10406 cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10407 AssignDumpId(&cfginfo[i].dobj);
10408 cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname));
10409 cfginfo[i].dobj.namespace =
10411 cfginfo[i].rolname = getRoleName(PQgetvalue(res, i, i_cfgowner));
10412 cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser));
10413
10414 /* Decide whether we want to dump it */
10416 }
10417
10418 PQclear(res);
10419
10420 destroyPQExpBuffer(query);
10421}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TSCONFIG, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getTSDictionaries()

void getTSDictionaries ( Archive fout)
extern

Definition at line 10244 of file pg_dump.c.

10245{
10246 PGresult *res;
10247 int ntups;
10248 int i;
10249 PQExpBuffer query;
10251 int i_tableoid;
10252 int i_oid;
10253 int i_dictname;
10254 int i_dictnamespace;
10255 int i_dictowner;
10256 int i_dicttemplate;
10257 int i_dictinitoption;
10258
10259 query = createPQExpBuffer();
10260
10261 appendPQExpBufferStr(query, "SELECT tableoid, oid, dictname, "
10262 "dictnamespace, dictowner, "
10263 "dicttemplate, dictinitoption "
10264 "FROM pg_ts_dict");
10265
10266 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10267
10268 ntups = PQntuples(res);
10269
10270 dictinfo = (TSDictInfo *) pg_malloc(ntups * sizeof(TSDictInfo));
10271
10272 i_tableoid = PQfnumber(res, "tableoid");
10273 i_oid = PQfnumber(res, "oid");
10274 i_dictname = PQfnumber(res, "dictname");
10275 i_dictnamespace = PQfnumber(res, "dictnamespace");
10276 i_dictowner = PQfnumber(res, "dictowner");
10277 i_dictinitoption = PQfnumber(res, "dictinitoption");
10278 i_dicttemplate = PQfnumber(res, "dicttemplate");
10279
10280 for (i = 0; i < ntups; i++)
10281 {
10282 dictinfo[i].dobj.objType = DO_TSDICT;
10283 dictinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10284 dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10285 AssignDumpId(&dictinfo[i].dobj);
10286 dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname));
10287 dictinfo[i].dobj.namespace =
10289 dictinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_dictowner));
10290 dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate));
10291 if (PQgetisnull(res, i, i_dictinitoption))
10292 dictinfo[i].dictinitoption = NULL;
10293 else
10294 dictinfo[i].dictinitoption = pg_strdup(PQgetvalue(res, i, i_dictinitoption));
10295
10296 /* Decide whether we want to dump it */
10298 }
10299
10300 PQclear(res);
10301
10302 destroyPQExpBuffer(query);
10303}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TSDICT, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getTSParsers()

void getTSParsers ( Archive fout)
extern

Definition at line 10170 of file pg_dump.c.

10171{
10172 PGresult *res;
10173 int ntups;
10174 int i;
10175 PQExpBuffer query;
10177 int i_tableoid;
10178 int i_oid;
10179 int i_prsname;
10180 int i_prsnamespace;
10181 int i_prsstart;
10182 int i_prstoken;
10183 int i_prsend;
10184 int i_prsheadline;
10185 int i_prslextype;
10186
10187 query = createPQExpBuffer();
10188
10189 /*
10190 * find all text search objects, including builtin ones; we filter out
10191 * system-defined objects at dump-out time.
10192 */
10193
10194 appendPQExpBufferStr(query, "SELECT tableoid, oid, prsname, prsnamespace, "
10195 "prsstart::oid, prstoken::oid, "
10196 "prsend::oid, prsheadline::oid, prslextype::oid "
10197 "FROM pg_ts_parser");
10198
10199 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10200
10201 ntups = PQntuples(res);
10202
10203 prsinfo = (TSParserInfo *) pg_malloc(ntups * sizeof(TSParserInfo));
10204
10205 i_tableoid = PQfnumber(res, "tableoid");
10206 i_oid = PQfnumber(res, "oid");
10207 i_prsname = PQfnumber(res, "prsname");
10208 i_prsnamespace = PQfnumber(res, "prsnamespace");
10209 i_prsstart = PQfnumber(res, "prsstart");
10210 i_prstoken = PQfnumber(res, "prstoken");
10211 i_prsend = PQfnumber(res, "prsend");
10212 i_prsheadline = PQfnumber(res, "prsheadline");
10213 i_prslextype = PQfnumber(res, "prslextype");
10214
10215 for (i = 0; i < ntups; i++)
10216 {
10217 prsinfo[i].dobj.objType = DO_TSPARSER;
10218 prsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10219 prsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10220 AssignDumpId(&prsinfo[i].dobj);
10221 prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname));
10222 prsinfo[i].dobj.namespace =
10224 prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart));
10225 prsinfo[i].prstoken = atooid(PQgetvalue(res, i, i_prstoken));
10226 prsinfo[i].prsend = atooid(PQgetvalue(res, i, i_prsend));
10227 prsinfo[i].prsheadline = atooid(PQgetvalue(res, i, i_prsheadline));
10228 prsinfo[i].prslextype = atooid(PQgetvalue(res, i, i_prslextype));
10229
10230 /* Decide whether we want to dump it */
10232 }
10233
10234 PQclear(res);
10235
10236 destroyPQExpBuffer(query);
10237}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TSPARSER, ExecuteSqlQuery(), fb(), findNamespace(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getTSTemplates()

void getTSTemplates ( Archive fout)
extern

Definition at line 10310 of file pg_dump.c.

10311{
10312 PGresult *res;
10313 int ntups;
10314 int i;
10315 PQExpBuffer query;
10317 int i_tableoid;
10318 int i_oid;
10319 int i_tmplname;
10320 int i_tmplnamespace;
10321 int i_tmplinit;
10322 int i_tmpllexize;
10323
10324 query = createPQExpBuffer();
10325
10326 appendPQExpBufferStr(query, "SELECT tableoid, oid, tmplname, "
10327 "tmplnamespace, tmplinit::oid, tmpllexize::oid "
10328 "FROM pg_ts_template");
10329
10330 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10331
10332 ntups = PQntuples(res);
10333
10334 tmplinfo = (TSTemplateInfo *) pg_malloc(ntups * sizeof(TSTemplateInfo));
10335
10336 i_tableoid = PQfnumber(res, "tableoid");
10337 i_oid = PQfnumber(res, "oid");
10338 i_tmplname = PQfnumber(res, "tmplname");
10339 i_tmplnamespace = PQfnumber(res, "tmplnamespace");
10340 i_tmplinit = PQfnumber(res, "tmplinit");
10341 i_tmpllexize = PQfnumber(res, "tmpllexize");
10342
10343 for (i = 0; i < ntups; i++)
10344 {
10345 tmplinfo[i].dobj.objType = DO_TSTEMPLATE;
10346 tmplinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10347 tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10348 AssignDumpId(&tmplinfo[i].dobj);
10349 tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname));
10350 tmplinfo[i].dobj.namespace =
10352 tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit));
10353 tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize));
10354
10355 /* Decide whether we want to dump it */
10357 }
10358
10359 PQclear(res);
10360
10361 destroyPQExpBuffer(query);
10362}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TSTEMPLATE, ExecuteSqlQuery(), fb(), findNamespace(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getTypes()

void getTypes ( Archive fout)
extern

Definition at line 6212 of file pg_dump.c.

6213{
6214 PGresult *res;
6215 int ntups;
6216 int i;
6220 int i_tableoid;
6221 int i_oid;
6222 int i_typname;
6223 int i_typnamespace;
6224 int i_typacl;
6225 int i_acldefault;
6226 int i_typowner;
6227 int i_typelem;
6228 int i_typrelid;
6229 int i_typrelkind;
6230 int i_typtype;
6231 int i_typisdefined;
6232 int i_isarray;
6233 int i_typarray;
6234
6235 /*
6236 * we include even the built-in types because those may be used as array
6237 * elements by user-defined types
6238 *
6239 * we filter out the built-in types when we dump out the types
6240 *
6241 * same approach for undefined (shell) types and array types
6242 *
6243 * Note: as of 8.3 we can reliably detect whether a type is an
6244 * auto-generated array type by checking the element type's typarray.
6245 * (Before that the test is capable of generating false positives.) We
6246 * still check for name beginning with '_', though, so as to avoid the
6247 * cost of the subselect probe for all standard types. This would have to
6248 * be revisited if the backend ever allows renaming of array types.
6249 */
6250 appendPQExpBufferStr(query, "SELECT tableoid, oid, typname, "
6251 "typnamespace, typacl, "
6252 "acldefault('T', typowner) AS acldefault, "
6253 "typowner, "
6254 "typelem, typrelid, typarray, "
6255 "CASE WHEN typrelid = 0 THEN ' '::\"char\" "
6256 "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, "
6257 "typtype, typisdefined, "
6258 "typname[0] = '_' AND typelem != 0 AND "
6259 "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray "
6260 "FROM pg_type");
6261
6262 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6263
6264 ntups = PQntuples(res);
6265
6266 tyinfo = (TypeInfo *) pg_malloc(ntups * sizeof(TypeInfo));
6267
6268 i_tableoid = PQfnumber(res, "tableoid");
6269 i_oid = PQfnumber(res, "oid");
6270 i_typname = PQfnumber(res, "typname");
6271 i_typnamespace = PQfnumber(res, "typnamespace");
6272 i_typacl = PQfnumber(res, "typacl");
6273 i_acldefault = PQfnumber(res, "acldefault");
6274 i_typowner = PQfnumber(res, "typowner");
6275 i_typelem = PQfnumber(res, "typelem");
6276 i_typrelid = PQfnumber(res, "typrelid");
6277 i_typrelkind = PQfnumber(res, "typrelkind");
6278 i_typtype = PQfnumber(res, "typtype");
6279 i_typisdefined = PQfnumber(res, "typisdefined");
6280 i_isarray = PQfnumber(res, "isarray");
6281 i_typarray = PQfnumber(res, "typarray");
6282
6283 for (i = 0; i < ntups; i++)
6284 {
6285 tyinfo[i].dobj.objType = DO_TYPE;
6286 tyinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6287 tyinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6288 AssignDumpId(&tyinfo[i].dobj);
6289 tyinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_typname));
6290 tyinfo[i].dobj.namespace =
6292 tyinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_typacl));
6293 tyinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6294 tyinfo[i].dacl.privtype = 0;
6295 tyinfo[i].dacl.initprivs = NULL;
6296 tyinfo[i].ftypname = NULL; /* may get filled later */
6297 tyinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_typowner));
6298 tyinfo[i].typelem = atooid(PQgetvalue(res, i, i_typelem));
6299 tyinfo[i].typrelid = atooid(PQgetvalue(res, i, i_typrelid));
6300 tyinfo[i].typrelkind = *PQgetvalue(res, i, i_typrelkind);
6301 tyinfo[i].typtype = *PQgetvalue(res, i, i_typtype);
6302 tyinfo[i].shellType = NULL;
6303
6304 if (strcmp(PQgetvalue(res, i, i_typisdefined), "t") == 0)
6305 tyinfo[i].isDefined = true;
6306 else
6307 tyinfo[i].isDefined = false;
6308
6309 if (strcmp(PQgetvalue(res, i, i_isarray), "t") == 0)
6310 tyinfo[i].isArray = true;
6311 else
6312 tyinfo[i].isArray = false;
6313
6314 tyinfo[i].typarray = atooid(PQgetvalue(res, i, i_typarray));
6315
6316 if (tyinfo[i].typtype == TYPTYPE_MULTIRANGE)
6317 tyinfo[i].isMultirange = true;
6318 else
6319 tyinfo[i].isMultirange = false;
6320
6321 /* Decide whether we want to dump it */
6323
6324 /* Mark whether type has an ACL */
6325 if (!PQgetisnull(res, i, i_typacl))
6326 tyinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6327
6328 /*
6329 * If it's a domain, fetch info about its constraints, if any
6330 */
6331 tyinfo[i].nDomChecks = 0;
6332 tyinfo[i].domChecks = NULL;
6333 tyinfo[i].notnull = NULL;
6334 if ((tyinfo[i].dobj.dump & DUMP_COMPONENT_DEFINITION) &&
6335 tyinfo[i].typtype == TYPTYPE_DOMAIN)
6337
6338 /*
6339 * If it's a base type, make a DumpableObject representing a shell
6340 * definition of the type. We will need to dump that ahead of the I/O
6341 * functions for the type. Similarly, range types need a shell
6342 * definition in case they have a canonicalize function.
6343 *
6344 * Note: the shell type doesn't have a catId. You might think it
6345 * should copy the base type's catId, but then it might capture the
6346 * pg_depend entries for the type, which we don't want.
6347 */
6348 if ((tyinfo[i].dobj.dump & DUMP_COMPONENT_DEFINITION) &&
6349 (tyinfo[i].typtype == TYPTYPE_BASE ||
6350 tyinfo[i].typtype == TYPTYPE_RANGE))
6351 {
6353 stinfo->dobj.objType = DO_SHELL_TYPE;
6354 stinfo->dobj.catId = nilCatalogId;
6355 AssignDumpId(&stinfo->dobj);
6356 stinfo->dobj.name = pg_strdup(tyinfo[i].dobj.name);
6357 stinfo->dobj.namespace = tyinfo[i].dobj.namespace;
6358 stinfo->baseType = &(tyinfo[i]);
6359 tyinfo[i].shellType = stinfo;
6360
6361 /*
6362 * Initially mark the shell type as not to be dumped. We'll only
6363 * dump it if the I/O or canonicalize functions need to be dumped;
6364 * this is taken care of while sorting dependencies.
6365 */
6366 stinfo->dobj.dump = DUMP_COMPONENT_NONE;
6367 }
6368 }
6369
6370 PQclear(res);
6371
6372 destroyPQExpBuffer(query);
6373}
static const CatalogId nilCatalogId
Definition pg_dump.c:191
static void getDomainConstraints(Archive *fout, TypeInfo *tyinfo)
Definition pg_dump.c:8490
static void selectDumpableType(TypeInfo *tyinfo, Archive *fout)
Definition pg_dump.c:2137

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_SHELL_TYPE, DO_TYPE, DUMP_COMPONENT_ACL, DUMP_COMPONENT_DEFINITION, DUMP_COMPONENT_NONE, ExecuteSqlQuery(), fb(), findNamespace(), getDomainConstraints(), getRoleName(), i, nilCatalogId, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableType().

Referenced by getSchemaData().

◆ parseOidArray()

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

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}

References atooid, fb(), InvalidOid, j, pg_fatal, and str.

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

◆ processExtensionTables()

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

Definition at line 20038 of file pg_dump.c.

20040{
20041 DumpOptions *dopt = fout->dopt;
20042 PQExpBuffer query;
20043 PGresult *res;
20044 int ntups,
20045 i;
20046 int i_conrelid,
20048
20049 /* Nothing to do if no extensions */
20050 if (numExtensions == 0)
20051 return;
20052
20053 /*
20054 * Identify extension configuration tables and create TableDataInfo
20055 * objects for them, ensuring their data will be dumped even though the
20056 * tables themselves won't be.
20057 *
20058 * Note that we create TableDataInfo objects even in schema-only mode, ie,
20059 * user data in a configuration table is treated like schema data. This
20060 * seems appropriate since system data in a config table would get
20061 * reloaded by CREATE EXTENSION. If the extension is not listed in the
20062 * list of extensions to be included, none of its data is dumped.
20063 */
20064 for (i = 0; i < numExtensions; i++)
20065 {
20067 char *extconfig = curext->extconfig;
20068 char *extcondition = curext->extcondition;
20069 char **extconfigarray = NULL;
20070 char **extconditionarray = NULL;
20071 int nconfigitems = 0;
20072 int nconditionitems = 0;
20073
20074 /*
20075 * Check if this extension is listed as to include in the dump. If
20076 * not, any table data associated with it is discarded.
20077 */
20080 curext->dobj.catId.oid))
20081 continue;
20082
20083 /*
20084 * Check if this extension is listed as to exclude in the dump. If
20085 * yes, any table data associated with it is discarded.
20086 */
20089 curext->dobj.catId.oid))
20090 continue;
20091
20092 if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
20093 {
20094 int j;
20095
20096 if (!parsePGArray(extconfig, &extconfigarray, &nconfigitems))
20097 pg_fatal("could not parse %s array", "extconfig");
20098 if (!parsePGArray(extcondition, &extconditionarray, &nconditionitems))
20099 pg_fatal("could not parse %s array", "extcondition");
20101 pg_fatal("mismatched number of configurations and conditions for extension");
20102
20103 for (j = 0; j < nconfigitems; j++)
20104 {
20107 bool dumpobj =
20108 curext->dobj.dump & DUMP_COMPONENT_DEFINITION;
20109
20111 if (configtbl == NULL)
20112 continue;
20113
20114 /*
20115 * Tables of not-to-be-dumped extensions shouldn't be dumped
20116 * unless the table or its schema is explicitly included
20117 */
20118 if (!(curext->dobj.dump & DUMP_COMPONENT_DEFINITION))
20119 {
20120 /* check table explicitly requested */
20121 if (table_include_oids.head != NULL &&
20123 configtbloid))
20124 dumpobj = true;
20125
20126 /* check table's schema explicitly requested */
20127 if (configtbl->dobj.namespace->dobj.dump &
20129 dumpobj = true;
20130 }
20131
20132 /* check table excluded by an exclusion switch */
20133 if (table_exclude_oids.head != NULL &&
20135 configtbloid))
20136 dumpobj = false;
20137
20138 /* check schema excluded by an exclusion switch */
20140 configtbl->dobj.namespace->dobj.catId.oid))
20141 dumpobj = false;
20142
20143 if (dumpobj)
20144 {
20146 if (configtbl->dataObj != NULL)
20147 {
20148 if (strlen(extconditionarray[j]) > 0)
20149 configtbl->dataObj->filtercond = pg_strdup(extconditionarray[j]);
20150 }
20151 }
20152 }
20153 }
20154 if (extconfigarray)
20158 }
20159
20160 /*
20161 * Now that all the TableDataInfo objects have been created for all the
20162 * extensions, check their FK dependencies and register them to try and
20163 * dump the data out in an order that they can be restored in.
20164 *
20165 * Note that this is not a problem for user tables as their FKs are
20166 * recreated after the data has been loaded.
20167 */
20168
20169 query = createPQExpBuffer();
20170
20171 printfPQExpBuffer(query,
20172 "SELECT conrelid, confrelid "
20173 "FROM pg_constraint "
20174 "JOIN pg_depend ON (objid = confrelid) "
20175 "WHERE contype = 'f' "
20176 "AND refclassid = 'pg_extension'::regclass "
20177 "AND classid = 'pg_class'::regclass;");
20178
20179 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
20180 ntups = PQntuples(res);
20181
20182 i_conrelid = PQfnumber(res, "conrelid");
20183 i_confrelid = PQfnumber(res, "confrelid");
20184
20185 /* Now get the dependencies and register them */
20186 for (i = 0; i < ntups; i++)
20187 {
20188 Oid conrelid,
20189 confrelid;
20191 *contable;
20192
20193 conrelid = atooid(PQgetvalue(res, i, i_conrelid));
20194 confrelid = atooid(PQgetvalue(res, i, i_confrelid));
20195 contable = findTableByOid(conrelid);
20196 reftable = findTableByOid(confrelid);
20197
20198 if (reftable == NULL ||
20199 reftable->dataObj == NULL ||
20200 contable == NULL ||
20201 contable->dataObj == NULL)
20202 continue;
20203
20204 /*
20205 * Make referencing TABLE_DATA object depend on the referenced table's
20206 * TABLE_DATA object.
20207 */
20208 addObjectDependency(&contable->dataObj->dobj,
20209 reftable->dataObj->dobj.dumpId);
20210 }
20211 PQclear(res);
20212 destroyPQExpBuffer(query);
20213}
static SimpleOidList schema_exclude_oids
Definition pg_dump.c:170
static SimpleOidList extension_include_oids
Definition pg_dump.c:186
static SimpleOidList extension_exclude_oids
Definition pg_dump.c:189
static void makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo)
Definition pg_dump.c:3053
static SimpleOidList table_exclude_oids
Definition pg_dump.c:177
static SimpleOidList table_include_oids
Definition pg_dump.c:174
bool simple_oid_list_member(SimpleOidList *list, Oid val)
Definition simple_list.c:45
SimpleOidListCell * head
Definition simple_list.h:28

References addObjectDependency(), atooid, createPQExpBuffer(), PQExpBufferData::data, _tableInfo::dataObj, destroyPQExpBuffer(), _tableDataInfo::dobj, DUMP_COMPONENT_DATA, DUMP_COMPONENT_DEFINITION, _dumpableObject::dumpId, ExecuteSqlQuery(), _extensionInfo::extconfig, extension_exclude_oids, extension_include_oids, fb(), findTableByOid(), free, SimpleOidList::head, i, j, makeTableDataInfo(), 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 
)
extern

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 */
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, _catalogIdMapEntry::ext, and fb().

Referenced by getLOs().

◆ recordExtensionMembership()

void recordExtensionMembership ( CatalogId  catId,
ExtensionInfo ext 
)
extern

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 */
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, _catalogIdMapEntry::ext, and fb().

Referenced by getExtensionMembership().

◆ removeObjectDependency()

◆ shouldPrintColumn()

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

Definition at line 10155 of file pg_dump.c.

10156{
10157 if (dopt->binary_upgrade)
10158 return true;
10159 if (tbinfo->attisdropped[colno])
10160 return false;
10161 return (tbinfo->attislocal[colno] || tbinfo->ispartition);
10162}

References _dumpOptions::binary_upgrade, and fb().

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

◆ sortDumpableObjects()

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

Definition at line 559 of file pg_dump_sort.c.

561{
562 DumpableObject **ordering;
563 int nOrdering;
564
565 if (numObjs <= 0) /* can't happen anymore ... */
566 return;
567
568 /*
569 * Saving the boundary IDs in static variables is a bit grotty, but seems
570 * better than adding them to parameter lists of subsidiary functions.
571 */
574
575 ordering = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *));
576 while (!TopoSort(objs, numObjs, ordering, &nOrdering))
578
579 memcpy(objs, ordering, numObjs * sizeof(DumpableObject *));
580
581 free(ordering);
582}
static void findDependencyLoops(DumpableObject **objs, int nObjs, int totObjs)
static DumpId preDataBoundId
static bool TopoSort(DumpableObject **objs, int numObjs, DumpableObject **ordering, int *nOrdering)
static DumpId postDataBoundId

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

Referenced by main().

◆ sortDumpableObjectsByTypeName()

void sortDumpableObjectsByTypeName ( DumpableObject **  objs,
int  numObjs 
)
extern

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)
#define qsort(a, b, c, d)
Definition port.h:495

References DOTypeNameCompare(), fb(), and qsort.

Referenced by main().