Skip to content
Learn Netverks

Lesson

Step 16/36 44% through track

schemas-postgresql

Schemas and namespaces

Last reviewed Jun 1, 2026 Content v20260601
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches Schemas and namespaces: the SQL patterns, schema habits, and query reasoning you need before advancing in PostgreSQL.

Teams query Schemas and namespaces on every PostgreSQL codebase—skipping it leaves gaps in debugging and data reviews.

You will apply Schemas and namespaces in contexts like: Modern startups, geospatial apps, and analytics-friendly OLTP systems.

Copy Postgres SQL into psql, local PostgreSQL, or DB Fiddle (PostgreSQL dialect)—use \d and EXPLAIN ANALYZE where lessons show them. The in-browser lab ships later; psql is the practice path now.

When you can explain the previous lesson's ideas without copying example queries verbatim.

Schemas group tables, views, and functions within a database—like folders. public is default; multi-tenant apps sometimes use one schema per tenant.

Creating and using schemas

CREATE SCHEMA IF NOT EXISTS billing;

CREATE TABLE billing.invoices (
  id BIGSERIAL PRIMARY KEY,
  amount NUMERIC(12,2) NOT NULL
);

SET search_path TO billing, public;
SELECT * FROM invoices;

Practice: Apply DDL in a throwaway practice database. Use \d table in psql to verify constraints and indexes.

search_path security

Always qualify object names in migrations and security definer functions—unqualified names resolve via search_path, which attackers can manipulate if careless.

Permissions per schema

GRANT USAGE ON SCHEMA billing TO app_role;
GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA billing TO app_role;

Important interview questions and answers

  1. Q: Schema vs database?
    A: Database is isolated connection boundary; schema is namespace inside a database.
  2. Q: Why SET search_path?
    A: Controls default schema resolution for unqualified table names.

Self-check

  1. What is the default schema?
  2. Why qualify table names in security-sensitive SQL?

Pitfall: Unqualified names in security definer functions—set search_path explicitly.

Interview prep

Schema vs database?

Database is connection boundary; schema is namespace inside it.

search_path risk?

Unqualified names resolve via search_path—security concern in functions.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • public schema?
  • search_path?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump