A common way to store documents in PostgreSQL is a table with an ID and a JSONB column. The open-source DocumentDB extension instead stores BSON, the binary document format used by MongoDB, to provide more data types and MongoDB compatibility.
Both approaches commonly combine two patterns that do not perfectly fit what SQL databases were designed for:
Rows with a single variable-length column, whose values can range from a few dozen bytes to many megabytes.
Repeated data or metadata, such as similar field names and arrays of objects with the same schema, like time-series buckets.
MongoDB's storage engine, WiredTiger, packs many documents into B-tree leaf pages. The default maximum page sizes — 32 KB for leaf pages and 4 KB for internal pages — are limits on the uncompressed page image fed to the block compressor, not on individual documents: MongoDB configures leaf_value_max=64MB, so a document larger than 32 KB simply produces a larger leaf page rather than overflow storage.…