PostgreSQL Schemas

A schema is a namespace inside a database. It helps organize database objects like tables, views, functions, and sequences.

Why schemas matter

  • Organize objects
  • Separate modules
  • Support multi-tenant design
  • Help with access control

Create a schema

CREATE SCHEMA app;

Grant access to a schema

GRANT USAGE ON SCHEMA app TO tenant_user;

Allow object creation in a schema

GRANT CREATE ON SCHEMA app TO tenant_user;

List schemas

\dn

Show schema privileges

\dn+