Every SaaS product makes one promise that matters more than any feature: one customer will never see another customer's data. In a multi-tenant system, where many customers share one application and one database, keeping that promise depends on every query in the code including the right filter. Miss it once, in one report or one background job, and the promise is broken.
PostgreSQL's row-level security moves that promise from the application code into the database. This is how we use it in practice, and the traps worth knowing about before you rely on it.
Three ways to separate tenants
A database per tenant. Strongest separation and easy to explain to security reviewers. But every schema change has to run on every database, and costs grow with the number of customers. Good for a small number of large customers with strict requirements.
A schema per tenant. Similar trade-offs, and very large numbers of schemas become hard to manage.
Shared tables with a tenant column. Every row carries a tenant_id .…