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.
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 )
40 typedef enum _archiveFormat
49 typedef enum _archiveMode
57 * We may want to have some more user-readable data, but in the mean
58 * time this gives us some abstraction and type checking.
60 typedef struct _Archive
63 char *remoteVersionStr
; /* server's version string */
64 int remoteVersion
; /* same in numeric form */
66 int minRemoteVersion
; /* allowable range */
69 /* info needed for string escaping */
70 int encoding
; /* libpq code for client_encoding */
71 bool std_strings
; /* standard_conforming_strings */
74 bool exit_on_error
; /* whether to exit on SQL errors... */
75 int n_errors
; /* number of errors (if no die) */
77 /* The rest is private */
80 typedef int (*DataDumperPtr
) (Archive
*AH
, void *userArg
);
82 typedef struct _restoreOptions
84 int create
; /* Issue commands to create the database */
85 int noOwner
; /* Don't try to match original object owner */
86 int noTablespace
; /* Don't issue tablespace-related commands */
87 int disable_triggers
; /* disable triggers during data-only
89 int use_setsessauth
;/* Use SET SESSION AUTHORIZATION commands
90 * instead of OWNER TO */
91 char *superuser
; /* Username to use as superuser */
119 int noDataForFailedTables
;
123 int suppressDumpWarnings
; /* Suppress output of WARNING entries
127 bool *idWanted
; /* array showing which dump IDs to emit */
131 * Main archiver interface.
135 exit_horribly(Archive
*AH
, const char *modulename
, const char *fmt
,...)
136 __attribute__((format(printf
, 3, 4)));
139 /* Lets the archive know we have a DB connection to shutdown if it dies */
141 PGconn
*ConnectDatabase(Archive
*AH
,
145 const char *username
,
148 /* Called to add a TOC entry */
149 extern void ArchiveEntry(Archive
*AHX
,
150 CatalogId catalogId
, DumpId dumpId
,
152 const char *namespace, const char *tablespace
,
153 const char *owner
, bool withOids
,
154 const char *desc
, const char *defn
,
155 const char *dropStmt
, const char *copyStmt
,
156 const DumpId
*deps
, int nDeps
,
157 DataDumperPtr dumpFn
, void *dumpArg
);
159 /* Called to write *data* to the archive */
160 extern size_t WriteData(Archive
*AH
, const void *data
, size_t dLen
);
162 extern int StartBlob(Archive
*AH
, Oid oid
);
163 extern int EndBlob(Archive
*AH
, Oid oid
);
165 extern void CloseArchive(Archive
*AH
);
167 extern void RestoreArchive(Archive
*AH
, RestoreOptions
*ropt
);
169 /* Open an existing archive */
170 extern Archive
*OpenArchive(const char *FileSpec
, const ArchiveFormat fmt
);
172 /* Create a new archive */
173 extern Archive
*CreateArchive(const char *FileSpec
, const ArchiveFormat fmt
,
174 const int compression
, ArchiveMode mode
);
176 /* The --list option */
177 extern void PrintTOCSummary(Archive
*AH
, RestoreOptions
*ropt
);
179 extern RestoreOptions
*NewRestoreOptions(void);
181 /* Rearrange and filter TOC entries */
182 extern void SortTocFromFile(Archive
*AHX
, RestoreOptions
*ropt
);
183 extern void InitDummyWantedList(Archive
*AHX
, RestoreOptions
*ropt
);
185 /* Convenience functions used only when writing DATA */
186 extern int archputs(const char *s
, Archive
*AH
);
188 archprintf(Archive
*AH
, const char *fmt
,...)
189 /* This extension allows gcc to check the format string */
190 __attribute__((format(printf
, 2, 3)));
192 #define appendStringLiteralAH(buf,str,AH) \
193 appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
195 #endif /* PG_BACKUP_H */