【问题标题】:Running init script on oracle test container with system privileges使用系统权限在 oracle 测试容器上运行 init 脚本
【发布时间】:2022-04-23 05:34:50
【问题描述】:

我正在为 org.testcontainers:oracle-xe:1.14.3 苦苦挣扎。 我正在尝试运行旨在验证架构创建和迁移的测试,但是在尝试使用用户“sys as sysdba”初始化用户进行测试时,我遇到了 InitScript。

@Before
public void setUp() {
    oracleContainer = new OracleContainer("oracleinanutshell/oracle-xe-11g")
    .withUsername("sys as sysdba")
    .withInitScript("oracle-initscript.sql");
    oracleContainer.start();
}

上面好像可以连接,但是init脚本的执行失败了

ORA-01109: 数据库未打开

在上面使用“system”用户不会提供具有 sysdba 权限的 InitScript 连接,但会导致打开数据库。

我正在寻找一种允许我在测试前初始化多个用户的解决方案。此初始化具有需要 sysdba 权限的授权。执行一些 SQL 脚本的测试要求在数据库中创建两个用户并且可以连接到数据库。

【问题讨论】:

  • 你找到替代品了吗?
  • 不,但我确实做了一个解决方法。我制作了一个包含一些常规初始化的图像,并将初始化步骤作为我使用的一部分。

标签: docker oracle11g testcontainers


【解决方案1】:

就我而言,我正在使用

oracleContainer = new OracleContainer("gvenzl/oracle-xe:18.4.0-slim")
    .withUsername("test")
    .withPassword("test")
    .addEnv("ORACLE_PASSWORD", "s") // Sys password is required
    .withCopyFileToContainer(MountableFile.forHostPath("oracle-initscript.sql"), "/container-entrypoint-initdb.d/init.sql")

gvenzl/oracle-xe 是 org.testcontainers.oracle-xe 库使用的默认映像。

The documentation for this image 描述了如何在 DB 启动时调用初始化 SQL,效果很好。

很难说是什么问题,但这里有一些技巧:

  • 可能“sys as sysdba”在您的代码中无效,文档中的用法并不清楚
  • 也许 withLogConsumer 可以提供一些线索,什么是错的
  • 我推荐镜像 gvenzl/oracle-xe,
  • 在某些情况下 withInitScript 可能无法正常工作。
  • 在手动启动的容器上测试初始化​​脚本很有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-01
    相关资源
    最近更新 更多