postgresql - Flyway无法在Postgres Docker中找到角色

标签 postgresql docker flyway

我正在尝试使用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容器,可以看到在docker-compose执行过程中创建了用户角色flyway-service:
$ 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上运行此代码。我想,我这里缺少明显的东西,但不确定是什么!任何指针将不胜感激。

最佳答案

终于在 friend 的帮助下找到了问题所在!问题不在于附加的代码,而是旧的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)

关于postgresql - Flyway无法在Postgres Docker中找到角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61856828/

相关文章:

postgresql - 在存在于多个具有相同名称的模式中的表上创建 View

ruby-on-rails-3 - 启动 rails3.1 应用时出现 Heroku 错误,缺少 postgres gem

postgresql - Play Framework EBean 获取具有关系的对象

docker - 将 Docker 镜像从 GKE 中运行的容器推送到 Google 容器注册表

grails - 如何在Grails中使用Flyway

sql - 添加到 Postgres 中的 json 列中的数组

apache-spark - docker-compose v3 + apache spark,端口 7077 上的连接被拒绝

docker - 从我拥有的存储库中提取 Docker 镜像时访问被拒绝

java - 使用 Flyway 进行惰性数据库迁移

flyway - Flyway 有什么方法可以包含或排除脚本吗?