1 /*-------------------------------------------------------------------------
4 * Common header file for the pg_dump utility
6 * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.130 2006/10/09 23:36:59 tgl Exp $
11 *-------------------------------------------------------------------------
17 #include "postgres_fe.h"
21 * pg_dump uses two different mechanisms for identifying database objects:
23 * CatalogId represents an object by the tableoid and oid of its defining
24 * entry in the system catalogs. We need this to interpret pg_depend entries,
27 * DumpId is a simple sequential integer counter assigned as dumpable objects
28 * are identified during a pg_dump run. We use DumpId internally in preference
29 * to CatalogId for two reasons: it's more compact, and we can assign DumpIds
30 * to "objects" that don't have a separate CatalogId. For example, it is
31 * convenient to consider a table, its data, and its ACL as three separate
32 * dumpable "objects" with distinct DumpIds --- this lets us reason about the
33 * order in which to dump these things.
45 * Data structures for simple lists of OIDs and strings. The support for
46 * these is very primitive compared to the backend's List facilities, but
47 * it's all we need in pg_dump.
50 typedef struct SimpleOidListCell
52 struct SimpleOidListCell *next;
56 typedef struct SimpleOidList
58 SimpleOidListCell *head;
59 SimpleOidListCell *tail;
62 typedef struct SimpleStringListCell
64 struct SimpleStringListCell *next;
65 char val[1]; /* VARIABLE LENGTH FIELD */
66 } SimpleStringListCell;
68 typedef struct SimpleStringList
70 SimpleStringListCell *head;
71 SimpleStringListCell *tail;
75 * The data structures used to store system catalog information. Every
76 * dumpable object is a subclass of DumpableObject.
78 * NOTE: the structures described here live for the entire pg_dump run;
79 * and in most cases we make a struct for every object we can find in the
80 * catalogs, not only those we are actually going to dump. Hence, it's
81 * best to store a minimal amount of per-object info in these structs,
82 * and retrieve additional per-object info when and if we dump a specific
83 * object. In particular, try to avoid retrieving expensive-to-compute
84 * information until it's known to be needed. We do, however, have to
85 * store enough info to determine whether an object should be dumped and
86 * what order to dump in.
91 /* When modifying this enum, update priority tables in pg_dump_sort.c! */
106 DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
113 } DumpableObjectType;
115 typedef struct _dumpableObject
117 DumpableObjectType objType;
118 CatalogId catId; /* zero if not a cataloged object */
119 DumpId dumpId; /* assigned by AssignDumpId() */
120 char *name; /* object name (should never be NULL) */
121 struct _namespaceInfo *namespace; /* containing namespace, or NULL */
122 bool dump; /* true if we want to dump this object */
123 DumpId *dependencies; /* dumpIds of objects this one depends on */
124 int nDeps; /* number of valid dependencies */
125 int allocDeps; /* allocated size of dependencies[] */
128 typedef struct _namespaceInfo
131 char *rolname; /* name of owner, or empty string */
135 typedef struct _typeInfo
140 * Note: dobj.name is the pg_type.typname entry. format_type() might
141 * produce something different than typname
143 char *rolname; /* name of owner, or empty string */
146 char typrelkind; /* 'r', 'v', 'c', etc */
147 char typtype; /* 'b', 'c', etc */
148 bool isArray; /* true if user-defined array type */
149 bool isDefined; /* true if typisdefined */
150 /* If it's a dumpable base type, we create a "shell type" entry for it */
151 struct _shellTypeInfo *shellType; /* shell-type entry, or NULL */
152 /* If it's a domain, we store links to its constraints here: */
154 struct _constraintInfo *domChecks;
157 typedef struct _shellTypeInfo
161 TypeInfo *baseType; /* back link to associated base type */
164 typedef struct _funcInfo
167 char *rolname; /* name of owner, or empty string */
175 /* AggInfo is a superset of FuncInfo */
176 typedef struct _aggInfo
179 /* we don't require any other fields at the moment */
182 typedef struct _oprInfo
189 typedef struct _opclassInfo
195 typedef struct _convInfo
201 typedef struct _tableInfo
204 * These fields are collected for every table in the database.
207 char *rolname; /* name of owner, or empty string */
210 char *reltablespace; /* relation tablespace */
211 char *reloptions; /* options specified by WITH (...) */
212 bool hasindex; /* does it have any indexes? */
213 bool hasrules; /* does it have any rules? */
214 bool hasoids; /* does it have OIDs? */
215 int ncheck; /* # of CHECK expressions */
216 int ntrig; /* # of triggers */
217 /* these two are set only if table is a sequence owned by a column: */
218 Oid owning_tab; /* OID of table owning sequence */
219 int owning_col; /* attr # of column owning sequence */
221 bool interesting; /* true if need to collect more data */
224 * These fields are computed only if we decide the table is interesting
225 * (it's either a table to dump, or a direct parent of a dumpable table).
227 int numatts; /* number of attributes */
228 char **attnames; /* the attribute names */
229 char **atttypnames; /* attribute type names */
230 int *atttypmod; /* type-specific type modifiers */
231 int *attstattarget; /* attribute statistics targets */
232 char *attstorage; /* attribute storage scheme */
233 char *typstorage; /* type storage scheme */
234 bool *attisdropped; /* true if attr is dropped; don't dump it */
235 bool *attislocal; /* true if attr has local definition */
238 * Note: we need to store per-attribute notnull, default, and constraint
239 * stuff for all interesting tables so that we can tell which constraints
242 bool *notnull; /* Not null constraints on attributes */
243 struct _attrDefInfo **attrdefs; /* DEFAULT expressions */
244 bool *inhAttrs; /* true if each attribute is inherited */
245 bool *inhAttrDef; /* true if attr's default is inherited */
246 bool *inhNotNull; /* true if NOT NULL is inherited */
247 struct _constraintInfo *checkexprs; /* CHECK constraints */
250 * Stuff computed only for dumpable tables.
252 int numParents; /* number of (immediate) parent tables */
253 struct _tableInfo **parents; /* TableInfos of immediate parents */
256 typedef struct _attrDefInfo
259 TableInfo *adtable; /* link to table of attribute */
261 char *adef_expr; /* decompiled DEFAULT expression */
262 bool separate; /* TRUE if must dump as separate item */
265 typedef struct _tableDataInfo
268 TableInfo *tdtable; /* link to table to dump */
269 bool oids; /* include OIDs in data? */
272 typedef struct _indxInfo
275 TableInfo *indextable; /* link to table the index is for */
277 char *tablespace; /* tablespace in which index is stored */
278 char *options; /* options specified by WITH (...) */
282 /* if there is an associated constraint object, its dumpId: */
283 DumpId indexconstraint;
286 typedef struct _ruleInfo
289 TableInfo *ruletable; /* link to table the rule is for */
292 bool separate; /* TRUE if must dump as separate item */
293 /* separate is always true for non-ON SELECT rules */
296 typedef struct _triggerInfo
299 TableInfo *tgtable; /* link to table the trigger is for */
307 char *tgconstrrelname;
314 * struct ConstraintInfo is used for all constraint types. However we
315 * use a different objType for foreign key constraints, to make it easier
316 * to sort them the way we want.
318 typedef struct _constraintInfo
321 TableInfo *contable; /* NULL if domain constraint */
322 TypeInfo *condomain; /* NULL if table constraint */
324 char *condef; /* definition, if CHECK or FOREIGN KEY */
325 DumpId conindex; /* identifies associated index if any */
326 bool coninherited; /* TRUE if appears to be inherited */
327 bool separate; /* TRUE if must dump as separate item */
330 typedef struct _procLangInfo
337 char *lanowner; /* name of owner, or empty string */
340 typedef struct _castInfo
349 /* InhInfo isn't a DumpableObject, just temporary state */
350 typedef struct _inhInfo
352 Oid inhrelid; /* OID of a child table */
353 Oid inhparent; /* OID of its parent */
358 extern bool force_quotes; /* double-quotes for identifiers flag */
359 extern bool g_verbose; /* verbose flag */
361 /* placeholders for comment starting and ending delimiters */
362 extern char g_comment_start[10];
363 extern char g_comment_end[10];
365 extern char g_opaque_type[10]; /* name for the opaque type */
368 * common utility functions
371 extern TableInfo *getSchemaData(int *numTablesPtr);
373 typedef enum _OidOptions
381 extern void AssignDumpId(DumpableObject *dobj);
382 extern DumpId createDumpId(void);
383 extern DumpId getMaxDumpId(void);
384 extern DumpableObject *findObjectByDumpId(DumpId dumpId);
385 extern DumpableObject *findObjectByCatalogId(CatalogId catalogId);
386 extern void getDumpableObjects(DumpableObject ***objs, int *numObjs);
388 extern void addObjectDependency(DumpableObject *dobj, DumpId refId);
389 extern void removeObjectDependency(DumpableObject *dobj, DumpId refId);
391 extern TableInfo *findTableByOid(Oid oid);
392 extern TypeInfo *findTypeByOid(Oid oid);
393 extern FuncInfo *findFuncByOid(Oid oid);
394 extern OprInfo *findOprByOid(Oid oid);
396 extern void simple_oid_list_append(SimpleOidList *list, Oid val);
397 extern void simple_string_list_append(SimpleStringList *list, const char *val);
398 extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
399 extern bool simple_string_list_member(SimpleStringList *list, const char *val);
401 extern char *pg_strdup(const char *string);
402 extern void *pg_malloc(size_t size);
403 extern void *pg_calloc(size_t nmemb, size_t size);
404 extern void *pg_realloc(void *ptr, size_t size);
406 extern void check_conn_and_db(void);
407 extern void exit_nicely(void);
409 extern void parseOidArray(const char *str, Oid *array, int arraysize);
411 extern void sortDumpableObjects(DumpableObject **objs, int numObjs);
412 extern void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs);
413 extern void sortDumpableObjectsByTypeOid(DumpableObject **objs, int numObjs);
416 * version specific routines
418 extern NamespaceInfo *getNamespaces(int *numNamespaces);
419 extern TypeInfo *getTypes(int *numTypes);
420 extern FuncInfo *getFuncs(int *numFuncs);
421 extern AggInfo *getAggregates(int *numAggregates);
422 extern OprInfo *getOperators(int *numOperators);
423 extern OpclassInfo *getOpclasses(int *numOpclasses);
424 extern ConvInfo *getConversions(int *numConversions);
425 extern TableInfo *getTables(int *numTables);
426 extern InhInfo *getInherits(int *numInherits);
427 extern void getIndexes(TableInfo tblinfo[], int numTables);
428 extern void getConstraints(TableInfo tblinfo[], int numTables);
429 extern RuleInfo *getRules(int *numRules);
430 extern void getTriggers(TableInfo tblinfo[], int numTables);
431 extern ProcLangInfo *getProcLangs(int *numProcLangs);
432 extern CastInfo *getCasts(int *numCasts);
433 extern void getTableAttrs(TableInfo *tbinfo, int numTables);
435 #endif /* PG_DUMP_H */