Definition
Row-level security (RLS) is a database feature, built into PostgreSQL, that decides which individual rows each user can read or change, using policies attached to a table. Once it is enabled, queries only see permitted rows, even if application code forgets to filter.
How RLS works
Without RLS, database permissions are all or nothing per table: a role can read the orders table or it cannot. With RLS enabled, every query on that table is filtered by policies, conditions such as "the row's owner is the current user". The PostgreSQL documentation is precise about the default: once row security is enabled and no policy exists, a default-deny policy applies and no rows are visible or can be modified.
Policies have two parts. USING decides which existing rows a command can see, update or delete. WITH CHECK decides whether a new or changed row may be written. Getting the second wrong, for example an insert policy that checks nothing, lets a user write rows that belong to someone else.
When it matters
RLS matters most when the browser or mobile app talks to the database directly, which is how Supabase works. There, a public key ships inside your app, and the policies are the only thing between a curious user and every other customer's data. Supabase's documentation says to enable RLS on every table in an exposed schema, and notes that its secret key authorizes a role that bypasses RLS, so it must never reach the browser.
In a traditional backend where only your server talks to the database, RLS is a second wall rather than the only one. It is still valuable in multi-tenant products, because one forgotten filter in one API route is all it takes to show customer A the invoices of customer B.
The pitfalls
Wrong policies fail quietly. Supabase points out that auth.uid() returns null for signed-out users, and a comparison with null is never true, so a policy can pass the tests you thought of and still misbehave for a case you did not; it recommends an explicit not-null check. In PostgreSQL, superusers always bypass RLS and table owners do too unless the table forces row security, so a test run as the owner proves nothing.
Performance is the other trap. Policies are evaluated for the rows a query touches. Index the columns your policies filter on, and, as Supabase recommends, wrap calls like auth.uid() in a select so Postgres evaluates them once per statement rather than once per row. Then test with real sessions for each role, including the view of a user trying to read what is not theirs.
What it does to a quote
On a $850 web product built on Supabase or Postgres, the written quote scopes policies for each table, and tests that try to read another account's rows, as part of the auth work. Backend work on an existing database, such as auditing or adding RLS to a product that is already live, starts at $390. The number of user roles moves the quote most, because each role multiplies policies.
Questions
Do we need RLS if our API already checks permissions?
It is not mandatory, but it is cheap insurance in a multi-tenant product. API checks are written route by route, and one missed filter leaks data. RLS enforces the rule in the database for every query. If clients talk to the database directly, as with Supabase, it is required.
Does RLS slow the database down?
It can, if policies are written carelessly. Each policy runs as part of the query, so unindexed columns or functions evaluated for every row add up on large tables. With indexes on policy columns and functions evaluated once per statement, the overhead is usually small.
Sources
- Row Security Policies (PostgreSQL 18 documentation, section 5.9), PostgreSQL Global Development Group
- Row Level Security, Supabase Docs