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