Home > Back-end >  postgres database issues with encoding UTF-8
postgres database issues with encoding UTF-8

Time:06-18

I have created a docker image with this command docker compose up -d where I was able to load pgAdmin instance in http://localhost:5050/browser/ create a database and table in the same , credentials are working properly.

However when I start to run my main spring boot application CustomerApplication it fails with below error >

org.postgresql.util.PSQLException: FATAL: la autentificación password falló para el usuario «amigoscode» (pgjdbc: autodetected server-encoding to be ISO-8859-1, if the message is not readable, please check database logs and/or host, port, dbname, user, password, pg_hba.conf)

I do not know what is wrong, my credentials are correct. what seems to be the issue?

below are application.yml and docker-compose.yml

docker-compose.yml

services:
  postgres:
    container_name: postgres
    image: postgres
    environment:
      POSTGRES_USER: amigoscode
      POSTGRES_PASSWORD: password
      PGDATA: /data/postgres
    volumes:
      - postgres:/data/postgres
    ports:
      - "5432:5432"
    networks:
      - postgres
    restart: unless-stopped

  pgadmin:
    container_name: pgadmin
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:[email protected]}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
      PGADMIN_CONFIG_SERVER_MODE: 'False'
    volumes:
      - pgadmin:/var/lib/pgadmin
    ports:
      - "5050:80"
    networks:
      - postgres
    restart: unless-stopped

networks:
  postgres:
    driver: bridge

volumes:
  postgres:
  pgadmin:

application.yml

server:
  port: 8080
spring:
  application:
    name: customer
  datasource:
    username: amigoscode
    url: jdbc:postgresql://localhost:5432/customer
    password: password
  jpa:
    hibernate:
      ddl-auto: create-drop
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect
        format_sql: true
    show-sql: true

customer table Script

CREATE DATABASE customer
    WITH
    OWNER = amigoscode
    ENCODING = 'UTF8'
    LC_COLLATE = 'en_US.utf8'
    LC_CTYPE = 'en_US.utf8'
    TABLESPACE = pg_default
    CONNECTION LIMIT = -1;

CodePudding user response:

When you created the role amigoscode did you actually set a password for it?

CREATE ROLE amigoscode WITH LOGIN PASSWORD 'password';

You may have logged into pgadmin as the postgres superuser, created the role amigoscode and never set a password. The encoding issue looks similar to the one specified enter image description here

  • Related