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

Commit0f57851

Browse files
committed
Add psql option:
-1 or --single-transactionSimon Riggs
1 parent3884ede commit0f57851

File tree

9 files changed

+76
-22
lines changed

9 files changed

+76
-22
lines changed

‎doc/src/sgml/ref/pg_restore.sgml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.56 2005/11/01 21:09:50 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.57 2006/02/12 04:04:32 momjian Exp $ -->
22

33
<refentry id="APP-PGRESTORE">
44
<refmeta>
@@ -448,6 +448,19 @@
448448
</para>
449449
</listitem>
450450
</varlistentry>
451+
452+
<varlistentry>
453+
<term><option>-1</option></term>
454+
<term><option>--single-transaction</option></term>
455+
<listitem>
456+
<para>
457+
Force the restore to execute as a single transaction. Either all
458+
SQL statements complete successfully, or no changes are applied. This
459+
option also forces --exit-on-error.
460+
</para>
461+
</listitem>
462+
</varlistentry>
463+
451464
</variablelist>
452465
</para>
453466
</refsect1>

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.158 2006/02/1202:54:30 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.159 2006/02/1204:04:32 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -463,6 +463,18 @@ PostgreSQL documentation
463463
</listitem>
464464
</varlistentry>
465465

466+
<varlistentry>
467+
<term><option>-1</option></term>
468+
<term><option>--single-transaction</option></term>
469+
<listitem>
470+
<para>
471+
When psql executes a script with the -f option, this additional option
472+
will force the script to execute as a single transaction. Either all
473+
SQL statements complete successfully, or no changes are applied.
474+
</para>
475+
</listitem>
476+
</varlistentry>
477+
466478
<varlistentry>
467479
<term><option>-?</></term>
468480
<term><option>--help</></term>

‎src/bin/pg_dump/pg_backup.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.37 2005/10/15 02:49:38 momjian Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.38 2006/02/12 04:04:32 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -115,6 +115,8 @@ typedef struct _restoreOptions
115115

116116
intsuppressDumpWarnings;/* Suppress output of WARNING entries
117117
* to stderr */
118+
boolsingle_txn;
119+
118120
}RestoreOptions;
119121

120122
/*

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.121 2006/02/09 20:52:13 momjian Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.122 2006/02/12 04:04:32 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -217,6 +217,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
217217

218218
AH->stage=STAGE_PROCESSING;
219219

220+
if (ropt->single_txn)
221+
ahprintf(AH,"BEGIN;\n\n");
222+
220223
/*
221224
* Drop the items at the start, in reverse order
222225
*/
@@ -370,6 +373,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
370373
}
371374
}
372375

376+
if (ropt->single_txn)
377+
ahprintf(AH,"COMMIT;\n\n");
378+
373379
if (AH->public.verbose)
374380
dumpTimestamp(AH,"Completed on",time(NULL));
375381

‎src/bin/pg_dump/pg_restore.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*
3535
*
3636
* IDENTIFICATION
37-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.73 2005/10/15 02:49:39 momjian Exp $
37+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.74 2006/02/12 04:04:32 momjian Exp $
3838
*
3939
*-------------------------------------------------------------------------
4040
*/
@@ -111,6 +111,7 @@ main(int argc, char **argv)
111111
{"use-list",1,NULL,'L'},
112112
{"username",1,NULL,'U'},
113113
{"verbose",0,NULL,'v'},
114+
{"single-transaction",0,NULL,'1'},
114115

115116
/*
116117
* the following options don't have an equivalent short option letter,
@@ -142,7 +143,7 @@ main(int argc, char **argv)
142143
}
143144
}
144145

145-
while ((c=getopt_long(argc,argv,"acCd:ef:F:h:iI:lL:n:Op:P:RsS:t:T:uU:vWxX:",
146+
while ((c=getopt_long(argc,argv,"acCd:ef:F:h:iI:lL:n:Op:P:RsS:t:T:uU:vWxX:1",
146147
cmdopts,NULL))!=-1)
147148
{
148149
switch (c)
@@ -185,9 +186,15 @@ main(int argc, char **argv)
185186
opts->tocFile=strdup(optarg);
186187
break;
187188

189+
case'n':/* Dump data for this schema only */
190+
opts->selTypes=1;
191+
opts->schemaNames=strdup(optarg);
192+
break;
193+
188194
case'O':
189195
opts->noOwner=1;
190196
break;
197+
191198
case'p':
192199
if (strlen(optarg)!=0)
193200
opts->pgport=strdup(optarg);
@@ -223,11 +230,6 @@ main(int argc, char **argv)
223230
opts->tableNames=strdup(optarg);
224231
break;
225232

226-
case'n':/* Dump data for this schema only */
227-
opts->selTypes=1;
228-
opts->schemaNames=strdup(optarg);
229-
break;
230-
231233
case'u':
232234
opts->requirePassword= true;
233235
opts->username=simple_prompt("User name: ",100, true);
@@ -268,6 +270,11 @@ main(int argc, char **argv)
268270
case0:
269271
break;
270272

273+
case'1':/* Restore data in a single transaction */
274+
opts->single_txn= true;
275+
opts->exit_on_error= true;
276+
break;
277+
271278
default:
272279
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),progname);
273280
exit(1);
@@ -394,6 +401,7 @@ usage(const char *progname)
394401
printf(_(" -X use-set-session-authorization, --use-set-session-authorization\n"
395402
" use SESSION AUTHORIZATION commands instead of\n"
396403
" OWNER TO commands\n"));
404+
printf(_(" -1, --single-transaction restore as a single transaction\n"));
397405

