PostgreSQL multi-company: three strategies to isolate customer data in a SaaS
Published on 2026-11-14 by frfrand
Compare databases per customer, independent schemas and shared tables with tenant_id and RLS, with security, cost and operational criteria.

If your SaaS serves multiple companies, the problem is not just storing an empresa_id column: it is ensuring that no error allows viewing or modifying another company's information. PostgreSQL offers three common architectures, with different development, deployment, and operational costs.
1. One database per company
Each client gets a separate database. This makes it easier to establish separate access policies, gradual migrations, and certain backup or restoration strategies per client. In return, the number of connections, resources, and operations you must manage grows.
It is appropriate when there are strong isolation requirements, specific client needs, or very different data sizes. It does not automatically eliminate application authorization failures.
2. One schema per company
Tables live within different schemas of the same PostgreSQL instance. You isolate names and structures, but share CPU, RAM, storage, and server administration. You must carefully review search_path, roles, permissions, and migrations: choosing the wrong schema can cause a leak.
This model can balance logical separation and cost, although a large number of tenants multiplies maintenance operations and schema changes.
3. Shared tables with tenant_id
Different clients share tables such as orders and users, with a tenant_id column per row. It simplifies migrations and joint analysis, but requires extreme discipline in queries and authorization.
Example conceptual design:
CREATE TABLE orders (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
tenant_id uuid NOT NULL,
external_ref text NOT NULL,
UNIQUE (tenant_id, external_ref)
);
CREATE INDEX orders_tenant_id_idx ON orders (tenant_id);
Composite uniqueness prevents clashes between company references. Add constraints between tables that include tenant_id to prevent accidental cross-relationships.
4. Isolation with Row Level Security
RLS allows applying row-level policies within PostgreSQL. For example, you can associate the current company with the connection or transaction and require that tenant_id matches that context. Implementing it requires roles without bypass privileges, correct read and write policies, and great care with connection pooling so that one client's context is not inherited by another.
Simply enabling RLS is not enough: policies may be missing and privileged users or owners may behave differently. Test cross-access attacks using a real application user.
5. Comparison for decision making
| Strategy | Advantage | Technical cost | |---|---|---| | Database per client | Stronger operational separation | Multiply backups, connections, and migrations | | Schema per client | Separate structure | Manage schemas, roles, and search_path | | Shared table | Schema simplicity and efficiency | Maximum attention to policies and filters |
For a new product with many small customers, shared tables with RLS and rigorous testing may be sufficient. For regulated or very large customers, it is worth studying greater separation.
6. Mandatory tests before launching
Create two tenants with deliberately similar data. Try to list, read, update, and delete objects from the other company, also using direct references. Verify permissions in exports, batch processes, queues, and administrative tasks. Ensure that backups and restorations respect the required separation.
Delve into Supabase RLS with examples, what is RLS in PostgreSQL and PostgreSQL at ArduMaker.
Frequently asked questions
### Is an independent database completely secure? It increases isolation, but does not replace application controls and credentials.
Does RLS replace backend authorization?
No. It complements access controls, it does not eliminate them.
Can I change models later?
Yes, but it requires planned migration of data, permissions, and application logic.
Reference: PostgreSQL Row Security Policies.