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

Commitd015dcb

Browse files
committed
Have SET not start transaction when autocommit off, with doc updates.
1 parenteb94972 commitd015dcb

File tree

4 files changed

+63
-22
lines changed

4 files changed

+63
-22
lines changed

‎doc/src/sgml/ref/reset.sgml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/reset.sgml,v 1.15 2002/09/21 18:32:54 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/reset.sgml,v 1.16 2002/10/09 04:59:38 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -66,6 +66,12 @@ SET <replaceable class="parameter">variable</replaceable> TO DEFAULT
6666
switches, or per-database or per-user default settings. See the
6767
<citetitle>Administrator's Guide</citetitle> for details.
6868
</para>
69+
70+
<para>
71+
See the <command>SHOW</> manual page for details on the transaction
72+
behavior of <command>RESET</>.
73+
</para>
74+
6975
</refsect1>
7076

7177
<refsect1>

‎doc/src/sgml/ref/set.sgml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/set.sgml,v 1.65 2002/09/21 18:32:54 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/set.sgml,v 1.66 2002/10/09 04:59:38 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -108,6 +108,12 @@ SET [ SESSION | LOCAL ] TIME ZONE { <replaceable class="PARAMETER">timezone</rep
108108
is committed) the <command>SET</command> value will take effect.
109109
</para>
110110

111+
<para>
112+
With <literal>autocommit</> set to <literal>off</>, <command>SET</>
113+
does not start a new transaction block. See the
114+
<literal>autocommit</> section of the documentation for details.
115+
</para>
116+
111117
<para>
112118
Here are additional details about a few of the parameters that can be set:
113119

‎doc/src/sgml/runtime.sgml

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.143 2002/10/03 02:26:49 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.144 2002/10/09 04:59:38 momjian Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -1235,16 +1235,32 @@ env PGOPTIONS='-c geqo=off' psql
12351235
that is not inside an explicit transaction block (that is, unless a
12361236
<command>BEGIN</> with no matching <command>COMMIT</> has been
12371237
given).
1238-
If set to false, <productname>PostgreSQL</productname> will commit
1239-
the effects of commands only on receiving an explicit
1240-
<command>COMMIT</> command. This mode can also be thought of as
1241-
implicitly issuing <command>BEGIN</> whenever a command is received
1242-
and <productname>PostgreSQL</productname> is not already inside
1243-
a transaction block.
1244-
The default is true, for compatibility with historical
1245-
<productname>PostgreSQL</productname> behavior. But for maximum
1246-
compatibility with the SQL specification, set it to false.
1247-
</para>
1238+
If set to false, <productname>PostgreSQL</productname> will
1239+
commit the commands only when receiving an explicit
1240+
<command>COMMIT</> command. This mode can also be thought of as
1241+
implicitly issuing <command>BEGIN</> whenever a command is
1242+
received that is not already inside a transaction block. The
1243+
default is true, for compatibility with historical
1244+
<productname>PostgreSQL</productname> behavior. However, for
1245+
maximum compatibility with the SQL specification, set it to
1246+
false.
1247+
</para>
1248+
<note>
1249+
<para>
1250+
With <varname>autocommit</> set to false, <command>SET</>,
1251+
<command>SHOW</>, and <command>RESET</> do not start new
1252+
transaction blocks. They are run in their own transactions.
1253+
Once another command is issued, multi-statement transaction
1254+
behavior begins and any <command>SET</>, <command>SHOW</>, or
1255+
<command>RESET</> commands are considered to be part of the
1256+
transaction, i.e. they are committed or rolled back depending
1257+
on the completion status of the transaction. To have
1258+
<command>SET</>, <command>SHOW</>, and <command>RESET</>
1259+
commands at the start of a transaction, use <command>BEGIN</>
1260+
first.
1261+
</para>
1262+
</note>
1263+
12481264
</listitem>
12491265
</varlistentry>
12501266

