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{
450 Oid relid;
452 char *reltuples;
455 char relkind; /* 'r', 'm', 'i', etc */
456
457 /*
458 * indAttNames/nindAttNames are populated only if the relation is an index
459 * with at least one expression column; we don't need them otherwise.
460 */
461 char **indAttNames; /* attnames of the index, in order */
462 int32 nindAttNames; /* number of attnames stored (can be 0) */
463 teSection section; /* stats may appear in data or post-data */
465
466typedef struct _statsExtInfo
467{
469 const char *rolname; /* owner */
470 TableInfo *stattable; /* link to table the stats are for */
471 int stattarget; /* statistics target */
473
474typedef struct _ruleInfo
475{
477 TableInfo *ruletable; /* link to table the rule is for */
478 char ev_type;
479 bool is_instead;
480 char ev_enabled;
481 bool separate; /* true if must dump as separate item */
482 /* separate is always true for non-ON SELECT rules */
483} RuleInfo;
484
485typedef struct _triggerInfo
486{
488 TableInfo *tgtable; /* link to table the trigger is for */
489 char tgenabled;
490 bool tgispartition;
491 char *tgdef;
493
494typedef struct _evttriggerInfo
495{
497 char *evtname;
498 char *evtevent;
499 const char *evtowner;
500 char *evttags;
501 char *evtfname;
502 char evtenabled;
504
505/*
506 * struct ConstraintInfo is used for all constraint types. However we
507 * use a different objType for foreign key constraints, to make it easier
508 * to sort them the way we want.
509 *
510 * Not-null constraints don't need this, unless they are NOT VALID.
511 *
512 * Note: condeferrable and condeferred are currently only valid for
513 * unique/primary-key constraints. Otherwise that info is in condef.
514 */
515typedef struct _constraintInfo
516{
518 TableInfo *contable; /* NULL if domain constraint */
519 TypeInfo *condomain; /* NULL if table constraint */
520 char contype;
521 char *condef; /* definition, if CHECK or FOREIGN KEY */
522 Oid confrelid; /* referenced table, if FOREIGN KEY */
523 DumpId conindex; /* identifies associated index if any */
524 bool condeferrable; /* true if constraint is DEFERRABLE */
525 bool condeferred; /* true if constraint is INITIALLY DEFERRED */
526 bool conperiod; /* true if the constraint is WITHOUT OVERLAPS */
527 bool conislocal; /* true if constraint has local definition */
528 bool separate; /* true if must dump as separate item */
530
531typedef struct _procLangInfo
532{
535 bool lanpltrusted;
539 const char *lanowner;
541
542typedef struct _castInfo
543{
548 char castcontext;
549 char castmethod;
550} CastInfo;
551
552typedef struct _transformInfo
553{
555 Oid trftype;
556 Oid trflang;
560
561/* InhInfo isn't a DumpableObject, just temporary state */
562typedef struct _inhInfo
563{
564 Oid inhrelid; /* OID of a child table */
565 Oid inhparent; /* OID of its parent */
566} InhInfo;
567
568typedef struct _prsInfo
569{
573 Oid prsend;
577
578typedef struct _dictInfo
579{
581 const char *rolname;
583 char *dictinitoption;
584} TSDictInfo;
585
586typedef struct _tmplInfo
587{
592
593typedef struct _cfgInfo
594{
596 const char *rolname;
599
600typedef struct _fdwInfo
601{
604 const char *rolname;
605 char *fdwhandler;
606 char *fdwvalidator;
607 char *fdwconnection;
608 char *fdwoptions;
609} FdwInfo;
610
611typedef struct _foreignServerInfo
612{
615 const char *rolname;
616 Oid srvfdw;
617 char *srvtype;
618 char *srvversion;
619 char *srvoptions;
621
622typedef struct _defaultACLInfo
623{
626 const char *defaclrole;
627 char defaclobjtype;
629
630/*
631 * LoInfo represents a group of large objects (blobs) that share the same
632 * owner and ACL setting. dobj.components has the DUMP_COMPONENT_COMMENT bit
633 * set if any blob in the group has a comment; similarly for sec labels.
634 * If there are many blobs with the same owner/ACL, we can divide them into
635 * multiple LoInfo groups, which will each spawn a BLOB METADATA and a BLOBS
636 * (data) TOC entry. This allows more parallelism during restore.
637 */
638typedef struct _loInfo
639{
642 const char *rolname;
643 int numlos;
645} LoInfo;
646
647/*
648 * The PolicyInfo struct is used to represent policies on a table and
649 * to indicate if a table has RLS enabled (ENABLE ROW SECURITY). If
650 * polname is NULL, then the record indicates ENABLE ROW SECURITY, while if
651 * it's non-NULL then this is a regular policy definition.
652 */
653typedef struct _policyInfo
654{
657 char *polname; /* null indicates RLS is enabled on rel */
658 char polcmd;
659 bool polpermissive;
660 char *polroles;
661 char *polqual;
662 char *polwithcheck;
663} PolicyInfo;
664
665/*
666 * The PublicationInfo struct is used to represent publications.
667 */
668typedef struct _PublicationInfo
669{
671 const char *rolname;
672 bool puballtables;
673 bool puballsequences;
674 bool pubinsert;
675 bool pubupdate;
676 bool pubdelete;
677 bool pubtruncate;
678 bool pubviaroot;
682
683/*
684 * The PublicationRelInfo struct is used to represent publication table
685 * mapping.
686 */
687typedef struct _PublicationRelInfo
688{
692 char *pubrelqual;
693 char *pubrattrs;
695
696/*
697 * The PublicationSchemaInfo struct is used to represent publication schema
698 * mapping.
699 */
700typedef struct _PublicationSchemaInfo
701{
706
707/*
708 * The SubscriptionInfo struct is used to represent subscription.
709 */
710typedef struct _SubscriptionInfo
711{
713 const char *rolname;
714 bool subenabled;
715 bool subbinary;
716 char substream;
717 char subtwophasestate;
718 bool subdisableonerr;
720 bool subrunasowner;
721 bool subfailover;
723 int submaxretention;
724 char *subservername;
725 char *subconninfo;
726 char *subslotname;
727 char *subsynccommit;
728 char *subwalrcvtimeout;
729 char *subpublications;
730 char *suborigin;
731 char *suboriginremotelsn;
733
734/*
735 * The SubRelInfo struct is used to represent a subscription relation.
736 *
737 * XXX Currently, the subscription tables are added to the subscription after
738 * enabling the subscription in binary-upgrade mode. As the apply workers will
739 * not be started in binary_upgrade mode the ordering of enable subscription
740 * does not matter. The order of adding the subscription tables to the
741 * subscription and enabling the subscription should be taken care of if this
742 * feature will be supported in a non-binary-upgrade mode in the future.
743 */
744typedef struct _SubRelInfo
745{
749 char srsubstate;
750 char *srsublsn;
751} SubRelInfo;
752
753/*
754 * common utility functions
755 */
756
758
759extern void AssignDumpId(DumpableObject *dobj);
760extern void recordAdditionalCatalogID(CatalogId catId, DumpableObject *dobj);
761extern DumpId createDumpId(void);
762extern DumpId getMaxDumpId(void);
765extern void getDumpableObjects(DumpableObject ***objs, int *numObjs);
766
769
770extern TableInfo *findTableByOid(Oid oid);
771extern TypeInfo *findTypeByOid(Oid oid);
772extern FuncInfo *findFuncByOid(Oid oid);
773extern OprInfo *findOprByOid(Oid oid);
775extern CollInfo *findCollationByOid(Oid oid);
780
781extern void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext);
783
784extern void parseOidArray(const char *str, Oid *array, int arraysize);
785
789
790/*
791 * version specific routines
792 */
793extern void getNamespaces(Archive *fout);
795extern void getTypes(Archive *fout);
796extern void getFuncs(Archive *fout);
797extern void getAggregates(Archive *fout);
798extern void getOperators(Archive *fout);
799extern void getAccessMethods(Archive *fout);
800extern void getOpclasses(Archive *fout);
801extern void getOpfamilies(Archive *fout);
802extern void getCollations(Archive *fout);
803extern void getConversions(Archive *fout);
805extern void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables);
807extern void getPartitioningInfo(Archive *fout);
808extern void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables);
810extern void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables);
811extern void getRules(Archive *fout);
812extern void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables);
813extern void getProcLangs(Archive *fout);
814extern void getCasts(Archive *fout);
815extern void getTransforms(Archive *fout);
816extern void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables);
817extern bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno);
818extern void getTSParsers(Archive *fout);
819extern void getTSDictionaries(Archive *fout);
820extern void getTSTemplates(Archive *fout);
821extern void getTSConfigurations(Archive *fout);
823extern void getForeignServers(Archive *fout);
824extern void getDefaultACLs(Archive *fout);
826 int numExtensions);
828 int numExtensions);
829extern void getEventTriggers(Archive *fout);
830extern void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables);
831extern void getPublications(Archive *fout);
833extern void getPublicationTables(Archive *fout, TableInfo tblinfo[],
834 int numTables);
835extern void getSubscriptions(Archive *fout);
837
838#endif /* PG_DUMP_H */
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:617
int32_t int32
Definition c.h:679
uint32_t uint32
Definition c.h:683
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:8219
struct _collInfo CollInfo
void recordAdditionalCatalogID(CatalogId catId, DumpableObject *dobj)
Definition common.c:722
struct _transformInfo TransformInfo
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition pg_dump.c:6169
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition common.c:1066
void getPublicationNamespaces(Archive *fout)
Definition pg_dump.c:4758
struct _opfamilyInfo OpfamilyInfo
void getPartitioningInfo(Archive *fout)
Definition pg_dump.c:7716
struct _indxInfo IndxInfo
struct _fdwInfo FdwInfo
struct _triggerInfo TriggerInfo
struct _tmplInfo TSTemplateInfo
struct _tableInfo TableInfo
FuncInfo * findFuncByOid(Oid oid)
Definition common.c:921
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition pg_dump.c:7660
TableInfo * findTableByOid(Oid oid)
Definition common.c:866
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10338
struct _aggInfo AggInfo
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4187
ExtensionInfo * findExtensionByOid(Oid oid)
Definition common.c:1011
struct _castInfo CastInfo
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:19897
CollInfo * findCollationByOid(Oid oid)
Definition common.c:975
struct _tableDataInfo TableDataInfo
struct _cfgInfo TSConfigInfo
SubscriptionInfo * findSubscriptionByOid(Oid oid)
Definition common.c:1047
void getTypes(Archive *fout)
Definition pg_dump.c:6244
struct _dumpableObject DumpableObject
struct _accessMethodInfo AccessMethodInfo
struct _attrDefInfo AttrDefInfo
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7595
void getOpclasses(Archive *fout)
Definition pg_dump.c:6678
void getForeignServers(Archive *fout)
Definition pg_dump.c:10432
void getFuncs(Archive *fout)
Definition pg_dump.c:6921
OprInfo * findOprByOid(Oid oid)
Definition common.c:939
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10154
struct _ruleInfo RuleInfo
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4838
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition common.c:993
struct _relStatsInfo RelStatsInfo
void getCasts(Archive *fout)
Definition pg_dump.c:8964
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7776
AccessMethodInfo * findAccessMethodByOid(Oid oid)
Definition common.c:957
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:821
void getTSConfigurations(Archive *fout)
Definition pg_dump.c:10279
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition common.c:768
struct _foreignServerInfo ForeignServerInfo
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition common.c:1114
struct _inhInfo InhInfo
struct _indexAttachInfo IndexAttachInfo
struct _SubRelInfo SubRelInfo
struct _procLangInfo ProcLangInfo
void getAccessMethods(Archive *fout)
Definition pg_dump.c:6616
void getConversions(Archive *fout)
Definition pg_dump.c:6554
void getRules(Archive *fout)
Definition pg_dump.c:8513
ExtensionInfo * findOwningExtension(CatalogId catalogId)
Definition common.c:1090
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9154
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:6488
struct _namespaceInfo NamespaceInfo
void getAggregates(Archive *fout)
Definition pg_dump.c:6806
struct _shellTypeInfo ShellTypeInfo
void getNamespaces(Archive *fout)
Definition pg_dump.c:6037
void getPublications(Archive *fout)
Definition pg_dump.c:4470
void getTSParsers(Archive *fout)
Definition pg_dump.c:10080
TypeInfo * findTypeByOid(Oid oid)
Definition common.c:902
struct _dumpableObjectWithAcl DumpableObjectWithAcl
struct _defaultACLInfo DefaultACLInfo
DumpId createDumpId(void)
Definition common.c:748
TableInfo * getTables(Archive *fout, int *numTables)
Definition pg_dump.c:7151
struct _loInfo LoInfo
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition common.c:781
void AssignDumpId(DumpableObject *dobj)
Definition common.c:660
struct _evttriggerInfo EventTriggerInfo
void getExtendedStatistics(Archive *fout)
Definition pg_dump.c:8141
struct _dumpableAcl DumpableAcl
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:19990
DumpId getMaxDumpId(void)
Definition common.c:757
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10520
uint32 DumpComponents
Definition pg_dump.h:107
struct _typeInfo TypeInfo
void getSubscriptions(Archive *fout)
Definition pg_dump.c:5113
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:800
struct _statsExtInfo StatsExtInfo
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8610
void getTransforms(Archive *fout)
Definition pg_dump.c:9074
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8806
DumpableObjectType
Definition pg_dump.h:39
struct _PublicationRelInfo PublicationRelInfo
PublicationInfo * findPublicationByOid(Oid oid)
Definition common.c:1029
void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs)
struct _convInfo ConvInfo
struct _constraintInfo ConstraintInfo
void getTSTemplates(Archive *fout)
Definition pg_dump.c:10220
void getProcLangs(Archive *fout)
Definition pg_dump.c:8880
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition pg_dump.c:10065
void getSubscriptionRelations(Archive *fout)
Definition pg_dump.c:5362
struct _tableAttachInfo TableAttachInfo
void removeObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:846
void getOperators(Archive *fout)
Definition pg_dump.c:6412
void getOpfamilies(Archive *fout)
Definition pg_dump.c:6741
struct _oprInfo OprInfo
struct _PublicationSchemaInfo PublicationSchemaInfo
unsigned int Oid
static int fb(int x)
const char * rolname
Definition pg_dump.h:672
SimplePtrList except_tables
Definition pg_dump.h:681
bool puballsequences
Definition pg_dump.h:674
PublishGencolsType pubgencols_type
Definition pg_dump.h:680
DumpableObject dobj
Definition pg_dump.h:671
TableInfo * pubtable
Definition pg_dump.h:692
PublicationInfo * publication
Definition pg_dump.h:691
DumpableObject dobj
Definition pg_dump.h:690
NamespaceInfo * pubschema
Definition pg_dump.h:705
DumpableObject dobj
Definition pg_dump.h:703
PublicationInfo * publication
Definition pg_dump.h:704
DumpableObject dobj
Definition pg_dump.h:747
char * srsublsn
Definition pg_dump.h:751
SubscriptionInfo * subinfo
Definition pg_dump.h:748
TableInfo * tblinfo
Definition pg_dump.h:749
char srsubstate
Definition pg_dump.h:750
char * suboriginremotelsn
Definition pg_dump.h:732
bool subpasswordrequired
Definition pg_dump.h:720
const char * rolname
Definition pg_dump.h:714
char * subservername
Definition pg_dump.h:725
char * subsynccommit
Definition pg_dump.h:728
char * subpublications
Definition pg_dump.h:730
char * subwalrcvtimeout
Definition pg_dump.h:729
char * subslotname
Definition pg_dump.h:727
char subtwophasestate
Definition pg_dump.h:718
bool subretaindeadtuples
Definition pg_dump.h:723
char * subconninfo
Definition pg_dump.h:726
DumpableObject dobj
Definition pg_dump.h:713
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:550
Oid casttarget
Definition pg_dump.h:547
char castcontext
Definition pg_dump.h:549
DumpableObject dobj
Definition pg_dump.h:545
Oid castsource
Definition pg_dump.h:546
Oid castfunc
Definition pg_dump.h:548
Oid cfgparser
Definition pg_dump.h:598
DumpableObject dobj
Definition pg_dump.h:596
const char * rolname
Definition pg_dump.h:597
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:520
TableInfo * contable
Definition pg_dump.h:519
DumpableObject dobj
Definition pg_dump.h:518
DumpId conindex
Definition pg_dump.h:524
bool condeferrable
Definition pg_dump.h:525
char * condef
Definition pg_dump.h:522
DumpableObject dobj
Definition pg_dump.h:298
const char * rolname
Definition pg_dump.h:299
DumpableObject dobj
Definition pg_dump.h:625
DumpableAcl dacl
Definition pg_dump.h:626
const char * defaclrole
Definition pg_dump.h:627
char defaclobjtype
Definition pg_dump.h:628
char * dictinitoption
Definition pg_dump.h:584
DumpableObject dobj
Definition pg_dump.h:581
const char * rolname
Definition pg_dump.h:582
Oid dicttemplate
Definition pg_dump.h:583
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:499
char * evtfname
Definition pg_dump.h:502
char * evtname
Definition pg_dump.h:498
const char * evtowner
Definition pg_dump.h:500
char * evttags
Definition pg_dump.h:501
DumpableObject dobj
Definition pg_dump.h:497
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:606
const char * rolname
Definition pg_dump.h:605
char * fdwvalidator
Definition pg_dump.h:607
char * fdwoptions
Definition pg_dump.h:609
DumpableAcl dacl
Definition pg_dump.h:604
char * fdwconnection
Definition pg_dump.h:608
DumpableObject dobj
Definition pg_dump.h:603
DumpableAcl dacl
Definition pg_dump.h:615
DumpableObject dobj
Definition pg_dump.h:614
const char * rolname
Definition pg_dump.h:616
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:566
Oid inhrelid
Definition pg_dump.h:565
const char * rolname
Definition pg_dump.h:643
DumpableObject dobj
Definition pg_dump.h:641
DumpableAcl dacl
Definition pg_dump.h:642
Oid looids[FLEXIBLE_ARRAY_MEMBER]
Definition pg_dump.h:645
int numlos
Definition pg_dump.h:644
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:657
char * polqual
Definition pg_dump.h:662
char polcmd
Definition pg_dump.h:659
char * polroles
Definition pg_dump.h:661
char * polwithcheck
Definition pg_dump.h:663
DumpableObject dobj
Definition pg_dump.h:656
bool polpermissive
Definition pg_dump.h:660
char * polname
Definition pg_dump.h:658
Oid lanvalidator
Definition pg_dump.h:539
DumpableAcl dacl
Definition pg_dump.h:535
DumpableObject dobj
Definition pg_dump.h:534
const char * lanowner
Definition pg_dump.h:540
Oid lanplcallfoid
Definition pg_dump.h:537
bool lanpltrusted
Definition pg_dump.h:536
DumpableObject dobj
Definition pg_dump.h:571
Oid prstoken
Definition pg_dump.h:573
Oid prslextype
Definition pg_dump.h:576
Oid prsheadline
Definition pg_dump.h:575
Oid prsstart
Definition pg_dump.h:572
Oid prsend
Definition pg_dump.h:574
int32 nindAttNames
Definition pg_dump.h:463
char ** indAttNames
Definition pg_dump.h:462
int32 relpages
Definition pg_dump.h:452
int32 relallfrozen
Definition pg_dump.h:455
char * reltuples
Definition pg_dump.h:453
teSection section
Definition pg_dump.h:464
int32 relallvisible
Definition pg_dump.h:454
DumpableObject dobj
Definition pg_dump.h:450
DumpableObject dobj
Definition pg_dump.h:477
bool separate
Definition pg_dump.h:482
char ev_enabled
Definition pg_dump.h:481
bool is_instead
Definition pg_dump.h:480
TableInfo * ruletable
Definition pg_dump.h:478
char ev_type
Definition pg_dump.h:479
TypeInfo * baseType
Definition pg_dump.h:236
DumpableObject dobj
Definition pg_dump.h:234
TableInfo * stattable
Definition pg_dump.h:471
const char * rolname
Definition pg_dump.h:470
DumpableObject dobj
Definition pg_dump.h:469
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:591
Oid tmplinit
Definition pg_dump.h:590
DumpableObject dobj
Definition pg_dump.h:589
DumpableObject dobj
Definition pg_dump.h:555
TableInfo * tgtable
Definition pg_dump.h:489
DumpableObject dobj
Definition pg_dump.h:488
char tgenabled
Definition pg_dump.h:490
char * tgdef
Definition pg_dump.h:492
bool tgispartition
Definition pg_dump.h:491
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 660 of file common.c.

661{
662 dobj->dumpId = ++lastDumpId;
663 dobj->name = NULL; /* must be set later */
664 dobj->namespace = NULL; /* may be set later */
665 dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
666 dobj->dump_contains = DUMP_COMPONENT_ALL; /* default assumption */
667 /* All objects have definitions; we may set more components bits later */
669 dobj->ext_member = false; /* default assumption */
670 dobj->depends_on_ext = false; /* default assumption */
671 dobj->dependencies = NULL;
672 dobj->nDeps = 0;
673 dobj->allocDeps = 0;
674
675 /* Add object to dumpIdMap[], enlarging that array if need be */
676 while (dobj->dumpId >= allocedDumpIds)
677 {
678 int newAlloc;
679
680 if (allocedDumpIds <= 0)
681 {
682 newAlloc = 256;
684 }
685 else
686 {
689 }
691 (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
693 }
694 dumpIdMap[dobj->dumpId] = dobj;
695
696 /* If it has a valid CatalogId, enter it into the hash table */
697 if (OidIsValid(dobj->catId.tableoid))
698 {
699 CatalogIdMapEntry *entry;
700 bool found;
701
702 /* Initialize CatalogId hash table if not done yet */
703 if (catalogIdHash == NULL)
705
706 entry = catalogid_insert(catalogIdHash, dobj->catId, &found);
707 if (!found)
708 {
709 entry->dobj = NULL;
710 entry->ext = NULL;
711 }
712 Assert(entry->dobj == NULL);
713 entry->dobj = dobj;
714 }
715}
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:1002
#define OidIsValid(objectId)
Definition c.h:917
#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 957 of file common.c.

958{
959 CatalogId catId;
960 DumpableObject *dobj;
961
963 catId.oid = oid;
964 dobj = findObjectByCatalogId(catId);
965 Assert(dobj == NULL || dobj->objType == DO_ACCESS_METHOD);
966 return (AccessMethodInfo *) dobj;
967}
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition common.c:781
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 975 of file common.c.

976{
977 CatalogId catId;
978 DumpableObject *dobj;
979
981 catId.oid = oid;
982 dobj = findObjectByCatalogId(catId);
983 Assert(dobj == NULL || dobj->objType == DO_COLLATION);
984 return (CollInfo *) dobj;
985}

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

1012{
1013 CatalogId catId;
1014 DumpableObject *dobj;
1015
1017 catId.oid = oid;
1018 dobj = findObjectByCatalogId(catId);
1019 Assert(dobj == NULL || dobj->objType == DO_EXTENSION);
1020 return (ExtensionInfo *) dobj;
1021}

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

922{
923 CatalogId catId;
924 DumpableObject *dobj;
925
927 catId.oid = oid;
928 dobj = findObjectByCatalogId(catId);
929 Assert(dobj == NULL || dobj->objType == DO_FUNC);
930 return (FuncInfo *) dobj;
931}

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

994{
995 CatalogId catId;
996 DumpableObject *dobj;
997
999 catId.oid = oid;
1000 dobj = findObjectByCatalogId(catId);
1001 Assert(dobj == NULL || dobj->objType == DO_NAMESPACE);
1002 return (NamespaceInfo *) dobj;
1003}

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

769{
771 return NULL; /* out of range? */
772 return dumpIdMap[dumpId];
773}

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

940{
941 CatalogId catId;
942 DumpableObject *dobj;
943
945 catId.oid = oid;
946 dobj = findObjectByCatalogId(catId);
947 Assert(dobj == NULL || dobj->objType == DO_OPERATOR);
948 return (OprInfo *) dobj;
949}

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

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

References catalogIdHash, _catalogIdMapEntry::ext, and fb().

Referenced by checkExtensionMembership().

◆ findPublicationByOid()

PublicationInfo * findPublicationByOid ( Oid  oid)
extern

Definition at line 1029 of file common.c.

1030{
1031 CatalogId catId;
1032 DumpableObject *dobj;
1033
1035 catId.oid = oid;
1036 dobj = findObjectByCatalogId(catId);
1037 Assert(dobj == NULL || dobj->objType == DO_PUBLICATION);
1038 return (PublicationInfo *) dobj;
1039}

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

1048{
1049 CatalogId catId;
1050 DumpableObject *dobj;
1051
1053 catId.oid = oid;
1054 dobj = findObjectByCatalogId(catId);
1055 Assert(dobj == NULL || dobj->objType == DO_SUBSCRIPTION);
1056 return (SubscriptionInfo *) dobj;
1057}

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

6617{
6618 PGresult *res;
6619 int ntups;
6620 int i;
6621 PQExpBuffer query;
6623 int i_tableoid;
6624 int i_oid;
6625 int i_amname;
6626 int i_amhandler;
6627 int i_amtype;
6628
6629 query = createPQExpBuffer();
6630
6631 /*
6632 * Select all access methods from pg_am table.
6633 */
6634 appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, ");
6636 "amtype, "
6637 "amhandler::pg_catalog.regproc AS amhandler ");
6638 appendPQExpBufferStr(query, "FROM pg_am");
6639
6640 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6641
6642 ntups = PQntuples(res);
6643
6645
6646 i_tableoid = PQfnumber(res, "tableoid");
6647 i_oid = PQfnumber(res, "oid");
6648 i_amname = PQfnumber(res, "amname");
6649 i_amhandler = PQfnumber(res, "amhandler");
6650 i_amtype = PQfnumber(res, "amtype");
6651
6652 for (i = 0; i < ntups; i++)
6653 {
6654 aminfo[i].dobj.objType = DO_ACCESS_METHOD;
6655 aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6656 aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6657 AssignDumpId(&aminfo[i].dobj);
6658 aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
6659 aminfo[i].dobj.namespace = NULL;
6660 aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
6661 aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
6662
6663 /* Decide whether we want to dump it */
6665 }
6666
6667 PQclear(res);
6668
6669 destroyPQExpBuffer(query);
6670}
void AssignDumpId(DumpableObject *dobj)
Definition common.c:660
int PQfnumber(const PGresult *res, const char *field_name)
Definition fe-exec.c:3620
char * pg_strdup(const char *in)
Definition fe_memutils.c:91
int i
Definition isn.c:77
#define PQgetvalue
#define PQclear
#define PQntuples
@ PGRES_TUPLES_OK
Definition libpq-fe.h:134
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition pg_dump.c:2213
#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_array, pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableAccessMethod().

Referenced by getSchemaData().

◆ getAggregates()

void getAggregates ( Archive fout)
extern

Definition at line 6806 of file pg_dump.c.

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

Referenced by getSchemaData().

◆ getCasts()

void getCasts ( Archive fout)
extern

Definition at line 8964 of file pg_dump.c.

8965{
8966 PGresult *res;
8967 int ntups;
8968 int i;
8971 int i_tableoid;
8972 int i_oid;
8973 int i_castsource;
8974 int i_casttarget;
8975 int i_castfunc;
8976 int i_castcontext;
8977 int i_castmethod;
8978
8979 if (fout->remoteVersion >= 140000)
8980 {
8981 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8982 "castsource, casttarget, castfunc, castcontext, "
8983 "castmethod "
8984 "FROM pg_cast c "
8985 "WHERE NOT EXISTS ( "
8986 "SELECT 1 FROM pg_range r "
8987 "WHERE c.castsource = r.rngtypid "
8988 "AND c.casttarget = r.rngmultitypid "
8989 ") "
8990 "ORDER BY 3,4");
8991 }
8992 else
8993 {
8994 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8995 "castsource, casttarget, castfunc, castcontext, "
8996 "castmethod "
8997 "FROM pg_cast ORDER BY 3,4");
8998 }
8999
9000 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9001
9002 ntups = PQntuples(res);
9003
9005
9006 i_tableoid = PQfnumber(res, "tableoid");
9007 i_oid = PQfnumber(res, "oid");
9008 i_castsource = PQfnumber(res, "castsource");
9009 i_casttarget = PQfnumber(res, "casttarget");
9010 i_castfunc = PQfnumber(res, "castfunc");
9011 i_castcontext = PQfnumber(res, "castcontext");
9012 i_castmethod = PQfnumber(res, "castmethod");
9013
9014 for (i = 0; i < ntups; i++)
9015 {
9019
9021 castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9022 castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9023 AssignDumpId(&castinfo[i].dobj);
9024 castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
9025 castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
9026 castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
9027 castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
9028 castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
9029
9030 /*
9031 * Try to name cast as concatenation of typnames. This is only used
9032 * for purposes of sorting. If we fail to find either type, the name
9033 * will be an empty string.
9034 */
9036 sTypeInfo = findTypeByOid(castinfo[i].castsource);
9037 tTypeInfo = findTypeByOid(castinfo[i].casttarget);
9038 if (sTypeInfo && tTypeInfo)
9039 appendPQExpBuffer(&namebuf, "%s %s",
9040 sTypeInfo->dobj.name, tTypeInfo->dobj.name);
9041 castinfo[i].dobj.name = namebuf.data;
9042
9043 /* Decide whether we want to dump it */
9045 }
9046
9047 PQclear(res);
9048
9049 destroyPQExpBuffer(query);
9050}
TypeInfo * findTypeByOid(Oid oid)
Definition common.c:902
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition pg_dump.c:2156
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_array, PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableCast().

Referenced by getSchemaData().

◆ getCollations()

void getCollations ( Archive fout)
extern

Definition at line 6488 of file pg_dump.c.

6489{
6490 PGresult *res;
6491 int ntups;
6492 int i;
6493 PQExpBuffer query;
6495 int i_tableoid;
6496 int i_oid;
6497 int i_collname;
6498 int i_collnamespace;
6499 int i_collowner;
6500 int i_collencoding;
6501
6502 query = createPQExpBuffer();
6503
6504 /*
6505 * find all collations, including builtin collations; we filter out
6506 * system-defined collations at dump-out time.
6507 */
6508
6509 appendPQExpBufferStr(query, "SELECT tableoid, oid, collname, "
6510 "collnamespace, "
6511 "collowner, "
6512 "collencoding "
6513 "FROM pg_collation");
6514
6515 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6516
6517 ntups = PQntuples(res);
6518
6520
6521 i_tableoid = PQfnumber(res, "tableoid");
6522 i_oid = PQfnumber(res, "oid");
6523 i_collname = PQfnumber(res, "collname");
6524 i_collnamespace = PQfnumber(res, "collnamespace");
6525 i_collowner = PQfnumber(res, "collowner");
6526 i_collencoding = PQfnumber(res, "collencoding");
6527
6528 for (i = 0; i < ntups; i++)
6529 {
6530 collinfo[i].dobj.objType = DO_COLLATION;
6531 collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6532 collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6533 AssignDumpId(&collinfo[i].dobj);
6534 collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
6535 collinfo[i].dobj.namespace =
6537 collinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_collowner));
6538 collinfo[i].collencoding = atoi(PQgetvalue(res, i, i_collencoding));
6539
6540 /* Decide whether we want to dump it */
6542 }
6543
6544 PQclear(res);
6545
6546 destroyPQExpBuffer(query);
6547}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_COLLATION, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc_array, 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 8219 of file pg_dump.c.

8220{
8223 PGresult *res;
8224 int ntups;
8225 int curtblindx;
8228 int i_contableoid,
8229 i_conoid,
8230 i_conrelid,
8231 i_conname,
8233 i_conindid,
8234 i_condef;
8235
8236 /*
8237 * We want to perform just one query against pg_constraint. However, we
8238 * mustn't try to select every row of the catalog and then sort it out on
8239 * the client side, because some of the server-side functions we need
8240 * would be unsafe to apply to tables we don't have lock on. Hence, we
8241 * build an array of the OIDs of tables we care about (and now have lock
8242 * on!), and use a WHERE clause to constrain which rows are selected.
8243 */
8245 for (int i = 0; i < numTables; i++)
8246 {
8247 TableInfo *tinfo = &tblinfo[i];
8248
8249 if (!(tinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
8250 continue;
8251
8252 /* OK, we need info for this table */
8253 if (tbloids->len > 1) /* do we have more than the '{'? */
8255 appendPQExpBuffer(tbloids, "%u", tinfo->dobj.catId.oid);
8256 }
8258
8260 "SELECT c.tableoid, c.oid, "
8261 "conrelid, conname, confrelid, ");
8262 if (fout->remoteVersion >= 110000)
8263 appendPQExpBufferStr(query, "conindid, ");
8264 else
8265 appendPQExpBufferStr(query, "0 AS conindid, ");
8266 appendPQExpBuffer(query,
8267 "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
8268 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8269 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
8270 "WHERE contype = 'f' ",
8271 tbloids->data);
8272 if (fout->remoteVersion >= 110000)
8274 "AND conparentid = 0 ");
8276 "ORDER BY conrelid, conname");
8277
8278 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8279
8280 ntups = PQntuples(res);
8281
8282 i_contableoid = PQfnumber(res, "tableoid");
8283 i_conoid = PQfnumber(res, "oid");
8284 i_conrelid = PQfnumber(res, "conrelid");
8285 i_conname = PQfnumber(res, "conname");
8286 i_confrelid = PQfnumber(res, "confrelid");
8287 i_conindid = PQfnumber(res, "conindid");
8288 i_condef = PQfnumber(res, "condef");
8289
8291
8292 curtblindx = -1;
8293 for (int j = 0; j < ntups; j++)
8294 {
8295 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
8297
8298 /*
8299 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8300 * order.
8301 */
8302 if (tbinfo == NULL || tbinfo->dobj.catId.oid != conrelid)
8303 {
8304 while (++curtblindx < numTables)
8305 {
8306 tbinfo = &tblinfo[curtblindx];
8307 if (tbinfo->dobj.catId.oid == conrelid)
8308 break;
8309 }
8310 if (curtblindx >= numTables)
8311 pg_fatal("unrecognized table OID %u", conrelid);
8312 }
8313
8314 constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
8315 constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
8316 constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
8317 AssignDumpId(&constrinfo[j].dobj);
8318 constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
8319 constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
8320 constrinfo[j].contable = tbinfo;
8321 constrinfo[j].condomain = NULL;
8322 constrinfo[j].contype = 'f';
8323 constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
8324 constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
8325 constrinfo[j].conindex = 0;
8326 constrinfo[j].condeferrable = false;
8327 constrinfo[j].condeferred = false;
8328 constrinfo[j].conislocal = true;
8329 constrinfo[j].separate = true;
8330
8331 /*
8332 * Restoring an FK that points to a partitioned table requires that
8333 * all partition indexes have been attached beforehand. Ensure that
8334 * happens by making the constraint depend on each index partition
8335 * attach object.
8336 */
8337 reftable = findTableByOid(constrinfo[j].confrelid);
8338 if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
8339 {
8340 Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
8341
8342 if (indexOid != InvalidOid)
8343 {
8344 for (int k = 0; k < reftable->numIndexes; k++)
8345 {
8347
8348 /* not our index? */
8349 if (reftable->indexes[k].dobj.catId.oid != indexOid)
8350 continue;
8351
8352 refidx = &reftable->indexes[k];
8354 break;
8355 }
8356 }
8357 }
8358 }
8359
8360 PQclear(res);
8361
8362 destroyPQExpBuffer(query);
8364}
TableInfo * findTableByOid(Oid oid)
Definition common.c:866
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:8378

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_array, pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and tinfo.

Referenced by getSchemaData().

◆ getConversions()

void getConversions ( Archive fout)
extern

Definition at line 6554 of file pg_dump.c.

6555{
6556 PGresult *res;
6557 int ntups;
6558 int i;
6559 PQExpBuffer query;
6561 int i_tableoid;
6562 int i_oid;
6563 int i_conname;
6564 int i_connamespace;
6565 int i_conowner;
6566
6567 query = createPQExpBuffer();
6568
6569 /*
6570 * find all conversions, including builtin conversions; we filter out
6571 * system-defined conversions at dump-out time.
6572 */
6573
6574 appendPQExpBufferStr(query, "SELECT tableoid, oid, conname, "
6575 "connamespace, "
6576 "conowner "
6577 "FROM pg_conversion");
6578
6579 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6580
6581 ntups = PQntuples(res);
6582
6584
6585 i_tableoid = PQfnumber(res, "tableoid");
6586 i_oid = PQfnumber(res, "oid");
6587 i_conname = PQfnumber(res, "conname");
6588 i_connamespace = PQfnumber(res, "connamespace");
6589 i_conowner = PQfnumber(res, "conowner");
6590
6591 for (i = 0; i < ntups; i++)
6592 {
6593 convinfo[i].dobj.objType = DO_CONVERSION;
6594 convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6595 convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6596 AssignDumpId(&convinfo[i].dobj);
6597 convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
6598 convinfo[i].dobj.namespace =
6600 convinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_conowner));
6601
6602 /* Decide whether we want to dump it */
6604 }
6605
6606 PQclear(res);
6607
6608 destroyPQExpBuffer(query);
6609}

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

Referenced by getSchemaData().

◆ getDefaultACLs()

void getDefaultACLs ( Archive fout)
extern

Definition at line 10520 of file pg_dump.c.

10521{
10522 DumpOptions *dopt = fout->dopt;
10524 PQExpBuffer query;
10525 PGresult *res;
10526 int i_oid;
10527 int i_tableoid;
10528 int i_defaclrole;
10530 int i_defaclobjtype;
10531 int i_defaclacl;
10532 int i_acldefault;
10533 int i,
10534 ntups;
10535
10536 query = createPQExpBuffer();
10537
10538 /*
10539 * Global entries (with defaclnamespace=0) replace the hard-wired default
10540 * ACL for their object type. We should dump them as deltas from the
10541 * default ACL, since that will be used as a starting point for
10542 * interpreting the ALTER DEFAULT PRIVILEGES commands. On the other hand,
10543 * non-global entries can only add privileges not revoke them. We must
10544 * dump those as-is (i.e., as deltas from an empty ACL).
10545 *
10546 * We can use defaclobjtype as the object type for acldefault(), except
10547 * for the case of 'S' (DEFACLOBJ_SEQUENCE) which must be converted to
10548 * 's'.
10549 */
10551 "SELECT oid, tableoid, "
10552 "defaclrole, "
10553 "defaclnamespace, "
10554 "defaclobjtype, "
10555 "defaclacl, "
10556 "CASE WHEN defaclnamespace = 0 THEN "
10557 "acldefault(CASE WHEN defaclobjtype = 'S' "
10558 "THEN 's'::\"char\" ELSE defaclobjtype END, "
10559 "defaclrole) ELSE '{}' END AS acldefault "
10560 "FROM pg_default_acl");
10561
10562 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10563
10564 ntups = PQntuples(res);
10565
10567
10568 i_oid = PQfnumber(res, "oid");
10569 i_tableoid = PQfnumber(res, "tableoid");
10570 i_defaclrole = PQfnumber(res, "defaclrole");
10571 i_defaclnamespace = PQfnumber(res, "defaclnamespace");
10572 i_defaclobjtype = PQfnumber(res, "defaclobjtype");
10573 i_defaclacl = PQfnumber(res, "defaclacl");
10574 i_acldefault = PQfnumber(res, "acldefault");
10575
10576 for (i = 0; i < ntups; i++)
10577 {
10579
10580 daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
10581 daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10582 daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10583 AssignDumpId(&daclinfo[i].dobj);
10584 /* cheesy ... is it worth coming up with a better object name? */
10585 daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
10586
10587 if (nspid != InvalidOid)
10588 daclinfo[i].dobj.namespace = findNamespace(nspid);
10589 else
10590 daclinfo[i].dobj.namespace = NULL;
10591
10592 daclinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
10593 daclinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10594 daclinfo[i].dacl.privtype = 0;
10595 daclinfo[i].dacl.initprivs = NULL;
10596 daclinfo[i].defaclrole = getRoleName(PQgetvalue(res, i, i_defaclrole));
10597 daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
10598
10599 /* Default ACLs are ACLs, of course */
10600 daclinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10601
10602 /* Decide whether we want to dump it */
10604 }
10605
10606 PQclear(res);
10607
10608 destroyPQExpBuffer(query);
10609}
int nspid
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition pg_dump.c:2134

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_DEFAULT_ACL, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, InvalidOid, nspid, pg_malloc_array, 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 800 of file common.c.

801{
802 int i,
803 j;
804
806 j = 0;
807 for (i = 1; i < allocedDumpIds; i++)
808 {
809 if (dumpIdMap[i])
810 (*objs)[j++] = dumpIdMap[i];
811 }
812 *numObjs = j;
813}

References allocedDumpIds, dumpIdMap, fb(), i, j, and pg_malloc_array.

Referenced by getTableDataFKConstraints(), and main().

◆ getEventTriggers()

void getEventTriggers ( Archive fout)
extern

Definition at line 8806 of file pg_dump.c.

8807{
8808 int i;
8809 PQExpBuffer query;
8810 PGresult *res;
8812 int i_tableoid,
8813 i_oid,
8814 i_evtname,
8815 i_evtevent,
8816 i_evtowner,
8817 i_evttags,
8818 i_evtfname,
8820 int ntups;
8821
8822 query = createPQExpBuffer();
8823
8825 "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8826 "evtevent, evtowner, "
8827 "array_to_string(array("
8828 "select quote_literal(x) "
8829 " from unnest(evttags) as t(x)), ', ') as evttags, "
8830 "e.evtfoid::regproc as evtfname "
8831 "FROM pg_event_trigger e "
8832 "ORDER BY e.oid");
8833
8834 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8835
8836 ntups = PQntuples(res);
8837
8839
8840 i_tableoid = PQfnumber(res, "tableoid");
8841 i_oid = PQfnumber(res, "oid");
8842 i_evtname = PQfnumber(res, "evtname");
8843 i_evtevent = PQfnumber(res, "evtevent");
8844 i_evtowner = PQfnumber(res, "evtowner");
8845 i_evttags = PQfnumber(res, "evttags");
8846 i_evtfname = PQfnumber(res, "evtfname");
8847 i_evtenabled = PQfnumber(res, "evtenabled");
8848
8849 for (i = 0; i < ntups; i++)
8850 {
8851 evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
8852 evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8853 evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8854 AssignDumpId(&evtinfo[i].dobj);
8855 evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
8856 evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
8857 evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
8858 evtinfo[i].evtowner = getRoleName(PQgetvalue(res, i, i_evtowner));
8859 evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
8860 evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
8861 evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
8862
8863 /* Decide whether we want to dump it */
8865 }
8866
8867 PQclear(res);
8868
8869 destroyPQExpBuffer(query);
8870}

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

Referenced by getSchemaData().

◆ getExtendedStatistics()

void getExtendedStatistics ( Archive fout)
extern

Definition at line 8141 of file pg_dump.c.

8142{
8143 PQExpBuffer query;
8144 PGresult *res;
8146 int ntups;
8147 int i_tableoid;
8148 int i_oid;
8149 int i_stxname;
8150 int i_stxnamespace;
8151 int i_stxowner;
8152 int i_stxrelid;
8153 int i_stattarget;
8154 int i;
8155
8156 query = createPQExpBuffer();
8157
8158 if (fout->remoteVersion < 130000)
8159 appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
8160 "stxnamespace, stxowner, stxrelid, NULL AS stxstattarget "
8161 "FROM pg_catalog.pg_statistic_ext");
8162 else
8163 appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
8164 "stxnamespace, stxowner, stxrelid, stxstattarget "
8165 "FROM pg_catalog.pg_statistic_ext");
8166
8167 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8168
8169 ntups = PQntuples(res);
8170
8171 i_tableoid = PQfnumber(res, "tableoid");
8172 i_oid = PQfnumber(res, "oid");
8173 i_stxname = PQfnumber(res, "stxname");
8174 i_stxnamespace = PQfnumber(res, "stxnamespace");
8175 i_stxowner = PQfnumber(res, "stxowner");
8176 i_stxrelid = PQfnumber(res, "stxrelid");
8177 i_stattarget = PQfnumber(res, "stxstattarget");
8178
8180
8181 for (i = 0; i < ntups; i++)
8182 {
8183 statsextinfo[i].dobj.objType = DO_STATSEXT;
8184 statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8185 statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8186 AssignDumpId(&statsextinfo[i].dobj);
8187 statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
8188 statsextinfo[i].dobj.namespace =
8190 statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
8191 statsextinfo[i].stattable =
8193 if (PQgetisnull(res, i, i_stattarget))
8194 statsextinfo[i].stattarget = -1;
8195 else
8196 statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
8197
8198 /* Decide whether we want to dump it */
8200
8201 if (fout->dopt->dumpStatistics)
8202 statsextinfo[i].dobj.components |= DUMP_COMPONENT_STATISTICS;
8203 }
8204
8205 PQclear(res);
8206 destroyPQExpBuffer(query);
8207}
static void selectDumpableStatisticsObject(StatsExtInfo *sobj, Archive *fout)
Definition pg_dump.c:2298

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_STATSEXT, DUMP_COMPONENT_STATISTICS, ExecuteSqlQuery(), fb(), findNamespace(), findTableByOid(), getRoleName(), i, pg_malloc_array, 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 19897 of file pg_dump.c.

