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
9 * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.145 2009/01/01 17:23:54 momjian Exp $
11 *-------------------------------------------------------------------------
17 #include "postgres_fe.h"
20 * WIN32 does not provide 64-bit off_t, but does provide the functions operating
21 * with 64-bit offsets.
24 #define pgoff_t __int64
27 #ifdef WIN32_ONLY_COMPILER
28 #define fseeko(stream, offset, origin) _fseeki64(stream, offset, origin)
29 #define ftello(stream) _ftelli64(stream)
31 #define fseeko(stream, offset, origin) fseeko64(stream, offset, origin)
32 #define ftello(stream) ftello64(stream)
39 * pg_dump uses two different mechanisms for identifying database objects:
41 * CatalogId represents an object by the tableoid and oid of its defining
42 * entry in the system catalogs. We need this to interpret pg_depend entries,
45 * DumpId is a simple sequential integer counter assigned as dumpable objects
46 * are identified during a pg_dump run. We use DumpId internally in preference
47 * to CatalogId for two reasons: it's more compact, and we can assign DumpIds
48 * to "objects" that don't have a separate CatalogId. For example, it is
49 * convenient to consider a table, its data, and its ACL as three separate
50 * dumpable "objects" with distinct DumpIds --- this lets us reason about the
51 * order in which to dump these things.
63 * Data structures for simple lists of OIDs and strings. The support for
64 * these is very primitive compared to the backend's List facilities, but
65 * it's all we need in pg_dump.
68 typedef struct SimpleOidListCell
70 struct SimpleOidListCell *next;
74 typedef struct SimpleOidList
76 SimpleOidListCell *head;
77 SimpleOidListCell *tail;
80 typedef struct SimpleStringListCell
82 struct SimpleStringListCell *next;
83 char val[1]; /* VARIABLE LENGTH FIELD */
84 } SimpleStringListCell;
86 typedef struct SimpleStringList
88 SimpleStringListCell *head;
89 SimpleStringListCell *tail;
93 * The data structures used to store system catalog information. Every
94 * dumpable object is a subclass of DumpableObject.
96 * NOTE: the structures described here live for the entire pg_dump run;
97 * and in most cases we make a struct for every object we can find in the
98 * catalogs, not only those we are actually going to dump. Hence, it's
99 * best to store a minimal amount of per-object info in these structs,
100 * and retrieve additional per-object info when and if we dump a specific
101 * object. In particular, try to avoid retrieving expensive-to-compute
102 * information until it's known to be needed. We do, however, have to
103 * store enough info to determine whether an object should be dumped and
104 * what order to dump in.
109 /* When modifying this enum, update priority tables in pg_dump_sort.c! */
125 DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
138 } DumpableObjectType;
140 typedef struct _dumpableObject
142 DumpableObjectType objType;
143 CatalogId catId; /* zero if not a cataloged object */
144 DumpId dumpId; /* assigned by AssignDumpId() */
145 char *name; /* object name (should never be NULL) */
146 struct _namespaceInfo *namespace; /* containing namespace, or NULL */
147 bool dump; /* true if we want to dump this object */
148 DumpId *dependencies; /* dumpIds of objects this one depends on */
149 int nDeps; /* number of valid dependencies */
150 int allocDeps; /* allocated size of dependencies[] */
153 typedef struct _namespaceInfo
156 char *rolname; /* name of owner, or empty string */
160 typedef struct _typeInfo
165 * Note: dobj.name is the pg_type.typname entry. format_type() might
166 * produce something different than typname
168 char *rolname; /* name of owner, or empty string */
171 char typrelkind; /* 'r', 'v', 'c', etc */
172 char typtype; /* 'b', 'c', etc */
173 bool isArray; /* true if auto-generated array type */
174 bool isDefined; /* true if typisdefined */
175 /* If it's a dumpable base type, we create a "shell type" entry for it */
176 struct _shellTypeInfo *shellType; /* shell-type entry, or NULL */
177 /* If it's a domain, we store links to its constraints here: */
179 struct _constraintInfo *domChecks;
182 typedef struct _shellTypeInfo
186 TypeInfo *baseType; /* back link to associated base type */
189 typedef struct _funcInfo
192 char *rolname; /* name of owner, or empty string */
200 /* AggInfo is a superset of FuncInfo */
201 typedef struct _aggInfo
204 /* we don't require any other fields at the moment */
207 typedef struct _oprInfo
214 typedef struct _opclassInfo
220 typedef struct _opfamilyInfo
226 typedef struct _convInfo
232 typedef struct _tableInfo
235 * These fields are collected for every table in the database.
238 char *rolname; /* name of owner, or empty string */
241 char *reltablespace; /* relation tablespace */
242 char *reloptions; /* options specified by WITH (...) */
243 bool hasindex; /* does it have any indexes? */
244 bool hasrules; /* does it have any rules? */
245 bool hastriggers; /* does it have any triggers? */
246 bool hasoids; /* does it have OIDs? */
247 int ncheck; /* # of CHECK expressions */
248 /* these two are set only if table is a sequence owned by a column: */
249 Oid owning_tab; /* OID of table owning sequence */
250 int owning_col; /* attr # of column owning sequence */
252 bool interesting; /* true if need to collect more data */
255 * These fields are computed only if we decide the table is interesting
256 * (it's either a table to dump, or a direct parent of a dumpable table).
258 int numatts; /* number of attributes */
259 char **attnames; /* the attribute names */
260 char **atttypnames; /* attribute type names */
261 int *atttypmod; /* type-specific type modifiers */
262 int *attstattarget; /* attribute statistics targets */
263 char *attstorage; /* attribute storage scheme */
264 char *typstorage; /* type storage scheme */
265 bool *attisdropped; /* true if attr is dropped; don't dump it */
266 bool *attislocal; /* true if attr has local definition */
269 * Note: we need to store per-attribute notnull, default, and constraint
270 * stuff for all interesting tables so that we can tell which constraints
273 bool *notnull; /* Not null constraints on attributes */
274 struct _attrDefInfo **attrdefs; /* DEFAULT expressions */
275 bool *inhAttrs; /* true if each attribute is inherited */
276 bool *inhAttrDef; /* true if attr's default is inherited */
277 bool *inhNotNull; /* true if NOT NULL is inherited */
278 struct _constraintInfo *checkexprs; /* CHECK constraints */
281 * Stuff computed only for dumpable tables.
283 int numParents; /* number of (immediate) parent tables */
284 struct _tableInfo **parents; /* TableInfos of immediate parents */
285 struct _tableDataInfo *dataObj; /* TableDataInfo, if dumping its data */
288 typedef struct _attrDefInfo
291 TableInfo *adtable; /* link to table of attribute */
293 char *adef_expr; /* decompiled DEFAULT expression */
294 bool separate; /* TRUE if must dump as separate item */
297 typedef struct _tableDataInfo
300 TableInfo *tdtable; /* link to table to dump */
301 bool oids; /* include OIDs in data? */
304 typedef struct _indxInfo
307 TableInfo *indextable; /* link to table the index is for */
309 char *tablespace; /* tablespace in which index is stored */
310 char *options; /* options specified by WITH (...) */
314 /* if there is an associated constraint object, its dumpId: */
315 DumpId indexconstraint;
318 typedef struct _ruleInfo
321 TableInfo *ruletable; /* link to table the rule is for */
325 bool separate; /* TRUE if must dump as separate item */
326 /* separate is always true for non-ON SELECT rules */
329 typedef struct _triggerInfo
332 TableInfo *tgtable; /* link to table the trigger is for */
340 char *tgconstrrelname;
347 * struct ConstraintInfo is used for all constraint types. However we
348 * use a different objType for foreign key constraints, to make it easier
349 * to sort them the way we want.
351 typedef struct _constraintInfo
354 TableInfo *contable; /* NULL if domain constraint */
355 TypeInfo *condomain; /* NULL if table constraint */
357 char *condef; /* definition, if CHECK or FOREIGN KEY */
358 Oid confrelid; /* referenced table, if FOREIGN KEY */
359 DumpId conindex; /* identifies associated index if any */
360 bool conislocal; /* TRUE if constraint has local definition */
361 bool separate; /* TRUE if must dump as separate item */
364 typedef struct _procLangInfo
371 char *lanowner; /* name of owner, or empty string */
374 typedef struct _castInfo
384 /* InhInfo isn't a DumpableObject, just temporary state */
385 typedef struct _inhInfo
387 Oid inhrelid; /* OID of a child table */
388 Oid inhparent; /* OID of its parent */
391 typedef struct _prsInfo
401 typedef struct _dictInfo
406 char *dictinitoption;
409 typedef struct _tmplInfo
416 typedef struct _cfgInfo
423 typedef struct _fdwInfo
432 typedef struct _foreignServerInfo
444 extern bool force_quotes; /* double-quotes for identifiers flag */
445 extern bool g_verbose; /* verbose flag */
447 /* placeholders for comment starting and ending delimiters */
448 extern char g_comment_start[10];
449 extern char g_comment_end[10];
451 extern char g_opaque_type[10]; /* name for the opaque type */
454 * common utility functions
457 extern TableInfo *getSchemaData(int *numTablesPtr);
459 typedef enum _OidOptions
467 extern void AssignDumpId(DumpableObject *dobj);
468 extern DumpId createDumpId(void);
469 extern DumpId getMaxDumpId(void);
470 extern DumpableObject *findObjectByDumpId(DumpId dumpId);
471 extern DumpableObject *findObjectByCatalogId(CatalogId catalogId);
472 extern void getDumpableObjects(DumpableObject ***objs, int *numObjs);
474 extern void addObjectDependency(DumpableObject *dobj, DumpId refId);
475 extern void removeObjectDependency(DumpableObject *dobj, DumpId refId);
477 extern TableInfo *findTableByOid(Oid oid);
478 extern TypeInfo *findTypeByOid(Oid oid);
479 extern FuncInfo *findFuncByOid(Oid oid);
480 extern OprInfo *findOprByOid(Oid oid);
482 extern void simple_oid_list_append(SimpleOidList *list, Oid val);
483 extern void simple_string_list_append(SimpleStringList *list, const char *val);
484 extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
485 extern bool simple_string_list_member(SimpleStringList *list, const char *val);
487 extern char *pg_strdup(const char *string);
488 extern void *pg_malloc(size_t size);
489 extern void *pg_calloc(size_t nmemb, size_t size);
490 extern void *pg_realloc(void *ptr, size_t size);
492 extern void check_conn_and_db(void);
493 extern void exit_nicely(void);
495 extern void parseOidArray(const char *str, Oid *array, int arraysize);
497 extern void sortDumpableObjects(DumpableObject **objs, int numObjs);
498 extern void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs);
499 extern void sortDumpableObjectsByTypeOid(DumpableObject **objs, int numObjs);
502 * version specific routines
504 extern NamespaceInfo *getNamespaces(int *numNamespaces);
505 extern TypeInfo *getTypes(int *numTypes);
506 extern FuncInfo *getFuncs(int *numFuncs);
507 extern AggInfo *getAggregates(int *numAggregates);
508 extern OprInfo *getOperators(int *numOperators);
509 extern OpclassInfo *getOpclasses(int *numOpclasses);
510 extern OpfamilyInfo *getOpfamilies(int *numOpfamilies);
511 extern ConvInfo *getConversions(int *numConversions);
512 extern TableInfo *getTables(int *numTables);
513 extern InhInfo *getInherits(int *numInherits);
514 extern void getIndexes(TableInfo tblinfo[], int numTables);
515 extern void getConstraints(TableInfo tblinfo[], int numTables);
516 extern RuleInfo *getRules(int *numRules);
517 extern void getTriggers(TableInfo tblinfo[], int numTables);
518 extern ProcLangInfo *getProcLangs(int *numProcLangs);
519 extern CastInfo *getCasts(int *numCasts);
520 extern void getTableAttrs(TableInfo *tbinfo, int numTables);
521 extern TSParserInfo *getTSParsers(int *numTSParsers);
522 extern TSDictInfo *getTSDictionaries(int *numTSDicts);
523 extern TSTemplateInfo *getTSTemplates(int *numTSTemplates);
524 extern TSConfigInfo *getTSConfigurations(int *numTSConfigs);
525 extern FdwInfo *getForeignDataWrappers(int *numForeignDataWrappers);
526 extern ForeignServerInfo *getForeignServers(int *numForeignServers);
528 #endif /* PG_DUMP_H */