# PostgreSQL UNLOGGED tables as a cache

By Saurabh Kumar · TIL note, Jun 28, 2026 · Tags: databases

Source: https://saurabh-kumar.com/til/1782648000/

PostgreSQL `UNLOGGED` tables skip the write-ahead log, making writes considerably faster than ordinary tables. Trade-off: they are truncated after a crash or unclean shutdown and are not replicated to standbys. [hynek/psycache](https://github.com/hynek/psycache) exploits this as a PostgreSQL-native cache replacing Redis — crash truncation is acceptable since it's a cache anyway, and you reuse existing Postgres connections.
Interesting idea: port this to Django as a custom `BaseCache` backend — swap `DatabaseCache`'s regular table for `CREATE UNLOGGED TABLE`, reuse Django's existing DB connections, and skip Redis entirely. ~200 lines.
