Error asyncpg.exceptions.InvalidPasswordError: password authentication failed for user "steamtrader_pguser"

Viewed 798

I am trying to run Telegram bot on Aiogram Python with PostgreSQL database on Ubuntu 20.04 server in Docker using docker-compose. The script runs, but I get

asyncpg.exceptions.InvalidPasswordError: password authentication failed for user "steamtrader_pguser"

Here is my docker-compose.yml file:

version: "3.1"

services:
  steamtraderpurchases_db:
    container_name: steamtraderpurchases_db
    image: sameersbn/postgresql:10-2
    environment:
      PG_PASSWORD: $PGPASSWORD
    restart: always
    ports:
      - 5432:5432
    networks:
      - steamtraderpurchases_botnet
    volumes:
      - ./pgdata:/var/lib/postgresql

  steamtraderpurchases_bot:
    container_name: steamtraderpurchases
    build:
      context: .
    command: python app.py
    restart: always
    networks:
      - steamtraderpurchases_botnet
    env_file:
      - ".env"
    volumes:
      - .:/src
    depends_on:
      - steamtraderpurchases_db
    ports:
      - 8443:3001


networks:
  steamtraderpurchases_botnet:
    driver: bridge

Here is the Dockerfile:

FROM python:3.9.5

WORKDIR /src
COPY requirements.txt /src
RUN pip install -r requirements.txt
COPY . /src

In the .env file I have specified:

DATABASE=steamtrader
PGUSER=steamtrader_pguser
PGPASSWORD=password
DB_HOST=steamtraderpurchases_db
IP=*ip of my server*

The rest of the code is a Telegram bot. Also, I create a database with the required fields using SQLAlchemy and Gino. This is my first time trying to run a bot on the server, so I will be very grateful for your help!

UPD: I found these lines in the logs when running docker-compose:

FATAL: password authentication failed for user "steamtrader_pguser"
DETAIL:  Role "steamtrader_pguser" does not exist.

I tried to create a role but nothing worked

1 Answers

Please see sameersbn/postgresql's doc:

By default the postgres user is not assigned a password and as a result you can only login to the PostgreSQL server locally. If you wish to login remotely to the PostgreSQL server as the postgres user, you will need to assign a password for the user using the PG_PASSWORD variable.

Above means the corresponding user of PG_PASSWORD is postgres, not steamtrader_pguser. To add a new user steamtrader_pguser, you will have to follow next:

A new PostgreSQL database user can be created by specifying the DB_USER and DB_PASS variables while starting the container.

docker run --name postgresql -itd --restart always \
 --env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' \
 sameersbn/postgresql:12-20200524

Above means you need to set DB_USER and DB_PASS in docker-compose.yaml's environment section.

Related