isolamento-de-banco-de-dados-com-rls

Implements multi-tenant data isolation in PostgreSQL using declarative Row-Level Security policies.

Updated Jul 19, 2026
One-click install
npx skills add https://github.com/Ryanzucchi/Eldritch_Lich --skill isolamento-de-banco-de-dados-com-rls-ryanzucchi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: isolamento-de-banco-de-dados-com-rls
Source: https://github.com/Ryanzucchi/Eldritch_Lich/tree/main/.agents/skills/isolamento-de-banco-de-dados-com-rls
Command: npx skills add https://github.com/Ryanzucchi/Eldritch_Lich --skill isolamento-de-banco-de-dados-com-rls-ryanzucchi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? When multiple tenants share the same physical PostgreSQL tables in a SaaS platform, there is a risk of one tenant reading or modifying another tenant's data. This Skill enforces logical isolation at the database level using Row-Level Security, so each user or organization only accesses its own rows without needing separate schemas per tenant. ## Core Features & Use Cases - Declarative RLS Policies: Creates SELECT, INSERT, and UPDATE policies bound to a session-level tenant variable, with FORCE ROW LEVEL SECURITY to block even table owners from bypassing isolation. - Tenant Key Modeling: Adds a tenant_id column with composite primary-key indexing to keep RLS-filtered queries on Index Scans instead of full table scans. - Session Binding per Request: Injects the authenticated tenant_id into each transaction via SET LOCAL from the application middleware. - Use Case: A SaaS writing platform stores manuscripts from hundreds of organizations in one table. Apply this Skill so that a query from Tenant A can never return Tenant B's manuscripts, verified by penetration tests and a latency overhead under 10%. ## Quick Start Ask the AI to apply Row-Level Security tenant isolation to the shared manuscripts table in PostgreSQL, including the tenant_id column, policies, and session binding.

Frequently Asked Questions about isolamento-de-banco-de-dados-com-rls

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement multi-tenant isolation in PostgreSQL with Row-Level Security?▼

Add a tenant_id column to every shared table, enable and force RLS, then create SELECT, INSERT, and UPDATE policies comparing tenant_id to a session variable set with SET LOCAL at the start of each transaction.

How to set the current tenant per request in PostgreSQL RLS?▼

In the application middleware, begin a transaction and run SET LOCAL app.current_tenant_id with the authenticated tenant's UUID. All subsequent queries in that transaction are automatically filtered by the RLS policies.

Does PostgreSQL RLS cause performance problems on large tables?▼

RLS can trigger full table scans if tenant_id is not indexed. Create a composite index on (tenant_id, id) and verify with EXPLAIN ANALYZE that queries use Index Scan; the target overhead is under 10% of baseline latency.

Why does FORCE ROW LEVEL SECURITY matter for table owners?▼

Without FORCE ROW LEVEL SECURITY, the table owner bypasses RLS policies, which can let administrative queries leak data across tenants. Forcing RLS ensures only a designated bypass role like rls_admin can skip the policies.

When should I not use Row-Level Security for tenant isolation?▼

Avoid RLS for internal system tables without user PII, such as technical logs, and in single-tenant local development environments where the policy overhead adds no isolation benefit.