Multi-tenant SaaS on PostgreSQL: shared tables, schemas or databases

Choosing a PostgreSQL tenancy model decides how you run migrations, backups, isolation and cost for every customer. This page compares the three models and what each one changes in operations.

On this page

Multi-tenant SaaS on PostgreSQL: which tenancy model fits your product

If you run a SaaS product on self-hosted PostgreSQL, you are choosing between three ways to separate customer data: shared tables with a tenant key, a schema per tenant and a database per tenant. The choice shapes how you run migrations, how you take and restore backups, and how exposed each customer is when another customer's workload consumes the database's CPU, memory or I/O. It is also hard to reverse once customers depend on it, because moving data between models later means a data migration for every tenant.

In the shared model, every tenant's rows live in the same tables and carry a tenant identifier, usually a tenant_id column that every query filters on. This is the cheapest model to operate and the easiest to migrate, since one schema change applies to everyone. The risk is isolation: a missing filter leaks data, so teams usually add PostgreSQL row-level security policies as a second barrier. A schema per tenant gives each customer its own namespace of tables, selected with search_path. Teams often pick it when customers need separate table-level grants or customizations, but schema migrations must then run against every schema, and the PostgreSQL schemas documentation warns that placing a schema on search_path effectively trusts every user with CREATE privilege on it. A database per tenant gives the strongest logical separation and the simplest per-customer restore, at the cost of many connection pools, catalogs and backup jobs to manage.

Before you commit, confirm the following with your own workload: how many tenants you expect and how fast that number grows, whether any customer has contractual requirements for dedicated data or per-customer restore, how large the largest tenant is compared with the rest, and how your release process will apply a migration to every tenant without a long outage. Ask your compliance team which isolation evidence auditors will expect for your SOC 2 or other assessment scope, because that answer often decides the model before the engineering trade-offs do.

How the three tenancy models differ in practice

All tenants share the same tables, and each row carries a tenant key such as tenant_id. Isolation is enforced by the application's queries and, when you add it, by row-level security policies that filter rows based on a session setting. Because one set of tables serves every tenant, a schema change runs once and touches every customer at the same time, so the migration plan has to account for the largest tables and the longest locks. Backups are taken for the whole database, so restoring a single tenant's data means extracting its rows from a full restore, which is slower and needs careful handling of related rows.

  • Isolation: Enforcement depends on every query filtering by tenant. Row-level security adds a database-side check, but policies must be tested for default-deny behavior and must not be bypassed by the table owner or roles with BYPASSRLS.
  • Schema changes: One migration covers all tenants, which keeps versions identical but makes every change a shared-risk event.
  • Per-tenant restore: Usually requires a point-in-time restore to a separate instance followed by a targeted data extraction.
  • Noisy neighbors: A heavy tenant's queries share buffers, connections, CPU and I/O with everyone else. Indexes that lead with the tenant key and query limits help, but they do not remove contention.
  • Offboarding: Deleting one tenant means deleting across many tables, which affects vacuum and index bloat.

Check whether your product needs per-tenant restore commitments, whether your largest tenants will need dedicated capacity, and whether your security reviewers accept database-enforced row filtering as the primary control.

Which tenancy model fits which product shape

This table compares shared tables, schema per tenant and database per tenant across tenant count, isolation, schema change, restore, noisy neighbors and operations. Read each row against your own product shape, then test the tenant counts and change rates you expect before committing.

