1 /*-------------------------------------------------------------------------
5 * Public interface to the pg_dump archiver routines.
7 * See the headers to pg_restore for more details.
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.
13 * The author is not responsible for loss or damages that may
14 * result from its use.
18 * src/bin/pg_dump/pg_backup.h
20 *-------------------------------------------------------------------------
26 #include "common/compression.h"
27 #include "common/file_utils.h"
28 #include "fe_utils/simple_list.h"
39 typedef enum _archiveFormat
48 typedef enum _archiveMode
55 typedef enum _teSection
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 */
63 /* We need one enum entry per prepared query in pg_dump */
64 enum _dumpPreparedQueries
67 PREPQUERY_DUMPBASETYPE
,
68 PREPQUERY_DUMPCOMPOSITETYPE
,
70 PREPQUERY_DUMPENUMTYPE
,
73 PREPQUERY_DUMPRANGETYPE
,
74 PREPQUERY_DUMPTABLEATTACH
,
75 PREPQUERY_GETCOLUMNACLS
,
76 PREPQUERY_GETDOMAINCONSTRAINTS
,
79 #define NUM_PREP_QUERIES (PREPQUERY_GETDOMAINCONSTRAINTS + 1)
81 /* Parameters needed by ConnectDatabase; same for dump and restore */
82 typedef struct _connParams
84 /* These fields record the actual command line parameters */
85 char *dbname
; /* this may be a connstring! */
89 trivalue promptPassword
;
90 /* If not NULL, this overrides the dbname obtained from command line */
91 /* (but *only* the DB name, not anything else in the connstring) */
92 char *override_dbname
;
95 typedef struct _restoreOptions
97 int createDB
; /* Issue commands to create the database */
98 int noOwner
; /* Don't try to match original object owner */
99 int noTableAm
; /* Don't issue table-AM-related commands */
100 int noTablespace
; /* Don't issue tablespace-related commands */
101 int disable_triggers
; /* disable triggers during data-only
103 int use_setsessauth
; /* Use SET SESSION AUTHORIZATION commands
104 * instead of OWNER TO */
105 char *superuser
; /* Username to use as superuser */
106 char *use_role
; /* Issue SET ROLE to this */
108 int disable_dollar_quoting
;
109 int dump_inserts
; /* 0 = COPY, otherwise rows per INSERT */
112 int no_comments
; /* Skip comments */
113 int no_publications
; /* Skip publication entries */
114 int no_security_labels
; /* Skip security label entries */
115 int no_subscriptions
; /* Skip subscription entries */
118 const char *filename
;
122 const char *lockWaitTimeout
;
123 int include_everything
;
135 SimpleStringList indexNames
;
136 SimpleStringList functionNames
;
137 SimpleStringList schemaNames
;
138 SimpleStringList schemaExcludeNames
;
139 SimpleStringList triggerNames
;
140 SimpleStringList tableNames
;
143 ConnParams cparams
; /* parameters to use if useDB */
145 int noDataForFailedTables
;
147 pg_compress_specification compression_spec
; /* Specification for
149 int suppressDumpWarnings
; /* Suppress output of WARNING entries
152 bool single_txn
; /* restore all TOCs in one transaction */
153 int txn_size
; /* restore this many TOCs per txn, if > 0 */
155 bool *idWanted
; /* array showing which dump IDs to emit */
156 int enable_row_security
;
157 int sequence_data
; /* dump sequence data even in schema-only mode */
160 /* flags derived from the user-settable flags */
165 typedef struct _dumpOptions
171 /* various user-settable parameters */
172 int dumpSections
; /* bitmask of chosen sections */
174 const char *lockWaitTimeout
;
175 int dump_inserts
; /* 0 = COPY, otherwise rows per INSERT */
177 /* flags for various command-line long options */
178 int disable_dollar_quoting
;
182 int no_security_labels
;
184 int no_subscriptions
;
185 int no_toast_compression
;
186 int no_unlogged_table_data
;
187 int serializable_deferrable
;
188 int disable_triggers
;
190 int outputNoTablespaces
;
192 int enable_row_security
;
193 int load_via_partition_root
;
195 /* default, if no "inclusion" switches appear, is to dump everything */
196 bool include_everything
;
203 char *outputSuperuser
;
205 int sequence_data
; /* dump sequence data even in schema-only mode */
208 /* flags derived from the user-settable flags */
214 * We may want to have some more user-readable data, but in the mean
215 * time this gives us some abstraction and type checking.
217 typedef struct Archive
219 DumpOptions
*dopt
; /* options, if dumping */
220 RestoreOptions
*ropt
; /* options, if restoring */
223 char *remoteVersionStr
; /* server's version string */
224 int remoteVersion
; /* same in numeric form */
225 bool isStandby
; /* is server a standby node */
227 int minRemoteVersion
; /* allowable range */
228 int maxRemoteVersion
;
230 int numWorkers
; /* number of parallel processes */
231 char *sync_snapshot_id
; /* sync snapshot id for parallel operation */
233 /* info needed for string escaping */
234 int encoding
; /* libpq code for client_encoding */
235 bool std_strings
; /* standard_conforming_strings */
237 /* other important stuff */
238 char *searchpath
; /* search_path to set during restore */
239 char *use_role
; /* Issue SET ROLE to this */
242 bool exit_on_error
; /* whether to exit on SQL errors... */
243 int n_errors
; /* number of errors (if no die) */
245 /* prepared-query status */
246 bool *is_prepared
; /* indexed by enum _dumpPreparedQueries */
248 /* The rest is private */
253 * pg_dump uses two different mechanisms for identifying database objects:
255 * CatalogId represents an object by the tableoid and oid of its defining
256 * entry in the system catalogs. We need this to interpret pg_depend entries,
259 * DumpId is a simple sequential integer counter assigned as dumpable objects
260 * are identified during a pg_dump run. We use DumpId internally in preference
261 * to CatalogId for two reasons: it's more compact, and we can assign DumpIds
262 * to "objects" that don't have a separate CatalogId. For example, it is
263 * convenient to consider a table, its data, and its ACL as three separate
264 * dumpable "objects" with distinct DumpIds --- this lets us reason about the
265 * order in which to dump these things.
270 /* Note: this struct must not contain any unused bytes */
277 #define InvalidDumpId 0
280 * Function pointer prototypes for assorted callback methods.
283 typedef int (*DataDumperPtr
) (Archive
*AH
, const void *userArg
);
285 typedef void (*SetupWorkerPtrType
) (Archive
*AH
);
288 * Main archiver interface.
291 extern void ConnectDatabase(Archive
*AHX
,
292 const ConnParams
*cparams
,
294 extern void DisconnectDatabase(Archive
*AHX
);
295 extern PGconn
*GetConnection(Archive
*AHX
);
297 /* Called to write *data* to the archive */
298 extern void WriteData(Archive
*AHX
, const void *data
, size_t dLen
);
300 extern int StartLO(Archive
*AHX
, Oid oid
);
301 extern int EndLO(Archive
*AHX
, Oid oid
);
303 extern void CloseArchive(Archive
*AHX
);
305 extern void SetArchiveOptions(Archive
*AH
, DumpOptions
*dopt
, RestoreOptions
*ropt
);
307 extern void ProcessArchiveRestoreOptions(Archive
*AHX
);
309 extern void RestoreArchive(Archive
*AHX
);
311 /* Open an existing archive */
312 extern Archive
*OpenArchive(const char *FileSpec
, const ArchiveFormat fmt
);
314 /* Create a new archive */
315 extern Archive
*CreateArchive(const char *FileSpec
, const ArchiveFormat fmt
,
316 const pg_compress_specification compression_spec
,
317 bool dosync
, ArchiveMode mode
,
318 SetupWorkerPtrType setupDumpWorker
,
319 DataDirSyncMethod sync_method
);
321 /* The --list option */
322 extern void PrintTOCSummary(Archive
*AHX
);
324 extern RestoreOptions
*NewRestoreOptions(void);
326 extern DumpOptions
*NewDumpOptions(void);
327 extern void InitDumpOptions(DumpOptions
*opts
);
328 extern DumpOptions
*dumpOptionsFromRestoreOptions(RestoreOptions
*ropt
);
330 /* Rearrange and filter TOC entries */
331 extern void SortTocFromFile(Archive
*AHX
);
333 /* Convenience functions used only when writing DATA */
334 extern void archputs(const char *s
, Archive
*AH
);
335 extern int archprintf(Archive
*AH
, const char *fmt
,...) pg_attribute_printf(2, 3);
337 #define appendStringLiteralAH(buf,str,AH) \
338 appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
340 #endif /* PG_BACKUP_H */