Migrate to RunxBuild and earn up to $50 in hosting credit on your first deposit.

Calculate your savings
unxBuild

PostgreSQL Port: 5432 (Default), How to Change, and Multi-Version Setup

Sean

Platform Writer

Jul 05, 2026
4 min read

PostgreSQL default port is 5432, registered with IANA. Multiple installations on one host use 5432, 5433, 5434 etc. (each major version gets the next port). Change the port via port = XXXX in postgresql.conf, then sudo systemctl reload postgresql. The team that uses non-standard ports for security-through-obscurity knows the real protection is the firewall, not the port.

PostgreSQL Port: 5432 (Default), How to Change, and Multi-Version Setup

Table of contents

The default port

PostgreSQL’s IANA-registered port is 5432. Confirmed in the Postgres docs.

psql -h localhost -p 5432 -U postgres

If unspecified, psql uses 5432.

Why 5433, 5434, etc.

PostgreSQL Apt repo’s postgresql-XX packages auto-assign ports:

  • 16: 5432
  • 17: 5433
  • 18: 5434
  • etc.

Run multiple major versions side by side:

sudo apt install postgresql-16 postgresql-17 postgresql-18
# All running, on different ports

The team that runs multiple versions has no port conflicts.

Change the port

Edit postgresql.conf:

port = 5433

Then sudo systemctl reload postgresql.

Verify:

ss -tlnp | grep 5433

The team that has the config has the new port listening.

Connection strings

With port change:

postgresql://user:pass@host:5433/dbname

Or keyword/value:

host=db.example.com port=5433 user=postgres dbname=mydb

The team that updates connection strings has clients connecting to the new port.

Firewall considerations

Open the new port:

sudo ufw allow 5433/tcp

The team that has a firewall allows the right port. The team that forgets has no remote connections.

When to use non-standard port

  • Multi-version on one host (5432, 5433, 5434).
  • Dev/staging that needs separation from prod.
  • Security-through-obscurity (minor benefit).

The team that uses non-standard ports for security knows it’s a minor defense-in-depth, not a primary control.

FAQ

What’s the default port for PostgreSQL?

5432, registered with IANA.

Can I run multiple versions on different ports?

Yes - PGDG’s packages auto-assign 5432, 5433, 5434 for v16, 17, 18. The team that runs multiple versions for testing has them coexisting.

How do I find which port Postgres is on?

ss -tlnp | grep postgres or cat /etc/postgresql/<version>/main/postgresql.conf | grep ^port. The team that uses these finds the listening port.

Is it safe to run Postgres on a non-standard port?

Slightly safer (reduces drive-by scans) but the real protection is firewall + auth + TLS. The team that uses port 5432 with proper security is fine.

What if I change the port but forget to update connection strings?

Clients fail to connect with ‘connection refused’ or timeout. Fix: update connection strings and firewall rules together.

If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.

Useful related references:

#postgresql#port#config#dev-infra