Hard Limits and Resource Constraints in PostgreSQL and SQLite
These entries detail the technical constraints and maximum capacities for PostgreSQL and SQLite. They outline specific limits regarding database size, table columns, row counts, and field lengths. The documentation also covers restrictions on query parameters, join limits, and schema objects, including how these ceilings are enforced and the consequences of exceeding them, such as returning SQLITE_FULL in SQLite.
PostgreSQL Database Hard Limits and Constraints
PostgreSQL enforces several hard limits, although performance and disk space often act as practical constraints. While the overall database size is unlimited, the system caps the number of databases at 4,294,950,911 and the number of relations per database at 1,431,650,303. A single relation's size is limited to 32 TB when using the default BLCKSZ of 8192 bytes, and the number of rows per table is determined by the tuples that can fit onto 4,294,967,295 pages. Tables are limited to 1,600 columns, a number further restricted by the requirement that tuples must fit on a single 8192-byte heap page; notably, dropped columns still count toward this limit. Variable-length fields such as varchar, text, and char may be stored out-of-line in TOAST tables, utilizing an 18-byte pointer in the heap. While there is a theoretical maximum of 2^32 out-of-line values due to 32-bit OIDs, filling this space can degrade the performance of INSERT and UPDATE operations. Additional constraints include a maximum of 32,767 CHECK constraints per table, a result set limit of 1,664 columns, and a maximum field size of 1 GB. While the number of indexes per table is unlimited, it is capped by the maximum relations per database. Furthermore, partition keys and columns per index are limited to 32, and function arguments are limited to 100; these three limits, along with the 63-byte identifier length, can be increased by recompiling PostgreSQL. Finally, the system restricts query parameters to a maximum of 65,535.
Source: https://www.postgresql.org/docs/current/limits.html
SQLite Database Resource Limits and Constraints
SQLite implements various limits on sizes and quantities to maintain stability and prevent resource exhaustion or denial-of-service attacks. While many limits are established via compile-time macros, they can be lowered during run-time using the sqlite3_limit() interface.
String and BLOB lengths, as well as maximum row size, are governed by SQLITE_MAX_LENGTH, which defaults to 1 billion bytes with a hard ceiling of 2,147,483,645 bytes. SQL statement length is similarly managed by SQLITE_MAX_SQL_LENGTH (default 1 billion bytes). The number of columns in tables, indices, views, result sets, and specific statement terms is limited by SQLITE_MAX_COLUMN, defaulting to 2000 with a maximum of 32767.
Additional constraints include a limit of 64 tables in a join, an expression tree depth of SQLITE_MAX_EXPR_DEPTH (default 1000), and function arguments capped by SQLITE_MAX_FUNCTION_ARG (default 1000, max 32767). Compound SELECT statements are limited to SQLITE_MAX_COMPOUND_SELECT (default 500) terms, and LIKE or GLOB patterns are restricted to SQLITE_MAX_LIKE_PATTERN_LENGTH (default 50,000 bytes). Host parameter numbers are capped at 32,766 for versions after 3.32.0 via SQLITE_MAX_VARIABLE_NUMBER.
Operational limits include a recursive trigger depth governed by SQLITE_MAX_TRIGGER_DEPTH (default 1000) and the number of attached databases limited by SQLITE_MAX_ATTACHED (default 10, max 125). Database file size is constrained by SQLITE_MAX_PAGE_COUNT (default 4,294,967,294 pages), potentially reaching approximately 281 terabytes depending on page size; exceeding this limit returns SQLITE_FULL. Although the theoretical row limit is 2^64, the file size limit is typically reached first. Finally, schema objects are capped by SQLITE_LIMIT_SCHEMA, which defaults to 10 million.