Postgres startup error

Posted on 2006-05-29
Last Modified: 2013-12-16
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?
Question by:klukac
    LVL 43

    Assisted Solution

    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

    Author Comment

    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.

    LVL 43

    Accepted Solution

    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.

    Author Comment

    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

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
    Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now