Force a checkpoint in CREATE DATABASE before starting to copy the files,
[PostgreSQL.git] / src / bin / pg_dump / pg_backup.h
blobc57bb22d9aaa8e31c571b2b43bece37a6e01bf0f
1 /*-------------------------------------------------------------------------
3 * pg_backup.h
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.
17 * IDENTIFICATION
18 * $PostgreSQL$
20 *-------------------------------------------------------------------------
23 #ifndef PG_BACKUP_H
24 #define PG_BACKUP_H
26 #include "postgres_fe.h"
28 #include "pg_dump.h"
30 #include "libpq-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
42 archUnknown = 0,
43 archCustom = 1,
44 archFiles = 2,
45 archTar = 3,
46 archNull = 4
47 } ArchiveFormat;
49 typedef enum _archiveMode
51 archModeAppend,
52 archModeWrite,
53 archModeRead
54 } 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
62 int verbose;
63 char *remoteVersionStr; /* server's version string */
64 int remoteVersion; /* same in numeric form */
66 int minRemoteVersion; /* allowable range */
67 int maxRemoteVersion;
69 /* info needed for string escaping */
70 int encoding; /* libpq code for client_encoding */
71 bool std_strings; /* standard_conforming_strings */
73 /* error handling */
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 */
78 } Archive;
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
88 * restore */
89 int use_setsessauth;/* Use SET SESSION AUTHORIZATION commands
90 * instead of OWNER TO */
91 char *superuser; /* Username to use as superuser */
92 int dataOnly;
93 int dropSchema;
94 char *filename;
95 int schemaOnly;
96 int verbose;
97 int aclsSkip;
98 int tocSummary;
99 char *tocFile;
100 int format;
101 char *formatName;
103 int selTypes;
104 int selIndex;
105 int selFunction;
106 int selTrigger;
107 int selTable;
108 char *indexNames;
109 char *functionNames;
110 char *tableNames;
111 char *schemaNames;
112 char *triggerNames;
114 int useDB;
115 char *dbname;
116 char *pgport;
117 char *pghost;
118 char *username;
119 int noDataForFailedTables;
120 int requirePassword;
121 int exit_on_error;
122 int compression;
123 int suppressDumpWarnings; /* Suppress output of WARNING entries
124 * to stderr */
125 bool single_txn;
127 bool *idWanted; /* array showing which dump IDs to emit */
128 } RestoreOptions;
131 * Main archiver interface.
134 extern void
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,
142 const char *dbname,
143 const char *pghost,
144 const char *pgport,
145 const char *username,
146 int reqPwd);
148 /* Called to add a TOC entry */
149 extern void ArchiveEntry(Archive *AHX,
150 CatalogId catalogId, DumpId dumpId,
151 const char *tag,
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);
187 extern int
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 */