What is the maximum number of columns that can make up a primary key in PostgreSQL

What is the maximum number of columns that can make up a primary key in PostgreSQL

Problem Description:

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

As documented in the manual

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

Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject