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