PostgreSQL Source Code  git master
pg_backup.h
Go to the documentation of this file.
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 
30 typedef enum trivalue
31 {
35 } trivalue;
36 
37 typedef enum _archiveFormat
38 {
41  archTar = 3,
42  archNull = 4,
45 
46 typedef enum _archiveMode
47 {
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;
70  /* If not NULL, this overrides the dbname obtained from command line */
71  /* (but *only* the DB name, not anything else in the connstring) */
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 */
88  int dump_inserts; /* 0 = COPY, otherwise rows per INSERT */
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 */
96 
97  const char *filename;
98  int dataOnly;
101  int verbose;
102  int aclsSkip;
103  const char *lockWaitTimeout;
105 
107  char *tocFile;
108  int format;
109  char *formatName;
110 
111  int selTypes;
112  int selIndex;
115  int selTable;
122 
123  int useDB;
124  ConnParams cparams; /* parameters to use if useDB */
125 
129  int suppressDumpWarnings; /* Suppress output of WARNING entries
130  * to stderr */
132 
133  bool *idWanted; /* array showing which dump IDs to emit */
135  int sequence_data; /* dump sequence data even in schema-only mode */
138 
139 typedef struct _dumpOptions
140 {
142 
144 
145  /* various user-settable parameters */
147  bool dataOnly;
148  int dumpSections; /* bitmask of chosen sections */
149  bool aclsSkip;
150  const char *lockWaitTimeout;
151  int dump_inserts; /* 0 = COPY, otherwise rows per INSERT */
152 
153  /* flags for various command-line long options */
170 
171  /* default, if no "inclusion" switches appear, is to dump everything */
173 
180 
181  int sequence_data; /* dump sequence data even in schema-only mode */
183 } DumpOptions;
184 
185 /*
186  * We may want to have some more user-readable data, but in the mean
187  * time this gives us some abstraction and type checking.
188  */
189 typedef struct Archive
190 {
191  DumpOptions *dopt; /* options, if dumping */
192  RestoreOptions *ropt; /* options, if restoring */
193 
194  int verbose;
195  char *remoteVersionStr; /* server's version string */
196  int remoteVersion; /* same in numeric form */
197  bool isStandby; /* is server a standby node */
198 
199  int minRemoteVersion; /* allowable range */
201 
202  int numWorkers; /* number of parallel processes */
203  char *sync_snapshot_id; /* sync snapshot id for parallel operation */
204 
205  /* info needed for string escaping */
206  int encoding; /* libpq code for client_encoding */
207  bool std_strings; /* standard_conforming_strings */
208 
209  /* other important stuff */
210  char *searchpath; /* search_path to set during restore */
211  char *default_toast_compression; /* default TOAST compression to
212  * set during restore */
213  char *use_role; /* Issue SET ROLE to this */
214 
215  /* error handling */
216  bool exit_on_error; /* whether to exit on SQL errors... */
217  int n_errors; /* number of errors (if no die) */
218 
219  /* The rest is private */
220 } Archive;
221 
222 
223 /*
224  * pg_dump uses two different mechanisms for identifying database objects:
225  *
226  * CatalogId represents an object by the tableoid and oid of its defining
227  * entry in the system catalogs. We need this to interpret pg_depend entries,
228  * for instance.
229  *
230  * DumpId is a simple sequential integer counter assigned as dumpable objects
231  * are identified during a pg_dump run. We use DumpId internally in preference
232  * to CatalogId for two reasons: it's more compact, and we can assign DumpIds
233  * to "objects" that don't have a separate CatalogId. For example, it is
234  * convenient to consider a table, its data, and its ACL as three separate
235  * dumpable "objects" with distinct DumpIds --- this lets us reason about the
236  * order in which to dump these things.
237  */
238 
239 typedef struct
240 {
243 } CatalogId;
244 
245 typedef int DumpId;
246 
247 #define InvalidDumpId 0
248 
249 /*
250  * Function pointer prototypes for assorted callback methods.
251  */
252 
253 typedef int (*DataDumperPtr) (Archive *AH, const void *userArg);
254 
255 typedef void (*SetupWorkerPtrType) (Archive *AH);
256 
257 /*
258  * Main archiver interface.
259  */
260 
261 extern void ConnectDatabase(Archive *AHX,
262  const ConnParams *cparams,
263  bool isReconnect);
264 extern void DisconnectDatabase(Archive *AHX);
265 extern PGconn *GetConnection(Archive *AHX);
266 
267 /* Called to write *data* to the archive */
268 extern void WriteData(Archive *AH, const void *data, size_t dLen);
269 
270 extern int StartBlob(Archive *AH, Oid oid);
271 extern int EndBlob(Archive *AH, Oid oid);
272 
273 extern void CloseArchive(Archive *AH);
274 
275 extern void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt);
276 
277 extern void ProcessArchiveRestoreOptions(Archive *AH);
278 
279 extern void RestoreArchive(Archive *AH);
280 
281 /* Open an existing archive */
282 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
283 
284 /* Create a new archive */
285 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
286  const int compression, bool dosync, ArchiveMode mode,
288 
289 /* The --list option */
290 extern void PrintTOCSummary(Archive *AH);
291 
292 extern RestoreOptions *NewRestoreOptions(void);
293 
294 extern DumpOptions *NewDumpOptions(void);
295 extern void InitDumpOptions(DumpOptions *opts);
297 
298 /* Rearrange and filter TOC entries */
299 extern void SortTocFromFile(Archive *AHX);
300 
301 /* Convenience functions used only when writing DATA */
302 extern void archputs(const char *s, Archive *AH);
303 extern int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2, 3);
304 
305 #define appendStringLiteralAH(buf,str,AH) \
306  appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
307 
308 #endif /* PG_BACKUP_H */
int column_inserts
Definition: pg_backup.h:155
static PgChecksumMode mode
Definition: pg_checksums.c:61
int disable_triggers
Definition: pg_backup.h:165
int DumpId
Definition: pg_backup.h:245
void ConnectDatabase(Archive *AHX, const ConnParams *cparams, bool isReconnect)
Definition: pg_backup_db.c:114
int noDataForFailedTables
Definition: pg_backup.h:126
struct _restoreOptions RestoreOptions
DumpOptions * NewDumpOptions(void)
int disable_dollar_quoting
Definition: pg_backup.h:87
_archiveFormat
Definition: pg_backup.h:37
Oid tableoid
Definition: pg_backup.h:241
char * use_role
Definition: pg_backup.h:213
char * pgport
Definition: pg_backup.h:66
SimpleStringList triggerNames
Definition: pg_backup.h:120
RestoreOptions * ropt
Definition: pg_backup.h:192
bool schemaOnly
Definition: pg_backup.h:146
int no_subscriptions
Definition: pg_backup.h:160
int no_publications
Definition: pg_backup.h:159
Archive * OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
enum _archiveMode ArchiveMode
static bool dosync
Definition: pg_dump.c:91
Archive * CreateArchive(const char *FileSpec, const ArchiveFormat fmt, const int compression, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupDumpWorker)
struct _connParams ConnParams
char * use_role
Definition: pg_backup.h:85
SimpleStringList schemaNames
Definition: pg_backup.h:118
int n_errors
Definition: pg_backup.h:217
int sequence_data
Definition: pg_backup.h:181
unsigned int Oid
Definition: postgres_ext.h:31
int encoding
Definition: pg_backup.h:206
_teSection
Definition: pg_backup.h:53
char * formatName
Definition: pg_backup.h:109
RestoreOptions * NewRestoreOptions(void)
int maxRemoteVersion
Definition: pg_backup.h:200
#define pg_attribute_printf(f, a)
Definition: c.h:164
char * sync_snapshot_id
Definition: pg_backup.h:203
trivalue promptPassword
Definition: pg_backup.h:69
char * dbname
Definition: pg_backup.h:65
const char * lockWaitTimeout
Definition: pg_backup.h:103
trivalue
Definition: pg_backup.h:30
bool isStandby
Definition: pg_backup.h:197
int use_setsessauth
Definition: pg_backup.h:167
const char * filename
Definition: pg_backup.h:97
int disable_dollar_quoting
Definition: pg_backup.h:154
int no_toast_compression
Definition: pg_backup.h:162
bool * idWanted
Definition: pg_backup.h:133
int StartBlob(Archive *AH, Oid oid)
int binary_upgrade
Definition: pg_backup.h:143
DumpOptions * dopt
Definition: pg_backup.h:191
int column_inserts
Definition: pg_backup.h:89
const char * lockWaitTimeout
Definition: pg_backup.h:150
int(* DataDumperPtr)(Archive *AH, const void *userArg)
Definition: pg_backup.h:253
bool dataOnly
Definition: pg_backup.h:147
bool include_everything
Definition: pg_backup.h:172
SimpleStringList tableNames
Definition: pg_backup.h:121
void WriteData(Archive *AH, const void *data, size_t dLen)
char * outputSuperuser
Definition: pg_backup.h:179
int no_unlogged_table_data
Definition: pg_backup.h:163
int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2
SimpleStringList functionNames
Definition: pg_backup.h:117
ConnParams cparams
Definition: pg_backup.h:141
struct Archive Archive
void InitDumpOptions(DumpOptions *opts)
void PrintTOCSummary(Archive *AH)
int include_everything
Definition: pg_backup.h:104
void CloseArchive(Archive *AH)
int no_security_labels
Definition: pg_backup.h:93
bool outputBlobs
Definition: pg_backup.h:176
int dumpSections
Definition: pg_backup.h:148
int enable_row_security
Definition: pg_backup.h:134
DumpOptions * dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
int dump_inserts
Definition: pg_backup.h:151
int outputNoOwner
Definition: pg_backup.h:178
char * override_dbname
Definition: pg_backup.h:72
ConnParams cparams
Definition: pg_backup.h:124
void DisconnectDatabase(Archive *AHX)
Definition: pg_backup_db.c:230
static AmcheckOptions opts
Definition: pg_amcheck.c:110
int no_security_labels
Definition: pg_backup.h:158
char * pghost
Definition: pg_backup.h:67
char * username
Definition: pg_backup.h:68
int no_subscriptions
Definition: pg_backup.h:94
trivalue
Definition: vacuumlo.c:34
char * superuser
Definition: pg_backup.h:84
char * default_toast_compression
Definition: pg_backup.h:211
bool aclsSkip
Definition: pg_backup.h:149
int use_setsessauth
Definition: pg_backup.h:82
int verbose
Definition: pg_backup.h:194
PGconn * GetConnection(Archive *AHX)
Definition: pg_backup_db.c:259
char * searchpath
Definition: pg_backup.h:210
_archiveMode
Definition: pg_backup.h:46
int enable_row_security
Definition: pg_backup.h:168
enum _archiveFormat ArchiveFormat
enum _teSection teSection
int outputCreateDB
Definition: pg_backup.h:175
ArchiveMode
Definition: xlog.h:154
int outputClean
Definition: pg_backup.h:174
struct _dumpOptions DumpOptions
int no_comments
Definition: pg_backup.h:157
int numWorkers
Definition: pg_backup.h:202
void SortTocFromFile(Archive *AHX)
SimpleStringList indexNames
Definition: pg_backup.h:116
int outputNoTablespaces
Definition: pg_backup.h:166
char * remoteVersionStr
Definition: pg_backup.h:195
int EndBlob(Archive *AH, Oid oid)
int no_publications
Definition: pg_backup.h:92
void RestoreArchive(Archive *AH)
bool exit_on_error
Definition: pg_backup.h:216
void ProcessArchiveRestoreOptions(Archive *AH)
int no_synchronized_snapshots
Definition: pg_backup.h:161
bool dontOutputBlobs
Definition: pg_backup.h:177
int suppressDumpWarnings
Definition: pg_backup.h:129
int do_nothing
Definition: pg_backup.h:182
SimpleStringList schemaExcludeNames
Definition: pg_backup.h:119
void(* SetupWorkerPtrType)(Archive *AH)
Definition: pg_backup.h:255
static void setupDumpWorker(Archive *AHX)
Definition: pg_dump.c:1275
int serializable_deferrable
Definition: pg_backup.h:164
char * tocFile
Definition: pg_backup.h:107
void archputs(const char *s, Archive *AH)
bool std_strings
Definition: pg_backup.h:207
int load_via_partition_root
Definition: pg_backup.h:169
int disable_triggers
Definition: pg_backup.h:80
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
int remoteVersion
Definition: pg_backup.h:196
int minRemoteVersion
Definition: pg_backup.h:199