You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PostgreSQL复合类型长度限制咨询:是固定8KB还是依组成数据而定?

PostgreSQL复合类型的大小限制:8KB还是取决于组成数据?

Hey there! Let’s clear up this confusion about composite type size limits in PostgreSQL once and for all.

First off: PostgreSQL does NOT impose a hard 8KB limit on composite types themselves. That 8KB number you’re thinking of is actually the default size of a PostgreSQL data page—the basic unit for storing table rows—but it doesn’t directly restrict composite types.

The actual maximum size of a composite type depends entirely on its constituent elements and how PostgreSQL handles large data via its TOAST (The Oversized-Attribute Storage Technique) system:

  • If your composite type includes TOAST-able data types (like text, bytea, arrays, or other variable-length types that support compression/offloading):

    • There’s effectively no practical size limit (other than your available disk space). When a composite type’s total size exceeds a threshold (controlled by the toast_tuple_target configuration parameter, usually around 2KB), PostgreSQL automatically compresses the large elements or stores them in a separate TOAST table, leaving only a small pointer in the main table row. This means even a composite type with multiple huge text fields can be stored without hitting the 8KB page barrier.
  • If your composite type only uses non-TOAST-able, fixed-size types (like int, bool, char(n), or numeric types with fixed precision):

    • The total size of the composite type can’t exceed the maximum row size in PostgreSQL, which is roughly 8160 bytes (the default 8KB page minus metadata overhead). Since these types can’t be compressed or offloaded, their combined size has to fit within a single data page. This scenario is pretty rare for "large, complex structures" though—most use cases for composite types will include at least some TOAST-able fields.

To put it simply: The 8KB page size is a storage implementation detail, not a hard cap on composite types. Your composite type’s maximum size is determined by what you put inside it, with TOAST handling the heavy lifting for large, variable-length data.

内容的提问来源于stack exchange,提问作者Shore

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 07:03:46