2 67.1. Transactions and Identifiers #
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.
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.
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.
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.
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
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.