psql: FATAL: could not write init file

as the title points out, I'm getting this error when trying to connect to a PostgreSql database from command line, using PostgreSQL.

The client machine is an Ubuntu 11.10 x86_64 and the PostgreSQL libraries are from Version 9.1

Server is PostgreSql 8.3.

This is the command that I executed:

psql -U postgres -d my_database -h 192.168.0.161 -p 5432 -c "select * from xxyy"

I get the same results when I use sudo or su postgres.

The sad thing is that I can connect without problems using pgAdmin.

Any hint?


Solution 1:

I had the same issue earlier.

Upon checking the log, I saw that postgres was complaining about diskspace. A df -h showed that the device had 0MB free space available. After freeing up some space, it worked.

Solution 2:

Try to look in /var/log/postgresql/postgresql-[your_version]-main.log on the server for signs of what's failing.

You might also try to launch that psql command locally, from the server, to see whether the problem is really with your client.