Flyway无法在postgres docker中找到角色

问题描述 投票:0回答:1

我正在尝试使用docker postgres图像运行我的第一个飞行路线示例,但出现以下错误:

INFO: Flyway Community Edition 6.4.2 by Redgate
Exception in thread "main" org.flywaydb.core.internal.exception.FlywaySqlException: 
Unable to obtain connection from database (jdbc:postgresql://localhost/flyway-service) for user 'flyway-service': FATAL: role "flyway-service" does not exist
-------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL State  : 28000
Error Code : 0
Message    : FATAL: role "flyway-service" does not exist

    at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:65)
    at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:80)

我查看了Docker容器,可以看到用户角色flyway-service是在docker-compose执行过程中创建的:

$ docker exec -it flywayexample_postgres_1 bash
root@b2037e382112:/# psql -U flyway-service;
psql (12.2 (Debian 12.2-2.pgdg100+1))
Type "help" for help.

flyway-service=# \du;
                                      List of roles
   Role name    |                         Attributes                         | Member of 
----------------+------------------------------------------------------------+-----------
 flyway-service | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

flyway-service=# 

主类是:

    public static void main( String[] args ) {
        var flyway = Flyway.configure().schemas("flyway_test_schema")
                .dataSource("jdbc:postgresql://localhost/flyway-service", "flyway-service",
                        "password")
                .load()
                .migrate();
        System.out.println( "Flyway example's hello world!" );
    }
}

称为src / main / resources / db / migration / V1__Create_person_table.sql的迁移:

create table PERSON (
    ID int not null,
    NAME varchar(100) not null
);

Docker-compose yml文件:

version: "3.8"
services:
  postgres:
    image: postgres:12.2
    ports: ["5432:5432"]
    environment:
      - POSTGRES_PASSWORD=password
      - POSTGRES_USER=flyway-service

我正在MAC OSX上运行此代码。我想,我在这里遗漏了一些明显的东西,但不确定是什么!任何指针将不胜感激。

postgresql docker flyway
1个回答
1
投票

最后在朋友的帮助下设法解决了这个问题!问题不在于附加的代码,而是旧的Postgres安装在同一端口5432上运行的postgres守护进程。

我找到了完整的卸载过程here。删除其他守护程序后,仅监听了一个端口。

a$ lsof -n -i4TCP:5432
COMMAND   PID         USER   FD   TYPE            DEVICE SIZE/OFF NODE NAME
com.docke 654 root   50u  IPv6 0x7ae1b5f8fbcf1cb      0t0  TCP *:postgresql (LISTEN)
© www.soinside.com 2019 - 2024. All rights reserved.