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 * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.42 2006/08/01 18:21:44 momjian Exp $
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
50 * We may want to have some more user-readable data, but in the mean
51 * time this gives us some abstraction and type checking.
53 typedef struct _Archive
56 char *remoteVersionStr; /* server's version string */
57 int remoteVersion; /* same in numeric form */
59 int minRemoteVersion; /* allowable range */
62 /* info needed for string escaping */
63 int encoding; /* libpq code for client_encoding */
64 bool std_strings; /* standard_conforming_strings */
67 bool exit_on_error; /* whether to exit on SQL errors... */
68 int n_errors; /* number of errors (if no die) */
70 /* The rest is private */
73 typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
75 typedef struct _restoreOptions
77 int create; /* Issue commands to create the database */
78 int noOwner; /* Don't try to match original object owner */
79 int disable_triggers; /* disable triggers during data-only
81 int use_setsessauth;/* Use SET SESSION AUTHORIZATION commands
82 * instead of OWNER TO */
83 char *superuser; /* Username to use as superuser */
112 int noDataForFailedTables;
120 int suppressDumpWarnings; /* Suppress output of WARNING entries
127 * Main archiver interface.
131 exit_horribly(Archive *AH, const char *modulename, const char *fmt,...)
132 __attribute__((format(printf, 3, 4)));
135 /* Lets the archive know we have a DB connection to shutdown if it dies */
137 PGconn *ConnectDatabase(Archive *AH,
141 const char *username,
143 const int ignoreVersion);
146 /* Called to add a TOC entry */
147 extern void ArchiveEntry(Archive *AHX,
148 CatalogId catalogId, DumpId dumpId,
150 const char *namespace, const char *tablespace,
151 const char *owner, bool withOids,
152 const char *desc, const char *defn,
153 const char *dropStmt, const char *copyStmt,
154 const DumpId *deps, int nDeps,
155 DataDumperPtr dumpFn, void *dumpArg);
157 /* Called to write *data* to the archive */
158 extern size_t WriteData(Archive *AH, const void *data, size_t dLen);
160 extern int StartBlob(Archive *AH, Oid oid);
161 extern int EndBlob(Archive *AH, Oid oid);
163 extern void CloseArchive(Archive *AH);
165 extern void RestoreArchive(Archive *AH, RestoreOptions *ropt);
167 /* Open an existing archive */
168 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
170 /* Create a new archive */
171 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
172 const int compression);
174 /* The --list option */
175 extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
177 extern RestoreOptions *NewRestoreOptions(void);
179 /* Rearrange TOC entries */
180 extern void SortTocFromFile(Archive *AH, RestoreOptions *ropt);
182 /* Convenience functions used only when writing DATA */
183 extern int archputs(const char *s, Archive *AH);
185 archprintf(Archive *AH, const char *fmt,...)
186 /* This extension allows gcc to check the format string */
187 __attribute__((format(printf, 2, 3)));
189 #define appendStringLiteralAH(buf,str,AH) \
190 appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
192 #endif /* PG_BACKUP_H */