Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

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