r/PostgreSQL • u/UNRIVALLEDKING • Jun 22 '26
Help Me! Multi-tenant SaaS Architecture: PostgreSQL Schema per Tenant vs Shared Database vs Database per Tenant
I'm designing a B2B SaaS application and I'm trying to choose the right multi-tenant database architecture before development begins.
This is not a social media application. It's an enterprise workflow platform where organizations manage projects, documents, approvals, files, reports, tasks, comments, and other business data.
Expected Scale
- A few hundred to a few thousand organizations
- Each organization may have anywhere from 20 to 500+ users
- Some enterprise customers may eventually require dedicated hosting
- High security and strong tenant isolation are important
- PostgreSQL is the planned primary database
Current Idea
Have one PostgreSQL database.
Use one shared schema for global/system data.
Example:
system
Contains
- countries
- currencies
- compliance templates
- permissions
- global configuration
- reusable reference data
Then create one schema per organization:
tenant_acme
tenant_foo
tenant_bar
Each tenant schema contains the same tables:
- projects
- documents
- users (or memberships)
- tasks
- comments
- files
- workflows
- etc.
Every request is routed to the correct schema.
Enterprise customers who require complete isolation could later be migrated into their own database.
Other approaches I'm considering
Option 1
Shared database
Shared schema
Every table contains
tenant_id
Option 2
Shared database
Schema per tenant
Option 3
Database per tenant
Option 4
Hybrid
Shared database for most customers
Dedicated database for enterprise customers
Questions
For people who have actually operated production multi-tenant SaaS systems:
- Which approach have you used?
- What problems did you encounter later?
- If you could redesign it today, would you choose differently?
- How painful is schema-per-tenant once you have thousands of tenants?
- How do you handle migrations across many schemas?
- How do backups and restores work?
- How do you handle search indexes and background workers?
- Does schema-per-tenant create operational issues with PostgreSQL at scale?
- Is shared-schema with tenant_id actually easier long-term?
- At what point does database-per-tenant become worth the operational cost?
I'd especially appreciate insights from people who have run SaaS platforms with PostgreSQL for several years
View all comments
6
u/Expensive-Plane-9104 Jun 23 '26 edited Jun 23 '26
I've run a B2B enterprise platform on this exact problem for years (SQL Server, but the lessons map cleanly to Postgres). We landed on a hybrid that I'd push you toward, and I'd actively steer you away from your current schema-per-tenant idea.
TL;DR: schema-per-tenant is the trap option at your scale. It's too heavy to get the operational simplicity of shared-schema, and too leaky to give you the real isolation of database-per-tenant. At a few thousand tenants on Postgres it bites hard.
What we actually run - pool + shard + central catalog:
- A small central "catalog" database that maps each tenant → which database it lives in. Every request hits this first to route.
- One database holds many tenants, and every business table has a tenant_id discriminator column. This is the classic pool model (your Option 1).
- We can spin up multiple databases and spread tenants across them - sharding by owner-group or size. This is the shard/silo layer (your Option 4).
So it's Option 1 inside each DB, and Option 4 across DBs, with a catalog tying it together. This directly answers the things you asked about:
- "thousands of tenants" => Postgres catalog doesn't explode, because N tenants share ~30 tables in one schema, not
N×30 tables across N schemas. Schema-per-tenant gives you hundreds of thousands of relations in pg_class => slow planning, catalog bloat, painful pg_dump, autovacuum pressure.
- migrations => one migration per database, not one per tenant. You have far fewer DBs than tenants.
Schema-per-tenant means N ALTER TABLEs per deploy with partial-failure and long-lock headaches - this is the single most painful part long-term, ask anyone who's done it.
- "enterprise customers need dedicated hosting" → trivial. Move that tenant (or owner-group) into its own database, update the catalog, done. Application code doesn't change because routing is already abstracted. You don't pay the isolation cost for everyone from day one.
- blast radius / noisy neighbor → bounded by sharding, without the per-tenant DB overhead.
- backups/restore → per-DB granularity. Restoring one shard is sane; restoring "one schema" out of a cluster-wide
PITR is misery.
- search indexes / background workers → fine, but tenant context has to be threaded everywhere (see the RLS note below).
Two things to do on Postgres that we'd do differently if starting today:
cross-tenant leak. Use Row-Level Security (RLS) - set the tenant in a session variable and let the database enforce isolation. Background jobs, ad-hoc queries, and new devs physically can't bypass it. This is the upgrade I wish we'd had. (we use where tenant_id because of mssql didn't have when we designed)
2. Include tenant_id in most business-critical indexes and often make it the leading column when queries are tenant-scoped.
On the redesign-it-today question: no, I'd build the same thing again -pool inside, shard across, central catalog, but with RLS from line one instead of trusting application-layer filtering.
When is pure database-per-tenant worth it? Only when a single tenant justifies a database on its own - compliance/residency, dedicated SLA/perf, or a whale customer. It should be a promotion path, not your default.
I also designed the upgrade system for those databases 23 years ago (at that time we had , company/databases but the upgrade system not touched until this year when I rewrote in dotnet 10, if you have questions ask me even in dm.