Schema
What is a schema in PostgreSQL?
A schema is a namespace inside a database that holds tables, views, functions and other objects. search_path decides where unqualified names are looked up.
A PostgreSQL database contains one or more schemas, and each schema contains tables and other named objects. The same table name can exist in different schemas, and you can refer to an object as schema.table. Every new database has a schema named public.
Schemas group related objects, let several users or applications share one database without name clashes, and make it easier to manage privileges. Unqualified names are resolved through search_path, which by default looks first for a schema named after the current user and then in public. In PostgreSQL 15 and later, ordinary users can no longer create objects in public by default.
Example
The example creates a billing schema, puts a table in it and changes search_path so the table can be used without the schema name.
CREATE SCHEMA billing;
CREATE TABLE billing.invoices (id int PRIMARY KEY);
SHOW search_path;
SET search_path TO billing, public;
SELECT count(*) FROM invoices;
RESET search_path;Plain SQL for stock PostgreSQL 16 or 17, no extensions needed. Run it in an empty database you can throw away.
Sources
Official PostgreSQL documentation (in English).