mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +03:00
Make pg_dump save for autocommit = off.
This commit is contained in:
parent
ec64390e91
commit
cda776e613
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 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
|
#ifndef HAVE_LIBZ
|
||||||
if (AH->compression != 0)
|
if (AH->compression != 0)
|
||||||
@ -304,11 +304,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
|
|||||||
*/
|
*/
|
||||||
if (!AH->CustomOutPtr)
|
if (!AH->CustomOutPtr)
|
||||||
write_msg(modulename, "WARNING: skipping large object restoration\n");
|
write_msg(modulename, "WARNING: skipping large object restoration\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
_disableTriggersIfNecessary(AH, te, ropt);
|
_disableTriggersIfNecessary(AH, te, ropt);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -362,11 +360,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
|
|||||||
te = AH->toc->next;
|
te = AH->toc->next;
|
||||||
while (te != AH->toc)
|
while (te != AH->toc)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Is it table data? */
|
/* Is it table data? */
|
||||||
if (strcmp(te->desc, "TABLE DATA") == 0)
|
if (strcmp(te->desc, "TABLE DATA") == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
ahlog(AH, 2, "checking whether we loaded %s\n", te->tag);
|
ahlog(AH, 2, "checking whether we loaded %s\n", te->tag);
|
||||||
|
|
||||||
reqs = _tocEntryRequired(te, ropt);
|
reqs = _tocEntryRequired(te, ropt);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* Implements the basic DB functions used by the archiver.
|
* Implements the basic DB functions used by the archiver.
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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);
|
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 ||
|
if (!res ||
|
||||||
PQresultStatus(res) != PGRES_TUPLES_OK ||
|
PQresultStatus(res) != PGRES_TUPLES_OK ||
|
||||||
PQntuples(res) != 1)
|
PQntuples(res) != 1)
|
||||||
|
|
||||||
die_horribly(AH, modulename, "could not get version from server: %s", PQerrorMessage(conn));
|
die_horribly(AH, modulename, "could not get version from server: %s", PQerrorMessage(conn));
|
||||||
|
|
||||||
remoteversion_str = PQgetvalue(res, 0, 0);
|
remoteversion_str = PQgetvalue(res, 0, 0);
|
||||||
@ -73,6 +77,12 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
|
|||||||
|
|
||||||
PQclear(res);
|
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;
|
AH->public.remoteVersion = remoteversion;
|
||||||
|
|
||||||
if (myversion != remoteversion
|
if (myversion != remoteversion
|
||||||
@ -277,6 +287,18 @@ ConnectDatabase(Archive *AHX,
|
|||||||
/* check for version mismatch */
|
/* check for version mismatch */
|
||||||
_check_database_version(AH, ignoreVersion);
|
_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);
|
PQsetNoticeProcessor(AH->connection, notice_processor, NULL);
|
||||||
|
|
||||||
return AH->connection;
|
return AH->connection;
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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);
|
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;
|
PGresult *res;
|
||||||
|
|
||||||
res = PQexec(g_conn, "begin");
|
res = PQexec(g_conn, "BEGIN");
|
||||||
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
|
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||||
exit_horribly(g_fout, NULL, "BEGIN command failed: %s",
|
exit_horribly(g_fout, NULL, "BEGIN command failed: %s",
|
||||||
PQerrorMessage(g_conn));
|
PQerrorMessage(g_conn));
|
||||||
|
|
||||||
PQclear(res);
|
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)
|
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||||
exit_horribly(g_fout, NULL, "could not set transaction isolation level to serializable: %s",
|
exit_horribly(g_fout, NULL, "could not set transaction isolation level to serializable: %s",
|
||||||
PQerrorMessage(g_conn));
|
PQerrorMessage(g_conn));
|
||||||
|
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user