Slotted Page Structure: Stable Pointers on Disk

A slotted page organizes data by growing records from the end of the page and pointers from the beginning. This allows databases to handle variable-sized records without costly reshuffling, keeping pointers stable.
Why it exists
Storing records sequentially in a database page is simple but inefficient. When a record is deleted, it leaves a gap. To reclaim that space, all subsequent records must be shifted, which is a slow operation. More importantly, this reshuffling invalidates any pointers from indexes or other structures that were pointing to the moved data.
The mental model
Imagine a fixed-size block of memory, like a 4KB page, as a bookshelf. A slotted page layout puts the books (the actual data) on the shelf starting from the right side. A separate card catalog (the pointers, or 'slots') is kept on the left side. As you add books, you also add a card to the catalog. The empty space in the middle shrinks from both sides. This way, you can remove a book and its card without shifting all the other books.
How it works
A slotted page is divided into three main regions that grow toward each other. First, a fixed-size header at the beginning of the page stores metadata like the page ID and the boundaries of the free space. Second, an array of item pointers, or 'slots', grows from left to right after the header. Each slot stores the offset and size of a data cell. Third, the actual data cells (e.g., table rows) are placed at the end of the page, growing from right to left. The space between the end of the slot array and the start of the cell data is the contiguous free space.
When to use it
This structure is fundamental for database storage engines like PostgreSQL that need to manage variable-sized records within fixed-size pages. It allows for efficient insertions, updates, and deletions because data doesn't need to be constantly repacked. This provides pointer stability, which is critical for indexes that refer to records by their page and slot number.
When not to use it
If all records are a fixed, known size, a simpler array-based layout can be more efficient, as a record's location can be calculated directly from its index without the indirection of a pointer array. It also adds slight overhead for the pointers, which may be unnecessary for simple, append-only data where records are never updated or deleted in place.
One canonical example
A PostgreSQL table page uses a slotted page structure. When you insert a new row, PostgreSQL finds a page with enough free space. It writes the row data into the page from the end and adds an item pointer to the slot array near the beginning. An index on that table stores a reference to the page and the slot number, not a direct byte offset. This allows the database to perform maintenance like compaction within the page without breaking the index pointers.
Interview question
What is the key mechanism enabling stable pointers to records in a slotted page structure?
- a.Free space is immediately compacted after deletions, shifting records to maintain contiguity.
- b.An array of item pointers (slots) provides an unchanging reference number, each storing the current data offset.Correct
- c.Each record is assigned a unique, immutable identifier that indexes directly reference.
- d.Records are stored in fixed-size blocks, preventing any movement within the page.
Why? this is the answer
The slotted page structure uses an array of item pointers (slots) where external indexes refer to records by their stable slot number. If a record's physical location within the page changes, only the offset stored within that slot needs updating, not the slot number itself. Option A describes the inefficient behavior that slotted pages are designed to avoid, as shifting records would invalidate direct pointers.
Just read this? Test yourself on what you have been reading.
Read the original → siemens.blog
- #databases
- #storage engines
- #data structures
- #page layout
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on databases — each one lists the topics its interview covers.
See open roles