K. PostgreSQL Limits

Table K.1 描述了 PostgreSQL 的各種硬限制。但是,在達到絕對硬限制之前,可能會在實際應用時就產生其他的限制情況,例如效能限制或可用的磁碟空間。

Table K.1. PostgreSQL Limitations

ItemUpper LimitComment

database size

unlimited

number of databases

4,294,950,911

relations per database

1,431,650,303

relation size

32 TB

with the default BLCKSZ of 8192 bytes

rows per table

limited by the number of tuples that can fit onto 4,294,967,295 pages

columns per table

1600

further limited by tuple size fitting on a single page; see note below

columns in a result set

1664

field size

1 GB

identifier length

63 bytes

can be increased by recompiling PostgreSQL

indexes per table

unlimited

constrained by maximum relations per database

columns per index

32

can be increased by recompiling PostgreSQL

partition keys

32

can be increased by recompiling PostgreSQL

由於要儲存的 tuple 要儘量塞進一個 8,192 位元組的 heap page,因此資料表的最大欄位數量可能還會減少一些。 例如,如果不包括 tuple 標頭資訊的話,由 1600 個 int 欄位組成的 tuple 將會佔用 6,400 個位元組,並且可以儲存在 heap page 之中,但是具有 1600 個 bigint 欄位的 tuple 將需要使用 12,800 個位元組,因此不適合放入 heap page 之中。型別是可變動長度(例如 text,varchar 和 char)的內容可以儲存在資料表的 TOAST 資料表中,而這些內容到了足夠長度就會這樣使用。資料 heap 中的 tuple 中只會保留 18 位元組的指標。對於較短長度的可變長度文字,會使用 4 位元組或 1 位元組的字串標頭,並且該內容儲存在 heap tuple 之內。

從資料表中刪除的欄位也會影響最大欄位數的限制。此外,儘管在 tuple 的 null bitmap 中將新建立的 tuple 的刪除欄位值內部標記為 null,但 null bitmap 也還是佔用空間。