19899{
19900 PQExpBuffer query;
19901 PGresult *res;
19902 int ntups,
19903 i;
19904 int i_classid,
19905 i_objid,
19906 i_refobjid;
19907 ExtensionInfo *ext;
19908
19909 /* Nothing to do if no extensions */
19910 if (numExtensions == 0)
19911 return;
19912
19913 query = createPQExpBuffer();
19914
19915 /* refclassid constraint is redundant but may speed the search */
19916 appendPQExpBufferStr(query, "SELECT "
19917 "classid, objid, refobjid "
19918 "FROM pg_depend "
19919 "WHERE refclassid = 'pg_extension'::regclass "
19920 "AND deptype = 'e' "
19921 "ORDER BY 3");
19922
19923 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
19924
19925 ntups = PQntuples(res);
19926
19927 i_classid = PQfnumber(res, "classid");
19928 i_objid = PQfnumber(res, "objid");
19929 i_refobjid = PQfnumber(res, "refobjid");
19930
19931 /*
19932 * Since we ordered the SELECT by referenced ID, we can expect that
19933 * multiple entries for the same extension will appear together; this
19934 * saves on searches.
19935 */
19936 ext = NULL;
19937
19938 for (i = 0; i < ntups; i++)
19939 {
19940 CatalogId objId;
19941 Oid extId;
19942
19943 objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
19944 objId.oid = atooid(PQgetvalue(res, i, i_objid));
19946
19947 if (ext == NULL ||
19948 ext->dobj.catId.oid != extId)
19950
19951 if (ext == NULL)
19952 {
19953 /* shouldn't happen */
19954 pg_log_warning("could not find referenced extension %u", extId);
19955 continue;
19956 }
19957
19958 recordExtensionMembership(objId, ext);
19959 }
19960
19961 PQclear(res);
19962
19963 destroyPQExpBuffer(query);
19964}
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition common.c:1066
ExtensionInfo * findExtensionByOid(Oid oid)
Definition common.c:1011
#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 6169 of file pg_dump.c.

6170{
6171 DumpOptions *dopt = fout->dopt;
6172 PGresult *res;
6173 int ntups;
6174 int i;
6175 PQExpBuffer query;
6177 int i_tableoid;
6178 int i_oid;
6179 int i_extname;
6180 int i_nspname;
6181 int i_extrelocatable;
6182 int i_extversion;
6183 int i_extconfig;
6184 int i_extcondition;
6185
6186 query = createPQExpBuffer();
6187
6188 appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
6189 "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
6190 "FROM pg_extension x "
6191 "JOIN pg_namespace n ON n.oid = x.extnamespace");
6192
6193 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6194
6195 ntups = PQntuples(res);
6196 if (ntups == 0)
6197 goto cleanup;
6198
6200
6201 i_tableoid = PQfnumber(res, "tableoid");
6202 i_oid = PQfnumber(res, "oid");
6203 i_extname = PQfnumber(res, "extname");
6204 i_nspname = PQfnumber(res, "nspname");
6205 i_extrelocatable = PQfnumber(res, "extrelocatable");
6206 i_extversion = PQfnumber(res, "extversion");
6207 i_extconfig = PQfnumber(res, "extconfig");
6208 i_extcondition = PQfnumber(res, "extcondition");
6209
6210 for (i = 0; i < ntups; i++)
6211 {
6212 extinfo[i].dobj.objType = DO_EXTENSION;
6213 extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6214 extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6215 AssignDumpId(&extinfo[i].dobj);
6216 extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
6217 extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
6218 extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
6219 extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
6220 extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
6221 extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
6222
6223 /* Decide whether we want to dump it */
6225 }
6226
6227cleanup:
6228 PQclear(res);
6229 destroyPQExpBuffer(query);
6230
6231 *numExtensions = ntups;
6232
6233 return extinfo;
6234}
static void cleanup(void)
Definition bootstrap.c:886
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition pg_dump.c:2241

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

Referenced by getSchemaData().

◆ getForeignDataWrappers()

void getForeignDataWrappers ( Archive fout)
extern

Definition at line 10338 of file pg_dump.c.

10339{
10340 PGresult *res;
10341 int ntups;
10342 int i;
10343 PQExpBuffer query;
10345 int i_tableoid;
10346 int i_oid;
10347 int i_fdwname;
10348 int i_fdwowner;
10349 int i_fdwhandler;
10350 int i_fdwvalidator;
10351 int i_fdwconnection;
10352 int i_fdwacl;
10353 int i_acldefault;
10354 int i_fdwoptions;
10355
10356 query = createPQExpBuffer();
10357
10358 appendPQExpBufferStr(query, "SELECT tableoid, oid, fdwname, "
10359 "fdwowner, "
10360 "fdwhandler::pg_catalog.regproc, "
10361 "fdwvalidator::pg_catalog.regproc, ");
10362
10363 if (fout->remoteVersion >= 190000)
10364 appendPQExpBufferStr(query, "fdwconnection::pg_catalog.regproc, ");
10365 else
10366 appendPQExpBufferStr(query, "'-' AS fdwconnection, ");
10367
10369 "fdwacl, "
10370 "acldefault('F', fdwowner) AS acldefault, "
10371 "array_to_string(ARRAY("
10372 "SELECT quote_ident(option_name) || ' ' || "
10373 "quote_literal(option_value) "
10374 "FROM pg_options_to_table(fdwoptions) "
10375 "ORDER BY option_name"
10376 "), E',\n ') AS fdwoptions "
10377 "FROM pg_foreign_data_wrapper");
10378
10379 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10380
10381 ntups = PQntuples(res);
10382
10384
10385 i_tableoid = PQfnumber(res, "tableoid");
10386 i_oid = PQfnumber(res, "oid");
10387 i_fdwname = PQfnumber(res, "fdwname");
10388 i_fdwowner = PQfnumber(res, "fdwowner");
10389 i_fdwhandler = PQfnumber(res, "fdwhandler");
10390 i_fdwvalidator = PQfnumber(res, "fdwvalidator");
10391 i_fdwconnection = PQfnumber(res, "fdwconnection");
10392 i_fdwacl = PQfnumber(res, "fdwacl");
10393 i_acldefault = PQfnumber(res, "acldefault");
10394 i_fdwoptions = PQfnumber(res, "fdwoptions");
10395
10396 for (i = 0; i < ntups; i++)
10397 {
10398 fdwinfo[i].dobj.objType = DO_FDW;
10399 fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10400 fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10401 AssignDumpId(&fdwinfo[i].dobj);
10402 fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
10403 fdwinfo[i].dobj.namespace = NULL;
10404 fdwinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
10405 fdwinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10406 fdwinfo[i].dacl.privtype = 0;
10407 fdwinfo[i].dacl.initprivs = NULL;
10408 fdwinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_fdwowner));
10409 fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
10410 fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
10411 fdwinfo[i].fdwconnection = pg_strdup(PQgetvalue(res, i, i_fdwconnection));
10412 fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
10413
10414 /* Decide whether we want to dump it */
10416
10417 /* Mark whether FDW has an ACL */
10418 if (!PQgetisnull(res, i, i_fdwacl))
10419 fdwinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10420 }
10421
10422 PQclear(res);
10423
10424 destroyPQExpBuffer(query);
10425}

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

Referenced by getSchemaData().

◆ getForeignServers()

void getForeignServers ( Archive fout)
extern

Definition at line 10432 of file pg_dump.c.

10433{
10434 PGresult *res;
10435 int ntups;
10436 int i;
10437 PQExpBuffer query;
10439 int i_tableoid;
10440 int i_oid;
10441 int i_srvname;
10442 int i_srvowner;
10443 int i_srvfdw;
10444 int i_srvtype;
10445 int i_srvversion;
10446 int i_srvacl;
10447 int i_acldefault;
10448 int i_srvoptions;
10449
10450 query = createPQExpBuffer();
10451
10452 appendPQExpBufferStr(query, "SELECT tableoid, oid, srvname, "
10453 "srvowner, "
10454 "srvfdw, srvtype, srvversion, srvacl, "
10455 "acldefault('S', srvowner) AS acldefault, "
10456 "array_to_string(ARRAY("
10457 "SELECT quote_ident(option_name) || ' ' || "
10458 "quote_literal(option_value) "
10459 "FROM pg_options_to_table(srvoptions) "
10460 "ORDER BY option_name"
10461 "), E',\n ') AS srvoptions "
10462 "FROM pg_foreign_server");
10463
10464 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10465
10466 ntups = PQntuples(res);
10467
10469
10470 i_tableoid = PQfnumber(res, "tableoid");
10471 i_oid = PQfnumber(res, "oid");
10472 i_srvname = PQfnumber(res, "srvname");
10473 i_srvowner = PQfnumber(res, "srvowner");
10474 i_srvfdw = PQfnumber(res, "srvfdw");
10475 i_srvtype = PQfnumber(res, "srvtype");
10476 i_srvversion = PQfnumber(res, "srvversion");
10477 i_srvacl = PQfnumber(res, "srvacl");
10478 i_acldefault = PQfnumber(res, "acldefault");
10479 i_srvoptions = PQfnumber(res, "srvoptions");
10480
10481 for (i = 0; i < ntups; i++)
10482 {
10483 srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
10484 srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10485 srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10486 AssignDumpId(&srvinfo[i].dobj);
10487 srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
10488 srvinfo[i].dobj.namespace = NULL;
10489 srvinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_srvacl));
10490 srvinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10491 srvinfo[i].dacl.privtype = 0;
10492 srvinfo[i].dacl.initprivs = NULL;
10493 srvinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_srvowner));
10494 srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
10495 srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
10496 srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
10497 srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
10498
10499 /* Decide whether we want to dump it */
10501
10502 /* Servers have user mappings */
10503 srvinfo[i].dobj.components |= DUMP_COMPONENT_USERMAP;
10504
10505 /* Mark whether server has an ACL */
10506 if (!PQgetisnull(res, i, i_srvacl))
10507 srvinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10508 }
10509
10510 PQclear(res);
10511
10512 destroyPQExpBuffer(query);
10513}
#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_array, pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getFuncs()

void getFuncs ( Archive fout)
extern

Definition at line 6921 of file pg_dump.c.

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

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

7661{
7662 PGresult *res;
7663 int ntups;
7664 int i;
7667
7668 int i_inhrelid;
7669 int i_inhparent;
7670
7671 /* find all the inheritance information */
7672 appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
7673
7674 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7675
7676 ntups = PQntuples(res);
7677
7678 *numInherits = ntups;
7679
7681
7682 i_inhrelid = PQfnumber(res, "inhrelid");
7683 i_inhparent = PQfnumber(res, "inhparent");
7684
7685 for (i = 0; i < ntups; i++)
7686 {
7687 inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
7688 inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
7689 }
7690
7691 PQclear(res);
7692
7693 destroyPQExpBuffer(query);
7694
7695 return inhinfo;
7696}

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

Referenced by getSchemaData().

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )
extern

Definition at line 757 of file common.c.

758{
759 return lastDumpId;
760}

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

◆ getNamespaces()

void getNamespaces ( Archive fout)
extern

Definition at line 6037 of file pg_dump.c.

6038{
6039 PGresult *res;
6040 int ntups;
6041 int i;
6042 PQExpBuffer query;
6044 int i_tableoid;
6045 int i_oid;
6046 int i_nspname;
6047 int i_nspowner;
6048 int i_nspacl;
6049 int i_acldefault;
6050
6051 query = createPQExpBuffer();
6052
6053 /*
6054 * we fetch all namespaces including system ones, so that every object we
6055 * read in can be linked to a containing namespace.
6056 */
6057 appendPQExpBufferStr(query, "SELECT n.tableoid, n.oid, n.nspname, "
6058 "n.nspowner, "
6059 "n.nspacl, "
6060 "acldefault('n', n.nspowner) AS acldefault "
6061 "FROM pg_namespace n");
6062
6063 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6064
6065 ntups = PQntuples(res);
6066
6068
6069 i_tableoid = PQfnumber(res, "tableoid");
6070 i_oid = PQfnumber(res, "oid");
6071 i_nspname = PQfnumber(res, "nspname");
6072 i_nspowner = PQfnumber(res, "nspowner");
6073 i_nspacl = PQfnumber(res, "nspacl");
6074 i_acldefault = PQfnumber(res, "acldefault");
6075
6076 for (i = 0; i < ntups; i++)
6077 {
6078 const char *nspowner;
6079
6080 nsinfo[i].dobj.objType = DO_NAMESPACE;
6081 nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6082 nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6083 AssignDumpId(&nsinfo[i].dobj);
6084 nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
6085 nsinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_nspacl));
6086 nsinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6087 nsinfo[i].dacl.privtype = 0;
6088 nsinfo[i].dacl.initprivs = NULL;
6089 nspowner = PQgetvalue(res, i, i_nspowner);
6090 nsinfo[i].nspowner = atooid(nspowner);
6091 nsinfo[i].rolname = getRoleName(nspowner);
6092
6093 /* Decide whether to dump this namespace */
6095
6096 /* Mark whether namespace has an ACL */
6097 if (!PQgetisnull(res, i, i_nspacl))
6098 nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6099
6100 /*
6101 * We ignore any pg_init_privs.initprivs entry for the public schema
6102 * and assume a predetermined default, for several reasons. First,
6103 * dropping and recreating the schema removes its pg_init_privs entry,
6104 * but an empty destination database starts with this ACL nonetheless.
6105 * Second, we support dump/reload of public schema ownership changes.
6106 * ALTER SCHEMA OWNER filters nspacl through aclnewowner(), but
6107 * initprivs continues to reflect the initial owner. Hence,
6108 * synthesize the value that nspacl will have after the restore's
6109 * ALTER SCHEMA OWNER. Third, this makes the destination database
6110 * match the source's ACL, even if the latter was an initdb-default
6111 * ACL, which changed in v15. An upgrade pulls in changes to most
6112 * system object ACLs that the DBA had not customized. We've made the
6113 * public schema depart from that, because changing its ACL so easily
6114 * breaks applications.
6115 */
6116 if (strcmp(nsinfo[i].dobj.name, "public") == 0)
6117 {
6120
6121 /* Standard ACL as of v15 is {owner=UC/owner,=U/owner} */
6132
6133 nsinfo[i].dacl.privtype = 'i';
6134 nsinfo[i].dacl.initprivs = pstrdup(aclarray->data);
6135 nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6136
6139 }
6140 }
6141
6142 PQclear(res);
6143 destroyPQExpBuffer(query);
6144}
void quoteAclUserName(PQExpBuffer output, const char *input)
Definition dumputils.c:588
char * pstrdup(const char *in)
Definition mcxt.c:1910
NameData rolname
Definition pg_authid.h:36
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition pg_dump.c:1965
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_array, 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 6678 of file pg_dump.c.

6679{
6680 PGresult *res;
6681 int ntups;
6682 int i;
6685 int i_tableoid;
6686 int i_oid;
6687 int i_opcmethod;
6688 int i_opcname;
6689 int i_opcnamespace;
6690 int i_opcowner;
6691
6692 /*
6693 * find all opclasses, including builtin opclasses; we filter out
6694 * system-defined opclasses at dump-out time.
6695 */
6696
6697 appendPQExpBufferStr(query, "SELECT tableoid, oid, opcmethod, opcname, "
6698 "opcnamespace, "
6699 "opcowner "
6700 "FROM pg_opclass");
6701
6702 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6703
6704 ntups = PQntuples(res);
6705
6707
6708 i_tableoid = PQfnumber(res, "tableoid");
6709 i_oid = PQfnumber(res, "oid");
6710 i_opcmethod = PQfnumber(res, "opcmethod");
6711 i_opcname = PQfnumber(res, "opcname");
6712 i_opcnamespace = PQfnumber(res, "opcnamespace");
6713 i_opcowner = PQfnumber(res, "opcowner");
6714
6715 for (i = 0; i < ntups; i++)
6716 {
6717 opcinfo[i].dobj.objType = DO_OPCLASS;
6718 opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6719 opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6720 AssignDumpId(&opcinfo[i].dobj);
6721 opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
6722 opcinfo[i].dobj.namespace =
6724 opcinfo[i].opcmethod = atooid(PQgetvalue(res, i, i_opcmethod));
6725 opcinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opcowner));
6726
6727 /* Decide whether we want to dump it */
6729 }
6730
6731 PQclear(res);
6732
6733 destroyPQExpBuffer(query);
6734}

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

Referenced by getSchemaData().

◆ getOperators()

void getOperators ( Archive fout)
extern

Definition at line 6412 of file pg_dump.c.

6413{
6414 PGresult *res;
6415 int ntups;
6416 int i;
6419 int i_tableoid;
6420 int i_oid;
6421 int i_oprname;
6422 int i_oprnamespace;
6423 int i_oprowner;
6424 int i_oprkind;
6425 int i_oprleft;
6426 int i_oprright;
6427 int i_oprcode;
6428
6429 /*
6430 * find all operators, including builtin operators; we filter out
6431 * system-defined operators at dump-out time.
6432 */
6433
6434 appendPQExpBufferStr(query, "SELECT tableoid, oid, oprname, "
6435 "oprnamespace, "
6436 "oprowner, "
6437 "oprkind, "
6438 "oprleft, "
6439 "oprright, "
6440 "oprcode::oid AS oprcode "
6441 "FROM pg_operator");
6442
6443 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6444
6445 ntups = PQntuples(res);
6446
6448
6449 i_tableoid = PQfnumber(res, "tableoid");
6450 i_oid = PQfnumber(res, "oid");
6451 i_oprname = PQfnumber(res, "oprname");
6452 i_oprnamespace = PQfnumber(res, "oprnamespace");
6453 i_oprowner = PQfnumber(res, "oprowner");
6454 i_oprkind = PQfnumber(res, "oprkind");
6455 i_oprleft = PQfnumber(res, "oprleft");
6456 i_oprright = PQfnumber(res, "oprright");
6457 i_oprcode = PQfnumber(res, "oprcode");
6458
6459 for (i = 0; i < ntups; i++)
6460 {
6461 oprinfo[i].dobj.objType = DO_OPERATOR;
6462 oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6463 oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6464 AssignDumpId(&oprinfo[i].dobj);
6465 oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
6466 oprinfo[i].dobj.namespace =
6468 oprinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_oprowner));
6469 oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
6470 oprinfo[i].oprleft = atooid(PQgetvalue(res, i, i_oprleft));
6471 oprinfo[i].oprright = atooid(PQgetvalue(res, i, i_oprright));
6472 oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
6473
6474 /* Decide whether we want to dump it */
6476 }
6477
6478 PQclear(res);
6479
6480 destroyPQExpBuffer(query);
6481}

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

Referenced by getSchemaData().

◆ getOpfamilies()

void getOpfamilies ( Archive fout)
extern

Definition at line 6741 of file pg_dump.c.

6742{
6743 PGresult *res;
6744 int ntups;
6745 int i;
6746 PQExpBuffer query;
6748 int i_tableoid;
6749 int i_oid;
6750 int i_opfmethod;
6751 int i_opfname;
6752 int i_opfnamespace;
6753 int i_opfowner;
6754
6755 query = createPQExpBuffer();
6756
6757 /*
6758 * find all opfamilies, including builtin opfamilies; we filter out
6759 * system-defined opfamilies at dump-out time.
6760 */
6761
6762 appendPQExpBufferStr(query, "SELECT tableoid, oid, opfmethod, opfname, "
6763 "opfnamespace, "
6764 "opfowner "
6765 "FROM pg_opfamily");
6766
6767 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6768
6769 ntups = PQntuples(res);
6770
6772
6773 i_tableoid = PQfnumber(res, "tableoid");
6774 i_oid = PQfnumber(res, "oid");
6775 i_opfname = PQfnumber(res, "opfname");
6776 i_opfmethod = PQfnumber(res, "opfmethod");
6777 i_opfnamespace = PQfnumber(res, "opfnamespace");
6778 i_opfowner = PQfnumber(res, "opfowner");
6779
6780 for (i = 0; i < ntups; i++)
6781 {
6782 opfinfo[i].dobj.objType = DO_OPFAMILY;
6783 opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6784 opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6785 AssignDumpId(&opfinfo[i].dobj);
6786 opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
6787 opfinfo[i].dobj.namespace =
6789 opfinfo[i].opfmethod = atooid(PQgetvalue(res, i, i_opfmethod));
6790 opfinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opfowner));
6791
6792 /* Decide whether we want to dump it */
6794 }
6795
6796 PQclear(res);
6797
6798 destroyPQExpBuffer(query);
6799}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPFAMILY, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc_array, 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 7595 of file pg_dump.c.

7596{
7597 int i;
7598
7599 /*
7600 * Force sequences that are "owned" by table columns to be dumped whenever
7601 * their owning table is being dumped.
7602 */
7603 for (i = 0; i < numTables; i++)
7604 {
7605 TableInfo *seqinfo = &tblinfo[i];
7606 TableInfo *owning_tab;
7607
7608 if (!OidIsValid(seqinfo->owning_tab))
7609 continue; /* not an owned sequence */
7610
7611 owning_tab = findTableByOid(seqinfo->owning_tab);
7612 if (owning_tab == NULL)
7613 pg_fatal("failed sanity check, parent table with OID %u of sequence with OID %u not found",
7614 seqinfo->owning_tab, seqinfo->dobj.catId.oid);
7615
7616 /*
7617 * For an identity sequence, dump exactly the same components for the
7618 * sequence as for the owning table. This is important because we
7619 * treat the identity sequence as an integral part of the table. For
7620 * example, there is not any DDL command that allows creation of such
7621 * a sequence independently of the table.
7622 *
7623 * For other owned sequences such as serial sequences, we need to dump
7624 * the components that are being dumped for the table and any
7625 * components that the sequence is explicitly marked with.
7626 *
7627 * We can't simply use the set of components which are being dumped
7628 * for the table as the table might be in an extension (and only the
7629 * non-extension components, eg: ACLs if changed, security labels, and
7630 * policies, are being dumped) while the sequence is not (and
7631 * therefore the definition and other components should also be
7632 * dumped).
7633 *
7634 * If the sequence is part of the extension then it should be properly
7635 * marked by checkExtensionMembership() and this will be a no-op as
7636 * the table will be equivalently marked.
7637 */
7638 if (seqinfo->is_identity_sequence)
7639 seqinfo->dobj.dump = owning_tab->dobj.dump;
7640 else
7641 seqinfo->dobj.dump |= owning_tab->dobj.dump;
7642
7643 /* Make sure that necessary data is available if we're dumping it */
7644 if (seqinfo->dobj.dump != DUMP_COMPONENT_NONE)
7645 {
7646 seqinfo->interesting = true;
7647 owning_tab->interesting = true;
7648 }
7649 }
7650}
#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 7716 of file pg_dump.c.

7717{
7718 PQExpBuffer query;
7719 PGresult *res;
7720 int ntups;
7721
7722 /* hash partitioning didn't exist before v11 */
7723 if (fout->remoteVersion < 110000)
7724 return;
7725 /* needn't bother if not dumping data */
7726 if (!fout->dopt->dumpData)
7727 return;
7728
7729 query = createPQExpBuffer();
7730
7731 /*
7732 * Unsafe partitioning schemes are exactly those for which hash enum_ops
7733 * appears among the partition opclasses. We needn't check partstrat.
7734 *
7735 * Note that this query may well retrieve info about tables we aren't
7736 * going to dump and hence have no lock on. That's okay since we need not
7737 * invoke any unsafe server-side functions.
7738 */
7740 "SELECT partrelid FROM pg_partitioned_table WHERE\n"
7741 "(SELECT c.oid FROM pg_opclass c JOIN pg_am a "
7742 "ON c.opcmethod = a.oid\n"
7743 "WHERE opcname = 'enum_ops' "
7744 "AND opcnamespace = 'pg_catalog'::regnamespace "
7745 "AND amname = 'hash') = ANY(partclass)");
7746
7747 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7748
7749 ntups = PQntuples(res);
7750
7751 for (int i = 0; i < ntups; i++)
7752 {
7753 Oid tabrelid = atooid(PQgetvalue(res, i, 0));
7755
7757 if (tbinfo == NULL)
7758 pg_fatal("failed sanity check, table OID %u appearing in pg_partitioned_table not found",
7759 tabrelid);
7760 tbinfo->unsafe_partitions = true;
7761 }
7762
7763 PQclear(res);
7764
7765 destroyPQExpBuffer(query);
7766}

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

4188{
4189 DumpOptions *dopt = fout->dopt;
4190 PQExpBuffer query;
4192 PGresult *res;
4194 int i_oid;
4195 int i_tableoid;
4196 int i_polrelid;
4197 int i_polname;
4198 int i_polcmd;
4199 int i_polpermissive;
4200 int i_polroles;
4201 int i_polqual;
4202 int i_polwithcheck;
4203 int i,
4204 j,
4205 ntups;
4206
4207 /* Skip if --no-policies was specified */
4208 if (dopt->no_policies)
4209 return;
4210
4211 query = createPQExpBuffer();
4213
4214 /*
4215 * Identify tables of interest, and check which ones have RLS enabled.
4216 */
4218 for (i = 0; i < numTables; i++)
4219 {
4220 TableInfo *tbinfo = &tblinfo[i];
4221
4222 /* Ignore row security on tables not to be dumped */
4223 if (!(tbinfo->dobj.dump & DUMP_COMPONENT_POLICY))
4224 continue;
4225
4226 /* It can't have RLS or policies if it's not a table */
4227 if (tbinfo->relkind != RELKIND_RELATION &&
4229 continue;
4230
4231 /* Add it to the list of table OIDs to be probed below */
4232 if (tbloids->len > 1) /* do we have more than the '{'? */
4234 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
4235
4236 /* Is RLS enabled? (That's separate from whether it has policies) */
4237 if (tbinfo->rowsec)
4238 {
4239 tbinfo->dobj.components |= DUMP_COMPONENT_POLICY;
4240
4241 /*
4242 * We represent RLS being enabled on a table by creating a
4243 * PolicyInfo object with null polname.
4244 *
4245 * Note: use tableoid 0 so that this object won't be mistaken for
4246 * something that pg_depend entries apply to.
4247 */
4249 polinfo->dobj.objType = DO_POLICY;
4250 polinfo->dobj.catId.tableoid = 0;
4251 polinfo->dobj.catId.oid = tbinfo->dobj.catId.oid;
4252 AssignDumpId(&polinfo->dobj);
4253 polinfo->dobj.namespace = tbinfo->dobj.namespace;
4254 polinfo->dobj.name = pg_strdup(tbinfo->dobj.name);
4255 polinfo->poltable = tbinfo;
4256 polinfo->polname = NULL;
4257 polinfo->polcmd = '\0';
4258 polinfo->polpermissive = 0;
4259 polinfo->polroles = NULL;
4260 polinfo->polqual = NULL;
4261 polinfo->polwithcheck = NULL;
4262 }
4263 }
4265
4266 /*
4267 * Now, read all RLS policies belonging to the tables of interest, and
4268 * create PolicyInfo objects for them. (Note that we must filter the
4269 * results server-side not locally, because we dare not apply pg_get_expr
4270 * to tables we don't have lock on.)
4271 */
4272 pg_log_info("reading row-level security policies");
4273
4274 printfPQExpBuffer(query,
4275 "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
4276 appendPQExpBufferStr(query, "pol.polpermissive, ");
4277 appendPQExpBuffer(query,
4278 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
4279 " 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, "
4280 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
4281 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
4282 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
4283 "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
4284 tbloids->data);
4285
4286 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4287
4288 ntups = PQntuples(res);
4289 if (ntups > 0)
4290 {
4291 i_oid = PQfnumber(res, "oid");
4292 i_tableoid = PQfnumber(res, "tableoid");
4293 i_polrelid = PQfnumber(res, "polrelid");
4294 i_polname = PQfnumber(res, "polname");
4295 i_polcmd = PQfnumber(res, "polcmd");
4296 i_polpermissive = PQfnumber(res, "polpermissive");
4297 i_polroles = PQfnumber(res, "polroles");
4298 i_polqual = PQfnumber(res, "polqual");
4299 i_polwithcheck = PQfnumber(res, "polwithcheck");
4300
4302
4303 for (j = 0; j < ntups; j++)
4304 {
4307
4308 tbinfo->dobj.components |= DUMP_COMPONENT_POLICY;
4309
4310 polinfo[j].dobj.objType = DO_POLICY;
4311 polinfo[j].dobj.catId.tableoid =
4312 atooid(PQgetvalue(res, j, i_tableoid));
4313 polinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
4314 AssignDumpId(&polinfo[j].dobj);
4315 polinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4316 polinfo[j].poltable = tbinfo;
4317 polinfo[j].polname = pg_strdup(PQgetvalue(res, j, i_polname));
4318 polinfo[j].dobj.name = pg_strdup(polinfo[j].polname);
4319
4320 polinfo[j].polcmd = *(PQgetvalue(res, j, i_polcmd));
4321 polinfo[j].polpermissive = *(PQgetvalue(res, j, i_polpermissive)) == 't';
4322
4323 if (PQgetisnull(res, j, i_polroles))
4324 polinfo[j].polroles = NULL;
4325 else
4326 polinfo[j].polroles = pg_strdup(PQgetvalue(res, j, i_polroles));
4327
4328 if (PQgetisnull(res, j, i_polqual))
4329 polinfo[j].polqual = NULL;
4330 else
4331 polinfo[j].polqual = pg_strdup(PQgetvalue(res, j, i_polqual));
4332
4333 if (PQgetisnull(res, j, i_polwithcheck))
4334 polinfo[j].polwithcheck = NULL;
4335 else
4336 polinfo[j].polwithcheck
4338 }
4339 }
4340
4341 PQclear(res);
4342
4343 destroyPQExpBuffer(query);
4345}
#define pg_log_info(...)
Definition logging.h:126
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_array, pg_malloc_object, pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and printfPQExpBuffer().

Referenced by getSchemaData().

◆ getProcLangs()

void getProcLangs ( Archive fout)
extern

Definition at line 8880 of file pg_dump.c.

8881{
8882 PGresult *res;
8883 int ntups;
8884 int i;
8887 int i_tableoid;
8888 int i_oid;
8889 int i_lanname;
8890 int i_lanpltrusted;
8891 int i_lanplcallfoid;
8892 int i_laninline;
8893 int i_lanvalidator;
8894 int i_lanacl;
8895 int i_acldefault;
8896 int i_lanowner;
8897
8898 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8899 "lanname, lanpltrusted, lanplcallfoid, "
8900 "laninline, lanvalidator, "
8901 "lanacl, "
8902 "acldefault('l', lanowner) AS acldefault, "
8903 "lanowner "
8904 "FROM pg_language "
8905 "WHERE lanispl "
8906 "ORDER BY oid");
8907
8908 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8909
8910 ntups = PQntuples(res);
8911
8913
8914 i_tableoid = PQfnumber(res, "tableoid");
8915 i_oid = PQfnumber(res, "oid");
8916 i_lanname = PQfnumber(res, "lanname");
8917 i_lanpltrusted = PQfnumber(res, "lanpltrusted");
8918 i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
8919 i_laninline = PQfnumber(res, "laninline");
8920 i_lanvalidator = PQfnumber(res, "lanvalidator");
8921 i_lanacl = PQfnumber(res, "lanacl");
8922 i_acldefault = PQfnumber(res, "acldefault");
8923 i_lanowner = PQfnumber(res, "lanowner");
8924
8925 for (i = 0; i < ntups; i++)
8926 {
8927 planginfo[i].dobj.objType = DO_PROCLANG;
8928 planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8929 planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8930 AssignDumpId(&planginfo[i].dobj);
8931
8932 planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
8933 planginfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_lanacl));
8934 planginfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
8935 planginfo[i].dacl.privtype = 0;
8936 planginfo[i].dacl.initprivs = NULL;
8937 planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
8938 planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
8939 planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
8940 planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
8941 planginfo[i].lanowner = getRoleName(PQgetvalue(res, i, i_lanowner));
8942
8943 /* Decide whether we want to dump it */
8945
8946 /* Mark whether language has an ACL */
8947 if (!PQgetisnull(res, i, i_lanacl))
8948 planginfo[i].dobj.components |= DUMP_COMPONENT_ACL;
8949 }
8950
8951 PQclear(res);
8952
8953 destroyPQExpBuffer(query);
8954}
static void selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
Definition pg_dump.c:2181

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

Referenced by getSchemaData().

◆ getPublicationNamespaces()

void getPublicationNamespaces ( Archive fout)
extern

Definition at line 4758 of file pg_dump.c.

4759{
4760 PQExpBuffer query;
4761 PGresult *res;
4763 DumpOptions *dopt = fout->dopt;
4764 int i_tableoid;
4765 int i_oid;
4766 int i_pnpubid;
4767 int i_pnnspid;
4768 int i,
4769 j,
4770 ntups;
4771
4772 if (dopt->no_publications || fout->remoteVersion < 150000)
4773 return;
4774
4775 query = createPQExpBuffer();
4776
4777 /* Collect all publication membership info. */
4779 "SELECT tableoid, oid, pnpubid, pnnspid "
4780 "FROM pg_catalog.pg_publication_namespace");
4781 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4782
4783 ntups = PQntuples(res);
4784
4785 i_tableoid = PQfnumber(res, "tableoid");
4786 i_oid = PQfnumber(res, "oid");
4787 i_pnpubid = PQfnumber(res, "pnpubid");
4788 i_pnnspid = PQfnumber(res, "pnnspid");
4789
4790 /* this allocation may be more than we need */
4792 j = 0;
4793
4794 for (i = 0; i < ntups; i++)
4795 {
4800
4801 /*
4802 * Ignore any entries for which we aren't interested in either the
4803 * publication or the rel.
4804 */
4806 if (pubinfo == NULL)
4807 continue;
4809 if (nspinfo == NULL)
4810 continue;
4811
4812 /* OK, make a DumpableObject for this relationship */
4814 pubsinfo[j].dobj.catId.tableoid =
4815 atooid(PQgetvalue(res, i, i_tableoid));
4816 pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4817 AssignDumpId(&pubsinfo[j].dobj);
4818 pubsinfo[j].dobj.namespace = nspinfo->dobj.namespace;
4819 pubsinfo[j].dobj.name = nspinfo->dobj.name;
4820 pubsinfo[j].publication = pubinfo;
4821 pubsinfo[j].pubschema = nspinfo;
4822
4823 /* Decide whether we want to dump it */
4825
4826 j++;
4827 }
4828
4829 PQclear(res);
4830 destroyPQExpBuffer(query);
4831}
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition common.c:993
PublicationInfo * findPublicationByOid(Oid oid)
Definition common.c:1029
static void selectDumpablePublicationObject(DumpableObject *dobj, Archive *fout)
Definition pg_dump.c:2280
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_array, PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpablePublicationObject().

Referenced by getSchemaData().

◆ getPublications()

void getPublications ( Archive fout)
extern

Definition at line 4470 of file pg_dump.c.

4471{
4472 DumpOptions *dopt = fout->dopt;
4473 PQExpBuffer query;
4474 PGresult *res;
4476 int i_tableoid;
4477 int i_oid;
4478 int i_pubname;
4479 int i_pubowner;
4480 int i_puballtables;
4482 int i_pubinsert;
4483 int i_pubupdate;
4484 int i_pubdelete;
4485 int i_pubtruncate;
4486 int i_pubviaroot;
4487 int i_pubgencols;
4488 int i,
4489 ntups;
4490
4491 if (dopt->no_publications)
4492 return;
4493
4494 query = createPQExpBuffer();
4495
4496 /* Get the publications. */
4497 appendPQExpBufferStr(query, "SELECT p.tableoid, p.oid, p.pubname, "
4498 "p.pubowner, p.puballtables, p.pubinsert, "
4499 "p.pubupdate, p.pubdelete, ");
4500
4501 if (fout->remoteVersion >= 110000)
4502 appendPQExpBufferStr(query, "p.pubtruncate, ");
4503 else
4504 appendPQExpBufferStr(query, "false AS pubtruncate, ");
4505
4506 if (fout->remoteVersion >= 130000)
4507 appendPQExpBufferStr(query, "p.pubviaroot, ");
4508 else
4509 appendPQExpBufferStr(query, "false AS pubviaroot, ");
4510
4511 if (fout->remoteVersion >= 180000)
4512 appendPQExpBufferStr(query, "p.pubgencols, ");
4513 else
4514 appendPQExpBuffer(query, "'%c' AS pubgencols, ", PUBLISH_GENCOLS_NONE);
4515
4516 if (fout->remoteVersion >= 190000)
4517 appendPQExpBufferStr(query, "p.puballsequences ");
4518 else
4519 appendPQExpBufferStr(query, "false AS puballsequences ");
4520
4521 appendPQExpBufferStr(query, "FROM pg_publication p");
4522
4523 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4524
4525 ntups = PQntuples(res);
4526
4527 if (ntups == 0)
4528 goto cleanup;
4529
4530 i_tableoid = PQfnumber(res, "tableoid");
4531 i_oid = PQfnumber(res, "oid");
4532 i_pubname = PQfnumber(res, "pubname");
4533 i_pubowner = PQfnumber(res, "pubowner");
4534 i_puballtables = PQfnumber(res, "puballtables");
4535 i_puballsequences = PQfnumber(res, "puballsequences");
4536 i_pubinsert = PQfnumber(res, "pubinsert");
4537 i_pubupdate = PQfnumber(res, "pubupdate");
4538 i_pubdelete = PQfnumber(res, "pubdelete");
4539 i_pubtruncate = PQfnumber(res, "pubtruncate");
4540 i_pubviaroot = PQfnumber(res, "pubviaroot");
4541 i_pubgencols = PQfnumber(res, "pubgencols");
4542
4544
4545 for (i = 0; i < ntups; i++)
4546 {
4547 pubinfo[i].dobj.objType = DO_PUBLICATION;
4548 pubinfo[i].dobj.catId.tableoid =
4549 atooid(PQgetvalue(res, i, i_tableoid));
4550 pubinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4551 AssignDumpId(&pubinfo[i].dobj);
4552 pubinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_pubname));
4553 pubinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_pubowner));
4554 pubinfo[i].puballtables =
4555 (strcmp(PQgetvalue(res, i, i_puballtables), "t") == 0);
4556 pubinfo[i].puballsequences =
4557 (strcmp(PQgetvalue(res, i, i_puballsequences), "t") == 0);
4558 pubinfo[i].pubinsert =
4559 (strcmp(PQgetvalue(res, i, i_pubinsert), "t") == 0);
4560 pubinfo[i].pubupdate =
4561 (strcmp(PQgetvalue(res, i, i_pubupdate), "t") == 0);
4562 pubinfo[i].pubdelete =
4563 (strcmp(PQgetvalue(res, i, i_pubdelete), "t") == 0);
4564 pubinfo[i].pubtruncate =
4565 (strcmp(PQgetvalue(res, i, i_pubtruncate), "t") == 0);
4566 pubinfo[i].pubviaroot =
4567 (strcmp(PQgetvalue(res, i, i_pubviaroot), "t") == 0);
4568 pubinfo[i].pubgencols_type =
4569 *(PQgetvalue(res, i, i_pubgencols));
4570 pubinfo[i].except_tables = (SimplePtrList)
4571 {
4572 NULL, NULL
4573 };
4574
4575 /* Decide whether we want to dump it */
4577
4578 /*
4579 * Get the list of tables for publications specified in the EXCEPT
4580 * TABLE clause.
4581 *
4582 * Although individual table entries in EXCEPT list could be stored in
4583 * PublicationRelInfo, dumpPublicationTable cannot be used to emit
4584 * them, because there is no ALTER PUBLICATION ... ADD command to add
4585 * individual table entries to the EXCEPT list.
4586 *
4587 * Therefore, the approach is to dump the complete EXCEPT list in a
4588 * single CREATE PUBLICATION statement. PublicationInfo is used to
4589 * collect this information, which is then emitted by
4590 * dumpPublication().
4591 */
4592 if (fout->remoteVersion >= 190000)
4593 {
4594 int ntbls;
4596
4597 resetPQExpBuffer(query);
4598 appendPQExpBuffer(query,
4599 "SELECT prrelid\n"
4600 "FROM pg_catalog.pg_publication_rel\n"
4601 "WHERE prpubid = %u AND prexcept",
4602 pubinfo[i].dobj.catId.oid);
4603
4605
4607
4608 for (int j = 0; j < ntbls; j++)
4609 {
4610 Oid prrelid;
4612
4614
4616
4617 if (tbinfo != NULL)
4618 simple_ptr_list_append(&pubinfo[i].except_tables, tbinfo);
4619 }
4620
4622 }
4623 }
4624
4625cleanup:
4626 PQclear(res);
4627
4628 destroyPQExpBuffer(query);
4629}
void simple_ptr_list_append(SimplePtrList *list, void *ptr)

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

Referenced by getSchemaData().

◆ getPublicationTables()

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

Definition at line 4838 of file pg_dump.c.

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

Referenced by getSchemaData().

◆ getRules()

void getRules ( Archive fout)
extern

Definition at line 8513 of file pg_dump.c.

8514{
8515 PGresult *res;
8516 int ntups;
8517 int i;
8520 int i_tableoid;
8521 int i_oid;
8522 int i_rulename;
8523 int i_ruletable;
8524 int i_ev_type;
8525 int i_is_instead;
8526 int i_ev_enabled;
8527
8528 appendPQExpBufferStr(query, "SELECT "
8529 "tableoid, oid, rulename, "
8530 "ev_class AS ruletable, ev_type, is_instead, "
8531 "ev_enabled "
8532 "FROM pg_rewrite "
8533 "ORDER BY oid");
8534
8535 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8536
8537 ntups = PQntuples(res);
8538
8540
8541 i_tableoid = PQfnumber(res, "tableoid");
8542 i_oid = PQfnumber(res, "oid");
8543 i_rulename = PQfnumber(res, "rulename");
8544 i_ruletable = PQfnumber(res, "ruletable");
8545 i_ev_type = PQfnumber(res, "ev_type");
8546 i_is_instead = PQfnumber(res, "is_instead");
8547 i_ev_enabled = PQfnumber(res, "ev_enabled");
8548
8549 for (i = 0; i < ntups; i++)
8550 {
8552
8553 ruleinfo[i].dobj.objType = DO_RULE;
8554 ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8555 ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8556 AssignDumpId(&ruleinfo[i].dobj);
8557 ruleinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_rulename));
8559 ruleinfo[i].ruletable = findTableByOid(ruletableoid);
8560 if (ruleinfo[i].ruletable == NULL)
8561 pg_fatal("failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
8562 ruletableoid, ruleinfo[i].dobj.catId.oid);
8563 ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace;
8564 ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump;
8565 ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type));
8566 ruleinfo[i].is_instead = *(PQgetvalue(res, i, i_is_instead)) == 't';
8567 ruleinfo[i].ev_enabled = *(PQgetvalue(res, i, i_ev_enabled));
8568 if (ruleinfo[i].ruletable)
8569 {
8570 /*
8571 * If the table is a view or materialized view, force its ON
8572 * SELECT rule to be sorted before the view itself --- this
8573 * ensures that any dependencies for the rule affect the table's
8574 * positioning. Other rules are forced to appear after their
8575 * table.
8576 */
8577 if ((ruleinfo[i].ruletable->relkind == RELKIND_VIEW ||
8578 ruleinfo[i].ruletable->relkind == RELKIND_MATVIEW) &&
8579 ruleinfo[i].ev_type == '1' && ruleinfo[i].is_instead)
8580 {
8581 addObjectDependency(&ruleinfo[i].ruletable->dobj,
8582 ruleinfo[i].dobj.dumpId);
8583 /* We'll merge the rule into CREATE VIEW, if possible */
8584 ruleinfo[i].separate = false;
8585 }
8586 else
8587 {
8589 ruleinfo[i].ruletable->dobj.dumpId);
8590 ruleinfo[i].separate = true;
8591 }
8592 }
8593 else
8594 ruleinfo[i].separate = true;
8595 }
8596
8597 PQclear(res);
8598
8599 destroyPQExpBuffer(query);
8600}

