1 /*-------------------------------------------------------------------------
4 * Common header file for the pg_dump utility
6 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
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
;
61 typedef struct SimpleStringListCell
63 struct SimpleStringListCell
*next
;
64 char val
[1]; /* VARIABLE LENGTH FIELD */
65 } SimpleStringListCell
;
67 typedef struct SimpleStringList
69 SimpleStringListCell
*head
;
70 SimpleStringListCell
*tail
;
74 * The data structures used to store system catalog information. Every
75 * dumpable object is a subclass of DumpableObject.
77 * NOTE: the structures described here live for the entire pg_dump run;
78 * and in most cases we make a struct for every object we can find in the
79 * catalogs, not only those we are actually going to dump. Hence, it's
80 * best to store a minimal amount of per-object info in these structs,
81 * and retrieve additional per-object info when and if we dump a specific
82 * object. In particular, try to avoid retrieving expensive-to-compute
83 * information until it's known to be needed. We do, however, have to
84 * store enough info to determine whether an object should be dumped and
85 * what order to dump in.
90 /* When modifying this enum, update priority tables in pg_dump_sort.c! */
106 DO_FK_CONSTRAINT
, /* see note for ConstraintInfo */
119 } DumpableObjectType
;
121 typedef struct _dumpableObject
123 DumpableObjectType objType
;
124 CatalogId catId
; /* zero if not a cataloged object */
125 DumpId dumpId
; /* assigned by AssignDumpId() */
126 char *name
; /* object name (should never be NULL) */
127 struct _namespaceInfo
*namespace; /* containing namespace, or NULL */
128 bool dump
; /* true if we want to dump this object */
129 DumpId
*dependencies
; /* dumpIds of objects this one depends on */
130 int nDeps
; /* number of valid dependencies */
131 int allocDeps
; /* allocated size of dependencies[] */
134 typedef struct _namespaceInfo
137 char *rolname
; /* name of owner, or empty string */
141 typedef struct _typeInfo
146 * Note: dobj.name is the pg_type.typname entry. format_type() might
147 * produce something different than typname
149 char *rolname
; /* name of owner, or empty string */
152 char typrelkind
; /* 'r', 'v', 'c', etc */
153 char typtype
; /* 'b', 'c', etc */
154 bool isArray
; /* true if auto-generated array type */
155 bool isDefined
; /* true if typisdefined */
156 /* If it's a dumpable base type, we create a "shell type" entry for it */
157 struct _shellTypeInfo
*shellType
; /* shell-type entry, or NULL */
158 /* If it's a domain, we store links to its constraints here: */
160 struct _constraintInfo
*domChecks
;
163 typedef struct _shellTypeInfo
167 TypeInfo
*baseType
; /* back link to associated base type */
170 typedef struct _funcInfo
173 char *rolname
; /* name of owner, or empty string */
181 /* AggInfo is a superset of FuncInfo */
182 typedef struct _aggInfo
185 /* we don't require any other fields at the moment */
188 typedef struct _oprInfo
195 typedef struct _opclassInfo
201 typedef struct _opfamilyInfo
207 typedef struct _convInfo
213 typedef struct _tableInfo
216 * These fields are collected for every table in the database.
219 char *rolname
; /* name of owner, or empty string */
222 char *reltablespace
; /* relation tablespace */
223 char *reloptions
; /* options specified by WITH (...) */
224 char *toast_reloptions
; /* ditto, for the TOAST table */
225 bool hasindex
; /* does it have any indexes? */
226 bool hasrules
; /* does it have any rules? */
227 bool hastriggers
; /* does it have any triggers? */
228 bool hasoids
; /* does it have OIDs? */
229 uint32 frozenxid
; /* for restore frozen xid */
230 int ncheck
; /* # of CHECK expressions */
231 /* these two are set only if table is a sequence owned by a column: */
232 Oid owning_tab
; /* OID of table owning sequence */
233 int owning_col
; /* attr # of column owning sequence */
235 bool interesting
; /* true if need to collect more data */
238 * These fields are computed only if we decide the table is interesting
239 * (it's either a table to dump, or a direct parent of a dumpable table).
241 int numatts
; /* number of attributes */
242 char **attnames
; /* the attribute names */
243 char **atttypnames
; /* attribute type names */
244 int *atttypmod
; /* type-specific type modifiers */
245 int *attstattarget
; /* attribute statistics targets */
246 char *attstorage
; /* attribute storage scheme */
247 char *typstorage
; /* type storage scheme */
248 bool *attisdropped
; /* true if attr is dropped; don't dump it */
249 int *attlen
; /* attribute length, used by binary_upgrade */
250 char *attalign
; /* attribute align, used by binary_upgrade */
251 bool *attislocal
; /* true if attr has local definition */
254 * Note: we need to store per-attribute notnull, default, and constraint
255 * stuff for all interesting tables so that we can tell which constraints
258 bool *notnull
; /* Not null constraints on attributes */
259 struct _attrDefInfo
**attrdefs
; /* DEFAULT expressions */
260 bool *inhAttrs
; /* true if each attribute is inherited */
261 bool *inhAttrDef
; /* true if attr's default is inherited */
262 bool *inhNotNull
; /* true if NOT NULL is inherited */
263 struct _constraintInfo
*checkexprs
; /* CHECK constraints */
266 * Stuff computed only for dumpable tables.
268 int numParents
; /* number of (immediate) parent tables */
269 struct _tableInfo
**parents
; /* TableInfos of immediate parents */
270 struct _tableDataInfo
*dataObj
; /* TableDataInfo, if dumping its data */
273 typedef struct _attrDefInfo
276 TableInfo
*adtable
; /* link to table of attribute */
278 char *adef_expr
; /* decompiled DEFAULT expression */
279 bool separate
; /* TRUE if must dump as separate item */
282 typedef struct _tableDataInfo
285 TableInfo
*tdtable
; /* link to table to dump */
286 bool oids
; /* include OIDs in data? */
289 typedef struct _indxInfo
292 TableInfo
*indextable
; /* link to table the index is for */
294 char *tablespace
; /* tablespace in which index is stored */
295 char *options
; /* options specified by WITH (...) */
299 /* if there is an associated constraint object, its dumpId: */
300 DumpId indexconstraint
;
303 typedef struct _ruleInfo
306 TableInfo
*ruletable
; /* link to table the rule is for */
310 bool separate
; /* TRUE if must dump as separate item */
311 /* separate is always true for non-ON SELECT rules */
314 typedef struct _triggerInfo
317 TableInfo
*tgtable
; /* link to table the trigger is for */
325 char *tgconstrrelname
;
332 * struct ConstraintInfo is used for all constraint types. However we
333 * use a different objType for foreign key constraints, to make it easier
334 * to sort them the way we want.
336 typedef struct _constraintInfo
339 TableInfo
*contable
; /* NULL if domain constraint */
340 TypeInfo
*condomain
; /* NULL if table constraint */
342 char *condef
; /* definition, if CHECK or FOREIGN KEY */
343 Oid confrelid
; /* referenced table, if FOREIGN KEY */
344 DumpId conindex
; /* identifies associated index if any */
345 bool conislocal
; /* TRUE if constraint has local definition */
346 bool separate
; /* TRUE if must dump as separate item */
349 typedef struct _procLangInfo
356 char *lanowner
; /* name of owner, or empty string */
359 typedef struct _castInfo
369 /* InhInfo isn't a DumpableObject, just temporary state */
370 typedef struct _inhInfo
372 Oid inhrelid
; /* OID of a child table */
373 Oid inhparent
; /* OID of its parent */
376 typedef struct _prsInfo
386 typedef struct _dictInfo
391 char *dictinitoption
;
394 typedef struct _tmplInfo
401 typedef struct _cfgInfo
408 typedef struct _fdwInfo
417 typedef struct _foreignServerInfo
429 extern bool force_quotes
; /* double-quotes for identifiers flag */
430 extern bool g_verbose
; /* verbose flag */
432 /* placeholders for comment starting and ending delimiters */
433 extern char g_comment_start
[10];
434 extern char g_comment_end
[10];
436 extern char g_opaque_type
[10]; /* name for the opaque type */
439 * common utility functions
442 extern TableInfo
*getSchemaData(int *numTablesPtr
);
444 typedef enum _OidOptions
452 extern void AssignDumpId(DumpableObject
*dobj
);
453 extern DumpId
createDumpId(void);
454 extern DumpId
getMaxDumpId(void);
455 extern DumpableObject
*findObjectByDumpId(DumpId dumpId
);
456 extern DumpableObject
*findObjectByCatalogId(CatalogId catalogId
);
457 extern void getDumpableObjects(DumpableObject
***objs
, int *numObjs
);
459 extern void addObjectDependency(DumpableObject
*dobj
, DumpId refId
);
460 extern void removeObjectDependency(DumpableObject
*dobj
, DumpId refId
);
462 extern TableInfo
*findTableByOid(Oid oid
);
463 extern TypeInfo
*findTypeByOid(Oid oid
);
464 extern FuncInfo
*findFuncByOid(Oid oid
);
465 extern OprInfo
*findOprByOid(Oid oid
);
467 extern void simple_oid_list_append(SimpleOidList
*list
, Oid val
);
468 extern void simple_string_list_append(SimpleStringList
*list
, const char *val
);
469 extern bool simple_oid_list_member(SimpleOidList
*list
, Oid val
);
470 extern bool simple_string_list_member(SimpleStringList
*list
, const char *val
);
472 extern char *pg_strdup(const char *string
);
473 extern void *pg_malloc(size_t size
);
474 extern void *pg_calloc(size_t nmemb
, size_t size
);
475 extern void *pg_realloc(void *ptr
, size_t size
);
477 extern void check_conn_and_db(void);
478 extern void exit_nicely(void);
480 extern void parseOidArray(const char *str
, Oid
*array
, int arraysize
);
482 extern void sortDumpableObjects(DumpableObject
**objs
, int numObjs
);
483 extern void sortDumpableObjectsByTypeName(DumpableObject
**objs
, int numObjs
);
484 extern void sortDumpableObjectsByTypeOid(DumpableObject
**objs
, int numObjs
);
487 * version specific routines
489 extern NamespaceInfo
*getNamespaces(int *numNamespaces
);
490 extern TypeInfo
*getTypes(int *numTypes
);
491 extern FuncInfo
*getFuncs(int *numFuncs
);
492 extern AggInfo
*getAggregates(int *numAggregates
);
493 extern OprInfo
*getOperators(int *numOperators
);
494 extern OpclassInfo
*getOpclasses(int *numOpclasses
);
495 extern OpfamilyInfo
*getOpfamilies(int *numOpfamilies
);
496 extern ConvInfo
*getConversions(int *numConversions
);
497 extern TableInfo
*getTables(int *numTables
);
498 extern InhInfo
*getInherits(int *numInherits
);
499 extern void getIndexes(TableInfo tblinfo
[], int numTables
);
500 extern void getConstraints(TableInfo tblinfo
[], int numTables
);
501 extern RuleInfo
*getRules(int *numRules
);
502 extern void getTriggers(TableInfo tblinfo
[], int numTables
);
503 extern ProcLangInfo
*getProcLangs(int *numProcLangs
);
504 extern CastInfo
*getCasts(int *numCasts
);
505 extern void getTableAttrs(TableInfo
*tbinfo
, int numTables
);
506 extern TSParserInfo
*getTSParsers(int *numTSParsers
);
507 extern TSDictInfo
*getTSDictionaries(int *numTSDicts
);
508 extern TSTemplateInfo
*getTSTemplates(int *numTSTemplates
);
509 extern TSConfigInfo
*getTSConfigurations(int *numTSConfigs
);
510 extern FdwInfo
*getForeignDataWrappers(int *numForeignDataWrappers
);
511 extern ForeignServerInfo
*getForeignServers(int *numForeignServers
);
513 #endif /* PG_DUMP_H */