FactorShared tables with tenant keysSchema per tenantDatabase per tenant
Tenant countSuits large numbers of small tenants, since one set of objects serves everyoneSuits moderate tenant counts; catalog size and per-schema objects grow with each tenantSuits few, high-value tenants; each database adds its own connections, memory and maintenance overhead
Data isolationRelies on tenant_id filters and row-level security policies; a missed filter or exempt role can expose rowsSeparates tables by name; isolation depends on search_path and privilege grants, not only on queriesStrongest logical separation; cross-tenant access requires a separate connection
Schema change frequencyOne migration updates every tenant at once, so a failed change affects all tenantsMigrations must run in every schema; a partial run leaves tenants on different versionsMigrations run per database; rollout must be tracked tenant by tenant
Per-tenant restoreRestoring one tenant means extracting rows from a shared backup, which takes careful toolingA single schema can be dumped and restored, but shared objects still need careRestoring one tenant is straightforward, the most direct option for per-customer recovery
Noisy-neighbor exposureHighest: one tenant's heavy queries or bulk writes affect shared indexes, cache and vacuumModerate: schemas share one server's CPU, memory, I/O and autovacuum workersLowest on the shared database, but total server resources still need planning
Operational overheadLowest per tenant; the cost is in careful query design and policy testingModerate; tooling must iterate schemas and monitor each oneHighest; backups, monitoring, upgrades and connection pools multiply with each database
Best fitMany similar tenants, standard schema, strong engineering controls on tenant filtersMid-sized tenant base needing separation and per-tenant customization without full database sprawlRegulated or large tenants that need dedicated recovery, residency or strict isolation

What each model does to migrations, backups and noisy neighbors

The three tenancy models do not fail in the same places. Schema migrations, recovery granularity, backup scope and shared resources each shift depending on whether tenants share tables, schemas or databases. Read the cards together, since a choice that simplifies one operation often makes another harder.

Running schema migrations across tenants

With shared tables, one ALTER TABLE changes every tenant at once, so a single review and a single rollout cover the fleet. With a schema per tenant or a database per tenant, the same change must run once for each schema or database, and the migration tool has to track which ones succeeded. Ask how long a fleet-wide migration takes at your tenant count, whether it can resume after a partial failure, and how a locked table in one tenant affects the rest.

Per-tenant point-in-time recovery

PostgreSQL point-in-time recovery restores a whole cluster from a base backup plus archived WAL files. It does not restore one tenant's rows on its own. In a shared-table model, recovering one tenant usually means restoring the cluster elsewhere and copying that tenant's data back, which must be tested. Databases per tenant make single-tenant restores simpler, but only if you can restore each database to its own point in time without disturbing the others.

Continuous archiving docs

Backup scope and restore time

A single cluster backup covers every tenant in one job, which is simpler to schedule and verify but makes the restore of one tenant slower and larger. Per-database or per-schema dumps give smaller units to restore, though each needs its own schedule and consistency checks across many objects. Ask your team to measure restore time for the largest tenant, not the average, and to confirm that the restored data is consistent across any cross-tenant reference tables.

Connection pool sharing

Every database per tenant needs its own pool entries and server connections, while shared tables and schemas can use one pool in front of one database. PgBouncer keeps client connections separate from server connections, so many tenants can share a small set of server connections. Check the pooling mode you choose, since session state set per tenant, such as search_path, behaves differently under transaction pooling. Confirm this with your pooler settings before go-live.

PgBouncer project

Resource contention from large tenants

In a shared database, one tenant running heavy reports or a large bulk import can use CPU, memory, I/O and locks that all other tenants depend on. Separate schemas on one server share these resources just as shared tables do. Databases per tenant still share the instance unless you place large tenants on separate servers. Plan per-tenant limits, monitor query time by tenant, and decide in advance which tenants get dedicated capacity.

Blast radius of a failed change

A bad migration, a dropped index or a runaway query in a shared model can affect every tenant at once. Separate databases limit that impact to the tenants on the affected instance, but they multiply the number of instances you must patch and monitor. Define which change classes need a canary tenant first, and agree on a rollback path that does not depend on a full cluster restore.

How to choose a tenancy model

The decision path starts with regulatory and isolation requirements, since a contract or regulator may rule out shared tables before cost is considered. The next question is how many tenants the product will carry and whether individual tenants need their own restore points or data residency. Those answers lead to shared tables with tenant keys and row-level security, a schema per tenant with search_path, or a database per tenant. Teams with a mix of small pooled customers and a few large dedicated ones can split the path into both models. Check each branch against your migration tooling and backup plan before committing.

Decision path from isolation requirements to a tenancy model.

How shared tables with tenant keys and row-level security work

In a shared-table model, every tenant's rows live in the same tables, and the tenant_id column is what separates them. Each tenant-scoped table should carry a non-null tenant_id column, and the primary key and most indexes should lead with that column, for example a composite primary key on (tenant_id, id) and indexes such as (tenant_id, created_at). Queries filtered by tenant then use a narrow index range, and a tenant with heavy activity does not force the planner to scan rows that belong to everyone else. Confirm the query shapes your application actually runs against each large table before you commit to an index set, because a composite key also changes foreign keys, unique constraints and the way you generate identifiers.

Application filters are not a security boundary on their own, so the database should enforce isolation. Row-level security (covered in depth on the sibling topic, PostgreSQL row-level security for multi-tenant applications) attaches policies to a table, usually comparing tenant_id with a session setting that the application sets when a connection is opened. Use ALTER TABLE ... ENABLE ROW LEVEL SECURITY and FORCE ROW LEVEL SECURITY so the policy applies to the table owner as well. Table owners and roles with the BYPASSRLS attribute skip policies, so the application should connect as a role that is neither the owner nor a BYPASSRLS role, and migration and admin roles should be kept separate from it.

Policies are easy to write incorrectly, so test them before go-live. Create two tenants with overlapping identifiers, connect as the application role, and confirm that reads, updates and deletes against the other tenant return no rows or fail, and that inserts with a foreign tenant_id are rejected by the WITH CHECK clause. Repeat the tests for every new table in each migration, and include them in continuous integration. Ask your team which role runs background jobs and reporting, since those connections are a common path around the policy.

How to set up a tenancy model on self-hosted PostgreSQL

This sequence turns a tenancy decision into a running PostgreSQL setup where isolation, migrations, backups and capacity behave the way the design assumes, and each stage ends with a check you can verify.

  1. Document isolation and restore requirements

    Before choosing a model, write down which tenant data must be isolated from others, which tenants have contractual or regulatory restore commitments, how a single tenant can be restored without touching the rest, and how many tenants and what size range you expect. Involve your security, compliance and customer success leads, since they will answer the questions auditors and enterprise customers ask. The output is a short requirements register that names each isolation and restore expectation. Check it by confirming each requirement can be tested later, for example a single-tenant restore with a named recovery target.

  2. Pick the tenancy model

    Compare shared tables with a tenant key and row-level security, a schema per tenant with search_path, and a database per tenant against the requirements register. Weigh the migration effort across all tenants, backup granularity, connection management and how a large tenant can crowd out others. Record the decision and the conditions that would trigger a change, such as a tenant that needs its own data residency. Check it by getting sign-off from engineering, security and product on a one-page decision record.

  3. Define tenant identifiers and naming

    Decide how tenants are identified in the database: a stable tenant_id column type, a schema name derived from an immutable slug, or a database name. Keep identifiers independent of display names, so renames do not break routing or backups. Define a reserved-name list and a validation rule so that generated schema or database names cannot collide with system objects or inject SQL. Check it by running the naming rules against edge-case names in a test environment and confirming every generated identifier is quoted or validated.

  4. Create roles and privilege boundaries

    Create a migration owner role, a runtime application role without DDL rights, and a read-only reporting role. Revoke default CREATE privileges on the public schema from ordinary roles and grant only what each tenant path needs. For schema-per-tenant designs, confirm that the application role cannot create objects in tenant schemas it should not write to. Check it by connecting as the runtime role and attempting DDL and cross-tenant reads, expecting each attempt to fail.

  5. Configure search_path or row-level policies

    For schema-per-tenant designs, set search_path per connection or transaction, and keep it free of schemas a tenant should not reach. The PostgreSQL schemas documentation warns that adding a schema to search_path effectively trusts every user with CREATE privilege on it, so keep CREATE locked down. For shared tables, enable row-level security on each tenant table, write policies keyed on the tenant identifier, and test them as the runtime role. Decide with your security team whether table owners and BYPASSRLS roles are exempt, and document that exemption. Check it by running a test suite that reads and writes across tenants as the runtime role and confirms zero leaked rows.

  6. Build the per-tenant migration runner

    Write a runner that applies schema migrations to every tenant, whether that is each schema or each database or each shared table set. Record applied versions per tenant, make each migration idempotent where possible, and stop and report on the first failure instead of continuing silently. Include a dry-run mode and a way to pause rollouts for named tenants. Check it by running the migration set against a fleet of test tenants, including one deliberately broken tenant, and confirming the runner reports the failure and the version table matches reality.

  7. Configure backups and restore tests

    Set up base backups and WAL archiving so point-in-time recovery is possible at the database level, and decide how tenant-level restores will be done for each model. For shared tables this usually means logical extraction filtered by tenant, for schemas it may mean schema-level dumps, and for databases it is database-level restore. Store copies off site and run restores into an isolated environment on a schedule. The PostgreSQL continuous archiving documentation describes how base backups combine with archived WAL. Check it by restoring one tenant into a scratch environment, comparing row counts and checksums to the source, and recording the elapsed time.

  8. Load-test with a large tenant

    Create a test dataset with one tenant much larger than the rest, and run representative queries, writes, migrations and a backup concurrently. Watch connection use through PgBouncer or your pooler, query latency for small tenants, lock waits during migrations, and vacuum activity on the largest tables. Use the results to decide whether the large tenant needs dedicated resources, a separate database, or stricter per-tenant connection limits. Check it by confirming that small-tenant latency stays within the target your product owners set, and that the decision on the large tenant is written down with the measurements behind it.

