| 1 |
/*------------------------------------------------------------------------- |
| 2 |
* |
| 3 |
* pg_backup.h |
| 4 |
* |
| 5 |
* Public interface to the pg_dump archiver routines. |
| 6 |
* |
| 7 |
* See the headers to pg_restore for more details. |
| 8 |
* |
| 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. |
| 12 |
* |
| 13 |
* The author is not responsible for loss or damages that may |
| 14 |
* result from its use. |
| 15 |
* |
| 16 |
* |
| 17 |
* IDENTIFICATION |
| 18 |
* src/bin/pg_dump/pg_backup.h |
| 19 |
* |
| 20 |
*------------------------------------------------------------------------- |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef PG_BACKUP_H |
| 24 |
#define PG_BACKUP_H |
| 25 |
|
| 26 |
#include "common/compression.h" |
| 27 |
#include "common/file_utils.h" |
| 28 |
#include "fe_utils/simple_list.h" |
| 29 |
#include "libpq-fe.h" |
| 30 |
|
| 31 |
|
| 32 |
typedef enum trivalue |
| 33 |
{ |
| 34 |
TRI_DEFAULT, |
| 35 |
TRI_NO, |
| 36 |
TRI_YES, |
| 37 |
} trivalue; |
| 38 |
|
| 39 |
typedef enum _archiveFormat |
| 40 |
{ |
| 41 |
archUnknown = 0, |
| 42 |
archCustom = 1, |
| 43 |
archTar = 3, |
| 44 |
archNull = 4, |
| 45 |
archDirectory = 5, |
| 46 |
} ArchiveFormat; |
| 47 |
|
| 48 |
typedef enum _archiveMode |
| 49 |
{ |
| 50 |
archModeAppend, |
| 51 |
archModeWrite, |
| 52 |
archModeRead, |
| 53 |
} ArchiveMode; |
| 54 |
|
| 55 |
typedef enum _teSection |
| 56 |
{ |
| 57 |
SECTION_NONE = 1, /* comments, ACLs, etc; can be anywhere */ |
| 58 |
SECTION_PRE_DATA, /* stuff to be processed before data */ |
| 59 |
SECTION_DATA, /* table data, large objects, LO comments */ |
| 60 |
SECTION_POST_DATA, /* stuff to be processed after data */ |
| 61 |
} teSection; |
| 62 |
|
| 63 |
/* We need one enum entry per prepared query in pg_dump */ |
| 64 |
enum _dumpPreparedQueries |
| 65 |
{ |
| 66 |
PREPQUERY_DUMPAGG, |
| 67 |
PREPQUERY_DUMPBASETYPE, |
| 68 |
PREPQUERY_DUMPCOMPOSITETYPE, |
| 69 |
PREPQUERY_DUMPDOMAIN, |
| 70 |
PREPQUERY_DUMPENUMTYPE, |
| 71 |
PREPQUERY_DUMPFUNC, |
| 72 |
PREPQUERY_DUMPOPR, |
| 73 |
PREPQUERY_DUMPRANGETYPE, |
| 74 |
PREPQUERY_DUMPTABLEATTACH, |
| 75 |
PREPQUERY_GETATTRIBUTESTATS, |
| 76 |
PREPQUERY_GETCOLUMNACLS, |
| 77 |
PREPQUERY_GETDOMAINCONSTRAINTS, |
| 78 |
}; |
| 79 |
|
| 80 |
#define NUM_PREP_QUERIES (PREPQUERY_GETDOMAINCONSTRAINTS + 1) |
| 81 |
|
| 82 |
/* Parameters needed by ConnectDatabase; same for dump and restore */ |
| 83 |
typedef struct _connParams |
| 84 |
{ |
| 85 |
/* These fields record the actual command line parameters */ |
| 86 |
char *dbname; /* this may be a connstring! */ |
| 87 |
char *pgport; |
| 88 |
char *pghost; |
| 89 |
char *username; |
| 90 |
trivalue promptPassword; |
| 91 |
/* If not NULL, this overrides the dbname obtained from command line */ |
| 92 |
/* (but *only* the DB name, not anything else in the connstring) */ |
| 93 |
char *override_dbname; |
| 94 |
} ConnParams; |
| 95 |
|
| 96 |
typedef struct _restoreOptions |
| 97 |
{ |
| 98 |
int createDB; /* Issue commands to create the database */ |
| 99 |
int noOwner; /* Don't try to match original object owner */ |
| 100 |
int noTableAm; /* Don't issue table-AM-related commands */ |
| 101 |
int noTablespace; /* Don't issue tablespace-related commands */ |
| 102 |
int disable_triggers; /* disable triggers during data-only |
| 103 |
* restore */ |
| 104 |
int use_setsessauth; /* Use SET SESSION AUTHORIZATION commands |
| 105 |
* instead of OWNER TO */ |
| 106 |
char *superuser; /* Username to use as superuser */ |
| 107 |
char *use_role; /* Issue SET ROLE to this */ |
| 108 |
int dropSchema; |
| 109 |
int disable_dollar_quoting; |
| 110 |
int dump_inserts; /* 0 = COPY, otherwise rows per INSERT */ |
| 111 |
int column_inserts; |
| 112 |
int if_exists; |
| 113 |
int no_comments; /* Skip comments */ |
| 114 |
int no_policies; /* Skip row security policies */ |
| 115 |
int no_publications; /* Skip publication entries */ |
| 116 |
int no_security_labels; /* Skip security label entries */ |
| 117 |
int no_subscriptions; /* Skip subscription entries */ |
| 118 |
int strict_names; |
| 119 |
|
| 120 |
const char *filename; |
| 121 |
int dumpSections; |
| 122 |
int verbose; |
| 123 |
int aclsSkip; |
| 124 |
const char *lockWaitTimeout; |
| 125 |
int include_everything; |
| 126 |
|
| 127 |
int tocSummary; |
| 128 |
char *tocFile; |
| 129 |
int format; |
| 130 |
char *formatName; |
| 131 |
|
| 132 |
int selTypes; |
| 133 |
int selIndex; |
| 134 |
int selFunction; |
| 135 |
int selTrigger; |
| 136 |
int selTable; |
| 137 |
SimpleStringList indexNames; |
| 138 |
SimpleStringList functionNames; |
| 139 |
SimpleStringList schemaNames; |
| 140 |
SimpleStringList schemaExcludeNames; |
| 141 |
SimpleStringList triggerNames; |
| 142 |
SimpleStringList tableNames; |
| 143 |
|
| 144 |
int useDB; |
| 145 |
ConnParams cparams; /* parameters to use if useDB */ |
| 146 |
|
| 147 |
int noDataForFailedTables; |
| 148 |
int exit_on_error; |
| 149 |
pg_compress_specification compression_spec; /* Specification for |
| 150 |
* compression */ |
| 151 |
int suppressDumpWarnings; /* Suppress output of WARNING entries |
| 152 |
* to stderr */ |
| 153 |
|
| 154 |
bool single_txn; /* restore all TOCs in one transaction */ |
| 155 |
int txn_size; /* restore this many TOCs per txn, if > 0 */ |
| 156 |
|
| 157 |
bool *idWanted; /* array showing which dump IDs to emit */ |
| 158 |
int enable_row_security; |
| 159 |
int sequence_data; /* dump sequence data even in schema-only mode */ |
| 160 |
int binary_upgrade; |
| 161 |
|
| 162 |
/* flags derived from the user-settable flags */ |
| 163 |
bool dumpSchema; |
| 164 |
bool dumpData; |
| 165 |
bool dumpStatistics; |
| 166 |
|
| 167 |
char *restrict_key; |
| 168 |
} RestoreOptions; |
| 169 |
|
| 170 |
typedef struct _dumpOptions |
| 171 |
{ |
| 172 |
ConnParams cparams; |
| 173 |
|
| 174 |
int binary_upgrade; |
| 175 |
|
| 176 |
/* various user-settable parameters */ |
| 177 |
int dumpSections; /* bitmask of chosen sections */ |
| 178 |
bool aclsSkip; |
| 179 |
const char *lockWaitTimeout; |
| 180 |
int dump_inserts; /* 0 = COPY, otherwise rows per INSERT */ |
| 181 |
|
| 182 |
/* flags for various command-line long options */ |
| 183 |
int disable_dollar_quoting; |
| 184 |
int column_inserts; |
| 185 |
int if_exists; |
| 186 |
int no_comments; |
| 187 |
int no_policies; /* Skip row security policies */ |
| 188 |
int no_publications; |
| 189 |
int no_security_labels; |
| 190 |
int no_subscriptions; |
| 191 |
int no_toast_compression; |
| 192 |
int no_unlogged_table_data; |
| 193 |
int serializable_deferrable; |
| 194 |
int disable_triggers; |
| 195 |
int outputNoTableAm; |
| 196 |
int outputNoTablespaces; |
| 197 |
int use_setsessauth; |
| 198 |
int enable_row_security; |
| 199 |
int load_via_partition_root; |
| 200 |
|
| 201 |
/* default, if no "inclusion" switches appear, is to dump everything */ |
| 202 |
bool include_everything; |
| 203 |
|
| 204 |
int outputClean; |
| 205 |
int outputCreateDB; |
| 206 |
bool outputLOs; |
| 207 |
bool dontOutputLOs; |
| 208 |
int outputNoOwner; |
| 209 |
char *outputSuperuser; |
| 210 |
|
| 211 |
int sequence_data; /* dump sequence data even in schema-only mode */ |
| 212 |
int do_nothing; |
| 213 |
|
| 214 |
/* flags derived from the user-settable flags */ |
| 215 |
bool dumpSchema; |
| 216 |
bool dumpData; |
| 217 |
bool dumpStatistics; |
| 218 |
|
| 219 |
char *restrict_key; |
| 220 |
} DumpOptions; |
| 221 |
|
| 222 |
/* |
| 223 |
* We may want to have some more user-readable data, but in the mean |
| 224 |
* time this gives us some abstraction and type checking. |
| 225 |
*/ |
| 226 |
typedef struct Archive |
| 227 |
{ |
| 228 |
DumpOptions *dopt; /* options, if dumping */ |
| 229 |
RestoreOptions *ropt; /* options, if restoring */ |
| 230 |
|
| 231 |
int verbose; |
| 232 |
char *remoteVersionStr; /* server's version string */ |
| 233 |
int remoteVersion; /* same in numeric form */ |
| 234 |
bool isStandby; /* is server a standby node */ |
| 235 |
|
| 236 |
int minRemoteVersion; /* allowable range */ |
| 237 |
int maxRemoteVersion; |
| 238 |
|
| 239 |
int numWorkers; /* number of parallel processes */ |
| 240 |
char *sync_snapshot_id; /* sync snapshot id for parallel operation */ |
| 241 |
|
| 242 |
/* info needed for string escaping */ |
| 243 |
int encoding; /* libpq code for client_encoding */ |
| 244 |
bool std_strings; /* standard_conforming_strings */ |
| 245 |
|
| 246 |
/* other important stuff */ |
| 247 |
char *searchpath; /* search_path to set during restore */ |
| 248 |
char *use_role; /* Issue SET ROLE to this */ |
| 249 |
|
| 250 |
/* error handling */ |
| 251 |
bool exit_on_error; /* whether to exit on SQL errors... */ |
| 252 |
int n_errors; /* number of errors (if no die) */ |
| 253 |
|
| 254 |
/* prepared-query status */ |
| 255 |
bool *is_prepared; /* indexed by enum _dumpPreparedQueries */ |
| 256 |
|
| 257 |
/* The rest is private */ |
| 258 |
} Archive; |
| 259 |
|
| 260 |
|
| 261 |
/* |
| 262 |
* pg_dump uses two different mechanisms for identifying database objects: |
| 263 |
* |
| 264 |
* CatalogId represents an object by the tableoid and oid of its defining |
| 265 |
* entry in the system catalogs. We need this to interpret pg_depend entries, |
| 266 |
* for instance. |
| 267 |
* |
| 268 |
* DumpId is a simple sequential integer counter assigned as dumpable objects |
| 269 |
* are identified during a pg_dump run. We use DumpId internally in preference |
| 270 |
* to CatalogId for two reasons: it's more compact, and we can assign DumpIds |
| 271 |
* to "objects" that don't have a separate CatalogId. For example, it is |
| 272 |
* convenient to consider a table, its data, and its ACL as three separate |
| 273 |
* dumpable "objects" with distinct DumpIds --- this lets us reason about the |
| 274 |
* order in which to dump these things. |
| 275 |
*/ |
| 276 |
|
| 277 |
typedef struct |
| 278 |
{ |
| 279 |
/* Note: this struct must not contain any unused bytes */ |
| 280 |
Oid tableoid; |
| 281 |
Oid oid; |
| 282 |
} CatalogId; |
| 283 |
|
| 284 |
typedef int DumpId; |
| 285 |
|
| 286 |
#define InvalidDumpId 0 |
| 287 |
|
| 288 |
/* |
| 289 |
* Function pointer prototypes for assorted callback methods. |
| 290 |
*/ |
| 291 |
typedef void (*SetupWorkerPtrType) (Archive *AH); |
| 292 |
|
| 293 |
/* |
| 294 |
* Main archiver interface. |
| 295 |
*/ |
| 296 |
|
| 297 |
extern void ConnectDatabaseAhx(Archive *AHX, |
| 298 |
const ConnParams *cparams, |
| 299 |
bool isReconnect); |
| 300 |
extern void DisconnectDatabase(Archive *AHX); |
| 301 |
extern PGconn *GetConnection(Archive *AHX); |
| 302 |
|
| 303 |
/* Called to write *data* to the archive */ |
| 304 |
extern void WriteData(Archive *AHX, const void *data, size_t dLen); |
| 305 |
|
| 306 |
extern int StartLO(Archive *AHX, Oid oid); |
| 307 |
extern int EndLO(Archive *AHX, Oid oid); |
| 308 |
|
| 309 |
extern void CloseArchive(Archive *AHX); |
| 310 |
|
| 311 |
extern void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt); |
| 312 |
|
| 313 |
extern void ProcessArchiveRestoreOptions(Archive *AHX); |
| 314 |
|
| 315 |
extern void RestoreArchive(Archive *AHX); |
| 316 |
|
| 317 |
/* Open an existing archive */ |
| 318 |
extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt); |
| 319 |
|
| 320 |
/* Create a new archive */ |
| 321 |
extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt, |
| 322 |
const pg_compress_specification compression_spec, |
| 323 |
bool dosync, ArchiveMode mode, |
| 324 |
SetupWorkerPtrType setupDumpWorker, |
| 325 |
DataDirSyncMethod sync_method); |
| 326 |
|
| 327 |
/* The --list option */ |
| 328 |
extern void PrintTOCSummary(Archive *AHX); |
| 329 |
|
| 330 |
extern RestoreOptions *NewRestoreOptions(void); |
| 331 |
|
| 332 |
extern DumpOptions *NewDumpOptions(void); |
| 333 |
extern void InitDumpOptions(DumpOptions *opts); |
| 334 |
extern DumpOptions *dumpOptionsFromRestoreOptions(RestoreOptions *ropt); |
| 335 |
|
| 336 |
/* Rearrange and filter TOC entries */ |
| 337 |
extern void SortTocFromFile(Archive *AHX); |
| 338 |
|
| 339 |
/* Convenience functions used only when writing DATA */ |
| 340 |
extern void archputs(const char *s, Archive *AH); |
| 341 |
extern int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2, 3); |
| 342 |
|
| 343 |
#define appendStringLiteralAH(buf,str,AH) \ |
| 344 |
appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings) |
| 345 |
|
| 346 |
#endif /* PG_BACKUP_H */ |