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