Security and operational risks to control

Each tenancy model fails in different places, but the failures share a pattern: a tenant boundary that depends on one setting, one grant or one manual step. The cards below cover the risks to design out before go-live and the checks to repeat after every release.

Cross-tenant reads from search_path and policies

In a schema-per-tenant design, a request that runs with the wrong search_path reads another tenant's tables without any error. In a shared-table design, a missing tenant predicate or a policy that never applies returns rows from every tenant. Check that the connection sets search_path explicitly for each request, that no default or fallback path reaches shared objects, and that a test suite fails when tenant A can read tenant B's rows. Illustrative example: a background job that omits the tenant context returns an unscoped result set with no error raised.

Schemas docs

CREATE privilege on shared schemas

PostgreSQL's default search_path is "$user", public, and the documentation warns that adding a schema to search_path trusts every user with CREATE privilege on that schema. In a multi-tenant database, a tenant role that can create objects in public or a shared schema can plant functions or tables that shadow legitimate ones. Revoke CREATE on public from general roles, keep tenant roles out of shared schemas, and confirm the grants with a query against the catalog rather than assuming the defaults.

Schemas docs

Role sprawl across databases

A database-per-tenant model multiplies roles, grants and default privileges. Each new tenant adds login roles, group memberships and ownership records that drift apart over months of onboarding and offboarding. Orphaned roles keep access after a contract ends, and an owner role that bypasses row-level policies can leak data. Keep one role template applied by automation, review role membership on a fixed schedule, and remove the roles of departed tenants as part of the offboarding checklist.

Credential handling for per-tenant connections

Per-tenant connections need credentials for each tenant, a pool that stores them and a rotation process. A connection pooler shared across tenants can hand one tenant's session to another if session state or role switching is configured loosely. Decide where credentials live, which component holds them at runtime, how they rotate without downtime, and whether TLS and SCRAM authentication are enforced for every tenant role. Confirm pooler session reset and role handling against the current PgBouncer documentation before relying on them.

PgBouncer site

Audit logging per tenant

Audit records must show which tenant a query touched, under which role, and when. In shared tables, the tenant identifier is often absent from the database log, so the application must add it, and the database log alone cannot prove isolation. In schema-per-tenant or database-per-tenant designs, logs can be filtered by role or database, but they still need a retention period set by your compliance obligations. Confirm what your logging captures for each tenant and who can read those logs, since audit trails themselves can expose data.

Tenant data export and deletion procedures

Export and deletion requests reach every table that holds a tenant's data, including backups, replicas and archived WAL. A shared-table design needs a scripted, tested delete that covers every table with a tenant key, while a database-per-tenant design makes export a dump of one database but complicates restores that include other tenants. Document which copies are removed immediately, which expire with backup retention, and how a deleted tenant's data is excluded from a later point-in-time restore. Ask counsel to confirm the obligations that apply to your customers and jurisdictions.

Questions teams ask before choosing a tenancy model

What drives the cost of designing a multi-tenant PostgreSQL model?

The design cost follows the amount of decision work and the number of systems that depend on the tenancy choice, not the database itself. The main drivers are how many tenants and data types exist, how many services query the database, whether tenants need isolated backups or regional placement, and how much existing application code assumes one model. Expect a written scope to separate the tenancy design, the policy or schema build, the test harness and the handover documentation, since each is priced differently. Ask for a fixed scope and quote that names each deliverable, the systems in scope and the assumptions about your current codebase. DeployOpen does not publish a price list; a quote follows from that written scope.

How long does a migration to a different tenancy model take?

Duration depends mainly on the size of the data to move, the number of tenants, how much downtime the product can accept, and how many queries and migrations must change. Moving from shared tables to a schema or database per tenant usually needs a tenant-by-tenant data copy, a routing layer and a rewrite of every query path that assumed one schema, which makes it the longest path. Moving in the other direction often means consolidating schemas and adding tenant keys, which carries its own backfill and index work. No duration is given here because none was supplied for this topic. Ask for a timeline in the written scope that lists the cutover method, rollback steps and the tenants moved in each wave.

What must our team provide before a tenancy design project starts?

The team needs to supply the data model, the list of tables that carry tenant data, the current query patterns and the migration history, because these determine whether a shared, schema or database layout fits. You also need named owners for the application, the database and the security review, plus access to a staging environment that holds realistic but non-production data. For regulated products, provide the list of compliance obligations that apply, such as the SOC 2 scope your auditor has agreed or the GDPR processor terms you already use with customers. Confirm access rights and change windows in writing before work starts, so the scope and timeline reflect what your team can actually release.

Can our in-house team design and build the tenancy model without a partner?

Yes, many teams do this internally, especially when they already run PostgreSQL in production and have engineers who know row-level security, search_path behavior and backup tooling. The questions to answer honestly are whether the team has time to test policies and migrations at tenant scale, whether it can staff an independent review of the design, and whether the same people will operate the result for years. An outside partner adds value mainly as an independent review, a test plan and a documented handover. Compare the internal effort against a written scope from a partner, and decide which parts, such as policy testing or migration rehearsal, you want to delegate.

How do SOC 2 scope and GDPR processor terms affect the choice of tenancy model?

Both regimes care about how tenant data is separated, who can access it and how it is returned or deleted. SOC 2 examinations use the AICPA 2017 Trust Services Criteria, and the common criteria CC1 to CC9 apply to every SOC 2, so the controls that enforce tenant separation, access and change management fall within the examined system. A database per tenant can simplify evidence for some controls, but it multiplies the systems to monitor and back up. GDPR Article 28(3) requires processor contracts to limit processing to documented instructions and to cover security of processing under Article 32, which applies whichever model you choose. DeployOpen prepares systems and evidence for assessments but does not issue audit reports; your auditor decides the scope.

What changes for operations, backups and noisy neighbors after the move?

The model you pick changes how you back up, restore and isolate workload. With shared tables, one backup restores everything, but restoring a single tenant needs careful filtering and a clear rule for dependent data. With a database per tenant, tenant-level restores are simpler, but backup jobs, monitoring, connection pools and schema migrations multiply with the tenant count. Noisy neighbor risk is highest in shared tables, where one tenant's heavy queries affect others, and it is managed with per-tenant limits, indexes that include the tenant key and connection pooling with PgBouncer. Plan for a restore test per model, because a backup that has never been restored is not evidence of recovery. Also confirm the schema migration process, since changes must reach every schema or database in the same release.

Which tenancy model should an engineer check first for search_path risks?

Start with the schema-per-tenant model, because it depends on the search_path setting and PostgreSQL warns that adding a schema to search_path effectively trusts all users with CREATE privilege on that schema. Check that application roles cannot create objects in schemas they should not write to, and that the default search_path does not place tenant schemas ahead of trusted ones. Review the connection pooler setup as well, since session-level search_path changes can leak between pooled clients if they are not reset. Shared-table designs avoid this class of risk but depend on correct tenant keys and row-level security policies. Write these checks into the test plan so they run with each migration.

Limits to confirm in your own environment

A tenancy model holds up only if the limits around it hold up at your tenant count, data size and connection load. The cards below cover the numbers and scope questions to test on your own hardware and with your own auditors before you choose a model.

Tenant count and database size

