Installing PostgreSQL

Harry · 11 Sep 2026 · 11 views

Installing on Ubuntu / Debian

sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl enable --now postgresql
sudo -u postgres psql

On Debian-family systems the postgres OS user owns the database cluster. Connect as that user first.

Setting a Password and Creating a User

sudo -u postgres psql
ALTER USER postgres PASSWORD 'strong_password';
CREATE ROLE app_user LOGIN PASSWORD 'app_password';
CREATE DATABASE appdb OWNER app_user;
\q

Connecting With psql

psql -h localhost -U app_user -d appdb -W

Verifying the Install

psql --version
sudo systemctl status postgresql
sudo -u postgres psql -c "SELECT version();"

Installing on Windows / macOS

Use the interactive EDB installer for Windows, or Homebrew on macOS with brew install postgresql. The EDB installer starts the service and gives you pgAdmin automatically.

Key Points

  • The postgres superuser is created during install.
  • Create separate roles (users) for applications.
  • psql is the powerful command-line client.
  • Verify with psql --version and a version query.
Share this post:

Comments (0)

Please login or register to comment.