← Back to blog

Updated 18 November 2026

Choose a Postgres schema strategy for authentication


The best Postgres schema strategy is the one that makes ownership obvious. Authentication records need consistent transactions, predictable migrations, and strict access from the application backend. For most products, one application database with a dedicated authentication schema gives that balance. It keeps user and session data close to the business records that reference them while giving migrations, permissions, and backups a clear boundary. More elaborate tenant layouts can be useful, but they should follow a proven isolation requirement rather than become the default architecture.

Start with the records that must agree

List the writes that need one transaction. Account creation may need an application profile, an organisation membership, and an audit record. Account deletion may need business data cleanup and authentication revocation. If these records must either all commit or all roll back, placing them in one database keeps the transaction boundary direct. Separate schemas still provide naming and permission boundaries without introducing distributed coordination. A separate database changes recovery, deployment, and consistency rules, so it needs a stronger reason than tidy table names.

Foreign keys also reveal the natural boundary. Application tables often refer to a stable user identifier or organisation identifier. A shared database can enforce those references directly. If authentication lives elsewhere, the application must replace database constraints with asynchronous checks, local copies, or failure recovery. That can be correct for a service boundary, but it is an operational choice with ongoing cost. Make it only when independent scaling, legal separation, or team ownership outweighs the simpler integrity model.

Use schemas for responsibility and permissions

A dedicated schema can separate authentication tables from product tables without separating the database itself. Migration tooling can target the authentication objects. Database roles can grant the application the exact access it needs. Reporting jobs can be kept away from credential fields. Backups still capture a consistent application state. The schema name should describe the product responsibility and remain stable across environments. Avoid a layout that depends on search path surprises, because an unqualified table name can resolve differently between migration, runtime, and administrative sessions.

Permissions should follow runtime duties. The application role needs the reads and writes used by authentication. A migration role may create and alter objects. Read only analytics should receive only approved fields or views. Human access should be exceptional and auditable. Do not grant broad ownership merely to make a migration pass. Schema ownership, table privileges, sequence privileges, and default privileges must agree, or a later table can silently receive different access from the tables already deployed.

Treat tenant isolation as a product decision

A table per tenant or schema per tenant can look attractive because the names appear isolated. In practice, every migration must reach every tenant, connection routing becomes part of authentication, and operational tools must discover a growing set of objects. Large tenant counts amplify that work. A shared table with explicit tenant identifiers is usually easier to migrate and query. Database policies can add protection, but they do not replace correct application authorization or a carefully scoped database role.

Separate databases can be justified for customers that require independent encryption, residency, backup, or restore boundaries. If that is the requirement, make provisioning, migrations, monitoring, and recovery part of the product before the first tenant uses it. Authentication cannot depend on a manual database selection that differs between requests. The tenant routing key must be authenticated, deterministic, and unavailable for arbitrary caller control.

Test recovery before committing to the layout

Restore practice is the clearest architecture review. Confirm that a backup can restore authentication records and the application records that depend on them to a consistent point. Confirm that migration order is deterministic. Confirm that a revoked session stays revoked after restore and replay. Confirm that tenant routing cannot attach one customer's request to another customer's database. A schema design is complete when ordinary deploys and difficult recovery events preserve the same ownership and isolation rules.

Postgres schema questions

Does every tenant need a separate Postgres schema?

Usually not. Shared tables with explicit tenant identifiers are simpler to migrate and operate. A separate schema or database needs a concrete isolation, residency, backup, or restore requirement that justifies the extra routing and migration work.

Why keep authentication and application records in one database?

One database can preserve foreign keys and transactions across account and product records. Separate databases are valid when service ownership requires them, but the team must then design consistency, recovery, and authorization across that boundary.