Приложение J. Ограничения Postgres Pro
В Таблице J.1 описываются различные жёсткие ограничения Postgres Pro. Однако раньше этих абсолютных лимитов на практике могут достигаться другие, например, предел производительности или доступного объёма дискового хранилища.
Таблица J.1. Ограничения Postgres Pro
Объект | Верхний предел | Комментарий |
---|---|---|
размер базы данных | без ограничений | |
количество баз данных | 4 294 950 911 | |
отношений в базе данных | 1 431 650 303 | |
размер отношения | 32 ТБ | со значением BLCKSZ по умолчанию, равным 8192 байта |
строк в таблице | ограничивается количеством кортежей, которое может уместиться в 4 294 967 295 страниц | |
столбцов в таблице | 1600 | дополнительно ограничивается размером кортежа, который может уместиться в одной странице; см. примечание ниже |
столбцов в наборе результатов | 1664 | |
размер поля | 1 ГБ | |
индексов в таблице | без ограничений | ограничивается максимальным количеством отношений в базе данных |
столбцов в индексе | 32 | может быть увеличена при перекомпиляции Postgres Pro |
ключей секционирования | 32 | может быть увеличена при перекомпиляции Postgres Pro |
длина идентификатора | 63 байта | может быть увеличена при перекомпиляции Postgres Pro |
аргументы функции | 100 | может быть увеличена при перекомпиляции Postgres Pro |
параметры запроса | 65535 |
Максимальное количество столбцов таблицы дополнительно уменьшается в связи с тем, что сохраняемый кортеж должен умещаться в одной странице размером 8192 байта. Например, если не учитывать размер заголовка, кортеж, состоящий из 1600 столбцов int
, будет занимать 6400 байт и поместится в странице кучи, тогда как 1600 столбцов bigint
займут 12800 байт и в одной странице не поместятся. Поля переменной длины, например типов text
, varchar
и char
, могут храниться отдельно, в таблице TOAST, когда их значения достаточно велики для этого. При этом внутри кортежа кучи должен остаться только 18-байтовый указатель. Для более коротких значений полей переменной длины используется заголовок из 1 или 4 байт, и само значение сохраняется внутри кортежа в куче.
Максимальное количество столбцов может также зависеть от числа столбцов, удалённых из таблицы. И хотя значения удалённых столбцов для создаваемых впоследствии кортежей не хранятся, а только помечаются как NULL в специальной битовой карте, эта карта тоже занимает место.
Теоретически каждая таблица может хранить до 2^32 отделённых значений. Более подробно такие значения описаны в Разделе 69.2. Данное ограничение вызвано использованием 32-битных OID для идентификации каждого такого значения. В реальности же лимит значительно ниже, поскольку как только всё пространство для OID занято, найти свободный OID становится сложно, что замедляет работу операторов INSERT/UPDATE. Обычно это происходит только с таблицами объёмом в несколько терабайт. Возможным обходным решением может быть секционирование.
Chapter 60. Table Access Method Interface Definition
This chapter explains the interface between the core PostgreSQL system and table access methods, which manage the storage for tables. The core system knows little about these access methods beyond what is specified here, so it is possible to develop entirely new access method types by writing add-on code.
Each table access method is described by a row in the pg_am
system catalog. The pg_am
entry specifies a name and a handler function for the table access method. These entries can be created and deleted using the CREATE ACCESS METHOD and DROP ACCESS METHOD SQL commands.
A table access method handler function must be declared to accept a single argument of type internal
and to return the pseudo-type table_am_handler
. The argument is a dummy value that simply serves to prevent handler functions from being called directly from SQL commands. The result of the function must be a pointer to a struct of type TableAmRoutine
, which contains everything that the core code needs to know to make use of the table access method. The return value needs to be of server lifetime, which is typically achieved by defining it as a static const
variable in global scope. The TableAmRoutine
struct, also called the access method's API struct, defines the behavior of the access method using callbacks. These callbacks are pointers to plain C functions and are not visible or callable at the SQL level. All the callbacks and their behavior is defined in the TableAmRoutine
structure (with comments inside the struct defining the requirements for callbacks). Most callbacks have wrapper functions, which are documented from the point of view of a user (rather than an implementor) of the table access method. For details, please refer to the src/include/access/tableam.h
file.
To implement an access method, an implementor will typically need to implement an AM-specific type of tuple table slot (see src/include/executor/tuptable.h
), which allows code outside the access method to hold references to tuples of the AM, and to access the columns of the tuple.
Currently, the way an AM actually stores data is fairly unconstrained. For example, it's possible, but not required, to use postgres' shared buffer cache. In case it is used, it likely makes sense to use PostgreSQL's standard page layout as described in Section 69.6.
One fairly large constraint of the table access method API is that, currently, if the AM wants to support modifications and/or indexes, it is necessary for each tuple to have a tuple identifier (TID) consisting of a block number and an item number (see also Section 69.6). It is not strictly necessary that the sub-parts of TIDs have the same meaning they e.g., have for heap
, but if bitmap scan support is desired (it is optional), the block number needs to provide locality.
For crash safety, an AM can use postgres' WAL, or a custom implementation. If WAL is chosen, either Generic WAL Records can be used, or a new type of WAL records can be implemented. Generic WAL Records are easy, but imply higher WAL volume. Implementation of a new type of WAL record currently requires modifications to core code (specifically, src/include/access/rmgrlist.h
).
To implement transactional support in a manner that allows different table access methods be accessed within a single transaction, it likely is necessary to closely integrate with the machinery in src/backend/access/transam/xlog.c
.
Any developer of a new table access method
can refer to the existing heap
implementation present in src/backend/access/heap/heapam_handler.c
for details of its implementation.