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.
Thank you! It really helped me.
Hello Bernard,
No problem. Thanks for taking the time to leave feedback.
Thanks.
alex
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.
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
This Helped me ALOT .. had a long day trying to figure it out.
Thank you Alex
Hello Cliff,
No problem. Thanks for taking the time to leave feedback.
Thanks.
alex
Hello,
This cost a lot of head pain/hours digging and debugging, thank Mr Alex.
Hello SIFE,
No problem! Thanks for posting feedback!
Thanks.
alex