Checkmk plugin mk_postgres.py unable to connect to postgres database instance. It is looking for unix socket in default location

CMK version: - 2.16
OS version: RHEL 8

Error message: ./mk_postgres.py psql: error: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.8462”?

**Output of “cmk --debug -vvn hostname”: ./mk_postgres.py psql: error: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.8462”?

Note : It is looking to use unix socket from default directory /var/run/postgresql. Due to some security reasons we are not using the default path for unix socket. We are using /tmp. If the plugin mk_postgres.py can use PG_HOST variable that is specified in the environment file, it will look into /tmp location. Since there is no parameter or variable $PG_HOST in plugin file, it is failing. Kindly suggest . We can’t use the default path at any cost. If possible please update the plugin to use PG_HOST for connection in psql commands.

Try to run the agent itself. The agent script sets some environment variables, that tell e.g., plugins, where to find configuration.

No. the agent is not getting the monitoring metrics of postgresql database. like bloating, connections. locking, etc

I think we worked around it by creating a symlink. Would that be an option for you?

Hi Mickey,

Due to security reasons we are not supposed to use the default path for data directory, installation directory, socket directory, etc. creating a symbolic link is almost similar to using the socket in default directory. it would be better if the checkmk plugin for postgresql supports PG_HOST environment variable.