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

Commit 10e9cd2

Browse files
committed
Allow default transaction isolation level (a.k.a. set session
characteristics) to be set through GUC.
1 parent e4a40cc commit 10e9cd2

File tree

6 files changed

+79
-87
lines changed

6 files changed

+79
-87
lines changed

doc/src/sgml/ref/set_transaction.sgml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/set_transaction.sgml,v 1.3 2000/11/24 20:16:38 petere Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/set_transaction.sgml,v 1.4 2001/06/30 22:03:25 petere Exp $ -->
22
<refentry id="SQL-SET-TRANSACTION">
33
<docinfo>
44
<date>2000-11-24</date>
@@ -74,6 +74,18 @@ SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL { READ COMMITTED | SE
7474
</para>
7575
</refsect1>
7676

77+
<refsect1>
78+
<title>Notes</title>
79+
80+
<para>
81+
The session default transaction isolation level can also be set
82+
with the command <literal>SET default_transaction_isolation =
83+
'<replaceable>value</replaceable>'</literal> and in the
84+
configuration file. Consult the <citetitle>Administrator's
85+
Guide</citetitle> for more information.
86+
</para>
87+
</refsect1>
88+
7789
<refsect1 id="R1-SQL-SET-TRANSACTION-3">
7890
<title>Compatibility</title>
7991

doc/src/sgml/runtime.sgml

Lines changed: 27 additions & 4 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.71 2001/06/30 21:15:57 darcy Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.72 2001/06/30 22:03:25 petere Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -996,6 +996,29 @@ env PGOPTIONS='-c geqo=off' psql
996996
</listitem>
997997
</varlistentry>
998998

999+
<varlistentry>
1000+
<indexterm>
1001+
<primary>transaction isolation level</primary>
1002+
</indexterm>
1003+
1004+
<term>DEFAUL_TRANSACTION_ISOLATION (<type>string</type>)</term>
1005+
<listitem>
1006+
<para>
1007+
Each SQL transaction has an isolation level, which can be
1008+
either <quote>read committed</quote> or
1009+
<quote>serializable</quote>. This parameter controls what the
1010+
isolation level of each new transaction is set to. The
1011+
default is read committed.
1012+
</para>
1013+
1014+
<para>
1015+
Consult the <citetitle>PostgreSQL User's Guide</citetitle> and
1016+
the command <command>SET TRANSACTION</command> for more
1017+
information.
1018+
</para>
1019+
</listitem>
1020+
</varlistentry>
1021+
9991022
<varlistentry>
10001023
<term>DYNAMIC_LIBRARY_PATH (<type>string</type>)</term>
10011024
<listitem>
@@ -1051,9 +1074,9 @@ dynamic_library_path = '/usr/local/lib:/home/my_project/lib:$libdir:$libdir/cont
10511074
will use the <function>fsync()</> system call in several
10521075
places to make sure that updates are physically written to
10531076
disk and do not hang around in the kernel buffer cache. This
1054-
increases the chance that a database installation will still
1055-
be usable after an operating system or hardware crash by a
1056-
large amount. (Crashes of the database server itself do
1077+
increases the chance by a large amount that a database
1078+
installation will still be usable after an operating system or
1079+
hardware crash. (Crashes of the database server itself do
10571080
<emphasis>not</> affect this consideration.)
10581081
</para>
10591082

src/backend/commands/variable.c

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.50 2001/06/12 22:54:05 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.51 2001/06/30 22:03:25 petere Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -46,9 +46,6 @@ static bool show_timezone(void);
4646
static bool reset_timezone(void);
4747
static bool parse_timezone(char *);
4848

49-
static bool show_DefaultXactIsoLevel(void);
50-
static bool reset_DefaultXactIsoLevel(void);
51-
static bool parse_DefaultXactIsoLevel(char *);
5249
static bool show_XactIsoLevel(void);
5350
static bool reset_XactIsoLevel(void);
5451
static bool parse_XactIsoLevel(char *);
@@ -448,69 +445,6 @@ reset_timezone(void)
448445

449446
/* SET TRANSACTION */
450447

451-
static bool
452-
parse_DefaultXactIsoLevel(char *value)
453-
{
454-
#if 0
455-
TransactionState s = CurrentTransactionState;
456-
457-
#endif
458-
459-
if (value == NULL)
460-
{
461-
reset_DefaultXactIsoLevel();
462-
return TRUE;
463-
}
464-
465-
#if 0
466-
if (s->state != TRANS_DEFAULT)
467-
{
468-
elog(ERROR, "ALTER SESSION/SET TRANSACTION ISOLATION LEVEL"
469-
" can not be called within a transaction");
470-
return TRUE;
471-
}
472-
#endif
473-
474-
if (strcasecmp(value, "SERIALIZABLE") == 0)
475-
DefaultXactIsoLevel = XACT_SERIALIZABLE;
476-
else if (strcasecmp(value, "COMMITTED") == 0)
477-
DefaultXactIsoLevel = XACT_READ_COMMITTED;
478-
else
479-
elog(ERROR, "Bad TRANSACTION ISOLATION LEVEL (%s)", value);
480-
481-
return TRUE;
482-
}
483-
484-
static bool
485-
show_DefaultXactIsoLevel(void)
486-
{
487-
488-
if (DefaultXactIsoLevel == XACT_SERIALIZABLE)
489-
elog(NOTICE, "Default TRANSACTION ISOLATION LEVEL is SERIALIZABLE");
490-
else
491-
elog(NOTICE, "Default TRANSACTION ISOLATION LEVEL is READ COMMITTED");
492-
return TRUE;
493-
}
494-
495-
static bool
496-
reset_DefaultXactIsoLevel(void)
497-
{
498-
#if 0
499-
TransactionState s = CurrentTransactionState;
500-
501-
if (s->state != TRANS_DEFAULT)
502-
{
503-
elog(ERROR, "ALTER SESSION/SET TRANSACTION ISOLATION LEVEL"
504-
" can not be called within a transaction");
505-
return TRUE;
506-
}
507-
#endif
508-
509-
DefaultXactIsoLevel = XACT_READ_COMMITTED;
510-
511-
return TRUE;
512-
}
513-
514448
static bool
515449
parse_XactIsoLevel(char *value)
516450
{
@@ -530,7 +464,7 @@ parse_XactIsoLevel(char *value)
530464

531465
if (strcasecmp(value, "SERIALIZABLE") == 0)
532466
XactIsoLevel = XACT_SERIALIZABLE;
533-
else if (strcasecmp(value, "COMMITTED") == 0)
467+
else if (strcasecmp(value, "READ COMMITTED") == 0)
534468
XactIsoLevel = XACT_READ_COMMITTED;
535469
else
536470
elog(ERROR, "Bad TRANSACTION ISOLATION LEVEL (%s)", value);
@@ -711,8 +645,6 @@ SetPGVariable(const char *name, const char *value)
711645
parse_datestyle(mvalue);
712646
else if (strcasecmp(name, "timezone") == 0)
713647
parse_timezone(mvalue);
714-
else if (strcasecmp(name, "DefaultXactIsoLevel") == 0)
715-
parse_DefaultXactIsoLevel(mvalue);
716648
else if (strcasecmp(name, "XactIsoLevel") == 0)
717649
parse_XactIsoLevel(mvalue);
718650
else if (strcasecmp(name, "client_encoding") == 0)
@@ -737,8 +669,6 @@ GetPGVariable(const char *name)
737669
show_datestyle();
738670
else if (strcasecmp(name, "timezone") == 0)
739671
show_timezone();
740-
else if (strcasecmp(name, "DefaultXactIsoLevel") == 0)
741-
show_DefaultXactIsoLevel();
742672
else if (strcasecmp(name, "XactIsoLevel") == 0)
743673
show_XactIsoLevel();
744674
else if (strcasecmp(name, "client_encoding") == 0)
@@ -752,7 +682,6 @@ GetPGVariable(const char *name)
752682
ShowAllGUCConfig();
753683
show_datestyle();
754684
show_timezone();
755-
show_DefaultXactIsoLevel();
756685
show_XactIsoLevel();
757686
show_client_encoding();
758687
show_server_encoding();
@@ -772,8 +701,6 @@ ResetPGVariable(const char *name)
772701
reset_datestyle();
773702
else if (strcasecmp(name, "timezone") == 0)
774703
reset_timezone();
775-
else if (strcasecmp(name, "DefaultXactIsoLevel") == 0)
776-
reset_DefaultXactIsoLevel();
777704
else if (strcasecmp(name, "XactIsoLevel") == 0)
778705
reset_XactIsoLevel();
779706
else if (strcasecmp(name, "client_encoding") == 0)
@@ -784,16 +711,15 @@ ResetPGVariable(const char *name)
784711
reset_random_seed();
785712
else if (strcasecmp(name, "all") == 0)
786713
{
787-
reset_DefaultXactIsoLevel();
788-
reset_XactIsoLevel();
789714
reset_random_seed();
790715
/* reset_server_encoding(); */
791716
reset_client_encoding();
792717
reset_datestyle();
793718
reset_timezone();
794719

795720
ResetAllOptions(false);
796-
} else
721+
}
722+
else
797723
SetConfigOption(name, NULL,
798724
superuser() ? PGC_SUSET : PGC_USERSET,
799725
false);

src/backend/parser/gram.y

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.232 2001/06/23 00:07:34 momjian Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.233 2001/06/30 22:03:25 petere Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -752,7 +752,7 @@ VariableSetStmt: SET ColId TO var_value
752752
| SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL opt_level
753753
{
754754
VariableSetStmt *n = makeNode(VariableSetStmt);
755-
n->name = "DefaultXactIsoLevel";
755+
n->name = "default_transaction_isolation";
756756
n->value = $8;
757757
$$ = (Node *) n;
758758
}
@@ -772,7 +772,7 @@ VariableSetStmt: SET ColId TO var_value
772772
}
773773
;
774774

775-
opt_level: READ COMMITTED { $$ = "committed"; }
775+
opt_level: READ COMMITTED { $$ = "read committed"; }
776776
| SERIALIZABLE { $$ = "serializable"; }
777777
;
778778

src/backend/utils/misc/guc.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Support for grand unified configuration scheme, including SET
55
* command, configuration file, and command line options.
66
*
7-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.43 2001/06/27 23:31:39 tgl Exp $
7+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.44 2001/06/30 22:03:26 petere Exp $
88
*
99
* Copyright 2000 by PostgreSQL Global Development Group
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
@@ -51,6 +51,11 @@ extern char *Syslog_ident;
5151
static bool check_facility(const char *facility);
5252
#endif
5353

54+
static char *default_iso_level_string;
55+
56+
static bool check_defaultxactisolevel(const char *value);
57+
static void assign_defaultxactisolevel(const char *value);
58+
5459
/*
5560
* Debugging options
5661
*/
@@ -355,6 +360,9 @@ static struct config_real
355360
static struct config_string
356361
ConfigureNamesString[] =
357362
{
363+
{"default_transaction_isolation", PGC_USERSET, &default_iso_level_string,
364+
"read committed", check_defaultxactisolevel, assign_defaultxactisolevel},
365+
358366
{"dynamic_library_path", PGC_SUSET, &Dynamic_library_path,
359367
"$libdir", NULL, NULL},
360368

@@ -1092,3 +1100,25 @@ check_facility(const char *facility)
10921100
}
10931101

10941102
#endif
1103+
1104+
1105+
1106+
static bool
1107+
check_defaultxactisolevel(const char *value)
1108+
{
1109+
return (strcasecmp(value, "read committed") == 0
1110+
|| strcasecmp(value, "serializable") == 0)
1111+
? true : false;
1112+
}
1113+
1114+
1115+
static void
1116+
assign_defaultxactisolevel(const char *value)
1117+
{
1118+
if (strcasecmp(value, "serializable") == 0)
1119+
DefaultXactIsoLevel = XACT_SERIALIZABLE;
1120+
else if (strcasecmp(value, "read committed") == 0)
1121+
DefaultXactIsoLevel = XACT_READ_COMMITTED;
1122+
else
1123+
elog(ERROR, "bogus transaction isolation level");
1124+
}

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
#
167167
# Misc
168168
#
169+
#default_transaction_isolation = 'read committed'
169170
#sql_inheritance = true
170171
#australian_timezones = false
171172
#deadlock_timeout = 1000

0 commit comments

Comments
 (0)