Write a database. Depending on what angle you take, it can look like a compiler (SQL parsing, predicate evaluation, optimizing for index usage), OS (file systems for in-place updates of complex data structures, and scheduling with lock dependencies), distributed systems (consistency and availability tradeoffs across machines, with possible partitions).
And then there's the whole mental model of relational algebra and stream processing of queries.
It'll give new appreciation for existing databases and what they can and can't do for you.