PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_backup.h File Reference
#include "common/compression.h"
#include "common/file_utils.h"
#include "fe_utils/simple_list.h"
#include "libpq-fe.h"
Include dependency graph for pg_backup.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _connParams
 
struct  _restoreOptions
 
struct  _dumpOptions
 
struct  Archive
 
struct  CatalogId
 

Macros

#define NUM_PREP_QUERIES   (PREPQUERY_GETDOMAINCONSTRAINTS + 1)
 
#define InvalidDumpId   0
 
#define appendStringLiteralAH(buf, str, AH)    appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
 

Typedefs

typedef enum trivalue trivalue
 
typedef enum _archiveFormat ArchiveFormat
 
typedef enum _archiveMode ArchiveMode
 
typedef enum _teSection teSection
 
typedef struct _connParams ConnParams
 
typedef struct _restoreOptions RestoreOptions
 
typedef struct _dumpOptions DumpOptions
 
typedef struct Archive Archive
 
typedef int DumpId
 
typedef void(* SetupWorkerPtrType) (Archive *AH)
 

Enumerations

enum  trivalue { TRI_DEFAULT , TRI_NO , TRI_YES }
 
enum  _archiveFormat {
  archUnknown = 0 , archCustom = 1 , archTar = 3 , archNull = 4 ,
  archDirectory = 5
}
 
enum  _archiveMode { archModeAppend , archModeWrite , archModeRead }
 
enum  _teSection { SECTION_NONE = 1 , SECTION_PRE_DATA , SECTION_DATA , SECTION_POST_DATA }
 
enum  _dumpPreparedQueries {
  PREPQUERY_DUMPAGG , PREPQUERY_DUMPBASETYPE , PREPQUERY_DUMPCOMPOSITETYPE , PREPQUERY_DUMPDOMAIN ,
  PREPQUERY_DUMPENUMTYPE , PREPQUERY_DUMPEXTSTATSOBJSTATS , PREPQUERY_DUMPFUNC , PREPQUERY_DUMPOPR ,
  PREPQUERY_DUMPRANGETYPE , PREPQUERY_DUMPTABLEATTACH , PREPQUERY_GETATTRIBUTESTATS , PREPQUERY_GETCOLUMNACLS ,
  PREPQUERY_GETDOMAINCONSTRAINTS
}
 

Functions

void ConnectDatabaseAhx (Archive *AHX, const ConnParams *cparams, bool isReconnect)
 
void DisconnectDatabase (Archive *AHX)
 
PGconnGetConnection (Archive *AHX)
 
void WriteData (Archive *AHX, const void *data, size_t dLen)
 
int StartLO (Archive *AHX, Oid oid)
 
int EndLO (Archive *AHX, Oid oid)
 
void CloseArchive (Archive *AHX)
 
void SetArchiveOptions (Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
 
void ProcessArchiveRestoreOptions (Archive *AHX)
 
void RestoreArchive (Archive *AHX)
 
ArchiveOpenArchive (const char *FileSpec, const ArchiveFormat fmt)
 
ArchiveCreateArchive (const char *FileSpec, const ArchiveFormat fmt, const pg_compress_specification compression_spec, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupDumpWorker, DataDirSyncMethod sync_method)
 
void PrintTOCSummary (Archive *AHX)
 
RestoreOptionsNewRestoreOptions (void)
 
DumpOptionsNewDumpOptions (void)
 
void InitDumpOptions (DumpOptions *opts)
 
DumpOptionsdumpOptionsFromRestoreOptions (RestoreOptions *ropt)
 
void SortTocFromFile (Archive *AHX)
 
void archputs (const char *s, Archive *AH)
 
int archprintf (Archive *AH, const char *fmt,...) pg_attribute_printf(2
 

Macro Definition Documentation

◆ appendStringLiteralAH

#define appendStringLiteralAH (   buf,
  str,
  AH 
)     appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)

Definition at line 344 of file pg_backup.h.

◆ InvalidDumpId

#define InvalidDumpId   0

Definition at line 287 of file pg_backup.h.

◆ NUM_PREP_QUERIES

#define NUM_PREP_QUERIES   (PREPQUERY_GETDOMAINCONSTRAINTS + 1)

Definition at line 81 of file pg_backup.h.

Typedef Documentation

◆ Archive

◆ ArchiveFormat

◆ ArchiveMode

◆ ConnParams

◆ DumpId

Definition at line 285 of file pg_backup.h.

◆ DumpOptions

◆ RestoreOptions

◆ SetupWorkerPtrType

typedef void(* SetupWorkerPtrType) (Archive *AH)

Definition at line 292 of file pg_backup.h.

◆ teSection

◆ trivalue

Enumeration Type Documentation

◆ _archiveFormat

Enumerator
archUnknown 
archCustom 
archTar 
archNull 
archDirectory 

Definition at line 39 of file pg_backup.h.

