🏠 Home / Hub

🐘 PostgreSQL Lesson 01 — Intro & Setup

← Back to PostgreSQL Menu  |  🏠 Hub

1. PostgreSQL ဆိုတာ ဘာလဲ

PostgreSQL (Postgres) = World's most advanced open source relational database
1986 ကတည်းက UC Berkeley မှာ develop — 30+ years battle-tested

🏢 Use by: Apple, Instagram, Spotify, Reddit, Twitch
🆓 100% free and open source (BSD license)
🏆 DB-Engines "DBMS of the Year" multiple times
FeatureMySQLPostgreSQL
ACID complianceInnoDB only✅ Full
JSON supportBasic JSON✅ JSONB (indexed, fast)
Arrays✅ Native ARRAY type
Full-text searchBasic✅ Built-in tsvector
Window functionsLimited✅ Full SQL standard
Custom types✅ CREATE TYPE
GeospatialBasic✅ PostGIS extension
Default port33065432

2. Install PostgreSQL

# Windows: postgresql.org/download/windows → EDB installer
# Mac: brew install postgresql@16
# Ubuntu: sudo apt install postgresql postgresql-contrib

# Start service
# Windows: Services ထဲ "postgresql-x64-16" → Start
# Mac/Linux: sudo systemctl start postgresql

# Check version
psql --version     # psql (PostgreSQL) 16.x

# Connect
psql -U postgres   # connect as postgres superuser
# prompt: postgres=#

3. psql CLI — Basic Commands

-- psql commands (meta-commands start with \)
\l                    -- list databases
\c mydb               -- connect to database
\dt                   -- list tables in current db
\d users              -- describe table structure
\du                   -- list users/roles
\q                    -- quit

-- Create database & user
CREATE DATABASE myapp;
CREATE USER myuser WITH PASSWORD 'mypassword';
GRANT ALL PRIVILEGES ON DATABASE myapp TO myuser;

-- Connect to new db
\c myapp

-- Run SQL file
\i /path/to/setup.sql

4. pgAdmin — GUI Tool

pgAdmin = Free GUI for PostgreSQL (ships with installer)
Browser-based: http://localhost/pgadmin4
Features: Query editor, Table viewer, ER diagrams, Backup/restore

Alternatives: TablePlus, DBeaver, DataGrip (paid)
-- pgAdmin Quick Start
1. Open pgAdmin → Servers → PostgreSQL → Connect
2. Databases → Right-click → Create → Database
3. Query Tool → Write SQL → F5 to run

-- VS Code: SQLTools extension
-- Extension: "SQLTools" + "SQLTools PostgreSQL/Redshift"
-- Connect settings:
{
  "name": "Local PG",
  "driver": "PostgreSQL",
  "server": "localhost",
  "port": 5432,
  "database": "myapp",
  "username": "postgres"
}

5. Supabase — Free Cloud PostgreSQL

-- Supabase.com = PostgreSQL + REST API + Auth + Storage
-- Free tier: 500MB database, unlimited API calls

-- Setup:
1. supabase.com → Sign up → New Project
2. Get connection string:
   postgresql://postgres:[password]@db.xxx.supabase.co:5432/postgres

-- Features:
- PostgreSQL database (full access)
- Auto-generated REST API
- Authentication (email, OAuth)
- File Storage
- Realtime subscriptions

-- Great for: personal projects, startups, learning!
-- Production: AWS RDS, Google Cloud SQL, Neon.tech
💡 Local development → psql/pgAdmin | Production → Supabase (free) or AWS RDS

← PostgreSQL Menu  |  Next: PostgreSQL 02 → Tables →

📌 Study Checklist