Copyright | (c) Eitan Chatav 2017 |
---|---|
Maintainer | eitan@morphism.tech |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Squeal transaction control language.
- transactionally :: (MonadBaseControl IO tx, MonadPQ schema tx) => TransactionMode -> tx x -> tx x
- transactionally_ :: (MonadBaseControl IO tx, MonadPQ schema tx) => tx x -> tx x
- begin :: MonadPQ schema tx => TransactionMode -> tx (K Result NilRelation)
- commit :: MonadPQ schema tx => tx (K Result NilRelation)
- rollback :: MonadPQ schema tx => tx (K Result NilRelation)
- transactionallySchema :: MonadBaseControl IO io => TransactionMode -> PQ schema0 schema1 io x -> PQ schema0 schema1 io x
- transactionallySchema_ :: MonadBaseControl IO io => PQ schema0 schema1 io x -> PQ schema0 schema1 io x
- data TransactionMode = TransactionMode {}
- defaultMode :: TransactionMode
- longRunningMode :: TransactionMode
- data IsolationLevel
- renderIsolationLevel :: IsolationLevel -> ByteString
- data AccessMode
- renderAccessMode :: AccessMode -> ByteString
- data DeferrableMode
- renderDeferrableMode :: DeferrableMode -> ByteString
Transaction
:: (MonadBaseControl IO tx, MonadPQ schema tx) | |
=> TransactionMode | |
-> tx x | run inside a transaction |
-> tx x |
Run a schema invariant computation transactionally
.
:: (MonadBaseControl IO tx, MonadPQ schema tx) | |
=> tx x | run inside a transaction |
-> tx x |
Run a schema invariant computation transactionally_
in defaultMode
.
begin :: MonadPQ schema tx => TransactionMode -> tx (K Result NilRelation) Source #
BEGIN
a transaction.
commit :: MonadPQ schema tx => tx (K Result NilRelation) Source #
COMMIT
a schema invariant transaction.
rollback :: MonadPQ schema tx => tx (K Result NilRelation) Source #
ROLLBACK
a schema invariant transaction.
transactionallySchema :: MonadBaseControl IO io => TransactionMode -> PQ schema0 schema1 io x -> PQ schema0 schema1 io x Source #
Run a schema changing computation transactionallySchema
.
transactionallySchema_ :: MonadBaseControl IO io => PQ schema0 schema1 io x -> PQ schema0 schema1 io x Source #
Run a schema changing computation transactionallySchema_
in DefaultMode
.
Transaction Mode
data TransactionMode Source #
The available transaction characteristics are the transaction IsolationLevel
,
the transaction AccessMode
(ReadWrite
or ReadOnly
), and the DeferrableMode
.
longRunningMode :: TransactionMode Source #
TransactionMode
with a Serializable
IsolationLevel
,
ReadOnly
AccessMode
and Deferrable
DeferrableMode
.
This mode is well suited for long-running reports or backups.
data IsolationLevel Source #
The SQL standard defines four levels of transaction isolation.
The most strict is Serializable
, which is defined by the standard in a paragraph
which says that any concurrent execution of a set of Serializable
transactions is
guaranteed to produce the same effect as running them one at a time in some order.
The other three levels are defined in terms of phenomena, resulting from interaction
between concurrent transactions, which must not occur at each level.
The phenomena which are prohibited at various levels are:
Dirty read: A transaction reads data written by a concurrent uncommitted transaction.
Nonrepeatable read: A transaction re-reads data it has previously read and finds that data has been modified by another transaction (that committed since the initial read).
Phantom read: A transaction re-executes a query returning a set of rows that satisfy a search condition and finds that the set of rows satisfying the condition has changed due to another recently-committed transaction.
Serialization anomaly: The result of successfully committing a group of transactions is inconsistent with all possible orderings of running those transactions one at a time.
In PostgreSQL, you can request any of the four standard transaction
isolation levels, but internally only three distinct isolation levels are implemented,
i.e. PostgreSQL's ReadUncommitted
mode behaves like ReadCommitted
.
This is because it is the only sensible way to map the standard isolation levels to
PostgreSQL's multiversion concurrency control architecture.
Serializable | Dirty read is not possible. Nonrepeatable read is not possible. Phantom read is not possible. Serialization anomaly is not possible. |
RepeatableRead | Dirty read is not possible. Nonrepeatable read is not possible. Phantom read is not possible. Serialization anomaly is possible. |
ReadCommitted | Dirty read is not possible. Nonrepeatable read is possible. Phantom read is possible. Serialization anomaly is possible. |
ReadUncommitted | Dirty read is not possible. Nonrepeatable read is possible. Phantom read is possible. Serialization anomaly is possible. |
renderIsolationLevel :: IsolationLevel -> ByteString Source #
Render an IsolationLevel
.
data AccessMode Source #
The transaction access mode determines whether the transaction is ReadWrite
or ReadOnly
.
ReadWrite
is the default. When a transaction is ReadOnly
,
the following SQL commands are disallowed:
INSERT
, UPDATE
, DELETE
, and COPY FROM
if the table they would write to is not a temporary table;
all CREATE
, ALTER
, and DROP
commands;
COMMENT
, GRANT
, REVOKE
, TRUNCATE
;
and EXPLAIN ANALYZE
and EXECUTE
if the command they would execute is among those listed.
This is a high-level notion of ReadOnly
that does not prevent all writes to disk.
renderAccessMode :: AccessMode -> ByteString Source #
Render an AccessMode
.
data DeferrableMode Source #
The Deferrable
transaction property has no effect
unless the transaction is also Serializable
and ReadOnly
.
When all three of these properties are selected for a transaction,
the transaction may block when first acquiring its snapshot,
after which it is able to run without the normal overhead of a
Serializable
transaction and without any risk of contributing
to or being canceled by a serialization failure.
This longRunningMode
is well suited for long-running reports or backups.
renderDeferrableMode :: DeferrableMode -> ByteString Source #
Render a DeferrableMode
.