Home > database >  Unable to login to Postgres
Unable to login to Postgres

Time:05-13

I am not able to login into my postgres databse deployed in docker. PFB my docker-compose.yml

  discountdb:
    image: postgres

docker-compose.override.yml

  discountdb:
    container_name: discountdb
    environment:
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=admin1234
      - POSTGRES_DB=DiscountDb
    restart: always
    ports:
        - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data/

When I am trying to create server from pgAdmin4, I am getting the following error

enter image description here

Following is the db logs

enter image description here

What did I miss?

CodePudding user response:

The environment variables you set are only used if Postgres can't find an existing database when then container starts.

Since you map a docker volume to /var/lib/postgresql/data/, chances are that you already have a database with existing users defined.

Try removing the volume mapping, so you're sure that Postgres creates a fresh database. If that solves it, then you have two options:

  1. If you don't need the data in the volume, you can delete the postgres_data volume so Postgres creates a new database
  2. If you need the data, you need to find out what userid/password you need to use to access the existing database in the volume

CodePudding user response:

Nothing is wrong here but the POSTGRES_PASSWORD is taken into account the first time you start the container I mean when your postgres_data folder is still empty. If you changed the password but postgres_data is not empty the new password is ignored, you must log in with the first one.

CodePudding user response:

The issue was with my postgres_data volume. I removed the volume using the command

docker volume rm -f discountdb

then ran the docker-compose again which resolved the issue.

  • Related