PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 "common/compression.h"
27#include "common/file_utils.h"
29#include "libpq-fe.h"
30
31
38
47
54
55typedef enum _teSection
56{
57 SECTION_NONE = 1, /* comments, ACLs, etc; can be anywhere */
58 SECTION_PRE_DATA, /* stuff to be processed before data */
59 SECTION_DATA, /* table data, large objects, LO comments */
60 SECTION_POST_DATA, /* stuff to be processed after data */
62
63/* We need one enum entry per prepared query in pg_dump */
80
81#define NUM_PREP_QUERIES (PREPQUERY_GETDOMAINCONSTRAINTS + 1)
82
83/* Parameters needed by ConnectDatabase; same for dump and restore */
84typedef struct _connParams
85{
86 /* These fields record the actual command line parameters */
87 char *dbname; /* this may be a connstring! */
88 char *pgport;
89 char *pghost;
90 char *username;
92 /* If not NULL, this overrides the dbname obtained from command line */
93 /* (but *only* the DB name, not anything else in the connstring) */
96
97typedef struct _restoreOptions
98{
99 int createDB; /* Issue commands to create the database */
100 int noOwner; /* Don't try to match original object owner */
101 int noTableAm; /* Don't issue table-AM-related commands */
102 int noTablespace; /* Don't issue tablespace-related commands */
103 int disable_triggers; /* disable triggers during data-only
104 * restore */
105 int use_setsessauth; /* Use SET SESSION AUTHORIZATION commands
106 * instead of OWNER TO */
107 char *superuser; /* Username to use as superuser */
108 char *use_role; /* Issue SET ROLE to this */
111 int dump_inserts; /* 0 = COPY, otherwise rows per INSERT */
114 int no_comments; /* Skip comments */
115 int no_policies; /* Skip row security policies */
116 int no_publications; /* Skip publication entries */
117 int no_security_labels; /* Skip security label entries */
118 int no_subscriptions; /* Skip subscription entries */
120
121 const char *filename;
125 const char *lockWaitTimeout;
127
129 char *tocFile;
132
144
145 int useDB;
146 ConnParams cparams; /* parameters to use if useDB */
147
151 * compression */
152 int suppressDumpWarnings; /* Suppress output of WARNING entries
153 * to stderr */
154
155 bool single_txn; /* restore all TOCs in one transaction */
156 int txn_size; /* restore this many TOCs per txn, if > 0 */
157
158 bool *idWanted; /* array showing which dump IDs to emit */
160 int sequence_data; /* dump sequence data even in schema-only mode */
162
163 /* flags derived from the user-settable flags */
167
170
171typedef struct _dumpOptions
172{
174
176
177 /* various user-settable parameters */
178 int dumpSections; /* bitmask of chosen sections */
180 const char *lockWaitTimeout;
181 int dump_inserts; /* 0 = COPY, otherwise rows per INSERT */
182
183 /* flags for various command-line long options */
188 int no_policies; /* Skip row security policies */
201
202 /* default, if no "inclusion" switches appear, is to dump everything */
204
211
212 int sequence_data; /* dump sequence data even in schema-only mode */
214
215 /* flags derived from the user-settable flags */
219
222
223/*
224 * We may want to have some more user-readable data, but in the mean
225 * time this gives us some abstraction and type checking.
226 */
227typedef struct Archive
228{
229 DumpOptions *dopt; /* options, if dumping */
230 RestoreOptions *ropt; /* options, if restoring */
231
233 char *remoteVersionStr; /* server's version string */
234 int remoteVersion; /* same in numeric form */
235 bool isStandby; /* is server a standby node */
236
237 int minRemoteVersion; /* allowable range */
239
240 int numWorkers; /* number of parallel processes */
241 char *sync_snapshot_id; /* sync snapshot id for parallel operation */
242
243 /* info needed for string escaping */
244 int encoding; /* libpq code for client_encoding */
245 bool std_strings; /* standard_conforming_strings */
246
247 /* other important stuff */
248 char *searchpath; /* search_path to set during restore */
249 char *use_role; /* Issue SET ROLE to this */
250
251 /* error handling */
252 bool exit_on_error; /* whether to exit on SQL errors... */
253 int n_errors; /* number of errors (if no die) */
254
255 /* prepared-query status */
256 bool *is_prepared; /* indexed by enum _dumpPreparedQueries */
257
258 /* The rest is private */
260
261
262/*
263 * pg_dump uses two different mechanisms for identifying database objects:
264 *
265 * CatalogId represents an object by the tableoid and oid of its defining
266 * entry in the system catalogs. We need this to interpret pg_depend entries,
267 * for instance.
268 *
269 * DumpId is a simple sequential integer counter assigned as dumpable objects
270 * are identified during a pg_dump run. We use DumpId internally in preference
271 * to CatalogId for two reasons: it's more compact, and we can assign DumpIds
272 * to "objects" that don't have a separate CatalogId. For example, it is
273 * convenient to consider a table, its data, and its ACL as three separate
274 * dumpable "objects" with distinct DumpIds --- this lets us reason about the
275 * order in which to dump these things.
276 */
277
278typedef struct
279{
280 /* Note: this struct must not contain any unused bytes */
283} CatalogId;
284
285typedef int DumpId;
286
287#define InvalidDumpId 0
288
289/*
290 * Function pointer prototypes for assorted callback methods.
291 */
293
294/*
295 * Main archiver interface.
296 */
297
298extern void ConnectDatabaseAhx(Archive *AHX,
299 const ConnParams *cparams,
300 bool isReconnect);
301extern void DisconnectDatabase(Archive *AHX);
302extern PGconn *GetConnection(Archive *AHX);
303
304/* Called to write *data* to the archive */
305extern void WriteData(Archive *AHX, const void *data, size_t dLen);
306
307extern int StartLO(Archive *AHX, Oid oid);
308extern int EndLO(Archive *AHX, Oid oid);
309
310extern void CloseArchive(Archive *AHX);
311
312extern void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt);
313
314extern void ProcessArchiveRestoreOptions(Archive *AHX);
315
316extern void RestoreArchive(Archive *AHX);
317
318/* Open an existing archive */
319extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
320
321/* Create a new archive */
322extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
323 const pg_compress_specification compression_spec,
324 bool dosync, ArchiveMode mode,
327
328/* The --list option */
329extern void PrintTOCSummary(Archive *AHX);
330
332
333extern DumpOptions *NewDumpOptions(void);
334extern void InitDumpOptions(DumpOptions *opts);
336
337/* Rearrange and filter TOC entries */
338extern void SortTocFromFile(Archive *AHX);
339
340/* Convenience functions used only when writing DATA */
341extern void archputs(const char *s, Archive *AH);
342extern int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2, 3);
343
344#define appendStringLiteralAH(buf,str,AH) \
345 appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
346
347#endif /* PG_BACKUP_H */
#define pg_attribute_printf(f, a)
Definition c.h:242
trivalue
DataDirSyncMethod
Definition file_utils.h:28
static DataDirSyncMethod sync_method
Definition initdb.c:170
static AmcheckOptions opts
Definition pg_amcheck.c:112
_teSection
Definition pg_backup.h:56
@ SECTION_NONE
Definition pg_backup.h:57
@ SECTION_POST_DATA
Definition pg_backup.h:60
@ SECTION_PRE_DATA
Definition pg_backup.h:58
@ SECTION_DATA
Definition pg_backup.h:59
int DumpId
Definition pg_backup.h:285
int EndLO(Archive *AHX, Oid oid)
void ProcessArchiveRestoreOptions(Archive *AHX)
RestoreOptions * NewRestoreOptions(void)
void(* SetupWorkerPtrType)(Archive *AH)
Definition pg_backup.h:292
int StartLO(Archive *AHX, Oid oid)
enum _archiveFormat ArchiveFormat
Archive * OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
void ConnectDatabaseAhx(Archive *AHX, const ConnParams *cparams, bool isReconnect)
void CloseArchive(Archive *AHX)
struct _connParams ConnParams
Archive * CreateArchive(const char *FileSpec, const ArchiveFormat fmt, const pg_compress_specification compression_spec, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupDumpWorker, DataDirSyncMethod sync_method)
DumpOptions * NewDumpOptions(void)
void SortTocFromFile(Archive *AHX)
_archiveMode
Definition pg_backup.h:49
@ archModeWrite
Definition pg_backup.h:51
@ archModeAppend
Definition pg_backup.h:50
@ archModeRead
Definition pg_backup.h:52
_dumpPreparedQueries
Definition pg_backup.h:65
@ PREPQUERY_DUMPFUNC
Definition pg_backup.h:72
@ PREPQUERY_DUMPTABLEATTACH
Definition pg_backup.h:75
@ PREPQUERY_DUMPBASETYPE
Definition pg_backup.h:67
@ PREPQUERY_DUMPRANGETYPE
Definition pg_backup.h:74
@ PREPQUERY_DUMPOPR
Definition pg_backup.h:73
@ PREPQUERY_DUMPEXTSTATSOBJSTATS
Definition pg_backup.h:71
@ PREPQUERY_GETATTRIBUTESTATS
Definition pg_backup.h:76
@ PREPQUERY_DUMPDOMAIN
Definition pg_backup.h:69
@ PREPQUERY_DUMPCOMPOSITETYPE
Definition pg_backup.h:68
@ PREPQUERY_DUMPAGG
Definition pg_backup.h:66
@ PREPQUERY_GETCOLUMNACLS
Definition pg_backup.h:77
@ PREPQUERY_GETDOMAINCONSTRAINTS
Definition pg_backup.h:78
@ PREPQUERY_DUMPENUMTYPE
Definition pg_backup.h:70
trivalue
Definition pg_backup.h:33
@ TRI_YES
Definition pg_backup.h:36
@ TRI_DEFAULT
Definition pg_backup.h:34
@ TRI_NO
Definition pg_backup.h:35
int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2
struct _restoreOptions RestoreOptions
void PrintTOCSummary(Archive *AHX)
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
void DisconnectDatabase(Archive *AHX)
void RestoreArchive(Archive *AHX)
void archputs(const char *s, Archive *AH)
enum _teSection teSection
struct _dumpOptions DumpOptions
enum _archiveMode ArchiveMode
DumpOptions * dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
_archiveFormat
Definition pg_backup.h:40
@ archUnknown
Definition pg_backup.h:41
@ archTar
Definition pg_backup.h:43
@ archCustom
Definition pg_backup.h:42
@ archDirectory
Definition pg_backup.h:45
@ archNull
Definition pg_backup.h:44
void InitDumpOptions(DumpOptions *opts)
void WriteData(Archive *AHX, const void *data, size_t dLen)
static PgChecksumMode mode
const void * data
static bool dosync
Definition pg_dump.c:152
static void setupDumpWorker(Archive *AH)
Definition pg_dump.c:1610
unsigned int Oid
static int fb(int x)
PGconn * GetConnection(void)
Definition streamutil.c:60
int minRemoteVersion
Definition pg_backup.h:237
int remoteVersion
Definition pg_backup.h:234
char * remoteVersionStr
Definition pg_backup.h:233
DumpOptions * dopt
Definition pg_backup.h:229
bool * is_prepared
Definition pg_backup.h:256
bool exit_on_error
Definition pg_backup.h:252
char * searchpath
Definition pg_backup.h:248
bool isStandby
Definition pg_backup.h:235
int maxRemoteVersion
Definition pg_backup.h:238
int n_errors
Definition pg_backup.h:253
bool std_strings
Definition pg_backup.h:245
int numWorkers
Definition pg_backup.h:240
int encoding
Definition pg_backup.h:244
char * use_role
Definition pg_backup.h:249
char * sync_snapshot_id
Definition pg_backup.h:241
int verbose
Definition pg_backup.h:232
RestoreOptions * ropt
Definition pg_backup.h:230
Oid tableoid
Definition pg_backup.h:281
char * override_dbname
Definition pg_backup.h:94
char * pgport
Definition pg_backup.h:88
char * pghost
Definition pg_backup.h:89
trivalue promptPassword
Definition pg_backup.h:91
char * username
Definition pg_backup.h:90
char * dbname
Definition pg_backup.h:87
int no_toast_compression
Definition pg_backup.h:192
char * restrict_key
Definition pg_backup.h:220
int column_inserts
Definition pg_backup.h:185
bool dontOutputLOs
Definition pg_backup.h:208
int use_setsessauth
Definition pg_backup.h:198
int outputCreateDB
Definition pg_backup.h:206
bool include_everything
Definition pg_backup.h:203
int sequence_data
Definition pg_backup.h:212
int disable_dollar_quoting
Definition pg_backup.h:184
bool dumpSchema
Definition pg_backup.h:216
int serializable_deferrable
Definition pg_backup.h:194
int outputNoTableAm
Definition pg_backup.h:196
int enable_row_security
Definition pg_backup.h:199
char * outputSuperuser
Definition pg_backup.h:210
int no_security_labels
Definition pg_backup.h:190
int no_unlogged_table_data
Definition pg_backup.h:193
bool dumpStatistics
Definition pg_backup.h:218
int no_publications
Definition pg_backup.h:189
ConnParams cparams
Definition pg_backup.h:173
const char * lockWaitTimeout
Definition pg_backup.h:180
int no_subscriptions
Definition pg_backup.h:191
int load_via_partition_root
Definition pg_backup.h:200
int outputNoTablespaces
Definition pg_backup.h:197
int disable_triggers
Definition pg_backup.h:195
int outputNoOwner
Definition pg_backup.h:209
int binary_upgrade
Definition pg_backup.h:175
SimpleStringList schemaExcludeNames
Definition pg_backup.h:141
int suppressDumpWarnings
Definition pg_backup.h:152
ConnParams cparams
Definition pg_backup.h:146
SimpleStringList functionNames
Definition pg_backup.h:139
SimpleStringList tableNames
Definition pg_backup.h:143
SimpleStringList indexNames
Definition pg_backup.h:138
pg_compress_specification compression_spec
Definition pg_backup.h:150
SimpleStringList triggerNames
Definition pg_backup.h:142
int disable_dollar_quoting
Definition pg_backup.h:110
char * formatName
Definition pg_backup.h:131
SimpleStringList schemaNames
Definition pg_backup.h:140
char * restrict_key
Definition pg_backup.h:168
const char * filename
Definition pg_backup.h:121
const char * lockWaitTimeout
Definition pg_backup.h:125
int enable_row_security
Definition pg_backup.h:159
int noDataForFailedTables
Definition pg_backup.h:148
trivalue
Definition vacuumlo.c:35
ArchiveMode
Definition xlog.h:65