Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a local postgres server running (on ubuntu linux). It is listening via a socket file:

$ ls -la /var/run/postgresql/
total 8
drwxrwsrwx  2 postgres postgres  100 2011-04-15 19:06 .
drwxr-xr-x 26 root     root     1100 2011-04-15 19:12 ..
-rw-------  1 postgres postgres    5 2011-04-15 19:06
srwxrwxrwx  1 postgres postgres    0 2011-04-15 19:06 .s.PGSQL.5433
-rw-------  1 postgres postgres   34 2011-04-15 19:06 .s.PGSQL.5433.lock

I can connect to the server fine on the command line:

$ psql -d gis -U rory
psql (8.4.7)
Type "help" for help.

gis=# \q
$ psql -d gis
psql (8.4.7)
Type "help" for help.

 gis=# \q

I am trying to use osm2pgsql, an application from the OpenStreetMap project, which imports data into a pgsql database.

However the error I get is:

$ ./osm2pgsql/osm2pgsql -m -d gis -U rory ../data.osm.bz2 
osm2pgsql SVN version 0.70.5

Connection to database failed: 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.5432"?

Noticably, it is trying to use the socket file .s.PGSQL.5432, which doesn't exist, whereas the actual socket filename is .s.PGSQL.5433, the filenames are almost exactly the same.

Why is it using the wrong filename, and how do I make it use the correct one?

share|improve this question

It looks like your PostgreSQL server has been configured to listen on port 5433, instead of the default 5432. Your Postgres client app is assuming the default, and is thus not finding the socket. Try setting the PGPORT environment variable to 5433 before your run your app. E.g.:

PGPORT=5433 ./osm2pgsql/osm2pgsql -m -d gis -U rory ../data.osm.bz2
share|improve this answer

For me what worked to fix this error was adding -H localhost to the command (even though intuitively, I shouldn't have to)


 osm2pgsql -H localhost -s -d foo switzerland-latest.osm.pbf

Caveat: I am using the default postgres 5432 port though

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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