4
tameen@tameen-HP:~/Downloads/$ sudo -u postgres 
tameen@tameen-HP:~/Downloads/$ sudo -u postgres psql
[sudo] password for tameen: 
psql: 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.5433"?

tameen@tameen-HP:~/Downloads/$ netstat -an | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:5939          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN  

if its listening the port 5432 and by using export PGPORT=5432 its not working . How to solve this problem?


tameen@tameen-HP:~/Downloads$ sudo su postgres 
postgres@tameen-HP:/home/tameen/Downloads$ createdb template_postgis
could not change directory to "/home/tameen/Downloads": Permission denied
createdb: could not connect to database template1: 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.5433"?

3 Answers 3

7

Provide the port and host via -p/-h options:

sudo -u postgres psql -p 5432 -h 127.0.0.1

createdb -p 5432 -h 127.0.0.1 template_postgis
Sign up to request clarification or add additional context in comments.

5 Comments

okay - see i am using postgresql 9.4 version - and django gives me this exception django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database "geodjango". GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?
Did you follow "Installing PostGIS" instruction? docs.djangoproject.com/en/1.7/ref/contrib/gis/install/postgis
okay i am using django 1.5 old version for an old project to run it and to know its functionality - should i remove Postgresql - 9.4 and install 2.1 or above version - yes i follow this but i installed 9.4 -
Is 9.4 not a spatial?
createdb has the same -p/-h options as the psql command.
2

At a guess you're using a PostgreSQL psql client and libpq compiled with a default unix_socket_directories of /var/run/postgresql but your server is compiled with /tmp as the default.

This is common when you have PostgreSQL installed from your distro's packages and also installed by some other means.

Use psql -h /tmp/ to specify the unix socket directory, rather than switching to tcp/ip as @catavaran suggests.

Comments

0

As you can see on the unix socket /var/run/postgresql/.s.PGSQL.5433 your client tries to connect to unix socket for a server running on port 5433. According to your netstat output, your server is running on port 5432.

I would suggest:

  1. Stop the server
  2. Delete all leftover socket files in /var/run/postgresql/
  3. start the server again

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.