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 */
169 
170  /* default, if no "inclusion" switches appear, is to dump everything */
172 
179 
180  int sequence_data; /* dump sequence data even in schema-only mode */
182 } DumpOptions;
183 
184 /*
185  * We may want to have some more user-readable data, but in the mean
186  * time this gives us some abstraction and type checking.
187  */
188 typedef struct Archive
189 {
190  DumpOptions *dopt; /* options, if dumping */
191  RestoreOptions *ropt; /* options, if restoring */
192 
193  int verbose;
194  char *remoteVersionStr; /* server's version string */
195  int remoteVersion; /* same in numeric form */
196  bool isStandby; /* is server a standby node */
197 
198  int minRemoteVersion; /* allowable range */
200 
201  int numWorkers; /* number of parallel processes */
202  char *sync_snapshot_id; /* sync snapshot id for parallel operation */
203 
204  /* info needed for string escaping */
205  int encoding; /* libpq code for client_encoding */
206  bool std_strings; /* standard_conforming_strings */
207 
208  /* other important stuff */
209  char *searchpath; /* search_path to set during restore */
210  char *use_role; /* Issue SET ROLE to this */
211 
212  /* error handling */
213  bool exit_on_error; /* whether to exit on SQL errors... */
214  int n_errors; /* number of errors (if no die) */
215 
216  /* The rest is private */
217 } Archive;
218 
219 
220 /*
221  * pg_dump uses two different mechanisms for identifying database objects:
222  *
223  * CatalogId represents an object by the tableoid and oid of its defining
224  * entry in the system catalogs. We need this to interpret pg_depend entries,
225  * for instance.
226  *
227  * DumpId is a simple sequential integer counter assigned as dumpable objects
228  * are identified during a pg_dump run. We use DumpId internally in preference
229  * to CatalogId for two reasons: it's more compact, and we can assign DumpIds
230  * to "objects" that don't have a separate CatalogId. For example, it is
231  * convenient to consider a table, its data, and its ACL as three separate
232  * dumpable "objects" with distinct DumpIds --- this lets us reason about the
233  * order in which to dump these things.
234  */
235 
236 typedef struct
237 {
240 } CatalogId;
241 
242 typedef int DumpId;
243 
244 #define InvalidDumpId 0
245 
246 /*
247  * Function pointer prototypes for assorted callback methods.
248  */
249 
250 typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
251 
252 typedef void (*SetupWorkerPtrType) (Archive *AH);
253 
254 /*
255  * Main archiver interface.
256  */
257 
258 extern void ConnectDatabase(Archive *AHX,
259  const ConnParams *cparams,
260  bool isReconnect);
261 extern void DisconnectDatabase(Archive *AHX);
262 extern PGconn *GetConnection(Archive *AHX);
263 
264 /* Called to write *data* to the archive */
265 extern void WriteData(Archive *AH, const void *data, size_t dLen);
266 
267 extern int StartBlob(Archive *AH, Oid oid);
268 extern int EndBlob(Archive *AH, Oid oid);
269 
270 extern void CloseArchive(Archive *AH);
271 
272 extern void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt);
273 
274 extern void ProcessArchiveRestoreOptions(Archive *AH);
275 
276 extern void RestoreArchive(Archive *AH);
277 
278 /* Open an existing archive */
279 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
280 
281 /* Create a new archive */
282 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
283  const int compression, bool dosync, ArchiveMode mode,
285 
286 /* The --list option */
287 extern void PrintTOCSummary(Archive *AH);
288 
289 extern RestoreOptions *NewRestoreOptions(void);
290 
291 extern DumpOptions *NewDumpOptions(void);
292 extern void InitDumpOptions(DumpOptions *opts);
294 
295 /* Rearrange and filter TOC entries */
296 extern void SortTocFromFile(Archive *AHX);
297 
298 /* Convenience functions used only when writing DATA */
299 extern void archputs(const char *s, Archive *AH);
300 extern int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2, 3);
301 
302 #define appendStringLiteralAH(buf,str,AH) \
303  appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
304 
305 #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:164
int DumpId
Definition: pg_backup.h:242
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:238
char * use_role
Definition: pg_backup.h:210
char * pgport
Definition: pg_backup.h:66
SimpleStringList triggerNames
Definition: pg_backup.h:120
RestoreOptions * ropt
Definition: pg_backup.h:191
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:214
int sequence_data
Definition: pg_backup.h:180
unsigned int Oid
Definition: postgres_ext.h:31
int encoding
Definition: pg_backup.h:205
_teSection
Definition: pg_backup.h:53
char * formatName
Definition: pg_backup.h:109
RestoreOptions * NewRestoreOptions(void)
int maxRemoteVersion
Definition: pg_backup.h:199
#define pg_attribute_printf(f, a)
Definition: c.h:130
char * sync_snapshot_id
Definition: pg_backup.h:202
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:196
int use_setsessauth
Definition: pg_backup.h:166
const char * filename
Definition: pg_backup.h:97
int disable_dollar_quoting
Definition: pg_backup.h:154
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:190
int column_inserts
Definition: pg_backup.h:89
const char * lockWaitTimeout
Definition: pg_backup.h:150
bool dataOnly
Definition: pg_backup.h:147
bool include_everything
Definition: pg_backup.h:171
SimpleStringList tableNames
Definition: pg_backup.h:121
void WriteData(Archive *AH, const void *data, size_t dLen)
char * outputSuperuser
Definition: pg_backup.h:178
int no_unlogged_table_data
Definition: pg_backup.h:162
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:175
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:177
char * override_dbname
Definition: pg_backup.h:72
ConnParams cparams
Definition: pg_backup.h:124
void DisconnectDatabase(Archive *AHX)
Definition: pg_backup_db.c:232
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
bool aclsSkip
Definition: pg_backup.h:149
int use_setsessauth
Definition: pg_backup.h:82
int verbose
Definition: pg_backup.h:193
PGconn * GetConnection(Archive *AHX)
Definition: pg_backup_db.c:261
char * searchpath
Definition: pg_backup.h:209
_archiveMode
Definition: pg_backup.h:46
int enable_row_security
Definition: pg_backup.h:167
enum _archiveFormat ArchiveFormat
enum _teSection teSection
int outputCreateDB
Definition: pg_backup.h:174
ArchiveMode
Definition: xlog.h:153
int outputClean
Definition: pg_backup.h:173
struct _dumpOptions DumpOptions
int no_comments
Definition: pg_backup.h:157
int numWorkers
Definition: pg_backup.h:201
int(* DataDumperPtr)(Archive *AH, void *userArg)
Definition: pg_backup.h:250
void SortTocFromFile(Archive *AHX)
SimpleStringList indexNames
Definition: pg_backup.h:116
int outputNoTablespaces
Definition: pg_backup.h:165
char * remoteVersionStr
Definition: pg_backup.h:194
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:213
void ProcessArchiveRestoreOptions(Archive *AH)
int no_synchronized_snapshots
Definition: pg_backup.h:161
bool dontOutputBlobs
Definition: pg_backup.h:176
int suppressDumpWarnings
Definition: pg_backup.h:129
int do_nothing
Definition: pg_backup.h:181
SimpleStringList schemaExcludeNames
Definition: pg_backup.h:119
void(* SetupWorkerPtrType)(Archive *AH)
Definition: pg_backup.h:252
static void setupDumpWorker(Archive *AHX)
Definition: pg_dump.c:1242
int serializable_deferrable
Definition: pg_backup.h:163
char * tocFile
Definition: pg_backup.h:107
void archputs(const char *s, Archive *AH)
bool std_strings
Definition: pg_backup.h:206
int load_via_partition_root
Definition: pg_backup.h:168
int disable_triggers
Definition: pg_backup.h:80
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
int remoteVersion
Definition: pg_backup.h:195
int minRemoteVersion
Definition: pg_backup.h:198