What is the maximum number of columns that can make up a primary key in PostgreSQL
In SQL Server, mySQL, its 16. In postgres, its greater but I cannot find any documentation.
I created a table with 20 columns as the PK and it worked fine. Curious what is the max?
Solution – 1
columns per index 32
However, this is only part of the truth.
There is also a limit on the maximum size of an index entry which a bit under 1/3 of the block size.
The default block size is 8192 bytes, so the sum of all column values cannot exceed roughly 2700 bytes in an index