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