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 it's use.
18 * src/bin/pg_dump/pg_backup.h
20 *-------------------------------------------------------------------------
26 #include "postgres_fe.h"
33 #define atooid(x) ((Oid) strtoul((x), NULL, 10))
34 #define oidcmp(x,y) ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) )
35 #define oideq(x,y) ( (x) == (y) )
36 #define oidle(x,y) ( (x) <= (y) )
37 #define oidge(x,y) ( (x) >= (y) )
38 #define oidzero(x) ( (x) == 0 )
47 typedef enum _archiveFormat
57 typedef enum _archiveMode
64 typedef enum _teSection
66 SECTION_NONE = 1, /* COMMENTs, ACLs, etc; can be anywhere */
67 SECTION_PRE_DATA, /* stuff to be processed before data */
68 SECTION_DATA, /* TABLE DATA, BLOBS, BLOB COMMENTS */
69 SECTION_POST_DATA /* stuff to be processed after data */
76 DUMP_POST_DATA = 0x04,
77 DUMP_UNSECTIONED = 0xff
81 * We may want to have some more user-readable data, but in the mean
82 * time this gives us some abstraction and type checking.
87 char *remoteVersionStr; /* server's version string */
88 int remoteVersion; /* same in numeric form */
90 int minRemoteVersion; /* allowable range */
93 /* info needed for string escaping */
94 int encoding; /* libpq code for client_encoding */
95 bool std_strings; /* standard_conforming_strings */
98 bool exit_on_error; /* whether to exit on SQL errors... */
99 int n_errors; /* number of errors (if no die) */
101 /* The rest is private */
104 typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
106 typedef struct _restoreOptions
108 int createDB; /* Issue commands to create the database */
109 int noOwner; /* Don't try to match original object owner */
110 int noTablespace; /* Don't issue tablespace-related commands */
111 int disable_triggers; /* disable triggers during data-only
113 int use_setsessauth;/* Use SET SESSION AUTHORIZATION commands
114 * instead of OWNER TO */
115 int no_security_labels; /* Skip security label entries */
116 char *superuser; /* Username to use as superuser */
117 char *use_role; /* Issue SET ROLE to this */
146 int noDataForFailedTables;
147 enum trivalue promptPassword;
150 int suppressDumpWarnings; /* Suppress output of WARNING entries
155 bool *idWanted; /* array showing which dump IDs to emit */
159 * Main archiver interface.
163 /* Lets the archive know we have a DB connection to shutdown if it dies */
165 PGconn *ConnectDatabase(Archive *AH,
169 const char *username,
170 enum trivalue prompt_password);
172 /* Called to add a TOC entry */
173 extern void ArchiveEntry(Archive *AHX,
174 CatalogId catalogId, DumpId dumpId,
176 const char *namespace, const char *tablespace,
177 const char *owner, bool withOids,
178 const char *desc, teSection section,
180 const char *dropStmt, const char *copyStmt,
181 const DumpId *deps, int nDeps,
182 DataDumperPtr dumpFn, void *dumpArg);
184 /* Called to write *data* to the archive */
185 extern size_t WriteData(Archive *AH, const void *data, size_t dLen);
187 extern int StartBlob(Archive *AH, Oid oid);
188 extern int EndBlob(Archive *AH, Oid oid);
190 extern void CloseArchive(Archive *AH);
192 extern void RestoreArchive(Archive *AH, RestoreOptions *ropt);
194 /* Open an existing archive */
195 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
197 /* Create a new archive */
198 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
199 const int compression, ArchiveMode mode);
201 /* The --list option */
202 extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
204 extern RestoreOptions *NewRestoreOptions(void);
206 /* Rearrange and filter TOC entries */
207 extern void SortTocFromFile(Archive *AHX, RestoreOptions *ropt);
208 extern void InitDummyWantedList(Archive *AHX, RestoreOptions *ropt);
210 /* Convenience functions used only when writing DATA */
211 extern int archputs(const char *s, Archive *AH);
213 archprintf(Archive *AH, const char *fmt,...)
214 /* This extension allows gcc to check the format string */
215 __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
217 #define appendStringLiteralAH(buf,str,AH) \
218 appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
220 #endif /* PG_BACKUP_H */