aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_backup_db.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/pg_dump/pg_backup_db.c')
-rw-r--r--src/bin/pg_dump/pg_backup_db.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c
index e5572db01d7..1075c06053d 100644
--- a/src/bin/pg_dump/pg_backup_db.c
+++ b/src/bin/pg_dump/pg_backup_db.c
@@ -5,7 +5,7 @@
* Implements the basic DB functions used by the archiver.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.41 2002/09/07 16:14:33 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.42 2002/10/16 05:46:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -61,11 +61,15 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
myversion = _parse_version(AH, PG_VERSION);
- res = PQexec(conn, "SELECT version();");
+ /*
+ * Autocommit could be off. We turn it off later but we have to check
+ * the database version first.
+ */
+
+ res = PQexec(conn, "BEGIN;SELECT version();");
if (!res ||
PQresultStatus(res) != PGRES_TUPLES_OK ||
PQntuples(res) != 1)
-
die_horribly(AH, modulename, "could not get version from server: %s", PQerrorMessage(conn));
remoteversion_str = PQgetvalue(res, 0, 0);
@@ -73,6 +77,12 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
PQclear(res);
+ res = PQexec(conn, "COMMIT;");
+ if (!res ||
+ PQresultStatus(res) != PGRES_COMMAND_OK)
+ die_horribly(AH, modulename, "could not get version from server: %s", PQerrorMessage(conn));
+ PQclear(res);
+
AH->public.remoteVersion = remoteversion;
if (myversion != remoteversion
@@ -277,6 +287,18 @@ ConnectDatabase(Archive *AHX,
/* check for version mismatch */
_check_database_version(AH, ignoreVersion);
+ /* Turn autocommit on */
+ if (AH->public.remoteVersion >= 70300)
+ {
+ PGresult *res;
+
+ res = PQexec(AH->connection, "SET autocommit TO 'on'");
+ if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
+ die_horribly(AH, NULL, "SET autocommit TO 'on' failed: %s",
+ PQerrorMessage(AH->connection));
+ PQclear(res);
+ }
+
PQsetNoticeProcessor(AH->connection, notice_processor, NULL);
return AH->connection;