2

I have VM with ubuntu 18.04 server installed. I have installed postgres 10 from the repo.

Default installation. I made some connection count related changes in postgres.conf and connection security related changes in pg_hba.conf.

The install directories are all the default, including the data directory.

Server is running. I was able to create databases and access the same from java client.

But when I start psql from the same VM, it throws the following error.

Error: Invalid data directory

Just psql without any parameters also gives this error.

People have faced this error when they have tried to change the data directory which is not the case for me. Data directory is the default and it is owned by the postgres user.

ubuntu@ubuntu:~$ ls -l /var/lib/postgresql/10/
total 4
drwx------ 20 postgres postgres 4096 Jun 12 02:54 main

Any idea what could be the cause or where should I look for detailed error for psql client?

  • 1
    psql command-line client or postmaster server process? what did you try that provoked that error message? – Jasen Jun 12 '18 at 10:14
  • which repo? ubuntu or postgres? – Jasen Jun 12 '18 at 10:17
6

Error: Invalid data directory

This happens when pg_wrapper is unable to figure out the data directory from the configuration. pg_wrapper is the layer on top of postgres that can juggle between several live PostgreSQL instances on debian-based systems. As installed by the postgresql-client package, psql is a link to pg_wrapper on such systems:

/usr/bin/psql -> ../share/postgresql-common/pg_wrapper

Since you mention slightly modifying postgresql.conf, make sure you didn't change the permissions inside /etc/postgresql/, including postgresql.conf. That looks like the most plausible change that would immediately lead to the mentioned error. The next one would be that your changes are syntactically wrong, in a way that pg_wrapper would no longer be able to parse the file.

  • Thanks, you are right. I was using ansible to update the postgres.conf. It changed the permission from 0644 to 0640. Resetting back the permission fixed the issue. Somehow this was not happening on ubuntu 16.04. Is there anyway to increase the verbosity of psql command so that I could have got this hint. – gagan singh Jun 12 '18 at 16:21
  • Indeed, my user (as opposed to postgres user) didn't have read access to postgresql.conf. The culprit is ANXS.postgresql. – x-yuri Feb 11 at 19:54
  • A couple of links that show the stacktrace. – x-yuri Feb 11 at 19:55

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.