Reputation: 1030
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
Upvotes: 0
Views: 241
Reputation: 4083
You can connect in 2 different ways to PostgreSQL:
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',
[...]
}
}
Upvotes: 1