References addObjectDependency(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_RULE, ExecuteSqlQuery(), fb(), findTableByOid(), i, pg_fatal, pg_malloc_array, 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:480
static void flagInhTables(Archive *fout, TableInfo *tblinfo, int numTables, InhInfo *inhinfo, int numInherits)
Definition common.c:270
static void flagInhIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8219
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition pg_dump.c:6169
void getPublicationNamespaces(Archive *fout)
Definition pg_dump.c:4758
void getPartitioningInfo(Archive *fout)
Definition pg_dump.c:7716
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition pg_dump.c:7660
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10338
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4187
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:19897
void getTypes(Archive *fout)
Definition pg_dump.c:6244
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7595
void getOpclasses(Archive *fout)
Definition pg_dump.c:6678
void getForeignServers(Archive *fout)
Definition pg_dump.c:10432
void getFuncs(Archive *fout)
Definition pg_dump.c:6921
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10154
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4838
void getCasts(Archive *fout)
Definition pg_dump.c:8964
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7776
void getTSConfigurations(Archive *fout)
Definition pg_dump.c:10279
void getAccessMethods(Archive *fout)
Definition pg_dump.c:6616
void getConversions(Archive *fout)
Definition pg_dump.c:6554
void getRules(Archive *fout)
Definition pg_dump.c:8513
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9154
void getCollations(Archive *fout)
Definition pg_dump.c:6488
void getAggregates(Archive *fout)
Definition pg_dump.c:6806
void getNamespaces(Archive *fout)
Definition pg_dump.c:6037
void getPublications(Archive *fout)
Definition pg_dump.c:4470
void getTSParsers(Archive *fout)
Definition pg_dump.c:10080
TableInfo * getTables(Archive *fout, int *numTables)
Definition pg_dump.c:7151
void getExtendedStatistics(Archive *fout)
Definition pg_dump.c:8141
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:19990
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10520
void getSubscriptions(Archive *fout)
Definition pg_dump.c:5113
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8610
void getTransforms(Archive *fout)
Definition pg_dump.c:9074
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8806
void getTSTemplates(Archive *fout)
Definition pg_dump.c:10220
void getProcLangs(Archive *fout)
Definition pg_dump.c:8880
void getSubscriptionRelations(Archive *fout)
Definition pg_dump.c:5362
void getOperators(Archive *fout)
Definition pg_dump.c:6412
void getOpfamilies(Archive *fout)
Definition pg_dump.c:6741

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

5363{
5364 DumpOptions *dopt = fout->dopt;
5365 SubscriptionInfo *subinfo = NULL;
5367 PGresult *res;
5368 int i_srsubid;
5369 int i_srrelid;
5370 int i_srsubstate;
5371 int i_srsublsn;
5372 int ntups;
5374
5375 if (dopt->no_subscriptions || !dopt->binary_upgrade ||
5376 fout->remoteVersion < 170000)
5377 return;
5378
5379 res = ExecuteSqlQuery(fout,
5380 "SELECT srsubid, srrelid, srsubstate, srsublsn "
5381 "FROM pg_catalog.pg_subscription_rel "
5382 "ORDER BY srsubid",
5384 ntups = PQntuples(res);
5385 if (ntups == 0)
5386 goto cleanup;
5387
5388 /* Get pg_subscription_rel attributes */
5389 i_srsubid = PQfnumber(res, "srsubid");
5390 i_srrelid = PQfnumber(res, "srrelid");
5391 i_srsubstate = PQfnumber(res, "srsubstate");
5392 i_srsublsn = PQfnumber(res, "srsublsn");
5393
5395 for (int i = 0; i < ntups; i++)
5396 {
5398 Oid relid = atooid(PQgetvalue(res, i, i_srrelid));
5399 TableInfo *tblinfo;
5400
5401 /*
5402 * If we switched to a new subscription, check if the subscription
5403 * exists.
5404 */
5406 {
5408 if (subinfo == NULL)
5409 pg_fatal("subscription with OID %u does not exist", cur_srsubid);
5410
5412 }
5413
5414 tblinfo = findTableByOid(relid);
5415 if (tblinfo == NULL)
5416 pg_fatal("failed sanity check, relation with OID %u not found",
5417 relid);
5418
5419 /* OK, make a DumpableObject for this relationship */
5420 subrinfo[i].dobj.objType = DO_SUBSCRIPTION_REL;
5421 subrinfo[i].dobj.catId.tableoid = relid;
5422 subrinfo[i].dobj.catId.oid = cur_srsubid;
5423 AssignDumpId(&subrinfo[i].dobj);
5424 subrinfo[i].dobj.namespace = tblinfo->dobj.namespace;
5425 subrinfo[i].dobj.name = tblinfo->dobj.name;
5426 subrinfo[i].subinfo = subinfo;
5427 subrinfo[i].tblinfo = tblinfo;
5428 subrinfo[i].srsubstate = PQgetvalue(res, i, i_srsubstate)[0];
5429 if (PQgetisnull(res, i, i_srsublsn))
5430 subrinfo[i].srsublsn = NULL;
5431 else
5432 subrinfo[i].srsublsn = pg_strdup(PQgetvalue(res, i, i_srsublsn));
5433
5434 /* Decide whether we want to dump it */
5436 }
5437
5438cleanup:
5439 PQclear(res);
5440}
SubscriptionInfo * findSubscriptionByOid(Oid oid)
Definition common.c:1047
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_array, pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getSubscriptions()

void getSubscriptions ( Archive fout)
extern

Definition at line 5113 of file pg_dump.c.

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

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_array, 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::subservername, _SubscriptionInfo::subslotname, _SubscriptionInfo::substream, _SubscriptionInfo::subsynccommit, _SubscriptionInfo::subtwophasestate, _SubscriptionInfo::subwalrcvtimeout, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getTableAttrs()

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

Definition at line 9154 of file pg_dump.c.

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

References addObjectDependency(), _attrDefInfo::adef_expr, _attrDefInfo::adnum, _attrDefInfo::adtable, appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, CppAsString2, 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_array, 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 7151 of file pg_dump.c.

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

9075{
9076 PGresult *res;
9077 int ntups;
9078 int i;
9079 PQExpBuffer query;
9081 int i_tableoid;
9082 int i_oid;
9083 int i_trftype;
9084 int i_trflang;
9085 int i_trffromsql;
9086 int i_trftosql;
9087
9088 query = createPQExpBuffer();
9089
9090 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9091 "trftype, trflang, trffromsql::oid, trftosql::oid "
9092 "FROM pg_transform "
9093 "ORDER BY 3,4");
9094
9095 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9096
9097 ntups = PQntuples(res);
9098
9100
9101 i_tableoid = PQfnumber(res, "tableoid");
9102 i_oid = PQfnumber(res, "oid");
9103 i_trftype = PQfnumber(res, "trftype");
9104 i_trflang = PQfnumber(res, "trflang");
9105 i_trffromsql = PQfnumber(res, "trffromsql");
9106 i_trftosql = PQfnumber(res, "trftosql");
9107
9108 for (i = 0; i < ntups; i++)
9109 {
9112 char *lanname;
9113
9115 transforminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9116 transforminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9118 transforminfo[i].trftype = atooid(PQgetvalue(res, i, i_trftype));
9119 transforminfo[i].trflang = atooid(PQgetvalue(res, i, i_trflang));
9120 transforminfo[i].trffromsql = atooid(PQgetvalue(res, i, i_trffromsql));
9121 transforminfo[i].trftosql = atooid(PQgetvalue(res, i, i_trftosql));
9122
9123 /*
9124 * Try to name transform as concatenation of type and language name.
9125 * This is only used for purposes of sorting. If we fail to find
9126 * either, the name will be an empty string.
9127 */
9131 if (typeInfo && lanname)
9132 appendPQExpBuffer(&namebuf, "%s %s",
9133 typeInfo->dobj.name, lanname);
9134 transforminfo[i].dobj.name = namebuf.data;
9135 free(lanname);
9136
9137 /* Decide whether we want to dump it */
9139 }
9140
9141 PQclear(res);
9142
9143 destroyPQExpBuffer(query);
9144}
static char * get_language_name(Archive *fout, Oid langid)
Definition pg_dump.c:9053

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

8611{
8614 PGresult *res;
8615 int ntups;
8616 int curtblindx;
8618 int i_tableoid,
8619 i_oid,
8620 i_tgrelid,
8621 i_tgname,
8624 i_tgdef;
8625
8626 /*
8627 * We want to perform just one query against pg_trigger. However, we
8628 * mustn't try to select every row of the catalog and then sort it out on
8629 * the client side, because some of the server-side functions we need
8630 * would be unsafe to apply to tables we don't have lock on. Hence, we
8631 * build an array of the OIDs of tables we care about (and now have lock
8632 * on!), and use a WHERE clause to constrain which rows are selected.
8633 */
8635 for (int i = 0; i < numTables; i++)
8636 {
8637 TableInfo *tbinfo = &tblinfo[i];
8638
8639 if (!tbinfo->hastriggers ||
8640 !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
8641 continue;
8642
8643 /* OK, we need info for this table */
8644 if (tbloids->len > 1) /* do we have more than the '{'? */
8646 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
8647 }
8649
8650 if (fout->remoteVersion >= 150000)
8651 {
8652 /*
8653 * NB: think not to use pretty=true in pg_get_triggerdef. It could
8654 * result in non-forward-compatible dumps of WHEN clauses due to
8655 * under-parenthesization.
8656 *
8657 * NB: We need to see partition triggers in case the tgenabled flag
8658 * has been changed from the parent.
8659 */
8660 appendPQExpBuffer(query,
8661 "SELECT t.tgrelid, t.tgname, "
8662 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8663 "t.tgenabled, t.tableoid, t.oid, "
8664 "t.tgparentid <> 0 AS tgispartition\n"
8665 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8666 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8667 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8668 "WHERE ((NOT t.tgisinternal AND t.tgparentid = 0) "
8669 "OR t.tgenabled != u.tgenabled) "
8670 "ORDER BY t.tgrelid, t.tgname",
8671 tbloids->data);
8672 }
8673 else if (fout->remoteVersion >= 130000)
8674 {
8675 /*
8676 * NB: think not to use pretty=true in pg_get_triggerdef. It could
8677 * result in non-forward-compatible dumps of WHEN clauses due to
8678 * under-parenthesization.
8679 *
8680 * NB: We need to see tgisinternal triggers in partitions, in case the
8681 * tgenabled flag has been changed from the parent.
8682 */
8683 appendPQExpBuffer(query,
8684 "SELECT t.tgrelid, t.tgname, "
8685 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8686 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
8687 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8688 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8689 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8690 "WHERE (NOT t.tgisinternal OR t.tgenabled != u.tgenabled) "
8691 "ORDER BY t.tgrelid, t.tgname",
8692 tbloids->data);
8693 }
8694 else if (fout->remoteVersion >= 110000)
8695 {
8696 /*
8697 * NB: We need to see tgisinternal triggers in partitions, in case the
8698 * tgenabled flag has been changed from the parent. No tgparentid in
8699 * version 11-12, so we have to match them via pg_depend.
8700 *
8701 * See above about pretty=true in pg_get_triggerdef.
8702 */
8703 appendPQExpBuffer(query,
8704 "SELECT t.tgrelid, t.tgname, "
8705 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8706 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
8707 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8708 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8709 "LEFT JOIN pg_catalog.pg_depend AS d ON "
8710 " d.classid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8711 " d.refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8712 " d.objid = t.oid "
8713 "LEFT JOIN pg_catalog.pg_trigger AS pt ON pt.oid = refobjid "
8714 "WHERE (NOT t.tgisinternal OR t.tgenabled != pt.tgenabled) "
8715 "ORDER BY t.tgrelid, t.tgname",
8716 tbloids->data);
8717 }
8718 else
8719 {
8720 /* See above about pretty=true in pg_get_triggerdef */
8721 appendPQExpBuffer(query,
8722 "SELECT t.tgrelid, t.tgname, "
8723 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8724 "t.tgenabled, false as tgispartition, "
8725 "t.tableoid, t.oid "
8726 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8727 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8728 "WHERE NOT tgisinternal "
8729 "ORDER BY t.tgrelid, t.tgname",
8730 tbloids->data);
8731 }
8732
8733 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8734
8735 ntups = PQntuples(res);
8736
8737 i_tableoid = PQfnumber(res, "tableoid");
8738 i_oid = PQfnumber(res, "oid");
8739 i_tgrelid = PQfnumber(res, "tgrelid");
8740 i_tgname = PQfnumber(res, "tgname");
8741 i_tgenabled = PQfnumber(res, "tgenabled");
8742 i_tgispartition = PQfnumber(res, "tgispartition");
8743 i_tgdef = PQfnumber(res, "tgdef");
8744
8746
8747 /*
8748 * Outer loop iterates once per table, not once per row. Incrementing of
8749 * j is handled by the inner loop.
8750 */
8751 curtblindx = -1;
8752 for (int j = 0; j < ntups;)
8753 {
8756 int numtrigs;
8757
8758 /* Count rows for this table */
8759 for (numtrigs = 1; numtrigs < ntups - j; numtrigs++)
8760 if (atooid(PQgetvalue(res, j + numtrigs, i_tgrelid)) != tgrelid)
8761 break;
8762
8763 /*
8764 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8765 * order.
8766 */
8767 while (++curtblindx < numTables)
8768 {
8769 tbinfo = &tblinfo[curtblindx];
8770 if (tbinfo->dobj.catId.oid == tgrelid)
8771 break;
8772 }
8773 if (curtblindx >= numTables)
8774 pg_fatal("unrecognized table OID %u", tgrelid);
8775
8776 /* Save data for this table */
8777 tbinfo->triggers = tginfo + j;
8778 tbinfo->numTriggers = numtrigs;
8779
8780 for (int c = 0; c < numtrigs; c++, j++)
8781 {
8782 tginfo[j].dobj.objType = DO_TRIGGER;
8783 tginfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
8784 tginfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
8785 AssignDumpId(&tginfo[j].dobj);
8786 tginfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_tgname));
8787 tginfo[j].dobj.namespace = tbinfo->dobj.namespace;
8788 tginfo[j].tgtable = tbinfo;
8789 tginfo[j].tgenabled = *(PQgetvalue(res, j, i_tgenabled));
8790 tginfo[j].tgispartition = *(PQgetvalue(res, j, i_tgispartition)) == 't';
8791 tginfo[j].tgdef = pg_strdup(PQgetvalue(res, j, i_tgdef));
8792 }
8793 }
8794
8795 PQclear(res);
8796
8797 destroyPQExpBuffer(query);
8799}

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

Referenced by getSchemaData().

◆ getTSConfigurations()

void getTSConfigurations ( Archive fout)
extern

Definition at line 10279 of file pg_dump.c.

10280{
10281 PGresult *res;
10282 int ntups;
10283 int i;
10284 PQExpBuffer query;
10286 int i_tableoid;
10287 int i_oid;
10288 int i_cfgname;
10289 int i_cfgnamespace;
10290 int i_cfgowner;
10291 int i_cfgparser;
10292
10293 query = createPQExpBuffer();
10294
10295 appendPQExpBufferStr(query, "SELECT tableoid, oid, cfgname, "
10296 "cfgnamespace, cfgowner, cfgparser "
10297 "FROM pg_ts_config");
10298
10299 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10300
10301 ntups = PQntuples(res);
10302
10304
10305 i_tableoid = PQfnumber(res, "tableoid");
10306 i_oid = PQfnumber(res, "oid");
10307 i_cfgname = PQfnumber(res, "cfgname");
10308 i_cfgnamespace = PQfnumber(res, "cfgnamespace");
10309 i_cfgowner = PQfnumber(res, "cfgowner");
10310 i_cfgparser = PQfnumber(res, "cfgparser");
10311
10312 for (i = 0; i < ntups; i++)
10313 {
10314 cfginfo[i].dobj.objType = DO_TSCONFIG;
10315 cfginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10316 cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10317 AssignDumpId(&cfginfo[i].dobj);
10318 cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname));
10319 cfginfo[i].dobj.namespace =
10321 cfginfo[i].rolname = getRoleName(PQgetvalue(res, i, i_cfgowner));
10322 cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser));
10323
10324 /* Decide whether we want to dump it */
10326 }
10327
10328 PQclear(res);
10329
10330 destroyPQExpBuffer(query);
10331}

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

Referenced by getSchemaData().

◆ getTSDictionaries()

void getTSDictionaries ( Archive fout)
extern

Definition at line 10154 of file pg_dump.c.

10155{
10156 PGresult *res;
10157 int ntups;
10158 int i;
10159 PQExpBuffer query;
10161 int i_tableoid;
10162 int i_oid;
10163 int i_dictname;
10164 int i_dictnamespace;
10165 int i_dictowner;
10166 int i_dicttemplate;
10167 int i_dictinitoption;
10168
10169 query = createPQExpBuffer();
10170
10171 appendPQExpBufferStr(query, "SELECT tableoid, oid, dictname, "
10172 "dictnamespace, dictowner, "
10173 "dicttemplate, dictinitoption "
10174 "FROM pg_ts_dict");
10175
10176 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10177
10178 ntups = PQntuples(res);
10179
10181
10182 i_tableoid = PQfnumber(res, "tableoid");
10183 i_oid = PQfnumber(res, "oid");
10184 i_dictname = PQfnumber(res, "dictname");
10185 i_dictnamespace = PQfnumber(res, "dictnamespace");
10186 i_dictowner = PQfnumber(res, "dictowner");
10187 i_dictinitoption = PQfnumber(res, "dictinitoption");
10188 i_dicttemplate = PQfnumber(res, "dicttemplate");
10189
10190 for (i = 0; i < ntups; i++)
10191 {
10192 dictinfo[i].dobj.objType = DO_TSDICT;
10193 dictinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10194 dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10195 AssignDumpId(&dictinfo[i].dobj);
10196 dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname));
10197 dictinfo[i].dobj.namespace =
10199 dictinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_dictowner));
10200 dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate));
10201 if (PQgetisnull(res, i, i_dictinitoption))
10202 dictinfo[i].dictinitoption = NULL;
10203 else
10204 dictinfo[i].dictinitoption = pg_strdup(PQgetvalue(res, i, i_dictinitoption));
10205
10206 /* Decide whether we want to dump it */
10208 }
10209
10210 PQclear(res);
10211
10212 destroyPQExpBuffer(query);
10213}

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

Referenced by getSchemaData().

◆ getTSParsers()

void getTSParsers ( Archive fout)
extern

Definition at line 10080 of file pg_dump.c.

10081{
10082 PGresult *res;
10083 int ntups;
10084 int i;
10085 PQExpBuffer query;
10087 int i_tableoid;
10088 int i_oid;
10089 int i_prsname;
10090 int i_prsnamespace;
10091 int i_prsstart;
10092 int i_prstoken;
10093 int i_prsend;
10094 int i_prsheadline;
10095 int i_prslextype;
10096
10097 query = createPQExpBuffer();
10098
10099 /*
10100 * find all text search objects, including builtin ones; we filter out
10101 * system-defined objects at dump-out time.
10102 */
10103
10104 appendPQExpBufferStr(query, "SELECT tableoid, oid, prsname, prsnamespace, "
10105 "prsstart::oid, prstoken::oid, "
10106 "prsend::oid, prsheadline::oid, prslextype::oid "
10107 "FROM pg_ts_parser");
10108
10109 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10110
10111 ntups = PQntuples(res);
10112
10114
10115 i_tableoid = PQfnumber(res, "tableoid");
10116 i_oid = PQfnumber(res, "oid");
10117 i_prsname = PQfnumber(res, "prsname");
10118 i_prsnamespace = PQfnumber(res, "prsnamespace");
10119 i_prsstart = PQfnumber(res, "prsstart");
10120 i_prstoken = PQfnumber(res, "prstoken");
10121 i_prsend = PQfnumber(res, "prsend");
10122 i_prsheadline = PQfnumber(res, "prsheadline");
10123 i_prslextype = PQfnumber(res, "prslextype");
10124
10125 for (i = 0; i < ntups; i++)
10126 {
10127 prsinfo[i].dobj.objType = DO_TSPARSER;
10128 prsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10129 prsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10130 AssignDumpId(&prsinfo[i].dobj);
10131 prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname));
10132 prsinfo[i].dobj.namespace =
10134 prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart));
10135 prsinfo[i].prstoken = atooid(PQgetvalue(res, i, i_prstoken));
10136 prsinfo[i].prsend = atooid(PQgetvalue(res, i, i_prsend));
10137 prsinfo[i].prsheadline = atooid(PQgetvalue(res, i, i_prsheadline));
10138 prsinfo[i].prslextype = atooid(PQgetvalue(res, i, i_prslextype));
10139
10140 /* Decide whether we want to dump it */
10142 }
10143
10144 PQclear(res);
10145
10146 destroyPQExpBuffer(query);
10147}

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

Referenced by getSchemaData().

◆ getTSTemplates()

void getTSTemplates ( Archive fout)
extern

Definition at line 10220 of file pg_dump.c.

10221{
10222 PGresult *res;
10223 int ntups;
10224 int i;
10225 PQExpBuffer query;
10227 int i_tableoid;
10228 int i_oid;
10229 int i_tmplname;
10230 int i_tmplnamespace;
10231 int i_tmplinit;
10232 int i_tmpllexize;
10233
10234 query = createPQExpBuffer();
10235
10236 appendPQExpBufferStr(query, "SELECT tableoid, oid, tmplname, "
10237 "tmplnamespace, tmplinit::oid, tmpllexize::oid "
10238 "FROM pg_ts_template");
10239
10240 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10241
10242 ntups = PQntuples(res);
10243
10245
10246 i_tableoid = PQfnumber(res, "tableoid");
10247 i_oid = PQfnumber(res, "oid");
10248 i_tmplname = PQfnumber(res, "tmplname");
10249 i_tmplnamespace = PQfnumber(res, "tmplnamespace");
10250 i_tmplinit = PQfnumber(res, "tmplinit");
10251 i_tmpllexize = PQfnumber(res, "tmpllexize");
10252
10253 for (i = 0; i < ntups; i++)
10254 {
10255 tmplinfo[i].dobj.objType = DO_TSTEMPLATE;
10256 tmplinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10257 tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10258 AssignDumpId(&tmplinfo[i].dobj);
10259 tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname));
10260 tmplinfo[i].dobj.namespace =
10262 tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit));
10263 tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize));
10264
10265 /* Decide whether we want to dump it */
10267 }
10268
10269 PQclear(res);
10270
10271 destroyPQExpBuffer(query);
10272}

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

Referenced by getSchemaData().

◆ getTypes()

void getTypes ( Archive fout)
extern

Definition at line 6244 of file pg_dump.c.

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

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_array, pg_malloc_object, 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 1114 of file common.c.

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

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

19992{
19993 DumpOptions *dopt = fout->dopt;
19994 PQExpBuffer query;
19995 PGresult *res;
19996 int ntups,
19997 i;
19998 int i_conrelid,
20000
20001 /* Nothing to do if no extensions */
20002 if (numExtensions == 0)
20003 return;
20004
20005 /*
20006 * Identify extension configuration tables and create TableDataInfo
20007 * objects for them, ensuring their data will be dumped even though the
20008 * tables themselves won't be.
20009 *
20010 * Note that we create TableDataInfo objects even in schema-only mode, ie,
20011 * user data in a configuration table is treated like schema data. This
20012 * seems appropriate since system data in a config table would get
20013 * reloaded by CREATE EXTENSION. If the extension is not listed in the
20014 * list of extensions to be included, none of its data is dumped.
20015 */
20016 for (i = 0; i < numExtensions; i++)
20017 {
20019 char *extconfig = curext->extconfig;
20020 char *extcondition = curext->extcondition;
20021 char **extconfigarray = NULL;
20022 char **extconditionarray = NULL;
20023 int nconfigitems = 0;
20024 int nconditionitems = 0;
20025
20026 /*
20027 * Check if this extension is listed as to include in the dump. If
20028 * not, any table data associated with it is discarded.
20029 */
20032 curext->dobj.catId.oid))
20033 continue;
20034
20035 /*
20036 * Check if this extension is listed as to exclude in the dump. If
20037 * yes, any table data associated with it is discarded.
20038 */
20041 curext->dobj.catId.oid))
20042 continue;
20043
20044 if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
20045 {
20046 int j;
20047
20048 if (!parsePGArray(extconfig, &extconfigarray, &nconfigitems))
20049 pg_fatal("could not parse %s array", "extconfig");
20050 if (!parsePGArray(extcondition, &extconditionarray, &nconditionitems))
20051 pg_fatal("could not parse %s array", "extcondition");
20053 pg_fatal("mismatched number of configurations and conditions for extension");
20054
20055 for (j = 0; j < nconfigitems; j++)
20056 {
20059 bool dumpobj =
20060 curext->dobj.dump & DUMP_COMPONENT_DEFINITION;
20061
20063 if (configtbl == NULL)
20064 continue;
20065
20066 /*
20067 * Tables of not-to-be-dumped extensions shouldn't be dumped
20068 * unless the table or its schema is explicitly included
20069 */
20070 if (!(curext->dobj.dump & DUMP_COMPONENT_DEFINITION))
20071 {
20072 /* check table explicitly requested */
20073 if (table_include_oids.head != NULL &&
20075 configtbloid))
20076 dumpobj = true;
20077
20078 /* check table's schema explicitly requested */
20079 if (configtbl->dobj.namespace->dobj.dump &
20081 dumpobj = true;
20082 }
20083
20084 /* check table excluded by an exclusion switch */
20085 if (table_exclude_oids.head != NULL &&
20087 configtbloid))
20088 dumpobj = false;
20089
20090 /* check schema excluded by an exclusion switch */
20092 configtbl->dobj.namespace->dobj.catId.oid))
20093 dumpobj = false;
20094
20095 if (dumpobj)
20096 {
20098 if (configtbl->dataObj != NULL)
20099 {
20100 if (strlen(extconditionarray[j]) > 0)
20101 configtbl->dataObj->filtercond = pg_strdup(extconditionarray[j]);
20102 }
20103 }
20104 }
20105 }
20106 if (extconfigarray)
20110 }
20111
20112 /*
20113 * Now that all the TableDataInfo objects have been created for all the
20114 * extensions, check their FK dependencies and register them to try and
20115 * dump the data out in an order that they can be restored in.
20116 *
20117 * Note that this is not a problem for user tables as their FKs are
20118 * recreated after the data has been loaded.
20119 */
20120
20121 query = createPQExpBuffer();
20122
20123 printfPQExpBuffer(query,
20124 "SELECT conrelid, confrelid "
20125 "FROM pg_constraint "
20126 "JOIN pg_depend ON (objid = confrelid) "
20127 "WHERE contype = 'f' "
20128 "AND refclassid = 'pg_extension'::regclass "
20129 "AND classid = 'pg_class'::regclass;");
20130
20131 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
20132 ntups = PQntuples(res);
20133
20134 i_conrelid = PQfnumber(res, "conrelid");
20135 i_confrelid = PQfnumber(res, "confrelid");
20136
20137 /* Now get the dependencies and register them */
20138 for (i = 0; i < ntups; i++)
20139 {
20140 Oid conrelid,
20141 confrelid;
20143 *contable;
20144
20145 conrelid = atooid(PQgetvalue(res, i, i_conrelid));
20146 confrelid = atooid(PQgetvalue(res, i, i_confrelid));
20147 contable = findTableByOid(conrelid);
20148 reftable = findTableByOid(confrelid);
20149
20150 if (reftable == NULL ||
20151 reftable->dataObj == NULL ||
20152 contable == NULL ||
20153 contable->dataObj == NULL)
20154 continue;
20155
20156 /*
20157 * Make referencing TABLE_DATA object depend on the referenced table's
20158 * TABLE_DATA object.
20159 */
20160 addObjectDependency(&contable->dataObj->dobj,
20161 reftable->dataObj->dobj.dumpId);
20162 }
20163 PQclear(res);
20164 destroyPQExpBuffer(query);
20165}
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:3000
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 722 of file common.c.

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

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

Referenced by getLOs().

◆ recordExtensionMembership()

void recordExtensionMembership ( CatalogId  catId,
ExtensionInfo ext 
)
extern

Definition at line 1066 of file common.c.

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

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

10066{
10067 if (dopt->binary_upgrade)
10068 return true;
10069 if (tbinfo->attisdropped[colno])
10070 return false;
10071 return (tbinfo->attislocal[colno] || tbinfo->ispartition);
10072}

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
576 while (!TopoSort(objs, numObjs, ordering, &nOrdering))
578
579 memcpy(objs, ordering, numObjs * sizeof(DumpableObject *));
580
581 pg_free(ordering);
582}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
void pg_free(void *ptr)
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(), memcpy(), pg_free(), pg_malloc_array, 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:496

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

Referenced by main().