Schema-per-tenant and database-per-tenant designs multiply the objects PostgreSQL must track, including tables, indexes, roles and catalog entries. Load a realistic number of tenants into a staging cluster and measure how long migrations, backups and catalog queries take as that count grows. Also test the largest tenant's data volume against your restore time target, because a single oversized tenant can dominate a shared cluster. Ask your team to write down the tenant count at which the chosen model needs revisiting.

PgBouncer pooling mode choice

PgBouncer offers session, transaction and statement pooling, and each one interacts differently with per-tenant search_path settings, session variables used by row-level security, and prepared statements. Transaction pooling reuses server connections across tenants, so any session-level tenant context must be set inside each transaction. Test the pooling mode with your exact application driver before go-live. Confirm the PgBouncer version you deploy includes current security fixes, since PgBouncer 1.26.1 was released on October 14, 2026 with security fixes.

PgBouncer site

Connection limits per database

Each tenant database or schema-based connection pattern can multiply connection counts, and PostgreSQL's connection limit is shared across the whole cluster. Set max_connections and per-database or per-role limits deliberately, and size the pooler so that tenants cannot exhaust server slots. Load test with many tenants active at once to find where connection queuing starts to hurt latency. Record the limit values you chose so that a later capacity review can see the reasoning behind them.

Version support windows

Each PostgreSQL major version receives community support for a fixed period, and the window determines how long a tenancy design can run without a major upgrade. Schema-per-tenant estates are slower to upgrade because each migration must run across every schema, so plan those runs against the support end dates. As of the supported version list, PostgreSQL 14 is supported until November 12, 2026, and PostgreSQL 18 until November 14, 2030. Confirm which version you will run at launch and when you intend to move to the next one.

Versioning policy

Regulatory scope questions

Whether your tenancy model affects SOC 2, NIS2, GDPR or other obligations depends on your product, your customers and your jurisdictions, and no general rule settles it. Ask your auditors whether logical separation through tenant keys, schemas or databases satisfies the control objectives you have committed to, and whether any tenant-specific data residency or deletion commitments change the design. Document the answers in writing rather than assuming that one model is accepted everywhere. A SOC 2 report is issued by an independent CPA firm, so the auditor's view is the one that counts.

How tenancy choices affect SOC 2 and GDPR evidence

The tenancy model decides which controls you must show an auditor and how you produce the access evidence. In a shared-tables design, every tenant's rows sit in the same tables, so the evidence centers on the tenant key, row-level security policies and the roles that can bypass them. In a schema-per-tenant design, the evidence centers on search_path settings, schema ownership and the privileges that let one application role reach another tenant's schema. In a database-per-tenant design, access is separated at the connection and role level, and the evidence centers on how many databases exist, who holds credentials for each and how provisioning is recorded. Each model asks for different proof that tenant data stays separate, so pick the model with the evidence you can actually produce in mind.

SOC 2 examinations assess the Trust Services Criteria, and the security common criteria (CC1 to CC9) apply to every SOC 2 report. Without naming individual control IDs here, the practical question is the same for all three models: can you show that logical access is granted on approved requests, reviewed on a schedule and removed when people or tenants leave? For shared tables, a reviewer will ask who can run BYPASSRLS or table owner queries and whether FORCE ROW LEVEL SECURITY is set. For schemas, the PostgreSQL schema documentation warns that adding a schema to search_path trusts every user with CREATE privilege on it, so confirm that privilege is revoked and that the setting is reviewed. Confirm with your auditor which evidence they expect for your report type and period, since a Type 1 and a Type 2 report ask for different proof.

GDPR Article 28 requires a written contract with any processor that handles personal data for you, including a hosting or managed database provider. In plain terms, that contract must say the processor acts only on your documented instructions, including for transfers, and must commit it to the security measures Article 32 requires. Your tenancy model affects what you can document: a shared database makes it harder to show which tenant data a given operator touched, while database-per-tenant can make per-customer deletion and export simpler to demonstrate. Ask your hosting partner which PostgreSQL logs, role records and backup locations they can produce per tenant, and confirm with your privacy counsel what the contract must name. DeployOpen prepares systems, controls and evidence for assessments, but it does not issue audit reports or attestations, and independent auditors decide what your report says.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.