4

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
 }

}

BoumTAC
  • 3,531
  • 6
  • 32
  • 44

2 Answers2

2

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': '****',
 }

}

BoumTAC
  • 3,531
  • 6
  • 32
  • 44
  • After this I get: 5432 failed: FATAL: Ident authentication failed for user "geo". – mavavilj Jun 01 '22 at 09:51
  • The problem may also be reproduced for Peer authentication. The solution however seems to be: `sudo nano /var/lib/pgsql/data/pg_hba.conf`, where one should change peer or ident to md5, and then update `settings.py` DATABASES with appropriate USER and PASSWORD. – mavavilj Jun 01 '22 at 13:28
0

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

Community
  • 1
  • 1
Mathias Vonende
  • 1,400
  • 1
  • 18
  • 28