Skip to main content

🤖 Installation Guide

PostgreSQL install karvanu different platforms ma bahuj simple che. Let's see kevi rite install karvu.

Linux ma Installation

Ubuntu/Debian

Ubuntu/Debian ma official PostgreSQL repository thi install karvu best che because latest version male che.

# PostgreSQL repository add karo
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Repository key add karo security mate
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# Update karo ane install karo
sudo apt-get update
sudo apt-get install postgresql-16 postgresql-contrib-16

Installation pachhi service automatically start thai jay che.

RHEL/CentOS/Rocky Linux

Red Hat based systems ma thodu different process che:

# PostgreSQL repository RPM install karo
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Built-in PostgreSQL module disable karo (aa old version che)
sudo dnf -qy module disable postgresql

# PostgreSQL install karo
sudo dnf install -y postgresql16-server postgresql16-contrib

# Database cluster initialize karo
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb

# Service enable ane start karo
sudo systemctl enable postgresql-16
sudo systemctl start postgresql-16

macOS ma Installation

Mac ma sabse easy way Homebrew che:

# PostgreSQL install karo
brew install postgresql@16

# Service start karo
brew services start postgresql@16

Aa command automatic service background ma run karavi de che.

Postgres.app (GUI option)

Agar GUI prefer karo to Postgres.app download karo. Drag-and-drop install che, bahuj simple.

Windows ma Installation

Installer use karine

  1. postgresql.org thi installer download karo
  2. Installer run karo (administrator rights chahiye)
  3. Installation wizard follow karo:
    • Installation directory select karo
    • Components select karo (Server, pgAdmin, Command Line Tools)
    • Data directory location set karo
    • Important: postgres user nu password set karo (yaad rakho!)
    • Port number (default: 5432) set karo
    • Locale select karo

Installation complete thay pachhi pgAdmin automatically open thay.

Verify Installation

Installation success thayo ke nai check karva mate:

# PostgreSQL version check karo
psql --version
# Output: psql (PostgreSQL) 16.x

# PostgreSQL ma login karo
sudo -u postgres psql

# Version query run karo
SELECT version();

Post-Installation Setup

Installation pachhi aa steps follow karo:

1. Configuration Files Location

# Config files kya che locate karva mate
sudo -u postgres psql -c "SHOW config_file;"
sudo -u postgres psql -c "SHOW hba_file;"

Common locations:

  • Ubuntu/Debian: /etc/postgresql/16/main/
  • RHEL/CentOS: /var/lib/pgsql/16/data/
  • macOS: /usr/local/var/postgres/
  • Windows: C:\Program Files\PostgreSQL\16\data\

2. Basic Configuration

# postgresql.conf edit karo
sudo nano /etc/postgresql/16/main/postgresql.conf

# Important settings:
# listen_addresses = 'localhost' # Remote access mate change karo
# max_connections = 100 # Connections ni limit
# shared_buffers = 256MB # Memory allocation

3. Authentication Setup

# pg_hba.conf edit karo authentication mate
sudo nano /etc/postgresql/16/main/pg_hba.conf

# Local connections mate:
# local all all peer
# host all all 127.0.0.1/32 scram-sha-256

4. Firewall Configuration (Remote access mate)

# Ubuntu ma
sudo ufw allow 5432/tcp

# RHEL/CentOS ma
sudo firewall-cmd --permanent --add-port=5432/tcp
sudo firewall-cmd --reload

5. Service Management

# Status check karo
sudo systemctl status postgresql

# Start/Stop/Restart
sudo systemctl start postgresql
sudo systemctl stop postgresql
sudo systemctl restart postgresql

# Boot time pe automatically start thavu joiye to
sudo systemctl enable postgresql

First Login ane Database Creation

# postgres user sathe login karo
sudo -u postgres psql

# New database create karo
CREATE DATABASE mydb;

# Database list joyo
\l

# Specific database ma connect thavo
\c mydb

# Exit
\q

Common Installation Issues

Port already in use

# Port 5432 pe shu chale che check karo
sudo lsof -i :5432
# Ane tyare badlu port use karo ke existing process stop karo

Permission denied errors

# postgres user ne proper permissions apo
sudo chown -R postgres:postgres /var/lib/postgresql/16/main

Service not starting

# Logs check karo error mate
sudo journalctl -u postgresql -n 50
# Ke
sudo tail -f /var/log/postgresql/postgresql-16-main.log

Next Steps: Configuration tuning ane security setup (coming soon)