localhost:5432 — PostgreSQL

PostgreSQL has quietly become the default database for new projects. Rails chooses it. Django recommends it. Supabase is built on it. Vercel Postgres is it. If you started a new web project in the last few years and picked a database, there's a good chance you're running Postgres on port 5432.

What won developers over isn't one killer feature — it's the accumulation of things Postgres does that MySQL doesn't (or does worse): proper JSONB storage with indexing, full-text search built in, array columns, range types, CTEs that don't perform terribly, transactional DDL, and extensions like PostGIS (geospatial) and pgvector (AI embeddings). It's the "batteries included" database.

Connecting with psql

psql is Postgres's interactive terminal. It's powerful but its auth system confuses newcomers:

# Connect as the postgres superuser
psql -U postgres

# Connect to a specific database
psql -h localhost -p 5432 -U myuser -d mydb

# Useful psql commands once connected:
\l          -- list databases
\dt         -- list tables in current database
\d users    -- describe the 'users' table
\du         -- list users/roles
\q          -- quit
\x          -- toggle expanded output (easier to read wide rows)

Connection Strings

The standard URI format works everywhere:

postgresql://username:password@localhost:5432/database_name

Language-specific examples:

# Node.js (pg — the standard Postgres driver)
const { Pool } = require('pg');
const pool = new Pool({
  connectionString: 'postgresql://postgres:password@localhost:5432/myapp'
});

# Python (psycopg2 — the classic, or psycopg3 for async)
import psycopg2
conn = psycopg2.connect("dbname=myapp user=postgres password=password host=localhost")

# Django (settings.py)
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'myapp',
        'USER': 'postgres',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

# Rails (config/database.yml)
default: &default
  adapter: postgresql
  host: localhost
  username: postgres
  password: password

# Go (pgx)
conn, _ := pgx.Connect(ctx, "postgres://postgres:password@localhost:5432/myapp")

# .env (used by many ORMs/frameworks)
DATABASE_URL=postgresql://postgres:password@localhost:5432/myapp

Installing PostgreSQL

# macOS (Homebrew — easiest)
brew install postgresql@16
brew services start postgresql@16

# Ubuntu/Debian
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql

# Docker (fastest for a throwaway dev database)
docker run -d --name postgres \
  -e POSTGRES_PASSWORD=password \
  -p 5432:5432 \
  -v pgdata:/var/lib/postgresql/data \
  postgres:16

# Postgres.app (macOS — nice GUI in the menu bar)
# Download from postgresapp.com — click "Initialize" and you're done

The "Peer Authentication Failed" Problem

This is the single most common Postgres frustration for new users, especially on Linux. You install Postgres, try psql -U postgres, and get:

FATAL: Peer authentication failed for user "postgres"

What's happening: Postgres on Linux defaults to "peer" authentication for local connections. This means it checks your OS username against the Postgres username — if you're logged in as "john" but trying to connect as "postgres", it rejects you because the names don't match.

The fix: Edit pg_hba.conf (Postgres's authentication config):

# Find the file
sudo find / -name "pg_hba.conf" 2>/dev/null

# Edit it — change "peer" to "md5" for local connections:
# Before:
local   all   all   peer
# After:
local   all   all   md5

# Restart Postgres
sudo systemctl restart postgresql

# Now set a password for the postgres user
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'password';"

On macOS (Homebrew) and Docker, this isn't an issue — they default to password or trust authentication.

Creating a Database and User

# As the postgres superuser
psql -U postgres

CREATE DATABASE myapp;
CREATE USER myappuser WITH PASSWORD 'securepassword';
GRANT ALL PRIVILEGES ON DATABASE myapp TO myappuser;

-- PostgreSQL 15+ also requires:
\c myapp
GRANT ALL ON SCHEMA public TO myappuser;

That last grant is new in PostgreSQL 15 — they changed the default permissions on the public schema, which broke a lot of tutorials. If your app can create tables but the user can't access them, this is probably why.

pgAdmin: The GUI

pgAdmin is the standard GUI for Postgres. It runs as a web app (usually at localhost:5050 or in a browser tab) and gives you a visual way to browse databases, write queries, manage users, and inspect performance. To connect, use the same credentials as psql: host localhost, port 5432, username and password.

If you prefer something lighter, DBeaver is a cross-platform database GUI that supports Postgres (and MySQL, MongoDB, SQLite, etc.) with a more traditional desktop app feel.

Related Database Ports

PortDatabaseTypical Ecosystem
3306MySQL / MariaDBPHP, WordPress, LAMP
27017MongoDBNode.js, MERN stack
6379RedisCaching, sessions, queues
1433SQL Server.NET, enterprise