Day 2: Installing PostgreSQL and Setting Up Your Environment
Welcome back! Today, we'll install PostgreSQL on your system and set up the essential tools you'll need.
Installation Options
Windows Installation
-
Download the Installer
- Visit postgresql.org/download
- Download the latest stable version (15.x or 16.x)
-
Run the Installer
- Double-click the downloaded
.exe
file - Follow the installation wizard
- Set a strong password for the
postgres
superuser (SAVE THIS!) - Default port: 5432 (keep it unless you have conflicts)
- Double-click the downloaded
-
Install pgAdmin 4
- Typically included in the installer
- pgAdmin is a visual management tool for PostgreSQL
macOS Installation
Using Homebrew (Recommended)
# Install Homebrew if you haven't
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install PostgreSQL
brew install postgresql@16
# Start PostgreSQL service
brew services start postgresql@16
Or download from postgresql.org
Linux (Ubuntu/Debian) Installation
# Update package list
sudo apt update
# Install PostgreSQL
sudo apt install postgresql postgresql-contrib
# Start the service
sudo systemctl start postgresql
sudo systemctl enable postgresql
Verifying Your Installation
Open your terminal/command prompt:
# Check PostgreSQL version
psql --version
# Should output something like:
# psql (PostgreSQL) 16.x
First Connection
Using Command Line
Windows:
psql -U postgres
macOS/Linux:
sudo -u postgres psql
You should see:
postgres=#
Congratulations! You're connected! ๐
Installing pgAdmin 4
pgAdmin is a powerful graphical interface for PostgreSQL.
- Download from pgadmin.org
- Install and launch pgAdmin
- Create a new server connection:
- Right-click "Servers" โ Register โ Server
- Name: "Local PostgreSQL"
- Host: localhost
- Port: 5432
- Username: postgres
- Password: (the one you set during installation)
Basic Terminal Commands
-- List all databases
\l
-- Connect to a database
\c database_name
-- List all tables
\dt
-- Quit psql
\q
Troubleshooting Common Issues
"psql: command not found"
- Add PostgreSQL to your PATH environment variable
- Windows: Add
C:\Program Files\PostgreSQL\16\bin
to PATH
Connection refused errors
- Ensure PostgreSQL service is running
- Check if port 5432 is available
Permission denied
- Make sure you're using the correct username and password
Your First SQL Command
Let's test everything works:
SELECT version();
This should display your PostgreSQL version information.
Tomorrow's Preview: Day 3 - Creating Your First Database and Understanding Database Structure
Homework:
- Install PostgreSQL successfully
- Connect via both command line and pgAdmin
- Run the
SELECT version();
command
Share your PostgreSQL version in the comments! ๐
Top comments (0)