1 /*-------------------------------------------------------------------------
4 * Common header file for the pg_dump utility
6 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/bin/pg_dump/pg_dump.h
11 *-------------------------------------------------------------------------
17 #include "postgres_fe.h"
20 * pg_dump uses two different mechanisms for identifying database objects:
22 * CatalogId represents an object by the tableoid and oid of its defining
23 * entry in the system catalogs. We need this to interpret pg_depend entries,
26 * DumpId is a simple sequential integer counter assigned as dumpable objects
27 * are identified during a pg_dump run. We use DumpId internally in preference
28 * to CatalogId for two reasons: it's more compact, and we can assign DumpIds
29 * to "objects" that don't have a separate CatalogId. For example, it is
30 * convenient to consider a table, its data, and its ACL as three separate
31 * dumpable "objects" with distinct DumpIds --- this lets us reason about the
32 * order in which to dump these things.
44 * Data structures for simple lists of OIDs and strings. The support for
45 * these is very primitive compared to the backend's List facilities, but
46 * it's all we need in pg_dump.
49 typedef struct SimpleOidListCell
51 struct SimpleOidListCell *next;
55 typedef struct SimpleOidList
57 SimpleOidListCell *head;
58 SimpleOidListCell *tail;
63 * The data structures used to store system catalog information. Every
64 * dumpable object is a subclass of DumpableObject.
66 * NOTE: the structures described here live for the entire pg_dump run;
67 * and in most cases we make a struct for every object we can find in the
68 * catalogs, not only those we are actually going to dump. Hence, it's
69 * best to store a minimal amount of per-object info in these structs,
70 * and retrieve additional per-object info when and if we dump a specific
71 * object. In particular, try to avoid retrieving expensive-to-compute
72 * information until it's known to be needed. We do, however, have to
73 * store enough info to determine whether an object should be dumped and
74 * what order to dump in.
79 /* When modifying this enum, update priority tables in pg_dump_sort.c! */
97 DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
111 DO_PRE_DATA_BOUNDARY,
112 DO_POST_DATA_BOUNDARY,
115 } DumpableObjectType;
117 typedef struct _dumpableObject
119 DumpableObjectType objType;
120 CatalogId catId; /* zero if not a cataloged object */
121 DumpId dumpId; /* assigned by AssignDumpId() */
122 char *name; /* object name (should never be NULL) */
123 struct _namespaceInfo *namespace; /* containing namespace, or NULL */
124 bool dump; /* true if we want to dump this object */
125 bool ext_member; /* true if object is member of extension */
126 DumpId *dependencies; /* dumpIds of objects this one depends on */
127 int nDeps; /* number of valid dependencies */
128 int allocDeps; /* allocated size of dependencies[] */
131 typedef struct _namespaceInfo
134 char *rolname; /* name of owner, or empty string */
138 typedef struct _extensionInfo
141 char *namespace; /* schema containing extension's objects */
144 char *extconfig; /* info about configuration tables */
148 typedef struct _typeInfo
153 * Note: dobj.name is the pg_type.typname entry. format_type() might
154 * produce something different than typname
156 char *rolname; /* name of owner, or empty string */
160 char typrelkind; /* 'r', 'v', 'c', etc */
161 char typtype; /* 'b', 'c', etc */
162 bool isArray; /* true if auto-generated array type */
163 bool isDefined; /* true if typisdefined */
164 /* If it's a dumpable base type, we create a "shell type" entry for it */
165 struct _shellTypeInfo *shellType; /* shell-type entry, or NULL */
166 /* If it's a domain, we store links to its constraints here: */
168 struct _constraintInfo *domChecks;
171 typedef struct _shellTypeInfo
175 TypeInfo *baseType; /* back link to associated base type */
178 typedef struct _funcInfo
181 char *rolname; /* name of owner, or empty string */
190 /* AggInfo is a superset of FuncInfo */
191 typedef struct _aggInfo
194 /* we don't require any other fields at the moment */
197 typedef struct _oprInfo
205 typedef struct _opclassInfo
211 typedef struct _opfamilyInfo
217 typedef struct _collInfo
223 typedef struct _convInfo
229 typedef struct _tableInfo
232 * These fields are collected for every table in the database.
235 char *rolname; /* name of owner, or empty string */
238 char relpersistence; /* relation persistence */
239 bool relispopulated; /* relation is populated */
240 bool relreplident; /* replica identifier */
241 char *reltablespace; /* relation tablespace */
242 char *reloptions; /* options specified by WITH (...) */
243 char *checkoption; /* WITH CHECK OPTION */
244 char *toast_reloptions; /* WITH options for the TOAST table */
245 bool hasindex; /* does it have any indexes? */
246 bool hasrules; /* does it have any rules? */
247 bool hastriggers; /* does it have any triggers? */
248 bool hasoids; /* does it have OIDs? */
249 uint32 frozenxid; /* for restore frozen xid */
250 uint32 minmxid; /* for restore min multi xid */
251 Oid toast_oid; /* for restore toast frozen xid */
252 uint32 toast_frozenxid; /* for restore toast frozen xid */
253 uint32 toast_minmxid; /* for restore toast min multi xid */
254 int ncheck; /* # of CHECK expressions */
255 char *reloftype; /* underlying type for typed table */
256 /* these two are set only if table is a sequence owned by a column: */
257 Oid owning_tab; /* OID of table owning sequence */
258 int owning_col; /* attr # of column owning sequence */
259 int relpages; /* table's size in pages (from pg_class) */
261 bool interesting; /* true if need to collect more data */
262 bool postponed_def; /* matview must be postponed into post-data */
265 * These fields are computed only if we decide the table is interesting
266 * (it's either a table to dump, or a direct parent of a dumpable table).
268 int numatts; /* number of attributes */
269 char **attnames; /* the attribute names */
270 char **atttypnames; /* attribute type names */
271 int *atttypmod; /* type-specific type modifiers */
272 int *attstattarget; /* attribute statistics targets */
273 char *attstorage; /* attribute storage scheme */
274 char *typstorage; /* type storage scheme */
275 bool *attisdropped; /* true if attr is dropped; don't dump it */
276 int *attlen; /* attribute length, used by binary_upgrade */
277 char *attalign; /* attribute align, used by binary_upgrade */
278 bool *attislocal; /* true if attr has local definition */
279 char **attoptions; /* per-attribute options */
280 Oid *attcollation; /* per-attribute collation selection */
281 char **attfdwoptions; /* per-attribute fdw options */
282 bool *notnull; /* NOT NULL constraints on attributes */
283 bool *inhNotNull; /* true if NOT NULL is inherited */
284 struct _attrDefInfo **attrdefs; /* DEFAULT expressions */
285 struct _constraintInfo *checkexprs; /* CHECK constraints */
288 * Stuff computed only for dumpable tables.
290 int numParents; /* number of (immediate) parent tables */
291 struct _tableInfo **parents; /* TableInfos of immediate parents */
292 struct _tableDataInfo *dataObj; /* TableDataInfo, if dumping its data */
295 typedef struct _attrDefInfo
297 DumpableObject dobj; /* note: dobj.name is name of table */
298 TableInfo *adtable; /* link to table of attribute */
300 char *adef_expr; /* decompiled DEFAULT expression */
301 bool separate; /* TRUE if must dump as separate item */
304 typedef struct _tableDataInfo
307 TableInfo *tdtable; /* link to table to dump */
308 bool oids; /* include OIDs in data? */
309 char *filtercond; /* WHERE condition to limit rows dumped */
312 typedef struct _indxInfo
315 TableInfo *indextable; /* link to table the index is for */
317 char *tablespace; /* tablespace in which index is stored */
318 char *options; /* options specified by WITH (...) */
323 /* if there is an associated constraint object, its dumpId: */
324 DumpId indexconstraint;
325 int relpages; /* relpages of the underlying table */
328 typedef struct _ruleInfo
331 TableInfo *ruletable; /* link to table the rule is for */
335 bool separate; /* TRUE if must dump as separate item */
336 /* separate is always true for non-ON SELECT rules */
337 char *reloptions; /* options specified by WITH (...) */
338 /* reloptions is only set if we need to dump the options with the rule */
341 typedef struct _triggerInfo
344 TableInfo *tgtable; /* link to table the trigger is for */
352 char *tgconstrrelname;
359 typedef struct _evttriggerInfo
371 * struct ConstraintInfo is used for all constraint types. However we
372 * use a different objType for foreign key constraints, to make it easier
373 * to sort them the way we want.
375 * Note: condeferrable and condeferred are currently only valid for
376 * unique/primary-key constraints. Otherwise that info is in condef.
378 typedef struct _constraintInfo
381 TableInfo *contable; /* NULL if domain constraint */
382 TypeInfo *condomain; /* NULL if table constraint */
384 char *condef; /* definition, if CHECK or FOREIGN KEY */
385 Oid confrelid; /* referenced table, if FOREIGN KEY */
386 DumpId conindex; /* identifies associated index if any */
387 bool condeferrable; /* TRUE if constraint is DEFERRABLE */
388 bool condeferred; /* TRUE if constraint is INITIALLY DEFERRED */
389 bool conislocal; /* TRUE if constraint has local definition */
390 bool separate; /* TRUE if must dump as separate item */
393 typedef struct _procLangInfo
401 char *lanowner; /* name of owner, or empty string */
404 typedef struct _castInfo
414 /* InhInfo isn't a DumpableObject, just temporary state */
415 typedef struct _inhInfo
417 Oid inhrelid; /* OID of a child table */
418 Oid inhparent; /* OID of its parent */
421 typedef struct _prsInfo
431 typedef struct _dictInfo
436 char *dictinitoption;
439 typedef struct _tmplInfo
446 typedef struct _cfgInfo
453 typedef struct _fdwInfo
463 typedef struct _foreignServerInfo
474 typedef struct _defaultACLInfo
482 typedef struct _blobInfo
490 extern bool force_quotes; /* double-quotes for identifiers flag */
491 extern bool g_verbose; /* verbose flag */
493 /* placeholders for comment starting and ending delimiters */
494 extern char g_comment_start[10];
495 extern char g_comment_end[10];
497 extern char g_opaque_type[10]; /* name for the opaque type */
500 * common utility functions
504 typedef struct Archive Archive;
506 extern TableInfo *getSchemaData(Archive *, int *numTablesPtr);
508 typedef enum _OidOptions
516 extern void AssignDumpId(DumpableObject *dobj);
517 extern DumpId createDumpId(void);
518 extern DumpId getMaxDumpId(void);
519 extern DumpableObject *findObjectByDumpId(DumpId dumpId);
520 extern DumpableObject *findObjectByCatalogId(CatalogId catalogId);
521 extern void getDumpableObjects(DumpableObject ***objs, int *numObjs);
523 extern void addObjectDependency(DumpableObject *dobj, DumpId refId);
524 extern void removeObjectDependency(DumpableObject *dobj, DumpId refId);
526 extern TableInfo *findTableByOid(Oid oid);
527 extern TypeInfo *findTypeByOid(Oid oid);
528 extern FuncInfo *findFuncByOid(Oid oid);
529 extern OprInfo *findOprByOid(Oid oid);
530 extern CollInfo *findCollationByOid(Oid oid);
531 extern NamespaceInfo *findNamespaceByOid(Oid oid);
533 extern void simple_oid_list_append(SimpleOidList *list, Oid val);
534 extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
536 extern void parseOidArray(const char *str, Oid *array, int arraysize);
538 extern void sortDumpableObjects(DumpableObject **objs, int numObjs,
539 DumpId preBoundaryId, DumpId postBoundaryId);
540 extern void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs);
541 extern void sortDumpableObjectsByTypeOid(DumpableObject **objs, int numObjs);
542 extern void sortDataAndIndexObjectsBySize(DumpableObject **objs, int numObjs);
545 * version specific routines
547 extern NamespaceInfo *getNamespaces(Archive *fout, int *numNamespaces);
548 extern ExtensionInfo *getExtensions(Archive *fout, int *numExtensions);
549 extern TypeInfo *getTypes(Archive *fout, int *numTypes);
550 extern FuncInfo *getFuncs(Archive *fout, int *numFuncs);
551 extern AggInfo *getAggregates(Archive *fout, int *numAggregates);
552 extern OprInfo *getOperators(Archive *fout, int *numOperators);
553 extern OpclassInfo *getOpclasses(Archive *fout, int *numOpclasses);
554 extern OpfamilyInfo *getOpfamilies(Archive *fout, int *numOpfamilies);
555 extern CollInfo *getCollations(Archive *fout, int *numCollations);
556 extern ConvInfo *getConversions(Archive *fout, int *numConversions);
557 extern TableInfo *getTables(Archive *fout, int *numTables);
558 extern void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables);
559 extern InhInfo *getInherits(Archive *fout, int *numInherits);
560 extern void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables);
561 extern void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables);
562 extern RuleInfo *getRules(Archive *fout, int *numRules);
563 extern void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables);
564 extern ProcLangInfo *getProcLangs(Archive *fout, int *numProcLangs);
565 extern CastInfo *getCasts(Archive *fout, int *numCasts);
566 extern void getTableAttrs(Archive *fout, TableInfo *tbinfo, int numTables);
567 extern bool shouldPrintColumn(TableInfo *tbinfo, int colno);
568 extern TSParserInfo *getTSParsers(Archive *fout, int *numTSParsers);
569 extern TSDictInfo *getTSDictionaries(Archive *fout, int *numTSDicts);
570 extern TSTemplateInfo *getTSTemplates(Archive *fout, int *numTSTemplates);
571 extern TSConfigInfo *getTSConfigurations(Archive *fout, int *numTSConfigs);
572 extern FdwInfo *getForeignDataWrappers(Archive *fout,
573 int *numForeignDataWrappers);
574 extern ForeignServerInfo *getForeignServers(Archive *fout,
575 int *numForeignServers);
576 extern DefaultACLInfo *getDefaultACLs(Archive *fout, int *numDefaultACLs);
577 extern void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[],
579 extern EventTriggerInfo *getEventTriggers(Archive *fout, int *numEventTriggers);
581 #endif /* PG_DUMP_H */