0

Here's the error message I am receiving.

could not translate host name "localhost" to address: hostname nor servname provided, or not known

From my searching, it seems like postgresql has crashed due to an error. If a proper shutdown is initiated, the message is different.

FATAL:  the database system is shutting down

So I know it's not a proper shutdown of the database service that is occurring.

I am logging to syslog on a FreeBSD system. The log is very basic and essentially only shows me shutdown and startup attempts.

LOG:  database system was shut down at 2017-05-08 09:20:16 EDT
LOG:  database system is ready to accept connections

I am currently using default logging options. What do I need to change in order for PostgreSQL to log errors?

Requested Information

/etc/hosts:

127.0.0.1               localhost localhost.my.domain

DB connection code:

char conninfo[] = "host=localhost port=xxx dbname=xxx user=xxx password=xxx";
conn = PQconnectdb(conninfo);
if (PQstatus(conn) != CONNECTION_OK) {
print error
}
3
  • 1
    Can you ping localhost? Are you getting that error from the psql? Commented May 15, 2017 at 17:09
  • @EvanCarroll yes I can ping localhost. The database connects for some time before it reaches this error. I am printing this error in C code using libpq. The error happens after a few days of the server being on. Commented May 16, 2017 at 18:12
  • And if you change listen_addresses = '[to your real IP address]' in postgresql.conf, and connect to the database using that IP address, do you get the same error? Commented Mar 5 at 21:15

1 Answer 1

0
could not translate host name "localhost" to address

Implies a failure in your DNS resolver. You can see the error generated in libpq's fe-connect.c :1661. There is a call to pg_getaddrinfo_all which is a wrapper for getaddrinfo which is provided by glibc.

See man getaddrinfo.

Does your local /etc/hosts file have an entry for localhost, or are you relying on a remote DNS server to resolve localhost to 127.0.0.1? What are you providing in PGConn to connectDBStart?

1
  • There's no remote DNS setup and there is an entry in my hosts file (I'll add that to the original post). I can ping localhost just fine and the C code can connect to the server and will stay connected for days/weeks/etc. I'll add the connect info to the original post as well. Commented May 17, 2017 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.