40{
41 archUnknown = 0,
42 archCustom = 1,
43 archTar = 3,
44 archNull = 4,
45 archDirectory = 5,
enum _archiveFormat ArchiveFormat
@ archUnknown
Definition pg_backup.h:41
@ archTar
Definition pg_backup.h:43
@ archCustom
Definition pg_backup.h:42
@ archDirectory
Definition pg_backup.h:45
@ archNull
Definition pg_backup.h:44

◆ _archiveMode

Enumerator
archModeAppend 
archModeWrite 
archModeRead 

Definition at line 48 of file pg_backup.h.

49{
@ archModeWrite
Definition pg_backup.h:51
@ archModeAppend
Definition pg_backup.h:50
@ archModeRead
Definition pg_backup.h:52
enum _archiveMode ArchiveMode

◆ _dumpPreparedQueries

Enumerator
PREPQUERY_DUMPAGG 
PREPQUERY_DUMPBASETYPE 
PREPQUERY_DUMPCOMPOSITETYPE 
PREPQUERY_DUMPDOMAIN 
PREPQUERY_DUMPENUMTYPE 
PREPQUERY_DUMPEXTSTATSOBJSTATS 
PREPQUERY_DUMPFUNC 
PREPQUERY_DUMPOPR 
PREPQUERY_DUMPRANGETYPE 
PREPQUERY_DUMPTABLEATTACH 
PREPQUERY_GETATTRIBUTESTATS 
PREPQUERY_GETCOLUMNACLS 
PREPQUERY_GETDOMAINCONSTRAINTS 

Definition at line 64 of file pg_backup.h.

65{
79};
@ PREPQUERY_DUMPFUNC
Definition pg_backup.h:72
@ PREPQUERY_DUMPTABLEATTACH
Definition pg_backup.h:75
@ PREPQUERY_DUMPBASETYPE
Definition pg_backup.h:67
@ PREPQUERY_DUMPRANGETYPE
Definition pg_backup.h:74
@ PREPQUERY_DUMPOPR
Definition pg_backup.h:73
@ PREPQUERY_DUMPEXTSTATSOBJSTATS
Definition pg_backup.h:71
@ PREPQUERY_GETATTRIBUTESTATS
Definition pg_backup.h:76
@ PREPQUERY_DUMPDOMAIN
Definition pg_backup.h:69
@ PREPQUERY_DUMPCOMPOSITETYPE
Definition pg_backup.h:68
@ PREPQUERY_DUMPAGG
Definition pg_backup.h:66
@ PREPQUERY_GETCOLUMNACLS
Definition pg_backup.h:77
@ PREPQUERY_GETDOMAINCONSTRAINTS
Definition pg_backup.h:78
@ PREPQUERY_DUMPENUMTYPE
Definition pg_backup.h:70

◆ _teSection

Enumerator
SECTION_NONE 
SECTION_PRE_DATA 
SECTION_DATA 
SECTION_POST_DATA 

Definition at line 55 of file pg_backup.h.

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;
@ SECTION_NONE
Definition pg_backup.h:57
@ SECTION_POST_DATA
Definition pg_backup.h:60
@ SECTION_PRE_DATA
Definition pg_backup.h:58
@ SECTION_DATA
Definition pg_backup.h:59
enum _teSection teSection

◆ trivalue

Enumerator
TRI_DEFAULT 
TRI_NO 
TRI_YES 

Definition at line 32 of file pg_backup.h.

33{
35 TRI_NO,
36 TRI_YES,
37} trivalue;
trivalue
Definition pg_backup.h:33
@ TRI_YES
Definition pg_backup.h:36
@ TRI_DEFAULT
Definition pg_backup.h:34
@ TRI_NO
Definition pg_backup.h:35

Function Documentation

◆ archprintf()

int archprintf ( Archive AH,
const char fmt,
  ... 
)
extern

◆ archputs()

void archputs ( const char s,
Archive AH 
)
extern

Definition at line 1652 of file pg_backup_archiver.c.

1653{
1654 WriteData(AH, s, strlen(s));
1655}
void WriteData(Archive *AHX, const void *data, size_t dLen)
static int fb(int x)

References fb(), and WriteData().

Referenced by dumpTableData_insert().

◆ CloseArchive()

void CloseArchive ( Archive AHX)
extern

Definition at line 263 of file pg_backup_archiver.c.

264{
265 ArchiveHandle *AH = (ArchiveHandle *) AHX;
266
267 AH->ClosePtr(AH);
268
269 /* Close the output */
270 errno = 0;
271 if (!EndCompressFileHandle(AH->OF))
272 pg_fatal("could not close output file: %m");
273}
bool EndCompressFileHandle(CompressFileHandle *CFH)
#define pg_fatal(...)
ClosePtrType ClosePtr

References _archiveHandle::ClosePtr, EndCompressFileHandle(), fb(), _archiveHandle::OF, and pg_fatal.

Referenced by main().

◆ ConnectDatabaseAhx()

void ConnectDatabaseAhx ( Archive AHX,
const ConnParams cparams,
bool  isReconnect 
)
extern

Definition at line 109 of file pg_backup_db.c.

112{
113 ArchiveHandle *AH = (ArchiveHandle *) AHX;
114 trivalue prompt_password;
115 char *password;
116
117 if (AH->connection)
118 pg_fatal("already connected to a database");
119
120 /* Never prompt for a password during a reconnection */
121 prompt_password = isReconnect ? TRI_NO : cparams->promptPassword;
122
124
125 if (prompt_password == TRI_YES && password == NULL)
126 password = simple_prompt("Password: ", false);
127
128 AH->connection = ConnectDatabase(cparams->dbname, NULL, cparams->pghost,
129 cparams->pgport, cparams->username,
130 prompt_password, true,
132
133 /* Start strict; later phases may override this. */
136
137 if (password && password != AH->savedPassword)
138 free(password);
139
140 /*
141 * We want to remember connection's actual password, whether or not we got
142 * it by prompting. So we don't just store the password variable.
143 */
145 {
146 free(AH->savedPassword);
148 }
149
150 /* check for version mismatch */
152
154
155 /* arrange for SIGINT to issue a query cancel on this connection */
157}
void set_archive_cancel_info(ArchiveHandle *AH, PGconn *conn)
Definition parallel.c:732
#define ALWAYS_SECURE_SEARCH_PATH_SQL
Definition connect.h:25
PGconn * ConnectDatabase(const char *dbname, const char *connection_string, const char *pghost, const char *pgport, const char *pguser, trivalue prompt_password, bool fail_on_error, const char *progname, const char **connstr, int *server_version, char *password, char *override_dbname)
Definition connectdb.c:40
int PQconnectionUsedPassword(const PGconn *conn)
char * PQpass(const PGconn *conn)
PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
char * pg_strdup(const char *in)
Definition fe_memutils.c:91
#define PQclear
const char * progname
Definition main.c:44
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
static void _check_database_version(ArchiveHandle *AH)
static void notice_processor(void *arg, const char *message)
#define free(a)
char * simple_prompt(const char *prompt, bool echo)
Definition sprompt.c:38
static char * password
Definition streamutil.c:51
char * override_dbname
Definition pg_backup.h:94
char * pgport
Definition pg_backup.h:88
char * pghost
Definition pg_backup.h:89
trivalue promptPassword
Definition pg_backup.h:91
char * username
Definition pg_backup.h:90
char * dbname
Definition pg_backup.h:87
trivalue
Definition vacuumlo.c:35
@ TRI_YES
Definition vacuumlo.c:38
@ TRI_NO
Definition vacuumlo.c:37

References _check_database_version(), ALWAYS_SECURE_SEARCH_PATH_SQL, ConnectDatabase(), _archiveHandle::connection, _connParams::dbname, ExecuteSqlQueryForSingleRow(), fb(), free, notice_processor(), _connParams::override_dbname, password, pg_fatal, pg_strdup(), _connParams::pghost, _connParams::pgport, PQclear, PQconnectionUsedPassword(), PQpass(), PQsetNoticeProcessor(), progname, _connParams::promptPassword, _archiveHandle::savedPassword, set_archive_cancel_info(), simple_prompt(), TRI_NO, TRI_YES, and _connParams::username.

Referenced by CloneArchive(), main(), ReconnectToServer(), restore_toc_entries_postfork(), and RestoreArchive().

◆ CreateArchive()

Archive * CreateArchive ( const char FileSpec,
const ArchiveFormat  fmt,
const pg_compress_specification  compression_spec,
bool  dosync,
ArchiveMode  mode,
SetupWorkerPtrType  setupDumpWorker,
DataDirSyncMethod  sync_method 
)
extern

Definition at line 232 of file pg_backup_archiver.c.

238{
239 ArchiveHandle *AH = _allocAH(FileSpec, fmt, compression_spec,
241
242 return (Archive *) AH;
243}
static DataDirSyncMethod sync_method
Definition initdb.c:170
static ArchiveHandle * _allocAH(const char *FileSpec, const ArchiveFormat fmt, const pg_compress_specification compression_spec, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupWorkerPtr, DataDirSyncMethod sync_method)
static PgChecksumMode mode
static bool dosync
Definition pg_dump.c:152
static void setupDumpWorker(Archive *AH)
Definition pg_dump.c:1580

References _allocAH(), dosync, fb(), mode, setupDumpWorker(), and sync_method.

Referenced by main().

◆ DisconnectDatabase()

void DisconnectDatabase ( Archive AHX)
extern

Definition at line 164 of file pg_backup_db.c.

165{
166 ArchiveHandle *AH = (ArchiveHandle *) AHX;
167 char errbuf[1];
168
169 if (!AH->connection)
170 return;
171
172 if (AH->connCancel)
173 {
174 /*
175 * If we have an active query, send a cancel before closing, ignoring
176 * any errors. This is of no use for a normal exit, but might be
177 * helpful during pg_fatal().
178 */
180 (void) PQcancel(AH->connCancel, errbuf, sizeof(errbuf));
181
182 /*
183 * Prevent signal handler from sending a cancel after this.
184 */
186 }
187
188 PQfinish(AH->connection);
189 AH->connection = NULL;
190}
int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize)
Definition fe-cancel.c:548
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
void PQfinish(PGconn *conn)
@ PQTRANS_ACTIVE
Definition libpq-fe.h:154
PGcancel *volatile connCancel

References _archiveHandle::connCancel, _archiveHandle::connection, fb(), PQcancel(), PQfinish(), PQTRANS_ACTIVE, PQtransactionStatus(), and set_archive_cancel_info().

Referenced by archive_close_connection(), restore_toc_entries_prefork(), RestoreArchive(), and RunWorker().

◆ dumpOptionsFromRestoreOptions()

DumpOptions * dumpOptionsFromRestoreOptions ( RestoreOptions ropt)
extern

Definition at line 165 of file pg_backup_archiver.c.

166{
167 DumpOptions *dopt = NewDumpOptions();
168
169 /* this is the inverse of what's at the end of pg_dump.c's main() */
170 dopt->cparams.dbname = ropt->cparams.dbname ? pg_strdup(ropt->cparams.dbname) : NULL;
171 dopt->cparams.pgport = ropt->cparams.pgport ? pg_strdup(ropt->cparams.pgport) : NULL;
172 dopt->cparams.pghost = ropt->cparams.pghost ? pg_strdup(ropt->cparams.pghost) : NULL;
175 dopt->outputClean = ropt->dropSchema;
176 dopt->dumpData = ropt->dumpData;
177 dopt->dumpSchema = ropt->dumpSchema;
178 dopt->dumpSections = ropt->dumpSections;
179 dopt->dumpStatistics = ropt->dumpStatistics;
180 dopt->if_exists = ropt->if_exists;
181 dopt->column_inserts = ropt->column_inserts;
182 dopt->aclsSkip = ropt->aclsSkip;
183 dopt->outputSuperuser = ropt->superuser;
184 dopt->outputCreateDB = ropt->createDB;
185 dopt->outputNoOwner = ropt->noOwner;
186 dopt->outputNoTableAm = ropt->noTableAm;
187 dopt->outputNoTablespaces = ropt->noTablespace;
189 dopt->use_setsessauth = ropt->use_setsessauth;
191 dopt->dump_inserts = ropt->dump_inserts;
192 dopt->no_comments = ropt->no_comments;
193 dopt->no_policies = ropt->no_policies;
194 dopt->no_publications = ropt->no_publications;
197 dopt->lockWaitTimeout = ropt->lockWaitTimeout;
200 dopt->sequence_data = ropt->sequence_data;
201 dopt->restrict_key = ropt->restrict_key ? pg_strdup(ropt->restrict_key) : NULL;
202
203 return dopt;
204}
DumpOptions * NewDumpOptions(void)
char * restrict_key
Definition pg_backup.h:220
int column_inserts
Definition pg_backup.h:185
int use_setsessauth
Definition pg_backup.h:198
int outputCreateDB
Definition pg_backup.h:206
bool include_everything
Definition pg_backup.h:203
int sequence_data
Definition pg_backup.h:212
int disable_dollar_quoting
Definition pg_backup.h:184
bool dumpSchema
Definition pg_backup.h:216
int outputNoTableAm
Definition pg_backup.h:196
int enable_row_security
Definition pg_backup.h:199
char * outputSuperuser
Definition pg_backup.h:210
int no_security_labels
Definition pg_backup.h:190
bool dumpStatistics
Definition pg_backup.h:218
int no_publications
Definition pg_backup.h:189
ConnParams cparams
Definition pg_backup.h:173
const char * lockWaitTimeout
Definition pg_backup.h:180
int no_subscriptions
Definition pg_backup.h:191
int outputNoTablespaces
Definition pg_backup.h:197
int disable_triggers
Definition pg_backup.h:195
int outputNoOwner
Definition pg_backup.h:209
ConnParams cparams
Definition pg_backup.h:146
int disable_dollar_quoting
Definition pg_backup.h:110
char * restrict_key
Definition pg_backup.h:168
const char * lockWaitTimeout
Definition pg_backup.h:125
int enable_row_security
Definition pg_backup.h:159

References _restoreOptions::aclsSkip, _dumpOptions::aclsSkip, _restoreOptions::column_inserts, _dumpOptions::column_inserts, _restoreOptions::cparams, _dumpOptions::cparams, _restoreOptions::createDB, _connParams::dbname, _restoreOptions::disable_dollar_quoting, _dumpOptions::disable_dollar_quoting, _restoreOptions::disable_triggers, _dumpOptions::disable_triggers, _restoreOptions::dropSchema, _restoreOptions::dump_inserts, _dumpOptions::dump_inserts, _restoreOptions::dumpData, _dumpOptions::dumpData, _restoreOptions::dumpSchema, _dumpOptions::dumpSchema, _restoreOptions::dumpSections, _dumpOptions::dumpSections, _restoreOptions::dumpStatistics, _dumpOptions::dumpStatistics, _restoreOptions::enable_row_security, _dumpOptions::enable_row_security, fb(), _restoreOptions::if_exists, _dumpOptions::if_exists, _restoreOptions::include_everything, _dumpOptions::include_everything, _restoreOptions::lockWaitTimeout, _dumpOptions::lockWaitTimeout, NewDumpOptions(), _restoreOptions::no_comments, _dumpOptions::no_comments, _restoreOptions::no_policies, _dumpOptions::no_policies, _restoreOptions::no_publications, _dumpOptions::no_publications, _restoreOptions::no_security_labels, _dumpOptions::no_security_labels, _restoreOptions::no_subscriptions, _dumpOptions::no_subscriptions, _restoreOptions::noOwner, _restoreOptions::noTableAm, _restoreOptions::noTablespace, _dumpOptions::outputClean, _dumpOptions::outputCreateDB, _dumpOptions::outputNoOwner, _dumpOptions::outputNoTableAm, _dumpOptions::outputNoTablespaces, _dumpOptions::outputSuperuser, pg_strdup(), _connParams::pghost, _connParams::pgport, _connParams::promptPassword, _restoreOptions::restrict_key, _dumpOptions::restrict_key, _restoreOptions::sequence_data, _dumpOptions::sequence_data, _restoreOptions::superuser, _restoreOptions::use_setsessauth, _dumpOptions::use_setsessauth, and _connParams::username.

Referenced by SetArchiveOptions().

◆ EndLO()

int EndLO ( Archive AHX,
Oid  oid 
)
extern

Definition at line 1430 of file pg_backup_archiver.c.

1431{
1432 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1433
1434 if (AH->EndLOPtr)
1435 AH->EndLOPtr(AH, AH->currToc, oid);
1436
1437 return 1;
1438}
EndLOPtrType EndLOPtr
struct _tocEntry * currToc

References _archiveHandle::currToc, and _archiveHandle::EndLOPtr.

Referenced by dumpLOs().

◆ GetConnection()

PGconn * GetConnection ( Archive AHX)
extern

Definition at line 193 of file pg_backup_db.c.

194{
195 ArchiveHandle *AH = (ArchiveHandle *) AHX;
196
197 return AH->connection;
198}

References _archiveHandle::connection.

◆ InitDumpOptions()

void InitDumpOptions ( DumpOptions opts)
extern

Definition at line 148 of file pg_backup_archiver.c.

149{
150 memset(opts, 0, sizeof(DumpOptions));
151 /* set any fields that shouldn't default to zeroes */
152 opts->include_everything = true;
153 opts->cparams.promptPassword = TRI_DEFAULT;
154 opts->dumpSections = DUMP_UNSECTIONED;
155 opts->dumpSchema = true;
156 opts->dumpData = true;
157 opts->dumpStatistics = false;
158}
static AmcheckOptions opts
Definition pg_amcheck.c:112
#define DUMP_UNSECTIONED
@ TRI_DEFAULT
Definition vacuumlo.c:36

References DUMP_UNSECTIONED, fb(), opts, and TRI_DEFAULT.

Referenced by main(), and NewDumpOptions().

◆ NewDumpOptions()

DumpOptions * NewDumpOptions ( void  )
extern

Definition at line 136 of file pg_backup_archiver.c.

137{
139
141 return opts;
142}
#define pg_malloc_object(type)
Definition fe_memutils.h:60
void InitDumpOptions(DumpOptions *opts)

References InitDumpOptions(), opts, and pg_malloc_object.

Referenced by dumpOptionsFromRestoreOptions().

◆ NewRestoreOptions()

RestoreOptions * NewRestoreOptions ( void  )
extern

Definition at line 1107 of file pg_backup_archiver.c.

1108{
1110
1112
1113 /* set any fields that shouldn't default to zeroes */
1114 opts->format = archUnknown;
1115 opts->cparams.promptPassword = TRI_DEFAULT;
1116 opts->dumpSections = DUMP_UNSECTIONED;
1117 opts->compression_spec.algorithm = PG_COMPRESSION_NONE;
1118 opts->compression_spec.level = 0;
1119 opts->dumpSchema = true;
1120 opts->dumpData = true;
1121 opts->dumpStatistics = true;
1122
1123 return opts;
1124}
@ PG_COMPRESSION_NONE
Definition compression.h:23
#define pg_malloc0_object(type)
Definition fe_memutils.h:61

References archUnknown, DUMP_UNSECTIONED, opts, PG_COMPRESSION_NONE, pg_malloc0_object, and TRI_DEFAULT.

Referenced by _CloseArchive(), and main().

◆ OpenArchive()

Archive * OpenArchive ( const char FileSpec,
const ArchiveFormat  fmt 
)
extern

Definition at line 248 of file pg_backup_archiver.c.

249{
250 ArchiveHandle *AH;
251 pg_compress_specification compression_spec = {0};
252
253 compression_spec.algorithm = PG_COMPRESSION_NONE;
254 AH = _allocAH(FileSpec, fmt, compression_spec, true,
257
258 return (Archive *) AH;
259}
@ DATA_DIR_SYNC_METHOD_FSYNC
Definition file_utils.h:29
static void setupRestoreWorker(Archive *AHX)
pg_compress_algorithm algorithm
Definition compression.h:34

References _allocAH(), pg_compress_specification::algorithm, archModeRead, DATA_DIR_SYNC_METHOD_FSYNC, fb(), PG_COMPRESSION_NONE, and setupRestoreWorker().

Referenced by main().

◆ PrintTOCSummary()

void PrintTOCSummary ( Archive AHX)
extern

Definition at line 1304 of file pg_backup_archiver.c.

1305{
1306 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1307 RestoreOptions *ropt = AH->public.ropt;
1308 TocEntry *te;
1312 const char *fmtName;
1313 char stamp_str[64];
1314
1315 /* TOC is always uncompressed */
1317
1318 sav = SaveOutput(AH);
1319 if (ropt->filename)
1321
1323 localtime(&AH->createDate)) == 0)
1324 strcpy(stamp_str, "[unknown]");
1325
1326 ahprintf(AH, ";\n; Archive created at %s\n", stamp_str);
1327 ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %s\n",
1328 sanitize_line(AH->archdbname, false),
1329 AH->tocCount,
1331
1332 switch (AH->format)
1333 {
1334 case archCustom:
1335 fmtName = "CUSTOM";
1336 break;
1337 case archDirectory:
1338 fmtName = "DIRECTORY";
1339 break;
1340 case archTar:
1341 fmtName = "TAR";
1342 break;
1343 default:
1344 fmtName = "UNKNOWN";
1345 }
1346
1347 ahprintf(AH, "; Dump Version: %d.%d-%d\n",
1349 ahprintf(AH, "; Format: %s\n", fmtName);
1350 ahprintf(AH, "; Integer: %zu bytes\n", AH->intSize);
1351 ahprintf(AH, "; Offset: %zu bytes\n", AH->offSize);
1352 if (AH->archiveRemoteVersion)
1353 ahprintf(AH, "; Dumped from database version: %s\n",
1355 if (AH->archiveDumpVersion)
1356 ahprintf(AH, "; Dumped by pg_dump version: %s\n",
1357 AH->archiveDumpVersion);
1358
1359 ahprintf(AH, ";\n;\n; Selected TOC Entries:\n;\n");
1360
1362 for (te = AH->toc->next; te != AH->toc; te = te->next)
1363 {
1364 /* This bit must match ProcessArchiveRestoreOptions' marking logic */
1365 if (te->section != SECTION_NONE)
1366 curSection = te->section;
1367 te->reqs = _tocEntryRequired(te, curSection, AH);
1368 /* Now, should we print it? */
1369 if (ropt->verbose ||
1370 (te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_STATS)) != 0)
1371 {
1372 char *sanitized_name;
1373 char *sanitized_schema;
1374 char *sanitized_owner;
1375
1376 /*
1377 */
1378 sanitized_name = sanitize_line(te->tag, false);
1379 sanitized_schema = sanitize_line(te->namespace, true);
1380 sanitized_owner = sanitize_line(te->owner, false);
1381
1382 ahprintf(AH, "%d; %u %u %s %s %s %s\n", te->dumpId,
1386
1390 }
1391 if (ropt->verbose && te->nDeps > 0)
1392 {
1393 int i;
1394
1395 ahprintf(AH, ";\tdepends on:");
1396 for (i = 0; i < te->nDeps; i++)
1397 ahprintf(AH, " %d", te->dependencies[i]);
1398 ahprintf(AH, "\n");
1399 }
1400 }
1401
1402 /* Enforce strict names checking */
1403 if (ropt->strict_names)
1404 StrictNamesCheck(ropt);
1405
1406 if (ropt->filename)
1407 RestoreOutput(AH, sav);
1408}
const char * get_compress_algorithm_name(pg_compress_algorithm algorithm)
Definition compression.c:99
char * sanitize_line(const char *str, bool want_hyphen)
Definition dumputils.c:52
#define PGDUMP_STRFTIME_FMT
Definition dumputils.h:34
int i
Definition isn.c:77
static CompressFileHandle * SaveOutput(ArchiveHandle *AH)
static void StrictNamesCheck(RestoreOptions *ropt)
static void SetOutput(ArchiveHandle *AH, const char *filename, const pg_compress_specification compression_spec)
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
static void RestoreOutput(ArchiveHandle *AH, CompressFileHandle *savedOutput)
static int _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
#define ARCHIVE_MAJOR(version)
#define ARCHIVE_MINOR(version)
#define REQ_SCHEMA
#define ARCHIVE_REV(version)
#define REQ_STATS
#define REQ_DATA
RestoreOptions * ropt
Definition pg_backup.h:230
Oid tableoid
Definition pg_backup.h:281
ArchiveFormat format
struct _tocEntry * toc
pg_compress_specification compression_spec
const char * filename
Definition pg_backup.h:121
teSection section
CatalogId catalogId
struct _tocEntry * next
DumpId * dependencies

References _tocEntryRequired(), ahprintf(), pg_compress_specification::algorithm, archCustom, _archiveHandle::archdbname, archDirectory, ARCHIVE_MAJOR, ARCHIVE_MINOR, ARCHIVE_REV, _archiveHandle::archiveDumpVersion, _archiveHandle::archiveRemoteVersion, archTar, _tocEntry::catalogId, _archiveHandle::compression_spec, _archiveHandle::createDate, _tocEntry::dependencies, _tocEntry::desc, _tocEntry::dumpId, fb(), _restoreOptions::filename, _archiveHandle::format, free, get_compress_algorithm_name(), i, _archiveHandle::intSize, _tocEntry::nDeps, _tocEntry::next, _archiveHandle::offSize, CatalogId::oid, _tocEntry::owner, PG_COMPRESSION_NONE, PGDUMP_STRFTIME_FMT, _archiveHandle::public, REQ_DATA, REQ_SCHEMA, REQ_STATS, _tocEntry::reqs, RestoreOutput(), Archive::ropt, sanitize_line(), SaveOutput(), _tocEntry::section, SECTION_NONE, SECTION_PRE_DATA, SetOutput(), _restoreOptions::strict_names, StrictNamesCheck(), CatalogId::tableoid, _tocEntry::tag, _archiveHandle::toc, _archiveHandle::tocCount, _restoreOptions::verbose, and _archiveHandle::version.

Referenced by main().

◆ ProcessArchiveRestoreOptions()

void ProcessArchiveRestoreOptions ( Archive AHX)
extern

Definition at line 290 of file pg_backup_archiver.c.

291{
292 ArchiveHandle *AH = (ArchiveHandle *) AHX;
293 RestoreOptions *ropt = AH->public.ropt;
294 TocEntry *te;
296
297 /* Decide which TOC entries will be dumped/restored, and mark them */
299 for (te = AH->toc->next; te != AH->toc; te = te->next)
300 {
301 /*
302 * When writing an archive, we also take this opportunity to check
303 * that we have generated the entries in a sane order that respects
304 * the section divisions. When reading, don't complain, since buggy
305 * old versions of pg_dump might generate out-of-order archives.
306 */
307 if (AH->mode != archModeRead)
308 {
309 switch (te->section)
310 {
311 case SECTION_NONE:
312 /* ok to be anywhere */
313 break;
314 case SECTION_PRE_DATA:
316 pg_log_warning("archive items not in correct section order");
317 break;
318 case SECTION_DATA:
320 pg_log_warning("archive items not in correct section order");
321 break;
323 /* ok no matter which section we were in */
324 break;
325 default:
326 pg_fatal("unexpected section code %d",
327 (int) te->section);
328 break;
329 }
330 }
331
332 if (te->section != SECTION_NONE)
333 curSection = te->section;
334
335 te->reqs = _tocEntryRequired(te, curSection, AH);
336 }
337
338 /* Enforce strict names checking */
339 if (ropt->strict_names)
340 StrictNamesCheck(ropt);
341}
#define pg_log_warning(...)
Definition pgfnames.c:24

References _tocEntryRequired(), archModeRead, fb(), _archiveHandle::mode, _tocEntry::next, pg_fatal, pg_log_warning, _archiveHandle::public, _tocEntry::reqs, Archive::ropt, _tocEntry::section, SECTION_DATA, SECTION_NONE, SECTION_POST_DATA, SECTION_PRE_DATA, _restoreOptions::strict_names, StrictNamesCheck(), and _archiveHandle::toc.

Referenced by main().

◆ RestoreArchive()

void RestoreArchive ( Archive AHX)
extern

Definition at line 345 of file pg_backup_archiver.c.

346{
347 ArchiveHandle *AH = (ArchiveHandle *) AHX;
348 RestoreOptions *ropt = AH->public.ropt;
349 bool parallel_mode;
350 TocEntry *te;
352
354
355 /*
356 * If we're going to do parallel restore, there are some restrictions.
357 */
358 parallel_mode = (AH->public.numWorkers > 1 && ropt->useDB);
359 if (parallel_mode)
360 {
361 /* We haven't got round to making this work for all archive formats */
362 if (AH->ClonePtr == NULL || AH->ReopenPtr == NULL)
363 pg_fatal("parallel restore is not supported with this archive file format");
364
365 /* Doesn't work if the archive represents dependencies as OIDs */
366 if (AH->version < K_VERS_1_8)
367 pg_fatal("parallel restore is not supported with archives made by pre-8.0 pg_dump");
368
369 /*
370 * It's also not gonna work if we can't reopen the input file, so
371 * let's try that immediately.
372 */
373 AH->ReopenPtr(AH);
374 }
375
376 /*
377 * Make sure we won't need (de)compression we haven't got
378 */
379 if (AH->PrintTocDataPtr != NULL)
380 {
381 for (te = AH->toc->next; te != AH->toc; te = te->next)
382 {
383 if (te->hadDumper && (te->reqs & REQ_DATA) != 0)
384 {
386
387 if (errmsg)
388 pg_fatal("cannot restore from compressed archive (%s)",
389 errmsg);
390 else
391 break;
392 }
393 }
394 }
395
396 /*
397 * Prepare index arrays, so we can assume we have them throughout restore.
398 * It's possible we already did this, though.
399 */
400 if (AH->tocsByDumpId == NULL)
402
403 /*
404 * If we're using a DB connection, then connect it.
405 */
406 if (ropt->useDB)
407 {
408 pg_log_info("connecting to database for restore");
409 if (AH->version < K_VERS_1_3)
410 pg_fatal("direct database connections are not supported in pre-1.3 archives");
411
412 /*
413 * We don't want to guess at whether the dump will successfully
414 * restore; allow the attempt regardless of the version of the restore
415 * target.
416 */
417 AHX->minRemoteVersion = 0;
418 AHX->maxRemoteVersion = 9999999;
419
420 ConnectDatabaseAhx(AHX, &ropt->cparams, false);
421
422 /*
423 * If we're talking to the DB directly, don't send comments since they
424 * obscure SQL when displaying errors
425 */
426 AH->noTocComments = 1;
427 }
428
429 /*
430 * Work out if we have an implied schema-less restore. This can happen if
431 * the dump excluded the schema or the user has used a toc list to exclude
432 * all of the schema data. All we do is look for schema entries - if none
433 * are found then we unset the dumpSchema flag.
434 *
435 * We could scan for wanted TABLE entries, but that is not the same as
436 * data-only. At this stage, it seems unnecessary (6-Mar-2001).
437 */
438 if (ropt->dumpSchema)
439 {
440 bool no_schema_found = true;
441
442 for (te = AH->toc->next; te != AH->toc; te = te->next)
443 {
444 if ((te->reqs & REQ_SCHEMA) != 0)
445 {
446 no_schema_found = false;
447 break;
448 }
449 }
450 if (no_schema_found)
451 {
452 ropt->dumpSchema = false;
453 pg_log_info("implied no-schema restore");
454 }
455 }
456
457 /*
458 * Setup the output file if necessary.
459 */
460 sav = SaveOutput(AH);
462 SetOutput(AH, ropt->filename, ropt->compression_spec);
463
464 ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");
465
466 /*
467 * If generating plain-text output, enter restricted mode to block any
468 * unexpected psql meta-commands. A malicious source might try to inject
469 * a variety of things via bogus responses to queries. While we cannot
470 * prevent such sources from affecting the destination at restore time, we
471 * can block psql meta-commands so that the client machine that runs psql
472 * with the dump output remains unaffected.
473 */
474 if (ropt->restrict_key)
475 ahprintf(AH, "\\restrict %s\n\n", ropt->restrict_key);
476
477 if (AH->archiveRemoteVersion)
478 ahprintf(AH, "-- Dumped from database version %s\n",
480 if (AH->archiveDumpVersion)
481 ahprintf(AH, "-- Dumped by pg_dump version %s\n",
483
484 ahprintf(AH, "\n");
485
486 if (AH->public.verbose)
487 dumpTimestamp(AH, "Started on", AH->createDate);
488
489 if (ropt->single_txn)
490 {
491 if (AH->connection)
492 StartTransaction(AHX);
493 else
494 ahprintf(AH, "BEGIN;\n\n");
495 }
496
497 /*
498 * Establish important parameter values right away.
499 */
501
503
504 /*
505 * Drop the items at the start, in reverse order
506 */
507 if (ropt->dropSchema)
508 {
509 for (te = AH->toc->prev; te != AH->toc; te = te->prev)
510 {
511 AH->currentTE = te;
512
513 /*
514 * In createDB mode, issue a DROP *only* for the database as a
515 * whole. Issuing drops against anything else would be wrong,
516 * because at this point we're connected to the wrong database.
517 * (The DATABASE PROPERTIES entry, if any, should be treated like
518 * the DATABASE entry.)
519 */
520 if (ropt->createDB)
521 {
522 if (strcmp(te->desc, "DATABASE") != 0 &&
523 strcmp(te->desc, "DATABASE PROPERTIES") != 0)
524 continue;
525 }
526
527 /* Otherwise, drop anything that's selected and has a dropStmt */
528 if (((te->reqs & (REQ_SCHEMA | REQ_DATA)) != 0) && te->dropStmt)
529 {
530 bool not_allowed_in_txn = false;
531
532 pg_log_info("dropping %s %s", te->desc, te->tag);
533
534 /*
535 * In --transaction-size mode, we have to temporarily exit our
536 * transaction block to drop objects that can't be dropped
537 * within a transaction.
538 */
539 if (ropt->txn_size > 0)
540 {
541 if (strcmp(te->desc, "DATABASE") == 0 ||
542 strcmp(te->desc, "DATABASE PROPERTIES") == 0)
543 {
544 not_allowed_in_txn = true;
545 if (AH->connection)
547 else
548 ahprintf(AH, "COMMIT;\n");
549 }
550 }
551
552 /* Select owner and schema as necessary */
553 _becomeOwner(AH, te);
554 _selectOutputSchema(AH, te->namespace);
555
556 /*
557 * Now emit the DROP command, if the object has one. Note we
558 * don't necessarily emit it verbatim; at this point we add an
559 * appropriate IF EXISTS clause, if the user requested it.
560 */
561 if (strcmp(te->desc, "BLOB METADATA") == 0)
562 {
563 /* We must generate the per-blob commands */
564 if (ropt->if_exists)
565 IssueCommandPerBlob(AH, te,
566 "SELECT pg_catalog.lo_unlink(oid) "
567 "FROM pg_catalog.pg_largeobject_metadata "
568 "WHERE oid = '", "'");
569 else
570 IssueCommandPerBlob(AH, te,
571 "SELECT pg_catalog.lo_unlink('",
572 "')");
573 }
574 else if (*te->dropStmt != '\0')
575 {
576 if (!ropt->if_exists ||
577 strncmp(te->dropStmt, "--", 2) == 0)
578 {
579 /*
580 * Without --if-exists, or if it's just a comment (as
581 * happens for the public schema), print the dropStmt
582 * as-is.
583 */
584 ahprintf(AH, "%s", te->dropStmt);
585 }
586 else
587 {
588 /*
589 * Inject an appropriate spelling of "if exists". For
590 * old-style large objects, we have a routine that
591 * knows how to do it, without depending on
592 * te->dropStmt; use that. For other objects we need
593 * to parse the command.
594 */
595 if (strcmp(te->desc, "BLOB") == 0)
596 {
598 }
599 else
600 {
601 char *dropStmt = pg_strdup(te->dropStmt);
602 char *dropStmtOrig = dropStmt;
604
605 /*
606 * Need to inject IF EXISTS clause after ALTER
607 * TABLE part in ALTER TABLE .. DROP statement
608 */
609 if (strncmp(dropStmt, "ALTER TABLE", 11) == 0)
610 {
612 "ALTER TABLE IF EXISTS");
613 dropStmt = dropStmt + 11;
614 }
615
616 /*
617 * ALTER TABLE..ALTER COLUMN..DROP DEFAULT does
618 * not support the IF EXISTS clause, and therefore
619 * we simply emit the original command for DEFAULT
620 * objects (modulo the adjustment made above).
621 *
622 * Likewise, don't mess with DATABASE PROPERTIES.
623 *
624 * If we used CREATE OR REPLACE VIEW as a means of
625 * quasi-dropping an ON SELECT rule, that should
626 * be emitted unchanged as well.
627 *
628 * For other object types, we need to extract the
629 * first part of the DROP which includes the
630 * object type. Most of the time this matches
631 * te->desc, so search for that; however for the
632 * different kinds of CONSTRAINTs, we know to
633 * search for hardcoded "DROP CONSTRAINT" instead.
634 */
635 if (strcmp(te->desc, "DEFAULT") == 0 ||
636 strcmp(te->desc, "DATABASE PROPERTIES") == 0 ||
637 strncmp(dropStmt, "CREATE OR REPLACE VIEW", 22) == 0)
638 appendPQExpBufferStr(ftStmt, dropStmt);
639 else
640 {
641 char buffer[40];
642 char *mark;
643
644 if (strcmp(te->desc, "CONSTRAINT") == 0 ||
645 strcmp(te->desc, "CHECK CONSTRAINT") == 0 ||
646 strcmp(te->desc, "FK CONSTRAINT") == 0)
647 strcpy(buffer, "DROP CONSTRAINT");
648 else
649 snprintf(buffer, sizeof(buffer), "DROP %s",
650 te->desc);
651
652 mark = strstr(dropStmt, buffer);
653
654 if (mark)
655 {
656 *mark = '\0';
657 appendPQExpBuffer(ftStmt, "%s%s IF EXISTS%s",
658 dropStmt, buffer,
659 mark + strlen(buffer));
660 }
661 else
662 {
663 /* complain and emit unmodified command */
664 pg_log_warning("could not find where to insert IF EXISTS in statement \"%s\"",
666 appendPQExpBufferStr(ftStmt, dropStmt);
667 }
668 }
669
670 ahprintf(AH, "%s", ftStmt->data);
671
674 }
675 }
676 }
677
678 /*
679 * In --transaction-size mode, re-establish the transaction
680 * block if needed; otherwise, commit after every N drops.
681 */
682 if (ropt->txn_size > 0)
683 {
685 {
686 if (AH->connection)
687 StartTransaction(AHX);
688 else
689 ahprintf(AH, "BEGIN;\n");
690 AH->txnCount = 0;
691 }
692 else if (++AH->txnCount >= ropt->txn_size)
693 {
694 if (AH->connection)
695 {
697 StartTransaction(AHX);
698 }
699 else
700 ahprintf(AH, "COMMIT;\nBEGIN;\n");
701 AH->txnCount = 0;
702 }
703 }
704 }
705 }
706
707 /*
708 * _selectOutputSchema may have set currSchema to reflect the effect
709 * of a "SET search_path" command it emitted. However, by now we may
710 * have dropped that schema; or it might not have existed in the first
711 * place. In either case the effective value of search_path will not
712 * be what we think. Forcibly reset currSchema so that we will
713 * re-establish the search_path setting when needed (after creating
714 * the schema).
715 *
716 * If we treated users as pg_dump'able objects then we'd need to reset
717 * currUser here too.
718 */
719 free(AH->currSchema);
720 AH->currSchema = NULL;
721 }
722
723 if (parallel_mode)
724 {
725 /*
726 * In parallel mode, turn control over to the parallel-restore logic.
727 */
728 ParallelState *pstate;
730
731 /* The archive format module may need some setup for this */
734
736
737 /* This runs PRE_DATA items and then disconnects from the database */
739 Assert(AH->connection == NULL);
740
741 /* ParallelBackupStart() will actually fork the processes */
742 pstate = ParallelBackupStart(AH);
744 ParallelBackupEnd(AH, pstate);
745
746 /* reconnect the leader and see if we missed something */
748 Assert(AH->connection != NULL);
749 }
750 else
751 {
752 /*
753 * In serial mode, process everything in three phases: normal items,
754 * then ACLs, then post-ACL items. We might be able to skip one or
755 * both extra phases in some cases, eg data-only restores.
756 */
757 bool haveACL = false;
758 bool havePostACL = false;
759
760 for (te = AH->toc->next; te != AH->toc; te = te->next)
761 {
762 if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_STATS)) == 0)
763 continue; /* ignore if not to be dumped at all */
764
765 switch (_tocEntryRestorePass(te))
766 {
768 (void) restore_toc_entry(AH, te, false);
769 break;
770 case RESTORE_PASS_ACL:
771 haveACL = true;
772 break;
774 havePostACL = true;
775 break;
776 }
777 }
778
779 if (haveACL)
780 {
781 for (te = AH->toc->next; te != AH->toc; te = te->next)
782 {
783 if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_STATS)) != 0 &&
785 (void) restore_toc_entry(AH, te, false);
786 }
787 }
788
789 if (havePostACL)
790 {
791 for (te = AH->toc->next; te != AH->toc; te = te->next)
792 {
793 if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_STATS)) != 0 &&
795 (void) restore_toc_entry(AH, te, false);
796 }
797 }
798 }
799
800 /*
801 * Close out any persistent transaction we may have. While these two
802 * cases are started in different places, we can end both cases here.
803 */
804 if (ropt->single_txn || ropt->txn_size > 0)
805 {
806 if (AH->connection)
808 else
809 ahprintf(AH, "COMMIT;\n\n");
810 }
811
812 if (AH->public.verbose)
813 dumpTimestamp(AH, "Completed on", time(NULL));
814
815 ahprintf(AH, "--\n-- PostgreSQL database dump complete\n--\n\n");
816
817 /*
818 * If generating plain-text output, exit restricted mode at the very end
819 * of the script. This is not pro forma; in particular, pg_dumpall
820 * requires this when transitioning from one database to another.
821 */
822 if (ropt->restrict_key)
823 ahprintf(AH, "\\unrestrict %s\n\n", ropt->restrict_key);
824
825 /*
826 * Clean up & we're done.
827 */
829
831 RestoreOutput(AH, sav);
832
833 if (ropt->useDB)
835}
void ParallelBackupEnd(ArchiveHandle *AH, ParallelState *pstate)
Definition parallel.c:1061
ParallelState * ParallelBackupStart(ArchiveHandle *AH)
Definition parallel.c:899
#define Assert(condition)
Definition c.h:943
char * supports_compression(const pg_compress_specification compression_spec)
Definition compress_io.c:87
void pg_free(void *ptr)
#define pg_log_info(...)
Definition logging.h:126
static char * errmsg
void ConnectDatabaseAhx(Archive *AHX, const ConnParams *cparams, bool isReconnect)
void DisconnectDatabase(Archive *AHX)
static void _becomeOwner(ArchiveHandle *AH, TocEntry *te)
static int restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
static void buildTocEntryArrays(ArchiveHandle *AH)
static RestorePass _tocEntryRestorePass(TocEntry *te)
static void pending_list_header_init(TocEntry *l)
static void restore_toc_entries_parallel(ArchiveHandle *AH, ParallelState *pstate, TocEntry *pending_list)
static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim)
static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName)
static void restore_toc_entries_prefork(ArchiveHandle *AH, TocEntry *pending_list)
static void restore_toc_entries_postfork(ArchiveHandle *AH, TocEntry *pending_list)
static void _doSetFixedOutputState(ArchiveHandle *AH)
void DropLOIfExists(ArchiveHandle *AH, Oid oid)
void IssueCommandPerBlob(ArchiveHandle *AH, TocEntry *te, const char *cmdBegin, const char *cmdEnd)
@ STAGE_INITIALIZING
@ STAGE_PROCESSING
@ STAGE_FINALIZING
#define K_VERS_1_8
@ RESTORE_PASS_POST_ACL
@ RESTORE_PASS_ACL
@ RESTORE_PASS_MAIN
#define K_VERS_1_3
#define snprintf
Definition port.h:261
PQExpBuffer createPQExpBuffer(void)
Definition pqexpbuffer.c:72
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
int minRemoteVersion
Definition pg_backup.h:237
int maxRemoteVersion
Definition pg_backup.h:238
int numWorkers
Definition pg_backup.h:240
int verbose
Definition pg_backup.h:232
ArchiverStage stage
struct _tocEntry * currentTE
struct _tocEntry ** tocsByDumpId
ClonePtrType ClonePtr
PrepParallelRestorePtrType PrepParallelRestorePtr
PrintTocDataPtrType PrintTocDataPtr
ReopenPtrType ReopenPtr
pg_compress_specification compression_spec
Definition pg_backup.h:150
struct _tocEntry * prev
static void StartTransaction(void)
Definition xact.c:2106
static void CommitTransaction(void)
Definition xact.c:2270

