localhost:5432

Port 5432 is PostgreSQL. If MySQL is everywhere, Postgres is the choice for developers who want more features — JSON support, full-text search, and better standards compliance. Rails, Django, and most startups run on Postgres.

Connect to PostgreSQL

psql Command Line

# Connect as postgres user
psql -U postgres

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

# List databases
\l

# List tables
\dt

Connection Strings

# Standard format
postgresql://user:password@localhost:5432/dbname

# Node.js (pg)
const pool = new Pool({
  host: 'localhost',
  port: 5432,
  user: 'postgres',
  password: 'password',
  database: 'mydb'
});

# Python (psycopg2)
conn = psycopg2.connect(
  host='localhost',
  port=5432,
  user='postgres',
  password='password',
  dbname='mydb'
)

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

Check if PostgreSQL is Running

# Linux
sudo systemctl status postgresql

# Mac (Homebrew)
brew services list | grep postgresql

# Check port
pg_isready -h localhost -p 5432

Common Errors

ErrorSolution
Connection refusedPostgreSQL not running or wrong port
FATAL: role does not existCreate user: createuser myuser
FATAL: database does not existCreate db: createdb mydb
Peer authentication failedEdit pg_hba.conf, change to md5 auth

PostgreSQL vs MySQL

FeaturePostgreSQL (5432)MySQL (3306)
JSON supportNative JSONBBasic JSON
Full-text searchBuilt-inRequires config
StandardsSQL compliantSome deviations
Popular withRails, DjangoWordPress, PHP

Related Ports

PortDatabase
3306MySQL
27017MongoDB
6379Redis