Port 5432

PostgreSQL Database

Port 5432: PostgreSQL Database

Protocol TCP
Service PostgreSQL
Encrypted Optional (SSL)
IANA Status Official

What is Port 5432?

Port 5432 is the default port for PostgreSQL, a powerful open-source relational database. It's widely used in modern web applications and supports advanced features like JSONB, full-text search, and extensions.

Connection Examples

# psql command line
psql -h hostname -p 5432 -U username -d database

# Connection string (URI format)
postgresql://user:password@localhost:5432/database
postgres://user:password@localhost:5432/database?sslmode=require

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

# Python (psycopg2)
conn = psycopg2.connect(
    host="localhost",
    port=5432,
    user="postgres",
    password="secret",
    database="myapp"
)

Configuration Files

# Find config file location
sudo -u postgres psql -c "SHOW config_file;"
# Typically: /etc/postgresql/14/main/postgresql.conf

# postgresql.conf - listen on all interfaces (be careful!)
listen_addresses = 'localhost'  # Safe default
# listen_addresses = '*'  # All interfaces (needs pg_hba.conf)

# Change port
port = 5432

# Restart PostgreSQL
sudo systemctl restart postgresql

Client Authentication (pg_hba.conf)

# /etc/postgresql/14/main/pg_hba.conf

# TYPE  DATABASE  USER  ADDRESS       METHOD

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

# Allow specific IP (internal network only)
host    all       all   10.0.0.0/8    scram-sha-256

# Reload after changes
sudo systemctl reload postgresql

SSL Connections

# Check if SSL is enabled
psql -c "SHOW ssl;"

# Connection string with SSL
postgres://user:pass@host:5432/db?sslmode=require
postgres://user:pass@host:5432/db?sslmode=verify-full

# SSL modes:
# disable  - No SSL
# allow    - Try non-SSL first
# prefer   - Try SSL first (default)
# require  - Must use SSL
# verify-ca - Verify server cert
# verify-full - Verify cert + hostname

Troubleshooting

# Check if PostgreSQL is running
sudo systemctl status postgresql
sudo ss -tlnp | grep 5432

# Check what address it's listening on
sudo -u postgres psql -c "SHOW listen_addresses;"

# Test connection
nc -zv localhost 5432
psql -h localhost -U postgres

# View connection errors
sudo tail -f /var/log/postgresql/postgresql-14-main.log

Common Issues

  • FATAL: no pg_hba.conf entry: Add client IP to pg_hba.conf
  • Connection refused: Check listen_addresses and service status
  • Password authentication failed: Verify credentials and auth method
  • Too many connections: Increase max_connections or use connection pooler

Monitor your PostgreSQL server

UptimeSignal can monitor TCP port 5432 to ensure your database is accessible.

Start monitoring free →

Related Ports