I run Postgresql 8.4 as a service on a CentOS 6.2 server.

I set port = 21444 and listen_addresses = '*' in /var/lib/pgsql/data/postgresql.conf file

and I changed 5432 to 21444 in postmaster.opts and restarted postgres, but when I run netstat -lntp postgresql is still running on port 5432

tcp        0      0      *                   LISTEN      20276/postmaster 

When I restart postgresql I get a writting error warning on /proc/self/oom_adj, but the service starts anyway.

I read that we could get this error when using virtualized servers, but I don't really know if this has inpact on postgresql listening port.

The correct pgsql config file is loaded in /var/lib/pgsql/data :

[root@srv02 ~]# ps -ef | grep postgres
root      1358 22140  0 09:42 pts/0    00:00:00 grep postgres
postgres  9519     1  0 Mar16 ?        00:00:01 /usr/bin/postmaster -p 5432 -D /var/lib/pgsql/data
postgres  9573  9519  0 Mar16 ?        00:00:00 postgres: logger process                          
postgres  9575  9519  0 Mar16 ?        00:00:05 postgres: writer process                          
postgres  9576  9519  0 Mar16 ?        00:00:03 postgres: wal writer process                      
postgres  9577  9519  0 Mar16 ?        00:00:01 postgres: autovacuum launcher process             
postgres  9578  9519  0 Mar16 ?        00:00:01 postgres: stats collector process             

any thought?

  • The line of netstat output you pasted above shows a UNIX socket listener, not a TCP listener. You should use netstat -lntp to only show TCP listeners. – ThatGraemeGuy Mar 15 '12 at 12:33
  • sorry, I replaced it – Jerec TheSith Mar 15 '12 at 13:17
  • Check this stackoverflow.com/a/25155581/2889419 dude, I had the same problem, finally found it. – user2889419 Aug 11 '14 at 21:15

I have same problem when trying to set port number in postgresql.conf, as many instructions indicated. Your ps -ef reads:

/usr/bin/postmaster -p 5432

this line tells it starts at 5432.

It is run by the service start script, in my case (CentOS6.3 + postgresql-9.1) it's here:


There is a line read:

# Override defaults from /etc/sysconfig/pgsql if file is present
[ -f /etc/sysconfig/pgsql/${NAME} ] && . /etc/sysconfig/pgsql/${NAME}

So All I did is go to /etc/sysconfig/pgsql, create a new file postgresql-9.1, add one line there: PGPORT=8100. In above case, you should add PGDATA=. Note, the filename should be the same as your service name, if you don't know, use

chkconfig --list | grep post* 

to find out.

Then restart the server by:

sudo service postgresql-9.1 restart.
  • thank you very much I'll try this this fternoon. is this a bug that should be reported to postgresql ? – Jerec TheSith Feb 5 '13 at 9:37
  • @JerecTheSith, it could be a bug, or they are encourage user to set PGPORT that way (maybe other ways in other linux distro) – simonxy Feb 5 '13 at 20:18
  • This is indeed the proper way to change the port on CentOs/RHEL or Scientific. Ubuntu is a different story – Ross Dec 11 '15 at 0:47
  • The part where you say 'the filename should be the same as your service name' is CRUCIAL. :) – Alfabravo Mar 21 '17 at 18:37

Are you restarting it using a restart action, or are you stopping the service and then starting it again?

I have Ubuntu, but I managed to get the same behaviour as you by restarting, but when I stopped and then started postgresql, it listened on the new port. So try to stop it and then start it, and see if it starts listening on the new port.

  • I tried this too, but I'm getting the same warning when stopping/starting or restarting the service, and pgAdmin3 can't connect on port 5432 – Jerec TheSith Mar 16 '12 at 10:15
  • Are you sure you're editing the correct config file? Run ps -ef | grep postgres and you should see a line that includes the config file path as an option. For example mine looks like this: config_file=/etc/postgresql/8.4/main/postgresql.conf – ThatGraemeGuy Mar 18 '12 at 19:22
  • Thanks for your help, ps show that the correct pgsql process is started, even though the config file is not displayed in this output – Jerec TheSith Mar 19 '12 at 8:46

in /etc/init.d/postgresql-9.3 find PGPORT = 5432 and change it to Your Desired Port Number then restart. It solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.