# Row-Level Security (RLS)

> One table, with rows hidden by person. Each reader sees only their own rows.

**Field:** Data Engineering  
**Category:** Governance & Quality  
**Also known as:** RLS, Row Access Policy, Row-Level Access Control

## Think of it like

It is like a class list where each teacher sees only their own pupils. It is still one list.

## Definition

Row-level security lets people read one table but see different rows. A rule, called a policy, is set on the table. Each time someone reads it, the database adds a filter for them. A sales rep in Europe then sees only customers in Europe. Users cannot skip the filter. So one table can serve many teams.

## 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.

## Example code

```sql
ALTER TABLE accounts ENABLE ROW LEVEL SECURITY;
CREATE POLICY own_accounts ON accounts
  USING (manager = current_user);
```

Each manager now sees only the rows that name them.

## 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.

## Common mistake

Testing it while logged in as the owner of the table. In PostgreSQL the owner skips the policy by default. So every row still shows.

## Three principles

- **Same table.** One table, many views of it.
- **Filtered on read.** The database adds the filter each time.
- **Hard to skip.** Users cannot turn the filter off.

## Related terms

- [Data Access Control](https://learn.benibix.com/term/data/data-access-control)
- [Column-Level Security](https://learn.benibix.com/term/data/column-level-security)
- [Data Masking](https://learn.benibix.com/term/data/data-masking)
- [PostgreSQL](https://learn.benibix.com/term/development/postgresql)
- [Authorization](https://learn.benibix.com/term/development/authorization)
- [Multi-Tenancy](https://learn.benibix.com/term/development/multi-tenancy)

![Two copies of one customer table with region, customer, email and total columns. On the left, the whole table the data owner can read. On the right, what Lucy, an analyst for Europe, can read: the two US rows and the email column are greyed out.](https://learn.benibix.com/diagrams/dat2-access-control.svg)

---

Source: https://learn.benibix.com/term/data/row-level-security
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
