SQLSTATE 42P16Severity lowLab verified

Incident brief

Multiple primary keys not allowed

A table can have at most one PRIMARY KEY; declaring PRIMARY KEY on two columns separately raises this invalid-table-definition error. Use a composite key for several columns.

What lands in your log

ERROR: multiple primary keys for table "two_pk" are not allowed

Reproduced on PostgreSQL 18.4Verified 2026-07-24 (isolated lab, PostgreSQL 18.4)Verified against PostgreSQL 18.4 in an isolated lab environment

In 10 seconds

What triggers it
Write CREATE TABLE with PRIMARY KEY on two different columns.
Fix
Keep a single PRIMARY KEY, use one column, or a composite PRIMARY KEY (a, b).
Proof
Reproduced on PostgreSQL 18.4 → A CREATE TABLE reproduces SQLSTATE 42P16; the second PRIMARY KEY clause is rejected and the LINE points at it.

Fix

What to do right now

Application-level steps for this error.

  • Keep a single PRIMARY KEY, use one column, or a composite PRIMARY KEY (a, b).
  • Model additional uniqueness with UNIQUE constraints instead of extra primary keys.
Fix SQL
CREATE TABLE two_pk (
  a int PRIMARY KEY,
  b int UNIQUE
);

Runbook to fix this

The runbook for this incident

Full step-by-step fixes for the condition behind this error: the diagnosis, the exact SQL, and output captured in the lab.

Verification

PG 18.4
Last verified
2026-07-24 (isolated lab, PostgreSQL 18.4)
Verification scope
Verified against PostgreSQL 18.4 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops