๐Ÿ› ๏ธ Installation & Setup

Install PostgreSQL and DBeaver step-by-step. So clear, so detailed, your pet goldfish could follow along. Let's get your database running!

๐ŸŽฏ What We're Installing (And Why)

๐Ÿง’ ELI5 โ€” Two Things, Two Jobs

Think of it like a car. You need two things:

1. The Engine = PostgreSQL โ€” This is the actual database. It stores your data, runs your queries, and does all the heavy lifting. But you can't see it โ€” it runs in the background like a service.

2. The Steering Wheel + Dashboard = DBeaver โ€” This is a visual tool that lets you see your databases, tables, and data in a friendly window. You type SQL here, click buttons, browse data โ€” it's your control panel.

You COULD drive a car using only the engine (using the command line tool called psql), but having a dashboard makes everything easier, especially when learning!

๐Ÿ˜
PostgreSQL 16
The database engine
Free & open-source
๐Ÿฆซ
DBeaver CE
Visual database manager
Free Community Edition

๐Ÿ’ก Why DBeaver?

There are many database tools: pgAdmin, DataGrip, TablePlus, Postico. We chose DBeaver because:

  • โœ… Completely free (Community Edition)
  • โœ… Works on Windows, Mac, AND Linux
  • โœ… Works with ANY database (PostgreSQL, MySQL, MongoDB, SQLite...)
  • โœ… Beautiful, intuitive interface
  • โœ… Built-in SQL autocompletion

๐Ÿ˜ Step 1: Install PostgreSQL

Choose your operating system below. Each set of instructions is complete โ€” follow every step and you'll be running in 10 minutes.

๐ŸชŸ Windows Installation

Download the Installer

Go to postgresql.org/download/windows and click "Download the installer". This takes you to EnterpriseDB's download page. Choose the latest version (16.x) for Windows x86-64.

Run the Installer

Double-click the downloaded .exe file. If Windows asks "Do you want to allow this app to make changes?", click Yes.

Choose Components

Keep all four checked: PostgreSQL Server, pgAdmin 4, Stack Builder, Command Line Tools. Click Next.

Choose Data Directory

Leave the default (C:\Program Files\PostgreSQL\16\data). This is where your actual database files will live. Click Next.

Set the Password (IMPORTANT!)

This is the password for the postgres superuser โ€” the admin account. Write it down! You'll need it every time you connect. Use something simple for learning (like postgres123) โ€” you can change it later.

Choose the Port

Default is 5432. Don't change it unless another PostgreSQL instance is already using this port. Click Next.

Finish Installation

Click through the remaining screens and wait for installation to complete. Uncheck "Launch Stack Builder" at the end โ€” you don't need it right now.

โœ… Verify It's Running

Open Command Prompt (press Win + R, type cmd, hit Enter) and run:

-- Check PostgreSQL version
psql --version

-- Expected output:
psql (PostgreSQL) 16.x

โš ๏ธ "psql is not recognized" Error?

This means PostgreSQL's bin folder isn't in your PATH. Fix: Search "Environment Variables" in Windows, edit the Path variable, and add: C:\Program Files\PostgreSQL\16\bin. Restart Command Prompt and try again.

๐ŸŽ macOS Installation

The easiest way on Mac is using Homebrew (a package manager). If you don't have Homebrew, install it first:

# Install Homebrew (if you don't have it)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install PostgreSQL
brew install postgresql@16

# Start the PostgreSQL service
brew services start postgresql@16

# Verify it's running
psql --version
psql (PostgreSQL) 16.x

๐Ÿ’ก Mac Pro Tip

After installing with Homebrew, PostgreSQL automatically creates a superuser with your Mac username (no password needed for local connections). You can connect instantly with: psql postgres

๐Ÿง’ Alternative: Postgres.app

If you prefer a visual approach, download Postgres.app โ€” it's a one-click PostgreSQL installer for Mac. Just drag it to your Applications folder, open it, and click "Initialize." Done!

๐Ÿง Linux (Ubuntu/Debian) Installation

# Update package list
sudo apt update

# Install PostgreSQL and utilities
sudo apt install postgresql postgresql-contrib

# Check it's running
sudo systemctl status postgresql
โ— postgresql.service - PostgreSQL RDBMS
     Active: active (exited)

# Switch to the postgres user and test
sudo -u postgres psql
postgres=# SELECT version();
-- Shows: PostgreSQL 16.x on x86_64-pc-linux-gnu
postgres=# \q

Set a Password for the postgres User

On Linux, the default postgres user has no password. Let's set one so DBeaver can connect:

sudo -u postgres psql
ALTER USER postgres PASSWORD 'postgres123';
\q

๐Ÿฆซ Step 2: Install DBeaver

๐Ÿง’ ELI5

DBeaver is like the "Finder" (Mac) or "File Explorer" (Windows) for databases. Instead of browsing folders and files, you browse databases, tables, and rows. It has a nice window where you can write SQL, see results, and explore your data visually.

Download DBeaver Community Edition

Go to dbeaver.io/download and download the Community Edition (it's free) for your operating system:

  • Windows: Download the .exe installer
  • macOS: Download the .dmg file (or use brew install --cask dbeaver-community)
  • Linux: Download the .deb package (or use sudo snap install dbeaver-ce)

Install It

Windows: Run the .exe, click Next through the wizard, leave defaults.

Mac: Open the .dmg, drag DBeaver to Applications.

Linux: sudo dpkg -i dbeaver-ce_*.deb or use Snap.

Open DBeaver

Launch DBeaver. On first run, it might ask to download a sample database โ€” you can skip this. You'll also see a "Tip of the Day" โ€” close that too.

๐ŸŽจ DBeaver's Interface

When DBeaver opens, you'll see:

  • Left Panel: Database Navigator โ€” shows all your connections, databases, tables
  • Center: SQL Editor โ€” where you write and run queries
  • Bottom: Results Panel โ€” shows query results as a table

Think of it like a code editor (VS Code), but specialized for databases.

๐Ÿ”Œ Step 3: Connect DBeaver to PostgreSQL

๐Ÿง’ ELI5

Right now, PostgreSQL is running on your computer like a chef in a kitchen. DBeaver is the dining room where you sit. We need to open the door between them so you can send orders (SQL queries) to the chef and get food (data) back. That "door" is called a connection.

Click "New Database Connection"

In DBeaver, click the plug icon (๐Ÿ”Œ) in the top-left toolbar, OR go to Database โ†’ New Database Connection.

Choose PostgreSQL

In the dialog that appears, you'll see a list of database types. Click PostgreSQL (the elephant icon ๐Ÿ˜), then click Next.

Fill In Connection Details

Fill in these fields:

FieldValueWhy
HostlocalhostPostgreSQL is on YOUR computer
Port5432Default PostgreSQL port
DatabasepostgresDefault database that always exists
UsernamepostgresDefault superuser account
PasswordThe one you set during installationAuthentication

Test the Connection

Click "Test Connection" at the bottom. If it says "Connected" with a green checkmark โ€” you're in! Click Finish.

โš ๏ธ Connection Failed? Common Fixes:

  • "Connection refused" โ†’ PostgreSQL service isn't running. Start it:
    Windows: net start postgresql-x64-16
    Mac: brew services start postgresql@16
    Linux: sudo systemctl start postgresql
  • "Authentication failed" โ†’ Wrong password. Reset it via psql: ALTER USER postgres PASSWORD 'newpass';
  • "Download driver" dialog โ†’ DBeaver needs the PostgreSQL JDBC driver. Click "Download" โ€” it's automatic and one-time.

๐Ÿ’ก Pro Tip โ€” Save Your Password

In the connection dialog, check "Save password locally" so you don't have to type it every time. For a learning environment, this is perfectly fine.

๐ŸŽ‰ Step 4: Your First Database & Query!

๐Ÿง’ ELI5

You're connected to PostgreSQL โ€” the kitchen is open! Right now there's a default database called postgres, but it's like the chef's break room. Let's create our OWN database โ€” our own restaurant โ€” and run our very first query!

Create Your First Database

In DBeaver, click on your PostgreSQL connection in the left panel to expand it. Then open a new SQL editor: SQL Editor โ†’ New SQL Script (or press Ctrl+] / Cmd+]). Type:

-- Create your very first database!
CREATE DATABASE my_first_db;

Press Ctrl+Enter (or Cmd+Enter on Mac) to execute. You should see a success message at the bottom. ๐ŸŽ‰

๐ŸŽฏ What Just Happened?

You just created a brand new, empty database on your computer. It's like creating a new, empty folder in your file system โ€” but this folder is designed to hold tables of data. Right-click your connection in the left panel and click "Refresh" to see my_first_db appear in the list!

