```{index} single: begin (Peta::LMDB::Env) ``` ```{index} single: Peta::LMDB::Env::begin ``` # begin Start a transaction: `$env->begin` for a write transaction, `$env->begin(MDB_RDONLY)` for a read one. ## Synopsis ```perl my $txn = $env->begin; my $r = $env->begin(MDB_RDONLY); ``` ## What you get back A `Peta::LMDB::Txn`. A read transaction sees the data as it was when it began, however long it lives, and never waits. A write transaction waits while another one - in this process or another - is live, as there is one writer at a time. ## Edge cases - A transaction that goes out of scope without `commit` is aborted: its writes are discarded. - A long-lived read transaction keeps the pages it sees from being reused, so the file grows while writers work; end read transactions (or `reset` them) when done. ## See also - `Peta::LMDB::Txn` - what a transaction does - `stat` - the size of the unnamed database