RLS infinite recursion
RLS infinite recursion is the PostgreSQL error "infinite recursion detected in policy for relation". It happens when a Row-Level Security policy on a table runs a subquery against that same table (often to check membership or roles), so evaluating the policy re-triggers the policy.
Also known as: infinite recursion detected in policy · recursive RLS policy
It typically appears on tables like memberships, teams, or profiles where the policy needs to look up the user's role in the very table it guards. The fix is to break the loop — commonly by moving the lookup into a SECURITY DEFINER function, a separate non-recursive table, or a cached claim — so the policy no longer reads itself.
In Lovable apps this often surfaces after you ask the builder to add team or role-based permissions, because the generated policy naturally references the same membership table it protects. Common mistake: writing a membership or role policy that selects from the same table it guards — instead, isolate the role lookup in a SECURITY DEFINER helper function so the policy never re-triggers itself.
Stuck on the thing this term describes? Talk to a senior engineer.
Book a free 30-minute audit call. We'll diagnose what's wrong and tell you exactly what it costs to fix.