postgresql - Flyway 无法找到 postgres docker 的角色
问题描述
我正在尝试使用 docker postgres 图像运行我的第一个 flyway 示例,但出现以下错误:
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 编写 yml 文件:
version: "3.8"
services:
postgres:
image: postgres:12.2
ports: ["5432:5432"]
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_USER=flyway-service
我在 MAC OSX 上运行此代码。我想,我在这里遗漏了一些明显的东西,但不确定是什么!任何指针将不胜感激。
解决方案
终于在朋友的帮助下解决了这个问题!5432
问题不在于附加代码,而在于旧 Postgres 安装在同一端口上运行的 postgres 守护进程。
我在这里找到了完整的卸载程序。删除额外的守护进程后,只有一个端口监听。
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)
推荐阅读
- javascript - Angular POST 请求在命中 Spring Boot 端点时不起作用
- dafny - 在 Dafny 链表实现中使用空引用终止循环
- xaml - 汉堡图标和搜索栏之间的空白来自哪里?
- nginx - X-Frame-Options 标头未设置为 nginx
- node.js - Hyperledger Fabric 2.3 错误:在 Endorser-name 的截止日期之前无法连接:
- prometheus - 如何将 Confluent 云指标发送到 Datadog?
- node.js - putItem() 是异步函数吗?如果是,那么为什么我的 Lambda 函数只需要 ~20 次 putItem() 调用就会超时?
- python - 对 2 个 NumPy 数组的元素求和
- python - 单元测试从 s3 下载 json 文件的函数
- c# - 如何使叙述者正确对待 NavigationView 中的组