/Users/deen/code/yugabyte-db/src/postgres/src/bin/pg_dump/pg_backup.h
Line | Count | Source (jump to first uncovered line) |
1 | | /*------------------------------------------------------------------------- |
2 | | * |
3 | | * pg_backup.h |
4 | | * |
5 | | * Public interface to the pg_dump archiver routines. |
6 | | * |
7 | | * See the headers to pg_restore for more details. |
8 | | * |
9 | | * Copyright (c) 2000, Philip Warner |
10 | | * Rights are granted to use this software in any way so long |
11 | | * as this notice is not removed. |
12 | | * |
13 | | * The author is not responsible for loss or damages that may |
14 | | * result from it's use. |
15 | | * |
16 | | * |
17 | | * IDENTIFICATION |
18 | | * src/bin/pg_dump/pg_backup.h |
19 | | * |
20 | | *------------------------------------------------------------------------- |
21 | | */ |
22 | | |
23 | | #ifndef PG_BACKUP_H |
24 | | #define PG_BACKUP_H |
25 | | |
26 | | #include "fe_utils/simple_list.h" |
27 | | #include "libpq-fe.h" |
28 | | |
29 | | |
30 | | typedef enum trivalue |
31 | | { |
32 | | TRI_DEFAULT, |
33 | | TRI_NO, |
34 | | TRI_YES |
35 | | } trivalue; |
36 | | |
37 | | typedef enum _archiveFormat |
38 | | { |
39 | | archUnknown = 0, |
40 | | archCustom = 1, |
41 | | archTar = 3, |
42 | | archNull = 4, |
43 | | archDirectory = 5 |
44 | | } ArchiveFormat; |
45 | | |
46 | | typedef enum _archiveMode |
47 | | { |
48 | | archModeAppend, |
49 | | archModeWrite, |
50 | | archModeRead |
51 | | } ArchiveMode; |
52 | | |
53 | | typedef enum _teSection |
54 | | { |
55 | | SECTION_NONE = 1, /* COMMENTs, ACLs, etc; can be anywhere */ |
56 | | SECTION_PRE_DATA, /* stuff to be processed before data */ |
57 | | SECTION_DATA, /* TABLE DATA, BLOBS, BLOB COMMENTS */ |
58 | | SECTION_POST_DATA /* stuff to be processed after data */ |
59 | | } teSection; |
60 | | |
61 | | /* Parameters needed by ConnectDatabase; same for dump and restore */ |
62 | | typedef struct _connParams |
63 | | { |
64 | | /* These fields record the actual command line parameters */ |
65 | | char *dbname; /* this may be a connstring! */ |
66 | | char *pgport; |
67 | | char *pghost; |
68 | | char *username; |
69 | | trivalue promptPassword; |
70 | | /* If not NULL, this overrides the dbname obtained from command line */ |
71 | | /* (but *only* the DB name, not anything else in the connstring) */ |
72 | | char *override_dbname; |
73 | | } ConnParams; |
74 | | |
75 | | typedef struct _restoreOptions |
76 | | { |
77 | | int createDB; /* Issue commands to create the database */ |
78 | | int noOwner; /* Don't try to match original object owner */ |
79 | | int noTablespace; /* Don't issue tablespace-related commands */ |
80 | | int disable_triggers; /* disable triggers during data-only |
81 | | * restore */ |
82 | | int use_setsessauth; /* Use SET SESSION AUTHORIZATION commands |
83 | | * instead of OWNER TO */ |
84 | | char *superuser; /* Username to use as superuser */ |
85 | | char *use_role; /* Issue SET ROLE to this */ |
86 | | int dropSchema; |
87 | | int disable_dollar_quoting; |
88 | | int dump_inserts; |
89 | | int column_inserts; |
90 | | int if_exists; |
91 | | int no_comments; /* Skip comments */ |
92 | | int no_publications; /* Skip publication entries */ |
93 | | int no_security_labels; /* Skip security label entries */ |
94 | | int no_subscriptions; /* Skip subscription entries */ |
95 | | int strict_names; |
96 | | |
97 | | const char *filename; |
98 | | int dataOnly; |
99 | | int schemaOnly; |
100 | | int dumpSections; |
101 | | int verbose; |
102 | | int aclsSkip; |
103 | | const char *lockWaitTimeout; |
104 | | int include_everything; |
105 | | |
106 | | int tocSummary; |
107 | | char *tocFile; |
108 | | int format; |
109 | | char *formatName; |
110 | | |
111 | | int selTypes; |
112 | | int selIndex; |
113 | | int selFunction; |
114 | | int selTrigger; |
115 | | int selTable; |
116 | | SimpleStringList indexNames; |
117 | | SimpleStringList functionNames; |
118 | | SimpleStringList schemaNames; |
119 | | SimpleStringList schemaExcludeNames; |
120 | | SimpleStringList triggerNames; |
121 | | SimpleStringList tableNames; |
122 | | |
123 | | int useDB; |
124 | | ConnParams cparams; /* parameters to use if useDB */ |
125 | | |
126 | | int noDataForFailedTables; |
127 | | int exit_on_error; |
128 | | int compression; |
129 | | int suppressDumpWarnings; /* Suppress output of WARNING entries |
130 | | * to stderr */ |
131 | | bool single_txn; |
132 | | |
133 | | bool *idWanted; /* array showing which dump IDs to emit */ |
134 | | int enable_row_security; |
135 | | int sequence_data; /* dump sequence data even in schema-only mode */ |
136 | | int binary_upgrade; |
137 | | } RestoreOptions; |
138 | | |
139 | | typedef struct _dumpOptions |
140 | | { |
141 | | ConnParams cparams; |
142 | | const char *master_hosts; /* YB Master hosts */ |
143 | | bool oids; |
144 | | |
145 | | int binary_upgrade; |
146 | | |
147 | | /* various user-settable parameters */ |
148 | | bool schemaOnly; |
149 | | bool dataOnly; |
150 | | int dumpSections; /* bitmask of chosen sections */ |
151 | | bool aclsSkip; |
152 | | const char *lockWaitTimeout; |
153 | | |
154 | | /* flags for various command-line long options */ |
155 | | int disable_dollar_quoting; |
156 | | int dump_inserts; |
157 | | int column_inserts; |
158 | | int if_exists; |
159 | | int no_comments; |
160 | | int no_security_labels; |
161 | | int no_publications; |
162 | | int no_subscriptions; |
163 | | int no_synchronized_snapshots; |
164 | | int no_unlogged_table_data; |
165 | | int no_tablegroups; |
166 | | int no_tablegroup_creations; |
167 | | int serializable_deferrable; |
168 | | int quote_all_identifiers; |
169 | | int disable_triggers; |
170 | | int outputNoTablespaces; |
171 | | int use_setsessauth; |
172 | | int enable_row_security; |
173 | | int load_via_partition_root; |
174 | | int include_yb_metadata; /* In this mode DDL statements include YB specific |
175 | | * metadata such as tablet partitions. */ |
176 | | /* default, if no "inclusion" switches appear, is to dump everything */ |
177 | | bool include_everything; |
178 | | |
179 | | int outputClean; |
180 | | int outputCreateDB; |
181 | | bool outputBlobs; |
182 | | bool dontOutputBlobs; |
183 | | int outputNoOwner; |
184 | | char *outputSuperuser; |
185 | | |
186 | | int sequence_data; /* dump sequence data even in schema-only mode */ |
187 | | |
188 | | Oid db_oid; /* initiated only if include-yb-metadata flag is set */ |
189 | | } DumpOptions; |
190 | | |
191 | | /* |
192 | | * We may want to have some more user-readable data, but in the mean |
193 | | * time this gives us some abstraction and type checking. |
194 | | */ |
195 | | typedef struct Archive |
196 | | { |
197 | | DumpOptions *dopt; /* options, if dumping */ |
198 | | RestoreOptions *ropt; /* options, if restoring */ |
199 | | |
200 | | int verbose; |
201 | | char *remoteVersionStr; /* server's version string */ |
202 | | int remoteVersion; /* same in numeric form */ |
203 | | bool isStandby; /* is server a standby node */ |
204 | | |
205 | | int minRemoteVersion; /* allowable range */ |
206 | | int maxRemoteVersion; |
207 | | |
208 | | int numWorkers; /* number of parallel processes */ |
209 | | char *sync_snapshot_id; /* sync snapshot id for parallel operation */ |
210 | | |
211 | | /* info needed for string escaping */ |
212 | | int encoding; /* libpq code for client_encoding */ |
213 | | bool std_strings; /* standard_conforming_strings */ |
214 | | |
215 | | /* other important stuff */ |
216 | | char *searchpath; /* search_path to set during restore */ |
217 | | char *use_role; /* Issue SET ROLE to this */ |
218 | | |
219 | | /* error handling */ |
220 | | bool exit_on_error; /* whether to exit on SQL errors... */ |
221 | | int n_errors; /* number of errors (if no die) */ |
222 | | |
223 | | /* The rest is private */ |
224 | | } Archive; |
225 | | |
226 | | |
227 | | /* |
228 | | * pg_dump uses two different mechanisms for identifying database objects: |
229 | | * |
230 | | * CatalogId represents an object by the tableoid and oid of its defining |
231 | | * entry in the system catalogs. We need this to interpret pg_depend entries, |
232 | | * for instance. |
233 | | * |
234 | | * DumpId is a simple sequential integer counter assigned as dumpable objects |
235 | | * are identified during a pg_dump run. We use DumpId internally in preference |
236 | | * to CatalogId for two reasons: it's more compact, and we can assign DumpIds |
237 | | * to "objects" that don't have a separate CatalogId. For example, it is |
238 | | * convenient to consider a table, its data, and its ACL as three separate |
239 | | * dumpable "objects" with distinct DumpIds --- this lets us reason about the |
240 | | * order in which to dump these things. |
241 | | */ |
242 | | |
243 | | typedef struct |
244 | | { |
245 | | Oid tableoid; |
246 | | Oid oid; |
247 | | } CatalogId; |
248 | | |
249 | | typedef int DumpId; |
250 | | |
251 | | typedef int (*DataDumperPtr) (Archive *AH, void *userArg); |
252 | | |
253 | | typedef void (*SetupWorkerPtrType) (Archive *AH); |
254 | | |
255 | | /* |
256 | | * Main archiver interface. |
257 | | */ |
258 | | |
259 | | extern void ConnectDatabase(Archive *AHX, |
260 | | const ConnParams *cparams, |
261 | | bool isReconnect); |
262 | | extern void DisconnectDatabase(Archive *AHX); |
263 | | extern PGconn *GetConnection(Archive *AHX); |
264 | | |
265 | | /* Called to add a TOC entry */ |
266 | | extern void ArchiveEntry(Archive *AHX, |
267 | | CatalogId catalogId, DumpId dumpId, |
268 | | const char *tag, |
269 | | const char *namespace, const char *tablespace, |
270 | | const char *owner, bool withOids, |
271 | | const char *desc, teSection section, |
272 | | const char *defn, |
273 | | const char *dropStmt, const char *copyStmt, |
274 | | const DumpId *deps, int nDeps, |
275 | | DataDumperPtr dumpFn, void *dumpArg); |
276 | | |
277 | | /* Called to write *data* to the archive */ |
278 | | extern void WriteData(Archive *AH, const void *data, size_t dLen); |
279 | | |
280 | | extern int StartBlob(Archive *AH, Oid oid); |
281 | | extern int EndBlob(Archive *AH, Oid oid); |
282 | | |
283 | | extern void CloseArchive(Archive *AH); |
284 | | |
285 | | extern void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt); |
286 | | |
287 | | extern void ProcessArchiveRestoreOptions(Archive *AH); |
288 | | |
289 | | extern void RestoreArchive(Archive *AH); |
290 | | |
291 | | /* Open an existing archive */ |
292 | | extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt); |
293 | | |
294 | | /* Create a new archive */ |
295 | | extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt, |
296 | | const int compression, bool dosync, ArchiveMode mode, |
297 | | SetupWorkerPtrType setupDumpWorker); |
298 | | |
299 | | /* The --list option */ |
300 | | extern void PrintTOCSummary(Archive *AH); |
301 | | |
302 | | extern RestoreOptions *NewRestoreOptions(void); |
303 | | |
304 | | extern DumpOptions *NewDumpOptions(void); |
305 | | extern void InitDumpOptions(DumpOptions *opts); |
306 | | extern DumpOptions *dumpOptionsFromRestoreOptions(RestoreOptions *ropt); |
307 | | |
308 | | /* Rearrange and filter TOC entries */ |
309 | | extern void SortTocFromFile(Archive *AHX); |
310 | | |
311 | | /* Convenience functions used only when writing DATA */ |
312 | | extern void archputs(const char *s, Archive *AH); |
313 | | extern int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2, 3); |
314 | | |
315 | | #define appendStringLiteralAH(buf,str,AH) \ |
316 | 0 | appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings) |
317 | | |
318 | | #endif /* PG_BACKUP_H */ |