/tools

Multi-tenant architecture workbench

Compare shared-table, per-schema and per-database layouts. Review tenant-scoped keys and relationships, explore isolation scenarios and prepare SQL scaffolds. This browser does not connect to PostgreSQL or certify authorization.

Save each form before exporting or changing views. Saving/selecting restores other unsaved forms. Undo keeps 20 revisions; export JSON before reloading. All tenant/table/role identities below are design declarations.

Architecture comparison

Counts use the declared population and pool assumptions. They are not performance ratings or connection requirements inherent to a layout. Connection multiplexing, replicas, indexes and migration cost need a deployment-specific design.

Relationship boundaries

Architecture findings

    Isolation scenario

    This is a bounded expectation under the declared grants/policies, not a live permission test. Owner and superuser/BYPASSRLS scenarios are explicit. UPDATE requires both the existing row to match USING and the proposed row to match WITH CHECK. Schema/database scenarios depend on separate tenant-role grants and routing. Global lookup writes are not granted to application roles.

    Architecture assumptions

    Shared backend context is appropriate only when SQL is issued by an authenticated/authorized trusted backend. A client-settable app.tenant_id custom setting is not authentication. For direct SQL clients, the shared layout offers fixed tenant-role UUID policies. Schemas require privilege boundaries; databases on one cluster still share resources/WAL.

    Example tenant registry

    Example registry entries are not the entire planned population. Roles, schemas, databases and authentication must be provisioned separately. Tenant roles are distinct cluster-level identities; no passwords or role membership grants are generated.

    Table scopes

    Scaffold columns are application-supplied UUID id, JSONB attributes, optional business_key and relationship UUID fields. Shared tenant tables also have tenant_id. Per-schema/database scopes use local keys. Global lookups receive SELECT-only application grants. RLS/key flags are checked for shared tenant tables; other layouts use container privileges.

    Relationships

    Shared tenant-to-tenant FKs use (tenant_id, reference_id) → (tenant_id, id). Global references use id alone. Global-to-tenant references are rejected. Foreign keys use ON DELETE RESTRICT. Deleting a table retains affected references for visible repair.

    Layout decision reference
    Open tenancy design JSON
    SQL trust model, scope and limits

    Backend-context policies compare tenant_id with nullif(current_setting('app.tenant_id', true), '')::uuid in both USING and WITH CHECK. Missing/empty context denies rows; invalid UUID context can error. The backend must authenticate and authorize the selected tenant, prevent arbitrary client SQL, and set transaction-local context on the same acquired connection. Session-level settings can leak between pooled requests. Transaction pooling must pin the transaction. SQL injection/shared-role SQL clients can change a custom setting; this pattern is not authentication.

    Tenant-role policies bind a fixed UUID and exact current_user to each declared role. Test actual login/SET ROLE/membership/inheritance paths, superuser/BYPASSRLS, table ownership, existing permissive policies, global privileges, views, triggers and SECURITY DEFINER functions. FORCE RLS does not constrain superusers/BYPASSRLS. RLS does not cover TRUNCATE/REFERENCES; those are not granted here. Referential integrity and uniqueness checks can reveal existence through errors. The bounded scenario assumes only the declared grants and policies, with no additional objects or privileges.

    SQL creates a new scaffold for the selected layout. Shared layout emits all example tenant-role policies when that mode is selected. Per-schema/database layouts emit one selected tenant context plus global definitions for a new deployment; shared foundation definitions must not be blindly rerun for each tenant. Create application-owned schemas/roles/databases separately and execute as a separate owner. SQL revokes schema PUBLIC privileges and grants schema USAGE, tenant-table CRUD and lookup SELECT. Existing grants/default privileges are not fully reconciled. Public/system schemas are rejected. No passwords, role creation, role membership, database CONNECT changes, auth service, migration runner or provisioning job is generated. Database mode checks current_database before creating tables; lookup definitions/data synchronization are a separate design.

    Inspection SQL reads roles, memberships, owners and policies; it is not a complete effective-privilege audit or execution test. Test cross-tenant SELECT/INSERT/UPDATE/DELETE, composite FK attempts, missing/malformed context and connection reuse using actual app roles on a disposable database. Full SQL has not been executed by this browser.

    Limits: 1 MB; 50 example tenants, 30 tables, 100 relationships, planned population up to 1,000,000. Topology shows at most four example containers and 12 table labels/container; full registry/model remains in JSON and notes. Counts use integer assumptions, not measured capacity. Undo keeps 20 revisions. No input storage or transmission.

    Row security · Schemas · Databases