Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcda776e

Browse files
committed
Make pg_dump save for autocommit = off.
1 parentec64390 commitcda776e

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 2 additions & 6 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.57 2002/09/04 20:31:34 momjian Exp $
18+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.58 2002/10/16 05:46:54 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -280,7 +280,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
280280
/*
281281
* If we can output the data, then restore it.
282282
*/
283-
if (AH->PrintTocDataPtr!=NULL&& (reqs&REQ_DATA)!=0)
283+
if (AH->PrintTocDataPtr!=NULL&& (reqs&REQ_DATA)!=0)
284284
{
285285
#ifndefHAVE_LIBZ
286286
if (AH->compression!=0)
@@ -304,11 +304,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
304304
*/
305305
if (!AH->CustomOutPtr)
306306
write_msg(modulename,"WARNING: skipping large object restoration\n");
307-
308307
}
309308
else
310309
{
311-
312310
_disableTriggersIfNecessary(AH,te,ropt);
313311

314312
/*
@@ -362,11 +360,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
362360
te=AH->toc->next;
363361
while (te!=AH->toc)
364362
{
365-
366363
/* Is it table data? */
367364
if (strcmp(te->desc,"TABLE DATA")==0)
368365
{
369-
370366
ahlog(AH,2,"checking whether we loaded %s\n",te->tag);
371367

372368
reqs=_tocEntryRequired(te,ropt);

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 25 additions & 3 deletions
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.41 2002/09/07 16:14:33 petere Exp $
8+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.42 2002/10/16 05:46:54 momjian Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -61,18 +61,28 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
6161

6262
myversion=_parse_version(AH,PG_VERSION);
6363

64-
res=PQexec(conn,"SELECT version();");
64+
/*
65+
*Autocommit could be off. We turn it off later but we have to check
66+
*the database version first.
67+
*/
68+
69+
res=PQexec(conn,"BEGIN;SELECT version();");
6570
if (!res||
6671
PQresultStatus(res)!=PGRES_TUPLES_OK||
6772
PQntuples(res)!=1)
68-
6973
die_horribly(AH,modulename,"could not get version from server: %s",PQerrorMessage(conn));
7074

7175
remoteversion_str=PQgetvalue(res,0,0);
7276
remoteversion=_parse_version(AH,remoteversion_str+11);
7377

7478
PQclear(res);
7579

80+
res=PQexec(conn,"COMMIT;");
81+
if (!res||
82+
PQresultStatus(res)!=PGRES_COMMAND_OK)
83+
die_horribly(AH,modulename,"could not get version from server: %s",PQerrorMessage(conn));
84+
PQclear(res);
85+
7686
AH->public.remoteVersion=remoteversion;
7787

7888
if (myversion!=remoteversion
@@ -277,6 +287,18 @@ ConnectDatabase(Archive *AHX,
277287
/* check for version mismatch */
278288
_check_database_version(AH,ignoreVersion);
279289

290+
/* Turn autocommit on */
291+
if (AH->public.remoteVersion >=70300)
292+
{
293+
PGresult*res;
294+
295+
res=PQexec(AH->connection,"SET autocommit TO 'on'");
296+
if (!res||PQresultStatus(res)!=PGRES_COMMAND_OK)
297+
die_horribly(AH,NULL,"SET autocommit TO 'on' failed: %s",
298+
PQerrorMessage(AH->connection));
299+
PQclear(res);
300+
}
301+
280302
PQsetNoticeProcessor(AH->connection,notice_processor,NULL);
281303

282304
returnAH->connection;

‎src/bin/pg_dump/pg_dump.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.302 2002/10/09 16:20:25 momjian Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.303 2002/10/16 05:46:54 momjian Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -549,22 +549,21 @@ main(int argc, char **argv)
549549
g_conn=ConnectDatabase(g_fout,dbname,pghost,pgport,username,force_password,ignore_version);
550550

551551
/*
552-
* Start serializable transaction to dump consistent data
552+
* Start serializable transaction to dump consistent data.
553553
*/
554554
{
555555
PGresult*res;
556556

557-
res=PQexec(g_conn,"begin");
557+
res=PQexec(g_conn,"BEGIN");
558558
if (!res||PQresultStatus(res)!=PGRES_COMMAND_OK)
559559
exit_horribly(g_fout,NULL,"BEGIN command failed: %s",
560560
PQerrorMessage(g_conn));
561-
562561
PQclear(res);
563-
res=PQexec(g_conn,"set transaction isolation level serializable");
562+
563+
res=PQexec(g_conn,"SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
564564
if (!res||PQresultStatus(res)!=PGRES_COMMAND_OK)
565565
exit_horribly(g_fout,NULL,"could not set transaction isolation level to serializable: %s",
566566
PQerrorMessage(g_conn));
567-
568567
PQclear(res);
569568
}
570569

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp