PostgreSQL Source Code  git master
pg_backup.h File Reference
#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 int(* DataDumperPtr) (Archive *AH, const void *userArg)
 
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_GETCOLUMNACLS , PREPQUERY_GETDOMAINCONSTRAINTS , NUM_PREP_QUERIES
}
 

Functions

void ConnectDatabase (Archive *AHX, const ConnParams *cparams, bool isReconnect)
 
void DisconnectDatabase (Archive *AHX)
 
PGconnGetConnection (Archive *AHX)
 
void WriteData (Archive *AH, const void *data, size_t dLen)
 
int StartBlob (Archive *AH, Oid oid)
 
int EndBlob (Archive *AH, Oid oid)
 
void CloseArchive (Archive *AH)
 
void SetArchiveOptions (Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
 
void ProcessArchiveRestoreOptions (Archive *AH)
 
void RestoreArchive (Archive *AH)
 
ArchiveOpenArchive (const char *FileSpec, const ArchiveFormat fmt)
 
ArchiveCreateArchive (const char *FileSpec, const ArchiveFormat fmt, const int compression, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupDumpWorker)
 
void PrintTOCSummary (Archive *AH)
 
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 325 of file pg_backup.h.

◆ InvalidDumpId

#define InvalidDumpId   0

Definition at line 267 of file pg_backup.h.

Typedef Documentation

◆ Archive

typedef struct Archive Archive

◆ ArchiveFormat

◆ ArchiveMode

typedef enum _archiveMode ArchiveMode

◆ ConnParams

typedef struct _connParams ConnParams

◆ DataDumperPtr

typedef int(* DataDumperPtr) (Archive *AH, const void *userArg)

Definition at line 273 of file pg_backup.h.

◆ DumpId

typedef int DumpId

Definition at line 265 of file pg_backup.h.

◆ DumpOptions

typedef struct _dumpOptions DumpOptions

◆ RestoreOptions

◆ SetupWorkerPtrType

typedef void(* SetupWorkerPtrType) (Archive *AH)

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

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

◆ _archiveMode

Enumerator
archModeAppend 
archModeWrite 
archModeRead 

Definition at line 46 of file pg_backup.h.

47 {
51 } ArchiveMode;
@ archModeWrite
Definition: pg_backup.h:49
@ archModeAppend
Definition: pg_backup.h:48
@ archModeRead
Definition: pg_backup.h:50
enum _archiveMode ArchiveMode

◆ _dumpPreparedQueries

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

Definition at line 62 of file pg_backup.h.

63 {
75  NUM_PREP_QUERIES /* must be last */
76 };
@ PREPQUERY_DUMPFUNC
Definition: pg_backup.h:69
@ PREPQUERY_DUMPTABLEATTACH
Definition: pg_backup.h:72
@ PREPQUERY_DUMPBASETYPE
Definition: pg_backup.h:65
@ PREPQUERY_DUMPRANGETYPE
Definition: pg_backup.h:71
@ PREPQUERY_DUMPOPR
Definition: pg_backup.h:70
@ PREPQUERY_DUMPDOMAIN
Definition: pg_backup.h:67
@ NUM_PREP_QUERIES
Definition: pg_backup.h:75
@ PREPQUERY_DUMPCOMPOSITETYPE
Definition: pg_backup.h:66
@ PREPQUERY_DUMPAGG
Definition: pg_backup.h:64
@ PREPQUERY_GETCOLUMNACLS
Definition: pg_backup.h:73
@ PREPQUERY_GETDOMAINCONSTRAINTS
Definition: pg_backup.h:74
@ PREPQUERY_DUMPENUMTYPE
Definition: pg_backup.h:68

◆ _teSection

enum _teSection
Enumerator
SECTION_NONE 
SECTION_PRE_DATA 
SECTION_DATA 
SECTION_POST_DATA 

Definition at line 53 of file pg_backup.h.

54 {
55  SECTION_NONE = 1, /* COMMENTs, ACLs, etc; can be anywhere */
56  SECTION_PRE_DATA, /* stuff to be processed before data */
57  SECTION_DATA, /* TABLE DATA, BLOBS, BLOB COMMENTS */
58  SECTION_POST_DATA /* stuff to be processed after data */
59 } teSection;
@ SECTION_NONE
Definition: pg_backup.h:55
@ SECTION_POST_DATA
Definition: pg_backup.h:58
@ SECTION_PRE_DATA
Definition: pg_backup.h:56
@ SECTION_DATA
Definition: pg_backup.h:57
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 30 of file pg_backup.h.

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

Function Documentation

◆ archprintf()

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

◆ archputs()

void archputs ( const char *  s,
Archive AH 
)

Definition at line 1443 of file pg_backup_archiver.c.

1444 {
1445  WriteData(AH, s, strlen(s));
1446 }
void WriteData(Archive *AHX, const void *data, size_t dLen)

References WriteData().

Referenced by dumpTableData_insert().

◆ CloseArchive()

void CloseArchive ( Archive AH)

Definition at line 264 of file pg_backup_archiver.c.

265 {
266  int res = 0;
267  ArchiveHandle *AH = (ArchiveHandle *) AHX;
268 
269  AH->ClosePtr(AH);
270 
271  /* Close the output */
272  errno = 0; /* in case gzclose() doesn't set it */
273  if (AH->gzOut)
274  res = GZCLOSE(AH->OF);
275  else if (AH->OF != stdout)
276  res = fclose(AH->OF);
277 
278  if (res != 0)
279  pg_fatal("could not close output file: %m");
280 }
#define GZCLOSE(fh)
#define pg_fatal(...)
ClosePtrType ClosePtr

References _archiveHandle::ClosePtr, GZCLOSE, _archiveHandle::gzOut, _archiveHandle::OF, pg_fatal, res, and generate_unaccent_rules::stdout.

Referenced by main().

◆ ConnectDatabase()

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

Definition at line 110 of file pg_backup_db.c.

113 {
114  ArchiveHandle *AH = (ArchiveHandle *) AHX;
115  trivalue prompt_password;
116  char *password;
117  bool new_pass;
118 
119  if (AH->connection)
120  pg_fatal("already connected to a database");
121 
122  /* Never prompt for a password during a reconnection */
123  prompt_password = isReconnect ? TRI_NO : cparams->promptPassword;
124 
125  password = AH->savedPassword;
126 
127  if (prompt_password == TRI_YES && password == NULL)
128  password = simple_prompt("Password: ", false);
129 
130  /*
131  * Start the connection. Loop until we have a password if requested by
132  * backend.
133  */
134  do
135  {
136  const char *keywords[8];
137  const char *values[8];
138  int i = 0;
139 
140  /*
141  * If dbname is a connstring, its entries can override the other
142  * values obtained from cparams; but in turn, override_dbname can
143  * override the dbname component of it.
144  */
145  keywords[i] = "host";
146  values[i++] = cparams->pghost;
147  keywords[i] = "port";
148  values[i++] = cparams->pgport;
149  keywords[i] = "user";
150  values[i++] = cparams->username;
151  keywords[i] = "password";
152  values[i++] = password;
153  keywords[i] = "dbname";
154  values[i++] = cparams->dbname;
155  if (cparams->override_dbname)
156  {
157  keywords[i] = "dbname";
158  values[i++] = cparams->override_dbname;
159  }
160  keywords[i] = "fallback_application_name";
161  values[i++] = progname;
162  keywords[i] = NULL;
163  values[i++] = NULL;
164  Assert(i <= lengthof(keywords));
165 
166  new_pass = false;
167  AH->connection = PQconnectdbParams(keywords, values, true);
168 
169  if (!AH->connection)
170  pg_fatal("could not connect to database");
171 
172  if (PQstatus(AH->connection) == CONNECTION_BAD &&
174  password == NULL &&
175  prompt_password != TRI_NO)
176  {
177  PQfinish(AH->connection);
178  password = simple_prompt("Password: ", false);
179  new_pass = true;
180  }
181  } while (new_pass);
182 
183  /* check to see that the backend connection was successfully made */
184  if (PQstatus(AH->connection) == CONNECTION_BAD)
185  {
186  if (isReconnect)
187  pg_fatal("reconnection failed: %s",
189  else
190  pg_fatal("%s",
192  }
193 
194  /* Start strict; later phases may override this. */
197 
198  if (password && password != AH->savedPassword)
199  free(password);
200 
201  /*
202  * We want to remember connection's actual password, whether or not we got
203  * it by prompting. So we don't just store the password variable.
204  */
206  {
207  if (AH->savedPassword)
208  free(AH->savedPassword);
210  }
211 
212  /* check for version mismatch */
214 
216 
217  /* arrange for SIGINT to issue a query cancel on this connection */
219 }
void set_archive_cancel_info(ArchiveHandle *AH, PGconn *conn)
Definition: parallel.c:732
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define lengthof(array)
Definition: c.h:734
#define ALWAYS_SECURE_SEARCH_PATH_SQL
Definition: connect.h:25
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
Definition: fe-connect.c:658
int PQconnectionUsedPassword(const PGconn *conn)
Definition: fe-connect.c:6974
int PQconnectionNeedsPassword(const PGconn *conn)
Definition: fe-connect.c:6959
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6908
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:6855
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4261
char * PQpass(const PGconn *conn)
Definition: fe-connect.c:6770
PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
Definition: fe-connect.c:7076
void PQclear(PGresult *res)
Definition: fe-exec.c:718
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define free(a)
Definition: header.h:65
int i
Definition: isn.c:73
@ CONNECTION_BAD
Definition: libpq-fe.h:61
Assert(fmt[strlen(fmt) - 1] !='\n')
const char * progname
Definition: main.c:50
static void _check_database_version(ArchiveHandle *AH)
Definition: pg_backup_db.c:33
static void notice_processor(void *arg, const char *message)
Definition: pg_backup_db.c:263
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:306
char * simple_prompt(const char *prompt, bool echo)
Definition: sprompt.c:38
static char * password
Definition: streamutil.c:53
char * override_dbname
Definition: pg_backup.h:89
char * pgport
Definition: pg_backup.h:83
char * pghost
Definition: pg_backup.h:84
trivalue promptPassword
Definition: pg_backup.h:86
char * username
Definition: pg_backup.h:85
char * dbname
Definition: pg_backup.h:82
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, Assert(), _archiveHandle::connection, CONNECTION_BAD, _connParams::dbname, ExecuteSqlQueryForSingleRow(), free, i, lengthof, notice_processor(), _connParams::override_dbname, password, pg_fatal, pg_strdup(), _connParams::pghost, _connParams::pgport, PQclear(), PQconnectdbParams(), PQconnectionNeedsPassword(), PQconnectionUsedPassword(), PQerrorMessage(), PQfinish(), PQpass(), PQsetNoticeProcessor(), PQstatus(), progname, _connParams::promptPassword, _archiveHandle::savedPassword, set_archive_cancel_info(), simple_prompt(), TRI_NO, TRI_YES, _connParams::username, and values.

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

◆ CreateArchive()

Archive* CreateArchive ( const char *  FileSpec,
const ArchiveFormat  fmt,
const int  compression,
bool  dosync,
ArchiveMode  mode,
SetupWorkerPtrType  setupDumpWorker 
)

Definition at line 241 of file pg_backup_archiver.c.

245 {
246  ArchiveHandle *AH = _allocAH(FileSpec, fmt, compression, dosync,
248 
249  return (Archive *) AH;
250 }
static void const char * fmt
static ArchiveHandle * _allocAH(const char *FileSpec, const ArchiveFormat fmt, const int compression, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupWorkerPtr)
static PgChecksumMode mode
Definition: pg_checksums.c:65
static bool dosync
Definition: pg_dump.c:100
static void setupDumpWorker(Archive *AHX)
Definition: pg_dump.c:1232

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

Referenced by main().

◆ DisconnectDatabase()

void DisconnectDatabase ( Archive AHX)

Definition at line 226 of file pg_backup_db.c.

227 {
228  ArchiveHandle *AH = (ArchiveHandle *) AHX;
229  char errbuf[1];
230 
231  if (!AH->connection)
232  return;
233 
234  if (AH->connCancel)
235  {
236  /*
237  * If we have an active query, send a cancel before closing, ignoring
238  * any errors. This is of no use for a normal exit, but might be
239  * helpful during pg_fatal().
240  */
242  (void) PQcancel(AH->connCancel, errbuf, sizeof(errbuf));
243 
244  /*
245  * Prevent signal handler from sending a cancel after this.
246  */
247  set_archive_cancel_info(AH, NULL);
248  }
249 
250  PQfinish(AH->connection);
251  AH->connection = NULL;
252 }
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:6863
int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize)
Definition: fe-connect.c:4481
@ PQTRANS_ACTIVE
Definition: libpq-fe.h:119
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 177 of file pg_backup_archiver.c.

178 {
179  DumpOptions *dopt = NewDumpOptions();
180 
181  /* this is the inverse of what's at the end of pg_dump.c's main() */
182  dopt->cparams.dbname = ropt->cparams.dbname ? pg_strdup(ropt->cparams.dbname) : NULL;
183  dopt->cparams.pgport = ropt->cparams.pgport ? pg_strdup(ropt->cparams.pgport) : NULL;
184  dopt->cparams.pghost = ropt->cparams.pghost ? pg_strdup(ropt->cparams.pghost) : NULL;
185  dopt->cparams.username = ropt->cparams.username ? pg_strdup(ropt->cparams.username) : NULL;
187  dopt->outputClean = ropt->dropSchema;
188  dopt->dataOnly = ropt->dataOnly;
189  dopt->schemaOnly = ropt->schemaOnly;
190  dopt->if_exists = ropt->if_exists;
191  dopt->column_inserts = ropt->column_inserts;
192  dopt->dumpSections = ropt->dumpSections;
193  dopt->aclsSkip = ropt->aclsSkip;
194  dopt->outputSuperuser = ropt->superuser;
195  dopt->outputCreateDB = ropt->createDB;
196  dopt->outputNoOwner = ropt->noOwner;
197  dopt->outputNoTableAm = ropt->noTableAm;
198  dopt->outputNoTablespaces = ropt->noTablespace;
199  dopt->disable_triggers = ropt->disable_triggers;
200  dopt->use_setsessauth = ropt->use_setsessauth;
202  dopt->dump_inserts = ropt->dump_inserts;
203  dopt->no_comments = ropt->no_comments;
204  dopt->no_publications = ropt->no_publications;
206  dopt->no_subscriptions = ropt->no_subscriptions;
207  dopt->lockWaitTimeout = ropt->lockWaitTimeout;
210  dopt->sequence_data = ropt->sequence_data;
211 
212  return dopt;
213 }
DumpOptions * NewDumpOptions(void)
bool dataOnly
Definition: pg_backup.h:165
int dump_inserts
Definition: pg_backup.h:169
int column_inserts
Definition: pg_backup.h:173
int use_setsessauth
Definition: pg_backup.h:185
int outputCreateDB
Definition: pg_backup.h:193
bool include_everything
Definition: pg_backup.h:190
int sequence_data
Definition: pg_backup.h:199
int disable_dollar_quoting
Definition: pg_backup.h:172
int no_comments
Definition: pg_backup.h:175
int outputNoTableAm
Definition: pg_backup.h:183
int enable_row_security
Definition: pg_backup.h:186
char * outputSuperuser
Definition: pg_backup.h:197
int dumpSections
Definition: pg_backup.h:166
int no_security_labels
Definition: pg_backup.h:176
int no_publications
Definition: pg_backup.h:177
ConnParams cparams
Definition: pg_backup.h:159
const char * lockWaitTimeout
Definition: pg_backup.h:168
int no_subscriptions
Definition: pg_backup.h:178
bool aclsSkip
Definition: pg_backup.h:167
int outputClean
Definition: pg_backup.h:192
int outputNoTablespaces
Definition: pg_backup.h:184
int disable_triggers
Definition: pg_backup.h:182
int outputNoOwner
Definition: pg_backup.h:196
bool schemaOnly
Definition: pg_backup.h:164
int include_everything
Definition: pg_backup.h:122
ConnParams cparams
Definition: pg_backup.h:142
int no_subscriptions
Definition: pg_backup.h:112
int disable_dollar_quoting
Definition: pg_backup.h:105
int no_security_labels
Definition: pg_backup.h:111
char * superuser
Definition: pg_backup.h:102
const char * lockWaitTimeout
Definition: pg_backup.h:121
int enable_row_security
Definition: pg_backup.h:152
int disable_triggers
Definition: pg_backup.h:98

References _restoreOptions::aclsSkip, _dumpOptions::aclsSkip, _restoreOptions::column_inserts, _dumpOptions::column_inserts, _restoreOptions::cparams, _dumpOptions::cparams, _restoreOptions::createDB, _restoreOptions::dataOnly, _dumpOptions::dataOnly, _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::dumpSections, _dumpOptions::dumpSections, _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_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::schemaOnly, _dumpOptions::schemaOnly, _restoreOptions::sequence_data, _dumpOptions::sequence_data, _restoreOptions::superuser, _restoreOptions::use_setsessauth, _dumpOptions::use_setsessauth, and _connParams::username.

Referenced by SetArchiveOptions().

◆ EndBlob()

int EndBlob ( Archive AH,
Oid  oid 
)

Definition at line 1232 of file pg_backup_archiver.c.

1233 {
1234  ArchiveHandle *AH = (ArchiveHandle *) AHX;
1235 
1236  if (AH->EndBlobPtr)
1237  AH->EndBlobPtr(AH, AH->currToc, oid);
1238 
1239  return 1;
1240 }
EndBlobPtrType EndBlobPtr
struct _tocEntry * currToc

References _archiveHandle::currToc, and _archiveHandle::EndBlobPtr.

Referenced by dumpBlobs().

◆ GetConnection()

PGconn* GetConnection ( Archive AHX)

Definition at line 255 of file pg_backup_db.c.

256 {
257  ArchiveHandle *AH = (ArchiveHandle *) AHX;
258 
259  return AH->connection;
260 }

References _archiveHandle::connection.

◆ InitDumpOptions()

void InitDumpOptions ( DumpOptions opts)

Definition at line 163 of file pg_backup_archiver.c.

164 {
165  memset(opts, 0, sizeof(DumpOptions));
166  /* set any fields that shouldn't default to zeroes */
167  opts->include_everything = true;
168  opts->cparams.promptPassword = TRI_DEFAULT;
169  opts->dumpSections = DUMP_UNSECTIONED;
170 }
static AmcheckOptions opts
Definition: pg_amcheck.c:110
#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 151 of file pg_backup_archiver.c.

152 {
154 
156  return opts;
157 }
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 963 of file pg_backup_archiver.c.

964 {
966 
968 
969  /* set any fields that shouldn't default to zeroes */
970  opts->format = archUnknown;
971  opts->cparams.promptPassword = TRI_DEFAULT;
972  opts->dumpSections = DUMP_UNSECTIONED;
973 
974  return opts;
975 }
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53

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

Referenced by _CloseArchive(), and main().

◆ OpenArchive()

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

Definition at line 255 of file pg_backup_archiver.c.

256 {
257  ArchiveHandle *AH = _allocAH(FileSpec, fmt, 0, true, archModeRead, setupRestoreWorker);
258 
259  return (Archive *) AH;
260 }
static void setupRestoreWorker(Archive *AHX)

References _allocAH(), archModeRead, fmt, and setupRestoreWorker().

Referenced by main().

◆ PrintTOCSummary()

void PrintTOCSummary ( Archive AH)

Definition at line 1114 of file pg_backup_archiver.c.

1115 {
1116  ArchiveHandle *AH = (ArchiveHandle *) AHX;
1117  RestoreOptions *ropt = AH->public.ropt;
1118  TocEntry *te;
1119  teSection curSection;
1120  OutputContext sav;
1121  const char *fmtName;
1122  char stamp_str[64];
1123 
1124  sav = SaveOutput(AH);
1125  if (ropt->filename)
1126  SetOutput(AH, ropt->filename, 0 /* no compression */ );
1127 
1128  if (strftime(stamp_str, sizeof(stamp_str), PGDUMP_STRFTIME_FMT,
1129  localtime(&AH->createDate)) == 0)
1130  strcpy(stamp_str, "[unknown]");
1131 
1132  ahprintf(AH, ";\n; Archive created at %s\n", stamp_str);
1133  ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n",
1134  sanitize_line(AH->archdbname, false),
1135  AH->tocCount, AH->compression);
1136 
1137  switch (AH->format)
1138  {
1139  case archCustom:
1140  fmtName = "CUSTOM";
1141  break;
1142  case archDirectory:
1143  fmtName = "DIRECTORY";
1144  break;
1145  case archTar:
1146  fmtName = "TAR";
1147  break;
1148  default:
1149  fmtName = "UNKNOWN";
1150  }
1151 
1152  ahprintf(AH, "; Dump Version: %d.%d-%d\n",
1154  ahprintf(AH, "; Format: %s\n", fmtName);
1155  ahprintf(AH, "; Integer: %d bytes\n", (int) AH->intSize);
1156  ahprintf(AH, "; Offset: %d bytes\n", (int) AH->offSize);
1157  if (AH->archiveRemoteVersion)
1158  ahprintf(AH, "; Dumped from database version: %s\n",
1159  AH->archiveRemoteVersion);
1160  if (AH->archiveDumpVersion)
1161  ahprintf(AH, "; Dumped by pg_dump version: %s\n",
1162  AH->archiveDumpVersion);
1163 
1164  ahprintf(AH, ";\n;\n; Selected TOC Entries:\n;\n");
1165 
1166  curSection = SECTION_PRE_DATA;
1167  for (te = AH->toc->next; te != AH->toc; te = te->next)
1168  {
1169  if (te->section != SECTION_NONE)
1170  curSection = te->section;
1171  if (ropt->verbose ||
1172  (_tocEntryRequired(te, curSection, AH) & (REQ_SCHEMA | REQ_DATA)) != 0)
1173  {
1174  char *sanitized_name;
1175  char *sanitized_schema;
1176  char *sanitized_owner;
1177 
1178  /*
1179  */
1180  sanitized_name = sanitize_line(te->tag, false);
1181  sanitized_schema = sanitize_line(te->namespace, true);
1182  sanitized_owner = sanitize_line(te->owner, false);
1183 
1184  ahprintf(AH, "%d; %u %u %s %s %s %s\n", te->dumpId,
1185  te->catalogId.tableoid, te->catalogId.oid,
1186  te->desc, sanitized_schema, sanitized_name,
1187  sanitized_owner);
1188 
1189  free(sanitized_name);
1190  free(sanitized_schema);
1191  free(sanitized_owner);
1192  }
1193  if (ropt->verbose && te->nDeps > 0)
1194  {
1195  int i;
1196 
1197  ahprintf(AH, ";\tdepends on:");
1198  for (i = 0; i < te->nDeps; i++)
1199  ahprintf(AH, " %d", te->dependencies[i]);
1200  ahprintf(AH, "\n");
1201  }
1202  }
1203 
1204  /* Enforce strict names checking */
1205  if (ropt->strict_names)
1206  StrictNamesCheck(ropt);
1207 
1208  if (ropt->filename)
1209  RestoreOutput(AH, sav);
1210 }
#define PGDUMP_STRFTIME_FMT
Definition: dumputils.h:33
static void StrictNamesCheck(RestoreOptions *ropt)
static OutputContext SaveOutput(ArchiveHandle *AH)
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
static void SetOutput(ArchiveHandle *AH, const char *filename, int compression)
static void RestoreOutput(ArchiveHandle *AH, OutputContext savedContext)
static char * sanitize_line(const char *str, bool want_hyphen)
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_DATA
RestoreOptions * ropt
Definition: pg_backup.h:210
Oid tableoid
Definition: pg_backup.h:261
ArchiveFormat format
struct _tocEntry * toc
const char * filename
Definition: pg_backup.h:115
teSection section
CatalogId catalogId
struct _tocEntry * next
DumpId * dependencies

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

Referenced by main().

◆ ProcessArchiveRestoreOptions()

void ProcessArchiveRestoreOptions ( Archive AH)

Definition at line 297 of file pg_backup_archiver.c.

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

◆ RestoreArchive()

void RestoreArchive ( Archive AH)

Definition at line 352 of file pg_backup_archiver.c.

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

References _becomeOwner(), _doSetFixedOutputState(), _selectOutputSchema(), _tocEntryRestorePass(), ahprintf(), appendPQExpBuffer(), appendPQExpBufferStr(), _archiveHandle::archiveDumpVersion, _archiveHandle::archiveRemoteVersion, Assert(), buildTocEntryArrays(), _tocEntry::catalogId, _archiveHandle::ClonePtr, CommitTransaction(), _restoreOptions::compression, _archiveHandle::compression, ConnectDatabase(), _archiveHandle::connection, _restoreOptions::cparams, _archiveHandle::createDate, _restoreOptions::createDB, createPQExpBuffer(), _archiveHandle::currentTE, _archiveHandle::currSchema, PQExpBufferData::data, _restoreOptions::dataOnly, _tocEntry::desc, destroyPQExpBuffer(), DisconnectDatabase(), DropBlobIfExists(), _restoreOptions::dropSchema, _tocEntry::dropStmt, dumpTimestamp(), _restoreOptions::filename, free, _tocEntry::hadDumper, _restoreOptions::if_exists, 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_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, _tocEntry::reqs, RESTORE_PASS_ACL, RESTORE_PASS_MAIN, 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(), _tocEntry::tag, _archiveHandle::toc, _archiveHandle::tocsByDumpId, _restoreOptions::useDB, Archive::verbose, and _archiveHandle::version.

Referenced by _CloseArchive(), and main().

◆ SetArchiveOptions()

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

Definition at line 284 of file pg_backup_archiver.c.

285 {
286  /* Caller can omit dump options, in which case we synthesize them */
287  if (dopt == NULL && ropt != NULL)
288  dopt = dumpOptionsFromRestoreOptions(ropt);
289 
290  /* Save options for later access */
291  AH->dopt = dopt;
292  AH->ropt = ropt;
293 }
DumpOptions * dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
DumpOptions * dopt
Definition: pg_backup.h:209

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

Referenced by _CloseArchive(), and main().

◆ SortTocFromFile()

void SortTocFromFile ( Archive AHX)

Definition at line 1362 of file pg_backup_archiver.c.

1363 {
1364  ArchiveHandle *AH = (ArchiveHandle *) AHX;
1365  RestoreOptions *ropt = AH->public.ropt;
1366  FILE *fh;
1367  StringInfoData linebuf;
1368 
1369  /* Allocate space for the 'wanted' array, and init it */
1370  ropt->idWanted = (bool *) pg_malloc0(sizeof(bool) * AH->maxDumpId);
1371 
1372  /* Setup the file */
1373  fh = fopen(ropt->tocFile, PG_BINARY_R);
1374  if (!fh)
1375  pg_fatal("could not open TOC file \"%s\": %m", ropt->tocFile);
1376 
1377  initStringInfo(&linebuf);
1378 
1379  while (pg_get_line_buf(fh, &linebuf))
1380  {
1381  char *cmnt;
1382  char *endptr;
1383  DumpId id;
1384  TocEntry *te;
1385 
1386  /* Truncate line at comment, if any */
1387  cmnt = strchr(linebuf.data, ';');
1388  if (cmnt != NULL)
1389  {
1390  cmnt[0] = '\0';
1391  linebuf.len = cmnt - linebuf.data;
1392  }
1393 
1394  /* Ignore if all blank */
1395  if (strspn(linebuf.data, " \t\r\n") == linebuf.len)
1396  continue;
1397 
1398  /* Get an ID, check it's valid and not already seen */
1399  id = strtol(linebuf.data, &endptr, 10);
1400  if (endptr == linebuf.data || id <= 0 || id > AH->maxDumpId ||
1401  ropt->idWanted[id - 1])
1402  {
1403  pg_log_warning("line ignored: %s", linebuf.data);
1404  continue;
1405  }
1406 
1407  /* Find TOC entry */
1408  te = getTocEntryByDumpId(AH, id);
1409  if (!te)
1410  pg_fatal("could not find entry for ID %d",
1411  id);
1412 
1413  /* Mark it wanted */
1414  ropt->idWanted[id - 1] = true;
1415 
1416  /*
1417  * Move each item to the end of the list as it is selected, so that
1418  * they are placed in the desired order. Any unwanted items will end
1419  * up at the front of the list, which may seem unintuitive but it's
1420  * what we need. In an ordinary serial restore that makes no
1421  * difference, but in a parallel restore we need to mark unrestored
1422  * items' dependencies as satisfied before we start examining
1423  * restorable items. Otherwise they could have surprising
1424  * side-effects on the order in which restorable items actually get
1425  * restored.
1426  */
1427  _moveBefore(AH->toc, te);
1428  }
1429 
1430  pg_free(linebuf.data);
1431 
1432  if (fclose(fh) != 0)
1433  pg_fatal("could not close TOC file: %m");
1434 }
#define PG_BINARY_R
Definition: c.h:1270
int DumpId
Definition: pg_backup.h:265
TocEntry * getTocEntryByDumpId(ArchiveHandle *AH, DumpId id)
static void _moveBefore(TocEntry *pos, TocEntry *te)
bool pg_get_line_buf(FILE *stream, StringInfo buf)
Definition: pg_get_line.c:95
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
bool * idWanted
Definition: pg_backup.h:151
char * tocFile
Definition: pg_backup.h:125

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

◆ StartBlob()

int StartBlob ( Archive AH,
Oid  oid 
)

Definition at line 1218 of file pg_backup_archiver.c.

1219 {
1220  ArchiveHandle *AH = (ArchiveHandle *) AHX;
1221 
1222  if (!AH->StartBlobPtr)
1223  pg_fatal("large-object output not supported in chosen format");
1224 
1225  AH->StartBlobPtr(AH, AH->currToc, oid);
1226 
1227  return 1;
1228 }
StartBlobPtrType StartBlobPtr

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

Referenced by dumpBlobs().

◆ WriteData()

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

Definition at line 1035 of file pg_backup_archiver.c.

1036 {
1037  ArchiveHandle *AH = (ArchiveHandle *) AHX;
1038 
1039  if (!AH->currToc)
1040  pg_fatal("internal error -- WriteData cannot be called outside the context of a DataDumper routine");
1041 
1042  AH->WriteDataPtr(AH, data, dLen);
1043 }
const void * data
WriteDataPtrType WriteDataPtr

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

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