mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-06 15:24:56 +08:00
Make pg_dump save for autocommit = off.
This commit is contained in:
parent
ec64390e91
commit
cda776e613
@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.57 2002/09/04 20:31:34 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.58 2002/10/16 05:46:54 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -280,7 +280,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
|
||||
/*
|
||||
* If we can output the data, then restore it.
|
||||
*/
|
||||
if (AH->PrintTocDataPtr !=NULL && (reqs & REQ_DATA) != 0)
|
||||
if (AH->PrintTocDataPtr != NULL && (reqs & REQ_DATA) != 0)
|
||||
{
|
||||
#ifndef HAVE_LIBZ
|
||||
if (AH->compression != 0)
|
||||
@ -304,11 +304,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
|
||||
*/
|
||||
if (!AH->CustomOutPtr)
|
||||
write_msg(modulename, "WARNING: skipping large object restoration\n");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
_disableTriggersIfNecessary(AH, te, ropt);
|
||||
|
||||
/*
|
||||
@ -362,11 +360,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
|
||||
te = AH->toc->next;
|
||||
while (te != AH->toc)
|
||||
{
|
||||
|
||||
/* Is it table data? */
|
||||
if (strcmp(te->desc, "TABLE DATA") == 0)
|
||||
{
|
||||
|
||||
ahlog(AH, 2, "checking whether we loaded %s\n", te->tag);
|
||||
|
||||
reqs = _tocEntryRequired(te, ropt);
|
||||
|
@ -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;
|
||||
|
@ -22,7 +22,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.302 2002/10/09 16:20:25 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.303 2002/10/16 05:46:54 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -549,22 +549,21 @@ main(int argc, char **argv)
|
||||
g_conn = ConnectDatabase(g_fout, dbname, pghost, pgport, username, force_password, ignore_version);
|
||||
|
||||
/*
|
||||
* Start serializable transaction to dump consistent data
|
||||
* Start serializable transaction to dump consistent data.
|
||||
*/
|
||||
{
|
||||
PGresult *res;
|
||||
|
||||
res = PQexec(g_conn, "begin");
|
||||
res = PQexec(g_conn, "BEGIN");
|
||||
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||
exit_horribly(g_fout, NULL, "BEGIN command failed: %s",
|
||||
PQerrorMessage(g_conn));
|
||||
|
||||
PQclear(res);
|
||||
res = PQexec(g_conn, "set transaction isolation level serializable");
|
||||
|
||||
res = PQexec(g_conn, "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
|
||||
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||
exit_horribly(g_fout, NULL, "could not set transaction isolation level to serializable: %s",
|
||||
PQerrorMessage(g_conn));
|
||||
|
||||
PQclear(res);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user