When should you use the JSONB type in Postgres?
A review of different sources on when JSONB is suitable for use.
Note: database solutions are context-dependent, varying by version, implementation difficulty, and maintenance burden. Experiment with multiple designs before settling on one.
I recently designed a database schema for new metrics in a data analytics project. As a software engineer new to schema design, I explored different storage options, including the JSONB type. This post summarises what I learned from various sources.
JSONB seems attractive because it eliminates schema management overhead. But it’s a common pitfall: multiple undocumented schema variations proliferate in the database, stored opaquely. Using JSONB for anything beyond unstructured blobs introduces significant downsides.
Pros for using JSONB
- No schema management required for that column (though undocumented variations risk proliferating).
- Useful for data with variable structure.
- Good for data that doesn’t fit the relational model (e.g., unstructured customer input).
- Convenient for JSON-native data.
Cons of using JSONB
- Queries are slower because Postgres cannot maintain column statistics for JSONB, hampering query optimisation.
- JSONB lacks fixed typing, causing conversion problems when storing and extracting data.
- No constraints on data entry means errors slip through more easily.
- JSONB typically requires more storage than equivalent relational columns.
Annotated bibliography
Heap: When To Avoid JSONB In A PostgreSQL Schema
- Nice analysis on when JSONB is suitable for use from an organisation which uses this format to store data of arbitrary length, i.e. customer entered data.
When to Avoid JSONB in a PostgreSQL Schema
- Discussion of the Heap post on hacker news.
- I find it interesting to learn about other peoples experiences, however anecdotal they might be.
Faster Operations with the JSONB Data Type in PostgreSQL
- A post describing how to use JSONB faster if you have to use it.
Explanation of JSONB introduced by PostgreSQL
- Reliable reference for technical explanation.