Virtual transactions
One bit that isn't really clear from the documentation is how the database internally handles assignment of transaction identification numbers called transaction ids or simply XIDs. And you can't easily decode the pg_locks
information without knowing some trivia here.
Every statement in PostgreSQL executes within a transaction, either explicit or implied. If you want a transaction to span multiple statements, you put it into a transaction block using the BEGIN
statement. Giving something an XID in PostgreSQL has some overhead. For example, each one of them is assigned its own space in the database commit logs, stored in the pg_clog
directory.
As that involves several types of work including an eventual disk write; this is somewhat expensive. And simple read-only statements like many SELECT
s don't really need a transaction ID anyway. Starting in PostgreSQL 8.3, an optimization was added to avoid this overhead when it's not needed, using what...