2
votes

I'm starting the geodjango tutorial. I've copy and past everythings but I still get the error.

django.db.utils.OperationalError: FATAL:  Peer authentication failed for user "geo"

I'm new to geodjango and postgresql and postgis. I've made a fresh install of postgresql and postgis.

I create the geo user as in the doc.

$ sudo su - postgres
$ createuser --createdb geo
$ exit

I can't figure how to resolve it.

Here is my settings:

DATABASES = {
'default': {
     'ENGINE': 'django.contrib.gis.db.backends.postgis',
     'NAME': 'geodjango',
     'USER': 'geo',
     # 'HOST': 'localhost', I tried this but didn't work
     # 'PASSWORD': '***', I tried it too using a password but didn't work
 }

}

2

2 Answers

1
votes

So I find a solution, the geodjango tutorial is not working.

sudo -i -u postgres

then:

psql

then:

CREATE USER username;

ALTER ROLE username WITH CREATEDB;

ALTER USER username WITH ENCRYPTED PASSWORD 'password';

and I have my settings like this:

DATABASES = {
'default': {
     'ENGINE': 'django.contrib.gis.db.backends.postgis',
     'NAME': 'geodjango',
     'USER': 'username',
     'HOST': 'localhost',
     'PASSWORD': '****',
 }

}

0
votes

Peer authentication Errors are usually caused by a bad pg_hba.conf file. There are entries in your file, that prevent your user from executing queries.

The pg_hba.conf is located in your postgres-data directory and defines basic configurations of your postgres-installation. In your case, the database gets a request, but denies the processing, because your user is not autheticated to perform the request.

Log in as your postgres-user:

sudo su - postgres

edit the file, with the editor of your choice (I use emacs):

emacs -nw data/pg_hba.conf

change the access-restrictions: Here it becomes tricky. If your have a postgres-Installation to play and develop with (not in production) you may set access to 'trust':

change:

host    all             all             0.0.0.0/0            ident

to:

host    all             all             0.0.0.0/0            trust

However, if you use the Database in production, don't set it to trust!. Instead configure it to check against passwords / hashes.

host    all             all             0.0.0.0/0            md5

Here are some Links, that might help out:

Link to the docs

Question on SO