aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_dump.h
blob: 8193f66aeb9e0a53debb4125558f34649ba15d29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*-------------------------------------------------------------------------
 *
 * pg_dump.h
 *	  Common header file for the pg_dump utility
 *
 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * $Id: pg_dump.h,v 1.100 2002/10/09 16:20:25 momjian Exp $
 *
 *-------------------------------------------------------------------------
 */

#ifndef PG_DUMP_H
#define PG_DUMP_H

#include "pg_backup.h"

/*
 * The data structures used to store system catalog information
 *
 * NOTE: the structures described here live for the entire pg_dump run;
 * and in most cases we make a struct for every object we can find in the
 * catalogs, not only those we are actually going to dump.	Hence, it's
 * best to store a minimal amount of per-object info in these structs,
 * and retrieve additional per-object info when and if we dump a specific
 * object.	In particular, try to avoid retrieving expensive-to-compute
 * information until it's known to be needed.
 */

typedef struct _namespaceInfo
{
	char	   *oid;
	char	   *nspname;
	char	   *usename;		/* name of owner, or empty string */
	char	   *nspacl;
	bool		dump;			/* true if need to dump definition */
} NamespaceInfo;

typedef struct _typeInfo
{
	char	   *oid;
	char	   *typname;		/* name as seen in catalog */
	/* Note: format_type might produce something different than typname */
	NamespaceInfo *typnamespace;	/* link to containing namespace */
	char	   *usename;		/* name of owner, or empty string */
	char	   *typelem;		/* OID */
	char	   *typrelid;		/* OID */
	char		typrelkind;		/* 'r', 'v', 'c', etc */
	char		typtype;		/* 'b', 'c', etc */
	bool		isArray;		/* true if user-defined array type */
	bool		isDefined;		/* true if typisdefined */
} TypeInfo;

typedef struct _funcInfo
{
	char	   *oid;
	char	   *proname;
	NamespaceInfo *pronamespace;	/* link to containing namespace */
	char	   *usename;		/* name of owner, or empty string */
	Oid			lang;
	int			nargs;
	char	  **argtypes;		/* OIDs */
	char	   *prorettype;		/* OID */
	char	   *proacl;
	bool		dumped;			/* true if already dumped */
} FuncInfo;

typedef struct _aggInfo
{
	char	   *oid;
	char	   *aggname;
	char	   *aggbasetype;	/* OID */
	NamespaceInfo *aggnamespace;	/* link to containing namespace */
	char	   *usename;
	char	   *aggacl;
	bool		anybasetype;	/* is the basetype "any"? */
	char	   *fmtbasetype;	/* formatted type name */
} AggInfo;

typedef struct _oprInfo
{
	char	   *oid;
	char	   *oprname;
	NamespaceInfo *oprnamespace;	/* link to containing namespace */
	char	   *usename;
	char	   *oprcode;		/* as OID, not regproc name */
} OprInfo;

typedef struct _opclassInfo
{
	char	   *oid;
	char	   *opcname;
	NamespaceInfo *opcnamespace;	/* link to containing namespace */
	char	   *usename;
} OpclassInfo;

