BEGIN(7)
๐ BEGIN(7) โ bestie edition ๐
PostgreSQL 18.6 Documentation ๐ฆ no cap, this is the manual page for BEGIN in section 7 and we're gonna make it make sense fr fr
โจ NAME โจ
BEGIN โ start a transaction block ๐
๐ธ SYNOPSIS ๐ธ
BEGIN [ WORK | TRANSACTION ] [ transaction_mode [, ...] ]
where transaction_mode is one of:
ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
READ WRITE | READ ONLY
[ NOT ] DEFERRABLE
like. that's the whole vibe check right there. ๐
๐ DESCRIPTION ๐
okay so BEGIN initiates a transaction block. translation: every single statement after your BEGIN runs inside one single transaction until you explicitly hand it a COMMIT or a ROLLBACK. that's it. that's the whole thing. ๐
by default โ meaning without BEGIN โ PostgreSQL runs transactions in "autocommit" mode. which is exactly what it sounds like: each statement gets its own lil baby transaction, and a commit is implicitly performed at the end of the statement. if execution was successful, you get the commit. otherwise? rollback. sorry bestie ๐ญ
statements execute more quickly inside a transaction block, because transaction start/commit eats up significant CPU and disk activity. so batching = less overhead = slay. ๐ฅ
running multiple statements inside a transaction is also useful for keeping things consistent when you're making several related changes. because here's the tea: other sessions will not be able to see the intermediate states where not all the related updates have been done yet. no half-finished glow-ups visible to anybody. iconic. โจ
and if you specify the isolation level, read/write mode, or deferrable mode, the new transaction has those characteristics โ exactly as if SET TRANSACTION had been executed. same energy, different spelling. ๐ซ
๐ PARAMETERS ๐
WORKโ optional key word. it does absolutely nothing. zero effect. purely decorative. a little accessory. ๐TRANSACTIONโ optional key word. also has no effect. twins!! ๐ซถ
for the meaning of the other parameters to this statement, go read SET TRANSACTION (SET_TRANSACTION(7)). it's giving homework but it's important, iykyk. ๐
๐ฆ NOTES ๐ฆ
START TRANSACTIONhas the same functionality asBEGIN. same girl, different outfit. ๐- use
COMMITorROLLBACKto terminate a transaction block. you gotta close the loop, bestie. ๐ - issuing
BEGINwhen you're already inside a transaction block will provoke a warning message. the state of the transaction is not affected โ it just yells at you a lil bit. if you actually want to nest transactions within a transaction block, use savepoints (seeSAVEPOINT(7)). ๐ - for reasons of backwards compatibility, the commas between successive *
transaction_mode*s can be omitted. the commas are optional, not mandatory. she's flexible. ๐ซ
โญ EXAMPLES โญ
to begin a transaction block:
BEGIN;
that's it. one line. main character energy. โจ
๐ COMPATIBILITY ๐
BEGIN is a PostgreSQL language extension. it's equivalent to the SQL-standard command START TRANSACTION, whose reference page contains additional compatibility information. so if you're wondering "is this standard" โ no, but she's equivalent to the one who is. ๐
the DEFERRABLE transaction_mode is also a PostgreSQL language extension. another extension. we stay extending. ๐
incidentally โ and this is the plot twist โ the BEGIN key word is used for a different purpose in embedded SQL. you are advised to be careful about the transaction semantics when porting database applications. like, genuinely careful. do not skip this. ๐จ
๐ SEE ALSO ๐
COMMIT(7), ROLLBACK(7), START TRANSACTION (START_TRANSACTION(7)), SAVEPOINT(7) ๐
bestie if you only remember one thing:BEGINopens,COMMITorROLLBACKcloses, and the optional words are just โจvibesโจ. that's the whole page. you ate. ๐
PostgreSQL 18.6 ยท 2026 โ ok that's the whole page, mwah, go start a transaction responsibly ๐ง๐
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms