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
}
  • 1
    Can you ping localhost? Are you getting that error from the psql? – Evan Carroll May 15 '17 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. – quickblueblur May 16 '17 at 18:12
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?

  • 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. – quickblueblur May 17 '17 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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