398406
printf(_("\nConnection options:\n"));
399407
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));

‎src/bin/psql/command.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.160 2006/02/1203:22:19 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.161 2006/02/1204:04:32 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -563,7 +563,7 @@ exec_command(const char *cmd,
563563
else
564564
{
565565
expand_tilde(&fname);
566-
success= (process_file(fname)==EXIT_SUCCESS);
566+
success= (process_file(fname, false)==EXIT_SUCCESS);
567567
free(fname);
568568
}
569569
}
@@ -1435,11 +1435,12 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
14351435
* MainLoop() error code.
14361436
*/
14371437
int
1438-
process_file(char*filename)
1438+
process_file(char*filename,boolsingle_txn)
14391439
{
14401440
FILE*fd;
14411441
intresult;
14421442
char*oldfilename;
1443+
PGresult*res;
14431444

14441445
if (!filename)
14451446
returnEXIT_FAILURE;
@@ -1455,7 +1456,13 @@ process_file(char *filename)
14551456

14561457
oldfilename=pset.inputfile;
14571458
pset.inputfile=filename;
1459+
1460+
if (single_txn)
1461+
res=PSQLexec("BEGIN", false);
14581462
result=MainLoop(fd);
1463+
if (single_txn)
1464+
res=PSQLexec("COMMIT", false);
1465+
14591466
fclose(fd);
14601467
pset.inputfile=oldfilename;
14611468
returnresult;

‎src/bin/psql/command.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.h,v 1.23 2005/12/18 02:17:16 petere Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.h,v 1.24 2006/02/12 04:04:32 momjian Exp $
77
*/
88
#ifndefCOMMAND_H
99
#defineCOMMAND_H
@@ -28,7 +28,7 @@ typedef enum _backslashResult
2828
externbackslashResultHandleSlashCmds(PsqlScanStatescan_state,
2929
PQExpBufferquery_buf);
3030

31-
externintprocess_file(char*filename);
31+
externintprocess_file(char*filename,boolsingle_txn);
3232

3333
externbooldo_pset(constchar*param,
3434
constchar*value,

‎src/bin/psql/help.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.108 2006/02/1202:54:30 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.109 2006/02/1204:04:32 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -93,6 +93,7 @@ usage(void)
9393
printf(_(" -d DBNAME specify database name to connect to (default: \"%s\")\n"),env);
9494
puts(_(" -c COMMAND run only single command (SQL or internal) and exit"));
9595
puts(_(" -f FILENAME execute commands from file, then exit"));
96+
puts(_(" -1 (numeral) execute command file as a single transaction"));
9697
puts(_(" -l list available databases, then exit"));
9798
puts(_(" -v NAME=VALUE set psql variable NAME to VALUE"));
9899
puts(_(" -X do not read startup file (~/.psqlrc)"));

‎src/bin/psql/startup.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.129 2005/12/18 02:17:16 petere Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.130 2006/02/12 04:04:32 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99

@@ -76,6 +76,7 @@ struct adhoc_opts
7676
char*action_string;
7777
boolno_readline;
7878
boolno_psqlrc;
79+
boolsingle_txn;
7980
};
8081

8182
staticintparse_version(constchar*versionString);
@@ -268,7 +269,7 @@ main(int argc, char *argv[])
268269
if (!options.no_psqlrc)
269270
process_psqlrc(argv[0]);
270271

271-
successResult=process_file(options.action_string);
272+
successResult=process_file(options.action_string,options.single_txn);
272273
}
273274

274275
/*
@@ -425,6 +426,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
425426
{"list",no_argument,NULL,'l'},
426427
{"log-file",required_argument,NULL,'L'},
427428
{"no-readline",no_argument,NULL,'n'},
429+
{"single-transaction",no_argument,NULL,'1'},
428430
{"output",required_argument,NULL,'o'},
429431
{"port",required_argument,NULL,'p'},
430432
{"pset",required_argument,NULL,'P'},
@@ -453,7 +455,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
453455

454456
memset(options,0,sizeof*options);
455457

456-
while ((c=getopt_long(argc,argv,"aAc:d:eEf:F:h:HlL:no:p:P:qR:sStT:uU:v:VWxX?",
458+
while ((c=getopt_long(argc,argv,"aAc:d:eEf:F:h:HlL:no:p:P:qR:sStT:uU:v:VWxX?1",
457459
long_options,&optindex))!=-1)
458460
{
459461
switch (c)
@@ -606,6 +608,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
606608
case'X':
607609
options->no_psqlrc= true;
608610
break;
611+
case'1':
612+
options->single_txn= true;
613+
break;
609614
case'?':
610615
/* Actual help option given */
611616
if (strcmp(argv[optind-1],"-?")==0||strcmp(argv[optind-1],"--help")==0)
@@ -690,9 +695,9 @@ process_psqlrc_file(char *filename)
690695
sprintf(psqlrc,"%s-%s",filename,PG_VERSION);
691696

692697
if (access(psqlrc,R_OK)==0)
693-
(void)process_file(psqlrc);
698+
(void)process_file(psqlrc, false);
694699
elseif (access(filename,R_OK)==0)
695-
(void)process_file(filename);
700+
(void)process_file(filename, false);
696701
free(psqlrc);
697702
}
698703

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp