I recently installed PostgreSQL on an Amazon Web Services CentOS instance however when I first attempted to start Postgres I received an error that I had never seen before. The pgstartup.log file located in /var/lib/pgsql contained the below data.

Error Contents Of pgstartup.log File:

LOG: could not translate host name "localhost", service "5432" to address: Name or service not known
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets

To view the pgstartup.log file use the below command.

less /var/lib/pgsql/pgstartup.log

After viewing the error file I realized that for some reason there was no localhost configured by default on the AWS instance that was using a CentOS 5.3 base image. So to resolve the issue all I needed to do was add a hosts file to the /etc directory with the below contents.

Contents of /etc/hosts:

127.0.0.1 localhost localhost.localdomain

After adding the above to /etc/hosts I attempted to start Postgres again using the below command.

Start Postgres:

/etc/init.d/postgresql start

This time PostgreSQL started without an issue on the Amazon Web Services instance.

PostgreSQL 8.4 Official Documentation - Volume I. The SQL Language (Paperback)

By (author): The PostgreSQL Global Development Group


List Price: $34.99 USD
New From: $27.50 USD In Stock
Used from: $5.94 USD In Stock


List Price: $29.99 USD
New From: $7.95 USD In Stock
Used from: $2.99 USD In Stock

DeliciousStumbleUponDiggTwitterFacebookRedditLinkedInEmail
Tags: , , , , , , , , , , , , , ,
8 Responses to “LOG: could not translate host name “localhost”, service “5432″ to address: Name or service not known”
  1. Bernard Banta says:

    Thank you! It really helped me.

    [Reply]

    alex Reply:

    Hello Bernard,

    No problem. Thanks for taking the time to leave feedback.

    Thanks.
    alex

    [Reply]

  2. arth1 says:

    No such luck here. localhost is defined in /etc/hosts, and /etc/hosts is world readable, but I still get:

    LOG: could not translate host name “localhost”, service “5432″ to address: Name or service not known
    WARNING: could not create listen socket for “localhost”
    FATAL: could not create any TCP/IP sockets

    localhost definitely resolves, as I can ping and ssh to it. And nothing else is listening to port 5432.

    [Reply]

    alex Reply:

    Hello arth1,

    You might try changing the listen host from localhost to 127.0.0.1 or a specific interface IP address to see if that resolves your problem.

    Thanks.
    alex

    [Reply]

  3. Cliff says:

    This Helped me ALOT .. had a long day trying to figure it out.
    Thank you Alex

    [Reply]

    alex Reply:

    Hello Cliff,

    No problem. Thanks for taking the time to leave feedback.

    Thanks.
    alex

    [Reply]

  4. SIFE says:

    Hello,
    This cost a lot of head pain/hours digging and debugging, thank Mr Alex.

    [Reply]

    alex Reply:

    Hello SIFE,

    No problem! Thanks for posting feedback!

    Thanks.
    alex

    [Reply]

  5.  
Leave a Reply

*Type the letter/number combination in the abvoe field before clicking submit.

*