PostgreSQL Installation

This section covers how to install PostgreSQL on different operating systems and using Docker Compose.

Linux Installation

Ubuntu/Debian

# Update package list
sudo apt update

# Install PostgreSQL
sudo apt install postgresql postgresql-contrib

# Start and enable PostgreSQL service
sudo systemctl start postgresql
sudo systemctl enable postgresql

# Switch to postgres user and create database
sudo -u postgres psql

CentOS/RHEL/Fedora

# Install PostgreSQL (CentOS/RHEL)
sudo yum install postgresql-server postgresql-contrib
# or for Fedora
sudo dnf install postgresql-server postgresql-contrib

# Initialize database
sudo postgresql-setup initdb

# Start and enable PostgreSQL service
sudo systemctl start postgresql
sudo systemctl enable postgresql

Arch Linux

# Install PostgreSQL
sudo pacman -S postgresql

# Initialize database cluster
sudo -u postgres initdb -D /var/lib/postgres/data

# Start and enable PostgreSQL service
sudo systemctl start postgresql
sudo systemctl enable postgresql

macOS Installation

Using Homebrew

# Install PostgreSQL
brew install postgresql

# Start PostgreSQL service
brew services start postgresql

# Create a database
createdb mydatabase

Using PostgreSQL.app

  1. Download PostgreSQL.app from postgresapp.com
  2. Drag the app to your Applications folder
  3. Open the app and click "Initialize" to create a new server
  4. Add /Applications/Postgres.app/Contents/Versions/latest/bin to your PATH

Windows Installation

Using Official Installer

  1. Download the PostgreSQL installer from postgresql.org
  2. Run the installer as administrator
  3. Follow the installation wizard:
    • Choose installation directory
    • Select components (PostgreSQL Server, pgAdmin, Command Line Tools)
    • Set data directory
    • Set superuser password
    • Set port (default: 5432)
    • Set locale
  4. Complete the installation

Docker Compose Installation

For a quick and portable PostgreSQL setup, you can use Docker Compose:

Basic Docker Compose Setup

Create a docker-compose.yml file:

version: '3.8'

services:
  postgres:
    image: postgres:15
    container_name: palpo-postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: palpo
      POSTGRES_USER: palpo_user
      POSTGRES_PASSWORD: your_secure_password
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - "5432:5432"
    networks:
      - palpo-network

volumes:
  postgres_data:

networks:
  palpo-network:
    driver: bridge

Advanced Docker Compose with pgAdmin

For database management, you can also include pgAdmin:

version: '3.8'

services:
  postgres:
    image: postgres:15
    container_name: palpo-postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: palpo
      POSTGRES_USER: palpo_user
      POSTGRES_PASSWORD: your_secure_password
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    networks:
      - palpo-network

  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: palpo-pgadmin
    restart: unless-stopped
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@palpo.im
      PGADMIN_DEFAULT_PASSWORD: admin_password
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    ports:
      - "8080:80"
    networks:
      - palpo-network
    depends_on:
      - postgres

volumes:
  postgres_data:
  pgadmin_data:

networks:
  palpo-network:
    driver: bridge

Running Docker Compose

# Start the services
docker-compose up -d

# Check service status
docker-compose ps

# View logs
docker-compose logs postgres

# Stop the services
docker-compose down

# Stop and remove volumes (⚠️ This will delete all data)
docker-compose down -v

Post-Installation Setup

After installing PostgreSQL, you'll need to:

  1. Create a database for palpo:
CREATE DATABASE palpo;
CREATE USER palpo_user WITH PASSWORD 'your_secure_password';
GRANT ALL PRIVILEGES ON DATABASE palpo TO palpo_user;
  1. Configure connection settings in your palpo application configuration file with the appropriate database URL:
postgresql://palpo_user:your_secure_password@localhost:5432/palpo
  1. Test the connection to ensure everything is working correctly.

With PostgreSQL installed and configured, you're ready to set up palpo. Make sure to update your application's database configuration with the correct connection details before proceeding with the application setup.