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:8250
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:7747
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:7691
TableInfo * findTableByOid(Oid oid)
Definition common.c:866
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10369
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:19928
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:7626
void getOpclasses(Archive *fout)
Definition pg_dump.c:6678
void getForeignServers(Archive *fout)
Definition pg_dump.c:10463
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:10185
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:8995
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7807
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:10310
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:8544
ExtensionInfo * findOwningExtension(CatalogId catalogId)
Definition common.c:1090
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9185
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:10111
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:8172
struct _dumpableAcl DumpableAcl
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20021
DumpId getMaxDumpId(void)
Definition common.c:757
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10551
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:8641
void getTransforms(Archive *fout)
Definition pg_dump.c:9105
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8837
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:10251
void getProcLangs(Archive *fout)
Definition pg_dump.c:8911
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition pg_dump.c:10096
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:10648
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 8995 of file pg_dump.c.

8996{
8997 PGresult *res;
8998 int ntups;
8999 int i;
9002 int i_tableoid;
9003 int i_oid;
9004 int i_castsource;
9005 int i_casttarget;
9006 int i_castfunc;
9007 int i_castcontext;
9008 int i_castmethod;
9009
9010 if (fout->remoteVersion >= 140000)
9011 {
9012 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9013 "castsource, casttarget, castfunc, castcontext, "
9014 "castmethod "
9015 "FROM pg_cast c "
9016 "WHERE NOT EXISTS ( "
9017 "SELECT 1 FROM pg_range r "
9018 "WHERE c.castsource = r.rngtypid "
9019 "AND c.casttarget = r.rngmultitypid "
9020 ") "
9021 "ORDER BY 3,4");
9022 }
9023 else
9024 {
9025 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9026 "castsource, casttarget, castfunc, castcontext, "
9027 "castmethod "
9028 "FROM pg_cast ORDER BY 3,4");
9029 }
9030
9031 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9032
9033 ntups = PQntuples(res);
9034
9036
9037 i_tableoid = PQfnumber(res, "tableoid");
9038 i_oid = PQfnumber(res, "oid");
9039 i_castsource = PQfnumber(res, "castsource");
9040 i_casttarget = PQfnumber(res, "casttarget");
9041 i_castfunc = PQfnumber(res, "castfunc");
9042 i_castcontext = PQfnumber(res, "castcontext");
9043 i_castmethod = PQfnumber(res, "castmethod");
9044
9045 for (i = 0; i < ntups; i++)
9046 {
9050
9052 castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9053 castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9054 AssignDumpId(&castinfo[i].dobj);
9055 castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
9056 castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
9057 castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
9058 castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
9059 castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
9060
9061 /*
9062 * Try to name cast as concatenation of typnames. This is only used
9063 * for purposes of sorting. If we fail to find either type, the name
9064 * will be an empty string.
9065 */
9067 sTypeInfo = findTypeByOid(castinfo[i].castsource);
9068 tTypeInfo = findTypeByOid(castinfo[i].casttarget);
9069 if (sTypeInfo && tTypeInfo)
9070 appendPQExpBuffer(&namebuf, "%s %s",
9071 sTypeInfo->dobj.name, tTypeInfo->dobj.name);
9072 castinfo[i].dobj.name = namebuf.data;
9073
9074 /* Decide whether we want to dump it */
9076 }
9077
9078 PQclear(res);
9079
9080 destroyPQExpBuffer(query);
9081}
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 8250 of file pg_dump.c.

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

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

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

8838{
8839 int i;
8840 PQExpBuffer query;
8841 PGresult *res;
8843 int i_tableoid,
8844 i_oid,
8845 i_evtname,
8846 i_evtevent,
8847 i_evtowner,
8848 i_evttags,
8849 i_evtfname,
8851 int ntups;
8852
8853 query = createPQExpBuffer();
8854
8856 "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8857 "evtevent, evtowner, "
8858 "array_to_string(array("
8859 "select quote_literal(x) "
8860 " from unnest(evttags) as t(x)), ', ') as evttags, "
8861 "e.evtfoid::regproc as evtfname "
8862 "FROM pg_event_trigger e "
8863 "ORDER BY e.oid");
8864
8865 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8866
8867 ntups = PQntuples(res);
8868
8870
8871 i_tableoid = PQfnumber(res, "tableoid");
8872 i_oid = PQfnumber(res, "oid");
8873 i_evtname = PQfnumber(res, "evtname");
8874 i_evtevent = PQfnumber(res, "evtevent");
8875 i_evtowner = PQfnumber(res, "evtowner");
8876 i_evttags = PQfnumber(res, "evttags");
8877 i_evtfname = PQfnumber(res, "evtfname");
8878 i_evtenabled = PQfnumber(res, "evtenabled");
8879
8880 for (i = 0; i < ntups; i++)
8881 {
8882 evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
8883 evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8884 evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8885 AssignDumpId(&evtinfo[i].dobj);
8886 evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
8887 evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
8888 evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
8889 evtinfo[i].evtowner = getRoleName(PQgetvalue(res, i, i_evtowner));
8890 evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
8891 evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
8892 evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
8893
8894 /* Decide whether we want to dump it */
8896 }
8897
8898 PQclear(res);
8899
8900 destroyPQExpBuffer(query);
8901}

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

8173{
8174 PQExpBuffer query;
8175 PGresult *res;
8177 int ntups;
8178 int i_tableoid;
8179 int i_oid;
8180 int i_stxname;
8181 int i_stxnamespace;
8182 int i_stxowner;
8183 int i_stxrelid;
8184 int i_stattarget;
8185 int i;
8186
8187 query = createPQExpBuffer();
8188
8189 if (fout->remoteVersion < 130000)
8190 appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
8191 "stxnamespace, stxowner, stxrelid, NULL AS stxstattarget "
8192 "FROM pg_catalog.pg_statistic_ext");
8193 else
8194 appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
8195 "stxnamespace, stxowner, stxrelid, stxstattarget "
8196 "FROM pg_catalog.pg_statistic_ext");
8197
8198 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8199
8200 ntups = PQntuples(res);
8201
8202 i_tableoid = PQfnumber(res, "tableoid");
8203 i_oid = PQfnumber(res, "oid");
8204 i_stxname = PQfnumber(res, "stxname");
8205 i_stxnamespace = PQfnumber(res, "stxnamespace");
8206 i_stxowner = PQfnumber(res, "stxowner");
8207 i_stxrelid = PQfnumber(res, "stxrelid");
8208 i_stattarget = PQfnumber(res, "stxstattarget");
8209
8211
8212 for (i = 0; i < ntups; i++)
8213 {
8214 statsextinfo[i].dobj.objType = DO_STATSEXT;
8215 statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8216 statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8217 AssignDumpId(&statsextinfo[i].dobj);
8218 statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
8219 statsextinfo[i].dobj.namespace =
8221 statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
8222 statsextinfo[i].stattable =
8224 if (PQgetisnull(res, i, i_stattarget))
8225 statsextinfo[i].stattarget = -1;
8226 else
8227 statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
8228
8229 /* Decide whether we want to dump it */
8231
8232 if (fout->dopt->dumpStatistics)
8233 statsextinfo[i].dobj.components |= DUMP_COMPONENT_STATISTICS;
8234 }
8235
8236 PQclear(res);
8237 destroyPQExpBuffer(query);
8238}
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 19928 of file pg_dump.c.

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

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

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

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

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

7692{
7693 PGresult *res;
7694 int ntups;
7695 int i;
7698
7699 int i_inhrelid;
7700 int i_inhparent;
7701
7702 /* find all the inheritance information */
7703 appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
7704
7705 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7706
7707 ntups = PQntuples(res);
7708
7709 *numInherits = ntups;
7710
7712
7713 i_inhrelid = PQfnumber(res, "inhrelid");
7714 i_inhparent = PQfnumber(res, "inhparent");
7715
7716 for (i = 0; i < ntups; i++)
7717 {
7718 inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
7719 inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
7720 }
7721
7722 PQclear(res);
7723
7724 destroyPQExpBuffer(query);
7725
7726 return inhinfo;
7727}

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

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

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

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

8912{
8913 PGresult *res;
8914 int ntups;
8915 int i;
8918 int i_tableoid;
8919 int i_oid;
8920 int i_lanname;
8921 int i_lanpltrusted;
8922 int i_lanplcallfoid;
8923 int i_laninline;
8924 int i_lanvalidator;
8925 int i_lanacl;
8926 int i_acldefault;
8927 int i_lanowner;
8928
8929 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8930 "lanname, lanpltrusted, lanplcallfoid, "
8931 "laninline, lanvalidator, "
8932 "lanacl, "
8933 "acldefault('l', lanowner) AS acldefault, "
8934 "lanowner "
8935 "FROM pg_language "
8936 "WHERE lanispl "
8937 "ORDER BY oid");
8938
8939 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8940
8941 ntups = PQntuples(res);
8942
8944
8945 i_tableoid = PQfnumber(res, "tableoid");
8946 i_oid = PQfnumber(res, "oid");
8947 i_lanname = PQfnumber(res, "lanname");
8948 i_lanpltrusted = PQfnumber(res, "lanpltrusted");
8949 i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
8950 i_laninline = PQfnumber(res, "laninline");
8951 i_lanvalidator = PQfnumber(res, "lanvalidator");
8952 i_lanacl = PQfnumber(res, "lanacl");
8953 i_acldefault = PQfnumber(res, "acldefault");
8954 i_lanowner = PQfnumber(res, "lanowner");
8955
8956 for (i = 0; i < ntups; i++)
8957 {
8958 planginfo[i].dobj.objType = DO_PROCLANG;
8959 planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8960 planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8961 AssignDumpId(&planginfo[i].dobj);
8962
8963 planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
8964 planginfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_lanacl));
8965 planginfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
8966 planginfo[i].dacl.privtype = 0;
8967 planginfo[i].dacl.initprivs = NULL;
8968 planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
8969 planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
8970 planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
8971 planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
8972 planginfo[i].lanowner = getRoleName(PQgetvalue(res, i, i_lanowner));
8973
8974 /* Decide whether we want to dump it */
8976
8977 /* Mark whether language has an ACL */
8978 if (!PQgetisnull(res, i, i_lanacl))
8979 planginfo[i].dobj.components |= DUMP_COMPONENT_ACL;
8980 }
8981
8982 PQclear(res);
8983
8984 destroyPQExpBuffer(query);
8985}
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 8544 of file pg_dump.c.

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

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:8250
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:7747
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition pg_dump.c:7691
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10369
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:19928
void getTypes(Archive *fout)
Definition pg_dump.c:6244
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7626
void getOpclasses(Archive *fout)
Definition pg_dump.c:6678
void getForeignServers(Archive *fout)
Definition pg_dump.c:10463
void getFuncs(Archive *fout)
Definition pg_dump.c:6921
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10185
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4838
void getCasts(Archive *fout)
Definition pg_dump.c:8995
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7807
void getTSConfigurations(Archive *fout)
Definition pg_dump.c:10310
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:8544
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9185
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:10111
TableInfo * getTables(Archive *fout, int *numTables)
Definition pg_dump.c:7151
void getExtendedStatistics(Archive *fout)
Definition pg_dump.c:8172
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20021
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10551
void getSubscriptions(Archive *fout)
Definition pg_dump.c:5113
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8641
void getTransforms(Archive *fout)
Definition pg_dump.c:9105
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8837
void getTSTemplates(Archive *fout)
Definition pg_dump.c:10251
void getProcLangs(Archive *fout)
Definition pg_dump.c:8911
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 9185 of file pg_dump.c.

9186{
9187 DumpOptions *dopt = fout->dopt;
9192 PGresult *res;
9193 int ntups;
9194 int curtblindx;
9195 int i_attrelid;
9196 int i_attnum;
9197 int i_attname;
9198 int i_atttypname;
9199 int i_attstattarget;
9200 int i_attstorage;
9201 int i_typstorage;
9202 int i_attidentity;
9203 int i_attgenerated;
9204 int i_attisdropped;
9205 int i_attlen;
9206 int i_attalign;
9207 int i_attislocal;
9208 int i_notnull_name;
9213 int i_attoptions;
9214 int i_attcollation;
9215 int i_attcompression;
9216 int i_attfdwoptions;
9217 int i_attmissingval;
9218 int i_atthasdef;
9219
9220 /*
9221 * We want to perform just one query against pg_attribute, and then just
9222 * one against pg_attrdef (for DEFAULTs) and two against pg_constraint
9223 * (for CHECK constraints and for NOT NULL constraints). However, we
9224 * mustn't try to select every row of those catalogs and then sort it out
9225 * on the client side, because some of the server-side functions we need
9226 * would be unsafe to apply to tables we don't have lock on. Hence, we
9227 * build an array of the OIDs of tables we care about (and now have lock
9228 * on!), and use a WHERE clause to constrain which rows are selected.
9229 */
9232 for (int i = 0; i < numTables; i++)
9233 {
9234 TableInfo *tbinfo = &tblinfo[i];
9235
9236 /* Don't bother to collect info for sequences */
9237 if (tbinfo->relkind == RELKIND_SEQUENCE)
9238 continue;
9239
9240 /*
9241 * Don't bother with uninteresting tables, either. For binary
9242 * upgrades, this is bypassed for pg_largeobject_metadata and
9243 * pg_shdepend so that the columns names are collected for the
9244 * corresponding COPY commands. Restoring the data for those catalogs
9245 * is faster than restoring the equivalent set of large object
9246 * commands.
9247 */
9248 if (!tbinfo->interesting &&
9249 !(fout->dopt->binary_upgrade &&
9250 (tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId ||
9251 tbinfo->dobj.catId.oid == SharedDependRelationId)))
9252 continue;
9253
9254 /* OK, we need info for this table */
9255 if (tbloids->len > 1) /* do we have more than the '{'? */
9257 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
9258
9259 if (tbinfo->ncheck > 0)
9260 {
9261 /* Also make a list of the ones with check constraints */
9262 if (checkoids->len > 1) /* do we have more than the '{'? */
9264 appendPQExpBuffer(checkoids, "%u", tbinfo->dobj.catId.oid);
9265 }
9266 }
9269
9270 /*
9271 * Find all the user attributes and their types.
9272 *
9273 * Since we only want to dump COLLATE clauses for attributes whose
9274 * collation is different from their type's default, we use a CASE here to
9275 * suppress uninteresting attcollations cheaply.
9276 */
9278 "SELECT\n"
9279 "a.attrelid,\n"
9280 "a.attnum,\n"
9281 "a.attname,\n"
9282 "a.attstattarget,\n"
9283 "a.attstorage,\n"
9284 "t.typstorage,\n"
9285 "a.atthasdef,\n"
9286 "a.attisdropped,\n"
9287 "a.attlen,\n"
9288 "a.attalign,\n"
9289 "a.attislocal,\n"
9290 "pg_catalog.format_type(t.oid, a.atttypmod) AS atttypname,\n"
9291 "array_to_string(a.attoptions, ', ') AS attoptions,\n"
9292 "CASE WHEN a.attcollation <> t.typcollation "
9293 "THEN a.attcollation ELSE 0 END AS attcollation,\n"
9294 "pg_catalog.array_to_string(ARRAY("
9295 "SELECT pg_catalog.quote_ident(option_name) || "
9296 "' ' || pg_catalog.quote_literal(option_value) "
9297 "FROM pg_catalog.pg_options_to_table(attfdwoptions) "
9298 "ORDER BY option_name"
9299 "), E',\n ') AS attfdwoptions,\n");
9300
9301 /*
9302 * Find out any NOT NULL markings for each column. In 18 and up we read
9303 * pg_constraint to obtain the constraint name, and for valid constraints
9304 * also pg_description to obtain its comment. notnull_noinherit is set
9305 * according to the NO INHERIT property. For versions prior to 18, we
9306 * store an empty string as the name when a constraint is marked as
9307 * attnotnull (this cues dumpTableSchema to print the NOT NULL clause
9308 * without a name); also, such cases are never NO INHERIT.
9309 *
9310 * For invalid constraints, we need to store their OIDs for processing
9311 * elsewhere, so we bring the pg_constraint.oid value when the constraint
9312 * is invalid, and NULL otherwise. Their comments are handled not here
9313 * but by collectComments, because they're their own dumpable object.
9314 *
9315 * We track in notnull_islocal whether the constraint was defined directly
9316 * in this table or via an ancestor, for binary upgrade. flagInhAttrs
9317 * might modify this later.
9318 */
9319 if (fout->remoteVersion >= 180000)
9321 "co.conname AS notnull_name,\n"
9322 "CASE WHEN co.convalidated THEN pt.description"
9323 " ELSE NULL END AS notnull_comment,\n"
9324 "CASE WHEN NOT co.convalidated THEN co.oid "
9325 "ELSE NULL END AS notnull_invalidoid,\n"
9326 "co.connoinherit AS notnull_noinherit,\n"
9327 "co.conislocal AS notnull_islocal,\n");
9328 else
9330 "CASE WHEN a.attnotnull THEN '' ELSE NULL END AS notnull_name,\n"
9331 "NULL AS notnull_comment,\n"
9332 "NULL AS notnull_invalidoid,\n"
9333 "false AS notnull_noinherit,\n"
9334 "CASE WHEN a.attislocal THEN true\n"
9335 " WHEN a.attnotnull AND NOT a.attislocal THEN true\n"
9336 " ELSE false\n"
9337 "END AS notnull_islocal,\n");
9338
9339 if (fout->remoteVersion >= 140000)
9341 "a.attcompression AS attcompression,\n");
9342 else
9344 "'' AS attcompression,\n");
9345
9347 "a.attidentity,\n");
9348
9349 if (fout->remoteVersion >= 110000)
9351 "CASE WHEN a.atthasmissing AND NOT a.attisdropped "
9352 "THEN a.attmissingval ELSE null END AS attmissingval,\n");
9353 else
9355 "NULL AS attmissingval,\n");
9356
9357 if (fout->remoteVersion >= 120000)
9359 "a.attgenerated\n");
9360 else
9362 "'' AS attgenerated\n");
9363
9364 /* need left join to pg_type to not fail on dropped columns ... */
9366 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9367 "JOIN pg_catalog.pg_attribute a ON (src.tbloid = a.attrelid) "
9368 "LEFT JOIN pg_catalog.pg_type t "
9369 "ON (a.atttypid = t.oid)\n",
9370 tbloids->data);
9371
9372 /*
9373 * In versions 18 and up, we need pg_constraint for explicit NOT NULL
9374 * entries and pg_description to get their comments.
9375 */
9376 if (fout->remoteVersion >= 180000)
9378 " LEFT JOIN pg_catalog.pg_constraint co ON "
9379 "(a.attrelid = co.conrelid\n"
9380 " AND co.contype = 'n' AND "
9381 "co.conkey = array[a.attnum])\n"
9382 " LEFT JOIN pg_catalog.pg_description pt ON "
9383 "(pt.classoid = co.tableoid AND pt.objoid = co.oid)\n");
9384
9386 "WHERE a.attnum > 0::pg_catalog.int2\n");
9387
9388 /*
9389 * For binary upgrades from <v12, be sure to pick up
9390 * pg_largeobject_metadata's oid column.
9391 */
9392 if (fout->dopt->binary_upgrade && fout->remoteVersion < 120000)
9394 "OR (a.attnum = -2::pg_catalog.int2 AND src.tbloid = "
9396
9398 "ORDER BY a.attrelid, a.attnum");
9399
9401
9402 ntups = PQntuples(res);
9403
9404 i_attrelid = PQfnumber(res, "attrelid");
9405 i_attnum = PQfnumber(res, "attnum");
9406 i_attname = PQfnumber(res, "attname");
9407 i_atttypname = PQfnumber(res, "atttypname");
9408 i_attstattarget = PQfnumber(res, "attstattarget");
9409 i_attstorage = PQfnumber(res, "attstorage");
9410 i_typstorage = PQfnumber(res, "typstorage");
9411 i_attidentity = PQfnumber(res, "attidentity");
9412 i_attgenerated = PQfnumber(res, "attgenerated");
9413 i_attisdropped = PQfnumber(res, "attisdropped");
9414 i_attlen = PQfnumber(res, "attlen");
9415 i_attalign = PQfnumber(res, "attalign");
9416 i_attislocal = PQfnumber(res, "attislocal");
9417 i_notnull_name = PQfnumber(res, "notnull_name");
9418 i_notnull_comment = PQfnumber(res, "notnull_comment");
9419 i_notnull_invalidoid = PQfnumber(res, "notnull_invalidoid");
9420 i_notnull_noinherit = PQfnumber(res, "notnull_noinherit");
9421 i_notnull_islocal = PQfnumber(res, "notnull_islocal");
9422 i_attoptions = PQfnumber(res, "attoptions");
9423 i_attcollation = PQfnumber(res, "attcollation");
9424 i_attcompression = PQfnumber(res, "attcompression");
9425 i_attfdwoptions = PQfnumber(res, "attfdwoptions");
9426 i_attmissingval = PQfnumber(res, "attmissingval");
9427 i_atthasdef = PQfnumber(res, "atthasdef");
9428
9429 /* Within the next loop, we'll accumulate OIDs of tables with defaults */
9432
9433 /*
9434 * Outer loop iterates once per table, not once per row. Incrementing of
9435 * r is handled by the inner loop.
9436 */
9437 curtblindx = -1;
9438 for (int r = 0; r < ntups;)
9439 {
9440 Oid attrelid = atooid(PQgetvalue(res, r, i_attrelid));
9442 int numatts;
9443 bool hasdefaults;
9444
9445 /* Count rows for this table */
9446 for (numatts = 1; numatts < ntups - r; numatts++)
9447 if (atooid(PQgetvalue(res, r + numatts, i_attrelid)) != attrelid)
9448 break;
9449
9450 /*
9451 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
9452 * order.
9453 */
9454 while (++curtblindx < numTables)
9455 {
9456 tbinfo = &tblinfo[curtblindx];
9457 if (tbinfo->dobj.catId.oid == attrelid)
9458 break;
9459 }
9460 if (curtblindx >= numTables)
9461 pg_fatal("unrecognized table OID %u", attrelid);
9462 /* cross-check that we only got requested tables */
9463 if (tbinfo->relkind == RELKIND_SEQUENCE ||
9464 (!tbinfo->interesting &&
9465 !(fout->dopt->binary_upgrade &&
9466 (tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId ||
9467 tbinfo->dobj.catId.oid == SharedDependRelationId))))
9468 pg_fatal("unexpected column data for table \"%s\"",
9469 tbinfo->dobj.name);
9470
9471 /* Save data for this table */
9472 tbinfo->numatts = numatts;
9473 tbinfo->attnames = pg_malloc_array(char *, numatts);
9474 tbinfo->atttypnames = pg_malloc_array(char *, numatts);
9475 tbinfo->attstattarget = pg_malloc_array(int, numatts);
9476 tbinfo->attstorage = pg_malloc_array(char, numatts);
9477 tbinfo->typstorage = pg_malloc_array(char, numatts);
9478 tbinfo->attidentity = pg_malloc_array(char, numatts);
9479 tbinfo->attgenerated = pg_malloc_array(char, numatts);
9480 tbinfo->attisdropped = pg_malloc_array(bool, numatts);
9481 tbinfo->attlen = pg_malloc_array(int, numatts);
9482 tbinfo->attalign = pg_malloc_array(char, numatts);
9483 tbinfo->attislocal = pg_malloc_array(bool, numatts);
9484 tbinfo->attoptions = pg_malloc_array(char *, numatts);
9485 tbinfo->attcollation = pg_malloc_array(Oid, numatts);
9486 tbinfo->attcompression = pg_malloc_array(char, numatts);
9487 tbinfo->attfdwoptions = pg_malloc_array(char *, numatts);
9488 tbinfo->attmissingval = pg_malloc_array(char *, numatts);
9489 tbinfo->notnull_constrs = pg_malloc_array(char *, numatts);
9490 tbinfo->notnull_comment = pg_malloc_array(char *, numatts);
9491 tbinfo->notnull_invalid = pg_malloc_array(bool, numatts);
9492 tbinfo->notnull_noinh = pg_malloc_array(bool, numatts);
9493 tbinfo->notnull_islocal = pg_malloc_array(bool, numatts);
9494 tbinfo->attrdefs = pg_malloc_array(AttrDefInfo *, numatts);
9495 hasdefaults = false;
9496
9497 for (int j = 0; j < numatts; j++, r++)
9498 {
9499 if (j + 1 != atoi(PQgetvalue(res, r, i_attnum)) &&
9500 !(fout->dopt->binary_upgrade && fout->remoteVersion < 120000 &&
9501 tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId))
9502 pg_fatal("invalid column numbering in table \"%s\"",
9503 tbinfo->dobj.name);
9504 tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, r, i_attname));
9505 tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, r, i_atttypname));
9506 if (PQgetisnull(res, r, i_attstattarget))
9507 tbinfo->attstattarget[j] = -1;
9508 else
9509 tbinfo->attstattarget[j] = atoi(PQgetvalue(res, r, i_attstattarget));
9510 tbinfo->attstorage[j] = *(PQgetvalue(res, r, i_attstorage));
9511 tbinfo->typstorage[j] = *(PQgetvalue(res, r, i_typstorage));
9512 tbinfo->attidentity[j] = *(PQgetvalue(res, r, i_attidentity));
9513 tbinfo->attgenerated[j] = *(PQgetvalue(res, r, i_attgenerated));
9514 tbinfo->needs_override = tbinfo->needs_override || (tbinfo->attidentity[j] == ATTRIBUTE_IDENTITY_ALWAYS);
9515 tbinfo->attisdropped[j] = (PQgetvalue(res, r, i_attisdropped)[0] == 't');
9516 tbinfo->attlen[j] = atoi(PQgetvalue(res, r, i_attlen));
9517 tbinfo->attalign[j] = *(PQgetvalue(res, r, i_attalign));
9518 tbinfo->attislocal[j] = (PQgetvalue(res, r, i_attislocal)[0] == 't');
9519
9520 /* Handle not-null constraint name and flags */
9522 tbinfo, j,
9529
9530 tbinfo->notnull_comment[j] = PQgetisnull(res, r, i_notnull_comment) ?
9532 tbinfo->attoptions[j] = pg_strdup(PQgetvalue(res, r, i_attoptions));
9533 tbinfo->attcollation[j] = atooid(PQgetvalue(res, r, i_attcollation));
9534 tbinfo->attcompression[j] = *(PQgetvalue(res, r, i_attcompression));
9535 tbinfo->attfdwoptions[j] = pg_strdup(PQgetvalue(res, r, i_attfdwoptions));
9536 tbinfo->attmissingval[j] = pg_strdup(PQgetvalue(res, r, i_attmissingval));
9537 tbinfo->attrdefs[j] = NULL; /* fix below */
9538 if (PQgetvalue(res, r, i_atthasdef)[0] == 't')
9539 hasdefaults = true;
9540 }
9541
9542 if (hasdefaults)
9543 {
9544 /* Collect OIDs of interesting tables that have defaults */
9545 if (tbloids->len > 1) /* do we have more than the '{'? */
9547 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
9548 }
9549 }
9550
9551 /* If invalidnotnulloids has any data, finalize it */
9552 if (invalidnotnulloids != NULL)
9554
9555 PQclear(res);
9556
9557 /*
9558 * Now get info about column defaults. This is skipped for a data-only
9559 * dump, as it is only needed for table schemas.
9560 */
9561 if (dopt->dumpSchema && tbloids->len > 1)
9562 {
9563 AttrDefInfo *attrdefs;
9564 int numDefaults;
9566
9567 pg_log_info("finding table default expressions");
9568
9570
9571 printfPQExpBuffer(q, "SELECT a.tableoid, a.oid, adrelid, adnum, "
9572 "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc\n"
9573 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9574 "JOIN pg_catalog.pg_attrdef a ON (src.tbloid = a.adrelid)\n"
9575 "ORDER BY a.adrelid, a.adnum",
9576 tbloids->data);
9577
9579
9580 numDefaults = PQntuples(res);
9582
9583 curtblindx = -1;
9584 for (int j = 0; j < numDefaults; j++)
9585 {
9586 Oid adtableoid = atooid(PQgetvalue(res, j, 0));
9587 Oid adoid = atooid(PQgetvalue(res, j, 1));
9588 Oid adrelid = atooid(PQgetvalue(res, j, 2));
9589 int adnum = atoi(PQgetvalue(res, j, 3));
9590 char *adsrc = PQgetvalue(res, j, 4);
9591
9592 /*
9593 * Locate the associated TableInfo; we rely on tblinfo[] being in
9594 * OID order.
9595 */
9596 if (tbinfo == NULL || tbinfo->dobj.catId.oid != adrelid)
9597 {
9598 while (++curtblindx < numTables)
9599 {
9600 tbinfo = &tblinfo[curtblindx];
9601 if (tbinfo->dobj.catId.oid == adrelid)
9602 break;
9603 }
9604 if (curtblindx >= numTables)
9605 pg_fatal("unrecognized table OID %u", adrelid);
9606 }
9607
9608 if (adnum <= 0 || adnum > tbinfo->numatts)
9609 pg_fatal("invalid adnum value %d for table \"%s\"",
9610 adnum, tbinfo->dobj.name);
9611
9612 /*
9613 * dropped columns shouldn't have defaults, but just in case,
9614 * ignore 'em
9615 */
9616 if (tbinfo->attisdropped[adnum - 1])
9617 continue;
9618
9619 attrdefs[j].dobj.objType = DO_ATTRDEF;
9620 attrdefs[j].dobj.catId.tableoid = adtableoid;
9621 attrdefs[j].dobj.catId.oid = adoid;
9622 AssignDumpId(&attrdefs[j].dobj);
9623 attrdefs[j].adtable = tbinfo;
9624 attrdefs[j].adnum = adnum;
9625 attrdefs[j].adef_expr = pg_strdup(adsrc);
9626
9627 attrdefs[j].dobj.name = pg_strdup(tbinfo->dobj.name);
9628 attrdefs[j].dobj.namespace = tbinfo->dobj.namespace;
9629
9630 attrdefs[j].dobj.dump = tbinfo->dobj.dump;
9631
9632 /*
9633 * Figure out whether the default/generation expression should be
9634 * dumped as part of the main CREATE TABLE (or similar) command or
9635 * as a separate ALTER TABLE (or similar) command. The preference
9636 * is to put it into the CREATE command, but in some cases that's
9637 * not possible.
9638 */
9639 if (tbinfo->attgenerated[adnum - 1])
9640 {
9641 /*
9642 * Column generation expressions cannot be dumped separately,
9643 * because there is no syntax for it. By setting separate to
9644 * false here we prevent the "default" from being processed as
9645 * its own dumpable object. Later, flagInhAttrs() will mark
9646 * it as not to be dumped at all, if possible (that is, if it
9647 * can be inherited from a parent).
9648 */
9649 attrdefs[j].separate = false;
9650 }
9651 else if (tbinfo->relkind == RELKIND_VIEW)
9652 {
9653 /*
9654 * Defaults on a VIEW must always be dumped as separate ALTER
9655 * TABLE commands.
9656 */
9657 attrdefs[j].separate = true;
9658 }
9659 else if (!shouldPrintColumn(dopt, tbinfo, adnum - 1))
9660 {
9661 /* column will be suppressed, print default separately */
9662 attrdefs[j].separate = true;
9663 }
9664 else
9665 {
9666 attrdefs[j].separate = false;
9667 }
9668
9669 if (!attrdefs[j].separate)
9670 {
9671 /*
9672 * Mark the default as needing to appear before the table, so
9673 * that any dependencies it has must be emitted before the
9674 * CREATE TABLE. If this is not possible, we'll change to
9675 * "separate" mode while sorting dependencies.
9676 */
9678 attrdefs[j].dobj.dumpId);
9679 }
9680
9681 tbinfo->attrdefs[adnum - 1] = &attrdefs[j];
9682 }
9683
9684 PQclear(res);
9685 }
9686
9687 /*
9688 * Get info about NOT NULL NOT VALID constraints. This is skipped for a
9689 * data-only dump, as it is only needed for table schemas.
9690 */
9691 if (dopt->dumpSchema && invalidnotnulloids)
9692 {
9694 int numConstrs;
9695 int i_tableoid;
9696 int i_oid;
9697 int i_conrelid;
9698 int i_conname;
9699 int i_consrc;
9700 int i_conislocal;
9701
9702 pg_log_info("finding invalid not-null constraints");
9703
9706 "SELECT c.tableoid, c.oid, conrelid, conname, "
9707 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9708 "conislocal, convalidated "
9709 "FROM unnest('%s'::pg_catalog.oid[]) AS src(conoid)\n"
9710 "JOIN pg_catalog.pg_constraint c ON (src.conoid = c.oid)\n"
9711 "ORDER BY c.conrelid, c.conname",
9712 invalidnotnulloids->data);
9713
9715
9716 numConstrs = PQntuples(res);
9718
9719 i_tableoid = PQfnumber(res, "tableoid");
9720 i_oid = PQfnumber(res, "oid");
9721 i_conrelid = PQfnumber(res, "conrelid");
9722 i_conname = PQfnumber(res, "conname");
9723 i_consrc = PQfnumber(res, "consrc");
9724 i_conislocal = PQfnumber(res, "conislocal");
9725
9726 /* As above, this loop iterates once per table, not once per row */
9727 curtblindx = -1;
9728 for (int j = 0; j < numConstrs;)
9729 {
9730 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
9732 int numcons;
9733
9734 /* Count rows for this table */
9735 for (numcons = 1; numcons < numConstrs - j; numcons++)
9736 if (atooid(PQgetvalue(res, j + numcons, i_conrelid)) != conrelid)
9737 break;
9738
9739 /*
9740 * Locate the associated TableInfo; we rely on tblinfo[] being in
9741 * OID order.
9742 */
9743 while (++curtblindx < numTables)
9744 {
9745 tbinfo = &tblinfo[curtblindx];
9746 if (tbinfo->dobj.catId.oid == conrelid)
9747 break;
9748 }
9749 if (curtblindx >= numTables)
9750 pg_fatal("unrecognized table OID %u", conrelid);
9751
9752 for (int c = 0; c < numcons; c++, j++)
9753 {
9754 constrs[j].dobj.objType = DO_CONSTRAINT;
9755 constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
9756 constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
9757 AssignDumpId(&constrs[j].dobj);
9758 constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
9759 constrs[j].dobj.namespace = tbinfo->dobj.namespace;
9760 constrs[j].contable = tbinfo;
9761 constrs[j].condomain = NULL;
9762 constrs[j].contype = 'n';
9763 constrs[j].condef = pg_strdup(PQgetvalue(res, j, i_consrc));
9764 constrs[j].confrelid = InvalidOid;
9765 constrs[j].conindex = 0;
9766 constrs[j].condeferrable = false;
9767 constrs[j].condeferred = false;
9768 constrs[j].conislocal = (PQgetvalue(res, j, i_conislocal)[0] == 't');
9769
9770 /*
9771 * All invalid not-null constraints must be dumped separately,
9772 * because CREATE TABLE would not create them as invalid, and
9773 * also because they must be created after potentially
9774 * violating data has been loaded.
9775 */
9776 constrs[j].separate = true;
9777
9778 constrs[j].dobj.dump = tbinfo->dobj.dump;
9779 }
9780 }
9781 PQclear(res);
9782 }
9783
9784 /*
9785 * Get info about table CHECK constraints. This is skipped for a
9786 * data-only dump, as it is only needed for table schemas.
9787 */
9788 if (dopt->dumpSchema && checkoids->len > 2)
9789 {
9791 int numConstrs;
9792 int i_tableoid;
9793 int i_oid;
9794 int i_conrelid;
9795 int i_conname;
9796 int i_consrc;
9797 int i_conislocal;
9798 int i_convalidated;
9799
9800 pg_log_info("finding table check constraints");
9801
9804 "SELECT c.tableoid, c.oid, conrelid, conname, "
9805 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9806 "conislocal, convalidated "
9807 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9808 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
9809 "WHERE contype = 'c' "
9810 "ORDER BY c.conrelid, c.conname",
9811 checkoids->data);
9812
9814
9815 numConstrs = PQntuples(res);
9817
9818 i_tableoid = PQfnumber(res, "tableoid");
9819 i_oid = PQfnumber(res, "oid");
9820 i_conrelid = PQfnumber(res, "conrelid");
9821 i_conname = PQfnumber(res, "conname");
9822 i_consrc = PQfnumber(res, "consrc");
9823 i_conislocal = PQfnumber(res, "conislocal");
9824 i_convalidated = PQfnumber(res, "convalidated");
9825
9826 /* As above, this loop iterates once per table, not once per row */
9827 curtblindx = -1;
9828 for (int j = 0; j < numConstrs;)
9829 {
9830 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
9832 int numcons;
9833
9834 /* Count rows for this table */
9835 for (numcons = 1; numcons < numConstrs - j; numcons++)
9836 if (atooid(PQgetvalue(res, j + numcons, i_conrelid)) != conrelid)
9837 break;
9838
9839 /*
9840 * Locate the associated TableInfo; we rely on tblinfo[] being in
9841 * OID order.
9842 */
9843 while (++curtblindx < numTables)
9844 {
9845 tbinfo = &tblinfo[curtblindx];
9846 if (tbinfo->dobj.catId.oid == conrelid)
9847 break;
9848 }
9849 if (curtblindx >= numTables)
9850 pg_fatal("unrecognized table OID %u", conrelid);
9851
9852 if (numcons != tbinfo->ncheck)
9853 {
9854 pg_log_error(ngettext("expected %d check constraint on table \"%s\" but found %d",
9855 "expected %d check constraints on table \"%s\" but found %d",
9856 tbinfo->ncheck),
9857 tbinfo->ncheck, tbinfo->dobj.name, numcons);
9858 pg_log_error_hint("The system catalogs might be corrupted.");
9859 exit_nicely(1);
9860 }
9861
9862 tbinfo->checkexprs = constrs + j;
9863
9864 for (int c = 0; c < numcons; c++, j++)
9865 {
9866 bool validated = PQgetvalue(res, j, i_convalidated)[0] == 't';
9867
9868 constrs[j].dobj.objType = DO_CONSTRAINT;
9869 constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
9870 constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
9871 AssignDumpId(&constrs[j].dobj);
9872 constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
9873 constrs[j].dobj.namespace = tbinfo->dobj.namespace;
9874 constrs[j].contable = tbinfo;
9875 constrs[j].condomain = NULL;
9876 constrs[j].contype = 'c';
9877 constrs[j].condef = pg_strdup(PQgetvalue(res, j, i_consrc));
9878 constrs[j].confrelid = InvalidOid;
9879 constrs[j].conindex = 0;
9880 constrs[j].condeferrable = false;
9881 constrs[j].condeferred = false;
9882 constrs[j].conislocal = (PQgetvalue(res, j, i_conislocal)[0] == 't');
9883
9884 /*
9885 * An unvalidated constraint needs to be dumped separately, so
9886 * that potentially-violating existing data is loaded before
9887 * the constraint.
9888 */
9889 constrs[j].separate = !validated;
9890
9891 constrs[j].dobj.dump = tbinfo->dobj.dump;
9892
9893 /*
9894 * Mark the constraint as needing to appear before the table
9895 * --- this is so that any other dependencies of the
9896 * constraint will be emitted before we try to create the
9897 * table. If the constraint is to be dumped separately, it
9898 * will be dumped after data is loaded anyway, so don't do it.
9899 * (There's an automatic dependency in the opposite direction
9900 * anyway, so don't need to add one manually here.)
9901 */
9902 if (!constrs[j].separate)
9904 constrs[j].dobj.dumpId);
9905
9906 /*
9907 * We will detect later whether the constraint must be split
9908 * out from the table definition.
9909 */
9910 }
9911 }
9912
9913 PQclear(res);
9914 }
9915
9919}
#define ngettext(s, p, n)
Definition c.h:1310
#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:9969
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition pg_dump.c:10096
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"
7235 " WHEN c.relkind = " CppAsString2(RELKIND_PROPGRAPH));
7236 /* 19beta1 didn't support acldefault('g'), so we'll fix that below */
7238 fout->remoteVersion >= 200000 ?
7239 " THEN 'g'::\"char\"" :
7240 " THEN NULL");
7242 " WHEN c.relkind = " CppAsString2(RELKIND_SEQUENCE)
7243 " THEN 's'::\"char\""
7244 " ELSE 'r'::\"char\" END, c.relowner) AS acldefault, "
7245 "CASE WHEN c.relkind = " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN "
7246 "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) "
7247 "ELSE 0 END AS foreignserver, "
7248 "c.relfrozenxid, tc.relfrozenxid AS tfrozenxid, "
7249 "tc.oid AS toid, "
7250 "tc.relpages AS toastpages, "
7251 "tc.reloptions AS toast_reloptions, "
7252 "d.refobjid AS owning_tab, "
7253 "d.refobjsubid AS owning_col, "
7254 "tsp.spcname AS reltablespace, ");
7255
7256 if (fout->remoteVersion >= 120000)
7258 "false AS relhasoids, ");
7259 else
7261 "c.relhasoids, ");
7262
7264 "c.relispopulated, ");
7265
7267 "c.relreplident, ");
7268
7270 "c.relrowsecurity, c.relforcerowsecurity, ");
7271
7273 "c.relminmxid, tc.relminmxid AS tminmxid, ");
7274
7276 "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, "
7277 "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text "
7278 "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, ");
7279
7281 "am.amname, ");
7282
7284 "(d.deptype = 'i') IS TRUE AS is_identity_sequence, ");
7285
7287 "c.relispartition AS ispartition ");
7288
7289 /*
7290 * Left join to pg_depend to pick up dependency info linking sequences to
7291 * their owning column, if any (note this dependency is AUTO except for
7292 * identity sequences, where it's INTERNAL). Also join to pg_tablespace to
7293 * collect the spcname.
7294 */
7296 "\nFROM pg_class c\n"
7297 "LEFT JOIN pg_depend d ON "
7298 "(c.relkind = " CppAsString2(RELKIND_SEQUENCE) " AND "
7299 "d.classid = 'pg_class'::regclass AND d.objid = c.oid AND "
7300 "d.objsubid = 0 AND "
7301 "d.refclassid = 'pg_class'::regclass AND d.deptype IN ('a', 'i'))\n"
7302 "LEFT JOIN pg_tablespace tsp ON (tsp.oid = c.reltablespace)\n");
7303
7304 /*
7305 * Left join to pg_am to pick up the amname.
7306 */
7308 "LEFT JOIN pg_am am ON (c.relam = am.oid)\n");
7309
7310 /*
7311 * We purposefully ignore toast OIDs for partitioned tables; the reason is
7312 * that versions 10 and 11 have them, but later versions do not, so
7313 * emitting them causes the upgrade to fail.
7314 */
7316 "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid"
7317 " AND tc.relkind = " CppAsString2(RELKIND_TOASTVALUE)
7318 " AND c.relkind <> " CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n");
7319
7320 /*
7321 * Restrict to interesting relkinds (in particular, not indexes). Not all
7322 * relkinds are possible in older servers, but it's not worth the trouble
7323 * to emit a version-dependent list.
7324 *
7325 * Composite-type table entries won't be dumped as such, but we have to
7326 * make a DumpableObject for them so that we can track dependencies of the
7327 * composite type (pg_depend entries for columns of the composite type
7328 * link to the pg_class entry not the pg_type entry).
7329 */
7331 "WHERE c.relkind IN ("
7340 "ORDER BY c.oid");
7341
7342 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7343
7344 ntups = PQntuples(res);
7345
7346 *numTables = ntups;
7347
7348 /*
7349 * Extract data from result and lock dumpable tables. We do the locking
7350 * before anything else, to minimize the window wherein a table could
7351 * disappear under us.
7352 *
7353 * Note that we have to save info about all tables here, even when dumping
7354 * only one, because we don't yet know which tables might be inheritance
7355 * ancestors of the target table.
7356 */
7357 tblinfo = pg_malloc0_array(TableInfo, ntups);
7358
7359 i_reltableoid = PQfnumber(res, "tableoid");
7360 i_reloid = PQfnumber(res, "oid");
7361 i_relname = PQfnumber(res, "relname");
7362 i_relnamespace = PQfnumber(res, "relnamespace");
7363 i_relkind = PQfnumber(res, "relkind");
7364 i_reltype = PQfnumber(res, "reltype");
7365 i_relowner = PQfnumber(res, "relowner");
7366 i_relchecks = PQfnumber(res, "relchecks");
7367 i_relhasindex = PQfnumber(res, "relhasindex");
7368 i_relhasrules = PQfnumber(res, "relhasrules");
7369 i_relpages = PQfnumber(res, "relpages");
7370 i_reltuples = PQfnumber(res, "reltuples");
7371 i_relallvisible = PQfnumber(res, "relallvisible");
7372 i_relallfrozen = PQfnumber(res, "relallfrozen");
7373 i_toastpages = PQfnumber(res, "toastpages");
7374 i_owning_tab = PQfnumber(res, "owning_tab");
7375 i_owning_col = PQfnumber(res, "owning_col");
7376 i_reltablespace = PQfnumber(res, "reltablespace");
7377 i_relhasoids = PQfnumber(res, "relhasoids");
7378 i_relhastriggers = PQfnumber(res, "relhastriggers");
7379 i_relpersistence = PQfnumber(res, "relpersistence");
7380 i_relispopulated = PQfnumber(res, "relispopulated");
7381 i_relreplident = PQfnumber(res, "relreplident");
7382 i_relrowsec = PQfnumber(res, "relrowsecurity");
7383 i_relforcerowsec = PQfnumber(res, "relforcerowsecurity");
7384 i_relfrozenxid = PQfnumber(res, "relfrozenxid");
7385 i_toastfrozenxid = PQfnumber(res, "tfrozenxid");
7386 i_toastoid = PQfnumber(res, "toid");
7387 i_relminmxid = PQfnumber(res, "relminmxid");
7388 i_toastminmxid = PQfnumber(res, "tminmxid");
7389 i_reloptions = PQfnumber(res, "reloptions");
7390 i_checkoption = PQfnumber(res, "checkoption");
7391 i_toastreloptions = PQfnumber(res, "toast_reloptions");
7392 i_reloftype = PQfnumber(res, "reloftype");
7393 i_foreignserver = PQfnumber(res, "foreignserver");
7394 i_amname = PQfnumber(res, "amname");
7395 i_is_identity_sequence = PQfnumber(res, "is_identity_sequence");
7396 i_relacl = PQfnumber(res, "relacl");
7397 i_acldefault = PQfnumber(res, "acldefault");
7398 i_ispartition = PQfnumber(res, "ispartition");
7399
7400 if (dopt->lockWaitTimeout)
7401 {
7402 /*
7403 * Arrange to fail instead of waiting forever for a table lock.
7404 *
7405 * NB: this coding assumes that the only queries issued within the
7406 * following loop are LOCK TABLEs; else the timeout may be undesirably
7407 * applied to other things too.
7408 */
7409 resetPQExpBuffer(query);
7410 appendPQExpBufferStr(query, "SET statement_timeout = ");
7412 ExecuteSqlStatement(fout, query->data);
7413 }
7414
7415 resetPQExpBuffer(query);
7416
7417 for (i = 0; i < ntups; i++)
7418 {
7419 int32 relallvisible = atoi(PQgetvalue(res, i, i_relallvisible));
7420 int32 relallfrozen = atoi(PQgetvalue(res, i, i_relallfrozen));
7421
7422 tblinfo[i].dobj.objType = DO_TABLE;
7423 tblinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_reltableoid));
7424 tblinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_reloid));
7425 AssignDumpId(&tblinfo[i].dobj);
7426 tblinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_relname));
7427 tblinfo[i].dobj.namespace =
7429 tblinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_relacl));
7430 /* acldefault computed below */
7431 tblinfo[i].dacl.privtype = 0;
7432 tblinfo[i].dacl.initprivs = NULL;
7433 tblinfo[i].relkind = *(PQgetvalue(res, i, i_relkind));
7434 tblinfo[i].reltype = atooid(PQgetvalue(res, i, i_reltype));
7435 tblinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_relowner));
7436 tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
7437 tblinfo[i].hasindex = (strcmp(PQgetvalue(res, i, i_relhasindex), "t") == 0);
7438 tblinfo[i].hasrules = (strcmp(PQgetvalue(res, i, i_relhasrules), "t") == 0);
7439 tblinfo[i].relpages = atoi(PQgetvalue(res, i, i_relpages));
7440 if (PQgetisnull(res, i, i_toastpages))
7441 tblinfo[i].toastpages = 0;
7442 else
7443 tblinfo[i].toastpages = atoi(PQgetvalue(res, i, i_toastpages));
7444 if (PQgetisnull(res, i, i_owning_tab))
7445 {
7446 tblinfo[i].owning_tab = InvalidOid;
7447 tblinfo[i].owning_col = 0;
7448 }
7449 else
7450 {
7451 tblinfo[i].owning_tab = atooid(PQgetvalue(res, i, i_owning_tab));
7452 tblinfo[i].owning_col = atoi(PQgetvalue(res, i, i_owning_col));
7453 }
7455 tblinfo[i].hasoids = (strcmp(PQgetvalue(res, i, i_relhasoids), "t") == 0);
7456 tblinfo[i].hastriggers = (strcmp(PQgetvalue(res, i, i_relhastriggers), "t") == 0);
7457 tblinfo[i].relpersistence = *(PQgetvalue(res, i, i_relpersistence));
7458 tblinfo[i].relispopulated = (strcmp(PQgetvalue(res, i, i_relispopulated), "t") == 0);
7459 tblinfo[i].relreplident = *(PQgetvalue(res, i, i_relreplident));
7460 tblinfo[i].rowsec = (strcmp(PQgetvalue(res, i, i_relrowsec), "t") == 0);
7461 tblinfo[i].forcerowsec = (strcmp(PQgetvalue(res, i, i_relforcerowsec), "t") == 0);
7462 tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid));
7464 tblinfo[i].toast_oid = atooid(PQgetvalue(res, i, i_toastoid));
7465 tblinfo[i].minmxid = atooid(PQgetvalue(res, i, i_relminmxid));
7466 tblinfo[i].toast_minmxid = atooid(PQgetvalue(res, i, i_toastminmxid));
7467 tblinfo[i].reloptions = pg_strdup(PQgetvalue(res, i, i_reloptions));
7468 if (PQgetisnull(res, i, i_checkoption))
7469 tblinfo[i].checkoption = NULL;
7470 else
7471 tblinfo[i].checkoption = pg_strdup(PQgetvalue(res, i, i_checkoption));
7473 tblinfo[i].reloftype = atooid(PQgetvalue(res, i, i_reloftype));
7475 if (PQgetisnull(res, i, i_amname))
7476 tblinfo[i].amname = NULL;
7477 else
7478 tblinfo[i].amname = pg_strdup(PQgetvalue(res, i, i_amname));
7479 tblinfo[i].is_identity_sequence = (strcmp(PQgetvalue(res, i, i_is_identity_sequence), "t") == 0);
7480 tblinfo[i].ispartition = (strcmp(PQgetvalue(res, i, i_ispartition), "t") == 0);
7481
7482 if (tblinfo[i].relkind == RELKIND_PROPGRAPH &&
7483 !(fout->remoteVersion >= 200000))
7484 {
7487
7488 /* Standard ACL as of v19 is {owner=r/owner} */
7490 quoteAclUserName(aclitem, tblinfo[i].rolname);
7492 quoteAclUserName(aclitem, tblinfo[i].rolname);
7495
7496 tblinfo[i].dacl.acldefault = pstrdup(aclarray->data);
7497
7500 }
7501 else
7502 tblinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
7503
7504 /* other fields were zeroed above */
7505
7506 /*
7507 * Decide whether we want to dump this table.
7508 */
7509 if (tblinfo[i].relkind == RELKIND_COMPOSITE_TYPE)
7510 tblinfo[i].dobj.dump = DUMP_COMPONENT_NONE;
7511 else
7512 selectDumpableTable(&tblinfo[i], fout);
7513
7514 /*
7515 * Now, consider the table "interesting" if we need to dump its
7516 * definition, data or its statistics. Later on, we'll skip a lot of
7517 * data collection for uninteresting tables.
7518 *
7519 * Note: the "interesting" flag will also be set by flagInhTables for
7520 * parents of interesting tables, so that we collect necessary
7521 * inheritance info even when the parents are not themselves being
7522 * dumped. This is the main reason why we need an "interesting" flag
7523 * that's separate from the components-to-dump bitmask.
7524 */
7525 tblinfo[i].interesting = (tblinfo[i].dobj.dump &
7529
7530 tblinfo[i].dummy_view = false; /* might get set during sort */
7531 tblinfo[i].postponed_def = false; /* might get set during sort */
7532
7533 /* Tables have data */
7535
7536 /* Mark whether table has an ACL */
7537 if (!PQgetisnull(res, i, i_relacl))
7538 tblinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
7539 tblinfo[i].hascolumnACLs = false; /* may get set later */
7540
7541 /* Add statistics */
7542 if (tblinfo[i].interesting)
7543 {
7544 RelStatsInfo *stats;
7545
7546 stats = getRelationStatistics(fout, &tblinfo[i].dobj,
7547 tblinfo[i].relpages,
7548 PQgetvalue(res, i, i_reltuples),
7549 relallvisible, relallfrozen,
7550 tblinfo[i].relkind, NULL, 0);
7551 if (tblinfo[i].relkind == RELKIND_MATVIEW)
7552 tblinfo[i].stats = stats;
7553 }
7554
7555 /*
7556 * Read-lock target tables to make sure they aren't DROPPED or altered
7557 * in schema before we get around to dumping them.
7558 *
7559 * Note that we don't explicitly lock parents of the target tables; we
7560 * assume our lock on the child is enough to prevent schema
7561 * alterations to parent tables.
7562 *
7563 * NOTE: it'd be kinda nice to lock other relations too, not only
7564 * plain or partitioned tables, but the backend doesn't presently
7565 * allow that.
7566 *
7567 * We only need to lock the table for certain components; see
7568 * pg_dump.h
7569 */
7570 if ((tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK) &&
7571 (tblinfo[i].relkind == RELKIND_RELATION ||
7572 tblinfo[i].relkind == RELKIND_PARTITIONED_TABLE))
7573 {
7574 /*
7575 * Tables are locked in batches. When dumping from a remote
7576 * server this can save a significant amount of time by reducing
7577 * the number of round trips.
7578 */
7579 if (query->len == 0)
7580 appendPQExpBuffer(query, "LOCK TABLE %s",
7581 fmtQualifiedDumpable(&tblinfo[i]));
7582 else
7583 {
7584 appendPQExpBuffer(query, ", %s",
7585 fmtQualifiedDumpable(&tblinfo[i]));
7586
7587 /* Arbitrarily end a batch when query length reaches 100K. */
7588 if (query->len >= 100000)
7589 {
7590 /* Lock another batch of tables. */
7591 appendPQExpBufferStr(query, " IN ACCESS SHARE MODE");
7592 ExecuteSqlStatement(fout, query->data);
7593 resetPQExpBuffer(query);
7594 }
7595 }
7596 }
7597 }
7598
7599 if (query->len != 0)
7600 {
7601 /* Lock the tables in the last batch. */
7602 appendPQExpBufferStr(query, " IN ACCESS SHARE MODE");
7603 ExecuteSqlStatement(fout, query->data);
7604 }
7605
7606 if (dopt->lockWaitTimeout)
7607 {
7608 ExecuteSqlStatement(fout, "SET statement_timeout = 0");
7609 }
7610
7611 PQclear(res);
7612
7613 destroyPQExpBuffer(query);
7614
7615 return tblinfo;
7616}
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, appendPGArray(), appendPQExpBuffer(), appendPQExpBufferChar(), 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, pstrdup(), quoteAclUserName(), _tableInfo::relispopulated, _tableInfo::relkind, _tableInfo::reloftype, _tableInfo::reloptions, _tableInfo::relpages, _tableInfo::relpersistence, _tableInfo::relreplident, _tableInfo::reltablespace, _tableInfo::reltype, resetPQExpBuffer(), _tableInfo::rolname, 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 9105 of file pg_dump.c.

9106{
9107 PGresult *res;
9108 int ntups;
9109 int i;
9110 PQExpBuffer query;
9112 int i_tableoid;
9113 int i_oid;
9114 int i_trftype;
9115 int i_trflang;
9116 int i_trffromsql;
9117 int i_trftosql;
9118
9119 query = createPQExpBuffer();
9120
9121 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9122 "trftype, trflang, trffromsql::oid, trftosql::oid "
9123 "FROM pg_transform "
9124 "ORDER BY 3,4");
9125
9126 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9127
9128 ntups = PQntuples(res);
9129
9131
9132 i_tableoid = PQfnumber(res, "tableoid");
9133 i_oid = PQfnumber(res, "oid");
9134 i_trftype = PQfnumber(res, "trftype");
9135 i_trflang = PQfnumber(res, "trflang");
9136 i_trffromsql = PQfnumber(res, "trffromsql");
9137 i_trftosql = PQfnumber(res, "trftosql");
9138
9139 for (i = 0; i < ntups; i++)
9140 {
9143 char *lanname;
9144
9146 transforminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9147 transforminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9149 transforminfo[i].trftype = atooid(PQgetvalue(res, i, i_trftype));
9150 transforminfo[i].trflang = atooid(PQgetvalue(res, i, i_trflang));
9151 transforminfo[i].trffromsql = atooid(PQgetvalue(res, i, i_trffromsql));
9152 transforminfo[i].trftosql = atooid(PQgetvalue(res, i, i_trftosql));
9153
9154 /*
9155 * Try to name transform as concatenation of type and language name.
9156 * This is only used for purposes of sorting. If we fail to find
9157 * either, the name will be an empty string.
9158 */
9162 if (typeInfo && lanname)
9163 appendPQExpBuffer(&namebuf, "%s %s",
9164 typeInfo->dobj.name, lanname);
9165 transforminfo[i].dobj.name = namebuf.data;
9166 free(lanname);
9167
9168 /* Decide whether we want to dump it */
9170 }
9171
9172 PQclear(res);
9173
9174 destroyPQExpBuffer(query);
9175}
static char * get_language_name(Archive *fout, Oid langid)
Definition pg_dump.c:9084

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

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

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

10311{
10312 PGresult *res;
10313 int ntups;
10314 int i;
10315 PQExpBuffer query;
10317 int i_tableoid;
10318 int i_oid;
10319 int i_cfgname;
10320 int i_cfgnamespace;
10321 int i_cfgowner;
10322 int i_cfgparser;
10323
10324 query = createPQExpBuffer();
10325
10326 appendPQExpBufferStr(query, "SELECT tableoid, oid, cfgname, "
10327 "cfgnamespace, cfgowner, cfgparser "
10328 "FROM pg_ts_config");
10329
10330 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10331
10332 ntups = PQntuples(res);
10333
10335
10336 i_tableoid = PQfnumber(res, "tableoid");
10337 i_oid = PQfnumber(res, "oid");
10338 i_cfgname = PQfnumber(res, "cfgname");
10339 i_cfgnamespace = PQfnumber(res, "cfgnamespace");
10340 i_cfgowner = PQfnumber(res, "cfgowner");
10341 i_cfgparser = PQfnumber(res, "cfgparser");
10342
10343 for (i = 0; i < ntups; i++)
10344 {
10345 cfginfo[i].dobj.objType = DO_TSCONFIG;
10346 cfginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10347 cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10348 AssignDumpId(&cfginfo[i].dobj);
10349 cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname));
10350 cfginfo[i].dobj.namespace =
10352 cfginfo[i].rolname = getRoleName(PQgetvalue(res, i, i_cfgowner));
10353 cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser));
10354
10355 /* Decide whether we want to dump it */
10357 }
10358
10359 PQclear(res);
10360
10361 destroyPQExpBuffer(query);
10362}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_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 10185 of file pg_dump.c.

10186{
10187 PGresult *res;
10188 int ntups;
10189 int i;
10190 PQExpBuffer query;
10192 int i_tableoid;
10193 int i_oid;
10194 int i_dictname;
10195 int i_dictnamespace;
10196 int i_dictowner;
10197 int i_dicttemplate;
10198 int i_dictinitoption;
10199
10200 query = createPQExpBuffer();
10201
10202 appendPQExpBufferStr(query, "SELECT tableoid, oid, dictname, "
10203 "dictnamespace, dictowner, "
10204 "dicttemplate, dictinitoption "
10205 "FROM pg_ts_dict");
10206
10207 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10208
10209 ntups = PQntuples(res);
10210
10212
10213 i_tableoid = PQfnumber(res, "tableoid");
10214 i_oid = PQfnumber(res, "oid");
10215 i_dictname = PQfnumber(res, "dictname");
10216 i_dictnamespace = PQfnumber(res, "dictnamespace");
10217 i_dictowner = PQfnumber(res, "dictowner");
10218 i_dictinitoption = PQfnumber(res, "dictinitoption");
10219 i_dicttemplate = PQfnumber(res, "dicttemplate");
10220
10221 for (i = 0; i < ntups; i++)
10222 {
10223 dictinfo[i].dobj.objType = DO_TSDICT;
10224 dictinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10225 dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10226 AssignDumpId(&dictinfo[i].dobj);
10227 dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname));
10228 dictinfo[i].dobj.namespace =
10230 dictinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_dictowner));
10231 dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate));
10232 if (PQgetisnull(res, i, i_dictinitoption))
10233 dictinfo[i].dictinitoption = NULL;
10234 else
10235 dictinfo[i].dictinitoption = pg_strdup(PQgetvalue(res, i, i_dictinitoption));
10236
10237 /* Decide whether we want to dump it */
10239 }
10240
10241 PQclear(res);
10242
10243 destroyPQExpBuffer(query);
10244}

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

10112{
10113 PGresult *res;
10114 int ntups;
10115 int i;
10116 PQExpBuffer query;
10118 int i_tableoid;
10119 int i_oid;
10120 int i_prsname;
10121 int i_prsnamespace;
10122 int i_prsstart;
10123 int i_prstoken;
10124 int i_prsend;
10125 int i_prsheadline;
10126 int i_prslextype;
10127
10128 query = createPQExpBuffer();
10129
10130 /*
10131 * find all text search objects, including builtin ones; we filter out
10132 * system-defined objects at dump-out time.
10133 */
10134
10135 appendPQExpBufferStr(query, "SELECT tableoid, oid, prsname, prsnamespace, "
10136 "prsstart::oid, prstoken::oid, "
10137 "prsend::oid, prsheadline::oid, prslextype::oid "
10138 "FROM pg_ts_parser");
10139
10140 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10141
10142 ntups = PQntuples(res);
10143
10145
10146 i_tableoid = PQfnumber(res, "tableoid");
10147 i_oid = PQfnumber(res, "oid");
10148 i_prsname = PQfnumber(res, "prsname");
10149 i_prsnamespace = PQfnumber(res, "prsnamespace");
10150 i_prsstart = PQfnumber(res, "prsstart");
10151 i_prstoken = PQfnumber(res, "prstoken");
10152 i_prsend = PQfnumber(res, "prsend");
10153 i_prsheadline = PQfnumber(res, "prsheadline");
10154 i_prslextype = PQfnumber(res, "prslextype");
10155
10156 for (i = 0; i < ntups; i++)
10157 {
10158 prsinfo[i].dobj.objType = DO_TSPARSER;
10159 prsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10160 prsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10161 AssignDumpId(&prsinfo[i].dobj);
10162 prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname));
10163 prsinfo[i].dobj.namespace =
10165 prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart));
10166 prsinfo[i].prstoken = atooid(PQgetvalue(res, i, i_prstoken));
10167 prsinfo[i].prsend = atooid(PQgetvalue(res, i, i_prsend));
10168 prsinfo[i].prsheadline = atooid(PQgetvalue(res, i, i_prsheadline));
10169 prsinfo[i].prslextype = atooid(PQgetvalue(res, i, i_prslextype));
10170
10171 /* Decide whether we want to dump it */
10173 }
10174
10175 PQclear(res);
10176
10177 destroyPQExpBuffer(query);
10178}

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

