]> granicus.if.org Git - postgresql/blob - src/bin/pg_dump/pg_dump.h
b8fcfdc4ff53c0543b1186f4656c29369e549849
[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-2002, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: pg_dump.h,v 1.96 2002/08/18 09:36:26 petere Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13
14 #ifndef PG_DUMP_H
15 #define PG_DUMP_H
16
17 #include "pg_backup.h"
18
19 /*
20  * The data structures used to store system catalog information
21  *
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.
29  */
30
31 typedef struct _namespaceInfo
32 {
33         char       *oid;
34         char       *nspname;
35         char       *usename;            /* name of owner, or empty string */
36         char       *nspacl;
37         bool            dump;                   /* true if need to dump definition */
38 } NamespaceInfo;
39
40 typedef struct _typeInfo
41 {
42         char       *oid;
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 */
53 } TypeInfo;
54
55 typedef struct _funcInfo
56 {
57         char       *oid;
58         char       *proname;
59         NamespaceInfo *pronamespace;    /* link to containing namespace */
60         char       *usename;            /* name of owner, or empty string */
61         Oid                     lang;
62         int                     nargs;
63         char       **argtypes;          /* OIDs */
64         char       *prorettype;         /* OID */
65         char       *proacl;
66         bool            dumped;                 /* true if already dumped */
67 } FuncInfo;
68
69 typedef struct _aggInfo
70 {
71         char       *oid;
72         char       *aggname;
73         char       *aggbasetype;        /* OID */
74         NamespaceInfo *aggnamespace;    /* link to containing namespace */
75         char       *usename;
76         char       *aggacl;
77         char       *fmtbasetype;        /* formatted type name */
78 } AggInfo;
79
80 typedef struct _oprInfo
81 {
82         char       *oid;
83         char       *oprname;
84         NamespaceInfo *oprnamespace;    /* link to containing namespace */
85         char       *usename;
86         char       *oprcode;            /* as OID, not regproc name */
87 } OprInfo;
88
89 typedef struct _opclassInfo
90 {
91         char       *oid;
92         char       *opcname;
93         NamespaceInfo *opcnamespace;    /* link to containing namespace */
94         char       *usename;
95 } OpclassInfo;
96
97 typedef struct _tableInfo
98 {
99         /*
100          * These fields are collected for every table in the database.
101          */
102         char       *oid;
103         char       *relname;
104         NamespaceInfo *relnamespace;    /* link to containing namespace */
105         char       *usename;            /* name of owner, or empty string */
106         char       *relacl;
107         char            relkind;
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 */
113
114         bool            interesting;    /* true if need to collect more data */
115         bool            dump;                   /* true if we want to dump it */
116
117         /*
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).
120          */
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 */
126         /*
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
129          * inherited.
130          */
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 */
137
138         /*
139          * Stuff computed only for dumpable tables.
140          */
141         int                     numParents;             /* number of (immediate) parent tables */
142         int                *parentIndexes;      /* TableInfo indexes of immediate parents */
143
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. */
149 } TableInfo;
150
151 typedef struct _inhInfo
152 {
153         char       *inhrelid;           /* OID of a child table */
154         char       *inhparent;          /* OID of its parent */
155 } InhInfo;
156
157
158 /* global decls */
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 */
162
163 /* placeholders for comment starting and ending delimiters */
164 extern char g_comment_start[10];
165 extern char g_comment_end[10];
166
167 extern char g_opaque_type[10];  /* name for the opaque type */
168
169 /*
170  *      common utility functions
171  */
172
173 extern TableInfo *dumpSchema(Archive *fout,
174                    int *numTablesPtr,
175                    const bool aclsSkip,
176                    const bool schemaOnly,
177                    const bool dataOnly);
178
179 typedef enum _OidOptions
180 {
181         zeroAsOpaque = 1,
182         zeroAsAny = 2,
183         zeroAsStar = 4,
184         zeroAsNone = 8
185 } OidOptions;
186
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);
191
192 extern void check_conn_and_db(void);
193 extern void exit_nicely(void);
194
195 extern void parseNumericArray(const char *str, char **array, int arraysize);
196
197 /*
198  * version specific routines
199  */
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);
208
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,
224                                            const bool aclsSkip,
225                                            const bool schemaOnly, const bool dataOnly);
226 extern void dumpIndexes(Archive *fout, TableInfo *tbinfo, int numTables);
227
228 /* sprompt.h */
229 extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
230
231 #endif   /* PG_DUMP_H */