# Remember to use primary keys vs unique constraints in Postgres

DevFeed: [Remember to use primary keys vs unique constraints in Postgres](<https://devfeed.tech/articles/remember-to-use-primary-keys-vs-unique-constraints-in-postgres-5769.md>)

Original publisher: [Read original article](<https://neon.com/blog/remember-to-use-primary-keys-vs-unique-constraints-in-postgres>)

Author: Nikolai Rekubratskii

Published: 2024-05-15T16:23:24Z

Content type: tutorial

Language: en

Sources: [Blog -- Neon Docs](<https://devfeed.tech/sources/blog-neon-docs.md>)

Topics: [Databases](<https://devfeed.tech/topics/databases.md>), [Database](<https://devfeed.tech/topics/database.md>), [Replication](<https://devfeed.tech/topics/replication.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>)

Tags: [database](<https://devfeed.tech/tags/database.md>), [databases](<https://devfeed.tech/tags/databases.md>), [features](<https://devfeed.tech/tags/features.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgres](<https://devfeed.tech/tags/postgres.md>), [replication](<https://devfeed.tech/tags/replication.md>)

## AI overview

This article explains why PostgreSQL tables should use primary keys rather than relying on unique constraints as a substitute. It covers row identification, uniqueness, non-nullability, automatic indexing, logical replication, referential integrity, and query optimization.

## Source excerpt

If you are setting up a new table in Postgres, the first line is probably going to look like this: You're going to have an id of type INTEGER, and you're setting it as the PRIMARY KEY. If this is you, congrats, you can stop reading right here. However, if this is you: Then, read...