How to Change Port of PostgreSQL Server on AlmaLinux 8

a) Edit Configuration File

Open the /var/lib/pgsql/data/postgresql.conf file in your favorite text editor with superuser privileges. Find and uncomment the following line.
# Port = 5432
Change the value to your desired port number. Suppose it will be 1702.
Port = 1702

b) Let FirewallD Know

If you want remote access, you have to add the new port to FirewallD‘s allow list.
sudo firewall-cmd --permanent --add-port=1702/tcp
You should remove the default, i.e., the previous port of PostgreSQL, from FirewallD‘s allow list.
sudo firewall-cmd --permanent --remove-port=5432/tcp
Then reload FirewallD.
sudo firewall-cmd --reload

c) Restart PostgreSQL

Restart the database server to make the change take effect.
sudo systemctl restart postgresql.service


Abdullah As-Sadeed

Abdullah As-Sadeed