📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials PostgreSQL Essentials Row Level Security

Row Level Security

7 min read
Row Level Security restricts which rows each user can see or modify. Enable with ALTER TABLE ... ENABLE ROW LEVEL SECURITY, then CREATE POLICY to define rules. Ideal for multi-tenant apps storing all data together.

Row Level Security (RLS)

ALTER TABLE orders ENABLE ROW LEVEL SECURITY;

-- Users see only their own orders
CREATE POLICY user_orders ON orders
  FOR ALL TO application_role
  USING (user_id = current_setting('app.user_id')::INT);

-- Set context in app
SET app.user_id = 42;

RLS enforces data isolation at the database layer.