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 * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.17 2001/10/28 06:25:58 momjian Exp $
20 * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
25 * Modifications - 28-Jul-2000 - pjw@rhyme.com.au (1.45)
27 * Added --create, --no-owner, --superuser, --no-reconnect (pg_dump & pg_restore)
28 * Added code to dump 'Create Schema' statement (pg_dump)
29 * Don't bother to disable/enable triggers if we don't have a superuser (pg_restore)
30 * Cleaned up code for reconnecting to database.
31 * Force a reconnect as superuser before enabling/disabling triggers.
33 * Modifications - 31-Jul-2000 - pjw@rhyme.com.au (1.46, 1.47)
34 * Added & Removed --throttle (pg_dump)
35 * Fixed minor bug in language dumping code: expbuffres were not being reset.
36 * Fixed version number initialization in _allocAH (pg_backup_archiver.c)
37 * Added second connection when restoring BLOBs to allow temp. table to survive
38 * (db reconnection causes temp tables to be lost).
40 *-------------------------------------------------------------------------
46 #include "postgres_fe.h"
50 #define atooid(x) ((Oid) strtoul((x), NULL, 10))
51 #define oidcmp(x,y) ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) )
52 #define oideq(x,y) ( (x) == (y) )
53 #define oidle(x,y) ( (x) <= (y) )
54 #define oidge(x,y) ( (x) >= (y) )
55 #define oidzero(x) ( (x) == 0 )
57 typedef enum _archiveFormat
67 * We may want to have so user-readbale data, but in the mean
68 * time this gives us some abstraction and type checking.
70 typedef struct _Archive
76 /* The rest is private */
79 typedef int (*DataDumperPtr) (Archive *AH, char *oid, void *userArg);
81 typedef struct _restoreOptions
83 int create; /* Issue commands to create the database */
84 int noOwner; /* Don't reconnect to database to match
85 * original object owner */
86 int noReconnect; /* Don't reconnect to database under any
88 int use_setsessauth;/* use SET SESSSION AUTHORIZATION instead
90 char *superuser; /* Username to use as superuser */
127 int suppressDumpWarnings; /* Suppress output of WARNING
128 * entries to stderr */
132 * Main archiver interface.
136 exit_horribly(Archive *AH, const char *modulename, const char *fmt,...)
137 __attribute__((format(printf, 3, 4)));
140 simple_prompt(const char *prompt, int maxlen, bool echo);
142 /* Lets the archibe know we have a DB connection to shutdown if it dies */
144 PGconn *ConnectDatabase(Archive *AH,
148 const char *username,
150 const int ignoreVersion);
153 /* Called to add a TOC entry */
154 extern void ArchiveEntry(Archive *AH, const char *oid, const char *name,
155 const char *desc, const char *((*deps)[]), const char *defn,
156 const char *dropStmt, const char *copyStmt, const char *owner,
157 DataDumperPtr dumpFn, void *dumpArg);
159 /* Called to write *data* to the archive */
160 extern int WriteData(Archive *AH, const void *data, int dLen);
163 extern int StartBlobs(Archive* AH);
164 extern int EndBlobs(Archive* AH);
166 extern int StartBlob(Archive *AH, Oid oid);
167 extern int EndBlob(Archive *AH, Oid oid);
169 extern void CloseArchive(Archive *AH);
171 extern void RestoreArchive(Archive *AH, RestoreOptions *ropt);
173 /* Open an existing archive */
174 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
176 /* Create a new archive */
177 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
178 const int compression);
180 /* The --list option */
181 extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
183 extern RestoreOptions *NewRestoreOptions(void);
185 /* Rearrange TOC entries */
186 extern void MoveToStart(Archive *AH, char *oType);
187 extern void MoveToEnd(Archive *AH, char *oType);
188 extern void SortTocByOID(Archive *AH);
189 extern void SortTocByID(Archive *AH);
190 extern void SortTocFromFile(Archive *AH, RestoreOptions *ropt);
192 /* Convenience functions used only when writing DATA */
193 extern int archputs(const char *s, Archive *AH);
194 extern int archputc(const char c, Archive *AH);
196 archprintf(Archive *AH, const char *fmt,...)
197 /* This extension allows gcc to check the format string */
198 __attribute__((format(printf, 2, 3)));