Module 03

Physical storage: pages, areas and db-keys

In most databases you never think about where a row physically sits. Here you have to. The storage layout is part of the design, it is visible to programmers, and it decides both how fast things run and — uncomfortably often — whether your copy of the data still matches next month.

~50 min2 simulators10-question checkpoint
What this module is really about

The warehouse itself: numbered shelves, numbered slots, and the address that identifies each card.

One thing here matters more than everything else. A record’s address is physical and temporary. It is very fast to use, and it changes every time storage is tidied up. Build anything permanent on it — a key in your target database, for instance — and the day someone reorganises the storage your copy silently stops matching. No error is raised anywhere. You find out from a row count.

New words on this page, one line each
page
A fixed-size block of storage, usually about 4 KB. One shelf. Reading one page is one disk operation.
line
A numbered slot on that shelf, where one record sits.
db-key
A record’s address: page number plus slot number. “Shelf 71003, slot 1”.
area
A named range of pages. What gets locked, backed up and restored as a unit.
radix
How the address splits between page number and slot number. Sets the maximum records per page.
page group
A numbering namespace. Page numbers are unique only inside one group, which is why relationships cannot cross groups.
CALC
A storage rule: run the key through a formula to decide which page the record belongs on.
VIA
A storage rule: put this record physically next to its parent.
synonym chain
What happens when the calculated page is already full — the record goes elsewhere and is linked back, costing an extra read.
fragmentation
Records that outgrew their space and had to be split, costing an extra read every time they are used.
reorganisation
Unloading and reloading storage to tidy it up. Renumbers every address.

From whole database down to a single slot

Picture it

The warehouse (the database) contains rooms (areas). Rooms contain numbered shelves (pages). Shelves contain numbered slots (lines). Slots contain index cards (records).

The room is the level worth remembering: it is what gets locked, backed up and restored in one piece. When someone tells you “we can take that area offline for twenty minutes on Sunday”, they are telling you the size of the window you have to take a consistent copy.

LevelWhat it isDefined in
Database (DBNAME)A named collection of segments that a run unit can address as one thing.DBTABLE
SegmentA named group of areas and the files behind them. The unit of physical administration.DMCL
AreaA contiguous range of pages holding one or more record types. The unit of READY, locking, backup and recovery.Schema (logical) + DMCL (physical)
FileThe actual z/OS dataset. An area maps to one or more files; a file can hold several areas.DMCL
PageThe unit of I/O and of buffering. Typically 4 KB, but sized per area.DMCL
LineA slot within a page. A record occurrence's address is (page, line).Runtime
Areas are the recovery unit READY operates on areas. Locks escalate to areas. Image copies are taken of areas. When operations tells you "we can quiesce the ORG area but not the EMP area during the cutover window", they are telling you something that directly constrains how you take a consistent initial extract.

What one shelf looks like inside

The one detail worth carrying

Records grow inwards from one end of the shelf. A small directory of slot positions grows inwards from the other end. They meet when the shelf is full.

That directory is why an address stays valid. It names a slot, not a byte position, so the database can shuffle records around inside a shelf during housekeeping without invalidating a single stored address.

An IDMS page is a slotted page, the same family of design as a Db2 or PostgreSQL page, with some specifically IDMS features.

Pageheader page number next avail line space left page group line 1 · EMPLOYEE prefix: set db-keys data: PIC fields record id 415 line 2 · EMPOSITION prefix: 3 db-keys data: packed salary stored VIA the set free space (page reserve keeps some of this back for records that grow after they are stored) Lineindex slot → offset grows ← indirection keeps db-keys stable inside the page Foot page no. repeated catches a partial or torn write Records grow inwards from the left; the line index grows inwards from the right. They meet when the page is full.
The line index is the key idea: a db-key names a slot, not a byte offset. IDMS can shuffle records inside a page during maintenance without invalidating a single stored pointer.

Some structural points that matter later:

  • Space management pages (SMPs) are interspersed through an area at a fixed interval, recording how much free space each nearby page has. A STORE that finds its target page full consults the SMP to choose an overflow page instead of blindly probing.
  • Page reserve holds back a declared number of bytes per page so that records which grow (variable-length, compressed, or with an OCCURS DEPENDING ON) can expand in place instead of being relocated.
  • System record types (SRn) occupy lines like user records. The two you will meet by name are SR7, the owner record of an index, and SR8, an index block holding sorted key entries and pointers. Others handle internal bookkeeping.
  • The page footer repeats the page number. If header and footer disagree, the page was written partially and the DBMS knows the page is broken rather than silently serving corrupt pointers.

The address of a record

In plain English

An address is one number packing two things: which shelf, and which slot. Splitting it back apart is division and remainder, nothing cleverer.

The setting that decides where the split falls is fixed when the database is built, and it is baked into every stored address. Changing it means rewriting the entire storage area.