References _becomeOwner(), _doSetFixedOutputState(), _selectOutputSchema(), _tocEntryRestorePass(), ahprintf(), pg_compress_specification::algorithm, appendPQExpBuffer(), appendPQExpBufferStr(), _archiveHandle::archiveDumpVersion, _archiveHandle::archiveRemoteVersion, Assert, buildTocEntryArrays(), _tocEntry::catalogId, _archiveHandle::ClonePtr, CommitTransaction(), _restoreOptions::compression_spec, _archiveHandle::compression_spec, ConnectDatabaseAhx(), _archiveHandle::connection, _restoreOptions::cparams, _archiveHandle::createDate, _restoreOptions::createDB, createPQExpBuffer(), _archiveHandle::currentTE, _archiveHandle::currSchema, _tocEntry::desc, destroyPQExpBuffer(), DisconnectDatabase(), DropLOIfExists(), _restoreOptions::dropSchema, _tocEntry::dropStmt, _restoreOptions::dumpSchema, dumpTimestamp(), errmsg, fb(), _restoreOptions::filename, free, _tocEntry::hadDumper, _restoreOptions::if_exists, IssueCommandPerBlob(), K_VERS_1_3, K_VERS_1_8, Archive::maxRemoteVersion, Archive::minRemoteVersion, _tocEntry::next, _archiveHandle::noTocComments, Archive::numWorkers, CatalogId::oid, ParallelBackupEnd(), ParallelBackupStart(), pending_list_header_init(), PG_COMPRESSION_NONE, pg_fatal, pg_free(), pg_log_info, pg_log_warning, pg_strdup(), _archiveHandle::PrepParallelRestorePtr, _tocEntry::prev, _archiveHandle::PrintTocDataPtr, _archiveHandle::public, _archiveHandle::ReopenPtr, REQ_DATA, REQ_SCHEMA, REQ_STATS, _tocEntry::reqs, RESTORE_PASS_ACL, RESTORE_PASS_MAIN, RESTORE_PASS_POST_ACL, restore_toc_entries_parallel(), restore_toc_entries_postfork(), restore_toc_entries_prefork(), restore_toc_entry(), RestoreOutput(), _restoreOptions::restrict_key, Archive::ropt, SaveOutput(), SetOutput(), _restoreOptions::single_txn, snprintf, _archiveHandle::stage, STAGE_FINALIZING, STAGE_INITIALIZING, STAGE_PROCESSING, StartTransaction(), supports_compression(), _tocEntry::tag, _archiveHandle::toc, _archiveHandle::tocsByDumpId, _restoreOptions::txn_size, _archiveHandle::txnCount, _restoreOptions::useDB, Archive::verbose, and _archiveHandle::version.

Referenced by _CloseArchive(), and main().

◆ SetArchiveOptions()

void SetArchiveOptions ( Archive AH,
DumpOptions dopt,
RestoreOptions ropt 
)
extern

Definition at line 277 of file pg_backup_archiver.c.

278{
279 /* Caller can omit dump options, in which case we synthesize them */
280 if (dopt == NULL && ropt != NULL)
282
283 /* Save options for later access */
284 AH->dopt = dopt;
285 AH->ropt = ropt;
286}
DumpOptions * dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
DumpOptions * dopt
Definition pg_backup.h:229

References Archive::dopt, dumpOptionsFromRestoreOptions(), fb(), and Archive::ropt.

Referenced by _CloseArchive(), and main().

◆ SortTocFromFile()

void SortTocFromFile ( Archive AHX)
extern

Definition at line 1571 of file pg_backup_archiver.c.

1572{
1573 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1574 RestoreOptions *ropt = AH->public.ropt;
1575 FILE *fh;
1577
1578 /* Allocate space for the 'wanted' array, and init it */
1579 ropt->idWanted = pg_malloc0_array(bool, AH->maxDumpId);
1580
1581 /* Setup the file */
1582 fh = fopen(ropt->tocFile, PG_BINARY_R);
1583 if (!fh)
1584 pg_fatal("could not open TOC file \"%s\": %m", ropt->tocFile);
1585
1587
1588 while (pg_get_line_buf(fh, &linebuf))
1589 {
1590 char *cmnt;
1591 char *endptr;
1592 DumpId id;
1593 TocEntry *te;
1594
1595 /* Truncate line at comment, if any */
1596 cmnt = strchr(linebuf.data, ';');
1597 if (cmnt != NULL)
1598 {
1599 cmnt[0] = '\0';
1600 linebuf.len = cmnt - linebuf.data;
1601 }
1602
1603 /* Ignore if all blank */
1604 if (strspn(linebuf.data, " \t\r\n") == linebuf.len)
1605 continue;
1606
1607 /* Get an ID, check it's valid and not already seen */
1608 id = strtol(linebuf.data, &endptr, 10);
1609 if (endptr == linebuf.data || id <= 0 || id > AH->maxDumpId ||
1610 ropt->idWanted[id - 1])
1611 {
1612 pg_log_warning("line ignored: %s", linebuf.data);
1613 continue;
1614 }
1615
1616 /* Find TOC entry */
1617 te = getTocEntryByDumpId(AH, id);
1618 if (!te)
1619 pg_fatal("could not find entry for ID %d",
1620 id);
1621
1622 /* Mark it wanted */
1623 ropt->idWanted[id - 1] = true;
1624
1625 /*
1626 * Move each item to the end of the list as it is selected, so that
1627 * they are placed in the desired order. Any unwanted items will end
1628 * up at the front of the list, which may seem unintuitive but it's
1629 * what we need. In an ordinary serial restore that makes no
1630 * difference, but in a parallel restore we need to mark unrestored
1631 * items' dependencies as satisfied before we start examining
1632 * restorable items. Otherwise they could have surprising
1633 * side-effects on the order in which restorable items actually get
1634 * restored.
1635 */
1636 _moveBefore(AH->toc, te);
1637 }
1638
1639 pg_free(linebuf.data);
1640
1641 if (fclose(fh) != 0)
1642 pg_fatal("could not close TOC file: %m");
1643}
#define PG_BINARY_R
Definition c.h:1388
#define pg_malloc0_array(type, count)
Definition fe_memutils.h:67
int DumpId
Definition pg_backup.h:285
static void _moveBefore(TocEntry *pos, TocEntry *te)
TocEntry * getTocEntryByDumpId(ArchiveHandle *AH, DumpId id)
bool pg_get_line_buf(FILE *stream, StringInfo buf)
Definition pg_get_line.c:95
void initStringInfo(StringInfo str)
Definition stringinfo.c:97

References _moveBefore(), fb(), getTocEntryByDumpId(), _restoreOptions::idWanted, initStringInfo(), _archiveHandle::maxDumpId, PG_BINARY_R, pg_fatal, pg_free(), pg_get_line_buf(), pg_log_warning, pg_malloc0_array, _archiveHandle::public, Archive::ropt, _archiveHandle::toc, and _restoreOptions::tocFile.

Referenced by main().

◆ StartLO()

int StartLO ( Archive AHX,
Oid  oid 
)
extern

Definition at line 1416 of file pg_backup_archiver.c.

1417{
1418 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1419
1420 if (!AH->StartLOPtr)
1421 pg_fatal("large-object output not supported in chosen format");
1422
1423 AH->StartLOPtr(AH, AH->currToc, oid);
1424
1425 return 1;
1426}
StartLOPtrType StartLOPtr

References _archiveHandle::currToc, pg_fatal, and _archiveHandle::StartLOPtr.

Referenced by dumpLOs().

◆ WriteData()

void WriteData ( Archive AHX,
const void data,
size_t  dLen 
)
extern

Definition at line 1221 of file pg_backup_archiver.c.

1222{
1223 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1224
1225 if (!AH->currToc)
1226 pg_fatal("internal error -- WriteData cannot be called outside the context of a DataDumper routine");
1227
1228 AH->WriteDataPtr(AH, data, dLen);
1229}
const void * data
WriteDataPtrType WriteDataPtr

References _archiveHandle::currToc, data, fb(), pg_fatal, and _archiveHandle::WriteDataPtr.

Referenced by archprintf(), archputs(), dumpLOs(), and dumpTableData_copy().