summaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_backup_db.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2014-10-14 15:00:55 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2014-10-14 15:00:55 -0300
commit0eea8047bf0e15b402b951e383e39236bdfe57d5 (patch)
tree450b0761bb6d674de42e9018ac38c1d5f40e11f3 /src/bin/pg_dump/pg_backup_db.c
parente0d97d77bf0875e4d5cc7dedfe701d9999bf678c (diff)
pg_dump: Reduce use of global variables
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
Diffstat (limited to 'src/bin/pg_dump/pg_backup_db.c')
-rw-r--r--src/bin/pg_dump/pg_backup_db.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c
index 4d1d14f19b1..07313f40df5 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 <unistd.h>
#include <ctype.h>
@@ -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");
}