Customize PostgreSQL port on Linux

Customize PostgreSQL port on Linux

Spread the love

Changing PostgreSQL port is our adventure in this article, hence, flow these instructions to achieve the objective in clear four steps.

If you didn’t have an adventure with PostgreSQL, then read this basics article.

PostgreSQL also called Postgres is a powerful DBMS. moreover, It is available in most Linux distributions. therefore, It comes with the default values.

I usually ask a few questions about any new software installation. for example, I ask what is the default values and where is the location of configuration files.

Postgres default port

PostgresSQL default port is 5432, however, the installer will pick the next available port if it is not available. for example port 5433 … etc.

Postgres default installation does not allow external access. hence, local applications use a socket or network port is 5432 from localhost only.

To check the current port used by Postgres service by using “netstat“. in default configuration, it will show you the port mapped to localhost


changing Postgres default port

Open postgres main configuration file postgresql.conf. This file located inside /etc/postgresql/<PG-Version>/main/ . To clarify, PGVersion will replaced by postgresSQL version.

Changing port for postgresSQL 9.5

To successfully change database port the following steps Stop database if running by executing the following command

open postgresql.conf file

Firstly you need to change the value of the paramter located in line 63, or you can search for word “port”. Then, under the section titled CONNECTIONS AND AUTHENTICATION.

Keep in mind, that make sure that the new port number is free.

Start the postgreSQL service using systemctl

PostgreSQL error log

You should the error log of after service is started. using


In conclusion, If you want to change postgresql default port 5432, You should edit the file /etc/postgresql/9.5/main/postgresql.conf file.
Make sure to configure your application to use the new port to avoid application crash