Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3f63333

Browse files
committed
Make pg_dump/restore safer for autocommit=off in postgresql.conf.
1 parent 37664ee commit 3f63333

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.67 2003/02/01 22:06:59 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.68 2003/02/14 19:40:42 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -206,7 +206,8 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
206206
sav = SetOutput(AH, ropt->filename, ropt->compression);
207207

208208
ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");
209-
209+
ahprintf(AH, "SET autocommit TO 'on';\n\n");
210+
210211
/*
211212
* Drop the items at the start, in reverse order
212213
*/
@@ -2109,7 +2110,8 @@ _reconnectAsUser(ArchiveHandle *AH, const char *dbname, const char *user)
21092110
dbname ? fmtId(dbname) : "-");
21102111
appendPQExpBuffer(qry, " %s\n\n",
21112112
fmtId(user));
2112-
2113+
appendPQExpBuffer(qry, "SET autocommit TO 'on';\n\n");
2114+
21132115
ahprintf(AH, qry->data);
21142116

21152117
destroyPQExpBuffer(qry);

src/bin/pg_dump/pg_backup_db.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Implements the basic DB functions used by the archiver.
66
*
77
* IDENTIFICATION
8-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.45 2003/02/13 04:54:15 momjian Exp $
8+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.46 2003/02/14 19:40:42 momjian Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -213,6 +213,21 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser)
213213
if (password)
214214
free(password);
215215

216+
/* check for version mismatch */
217+
_check_database_version(AH, true);
218+
219+
/* Turn autocommit on */
220+
if (AH->public.remoteVersion >= 70300)
221+
{
222+
PGresult *res;
223+
224+
res = PQexec(AH->connection, "SET autocommit TO 'on'");
225+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
226+
die_horribly(AH, NULL, "SET autocommit TO 'on' failed: %s",
227+
PQerrorMessage(AH->connection));
228+
PQclear(res);
229+
}
230+
216231
PQsetNoticeProcessor(newConn, notice_processor, NULL);
217232

218233
return newConn;

src/bin/pg_dump/pg_dumpall.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.13 2003/01/16 15:27:59 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.14 2003/02/14 19:40:42 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -190,6 +190,7 @@ main(int argc, char *argv[])
190190
printf("-- PostgreSQL database cluster dump\n");
191191
printf("--\n\n");
192192
printf("\\connect \"template1\"\n\n");
193+
printf("SET autocommit TO 'on';\n\n");
193194

194195
dumpUsers(conn);
195196
dumpGroups(conn);
@@ -552,6 +553,7 @@ dumpDatabases(PGconn *conn)
552553
fprintf(stderr, _("%s: dumping database \"%s\"...\n"), progname, dbname);
553554

554555
printf("\\connect %s\n", fmtId(dbname));
556+
printf("SET autocommit TO 'on';\n\n");
555557
ret = runPgDump(dbname);
556558
if (ret != 0)
557559
{
@@ -677,6 +679,14 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
677679
}
678680
PQclear(res);
679681

682+
if (server_version >= 70300)
683+
{
684+
PGresult *res;
685+
686+
res = executeQuery(conn, "SET autocommit TO 'on';SELECT 1;");
687+
PQclear(res);
688+
}
689+
680690
return conn;
681691
}
682692

0 commit comments

Comments
 (0)