Skip to main content
InterviewHubPRO
Section Overview
Q18

Question 18 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

36%
PostgreSQL Enterprise (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

What is Row-Level Security (RLS) and how does it protect Multi-Tenant data?

senior LevelCode ExampleSecurity & AuthSystem Design

In Simple Words: RLS enforces access policies directly at the database engine level, regardless of what query the client sends:

  • Even if an application developer forgets to append WHERE tenant_id = 'acme', PostgreSQL automatically enforces the policy!
sql
ALTER TABLE documents ENABLE ROW LEVEL SECURITY;

CREATE POLICY tenant_isolation_policy ON documents
FOR ALL
USING (tenant_id = current_setting('app.current_tenant_id'));