Skip to content

PostgreSQL Installation Guide

This guide covers the installation and initial setup of PostgreSQL across different operating systems.

Table of Contents

System Requirements

Minimum Requirements

  • CPU: 1 GHz or faster
  • RAM: 1 GB minimum (4 GB recommended)
  • Storage: 10 GB minimum free space
  • Operating System: Linux, macOS, or Windows
  • CPU: 2 GHz or faster
  • RAM: 8 GB or more
  • Storage: 50 GB or more free space
  • SSD storage for better performance

Installation Methods

Ubuntu/Debian

1
2
3
4
5
6
7
8
# Update package lists
sudo apt update

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

# Verify installation
psql --version

macOS (using Homebrew)

# Update Homebrew
brew update

# Install PostgreSQL
brew install postgresql

# Start PostgreSQL service
brew services start postgresql

# Verify installation
psql --version

Windows

  1. Download the installer from PostgreSQL Downloads
  2. Run the installer and follow the wizard
  3. Choose components to install (PostgreSQL Server, pgAdmin, Command Line Tools)
  4. Set password for the postgres user
  5. Choose port (default: 5432)
  6. Complete the installation

Docker

1
2
3
4
5
6
7
8
# Pull the official PostgreSQL image
docker pull postgres

# Run PostgreSQL container
docker run --name my-postgres \
    -e POSTGRES_PASSWORD=mysecretpassword \
    -p 5432:5432 \
    -d postgres

Post-Installation Steps

1. Verify Installation

1
2
3
4
5
# Check PostgreSQL version
psql --version

# Connect to PostgreSQL
psql -U postgres

2. Basic Security Setup

-- Change postgres user password
ALTER USER postgres WITH PASSWORD 'new_password';

-- Create a new user
CREATE USER myuser WITH PASSWORD 'mypassword';

-- Create a new database
CREATE DATABASE mydatabase;

-- Grant privileges
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;

3. Enable Remote Access (Optional)

Edit postgresql.conf:

listen_addresses = '*'  # or specific IP

Edit pg_hba.conf:

# Allow remote connections
host    all             all             0.0.0.0/0               md5

Troubleshooting

Common Issues

  1. Connection Refused
  2. Check if PostgreSQL is running
  3. Verify port configuration
  4. Check firewall settings

  5. Authentication Failed

  6. Verify username and password
  7. Check pg_hba.conf configuration
  8. Ensure proper permissions

  9. Port Already in Use

  10. Check if another PostgreSQL instance is running
  11. Change port in postgresql.conf
  12. Kill the process using the port

Getting Help

Next Steps