Back to blog
Security PostgreSQL Architecture Multi-tenant SaaS

Row-Level Security in Postgres: When to Turn It On, and When to Wait

By Ken B Portfolio · Published on November 5, 2026
Illustration of a developer working at a laptop

Most SaaS apps keep every customer in one database. What keeps them apart is one line in every query: “only this customer’s rows”. Forget it once, and one customer sees another’s data.

Code review catches most of those. Not all. And with AI writing more of the code, there are more queries to check every week.

Row-level security (RLS) moves that line into the database. Postgres checks every row against a rule. A query that forgets the filter gets nothing back, not someone else’s data.

I turned it on in a job-alert app I built. Here is how, what I planned for later, and how to tell if your app needs it.

You don’t need to read SQL to decide this. I check how your app keeps customers apart, add the rules table by table, and add the tests that prove each wall holds.

How I set it up

No new passwords. The app keeps its one database login. For each customer request it switches, for one short transaction, to a role that has no password and cannot log in, and tells the database which account is asking. When the transaction ends, the switch ends too. The next request starts clean.

Two doors. Admin pages, payment webhooks, nightly jobs and sign-in use a system door that skips the rules. Everything else uses the member door. A test holds the exact list of files allowed on the system door, so a customer page cannot use it by mistake.

Every table, tested. Rules are on for 49 of 50 tables; the last is the database’s own change log. Tests check that account A sees only A’s rows, that no account set means zero rows, and that a new table with no rule fails. The full suite passed: 1,987 tests.

Easy to undo. The rules do not bind the app’s own login, so undo is one click: roll back to the previous version.

What I planned for later

Teams. The rules are keyed on the account, so when several people share one account, they share its work. Personal settings check the person too, so they stay private.

Speed. Each customer query now takes three short trips to the database instead of one. I have not measured the cost yet. If pages slow down, a driver that sends all three in one trip fixes it, and only one file changes.

Turn it on, skip it, or wait?

Turn it on when many customers share one database, when the browser talks to the database directly (on Supabase, RLS is the only wall), when more than one person or AI writes queries, or when the data is sensitive.

Skip it with one database per customer, an internal tool where everyone may see everything, or a prototype with no real users.

Wait if you are still finding your market, the schema changes every week, and one person writes all the code. Every new table needs a rule, and a missing rule shows up as empty pages.

But do one thing now: put the customer’s account id on every table. That turns RLS into a small job later instead of a rebuild. Turn it on before real customer data arrives or the second developer joins, whichever comes first.

For the other walls an app needs, see understanding security in your SaaS. To check the walls you already have, see a practical security audit toolkit.

The short version

RLS makes the database refuse the query you forgot to filter. Add the account id everywhere today, and turn the rules on before the risk is real.

Tell me how your app keeps customers apart and I’ll tell you if you need row-level security now, later, or never.

Where does your app keep customers apart today: in every query, or in the database?

AREYOURCUSTOMERSWALLEDOFF?

Tell me how your app keeps customers apart and I'll tell you if you need row-level security now, later, or never.

More Posts

All posts