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 its 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
30typedef enum trivalue
31{
32 TRI_DEFAULT,
33 TRI_NO,
34 TRI_YES
35} trivalue;
36
37typedef enum _archiveFormat
38{
39 archUnknown = 0,
40 archCustom = 1,
41 archTar = 3,
42 archNull = 4,
43 archDirectory = 5
44} ArchiveFormat;
45
46typedef enum _archiveMode
47{
48 archModeAppend,
49 archModeWrite,
50 archModeRead
51} ArchiveMode;
52
53typedef 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
61typedef struct _restoreOptions
62{
63 int createDB; /* Issue commands to create the database */
64 int noOwner; /* Don't try to match original object owner */
65 int noTablespace; /* Don't issue tablespace-related commands */
66 int disable_triggers; /* disable triggers during data-only
67 * restore */
68 int use_setsessauth; /* Use SET SESSION AUTHORIZATION commands
69 * instead of OWNER TO */
70 char *superuser; /* Username to use as superuser */
71 char *use_role; /* Issue SET ROLE to this */
72 int dropSchema;
73 int disable_dollar_quoting;
74 int dump_inserts;
75 int column_inserts;
76 int if_exists;
77 int no_comments; /* Skip comments */
78 int no_publications; /* Skip publication entries */
79 int no_security_labels; /* Skip security label entries */
80 int no_subscriptions; /* Skip subscription entries */
81 int strict_names;
82
83 const char *filename;
84 int dataOnly;
85 int schemaOnly;
86 int dumpSections;
87 int verbose;
88 int aclsSkip;
89 const char *lockWaitTimeout;
90 int include_everything;
91
92 int tocSummary;
93 char *tocFile;
94 int format;
95 char *formatName;
96
97 int selTypes;
98 int selIndex;
99 int selFunction;
100 int selTrigger;
101 int selTable;
102 SimpleStringList indexNames;
103 SimpleStringList functionNames;
104 SimpleStringList schemaNames;
105 SimpleStringList schemaExcludeNames;
106 SimpleStringList triggerNames;
107 SimpleStringList tableNames;
108
109 int useDB;
110 char *dbname; /* subject to expand_dbname */
111 char *pgport;
112 char *pghost;
113 char *username;
114 int noDataForFailedTables;
115 trivalue promptPassword;
116 int exit_on_error;
117 int compression;
118 int suppressDumpWarnings; /* Suppress output of WARNING entries
119 * to stderr */
120 bool single_txn;
121
122 bool *idWanted; /* array showing which dump IDs to emit */
123 int enable_row_security;
124 int sequence_data; /* dump sequence data even in schema-only mode */
125 int binary_upgrade;
126} RestoreOptions;
127
128typedef struct _dumpOptions
129{
130 const char *dbname; /* subject to expand_dbname */
131 const char *pghost;
132 const char *pgport;
133 const char *username;
134
135 int binary_upgrade;
136
137 /* various user-settable parameters */
138 bool schemaOnly;
139 bool dataOnly;
140 int dumpSections; /* bitmask of chosen sections */
141 bool aclsSkip;
142 const char *lockWaitTimeout;
143 int dump_inserts; /* 0 = COPY, otherwise rows per INSERT */
144
145 /* flags for various command-line long options */
146 int disable_dollar_quoting;
147 int column_inserts;
148 int if_exists;
149 int no_comments;
150 int no_security_labels;
151 int no_publications;
152 int no_subscriptions;
153 int no_synchronized_snapshots;
154 int no_unlogged_table_data;
155 int serializable_deferrable;
156 int quote_all_identifiers;
157 int disable_triggers;
158 int outputNoTablespaces;
159 int use_setsessauth;
160 int enable_row_security;
161 int load_via_partition_root;
162
163 /* default, if no "inclusion" switches appear, is to dump everything */
164 bool include_everything;
165
166 int outputClean;
167 int outputCreateDB;
168 bool outputBlobs;
169 bool dontOutputBlobs;
170 int outputNoOwner;
171 char *outputSuperuser;
172
173 int sequence_data; /* dump sequence data even in schema-only mode */
174 int do_nothing;
175} DumpOptions;
176
177/*
178 * We may want to have some more user-readable data, but in the mean
179 * time this gives us some abstraction and type checking.
180 */
181typedef struct Archive
182{
183 DumpOptions *dopt; /* options, if dumping */
184 RestoreOptions *ropt; /* options, if restoring */
185
186 int verbose;
187 char *remoteVersionStr; /* server's version string */
188 int remoteVersion; /* same in numeric form */
189 bool isStandby; /* is server a standby node */
190
191 int minRemoteVersion; /* allowable range */
192 int maxRemoteVersion;
193
194 int numWorkers; /* number of parallel processes */
195 char *sync_snapshot_id; /* sync snapshot id for parallel operation */
196
197 /* info needed for string escaping */
198 int encoding; /* libpq code for client_encoding */
199 bool std_strings; /* standard_conforming_strings */
200
201 /* other important stuff */
202 char *searchpath; /* search_path to set during restore */
203 char *use_role; /* Issue SET ROLE to this */
204
205 /* error handling */
206 bool exit_on_error; /* whether to exit on SQL errors... */
207 int n_errors; /* number of errors (if no die) */
208
209 /* The rest is private */
210} Archive;
211
212
213/*
214 * pg_dump uses two different mechanisms for identifying database objects:
215 *
216 * CatalogId represents an object by the tableoid and oid of its defining
217 * entry in the system catalogs. We need this to interpret pg_depend entries,
218 * for instance.
219 *
220 * DumpId is a simple sequential integer counter assigned as dumpable objects
221 * are identified during a pg_dump run. We use DumpId internally in preference
222 * to CatalogId for two reasons: it's more compact, and we can assign DumpIds
223 * to "objects" that don't have a separate CatalogId. For example, it is
224 * convenient to consider a table, its data, and its ACL as three separate
225 * dumpable "objects" with distinct DumpIds --- this lets us reason about the
226 * order in which to dump these things.
227 */
228
229typedef struct
230{
231 Oid tableoid;
232 Oid oid;
233} CatalogId;
234
235typedef int DumpId;
236
237typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
238
239typedef void (*SetupWorkerPtrType) (Archive *AH);
240
241/*
242 * Main archiver interface.
243 */
244
245extern void ConnectDatabase(Archive *AH,
246 const char *dbname,
247 const char *pghost,
248 const char *pgport,
249 const char *username,
250 trivalue prompt_password);
251extern void DisconnectDatabase(Archive *AHX);
252extern PGconn *GetConnection(Archive *AHX);
253
254/* Called to write *data* to the archive */
255extern void WriteData(Archive *AH, const void *data, size_t dLen);
256
257extern int StartBlob(Archive *AH, Oid oid);
258extern int EndBlob(Archive *AH, Oid oid);
259
260extern void CloseArchive(Archive *AH);
261
262extern void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt);
263
264extern void ProcessArchiveRestoreOptions(Archive *AH);
265
266extern void RestoreArchive(Archive *AH);
267
268/* Open an existing archive */
269extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
270
271/* Create a new archive */
272extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
273 const int compression, bool dosync, ArchiveMode mode,
274 SetupWorkerPtrType setupDumpWorker);
275
276/* The --list option */
277extern void PrintTOCSummary(Archive *AH);
278
279extern RestoreOptions *NewRestoreOptions(void);
280
281extern DumpOptions *NewDumpOptions(void);
282extern void InitDumpOptions(DumpOptions *opts);
283extern DumpOptions *dumpOptionsFromRestoreOptions(RestoreOptions *ropt);
284
285/* Rearrange and filter TOC entries */
286extern void SortTocFromFile(Archive *AHX);
287
288/* Convenience functions used only when writing DATA */
289extern void archputs(const char *s, Archive *AH);
290extern int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2, 3);
291
292#define appendStringLiteralAH(buf,str,AH) \
293 appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
294
295#endif /* PG_BACKUP_H */
296