PostgreSQL Source Code git master
Data Structures | Macros | Typedefs | Enumerations | Functions
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  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   _archiveFormat {
  archUnknown = 0 , archCustom = 1 , archTar = 3 , archNull = 4 ,
  archDirectory = 5
}
 
 
 
 

Functions

void  ConnectDatabaseAhx (Archive *AHX, const ConnParams *cparams, bool isReconnect)
 
 
 
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  RestoreArchive (Archive *AHX)
 
ArchiveOpenArchive (const char *FileSpec, const ArchiveFormat fmt)
 
 
void  PrintTOCSummary (Archive *AHX)
 
 
 
 
 
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 343 of file pg_backup.h.

InvalidDumpId

#define InvalidDumpId   0

Definition at line 286 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 284 of file pg_backup.h.

DumpOptions

typedef struct _dumpOptions DumpOptions

RestoreOptions

SetupWorkerPtrType

typedef void(* SetupWorkerPtrType) (Archive *AH)

Definition at line 291 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 ( ArchiveAH,
const char *  fmt,
  ... 
)

Referenced by dumpTableData_copy(), and dumpTableData_insert().

archputs()

void archputs ( const char *  s,
ArchiveAH 
)

Definition at line 1651 of file pg_backup_archiver.c.

1652{
1653 WriteData(AH, s, strlen(s));
1654}
void WriteData(Archive *AHX, const void *data, size_t dLen)

References WriteData().

Referenced by dumpTableData_insert().

CloseArchive()

void CloseArchive ( ArchiveAHX )

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)
Definition: compress_io.c:289
#define pg_fatal(...)
ClosePtrType ClosePtr

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

Referenced by main().

ConnectDatabaseAhx()

void ConnectDatabaseAhx ( ArchiveAHX,
const ConnParamscparams,
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:732
#define ALWAYS_SECURE_SEARCH_PATH_SQL
Definition: connect.h:25
PGconn * ConnectDatabase(const char *dbname, const char *connection_string, const char *pghost, const char *pgport, const char *pguser, trivalue prompt_password, bool fail_on_error, const char *progname, const char **connstr, int *server_version, char *password, char *override_dbname)
Definition: connectdb.c:40
int PQconnectionUsedPassword(const PGconn *conn)
Definition: fe-connect.c:7747
char * PQpass(const PGconn *conn)
Definition: fe-connect.c:7529
PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
Definition: fe-connect.c:7860
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define free(a)
Definition: header.h:65
#define PQclear
Definition: libpq-be-fe.h:245
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 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
Definition: pg_checksums.c:55
static bool dosync
Definition: pg_dump.c:150
static void setupDumpWorker(Archive *AH)
Definition: pg_dump.c:1582

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

Referenced by main().

DisconnectDatabase()

void DisconnectDatabase ( ArchiveAHX )

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:548
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:7624
void PQfinish(PGconn *conn)
Definition: fe-connect.c:5305
@ 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 ( RestoreOptionsropt )

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;
172 dopt->cparams.username = ropt->cparams.username ? pg_strdup(ropt->cparams.username) : 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)
int dump_inserts
Definition: pg_backup.h:180
char * restrict_key
Definition: pg_backup.h:219
int column_inserts
Definition: pg_backup.h:184
int use_setsessauth
Definition: pg_backup.h:197
int if_exists
Definition: pg_backup.h:185
int outputCreateDB
Definition: pg_backup.h:205
bool include_everything
Definition: pg_backup.h:202
int sequence_data
Definition: pg_backup.h:211
int disable_dollar_quoting
Definition: pg_backup.h:183
bool dumpSchema
Definition: pg_backup.h:215
int no_comments
Definition: pg_backup.h:186
int outputNoTableAm
Definition: pg_backup.h:195
int enable_row_security
Definition: pg_backup.h:198
char * outputSuperuser
Definition: pg_backup.h:209
int dumpSections
Definition: pg_backup.h:177
int no_security_labels
Definition: pg_backup.h:189
bool dumpData
Definition: pg_backup.h:216
bool dumpStatistics
Definition: pg_backup.h:217
int no_publications
Definition: pg_backup.h:188
ConnParams cparams
Definition: pg_backup.h:172
const char * lockWaitTimeout
Definition: pg_backup.h:179
int no_subscriptions
Definition: pg_backup.h:190
bool aclsSkip
Definition: pg_backup.h:178
int outputClean
Definition: pg_backup.h:204
int no_policies
Definition: pg_backup.h:187
int outputNoTablespaces
Definition: pg_backup.h:196
int disable_triggers
Definition: pg_backup.h:194
int outputNoOwner
Definition: pg_backup.h:208
int sequence_data
Definition: pg_backup.h:159
int no_publications
Definition: pg_backup.h:115
int include_everything
Definition: pg_backup.h:125
int column_inserts
Definition: pg_backup.h:111
ConnParams cparams
Definition: pg_backup.h:145
int createDB
Definition: pg_backup.h:98
int noTablespace
Definition: pg_backup.h:101
int dumpSections
Definition: pg_backup.h:121
int dropSchema
Definition: pg_backup.h:108
int no_subscriptions
Definition: pg_backup.h:117
int no_policies
Definition: pg_backup.h:114
int no_comments
Definition: pg_backup.h:113
bool dumpStatistics
Definition: pg_backup.h:165
int disable_dollar_quoting
Definition: pg_backup.h:109
char * restrict_key
Definition: pg_backup.h:167
int no_security_labels
Definition: pg_backup.h:116
bool dumpSchema
Definition: pg_backup.h:163
bool dumpData
Definition: pg_backup.h:164
char * superuser
Definition: pg_backup.h:106
int dump_inserts
Definition: pg_backup.h:110
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
int use_setsessauth
Definition: pg_backup.h:104

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::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 ( ArchiveAHX,
Oid  oid 
)

Definition at line 1429 of file pg_backup_archiver.c.

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

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

Referenced by dumpLOs().

GetConnection()

PGconn * GetConnection ( ArchiveAHX )

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 ( DumpOptionsopts )

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, opts, and TRI_DEFAULT.

Referenced by main(), and NewDumpOptions().

NewDumpOptions()

DumpOptions * NewDumpOptions ( void  )

Definition at line 135 of file pg_backup_archiver.c.

136{
138
140 return opts;
141}
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 1106 of file pg_backup_archiver.c.

1107{
1109
1111
1112 /* set any fields that shouldn't default to zeroes */
1113 opts->format = archUnknown;
1114 opts->cparams.promptPassword = TRI_DEFAULT;
1115 opts->dumpSections = DUMP_UNSECTIONED;
1116 opts->compression_spec.algorithm = PG_COMPRESSION_NONE;
1117 opts->compression_spec.level = 0;
1118 opts->dumpSchema = true;
1119 opts->dumpData = true;
1120 opts->dumpStatistics = true;
1121
1122 return opts;
1123}
@ 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 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, PG_COMPRESSION_NONE, and setupRestoreWorker().

Referenced by main().

PrintTOCSummary()

void PrintTOCSummary ( ArchiveAHX )

Definition at line 1303 of file pg_backup_archiver.c.

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

ProcessArchiveRestoreOptions()

void ProcessArchiveRestoreOptions ( ArchiveAHX )

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;
294 teSection curSection;
295
296 /* Decide which TOC entries will be dumped/restored, and mark them */
297 curSection = SECTION_PRE_DATA;
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:
314 if (curSection != SECTION_PRE_DATA)
315 pg_log_warning("archive items not in correct section order");
316 break;
317 case SECTION_DATA:
318 if (curSection == SECTION_POST_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
ArchiveMode mode

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().

RestoreArchive()

void RestoreArchive ( ArchiveAHX )

Definition at line 344 of file pg_backup_archiver.c.

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

References _becomeOwner(), _doSetFixedOutputState(), _selectOutputSchema(), _tocEntryRestorePass(), ahprintf(), pg_compress_specification::algorithm, appendPQExpBuffer(), appendPQExpBufferStr(), _archiveHandle::archiveDumpVersion, _archiveHandle::archiveRemoteVersion, Assert(), buildTocEntryArrays(), _tocEntry::catalogId, _archiveHandle::ClonePtr, CommitTransaction(), _restoreOptions::compression_spec, _archiveHandle::compression_spec, ConnectDatabaseAhx(), _archiveHandle::connection, _restoreOptions::cparams, _archiveHandle::createDate, _restoreOptions::createDB, createPQExpBuffer(), _archiveHandle::currentTE, _archiveHandle::currSchema, 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(), _restoreOptions::restrict_key, Archive::ropt, SaveOutput(), SetOutput(), _restoreOptions::single_txn, snprintf, _archiveHandle::stage, STAGE_FINALIZING, STAGE_INITIALIZING, STAGE_PROCESSING, StartTransaction(), supports_compression(), _tocEntry::tag, _archiveHandle::toc, _archiveHandle::tocsByDumpId, _restoreOptions::txn_size, _archiveHandle::txnCount, _restoreOptions::useDB, Archive::verbose, and _archiveHandle::version.

Referenced by _CloseArchive(), and main().

SetArchiveOptions()

void SetArchiveOptions ( ArchiveAH,
DumpOptionsdopt,
RestoreOptionsropt 
)

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:228

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

Referenced by _CloseArchive(), and main().

SortTocFromFile()

void SortTocFromFile ( ArchiveAHX )

Definition at line 1570 of file pg_backup_archiver.c.

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

StartLO()

int StartLO ( ArchiveAHX,
Oid  oid 
)

Definition at line 1415 of file pg_backup_archiver.c.

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

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

Referenced by dumpLOs().

WriteData()

void WriteData ( ArchiveAHX,
const void *  data,
size_t  dLen 
)

Definition at line 1220 of file pg_backup_archiver.c.

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

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

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

AltStyle によって変換されたページ (->オリジナル) /