]> begriffs open source - ai-pg/blob - full-docs/txt/transaction-id.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / transaction-id.txt
1
2 67.1. Transactions and Identifiers #
3
4    Transactions can be created explicitly using BEGIN or START TRANSACTION
5    and ended using COMMIT or ROLLBACK. SQL statements outside of explicit
6    transactions automatically use single-statement transactions.
7
8    Every transaction is identified by a unique VirtualTransactionId (also
9    called virtualXID or vxid), which is comprised of a backend's process
10    number (or procNumber) and a sequentially-assigned number local to each
11    backend, known as localXID. For example, the virtual transaction ID
12    4/12532 has a procNumber of 4 and a localXID of 12532.
13
14    Non-virtual TransactionIds (or xid), e.g., 278394, are assigned
15    sequentially to transactions from a global counter used by all
16    databases within the PostgreSQL cluster. This assignment happens when a
17    transaction first writes to the database. This means lower-numbered
18    xids started writing before higher-numbered xids. Note that the order
19    in which transactions perform their first database write might be
20    different from the order in which the transactions started,
21    particularly if the transaction started with statements that only
22    performed database reads.
23
24    The internal transaction ID type xid is 32 bits wide and wraps around
25    every 4 billion transactions. A 32-bit epoch is incremented during each
26    wraparound. There is also a 64-bit type xid8 which includes this epoch
27    and therefore does not wrap around during the life of an installation;
28    it can be converted to xid by casting. The functions in Table 9.84
29    return xid8 values. Xids are used as the basis for PostgreSQL's MVCC
30    concurrency mechanism and streaming replication.
31
32    When a top-level transaction with a (non-virtual) xid commits, it is
33    marked as committed in the pg_xact directory. Additional information is
34    recorded in the pg_commit_ts directory if track_commit_timestamp is
35    enabled.
36
37    In addition to vxid and xid, prepared transactions are also assigned
38    Global Transaction Identifiers (GID). GIDs are string literals up to
39    200 bytes long, which must be unique amongst other currently prepared
40    transactions. The mapping of GID to xid is shown in pg_prepared_xacts.