1

In my /var/lib/pgsql9/data/postgresql.conf I added port = 55434 and if I start Postgres with /usr/bin/pg_ctl start -D /var/lib/pgsql9/data/ as the postgres user then Postgres is listening to the right port lsof -i -nP:

COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
postgres 12127 postgres    3u  IPv4  49394      0t0  TCP *:55434 (LISTEN)
postgres 12127 postgres    4u  IPv6  49395      0t0  TCP *:55434 (LISTEN)
postgres 12127 postgres   10u  IPv4  49402      0t0  UDP 127.0.0.1:57562->127.0.0.1:57562
postgres 12130 postgres   10u  IPv4  49402      0t0  UDP 127.0.0.1:57562->127.0.0.1:57562
postgres 12131 postgres   10u  IPv4  49402      0t0  UDP 127.0.0.1:57562->127.0.0.1:57562
postgres 12132 postgres   10u  IPv4  49402      0t0  UDP 127.0.0.1:57562->127.0.0.1:57562
postgres 12133 postgres   10u  IPv4  49402      0t0  UDP 127.0.0.1:57562->127.0.0.1:57562
postgres 12134 postgres   10u  IPv4  49402      0t0  UDP 127.0.0.1:57562->127.0.0.1:57562

But if I try with service postgresql start as root, then it listens to the default 5432

COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
postmaste 12256 postgres    3u  IPv4  49690      0t0  TCP *:5432 (LISTEN)
postmaste 12256 postgres    4u  IPv6  49691      0t0  TCP *:5432 (LISTEN)
postmaste 12256 postgres   10u  IPv4  49698      0t0  UDP 127.0.0.1:42404->127.0.0.1:42404
postmaste 12260 postgres   10u  IPv4  49698      0t0  UDP 127.0.0.1:42404->127.0.0.1:42404
postmaste 12261 postgres   10u  IPv4  49698      0t0  UDP 127.0.0.1:42404->127.0.0.1:42404
postmaste 12262 postgres   10u  IPv4  49698      0t0  UDP 127.0.0.1:42404->127.0.0.1:42404
postmaste 12263 postgres   10u  IPv4  49698      0t0  UDP 127.0.0.1:42404->127.0.0.1:42404
postmaste 12264 postgres   10u  IPv4  49698      0t0  UDP 127.0.0.1:42404->127.0.0.1:42404

I've noticed the difference in COMMAND (postmaste vs postgres) but I don't really know why running service doesn't read the postgresql.conf that I edited. I would have assumed root could read it. I would like to use service since I can easily set Postgres to run at boot with chkconfig postgresql on, but if I have to use pg_ctrl then I guess I'll have to add the start command in /etc/rc.local (anything wrong with this?).

This is on a t1.micro instance of 64-bit Amazon Linux AMI 2014.03 (latest as of writing). And running psql (PostgreSQL) 9.2.7 (installed via yum).

I'm not very good with Linux so any help and tip is appreciated! Thanks!

  • 1
    looks like service command uses different config file, or even different postgres location – kofemann Apr 1 '14 at 6:09
  • 1
    Yep, check things like /etc/default/postgresql, /etc/sysconfig/postgresql, /etc/postgresql, etc, see if there's a config file that overrides the port. In general I strongly recommend avoiding Amazon's PostgreSQL packages, and using a well tested and established distribution like CentOS, RHEL, Ubuntu, or Debian that has proper packages from apt.postgresql.org or yum.postgresql.org – Craig Ringer Apr 1 '14 at 6:25
1

Actually it turned out I didn't read the postgres.conf carefully enough. It read (in the comments):

#port = 5432                # (change requires restart)
# Note: In RHEL/Fedora installations, you can't set the port number here;
# adjust it in the service file instead.

So I find that the file to edit was /etc/rc.d/init.d/postgresql and I changed the port setting in the following lines:

# Set defaults for configuration variables
PGENGINE=/usr/bin
PGPORT=55434
PGDATA=/var/lib/pgsql9/data
PGLOG=/var/lib/pgsql9/pgstartup.log
# Value to set as postmaster process's oom_adj
PG_OOM_ADJ=-17

Then I simply did service postgresql restart and it finally started listening on my 55434 port.

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.