Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

begin(7) [redhat man page]

BEGIN(7)							   SQL Commands 							  BEGIN(7)

NAME
BEGIN - start a transaction block SYNOPSIS
BEGIN [ WORK | TRANSACTION ] INPUTS WORK TRANSACTION Optional keywords. They have no effect. OUTPUTS BEGIN This signifies that a new transaction has been started. WARNING: BEGIN: already a transaction in progress This indicates that a transaction was already in progress. The current transaction is not affected. DESCRIPTION
By default, PostgreSQL executes transactions in unchained mode (also known as ``autocommit'' in other database systems). In other words, each user statement is executed in its own transaction and a commit is implicitly performed at the end of the statement (if execution was successful, otherwise a rollback is done). BEGIN initiates a user transaction in chained mode, i.e., all user statements after BEGIN com- mand will be executed in a single transaction until an explicit COMMIT [commit(7)] or ROLLBACK [rollback(7)]. Statements are executed more quickly in chained mode, because transaction start/commit requires significant CPU and disk activity. Execution of multiple statements inside a transaction is also useful to ensure consistency when changing several related tables: other clients will be unable to see the intermediate states wherein not all the related updates have been done. The default transaction isolation level in PostgreSQL is READ COMMITTED, wherein each query inside the transaction sees changes committed before that query begins execution. So, you have to use SET TRANSACTION ISOLATION LEVEL SERIALIZABLE just after BEGIN if you need more rig- orous transaction isolation. (Alternatively, you can change the default transaction isolation level; see the PostgreSQL Administrator's Guide for details.) In SERIALIZABLE mode queries will see only changes committed before the entire transaction began (actually, before execution of the first DML statement in the transaction). Transactions have the standard ACID (atomic, consistent, isolatable, and durable) properties. NOTES START TRANSACTION [start_transaction(7)] has the same functionality as BEGIN. Use COMMIT [commit(7)] or ROLLBACK [rollback(7)] to terminate a transaction. Refer to LOCK [lock(7)] for further information about locking tables inside a transaction. If you turn autocommit mode off, then BEGIN is not required: any SQL command automatically starts a transaction. USAGE
To begin a user transaction: BEGIN WORK; COMPATIBILITY
SQL92 BEGIN is a PostgreSQL language extension. There is no explicit BEGIN command in SQL92; transaction initiation is always implicit and it terminates either with a COMMIT or ROLLBACK statement. Note: Many relational database systems offer an autocommit feature as a convenience. Incidentally, the BEGIN keyword is used for a different purpose in embedded SQL. You are advised to be careful about the transaction seman- tics when porting database applications. SQL92 also requires SERIALIZABLE to be the default transaction isolation level. SQL - Language Statements 2002-11-22 BEGIN(7)

Check Out this Related Man Page

SET 
TRANSACTION(7) SQL Commands SET TRANSACTION(7) NAME
SET TRANSACTION - set the characteristics of the current transaction SYNOPSIS
SET TRANSACTION ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } DESCRIPTION
This command sets the transaction isolation level. The SET TRANSACTION command sets the characteristics for the current SQL-transaction. It has no effect on any subsequent transactions. This command cannot be used after the first query or data-modification statement (SELECT, INSERT, DELETE, UPDATE, FETCH, COPY) of a transaction has been executed. SET SESSION CHARACTERISTICS sets the default transaction isolation level for each transaction for a session. SET TRANSACTION can override it for an individual transaction. The isolation level of a transaction determines what data the transaction can see when other transactions are running concurrently. READ COMMITTED A statement can only see rows committed before it began. This is the default. SERIALIZABLE The current transaction can only see rows committed before first query or data-modification statement was executed in this transac- tion. Tip: Intuitively, serializable means that two concurrent transactions will leave the database in the same state as if the two has been executed strictly after one another in either order. NOTES
The session default transaction isolation level can also be set with the command SET default_transaction_isolation = 'value' and in the configuration file. Consult the Administrator's Guide for more information. COMPATIBILITY
SQL92, SQL99 SERIALIZABLE is the default level in SQL. PostgreSQL does not provide the isolation levels READ UNCOMMITTED and REPEATABLE READ. Because of multiversion concurrency control, the SERIALIZABLE level is not truly serializable. See the User's Guide for details. In SQL there are two other transaction characteristics that can be set with these commands: whether the transaction is read-only and the size of the diagnostics area. Neither of these concepts are supported in PostgreSQL. SQL - Language Statements 2000-11-24 SET TRANSACTION(7)
Man Page