PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_backup_db.h File Reference
#include "pg_backup.h"
Include dependency graph for pg_backup_db.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int ExecuteSqlCommandBuf (Archive *AHX, const char *buf, size_t bufLen)
 
void ExecuteSqlStatement (Archive *AHX, const char *query)
 
PGresultExecuteSqlQuery (Archive *AHX, const char *query, ExecStatusType status)
 
PGresultExecuteSqlQueryForSingleRow (Archive *fout, const char *query)
 
void EndDBCopyMode (Archive *AHX, const char *tocEntryTag)
 
void StartTransaction (Archive *AHX)
 
void CommitTransaction (Archive *AHX)
 

Function Documentation

◆ CommitTransaction()

void CommitTransaction ( Archive AHX)
extern

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

◆ EndDBCopyMode()

void EndDBCopyMode ( Archive AHX,
const char tocEntryTag 
)
extern

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}
char * PQerrorMessage(const PGconn *conn)
int PQputCopyEnd(PGconn *conn, const char *errormsg)
Definition fe-exec.c:2766
#define PQgetResult
#define PQclear
#define PQresultStatus
@ PGRES_COMMAND_OK
Definition libpq-fe.h:131
#define pg_log_error(...)
Definition logging.h:108
void warn_or_exit_horribly(ArchiveHandle *AH, const char *fmt,...)
void exit_nicely(int code)
#define is_cancel_in_progress()
#define pg_log_warning(...)
Definition pgfnames.c:24
static int fb(int x)

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

◆ ExecuteSqlCommandBuf()

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

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
void pg_free(void *ptr)
const char * str
@ OUTPUT_COPYDATA
@ OUTPUT_OTHERDATA
static void ExecuteSimpleCommands(ArchiveHandle *AH, const char *buf, size_t bufLen)
static char buf[DEFAULT_XLOG_SEG_SIZE]
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 
)
extern

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}
PGresult * PQexec(PGconn *conn, const char *query)
Definition fe-exec.c:2279
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 
)
extern

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
@ PGRES_TUPLES_OK
Definition libpq-fe.h:134
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
#define pg_fatal(...)

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

◆ StartTransaction()

void StartTransaction ( Archive AHX)
extern

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