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, bool append_data)
 
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 1669 of file pg_backup_archiver.c.

1670{
1671 WriteData(AH, s, strlen(s));
1672}
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 262 of file pg_backup_archiver.c.

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

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

Referenced by main(), main(), restore_global_objects(), and restore_one_database().

◆ 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:746
#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:85
#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 231 of file pg_backup_archiver.c.

237{
238 ArchiveHandle *AH = _allocAH(FileSpec, fmt, compression_spec,
240
241 return (Archive *) AH;
242}
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(), and 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 164 of file pg_backup_archiver.c.

165{
166 DumpOptions *dopt = NewDumpOptions();
167
168 /* this is the inverse of what's at the end of pg_dump.c's main() */
169 dopt->cparams.dbname = ropt->cparams.dbname ? pg_strdup(ropt->cparams.dbname) : NULL;
170 dopt->cparams.pgport = ropt->cparams.pgport ? pg_strdup(ropt->cparams.pgport) : NULL;
171 dopt->cparams.pghost = ropt->cparams.pghost ? pg_strdup(ropt->cparams.pghost) : NULL;
174 dopt->outputClean = ropt->dropSchema;
175 dopt->dumpData = ropt->dumpData;
176 dopt->dumpSchema = ropt->dumpSchema;
177 dopt->dumpSections = ropt->dumpSections;
178 dopt->dumpStatistics = ropt->dumpStatistics;
179 dopt->if_exists = ropt->if_exists;
180 dopt->column_inserts = ropt->column_inserts;
181 dopt->aclsSkip = ropt->aclsSkip;
182 dopt->outputSuperuser = ropt->superuser;
183 dopt->outputCreateDB = ropt->createDB;
184 dopt->outputNoOwner = ropt->noOwner;
185 dopt->outputNoTableAm = ropt->noTableAm;
186 dopt->outputNoTablespaces = ropt->noTablespace;
188 dopt->use_setsessauth = ropt->use_setsessauth;
190 dopt->dump_inserts = ropt->dump_inserts;
191 dopt->no_comments = ropt->no_comments;
192 dopt->no_policies = ropt->no_policies;
193 dopt->no_publications = ropt->no_publications;
196 dopt->lockWaitTimeout = ropt->lockWaitTimeout;
199 dopt->sequence_data = ropt->sequence_data;
200 dopt->restrict_key = ropt->restrict_key ? pg_strdup(ropt->restrict_key) : NULL;
201
202 return dopt;
203}
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 1447 of file pg_backup_archiver.c.

1448{
1449 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1450
1451 if (AH->EndLOPtr)
1452 AH->EndLOPtr(AH, AH->currToc, oid);
1453
1454 return 1;
1455}
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 147 of file pg_backup_archiver.c.

148{
149 memset(opts, 0, sizeof(DumpOptions));
150 /* set any fields that shouldn't default to zeroes */
151 opts->include_everything = true;
152 opts->cparams.promptPassword = TRI_DEFAULT;
153 opts->dumpSections = DUMP_UNSECTIONED;
154 opts->dumpSchema = true;
155 opts->dumpData = true;
156 opts->dumpStatistics = false;
157}
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(), main(), and NewDumpOptions().

◆ NewDumpOptions()

DumpOptions * NewDumpOptions ( void  )
extern

Definition at line 135 of file pg_backup_archiver.c.

136{
138
140 return opts;
141}
#define pg_malloc_object(type)
Definition fe_memutils.h:50
void InitDumpOptions(DumpOptions *opts)

References InitDumpOptions(), opts, and pg_malloc_object.

Referenced by dumpOptionsFromRestoreOptions().

◆ NewRestoreOptions()

RestoreOptions * NewRestoreOptions ( void  )
extern

Definition at line 1124 of file pg_backup_archiver.c.

1125{
1127
1129
1130 /* set any fields that shouldn't default to zeroes */
1131 opts->format = archUnknown;
1132 opts->cparams.promptPassword = TRI_DEFAULT;
1133 opts->dumpSections = DUMP_UNSECTIONED;
1134 opts->compression_spec.algorithm = PG_COMPRESSION_NONE;
1135 opts->compression_spec.level = 0;
1136 opts->dumpSchema = true;
1137 opts->dumpData = true;
1138 opts->dumpStatistics = true;
1139
1140 return opts;
1141}
@ PG_COMPRESSION_NONE
Definition compression.h:23
#define pg_malloc0_object(type)
Definition fe_memutils.h:51

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

Referenced by _CloseArchive(), main(), and main().

◆ OpenArchive()

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

Definition at line 247 of file pg_backup_archiver.c.

248{
249 ArchiveHandle *AH;
250 pg_compress_specification compression_spec = {0};
251
252 compression_spec.algorithm = PG_COMPRESSION_NONE;
253 AH = _allocAH(FileSpec, fmt, compression_spec, true,
256
257 return (Archive *) AH;
258}
@ 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 restore_global_objects(), and restore_one_database().

◆ PrintTOCSummary()

void PrintTOCSummary ( Archive AHX)
extern

Definition at line 1321 of file pg_backup_archiver.c.

1322{
1323 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1324 RestoreOptions *ropt = AH->public.ropt;
1325 TocEntry *te;
1329 const char *fmtName;
1330 char stamp_str[64];
1331
1332 /* TOC is always uncompressed */
1334
1335 sav = SaveOutput(AH);
1336 if (ropt->filename)
1337 SetOutput(AH, ropt->filename, out_compression_spec, false);
1338
1340 localtime(&AH->createDate)) == 0)
1341 strcpy(stamp_str, "[unknown]");
1342
1343 ahprintf(AH, ";\n; Archive created at %s\n", stamp_str);
1344 ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %s\n",
1345 sanitize_line(AH->archdbname, false),
1346 AH->tocCount,
1348
1349 switch (AH->format)
1350 {
1351 case archCustom:
1352 fmtName = "CUSTOM";
1353 break;
1354 case archDirectory:
1355 fmtName = "DIRECTORY";
1356 break;
1357 case archTar:
1358 fmtName = "TAR";
1359 break;
1360 default:
1361 fmtName = "UNKNOWN";
1362 }
1363
1364 ahprintf(AH, "; Dump Version: %d.%d-%d\n",
1366 ahprintf(AH, "; Format: %s\n", fmtName);
1367 ahprintf(AH, "; Integer: %zu bytes\n", AH->intSize);
1368 ahprintf(AH, "; Offset: %zu bytes\n", AH->offSize);
1369 if (AH->archiveRemoteVersion)
1370 ahprintf(AH, "; Dumped from database version: %s\n",
1372 if (AH->archiveDumpVersion)
1373 ahprintf(AH, "; Dumped by pg_dump version: %s\n",
1374 AH->archiveDumpVersion);
1375
1376 ahprintf(AH, ";\n;\n; Selected TOC Entries:\n;\n");
1377
1379 for (te = AH->toc->next; te != AH->toc; te = te->next)
1380 {
1381 /* This bit must match ProcessArchiveRestoreOptions' marking logic */
1382 if (te->section != SECTION_NONE)
1383 curSection = te->section;
1384 te->reqs = _tocEntryRequired(te, curSection, AH);
1385 /* Now, should we print it? */
1386 if (ropt->verbose ||
1387 (te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_STATS)) != 0)
1388 {
1389 char *sanitized_name;
1390 char *sanitized_schema;
1391 char *sanitized_owner;
1392
1393 /*
1394 */
1395 sanitized_name = sanitize_line(te->tag, false);
1396 sanitized_schema = sanitize_line(te->namespace, true);
1397 sanitized_owner = sanitize_line(te->owner, false);
1398
1399 ahprintf(AH, "%d; %u %u %s %s %s %s\n", te->dumpId,
1403
1407 }
1408 if (ropt->verbose && te->nDeps > 0)
1409 {
1410 int i;
1411
1412 ahprintf(AH, ";\tdepends on:");
1413 for (i = 0; i < te->nDeps; i++)
1414 ahprintf(AH, " %d", te->dependencies[i]);
1415 ahprintf(AH, "\n");
1416 }
1417 }
1418
1419 /* Enforce strict names checking */
1420 if (ropt->strict_names)
1421 StrictNamesCheck(ropt);
1422
1423 if (ropt->filename)
1424 RestoreOutput(AH, sav);
1425}
const char * get_compress_algorithm_name(pg_compress_algorithm algorithm)
Definition compression.c:69
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)
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
static void RestoreOutput(ArchiveHandle *AH, CompressFileHandle *savedOutput)
static void SetOutput(ArchiveHandle *AH, const char *filename, const pg_compress_specification compression_spec, bool append_data)
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 restore_one_database().

◆ ProcessArchiveRestoreOptions()

void ProcessArchiveRestoreOptions ( Archive AHX)
extern

Definition at line 289 of file pg_backup_archiver.c.

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

◆ RestoreArchive()

void RestoreArchive ( Archive AHX,
bool  append_data 
)
extern

Definition at line 349 of file pg_backup_archiver.c.

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

References _becomeOwner(), _doSetFixedOutputState(), _selectOutputSchema(), _tocEntryRestorePass(), ahprintf(), pg_compress_specification::algorithm, append_data(), 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, _restoreOptions::noTablespace, _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(), main(), restore_global_objects(), and restore_one_database().

◆ SetArchiveOptions()

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

Definition at line 276 of file pg_backup_archiver.c.

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

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

Referenced by _CloseArchive(), main(), main(), restore_global_objects(), and restore_one_database().

◆ SortTocFromFile()

void SortTocFromFile ( Archive AHX)
extern

Definition at line 1588 of file pg_backup_archiver.c.

1589{
1590 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1591 RestoreOptions *ropt = AH->public.ropt;
1592 FILE *fh;
1594
1595 /* Allocate space for the 'wanted' array, and init it */
1596 ropt->idWanted = pg_malloc0_array(bool, AH->maxDumpId);
1597
1598 /* Setup the file */
1599 fh = fopen(ropt->tocFile, PG_BINARY_R);
1600 if (!fh)
1601 pg_fatal("could not open TOC file \"%s\": %m", ropt->tocFile);
1602
1604
1605 while (pg_get_line_buf(fh, &linebuf))
1606 {
1607 char *cmnt;
1608 char *endptr;
1609 DumpId id;
1610 TocEntry *te;
1611
1612 /* Truncate line at comment, if any */
1613 cmnt = strchr(linebuf.data, ';');
1614 if (cmnt != NULL)
1615 {
1616 cmnt[0] = '\0';
1617 linebuf.len = cmnt - linebuf.data;
1618 }
1619
1620 /* Ignore if all blank */
1621 if (strspn(linebuf.data, " \t\r\n") == linebuf.len)
1622 continue;
1623
1624 /* Get an ID, check it's valid and not already seen */
1625 id = strtol(linebuf.data, &endptr, 10);
1626 if (endptr == linebuf.data || id <= 0 || id > AH->maxDumpId ||
1627 ropt->idWanted[id - 1])
1628 {
1629 pg_log_warning("line ignored: %s", linebuf.data);
1630 continue;
1631 }
1632
1633 /* Find TOC entry */
1634 te = getTocEntryByDumpId(AH, id);
1635 if (!te)
1636 pg_fatal("could not find entry for ID %d",
1637 id);
1638
1639 /* Mark it wanted */
1640 ropt->idWanted[id - 1] = true;
1641
1642 /*
1643 * Move each item to the end of the list as it is selected, so that
1644 * they are placed in the desired order. Any unwanted items will end
1645 * up at the front of the list, which may seem unintuitive but it's
1646 * what we need. In an ordinary serial restore that makes no
1647 * difference, but in a parallel restore we need to mark unrestored
1648 * items' dependencies as satisfied before we start examining
1649 * restorable items. Otherwise they could have surprising
1650 * side-effects on the order in which restorable items actually get
1651 * restored.
1652 */
1653 _moveBefore(AH->toc, te);
1654 }
1655
1656 pg_free(linebuf.data);
1657
1658 if (fclose(fh) != 0)
1659 pg_fatal("could not close TOC file: %m");
1660}
#define PG_BINARY_R
Definition c.h:1339
#define pg_malloc0_array(type, count)
Definition fe_memutils.h:57
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 restore_one_database().

◆ StartLO()

int StartLO ( Archive AHX,
Oid  oid 
)
extern

Definition at line 1433 of file pg_backup_archiver.c.

1434{
1435 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1436
1437 if (!AH->StartLOPtr)
1438 pg_fatal("large-object output not supported in chosen format");
1439
1440 AH->StartLOPtr(AH, AH->currToc, oid);
1441
1442 return 1;
1443}
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 1238 of file pg_backup_archiver.c.

1239{
1240 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1241
1242 if (!AH->currToc)
1243 pg_fatal("internal error -- WriteData cannot be called outside the context of a DataDumper routine");
1244
1245 AH->WriteDataPtr(AH, data, dLen);
1246}
const void * data
WriteDataPtrType WriteDataPtr

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

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