edu-samples icon indicating copy to clipboard operation
edu-samples copied to clipboard

connect postgres error

Open menghe999 opened this issue 2 years ago • 1 comments

with the guide of article, I started the postgresql service in docker,but i can't connected the postgresql remote.

when i use command to connect the postgresql service,found error

[mengh@pa1 ~]$ psql -h pa3 -p 5432 -U postgresuser -d shipment_db
psql: error: connection to server at "pa3" (10.100.1.228), port 5432 failed: FATAL:  role "postgresuser" does not exist

but when i connect the the postgresql service in container,It's fine.

[mengh@pa3 ~]$ docker exec -it my_postgres_1 /bin/bash
root@5040544d402e:/# 
root@5040544d402e:/# psql -h localhost -p 5432 -U postgresuser -d shipment_db
psql (13.11 (Debian 13.11-1.pgdg110+1))
Type "help" for help.

shipment_db=# 
shipment_db=# \dt
Did not find any relations.
shipment_db=# 

So i don't know the reason for the error, have you met the error ?

menghe999 avatar Jun 26 '23 09:06 menghe999

it's my docker compose file


version: "3.7"
services:
  postgres:
    image: debezium/postgres:13
    ports:
      - 5432:5432
    healthcheck:
      test: "pg_isready -U postgresuser -d shipment_db"
      interval: 2s
      timeout: 20s
      retries: 10
    environment:
      - POSTGRES_USER=postgresuser
      - POSTGRES_PASSWORD=postgrespw
      - POSTGRES_DB=shipment_db
      - PGPASSWORD=postgrespw
    volumes:
      - ./scripts:/docker-entrypoint-initdb.d
                                                   

menghe999 avatar Jun 26 '23 09:06 menghe999