Header And Logo

PostgreSQL
| The world's most advanced open source database.

pg_dump.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * pg_dump.h
00004  *    Common header file for the pg_dump utility
00005  *
00006  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  * Portions Copyright (c) 1994, Regents of the University of California
00008  *
00009  * src/bin/pg_dump/pg_dump.h
00010  *
00011  *-------------------------------------------------------------------------
00012  */
00013 
00014 #ifndef PG_DUMP_H
00015 #define PG_DUMP_H
00016 
00017 #include "postgres_fe.h"
00018 
00019 /*
00020  * pg_dump uses two different mechanisms for identifying database objects:
00021  *
00022  * CatalogId represents an object by the tableoid and oid of its defining
00023  * entry in the system catalogs.  We need this to interpret pg_depend entries,
00024  * for instance.
00025  *
00026  * DumpId is a simple sequential integer counter assigned as dumpable objects
00027  * are identified during a pg_dump run.  We use DumpId internally in preference
00028  * to CatalogId for two reasons: it's more compact, and we can assign DumpIds
00029  * to "objects" that don't have a separate CatalogId.  For example, it is
00030  * convenient to consider a table, its data, and its ACL as three separate
00031  * dumpable "objects" with distinct DumpIds --- this lets us reason about the
00032  * order in which to dump these things.
00033  */
00034 
00035 typedef struct
00036 {
00037     Oid         tableoid;
00038     Oid         oid;
00039 } CatalogId;
00040 
00041 typedef int DumpId;
00042 
00043 /*
00044  * Data structures for simple lists of OIDs and strings.  The support for
00045  * these is very primitive compared to the backend's List facilities, but
00046  * it's all we need in pg_dump.
00047  */
00048 
00049 typedef struct SimpleOidListCell
00050 {
00051     struct SimpleOidListCell *next;
00052     Oid         val;
00053 } SimpleOidListCell;
00054 
00055 typedef struct SimpleOidList
00056 {
00057     SimpleOidListCell *head;
00058     SimpleOidListCell *tail;
00059 } SimpleOidList;
00060 
00061 
00062 /*
00063  * The data structures used to store system catalog information.  Every
00064  * dumpable object is a subclass of DumpableObject.
00065  *
00066  * NOTE: the structures described here live for the entire pg_dump run;
00067  * and in most cases we make a struct for every object we can find in the
00068  * catalogs, not only those we are actually going to dump.  Hence, it's
00069  * best to store a minimal amount of per-object info in these structs,
00070  * and retrieve additional per-object info when and if we dump a specific
00071  * object.  In particular, try to avoid retrieving expensive-to-compute
00072  * information until it's known to be needed.  We do, however, have to
00073  * store enough info to determine whether an object should be dumped and
00074  * what order to dump in.
00075  */
00076 
00077 typedef enum
00078 {
00079     /* When modifying this enum, update priority tables in pg_dump_sort.c! */
00080     DO_NAMESPACE,
00081     DO_EXTENSION,
00082     DO_TYPE,
00083     DO_SHELL_TYPE,
00084     DO_FUNC,
00085     DO_AGG,
00086     DO_OPERATOR,
00087     DO_OPCLASS,
00088     DO_OPFAMILY,
00089     DO_COLLATION,
00090     DO_CONVERSION,
00091     DO_TABLE,
00092     DO_ATTRDEF,
00093     DO_INDEX,
00094     DO_RULE,
00095     DO_TRIGGER,
00096     DO_CONSTRAINT,
00097     DO_FK_CONSTRAINT,           /* see note for ConstraintInfo */
00098     DO_PROCLANG,
00099     DO_CAST,
00100     DO_TABLE_DATA,
00101     DO_DUMMY_TYPE,
00102     DO_TSPARSER,
00103     DO_TSDICT,
00104     DO_TSTEMPLATE,
00105     DO_TSCONFIG,
00106     DO_FDW,
00107     DO_FOREIGN_SERVER,
00108     DO_DEFAULT_ACL,
00109     DO_BLOB,
00110     DO_BLOB_DATA,
00111     DO_PRE_DATA_BOUNDARY,
00112     DO_POST_DATA_BOUNDARY,
00113     DO_EVENT_TRIGGER,
00114     DO_REFRESH_MATVIEW
00115 } DumpableObjectType;
00116 
00117 typedef struct _dumpableObject
00118 {
00119     DumpableObjectType objType;
00120     CatalogId   catId;          /* zero if not a cataloged object */
00121     DumpId      dumpId;         /* assigned by AssignDumpId() */
00122     char       *name;           /* object name (should never be NULL) */
00123     struct _namespaceInfo *namespace;   /* containing namespace, or NULL */
00124     bool        dump;           /* true if we want to dump this object */
00125     bool        ext_member;     /* true if object is member of extension */
00126     DumpId     *dependencies;   /* dumpIds of objects this one depends on */
00127     int         nDeps;          /* number of valid dependencies */
00128     int         allocDeps;      /* allocated size of dependencies[] */
00129 } DumpableObject;
00130 
00131 typedef struct _namespaceInfo
00132 {
00133     DumpableObject dobj;
00134     char       *rolname;        /* name of owner, or empty string */
00135     char       *nspacl;
00136 } NamespaceInfo;
00137 
00138 typedef struct _extensionInfo
00139 {
00140     DumpableObject dobj;
00141     char       *namespace;      /* schema containing extension's objects */
00142     bool        relocatable;
00143     char       *extversion;
00144     char       *extconfig;      /* info about configuration tables */
00145     char       *extcondition;
00146 } ExtensionInfo;
00147 
00148 typedef struct _typeInfo
00149 {
00150     DumpableObject dobj;
00151 
00152     /*
00153      * Note: dobj.name is the pg_type.typname entry.  format_type() might
00154      * produce something different than typname
00155      */
00156     char       *rolname;        /* name of owner, or empty string */
00157     char       *typacl;
00158     Oid         typelem;
00159     Oid         typrelid;
00160     char        typrelkind;     /* 'r', 'v', 'c', etc */
00161     char        typtype;        /* 'b', 'c', etc */
00162     bool        isArray;        /* true if auto-generated array type */
00163     bool        isDefined;      /* true if typisdefined */
00164     /* If it's a dumpable base type, we create a "shell type" entry for it */
00165     struct _shellTypeInfo *shellType;   /* shell-type entry, or NULL */
00166     /* If it's a domain, we store links to its constraints here: */
00167     int         nDomChecks;
00168     struct _constraintInfo *domChecks;
00169 } TypeInfo;
00170 
00171 typedef struct _shellTypeInfo
00172 {
00173     DumpableObject dobj;
00174 
00175     TypeInfo   *baseType;       /* back link to associated base type */
00176 } ShellTypeInfo;
00177 
00178 typedef struct _funcInfo
00179 {
00180     DumpableObject dobj;
00181     char       *rolname;        /* name of owner, or empty string */
00182     Oid         lang;
00183     int         nargs;
00184     Oid        *argtypes;
00185     Oid         prorettype;
00186     char       *proacl;
00187     char       *proiargs;
00188 } FuncInfo;
00189 
00190 /* AggInfo is a superset of FuncInfo */
00191 typedef struct _aggInfo
00192 {
00193     FuncInfo    aggfn;
00194     /* we don't require any other fields at the moment */
00195 } AggInfo;
00196 
00197 typedef struct _oprInfo
00198 {
00199     DumpableObject dobj;
00200     char       *rolname;
00201     char        oprkind;
00202     Oid         oprcode;
00203 } OprInfo;
00204 
00205 typedef struct _opclassInfo
00206 {
00207     DumpableObject dobj;
00208     char       *rolname;
00209 } OpclassInfo;
00210 
00211 typedef struct _opfamilyInfo
00212 {
00213     DumpableObject dobj;
00214     char       *rolname;
00215 } OpfamilyInfo;
00216 
00217 typedef struct _collInfo
00218 {
00219     DumpableObject dobj;
00220     char       *rolname;
00221 } CollInfo;
00222 
00223 typedef struct _convInfo
00224 {
00225     DumpableObject dobj;
00226     char       *rolname;
00227 } ConvInfo;
00228 
00229 typedef struct _tableInfo
00230 {
00231     /*
00232      * These fields are collected for every table in the database.
00233      */
00234     DumpableObject dobj;
00235     char       *rolname;        /* name of owner, or empty string */
00236     char       *relacl;
00237     char        relkind;
00238     char        relpersistence; /* relation persistence */
00239     char       *reltablespace;  /* relation tablespace */
00240     char       *reloptions;     /* options specified by WITH (...) */
00241     char       *toast_reloptions;       /* ditto, for the TOAST table */
00242     bool        hasindex;       /* does it have any indexes? */
00243     bool        hasrules;       /* does it have any rules? */
00244     bool        hastriggers;    /* does it have any triggers? */
00245     bool        hasoids;        /* does it have OIDs? */
00246     bool        isscannable;    /* is valid for use in queries */
00247     uint32      frozenxid;      /* for restore frozen xid */
00248     Oid         toast_oid;      /* for restore toast frozen xid */
00249     uint32      toast_frozenxid;    /* for restore toast frozen xid */
00250     int         ncheck;         /* # of CHECK expressions */
00251     char       *reloftype;      /* underlying type for typed table */
00252     /* these two are set only if table is a sequence owned by a column: */
00253     Oid         owning_tab;     /* OID of table owning sequence */
00254     int         owning_col;     /* attr # of column owning sequence */
00255     int         relpages;
00256 
00257     bool        interesting;    /* true if need to collect more data */
00258 
00259     /*
00260      * These fields are computed only if we decide the table is interesting
00261      * (it's either a table to dump, or a direct parent of a dumpable table).
00262      */
00263     int         numatts;        /* number of attributes */
00264     char      **attnames;       /* the attribute names */
00265     char      **atttypnames;    /* attribute type names */
00266     int        *atttypmod;      /* type-specific type modifiers */
00267     int        *attstattarget;  /* attribute statistics targets */
00268     char       *attstorage;     /* attribute storage scheme */
00269     char       *typstorage;     /* type storage scheme */
00270     bool       *attisdropped;   /* true if attr is dropped; don't dump it */
00271     int        *attlen;         /* attribute length, used by binary_upgrade */
00272     char       *attalign;       /* attribute align, used by binary_upgrade */
00273     bool       *attislocal;     /* true if attr has local definition */
00274     char      **attoptions;     /* per-attribute options */
00275     Oid        *attcollation;   /* per-attribute collation selection */
00276     char      **attfdwoptions;  /* per-attribute fdw options */
00277     bool       *notnull;        /* NOT NULL constraints on attributes */
00278     bool       *inhNotNull;     /* true if NOT NULL is inherited */
00279     struct _attrDefInfo **attrdefs;     /* DEFAULT expressions */
00280     struct _constraintInfo *checkexprs; /* CHECK constraints */
00281 
00282     /*
00283      * Stuff computed only for dumpable tables.
00284      */
00285     int         numParents;     /* number of (immediate) parent tables */
00286     struct _tableInfo **parents;    /* TableInfos of immediate parents */
00287     struct _tableDataInfo *dataObj;     /* TableDataInfo, if dumping its data */
00288 } TableInfo;
00289 
00290 typedef struct _attrDefInfo
00291 {
00292     DumpableObject dobj;        /* note: dobj.name is name of table */
00293     TableInfo  *adtable;        /* link to table of attribute */
00294     int         adnum;
00295     char       *adef_expr;      /* decompiled DEFAULT expression */
00296     bool        separate;       /* TRUE if must dump as separate item */
00297 } AttrDefInfo;
00298 
00299 typedef struct _tableDataInfo
00300 {
00301     DumpableObject dobj;
00302     TableInfo  *tdtable;        /* link to table to dump */
00303     bool        oids;           /* include OIDs in data? */
00304     char       *filtercond;     /* WHERE condition to limit rows dumped */
00305 } TableDataInfo;
00306 
00307 typedef struct _indxInfo
00308 {
00309     DumpableObject dobj;
00310     TableInfo  *indextable;     /* link to table the index is for */
00311     char       *indexdef;
00312     char       *tablespace;     /* tablespace in which index is stored */
00313     char       *options;        /* options specified by WITH (...) */
00314     int         indnkeys;
00315     Oid        *indkeys;
00316     bool        indisclustered;
00317     /* if there is an associated constraint object, its dumpId: */
00318     DumpId      indexconstraint;
00319     int         relpages;       /* relpages of the underlying table */
00320 } IndxInfo;
00321 
00322 typedef struct _ruleInfo
00323 {
00324     DumpableObject dobj;
00325     TableInfo  *ruletable;      /* link to table the rule is for */
00326     char        ev_type;
00327     bool        is_instead;
00328     char        ev_enabled;
00329     bool        separate;       /* TRUE if must dump as separate item */
00330     /* separate is always true for non-ON SELECT rules */
00331     char       *reloptions;     /* options specified by WITH (...) */
00332     /* reloptions is only set if we need to dump the options with the rule */
00333 } RuleInfo;
00334 
00335 typedef struct _triggerInfo
00336 {
00337     DumpableObject dobj;
00338     TableInfo  *tgtable;        /* link to table the trigger is for */
00339     char       *tgfname;
00340     int         tgtype;
00341     int         tgnargs;
00342     char       *tgargs;
00343     bool        tgisconstraint;
00344     char       *tgconstrname;
00345     Oid         tgconstrrelid;
00346     char       *tgconstrrelname;
00347     char        tgenabled;
00348     bool        tgdeferrable;
00349     bool        tginitdeferred;
00350     char       *tgdef;
00351 } TriggerInfo;
00352 
00353 typedef struct _evttriggerInfo
00354 {
00355     DumpableObject dobj;
00356     char       *evtname;
00357     char       *evtevent;
00358     char       *evtowner;
00359     char       *evttags;
00360     char       *evtfname;
00361     char        evttype;
00362     char        evtenabled;
00363 } EventTriggerInfo;
00364 
00365 /*
00366  * struct ConstraintInfo is used for all constraint types.  However we
00367  * use a different objType for foreign key constraints, to make it easier
00368  * to sort them the way we want.
00369  *
00370  * Note: condeferrable and condeferred are currently only valid for
00371  * unique/primary-key constraints.  Otherwise that info is in condef.
00372  */
00373 typedef struct _constraintInfo
00374 {
00375     DumpableObject dobj;
00376     TableInfo  *contable;       /* NULL if domain constraint */
00377     TypeInfo   *condomain;      /* NULL if table constraint */
00378     char        contype;
00379     char       *condef;         /* definition, if CHECK or FOREIGN KEY */
00380     Oid         confrelid;      /* referenced table, if FOREIGN KEY */
00381     DumpId      conindex;       /* identifies associated index if any */
00382     bool        condeferrable;  /* TRUE if constraint is DEFERRABLE */
00383     bool        condeferred;    /* TRUE if constraint is INITIALLY DEFERRED */
00384     bool        conislocal;     /* TRUE if constraint has local definition */
00385     bool        separate;       /* TRUE if must dump as separate item */
00386 } ConstraintInfo;
00387 
00388 typedef struct _procLangInfo
00389 {
00390     DumpableObject dobj;
00391     bool        lanpltrusted;
00392     Oid         lanplcallfoid;
00393     Oid         laninline;
00394     Oid         lanvalidator;
00395     char       *lanacl;
00396     char       *lanowner;       /* name of owner, or empty string */
00397 } ProcLangInfo;
00398 
00399 typedef struct _castInfo
00400 {
00401     DumpableObject dobj;
00402     Oid         castsource;
00403     Oid         casttarget;
00404     Oid         castfunc;
00405     char        castcontext;
00406     char        castmethod;
00407 } CastInfo;
00408 
00409 /* InhInfo isn't a DumpableObject, just temporary state */
00410 typedef struct _inhInfo
00411 {
00412     Oid         inhrelid;       /* OID of a child table */
00413     Oid         inhparent;      /* OID of its parent */
00414 } InhInfo;
00415 
00416 typedef struct _prsInfo
00417 {
00418     DumpableObject dobj;
00419     Oid         prsstart;
00420     Oid         prstoken;
00421     Oid         prsend;
00422     Oid         prsheadline;
00423     Oid         prslextype;
00424 } TSParserInfo;
00425 
00426 typedef struct _dictInfo
00427 {
00428     DumpableObject dobj;
00429     char       *rolname;
00430     Oid         dicttemplate;
00431     char       *dictinitoption;
00432 } TSDictInfo;
00433 
00434 typedef struct _tmplInfo
00435 {
00436     DumpableObject dobj;
00437     Oid         tmplinit;
00438     Oid         tmpllexize;
00439 } TSTemplateInfo;
00440 
00441 typedef struct _cfgInfo
00442 {
00443     DumpableObject dobj;
00444     char       *rolname;
00445     Oid         cfgparser;
00446 } TSConfigInfo;
00447 
00448 typedef struct _fdwInfo
00449 {
00450     DumpableObject dobj;
00451     char       *rolname;
00452     char       *fdwhandler;
00453     char       *fdwvalidator;
00454     char       *fdwoptions;
00455     char       *fdwacl;
00456 } FdwInfo;
00457 
00458 typedef struct _foreignServerInfo
00459 {
00460     DumpableObject dobj;
00461     char       *rolname;
00462     Oid         srvfdw;
00463     char       *srvtype;
00464     char       *srvversion;
00465     char       *srvacl;
00466     char       *srvoptions;
00467 } ForeignServerInfo;
00468 
00469 typedef struct _defaultACLInfo
00470 {
00471     DumpableObject dobj;
00472     char       *defaclrole;
00473     char        defaclobjtype;
00474     char       *defaclacl;
00475 } DefaultACLInfo;
00476 
00477 typedef struct _blobInfo
00478 {
00479     DumpableObject dobj;
00480     char       *rolname;
00481     char       *blobacl;
00482 } BlobInfo;
00483 
00484 /* global decls */
00485 extern bool force_quotes;       /* double-quotes for identifiers flag */
00486 extern bool g_verbose;          /* verbose flag */
00487 
00488 /* placeholders for comment starting and ending delimiters */
00489 extern char g_comment_start[10];
00490 extern char g_comment_end[10];
00491 
00492 extern char g_opaque_type[10];  /* name for the opaque type */
00493 
00494 /*
00495  *  common utility functions
00496  */
00497 
00498 struct Archive;
00499 typedef struct Archive Archive;
00500 
00501 extern TableInfo *getSchemaData(Archive *, int *numTablesPtr);
00502 
00503 typedef enum _OidOptions
00504 {
00505     zeroAsOpaque = 1,
00506     zeroAsAny = 2,
00507     zeroAsStar = 4,
00508     zeroAsNone = 8
00509 } OidOptions;
00510 
00511 extern void AssignDumpId(DumpableObject *dobj);
00512 extern DumpId createDumpId(void);
00513 extern DumpId getMaxDumpId(void);
00514 extern DumpableObject *findObjectByDumpId(DumpId dumpId);
00515 extern DumpableObject *findObjectByCatalogId(CatalogId catalogId);
00516 extern void getDumpableObjects(DumpableObject ***objs, int *numObjs);
00517 
00518 extern void addObjectDependency(DumpableObject *dobj, DumpId refId);
00519 extern void removeObjectDependency(DumpableObject *dobj, DumpId refId);
00520 
00521 extern TableInfo *findTableByOid(Oid oid);
00522 extern TypeInfo *findTypeByOid(Oid oid);
00523 extern FuncInfo *findFuncByOid(Oid oid);
00524 extern OprInfo *findOprByOid(Oid oid);
00525 extern CollInfo *findCollationByOid(Oid oid);
00526 extern NamespaceInfo *findNamespaceByOid(Oid oid);
00527 
00528 extern void simple_oid_list_append(SimpleOidList *list, Oid val);
00529 extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
00530 
00531 extern void parseOidArray(const char *str, Oid *array, int arraysize);
00532 
00533 extern void sortDumpableObjects(DumpableObject **objs, int numObjs,
00534                     DumpId preBoundaryId, DumpId postBoundaryId);
00535 extern void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs);
00536 extern void sortDumpableObjectsByTypeOid(DumpableObject **objs, int numObjs);
00537 extern void sortDataAndIndexObjectsBySize(DumpableObject **objs, int numObjs);
00538 
00539 /*
00540  * version specific routines
00541  */
00542 extern NamespaceInfo *getNamespaces(Archive *fout, int *numNamespaces);
00543 extern ExtensionInfo *getExtensions(Archive *fout, int *numExtensions);
00544 extern TypeInfo *getTypes(Archive *fout, int *numTypes);
00545 extern FuncInfo *getFuncs(Archive *fout, int *numFuncs);
00546 extern AggInfo *getAggregates(Archive *fout, int *numAggregates);
00547 extern OprInfo *getOperators(Archive *fout, int *numOperators);
00548 extern OpclassInfo *getOpclasses(Archive *fout, int *numOpclasses);
00549 extern OpfamilyInfo *getOpfamilies(Archive *fout, int *numOpfamilies);
00550 extern CollInfo *getCollations(Archive *fout, int *numCollations);
00551 extern ConvInfo *getConversions(Archive *fout, int *numConversions);
00552 extern TableInfo *getTables(Archive *fout, int *numTables);
00553 extern void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables);
00554 extern InhInfo *getInherits(Archive *fout, int *numInherits);
00555 extern void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables);
00556 extern void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables);
00557 extern RuleInfo *getRules(Archive *fout, int *numRules);
00558 extern void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables);
00559 extern ProcLangInfo *getProcLangs(Archive *fout, int *numProcLangs);
00560 extern CastInfo *getCasts(Archive *fout, int *numCasts);
00561 extern void getTableAttrs(Archive *fout, TableInfo *tbinfo, int numTables);
00562 extern bool shouldPrintColumn(TableInfo *tbinfo, int colno);
00563 extern TSParserInfo *getTSParsers(Archive *fout, int *numTSParsers);
00564 extern TSDictInfo *getTSDictionaries(Archive *fout, int *numTSDicts);
00565 extern TSTemplateInfo *getTSTemplates(Archive *fout, int *numTSTemplates);
00566 extern TSConfigInfo *getTSConfigurations(Archive *fout, int *numTSConfigs);
00567 extern FdwInfo *getForeignDataWrappers(Archive *fout,
00568                        int *numForeignDataWrappers);
00569 extern ForeignServerInfo *getForeignServers(Archive *fout,
00570                   int *numForeignServers);
00571 extern DefaultACLInfo *getDefaultACLs(Archive *fout, int *numDefaultACLs);
00572 extern void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[],
00573                        int numExtensions);
00574 extern EventTriggerInfo *getEventTriggers(Archive *fout, int *numEventTriggers);
00575 
00576 #endif   /* PG_DUMP_H */