What is Row Level Security (RLS) and how does it protect each row of PostgreSQL?
Published on 2026-10-20 by frfrand
RLS explained with an example of orders and users: row-level policies, SQL permissions, auth.uid(), service role and common security errors.

Short answer: Row Level Security (RLS) is a PostgreSQL feature that allows defining which rows of a table an account can read or modify according to access policies. It is especially useful when an application stores data from many users or companies in the same tables.
Imagine a table with orders from a thousand customers. Everyone can use the same application, but no one should see another person's purchases. RLS allows applying part of that separation directly where the data lives.
The cabinet example
Think of a building with a common storage room. Each customer has an identified compartment. The main door allows entering the building, but that does not mean you can open any cabinet.
In a relational database, table permissions are similar to general access to the storage room. RLS policies check which rows correspond to each identity and operation.
The metaphor is not perfect, but it helps distinguish permission to query a table and permission to query a specific row.
Does RLS replace normal permissions?
No. PostgreSQL uses object privileges and row policies. Both layers matter.
If an account does not have permission to execute SELECT on a table, adding an RLS policy does not automatically grant that privilege. And if an account has broad privileges or can bypass RLS, it is also not advisable to assume that a policy will restrict it.
In Supabase it is especially important to review which roles have permissions on exposed tables and which policies apply.
An example with an appointment application
Suppose you have a reservas table with fields id, usuario_id, fecha, and estado.
You want each person to consult their own reservations, but not those of other users. A read policy can compare the authenticated user's identifier with the usuario_id field of each row.
The specific mechanism depends on how identity reaches the database. In Supabase, for example, functions such as auth.uid() are used within policies.
The idea is that the database filters authorized rows, even when a request attempts to consult more information than it should.
And for updating or inserting information?
Policies can distinguish operations. Allowing reading one's own reservation does not mean allowing changing its amount, approving it on behalf of an administrator, or creating it for any user.
Rules must be defined for SELECT, INSERT, UPDATE, and DELETE according to the access model.
It is also advisable to prevent a person from changing the owner of a row to gain subsequent access. The design must contemplate both existing rows and new values.
Does RLS mean I can already trust the frontend?
No. The interface still needs correct design, and the server must perform additional checks when appropriate.
RLS protects row-level operations within PostgreSQL under its rules; it does not automatically validate payments, email sends, or complex business decisions.
It is a particularly valuable layer of defense when there are APIs or SDKs that allow access to certain tables from authenticated clients.
What is service_role in Supabase?
Supabase uses a service role with elevated privileges that can bypass RLS policies. For that reason, service keys must remain server-side and under appropriate access controls.
It is not safe to place a credential capable of bypassing policies within the public JavaScript of a website.
Also, do not confuse a project publishable key with universal authorization: effective access depends on roles, policies, and configuration.
Common mistakes
Creating the table and forgetting about RLS. If RLS is not enabled on the table, any role with privileges over it sees all rows. If it is enabled but has no policies, PostgreSQL denies everything by default (except the table owner and roles that can bypass RLS).
Applying only a read policy. Inserting or updating rows may require different rules.
Testing only with an administrator. If that account bypasses RLS, you might think everything works and later discover that real users cannot access or access improperly.
Not testing negative cases. Tests must confirm that client A cannot read or modify rows from client B.
How it fits into ArduMaker?
In ArduMaker, PostgreSQL is installed on your VPS from the app catalog, and in new installations the platform generates its own random user and password (never postgres). RLS is an engine feature, so it works the same as in any PostgreSQL: policies are created with SQL (ALTER TABLE … ENABLE ROW LEVEL SECURITY and CREATE POLICY), ideally from your project's migrations. What it does not include is the auth.uid() function, which is specific to Supabase: the user identity must reach the database through the mechanism chosen by your backend. Configuring the server does not define your application's policies: that belongs to data and permission design.
In summary: RLS helps control row-by-row access. Combined with SQL permissions, authentication, and testing, it can be an important defense for multi-user applications.
Frequently asked questions
Why doesn't my policy filter anything when I test it?
You are probably querying with a role that bypasses RLS. Superusers and roles with the BYPASSRLS attribute never apply policies, and neither does the table owner, unless you enable ALTER TABLE … FORCE ROW LEVEL SECURITY. Always test with the same role your application uses.
Does RLS slow down queries?
Each policy adds a condition to the query, as if it were an additional WHERE. If that condition compares unindexed columns —for example, usuario_id—, the cost can be noticeable on large tables. Indexing the columns used by policies usually solves it.
Sources: RLS en PostgreSQL · RLS en Supabase · Para qué sirve Supabase.
