🛡️Row-Level Security (RLS)
Also known as RLS, Row Access Policy, Row-Level Access Control
One table, with rows hidden by person. Each reader sees only their own rows.
Think of it like
It is like a class list where each teacher sees only their own pupils. It is still one list.
Example
In PostgreSQL, a table with row security on and no policy shows no rows at all. Lucy's team adds one policy. Now each manager sees only their own accounts.
Why it matters
Without it, teams make one copy of a table per group. The copies drift apart, and any one of them can leak.
Definition
Example code
sql
ALTER TABLE accounts ENABLE ROW LEVEL SECURITY;
CREATE POLICY own_accounts ON accounts
USING (manager = current_user);Common mistake
Key takeaways
- 1Same table. One table, many views of it.
- 2Filtered on read. The database adds the filter each time.
- 3Hard to skip. Users cannot turn the filter off.