A db-key is a 32-bit value that concatenates a page number and a line index. The split point is the db-key radix, declared per segment in the DMCL as the number of low-order bits reserved for the line number.

db-key arithmetic
db-key   = (page number × 2^radix) + line number

radix 8  → 255 lines per page max, ~16.7 million pages addressable
radix 4  →  15 lines per page max, ~268 million pages addressable
radix 3  →   7 lines per page max, ~536 million pages addressable

page     = db-key ÷ 2^radix      (integer division)
line     = db-key MOD 2^radix

The radix is a real design trade-off. Small pages full of small records want a high radix; very large databases with few records per page want a low one so that the page-number field can address more pages. And it is embedded in every stored pointer, so changing it means unloading and reloading the area.

Why page numbers are not unique, and what that stops you doing

Why you should care

An address is just a number. Nothing inside it says which numbering scheme it belongs to.

Two consequences. A relationship cannot span two numbering schemes, because there would be no way to tell which shelf 71003 was meant. And if you ever store one of these addresses in your target database, the address alone does not identify the record — you must record which segment it came from as well.

Every area belongs to a page group. Page numbers are unique within a page group, not globally. This lets one database contain areas whose page ranges overlap numerically, which is how very large databases get built.

The rule A set cannot span page groups, because a db-key pointer carries no page-group identifier — it is just a number, and it means "page 71003 in my page group". Owner and member of a set must therefore live in areas of the same page group with the same radix. When you see a schema that looks oddly duplicated, or a set that "should" exist and does not, page groups are frequently the reason.

The same rule tells you something important for replication: a db-key on its own does not identify a record in the database. It identifies a record within a page group. Any surrogate key built on db-keys must therefore include the page group, or the segment, or both.

Deciding which shelf a record goes on

CALC

Picture it

You want to file a card and find it again in one trip. So you agree a rule: run the customer number through a formula, and the answer is the shelf number. No catalogue to look in, no index to maintain — just arithmetic.

It works beautifully until the shelf is full. Then the card goes on a nearby shelf and a note is left behind pointing at it. Every such hop costs one extra trip, and as the room fills the hops multiply. That is why lookups get slower over time with no change to the application at all.

The DBMS hashes ("randomises") the declared CALC key to a target page within the area, then stores the record on that page if there is room. This gives single-I/O access by key with no index to maintain.

CALC declaration
LOCATION MODE IS CALC USING ( EMP-ID-0415 )
    DUPLICATES ARE NOT ALLOWED
WITHIN EMP-DEMO-REGION AREA.
  • DUPLICATES ARE NOT ALLOWED — the DBMS enforces uniqueness. This is a real constraint and a real natural key.
  • DUPLICATES ARE FIRST / LAST — duplicates permitted, chained off the same target page, new arrivals placed at the head or tail of the synonym chain.

When the target page is full, the record goes to a nearby page and is linked into a synonym chain rooted on the target page. Retrieval then costs one I/O for the target page plus one per hop. An area whose synonym chains have grown long is the classic "the database got slow and nothing changed" situation — nothing changed except that it filled up.

VIA

If you know clustered indexes

Same idea, and it is the highest-leverage decision in the entire design. Put the children physically next to the parent and reading all of a parent’s children touches perhaps three shelves. Scatter them and the same operation touches thirty. The relationship is identical either way — only the placement differs.

LOCATION MODE IS VIA <set> SET stores the record as physically close as possible to the owner occurrence it will be connected to in that set. If the owner's page has room, the member lands on the same page.

VIA declaration, with an optional displacement
LOCATION MODE IS VIA EMP-EMPOSITION SET
WITHIN EMP-DEMO-REGION AREA.

*> a displacement pushes members a fixed distance from the owner,
*> used to stop a hot owner page becoming a contention point
LOCATION MODE IS VIA EMP-COVERAGE SET
    DISPLACEMENT IS 4 PAGES
WITHIN INS-DEMO-REGION AREA.

VIA is the highest-leverage physical decision in an IDMS database. Walking a 30-member set whose members are clustered VIA costs perhaps three page reads. Walking the same set with members scattered by CALC costs thirty. The set definition is identical; only the placement differs.

DIRECT

The program supplies a suggested db-key and IDMS stores the record at or near it. Legitimate uses are narrow — loading a database in a controlled physical order, or record types whose access is always by saved db-key. It hands physical placement to application code, which means the application now owns a responsibility that normally belongs to the DBA.

What happens when a record outgrows its space

Why records are split rather than moved

Dozens of other records may be storing this record’s address. If it moved, every one of them would be wrong.

So instead the record stays where it is and the overflow goes elsewhere, linked back. The address keeps working; reading it just costs an extra trip from now on. Storage slowly fills up with these, which is exactly what a reorganisation cleans up — and why a reorganisation changes every address.

A record that grows beyond the space available on its page cannot simply move — dozens of pointers in other records address it by db-key. IDMS handles this by keeping the record's root at the original db-key and storing the overflow as a fragment elsewhere, linked from the root.

