6.2. Visibility Map
Vacuum processing is costly. Therefore, PostgreSQL introduced the Visibility Map (VM) in version 8.4 to reduce this cost.
The basic concept of the VM is simple:
- Each table has an individual visibility map that stores the visibility of each page.
- This visibility determines whether a page contains dead tuples.
- Vacuum processing skips pages without dead tuples by referring to the VM.
Figure 6.4 shows how the VM is used.
Figure 6.4. How the VM is used.
Suppose a table consists of three pages. If the 0th and 2nd pages contain dead tuples but the 1st page does not, the VM records this status. Vacuum processing then skips the 1st page by referring to the VM.
Each VM consists of one or more 8 KB pages, and the file is stored with the ‘vm’ suffix. For example, a table file with relfilenode 18751 is shown below alongside its FSM (18751_fsm) and VM (18751_vm) files.
$ cd $PGDATA
$ ls -la base/16384/18751*
-rw------- 1 postgres postgres 8192 Apr 21 10:21 base/16384/18751
-rw------- 1 postgres postgres 24576 Apr 21 10:18 base/16384/18751_fsm
-rw------- 1 postgres postgres 8192 Apr 21 10:18 base/16384/18751_vm6.2.1. Enhancement of VM
PostgreSQL enhanced the VM in version 9.6 to improve freeze processing efficiency. The enhanced VM tracks both page visibility and whether all tuples in a page are frozen (refer to Section 6.3.3 for details).