IT and security
How Database-Enforced Tenant Isolation Works in Postgres
By Yvion SpacePublished Updated 4 min read
The short answer
Personal Academy keeps each organisation’s data apart inside the database itself. Every business table carries a tenant_id column (the organisation that owns the row) and a restrictive policy named tenant_boundary. Postgres checks that policy on every query, so the rule does not depend on application code remembering to filter.
The rest of this article explains why that matters, how it works, and where it stops.
Why a filter in application code is not enough
On a shared platform, many customers’ rows sit in the same tables. The common approach is a convention: every query adds a condition such as "where the organisation is the current one". It works until someone forgets it. One reporting endpoint, one export, one new feature written in a hurry, and a query returns rows from another customer.
A convention is only as strong as the least careful query. The safer design makes the database refuse the read, so a forgotten filter returns nothing instead of leaking something.
How the rule works here
Row-level security (RLS) is a Postgres feature. You attach policies to a table, and the database applies them to every statement from signed-in users. Our tenant_boundary policy says a row is visible and writable only when its tenant_id equals the caller’s current organisation. It covers reads, inserts, updates and deletes.
The policy is restrictive, which matters. Postgres combines ordinary (permissive) policies with "or", so a policy written too loosely can open access wider than intended. A restrictive policy is combined with "and". Even if a later feature adds a permissive policy that is too generous, the organisation check still applies on top of it.
When a row is inserted without a tenant_id, a database trigger fills it in from the caller’s organisation, so application code cannot forget to set it. The caller’s organisation is worked out by one database function from the signed-in session, or from an open support session for platform staff, or from the person’s active membership.
Permissions sit on top. Whether a person may see a row inside their own organisation goes through the same permission check in the database and in the application, rather than through a role name written into code.
Where it does not apply
Row-level security does not cover everything, and it is better to say so. Server-side jobs, such as scheduled reports and background workers, use a service account that bypasses the policies, so that code has to scope its own queries. A few platform-wide tables, such as shared catalogues, have no tenant column because they hold no customer data.
Staff access is a separate control. Platform staff can enter a customer’s organisation only through a time-boxed support session that needs a stated reason and is recorded against the named person in the audit log.
Isolation is also not a certification. No independent penetration test has been commissioned yet, and the security page says so. What we can show is the design, and automated database tests that check the boundary.
Questions to put to any vendor
Ask where separation is enforced: in the database, or only in application code. Ask what bypasses it, and how those paths are controlled. Ask who at the vendor can reach your data, how long that access lasts and where it is logged. Ask how the boundary is tested, and how often.
The security questionnaire tool has pre-answered questions for an IT reviewer, and the RFP template gives you questions to put to every vendor on your shortlist.
Questions
What is tenant isolation?
Tenant isolation means one customer can never read another customer’s rows on a shared platform. A filter written in application code depends on every developer remembering it on every query. Row-level security makes the database itself check the organisation on every read and write.
How does Postgres row-level security work?
You attach policies to a table, and Postgres applies them to every statement from signed-in users. Personal Academy’s tenant_boundary policy says a row is visible and writable only when its tenant_id equals the caller’s current organisation. It covers reads, inserts, updates and deletes.
Why is the policy restrictive?
Postgres combines ordinary permissive policies with “or”, so a policy written too loosely can open access wider than intended. A restrictive policy is combined with “and”, so even if a later feature adds a generous permissive policy, the organisation check still applies on top of it.
What does row-level security not cover?
Server-side jobs such as scheduled reports use a service account that bypasses the policies, so that code has to scope its own queries. Isolation is also not a certification, and no independent penetration test has been commissioned yet. Ask any vendor what bypasses isolation and how it is tested.
Related tool
Security questionnaireFree to use on this site.Related