A multitenant SaaS application serves multiple customers from shared CPUs and storage while isolating each tenant’s data and access. A merchant is one tenant; its business data remains private from other merchants. section 2.1.1
Postgres supports three common multitenancy layouts:
- Table-level multitenancy stores all tenants in shared tables and distinguishes rows with a column such as tenant_id. section 2.1.1
- Schema-level multitenancy gives each tenant dedicated tables within one logical database. section 2.1.1
- Database-level multitenancy gives each tenant a dedicated database object, with access controlled through roles and permissions. section 2.1.1
Separate databases for two merchants
Treat a brewery and a coffee chain as separate tenants: CREATE DATABASE coffee_chain; CREATE DATABASE brewery; SELECT datname FROM pg_database; Connect to one tenant database with \\c coffee_chain. PostgreSQL then reports that the session is connected to coffee_chain, while the other tenant remains in its own database.