10252{
10253 PGresult *res;
10254 int ntups;
10255 int i;
10256 PQExpBuffer query;
10258 int i_tableoid;
10259 int i_oid;
10260 int i_tmplname;
10261 int i_tmplnamespace;
10262 int i_tmplinit;
10263 int i_tmpllexize;
10264
10265 query = createPQExpBuffer();
10266
10267 appendPQExpBufferStr(query, "SELECT tableoid, oid, tmplname, "
10268 "tmplnamespace, tmplinit::oid, tmpllexize::oid "
10269 "FROM pg_ts_template");
10270
10271 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10272
10273 ntups = PQntuples(res);
10274
10276
10277 i_tableoid = PQfnumber(res, "tableoid");
10278 i_oid = PQfnumber(res, "oid");
10279 i_tmplname = PQfnumber(res, "tmplname");
10280 i_tmplnamespace = PQfnumber(res, "tmplnamespace");
10281 i_tmplinit = PQfnumber(res, "tmplinit");
10282 i_tmpllexize = PQfnumber(res, "tmpllexize");
10283
10284 for (i = 0; i < ntups; i++)
10285 {
10286 tmplinfo[i].dobj.objType = DO_TSTEMPLATE;
10287 tmplinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10288 tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10289 AssignDumpId(&tmplinfo[i].dobj);
10290 tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname));
10291 tmplinfo[i].dobj.namespace =
10293 tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit));
10294 tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize));
10295
10296 /* Decide whether we want to dump it */
10298 }
10299
10300 PQclear(res);
10301
10302 destroyPQExpBuffer(query);
10303}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_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:8432
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 20021 of file pg_dump.c.

20023{
20024 DumpOptions *dopt = fout->dopt;
20025 PQExpBuffer query;
20026 PGresult *res;
20027 int ntups,
20028 i;
20029 int i_conrelid,
20031
20032 /* Nothing to do if no extensions */
20033 if (numExtensions == 0)
20034 return;
20035
20036 /*
20037 * Identify extension configuration tables and create TableDataInfo
20038 * objects for them, ensuring their data will be dumped even though the
20039 * tables themselves won't be.
20040 *
20041 * Note that we create TableDataInfo objects even in schema-only mode, ie,
20042 * user data in a configuration table is treated like schema data. This
20043 * seems appropriate since system data in a config table would get
20044 * reloaded by CREATE EXTENSION. If the extension is not listed in the
20045 * list of extensions to be included, none of its data is dumped.
20046 */
20047 for (i = 0; i < numExtensions; i++)
20048 {
20050 char *extconfig = curext->extconfig;
20051 char *extcondition = curext->extcondition;
20052 char **extconfigarray = NULL;
20053 char **extconditionarray = NULL;
20054 int nconfigitems = 0;
20055 int nconditionitems = 0;
20056
20057 /*
20058 * Check if this extension is listed as to include in the dump. If
20059 * not, any table data associated with it is discarded.
20060 */
20063 curext->dobj.catId.oid))
20064 continue;
20065
20066 /*
20067 * Check if this extension is listed as to exclude in the dump. If
20068 * yes, any table data associated with it is discarded.
20069 */
20072 curext->dobj.catId.oid))
20073 continue;
20074
20075 if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
20076 {
20077 int j;
20078
20079 if (!parsePGArray(extconfig, &extconfigarray, &nconfigitems))
20080 pg_fatal("could not parse %s array", "extconfig");
20081 if (!parsePGArray(extcondition, &extconditionarray, &nconditionitems))
20082 pg_fatal("could not parse %s array", "extcondition");
20084 pg_fatal("mismatched number of configurations and conditions for extension");
20085
20086 for (j = 0; j < nconfigitems; j++)
20087 {
20090 bool dumpobj =
20091 curext->dobj.dump & DUMP_COMPONENT_DEFINITION;
20092
20094 if (configtbl == NULL)
20095 continue;
20096
20097 /*
20098 * Tables of not-to-be-dumped extensions shouldn't be dumped
20099 * unless the table or its schema is explicitly included
20100 */
20101 if (!(curext->dobj.dump & DUMP_COMPONENT_DEFINITION))
20102 {
20103 /* check table explicitly requested */
20104 if (table_include_oids.head != NULL &&
20106 configtbloid))
20107 dumpobj = true;
20108
20109 /* check table's schema explicitly requested */
20110 if (configtbl->dobj.namespace->dobj.dump &
20112 dumpobj = true;
20113 }
20114
20115 /* check table excluded by an exclusion switch */
20116 if (table_exclude_oids.head != NULL &&
20118 configtbloid))
20119 dumpobj = false;
20120
20121 /* check schema excluded by an exclusion switch */
20123 configtbl->dobj.namespace->dobj.catId.oid))
20124 dumpobj = false;
20125
20126 if (dumpobj)
20127 {
20129 if (configtbl->dataObj != NULL)
20130 {
20131 if (strlen(extconditionarray[j]) > 0)
20132 configtbl->dataObj->filtercond = pg_strdup(extconditionarray[j]);
20133 }
20134 }
20135 }
20136 }
20137 if (extconfigarray)
20141 }
20142
20143 /*
20144 * Now that all the TableDataInfo objects have been created for all the
20145 * extensions, check their FK dependencies and register them to try and
20146 * dump the data out in an order that they can be restored in.
20147 *
20148 * Note that this is not a problem for user tables as their FKs are
20149 * recreated after the data has been loaded.
20150 */
20151
20152 query = createPQExpBuffer();
20153
20154 printfPQExpBuffer(query,
20155 "SELECT conrelid, confrelid "
20156 "FROM pg_constraint "
20157 "JOIN pg_depend ON (objid = confrelid) "
20158 "WHERE contype = 'f' "
20159 "AND refclassid = 'pg_extension'::regclass "
20160 "AND classid = 'pg_class'::regclass;");
20161
20162 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
20163 ntups = PQntuples(res);
20164
20165 i_conrelid = PQfnumber(res, "conrelid");
20166 i_confrelid = PQfnumber(res, "confrelid");
20167
20168 /* Now get the dependencies and register them */
20169 for (i = 0; i < ntups; i++)
20170 {
20171 Oid conrelid,
20172 confrelid;
20174 *contable;
20175
20176 conrelid = atooid(PQgetvalue(res, i, i_conrelid));
20177 confrelid = atooid(PQgetvalue(res, i, i_confrelid));
20178 contable = findTableByOid(conrelid);
20179 reftable = findTableByOid(confrelid);
20180
20181 if (reftable == NULL ||
20182 reftable->dataObj == NULL ||
20183 contable == NULL ||
20184 contable->dataObj == NULL)
20185 continue;
20186
20187 /*
20188 * Make referencing TABLE_DATA object depend on the referenced table's
20189 * TABLE_DATA object.
20190 */
20191 addObjectDependency(&contable->dataObj->dobj,
20192 reftable->dataObj->dobj.dumpId);
20193 }
20194 PQclear(res);
20195 destroyPQExpBuffer(query);
20196}
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 10096 of file pg_dump.c.

10097{
10098 if (dopt->binary_upgrade)
10099 return true;
10100 if (tbinfo->attisdropped[colno])
10101 return false;
10102 return (tbinfo->attislocal[colno] || tbinfo->ispartition);
10103}

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