]> granicus.if.org Git - postgresql/blob - src/bin/pg_dump/pg_dump.h
pg_upgrade: preserve database and relation minmxid values
[postgresql] / src / bin / pg_dump / pg_dump.h
1 /*-------------------------------------------------------------------------
2  *
3  * pg_dump.h
4  *        Common header file for the pg_dump utility
5  *
6  * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/bin/pg_dump/pg_dump.h
10  *
11  *-------------------------------------------------------------------------
12  */
13
14 #ifndef PG_DUMP_H
15 #define PG_DUMP_H
16
17 #include "postgres_fe.h"
18
19 /*
20  * pg_dump uses two different mechanisms for identifying database objects:
21  *
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.
25  *
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.
33  */
34
35 typedef struct
36 {
37         Oid                     tableoid;
38         Oid                     oid;
39 } CatalogId;
40
41 typedef int DumpId;
42
43 /*
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.
47  */
48
49 typedef struct SimpleOidListCell
50 {
51         struct SimpleOidListCell *next;
52         Oid                     val;
53 } SimpleOidListCell;
54
55 typedef struct SimpleOidList
56 {
57         SimpleOidListCell *head;
58         SimpleOidListCell *tail;
59 } SimpleOidList;
60
61
62 /*
63  * The data structures used to store system catalog information.  Every
64  * dumpable object is a subclass of DumpableObject.
65  *
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.
75  */
76
77 typedef enum
78 {
79         /* When modifying this enum, update priority tables in pg_dump_sort.c! */
80         DO_NAMESPACE,
81         DO_EXTENSION,
82         DO_TYPE,
83         DO_SHELL_TYPE,
84         DO_FUNC,
85         DO_AGG,
86         DO_OPERATOR,
87         DO_OPCLASS,
88         DO_OPFAMILY,
89         DO_COLLATION,
90         DO_CONVERSION,
91         DO_TABLE,
92         DO_ATTRDEF,
93         DO_INDEX,
94         DO_RULE,
95         DO_TRIGGER,
96         DO_CONSTRAINT,
97         DO_FK_CONSTRAINT,                       /* see note for ConstraintInfo */
98         DO_PROCLANG,
99         DO_CAST,
100         DO_TABLE_DATA,
101         DO_DUMMY_TYPE,
102         DO_TSPARSER,
103         DO_TSDICT,
104         DO_TSTEMPLATE,
105         DO_TSCONFIG,
106         DO_FDW,
107         DO_FOREIGN_SERVER,
108         DO_DEFAULT_ACL,
109         DO_BLOB,
110         DO_BLOB_DATA,
111         DO_PRE_DATA_BOUNDARY,
112         DO_POST_DATA_BOUNDARY,
113         DO_EVENT_TRIGGER,
114         DO_REFRESH_MATVIEW
115 } DumpableObjectType;
116
117 typedef struct _dumpableObject
118 {
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[] */
129 } DumpableObject;
130
131 typedef struct _namespaceInfo
132 {
133         DumpableObject dobj;
134         char       *rolname;            /* name of owner, or empty string */
135         char       *nspacl;
136 } NamespaceInfo;
137
138 typedef struct _extensionInfo
139 {
140         DumpableObject dobj;
141         char       *namespace;          /* schema containing extension's objects */
142         bool            relocatable;
143         char       *extversion;
144         char       *extconfig;          /* info about configuration tables */
145         char       *extcondition;
146 } ExtensionInfo;
147
148 typedef struct _typeInfo
149 {
150         DumpableObject dobj;
151
152         /*
153          * Note: dobj.name is the pg_type.typname entry.  format_type() might
154          * produce something different than typname
155          */
156         char       *rolname;            /* name of owner, or empty string */
157         char       *typacl;
158         Oid                     typelem;
159         Oid                     typrelid;
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: */
167         int                     nDomChecks;
168         struct _constraintInfo *domChecks;
169 } TypeInfo;
170
171 typedef struct _shellTypeInfo
172 {
173         DumpableObject dobj;
174
175         TypeInfo   *baseType;           /* back link to associated base type */
176 } ShellTypeInfo;
177
178 typedef struct _funcInfo
179 {
180         DumpableObject dobj;
181         char       *rolname;            /* name of owner, or empty string */
182         Oid                     lang;
183         int                     nargs;
184         Oid                *argtypes;
185         Oid                     prorettype;
186         char       *proacl;
187         char       *proiargs;
188 } FuncInfo;
189
190 /* AggInfo is a superset of FuncInfo */
191 typedef struct _aggInfo
192 {
193         FuncInfo        aggfn;
194         /* we don't require any other fields at the moment */
195 } AggInfo;
196
197 typedef struct _oprInfo
198 {
199         DumpableObject dobj;
200         char       *rolname;
201         char            oprkind;
202         Oid                     oprcode;
203 } OprInfo;
204
205 typedef struct _opclassInfo
206 {
207         DumpableObject dobj;
208         char       *rolname;
209 } OpclassInfo;
210
211 typedef struct _opfamilyInfo
212 {
213         DumpableObject dobj;
214         char       *rolname;
215 } OpfamilyInfo;
216
217 typedef struct _collInfo
218 {
219         DumpableObject dobj;
220         char       *rolname;
221 } CollInfo;
222
223 typedef struct _convInfo
224 {
225         DumpableObject dobj;
226         char       *rolname;
227 } ConvInfo;
228
229 typedef struct _tableInfo
230 {
231         /*
232          * These fields are collected for every table in the database.
233          */
234         DumpableObject dobj;
235         char       *rolname;            /* name of owner, or empty string */
236         char       *relacl;
237         char            relkind;
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) */
260
261         bool            interesting;    /* true if need to collect more data */
262         bool            postponed_def;  /* matview must be postponed into post-data */
263
264         /*
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).
267          */
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 */
286
287         /*
288          * Stuff computed only for dumpable tables.
289          */
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 */
293 } TableInfo;
294
295 typedef struct _attrDefInfo
296 {
297         DumpableObject dobj;            /* note: dobj.name is name of table */
298         TableInfo  *adtable;            /* link to table of attribute */
299         int                     adnum;
300         char       *adef_expr;          /* decompiled DEFAULT expression */
301         bool            separate;               /* TRUE if must dump as separate item */
302 } AttrDefInfo;
303
304 typedef struct _tableDataInfo
305 {
306         DumpableObject dobj;
307         TableInfo  *tdtable;            /* link to table to dump */
308         bool            oids;                   /* include OIDs in data? */
309         char       *filtercond;         /* WHERE condition to limit rows dumped */
310 } TableDataInfo;
311
312 typedef struct _indxInfo
313 {
314         DumpableObject dobj;
315         TableInfo  *indextable;         /* link to table the index is for */
316         char       *indexdef;
317         char       *tablespace;         /* tablespace in which index is stored */
318         char       *options;            /* options specified by WITH (...) */
319         int                     indnkeys;
320         Oid                *indkeys;
321         bool            indisclustered;
322         bool            indisreplident;
323         /* if there is an associated constraint object, its dumpId: */
324         DumpId          indexconstraint;
325         int                     relpages;               /* relpages of the underlying table */
326 } IndxInfo;
327
328 typedef struct _ruleInfo
329 {
330         DumpableObject dobj;
331         TableInfo  *ruletable;          /* link to table the rule is for */
332         char            ev_type;
333         bool            is_instead;
334         char            ev_enabled;
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 */
339 } RuleInfo;
340
341 typedef struct _triggerInfo
342 {
343         DumpableObject dobj;
344         TableInfo  *tgtable;            /* link to table the trigger is for */
345         char       *tgfname;
346         int                     tgtype;
347         int                     tgnargs;
348         char       *tgargs;
349         bool            tgisconstraint;
350         char       *tgconstrname;
351         Oid                     tgconstrrelid;
352         char       *tgconstrrelname;
353         char            tgenabled;
354         bool            tgdeferrable;
355         bool            tginitdeferred;
356         char       *tgdef;
357 } TriggerInfo;
358
359 typedef struct _evttriggerInfo
360 {
361         DumpableObject dobj;
362         char       *evtname;
363         char       *evtevent;
364         char       *evtowner;
365         char       *evttags;
366         char       *evtfname;
367         char            evtenabled;
368 } EventTriggerInfo;
369
370 /*
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.
374  *
375  * Note: condeferrable and condeferred are currently only valid for
376  * unique/primary-key constraints.  Otherwise that info is in condef.
377  */
378 typedef struct _constraintInfo
379 {
380         DumpableObject dobj;
381         TableInfo  *contable;           /* NULL if domain constraint */
382         TypeInfo   *condomain;          /* NULL if table constraint */
383         char            contype;
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 */
391 } ConstraintInfo;
392
393 typedef struct _procLangInfo
394 {
395         DumpableObject dobj;
396         bool            lanpltrusted;
397         Oid                     lanplcallfoid;
398         Oid                     laninline;
399         Oid                     lanvalidator;
400         char       *lanacl;
401         char       *lanowner;           /* name of owner, or empty string */
402 } ProcLangInfo;
403
404 typedef struct _castInfo
405 {
406         DumpableObject dobj;
407         Oid                     castsource;
408         Oid                     casttarget;
409         Oid                     castfunc;
410         char            castcontext;
411         char            castmethod;
412 } CastInfo;
413
414 /* InhInfo isn't a DumpableObject, just temporary state */
415 typedef struct _inhInfo
416 {
417         Oid                     inhrelid;               /* OID of a child table */
418         Oid                     inhparent;              /* OID of its parent */
419 } InhInfo;
420
421 typedef struct _prsInfo
422 {
423         DumpableObject dobj;
424         Oid                     prsstart;
425         Oid                     prstoken;
426         Oid                     prsend;
427         Oid                     prsheadline;
428         Oid                     prslextype;
429 } TSParserInfo;
430
431 typedef struct _dictInfo
432 {
433         DumpableObject dobj;
434         char       *rolname;
435         Oid                     dicttemplate;
436         char       *dictinitoption;
437 } TSDictInfo;
438
439 typedef struct _tmplInfo
440 {
441         DumpableObject dobj;
442         Oid                     tmplinit;
443         Oid                     tmpllexize;
444 } TSTemplateInfo;
445
446 typedef struct _cfgInfo
447 {
448         DumpableObject dobj;
449         char       *rolname;
450         Oid                     cfgparser;
451 } TSConfigInfo;
452
453 typedef struct _fdwInfo
454 {
455         DumpableObject dobj;
456         char       *rolname;
457         char       *fdwhandler;
458         char       *fdwvalidator;
459         char       *fdwoptions;
460         char       *fdwacl;
461 } FdwInfo;
462
463 typedef struct _foreignServerInfo
464 {
465         DumpableObject dobj;
466         char       *rolname;
467         Oid                     srvfdw;
468         char       *srvtype;
469         char       *srvversion;
470         char       *srvacl;
471         char       *srvoptions;
472 } ForeignServerInfo;
473
474 typedef struct _defaultACLInfo
475 {
476         DumpableObject dobj;
477         char       *defaclrole;
478         char            defaclobjtype;
479         char       *defaclacl;
480 } DefaultACLInfo;
481
482 typedef struct _blobInfo
483 {
484         DumpableObject dobj;
485         char       *rolname;
486         char       *blobacl;
487 } BlobInfo;
488
489 /* global decls */
490 extern bool force_quotes;               /* double-quotes for identifiers flag */
491 extern bool g_verbose;                  /* verbose flag */
492
493 /* placeholders for comment starting and ending delimiters */
494 extern char g_comment_start[10];
495 extern char g_comment_end[10];
496
497 extern char g_opaque_type[10];  /* name for the opaque type */
498
499 /*
500  *      common utility functions
501  */
502
503 struct Archive;
504 typedef struct Archive Archive;
505
506 extern TableInfo *getSchemaData(Archive *, int *numTablesPtr);
507
508 typedef enum _OidOptions
509 {
510         zeroAsOpaque = 1,
511         zeroAsAny = 2,
512         zeroAsStar = 4,
513         zeroAsNone = 8
514 } OidOptions;
515
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);
522
523 extern void addObjectDependency(DumpableObject *dobj, DumpId refId);
524 extern void removeObjectDependency(DumpableObject *dobj, DumpId refId);
525
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);
532
533 extern void simple_oid_list_append(SimpleOidList *list, Oid val);
534 extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
535
536 extern void parseOidArray(const char *str, Oid *array, int arraysize);
537
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);
543
544 /*
545  * version specific routines
546  */
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[],
578                                            int numExtensions);
579 extern EventTriggerInfo *getEventTriggers(Archive *fout, int *numEventTriggers);
580
581 #endif   /* PG_DUMP_H */