POSTGRESQL

Default PostgreSQL Port 5432: Configure, Verify, and Change Your Postgres Port

intro

Discover the PostgreSQL port configured by default (5432) and learn how to configure and change it.

Tools used in the tutorial
Tool Description Link
Dbvisualizer DBVISUALIZER
TOP RATED DATABASE MANAGEMENT TOOL AND SQL CLIENT

Each database server runs a service that listens on a specific port by default. For example the PostgreSQL default port is 5432. In this guide, you’ll learn everything you need to know about the PostgreSQL port—what it is, why it matters, and how to change it if needed.

Let’s dive in!

What’s the PostgreSQL Default Port?

When setting up or connecting to a PostgreSQL database, you might wonder which network port it uses. The port is an address on the server that the database listens on for incoming connections. Knowing the correct port is fundamental for configuring connections, firewalls, etc.

Well, the default PostgreSQL port is 5432. This is the port number PostgreSQL uses unless you or your package installer explicitly changed it.

Why 5432? No special reason beyond convention and registration. It’s just the assigned default.

For example, when connecting to PostgreSQL using a connection string or database client, you typically use the default port 5432. Specifically, a default psql connection URI might look like this:

Copy
        
1 psql postgresql://username@hostname:5432/database_name

Replace username, hostname, and database_name with your actual PostgreSQL credentials and server details.

How to Check Which Port PostgreSQL Is Listening On

The easiest way to check which port a running PostgreSQL server is listening on is by running the following SQL command:

Copy
        
1 SHOW port;

As you can see by executing the query in a visual PostgreSQL database client like DbVisualizer, the output your PostgreSQL port number:

Executing the SHOW port query in DbVisualizer
Executing the SHOW port query in DbVisualizer

In this case, it is the PostgreSQL default port5432.

An alternative approach is using the inet_server_port() function:

Copy
        
1 SELECT inet_server_port();
Executing the inet_server_port function query
Executing the inet_server_port function query

This function returns the port number on which the PostgreSQL server accepted the current connection. Otherwise, it returns NULL if the current connection is via a Unix-domain socket.

Checking the Postgres Port in Unix

To verify the port your PostgreSQL server is using on Unix-based systems like Linux or macOS, run the following command in the terminal:

Copy
        
1 sudo netstat -plnt | grep postgres

You’ll get output similar to this:

Copy
        
1 tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1234/postgres

Where 5432 is the port PostgreSQL is listening on.

Checking the Postgres Port in Windows

To check which port PostgreSQL is using on Windows, run this command in Powershell:

Copy
        
1 tasklist | findstr postgres

Take note of the PID (Process ID) from the output, and use it to find the corresponding port:

Copy
        
1 netstat -ano | findstr POSTGRES_PID

The result will be something like:

Checking the PostgreSQL port in Powershell
Checking the PostgreSQL port in Powershell

Again, note that the PostgreSQL port is 5432.

Notes about the PostgreSQL Port and How to Change It

  • Default Port: PostgreSQL has 5432 registered with IANA as its default TCP port. After installation, if you start the PostgreSQL server, it will listen on 5432 by default for TCP/IP connections.
  • Why change it? In some cases, you might need to run multiple PostgreSQL instances on one machine, or 5432 might already be in use. Many installers, if they detect 5432 is occupied, will choose the next available port, commonly 5433. That’s why you sometimes see Postgres on 5433 or another number – it’s usually the second instance on the system.
  • How to change the port: The port is configured in Postgres’s settings (postgresql.conf). There’s a parameter port which defaults to 5432. You can change it to another number (for example, port = 5433) and restart the server to have it listen on the new port. Keep in mind if you do this, clients must specify the new port when connecting.
  • Multiple instances: If you run multiple servers, ensure each has a unique port. Typical sequence is 5432, 5433, 5434, etc.
  • Firewall: If connecting to Postgres from another machine, make sure the port (5432) is open in the firewall. Many cloud servers or local firewalls block ports by default. Opening 5432 (or whichever port Postgres is on) for inbound connections is necessary for remote access.
  • Environment variable/connection default: If you don’t specify a port in a client, this will likely assume 5432. For example, the psql command-line uses 5432 by default unless you override with p option or PGPORT environment variable.

Platform Specific Notes

  • Debian/Ubuntu/macOS: The PostgreSQL package automatically uses 5432 for the first cluster. If you create a second cluster, it might assign 5433.
  • Windows: The installer configures 5432 as the Postgres port by default, unless already taken.
  • Dockerized Postgres: The container’s Postgres still runs on 5432 internally. When you do a Docker port mapping, you might map container 5432 to a different host port if needed.

Conclusion

In summary, 5432 is the default PostgreSQL port. If your Postgres isn’t reachable, double-check if it’s running on a non-standard port. Many client tools automatically use 5432, so if you changed it, you’ll need to specify the new port. And if you run multiple Postgres servers, they each need their own port (5433, 5434, etc., as appropriate).

It’s usually a good idea to stick with 5432 unless you have a specific reason not to, as it’s the well-known port and makes setups predictable. If you do change it, document it to avoid confusion for anyone else connecting to the database.

Dbvis download link img
About the author
TheTable
TheTable

The Table by DbVisualizer is where we gather together to learn about and simplify the complexity of working with database technologies.

The Table Icon
Sign up to receive The Table's roundup
More from the table
Title Author Tags Length Published
title

SQL DROP TABLE IF EXISTS: The Database Migration Lifesaver

author Leslie S. Gyamfi tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 10 min 2025-06-25
title

PostgreSQL OID: A Guide on The Object Identifier Type

author Antonello Zanini tags POSTGRESQL 7 min 2025-06-18
title

Postgres CREATE SCHEMA: A Complete Guide

author Antonello Zanini tags POSTGRESQL 7 min 2025-06-16
title

pg_dumpall: How to Dump All Your PostgreSQL Databases

author Antonello Zanini tags POSTGRESQL 7 min 2025-06-10
title

How to Compare Datetimes in SQL: Multiple Approaches

author TheTable tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 5 min 2025-06-04
title

The Complete Guide to CONCAT in SQL Queries: Syntax, Examples, and Best Practices

author Leslie S. Gyamfi tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 7 min 2025-06-03
title

How Often Should SQL Transaction Logs Be Backed Up?

author Antonello Zanini tags MySQL POSTGRESQL SQL SQL SERVER 7 min 2025-06-02
title

What Is a Database Catalog?

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 6 min 2025-05-27
title

Check If A Table Exists in SQL: Multiple Approaches

author Antonello Zanini tags MySQL POSTGRESQL SQL SQL SERVER 6 min 2025-05-14
title

A Complete Guide to NOT EXISTS in SQL

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 8 min 2025-05-12

The content provided on dbvis.com/thetable, including but not limited to code and examples, is intended for educational and informational purposes only. We do not make any warranties or representations of any kind. Read more here.