1 /*-------------------------------------------------------------------------
4 * Common header file for the pg_dump utility
6 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * $Id: pg_dump.h,v 1.96 2002/08/18 09:36:26 petere Exp $
11 *-------------------------------------------------------------------------
17 #include "pg_backup.h"
20 * The data structures used to store system catalog information
22 * NOTE: the structures described here live for the entire pg_dump run;
23 * and in most cases we make a struct for every object we can find in the
24 * catalogs, not only those we are actually going to dump. Hence, it's
25 * best to store a minimal amount of per-object info in these structs,
26 * and retrieve additional per-object info when and if we dump a specific
27 * object. In particular, try to avoid retrieving expensive-to-compute
28 * information until it's known to be needed.
31 typedef struct _namespaceInfo
35 char *usename; /* name of owner, or empty string */
37 bool dump; /* true if need to dump definition */
40 typedef struct _typeInfo
43 char *typname; /* name as seen in catalog */
44 /* Note: format_type might produce something different than typname */
45 NamespaceInfo *typnamespace; /* link to containing namespace */
46 char *usename; /* name of owner, or empty string */
47 char *typelem; /* OID */
48 char *typrelid; /* OID */
49 char typrelkind; /* 'r', 'v', 'c', etc */
50 char typtype; /* 'b', 'c', etc */
51 bool isArray; /* true if user-defined array type */
52 bool isDefined; /* true if typisdefined */
55 typedef struct _funcInfo
59 NamespaceInfo *pronamespace; /* link to containing namespace */
60 char *usename; /* name of owner, or empty string */
63 char **argtypes; /* OIDs */
64 char *prorettype; /* OID */
66 bool dumped; /* true if already dumped */
69 typedef struct _aggInfo
73 char *aggbasetype; /* OID */
74 NamespaceInfo *aggnamespace; /* link to containing namespace */
77 char *fmtbasetype; /* formatted type name */
80 typedef struct _oprInfo
84 NamespaceInfo *oprnamespace; /* link to containing namespace */
86 char *oprcode; /* as OID, not regproc name */
89 typedef struct _opclassInfo
93 NamespaceInfo *opcnamespace; /* link to containing namespace */
97 typedef struct _tableInfo
100 * These fields are collected for every table in the database.
104 NamespaceInfo *relnamespace; /* link to containing namespace */
105 char *usename; /* name of owner, or empty string */
108 bool hasindex; /* does it have any indexes? */
109 bool hasrules; /* does it have any rules? */
110 bool hasoids; /* does it have OIDs? */
111 int ncheck; /* # of CHECK expressions */
112 int ntrig; /* # of triggers */
114 bool interesting; /* true if need to collect more data */
115 bool dump; /* true if we want to dump it */
118 * These fields are computed only if we decide the table is interesting
119 * (it's either a table to dump, or a direct parent of a dumpable table).
121 int numatts; /* number of attributes */
122 char **attnames; /* the attribute names */
123 char **atttypnames; /* attribute type names */
124 int *atttypmod; /* type-specific type modifiers */
125 int *attstattarget; /* attribute statistics targets */
127 * Note: we need to store per-attribute notnull and default stuff for
128 * all interesting tables so that we can tell which constraints were
131 bool *attisdropped; /* true if attr is dropped; don't dump it */
132 bool *notnull; /* Not null constraints on attributes */
133 char **adef_expr; /* DEFAULT expressions */
134 bool *inhAttrs; /* true if each attribute is inherited */
135 bool *inhAttrDef; /* true if attr's default is inherited */
136 bool *inhNotNull; /* true if NOT NULL is inherited */
139 * Stuff computed only for dumpable tables.
141 int numParents; /* number of (immediate) parent tables */
142 int *parentIndexes; /* TableInfo indexes of immediate parents */
144 char *viewoid; /* OID of view - should be >= oid of table
145 * important because views may be
146 * constructed manually from rules, and
147 * rule may ref things created after the
148 * base table was created. */
151 typedef struct _inhInfo
153 char *inhrelid; /* OID of a child table */
154 char *inhparent; /* OID of its parent */
159 extern bool force_quotes; /* double-quotes for identifiers flag */
160 extern bool g_verbose; /* verbose flag */
161 extern Archive *g_fout; /* the script file */
163 /* placeholders for comment starting and ending delimiters */
164 extern char g_comment_start[10];
165 extern char g_comment_end[10];
167 extern char g_opaque_type[10]; /* name for the opaque type */
170 * common utility functions
173 extern TableInfo *dumpSchema(Archive *fout,
176 const bool schemaOnly,
177 const bool dataOnly);
179 typedef enum _OidOptions
187 extern int findTableByOid(TableInfo *tbinfo, int numTables, const char *oid);
188 extern char *findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid);
189 extern int findFuncByOid(FuncInfo *finfo, int numFuncs, const char *oid);
190 extern int findTypeByOid(TypeInfo *tinfo, int numTypes, const char *oid);
192 extern void check_conn_and_db(void);
193 extern void exit_nicely(void);
195 extern void parseNumericArray(const char *str, char **array, int arraysize);
198 * version specific routines
200 extern NamespaceInfo *getNamespaces(int *numNamespaces);
201 extern TypeInfo *getTypes(int *numTypes);
202 extern FuncInfo *getFuncs(int *numFuncs);
203 extern AggInfo *getAggregates(int *numAggregates);
204 extern OprInfo *getOperators(int *numOperators);
205 extern OpclassInfo *getOpclasses(int *numOpclasses);
206 extern TableInfo *getTables(int *numTables);
207 extern InhInfo *getInherits(int *numInherits);
209 extern void getTableAttrs(TableInfo *tbinfo, int numTables);
210 extern void dumpDBComment(Archive *outfile);
211 extern void dumpNamespaces(Archive *fout,
212 NamespaceInfo *nsinfo, int numNamespaces);
213 extern void dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
214 TypeInfo *tinfo, int numTypes);
215 extern void dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs);
216 extern void dumpFuncs(Archive *fout, FuncInfo finfo[], int numFuncs);
217 extern void dumpCasts(Archive *fout, FuncInfo *finfo, int numFuncs,
218 TypeInfo *tinfo, int numTypes);
219 extern void dumpAggs(Archive *fout, AggInfo agginfo[], int numAggregates);
220 extern void dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators);
221 extern void dumpOpclasses(Archive *fout,
222 OpclassInfo *opcinfo, int numOpclasses);
223 extern void dumpTables(Archive *fout, TableInfo tblinfo[], int numTables,
225 const bool schemaOnly, const bool dataOnly);
226 extern void dumpIndexes(Archive *fout, TableInfo *tbinfo, int numTables);
229 extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
231 #endif /* PG_DUMP_H */