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
How to Check if Port 5432 is Open
These commands help verify PostgreSQL connectivity from client and server side.
# From a remote machine
nc -zv db-server.example.com 5432
nmap -p 5432 db-server.example.com
psql -h db-server.example.com -p 5432 -U postgres
# On the server — check if PostgreSQL is listening
sudo ss -tlnp | grep 5432
sudo lsof -i :5432
# Check PostgreSQL listen address
sudo -u postgres psql -c "SHOW listen_addresses;"
# Check pg_hba.conf for client auth rules
sudo -u postgres psql -c "SHOW hba_file;"
# Check firewall
sudo ufw status | grep 5432
Connection Pooling with PgBouncer
PostgreSQL creates a new process per connection, which can exhaust resources under load. PgBouncer sits between your app and PostgreSQL to reuse connections efficiently.
# PgBouncer typically listens on port 6432
# /etc/pgbouncer/pgbouncer.ini
[databases]
myapp = host=127.0.0.1 port=5432 dbname=myapp
[pgbouncer]
listen_port = 6432
listen_addr = 127.0.0.1
pool_mode = transaction
max_client_conn = 1000
default_pool_size = 25
# App connects to PgBouncer instead of PostgreSQL directly
postgresql://user:pass@localhost:6432/myapp
Monitoring PostgreSQL with UptimeSignal
PostgreSQL downtime on port 5432 causes 500 errors in your application. UptimeSignal monitors your application's health endpoints, alerting you when database issues start affecting users. Combine with port monitoring for MySQL and Redis for full infrastructure coverage.
Frequently Asked Questions
What runs on port 5432?
What does "no pg_hba.conf entry" mean?
pg_hba.conf to control which clients can connect to which databases. This error means no rule matches your client IP, user, and database combination. Add a rule like host all all 10.0.0.0/8 scram-sha-256 for your network, then reload: sudo systemctl reload postgresql. This is independent from PostgreSQL user passwords.
How do I enable SSL for PostgreSQL connections?
postgresql.conf, set ssl = on and configure ssl_cert_file and ssl_key_file. Use hostssl in pg_hba.conf to require SSL. Clients use sslmode=require (or verify-full for production) in connection strings. Managed PostgreSQL services (AWS RDS, Supabase, Neon) have SSL enabled by default.
Should I expose PostgreSQL port 5432 to the internet?
listen_addresses = 'localhost' and use SSH tunnels, VPNs, or private networking. If remote access is unavoidable, restrict IPs in pg_hba.conf and enforce SSL. Managed database services handle this by placing PostgreSQL in a private subnet accessible only via VPC peering.
What causes PostgreSQL "too many connections" error?
max_connections = 100. Each connection creates a server process consuming memory. Fix by: increasing max_connections, closing leaked connections, using a connection pooler like PgBouncer (in transaction mode), or optimizing long-running queries. Check active connections: SELECT count(*) FROM pg_stat_activity;.