multi-tenant-postgres

Implement multi-tenant PostgreSQL isolation with row-level security.

2|Updated Dec 14, 2025
One-click install
npx skills add https://github.com/raphaelmansuy/k8s-agent-stack --skill multi-tenant-postgres
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: multi-tenant-postgres
Source: https://github.com/raphaelmansuy/k8s-agent-stack/tree/main/archive/skills/multi-tenant-postgres
Command: npx skills add https://github.com/raphaelmansuy/k8s-agent-stack --skill multi-tenant-postgres

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a single PostgreSQL database with row-level security (RLS) to isolate tenant data, reducing database complexity and operational overhead.

Core Features & Use Cases

  • Row-Level Security (RLS): Enforce per-tenant data access at the database layer.
  • Tenant isolation in a single DB: Manage organizations, projects, and agents without sharding.
  • Migrations and tooling: Versioned migrations and sqlc integration for typed queries.

Quick Start

Set up the initial migrations under migrations/ and configure your application to set the current tenant context (project_id) on each request; run migrations to initialize the schema and policies.

Frequently Asked Questions about multi-tenant-postgres

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

FAQPage Schema
How do I isolate tenant data in PostgreSQL without sharding?▼

Row-level security (RLS) enforces per-tenant data access at the database layer within a single PostgreSQL instance. Set the current tenant context (project_id) on each request, apply RLS policies tied to current_setting, and PostgreSQL automatically filters rows by tenant—eliminating the complexity of managing separate databases or shards.

Can I use row-level security to manage organizations and projects in one database?▼

Yes. RLS policies isolate data for organizations, projects, and agents in a single PostgreSQL database. Define policies that reference the current tenant context, and all queries automatically respect tenant boundaries—reducing operational overhead while maintaining strong isolation.

How do I set up PostgreSQL migrations for multi-tenant schemas?▼

Use versioned migrations to create your core schema (organizations, projects, agents) and define RLS policies that enforce tenant isolation. Run migrations during deployment to initialize the schema and activate policies; pair migrations with sqlc for type-safe, tenant-aware queries.

What's the best way to scale multi-tenant PostgreSQL with connection pooling?▼

Use PgBouncer to pool connections and manage tenant context efficiently across requests. Set the current_setting on each connection to establish the tenant scope; PgBouncer forwards requests to PostgreSQL while RLS policies enforce isolation, reducing per-connection overhead at scale.

Do I need sqlc to implement multi-tenant data access patterns?▼

sqlc generates type-safe queries from SQL, reducing errors when building tenant-aware data layers. While not required, it integrates well with RLS policies and migrations to ensure queries respect tenant isolation and maintain consistency across your application and agent stacks.