psycopg2 "could not connect to server" error on Ubuntu
While trying to run python manage.py syncdb with
Django 1.2.1, psycopg2 2.2.1 and PostgreSQL 8.4 on Ubuntu Lucid,
I got the following error saying I couldn't connect to the database.
$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/home/saltycrane/lib/python-environments/saltycrane121/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/saltycrane/lib/python-environments/saltycrane121/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/saltycrane/lib/python-environments/saltycrane121/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/saltycrane/lib/python-environments/saltycrane121/lib/python2.6/site-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File "/home/saltycrane/lib/python-environments/saltycrane121/lib/python2.6/site-packages/django/core/management/base.py", line 347, in handle
return self.handle_noargs(**options)
File "/home/saltycrane/lib/python-environments/saltycrane121/lib/python2.6/site-packages/django/core/management/commands/syncdb.py", line 52, in handle_noargs
cursor = connection.cursor()
File "/home/saltycrane/lib/python-environments/saltycrane121/lib/python2.6/site-packages/django/db/backends/__init__.py", line 75, in cursor
cursor = self._cursor()
File "/home/saltycrane/lib/python-environments/saltycrane121/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 136, in _cursor
self.connection = Database.connect(**conn_params)
psycopg2.OperationalError: 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"?
I tried connecting via psql and that worked. I looked in
/var/run/postgresql/ and found:
$ ls -lA /var/run/postgresql
total 8
srwxrwxrwx 1 postgres postgres 0 2010 06/08 21:29 .s.PGSQL.5433
-rw------- 1 postgres postgres 34 2010 06/08 21:29 .s.PGSQL.5433.lock
-rw------- 1 postgres postgres 5 2010 06/08 21:29 8.4-main.pid
So it turns out my Postgres server is running on port 5433, but
Django (psycopg2) expects to find it at 5432 by default.
So I changed the port number
to 5433 in my settings.py and it worked.
Note: I looks like the reason my Postgres server was running on port
5433 instead of 5432 is because I previously had PostgreSQL 8.3 installed
on my machine and there were configuration files left in
/etc/postgresql/8.3/
The port setting is configured in /etc/postgresql/8.x/main/postgresql.conf.
1
Comment
—
Comments feed for this post
Post a comment
About
I'm Eliot and this is my notepad for programming topics such as Python, Django, Ubuntu, Emacs, etc... more »
Search Blog
Tags
-
algorithms
(4)
-
aws
(8)
-
blogproject
(20)
-
c_cplusplus
(12)
-
cardstore
(8)
-
colinux
(2)
-
concurrency
(9)
-
conkeror
(2)
-
cygwin
(18)
-
datastructures
(15)
-
datetime
(3)
-
dell
(3)
-
django
(39)
-
emacs
(20)
-
files_directories
(10)
-
install_setup
(7)
-
javascript
(3)
-
keyboard
(6)
-
matplotlib
(5)
-
mercurial
(4)
-
nginx
(2)
-
preferences
(8)
-
processes
(3)
-
pyqt
(18)
-
python
(122)
-
ratpoison
(3)
-
regexes
(5)
-
rsync
(3)
-
softwaretools
(17)
-
sql
(13)
-
ssh
(7)
-
subversion
(6)
-
twisted
(6)
-
ubuntu
(60)
-
urxvt
(5)
-
vxworks
(25)
-
webservices
(4)
-
wmii
(7)
Blogroll
- Adam Gomaa
- Alex Clemesha
- Amir Salihefendic
- Armin Ronacher
- David Beazley
- David Ziegler
- Duncan McGreggor
- Gareth Rushgrave
- Glyph Lefkowitz
- Guido van Rossum
- Ian Bicking
- Jacob Kaplan-Moss
- James Bennett
- James Tauber
- Jesper Noehr
- Matt Harrison
- Nikolay Kolev
- Parand Darugar
- Peter Baumgartner
- Peter Bengtsson
- Rob Hudson
- Simon Willison
- Will McGugan
#1 LaundroMat commented on 2010-08-30:
Thanks! I was tearing my hair out over this one.