Connect to Your New Database

DBeaver is still connected to the postgres database. To switch:

  1. In the left panel, double-click my_first_db to connect to it
  2. Open a new SQL Script (make sure the dropdown at the top shows my_first_db)

Run Your Very First Query

-- Your first ever SQL query!
SELECT 'Hello, PostgreSQL! ๐Ÿ˜' AS greeting;

Press Ctrl+Enter. You should see:

greeting
Hello, PostgreSQL! ๐Ÿ˜

Congratulations! You just talked to a database! ๐Ÿฅณ That SELECT statement is SQL โ€” the language databases understand. You'll master it in the next modules.

Let's Do Something Real โ€” Create a Table!

-- Create a table for your favorite movies
CREATE TABLE movies (
    id      SERIAL PRIMARY KEY,
    title   VARCHAR(200) NOT NULL,
    year    INTEGER,
    rating  DECIMAL(2,1)
);

-- Add some movies
INSERT INTO movies (title, year, rating) VALUES
    ('The Shawshank Redemption', 1994, 9.3),
    ('The Dark Knight',          2008, 9.0),
    ('3 Idiots',                 2009, 8.4),
    ('Inception',                2010, 8.8),
    ('Dangal',                   2016, 8.3);

-- See all your movies!
SELECT * FROM movies;

Result:

idtitleyearrating
1The Shawshank Redemption19949.3
2The Dark Knight20089.0
33 Idiots20098.4
4Inception20108.8
5Dangal20168.3

๐Ÿง’ What Did We Just Do?

CREATE TABLE = We built a filing cabinet called "movies" with 4 columns.

INSERT INTO = We put 5 movie records into that cabinet.

SELECT * FROM = We asked "Show me everything in the movies cabinet!"

That's it! You're already doing real database work. The next 11 modules will make you a master. ๐Ÿš€

One More Fun Query

-- Find movies with rating above 8.5
SELECT title, rating
FROM movies
WHERE rating > 8.5
ORDER BY rating DESC;
titlerating
The Shawshank Redemption9.3
The Dark Knight9.0
Inception8.8

๐Ÿ’ก DBeaver Keyboard Shortcuts

ActionWindowsMac
Execute statementCtrl + EnterCmd + Enter
Execute entire scriptCtrl + Shift + EnterCmd + Shift + Enter
New SQL scriptCtrl + ]Cmd + ]
Auto-completeCtrl + SpaceCtrl + Space
Format SQLCtrl + Shift + FCmd + Shift + F

โŒจ๏ธ Bonus: The Command Line Tool (psql)

DBeaver is great for visual work, but every PostgreSQL pro also knows psql โ€” the command-line interface. It's like texting vs calling โ€” sometimes the quick text (psql) is faster than opening the app (DBeaver).

# Connect to your database
psql -U postgres -d my_first_db

# You'll see the prompt:
my_first_db=#

# Run a query
SELECT * FROM movies;

# Useful psql commands (backslash commands):
\l              -- List all databases
\dt             -- List all tables in current database
\d movies       -- Describe the 'movies' table structure
\c other_db     -- Switch to another database
\q              -- Quit psql

๐ŸŽฏ When to Use psql vs DBeaver

Use psql When...Use DBeaver When...
Quick one-line queriesExploring data visually
Server administration via SSHWriting multi-line queries
Running scripts from filesViewing table structures
You want to feel like a hacker ๐Ÿ˜ŽYou want a nice GUI

๐Ÿงช Quick Quiz

Question 1: What is DBeaver?

Question 2: What is the default port for PostgreSQL?

Question 3: What does SELECT * FROM movies; do?

Question 4: What command lists all tables in psql?

Question 5: What is the default superuser in PostgreSQL?

๐Ÿš€ What's Next?

You now have a fully working PostgreSQL setup! Here's what you accomplished:

โœ…
PostgreSQL installed & running
โœ…
DBeaver installed & connected
โœ…
Created your first database
โœ…
Ran your first SQL queries

๐Ÿ‘‰ Next up: SQL Basics โ€” CRUD Operations!

You've already done a tiny taste of CREATE, INSERT, and SELECT. In the next module, we'll go DEEP into all the CRUD operations โ€” CREATE, INSERT, SELECT, UPDATE, DELETE โ€” with tons of examples, exercises, and quizzes. Get excited! ๐Ÿ”ฅ

Meet PostgreSQL SQL Basics โ€” CRUD