Centos – Cannot change PostgreSQL port

centosportpostgresqlvirtualization

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 0.0.0.0:5432                0.0.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?

Best Answer

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:

/etc/rc.d/init.d/postgresql-9.1

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.