[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 521
  • Last Modified:

Postgres startup error

I installed postgres on my RHES a while ago and haven't worked with startup scripts yet, so every time I reboot my server I start postgres manually, changing to user postgres and executing this:
$ postmaster -D /usr/share/pgsql/data
or, in the background:
$ postmaster -D /usr/share/pgsql/data >logfile 2>&1 &
Now when I try starting postgres, I get this error:
LOG:  StreamServerPort: bind() failed: Cannot assign requested address
        Is another postmaster already running on port 5432?
        If not, wait a few seconds and retry.
postmaster: cannot create INET stream port
I've run netstat -a, netstat -an and ps -ef |grep '5432', 'postgres' and 'postmaster'
Nothing is running on port 5432 and postgres isn't running on any port.  
The environment variables are probably not the problem, but I've checked them and the paths to postgres, pg_ctl and pgsql files are in /etc/profile and $env confirms the paths are recognized.  
/var/log/messages repeats the same error, and postgres doesn't have a log file in /var/log, only an executable.  I've checked these pages and the postgres website for clues, no go so far.
Why won't postgres start?
  • 2
  • 2
2 Solutions
netstat -ltnp | grep 5432
Have You changed IP recently? Maybe postgres trying to bind to old IP?
try runnign it via strace, will show You bind() parameters. maybe You will spot something odd. strace -f postmaster -D /usr/share/pgsql/data
klukacAuthor Commented:
Thanks very much!  I did change my IP, and had completely forgotten that there are a couple of files in /usr/share/pgsql/data  (pg_hba.conf and postgresql.conf) where the IP of the host and virtual host are specified.  I wasn't sure about the virtual host, but put in the same IP as for the host to be sure, since apache is using name-based virtual hosting - a number of virtual hosts are defined for the same IP and port number, with a separate port for SSL connections.  So let me know if I'm doing this correctly :)

strace didn't work for me, but my main concern before closing this ticket is figuring out how to track startup errors.  It turns out that I did have a command to start up postgres on boot in my /etc/rc.d/rc.local file, but it wasn't working.  I modified it to make sure that it would execute as postgres and it still didn't work.  However I tried executing the same command in a terminal window and it worked.  So, from a terminal window, I can start postgres (as user postgres) with:
$ postmaster -D /usr/share/pgsql/data, or
$ /usr/bin/pg_ctl start -l logfile -D /usr/share/pgsql/data (so it runs in the background)
however boot startup with this line in rc.local doesn't work:
su -c '/usr/bin/pg_ctl start -l logfile -D /usr/share/pgsql/data' postgres
Interestingly, I have a similar problem with mysql - it's correctly linked at all the right run levels, but it doesn't start on boot - I have to start it manually each time from a terminal window, like so:
$/etc/rc.d/init.d/mysqld start
I see no errors in /var/log/messages, and the dtg on /usr/share/pgsql/data/logfile is July 2005, so it's not logging startup errors.  Mysql is supporting both regular http and https/SSL connections,  however my postgres db's are just demos (which I have not worked on in a while) and not using SSL.

With those virtualhosts You doing propably good. Anyway, the have one or many IPs ?

> su -c '/usr/bin/pg_ctl start -l logfile -D /usr/share/pgsql/data' postgres
it's very propable, that pg_ctl tries to create /logfile instead /usr/share/pgsql/data/logfile as You expecting.
klukacAuthor Commented:
I have two IPs on the server (motherboard LAN and a NIC card) but I'm only using one of them.

I removed the logging parameter, and postgres starts on boot, with su -c 'pg_ctl start -D /usr/share/pgsql/data' postgres, so thanks for that :)

My postgres is actually logging to syslog, which is frustrating for any debugging involving a server reboot.  I have version 7.3, and it's buggy - for example, when I type postgres -version, it looks for PG_VERSION in /var/lib/pgsql/data, however that file resides in /usr/share/pgsql.  Based on the postgres manual for version 7.3, the postgres start-up path should be in /usr/local, not /usr/share, and so on.  So it's time to upgrade.  I must have screwed up the initial install somehow, will be more careful next time.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now