90 likes | 103 Views
Learn about the fundamental aspects of disk and buffer management in Database Management Systems (DBMS), including disk storage, buffer management, page formats, and replacement policies.
E N D
Disks and Main Memory • DBMS stores information on (“hard”) disks. • This has major implications for DBMS design! • READ:transfer data from disk to main memory (RAM). • WRITE: transfer data from RAM to disk. • Both are high-cost operations, relative to in-memory operations, so must be planned carefully! • Why disks? • Cheaper than Main Memory • Higher Capacity • Main Memory is volatile • Typical storage hierarchy: • Main memory (RAM) for currently used data. • Disk for the main database (secondary storage). • Tapes for archiving older versions of the data (tertiary storage).
Disks • Secondary storage device of choice. • Data is stored and retrieved in units called disk blocks or pages. • Time to read/write data block: • 2- 20 msec for random data block (main factor is seek time) • If blocks are sequentially on disk, each additional block only 1 msec • Compare main memory access: in nanoseconds
Architecture Upper Layer Secondary Storage (stable) Cache/Buffer Manager Buffer (volatile)
Page Formats: Variable Length Records Rid = (i,N) • Record id (rid)= internal identifier of a record: <page id, slot #>. • Can move records on page without changing rid; Page i Rid = (i,2) Rid = (i,1) 20 16 N 24 Pointer to start of free space N . . . 2 1 # slots Record Length SLOT DIRECTORY
Buffer Management in a DBMS DB Page Requests from Higher Levels • Data must be in RAM for DBMS to operate on it! • Table of <frame#, pageid> pairs is maintained. • Some more information about each page in buffer is maintained BUFFER POOL disk page free frame MAIN MEMORY DISK choice of frame dictated by replacement policy
When a Page is Requested ... • If requested page is not in pool: • If there is an empty frame • Choose empty frame • Else (no empty frame) • Choose a frame for replacement • If frame is dirty (page was modified), write it to disk • Read requested page into chosen frame • Pin the new page and return its address.
More on Buffer Management • After operation has finished • Requestor unpins pages • Set dirty bit if page has been modified: • Page in pool may be requested many times: pin count • Page is requested: increase pin count • Unpin: decrease pin count • Frame is chosen for replacement by a replacement policy: • Only unpinned page can be chosen (pin count = 0) • Least-recently-used (LRU), Clock, MRU etc. • Pages are a common lock granularity for the lock manager
DBMS vs. OS File System OS does disk space & buffer mgmt: why not let OS manage these tasks? • Differences in OS support: portability issues • Some limitations, e.g., files can’t span disks. • Buffer management in DBMS requires ability to: • pin a page in buffer pool, force a page to disk (important for implementing CC & recovery), • adjust replacement policy, and pre-fetch pages based on access patterns in typical DB operations.