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 TRANSACTION has the same functionality as BEGIN. same girl, different outfit. ๐Ÿ‘‘
  • use COMMIT or ROLLBACK to terminate a transaction block. you gotta close the loop, bestie. ๐Ÿ”
  • issuing BEGIN when 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 (see SAVEPOINT(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: BEGIN opens, COMMIT or ROLLBACK closes, 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 ๐Ÿงš๐Ÿ’œ