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'm on RHEL 5.4, and I've set up a Django project using PostgreSQL as the database (I've used MySQL before, but want to try something new :) ). When I run the Django test server, everything works, I can also connect trough the command line with password authentification:

psql -U myuser -h

But when I try to access my project over Apache, I get a 500 error code and this python traceback in apache's error log:

mod_wsgi (pid=7026): Exception occurred processing WSGI script '/var/www/myproject/myproject/hook.wsgi'.
Traceback (most recent call last):
  File "/var/www/myproject/myproject/src/django/django/core/handlers/", line 245, in __call__
    response = middleware_method(request, response)
  File "/var/www/myproject/myproject/src/django/django/contrib/sessions/", line 36, in process_response
  File "/var/www/myproject/myproject/src/django/django/contrib/sessions/backends/", line 55, in save
    obj = Session(
  File "/var/www/myproject/myproject/src/django/django/contrib/sessions/backends/", line 152, in _get_session_key
    self._session_key = self._get_new_session_key()
  File "/var/www/myproject/myproject/src/django/django/contrib/sessions/backends/", line 144, in _get_new_session_key
    if not self.exists(session_key):
  File "/var/www/myproject/myproject/src/django/django/contrib/sessions/backends/", line 29, in exists
  File "/var/www/myproject/myproject/src/django/django/db/models/", line 132, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/var/www/myproject/myproject/src/django/django/db/models/", line 336, in get
    num = len(clone)
  File "/var/www/myproject/myproject/src/django/django/db/models/", line 81, in __len__
    self._result_cache = list(self.iterator())
  File "/var/www/myproject/myproject/src/django/django/db/models/", line 269, in iterator
    for row in compiler.results_iter():
  File "/var/www/myproject/myproject/src/django/django/db/models/sql/", line 672, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/var/www/myproject/myproject/src/django/django/db/models/sql/", line 726, in execute_sql
    cursor = self.connection.cursor()
  File "/var/www/myproject/myproject/src/django/django/db/backends/", line 75, in cursor
    cursor = self._cursor()
  File "/var/www/myproject/myproject/src/django/django/db/backends/postgresql_psycopg2/", line 136, in _cursor
    self.connection = Database.connect(**conn_params)
OperationalError: could not connect to server: Permission denied
\tIs the server running on host "" and accepting
\tTCP/IP connections on port 5432?

I checked the conn_params dictionary, it contains the correct username and password. My pg_hba.conf looks like this (I have the same exact configuration on an Ubuntu 9.04 server, where everything works peachy):

local   all         postgres                          ident
local   all         all                               md5
host    all         all          md5
host    all         all         ::1/128               md5

What am I doing wrong?

share|improve this question
up vote 1 down vote accepted

One of the common mistakes is to specify password in plain text, while according to your pg_hba.conf configuration it should be supplied as md5.
Update the password in your configuration file with it's md5 and try again. You may use any MD5 generator for that, like this one.

share|improve this answer
Unfortunately, that didn't help. Also, changing the method in pg_hba.conf to "password" and using the unhashed password didn't work, neither. – Benjamin Wohlwend Sep 8 '10 at 14:38
I see.. Can you please increase PostgreSQL logging verbosity, restart the service, and paste some logs after authentication failure? – Andrejs Cainikovs Sep 8 '10 at 15:58

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.