Skip to content

Postgres Installation

and install binaries from here

brew install postgresql

the source zip from here

# Extract the source
tar -xvzf postgresql-<VERSION>.tar.gz
cd postgresql-<VERSION>

Check the tags from here

# Clone the repo (assume you are in ~/dev)
git clone --depth 1 -b <TAG> https://git.postgresql.org/git/postgresql.git
cd postgresql

Make and Install

# Check openssl
which openssl

SSL_DIR="<ssl libs dir>" 
# for home brew you can get it using `brew --prefix openssl@1.1` 

# Configure the build
./configure --with-openssl \
  --with-includes=${SSL_DIR}/include \
  --with-libraries=${SSL_DIR}/lib \
  --prefix $HOME/dev/postgres/pgsql

# Make
make world

# Install
make install 

Configuration

Create ~/dev/postgres and ~/dev/postgres/pgdata

env variables and aliases

Postgres config
export PG_HOME="$HOME/dev/postgres"
export PG_LOG_FILE="$PG_HOME/postgres.log"
export PG_DATA="$PG_HOME/pgdata"

export PATH="$PG_HOME/pgsql/bin:$PATH" # (1)

alias start_postgres="pg_ctl -D ${PG_DATA} -l ${PG_LOG_FILE} start"
alias stop_postgres="pg_ctl -D ${PG_DATA} -l ${PG_LOG_FILE} stop"
  1. 🙅‍♂️ not required for homebrew installation

InitDB (create database folder structure)

initdb ${PG_DATA}

Create user/role

createuser --interactive --pwprompt

Create database

createdb -O <user_name> <db_name>

Login to database

psql -U <user_name> -d <database> [-h <host>] [-p <port>] -a