0

Last week, my integration tests were running fine. Today, this exception consistently gets thrown before my tests get run:

org.postgresql.util.PSQLException: FATAL: could not open file "base/12669/2601": No such file or directory
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433)
        at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2566)
        at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:131)
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:210)
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
        at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
        at org.postgresql.Driver.makeConnection(Driver.java:452)
        at org.postgresql.Driver.connect(Driver.java:254)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:270)
        at com.onzo.analytics.dal.PostgresForTesting.openConnection(PostgresForTesting.scala:111)

PostgresForTesting.scala:111 is the body of this function in my code:

  private def openConnection(): Unit = {
    _connection = DriverManager.getConnection(_dbUrl)
  }

DriverManager is java.sql.DriverManager.

_dbUrl is set up in here:

  private def startPostgres(): Unit = {
    val port = 5431 // standard port is 5432; use a non-standard port to avoid accidentally using a real Postgres
    _postgres = new EmbeddedPostgres(Version.V9_6_8, "imadatadir") // I changed this
    val config = sys.env.get("HOME") match {
      case None => EmbeddedPostgres.defaultRuntimeConfig()
      case Some(ndHome) =>
        val cache = Paths.get(ndHome, ".cache", "embedded-postgres")
        Files.createDirectories(cache)
        EmbeddedPostgres.cachedRuntimeConfig(cache)
    }
    // downloads Postgres, caches it locally (101MB)
    _dbUrl = _postgres.start(config, "localhost", port, _dbName, "username", "password", new util.ArrayList[String])

    val executor = AsyncExecutor(
      name = "pg-for-testing",
      minThreads = this.postgresConfig.numThreads,
      maxThreads = this.postgresConfig.numThreads,
      maxConnections = this.postgresConfig.maxConnections,
      queueSize = this.postgresConfig.queueSize
    )
    _db = Database.forURL(_dbUrl, driver = "org.postgresql.Driver", executor = executor)
  }

EmbeddedPostgres is ru.yandex.qatools.embed.postgresql.EmbeddedPostgres, from postgresql-embedded.

Before this issue raised its ugly head this morning, I was using a temporary directory, instead of hardcoding the imadatadir directory. (See line marked I changed this.) I hardcoded the imadatadir directory in an attempt to debug this issue. (So this was not what caused the issue.)

Interesting fact: the base/12669/2601 file it complains about not being able to open does actually exist:

$ ls -l imadatadir/base/12669/2601*
-rw-------  1 dave.hinton  staff   8192 17 Dec 12:57 imadatadir/base/12669/2601
-rw-------  1 dave.hinton  staff  24576 17 Dec 12:57 imadatadir/base/12669/2601_fsm
-rw-------  1 dave.hinton  staff   8192 17 Dec 12:57 imadatadir/base/12669/2601_vm

Further facts, which may or may not be relevant:

  • none of my colleagues can reproduce the issue; they're on Linux, I'm on macOS
  • I have not upgraded macOS over the weekend

Versions:

  • Scala 2.12.4
  • JVM: Oracle Java 8 Update 191
  • SBT 1.2.1
  • postgresql-embedded 2.9 (I see version 2.10 is out now... but no change when I upgrade to use it)
  • macOS Mojave 10.14.1

Any ideas on how I can get this working again? Or at least investigate further what's going wrong?

dave4420
  • 46,404
  • 6
  • 118
  • 152
  • 1
    You're specifying the datadir as a relative path. It's probably worth trying to specify it as an absolute path. – fvu Dec 17 '18 at 15:35
  • Same results when I specify the datadir as an absolute path, unfortunately @fvu. – dave4420 Dec 17 '18 at 15:42
  • this seems to be a duplicate https://dba.stackexchange.com/questions/17481/recover-from-postgres-fatal-could-not-open-file-pg-tblspc – Serhii Shynkarenko Dec 17 '18 at 17:24
  • @SergeyShinkarenko That doesn't seem to be a duplicate, as it is asking about recovering a production system after a disk failure, whereas I am asking how a freshly created system can be in a broken state (and how to prevent it from getting into that state). Am I missing something? – dave4420 Dec 17 '18 at 17:37

0 Answers0