Having issues with postgresql, what should I log? 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
}
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?