‎src/backend/tcop/postgres.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.299 2002/10/08 17:17:19 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.300 2002/10/09 04:59:38 momjian Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -76,6 +76,7 @@ char *debug_query_string; /* for pgmonitor and
7676
CommandDestwhereToSendOutput=Debug;
7777

7878
externintStatementTimeout;
79+
externboolautocommit;
7980

8081
staticbooldontExecute= false;
8182

@@ -122,7 +123,7 @@ static intReadCommand(StringInfo inBuf);
122123
staticList*pg_parse_query(StringInfoquery_string,Oid*typev,intnargs);
123124
staticList*pg_analyze_and_rewrite(Node*parsetree);
124125
staticvoidstart_xact_command(void);
125-
staticvoidfinish_xact_command(void);
126+
staticvoidfinish_xact_command(boolforceCommit);
126127
staticvoidSigHupHandler(SIGNAL_ARGS);
127128
staticvoidFloatExceptionHandler(SIGNAL_ARGS);
128129
staticconstchar*CreateCommandTag(Node*parsetree);
@@ -825,7 +826,7 @@ pg_exec_query_string(StringInfo query_string,/* string to execute */
825826
*/
826827
if (isTransactionStmt)
827828
{
828-
finish_xact_command();
829+
finish_xact_command(false);
829830
xact_started= false;
830831
}
831832
}/* end loop over queries generated from a
@@ -843,7 +844,19 @@ pg_exec_query_string(StringInfo query_string,/* string to execute */
843844
*/
844845
if (lnext(parsetree_item)==NIL&&xact_started)
845846
{
846-
finish_xact_command();
847+
/*
848+
*Don't allow SET/SHOW/RESET to start a new transaction
849+
*with autocommit off. We do this by forcing a COMMIT
850+
*when these commands start a transaction.
851+
*/
852+
if (autocommit||
853+
IsTransactionState()||
854+
(strcmp(commandTag,"SET")!=0&&
855+
strcmp(commandTag,"SHOW")!=0&&
856+
strcmp(commandTag,"RESET")!=0))
857+
finish_xact_command(false);
858+
else
859+
finish_xact_command(true);
847860
xact_started= false;
848861
}
849862

@@ -878,7 +891,7 @@ pg_exec_query_string(StringInfo query_string,/* string to execute */
878891
* will only happen if the querystring was empty.)
879892
*/
880893
if (xact_started)
881-
finish_xact_command();
894+
finish_xact_command(false);
882895

883896
if (save_Log_duration)
884897
{
@@ -907,15 +920,15 @@ start_xact_command(void)
907920
}
908921

909922
staticvoid
910-
finish_xact_command(void)
923+
finish_xact_command(boolforceCommit)
911924
{
912925
/* Invoke IMMEDIATE constraint triggers */
913926
DeferredTriggerEndQuery();
914927

915928
/* Now commit the command */
916929
elog(DEBUG1,"CommitTransactionCommand");
917930

918-
CommitTransactionCommand(false);
931+
CommitTransactionCommand(forceCommit);
919932

920933
#ifdefSHOW_MEMORY_STATS
921934
/* Print mem stats at each commit for leak tracking */
@@ -1720,7 +1733,7 @@ PostgresMain(int argc, char *argv[], const char *username)
17201733
if (!IsUnderPostmaster)
17211734
{
17221735
puts("\nPOSTGRES backend interactive interface ");
1723-
puts("$Revision: 1.299 $ $Date: 2002/10/08 17:17:19 $\n");
1736+
puts("$Revision: 1.300 $ $Date: 2002/10/09 04:59:38 $\n");
17241737
}
17251738

17261739
/*
@@ -1923,7 +1936,7 @@ PostgresMain(int argc, char *argv[], const char *username)
19231936
}
19241937

19251938
/* commit the function-invocation transaction */
1926-
finish_xact_command();
1939+
finish_xact_command(false);
19271940
break;
19281941

19291942
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp