Databases & Schemas — Complete Guide
Databases & Schemas — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of PostgreSQL Tutorial on Toolliyo Academy.
On this page
PostgreSQL Tutorial · Lesson 6 of 100
Databases & Schemas
SQL → Advanced
SQL · 1 — Queries · ~6 min · PostgreSQL — Foundations
What is this?
A PostgreSQL cluster holds multiple databases; each database has schemas that namespace objects. The public schema is default, but apps often use sales, billing, or tenant-specific schemas to organize tables.
Why should you care?
A SaaS product on PostgresVerse might keep shared reference data in public while isolating each tenant module in its own schema for cleaner permissions.
See it live — copy this example
Run in pgAdmin or psql.
CREATE SCHEMA IF NOT EXISTS billing;
SET search_path TO billing, public;
CREATE TABLE billing.invoices (
invoice_id bigserial PRIMARY KEY,
amount numeric(12,2) NOT NULL
);
What happened?
- CREATE SCHEMA makes a namespace.
- search_path tells PostgreSQL where to resolve unqualified names.
- The table lives in billing, not public, so you can GRANT schema-level access later.
Practice next
- Connect to PostgresVerse.
- Run CREATE SCHEMA IF NOT EXISTS billing;
- Run SET search_path TO billing, public;
- Create schema analytics and move a test table with ALTER TABLE ... SET SCHEMA.
- Run SHOW search_path; after changing it in pgAdmin.
Remember
Database = isolated catalog; schema = folder inside it. search_path controls default object lookup. Use schemas before multiplying databases.
PostgresVerse billing split
Finance wants invoices separated from catalog tables without a second database cluster.
Outcome: billing schema gets its own backup policy and read-only role.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!