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 it's 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 typedef struct _restoreOptions
62 {
63  int createDB; /* Issue commands to create the database */
64  int noOwner; /* Don't try to match original object owner */
65  int noTablespace; /* Don't issue tablespace-related commands */
66  int disable_triggers; /* disable triggers during data-only
67  * restore */
68  int use_setsessauth; /* Use SET SESSION AUTHORIZATION commands
69  * instead of OWNER TO */
70  char *superuser; /* Username to use as superuser */
71  char *use_role; /* Issue SET ROLE to this */
76  int if_exists;
77  int no_comments; /* Skip comments */
78  int no_publications; /* Skip publication entries */
79  int no_security_labels; /* Skip security label entries */
80  int no_subscriptions; /* Skip subscription entries */
82 
83  const char *filename;
84  int dataOnly;
87  int verbose;
88  int aclsSkip;
89  const char *lockWaitTimeout;
91 
93  char *tocFile;
94  int format;
95  char *formatName;
96 
97  int selTypes;
98  int selIndex;
101  int selTable;
108 
109  int useDB;
110  char *dbname; /* subject to expand_dbname */
111  char *pgport;
112  char *pghost;
113  char *username;
118  int suppressDumpWarnings; /* Suppress output of WARNING entries
119  * to stderr */
121 
122  bool *idWanted; /* array showing which dump IDs to emit */
124  int sequence_data; /* dump sequence data even in schema-only mode */
127 
128 typedef struct _dumpOptions
129 {
130  const char *dbname; /* subject to expand_dbname */
131  const char *pghost;
132  const char *pgport;
133  const char *username;
134  bool oids;
135 
137 
138  /* various user-settable parameters */
140  bool dataOnly;
141  int dumpSections; /* bitmask of chosen sections */
142  bool aclsSkip;
143  const char *lockWaitTimeout;
144 
145  /* flags for various command-line long options */
163 
164  /* default, if no "inclusion" switches appear, is to dump everything */
166 
173 
174  int sequence_data; /* dump sequence data even in schema-only mode */
175 } DumpOptions;
176 
177 /*
178  * We may want to have some more user-readable data, but in the mean
179  * time this gives us some abstraction and type checking.
180  */
181 typedef struct Archive
182 {
183  DumpOptions *dopt; /* options, if dumping */
184  RestoreOptions *ropt; /* options, if restoring */
185 
186  int verbose;
187  char *remoteVersionStr; /* server's version string */
188  int remoteVersion; /* same in numeric form */
189  bool isStandby; /* is server a standby node */
190 
191  int minRemoteVersion; /* allowable range */
193 
194  int numWorkers; /* number of parallel processes */
195  char *sync_snapshot_id; /* sync snapshot id for parallel operation */
196 
197  /* info needed for string escaping */
198  int encoding; /* libpq code for client_encoding */
199  bool std_strings; /* standard_conforming_strings */
200  char *use_role; /* Issue SET ROLE to this */
201 
202  /* error handling */
203  bool exit_on_error; /* whether to exit on SQL errors... */
204  int n_errors; /* number of errors (if no die) */
205 
206  /* The rest is private */
207 } Archive;
208 
209 
210 /*
211  * pg_dump uses two different mechanisms for identifying database objects:
212  *
213  * CatalogId represents an object by the tableoid and oid of its defining
214  * entry in the system catalogs. We need this to interpret pg_depend entries,
215  * for instance.
216  *
217  * DumpId is a simple sequential integer counter assigned as dumpable objects
218  * are identified during a pg_dump run. We use DumpId internally in preference
219  * to CatalogId for two reasons: it's more compact, and we can assign DumpIds
220  * to "objects" that don't have a separate CatalogId. For example, it is
221  * convenient to consider a table, its data, and its ACL as three separate
222  * dumpable "objects" with distinct DumpIds --- this lets us reason about the
223  * order in which to dump these things.
224  */
225 
226 typedef struct
227 {
230 } CatalogId;
231 
232 typedef int DumpId;
233 
234 typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
235 
236 typedef void (*SetupWorkerPtrType) (Archive *AH);
237 
238 /*
239  * Main archiver interface.
240  */
241 
242 extern void ConnectDatabase(Archive *AH,
243  const char *dbname,
244  const char *pghost,
245  const char *pgport,
246  const char *username,
247  trivalue prompt_password);
248 extern void DisconnectDatabase(Archive *AHX);
249 extern PGconn *GetConnection(Archive *AHX);
250 
251 /* Called to add a TOC entry */
252 extern void ArchiveEntry(Archive *AHX,
253  CatalogId catalogId, DumpId dumpId,
254  const char *tag,
255  const char *namespace, const char *tablespace,
256  const char *owner, bool withOids,
257  const char *desc, teSection section,
258  const char *defn,
259  const char *dropStmt, const char *copyStmt,
260  const DumpId *deps, int nDeps,
261  DataDumperPtr dumpFn, void *dumpArg);
262 
263 /* Called to write *data* to the archive */
264 extern void WriteData(Archive *AH, const void *data, size_t dLen);
265 
266 extern int StartBlob(Archive *AH, Oid oid);
267 extern int EndBlob(Archive *AH, Oid oid);
268 
269 extern void CloseArchive(Archive *AH);
270 
271 extern void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt);
272 
273 extern void ProcessArchiveRestoreOptions(Archive *AH);
274 
275 extern void RestoreArchive(Archive *AH);
276 
277 /* Open an existing archive */
278 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
279 
280 /* Create a new archive */
281 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
282  const int compression, bool dosync, ArchiveMode mode,
284 
285 /* The --list option */
286 extern void PrintTOCSummary(Archive *AH);
287 
288 extern RestoreOptions *NewRestoreOptions(void);
289 
290 extern DumpOptions *NewDumpOptions(void);
291 extern void InitDumpOptions(DumpOptions *opts);
293 
294 /* Rearrange and filter TOC entries */
295 extern void SortTocFromFile(Archive *AHX);
296 
297 /* Convenience functions used only when writing DATA */
298 extern void archputs(const char *s, Archive *AH);
299 extern int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2, 3);
300 
301 #define appendStringLiteralAH(buf,str,AH) \
302  appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
303 
304 #endif /* PG_BACKUP_H */
int column_inserts
Definition: pg_backup.h:148
int disable_triggers
Definition: pg_backup.h:158
int DumpId
Definition: pg_backup.h:232
int noDataForFailedTables
Definition: pg_backup.h:114
struct _restoreOptions RestoreOptions
DumpOptions * NewDumpOptions(void)
int disable_dollar_quoting
Definition: pg_backup.h:73
_archiveFormat
Definition: pg_backup.h:37
Oid tableoid
Definition: pg_backup.h:228
char * use_role
Definition: pg_backup.h:200
SimpleStringList triggerNames
Definition: pg_backup.h:106
RestoreOptions * ropt
Definition: pg_backup.h:184
bool schemaOnly
Definition: pg_backup.h:139
int no_subscriptions
Definition: pg_backup.h:153
int no_publications
Definition: pg_backup.h:152
char * username
Definition: pg_backup.h:113
Archive * OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
enum _archiveMode ArchiveMode
const char * dbname
Definition: pg_backup.h:130
static bool dosync
Definition: pg_dump.c:94
Archive * CreateArchive(const char *FileSpec, const ArchiveFormat fmt, const int compression, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupDumpWorker)
char * use_role
Definition: pg_backup.h:71
SimpleStringList schemaNames
Definition: pg_backup.h:104
int n_errors
Definition: pg_backup.h:204
int sequence_data
Definition: pg_backup.h:174
unsigned int Oid
Definition: postgres_ext.h:31
int encoding
Definition: pg_backup.h:198
_teSection
Definition: pg_backup.h:53
char * formatName
Definition: pg_backup.h:95
RestoreOptions * NewRestoreOptions(void)
int maxRemoteVersion
Definition: pg_backup.h:192
#define pg_attribute_printf(f, a)
Definition: c.h:132
char * sync_snapshot_id
Definition: pg_backup.h:195
const char * pgport
Definition: pg_backup.h:132
const char * lockWaitTimeout
Definition: pg_backup.h:89
trivalue
Definition: pg_backup.h:30
bool isStandby
Definition: pg_backup.h:189
int use_setsessauth
Definition: pg_backup.h:160
const char * filename
Definition: pg_backup.h:83
int disable_dollar_quoting
Definition: pg_backup.h:146
bool * idWanted
Definition: pg_backup.h:122
int StartBlob(Archive *AH, Oid oid)
int binary_upgrade
Definition: pg_backup.h:136
DumpOptions * dopt
Definition: pg_backup.h:183
int column_inserts
Definition: pg_backup.h:75
const char * lockWaitTimeout
Definition: pg_backup.h:143
bool dataOnly
Definition: pg_backup.h:140
bool include_everything
Definition: pg_backup.h:165
SimpleStringList tableNames
Definition: pg_backup.h:107
void WriteData(Archive *AH, const void *data, size_t dLen)
char * tablespace
Definition: pgbench.c:146
char * outputSuperuser
Definition: pg_backup.h:172
int no_unlogged_table_data
Definition: pg_backup.h:155
int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2
SimpleStringList functionNames
Definition: pg_backup.h:103
struct Archive Archive
void InitDumpOptions(DumpOptions *opts)
void PrintTOCSummary(Archive *AH)
int include_everything
Definition: pg_backup.h:90
void CloseArchive(Archive *AH)
int no_security_labels
Definition: pg_backup.h:79
bool outputBlobs
Definition: pg_backup.h:169
int dumpSections
Definition: pg_backup.h:141
int enable_row_security
Definition: pg_backup.h:123
DumpOptions * dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
int dump_inserts
Definition: pg_backup.h:147
int outputNoOwner
Definition: pg_backup.h:171
void DisconnectDatabase(Archive *AHX)
Definition: pg_backup_db.c:332
int no_security_labels
Definition: pg_backup.h:151
int no_subscriptions
Definition: pg_backup.h:80
trivalue
Definition: vacuumlo.c:31
char * superuser
Definition: pg_backup.h:70
bool aclsSkip
Definition: pg_backup.h:142
int use_setsessauth
Definition: pg_backup.h:68
int verbose
Definition: pg_backup.h:186
PGconn * GetConnection(Archive *AHX)
Definition: pg_backup_db.c:361
int quote_all_identifiers
Definition: pg_backup.h:157
_archiveMode
Definition: pg_backup.h:46
int enable_row_security
Definition: pg_backup.h:161
enum _archiveFormat ArchiveFormat
enum _teSection teSection
int outputCreateDB
Definition: pg_backup.h:168
ArchiveMode
Definition: xlog.h:116
int outputClean
Definition: pg_backup.h:167
struct _dumpOptions DumpOptions
int no_comments
Definition: pg_backup.h:150
int numWorkers
Definition: pg_backup.h:194
const char * username
Definition: pg_backup.h:133
int(* DataDumperPtr)(Archive *AH, void *userArg)
Definition: pg_backup.h:234
void SortTocFromFile(Archive *AHX)
SimpleStringList indexNames
Definition: pg_backup.h:102
int outputNoTablespaces
Definition: pg_backup.h:159
char * remoteVersionStr
Definition: pg_backup.h:187
int EndBlob(Archive *AH, Oid oid)
int no_publications
Definition: pg_backup.h:78
void RestoreArchive(Archive *AH)
bool exit_on_error
Definition: pg_backup.h:203
void ProcessArchiveRestoreOptions(Archive *AH)
const char * pghost
Definition: pg_backup.h:131
int no_synchronized_snapshots
Definition: pg_backup.h:154
bool dontOutputBlobs
Definition: pg_backup.h:170
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
int suppressDumpWarnings
Definition: pg_backup.h:118
SimpleStringList schemaExcludeNames
Definition: pg_backup.h:105
void(* SetupWorkerPtrType)(Archive *AH)
Definition: pg_backup.h:236
static void setupDumpWorker(Archive *AHX)
Definition: pg_dump.c:1166
int serializable_deferrable
Definition: pg_backup.h:156
char * tocFile
Definition: pg_backup.h:93
void archputs(const char *s, Archive *AH)
bool std_strings
Definition: pg_backup.h:199
int load_via_partition_root
Definition: pg_backup.h:162
int disable_triggers
Definition: pg_backup.h:66
void ConnectDatabase(Archive *AH, const char *dbname, const char *pghost, const char *pgport, const char *username, trivalue prompt_password)
Definition: pg_backup_db.c:235
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
int remoteVersion
Definition: pg_backup.h:188
trivalue promptPassword
Definition: pg_backup.h:115
int minRemoteVersion
Definition: pg_backup.h:191