liveBook · Manning

Tenant

As explained in Just Use Postgres!

A tenant is an independent customer or merchant whose data and operations are isolated within a shared multitenant system.

A tenant is an independent customer or merchant whose data and operations remain isolated inside a shared multitenant SaaS application. A brewery and a coffee chain can use the same eCommerce platform without sharing business data. section 2.1.1

Postgres multitenancy commonly separates tenant data at three levels:

  • Table level: store all tenants in shared tables and distinguish records with a tenant_id column. section 2.1.1
  • Schema level: give each tenant dedicated tables within its own schema in one logical database. section 2.1.1
  • Database level: give each tenant a dedicated database object, protected through roles and permissions. section 2.1.1

Separate merchant databases

Create one database for each merchant, then verify the instance contents: CREATE DATABASE coffee_chain; CREATE DATABASE brewery; SELECT datname FROM pg_database; The result lists both tenant databases alongside PostgreSQL’s default databases. Connecting with \c coffee_chain switches the session to the coffee-chain tenant.

How Just Use Postgres! covers it

How deep it goes
Defines tenants, compares table, schema, and database isolation, and demonstrates database creation without covering full administration.
Examples
Uses brewery and coffee-chain merchants, separate Postgres databases, database inventory output, and a connection command.
What you can do after
Operate database-level multitenancy by creating merchant databases, listing them, and connecting to a tenant database.
How it connects
Connects tenants with multitenancy, SaaS, schemas, databases, roles, permissions, and data isolation.

Also explained in

Compare how 4 books explain tenant →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.