简体   繁体   English

连接到在 Docker 中运行的 postgres 时出错:pq:用户“postgres”的密码验证失败

[英]Getting an error while connecting to postgres running in Docker: pq: password authentication failed for user “postgres”

Trying to open Database but it is saying password authentication failed for user "postgres" I am not able to find the root cause of this problem.First time,i am using Docker.试图打开数据库,但它说用户“postgres”的密码验证失败我无法找到这个问题的根本原因。第一次,我使用的是 Docker。 Pleas help请帮忙

func openDB() (*sqlx.DB, error) {
    q := url.Values{}
    q.Set("sslmode", "disable")
    q.Set("timezone", "utc")

    u := url.URL{
        Scheme:   "postgres",
        User:     url.UserPassword("postgres", "postgres"),
        Host:     "localhost",
        Path:     "postgres",
        RawQuery: q.Encode(),
    }
    fmt.Println(u.String())
    
    // fmt.Println(u.String()) is
    // postgre://postgres:postgres@localhost/postgres?sslmode=disable&timezone=utc
    return sqlx.Open("postgres", u.String())
}

docker-compose.yaml looks like this. docker-compose.yaml看起来像这样。

version: '3'
networks:
  shared-network:
    driver: bridge
services:
  db:
    container_name: sales_db
    networks:
      - shared-network
    image: postgres:11.1-alpine
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - 5432:5432

There was no problem in code.代码没有问题。 I changed the port eveything is working now.我改变了端口一切现在都在工作。

func openDB() (*sqlx.DB, error) {
    q := url.Values{}
    q.Set("sslmode", "disable")
    q.Set("timezone", "utc")

    u := url.URL{
        Scheme:   "postgres",
        User:     url.UserPassword("postgres", "postgres"),
        Host:     "localhost:5433", // change here
        Path:     "postgres",
        RawQuery: q.Encode(),
    }
    fmt.Println(u.String())
    
    // fmt.Println(u.String()) is
    // postgre://postgres:postgres@localhost/postgres?sslmode=disable&timezone=utc
    return sqlx.Open("postgres", u.String())
}

and

version: '3'
networks:
  shared-network:
    driver: bridge
services:
  db:
    container_name: sales_db
    networks:
      - shared-network
    image: postgres:11.1-alpine
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - 5433:5432 //change here

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命:连接到 postgres 时,用户“postgres”的密码身份验证失败 - FATAL: password authentication failed for user "postgres" While connecting to postgres pq:在 vscode 中访问 postgres 时用户“用户名”的密码验证失败 - pq: password authentication failed for user "user-name" while accessing postgres in vscode 将 postgres 从本地计算机连接到 docker 时,用户的密码身份验证失败 - password authentication failed for user while connecting postgres from local machine to docker Docker postgres映像中的用户密码验证失败 - Password authentication failed for user in Docker postgres image Postgres docker 错误:致命:用户密码验证失败 - Postgres docker error: FATAL: password authentication failed for user postgres / docker:用户的密码身份验证失败 - postgres / docker: password authentication failed for user 用户“postgres”的 Docker 密码认证失败 - Docker password authentication failed for user “postgres” panic:pq:用户“ postgres”的密码认证失败,同时通过hypertable中的timescaledb-parallel-copy将数据添加到表中 - panic: pq: password authentication failed for user “postgres” while adding the data into table through timescaledb-parallel-copy in hypertable 用户“postgres”的 Docker postgres 9.4 密码认证失败 - Docker postgres 9.4 password authentication failed for user “postgres” Docker Django Postgres 致命:用户“postgres”的密码验证失败 - Docker Django Postgres FATAL: password authentication failed for user "postgres
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM