PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_backup_db.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include <ctype.h>
#include "common/connect.h"
#include "common/string.h"
#include "connectdb.h"
#include "parallel.h"
#include "pg_backup_archiver.h"
#include "pg_backup_db.h"
#include "pg_backup_utils.h"
Include dependency graph for pg_backup_db.c:

Go to the source code of this file.

Functions

static void _check_database_version (ArchiveHandle *AH)
 
static void notice_processor (void *arg, const char *message)
 
void ReconnectToServer (ArchiveHandle *AH, const char *dbname)
 
void ConnectDatabaseAhx (Archive *AHX, const ConnParams *cparams, bool isReconnect)
 
void DisconnectDatabase (Archive *AHX)
 
PGconnGetConnection (Archive *AHX)
 
static void die_on_query_failure (ArchiveHandle *AH, const char *query)
 
void ExecuteSqlStatement (Archive *AHX, const char *query)
 
PGresultExecuteSqlQuery (Archive *AHX, const char *query, ExecStatusType status)
 
PGresultExecuteSqlQueryForSingleRow (Archive *fout, const char *query)
 
static void ExecuteSqlCommand (ArchiveHandle *AH, const char *qry, const char *desc)
 
static void ExecuteSimpleCommands (ArchiveHandle *AH, const char *buf, size_t bufLen)
 
int ExecuteSqlCommandBuf (Archive *AHX, const char *buf, size_t bufLen)
 
void EndDBCopyMode (Archive *AHX, const char *tocEntryTag)
 
void StartTransaction (Archive *AHX)
 
void CommitTransaction (Archive *AHX)
 
void IssueCommandPerBlob (ArchiveHandle *AH, TocEntry *te, const char *cmdBegin, const char *cmdEnd)
 
void IssueACLPerBlob (ArchiveHandle *AH, TocEntry *te)
 
void DropLOIfExists (ArchiveHandle *AH, Oid oid)
 

Function Documentation

◆ _check_database_version()

static void _check_database_version ( ArchiveHandle AH)
static

Definition at line 32 of file pg_backup_db.c.

33{
34 const char *remoteversion_str;
35 int remoteversion;
36 PGresult *res;
37
38 remoteversion_str = PQparameterStatus(AH->connection, "server_version");
41 pg_fatal("could not get \"server_version\" from libpq");
42
45 if (!AH->archiveRemoteVersion)
47
49 && (remoteversion < AH->public.minRemoteVersion ||
51 {
52 pg_log_error("aborting because of server version mismatch");
53 pg_log_error_detail("server version: %s; %s version: %s",
55 exit(1);
56 }
57
58 /*
59 * Check if server is in recovery mode, which means we are on a hot
60 * standby.
61 */
63 "SELECT pg_catalog.pg_is_in_recovery()");
64 AH->public.isStandby = (strcmp(PQgetvalue(res, 0, 0), "t") == 0);
65 PQclear(res);
66}
int PQserverVersion(const PGconn *conn)
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
char * pg_strdup(const char *in)
Definition fe_memutils.c:91
#define PQgetvalue
#define PQclear
#define pg_log_error(...)
Definition logging.h:108
#define pg_log_error_detail(...)
Definition logging.h:111
const char * progname
Definition main.c:44
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
#define pg_fatal(...)
static int fb(int x)
int remoteVersion
Definition pg_backup.h:234
char * remoteVersionStr
Definition pg_backup.h:233
bool isStandby
Definition pg_backup.h:235
int maxRemoteVersion
Definition pg_backup.h:238

References _archiveHandle::archiveRemoteVersion, _archiveHandle::connection, ExecuteSqlQueryForSingleRow(), fb(), Archive::isStandby, Archive::maxRemoteVersion, pg_fatal, pg_log_error, pg_log_error_detail, pg_strdup(), PQclear, PQgetvalue, PQparameterStatus(), PQserverVersion(), progname, _archiveHandle::public, Archive::remoteVersion, and Archive::remoteVersionStr.

Referenced by ConnectDatabaseAhx().

◆ CommitTransaction()

void CommitTransaction ( Archive AHX)

Definition at line 490 of file pg_backup_db.c.

491{
492 ArchiveHandle *AH = (ArchiveHandle *) AHX;
493
494 ExecuteSqlCommand(AH, "COMMIT", "could not commit database transaction");
495}
static void ExecuteSqlCommand(ArchiveHandle *AH, const char *qry, const char *desc)

References ExecuteSqlCommand().

◆ ConnectDatabaseAhx()

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

Definition at line 109 of file pg_backup_db.c.

112{
113 ArchiveHandle *AH = (ArchiveHandle *) AHX;
114 trivalue prompt_password;
115 char *password;
116
117 if (AH->connection)
118 pg_fatal("already connected to a database");
119
120 /* Never prompt for a password during a reconnection */
121 prompt_password = isReconnect ? TRI_NO : cparams->promptPassword;
122
124
125 if (prompt_password == TRI_YES && password == NULL)
126 password = simple_prompt("Password: ", false);
127
128 AH->connection = ConnectDatabase(cparams->dbname, NULL, cparams->pghost,
129 cparams->pgport, cparams->username,
130 prompt_password, true,
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 {
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:728
#define ALWAYS_SECURE_SEARCH_PATH_SQL
Definition connect.h:25
PGconn * ConnectDatabase(const char *dbname, const char *connection_string, const char *pghost, const char *pgport, const char *pguser, trivalue prompt_password, bool fail_on_error, const char *progname, const char **connstr, int *server_version, char *password, char *override_dbname)
Definition connectdb.c:40
int PQconnectionUsedPassword(const PGconn *conn)
char * PQpass(const PGconn *conn)
PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
void pg_free(void *ptr)
static void _check_database_version(ArchiveHandle *AH)
static void notice_processor(void *arg, const char *message)
#define free(a)
char * simple_prompt(const char *prompt, bool echo)
Definition sprompt.c:38
static char * password
Definition streamutil.c:51
char * override_dbname
Definition pg_backup.h:94
char * pgport
Definition pg_backup.h:88
char * pghost
Definition pg_backup.h:89
trivalue promptPassword
Definition pg_backup.h:91
char * username
Definition pg_backup.h:90
char * dbname
Definition pg_backup.h:87
trivalue
Definition vacuumlo.c:35
@ TRI_YES
Definition vacuumlo.c:38
@ TRI_NO
Definition vacuumlo.c:37

References _check_database_version(), ALWAYS_SECURE_SEARCH_PATH_SQL, ConnectDatabase(), _archiveHandle::connection, _connParams::dbname, ExecuteSqlQueryForSingleRow(), fb(), free, notice_processor(), _connParams::override_dbname, password, pg_fatal, pg_free(), 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().

◆ die_on_query_failure()

static void die_on_query_failure ( ArchiveHandle AH,
const char query 
)
static

Definition at line 208 of file pg_backup_db.c.

209{
211 {
212 pg_log_error("query failed: %s",
214 pg_log_error_detail("Query was: %s", query);
215 }
216
217 exit_nicely(1);
218}
char * PQerrorMessage(const PGconn *conn)
void exit_nicely(int code)
#define is_cancel_in_progress()

References _archiveHandle::connection, exit_nicely(), is_cancel_in_progress, pg_log_error, pg_log_error_detail, and PQerrorMessage().

Referenced by ExecuteSqlQuery(), and ExecuteSqlStatement().

◆ DisconnectDatabase()

void DisconnectDatabase ( Archive AHX)

Definition at line 164 of file pg_backup_db.c.

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

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

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

◆ DropLOIfExists()

void DropLOIfExists ( ArchiveHandle AH,
Oid  oid 
)

Definition at line 626 of file pg_backup_db.c.

627{
628 ahprintf(AH,
629 "SELECT pg_catalog.lo_unlink(oid) "
630 "FROM pg_catalog.pg_largeobject_metadata "
631 "WHERE oid = '%u';\n",
632 oid);
633}
int ahprintf(ArchiveHandle *AH, const char *fmt,...)

References ahprintf().

Referenced by _StartLO(), RestoreArchive(), and StartRestoreLO().

◆ EndDBCopyMode()

void EndDBCopyMode ( Archive AHX,
const char tocEntryTag 
)

Definition at line 448 of file pg_backup_db.c.

449{
450 ArchiveHandle *AH = (ArchiveHandle *) AHX;
451
452 if (AH->pgCopyIn)
453 {
454 PGresult *res;
455
456 if (PQputCopyEnd(AH->connection, NULL) <= 0)
457 {
458 /* Stay quiet if this is a result of our own cancellation. */
460 pg_log_error("error returned by PQputCopyEnd: %s",
462 exit_nicely(1);
463 }
464
465 /* Check command status and return to normal libpq state */
466 res = PQgetResult(AH->connection);
468 warn_or_exit_horribly(AH, "COPY failed for table \"%s\": %s",
470 PQclear(res);
471
472 /* Do this to ensure we've pumped libpq back to idle state */
473 if (PQgetResult(AH->connection) != NULL)
474 pg_log_warning("unexpected extra results during COPY of table \"%s\"",
476
477 AH->pgCopyIn = false;
478 }
479}
int PQputCopyEnd(PGconn *conn, const char *errormsg)
Definition fe-exec.c:2766
#define PQgetResult
#define PQresultStatus
@ PGRES_COMMAND_OK
Definition libpq-fe.h:131
void warn_or_exit_horribly(ArchiveHandle *AH, const char *fmt,...)
#define pg_log_warning(...)
Definition pgfnames.c:24

References _archiveHandle::connection, exit_nicely(), fb(), is_cancel_in_progress, pg_log_error, pg_log_warning, _archiveHandle::pgCopyIn, PGRES_COMMAND_OK, PQclear, PQerrorMessage(), PQgetResult, PQputCopyEnd(), PQresultStatus, and warn_or_exit_horribly().

Referenced by restore_toc_entry().

◆ ExecuteSimpleCommands()

static void ExecuteSimpleCommands ( ArchiveHandle AH,
const char buf,
size_t  bufLen 
)
static

Definition at line 323 of file pg_backup_db.c.

324{
325 const char *qry = buf;
326 const char *eos = buf + bufLen;
327
328 /* initialize command buffer if first time through */
329 if (AH->sqlparse.curCmd == NULL)
331
332 for (; qry < eos; qry++)
333 {
334 char ch = *qry;
335
336 /* For neatness, we skip any newlines between commands */
337 if (!(ch == '\n' && AH->sqlparse.curCmd->len == 0))
339
340 switch (AH->sqlparse.state)
341 {
342 case SQL_SCAN: /* Default state == 0, set in _allocAH */
343 if (ch == ';')
344 {
345 /*
346 * We've found the end of a statement. Send it and reset
347 * the buffer.
348 */
350 "could not execute query");
352 }
353 else if (ch == '\'')
354 {
356 AH->sqlparse.backSlash = false;
357 }
358 else if (ch == '"')
359 {
361 }
362 break;
363
365 /* We needn't handle '' specially */
366 if (ch == '\'' && !AH->sqlparse.backSlash)
367 AH->sqlparse.state = SQL_SCAN;
368 else if (ch == '\\' && !AH->public.std_strings)
370 else
371 AH->sqlparse.backSlash = false;
372 break;
373
375 /* We needn't handle "" specially */
376 if (ch == '"')
377 AH->sqlparse.state = SQL_SCAN;
378 break;
379 }
380 }
381}
@ SQL_IN_DOUBLE_QUOTE
@ SQL_IN_SINGLE_QUOTE
static char buf[DEFAULT_XLOG_SEG_SIZE]
PQExpBuffer createPQExpBuffer(void)
Definition pqexpbuffer.c:72
void resetPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
bool std_strings
Definition pg_backup.h:245
sqlparseInfo sqlparse
sqlparseState state

References appendPQExpBufferChar(), sqlparseInfo::backSlash, buf, createPQExpBuffer(), sqlparseInfo::curCmd, PQExpBufferData::data, ExecuteSqlCommand(), fb(), PQExpBufferData::len, _archiveHandle::public, resetPQExpBuffer(), SQL_IN_DOUBLE_QUOTE, SQL_IN_SINGLE_QUOTE, SQL_SCAN, _archiveHandle::sqlparse, sqlparseInfo::state, and Archive::std_strings.

Referenced by ExecuteSqlCommandBuf().

◆ ExecuteSqlCommand()

static void ExecuteSqlCommand ( ArchiveHandle AH,
const char qry,
const char desc 
)
static

Definition at line 271 of file pg_backup_db.c.

272{
273 PGconn *conn = AH->connection;
274 PGresult *res;
275
276#ifdef NOT_USED
277 fprintf(stderr, "Executing: '%s'\n\n", qry);
278#endif
279 res = PQexec(conn, qry);
280
281 switch (PQresultStatus(res))
282 {
283 case PGRES_COMMAND_OK:
284 case PGRES_TUPLES_OK:
286 /* A-OK */
287 break;
288 case PGRES_COPY_IN:
289 /* Assume this is an expected result */
290 AH->pgCopyIn = true;
291 break;
292 default:
293 /* trouble */
294 warn_or_exit_horribly(AH, "%s: %sCommand was: %s",
295 desc, PQerrorMessage(conn), qry);
296 break;
297 }
298
299 PQclear(res);
300}
#define fprintf(file, fmt, msg)
Definition cubescan.l:21
PGresult * PQexec(PGconn *conn, const char *query)
Definition fe-exec.c:2279
@ PGRES_COPY_IN
Definition libpq-fe.h:138
@ PGRES_EMPTY_QUERY
Definition libpq-fe.h:130
@ PGRES_TUPLES_OK
Definition libpq-fe.h:134
PGconn * conn
Definition streamutil.c:52

References conn, _archiveHandle::connection, fb(), fprintf, _archiveHandle::pgCopyIn, PGRES_COMMAND_OK, PGRES_COPY_IN, PGRES_EMPTY_QUERY, PGRES_TUPLES_OK, PQclear, PQerrorMessage(), PQexec(), PQresultStatus, and warn_or_exit_horribly().

Referenced by CommitTransaction(), ExecuteSimpleCommands(), ExecuteSqlCommandBuf(), and StartTransaction().

◆ ExecuteSqlCommandBuf()

int ExecuteSqlCommandBuf ( Archive AHX,
const char buf,
size_t  bufLen 
)

Definition at line 388 of file pg_backup_db.c.

389{
390 ArchiveHandle *AH = (ArchiveHandle *) AHX;
391
392 if (AH->outputKind == OUTPUT_COPYDATA)
393 {
394 /*
395 * COPY data.
396 *
397 * We drop the data on the floor if libpq has failed to enter COPY
398 * mode; this allows us to behave reasonably when trying to continue
399 * after an error in a COPY command.
400 */
401 if (AH->pgCopyIn &&
403 {
404 /* Stay quiet if this is a result of our own cancellation. */
406 pg_log_error("error returned by PQputCopyData: %s",
408 exit_nicely(1);
409 }
410 }
411 else if (AH->outputKind == OUTPUT_OTHERDATA)
412 {
413 /*
414 * Table data expressed as INSERT commands; or, in old dump files,
415 * BLOB COMMENTS data (which is expressed as COMMENT ON commands).
416 */
418 }
419 else
420 {
421 /*
422 * General SQL commands; we assume that commands will not be split
423 * across calls.
424 *
425 * In most cases the data passed to us will be a null-terminated
426 * string, but if it's not, we have to add a trailing null.
427 */
428 if (buf[bufLen] == '\0')
429 ExecuteSqlCommand(AH, buf, "could not execute query");
430 else
431 {
432 char *str = (char *) pg_malloc(bufLen + 1);
433
434 memcpy(str, buf, bufLen);
435 str[bufLen] = '\0';
436 ExecuteSqlCommand(AH, str, "could not execute query");
437 pg_free(str);
438 }
439 }
440
441 return bufLen;
442}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
int PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
Definition fe-exec.c:2712
void * pg_malloc(size_t size)
Definition fe_memutils.c:53
const char * str
@ OUTPUT_COPYDATA
@ OUTPUT_OTHERDATA
static void ExecuteSimpleCommands(ArchiveHandle *AH, const char *buf, size_t bufLen)
ArchiverOutput outputKind

References buf, _archiveHandle::connection, ExecuteSimpleCommands(), ExecuteSqlCommand(), exit_nicely(), fb(), is_cancel_in_progress, memcpy(), OUTPUT_COPYDATA, OUTPUT_OTHERDATA, _archiveHandle::outputKind, pg_free(), pg_log_error, pg_malloc(), _archiveHandle::pgCopyIn, PQerrorMessage(), PQputCopyData(), and str.

Referenced by ahwrite().

◆ ExecuteSqlQuery()

PGresult * ExecuteSqlQuery ( Archive AHX,
const char query,
ExecStatusType  status 
)

Definition at line 233 of file pg_backup_db.c.

234{
235 ArchiveHandle *AH = (ArchiveHandle *) AHX;
236 PGresult *res;
237
238 res = PQexec(AH->connection, query);
239 if (PQresultStatus(res) != status)
240 die_on_query_failure(AH, query);
241 return res;
242}
static void die_on_query_failure(ArchiveHandle *AH, const char *query)

References _archiveHandle::connection, die_on_query_failure(), PQexec(), and PQresultStatus.

Referenced by append_depends_on_extension(), buildMatViewRefreshDependencies(), collectBinaryUpgradeClassOids(), collectComments(), collectRoleNames(), collectSecLabels(), collectSequences(), createViewAsClause(), dumpCompositeType(), dumpDatabase(), dumpDatabaseConfig(), dumpEnumType(), dumpOpclass(), dumpOpfamily(), dumpRule(), dumpSequenceData(), dumpStatisticsExtStats(), dumpTable(), dumpTableData_copy(), dumpTableData_insert(), dumpTableSchema(), dumpTSConfig(), dumpUserMappings(), ExecuteSqlQueryForSingleRow(), expand_extension_name_patterns(), expand_foreign_server_name_patterns(), expand_schema_name_patterns(), expand_table_name_patterns(), fetchAttributeStats(), getAccessMethods(), getAdditionalACLs(), getAggregates(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDependencies(), getDomainConstraints(), getEventTriggers(), getExtendedStatistics(), getExtensionMembership(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), getInherits(), getLOs(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getPartitioningInfo(), getPolicies(), getProcLangs(), getPublicationNamespaces(), getPublications(), getPublicationTables(), getRules(), getSubscriptionRelations(), getSubscriptions(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), processExtensionTables(), and set_restrict_relation_kind().

◆ ExecuteSqlQueryForSingleRow()

PGresult * ExecuteSqlQueryForSingleRow ( Archive fout,
const char query 
)

Definition at line 248 of file pg_backup_db.c.

249{
250 PGresult *res;
251 int ntups;
252
253 res = ExecuteSqlQuery(fout, query, PGRES_TUPLES_OK);
254
255 /* Expecting a single result only */
256 ntups = PQntuples(res);
257 if (ntups != 1)
258 pg_fatal(ngettext("query returned %d row instead of one: %s",
259 "query returned %d rows instead of one: %s",
260 ntups),
261 ntups, query);
262
263 return res;
264}
#define ngettext(s, p, n)
Definition c.h:1329
#define PQntuples
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)

References ExecuteSqlQuery(), fb(), ngettext, pg_fatal, PGRES_TUPLES_OK, and PQntuples.

Referenced by _check_database_version(), binary_upgrade_set_type_oids_by_type_oid(), ConnectDatabaseAhx(), convertTSFunction(), dumpAgg(), dumpBaseType(), dumpCollation(), dumpConversion(), dumpDatabase(), dumpDomain(), dumpForeignServer(), dumpFunc(), dumpOpclass(), dumpOpfamily(), dumpOpr(), dumpRangeType(), dumpSearchPath(), dumpStatisticsExt(), dumpTableAttach(), dumpTableSchema(), dumpTSConfig(), dumpTSDictionary(), expand_table_name_patterns(), get_language_name(), get_next_possible_free_pg_type_oid(), get_synchronized_snapshot(), getFormattedTypeName(), and setup_connection().

◆ ExecuteSqlStatement()

◆ GetConnection()

PGconn * GetConnection ( Archive AHX)

Definition at line 193 of file pg_backup_db.c.

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

References _archiveHandle::connection.

◆ IssueACLPerBlob()

void IssueACLPerBlob ( ArchiveHandle AH,
TocEntry te 
)

Definition at line 552 of file pg_backup_db.c.

553{
555 char *buf;
556 char *st;
557 char *st2;
558 char *en;
559 bool inquotes;
560
561 if (!blobte)
562 pg_fatal("could not find entry for ID %d", te->dependencies[0]);
563 Assert(strcmp(blobte->desc, "BLOB METADATA") == 0);
564
565 /* Make a writable copy of the ACL commands string */
566 buf = pg_strdup(te->defn);
567
568 /*
569 * We have to parse out the commands sufficiently to locate the blob OIDs
570 * and find the command-ending semicolons. The commands should not
571 * contain anything hard to parse except for double-quoted role names,
572 * which are easy to ignore. Once we've split apart the first and second
573 * halves of a command, apply IssueCommandPerBlob. (This means the
574 * updates on the blobs are interleaved if there's multiple commands, but
575 * that should cause no trouble.)
576 */
577 inquotes = false;
578 st = en = buf;
579 st2 = NULL;
580 while (*en)
581 {
582 /* Ignore double-quoted material */
583 if (*en == '"')
585 if (inquotes)
586 {
587 en++;
588 continue;
589 }
590 /* If we found "LARGE OBJECT", that's the end of the first half */
591 if (strncmp(en, "LARGE OBJECT ", 13) == 0)
592 {
593 /* Terminate the first-half string */
594 en += 13;
595 Assert(isdigit((unsigned char) *en));
596 *en++ = '\0';
597 /* Skip the rest of the blob OID */
598 while (isdigit((unsigned char) *en))
599 en++;
600 /* Second half starts here */
601 Assert(st2 == NULL);
602 st2 = en;
603 }
604 /* If we found semicolon, that's the end of the second half */
605 else if (*en == ';')
606 {
607 /* Terminate the second-half string */
608 *en++ = '\0';
609 Assert(st2 != NULL);
610 /* Issue this command for each blob */
612 /* For neatness, skip whitespace before the next command */
613 while (isspace((unsigned char) *en))
614 en++;
615 /* Reset for new command */
616 st = en;
617 st2 = NULL;
618 }
619 else
620 en++;
621 }
622 pg_free(buf);
623}
#define Assert(condition)
Definition c.h:1002
TocEntry * getTocEntryByDumpId(ArchiveHandle *AH, DumpId id)
void IssueCommandPerBlob(ArchiveHandle *AH, TocEntry *te, const char *cmdBegin, const char *cmdEnd)
DumpId * dependencies

References Assert, buf, _tocEntry::defn, _tocEntry::dependencies, fb(), getTocEntryByDumpId(), IssueCommandPerBlob(), pg_fatal, pg_free(), and pg_strdup().

Referenced by _printTocEntry().

◆ IssueCommandPerBlob()

void IssueCommandPerBlob ( ArchiveHandle AH,
TocEntry te,
const char cmdBegin,
const char cmdEnd 
)

Definition at line 505 of file pg_backup_db.c.

507{
508 /* Make a writable copy of the command string */
509 char *buf = pg_strdup(te->defn);
510 RestoreOptions *ropt = AH->public.ropt;
511 char *st;
512 char *en;
513
514 st = buf;
515 while ((en = strchr(st, '\n')) != NULL)
516 {
517 *en++ = '\0';
518 ahprintf(AH, "%s%s%s;\n", cmdBegin, st, cmdEnd);
519
520 /* In --transaction-size mode, count each command as an action */
521 if (ropt && ropt->txn_size > 0)
522 {
523 if (++AH->txnCount >= ropt->txn_size)
524 {
525 if (AH->connection)
526 {
529 }
530 else
531 ahprintf(AH, "COMMIT;\nBEGIN;\n\n");
532 AH->txnCount = 0;
533 }
534 }
535
536 st = en;
537 }
538 ahprintf(AH, "\n");
539 pg_free(buf);
540}
RestoreOptions * ropt
Definition pg_backup.h:230
static void StartTransaction(void)
Definition xact.c:2106
static void CommitTransaction(void)
Definition xact.c:2270

References ahprintf(), buf, CommitTransaction(), _archiveHandle::connection, _tocEntry::defn, fb(), pg_free(), pg_strdup(), _archiveHandle::public, Archive::ropt, StartTransaction(), _restoreOptions::txn_size, and _archiveHandle::txnCount.

Referenced by _printTocEntry(), IssueACLPerBlob(), and RestoreArchive().

◆ notice_processor()

static void notice_processor ( void arg,
const char message 
)
static

Definition at line 201 of file pg_backup_db.c.

202{
203 pg_log_info("%s", message);
204}
#define pg_log_info(...)
Definition logging.h:126

References pg_log_info.

Referenced by ConnectDatabaseAhx().

◆ ReconnectToServer()

void ReconnectToServer ( ArchiveHandle AH,
const char dbname 
)

Definition at line 73 of file pg_backup_db.c.

74{
76 RestoreOptions *ropt = AH->public.ropt;
77
78 /*
79 * Save the dbname, if given, in override_dbname so that it will also
80 * affect any later reconnection attempt.
81 */
82 if (dbname)
84
85 /*
86 * Note: we want to establish the new connection, and in particular update
87 * ArchiveHandle's connCancel, before closing old connection. Otherwise
88 * an ill-timed SIGINT could try to access a dead connection.
89 */
90 AH->connection = NULL; /* dodge error check in ConnectDatabaseAhx */
91
92 ConnectDatabaseAhx((Archive *) AH, &ropt->cparams, true);
93
95}
void ConnectDatabaseAhx(Archive *AHX, const ConnParams *cparams, bool isReconnect)
char * dbname
Definition streamutil.c:49
ConnParams cparams
Definition pg_backup.h:146

References ConnectDatabaseAhx(), _archiveHandle::connection, _restoreOptions::cparams, dbname, fb(), _connParams::override_dbname, pg_strdup(), PQfinish(), _archiveHandle::public, and Archive::ropt.

Referenced by _reconnectToDB().

◆ StartTransaction()

void StartTransaction ( Archive AHX)

Definition at line 482 of file pg_backup_db.c.

483{
484 ArchiveHandle *AH = (ArchiveHandle *) AHX;
485
486 ExecuteSqlCommand(AH, "BEGIN", "could not start database transaction");
487}

References ExecuteSqlCommand().