0

I get an error password authentication failed for user "usertodoproject". Really losing my patience, so far I have done couple of new databases and used fpr example this ALTER USER todouser WITH PASSWORD 'todo'; it did not help either. Any ideas?

*EDIT IT IS DOCKER-COMPOSE FAULT NOT SETTINGS. App runs without docker.

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'todoproject',
        'USER': 'usertodoproject',
        'PASSWORD': 'todoprojectpass',
        'HOST': 'db',
        'PORT': '5432',
    }
}

docker-compose

version: "3"

services:
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    ports: 
      - 8000:8000
    volumes:
      - .:/code
    depends_on:
      - db
    restart: always
  db:
    image: postgres
    environment:
    - POSTGRES_DB=todoproject
    - POSTGRES_USER=usertodoproject
    - POSTGRES_PASSWORD=todoprojectpass
    ports:
    - 5432:5432
Kay
  • 591
  • 1
  • 7
  • 27
  • Make sure your database's [`postgresql.conf`](https://www.postgresql.org/docs/14/config-setting.html#CONFIG-SETTING-CONFIGURATION-FILE) and [`pg_hba.conf`](https://www.postgresql.org/docs/14/auth-pg-hba-conf.html) both [allow](https://stackoverflow.com/a/18580598/5298879) the type of connection you're trying to establish. – Zegarek Dec 05 '21 at 15:38
  • Questions to answer 1) How are you accessing the database(s) to do the `ALTER USER ...`? 2) Looks like you are running Postgres in a Docker container, is that correct? 3) Where is the Django app relative to the Docker container? 4) What versions of Postgres and psycopg2? Add answers as update to your question. – Adrian Klaver Dec 05 '21 at 15:57
  • I edited, it is something with docker-compose – Kay Dec 05 '21 at 15:59
  • 1
    @Zegarek, I doubt it is `postgresql.conf` or `pg_hba.conf` as you would get different errors: 1) Something like `Is the server running on that host and accepting TCP/IP connections?` for a change in `listen_addresses` 2) For the `pg_hba` case something like `FATAL: no pg_hba.conf entry ...` – Adrian Klaver Dec 05 '21 at 16:04
  • As i said it is something with docker-compose because without docker app is running correctly – Kay Dec 05 '21 at 16:13
  • You need to provide the answers for the other questions. In addition do you have another instance of the database running outside the Docker container? – Adrian Klaver Dec 05 '21 at 16:30

1 Answers1

0

You should verify few point that outscope the python programming:

  • Status of postgresql, is it running with systemctl status postgresql command
  • verify the listening port 5432 with netstat -plantu command (db is the host ?)
  • is user usertodoproject is created ?
jwko
  • 24
  • 4
  • 1
    Except all those where already answered as yes by the error message. If the server where not running on port 5432 you would not have gotten as far as this message. Same with user name, you would have gotten something like `role "" does not exist`. So basically this is a non-answer. Please update to something that is useful or delete it. – Adrian Klaver Dec 05 '21 at 16:28