0

I installed postgresql and (I think) pyscopg2. I want to run postgresql with django. I tried the command "createdb mydb", and I got the error message shown below. What should I do?

could not connect to database postgres:

could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

I am running a mac osx 10.8.2.

When I type in ps auwwx|grep postg I get:

robbie          27589   0.0  0.0  2443176   1528   ??  Ss    7:25am   0:00.01 postgres: autovacuum launcher process       
robbie          27588   0.0  0.0  2443044    552   ??  Ss    7:25am   0:00.01 postgres: wal writer process       
robbie          27587   0.0  0.0  2443044    592   ??  Ss    7:25am   0:00.16 postgres: writer process       
robbie          27586   0.0  0.0  2443044    612   ??  Ss    7:25am   0:00.00 postgres: checkpointer process       
robbie          27584   0.0  0.1  2443044   3524   ??  S     7:25am   0:00.02 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log
robbie          27626   0.0  0.0  2423572     24 s000  S+    7:36am   0:00.00 grep postg
robbie          27590   0.0  0.0  2439324    444   ??  Ss    7:25am   0:00.01 postgres: stats collector process

When I type in psql -V I get: psql (PostgreSQL) 9.1.4 When I type in which psql I get:/usr/bin/psql

5
  • 1
    As the error message says..Is your postgresql instance running? Which environment are you on? Commented Jun 18, 2013 at 13:33
  • Have you tried connecting via psql? like psql -U user databse_name Commented Jun 18, 2013 at 13:42
  • psql -U user databse_name Commented Jun 18, 2013 at 13:43
  • Doesn't work, I get the same error. Commented Jun 18, 2013 at 13:44
  • how do you start/stop postgres? I am not sure about mac but in ubuntu/gentoo you can use -- sudo service postgresql status or sudo /etc/init.d/postgresql-version status -- to check status of the service in case you run it as a service. Commented Jun 18, 2013 at 13:48

1 Answer 1

1

You can connect in 2 different ways to PostgreSQL:

  1. Unix sockets. They are special files on your filesystem that process can write into and read from.
  2. TCP sockets, which main purpose is to allow inter-machine communications on top of the Internet Protocol, but that can very well be used to connect 2 processes on the same machine.

The error message you're getting tells you that Django attempted method one, looking for a special file representing a Unix socket, but didn't succeed. It's very likely that your PostgreSQL instance listens on TCP sockets instead of Unix sockets. To confirm this, try to connect to PostgreSQL using the psql command line client like this:

psql -h localhost -U user databse_name

If you're successful, then you can configure Django to connect to localhost via TCP sockets by setting the HOST key in your settings.py file:

DATABASES = {
    'default': {
     [...]
        'HOST': 'localhost',
     [...]
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

I tried the psql code above and got this error: psql: FATAL: role "user" does not exist
You need to adapt this command to your own context. Replace user by the name of the PostgreSQL user you have created and database_name by your own database name. It seems you're a beginner with both Django and PostgreSQL. I'd recommend you get a bit more familiar with PostgreSQL before trying to connect it to Django: postgresql.org/docs/9.2/static/tutorial.html

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.