---image: "Math and Computation/Databases/Postgres/assets/chap_6_resources.png"
publish: true
description: "The Hunger of Resources: Understanding what the Lazy Elephant physically consumes to stay alive while avoiding work."
---
![[chap_6_resources.png]]
# Chapter 6: The Hunger of Resources
Being intensely lazy does not mean the elephant doesn't need to eat. Before it can perform the magnificent operations we ask of it—or effectively run around crossing things out with a Sharpie—Postgres has physical needs.
It consumes resources to stay alive, and it fiercely prioritizes the path of least physical exertion.
If we look at the hierarchy of the elephant's desires, its greatest love is **[[Memory]]**.
Memory is like snacks piled right on the elephant's desk. Grabbing a tuple out of `shared_buffers` happens instantly. It requires zero effort. The elephant will hoard as much memory as it can afford, fiercely battling to keep everything on the desk so it never has to get out of its chair.
However, if you force the elephant to remember more than its desk can hold, it becomes deeply miserable.
It has to push back its chair, groan softly, and engage in **[[Disk IO]]**.
Disk IO is walking across the brutal, freezing expanse of the office to the physical filing cabinet. It is spinning rust. Reading a sequential stream of contiguous pages isn't terrible, but `Random Page Costs`—bouncing from filing cabinet to filing cabinet searching for specific tuples—is the very definition of exhausting labor. The elephant builds `Indexes`, `CTEs`, and `Materialized Views` precisely to protect itself from ever doing Disk IO.
To think, it burns **[[CPU]]**. The CPU is where the lazy general calculates query plans, evaluates WHERE clauses, and hashes large piles of data into smaller buckets for joining.
And finally, to communicate back to the outside world, it relies on the **[[Network]]**. No matter how brilliantly optimized a `SeqScan` is, if the elephant has to physically shout ten million rows through a tiny soda straw connecting your database client to the server, everyone is going to have a terrible, very slow time.
When the database is struggling, it is usually because it is starved of one of these four essential food groups—and it is likely staring into space, waiting for one of them to become available so it can go back to resting.