Row-Level Security
ALTER TABLE ... ENABLE ROW LEVEL SECURITY
ALTER TABLE orders ENABLE ROW LEVEL SECURITY; What this does
The lock is brief, but the effect is not: every non-owner role now needs a matching policy. Without one, reads on the table silently return zero rows and writes fail, for every affected role, the moment this commits.
Safe rewrite
Define policies before enabling RLS, then test as the target role
-- 1. Create the policies first:
CREATE POLICY orders_owner_read ON orders FOR SELECT USING (customer_id = current_setting('app.customer_id')::bigint);
-- 2. Then enable RLS:
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
-- 3. Test as the target role:
SET ROLE app_role; SELECT count(*) FROM orders;