Chapter 3: PostgreSQL Get Started
- PostgreSQL Introduction → what it is, history, why it’s awesome
- PostgreSQL Home → official site + PGDATA folder
- PostgreSQL Tutorial → hands-on CREATE/INSERT/SELECT/JOIN examples
- Install Introduction → step-by-step install on Windows/mac/Linux/Docker
Now: “PostgreSQL Get Started”
This phrase almost always points to the very first practical steps after installation — the official “Getting Started” section in the PostgreSQL documentation (right now for version 18.2).
The official docs call it: Chapter 1. Getting Started → https://www.postgresql.org/docs/current/tutorial-start.html (That’s the link you should bookmark forever!)
It has four short but gold subsections:
- Installation (we already covered)
- Architectural Fundamentals
- Creating a Database
- Accessing a Database
Today I’m going to walk you through exactly what “Get Started” means in real life — like we’re doing it together on your laptop right now. We’ll follow the official flow but make it super clear, Hyderabad-style, with exact commands, what you’ll see on screen, and tiny explanations.
Step 0: Assume PostgreSQL is already running (from our Install class)
- Windows: service is auto-started
- macOS (Postgres.app): app is open
- Ubuntu: sudo systemctl status postgresql@18-main → active
- Docker: docker ps → see your postgres:18 container running
If not running → start it now (ask if stuck!).
Test alive:
|
0 1 2 3 4 5 6 7 8 9 |
# From any terminal/cmd/PowerShell psql --version # Should reply: psql (PostgreSQL) 18.2 # (or whatever minor patch is current today) |
Step 1: Architectural Fundamentals (the 2-minute mental model)
PostgreSQL is not just one big file — it’s a cluster of databases managed by one server process.
Key concepts (teacher drawing on imaginary board):
- One PostgreSQL server instance (called a “cluster”) runs on your machine
- It can manage many databases at once (like school_db, shop_db, blog_db)
- Every database has many schemas (default = public)
- Schemas have tables, views, functions, etc.
- One special database always exists: postgres (for admin tasks)
- One superuser always exists: postgres (like root)
Think: Server (postgres process) └── Cluster ├── Database: postgres ├── Database: template1 (blueprint) ├── Database: template0 (never touch) └── Your databases (school_db, etc.)
That’s it — no magic. Just hierarchy.
Step 2: Creating Your First Database (official 1.3 section)
Don’t work inside the default postgres database — always create your own.
Two easy ways:
Way A — Using createdb command (easiest, recommended first time)
|
0 1 2 3 4 5 6 7 8 9 10 |
# From your normal terminal (not inside psql) createdb my_first_db # If it asks for password → use the one you set during install # On Linux default → no password needed if you're the postgres OS user or peer auth |
Way B — Inside psql (what official tutorial shows)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# Connect to default 'postgres' database as superuser psql -U postgres # (enter password if prompted) # Now you're inside psql → prompt looks like: postgres=# CREATE DATABASE my_first_db; # Optional: with options CREATE DATABASE school_db OWNER postgres ENCODING 'UTF8' LC_COLLATE 'en_IN.UTF-8' LC_CTYPE 'en_IN.UTF-8' TEMPLATE template0; |
You should see: CREATE DATABASE
Type \l (list databases) → you see my_first_db in the list!
Step 3: Accessing / Connecting to Your Database (official 1.4 section)
Now switch into it.
|
0 1 2 3 4 5 6 7 8 9 |
# From terminal (best way) psql -U postgres -d my_first_db # or shorter if default user psql my_first_db |
Inside psql you’ll see:
|
0 1 2 3 4 5 6 |
my_first_db=# |
Or from inside an existing psql session:
|
0 1 2 3 4 5 6 7 |
\c my_first_db -- You should see: You are now connected to database "my_first_db" as user "postgres". |
Step 4: Your “It really works” moment — official style first commands
Now that you’re connected to my_first_db, let’s do the classic hello-world:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
-- Create a very simple table CREATE TABLE greetings ( id SERIAL PRIMARY KEY, message TEXT NOT NULL, when_said TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Insert one row INSERT INTO greetings (message) VALUES ('Hello from Hyderabad on Feb 13, 2026!'); -- See it SELECT * FROM greetings; -- Better formatted SELECT id, message, when_said FROM greetings; |
Expected output something like:
|
0 1 2 3 4 5 6 7 8 |
id | message | when_said ----+-------------------------------------------------------+------------------------------- 1 | Hello from Hyderabad on Feb 13, 2026! | 2026-02-13 18:05:42.123456+05:30 |
Boom! 🎉 You just:
- Created a database
- Connected to it
- Created a table
- Inserted data
- Queried it
That’s PostgreSQL Get Started in real life.
Bonus: Useful psql meta-commands (you’ll use every day)
| Command | What it does | Example output feeling |
|---|---|---|
| \l | List all databases | Shows your new db |
| \dt | List tables in current database | See greetings table |
| \d greetings | Describe table structure | Columns, types, constraints |
| \conninfo | Show current connection details | Host, port, user, db |
| \? | List all meta-commands | Your cheat sheet |
| \q | Quit psql | Back to terminal |
Where to go next (official path + my recommendation)
Official docs continue with:
- Simple SELECT queries
- Creating more tables
- INSERT / UPDATE / DELETE
- … up to joins, aggregates, etc.
My suggestion for you right now:
- Create one more table → students (like we did in Tutorial class)
- Insert 3–4 rows with Indian names
- Run SELECT * FROM students ORDER BY first_name;
- Play with \d students and \l
If you want GUI instead of terminal:
- Open pgAdmin 4 (installed with Windows/EDB)
- Or download DBeaver (free, works everywhere) → connect localhost:5432, user=postgres, db=my_first_db
Tell guru what next:
- Stuck on any command / error? Paste it!
- Want to do first real SELECT queries with WHERE / ORDER BY?
- How to create your own user (not just postgres superuser)?
- Or move to backup your first db?
Your call — we’re building step-by-step! 🚀
