A foreign key protects a link only inside one database
It refuses broken links with no app code, but it cannot cross databases, and copied tables ignore it.
A foreign key makes the database refuse a broken link
A foreign key is one line in the table definition. Look at the marked line in this seat table:
create table quest (id uuid primary key,seats int not null);create table seat (quest_id uuid not null references quest(id) on delete cascade,person_id text not null,primary key (quest_id, person_id));
That line gives 2 promises. A seat for a quest that does not exist is refused. And when the quest is deleted, its seats go in the same moment.
The promise holds at every moment, with no code of ours.
There is no worker and no retry. A seat never points at nothing, not even briefly.
A foreign key matters most where a broken link costs money
Not every broken link hurts the same. Compare 2 cases.
A paid seat in a deleted quest is lost money. Somebody must find it and refund it. Here the link must never break.
A like on a deleted post is invisible. Nobody can open the post, so nobody sees the like. Here a short broken moment is fine.
This table sorts common links by what a broken moment costs:
| Link | A broken moment costs | Foreign key needed |
|---|---|---|
| Seat to quest, with a limit | A seat nobody can use, or 11 seats of 10 | Yes |
| Gem ledger line to gem balance | Wrong money | Yes |
| Check-in to habit | A wrong streak | Yes, and it is free: same database |
| Like or comment to post | Nothing visible | No |
| Friend row to the other person | A friend who is gone, for a moment | No |
So the rule of thumb: money and limits need a foreign key. Social links can do without.
A foreign key cannot cross two databases, and a copied table ignores it
A foreign key lives inside one Postgres. It cannot point from US West to Singapore.
There is a second, quieter limit. Postgres switches foreign key checks off while it applies copied rows. From docs
We tested what that means. Our list of charities is written in one region and copied to the others. A habit row points at a charity with a normal foreign key.
Then we hard deleted one charity at the source. This is what the copy in Singapore did:
The foreign key was there, and it stayed silent. 2 habit rows and 1 penalty row pointed at nothing.
Postgres 17 manual, logical replication architecture: the apply process runs with session_replication_role set to replica, which disables foreign key checks. Our test: 22 Nov 2026.
Most links stay foreign keys in both models
Losing foreign keys everywhere would be a big cost. That is not what happens.
We counted the links in the test database, which models a habit app with friends and quests:
The first 2 tiles count the test database. The third counts our real habit app, a different database.
Most links never leave one database. Only links that cross a region lose the foreign key.