Disallow empty passwords in LDAP authentication, the same way
[PostgreSQL.git] / src / bin / pg_dump / pg_dump.h
bloba9b3daef3d89129d479501e5e417b00ea5cdd5ed
1 /*-------------------------------------------------------------------------
3 * pg_dump.h
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$
11 *-------------------------------------------------------------------------
14 #ifndef PG_DUMP_H
15 #define PG_DUMP_H
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,
24 * for instance.
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.
35 typedef struct
37 Oid tableoid;
38 Oid oid;
39 } CatalogId;
41 typedef int DumpId;
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;
52 Oid val;
53 } SimpleOidListCell;
55 typedef struct SimpleOidList
57 SimpleOidListCell *head;
58 SimpleOidListCell *tail;
59 } SimpleOidList;
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;
71 } SimpleStringList;
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.
88 typedef enum
90 /* When modifying this enum, update priority tables in pg_dump_sort.c! */
91 DO_NAMESPACE,
92 DO_TYPE,
93 DO_SHELL_TYPE,
94 DO_FUNC,
95 DO_AGG,
96 DO_OPERATOR,
97 DO_OPCLASS,
98 DO_OPFAMILY,
99 DO_CONVERSION,
100 DO_TABLE,
101 DO_ATTRDEF,
102 DO_INDEX,
103 DO_RULE,
104 DO_TRIGGER,
105 DO_CONSTRAINT,
106 DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
107 DO_PROCLANG,
108 DO_CAST,
109 DO_TABLE_DATA,
110 DO_DUMMY_TYPE,
111 DO_TSPARSER,
112 DO_TSDICT,
113 DO_TSTEMPLATE,
114 DO_TSCONFIG,
115 DO_FDW,
116 DO_FOREIGN_SERVER,
117 DO_BLOBS,
118 DO_BLOB_COMMENTS
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[] */
132 } DumpableObject;
134 typedef struct _namespaceInfo
136 DumpableObject dobj;
137 char *rolname; /* name of owner, or empty string */
138 char *nspacl;
139 } NamespaceInfo;
141 typedef struct _typeInfo
143 DumpableObject dobj;
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 */
150 Oid typelem;
151 Oid typrelid;
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: */
159 int nDomChecks;
160 struct _constraintInfo *domChecks;
161 } TypeInfo;
163 typedef struct _shellTypeInfo
165 DumpableObject dobj;
167 TypeInfo *baseType; /* back link to associated base type */
168 } ShellTypeInfo;
170 typedef struct _funcInfo
172 DumpableObject dobj;
173 char *rolname; /* name of owner, or empty string */
174 Oid lang;
175 int nargs;
176 Oid *argtypes;
177 Oid prorettype;
178 char *proacl;
179 } FuncInfo;
181 /* AggInfo is a superset of FuncInfo */
182 typedef struct _aggInfo
184 FuncInfo aggfn;
185 /* we don't require any other fields at the moment */
186 } AggInfo;
188 typedef struct _oprInfo
190 DumpableObject dobj;
191 char *rolname;
192 Oid oprcode;
193 } OprInfo;
195 typedef struct _opclassInfo
197 DumpableObject dobj;
198 char *rolname;
199 } OpclassInfo;
201 typedef struct _opfamilyInfo
203 DumpableObject dobj;
204 char *rolname;
205 } OpfamilyInfo;
207 typedef struct _convInfo
209 DumpableObject dobj;
210 char *rolname;
211 } ConvInfo;
213 typedef struct _tableInfo
216 * These fields are collected for every table in the database.
218 DumpableObject dobj;
219 char *rolname; /* name of owner, or empty string */
220 char *relacl;
221 char relkind;
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
256 * were inherited.
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 */
271 } TableInfo;
273 typedef struct _attrDefInfo
275 DumpableObject dobj;
276 TableInfo *adtable; /* link to table of attribute */
277 int adnum;
278 char *adef_expr; /* decompiled DEFAULT expression */
279 bool separate; /* TRUE if must dump as separate item */
280 } AttrDefInfo;
282 typedef struct _tableDataInfo
284 DumpableObject dobj;
285 TableInfo *tdtable; /* link to table to dump */
286 bool oids; /* include OIDs in data? */
287 } TableDataInfo;
289 typedef struct _indxInfo
291 DumpableObject dobj;
292 TableInfo *indextable; /* link to table the index is for */
293 char *indexdef;
294 char *tablespace; /* tablespace in which index is stored */
295 char *options; /* options specified by WITH (...) */
296 int indnkeys;
297 Oid *indkeys;
298 bool indisclustered;
299 /* if there is an associated constraint object, its dumpId: */
300 DumpId indexconstraint;
301 } IndxInfo;
303 typedef struct _ruleInfo
305 DumpableObject dobj;
306 TableInfo *ruletable; /* link to table the rule is for */
307 char ev_type;
308 bool is_instead;
309 char ev_enabled;
310 bool separate; /* TRUE if must dump as separate item */
311 /* separate is always true for non-ON SELECT rules */
312 } RuleInfo;
314 typedef struct _triggerInfo
316 DumpableObject dobj;
317 TableInfo *tgtable; /* link to table the trigger is for */
318 char *tgfname;
319 int tgtype;
320 int tgnargs;
321 char *tgargs;
322 bool tgisconstraint;
323 char *tgconstrname;
324 Oid tgconstrrelid;
325 char *tgconstrrelname;
326 char tgenabled;
327 bool tgdeferrable;
328 bool tginitdeferred;
329 } TriggerInfo;
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
338 DumpableObject dobj;
339 TableInfo *contable; /* NULL if domain constraint */
340 TypeInfo *condomain; /* NULL if table constraint */
341 char contype;
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 */
347 } ConstraintInfo;
349 typedef struct _procLangInfo
351 DumpableObject dobj;
352 bool lanpltrusted;
353 Oid lanplcallfoid;
354 Oid lanvalidator;
355 char *lanacl;
356 char *lanowner; /* name of owner, or empty string */
357 } ProcLangInfo;
359 typedef struct _castInfo
361 DumpableObject dobj;
362 Oid castsource;
363 Oid casttarget;
364 Oid castfunc;
365 char castcontext;
366 char castmethod;
367 } 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 */
374 } InhInfo;
376 typedef struct _prsInfo
378 DumpableObject dobj;
379 Oid prsstart;
380 Oid prstoken;
381 Oid prsend;
382 Oid prsheadline;
383 Oid prslextype;
384 } TSParserInfo;
386 typedef struct _dictInfo
388 DumpableObject dobj;
389 char *rolname;
390 Oid dicttemplate;
391 char *dictinitoption;
392 } TSDictInfo;
394 typedef struct _tmplInfo
396 DumpableObject dobj;
397 Oid tmplinit;
398 Oid tmpllexize;
399 } TSTemplateInfo;
401 typedef struct _cfgInfo
403 DumpableObject dobj;
404 char *rolname;
405 Oid cfgparser;
406 } TSConfigInfo;
408 typedef struct _fdwInfo
410 DumpableObject dobj;
411 char *rolname;
412 char *fdwvalidator;
413 char *fdwoptions;
414 char *fdwacl;
415 } FdwInfo;
417 typedef struct _foreignServerInfo
419 DumpableObject dobj;
420 char *rolname;
421 Oid srvfdw;
422 char *srvtype;
423 char *srvversion;
424 char *srvacl;
425 char *srvoptions;
426 } ForeignServerInfo;
428 /* global decls */
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
446 zeroAsOpaque = 1,
447 zeroAsAny = 2,
448 zeroAsStar = 4,
449 zeroAsNone = 8
450 } 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 */