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