Make pg_dump/restore safer for autocommit=off in postgresql.conf.
This commit is contained in:
parent
37664ee465
commit
3f6333357f
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.67 2003/02/01 22:06:59 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.68 2003/02/14 19:40:42 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -206,6 +206,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
|
|||||||
sav = SetOutput(AH, ropt->filename, ropt->compression);
|
sav = SetOutput(AH, ropt->filename, ropt->compression);
|
||||||
|
|
||||||
ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");
|
ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");
|
||||||
|
ahprintf(AH, "SET autocommit TO 'on';\n\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Drop the items at the start, in reverse order
|
* Drop the items at the start, in reverse order
|
||||||
@ -2109,6 +2110,7 @@ _reconnectAsUser(ArchiveHandle *AH, const char *dbname, const char *user)
|
|||||||
dbname ? fmtId(dbname) : "-");
|
dbname ? fmtId(dbname) : "-");
|
||||||
appendPQExpBuffer(qry, " %s\n\n",
|
appendPQExpBuffer(qry, " %s\n\n",
|
||||||
fmtId(user));
|
fmtId(user));
|
||||||
|
appendPQExpBuffer(qry, "SET autocommit TO 'on';\n\n");
|
||||||
|
|
||||||
ahprintf(AH, qry->data);
|
ahprintf(AH, qry->data);
|
||||||
|
|
||||||
|
@ -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.45 2003/02/13 04:54:15 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.46 2003/02/14 19:40:42 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -213,6 +213,21 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser)
|
|||||||
if (password)
|
if (password)
|
||||||
free(password);
|
free(password);
|
||||||
|
|
||||||
|
/* check for version mismatch */
|
||||||
|
_check_database_version(AH, true);
|
||||||
|
|
||||||
|
/* 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(newConn, notice_processor, NULL);
|
PQsetNoticeProcessor(newConn, notice_processor, NULL);
|
||||||
|
|
||||||
return newConn;
|
return newConn;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.13 2003/01/16 15:27:59 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.14 2003/02/14 19:40:42 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -190,6 +190,7 @@ main(int argc, char *argv[])
|
|||||||
printf("-- PostgreSQL database cluster dump\n");
|
printf("-- PostgreSQL database cluster dump\n");
|
||||||
printf("--\n\n");
|
printf("--\n\n");
|
||||||
printf("\\connect \"template1\"\n\n");
|
printf("\\connect \"template1\"\n\n");
|
||||||
|
printf("SET autocommit TO 'on';\n\n");
|
||||||
|
|
||||||
dumpUsers(conn);
|
dumpUsers(conn);
|
||||||
dumpGroups(conn);
|
dumpGroups(conn);
|
||||||
@ -552,6 +553,7 @@ dumpDatabases(PGconn *conn)
|
|||||||
fprintf(stderr, _("%s: dumping database \"%s\"...\n"), progname, dbname);
|
fprintf(stderr, _("%s: dumping database \"%s\"...\n"), progname, dbname);
|
||||||
|
|
||||||
printf("\\connect %s\n", fmtId(dbname));
|
printf("\\connect %s\n", fmtId(dbname));
|
||||||
|
printf("SET autocommit TO 'on';\n\n");
|
||||||
ret = runPgDump(dbname);
|
ret = runPgDump(dbname);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
@ -677,6 +679,14 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
|
|||||||
}
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
|
if (server_version >= 70300)
|
||||||
|
{
|
||||||
|
PGresult *res;
|
||||||
|
|
||||||
|
res = executeQuery(conn, "SET autocommit TO 'on';SELECT 1;");
|
||||||
|
PQclear(res);
|
||||||
|
}
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user