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

Commitb65cd56

Browse files
committed
Read-only transactions, as defined in SQL.
1 parentb7ca9bd commitb65cd56

File tree

16 files changed

+427
-146
lines changed

16 files changed

+427
-146
lines changed

‎doc/src/sgml/features.sgml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/features.sgml,v 2.13 2003/01/1011:02:41 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/features.sgml,v 2.14 2003/01/1022:03:26 petere Exp $
33
-->
44

55
<appendix id="features">
@@ -642,13 +642,26 @@ $Header: /cvsroot/pgsql/doc/src/sgml/features.sgml,v 2.13 2003/01/10 11:02:41 pe
642642
<entry>ROLLBACK statement</entry>
643643
<entry></entry>
644644
</row>
645+
<row>
646+
<entry>E152</entry>
647+
<entry>Core</entry>
648+
<entry>Basic SET TRANSACTION statement</entry>
649+
<entry></entry>
650+
</row>
645651
<row>
646652
<entry>E152-01</entry>
647653
<entry>Core</entry>
648654
<entry>SET TRANSACTION statement: ISOLATION LEVEL SERIALIZABLE
649655
clause</entry>
650656
<entry></entry>
651657
</row>
658+
<row>
659+
<entry>E152-02</entry>
660+
<entry>Core</entry>
661+
<entry>SET TRANSACTION statement: READ ONLY and READ WRITE
662+
clauses</entry>
663+
<entry></entry>
664+
</row>
652665
<row>
653666
<entry>E161</entry>
654667
<entry>Core</entry>
@@ -1598,19 +1611,6 @@ $Header: /cvsroot/pgsql/doc/src/sgml/features.sgml,v 2.13 2003/01/10 11:02:41 pe
15981611
<entry>WITH HOLD cursors</entry>
15991612
<entry>Cursor to stay open across transactions</entry>
16001613
</row>
1601-
<row>
1602-
<entry>E152</entry>
1603-
<entry>Core</entry>
1604-
<entry>Basic SET TRANSACTION statement</entry>
1605-
<entry></entry>
1606-
</row>
1607-
<row>
1608-
<entry>E152-02</entry>
1609-
<entry>Core</entry>
1610-
<entry>SET TRANSACTION statement: READ ONLY and READ WRITE
1611-
clauses</entry>
1612-
<entry>Syntax accepted; READ ONLY not supported</entry>
1613-
</row>
16141614
<row>
16151615
<entry>E153</entry>
16161616
<entry>Core</entry>

‎doc/src/sgml/ref/set_transaction.sgml

Lines changed: 47 additions & 23 deletions
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.9 2002/08/04 04:31:44 momjian Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/set_transaction.sgml,v 1.10 2003/01/10 22:03:27 petere Exp $ -->
22
<refentry id="SQL-SET-TRANSACTION">
33
<docinfo>
44
<date>2000-11-24</date>
@@ -16,27 +16,30 @@
1616

1717
<refsynopsisdiv>
1818
<synopsis>
19-
SET TRANSACTION ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE }
20-
SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL
21-
{ READ COMMITTED | SERIALIZABLE }
19+
SET TRANSACTION
20+
[ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]
21+
SET SESSION CHARACTERISTICS AS TRANSACTION
22+
[ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]
2223
</synopsis>
2324
</refsynopsisdiv>
2425

2526
<refsect1>
2627
<title>Description</title>
2728

2829
<para>
29-
This command sets the transaction isolation level. The
30-
<command>SET TRANSACTION</command> command sets the characteristics
31-
for the current SQL-transaction. It has no effect on any subsequent
32-
transactions. This command cannot be used after the first query or data-modification
33-
statement (<command>SELECT</command>, <command>INSERT</command>,
34-
<command>DELETE</command>, <command>UPDATE</command>,
35-
<command>FETCH</command>, <command>COPY</command>) of a transaction
36-
has been executed. <command>SET SESSION CHARACTERISTICS</command>
37-
sets the default transaction isolation level for each transaction
38-
for a session. <command>SET TRANSACTION</command> can override it
39-
for an individual transaction.
30+
The <command>SET TRANSACTION</command> command sets the transaction
31+
characteristics of the current SQL-transaction. It has no effect on
32+
any subsequent transactions. <command>SET SESSION
33+
CHARACTERISTICS</command> sets the default transaction
34+
characteristics for each transaction of a session. <command>SET
35+
TRANSACTION</command> can override it for an individual
36+
transaction.
37+
</para>
38+
39+
<para>
40+
The available transaction characteristics are the transaction
41+
isolation level and the transaction access mode (read/write or
42+
read-only).
4043
</para>
4144

4245
<para>
@@ -45,7 +48,7 @@ SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL
4548

4649
<variablelist>
4750
<varlistentry>
48-
<term>READ COMMITTED</term>
51+
<term><literal>READ COMMITTED<literal></term>
4952
<listitem>
5053
<para>
5154
A statement can only see rows committed before it began. This
@@ -55,7 +58,7 @@ SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL
5558
</varlistentry>
5659

5760
<varlistentry>
58-
<term>SERIALIZABLE</term>
61+
<term><literal>SERIALIZABLE</literal></term>
5962
<listitem>
6063
<para>
6164
The current transaction can only see rows committed before
@@ -72,6 +75,28 @@ SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL
7275
</listitem>
7376
</varlistentry>
7477
</variablelist>
78+
79+
The transaction isolation level cannot be set after the first query
80+
or data-modification statement (<command>SELECT</command>,
81+
<command>INSERT</command>, <command>DELETE</command>,
82+
<command>UPDATE</command>, <command>FETCH</command>,
83+
<command>COPY</command>) of a transaction has been executed.
84+
</para>
85+
86+
<para>
87+
The transaction access mode determines whether the transaction is
88+
read/write or read-only. Read/write is the default. When a
89+
transaction is read-only, the following SQL commands are
90+
disallowed: <literal>INSERT</literal>, <literal>UPDATE</literal>,
91+
<literal>DELETE</literal>, and <literal>COPY TO</literal> if the
92+
table they would write to is not a temporary table; all
93+
<literal>CREATE</literal>, <literal>ALTER</literal>, and
94+
<literal>DROP</literal> commands; <literal>COMMENT</literal>,
95+
<literal>GRANT</literal>, <literal>REVOKE</literal>,
96+
<literal>TRUNCATE</literal>; and <literal>EXPLAIN ANALYZE</literal>
97+
and <literal>EXECUTE</literal> if the command they would execute is
98+
among those listed. This is a high-level notion of read-only that
99+
does not prevent writes to disk.
75100
</para>
76101
</refsect1>
77102

@@ -97,7 +122,7 @@ SET default_transaction_isolation = '<replaceable>value</replaceable>'
97122
<title>SQL92, SQL99</title>
98123

99124
<para>
100-
<option>SERIALIZABLE</option> is the default level in
125+
<option>SERIALIZABLE</option> is the defaulttransaction isolationlevel in
101126
<acronym>SQL</acronym>. <productname>PostgreSQL</productname> does
102127
not provide the isolation levels <option>READ UNCOMMITTED</option>
103128
and <option>REPEATABLE READ</option>. Because of multiversion
@@ -107,11 +132,10 @@ SET default_transaction_isolation = '<replaceable>value</replaceable>'
107132
</para>
108133

109134
<para>
110-
In <acronym>SQL</acronym> there are two other transaction
111-
characteristics that can be set with these commands: whether the
112-
transaction is read-only and the size of the diagnostics area.
113-
Neither of these concepts are supported in
114-
<productname>PostgreSQL</productname>.
135+
In <acronym>SQL</acronym> there is one other transaction
136+
characteristic that can be set with these commands: the size of
137+
the diagnostics area. This concept is not supported in
138+
<productname>PostgreSQL</productname>.
115139
</para>
116140
</refsect2>
117141
</refsect1>

‎doc/src/sgml/ref/start_transaction.sgml

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/start_transaction.sgml,v 1.3 2002/08/30 22:45:25 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/start_transaction.sgml,v 1.4 2003/01/10 22:03:27 petere Exp $
33
PostgreSQL documentation
44
-->
55

@@ -20,7 +20,7 @@ PostgreSQL documentation
2020

2121
<refsynopsisdiv>
2222
<synopsis>
23-
START TRANSACTION [ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ]
23+
START TRANSACTION [ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]
2424
</synopsis>
2525

2626
<refsect2 id="R2-SQL-START-TRANSACTION-1">
@@ -77,52 +77,23 @@ WARNING: BEGIN: already a transaction in progress
7777
<title>Description</title>
7878

7979
<para>
80-
This command begins a new transaction. If the isolation level is
81-
specified, the new transaction has that isolation level. In all other
82-
respects, the behavior of this command is identical to the
83-
<xref linkend="sql-begin" endterm="sql-begin-title"> command.
80+
This command begins a new transaction. If the isolation level or
81+
read/write mode is specified, the new transaction has those
82+
characteristics, as if <xref linkend="sql-set-transaction"
83+
endterm="sql-set-transaction-title"> was executed. In all other
84+
respects, the behavior of this command is identical to the <xref
85+
linkend="sql-begin" endterm="sql-begin-title"> command.
8486
</para>
8587

8688
</refsect1>
8789

88-
<refsect1>
89-
<title>Notes</title>
90-
91-
<para>
92-
The isolation level of a transaction can also be set with the <xref
93-
linkend="sql-set-transaction" endterm="sql-set-transaction-title">
94-
command. If no isolation level is specified, the default isolation
95-
level is used.
96-
</para>
97-
</refsect1>
98-
9990
<refsect1 id="R1-SQL-START-TRANSACTION-3">
10091
<title>Compatibility</title>
10192

102-
<refsect2 id="R2-SQL-START-TRANSACTION-4">
103-
<title>SQL99</title>
104-
105-
<para>
106-
<option>SERIALIZABLE</option> is the default isolation level in
107-
<acronym>SQL99</acronym>, but it is not the usual default in
108-
<productname>PostgreSQL</productname>: the factory default setting
109-
is READ COMMITTED.
110-
<productname>PostgreSQL</productname>
111-
does not provide the isolation levels <option>READ UNCOMMITTED</option>
112-
and <option>REPEATABLE READ</option>. Because of lack of predicate
113-
locking, the <option>SERIALIZABLE</option> level is
114-
not truly serializable. See the <citetitle>User's Guide</citetitle>
115-
for details.
116-
</para>
117-
118-
<para>
119-
In <acronym>SQL99</acronym> this statement can specify two other
120-
properties of the new transaction: whether the transaction is
121-
read-only and the size of the diagnostics area. Neither of these
122-
concepts are currently supported in
123-
<productname>PostgreSQL</productname>.
124-
</para>
125-
</refsect2>
93+
<para>
94+
SQL99; but see also the compatibility section of <xref
95+
linkend="sql-set-transaction" endterm="sql-set-transaction-title">.
96+
</para>
12697
</refsect1>
12798
</refentry>
12899

‎doc/src/sgml/release.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.176 2003/01/08 00:22:26tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.177 2003/01/1022:03:26petere Exp $
33
-->
44

55
<appendix id="release">
@@ -36,6 +36,7 @@ System can use either hash- or sort-based strategy for grouped aggregation
3636
ON COMMIT options for temp tables
3737
extra_float_digits option allows pg_dump to dump float data accurately
3838
Long options for psql and pg_dump are now available on all platforms
39+
Read-only transactions
3940
]]></literallayout>
4041

4142
</sect1>

‎src/backend/access/transam/xact.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.140 2002/11/2303:59:06 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.141 2003/01/10 22:03:27 petere Exp $
1212
*
1313
* NOTES
1414
*Transaction aborts can now occur two ways:
@@ -208,6 +208,9 @@ TransactionState CurrentTransactionState = &CurrentTransactionStateData;
208208
intDefaultXactIsoLevel=XACT_READ_COMMITTED;
209209
intXactIsoLevel;
210210

211+
boolDefaultXactReadOnly= false;
212+
boolXactReadOnly;
213+
211214
boolautocommit= true;
212215

213216
intCommitDelay=0;/* precommit delay in microseconds */
@@ -848,6 +851,7 @@ StartTransaction(void)
848851

849852
FreeXactSnapshot();
850853
XactIsoLevel=DefaultXactIsoLevel;
854+
XactReadOnly=DefaultXactReadOnly;
851855

852856
/*
853857
* Check the current transaction state. If the transaction system is

‎src/backend/catalog/namespace.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.43 2003/01/07 20:56:06 tgl Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.44 2003/01/10 22:03:27 petere Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -278,6 +278,30 @@ RelnameGetRelid(const char *relname)
278278
returnInvalidOid;
279279
}
280280

281+
/*
282+
* RelidGetNamespaceId
283+
*Given a relation OID, return the namespace OID.
284+
*/
285+
Oid
286+
RelidGetNamespaceId(Oidrelid)
287+
{
288+
HeapTupletuple;
289+
Form_pg_classpg_class_form;
290+
Oidresult;
291+
292+
tuple=SearchSysCache(RELOID,
293+
ObjectIdGetDatum(relid),
294+
0,0,0);
295+
if (!HeapTupleIsValid(tuple))
296+
elog(ERROR,"cache lookup failed for relation %u",relid);
297+
pg_class_form= (Form_pg_class)GETSTRUCT(tuple);
298+
299+
result=pg_class_form->relnamespace;
300+
ReleaseSysCache(tuple);
301+
returnresult;
302+
}
303+
304+
281305
/*
282306
* RelationIsVisible
283307
*Determine whether a relation (identified by OID) is visible in the

‎src/backend/commands/copy.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.187 2002/12/15 16:17:38 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.188 2003/01/10 22:03:27 petere Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -348,6 +348,10 @@ DoCopy(const CopyStmt *stmt)
348348
*/
349349
rel=heap_openrv(relation, (is_from ?RowExclusiveLock :AccessShareLock));
350350

351+
/* check read-only transaction */
352+
if (XactReadOnly&& !is_from&& !isTempNamespace(RelationGetNamespace(rel)))
353+
elog(ERROR,"transaction is read-only");
354+
351355
/* Check permissions. */
352356
aclresult=pg_class_aclcheck(RelationGetRelid(rel),GetUserId(),
353357
required_access);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp