PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 , TRI_DEFAULT ,
  TRI_NO , TRI_YES , TRI_DEFAULT , TRI_NO ,
  TRI_YES , 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_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 339 of file pg_backup.h.

◆ InvalidDumpId

#define InvalidDumpId   0

Definition at line 282 of file pg_backup.h.

◆ NUM_PREP_QUERIES

#define NUM_PREP_QUERIES   (PREPQUERY_GETDOMAINCONSTRAINTS + 1)

Definition at line 80 of file pg_backup.h.

Typedef Documentation

◆ Archive

typedef struct Archive Archive

◆ ArchiveFormat

◆ ArchiveMode

typedef enum _archiveMode ArchiveMode

◆ ConnParams

typedef struct _connParams ConnParams

◆ DumpId

typedef int DumpId

Definition at line 280 of file pg_backup.h.

◆ DumpOptions

typedef struct _dumpOptions DumpOptions

◆ RestoreOptions

◆ SetupWorkerPtrType

typedef void(* SetupWorkerPtrType) (Archive *AH)

Definition at line 287 of file pg_backup.h.

◆ teSection

typedef enum _teSection teSection

◆ trivalue

typedef enum trivalue 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_DUMPFUNC 
PREPQUERY_DUMPOPR 
PREPQUERY_DUMPRANGETYPE 
PREPQUERY_DUMPTABLEATTACH 
PREPQUERY_GETATTRIBUTESTATS 
PREPQUERY_GETCOLUMNACLS 
PREPQUERY_GETDOMAINCONSTRAINTS 

Definition at line 64 of file pg_backup.h.

65{
78};
@ PREPQUERY_DUMPFUNC
Definition: pg_backup.h:71
@ PREPQUERY_DUMPTABLEATTACH
Definition: pg_backup.h:74
@ PREPQUERY_DUMPBASETYPE
Definition: pg_backup.h:67
@ PREPQUERY_DUMPRANGETYPE
Definition: pg_backup.h:73
@ PREPQUERY_DUMPOPR
Definition: pg_backup.h:72
@ PREPQUERY_GETATTRIBUTESTATS
Definition: pg_backup.h:75
@ 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:76
@ PREPQUERY_GETDOMAINCONSTRAINTS
Definition: pg_backup.h:77
@ PREPQUERY_DUMPENUMTYPE
Definition: pg_backup.h:70

◆ _teSection

enum _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

enum trivalue
Enumerator
TRI_DEFAULT 
TRI_NO 
TRI_YES 
TRI_DEFAULT 
TRI_NO 
TRI_YES 
TRI_DEFAULT 
TRI_NO 
TRI_YES 
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,
  ... 
)

◆ archputs()

void archputs ( const char *  s,
Archive AH 
)

Definition at line 1635 of file pg_backup_archiver.c.

1636{
1637 WriteData(AH, s, strlen(s));
1638}
void WriteData(Archive *AHX, const void *data, size_t dLen)

References WriteData().

Referenced by dumpTableData_insert().

◆ CloseArchive()

void CloseArchive ( Archive AHX)

Definition at line 260 of file pg_backup_archiver.c.

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

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

Referenced by main(), and restore_one_database().

◆ ConnectDatabaseAhx()

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

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,
131 progname, NULL, NULL, password, cparams->override_dbname);
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:742
#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)
Definition: fe-connect.c:7687
char * PQpass(const PGconn *conn)
Definition: fe-connect.c:7471
PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
Definition: fe-connect.c:7800
void PQclear(PGresult *res)
Definition: fe-exec.c:721
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define free(a)
Definition: header.h:65
const char * progname
Definition: main.c:44
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:244
static void _check_database_version(ArchiveHandle *AH)
Definition: pg_backup_db.c:32
static void notice_processor(void *arg, const char *message)
Definition: pg_backup_db.c:201
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:93
char * pgport
Definition: pg_backup.h:87
char * pghost
Definition: pg_backup.h:88
trivalue promptPassword
Definition: pg_backup.h:90
char * username
Definition: pg_backup.h:89
char * dbname
Definition: pg_backup.h:86
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(), 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 
)

Definition at line 229 of file pg_backup_archiver.c.

235{
236 ArchiveHandle *AH = _allocAH(FileSpec, fmt, compression_spec,
238
239 return (Archive *) AH;
240}
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
Definition: pg_checksums.c:55
static bool dosync
Definition: pg_dump.c:147
static void setupDumpWorker(Archive *AH)
Definition: pg_dump.c:1515

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

Referenced by main().

◆ DisconnectDatabase()

void DisconnectDatabase ( Archive AHX)

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 */
185 set_archive_cancel_info(AH, NULL);
186 }
187
188 PQfinish(AH->connection);
189 AH->connection = NULL;
190}
int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize)
Definition: fe-cancel.c:530
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:7564
void PQfinish(PGconn *conn)
Definition: fe-connect.c:5290
@ PQTRANS_ACTIVE
Definition: libpq-fe.h:148
PGcancel *volatile connCancel

References _archiveHandle::connCancel, _archiveHandle::connection, 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)

Definition at line 163 of file pg_backup_archiver.c.

164{
165 DumpOptions *dopt = NewDumpOptions();
166
167 /* this is the inverse of what's at the end of pg_dump.c's main() */
168 dopt->cparams.dbname = ropt->cparams.dbname ? pg_strdup(ropt->cparams.dbname) : NULL;
169 dopt->cparams.pgport = ropt->cparams.pgport ? pg_strdup(ropt->cparams.pgport) : NULL;
170 dopt->cparams.pghost = ropt->cparams.pghost ? pg_strdup(ropt->cparams.pghost) : NULL;
171 dopt->cparams.username = ropt->cparams.username ? pg_strdup(ropt->cparams.username) : NULL;
173 dopt->outputClean = ropt->dropSchema;
174 dopt->dumpData = ropt->dumpData;
175 dopt->dumpSchema = ropt->dumpSchema;
176 dopt->dumpSections = ropt->dumpSections;
177 dopt->dumpStatistics = ropt->dumpStatistics;
178 dopt->if_exists = ropt->if_exists;
179 dopt->column_inserts = ropt->column_inserts;
180 dopt->aclsSkip = ropt->aclsSkip;
181 dopt->outputSuperuser = ropt->superuser;
182 dopt->outputCreateDB = ropt->createDB;
183 dopt->outputNoOwner = ropt->noOwner;
184 dopt->outputNoTableAm = ropt->noTableAm;
185 dopt->outputNoTablespaces = ropt->noTablespace;
187 dopt->use_setsessauth = ropt->use_setsessauth;
189 dopt->dump_inserts = ropt->dump_inserts;
190 dopt->no_comments = ropt->no_comments;
191 dopt->no_policies = ropt->no_policies;
192 dopt->no_publications = ropt->no_publications;
195 dopt->lockWaitTimeout = ropt->lockWaitTimeout;
198 dopt->sequence_data = ropt->sequence_data;
199
200 return dopt;
201}
DumpOptions * NewDumpOptions(void)
int dump_inserts
Definition: pg_backup.h:178
int column_inserts
Definition: pg_backup.h:182
int use_setsessauth
Definition: pg_backup.h:195
int outputCreateDB
Definition: pg_backup.h:203
bool include_everything
Definition: pg_backup.h:200
int sequence_data
Definition: pg_backup.h:209
int disable_dollar_quoting
Definition: pg_backup.h:181
bool dumpSchema
Definition: pg_backup.h:213
int no_comments
Definition: pg_backup.h:184
int outputNoTableAm
Definition: pg_backup.h:193
int enable_row_security
Definition: pg_backup.h:196
char * outputSuperuser
Definition: pg_backup.h:207
int dumpSections
Definition: pg_backup.h:175
int no_security_labels
Definition: pg_backup.h:187
bool dumpData
Definition: pg_backup.h:214
bool dumpStatistics
Definition: pg_backup.h:215
int no_publications
Definition: pg_backup.h:186
ConnParams cparams
Definition: pg_backup.h:170
const char * lockWaitTimeout
Definition: pg_backup.h:177
int no_subscriptions
Definition: pg_backup.h:188
bool aclsSkip
Definition: pg_backup.h:176
int outputClean
Definition: pg_backup.h:202
int no_policies
Definition: pg_backup.h:185
int outputNoTablespaces
Definition: pg_backup.h:194
int disable_triggers
Definition: pg_backup.h:192
int outputNoOwner
Definition: pg_backup.h:206
int include_everything
Definition: pg_backup.h:125
ConnParams cparams
Definition: pg_backup.h:145
int no_subscriptions
Definition: pg_backup.h:117
bool dumpStatistics
Definition: pg_backup.h:165
int disable_dollar_quoting
Definition: pg_backup.h:109
int no_security_labels
Definition: pg_backup.h:116
char * superuser
Definition: pg_backup.h:106
const char * lockWaitTimeout
Definition: pg_backup.h:124
int enable_row_security
Definition: pg_backup.h:158
int disable_triggers
Definition: pg_backup.h:102

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, _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::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 
)

Definition at line 1413 of file pg_backup_archiver.c.

1414{
1415 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1416
1417 if (AH->EndLOPtr)
1418 AH->EndLOPtr(AH, AH->currToc, oid);
1419
1420 return 1;
1421}
EndLOPtrType EndLOPtr
struct _tocEntry * currToc

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

Referenced by dumpLOs().

◆ GetConnection()

PGconn * GetConnection ( Archive AHX)

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)

Definition at line 146 of file pg_backup_archiver.c.

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

References DUMP_UNSECTIONED, opts, and TRI_DEFAULT.

Referenced by main(), and NewDumpOptions().

◆ NewDumpOptions()

DumpOptions * NewDumpOptions ( void  )

Definition at line 134 of file pg_backup_archiver.c.

135{
137
139 return opts;
140}
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void InitDumpOptions(DumpOptions *opts)

References InitDumpOptions(), opts, and pg_malloc().

Referenced by dumpOptionsFromRestoreOptions().

◆ NewRestoreOptions()

RestoreOptions * NewRestoreOptions ( void  )

Definition at line 1090 of file pg_backup_archiver.c.

1091{
1093
1095
1096 /* set any fields that shouldn't default to zeroes */
1097 opts->format = archUnknown;
1098 opts->cparams.promptPassword = TRI_DEFAULT;
1099 opts->dumpSections = DUMP_UNSECTIONED;
1100 opts->compression_spec.algorithm = PG_COMPRESSION_NONE;
1101 opts->compression_spec.level = 0;
1102 opts->dumpSchema = true;
1103 opts->dumpData = true;
1104 opts->dumpStatistics = true;
1105
1106 return opts;
1107}
@ PG_COMPRESSION_NONE
Definition: compression.h:23
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53

References archUnknown, DUMP_UNSECTIONED, opts, PG_COMPRESSION_NONE, pg_malloc0(), and TRI_DEFAULT.

Referenced by _CloseArchive(), and main().

◆ OpenArchive()

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

Definition at line 245 of file pg_backup_archiver.c.

246{
247 ArchiveHandle *AH;
248 pg_compress_specification compression_spec = {0};
249
250 compression_spec.algorithm = PG_COMPRESSION_NONE;
251 AH = _allocAH(FileSpec, fmt, compression_spec, true,
254
255 return (Archive *) AH;
256}
@ 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, PG_COMPRESSION_NONE, and setupRestoreWorker().

Referenced by restore_one_database().

◆ PrintTOCSummary()

void PrintTOCSummary ( Archive AHX)

Definition at line 1287 of file pg_backup_archiver.c.

1288{
1289 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1290 RestoreOptions *ropt = AH->public.ropt;
1291 TocEntry *te;
1292 pg_compress_specification out_compression_spec = {0};
1293 teSection curSection;
1294 CompressFileHandle *sav;
1295 const char *fmtName;
1296 char stamp_str[64];
1297
1298 /* TOC is always uncompressed */
1299 out_compression_spec.algorithm = PG_COMPRESSION_NONE;
1300
1301 sav = SaveOutput(AH);
1302 if (ropt->filename)
1303 SetOutput(AH, ropt->filename, out_compression_spec, false);
1304
1305 if (strftime(stamp_str, sizeof(stamp_str), PGDUMP_STRFTIME_FMT,
1306 localtime(&AH->createDate)) == 0)
1307 strcpy(stamp_str, "[unknown]");
1308
1309 ahprintf(AH, ";\n; Archive created at %s\n", stamp_str);
1310 ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %s\n",
1311 sanitize_line(AH->archdbname, false),
1312 AH->tocCount,
1314
1315 switch (AH->format)
1316 {
1317 case archCustom:
1318 fmtName = "CUSTOM";
1319 break;
1320 case archDirectory:
1321 fmtName = "DIRECTORY";
1322 break;
1323 case archTar:
1324 fmtName = "TAR";
1325 break;
1326 default:
1327 fmtName = "UNKNOWN";
1328 }
1329
1330 ahprintf(AH, "; Dump Version: %d.%d-%d\n",
1332 ahprintf(AH, "; Format: %s\n", fmtName);
1333 ahprintf(AH, "; Integer: %d bytes\n", (int) AH->intSize);
1334 ahprintf(AH, "; Offset: %d bytes\n", (int) AH->offSize);
1335 if (AH->archiveRemoteVersion)
1336 ahprintf(AH, "; Dumped from database version: %s\n",
1338 if (AH->archiveDumpVersion)
1339 ahprintf(AH, "; Dumped by pg_dump version: %s\n",
1340 AH->archiveDumpVersion);
1341
1342 ahprintf(AH, ";\n;\n; Selected TOC Entries:\n;\n");
1343
1344 curSection = SECTION_PRE_DATA;
1345 for (te = AH->toc->next; te != AH->toc; te = te->next)
1346 {
1347 /* This bit must match ProcessArchiveRestoreOptions' marking logic */
1348 if (te->section != SECTION_NONE)
1349 curSection = te->section;
1350 te->reqs = _tocEntryRequired(te, curSection, AH);
1351 /* Now, should we print it? */
1352 if (ropt->verbose ||
1353 (te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_STATS)) != 0)
1354 {
1355 char *sanitized_name;
1356 char *sanitized_schema;
1357 char *sanitized_owner;
1358
1359 /*
1360 */
1361 sanitized_name = sanitize_line(te->tag, false);
1362 sanitized_schema = sanitize_line(te->namespace, true);
1363 sanitized_owner = sanitize_line(te->owner, false);
1364
1365 ahprintf(AH, "%d; %u %u %s %s %s %s\n", te->dumpId,
1367 te->desc, sanitized_schema, sanitized_name,
1368 sanitized_owner);
1369
1370 free(sanitized_name);
1371 free(sanitized_schema);
1372 free(sanitized_owner);
1373 }
1374 if (ropt->verbose && te->nDeps > 0)
1375 {
1376 int i;
1377
1378 ahprintf(AH, ";\tdepends on:");
1379 for (i = 0; i < te->nDeps; i++)
1380 ahprintf(AH, " %d", te->dependencies[i]);
1381 ahprintf(AH, "\n");
1382 }
1383 }
1384
1385 /* Enforce strict names checking */
1386 if (ropt->strict_names)
1387 StrictNamesCheck(ropt);
1388
1389 if (ropt->filename)
1390 RestoreOutput(AH, sav);
1391}
const char * get_compress_algorithm_name(pg_compress_algorithm algorithm)
Definition: compression.c:69
#define PGDUMP_STRFTIME_FMT
Definition: dumputils.h:33
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 char * sanitize_line(const char *str, bool want_hyphen)
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:225
Oid tableoid
Definition: pg_backup.h:276
ArchiveFormat format
struct _tocEntry * toc
pg_compress_specification compression_spec
const char * filename
Definition: pg_backup.h:120
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, _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)

Definition at line 287 of file pg_backup_archiver.c.

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

References _tocEntryRequired(), archModeRead, _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(), and restore_one_database().

◆ RestoreArchive()

void RestoreArchive ( Archive AHX,
bool  append_data 
)

Definition at line 347 of file pg_backup_archiver.c.

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

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, PQExpBufferData::data, _tocEntry::desc, destroyPQExpBuffer(), DisconnectDatabase(), DropLOIfExists(), _restoreOptions::dropSchema, _tocEntry::dropStmt, _restoreOptions::dumpSchema, dumpTimestamp(), errmsg(), _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(), 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(), and restore_one_database().

◆ SetArchiveOptions()

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

Definition at line 274 of file pg_backup_archiver.c.

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

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

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

◆ SortTocFromFile()

void SortTocFromFile ( Archive AHX)

Definition at line 1554 of file pg_backup_archiver.c.

1555{
1556 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1557 RestoreOptions *ropt = AH->public.ropt;
1558 FILE *fh;
1559 StringInfoData linebuf;
1560
1561 /* Allocate space for the 'wanted' array, and init it */
1562 ropt->idWanted = (bool *) pg_malloc0(sizeof(bool) * AH->maxDumpId);
1563
1564 /* Setup the file */
1565 fh = fopen(ropt->tocFile, PG_BINARY_R);
1566 if (!fh)
1567 pg_fatal("could not open TOC file \"%s\": %m", ropt->tocFile);
1568
1569 initStringInfo(&linebuf);
1570
1571 while (pg_get_line_buf(fh, &linebuf))
1572 {
1573 char *cmnt;
1574 char *endptr;
1575 DumpId id;
1576 TocEntry *te;
1577
1578 /* Truncate line at comment, if any */
1579 cmnt = strchr(linebuf.data, ';');
1580 if (cmnt != NULL)
1581 {
1582 cmnt[0] = '\0';
1583 linebuf.len = cmnt - linebuf.data;
1584 }
1585
1586 /* Ignore if all blank */
1587 if (strspn(linebuf.data, " \t\r\n") == linebuf.len)
1588 continue;
1589
1590 /* Get an ID, check it's valid and not already seen */
1591 id = strtol(linebuf.data, &endptr, 10);
1592 if (endptr == linebuf.data || id <= 0 || id > AH->maxDumpId ||
1593 ropt->idWanted[id - 1])
1594 {
1595 pg_log_warning("line ignored: %s", linebuf.data);
1596 continue;
1597 }
1598
1599 /* Find TOC entry */
1600 te = getTocEntryByDumpId(AH, id);
1601 if (!te)
1602 pg_fatal("could not find entry for ID %d",
1603 id);
1604
1605 /* Mark it wanted */
1606 ropt->idWanted[id - 1] = true;
1607
1608 /*
1609 * Move each item to the end of the list as it is selected, so that
1610 * they are placed in the desired order. Any unwanted items will end
1611 * up at the front of the list, which may seem unintuitive but it's
1612 * what we need. In an ordinary serial restore that makes no
1613 * difference, but in a parallel restore we need to mark unrestored
1614 * items' dependencies as satisfied before we start examining
1615 * restorable items. Otherwise they could have surprising
1616 * side-effects on the order in which restorable items actually get
1617 * restored.
1618 */
1619 _moveBefore(AH->toc, te);
1620 }
1621
1622 pg_free(linebuf.data);
1623
1624 if (fclose(fh) != 0)
1625 pg_fatal("could not close TOC file: %m");
1626}
#define PG_BINARY_R
Definition: c.h:1246
int DumpId
Definition: pg_backup.h:280
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
bool * idWanted
Definition: pg_backup.h:157
char * tocFile
Definition: pg_backup.h:128

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

Referenced by restore_one_database().

◆ StartLO()

int StartLO ( Archive AHX,
Oid  oid 
)

Definition at line 1399 of file pg_backup_archiver.c.

1400{
1401 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1402
1403 if (!AH->StartLOPtr)
1404 pg_fatal("large-object output not supported in chosen format");
1405
1406 AH->StartLOPtr(AH, AH->currToc, oid);
1407
1408 return 1;
1409}
StartLOPtrType StartLOPtr

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

Referenced by dumpLOs().

◆ WriteData()

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

Definition at line 1204 of file pg_backup_archiver.c.

1205{
1206 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1207
1208 if (!AH->currToc)
1209 pg_fatal("internal error -- WriteData cannot be called outside the context of a DataDumper routine");
1210
1211 AH->WriteDataPtr(AH, data, dLen);
1212}
const void * data
WriteDataPtrType WriteDataPtr

References _archiveHandle::currToc, data, pg_fatal, and _archiveHandle::WriteDataPtr.

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