Printing and PDF export are disabled for this content. View it online at Full Stack Learning Simplified.
PostgreSQL Databasesπ± Beginner
A single PostgreSQL installation is known as a server (or cluster). Inside that server, you can host multiple isolated databases, which themselves contain schemas and tables.
What is the Hierarchy?
PostgreSQL organizes data structurally. Understanding this hierarchy is critical for managing permissions and architectural layout.
Database Layout
Database Server (Port 5432)
ββ Database: "ecommerce_db"
ββ Schema: "public" (The default workspace)
β ββ Table: "users"
β ββ Table: "orders"
ββ Schema: "analytics" (A custom workspace)
ββ Table: "yearly_reports"Why Use Schemas?
By default, when you create a table, it goes into a namespace called public. While one database per application is standard, schemas allow you to subdivide that database. You might use schemas to separate microservice tables (e.g., a billing schema vs an inventory schema) or to build multi-tenant applications where every client gets their own isolated schema.
How to Manage Databases and Schemas
You can create and destroy these structures using standard SQL commands:
sql
-- 1. Create a new database for your project
CREATE DATABASE ecommerce_db;
-- (Switch to it in psql using: \c ecommerce_db)
-- 2. Create a custom schema inside the database
CREATE SCHEMA analytics;
-- 3. Create a table explicitly inside that new schema
CREATE TABLE analytics.yearly_reports (
id SERIAL PRIMARY KEY,
report_data JSONB
);Critical Warning: The command
DROP DATABASE my_database; is instantaneous and permanently irreversible. It instantly deletes the database and every single table inside it. Never run this command on a production server without a verified, recent backup.Pro Tip: For 90% of web applications, creating a single database and placing all your tables inside the default
public schema is the correct architectural choice. Don't overcomplicate your layout with multiple schemas unless you have a specific business reason (like strict multi-tenancy).Free preview. Sign in and subscribe to unlock all 982 lessons across 31 courses.
Free preview Β· Β© 2026 Full Stack Learning Simplified