From 0eea8047bf0e15b402b951e383e39236bdfe57d5 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Tue, 14 Oct 2014 15:00:55 -0300 Subject: pg_dump: Reduce use of global variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most pg_dump.c global variables, which were passed down individually to dumping routines, are now grouped as members of the new DumpOptions struct, which is used as a local variable and passed down into routines that need it. This helps future development efforts; in particular it is said to enable a mode in which a parallel pg_dump run can output multiple streams, and have them restored in parallel. Also take the opportunity to clean up the pg_dump header files somewhat, to avoid circularity. Author: Joachim Wieland, revised by Álvaro Herrera Reviewed by Peter Eisentraut --- src/bin/pg_dump/pg_backup_db.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/bin/pg_dump/pg_backup_db.c') diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c index 4d1d14f19b..07313f40df 100644 --- a/src/bin/pg_dump/pg_backup_db.c +++ b/src/bin/pg_dump/pg_backup_db.c @@ -9,11 +9,12 @@ * *------------------------------------------------------------------------- */ +#include "postgres_fe.h" +#include "dumputils.h" +#include "pg_backup_archiver.h" #include "pg_backup_db.h" #include "pg_backup_utils.h" -#include "dumputils.h" -#include "parallel.h" #include #include @@ -217,7 +218,7 @@ ConnectDatabase(Archive *AHX, const char *pghost, const char *pgport, const char *username, - enum trivalue prompt_password) + trivalue prompt_password) { ArchiveHandle *AH = (ArchiveHandle *) AHX; char *password = AH->savedPassword; @@ -500,8 +501,10 @@ ExecuteSimpleCommands(ArchiveHandle *AH, const char *buf, size_t bufLen) * Implement ahwrite() for direct-to-DB restore */ int -ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLen) +ExecuteSqlCommandBuf(Archive *AHX, const char *buf, size_t bufLen) { + ArchiveHandle *AH = (ArchiveHandle *) AHX; + if (AH->outputKind == OUTPUT_COPYDATA) { /* @@ -553,8 +556,10 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLen) * Terminate a COPY operation during direct-to-DB restore */ void -EndDBCopyMode(ArchiveHandle *AH, TocEntry *te) +EndDBCopyMode(Archive *AHX, const char *tocEntryTag) { + ArchiveHandle *AH = (ArchiveHandle *) AHX; + if (AH->pgCopyIn) { PGresult *res; @@ -567,7 +572,7 @@ EndDBCopyMode(ArchiveHandle *AH, TocEntry *te) res = PQgetResult(AH->connection); if (PQresultStatus(res) != PGRES_COMMAND_OK) warn_or_exit_horribly(AH, modulename, "COPY failed for table \"%s\": %s", - te->tag, PQerrorMessage(AH->connection)); + tocEntryTag, PQerrorMessage(AH->connection)); PQclear(res); AH->pgCopyIn = false; @@ -575,14 +580,18 @@ EndDBCopyMode(ArchiveHandle *AH, TocEntry *te) } void -StartTransaction(ArchiveHandle *AH) +StartTransaction(Archive *AHX) { + ArchiveHandle *AH = (ArchiveHandle *) AHX; + ExecuteSqlCommand(AH, "BEGIN", "could not start database transaction"); } void -CommitTransaction(ArchiveHandle *AH) +CommitTransaction(Archive *AHX) { + ArchiveHandle *AH = (ArchiveHandle *) AHX; + ExecuteSqlCommand(AH, "COMMIT", "could not commit database transaction"); } -- cgit v1.2.1