The consequences:

  • The db-key of a record is stable for the life of the record in that physical layout.
  • A fragmented record costs an extra I/O every time it is read.
  • Areas accumulate fragmentation over time; that is what an unload/reload fixes.
  • An unload/reload assigns new db-keys. Everything is renumbered.
Never use a raw db-key as a durable business key It is stable enough to save inside a run unit, and to store in an application record deliberately as a "direct pointer" — plenty of IDMS applications do exactly that. It is not stable across an unload/reload, an area expansion, a page-group change or a radix change. If your target model keys on db-keys, every reorganisation of the source silently orphans the entire target and you will find out from a reconciliation count, not from an error.

When and why a reorganisation happens

SymptomUnderlying causeRemedy
CALC retrieval I/O count climbingLong synonym chains — the area is too full or the key distribution is skewedExpand the area, reload, possibly change the key
Set traversal touching one page per memberVIA clustering has decayed as members were added after their owner's page filledUnload/reload restores clustering
Extra I/O on specific recordsRecord fragmentation after growthIncrease page reserve, reload
Index blocks splitting frequentlyIndex block size too small for the key volumeRedefine the index with a larger block, rebuild
Area approaching its page rangeGrowthArea expansion — which changes page ranges, hence db-keys

The utility that tells you which of these you have is IDMSDBAN, the database analysis utility: it walks the physical structures and reports chain lengths, fragmentation, space utilisation and broken pointers. When a DBA says "DBAN says the EMP area is 94% full with an average synonym chain of 3.2", that sentence now means something to you.

Worked example — reading a physical design

schema extract plus DMCL extract for the same area
*> ---- schema (logical) ----
RECORD NAME IS EMPLOYEE
    LOCATION MODE IS CALC USING ( EMP-ID-0415 ) DUPLICATES ARE NOT ALLOWED
    WITHIN EMP-DEMO-REGION AREA.

RECORD NAME IS EMPOSITION
    LOCATION MODE IS VIA EMP-EMPOSITION SET
    WITHIN EMP-DEMO-REGION AREA.

*> ---- DMCL (physical) ----
SEGMENT NAME IS EMPDEMO
    PAGE GROUP IS 0
    MAXIMUM RECORDS PER PAGE IS 255.

AREA NAME IS EMP-DEMO-REGION
    PRIMARY SPACE MANAGEMENT INTERVAL IS 32
    PAGE RESERVE IS 200 CHARACTERS.

FILE NAME IS EMPFILE
    ASSIGN TO EMPFILE
    PAGE SIZE IS 4276 CHARACTERS
    PAGE RANGE IS 71001 THRU 71100.

Read that as an engineer and you can already state, without touching the data:

  1. Employees are reachable in one I/O by employee number, and employee number is unique.
  2. Positions live on or near their employee's page, so "all positions for this employee" is cheap.
  3. The area is 100 pages of 4276 bytes — about 428 KB, which tells you this is a demonstration database, not production.
  4. 200 bytes per page are reserved for growth, so usable space is nearer 4076.
  5. Radix is 8 (255 records per page), so db-keys are page × 256 + line.
  6. A space management page appears every 32 pages.
  7. Everything is in page group 0, so sets may freely span the areas of this segment.

What this means for replication

  • Db-keys are physical, not logical. Use them as a within-run correlation handle if you must, never as the target primary key, unless you have a written procedure that triggers a full refresh after every reorganisation.
  • A db-key is only unique within its page group. Any surrogate you derive must be qualified by segment or page group.
  • Area boundaries are your consistency boundaries. An initial extract that spans two areas quiesced at different times is not a consistent snapshot; you need either a single quiesce window or a journal position to reconcile to.
  • Reorganisations are replication events. Ask to be told about them in advance and put them on the change calendar. A reload can rewrite every page in an area, which — depending on how the capture works — either floods the change stream or bypasses it entirely. Both need a plan.
  • Fragmented records may be journalled in pieces. Know whether your capture reassembles the root and its fragments, or whether you will receive partial images.
Exercise 3.1 — Db-key forensics

Using the decoder above, with radix 8:

  1. What page and line is db-key 18176769? Which area of the sample database is that in?
  2. An area has page range 90001–90500 and radix 4. What is the largest db-key it can produce, and how many records can it hold at most?
  3. A downstream table stores db-keys as DECIMAL(10,0). The source DBA raises the radix from 4 to 8 during a reorg. What happens to those stored values, and what will the reconciliation report look like?

Answers: (1) page 71003, line 1 — EMP-DEMO-REGION, and it is the first EMPLOYEE occurrence. (2) 90500 × 16 + 15 = 1,448,015; at most 500 × 15 = 7,500 records. (3) Every value is now wrong by a factor of roughly 16, no lookup matches, and the reconciliation shows 100% of target rows unmatched with no error having been raised anywhere — which is exactly why this rule exists.

Checkpoint