PulseAugur
EN
LIVE 19:51:33

PostgreSQL RLS policy creates infinite recursion loop

A developer encountered an infinite recursion error in PostgreSQL's Row Level Security (RLS) policies while working with Supabase. The issue stemmed from a policy on the `public.cours` table that queried the `public.user_roles` table, which itself had policies that also queried `public.user_roles`. This created a loop when a new `agent_readonly` role was added to the `authenticated` membership, causing PostgreSQL to evaluate all permissive policies. The developer explored solutions like `SECURITY DEFINER` functions and role isolation before ultimately deciding to move role information out of the database and into JWT custom claims. AI

IMPACT N/A

RANK_REASON Developer describes a technical problem and solution related to database security policies.

Read on dev.to — Claude Code tag →

AI-generated summary · Google Gemini · from 1 sources. How we write summaries →

PostgreSQL RLS policy creates infinite recursion loop

COVERAGE [1]

  1. dev.to — Claude Code tag TIER_1 English(EN) · Michel Faure ·

    RLS recursion infinite loop: why I gave up policies and bet everything on a JWT custom claims hook

    <blockquote> <p>Episode <strong>1/4</strong> — 3 incidents, one root: default GRANTs open more than you think — [CANONICAL URL EPISODE 1: fill in after push]<br /> Episode <strong>2/4</strong> — <code>await mutation()</code> lies when nobody opens the <code>{ error }</code> envel…