typedef struct _tableInfo
{
	/*
	 * These fields are collected for every table in the database.
	 */
	char	   *oid;
	char	   *relname;
	NamespaceInfo *relnamespace;	/* link to containing namespace */
	char	   *usename;		/* name of owner, or empty string */
	char	   *relacl;
	char		relkind;
	bool		hasindex;		/* does it have any indexes? */
	bool		hasrules;		/* does it have any rules? */
	bool		hasoids;		/* does it have OIDs? */
	int			ncheck;			/* # of CHECK expressions */
	int			ntrig;			/* # of triggers */
	/* these two are set only if table is a SERIAL column's sequence: */
	char	   *owning_tab;		/* OID of table owning sequence */
	int			owning_col;		/* attr # of column owning sequence */

	bool		interesting;	/* true if need to collect more data */
	bool		dump;			/* true if we want to dump it */

	/*
	 * These fields are computed only if we decide the table is
	 * interesting (it's either a table to dump, or a direct parent of a
	 * dumpable table).
	 */
	int			numatts;		/* number of attributes */
	char	  **attnames;		/* the attribute names */
	char	  **atttypnames;	/* attribute type names */
	int		   *atttypmod;		/* type-specific type modifiers */
	int		   *attstattarget;	/* attribute statistics targets */
	bool	   *attisdropped;	/* true if attr is dropped; don't dump it */
	bool	   *attislocal;		/* true if attr has local definition */
	bool	   *attisserial;	/* true if attr is serial or bigserial */

	/*
	 * Note: we need to store per-attribute notnull and default stuff for
	 * all interesting tables so that we can tell which constraints were
	 * inherited.
	 */
	bool	   *notnull;		/* Not null constraints on attributes */
	char	  **adef_expr;		/* DEFAULT expressions */
	bool	   *inhAttrs;		/* true if each attribute is inherited */
	bool	   *inhAttrDef;		/* true if attr's default is inherited */
	bool	   *inhNotNull;		/* true if NOT NULL is inherited */

	/*
	 * Stuff computed only for dumpable tables.
	 */
	int			numParents;		/* number of (immediate) parent tables */
	int		   *parentIndexes;	/* TableInfo indexes of immediate parents */

	char	   *viewoid;		/* OID of view - should be >= oid of table
								 * important because views may be
								 * constructed manually from rules, and
								 * rule may ref things created after the
								 * base table was created. */
} TableInfo;

typedef struct _inhInfo
{
	char	   *inhrelid;		/* OID of a child table */
	char	   *inhparent;		/* OID of its parent */
} InhInfo;


/* global decls */
extern bool force_quotes;		/* double-quotes for identifiers flag */
extern bool g_verbose;			/* verbose flag */
extern Archive *g_fout;			/* the script file */

/* placeholders for comment starting and ending delimiters */
extern char g_comment_start[10];
extern char g_comment_end[10];

extern char g_opaque_type[10];	/* name for the opaque type */

/*
 *	common utility functions
 */

extern TableInfo *dumpSchema(Archive *fout,
		   int *numTablesPtr,
		   const bool aclsSkip,
		   const bool schemaOnly,
		   const bool dataOnly);

typedef enum _OidOptions
{
	zeroAsOpaque = 1,
	zeroAsAny = 2,
	zeroAsStar = 4,
	zeroAsNone = 8
} OidOptions;

extern int	findTableByOid(TableInfo *tbinfo, int numTables, const char *oid);
extern char *findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid);
extern int	findFuncByOid(FuncInfo *finfo, int numFuncs, const char *oid);
extern int	findTypeByOid(TypeInfo *tinfo, int numTypes, const char *oid);

extern void check_conn_and_db(void);
extern void exit_nicely(void);

extern void parseNumericArray(const char *str, char **array, int arraysize);

/*
 * version specific routines
 */
extern NamespaceInfo *getNamespaces(int *numNamespaces);
extern TypeInfo *getTypes(int *numTypes);
extern FuncInfo *getFuncs(int *numFuncs);
extern AggInfo *getAggregates(int *numAggregates);
extern OprInfo *getOperators(int *numOperators);
extern OpclassInfo *getOpclasses(int *numOpclasses);
extern TableInfo *getTables(int *numTables);
extern InhInfo *getInherits(int *numInherits);

extern void getTableAttrs(TableInfo *tbinfo, int numTables);
extern void dumpDBComment(Archive *outfile);
extern void dumpNamespaces(Archive *fout,
			   NamespaceInfo *nsinfo, int numNamespaces);
extern void dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
		  TypeInfo *tinfo, int numTypes);
extern void dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs);
extern void dumpFuncs(Archive *fout, FuncInfo finfo[], int numFuncs);
extern void dumpCasts(Archive *fout, FuncInfo *finfo, int numFuncs,
		  TypeInfo *tinfo, int numTypes);
extern void dumpAggs(Archive *fout, AggInfo agginfo[], int numAggregates);
extern void dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators);
extern void dumpOpclasses(Archive *fout,
			  OpclassInfo *opcinfo, int numOpclasses);
extern void dumpTables(Archive *fout, TableInfo tblinfo[], int numTables,
		   const bool aclsSkip,
		   const bool schemaOnly, const bool dataOnly);
extern void dumpIndexes(Archive *fout, TableInfo *tbinfo, int numTables);

/* sprompt.h */
extern char *simple_prompt(const char *prompt, int maxlen, bool echo);

#endif   /* PG_DUMP_H */