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 "common/compression.h"
27 #include "common/file_utils.h"
28 #include "fe_utils/simple_list.h"
29 #include "libpq-fe.h"
30 
31 
32 typedef enum trivalue
33 {
38 
39 typedef enum _archiveFormat
40 {
43  archTar = 3,
44  archNull = 4,
47 
48 typedef enum _archiveMode
49 {
54 
55 typedef enum _teSection
56 {
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 */
62 
63 /* We need one enum entry per prepared query in pg_dump */
65 {
77  NUM_PREP_QUERIES /* must be last */
78 };
79 
80 /* Parameters needed by ConnectDatabase; same for dump and restore */
81 typedef struct _connParams
82 {
83  /* These fields record the actual command line parameters */
84  char *dbname; /* this may be a connstring! */
85  char *pgport;
86  char *pghost;
87  char *username;
89  /* If not NULL, this overrides the dbname obtained from command line */
90  /* (but *only* the DB name, not anything else in the connstring) */
93 
94 typedef struct _restoreOptions
95 {
96  int createDB; /* Issue commands to create the database */
97  int noOwner; /* Don't try to match original object owner */
98  int noTableAm; /* Don't issue table-AM-related commands */
99  int noTablespace; /* Don't issue tablespace-related commands */
100  int disable_triggers; /* disable triggers during data-only
101  * restore */
102  int use_setsessauth; /* Use SET SESSION AUTHORIZATION commands
103  * instead of OWNER TO */
104  char *superuser; /* Username to use as superuser */
105  char *use_role; /* Issue SET ROLE to this */
108  int dump_inserts; /* 0 = COPY, otherwise rows per INSERT */
111  int no_comments; /* Skip comments */
112  int no_publications; /* Skip publication entries */
113  int no_security_labels; /* Skip security label entries */
114  int no_subscriptions; /* Skip subscription entries */
116 
117  const char *filename;
118  int dataOnly;
121  int verbose;
122  int aclsSkip;
123  const char *lockWaitTimeout;
125 
127  char *tocFile;
128  int format;
129  char *formatName;
130 
131  int selTypes;
132  int selIndex;
135  int selTable;
142 
143  int useDB;
144  ConnParams cparams; /* parameters to use if useDB */
145 
149  * compression */
150  int suppressDumpWarnings; /* Suppress output of WARNING entries
151  * to stderr */
153 
154  bool *idWanted; /* array showing which dump IDs to emit */
156  int sequence_data; /* dump sequence data even in schema-only mode */
159 
160 typedef struct _dumpOptions
161 {
163 
165 
166  /* various user-settable parameters */
168  bool dataOnly;
169  int dumpSections; /* bitmask of chosen sections */
170  bool aclsSkip;
171  const char *lockWaitTimeout;
172  int dump_inserts; /* 0 = COPY, otherwise rows per INSERT */
173 
174  /* flags for various command-line long options */
191 
192  /* default, if no "inclusion" switches appear, is to dump everything */
194 
197  bool outputLOs;
201 
202  int sequence_data; /* dump sequence data even in schema-only mode */
205 
206 /*
207  * We may want to have some more user-readable data, but in the mean
208  * time this gives us some abstraction and type checking.
209  */
210 typedef struct Archive
211 {
212  DumpOptions *dopt; /* options, if dumping */
213  RestoreOptions *ropt; /* options, if restoring */
214 
215  int verbose;
216  char *remoteVersionStr; /* server's version string */
217  int remoteVersion; /* same in numeric form */
218  bool isStandby; /* is server a standby node */
219 
220  int minRemoteVersion; /* allowable range */
222 
223  int numWorkers; /* number of parallel processes */
224  char *sync_snapshot_id; /* sync snapshot id for parallel operation */
225 
226  /* info needed for string escaping */
227  int encoding; /* libpq code for client_encoding */
228  bool std_strings; /* standard_conforming_strings */
229 
230  /* other important stuff */
231  char *searchpath; /* search_path to set during restore */
232  char *use_role; /* Issue SET ROLE to this */
233 
234  /* error handling */
235  bool exit_on_error; /* whether to exit on SQL errors... */
236  int n_errors; /* number of errors (if no die) */
237 
238  /* prepared-query status */
239  bool *is_prepared; /* indexed by enum _dumpPreparedQueries */
240 
241  /* The rest is private */
243 
244 
245 /*
246  * pg_dump uses two different mechanisms for identifying database objects:
247  *
248  * CatalogId represents an object by the tableoid and oid of its defining
249  * entry in the system catalogs. We need this to interpret pg_depend entries,
250  * for instance.
251  *
252  * DumpId is a simple sequential integer counter assigned as dumpable objects
253  * are identified during a pg_dump run. We use DumpId internally in preference
254  * to CatalogId for two reasons: it's more compact, and we can assign DumpIds
255  * to "objects" that don't have a separate CatalogId. For example, it is
256  * convenient to consider a table, its data, and its ACL as three separate
257  * dumpable "objects" with distinct DumpIds --- this lets us reason about the
258  * order in which to dump these things.
259  */
260 
261 typedef struct
262 {
263  /* Note: this struct must not contain any unused bytes */
266 } CatalogId;
267 
268 typedef int DumpId;
269 
270 #define InvalidDumpId 0
271 
272 /*
273  * Function pointer prototypes for assorted callback methods.
274  */
275 
276 typedef int (*DataDumperPtr) (Archive *AH, const void *userArg);
277 
278 typedef void (*SetupWorkerPtrType) (Archive *AH);
279 
280 /*
281  * Main archiver interface.
282  */
283 
284 extern void ConnectDatabase(Archive *AHX,
285  const ConnParams *cparams,
286  bool isReconnect);
287 extern void DisconnectDatabase(Archive *AHX);
288 extern PGconn *GetConnection(Archive *AHX);
289 
290 /* Called to write *data* to the archive */
291 extern void WriteData(Archive *AHX, const void *data, size_t dLen);
292 
293 extern int StartLO(Archive *AHX, Oid oid);
294 extern int EndLO(Archive *AHX, Oid oid);
295 
296 extern void CloseArchive(Archive *AHX);
297 
298 extern void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt);
299 
300 extern void ProcessArchiveRestoreOptions(Archive *AHX);
301 
302 extern void RestoreArchive(Archive *AHX);
303 
304 /* Open an existing archive */
305 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
306 
307 /* Create a new archive */
308 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
309  const pg_compress_specification compression_spec,
310  bool dosync, ArchiveMode mode,
313 
314 /* The --list option */
315 extern void PrintTOCSummary(Archive *AHX);
316 
317 extern RestoreOptions *NewRestoreOptions(void);
318 
319 extern DumpOptions *NewDumpOptions(void);
320 extern void InitDumpOptions(DumpOptions *opts);
322 
323 /* Rearrange and filter TOC entries */
324 extern void SortTocFromFile(Archive *AHX);
325 
326 /* Convenience functions used only when writing DATA */
327 extern void archputs(const char *s, Archive *AH);
328 extern int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2, 3);
329 
330 #define appendStringLiteralAH(buf,str,AH) \
331  appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
332 
333 #endif /* PG_BACKUP_H */
#define pg_attribute_printf(f, a)
Definition: c.h:178
DataDirSyncMethod
Definition: file_utils.h:28
static DataDirSyncMethod sync_method
Definition: initdb.c:168
static void const char * fmt
static AmcheckOptions opts
Definition: pg_amcheck.c:111
void ConnectDatabase(Archive *AHX, const ConnParams *cparams, bool isReconnect)
Definition: pg_backup_db.c:110
_teSection
Definition: pg_backup.h:56
@ SECTION_NONE
Definition: pg_backup.h:57
@ SECTION_POST_DATA
Definition: pg_backup.h:60
@ SECTION_PRE_DATA
Definition: pg_backup.h:58
@ SECTION_DATA
Definition: pg_backup.h:59
int DumpId
Definition: pg_backup.h:268
int EndLO(Archive *AHX, Oid oid)
void ProcessArchiveRestoreOptions(Archive *AHX)
void(* SetupWorkerPtrType)(Archive *AH)
Definition: pg_backup.h:278
RestoreOptions * NewRestoreOptions(void)
int StartLO(Archive *AHX, Oid oid)
Archive * CreateArchive(const char *FileSpec, const ArchiveFormat fmt, const pg_compress_specification compression_spec, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupDumpWorker, DataDirSyncMethod sync_method)
enum _archiveFormat ArchiveFormat
PGconn * GetConnection(Archive *AHX)
Definition: pg_backup_db.c:254
struct Archive Archive
void CloseArchive(Archive *AHX)
struct _connParams ConnParams
void SortTocFromFile(Archive *AHX)
_archiveMode
Definition: pg_backup.h:49
@ archModeWrite
Definition: pg_backup.h:51
@ archModeAppend
Definition: pg_backup.h:50
@ archModeRead
Definition: pg_backup.h:52
_dumpPreparedQueries
Definition: pg_backup.h:65
@ PREPQUERY_DUMPFUNC
Definition: pg_backup.h:71
@ PREPQUERY_DUMPTABLEATTACH
Definition: pg_backup.h:74
@ PREPQUERY_DUMPBASETYPE
Definition: pg_backup.h:67
@ PREPQUERY_DUMPRANGETYPE
Definition: pg_backup.h:73
@ PREPQUERY_DUMPOPR
Definition: pg_backup.h:72
@ PREPQUERY_DUMPDOMAIN
Definition: pg_backup.h:69
@ NUM_PREP_QUERIES
Definition: pg_backup.h:77
@ PREPQUERY_DUMPCOMPOSITETYPE
Definition: pg_backup.h:68
@ PREPQUERY_DUMPAGG
Definition: pg_backup.h:66
@ PREPQUERY_GETCOLUMNACLS
Definition: pg_backup.h:75
@ PREPQUERY_GETDOMAINCONSTRAINTS
Definition: pg_backup.h:76
@ PREPQUERY_DUMPENUMTYPE
Definition: pg_backup.h:70
trivalue
Definition: pg_backup.h:33
@ TRI_YES
Definition: pg_backup.h:36
@ TRI_DEFAULT
Definition: pg_backup.h:34
@ TRI_NO
Definition: pg_backup.h:35
int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2
struct _restoreOptions RestoreOptions
void PrintTOCSummary(Archive *AHX)
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
DumpOptions * NewDumpOptions(void)
void DisconnectDatabase(Archive *AHX)
Definition: pg_backup_db.c:225
void RestoreArchive(Archive *AHX)
void archputs(const char *s, Archive *AH)
enum _teSection teSection
struct _dumpOptions DumpOptions
enum _archiveMode ArchiveMode
_archiveFormat
Definition: pg_backup.h:40
@ archUnknown
Definition: pg_backup.h:41
@ archTar
Definition: pg_backup.h:43
@ archCustom
Definition: pg_backup.h:42
@ archDirectory
Definition: pg_backup.h:45
@ archNull
Definition: pg_backup.h:44
Archive * OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
void InitDumpOptions(DumpOptions *opts)
DumpOptions * dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
void WriteData(Archive *AHX, const void *data, size_t dLen)
int(* DataDumperPtr)(Archive *AH, const void *userArg)
Definition: pg_backup.h:276
static PgChecksumMode mode
Definition: pg_checksums.c:56
const void * data
static bool dosync
Definition: pg_dump.c:103
static void setupDumpWorker(Archive *AH)
Definition: pg_dump.c:1330
unsigned int Oid
Definition: postgres_ext.h:31
int minRemoteVersion
Definition: pg_backup.h:220
int remoteVersion
Definition: pg_backup.h:217
char * remoteVersionStr
Definition: pg_backup.h:216
DumpOptions * dopt
Definition: pg_backup.h:212
bool * is_prepared
Definition: pg_backup.h:239
bool exit_on_error
Definition: pg_backup.h:235
char * searchpath
Definition: pg_backup.h:231
bool isStandby
Definition: pg_backup.h:218
int maxRemoteVersion
Definition: pg_backup.h:221
int n_errors
Definition: pg_backup.h:236
bool std_strings
Definition: pg_backup.h:228
int numWorkers
Definition: pg_backup.h:223
int encoding
Definition: pg_backup.h:227
char * use_role
Definition: pg_backup.h:232
char * sync_snapshot_id
Definition: pg_backup.h:224
int verbose
Definition: pg_backup.h:215
RestoreOptions * ropt
Definition: pg_backup.h:213
Oid tableoid
Definition: pg_backup.h:264
char * override_dbname
Definition: pg_backup.h:91
char * pgport
Definition: pg_backup.h:85
char * pghost
Definition: pg_backup.h:86
trivalue promptPassword
Definition: pg_backup.h:88
char * username
Definition: pg_backup.h:87
char * dbname
Definition: pg_backup.h:84
bool dataOnly
Definition: pg_backup.h:168
int dump_inserts
Definition: pg_backup.h:172
int no_toast_compression
Definition: pg_backup.h:182
int column_inserts
Definition: pg_backup.h:176
bool dontOutputLOs
Definition: pg_backup.h:198
int use_setsessauth
Definition: pg_backup.h:188
int outputCreateDB
Definition: pg_backup.h:196
bool include_everything
Definition: pg_backup.h:193
int sequence_data
Definition: pg_backup.h:202
int disable_dollar_quoting
Definition: pg_backup.h:175
bool outputLOs
Definition: pg_backup.h:197
int no_comments
Definition: pg_backup.h:178
int serializable_deferrable
Definition: pg_backup.h:184
int outputNoTableAm
Definition: pg_backup.h:186
int enable_row_security
Definition: pg_backup.h:189
char * outputSuperuser
Definition: pg_backup.h:200
int dumpSections
Definition: pg_backup.h:169
int no_security_labels
Definition: pg_backup.h:179
int no_unlogged_table_data
Definition: pg_backup.h:183
int no_publications
Definition: pg_backup.h:180
ConnParams cparams
Definition: pg_backup.h:162
const char * lockWaitTimeout
Definition: pg_backup.h:171
int no_subscriptions
Definition: pg_backup.h:181
bool aclsSkip
Definition: pg_backup.h:170
int load_via_partition_root
Definition: pg_backup.h:190
int outputClean
Definition: pg_backup.h:195
int do_nothing
Definition: pg_backup.h:203
int outputNoTablespaces
Definition: pg_backup.h:187
int disable_triggers
Definition: pg_backup.h:185
int outputNoOwner
Definition: pg_backup.h:199
bool schemaOnly
Definition: pg_backup.h:167
int binary_upgrade
Definition: pg_backup.h:164
SimpleStringList schemaExcludeNames
Definition: pg_backup.h:139
int include_everything
Definition: pg_backup.h:124
bool * idWanted
Definition: pg_backup.h:154
int suppressDumpWarnings
Definition: pg_backup.h:150
ConnParams cparams
Definition: pg_backup.h:144
SimpleStringList functionNames
Definition: pg_backup.h:137
char * use_role
Definition: pg_backup.h:105
SimpleStringList tableNames
Definition: pg_backup.h:141
SimpleStringList indexNames
Definition: pg_backup.h:136
pg_compress_specification compression_spec
Definition: pg_backup.h:148
int no_subscriptions
Definition: pg_backup.h:114
SimpleStringList triggerNames
Definition: pg_backup.h:140
int disable_dollar_quoting
Definition: pg_backup.h:107
char * formatName
Definition: pg_backup.h:129
SimpleStringList schemaNames
Definition: pg_backup.h:138
const char * filename
Definition: pg_backup.h:117
int no_security_labels
Definition: pg_backup.h:113
char * tocFile
Definition: pg_backup.h:127
char * superuser
Definition: pg_backup.h:104
const char * lockWaitTimeout
Definition: pg_backup.h:123
int enable_row_security
Definition: pg_backup.h:155
int disable_triggers
Definition: pg_backup.h:100
int noDataForFailedTables
Definition: pg_backup.h:146
trivalue
Definition: vacuumlo.c:35
ArchiveMode
Definition: xlog.h:62