PostgreSQL change connection port 5432

  • Last update: Apr 3, 2024
  • Views: 75
  • Author: Admin
PostgreSQL change connection port 5432

Colleagues hello to all.

In today's article, we'll talk about how you can change the connection port to a PostgreSQL database. It is highly desirable to change the connection port after creating the database in order to protect your data from hacking.

 

Article content:

  1. Check which port is currently set.
  2. Changing the connection port.
  3. Check.

 

1. Checking which port is currently set.

By default, the Postgresql database uses connection port 5432. We can verify this by running the command:

sql> SELECT name, setting FROM pg_settings WHERE name = 'port';

postgresql_change_port

Another way to check using the command in Linux:

$. sudo netstat -plunt |grep postmaster

postgresql_change_port

As we can see in all the results, we have port 5432.


 

2. Changing the connection port.

Changing the connection port dynamically will not work because this variable is static. We need to change this setting in the  postgresql.conf configuration file which is located in the same directory where you have your database installed.

Change the port parameter in the postgresql.conf file.

postgresql_change_port

Save the file and be sure to restart the database.


 

3. Check.

postgresql_change_port

When connecting to a database, now we need to additionally specify the connection port, or add a special variable called PGPORT = 5444 to bash_profile.

 

postgresql_change_port

The postmaster process now also listens on port 5444 instead of 5432.


 

Thank you all, I hope that my article helped you in some way.

SIMILAR ARTICLES