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