Move routines to manipulate WAL into PostgreSQL::Test::Cluster
[pgsql.git] / src / bin / pg_dump / pg_backup.h
blobf0f19bb0b291b159194d72c566c33a4eee2f0acc
1 /*-------------------------------------------------------------------------
3 * pg_backup.h
5 * Public interface to the pg_dump archiver routines.
7 * See the headers to pg_restore for more details.
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.
13 * The author is not responsible for loss or damages that may
14 * result from its use.
17 * IDENTIFICATION
18 * src/bin/pg_dump/pg_backup.h
20 *-------------------------------------------------------------------------
23 #ifndef PG_BACKUP_H
24 #define PG_BACKUP_H
26 #include "common/compression.h"
27 #include "common/file_utils.h"
28 #include "fe_utils/simple_list.h"
29 #include "libpq-fe.h"
32 typedef enum trivalue
34 TRI_DEFAULT,
35 TRI_NO,
36 TRI_YES,
37 } trivalue;
39 typedef enum _archiveFormat
41 archUnknown = 0,
42 archCustom = 1,
43 archTar = 3,
44 archNull = 4,
45 archDirectory = 5,
46 } ArchiveFormat;
48 typedef enum _archiveMode
50 archModeAppend,
51 archModeWrite,
52 archModeRead,
53 } ArchiveMode;
55 typedef enum _teSection
57 SECTION_NONE = 1, /* comments, ACLs, etc; can be anywhere */
58 SECTION_PRE_DATA, /* stuff to be processed before data */
59 SECTION_DATA, /* table data, large objects, LO comments */
60 SECTION_POST_DATA, /* stuff to be processed after data */
61 } teSection;
63 /* We need one enum entry per prepared query in pg_dump */
64 enum _dumpPreparedQueries
66 PREPQUERY_DUMPAGG,
67 PREPQUERY_DUMPBASETYPE,
68 PREPQUERY_DUMPCOMPOSITETYPE,
69 PREPQUERY_DUMPDOMAIN,
70 PREPQUERY_DUMPENUMTYPE,
71 PREPQUERY_DUMPFUNC,
72 PREPQUERY_DUMPOPR,
73 PREPQUERY_DUMPRANGETYPE,
74 PREPQUERY_DUMPTABLEATTACH,
75 PREPQUERY_GETCOLUMNACLS,
76 PREPQUERY_GETDOMAINCONSTRAINTS,
79 #define NUM_PREP_QUERIES (PREPQUERY_GETDOMAINCONSTRAINTS + 1)
81 /* Parameters needed by ConnectDatabase; same for dump and restore */
82 typedef struct _connParams
84 /* These fields record the actual command line parameters */
85 char *dbname; /* this may be a connstring! */
86 char *pgport;
87 char *pghost;
88 char *username;
89 trivalue promptPassword;
90 /* If not NULL, this overrides the dbname obtained from command line */
91 /* (but *only* the DB name, not anything else in the connstring) */
92 char *override_dbname;
93 } ConnParams;
95 typedef struct _restoreOptions
97 int createDB; /* Issue commands to create the database */
98 int noOwner; /* Don't try to match original object owner */
99 int noTableAm; /* Don't issue table-AM-related commands */
100 int noTablespace; /* Don't issue tablespace-related commands */
101 int disable_triggers; /* disable triggers during data-only
102 * restore */
103 int use_setsessauth; /* Use SET SESSION AUTHORIZATION commands
104 * instead of OWNER TO */
105 char *superuser; /* Username to use as superuser */
106 char *use_role; /* Issue SET ROLE to this */
107 int dropSchema;
108 int disable_dollar_quoting;
109 int dump_inserts; /* 0 = COPY, otherwise rows per INSERT */
110 int column_inserts;
111 int if_exists;
112 int no_comments; /* Skip comments */
113 int no_publications; /* Skip publication entries */
114 int no_security_labels; /* Skip security label entries */
115 int no_subscriptions; /* Skip subscription entries */
116 int strict_names;
118 const char *filename;
119 int dumpSections;
120 int verbose;
121 int aclsSkip;
122 const char *lockWaitTimeout;
123 int include_everything;
125 int tocSummary;
126 char *tocFile;
127 int format;
128 char *formatName;
130 int selTypes;
131 int selIndex;
132 int selFunction;
133 int selTrigger;
134 int selTable;
135 SimpleStringList indexNames;
136 SimpleStringList functionNames;
137 SimpleStringList schemaNames;
138 SimpleStringList schemaExcludeNames;
139 SimpleStringList triggerNames;
140 SimpleStringList tableNames;
142 int useDB;
143 ConnParams cparams; /* parameters to use if useDB */
145 int noDataForFailedTables;
146 int exit_on_error;
147 pg_compress_specification compression_spec; /* Specification for
148 * compression */
149 int suppressDumpWarnings; /* Suppress output of WARNING entries
150 * to stderr */
152 bool single_txn; /* restore all TOCs in one transaction */
153 int txn_size; /* restore this many TOCs per txn, if > 0 */
155 bool *idWanted; /* array showing which dump IDs to emit */
156 int enable_row_security;
157 int sequence_data; /* dump sequence data even in schema-only mode */
158 int binary_upgrade;
160 /* flags derived from the user-settable flags */
161 bool dumpSchema;
162 bool dumpData;
163 } RestoreOptions;
165 typedef struct _dumpOptions
167 ConnParams cparams;
169 int binary_upgrade;
171 /* various user-settable parameters */
172 int dumpSections; /* bitmask of chosen sections */
173 bool aclsSkip;
174 const char *lockWaitTimeout;
175 int dump_inserts; /* 0 = COPY, otherwise rows per INSERT */
177 /* flags for various command-line long options */
178 int disable_dollar_quoting;
179 int column_inserts;
180 int if_exists;
181 int no_comments;
182 int no_security_labels;
183 int no_publications;
184 int no_subscriptions;
185 int no_toast_compression;
186 int no_unlogged_table_data;
187 int serializable_deferrable;
188 int disable_triggers;
189 int outputNoTableAm;
190 int outputNoTablespaces;
191 int use_setsessauth;
192 int enable_row_security;
193 int load_via_partition_root;
195 /* default, if no "inclusion" switches appear, is to dump everything */
196 bool include_everything;
198 int outputClean;
199 int outputCreateDB;
200 bool outputLOs;
201 bool dontOutputLOs;
202 int outputNoOwner;
203 char *outputSuperuser;
205 int sequence_data; /* dump sequence data even in schema-only mode */
206 int do_nothing;
208 /* flags derived from the user-settable flags */
209 bool dumpSchema;
210 bool dumpData;
211 } DumpOptions;
214 * We may want to have some more user-readable data, but in the mean
215 * time this gives us some abstraction and type checking.
217 typedef struct Archive
219 DumpOptions *dopt; /* options, if dumping */
220 RestoreOptions *ropt; /* options, if restoring */
222 int verbose;
223 char *remoteVersionStr; /* server's version string */
224 int remoteVersion; /* same in numeric form */
225 bool isStandby; /* is server a standby node */
227 int minRemoteVersion; /* allowable range */
228 int maxRemoteVersion;
230 int numWorkers; /* number of parallel processes */
231 char *sync_snapshot_id; /* sync snapshot id for parallel operation */
233 /* info needed for string escaping */
234 int encoding; /* libpq code for client_encoding */
235 bool std_strings; /* standard_conforming_strings */
237 /* other important stuff */
238 char *searchpath; /* search_path to set during restore */
239 char *use_role; /* Issue SET ROLE to this */
241 /* error handling */
242 bool exit_on_error; /* whether to exit on SQL errors... */
243 int n_errors; /* number of errors (if no die) */
245 /* prepared-query status */
246 bool *is_prepared; /* indexed by enum _dumpPreparedQueries */
248 /* The rest is private */
249 } Archive;
253 * pg_dump uses two different mechanisms for identifying database objects:
255 * CatalogId represents an object by the tableoid and oid of its defining
256 * entry in the system catalogs. We need this to interpret pg_depend entries,
257 * for instance.
259 * DumpId is a simple sequential integer counter assigned as dumpable objects
260 * are identified during a pg_dump run. We use DumpId internally in preference
261 * to CatalogId for two reasons: it's more compact, and we can assign DumpIds
262 * to "objects" that don't have a separate CatalogId. For example, it is
263 * convenient to consider a table, its data, and its ACL as three separate
264 * dumpable "objects" with distinct DumpIds --- this lets us reason about the
265 * order in which to dump these things.
268 typedef struct
270 /* Note: this struct must not contain any unused bytes */
271 Oid tableoid;
272 Oid oid;
273 } CatalogId;
275 typedef int DumpId;
277 #define InvalidDumpId 0
280 * Function pointer prototypes for assorted callback methods.
283 typedef int (*DataDumperPtr) (Archive *AH, const void *userArg);
285 typedef void (*SetupWorkerPtrType) (Archive *AH);
288 * Main archiver interface.
291 extern void ConnectDatabase(Archive *AHX,
292 const ConnParams *cparams,
293 bool isReconnect);
294 extern void DisconnectDatabase(Archive *AHX);
295 extern PGconn *GetConnection(Archive *AHX);
297 /* Called to write *data* to the archive */
298 extern void WriteData(Archive *AHX, const void *data, size_t dLen);
300 extern int StartLO(Archive *AHX, Oid oid);
301 extern int EndLO(Archive *AHX, Oid oid);
303 extern void CloseArchive(Archive *AHX);
305 extern void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt);
307 extern void ProcessArchiveRestoreOptions(Archive *AHX);
309 extern void RestoreArchive(Archive *AHX);
311 /* Open an existing archive */
312 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
314 /* Create a new archive */
315 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
316 const pg_compress_specification compression_spec,
317 bool dosync, ArchiveMode mode,
318 SetupWorkerPtrType setupDumpWorker,
319 DataDirSyncMethod sync_method);
321 /* The --list option */
322 extern void PrintTOCSummary(Archive *AHX);
324 extern RestoreOptions *NewRestoreOptions(void);
326 extern DumpOptions *NewDumpOptions(void);
327 extern void InitDumpOptions(DumpOptions *opts);
328 extern DumpOptions *dumpOptionsFromRestoreOptions(RestoreOptions *ropt);
330 /* Rearrange and filter TOC entries */
331 extern void SortTocFromFile(Archive *AHX);
333 /* Convenience functions used only when writing DATA */
334 extern void archputs(const char *s, Archive *AH);
335 extern int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2, 3);
337 #define appendStringLiteralAH(buf,str,AH) \
338 appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
340 #endif /* PG_BACKUP_H */